[IMP] Add the xmlrpcs option group for the xmlrpc secure mode

[FIX] Availability to disable the Http, Https and NetRPC server via the command line

bzr revid: stephane@openerp.com-20100531141739-5z419xwhmaqikdba
This commit is contained in:
Stephane Wirtel 2010-05-31 16:17:39 +02:00
parent 733fe62640
commit ac1cc7ebf5
4 changed files with 41 additions and 37 deletions

View File

@ -172,13 +172,13 @@ httpsd = None
def init_servers():
global httpd, httpsd
if tools.config.get_misc('httpd','enable', True):
httpd = HttpDaemon(tools.config.get_misc('httpd','interface', ''), \
int(tools.config.get_misc('httpd','port', tools.config.get('port',8069))))
if tools.config.get('xmlrpc'):
httpd = HttpDaemon(tools.config.get('xmlrpc_interface', ''),
int(tools.config.get('xmlrpc_port', 8069)))
if tools.config.get_misc('httpsd','enable', False):
httpsd = HttpSDaemon(tools.config.get_misc('httpsd','interface', ''), \
int(tools.config.get_misc('httpsd','port', 8071)))
if tools.config.get('xmlrpcs'):
httpsd = HttpSDaemon(tools.config.get('xmlrpcs_interface', ''),
int(tools.config.get('xmlrpcs_port', 8071)))
def reg_http_service(hts, secure_only = False):
""" Register some handler to httpd.
@ -226,14 +226,17 @@ class XMLRPCRequestHandler(netsvc.OpenERPDispatcher,FixSendError,SimpleXMLRPCSer
def init_xmlrpc():
if not tools.config.get_misc('xmlrpc','enable', True):
return
reg_http_service(HTTPDir('/xmlrpc/',XMLRPCRequestHandler))
# Example of http file serving:
# reg_http_service(HTTPDir('/test/',HTTPHandler))
netsvc.Logger().notifyChannel("web-services", netsvc.LOG_INFO,
"Registered XML-RPC over HTTP")
if tools.config.get('xmlrpc', False):
# Example of http file serving:
# reg_http_service(HTTPDir('/test/',HTTPHandler))
reg_http_service(HTTPDir('/xmlrpc/', XMLRPCRequestHandler))
netsvc.Logger().notifyChannel("web-services", netsvc.LOG_INFO,
"Registered XML-RPC over HTTP")
if tools.config.get('xmlrpcs', False):
reg_http_service(HTTPDir('/xmlrpc/', XMLRPCRequestHandler, True))
netsvc.Logger().notifyChannel('web-services', netsvc.LOG_INFO,
"Registered XML-RPC over HTTPS")
class OerpAuthProxy(AuthProxy):
""" Require basic authentication..

View File

@ -26,7 +26,6 @@
import netsvc
import threading
import tools
import os
import select
import socket
@ -152,6 +151,7 @@ netrpcd = None
def init_servers():
global netrpcd
if tools.config.get_misc('netrpcd','enable', True):
netrpcd = TinySocketServerThread(tools.config.get_misc('netrpcd','interface', ''), \
int(tools.config.get_misc('netrpcd','port', tools.config.get('netport', 8070))))
if tools.config.get('netrpc', False):
netrpcd = TinySocketServerThread(
tools.config.get('netrpc_interface', ''),
int(tools.config.get('netrpc_port', 8070)))

View File

@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
#
# Copyright P. Christeas <p_christ@hol.gr> 2008,2009
#
# A part of the code comes from the ganeti project: http://www.mail-archive.com/ganeti-devel@googlegroups.com/msg00713.html#
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential

View File

