From 2367203ecea84c1b3f5803e7748db5de07c79bae Mon Sep 17 00:00:00 2001 From: stevenA Date: Fri, 28 Jan 2022 11:14:34 +0100 Subject: [PATCH] Resolve issue of softkeysets lost across installs --- Sccp_manager.class.php | 13 +++--------- install.php | 14 ++++--------- module.xml | 2 ++ sccpManTraits/ajaxHelper.php | 16 +++++++-------- sccpManTraits/helperFunctions.php | 34 ++++++++++++++++++++++--------- 5 files changed, 41 insertions(+), 38 deletions(-) diff --git a/Sccp_manager.class.php b/Sccp_manager.class.php index fd11586..96bdc28 100644 --- a/Sccp_manager.class.php +++ b/Sccp_manager.class.php @@ -714,16 +714,9 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO { 'tftp_countries_path' => $this->sccpvalues['tftp_countries_path']['data'] ); - $read_config = $this->cnf_read->getConfig('sccp.conf'); - $this->sccp_conf_init['general'] = $read_config['general']; - foreach ($read_config as $key => $value) { - if (isset($read_config[$key]['type'])) { // copy soft key - if ($read_config[$key]['type'] == 'softkeyset') { - $this->sccp_conf_init[$key] = $read_config[$key]; - } - } - } - /* + // initialise $sccp_conf_init + $this->sccp_conf_init = $this->initialiseConfInit(); + $hint = $this->aminterface->core_list_hints(); foreach ($hint as $key => $value) { if ($this->hint_context['default'] != $value) { diff --git a/install.php b/install.php index b07933f..eee43d3 100644 --- a/install.php +++ b/install.php @@ -1024,13 +1024,6 @@ function addDriver($sccp_compatible) { $file = $amp_conf['AMPWEBROOT'] . '/admin/modules/core/functions.inc/drivers/Sccp.class.php'; $contents = ""; file_put_contents($file, $contents); - - $dir = $cnf_int->get('ASTETCDIR'); - if (!file_exists("{$dir}/sccp.conf")) { // System re Config - outn("
  • " . _("Adding default configuration file ...") . "
  • "); - $sccpfile = file_get_contents($amp_conf['AMPWEBROOT'] . '/admin/modules/sccp_manager/conf/sccp.conf'); - file_put_contents("{$dir}/sccp.conf", $sccpfile); - } } function checkTftpServer() { outn("
  • " . _("Checking TFTP server path and availability ...") . "
  • "); @@ -1292,9 +1285,10 @@ function cleanUpSccpSettings() { )"; $results = $db->query($sql); } - - // Now correct sccp.conf to replace any illegal settings - $thisInstaller->createDefaultSccpConfig($settingsFromDb, $cnf_int->get('ASTETCDIR')); + // Need to load any existing sccp.conf so that retain softkeys section if exists. + $sccp_conf_init = $thisInstaller->initialiseConfInit(); + // Now correct sccp.conf to replace any illegal settings passing $sccp_conf_init + $thisInstaller->createDefaultSccpConfig($settingsFromDb, $cnf_int->get('ASTETCDIR'), $sccp_conf_init); // have to correct prior verion sccpline lists for allow/disallow and deny permit. Prior // versions used csl, but chan-sccp expects ; separated lists when returned by db. diff --git a/module.xml b/module.xml index 71f3ccc..a25b9db 100644 --- a/module.xml +++ b/module.xml @@ -42,7 +42,9 @@ * Version 14.4.0.3 * - Change method of selecting phonecodepage depending on if is java phone. * Version 14.4.0.5 * - Fix issue #59. * Version 14.5.0.1 * - Fix issue #32. + * Version 14.5.0.4 * - Fix issue where values with spaces are truncated. Preserve softkeys accross installs * Version 16.0.0.1 * - Improve compliance and use of BMO to optimise performance + https://github.com/chan-sccp/sccp_manager diff --git a/sccpManTraits/ajaxHelper.php b/sccpManTraits/ajaxHelper.php index ef91903..5c13fa7 100644 --- a/sccpManTraits/ajaxHelper.php +++ b/sccpManTraits/ajaxHelper.php @@ -231,11 +231,11 @@ trait ajaxHelper { case 'deleteSoftKey': if (!empty($request['softkey'])) { - //$id_name = $request['softkey']; - unset($this->sccp_conf_init[$request['softkey']]); - $this->createDefaultSccpConfig($this->sccpvalues, $this->sccppath["asterisk"]); - $msg = $this->aminterface->core_sccp_reload(); - return array('status' => true, 'reload' => true, 'message' => $msg['Response'] .' - Softkey set deleted'); + $id_name = $request['softkey']; + unset($this->sccp_conf_init[$id_name]); + $this->createDefaultSccpConfig($this->sccpvalues, $this->sccppath["asterisk"], $this->sccp_conf_init); + $msg = print_r($this->aminterface->core_sccp_reload(), 1); + return array('status' => true, 'table_reload' => true); } break; case 'updateSoftKey': @@ -247,7 +247,7 @@ trait ajaxHelper { $this->sccp_conf_init[$id_name][$keyl] = $request[$keyl]; } } - $this->createDefaultSccpConfig($this->sccpvalues, $this->sccppath["asterisk"]); + $this->createDefaultSccpConfig($this->sccpvalues, $this->sccppath["asterisk"], $this->sccp_conf_init); // !TODO!: -TODO-: Check SIP Support Enabled $this->createSccpXmlSoftkey(); @@ -403,7 +403,7 @@ trait ajaxHelper { $this->dbinterface->updateTableDefaults($rowToSave['table'], $rowToSave['field'], $rowToSave['Default']); } // rewrite sccp.conf - $this->createDefaultSccpConfig($this->sccpvalues, $this->sccppath["asterisk"]); + $this->createDefaultSccpConfig($this->sccpvalues, $this->sccppath["asterisk"], $this->sccp_conf_init); $this->createDefaultSccpXml(); // TODO: Need to be more specific on reload and only reload if critical settings changed. $res = $this->aminterface->core_sccp_reload(); @@ -607,7 +607,7 @@ trait ajaxHelper { $output[]= implode('/', $netValue); //} */ - + break; case 'setvar': $output[] = implode(';', $netValue); diff --git a/sccpManTraits/helperFunctions.php b/sccpManTraits/helperFunctions.php index 76d54ec..5beb1ba 100644 --- a/sccpManTraits/helperFunctions.php +++ b/sccpManTraits/helperFunctions.php @@ -268,6 +268,20 @@ trait helperfunctions { return false; } + public function initialiseConfInit(){ + $read_config = \FreePBX::LoadConfig()->getConfig('sccp.conf'); + $sccp_conf_init['general'] = $read_config['general']; + foreach ($read_config as $key => $value) { + if (isset($read_config[$key]['type'])) { // copy soft key + if ($read_config[$key]['type'] == 'softkeyset') { + $sccp_conf_init[$key] = $read_config[$key]; + } + } + } + return $sccp_conf_init; + } + + public function checkTftpMapping(){ exec('in.tftpd -V', $tftpInfo); $info['TFTP Server'] = array('Version' => 'Not Found', 'about' => 'Mapping not available'); @@ -336,18 +350,18 @@ trait helperfunctions { unset($sysConfig); } - public function createDefaultSccpConfig(array $sccpvalues, string $asteriskPath) { + public function createDefaultSccpConfig(array $sccpvalues, string $asteriskPath, $conf_init) { global $cnf_wr; // Make sccp.conf data // [general] section // TODO: Need to review sccpsettings seq numbering, as will speed this up, and remove the need for $permittedSettings. $cnf_wr = \FreePBX::WriteConfig(); //clear old general settings, and initiate with allow/disallow and permit/deny keys in correct order - $this->sccp_conf_init['general'] = array(); - $this->sccp_conf_init['general']['disallow'] = 'all'; - $this->sccp_conf_init['general']['allow'] = ''; - $this->sccp_conf_init['general']['deny'] = '0.0.0.0/0.0.0.0'; - $this->sccp_conf_init['general']['permit'] = '0.0.0.0/0.0.0.0'; + $conf_init['general'] = array(); + $conf_init['general']['disallow'] = 'all'; + $conf_init['general']['allow'] = ''; + $conf_init['general']['deny'] = '0.0.0.0/0.0.0.0'; + $conf_init['general']['permit'] = '0.0.0.0/0.0.0.0'; // permitted chan-sccp settings array $permittedSettings = array( 'debug', 'servername', 'keepalive', 'context', 'dateformat', 'bindaddr', 'port', 'secbindaddr', 'secport', 'disallow', 'allow', 'deny', 'permit', @@ -371,7 +385,7 @@ trait helperfunctions { case "deny": case "localnet": case "permit": - $this->sccp_conf_init['general'][$key] = explode(';', $value['data']); + $conf_init['general'][$key] = explode(';', $value['data']); break; case "devlang": /* @@ -388,7 +402,7 @@ trait helperfunctions { break; default: if (!empty($value['data'])) { - $this->sccp_conf_init['general'][$key] = $value['data']; + $conf_init['general'][$key] = $value['data']; } } } @@ -398,7 +412,7 @@ trait helperfunctions { // This will complicate solving problems caused by unexpected solutions from users. // if (file_exists($asteriskPath . "/sccp_custom.conf")) { - $this->sccp_conf_init['HEADER'] = array( + $conf_init['HEADER'] = array( "; ;", "; It is a very bad idea to add an external configuration file !!!! ;", "; This will complicate solving problems caused by unexpected solutions ;", @@ -407,7 +421,7 @@ trait helperfunctions { "#include sccp_custom.conf" ); } - $cnf_wr->WriteConfig('sccp.conf', $this->sccp_conf_init); + $cnf_wr->WriteConfig('sccp.conf', $conf_init); } public function initVarfromXml() {