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)
This commit is contained in:
steve-lad 2021-07-12 12:26:56 +02:00
parent 5a184ededb
commit 651f3adb44
11 changed files with 88 additions and 93 deletions

View file

@ -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() {

View file

@ -1165,7 +1165,9 @@ and open the template in the editor. Base Version before all crash :-)
<element type='p'>This section is responsible for the modes of operation of external services: tftp http.</element>
<element type='p'> * off - Flat model cisco. All data is in the directory TFTP Server Path</element>
<element type='p'> * Provision - The directory structure is strictly defined in the manager. Requires tftpd mapping support.</element>
<element type='p'> * Custom - TFTP Directory structure can be extended by index.cnf. This supports phones that can work on tftp and http. Remapping support is required</element>
<element type='p'> The mode is determined by Sccp_manager based on the presence of a mapping file in TFTP defaults</element>
<element type='p'> and must be the same as the tftp server, or the phones will not find required files</element>
<element type='p'> To change the mode, add or remove the -m option.</element>
</item>
<label>SCCP Server Path config</label>
<item type="IE" id="1" seq="2">
@ -1188,18 +1190,14 @@ and open the template in the editor. Base Version before all crash :-)
</input>
<help>Use path from provision index.cnf file. You must first make sure that you have properly configured the "Provision"</help>
</item>
<item type="IS" id="21" seq="20">
<item type="ISC" id="21" seq="20">
<name>tftp_rewrite</name>
<label>TFTP SERVER remapping support</label>
<default>off</default>
<option_hide class=".custom_hide">custom</option_hide>
<option_show class=".custom_show">custom</option_show>
<option_disable class=".custom_disable">Custom</option_disable>
<option_disable class=".provision_disable">Provision</option_disable>
<option_disable class=".off_disable">Off</option_disable>
<button value="off">Off</button>
<button value="pro">Provision</button>
<button value="custom">Custom</button>
<help>Support the use of regular-expression-based filename remapping</help>
</item>
<item type="IE" id="2">

View file

@ -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

View file

@ -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("<li>" . _("Found ftp root dir at {$tftpRootPath}") . "</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;
$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]);
}

View file

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

View file

@ -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 )

View file

@ -328,7 +328,7 @@ class formcreate
<?php
}
function addElementIS($child, $fvalues, $sccp_defaults,$npref) {
function addElementIS($child, $fvalues, $sccp_defaults,$npref, $disabledButtons) {
if ($npref == 'sccp_hw_') {
$this->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 = '';

View file

@ -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();

View file

@ -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) {

View file

@ -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':

View file

@ -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.<br>
Add option <br>
-m /etc/asterisk/sccpManagerRewrite.rules <br>
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.<br>
To enable Provision mode, add option <br>
-m /etc/asterisk/sccpManagerRewrite.rules <br>
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;
}
}