CLIENT-SERVER: improve netrpc
bzr revid: ced-228717f183c1bf3b42dbe1e9df452bde0fb3645c
This commit is contained in:
parent
cd498105b9
commit
840953821b
|
@ -242,8 +242,9 @@ if HAS_SSL:
|
||||||
else:
|
else:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
class HttpDaemon(object):
|
class HttpDaemon(threading.Thread):
|
||||||
def __init__(self, interface,port, secure=False):
|
def __init__(self, interface,port, secure=False):
|
||||||
|
threading.Thread.__init__(self)
|
||||||
self.__port=port
|
self.__port=port
|
||||||
self.__interface=interface
|
self.__interface=interface
|
||||||
if secure and HAS_SSL:
|
if secure and HAS_SSL:
|
||||||
|
@ -255,14 +256,20 @@ class HttpDaemon(object):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
|
self.running = False
|
||||||
|
self.server.socket.shutdown(socket.SHUT_RDWR)
|
||||||
self.server.socket.close()
|
self.server.socket.close()
|
||||||
self.server.socket.close()
|
# self.server.socket.close()
|
||||||
del self.server
|
# del self.server
|
||||||
|
|
||||||
def start(self):
|
def run(self):
|
||||||
self.server.register_introspection_functions()
|
self.server.register_introspection_functions()
|
||||||
|
|
||||||
self.server.serve_forever()
|
# self.server.serve_forever()
|
||||||
|
self.running = True
|
||||||
|
while self.running:
|
||||||
|
self.server.handle_request()
|
||||||
|
return True
|
||||||
|
|
||||||
# If the server need to be run recursively
|
# If the server need to be run recursively
|
||||||
#
|
#
|
||||||
|
@ -346,7 +353,6 @@ class TinySocketServerThread(threading.Thread):
|
||||||
# print "threads size:", len(self.threads)
|
# print "threads size:", len(self.threads)
|
||||||
self.socket.close()
|
self.socket.close()
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
print "exception server", e
|
|
||||||
self.socket.close()
|
self.socket.close()
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
|
@ -40,13 +40,13 @@ def login(db, login, password):
|
||||||
if res:
|
if res:
|
||||||
return res[0]
|
return res[0]
|
||||||
else:
|
else:
|
||||||
raise _('Bad username or password')
|
raise Exception('Bad username or password')
|
||||||
|
|
||||||
def check_super(passwd):
|
def check_super(passwd):
|
||||||
if passwd == tools.config['admin_passwd']:
|
if passwd == tools.config['admin_passwd']:
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
raise 'AccessDenied'
|
raise Exception('AccessDenied')
|
||||||
|
|
||||||
def check(db, uid, passwd):
|
def check(db, uid, passwd):
|
||||||
#FIXME: this should be db dependent
|
#FIXME: this should be db dependent
|
||||||
|
@ -57,7 +57,7 @@ def check(db, uid, passwd):
|
||||||
res = cr.fetchone()[0]
|
res = cr.fetchone()[0]
|
||||||
cr.close()
|
cr.close()
|
||||||
if not bool(res):
|
if not bool(res):
|
||||||
raise 'AccessDenied'
|
raise Exception('AccessDenied')
|
||||||
if res:
|
if res:
|
||||||
_uid_cache[uid] = passwd
|
_uid_cache[uid] = passwd
|
||||||
return bool(res)
|
return bool(res)
|
||||||
|
@ -68,5 +68,5 @@ def access(db, uid, passwd, sec_level, ids):
|
||||||
res = cr.fetchone()
|
res = cr.fetchone()
|
||||||
cr.close()
|
cr.close()
|
||||||
if not res:
|
if not res:
|
||||||
raise _('Bad username or password')
|
raise Exception('Bad username or password')
|
||||||
return res[0]
|
return res[0]
|
||||||
|
|
|
@ -66,10 +66,10 @@ logger = netsvc.Logger()
|
||||||
# import the tools module so that the commandline parameters are parsed
|
# import the tools module so that the commandline parameters are parsed
|
||||||
#-----------------------------------------------------------------------
|
#-----------------------------------------------------------------------
|
||||||
import tools
|
import tools
|
||||||
|
import time
|
||||||
|
|
||||||
if sys.platform=='win32':
|
if sys.platform=='win32':
|
||||||
import mx.DateTime
|
import mx.DateTime
|
||||||
import time
|
|
||||||
mx.DateTime.strptime = lambda x,y: mx.DateTime.mktime(time.strptime(x, y))
|
mx.DateTime.strptime = lambda x,y: mx.DateTime.mktime(time.strptime(x, y))
|
||||||
|
|
||||||
#os.chdir(tools.file_path_root)
|
#os.chdir(tools.file_path_root)
|
||||||
|
@ -200,35 +200,44 @@ if tools.config["stop_after_init"]:
|
||||||
#----------------------------------------------------------
|
#----------------------------------------------------------
|
||||||
# Launch Server
|
# Launch Server
|
||||||
#----------------------------------------------------------
|
#----------------------------------------------------------
|
||||||
try:
|
|
||||||
port = int(tools.config["port"])
|
|
||||||
except Exception:
|
|
||||||
logger.notifyChannel("init", netsvc.LOG_ERROR, "invalid port '%s'!" % (tools.config["port"],))
|
|
||||||
sys.exit(1)
|
|
||||||
interface = tools.config["interface"]
|
|
||||||
secure = tools.config["secure"]
|
|
||||||
|
|
||||||
httpd = netsvc.HttpDaemon(interface,port, secure)
|
if tools.config['xmlrpc']:
|
||||||
|
try:
|
||||||
|
port = int(tools.config["port"])
|
||||||
|
except Exception:
|
||||||
|
logger.notifyChannel("init", netsvc.LOG_ERROR, "invalid port '%s'!" % (tools.config["port"],))
|
||||||
|
sys.exit(1)
|
||||||
|
interface = tools.config["interface"]
|
||||||
|
secure = tools.config["secure"]
|
||||||
|
|
||||||
|
httpd = netsvc.HttpDaemon(interface,port, secure)
|
||||||
|
|
||||||
|
if tools.config["xmlrpc"]:
|
||||||
|
xml_gw = netsvc.xmlrpc.RpcGateway('web-services')
|
||||||
|
httpd.attach("/xmlrpc", xml_gw )
|
||||||
|
logger.notifyChannel("web-services", netsvc.LOG_INFO, "starting XML-RPC services, port "+str(port))
|
||||||
|
|
||||||
|
#
|
||||||
|
#if tools.config["soap"]:
|
||||||
|
# soap_gw = netsvc.xmlrpc.RpcGateway('web-services')
|
||||||
|
# httpd.attach("/soap", soap_gw )
|
||||||
|
# logger.notifyChannel("web-services", netsvc.LOG_INFO, 'starting SOAP services, port '+str(port))
|
||||||
|
#
|
||||||
|
if not (netsvc.HAS_SSL and tools.config['secure']):
|
||||||
|
logger.notifyChannel("web-services", netsvc.LOG_INFO, "You are not using the SSL layer")
|
||||||
|
else:
|
||||||
|
logger.notifyChannel("web-services", netsvc.LOG_INFO, "You are using the SSL Layer")
|
||||||
|
|
||||||
if tools.config["xmlrpc"]:
|
if tools.config['netrpc']:
|
||||||
xml_gw = netsvc.xmlrpc.RpcGateway('web-services')
|
try:
|
||||||
httpd.attach("/xmlrpc", xml_gw )
|
netport = int(tools.config["netport"])
|
||||||
logger.notifyChannel("web-services", netsvc.LOG_INFO, "starting XML-RPC services, port "+str(port))
|
except Exception:
|
||||||
|
logger.notifyChannel("init", netsvc.LOG_ERROR, "invalid port '%s'!" % (tools.config["netport"],))
|
||||||
#
|
sys.exit(1)
|
||||||
#if tools.config["soap"]:
|
netinterface = tools.config["netinterface"]
|
||||||
# soap_gw = netsvc.xmlrpc.RpcGateway('web-services')
|
|
||||||
# httpd.attach("/soap", soap_gw )
|
tinySocket = netsvc.TinySocketServerThread(netinterface, netport, False)
|
||||||
# logger.notifyChannel("web-services", netsvc.LOG_INFO, 'starting SOAP services, port '+str(port))
|
logger.notifyChannel("web-services", netsvc.LOG_INFO, "starting netrpc service, port "+str(netport))
|
||||||
#
|
|
||||||
if not (netsvc.HAS_SSL and tools.config['secure']):
|
|
||||||
logger.notifyChannel("web-services", netsvc.LOG_INFO, "You are not using the SSL layer")
|
|
||||||
else:
|
|
||||||
logger.notifyChannel("web-services", netsvc.LOG_INFO, "You are using the SSL Layer")
|
|
||||||
|
|
||||||
|
|
||||||
tinySocket = netsvc.TinySocketServerThread(interface, 8085, False)
|
|
||||||
logger.notifyChannel("web-services", netsvc.LOG_INFO, "starting TinySocket service, port "+str(8085))
|
|
||||||
|
|
||||||
def handler(signum, frame):
|
def handler(signum, frame):
|
||||||
from tools import config
|
from tools import config
|
||||||
|
@ -245,10 +254,16 @@ if config['pidfile']:
|
||||||
pidtext="%d" % (os.getpid())
|
pidtext="%d" % (os.getpid())
|
||||||
fd.write(pidtext)
|
fd.write(pidtext)
|
||||||
fd.close()
|
fd.close()
|
||||||
|
|
||||||
signal.signal(signal.SIGINT, handler)
|
signal.signal(signal.SIGINT, handler)
|
||||||
signal.signal(signal.SIGTERM, handler)
|
signal.signal(signal.SIGTERM, handler)
|
||||||
|
|
||||||
logger.notifyChannel("web-services", netsvc.LOG_INFO, 'the server is running, waiting for connections...')
|
logger.notifyChannel("web-services", netsvc.LOG_INFO, 'the server is running, waiting for connections...')
|
||||||
tinySocket.start()
|
if tools.config['netrpc']:
|
||||||
httpd.start()
|
tinySocket.start()
|
||||||
dispatcher.run()
|
if tools.config['xmlrpc']:
|
||||||
|
httpd.start()
|
||||||
|
#dispatcher.run()
|
||||||
|
|
||||||
|
while True:
|
||||||
|
time.sleep(1)
|
||||||
|
|
|
@ -36,6 +36,8 @@ class configmanager(object):
|
||||||
'verbose': False,
|
'verbose': False,
|
||||||
'interface': '', # this will bind the server to all interfaces
|
'interface': '', # this will bind the server to all interfaces
|
||||||
'port': '8069',
|
'port': '8069',
|
||||||
|
'netinterface': '',
|
||||||
|
'netport': '8070',
|
||||||
'db_host': False,
|
'db_host': False,
|
||||||
'db_port': False,
|
'db_port': False,
|
||||||
'db_name': 'terp',
|
'db_name': 'terp',
|
||||||
|
@ -71,6 +73,10 @@ class configmanager(object):
|
||||||
|
|
||||||
parser.add_option("-n", "--interface", dest="interface", help="specify the TCP IP address")
|
parser.add_option("-n", "--interface", dest="interface", help="specify the TCP IP address")
|
||||||
parser.add_option("-p", "--port", dest="port", help="specify the TCP port")
|
parser.add_option("-p", "--port", dest="port", help="specify the TCP port")
|
||||||
|
parser.add_option("--net_interface", dest="netinterface", help="specify the TCP IP address for netrpc")
|
||||||
|
parser.add_option("--net_port", dest="netport", help="specify the TCP port for netrpc")
|
||||||
|
parser.add_option("--no-netrpc", dest="netrpc", action="store_false", default=True, help="disable netrpc")
|
||||||
|
parser.add_option("--no-xmlrpc", dest="xmlrpc", action="store_false", default=True, help="disable xmlrpc")
|
||||||
|
|
||||||
parser.add_option("-i", "--init", dest="init", help="init a module (use \"all\" for all modules)")
|
parser.add_option("-i", "--init", dest="init", help="init a module (use \"all\" for all modules)")
|
||||||
parser.add_option("--without-demo", dest="without_demo", help="load demo data for a module (use \"all\" for all modules)", default=False)
|
parser.add_option("--without-demo", dest="without_demo", help="load demo data for a module (use \"all\" for all modules)", default=False)
|
||||||
|
@ -131,13 +137,13 @@ class configmanager(object):
|
||||||
self.options['pidfile'] = False
|
self.options['pidfile'] = False
|
||||||
|
|
||||||
for arg in ('interface', 'port', 'db_name', 'db_user', 'db_password', 'db_host',
|
for arg in ('interface', 'port', 'db_name', 'db_user', 'db_password', 'db_host',
|
||||||
'db_port', 'logfile', 'pidfile', 'secure', 'smtp_server', 'price_accuracy'):
|
'db_port', 'logfile', 'pidfile', 'secure', 'smtp_server', 'price_accuracy', 'netinterface', 'netport'):
|
||||||
if getattr(opt, arg):
|
if getattr(opt, arg):
|
||||||
self.options[arg] = getattr(opt, arg)
|
self.options[arg] = getattr(opt, arg)
|
||||||
|
|
||||||
for arg in ('language', 'translate_out', 'translate_in',
|
for arg in ('language', 'translate_out', 'translate_in',
|
||||||
'upgrade', 'verbose', 'debug_mode',
|
'upgrade', 'verbose', 'debug_mode',
|
||||||
'stop_after_init', 'without_demo'):
|
'stop_after_init', 'without_demo', 'netrpc', 'xmlrpc'):
|
||||||
self.options[arg] = getattr(opt, arg)
|
self.options[arg] = getattr(opt, arg)
|
||||||
|
|
||||||
if not self.options['root_path'] or self.options['root_path']=='None':
|
if not self.options['root_path'] or self.options['root_path']=='None':
|
||||||
|
|
Loading…
Reference in New Issue