Browse Source

Improve script: better default port, works when incoming phone number has a +

pull/177/head
Alexis de Lattre 6 years ago
parent
commit
69700805ab
  1. 34
      asterisk_click2dial/scripts/set_name_agi.py
  2. 7
      asterisk_click2dial/scripts/set_name_incoming_timeout.sh
  3. 3
      asterisk_click2dial/scripts/set_name_outgoing_timeout.sh

34
asterisk_click2dial/scripts/set_name_agi.py

@ -1,6 +1,7 @@
#! /usr/bin/python
# -*- coding: utf-8 -*-
# © 2010-2018 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
# Copyright 2010-2018 Akretion France
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
@ -98,8 +99,8 @@ from optparse import OptionParser
from asterisk import agi as agilib # pip install pyst2
__author__ = "Alexis de Lattre <alexis.delattre@akretion.com>"
__date__ = "February 2018"
__version__ = "0.6"
__date__ = "November 2018"
__version__ = "0.7"
# Name that will be displayed if there is no match
# and no geolocalisation. Set it to False if you don't want
@ -113,8 +114,9 @@ options = [
'help': 'DNS or IP address of the Odoo server. Default = none '
'(will not try to connect to Odoo)'},
{'names': ('-p', '--port'), 'dest': 'port', 'type': 'int',
'action': 'store', 'default': 8069,
'help': "Port of Odoo's XML-RPC interface. Default = 8069"},
'action': 'store', 'default': False,
'help': "Port of Odoo's webservice interface. Default = 443 when SSL is on, "
"8069 when SSL is off"},
{'names': ('-e', '--ssl'), 'dest': 'ssl',
'help': "Use SSL connections instead of clear connections. "
"Default = no, use clear XML-RPC or JSON-RPC",
@ -229,9 +231,11 @@ def main(options, arguments):
# If we already have a "True" caller ID name
# i.e. not just digits, but a real name, then we don't try to
# connect to Odoo or geoloc, we just keep it
phone_chars = [str(d) for d in range(10)]
phone_chars += ['+']
if (
agi.env.get('agi_calleridname') and
not agi.env['agi_calleridname'].isdigit() and
any([x not in phone_chars for x in agi.env['agi_calleridname']]) and
agi.env['agi_calleridname'].lower()
not in ['asterisk', 'unknown', 'anonymous'] and
not options.notify):
@ -265,6 +269,15 @@ def main(options, arguments):
else:
method = 'get_name_from_phone_number'
if options.port:
port = options.port
# default port depends on protocol
else:
if options.ssl:
port = 443
else:
port = 8069
res = False
# Yes, this script can be used without "-s odoo_server" !
if options.server and options.jsonrpc:
@ -272,10 +285,10 @@ def main(options, arguments):
proto = options.ssl and 'jsonrpc+ssl' or 'jsonrpc'
agi.verbose(
"Starting %s request on Odoo %s:%d database %s username %s" % (
proto.upper(), options.server, options.port, options.database,
proto.upper(), options.server, port, options.database,
options.username))
try:
odoo = odoorpc.ODOO(options.server, proto, options.port)
odoo = odoorpc.ODOO(options.server, proto, port)
odoo.login(options.database, options.username, options.password)
if options.notify:
res = odoo.execute(
@ -290,11 +303,10 @@ def main(options, arguments):
agi.verbose(
"Starting %s XML-RPC request on Odoo %s:%d "
"database %s user ID %d" % (
proto, options.server, options.port, options.database,
proto, options.server, port, options.database,
options.userid))
sock = xmlrpclib.ServerProxy(
'%s://%s:%d/xmlrpc/object'
% (proto, options.server, options.port))
'%s://%s:%d/xmlrpc/object' % (proto, options.server, port))
try:
if options.notify:
res = sock.execute(

7
asterisk_click2dial/scripts/set_name_incoming_timeout.sh

@ -11,7 +11,6 @@
# incoming or outgoing phone call... and if the script get stucks, the
# phone call will also get stucks !
# For Debian Lenny and Ubuntu Lucid, you need to install the package "timeout"
# For Ubuntu >= Maverick and Debian >= Squeeze, the "timeout" command is shipped
# in the "coreutils" package
@ -23,10 +22,6 @@
# is extremely high, about 3 seconds ! I don't know if it's a bug
# or if it will stay like that.
# To test this script manually (i.e. outside of Asterisk), run :
# echo "agi_callerid:0141401242"|set_name_incoming_timeout.sh
# where 0141401242 is a phone number that could be presented by the calling party
PATH=/usr/local/sbin:/usr/local/bin:/var/lib/asterisk/agi-bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/share/asterisk/agi-bin:.
timeout 2s set_name_agi.py --server odoo.mycompany.com --database erp_prod --user-id 12 --password "thepasswd" --geoloc --geoloc-country "FR" --geoloc-lang "fr"
timeout 2s set_name_agi.py --jsonrpc --ssl --server odoo.mycompany.com --database erp_prod --username "asterisk" --password "thepasswd"

3
asterisk_click2dial/scripts/set_name_outgoing_timeout.sh

@ -11,7 +11,6 @@
# incoming or outgoing phone call... and if the script get stucks, the
# phone call will also get stucks !
# For Debian Lenny and Ubuntu Lucid, you need to install the package "timeout"
# For Ubuntu >= Maverick and Debian >= Squeeze, the "timeout" command is shipped
# in the "coreutils" package
@ -29,4 +28,4 @@
PATH=/usr/local/sbin:/usr/local/bin:/var/lib/asterisk/agi-bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/share/asterisk/agi-bin:.
timeout 2s set_name_agi.py --server odoo.mycompany.com --database erp_prod --user-id 12 --password "thepasswd" --outgoing --outgoing-agi-variable extension
timeout 2s set_name_agi.py --jsonrpc --ssl --server odoo.mycompany.com --database erp_prod --username "asterisk" --password "thepasswd" --outgoing --outgoing-agi-variable extension
Loading…
Cancel
Save