2009-10-13 05:58:37 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2009-03-03 09:51:57 +00:00
|
|
|
##############################################################################
|
2009-10-14 11:15:34 +00:00
|
|
|
#
|
|
|
|
# OpenERP, Open Source Management Solution
|
2010-01-12 09:18:39 +00:00
|
|
|
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
|
2009-03-03 09:51:57 +00:00
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
2009-10-14 11:15:34 +00:00
|
|
|
# it under the terms of the GNU Affero General Public License as
|
|
|
|
# published by the Free Software Foundation, either version 3 of the
|
|
|
|
# License, or (at your option) any later version.
|
2009-03-03 09:51:57 +00:00
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2009-10-14 11:15:34 +00:00
|
|
|
# GNU Affero General Public License for more details.
|
2009-03-03 09:51:57 +00:00
|
|
|
#
|
2009-10-14 11:15:34 +00:00
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2009-03-03 09:51:57 +00:00
|
|
|
#
|
|
|
|
##############################################################################
|
|
|
|
|
2008-09-26 14:23:55 +00:00
|
|
|
import threading
|
2012-12-27 05:12:45 +00:00
|
|
|
import logging
|
|
|
|
|
2008-09-26 14:23:55 +00:00
|
|
|
import authorizer
|
|
|
|
import abstracted_fs
|
2012-12-27 05:12:45 +00:00
|
|
|
import ftpserver
|
|
|
|
|
|
|
|
import openerp
|
2012-12-06 14:56:32 +00:00
|
|
|
from openerp.tools import config
|
2012-06-22 06:48:39 +00:00
|
|
|
_logger = logging.getLogger(__name__)
|
2012-12-27 05:12:45 +00:00
|
|
|
|
2011-09-26 12:28:14 +00:00
|
|
|
def start_server():
|
2012-12-27 05:12:45 +00:00
|
|
|
if openerp.multi_process:
|
|
|
|
_logger.info("FTP disabled in multiprocess mode")
|
|
|
|
return
|
2013-11-13 18:30:16 +00:00
|
|
|
if openerp.evented:
|
|
|
|
_logger.info("FTP disabled in evented mode")
|
|
|
|
return
|
2011-09-26 12:28:14 +00:00
|
|
|
HOST = config.get('ftp_server_host', '127.0.0.1')
|
|
|
|
PORT = int(config.get('ftp_server_port', '8021'))
|
|
|
|
PASSIVE_PORTS = None
|
|
|
|
pps = config.get('ftp_server_passive_ports', '').split(':')
|
|
|
|
if len(pps) == 2:
|
|
|
|
PASSIVE_PORTS = int(pps[0]), int(pps[1])
|
2008-09-26 14:23:55 +00:00
|
|
|
|
2011-09-26 12:28:14 +00:00
|
|
|
class ftp_server(threading.Thread):
|
2012-06-22 06:48:39 +00:00
|
|
|
|
2011-09-26 12:28:14 +00:00
|
|
|
def run(self):
|
|
|
|
autho = authorizer.authorizer()
|
|
|
|
ftpserver.FTPHandler.authorizer = autho
|
|
|
|
ftpserver.max_cons = 300
|
|
|
|
ftpserver.max_cons_per_ip = 50
|
|
|
|
ftpserver.FTPHandler.abstracted_fs = abstracted_fs.abstracted_fs
|
|
|
|
if PASSIVE_PORTS:
|
|
|
|
ftpserver.FTPHandler.passive_ports = PASSIVE_PORTS
|
2009-07-13 13:28:55 +00:00
|
|
|
|
2012-06-22 06:48:39 +00:00
|
|
|
ftpserver.log = lambda msg: _logger.info(msg)
|
2011-09-26 12:28:14 +00:00
|
|
|
ftpserver.logline = lambda msg: None
|
2012-06-26 20:19:46 +00:00
|
|
|
ftpserver.logerror = lambda msg: _logger.error(msg)
|
2008-11-25 16:12:27 +00:00
|
|
|
|
2011-09-26 12:28:14 +00:00
|
|
|
ftpd = ftpserver.FTPServer((HOST, PORT), ftpserver.FTPHandler)
|
|
|
|
ftpd.serve_forever()
|
2009-11-16 15:00:21 +00:00
|
|
|
|
2011-09-26 12:28:14 +00:00
|
|
|
if HOST.lower() == 'none':
|
2012-06-22 06:48:39 +00:00
|
|
|
_logger.info("\n Server FTP Not Started\n")
|
2011-09-26 12:28:14 +00:00
|
|
|
else:
|
2012-06-22 06:48:39 +00:00
|
|
|
_logger.info("\n Serving FTP on %s:%s\n" % (HOST, PORT))
|
2011-09-26 12:28:14 +00:00
|
|
|
ds = ftp_server()
|
|
|
|
ds.daemon = True
|
|
|
|
ds.start()
|
2008-09-26 14:23:55 +00:00
|
|
|
|
2009-03-03 09:51:57 +00:00
|
|
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
2009-11-16 15:00:21 +00:00
|
|
|
|