Fix writing settings to sccp.conf

Only write chan-sccp allowed settings to sccp.conf
Clean sccp.conf on install
Move createDefaultSccpConfig to traits so that can access from installer
tighten calls to createDefaultSccpConfig
This commit is contained in:
stevenA 2021-12-30 09:39:28 +01:00
parent 03206f8384
commit f4aa2eda1c
7 changed files with 93 additions and 76 deletions

View file

@ -1002,67 +1002,6 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO {
return $filename; return $filename;
} }
function createDefaultSccpConfig() {
// Make sccp.conf data
// [general]
foreach ($this->sccpvalues as $key => $value) {
if ($value['seq'] == 0) {
switch ($key) {
case "allow":
case "disallow":
case "deny":
$this->sccp_conf_init['general'][$key] = explode(';', $value['data']);
break;
case "localnet":
case "permit":
$content = $value['data'];
if (strpos($content, 'internal') !== false) {
$content = str_replace(';0.0.0.0/0.0.0.0', '', $value['data']);
}
$this->sccp_conf_init['general'][$key] = explode(';', $content);
break;
case "devlang":
/*
$lang_data = $this->extconfigs->getExtConfig('sccp_lang', $value['data']);
if (!empty($lang_data)) {
// TODO: will always get here, but lang_data['codepage'] will be empty as not a valid key
$this->sccp_conf_init['general']['phonecodepage'] = $lang_data['codepage'];
}
break;
*/
case "netlang": // Remove Key
case "tftp_path":
case "sccp_compatible": // This is equal to SccpDBmodel
break;
default:
if (!empty($value['data'])) {
$this->sccp_conf_init['general'][$key] = $value['data'];
}
}
}
}
// [Namesoftkeyset]
// type=softkeyset
//
// ----- It is a very bad idea to add an external configuration file "sccp_custom.conf" !!!!
// This will add problems when solving problems caused by unexpected solutions from users.
//
if (file_exists($this->sccppath["asterisk"] . "/sccp_custom.conf")) {
$this->sccp_conf_init['HEADER'] = array(
"; ;",
"; It is a very bad idea to add an external configuration file !!!! ;",
"; This will add problems when solving problems caused by unexpected solutions ;",
"; from users. ;",
";--------------------------------------------------------------------------------;",
"#include sccp_custom.conf"
);
}
// ----- It is a very bad idea to add an external configuration file "sccp_custom.conf" !!!!
// TODO: Should only rewrite the general section - if users have extensions, this may overwrite
// Should read first and then rewrite all existing sections.
$this->cnf_wr->writeConfig('sccp.conf', $this->sccp_conf_init);
}
function getSccpModelInformation($get = "all", $validate = false, $format_list = "all", $filter = array()) { function getSccpModelInformation($get = "all", $validate = false, $format_list = "all", $filter = array()) {
$file_ext = array('.loads', '.sbn', '.bin', '.zup', '.sbin', '.SBN', '.LOADS'); $file_ext = array('.loads', '.sbn', '.bin', '.zup', '.sbin', '.SBN', '.LOADS');
$dir = $this->sccppath['tftp_firmware_path']; $dir = $this->sccppath['tftp_firmware_path'];

View file

@ -41,10 +41,3 @@ hotline_context=default
hotline_extension=111 hotline_extension=111
devicetable=sccpdevice devicetable=sccpdevice
linetable=sccpline linetable=sccpline
[KeySet1] ; Managed by sccp_manager
type=softkeyset
onhook=redial,newcall,cfwdall,dnd,pickup,gpickup,private
connected=hold,endcall,park,select,cfwdall,cfwdbusy
onhold=newcall

View file

@ -15,6 +15,8 @@ global $settingsFromDb;
global $thisInstaller; global $thisInstaller;
global $cnf_int; global $cnf_int;
global $sccp_compatible; global $sccp_compatible;
global $cnf_wr;
$mobile_hw = '0'; $mobile_hw = '0';
$autoincrement = (($amp_conf["AMPDBENGINE"] == "sqlite") || ($amp_conf["AMPDBENGINE"] == "sqlite3")) ? "AUTOINCREMENT" : "AUTO_INCREMENT"; $autoincrement = (($amp_conf["AMPDBENGINE"] == "sqlite") || ($amp_conf["AMPDBENGINE"] == "sqlite3")) ? "AUTOINCREMENT" : "AUTO_INCREMENT";
$table_req = array('sccpdevice', 'sccpline', 'sccpsettings'); $table_req = array('sccpdevice', 'sccpline', 'sccpsettings');
@ -1065,6 +1067,7 @@ function cleanUpSccpSettings() {
global $aminterface; global $aminterface;
global $sccp_compatible; global $sccp_compatible;
global $amp_conf; global $amp_conf;
global $cnf_int;
// Get current default settings from db // Get current default settings from db
$stmt = $db->prepare("SELECT keyword, sccpsettings.* FROM sccpsettings"); $stmt = $db->prepare("SELECT keyword, sccpsettings.* FROM sccpsettings");
@ -1148,7 +1151,6 @@ function cleanUpSccpSettings() {
unset($settingsFromDb[$key]); unset($settingsFromDb[$key]);
} }
} else { } else {
dbug($sysConfiguration);
$sysConfiguration[$key]['DefaultValue'] = ($sysConfiguration[$key]['DefaultValue'] == '(null)') ? '' : $sysConfiguration[$key]['DefaultValue']; $sysConfiguration[$key]['DefaultValue'] = ($sysConfiguration[$key]['DefaultValue'] == '(null)') ? '' : $sysConfiguration[$key]['DefaultValue'];
if (array_key_exists($key,$settingsFromDb)) { if (array_key_exists($key,$settingsFromDb)) {
// Preserve sequence and type // Preserve sequence and type
@ -1157,7 +1159,6 @@ function cleanUpSccpSettings() {
$settingsFromDb[$key] = array('keyword' => $key, 'seq' => 0, 'type' => 0, 'data' => '', 'systemdefault' => $sysConfiguration[$key]['DefaultValue']); $settingsFromDb[$key] = array('keyword' => $key, 'seq' => 0, 'type' => 0, 'data' => '', 'systemdefault' => $sysConfiguration[$key]['DefaultValue']);
} }
} }
dbug($settingsFromDb);
// Override certain chan-sccp defaults as they are based on a non-FreePbx system // Override certain chan-sccp defaults as they are based on a non-FreePbx system
$settingsFromDb['context']['systemdefault'] = 'from-internal'; $settingsFromDb['context']['systemdefault'] = 'from-internal';
$settingsFromDb['directed_pickup']['systemdefault'] = 'no'; $settingsFromDb['directed_pickup']['systemdefault'] = 'no';
@ -1222,6 +1223,10 @@ function cleanUpSccpSettings() {
)"; )";
$results = $db->query($sql); $results = $db->query($sql);
} }
// Now correct sccp.conf to replace any illegal settings
$thisInstaller->createDefaultSccpConfig($settingsFromDb, $cnf_int->get('ASTETCDIR'));
// 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

