From 029700aae2cadefc5c264d98b8d07f66dd4f4f6b Mon Sep 17 00:00:00 2001 From: Etienne Allovon Date: Mon, 19 Apr 2021 16:10:25 +0200 Subject: [PATCH 1/7] 3990 - make change pass vm script to work on MDS --- asterisk-bin/change-pass-vm | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/asterisk-bin/change-pass-vm b/asterisk-bin/change-pass-vm index 5a838c2..2d0bd35 100755 --- a/asterisk-bin/change-pass-vm +++ b/asterisk-bin/change-pass-vm @@ -20,20 +20,43 @@ import sys from xivo_confd_client import Client -DEFAULT_CONFD_CONFIG = {'host': 'localhost', - 'port': 9487, - 'https': 'False'} +XIVO_CONFD_CONFIG = {'host': 'localhost', + 'port': 9487, + 'https': 'False', + 'verify_certificate': 'False'} + +MDS_CONFD_CONFIG = {'host': 'xivo', + 'port': 9486, + 'https': 'True', + 'verify_certificate': 'False'} + +def get_xivo_voip_host_from_custom_env(file_path): + with open(file_path, 'r') as filehandle: + for line in filehandle: + if line.startswith('XIVO_VOIP_HOST'): + split_line = line.split("=") + if len(split_line) > 0: + return split_line[1].rstrip("\n") + return None def get_confd_client_config(): + if os.path.exists('/var/lib/xivo/mds_enabled'): + DEFAULT_CONFD_CONFIG = MDS_CONFD_CONFIG + DEFAULT_CONFD_CONFIG['host'] = get_xivo_voip_host_from_custom_env('/etc/docker/mds/custom.env') + else + DEFAULT_CONFD_CONFIG = XIVO_CONFD_CONFIG + host = os.environ.get('CONFD_HOST', DEFAULT_CONFD_CONFIG['host']) port = int(os.environ.get('CONFD_PORT', DEFAULT_CONFD_CONFIG['port'])) https = os.environ.get('CONFD_HTTPS', DEFAULT_CONFD_CONFIG['https']).lower() == 'true' username = os.environ.get('CONFD_USERNAME') passwd = os.environ.get('CONFD_PASSWORD') + verify_cert = os.environ.get('CONFD_VERIFY_CERT', DEFAULT_CONFD_CONFIG['verify_certificate']).lower() == 'true' config = {'host': host, 'port': port, - 'https': https} + 'https': https, + 'verify_certificate': verify_cert} if username: config['username'] = username if passwd: -- GitLab From 1bf95c8724bcbac92b4744822565decf58e20d6a Mon Sep 17 00:00:00 2001 From: Etienne Allovon Date: Mon, 19 Apr 2021 16:11:11 +0200 Subject: [PATCH 2/7] 3990 - bump changelog --- debian/changelog | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/debian/changelog b/debian/changelog index 668d1a1..de4e933 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +xivo-utils (2020.18.11) xivo-freya; urgency=medium + + * 3990 - update change pass vm to work on MDS + + -- Etienne Allovon Mon, 19 Apr 2021 14:10:34 +0000 + xivo-utils (2017.05.00) xivo-dev; urgency=medium * Prefix dialplan variable with XIVO_ -- GitLab From bdc5cc1cfbb2f857a30853c783418aa4d8efc784 Mon Sep 17 00:00:00 2001 From: Etienne Allovon Date: Mon, 19 Apr 2021 16:31:14 +0200 Subject: [PATCH 3/7] 3990 - fix syntax error --- asterisk-bin/change-pass-vm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/asterisk-bin/change-pass-vm b/asterisk-bin/change-pass-vm index 2d0bd35..4cde6e2 100755 --- a/asterisk-bin/change-pass-vm +++ b/asterisk-bin/change-pass-vm @@ -43,7 +43,7 @@ def get_confd_client_config(): if os.path.exists('/var/lib/xivo/mds_enabled'): DEFAULT_CONFD_CONFIG = MDS_CONFD_CONFIG DEFAULT_CONFD_CONFIG['host'] = get_xivo_voip_host_from_custom_env('/etc/docker/mds/custom.env') - else + else: DEFAULT_CONFD_CONFIG = XIVO_CONFD_CONFIG host = os.environ.get('CONFD_HOST', DEFAULT_CONFD_CONFIG['host']) -- GitLab From 1b66ee696144b9f35ad59650e345ef614af01929 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vo=C5=99=C3=AD=C5=A1ek=20V=C3=A1clav?= Date: Wed, 21 Apr 2021 14:02:50 +0200 Subject: [PATCH 4/7] Acquiring information from local sources. --- asterisk-bin/change-pass-vm | 85 +++++++++++++++++++++---------------- 1 file changed, 49 insertions(+), 36 deletions(-) diff --git a/asterisk-bin/change-pass-vm b/asterisk-bin/change-pass-vm index 4cde6e2..7b0acf1 100755 --- a/asterisk-bin/change-pass-vm +++ b/asterisk-bin/change-pass-vm @@ -19,51 +19,64 @@ import os import sys from xivo_confd_client import Client +from xivo_dao import accesswebservice_dao +from xivo_dao import asterisk_conf_dao + +XIVO_CONFD_CONFIG = { + 'host': 'localhost', + 'port': 9487, + 'https': 'False', + 'verify_certificate': 'False' +} + +MDS_CONFD_CONFIG = { + 'host': 'xivo', + 'port': 9486, + 'https': 'True', + 'verify_certificate': 'False', + 'username': 'mdsws' +} + + +def mds_get_confd_password(user_name): + return accesswebservice_dao.get_password(user_name) + + +def mdf_get_confd_host(): + mediaservers = asterisk_conf_dao.find_all_mediaservers() + for mds in mediaservers: + if mds.name == 'default': + return mds.voip_ip -XIVO_CONFD_CONFIG = {'host': 'localhost', - 'port': 9487, - 'https': 'False', - 'verify_certificate': 'False'} - -MDS_CONFD_CONFIG = {'host': 'xivo', - 'port': 9486, - 'https': 'True', - 'verify_certificate': 'False'} - -def get_xivo_voip_host_from_custom_env(file_path): - with open(file_path, 'r') as filehandle: - for line in filehandle: - if line.startswith('XIVO_VOIP_HOST'): - split_line = line.split("=") - if len(split_line) > 0: - return split_line[1].rstrip("\n") - return None def get_confd_client_config(): - if os.path.exists('/var/lib/xivo/mds_enabled'): - DEFAULT_CONFD_CONFIG = MDS_CONFD_CONFIG - DEFAULT_CONFD_CONFIG['host'] = get_xivo_voip_host_from_custom_env('/etc/docker/mds/custom.env') + + is_mds = os.path.exists('/var/lib/xivo/mds_enabled') + + if is_mds: + default_confd_config = MDS_CONFD_CONFIG + default_confd_config['host'] = mdf_get_confd_host() else: - DEFAULT_CONFD_CONFIG = XIVO_CONFD_CONFIG - - host = os.environ.get('CONFD_HOST', DEFAULT_CONFD_CONFIG['host']) - port = int(os.environ.get('CONFD_PORT', DEFAULT_CONFD_CONFIG['port'])) - https = os.environ.get('CONFD_HTTPS', DEFAULT_CONFD_CONFIG['https']).lower() == 'true' - username = os.environ.get('CONFD_USERNAME') - passwd = os.environ.get('CONFD_PASSWORD') - verify_cert = os.environ.get('CONFD_VERIFY_CERT', DEFAULT_CONFD_CONFIG['verify_certificate']).lower() == 'true' - - config = {'host': host, - 'port': port, - 'https': https, - 'verify_certificate': verify_cert} + default_confd_config = XIVO_CONFD_CONFIG + + config = { + 'host': os.environ.get('CONFD_HOST', default_confd_config['host']), + 'port': int(os.environ.get('CONFD_PORT', default_confd_config['port'])), + 'https': os.environ.get('CONFD_HTTPS', default_confd_config['https']).lower() == 'true', + 'verify_certificate': os.environ.get( + 'CONFD_VERIFY_CERT', default_confd_config['verify_certificate']).lower() == 'true' + } + + username = os.environ.get('CONFD_USERNAME', default_confd_config.get('username')) if username: config['username'] = username - if passwd: - config['password'] = passwd + passwd = os.environ.get('CONFD_PASSWORD', mds_get_confd_password(username) if is_mds else None) + if passwd: + config['password'] = passwd return config + def get_voicemail(client, number, context): response = client.voicemails.list(search=number) -- GitLab From 5f6f414bd0e2fdb8d82259e221ff5874efadef34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vo=C5=99=C3=AD=C5=A1ek=20V=C3=A1clav?= Date: Wed, 21 Apr 2021 14:37:05 +0200 Subject: [PATCH 5/7] DB init added. --- asterisk-bin/change-pass-vm | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/asterisk-bin/change-pass-vm b/asterisk-bin/change-pass-vm index 7b0acf1..2d75225 100755 --- a/asterisk-bin/change-pass-vm +++ b/asterisk-bin/change-pass-vm @@ -21,6 +21,7 @@ import sys from xivo_confd_client import Client from xivo_dao import accesswebservice_dao from xivo_dao import asterisk_conf_dao +import xivo_dao XIVO_CONFD_CONFIG = { 'host': 'localhost', @@ -42,7 +43,8 @@ def mds_get_confd_password(user_name): return accesswebservice_dao.get_password(user_name) -def mdf_get_confd_host(): +def mds_get_confd_host(): + xivo_dao.init_db_from_config() mediaservers = asterisk_conf_dao.find_all_mediaservers() for mds in mediaservers: if mds.name == 'default': @@ -55,7 +57,7 @@ def get_confd_client_config(): if is_mds: default_confd_config = MDS_CONFD_CONFIG - default_confd_config['host'] = mdf_get_confd_host() + default_confd_config['host'] = mds_get_confd_host() else: default_confd_config = XIVO_CONFD_CONFIG -- GitLab From db9d701572f886455dd27e81c84d18281d97d1e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vo=C5=99=C3=AD=C5=A1ek=20V=C3=A1clav?= Date: Thu, 22 Apr 2021 15:31:34 +0200 Subject: [PATCH 6/7] Gaia version. --- debian/changelog | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debian/changelog b/debian/changelog index de4e933..09ae1f9 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,4 +1,4 @@ -xivo-utils (2020.18.11) xivo-freya; urgency=medium +xivo-utils (2021.07.01) xivo-gaia; urgency=medium * 3990 - update change pass vm to work on MDS -- GitLab From 1b3069637c6b5a9a6e50ef63787993d583e93860 Mon Sep 17 00:00:00 2001 From: Laurent Meiller Date: Wed, 28 Apr 2021 13:21:12 +0200 Subject: [PATCH 7/7] 3990 Add xivo-auth-token to access confd from mds --- asterisk-bin/change-pass-vm | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/asterisk-bin/change-pass-vm b/asterisk-bin/change-pass-vm index 2d75225..94a6204 100755 --- a/asterisk-bin/change-pass-vm +++ b/asterisk-bin/change-pass-vm @@ -18,11 +18,14 @@ import os import sys -from xivo_confd_client import Client +from xivo_auth_client import Client as Auth +from xivo_confd_client import Client as Confd from xivo_dao import accesswebservice_dao from xivo_dao import asterisk_conf_dao import xivo_dao +XIVO_AUTH_TOKEN_TIMEOUT = 10 + XIVO_CONFD_CONFIG = { 'host': 'localhost', 'port': 9487, @@ -76,6 +79,11 @@ def get_confd_client_config(): if passwd: config['password'] = passwd + if is_mds: + auth = Auth(config['host'], username=config['username'], password=config['password'], verify_certificate=config['verify_certificate']) + token_data = auth.token.new('xivo_service', expiration=XIVO_AUTH_TOKEN_TIMEOUT) + config['token'] = token_data['token'] + return config @@ -104,7 +112,7 @@ if __name__ == "__main__": new_password = sys.argv[3] confd_client_config = get_confd_client_config() - client = Client(**confd_client_config) + client = Confd(**confd_client_config) voicemail = get_voicemail(client, number, context) update_password(client, voicemail, new_password) -- GitLab