@ -44,6 +44,8 @@ class configmanager(object):
'xmlrpc_port': 8069,
'netrpc_interface': '',
'netrpc_port': 8070,
'xmlrpcs_interface': '', # this will bind the server to all interfaces
'xmlrpcs_port': 8071,
'db_host': False,
'db_port': False,
'db_name': False,
@ -53,6 +55,7 @@ class configmanager(object):
'reportgz': False,
'netrpc': True,
'xmlrpc': True,
'xmlrpcs': True,
'translate_in': None,
'translate_out': None,
'language': None,
@ -73,7 +76,6 @@ class configmanager(object):
'smtp_password': False,
'stop_after_init': False, # this will stop the server after initialization
'price_accuracy': 2,
'secure' : False,
'syslog' : False,
'log_level': logging.INFO,
'assert_exit_level': logging.ERROR, # level above which a failed assert will be raised
@ -106,6 +108,15 @@ class configmanager(object):
group.add_option("--no-xmlrpc", dest="xmlrpc", action="store_false", help="disable the XML-RPC protocol")
parser.add_option_group(group)
if self.has_ssl:
group = optparse.OptionGroup(parser, "XML-RPC Secure Configuration")
group.add_option("--xmlrpcs-interface", dest="xmlrpcs_interface", help="specify the TCP IP address for the XML-RPC Secure protocol")
group.add_option("--xmlrpcs-port", dest="xmlrpcs_port", help="specify the TCP port for the XML-RPC Secure protocol", type="int")
group.add_option("--no-xmlrpcs", dest="xmlrpcs", action="store_false", help="disable the XML-RPC Secure protocol")
group.add_option("--cert-file", dest="secure_cert_file", default="server.cert", help="specify the certificate file for the SSL connection")
group.add_option("--pkey-file", dest="secure_pkey_file", default="server.pkey", help="specify the private key file for the SSL connection")
parser.add_option_group(group)
group = optparse.OptionGroup(parser, "NET-RPC Configuration")
group.add_option("--netrpc-interface", dest="netrpc_interface", help="specify the TCP IP address for the NETRPC protocol")
group.add_option("--netrpc-port", dest="netrpc_port", help="specify the TCP port for the NETRPC protocol", type="int")
@ -129,18 +140,6 @@ class configmanager(object):
help="specify the level at which a failed assertion will stop the server. Accepted values: %s" % (self._LOGLEVELS.keys(),))
parser.add_option('--price_accuracy', dest='price_accuracy', default='2', help='deprecated since v6.0, replaced by module decimal_precision')
if self.has_ssl:
group = optparse.OptionGroup(parser, "SSL Configuration")
group.add_option("-S", "--secure", dest="secure",
help="launch server over https instead of http")
group.add_option("--cert-file", dest="secure_cert_file",
default="server.cert",
help="specify the certificate file for the SSL connection")
group.add_option("--pkey-file", dest="secure_pkey_file",
default="server.pkey",
help="specify the private key file for the SSL connection")
parser.add_option_group(group)
# Testing Group
group = optparse.OptionGroup(parser, "Testing Configuration")
group.add_option("--test-disable", action="store_true", dest="test_disable",
@ -260,20 +259,22 @@ class configmanager(object):
'netrpc', 'xmlrpc', 'syslog', 'without_demo', 'timezone',]
if self.has_ssl:
keys.extend(['secure_cert_file', 'secure_pkey_file'])
keys.append('secure')
keys.extend([
'xmlrpcs_interface',
'xmlrpcs_port',
'xmlrpcs',
'secure_cert_file',
'secure_pkey_file']
)
for arg in keys:
if getattr(opt, arg):
self.options[arg] = getattr(opt, arg)
keys = ['language', 'translate_out', 'translate_in', 'debug_mode',
'stop_after_init', 'logrotate', 'without_demo', 'netrpc', 'xmlrpc', 'syslog',
'stop_after_init', 'logrotate', 'without_demo', 'netrpc', 'xmlrpc', 'xmlrpcs', 'syslog',
'list_db', 'server_actions_allow_code']
if self.has_ssl and not self.options['secure']:
keys.append('secure')
for arg in keys:
if getattr(opt, arg) is not None:
self.options[arg] = getattr(opt, arg)