From 248abe6cb78526d32d9a6d09f73af92a861150f2 Mon Sep 17 00:00:00 2001 From: steve-lad <72376554+steve-lad@users.noreply.github.com> Date: Sat, 10 Jul 2021 17:51:55 +0200 Subject: [PATCH] Clean up and correct missing save settings Remove unnecessary method from formcreate Correct indentation in formcreate Remove debug code in Sccp.class correct logic for updating TFTP mode --- sccpManClasses/Sccp.class.php.v433 | 2 - sccpManClasses/extconfigs.class.php | 77 ++++++++------ sccpManClasses/formcreate.class.php | 150 +++++++--------------------- sccpManTraits/ajaxHelper.php | 10 +- views/formShowSysDefs.php | 2 +- 5 files changed, 87 insertions(+), 154 deletions(-) diff --git a/sccpManClasses/Sccp.class.php.v433 b/sccpManClasses/Sccp.class.php.v433 index e74f6a6..b06aa4d 100644 --- a/sccpManClasses/Sccp.class.php.v433 +++ b/sccpManClasses/Sccp.class.php.v433 @@ -216,7 +216,6 @@ class Sccp extends \FreePBX\modules\Core\Driver { } public function getDeviceDisplay($display, $deviceInfo, $currentComponent, $primarySection) { - dbug('',$primarySection); $activeCodecs = array(); // load xml data to get help from same source as rest of module $xml_vars = $_SERVER['DOCUMENT_ROOT'] . '/admin/modules/sccp_manager/conf/sccpgeneral.xml.v433'; @@ -321,7 +320,6 @@ class Sccp extends \FreePBX\modules\Core\Driver { ); break; case 'IS': - dbug('', $child); $select = array(); foreach ($child->xpath('button') as $value) { $select[] = array('value' => strtolower((string)$value[@value]), 'text' => (string)$value); diff --git a/sccpManClasses/extconfigs.class.php b/sccpManClasses/extconfigs.class.php index 6e95fba..c07bbbb 100644 --- a/sccpManClasses/extconfigs.class.php +++ b/sccpManClasses/extconfigs.class.php @@ -249,27 +249,27 @@ class extconfigs 'languages' => 'languages', 'templates' => 'templates', 'dialplan' => 'dialplan', - 'softkey' => 'softkey' + 'softkey' => 'softkey', + 'ringtones' => 'ringtones', + 'wallpapers' => 'wallpapers' ); - - $adv_tree['pro'] = array('templates' => 'tftproot', - 'settings' => 'tftproot', - 'locales' => 'tftproot', - 'firmware' => 'tftproot', - 'languages' => 'locales', - 'dialplan' => 'tftproot', - 'softkey' => 'tftproot' - ); - - $adv_tree['def'] = array('templates' => 'tftproot', - 'settings' => '', - 'locales' => '', - 'firmware' => '', - 'languages' => 'tftproot', - 'dialplan' => '', - 'softkey' => '' - ); - + $adv_tree = array('pro' => array('templates' => 'tftproot', + 'settings' => 'tftproot', + 'locales' => 'tftproot', + 'firmware' => 'tftproot', + 'languages' => 'locales', + 'dialplan' => 'tftproot', + 'softkey' => 'tftproot' + ), + 'def' => array('templates' => 'tftproot', + 'settings' => '', + 'locales' => '', + 'firmware' => '', + 'languages' => 'tftproot', + 'dialplan' => '', + 'softkey' => '' + ) + ); $base_tree = array('tftp_templates_path' => 'templates', 'tftp_store_path' => 'settings', 'tftp_lang_path' => 'languages', @@ -277,18 +277,17 @@ class extconfigs 'tftp_dialplan_path' => 'dialplan', 'tftp_softkey_path' => 'softkey' ); - $base_config = array(); if (!empty($settingsFromDb['tftp_rewrite_path']['data'])) { - // Have a setting in sccpsettings. It should start with $tftpRootPath - // If not we will replace it with $tftpRootPath. Avoids issues with legacy values - if (!strpos($settingsFromDb['tftp_rewrite_path']["data"],$settingsFromDb['tftp_path']['data'])) { + // Have a setting in sccpsettings. It should start with $tftp_path + // If not we will replace it with $tftp_path. Avoids issues with legacy values + if (!strpos($settingsFromDb['tftp_rewrite_path']["data"],$settingsFromDb['tftp_path']['data'])) { - $adv_ini = "{$tftpRootPath}/index.cnf"; - $settingsToDb['tftp_rewrite_path'] = $settingsFromDb['tftp_rewrite_path']; - $settingsToDb['tftp_rewrite_path']['data'] = $tftpRootPath; - } + $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']; + } $adv_ini = "{$settingsFromDb['tftp_rewrite_path']["data"]}/index.cnf"; } @@ -301,14 +300,14 @@ class extconfigs $adv_ini_array = parse_ini_file($adv_ini); $adv_config = array_merge($adv_config, $adv_ini_array); } + $settingsToDb['tftp_rewrite'] =array( 'keyword' => 'tftp_rewrite', 'seq' => 20, 'type' => 2, 'data' => 'pro', 'systemdefault' => ''); break; case 'on': case 'internal': case 'off': - break; default: - // not defined so set here - $settingsToDb["tftp_rewrite"] =array( 'keyword' => 'tftp_rewrite', 'seq' => 20, 'type' => 2, 'data' => 'off'); + // not defined so set here to off + $settingsToDb['tftp_rewrite'] =array( 'keyword' => 'tftp_rewrite', 'seq' => 20, 'type' => 2, 'data' => 'off', 'systemdefault' => ''); } foreach ($adv_tree[$adv_tree_mode] as $key => $value) { @@ -322,10 +321,11 @@ 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]); + $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])); @@ -342,7 +342,18 @@ class extconfigs } // 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; + 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'); + } + } + } } public function validate_RealTime( $connector ) diff --git a/sccpManClasses/formcreate.class.php b/sccpManClasses/formcreate.class.php index c8cca0f..ee6d4c6 100644 --- a/sccpManClasses/formcreate.class.php +++ b/sccpManClasses/formcreate.class.php @@ -476,93 +476,7 @@ class formcreate name; - $res_id = $npref.$res_n; - // $select_opt is a simple array for these types. - $select_opt = array(); - - if (!empty($metainfo[$res_n])) { - if ($child->meta_help == '1' || $child->help == 'Help!') { - $child->help = $metaInfo[$res_n]; - } - } - if (empty($child->class)) { - $child->class = 'form-control'; - } - switch ($child['type']) { - case 'SLD': - $day_format = array("D.M.Y", "D.M.YA", "Y.M.D", "YA.M.D", "M-D-Y", "M-D-YA", "D-M-Y", "D-M-YA", "Y-M-D", "YA-M-D", "M/D/Y", "M/D/YA", - "D/M/Y", "D/M/YA", "Y/M/D", "YA/M/D", "M/D/Y", "M/D/YA"); - $select_opt= $day_format; - break; - case 'SLM': - if (function_exists('music_list')) { - $moh_list = music_list(); - } - if (!is_array($moh_list)) { - $moh_list = array('default'); - } - $select_opt= $moh_list; - break; - case 'SLK': - $softKeyList = \FreePBX::Sccp_manager()->aminterface->sccp_list_keysets(); - $select_opt= $softKeyList; - break; - case 'SLP': - $dialplan_list = array(); - foreach (\FreePBX::Sccp_manager()->getDialPlanList() as $tmpkey) { - $tmp_id = $tmpkey['id']; - $dialplan_list[$tmp_id] = $tmp_id; - } - $select_opt= $dialplan_list; - break; - } - if (!empty($fvalues[$res_n])) { - if (!empty($fvalues[$res_n]['data'])) { - $child->value = $fvalues[$res_n]['data']; - } - } - ?> -