From 651f3adb44326fdbcf16f93c80213e4f33d91877 Mon Sep 17 00:00:00 2001
From: steve-lad <72376554+steve-lad@users.noreply.github.com>
Date: Mon, 12 Jul 2021 12:26:56 +0200
Subject: [PATCH] Finalise TFTP Mapping treatment
User no longer can select on or pro: If remapping is enabled and rules are set, then must use pro or phones will not find files
Otherwise is Off (flat directory)
---
Sccp_manager.class.php | 2 +-
conf/sccpgeneral.xml.v433 | 10 +++---
contrib/rewrite.rules | 2 +-
install.php | 39 ++++++++++-------------
module.xml | 2 +-
sccpManClasses/extconfigs.class.php | 48 ++++++++++-------------------
sccpManClasses/formcreate.class.php | 11 ++-----
sccpManTraits/ajaxHelper.php | 17 +++++-----
sccpManTraits/helperFunctions.php | 13 +++++---
views/formShowSysDefs.php | 9 +++++-
views/server.info.php | 28 ++++++++++++-----
11 files changed, 88 insertions(+), 93 deletions(-)
diff --git a/Sccp_manager.class.php b/Sccp_manager.class.php
index 1425643..ea49bd2 100644
--- a/Sccp_manager.class.php
+++ b/Sccp_manager.class.php
@@ -749,7 +749,7 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO {
/**
* Retrieve Active Codecs
- * return fiends Lag pack
+ * return finds Languageg pack
*/
private function initTftpLang() {
diff --git a/conf/sccpgeneral.xml.v433 b/conf/sccpgeneral.xml.v433
index b837f35..c3a00f9 100644
--- a/conf/sccpgeneral.xml.v433
+++ b/conf/sccpgeneral.xml.v433
@@ -1165,7 +1165,9 @@ and open the template in the editor. Base Version before all crash :-)
This section is responsible for the modes of operation of external services: tftp http. * off - Flat model cisco. All data is in the directory TFTP Server Path * Provision - The directory structure is strictly defined in the manager. Requires tftpd mapping support.
- * Custom - TFTP Directory structure can be extended by index.cnf. This supports phones that can work on tftp and http. Remapping support is required
+ The mode is determined by Sccp_manager based on the presence of a mapping file in TFTP defaults
+ and must be the same as the tftp server, or the phones will not find required files
+ To change the mode, add or remove the -m option.
@@ -1188,18 +1190,14 @@ and open the template in the editor. Base Version before all crash :-)
Use path from provision index.cnf file. You must first make sure that you have properly configured the "Provision"
-
+ tftp_rewriteoff
- custom
- custom
- CustomProvisionOff
-
Support the use of regular-expression-based filename remapping
diff --git a/contrib/rewrite.rules b/contrib/rewrite.rules
index fc635b8..a59b15d 100644
--- a/contrib/rewrite.rules
+++ b/contrib/rewrite.rules
@@ -179,7 +179,7 @@ ri ^(ATA030204SCCP090202A.zup)$ firmware/ata186/\1
# settings
# Do not disable the first rule - this is required by sccp_manager
-#ri ^(.+\.tlzz)?$ settings/\1
+ri ^(.+\.tlzz)?$ settings/\1
#ri ^(.+\.tlv)?$ settings/\1
#ri ^\/(.+\.tlv)?$ settings/\1
#ri ^((.+\.cnf.xml)(\.enc)?(\.sgn)?)$ settings/\1
diff --git a/install.php b/install.php
index ee1e31d..5128255 100644
--- a/install.php
+++ b/install.php
@@ -854,6 +854,11 @@ function checkTftpServer() {
global $thisInstaller;
$confDir = $cnf_int->get('ASTETCDIR');
$tftpRootPath = "";
+ // put the rewrite rules into the required location
+ if (file_exists("{$confDir}/sccpManagerRewrite.rules")) {
+ rename("{$confDir}/sccpManagerRewrite.rules", "{$confDir}/sccpManagerRewrite.rules.bu");
+ }
+ copy($_SERVER['DOCUMENT_ROOT'] . '/admin/modules/sccp_manager/contrib/rewrite.rules',"{$confDir}/sccpManagerRewrite.rules");
// TODO: add option to use external server
$remoteFileName = ".sccp_manager_installer_probe_sentinel_temp".mt_rand(0, 9999999);
@@ -873,9 +878,7 @@ function checkTftpServer() {
$tftpRootPath = $dirToTest;
outn("
" . _("Found ftp root dir at {$tftpRootPath}") . "
");
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;
+ $settingsFromDb["tftp_path"] = array( 'keyword' => 'tftp_path', 'seq' => 2, 'type' => 0, 'data' => $tftpRootPath, 'systemdefault' => '');
}
// Found sentinel file. Remove it and exit loop
if (file_exists($tempFile)) {
@@ -893,27 +896,19 @@ function checkTftpServer() {
die_freepbx(_("Either TFTP server is down or TFTP root is non standard. Please fix, refresh, and try again"));
}
- $settingsToDb['asterisk_etc_path'] = array( 'keyword' => 'asterisk_etc_path', 'seq' => 20, 'type' => 0, 'data' => $confDir);
- $settingsFromDb['asterisk_etc_path'] = $settingsToDb['asterisk_etc_path'];
+ $settingsFromDb['asterisk_etc_path'] = array( 'keyword' => 'asterisk_etc_path', 'seq' => 20, 'type' => 0, 'data' => $confDir, 'systemdefault' => '');
- foreach ($settingsToDb as $settingToSave) {
- $sql = "REPLACE INTO sccpsettings (keyword, data, seq, type) VALUES ('{$settingToSave['keyword']}', '{$settingToSave['data']}', {$settingToSave['seq']}, {$settingToSave['type']});";
- $results = $db->query($sql);
- if (DB::IsError($results)) {
- die_freepbx(_("Error updating sccpsettings. $sql"));
- }
- unset($settingsToDb[$settingToSave['keyword']]);
+ // Get TFTP mapping Status
+ $settingsFromDb['tftp_rewrite'] = array('keyword' => 'tftp_rewrite', 'seq' => 20, 'type' => 0, 'data' => 'off', 'systemdefault' => '');
+ if (\FreePbx::Sccp_manager()->checkTftpMapping()) {
+ $settingsFromDb['tftp_rewrite']['data'] = 'pro';
}
- // put the rewrite rules into the required location
- if (file_exists("{$confDir}/sccpManagerRewrite.rules")) {
- rename("{$confDir}/sccpManagerRewrite.rules", "{$confDir}/sccpManagerRewrite.rules.bu");
- }
- copy($_SERVER['DOCUMENT_ROOT'] . '/admin/modules/sccp_manager/contrib/rewrite.rules',"{$confDir}/sccpManagerRewrite.rules");
- $settingsToDb = $extconfigs->updateTftpStructure($settingsFromDb);
- foreach ($settingsToDb as $settingKey => $settingVal) {
- $settingsFromDb[$settingKey]['data'] = $settingVal;
- $sql = "REPLACE INTO sccpsettings (keyword, data, seq, type) VALUES ('{$settingKey}', '{$settingVal}', 20, 0)";
+ // Populate TFTP paths in SccpSettings
+ $settingsFromDb = $extconfigs->updateTftpStructure($settingsFromDb);
+
+ foreach ($settingsFromDb as $settingToSave) {
+ $sql = "REPLACE INTO sccpsettings (keyword, data, seq, type, systemdefault) VALUES ('{$settingToSave['keyword']}', '{$settingToSave['data']}', {$settingToSave['seq']}, {$settingToSave['type']}, '{$settingToSave['systemdefault']}')";
$results = $db->query($sql);
if (DB::IsError($results)) {
die_freepbx(_("Error updating sccpsettings. $sql"));
@@ -1014,7 +1009,7 @@ function cleanUpSccpSettings() {
}
}
// Override certain chan-sccp defaults as they are based on a non-FreePbx system
- $settingsFromDb['context']['systemdefault'] = 'from-internal'
+ $settingsFromDb['context']['systemdefault'] = 'from-internal';
unset($sysConfiguration[$key]);
}
diff --git a/module.xml b/module.xml
index d600f86..3e5c4c2 100644
--- a/module.xml
+++ b/module.xml
@@ -1,7 +1,7 @@
sccp_managerSCCP Manager
- 14.3.0.1
+ 14.3.0.0setupSCCP ConnectivitySteve Lad, Alex GP
diff --git a/sccpManClasses/extconfigs.class.php b/sccpManClasses/extconfigs.class.php
index 470e855..8a6f397 100644
--- a/sccpManClasses/extconfigs.class.php
+++ b/sccpManClasses/extconfigs.class.php
@@ -280,7 +280,7 @@ class extconfigs
'tftp_dialplan_path' => 'dialplan',
'tftp_softkey_path' => 'softkey'
);
- $base_config = array();
+ $baseConfig = array();
if (!empty($settingsFromDb['tftp_rewrite_path']['data'])) {
// Have a setting in sccpsettings. It should start with $tftp_path
@@ -288,8 +288,7 @@ class extconfigs
if (!strpos($settingsFromDb['tftp_rewrite_path']["data"],$settingsFromDb['tftp_path']['data'])) {
$adv_ini = "{$settingsFromDb['tftp_path']['data']}/index.cnf";
- $settingsToDb['tftp_rewrite_path'] = $settingsFromDb['tftp_rewrite_path'];
- $settingsToDb['tftp_rewrite_path']['data'] = $settingsFromDb['tftp_path']['data'];
+ $settingsFromDb['tftp_rewrite_path']['data'] = $settingsFromDb['tftp_path']['data'];
}
$adv_ini = "{$settingsFromDb['tftp_rewrite_path']["data"]}/index.cnf";
}
@@ -313,17 +312,14 @@ class extconfigs
fwrite($indexFile, "{$advKey} = {$advVal}\n");
}
fclose($indexFile);
-
- $settingsToDb['tftp_rewrite'] =array( 'keyword' => 'tftp_rewrite', 'seq' => 20, 'type' => 2, 'data' => 'pro', 'systemdefault' => '');
+ $settingsFromDb['tftp_rewrite']['data'] = 'pro';
break;
- case 'unavailable':
- $settingsToDb['tftp_rewrite'] =array( 'keyword' => 'tftp_rewrite', 'seq' => 20, 'type' => 2, 'data' => 'unavailable', 'systemdefault' => '');
case 'on':
case 'internal':
case 'off':
default:
// not defined so set here to off
- $settingsToDb['tftp_rewrite'] =array( 'keyword' => 'tftp_rewrite', 'seq' => 20, 'type' => 2, 'data' => 'off', 'systemdefault' => '');
+ $settingsFromDb['tftp_rewrite']['data'] = 'off';
}
foreach ($adv_tree[$adv_tree_mode] as $key => $value) {
@@ -339,43 +335,31 @@ class extconfigs
}
foreach ($base_tree as $key => $value) {
- $base_config[$key] = $adv_config[$value];
- // Save to sccpsettings
- $settingsToDb[$key] =array( 'keyword' => $key, 'seq' => 20, 'type' => 0, 'data' => $adv_config[$value], 'systemdefault' => '');
- if (!is_dir($base_config[$key])) {
- if (!mkdir($base_config[$key], 0755, true)) {
- die_freepbx(_('Error creating dir : ' . $base_config[$key]));
+ $baseConfig[$key] = $adv_config[$value];
+ if (!is_dir($baseConfig[$key])) {
+ if (!mkdir($baseConfig[$key], 0755, true)) {
+ die_freepbx(_("Error creating dir: $baseConfig[$key]"));
}
}
}
// Set up tftproot/settings so that can test if mapping is Enabled and configured.
if (!is_dir("{$settingsFromDb['tftp_path']['data']}/settings")) {
if (!mkdir("{$settingsFromDb['tftp_path']['data']}/settings", 0755, true)) {
- die_freepbx(_('Error creating dir : ' . $base_config[$key]));
+ die_freepbx(_("Error creating dir: {$settingsFromDb['tftp_path']['data']}/settings"));
}
}
// TODO: Need to add index.cnf, after setting defaults correctly
- if (!file_exists($base_config["tftp_templates_path"] . '/XMLDefault.cnf.xml_template')) {
- $src_path = $_SERVER['DOCUMENT_ROOT'] . '/admin/modules/sccp_manager/conf/';
- $dst_path = $base_config["tftp_templates_path"] . '/';
- foreach (glob($src_path . '*.*_template') as $filename) {
+ if (!file_exists("{$baseConfig['tftp_templates_path']}/XMLDefault.cnf.xml_template")) {
+ $src_path = "{$_SERVER['DOCUMENT_ROOT']}/admin/modules/sccp_manager/conf/";
+ $dst_path = "{$baseConfig["tftp_templates_path"]}/";
+ foreach (glob("{$src_path}*.*_template") as $filename) {
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 $settingsToDb;
- }
- private function initializeTFtpLanguagePath() {
- $dir = $this->sccppath["tftp_lang_path"];
- foreach ($this->extconfigs->getExtConfig('sccp_lang') as $lang_key => $lang_value) {
- $filename = $dir . DIRECTORY_SEPARATOR . $lang_value['locale'];
- if (!file_exists($filename)) {
- if (!mkdir($filename, 0777, true)) {
- die('Error creating tftp language directory');
- }
- }
+ foreach ($baseConfig as $baseKey => $baseValue) {
+ $settingsFromDb[$baseKey] = array('keyword' => $baseKey, 'seq' => 20, 'type' => 0, 'data' => $baseValue, 'systemdefault' => '');
}
+ return $settingsFromDb;
}
public function validate_RealTime( $connector )
diff --git a/sccpManClasses/formcreate.class.php b/sccpManClasses/formcreate.class.php
index 2c814e2..f7eff97 100644
--- a/sccpManClasses/formcreate.class.php
+++ b/sccpManClasses/formcreate.class.php
@@ -328,7 +328,7 @@ class formcreate
buttonDefLabel = 'site';
$this->buttonHelpLabel = 'device';
@@ -449,14 +449,7 @@ class formcreate
}
$opt_hide .= ' data-vshow="'.$child->option_show.'" data-clshow="'.$child->option_show['class'].'" ';
}
- // If TFTP remapping is not available, disable options that require it
- $disabledButtons = array();
- if (($child['id'] == 21) && ($sccp_defaults['tftp_rewrite']['data'] == 'unavailable')) {
- $disabledButtons = (array)$child->option_disable;
- $unavailableButton = $child->addChild('button','Unavailable');
- $unavailableButton->addAttribute('value', 'unavailable');
- dbug('',$child);
- }
+
foreach ($child->xpath('button') as $value) {
$opt_disabled = '';
diff --git a/sccpManTraits/ajaxHelper.php b/sccpManTraits/ajaxHelper.php
index eac8891..d205cc3 100644
--- a/sccpManTraits/ajaxHelper.php
+++ b/sccpManTraits/ajaxHelper.php
@@ -387,6 +387,7 @@ trait ajaxHelper {
}
function handleSubmit($request, $validateonly = false) {
+ dbug('',$request);
$hdr_prefix = 'sccp_';
$hdr_arprefix = 'sccp-ar_';
$save_settings = array();
@@ -448,15 +449,16 @@ trait ajaxHelper {
$key = (str_replace($hdr_prefix, '', $key, $count_mods));
if ($count_mods) {
- if (!empty($this->sccpvalues[$key]) && (!($this->sccpvalues[$key]['data'] == $value))) {
- $save_settings[$this->sccpvalues[$key]['keyword']] = array(
- 'keyword' => $this->sccpvalues[$key]['keyword'],
+ if (!empty($this->sccpvalues[$key]) && ($this->sccpvalues[$key]['data'] != $value)) {
+ $save_settings[$key] = array(
+ 'keyword' => $key,
'data' => $value,
'seq' => $this->sccpvalues[$key]['seq'],
'type' => $this->sccpvalues[$key]['type'],
'systemdefault' => $this->sccpvalues[$key]['systemdefault']
);
}
+
}
$key = (str_replace($hdr_arprefix, '', $key, $count_mods));
if ($count_mods) {
@@ -488,8 +490,8 @@ trait ajaxHelper {
$arr_data = substr($arr_data, 0, -1);
}
if (!($this->sccpvalues[$key]['data'] == $arr_data)) {
- $save_settings[] = array(
- 'keyword' => $this->sccpvalues[$key]['keyword'],
+ $save_settings[$key] = array(
+ 'keyword' => $key,
'data' => $arr_data,
'seq' => $this->sccpvalues[$key]['seq'],
'type' => $this->sccpvalues[$key]['type'],
@@ -506,7 +508,7 @@ trait ajaxHelper {
};
$tmpv = implode(",", $save_codec);
if (!($this->sccpvalues['allow']['data'] == $tmpv)) {
- $save_settings[] = array(
+ $save_settings['allow'] = array(
'keyword' => 'allow',
'data' => $tmpv,
'seq' => $this->sccpvalues['allow']['seq'],
@@ -525,7 +527,7 @@ trait ajaxHelper {
$TZdata = $this->extconfigs->getExtConfig('sccp_timezone', $tz_id);
if (!empty($TZdata)) {
$value = $TZdata['offset']/60;
- $save_settings[] = array(
+ $save_settings['tzoffset'] = array(
'keyword' => 'tzoffset',
'data' => $value,
'seq' => '98',
@@ -539,6 +541,7 @@ trait ajaxHelper {
$extSettings = $this->extconfigs->updateTftpStructure(array_merge($this->sccpvalues, $save_settings));
$save_settings = array_merge($save_settings, $extSettings);
+ dbug('saveSettingsAfter', $save_settings);
if (!empty($save_settings)) {
$this->saveSccpSettings($save_settings);
$this->sccpvalues = $this->dbinterface->get_db_SccpSetting();
diff --git a/sccpManTraits/helperFunctions.php b/sccpManTraits/helperFunctions.php
index c12212f..280e1c2 100644
--- a/sccpManTraits/helperFunctions.php
+++ b/sccpManTraits/helperFunctions.php
@@ -221,7 +221,7 @@ trait helperfunctions {
$tftpInfo = explode(',',$tftpInfo[0]);
$info['TFTP Server'] = array('Version' => $tftpInfo[0], 'about' => 'Mapping not available');
$tftpInfo[1] = trim($tftpInfo[1]);
- $this->sccpvalues['tftp-rewrite']['data'] = 'unavailable';
+ $this->sccpvalues['tftp_rewrite']['data'] = 'off';
if ($tftpInfo[1] == 'with remap') {
$info['TFTP Server'] = array('Version' => $tftpInfo[0], 'about' => $tftpInfo[1]);
@@ -232,20 +232,23 @@ trait helperfunctions {
// write a sentinel to a tftp subdirectory to see if mapping is working
if (is_dir($testFtpDir) && is_writable($testFtpDir)) {
- // TODO: Need to be sure that installer creates this directory
$tempFile = "${testFtpDir}/{$remoteFileName}";
file_put_contents($tempFile, $remoteFileContent);
-
// try to pull the written file through tftp.
// this way we can determine if mapping is active and using sccp_manager maps
- if ($remoteFileContent != $this->tftpReadTestFile($remoteFileName)) {
+ if ($remoteFileContent == $this->tftpReadTestFile($remoteFileName)) {
+ //found the file and contents are correct
+ $this->sccpvalues['tftp_rewrite']['data'] = 'pro';
+ } else {
// Did not find sentinel so mapping not available
- $this->sccpvalues['tftp_rewrite']['data'] = 'unavailable';
+ $this->sccpvalues['tftp_rewrite']['data'] = 'off';
}
unlink($tempFile);
}
+ return true;
}
}
+ return false;
}
// temporary helper function to save xml with proper indentation
public function saveXml($xml, $filename) {
diff --git a/views/formShowSysDefs.php b/views/formShowSysDefs.php
index be79ba1..a47dba2 100644
--- a/views/formShowSysDefs.php
+++ b/views/formShowSysDefs.php
@@ -50,6 +50,7 @@ if ($h_show==1) {
}
foreach ($items as $child) {
+ $disabledButtons = array();
if (empty($child->help)) {
$child->help = 'Help is not available.';
$child->meta_help = '1';
@@ -62,8 +63,14 @@ foreach ($items as $child) {
case 'IED':
\FreePbx::sccp_manager()->formcreate->addElementIED($child, $fvalues, $sccp_defaults,$npref, $napref);
break;
+ case 'ISC':
+ // This is a special case for Provision mode. Set some parameters here and fall through to IS.
+ $disabledButtons = array('pro' => 'Provision');
+ if ($sccp_defaults['tftp_rewrite']['data'] == 'pro') {
+ $disabledButtons = array('off' => 'Off');
+ }
case 'IS':
- \FreePbx::sccp_manager()->formcreate->addElementIS($child, $fvalues, $sccp_defaults,$npref);
+ \FreePbx::sccp_manager()->formcreate->addElementIS($child, $fvalues, $sccp_defaults,$npref, $disabledButtons);
break;
case 'SLD':
case 'SLM':
diff --git a/views/server.info.php b/views/server.info.php
index 811b212..ad9494c 100644
--- a/views/server.info.php
+++ b/views/server.info.php
@@ -44,7 +44,17 @@ if (!empty($this->sccpvalues['SccpDBmodel'])) {
$info['DB Model'] = array('Version' => $this->sccpvalues['SccpDBmodel']['data'], 'about' => 'SCCP DB Configure');
}
-// Start testing tftp server settings - this should be moved after debug to extConfigs
+exec('in.tftpd -V', $tftpInfo);
+$info['TFTP Server'] = array('Version' => 'Not Found', 'about' => 'Mapping not available');
+
+if (isset($tftpInfo[0])) {
+ $tftpInfo = explode(',',$tftpInfo[0]);
+ $info['TFTP Server'] = array('Version' => $tftpInfo[0], 'about' => 'Mapping not available');
+ $tftpInfo[1] = trim($tftpInfo[1]);
+ if ($tftpInfo[1] == 'with remap') {
+ $info['TFTP Server'] = array('Version' => $tftpInfo[0], 'about' => $tftpInfo[1]);
+ }
+}
if (!empty($this->sccpvalues['tftp_rewrite']['data'])) {
switch ($this->sccpvalues['tftp_rewrite']['data']) {
@@ -52,14 +62,16 @@ if (!empty($this->sccpvalues['tftp_rewrite']['data'])) {
case 'pro':
$info['Provision_SCCP'] = array('Version' => 'base', 'about' => 'Provision Sccp enabled');
break;
- case 'unavailable':
- $info['TFTP Mapping'] = array('Version' => 'off', 'about' => 'remapping is available, but mapping file not included in tftpd-hpa default settings.
- Add option
- -m /etc/asterisk/sccpManagerRewrite.rules
- to the tftpd defaults, location dependant on the system, and restart the tftpd server');
- break;
default:
- $info['TFTP_Mapping'] = array('Version' => 'off', 'about' => 'Rewrite Supported');
+ if ($tftpInfo[1] == 'with remap') {
+ $info['TFTP_Mapping'] = array('Version' => 'off', 'about' => "TFTP mapping is available but the mapping file is not included in tftpd-hpa default settings.
+ To enable Provision mode, add option
+ -m /etc/asterisk/sccpManagerRewrite.rules
+ to the tftpd defaults, (location dependant on the system), and restart the tftpd server");
+
+ } else {
+ $info['TFTP_Mapping'] = array('Version' => 'off', 'about' => "Mapping capability is not built into the TFTP server. To enable Provision, upgrade the TFTP server.");
+ }
break;
}
}