Resolve issue of softkeysets lost across installs

This commit is contained in:
stevenA 2022-01-28 11:14:34 +01:00
parent b6485313fd
commit 2367203ece
5 changed files with 41 additions and 38 deletions

View file

@ -714,16 +714,9 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO {
'tftp_countries_path' => $this->sccpvalues['tftp_countries_path']['data'] 'tftp_countries_path' => $this->sccpvalues['tftp_countries_path']['data']
); );
$read_config = $this->cnf_read->getConfig('sccp.conf'); // initialise $sccp_conf_init
$this->sccp_conf_init['general'] = $read_config['general']; $this->sccp_conf_init = $this->initialiseConfInit();
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];
}
}
}
/*
$hint = $this->aminterface->core_list_hints(); $hint = $this->aminterface->core_list_hints();
foreach ($hint as $key => $value) { foreach ($hint as $key => $value) {
if ($this->hint_context['default'] != $value) { if ($this->hint_context['default'] != $value) {

View file

@ -1024,13 +1024,6 @@ function addDriver($sccp_compatible) {
$file = $amp_conf['AMPWEBROOT'] . '/admin/modules/core/functions.inc/drivers/Sccp.class.php'; $file = $amp_conf['AMPWEBROOT'] . '/admin/modules/core/functions.inc/drivers/Sccp.class.php';
$contents = "<?php include '/var/www/html/admin/modules/sccp_manager/sccpManClasses/Sccp.class.php.v{$sccp_compatible}'; ?>"; $contents = "<?php include '/var/www/html/admin/modules/sccp_manager/sccpManClasses/Sccp.class.php.v{$sccp_compatible}'; ?>";
file_put_contents($file, $contents); file_put_contents($file, $contents);
$dir = $cnf_int->get('ASTETCDIR');
if (!file_exists("{$dir}/sccp.conf")) { // System re Config
outn("<li>" . _("Adding default configuration file ...") . "</li>");
$sccpfile = file_get_contents($amp_conf['AMPWEBROOT'] . '/admin/modules/sccp_manager/conf/sccp.conf');
file_put_contents("{$dir}/sccp.conf", $sccpfile);
}
} }
function checkTftpServer() { function checkTftpServer() {
outn("<li>" . _("Checking TFTP server path and availability ...") . "</li>"); outn("<li>" . _("Checking TFTP server path and availability ...") . "</li>");
@ -1292,9 +1285,10 @@ function cleanUpSccpSettings() {
)"; )";
$results = $db->query($sql); $results = $db->query($sql);
} }
// Need to load any existing sccp.conf so that retain softkeys section if exists.
// Now correct sccp.conf to replace any illegal settings $sccp_conf_init = $thisInstaller->initialiseConfInit();
$thisInstaller->createDefaultSccpConfig($settingsFromDb, $cnf_int->get('ASTETCDIR')); // 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 // 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. // versions used csl, but chan-sccp expects ; separated lists when returned by db.

View file

@ -42,7 +42,9 @@
* Version 14.4.0.3 * - Change method of selecting phonecodepage depending on if is java phone. * 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.4.0.5 * - Fix issue #59.
* Version 14.5.0.1 * - Fix issue #32. * 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 * Version 16.0.0.1 * - Improve compliance and use of BMO to optimise performance
</changelog> </changelog>
<location>https://github.com/chan-sccp/sccp_manager</location> <location>https://github.com/chan-sccp/sccp_manager</location>
<depends> <depends>

View file

@ -231,11 +231,11 @@ trait ajaxHelper {
case 'deleteSoftKey': case 'deleteSoftKey':
if (!empty($request['softkey'])) { if (!empty($request['softkey'])) {
//$id_name = $request['softkey']; $id_name = $request['softkey'];
unset($this->sccp_conf_init[$request['softkey']]); unset($this->sccp_conf_init[$id_name]);
$this->createDefaultSccpConfig($this->sccpvalues, $this->sccppath["asterisk"]); $this->createDefaultSccpConfig($this->sccpvalues, $this->sccppath["asterisk"], $this->sccp_conf_init);
$msg = $this->aminterface->core_sccp_reload(); $msg = print_r($this->aminterface->core_sccp_reload(), 1);
return array('status' => true, 'reload' => true, 'message' => $msg['Response'] .' - Softkey set deleted'); return array('status' => true, 'table_reload' => true);
} }
break; break;
case 'updateSoftKey': case 'updateSoftKey':
@ -247,7 +247,7 @@ trait ajaxHelper {
$this->sccp_conf_init[$id_name][$keyl] = $request[$keyl]; $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 // !TODO!: -TODO-: Check SIP Support Enabled
$this->createSccpXmlSoftkey(); $this->createSccpXmlSoftkey();
@ -403,7 +403,7 @@ trait ajaxHelper {
$this->dbinterface->updateTableDefaults($rowToSave['table'], $rowToSave['field'], $rowToSave['Default']); $this->dbinterface->updateTableDefaults($rowToSave['table'], $rowToSave['field'], $rowToSave['Default']);
} }
// rewrite sccp.conf // rewrite sccp.conf
$this->createDefaultSccpConfig($this->sccpvalues, $this->sccppath["asterisk"]); $this->createDefaultSccpConfig($this->sccpvalues, $this->sccppath["asterisk"], $this->sccp_conf_init);
$this->createDefaultSccpXml(); $this->createDefaultSccpXml();
// TODO: Need to be more specific on reload and only reload if critical settings changed. // TODO: Need to be more specific on reload and only reload if critical settings changed.
$res = $this->aminterface->core_sccp_reload(); $res = $this->aminterface->core_sccp_reload();
@ -607,7 +607,7 @@ trait ajaxHelper {
$output[]= implode('/', $netValue); $output[]= implode('/', $netValue);
//} //}
*/ */
break; break;
case 'setvar': case 'setvar':
$output[] = implode(';', $netValue); $output[] = implode(';', $netValue);

