From 5a184ededb6c149a33390e81ace2f2143d41654f Mon Sep 17 00:00:00 2001 From: steve-lad <72376554+steve-lad@users.noreply.github.com> Date: Sun, 11 Jul 2021 16:52:24 +0200 Subject: [PATCH] Integrate Provision functionality into Sccp_Manager Create required directory structure Check if mapping support is enabled Check if mapping rules are defined Change options available based on above Create index.cnf and sccpManagerRewrite.rules --- Sccp_manager.class.php | 1 + conf/sccpgeneral.xml.v433 | 22 +++++++++-------- contrib/rewrite.rules | 8 +++++- contrib/tftp.xinetd | 2 +- install.php | 10 +++++--- sccpManClasses/extconfigs.class.php | 26 ++++++++++++++++++-- sccpManClasses/formcreate.class.php | 15 +++++++++++- sccpManTraits/helperFunctions.php | 34 ++++++++++++++++++++++++++ views/server.info.php | 38 +++++++++++++++++------------ views/server.setting.php | 1 - 10 files changed, 122 insertions(+), 35 deletions(-) diff --git a/Sccp_manager.class.php b/Sccp_manager.class.php index e864608..1425643 100644 --- a/Sccp_manager.class.php +++ b/Sccp_manager.class.php @@ -205,6 +205,7 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO { */ public function settingsShowPage() { + $this->checkTftpMapping(); $request = $_REQUEST; $action = !empty($request['action']) ? $request['action'] : ''; diff --git a/conf/sccpgeneral.xml.v433 b/conf/sccpgeneral.xml.v433 index b96617c..b837f35 100644 --- a/conf/sccpgeneral.xml.v433 +++ b/conf/sccpgeneral.xml.v433 @@ -1163,9 +1163,9 @@ and open the template in the editor. Base Version before all crash :-) Help_tftp_rewrite This section is responsible for the modes of operation of external services: tftp http. - * off - Flat model cisco. All data is in the directory /tftproot - * Custom - The directory structure is strictly defined in the manager (for internal use). Requires tftpd rewrite support. - * Provision - Directory structure data is read from an external file. This project supports phones that can work on tftp and http. Support rewrite. + * 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 @@ -1173,7 +1173,7 @@ and open the template in the editor. Base Version before all crash :-) provision_hide tftp_path - /tftpboot + sccp-custom Path to tftp home directory. This was determined by the Sccp_manager installer and should only be changed if the tftp root has been modified since installation @@ -1188,16 +1188,18 @@ 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_rewrite off - pro - pro - - Internal - + custom + custom + Custom + Provision + Off + + Support the use of regular-expression-based filename remapping diff --git a/contrib/rewrite.rules b/contrib/rewrite.rules index f2c5a45..fc635b8 100644 --- a/contrib/rewrite.rules +++ b/contrib/rewrite.rules @@ -1,5 +1,9 @@ # -# TFTPd Rewrite for SCCP_Manager Custom remaping +# TFTPd Rewrite for SCCP_Manager Custom remapping +# +# This file is maintained by Sccp_Manager, and will be overwritten by the installer +# a copy of the original can be found at sccpManagerRewrite.rules.bu +# # /firmware # /settings # /wallpapers @@ -174,6 +178,8 @@ ri ^(ATA030204SCCP090202A.zup)$ firmware/ata186/\1 # Sub-Directory Handling # settings +# Do not disable the first rule - this is required by sccp_manager +#ri ^(.+\.tlzz)?$ settings/\1 #ri ^(.+\.tlv)?$ settings/\1 #ri ^\/(.+\.tlv)?$ settings/\1 #ri ^((.+\.cnf.xml)(\.enc)?(\.sgn)?)$ settings/\1 diff --git a/contrib/tftp.xinetd b/contrib/tftp.xinetd index 6ea6509..cfea06a 100644 --- a/contrib/tftp.xinetd +++ b/contrib/tftp.xinetd @@ -10,7 +10,7 @@ service tftp wait = yes user = root server = /usr/sbin/in.tftpd - server_args = -c -s -v /tftpboot -m /tftpboot/rewrite.rules + server_args = -c -s -v /tftpboot -m -m /etc/asterisk/sccpManagerRewrite.rules disable = no per_source = 11 cps = 100 2 diff --git a/install.php b/install.php index 8eea9f1..ee1e31d 100644 --- a/install.php +++ b/install.php @@ -893,8 +893,8 @@ 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']['data'] = $confDir; + $settingsToDb['asterisk_etc_path'] = array( 'keyword' => 'asterisk_etc_path', 'seq' => 20, 'type' => 0, 'data' => $confDir); + $settingsFromDb['asterisk_etc_path'] = $settingsToDb['asterisk_etc_path']; foreach ($settingsToDb as $settingToSave) { $sql = "REPLACE INTO sccpsettings (keyword, data, seq, type) VALUES ('{$settingToSave['keyword']}', '{$settingToSave['data']}', {$settingToSave['seq']}, {$settingToSave['type']});"; @@ -904,7 +904,11 @@ function checkTftpServer() { } unset($settingsToDb[$settingToSave['keyword']]); } - + // 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) { diff --git a/sccpManClasses/extconfigs.class.php b/sccpManClasses/extconfigs.class.php index c07bbbb..470e855 100644 --- a/sccpManClasses/extconfigs.class.php +++ b/sccpManClasses/extconfigs.class.php @@ -254,12 +254,15 @@ class extconfigs 'wallpapers' => 'wallpapers' ); $adv_tree = array('pro' => array('templates' => 'tftproot', + 'firmware' => 'tftproot', 'settings' => 'tftproot', 'locales' => 'tftproot', - 'firmware' => 'tftproot', 'languages' => 'locales', + 'templates' => 'tftproot', 'dialplan' => 'tftproot', - 'softkey' => 'tftproot' + 'softkey' => 'tftproot', + 'ringtones' => 'tftproot', + 'wallpapers' => 'tftproot' ), 'def' => array('templates' => 'tftproot', 'settings' => '', @@ -300,8 +303,21 @@ class extconfigs $adv_ini_array = parse_ini_file($adv_ini); $adv_config = array_merge($adv_config, $adv_ini_array); } + // rewrite adv_ini to reflect the new $adv_config + if (file_exists($adv_ini)){ + rename($adv_ini, "{$adv_ini}.old"); + } + $indexFile = fopen($adv_ini,'w'); + fwrite($indexFile, "[main]\n"); + foreach ($adv_config as $advKey => $advVal) { + fwrite($indexFile, "{$advKey} = {$advVal}\n"); + } + fclose($indexFile); + $settingsToDb['tftp_rewrite'] =array( 'keyword' => 'tftp_rewrite', 'seq' => 20, 'type' => 2, 'data' => 'pro', 'systemdefault' => ''); break; + case 'unavailable': + $settingsToDb['tftp_rewrite'] =array( 'keyword' => 'tftp_rewrite', 'seq' => 20, 'type' => 2, 'data' => 'unavailable', 'systemdefault' => ''); case 'on': case 'internal': case 'off': @@ -332,6 +348,12 @@ class extconfigs } } } + // 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])); + } + } // 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/'; diff --git a/sccpManClasses/formcreate.class.php b/sccpManClasses/formcreate.class.php index ee6d4c6..2c814e2 100644 --- a/sccpManClasses/formcreate.class.php +++ b/sccpManClasses/formcreate.class.php @@ -449,7 +449,20 @@ 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 = ''; + if (in_array($value, $disabledButtons )) { + $opt_disabled = 'disabled'; + } $val_check = strtolower((string)$value[@value]); if ($val_check == strtolower($res_v)) { $val_check = " checked"; @@ -460,7 +473,7 @@ class formcreate } else {$val_check = "";} } else {$val_check = "";} } - echo ""; + echo ""; echo ""; $i++; } diff --git a/sccpManTraits/helperFunctions.php b/sccpManTraits/helperFunctions.php index 2229ff3..c12212f 100644 --- a/sccpManTraits/helperFunctions.php +++ b/sccpManTraits/helperFunctions.php @@ -213,6 +213,40 @@ trait helperfunctions { return false; } + public function checkTftpMapping(){ + 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]); + $this->sccpvalues['tftp-rewrite']['data'] = 'unavailable'; + if ($tftpInfo[1] == 'with remap') { + $info['TFTP Server'] = array('Version' => $tftpInfo[0], 'about' => $tftpInfo[1]); + + $remoteFileName = ".sccp_manager_remap_probe_sentinel_temp".mt_rand(0, 9999999).".tlzz"; + $remoteFileContent = "# This is a test file created by Sccp_Manager. It can be deleted without impact"; + $testFtpDir = "{$this->sccpvalues['tftp_path']['data']}/settings"; + + // 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)) { + // Did not find sentinel so mapping not available + $this->sccpvalues['tftp_rewrite']['data'] = 'unavailable'; + } + unlink($tempFile); + } + } + } + } // temporary helper function to save xml with proper indentation public function saveXml($xml, $filename) { $dom = new \DOMDocument("1.0"); diff --git a/views/server.info.php b/views/server.info.php index c1a2e47..811b212 100644 --- a/views/server.info.php +++ b/views/server.info.php @@ -36,29 +36,35 @@ $info['aminterface'] = $this->aminterface->info(); $info['XML'] = $this->xmlinterface->info(); $info['sccp_class'] = $driver['sccp']; $info['Core_sccp'] = array('Version' => $core['Version'], - 'about' => 'Sccp ver.' . $core['Version'] . - ' r' . $core['vCode'] . ' Revision :' . - $core['RevisionNum'] . ' Hash :' . - $core['RevisionHash']); -/* -if (!$this->srvinterface->useAmiInterface) { - $info['aminterface']['about'] .= ' -- Disabled'; - $info['Core_sccp'] = array('Version' => $core['Version'], 'about' => 'Sccp ver.' . $core['Version'] . ' r' . $core['vCode'] . ' Revision :' . $core['RevisionNum'] . ' Hash :' . $core['RevisionHash'] . ' ----Warning: Upgrade chan_sccp to use full ami functionality'); -} -*/ -$info['Asterisk'] = array('Version' => FreePBX::Config()->get('ASTVERSION'), 'about' => 'Asterisk.'); + 'about' => "Sccp ver: {$core['Version']} r{$core['vCode']} Revision: {$core['RevisionNum']} Hash: {$core['RevisionHash']}"); +$info['Asterisk'] = array('Version' => FreePBX::Config()->get('ASTVERSION'), 'about' => 'Asterisk.'); if (!empty($this->sccpvalues['SccpDBmodel'])) { $info['DB Model'] = array('Version' => $this->sccpvalues['SccpDBmodel']['data'], 'about' => 'SCCP DB Configure'); } -if (!empty($this->sccpvalues['tftp_rewrite'])) { - if ($this->sccpvalues['tftp_rewrite']['data'] == 'pro') { - $info['Provision_SCCP'] = array('Version' => 'base', 'about' => 'Provision Sccp enabled'); - } else { - $info['TFTP_Rewrite'] = array('Version' => 'base', 'about' => 'Rewrite Supported'); + +// Start testing tftp server settings - this should be moved after debug to extConfigs + +if (!empty($this->sccpvalues['tftp_rewrite']['data'])) { + switch ($this->sccpvalues['tftp_rewrite']['data']) { + case 'custom': + 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'); + break; } } + +// Finished testing tftp server options $info['Сompatible'] = array('Version' => $compatible, 'about' => 'Ok'); if (!empty($this->sccpvalues['SccpDBmodel'])) { if ($compatible > $this->sccpvalues['SccpDBmodel']['data']) { diff --git a/views/server.setting.php b/views/server.setting.php index 55acd1a..623df04 100644 --- a/views/server.setting.php +++ b/views/server.setting.php @@ -28,7 +28,6 @@ echo $this->showGroup('sccp_dev_time_s', 1); echo $this->showGroup('sccp_net', 1); echo $this->showGroup('sccp_lang', 1); - echo $this->showGroup('sccp_extpath_config', 1); ?>