@ -1,7 +1,7 @@
<module> <module>
<rawname>sccp_manager</rawname> <rawname>sccp_manager</rawname>
<name>SCCP Manager</name> <name>SCCP Manager</name>
<version>14.3.0.19</version> <version>14.3.0.20</version>
<type>setup</type> <type>setup</type>
<category>SCCP Connectivity</category> <category>SCCP Connectivity</category>
<publisher>Steve Lad, Alex GP</publisher> <publisher>Steve Lad, Alex GP</publisher>

View file

@ -218,7 +218,6 @@ class Sccp extends \FreePBX\modules\Core\Driver {
public function getDefaultDeviceSettings($id, $displayname, &$flag) { public function getDefaultDeviceSettings($id, $displayname, &$flag) {
// FreePBX required method // FreePBX required method
$settings = array(); $settings = array();
dbug($this->line_defaults);
$settingsFields = array('mailbox', 'incominglimit', 'context', 'directed_pickup_context', 'callgroup', 'pickupgroup', 'namedcallgroup', $settingsFields = array('mailbox', 'incominglimit', 'context', 'directed_pickup_context', 'callgroup', 'pickupgroup', 'namedcallgroup',
'namedpickupgroup', 'adhocNumber', 'secondary_dialtone_digits', 'secondary_dialtone_tone', 'directed_pickup', 'pickup_modeanswer', 'namedpickupgroup', 'adhocNumber', 'secondary_dialtone_digits', 'secondary_dialtone_tone', 'directed_pickup', 'pickup_modeanswer',
'transfer', 'echocancel', 'dnd', 'silencesuppression', 'musicclass', 'pin', 'allow', 'disallow'); 'transfer', 'echocancel', 'dnd', 'silencesuppression', 'musicclass', 'pin', 'allow', 'disallow');

View file

@ -247,7 +247,7 @@ trait ajaxHelper {
if (!empty($request['softkey'])) { if (!empty($request['softkey'])) {
$id_name = $request['softkey']; $id_name = $request['softkey'];
unset($this->sccp_conf_init[$id_name]); unset($this->sccp_conf_init[$id_name]);
$this->createDefaultSccpConfig(); $this->createDefaultSccpConfig($this->sccpvalues, $this->sccppath["asterisk"]);
$msg = print_r($this->aminterface->core_sccp_reload(), 1); $msg = print_r($this->aminterface->core_sccp_reload(), 1);
return array('status' => true, 'table_reload' => true); return array('status' => true, 'table_reload' => true);
} }
@ -261,7 +261,7 @@ trait ajaxHelper {
$this->sccp_conf_init[$id_name][$keyl] = $request[$keyl]; $this->sccp_conf_init[$id_name][$keyl] = $request[$keyl];
} }
} }
$this->createDefaultSccpConfig(); $this->createDefaultSccpConfig($this->sccpvalues, $this->sccppath["asterisk"]);
// !TODO!: -TODO-: Check SIP Support Enabled // !TODO!: -TODO-: Check SIP Support Enabled
$this->createSccpXmlSoftkey(); $this->createSccpXmlSoftkey();
@ -516,8 +516,8 @@ trait ajaxHelper {
foreach ($dbSaveArray as $key => $rowToSave) { foreach ($dbSaveArray as $key => $rowToSave) {
$this->dbinterface->updateTableDefaults($rowToSave['table'], $rowToSave['field'], $rowToSave['Default']); $this->dbinterface->updateTableDefaults($rowToSave['table'], $rowToSave['field'], $rowToSave['Default']);
} }
// rewrite sccp.conf
$this->createDefaultSccpConfig(); // Rewrite Config. $this->createDefaultSccpConfig($this->sccpvalues, $this->sccppath["asterisk"]);
$save_settings[] = array('status' => true, ); $save_settings[] = array('status' => true, );
$this->createDefaultSccpXml(); $this->createDefaultSccpXml();

View file

@ -274,6 +274,87 @@ trait helperfunctions {
unset($sysConfig); unset($sysConfig);
} }
public function createDefaultSccpConfig(array $sccpvalues, string $asteriskPath) {
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 settings, and initiate with allow/disallow and permit/deny keys in correct order
$this->sccp_conf_init = 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';
// permitted chan-sccp settings array
$permittedSettings = array(
'debug', 'servername', 'keepalive', 'context', 'dateformat', 'bindaddr', 'port', 'secbindaddr', 'secport', 'disallow', 'allow', 'deny', 'permit',
'localnet', 'externip', 'externrefresh', 'firstdigittimeout', 'digittimeout', 'digittimeoutchar', 'recorddigittimeoutchar', 'simulate_enbloc',
'ringtype', 'autoanswer_ring_time', 'autoanswer_tone', 'remotehangup_tone', 'transfer', 'transfer_tone', 'transfer_on_hangup', 'dnd_tone',
'callwaiting_tone', 'callwaiting_interval', 'musicclass', 'language', 'callevents', 'accountcode', 'sccp_tos', 'sccp_cos', 'audio_tos',
'audio_cos', 'video_tos', 'video_cos', 'echocancel', 'silencesuppression', 'earlyrtp', 'dndFeature', 'private', 'mwilamp', 'mwioncall',
'cfwdall', 'cfwdbusy', 'cfwdnoanswer', 'cfwdnoanswer_timeout', 'nat', 'directrtp', 'allowoverlap', 'pickup_modeanswer',
'callhistory_answered_elsewhere', 'amaflags', 'callanswerorder', 'devicetable', 'linetable', 'meetmeopts', 'jbenable', 'jbforce',
'jblog', 'jbmaxsize', 'jbresyncthreshold', 'jbimpl', 'hotline_enabled', 'hotline_extension', 'hotline_context', 'hotline_label', 'fallback',
'backoff_time', 'server_priority');
foreach ($sccpvalues as $key => $value) {
if (!in_array($key, $permittedSettings, true)) {
continue;
}
if ($value['seq'] == 0) {
switch ($key) {
case "allow":
case "disallow":
case "deny":
$this->sccp_conf_init['general'][$key] = explode(';', $value['data']);
break;
case "localnet":
case "permit":
$content = $value['data'];
if (strpos($content, 'internal') !== false) {
$content = str_replace(';0.0.0.0/0.0.0.0', '', $value['data']);
}
$this->sccp_conf_init['general'][$key] = explode(';', $content);
break;
case "devlang":
/*
$lang_data = $this->extconfigs->getExtConfig('sccp_lang', $value['data']);
if (!empty($lang_data)) {
// TODO: will always get here, but lang_data['codepage'] will be empty as not a valid key
$this->sccp_conf_init['general']['phonecodepage'] = $lang_data['codepage'];
}
break;
*/
case "netlang": // Remove Key
case "tftp_path":
case "sccp_compatible": // This is equal to SccpDBmodel
break;
default:
if (!empty($value['data'])) {
$this->sccp_conf_init['general'][$key] = $value['data'];
}
}
}
}
//
// ----- It is a very bad idea to add an external configuration file "sccp_custom.conf" !!!!
// This will complicate solving problems caused by unexpected solutions from users.
//
if (file_exists($asteriskPath . "/sccp_custom.conf")) {
$this->sccp_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 ;",
"; from users. ;",
";--------------------------------------------------------------------------------;",
"#include sccp_custom.conf"
);
}
$cnf_wr->WriteConfig('sccp.conf', $this->sccp_conf_init);
//$this->$cnf_wr->writeConfig('sccp.conf', $this->sccp_conf_init);
}
public function initVarfromXml() { public function initVarfromXml() {
if ((array) $this->xml_data) { if ((array) $this->xml_data) {
foreach ($this->xml_data->xpath('//page_group') as $item) { foreach ($this->xml_data->xpath('//page_group') as $item) {