From 2b3f941a2e1c17c1b6681bc4e979f8ad2dbe4ab3 Mon Sep 17 00:00:00 2001 From: Matteo Valentini Date: Tue, 13 Feb 2024 09:44:30 +0100 Subject: [PATCH] Get subscription credentials from the cluster The credentials are used to authenticate on the phones' remote provisioning server. --- imageroot/actions/configure-module/20setenvs | 2 -- .../actions/configure-module/21subscription | 20 +++++++++++++++++++ .../subscription-changed/10subscription | 1 + .../subscription-changed/80sevice_restart | 10 ++++++++++ 4 files changed, 31 insertions(+), 2 deletions(-) create mode 100755 imageroot/actions/configure-module/21subscription create mode 120000 imageroot/events/subscription-changed/10subscription create mode 100755 imageroot/events/subscription-changed/80sevice_restart diff --git a/imageroot/actions/configure-module/20setenvs b/imageroot/actions/configure-module/20setenvs index 4eecf7a8d..ee1ea3642 100755 --- a/imageroot/actions/configure-module/20setenvs +++ b/imageroot/actions/configure-module/20setenvs @@ -21,8 +21,6 @@ def getFromRequest(request, var_name, env_name, default = ""): # NETHVOICE_HOST_LOCAL_NETWORKS should be a jason containing local networks [{"network":"192.168.5.0","netmask":"255.255.255.0","gateway":"192.168.5.1"}] getFromRequest(request, 'nethvoice_host_local_networks', 'NETHVOICE_HOST_LOCAL_NETWORKS', '{[]}') getFromRequest(request, 'nethvoice_host', 'NETHVOICE_HOST', '') -getFromRequest(request, 'subscription_systemid', 'SUBSCRIPTION_SYSTEMID', '') -getFromRequest(request, 'subscription_secret', 'SUBSCRIPTION_SECRET', '') getFromRequest(request, 'nethcti_prefix', 'NETHCTI_PREFIX', '') getFromRequest(request, 'nethcti_autoc2c', 'NETHCTI_AUTOC2C', 'enabled') getFromRequest(request, 'nethcti_trunks_events', 'NETHCTI_TRUNKS_EVENTS', 'enabled') diff --git a/imageroot/actions/configure-module/21subscription b/imageroot/actions/configure-module/21subscription new file mode 100755 index 000000000..754af9418 --- /dev/null +++ b/imageroot/actions/configure-module/21subscription @@ -0,0 +1,20 @@ +#!/bin/python + +# +# Copyright (C) 2024 Nethesis S.r.l. +# SPDX-License-Identifier: GPL-3.0-or-later +# + +import agent + + +rdb = agent.redis_connect(privileged=False) + +subscription = rdb.hgetall('cluster/subscription') + +#check if the subscription hash table exists +if subscription: + #get the subscription secret + agent.set_env("SUBSCRIPTION_SECRET", subscription['auth_token']) + #get subscription ID + agent.set_env("SUBSCRIPTION_SYSTEMID", subscription['system_id']) diff --git a/imageroot/events/subscription-changed/10subscription b/imageroot/events/subscription-changed/10subscription new file mode 120000 index 000000000..5cdac1c17 --- /dev/null +++ b/imageroot/events/subscription-changed/10subscription @@ -0,0 +1 @@ +../../actions/configure-module/21subscription \ No newline at end of file diff --git a/imageroot/events/subscription-changed/80sevice_restart b/imageroot/events/subscription-changed/80sevice_restart new file mode 100755 index 000000000..eefae1240 --- /dev/null +++ b/imageroot/events/subscription-changed/80sevice_restart @@ -0,0 +1,10 @@ +#!/bin/bash + +# +# Copyright (C) 2023 Nethesis S.r.l. +# SPDX-License-Identifier: GPL-3.0-or-later +# + +# If the control reaches this step, the service can be enabled and started + +systemctl --user restart freepbx.service flexisip.service