From c80995b336e4bd4b867f943cd37034930a50700a Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Thu, 29 Sep 2011 11:02:25 +0200 Subject: [PATCH] Add support for XML-RPC secure with SSL. --- asterisk_click2dial/scripts/get_cid_name.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/asterisk_click2dial/scripts/get_cid_name.py b/asterisk_click2dial/scripts/get_cid_name.py index e734458..a379f97 100755 --- a/asterisk_click2dial/scripts/get_cid_name.py +++ b/asterisk_click2dial/scripts/get_cid_name.py @@ -66,12 +66,13 @@ default_cid_name = "Not in OpenERP" # Define command line options option_server = {'names': ('-s', '--server'), 'dest': 'server', 'type': 'string', 'help': 'DNS or IP address of the OpenERP server. Default = localhost', 'action': 'store', 'default':'localhost'} option_port = {'names': ('-p', '--port'), 'dest': 'port', 'type': 'int', 'help': "Port of OpenERP's XML-RPC interface. Default = 8069", 'action': 'store', 'default': 8069} +option_ssl = {'names': ('-e', '--ssl'), 'dest': 'ssl', 'help': "Use XML-RPC secure i.e. with SSL instead of clear XML-RPC. Default = no, use clear XML-RPC.", 'action': 'store_true', 'default': False} option_database = {'names': ('-d', '--database'), 'dest': 'database', 'type': 'string', 'help': "OpenERP database name. Default = openerp", 'action': 'store', 'default': 'openerp'} option_user = {'names': ('-u', '--user-id'), 'dest': 'user', 'type': 'int', 'help': "OpenERP user ID to use when connecting to OpenERP. Default = 2", 'action': 'store', 'default': 2} option_password = {'names': ('-w', '--password'), 'dest': 'password', 'type': 'string', 'help': "Password of the OpenERP user. Default = demo", 'action': 'store', 'default': 'demo'} option_ascii = {'names': ('-a', '--ascii'), 'dest': 'ascii', 'help': "Convert name from UTF-8 to ASCII. Default = no, keep UTF-8", 'action': 'store_true', 'default': False} -options = [option_server, option_port, option_database, option_user, option_password, option_ascii] +options = [option_server, option_port, option_ssl, option_database, option_user, option_password, option_ascii] def stdout_write(string): '''Wrapper on sys.stdout.write''' @@ -139,10 +140,14 @@ def main(options, arguments): stdout_write('VERBOSE "CallerID number = %s"\n' % input_cid_number) query_number = reformat_phone_number_before_query_openerp(input_cid_number) stderr_write("phone number sent to OpenERP = %s\n" % query_number) + if options.ssl: + stdout_write('VERBOSE "Starting XML-RPC secure request on OpenERP %s:%s"\n' % (options.server, str(options.port))) + protocol = 'https' + else: + stdout_write('VERBOSE "Starting clear XML-RPC request on OpenERP %s:%s"\n' % (options.server, str(options.port))) + protocol = 'http' - stdout_write('VERBOSE "Starting XML-RPC request on OpenERP %s:%s"\n' % (options.server, str(options.port))) - - sock = xmlrpclib.ServerProxy('http://%s:%s/xmlrpc/object' % (options.server, str(options.port))) + sock = xmlrpclib.ServerProxy('%s://%s:%s/xmlrpc/object' % (protocol, options.server, str(options.port))) res = sock.execute(options.database, options.user, options.password, 'res.partner.address', 'get_name_from_phone_number', query_number) # To simulate a long execution of the XML-RPC request