View file

@ -268,6 +268,20 @@ trait helperfunctions {
return false; 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(){ public function checkTftpMapping(){
exec('in.tftpd -V', $tftpInfo); exec('in.tftpd -V', $tftpInfo);
$info['TFTP Server'] = array('Version' => 'Not Found', 'about' => 'Mapping not available'); $info['TFTP Server'] = array('Version' => 'Not Found', 'about' => 'Mapping not available');
@ -336,18 +350,18 @@ trait helperfunctions {
unset($sysConfig); unset($sysConfig);
} }
public function createDefaultSccpConfig(array $sccpvalues, string $asteriskPath) { public function createDefaultSccpConfig(array $sccpvalues, string $asteriskPath, $conf_init) {
global $cnf_wr; global $cnf_wr;
// Make sccp.conf data // Make sccp.conf data
// [general] section // [general] section
// TODO: Need to review sccpsettings seq numbering, as will speed this up, and remove the need for $permittedSettings. // TODO: Need to review sccpsettings seq numbering, as will speed this up, and remove the need for $permittedSettings.
$cnf_wr = \FreePBX::WriteConfig(); $cnf_wr = \FreePBX::WriteConfig();
//clear old general settings, and initiate with allow/disallow and permit/deny keys in correct order //clear old general settings, and initiate with allow/disallow and permit/deny keys in correct order
$this->sccp_conf_init['general'] = array(); $conf_init['general'] = array();
$this->sccp_conf_init['general']['disallow'] = 'all'; $conf_init['general']['disallow'] = 'all';
$this->sccp_conf_init['general']['allow'] = ''; $conf_init['general']['allow'] = '';
$this->sccp_conf_init['general']['deny'] = '0.0.0.0/0.0.0.0'; $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']['permit'] = '0.0.0.0/0.0.0.0';
// permitted chan-sccp settings array // permitted chan-sccp settings array
$permittedSettings = array( $permittedSettings = array(
'debug', 'servername', 'keepalive', 'context', 'dateformat', 'bindaddr', 'port', 'secbindaddr', 'secport', 'disallow', 'allow', 'deny', 'permit', 'debug', 'servername', 'keepalive', 'context', 'dateformat', 'bindaddr', 'port', 'secbindaddr', 'secport', 'disallow', 'allow', 'deny', 'permit',
@ -371,7 +385,7 @@ trait helperfunctions {
case "deny": case "deny":
case "localnet": case "localnet":
case "permit": case "permit":
$this->sccp_conf_init['general'][$key] = explode(';', $value['data']); $conf_init['general'][$key] = explode(';', $value['data']);
break; break;
case "devlang": case "devlang":
/* /*
@ -388,7 +402,7 @@ trait helperfunctions {
break; break;
default: default:
if (!empty($value['data'])) { 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. // This will complicate solving problems caused by unexpected solutions from users.
// //
if (file_exists($asteriskPath . "/sccp_custom.conf")) { 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 !!!! ;", "; It is a very bad idea to add an external configuration file !!!! ;",
"; This will complicate solving problems caused by unexpected solutions ;", "; This will complicate solving problems caused by unexpected solutions ;",
@ -407,7 +421,7 @@ trait helperfunctions {
"#include sccp_custom.conf" "#include sccp_custom.conf"
); );
} }
$cnf_wr->WriteConfig('sccp.conf', $this->sccp_conf_init); $cnf_wr->WriteConfig('sccp.conf', $conf_init);
} }
public function initVarfromXml() { public function initVarfromXml() {