Update Installer and Sccp_manager Construct

Move initial defaults reading from Construct to Install
Move initVarFromXml to helper functions - no longer used as defaults should come from db
Remove extraneous initialisations from Sccp_manager - these are now handled in Installer
Save TFTP structure to sccpsettings in Installer
Pass tftp_root to extconfigs ( if changed or uninitialised, was not written back to settingsFromDb before being passed to extconfigs
This commit is contained in:
steve-lad 2021-06-24 10:02:26 +02:00
parent 4d7463f341
commit ff1c451fe1
5 changed files with 106 additions and 129 deletions

View file

@ -139,34 +139,10 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO {
return;
}
$this->sccpvalues = $this->dbinterface->get_db_SccpSetting(); // Overwrite Exist
$this->initializeSccpPath();
$this->initVarfromDefs();
$this->sccpvalues = $this->dbinterface->get_db_SccpSetting(); //Initialise core settings
$this->initializeSccpPath(); //Set required Paths
$this->updateTimeZone(); // Get timezone from FreePBX
$this->initTftpLang();
if (!empty($this->sccpvalues['SccpDBmodel'])) {
if ($this->sccpvalues['sccp_compatible']['data'] > $this->sccpvalues['SccpDBmodel']['data']) {
$this->sccpvalues['sccp_compatible']['data'] = $this->sccpvalues['SccpDBmodel']['data'];
}
}
// Load Advanced Form Constructor Data
if (empty($this->sccpvalues['displayconfig'])) {
$xml_vars = __DIR__ . '/conf/sccpgeneral.xml.v' . $this->sccpvalues['sccp_compatible']['data'];
} else {
$xml_vars = __DIR__ . '/conf/' . $this->sccpvalues['displayconfig']['data'] . '.xml.v' . $this->sccpvalues['sccp_compatible']['data'];
}
if (!file_exists($xml_vars)) {
$xml_vars = __DIR__ . '/conf/sccpgeneral.xml';
}
if (file_exists($xml_vars)) {
$this->xml_data = simplexml_load_file($xml_vars);
$this->initVarfromXml(); // Overwrite Exist
}
//if (get_class($freepbx) === 'FreePBX') {
// only save settings when building a new FreePBX object
$this->saveSccpSettings();
//}
}
/*
@ -199,73 +175,13 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO {
* Load config vars from base array
*/
public function initVarfromDefs() {
foreach ($this->extconfigs->getExtConfig('sccpDefaults') as $key => $value) {
if (empty($this->sccpvalues[$key])) {
$this->sccpvalues[$key] = array('keyword' => $key, 'data' => $value, 'type' => '0', 'seq' => '0');
}
}
public function updateTimeZone() {
// Check timezone has not been changed in FreePBX and update if has
if ($this->sccpvalues['ntp_timezone'] != \date_default_timezone_get()) {
$this->sccpvalues['ntp_timezone'] = array('keyword' => 'ntp_timezone', 'seq'=>95, 'type' => 2, 'data' => \date_default_timezone_get());
}
}
/*
* Load config vars from xml
*/
public function initVarfromXml() {
if ((array) $this->xml_data) {
foreach ($this->xml_data->xpath('//page_group') as $item) {
foreach ($item->children() as $child) {
$seq = 0;
if (!empty($child['seq'])) {
$seq = (string) $child['seq'];
}
if ($seq < 99) {
if ($child['type'] == 'IE') {
foreach ($child->xpath('input') as $value) {
$tp = 0;
if (empty($value->value)) {
$datav = (string) $value->default;
} else {
$datav = (string) $value->value;
}
if (strtolower($value->type) == 'number') {
$tp = 1;
}
if (empty($this->sccpvalues[(string) $value->name])) {
$this->sccpvalues[(string) $value->name] = array('keyword' => (string) $value->name, 'data' => $datav, 'type' => $tp, 'seq' => $seq);
}
}
}
if ($child['type'] == 'IS' || $child['type'] == 'IED') {
if (empty($child->value)) {
$datav = (string) $child->default;
} else {
$datav = (string) $child->value;
}
if (empty($this->sccpvalues[(string) $child->name])) {
$this->sccpvalues[(string) $child->name] = array('keyword' => (string) $child->name, 'data' => $datav, 'type' => '2', 'seq' => $seq);
}
}
if (in_array($child['type'], array('SLD', 'SLS', 'SLT', 'SL', 'SLM', 'SLZ', 'SLTZN', 'SLA'))) {
if (empty($child->value)) {
$datav = (string) $child->default;
} else {
$datav = (string) $child->value;
}
if (empty($this->sccpvalues[(string) $child->name])) {
$this->sccpvalues[(string) $child->name] = array('keyword' => (string) $child->name, 'data' => $datav, 'type' => '2', 'seq' => $seq);
}
}
}
}
}
}
}
/*
* Show form information - General
*/
@ -957,11 +873,7 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO {
*/
function initializeSccpPath() {
$driver_revision = array('0' => '', '430' => '.v431', '431' => '.v432', '432' => '.v432', '433' => '.v433' . $this->sccp_branch);
$ver_id = $this->aminterface->get_compatible_sccp();
if (!empty($this->sccpvalues['SccpDBmodel'])) {
$ver_id = $this->sccpvalues['SccpDBmodel']['data'];
}
$this->sccppath = array(
'asterisk' => $this->sccpvalues['asterisk_etc_path']['data'],
'tftp_path' => $this->sccpvalues['tftp_path']['data'],
@ -973,11 +885,6 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO {
'tftp_softkey' => $this->sccpvalues['tftp_softkey']['data']
);
$driver = $this->FreePBX->Core->getAllDriversInfo();
$this->sccpvalues['sccp_compatible'] = array('keyword' => 'sccp_compatible', 'data' => $ver_id, 'type' => '1', 'seq' => '99');
$driver = $this->FreePBX->Core->getAllDriversInfo(); // Check that Sccp Driver has been updated by above
$read_config = $this->cnf_read->getConfig('sccp.conf');
$this->sccp_conf_init['general'] = $read_config['general'];
foreach ($read_config as $key => $value) {
@ -1317,7 +1224,7 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO {
break;
case "netlang": // Remove Key
case "tftp_path":
case "sccp_compatible":
case "sccp_compatible": // This is equal to SccpDBmodel
break;
default:
if (!empty($value['data'])) {

View file

@ -8,7 +8,7 @@ global $db;
global $amp_conf;
global $version;
global $aminterface;
global $extConfigs;
global $extconfigs;
global $mobile_hw;
global $useAmiForSoftKeys;
global $settingsFromDb;
@ -23,11 +23,14 @@ $db_config = '';
$sccp_version = array();
$cnf_int = \FreePBX::Config();
// Do not create Sccp_Manager object as not required.
// Only include required classes and create anonymous class for thisInstaller
$thisInstaller = new class{
use \FreePBX\modules\Sccp_Manager\sccpManTraits\helperFunctions;
};
$requiredClasses = array('amiinterface', 'extconfigs');
$requiredClasses = array('aminterface', 'extconfigs');
foreach ($requiredClasses as $className) {
$class = "\\FreePBX\\Modules\\Sccp_manager\\$className";
if (!class_exists($class, false)) {
@ -38,6 +41,7 @@ foreach ($requiredClasses as $className) {
}
}
// Get current default settings from db
$stmt = $db->prepare("SELECT * FROM sccpsettings");
$stmt->execute();
$settingsFromDb = $stmt->fetchAll(\PDO::FETCH_ASSOC);
@ -45,11 +49,18 @@ foreach ($settingsFromDb as $key => $rowArray) {
$settingsFromDb[$rowArray['keyword']] = $rowArray;
unset($settingsFromDb[$key]);
}
// Check that required settings are initialised and update db and $settingsFromDb if not
foreach ($extconfigs->getExtConfig('sccpDefaults') as $key => $value) {
if (empty($settingsFromDb[$key])) {
$settingsFromDb[$key] = array('keyword' => $key, 'data' => $value, 'type' => 0, 'seq' => 0);
// Do not create Sccp_Manager object as not required.
// Only include required classes
$sql = "REPLACE INTO sccpsettings (keyword, data, seq, type) VALUES ('{$key}', '{$value}', 0, 0)";
$results = $db->query($sql);
if (DB::IsError($results)) {
die_freepbx(_("Error updating sccpsettings: $key"));
}
}
}
CheckAsteriskVersion();
$sccp_version = CheckChanSCCPCompatible();
@ -871,7 +882,7 @@ function checkTftpServer() {
global $db;
global $cnf_int;
global $settingsFromDb;
global $extConfigs;
global $extconfigs;
global $thisInstaller;
$confDir = $cnf_int->get('ASTETCDIR');
// TODO: add option to use external server
@ -886,6 +897,8 @@ function checkTftpServer() {
outn("<li>" . _("Found ftp root dir at {$dirToTest}") . "</li>");
if ($settingsFromDb['tftp_path']['data'] != $tftpRootPath) {
$settingsToDb["tftp_path"] =array( 'keyword' => 'tftp_path', 'seq' => 2, 'type' => 0, 'data' => $tftpRootPath);
// Need to set the new value here to pass to extconfigs below
$settingsFromDb['tftp_path']['data'] = $tftpRootPath;
}
break;
}
@ -898,8 +911,6 @@ function checkTftpServer() {
die_freepbx(_("{$tftpRootPath} is not writable by user asterisk. Please fix, refresh and try again"));
}
$extConfigs->updateTftpStructure($settingsFromDb);
$settingsToDb['asterisk_etc_path'] =array( 'keyword' => 'asterisk_etc_path', 'seq' => 20, 'type' => 0, 'data' => $confDir);
foreach ($settingsToDb as $settingToSave) {
@ -908,7 +919,19 @@ function checkTftpServer() {
if (DB::IsError($results)) {
die_freepbx(_("Error updating sccpsettings. $sql"));
}
unset($settingsToDb[$settingToSave['keyword']]);
}
$settingsToDb = $extconfigs->updateTftpStructure($settingsFromDb);
foreach ($settingsToDb as $settingKey => $settingVal) {
$sql = "REPLACE INTO sccpsettings (keyword, data, seq, type) VALUES ('{$settingKey}', '{$settingVal}', 20, 0)";
$results = $db->query($sql);
if (DB::IsError($results)) {
die_freepbx(_("Error updating sccpsettings. $sql"));
}
}
return;
}

View file

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

View file

@ -101,19 +101,19 @@ class extconfigs
}
private $sccpDefaults = array(
"servername" => 'VPBXSCCP',
"bindaddr" => '0.0.0.0', "port" => '2000', # chan_sccp also supports ipv6
"deny" => '0.0.0.0/0.0.0.0',
"permit" => '0.0.0.0/0.0.0.0', # !TODO!: please change this to 'internal' which would mean:
# permit:127.0.0.0/255.0.0.0,permit:10.0.0.0/255.0.0.0,permit:172.0.0.0/255.224.0.0,permit:192.168.0.0/255.255.0.0"
"dateformat" => 'D.M.Y',
"disallow" => 'all', "allow" => 'alaw;ulaw',
"hotline_enabled" => 'off',
"hotline_context" => 'default', # !TODO!: Should this not be from-internal on FreePBX ?
"hotline_extension" => '*60', # !TODO!: Is this a good default extension to dial for hotline ?
"hotline_label" => 'hotline',
"devicetable" => 'sccpdevice',
"linetable" => 'sccpline'
'servername' => 'VPBXSCCP',
'bindaddr' => '0.0.0.0', "port" => '2000', # chan_sccp also supports ipv6
'deny' => '0.0.0.0/0.0.0.0',
'permit' => '0.0.0.0/0.0.0.0', # !TODO!: please change this to 'internal' which would mean:
'dateformat' => 'D.M.Y',
'disallow' => 'all', "allow" => 'alaw;ulaw',
'hotline_enabled' => 'off',
'hotline_context' => 'default', # !TODO!: Should this not be from-internal on FreePBX ?
'hotline_extension' => '*60', # !TODO!: Is this a good default extension to dial for hotline ?
'hotline_label' => 'hotline',
'devicetable' => 'sccpdevice',
'linetable' => 'sccpline',
'displayconfig' => 'sccpgeneral'
);
private $keysetdefault = array('onhook' => 'redial,newcall,cfwdall,cfwdbusy,cfwdnoanswer,pickup,gpickup,dnd,private',
'connected' => 'hold,endcall,park,vidmode,select,cfwdall,cfwdbusy,idivert,monitor',
@ -311,7 +311,7 @@ class extconfigs
}
}
}
// TODO: Need to add index.cnf, after setting defaults correctly
if (!file_exists($base_config["tftp_templates"] . '/XMLDefault.cnf.xml_template')) {
$src_path = $_SERVER['DOCUMENT_ROOT'] . '/admin/modules/sccp_manager/conf/';
$dst_path = $base_config["tftp_templates"] . '/';
@ -319,12 +319,8 @@ class extconfigs
copy($filename, $dst_path . basename($filename));
}
}
// Remove keys that are not required before returning $base_config.
unset($base_config['asterisk'], $base_config['sccp_conf'], $base_config['tftp_path']);
return $base_config;
}

View file

@ -190,5 +190,56 @@ trait helperfunctions {
return;
}
public function initVarfromXml() {
if ((array) $this->xml_data) {
foreach ($this->xml_data->xpath('//page_group') as $item) {
foreach ($item->children() as $child) {
$seq = 0;
if (!empty($child['seq'])) {
$seq = (string) $child['seq'];
}
if ($seq < 99) {
if ($child['type'] == 'IE') {
foreach ($child->xpath('input') as $value) {
$tp = 0;
if (empty($value->value)) {
$datav = (string) $value->default;
} else {
$datav = (string) $value->value;
}
if (strtolower($value->type) == 'number') {
$tp = 1;
}
if (empty($this->sccpvalues[(string) $value->name])) {
$this->sccpvalues[(string) $value->name] = array('keyword' => (string) $value->name, 'data' => $datav, 'type' => $tp, 'seq' => $seq);
}
}
}
if ($child['type'] == 'IS' || $child['type'] == 'IED') {
if (empty($child->value)) {
$datav = (string) $child->default;
} else {
$datav = (string) $child->value;
}
if (empty($this->sccpvalues[(string) $child->name])) {
$this->sccpvalues[(string) $child->name] = array('keyword' => (string) $child->name, 'data' => $datav, 'type' => '2', 'seq' => $seq);
}
}
if (in_array($child['type'], array('SLD', 'SLS', 'SLT', 'SL', 'SLM', 'SLZ', 'SLTZN', 'SLA'))) {
if (empty($child->value)) {
$datav = (string) $child->default;
} else {
$datav = (string) $child->value;
}
if (empty($this->sccpvalues[(string) $child->name])) {
$this->sccpvalues[(string) $child->name] = array('keyword' => (string) $child->name, 'data' => $datav, 'type' => '2', 'seq' => $seq);
}
}
}
}
}
}
}
}
?>