diff --git a/Sccp_manager.class.php b/Sccp_manager.class.php index 7b444fd..82c6d8e 100644 --- a/Sccp_manager.class.php +++ b/Sccp_manager.class.php @@ -96,15 +96,13 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO { private $tftpLang = array(); // private $hint_context = '@ext-local'; /// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Get it from Config !!! private $hint_context = array('default' => '@ext-local'); /// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Get it from Config !!! - private $val_null = 'NONE'; /// REPLACE to null Field - public $sccp_model_list = array(); + public $sccp_model_list = array(); private $cnf_wr = null; public $sccppath = array(); public $sccpvalues = array(); public $sccp_conf_init = array(); public $xml_data; - public $class_error; //error construct public function __construct($freepbx = null) { @@ -142,17 +140,17 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO { $this->init_sccp_path(); $this->initVarfromDefs(); $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'] ; + $this->sccpvalues['sccp_compatible']['data'] = $this->sccpvalues['SccpDBmodel']['data']; } } // Load Advanced Form Constuctor 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']; + $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'; @@ -369,23 +367,22 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO { if (!empty($this->sccpvalues['displayconfig'])) { if (!empty($this->sccpvalues['displayconfig']['data']) && ($this->sccpvalues['displayconfig']['data'] == 'sccpsimple')) { - $this->pagedata = array( - "general" => array( - "name" => _("General SCCP Settings"), - "page" => 'views/server.setting.php' - ), - "sccpdevice" => array( - "name" => _("SCCP Device"), - "page" => 'views/server.device.php' - ), - "sccpinfo" => array( - "name" => _("SCCP info"), - "page" => 'views/server.info.php' - ), - ); + $this->pagedata = array( + "general" => array( + "name" => _("General SCCP Settings"), + "page" => 'views/server.setting.php' + ), + "sccpdevice" => array( + "name" => _("SCCP Device"), + "page" => 'views/server.device.php' + ), + "sccpinfo" => array( + "name" => _("SCCP info"), + "page" => 'views/server.info.php' + ), + ); } - - } + } if (empty($this->pagedata)) { // $driver = $this->FreePBX->Config->get_conf_setting('ASTSIPDRIVER'); @@ -415,7 +412,6 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO { "page" => 'views/server.info.php' ), ); - } if (!empty($this->pagedata)) { foreach ($this->pagedata as &$page) { @@ -427,27 +423,25 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO { } return $this->pagedata; } - + public function InfoServerShowPage() { $request = $_REQUEST; $action = !empty($request['action']) ? $request['action'] : ''; $this->pagedata = array( - "general" => array( - "name" => _("General SCCP Settings"), - "page" => 'views/server.info.php' - ), - - ); + "general" => array( + "name" => _("General SCCP Settings"), + "page" => 'views/server.info.php' + ), + ); - foreach ($this->pagedata as &$page) { - ob_start(); - include($page['page']); - $page['content'] = ob_get_contents(); - ob_end_clean(); - } + foreach ($this->pagedata as &$page) { + ob_start(); + include($page['page']); + $page['content'] = ob_get_contents(); + ob_end_clean(); + } return $this->pagedata; - } public function AdvServerShowPage() { @@ -898,21 +892,7 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO { break; // ------------------------------- Old deviece suport - In the development--- case 'backupsettings': - global $amp_conf; - $backup_files = array( $amp_conf['ASTETCDIR'].'/sccp.conf', $amp_conf['ASTETCDIR'].'/extensions_additional.conf', $amp_conf['ASTETCDIR'].'/extconfig.conf'); - - $result = $this->dbinterface->dump_sccp_tables($this->sccppath["tftp_path"],$amp_conf['AMPDBNAME'], $amp_conf['AMPDBUSER'], $amp_conf['AMPDBPASS']); - $backup_files[] = $result; - - $zip = new \ZipArchive(); - $filename = $result.".zip"; - if ($zip->open($filename, \ZIPARCHIVE::CREATE)) { - foreach ($backup_files as $file) { - $zip->addFile($file); - } - $zip->close(); - } - + $filename = $this->sccp_create_sccp_backup(); $file_name = basename($filename); header("Content-Type: application/zip"); @@ -920,12 +900,11 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO { header("Content-Length: " . filesize($filename)); readfile($filename); - unlink($result); unlink($filename); -// return array('status' => false, 'message' => $result); - // return $result; - break; +// return array('status' => false, 'message' => $result); + // return $result; + break; } } @@ -976,12 +955,11 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO { $value = strtoupper(str_replace(array('.', '-', ':'), '', $value)); // Delete mac Seporated from string $value = sprintf("%012s", $value); if ($hw_prefix == 'VG') { - $value = $hw_prefix . $value.'0'; + $value = $hw_prefix . $value . '0'; } else { $value = $hw_prefix . $value; } $name_dev = $value; - } break; case 'disallow': @@ -1015,7 +993,7 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO { foreach ($vval as $vkey => $vval) { switch ($vkey) { case 'inherit': - if ($vval=='on') { + if ($vval == 'on') { $arr_clear = TRUE; // Злобный ХАК if ($key == 'permit') { @@ -1024,7 +1002,7 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO { } break; case 'internal': - if ($vval=='on') { + if ($vval == 'on') { $tmp_data .= 'internal;'; } break; @@ -1034,13 +1012,13 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO { } } if (strlen($tmp_data) > 2) { - while (substr($tmp_data,-1)=='/') { + while (substr($tmp_data, -1) == '/') { $tmp_data = substr($tmp_data, 0, -1); } $arr_data .= $tmp_data . ';'; - } + } } - while (substr($arr_data,-1)==';') { + while (substr($arr_data, -1) == ';') { $arr_data = substr($arr_data, 0, -1); } if ($arr_clear) { @@ -1202,23 +1180,23 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO { switch ($vkey) { case 'inherit': case 'internal': - if ($vval=='on') { + if ($vval == 'on') { $tmp_data .= 'internal;'; } - break; + break; default: $tmp_data .= $vval . '/'; - break; + break; } } if (strlen($tmp_data) > 2) { - while (substr($tmp_data,-1)=='/') { + while (substr($tmp_data, -1) == '/') { $tmp_data = substr($tmp_data, 0, -1); } - $arr_data .= $tmp_data. ';'; - } + $arr_data .= $tmp_data . ';'; + } } - while (substr($arr_data,-1)==';') { + while (substr($arr_data, -1) == ';') { $arr_data = substr($arr_data, 0, -1); } if (!($this->sccpvalues[$key1]['data'] == $arr_data)) { @@ -1270,7 +1248,6 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO { return; } - public function getMyConfig($var = null, $id = "noid") { // $final = false; switch ($var) { @@ -1419,25 +1396,27 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO { function Sccp_manager_get_config($engine) { $this->debugdata($engine); } -/* - function soundlang_hookGet_config($engine) { - global $core_conf; - $this->debugdata($engine); + /* + function soundlang_hookGet_config($engine) { + + global $core_conf; + $this->debugdata($engine); + + switch ($engine) { + case "asterisk": + // if (isset($core_conf) && is_a($core_conf, "core_conf")) { + // $language = FreePBX::Soundlang()->getLanguage(); + // if ($language != "") { + // $core_conf->addSipGeneral('language', $language); + // $core_conf->addIaxGeneral('language', $language); + // } + // } + break; + } + } + */ - switch ($engine) { - case "asterisk": -// if (isset($core_conf) && is_a($core_conf, "core_conf")) { -// $language = FreePBX::Soundlang()->getLanguage(); -// if ($language != "") { -// $core_conf->addSipGeneral('language', $language); -// $core_conf->addIaxGeneral('language', $language); -// } -// } - break; - } - } -*/ /** * Retrieve Active Codecs * return fiends Lag pack @@ -1449,7 +1428,7 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO { private function initTftpLang() { $result = array(); - if (empty($this->sccppath["tftp_path"]) || empty($this->sccppath["tftp_lang_path"]) ) { + if (empty($this->sccppath["tftp_path"]) || empty($this->sccppath["tftp_lang_path"])) { return; } $dir = $this->sccppath["tftp_lang_path"]; @@ -1495,14 +1474,14 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO { */ // !TODO!: -TODO-: This function is getting a little big. Might be possible to sperate tftp work into it's own file/class. Initially, you need to remove the not working section and commented out section - + function init_sccp_path() { global $db; global $amp_conf; - $driver_revision = array('0' => '', '430' => '.v431', '431' => '.v432', '432' => '.v432', '433' => '.v433'); - - - $confDir = $amp_conf["ASTETCDIR"]; + $driver_revision = array('0' => '', '430' => '.v431', '431' => '.v432', '432' => '.v432', '433' => '.v433'); + + + $confDir = $amp_conf["ASTETCDIR"]; if (empty($this->sccppath["asterisk"])) { if (strlen($confDir) < 1) { $this->sccppath["asterisk"] = "/etc/asterisk"; @@ -1510,30 +1489,30 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO { $this->sccppath["asterisk"] = $confDir; } } - $ver_id = $this->srvinterface->get_compatible_sccp(); + $ver_id = $this->srvinterface->get_compatible_sccp(); if (!empty($this->sccpvalues['SccpDBmodel'])) { - $ver_id =$this->sccpvalues['SccpDBmodel']['data']; + $ver_id = $this->sccpvalues['SccpDBmodel']['data']; } $driver = $this->FreePBX->Core->getAllDriversInfo(); - $sccp_driver_replace= ''; + $sccp_driver_replace = ''; if (empty($driver['sccp'])) { $sccp_driver_replace = 'yes'; } else { if (empty($driver['sccp']['Version'])) { $sccp_driver_replace = 'yes'; } else { - if ($driver['sccp']['Version'] != $this->sccp_driver_ver.$driver_revision[$ver_id]) { + if ($driver['sccp']['Version'] != $this->sccp_driver_ver . $driver_revision[$ver_id]) { $sccp_driver_replace = 'yes'; } } } - + // $this->sccpvalues['sccp_compatible'] = '11'; $this->sccpvalues['sccp_compatible'] = array('keyword' => 'compatible', 'data' => $ver_id, 'type' => '1', 'seq' => '99'); - + $this->sccppath = $this->extconfigs->validate_init_path($confDir, $this->sccpvalues, $sccp_driver_replace); - + $driver = $this->FreePBX->Core->getAllDriversInfo(); // ?????? $read_config = $this->cnf_read->getConfig('sccp.conf'); @@ -1548,10 +1527,10 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO { $hint = $this->srvinterface->sccp_list_hints(); foreach ($hint as $key => $value) { - if ($this->hint_context['default'] != $value) { + if ($this->hint_context['default'] != $value) { $this->hint_context[$key] = $value; - } - } + } + } } /* @@ -1689,7 +1668,6 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO { $data_value['tftp_path'] = $this->sccppath["tftp_path"]; $this->xmlinterface->create_default_XML($this->sccppath["tftp_path_store"], $data_value, $model_information, $lang_data); - } /* @@ -1711,23 +1689,23 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO { $data_value['server_if_list'] = $this->getIP_information(); $dev_config['tftp_path'] = $this->sccppath["tftp_path"]; $dev_config['tftp_firmware'] = ''; -/* if (!empty($this->sccpvalues['tftp_rewrite'])) { - if ( $this->sccpvalues['tftp_rewrite']['data'] == 'internal' ) { - $dir_list = $this->find_all_files($dev_config['tftp_path'], $dev_config['loadimage']); - foreach ($dir_list as $filek){ - if (!empty($filek)) { - $fnd_path= ''; - $fnd_path = str_replace($dev_config['tftp_path'],'',$filek); - $fnd_path = substr($fnd_path,1,strpos($fnd_path, $dev_config['loadimage'])-1); - if (!empty($fnd_path)) { - $dev_config['tftp_firmware'] = $fnd_path; - } - break; - } - } - } - } - */ + /* if (!empty($this->sccpvalues['tftp_rewrite'])) { + if ( $this->sccpvalues['tftp_rewrite']['data'] == 'internal' ) { + $dir_list = $this->find_all_files($dev_config['tftp_path'], $dev_config['loadimage']); + foreach ($dir_list as $filek){ + if (!empty($filek)) { + $fnd_path= ''; + $fnd_path = str_replace($dev_config['tftp_path'],'',$filek); + $fnd_path = substr($fnd_path,1,strpos($fnd_path, $dev_config['loadimage'])-1); + if (!empty($fnd_path)) { + $dev_config['tftp_firmware'] = $fnd_path; + } + break; + } + } + } + } + */ $dev_config['addon_info'] = array(); if (!empty($dev_config['addon'])) { $hw_addon = explode(',', $dev_config['addon']); @@ -1738,9 +1716,8 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO { } $lang_data = $this->extconfigs->getextConfig('sccp_lang'); // return $this->sccppath["tftp_path_store"]; - + return $this->xmlinterface->create_SEP_XML($this->sccppath["tftp_path_store"], $data_value, $dev_config, $dev_id, $lang_data); - } function sccp_delete_device_XML($dev_id = '') { @@ -1765,6 +1742,31 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO { } } + private function sccp_create_sccp_backup() { + global $amp_conf; + $backup_files = array($amp_conf['ASTETCDIR'] . '/sccp', $amp_conf['ASTETCDIR'] . '/extensions', $amp_conf['ASTETCDIR'] . '/extconfig', + $amp_conf['ASTETCDIR'] . '/res_config_mysql', $amp_conf['ASTETCDIR'] . '/res_mysql'); + $backup_ext = array('.conf', '_additional.conf', '_custom.conf'); + + $result = $this->dbinterface->dump_sccp_tables($this->sccppath["tftp_path"], $amp_conf['AMPDBNAME'], $amp_conf['AMPDBUSER'], $amp_conf['AMPDBPASS']); + + $zip = new \ZipArchive(); + $filename = $result . ".zip"; + if ($zip->open($filename, \ZIPARCHIVE::CREATE)) { + $zip->addFile($result); + foreach ($backup_files as $file) { + foreach ($backup_ext as $b_ext) { + if (file_exists($file . $b_ext)) { + $zip->addFile($file . $b_ext); + } + } + } + $zip->close(); + } + unlink($result); + return $filename; + } + function sccp_create_sccp_init() { // Make sccp.conf data // [general] @@ -1805,12 +1807,12 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO { $search_mode = ''; if (!empty($this->sccpvalues['tftp_rewrite'])) { $search_mode = $this->sccpvalues['tftp_rewrite']['data']; - if ( $search_mode == 'pro' ) { + if ($search_mode == 'pro') { $dir_list = $this->find_all_files($dir, $file_ext, 'fileonly'); } else { $dir_list = $this->find_all_files($dir, $file_ext); } - } else { + } else { $dir_list = $this->find_all_files($dir, $file_ext, 'fileonly'); } @@ -1821,8 +1823,8 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO { $raw_settings[$i]['validate'] = '-;-'; if (!empty($raw_settings[$i]['loadimage'])) { $raw_settings[$i]['validate'] = 'no;'; - if ((strtolower($raw_settings[$i]['vendor'] == 'cisco')) || !empty($dir_list)) { - foreach ($dir_list as $filek){ + if ((strtolower($raw_settings[$i]['vendor'] == 'cisco')) || !empty($dir_list)) { + foreach ($dir_list as $filek) { switch ($search_mode) { case 'pro': case 'on': @@ -1832,12 +1834,12 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO { } break; case 'internal2': - + break; case 'off': default: // Place in root TFTP dir // $raw_settings[$i]['buttons'] = $dir.'/'.$raw_settings[$i]['loadimage']; - if (strpos(strtolower($filek), strtolower($dir.'/'.$raw_settings[$i]['loadimage'])) !== false) { + if (strpos(strtolower($filek), strtolower($dir . '/' . $raw_settings[$i]['loadimage'])) !== false) { // if (strpos(strtolower($filek), strtolower($raw_settings[$i]['loadimage'])) !== false) { $raw_settings[$i]['validate'] = 'yes;'; } @@ -1845,26 +1847,26 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO { } } } -/* OLD search - $file = $dir . '/' . $raw_settings[$i]['loadimage']; - if (is_dir($file)) { - $file .= '/' . $raw_settings[$i]['loadimage']; - } - $raw_settings[$i]['validate'] = 'no;'; - if (strtolower($raw_settings[$i]['vendor']) == 'cisco') { - foreach ($file_ext as $value) { - if (file_exists($file . $value)) { - $raw_settings[$i]['validate'] = 'yes;'; - break; - } - } - } else { - if (file_exists($file)) { - $raw_settings[$i]['validate'] = 'yes;'; - } - } - * - */ + /* OLD search + $file = $dir . '/' . $raw_settings[$i]['loadimage']; + if (is_dir($file)) { + $file .= '/' . $raw_settings[$i]['loadimage']; + } + $raw_settings[$i]['validate'] = 'no;'; + if (strtolower($raw_settings[$i]['vendor']) == 'cisco') { + foreach ($file_ext as $value) { + if (file_exists($file . $value)) { + $raw_settings[$i]['validate'] = 'yes;'; + break; + } + } + } else { + if (file_exists($file)) { + $raw_settings[$i]['validate'] = 'yes;'; + } + } + * + */ } else { $raw_settings[$i]['validate'] = '-;'; } @@ -1887,29 +1889,28 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO { $res = array(); $default_hint = '@ext-local'; // get all hints [101@ext-local] => 101@ext-local - $tmp_data = $this->srvinterface->sccp_list_all_hints(); + $tmp_data = $this->srvinterface->sccp_list_all_hints(); foreach ($tmp_data as $value) { -/* !TODO!: Add Hint Filtred List */ - $res[$value] = array('hint' => $value, 'name' => before('@', $value), 'label' => $value ); + /* !TODO!: Add Hint Filtred List */ + $res[$value] = array('hint' => $value, 'name' => before('@', $value), 'label' => $value); } // Update info from sccp_db - $tmp_data = $this->dbinterface->get_db_SccpTableData('SccpExtension'); + $tmp_data = $this->dbinterface->get_db_SccpTableData('SccpExtension'); foreach ($tmp_data as $value) { $name_l = $value['name']; - if (!empty($res[$name_l.$default_hint])) { - $res[$name_l.$default_hint]['name'] = $name_l; - $res[$name_l.$default_hint]['label'] = $value['label']; + if (!empty($res[$name_l . $default_hint])) { + $res[$name_l . $default_hint]['name'] = $name_l; + $res[$name_l . $default_hint]['label'] = $value['label']; } else { // if not exist in system hints ..... ??????? - $res[$name_l.$default_hint] = array('hint' => $name_l.$default_hint, 'name' => $name_l, 'label' => $value['label'] ); + $res[$name_l . $default_hint] = array('hint' => $name_l . $default_hint, 'name' => $name_l, 'label' => $value['label']); } - } // Update info from sip DB -/* !TODO!: Update Hint info from sip DB ??? */ + /* !TODO!: Update Hint info from sip DB ??? */ return $res; } - + function getIP_information() { $interfaces['auto'] = array('0.0.0.0', 'All', '0'); @@ -1968,64 +1969,74 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO { // $dom = dom_import_simplexml($node); // $dom->parentNode->removeChild($dom); // } -private function strpos_array($haystack, $needles) { - if (is_array($needles)) { - foreach ($needles as $str) { - if (is_array($str)) { - $pos = strpos_array($haystack, $str); - } else { - $pos = strpos($haystack, $str); + private function strpos_array($haystack, $needles) { + if (is_array($needles)) { + foreach ($needles as $str) { + if (is_array($str)) { + $pos = strpos_array($haystack, $str); + } else { + $pos = strpos($haystack, $str); + } + if ($pos !== FALSE) { + return $pos; + } } - if ($pos !== FALSE) { - return $pos; + } else { + return strpos($haystack, $needles); + } + return FALSE; + } + + private function find_all_files($dir, $file_mask = null, $mode = 'full') { + + $result = NULL; + if (empty($dir) || (!file_exists($dir))) { + return $result; + } + + $root = scandir($dir); + foreach ($root as $value) { + if ($value === '.' || $value === '..') { + continue; + } + if (is_file("$dir/$value")) { + $filter = false; + if (!empty($file_mask)) { + if (is_array($file_mask)) { + foreach ($file_mask as $k) { + if (strpos(strtolower($value), strtolower($k)) !== false) { + $filter = true; + } + } + } else { + if (strpos(strtolower($value), strtolower($file_mask)) !== false) { + $filter = true; + } + } + } else { + $filter = true; + } + if ($filter) { + if ($mode == 'fileonly') { + $result[] = "$value"; + } else { + $result[] = "$dir/$value"; + } + } else { + $result[] = null; + } + continue; + } + $sub_fiend = $this->find_all_files("$dir/$value", $file_mask, $mode); + if (!empty($sub_fiend)) { + foreach ($sub_fiend as $sub_value) { + if (!empty($sub_value)) { + $result[] = $sub_value; + } + } } } - } else { - return strpos($haystack, $needles); - } - return FALSE; -} - -private function find_all_files($dir, $file_mask=null, $mode='full'){ - - $result = NULL; - if (empty($dir) || (!file_exists($dir))) { return $result; } - $root = scandir($dir); - foreach($root as $value) { - if($value === '.' || $value === '..') {continue;} - if(is_file("$dir/$value")) { - $filter = false; - if (!empty($file_mask)) { - if (is_array($file_mask)) { - foreach ($file_mask as $k){ - if (strpos(strtolower($value), strtolower($k)) !== false) {$filter = true;} - } - } else { - if (strpos(strtolower($value), strtolower($file_mask)) !== false) {$filter = true;} - } - } else {$filter = true;} - if ($filter) { - if ($mode=='fileonly'){ - $result[]="$value"; - } else { - $result[]="$dir/$value"; - } - } else {$result[]=null;} - continue; - } - $sub_fiend = $this->find_all_files("$dir/$value",$file_mask,$mode); - if (!empty($sub_fiend)) { - foreach($sub_fiend as $sub_value) { - if (!empty($sub_value)) { - $result[]=$sub_value; - } - } - } - } - return $result; -} - } diff --git a/Sccp_manager.inc/extconfigs.class.php b/Sccp_manager.inc/extconfigs.class.php index 5abcbcc..527cacb 100644 --- a/Sccp_manager.inc/extconfigs.class.php +++ b/Sccp_manager.inc/extconfigs.class.php @@ -9,8 +9,7 @@ namespace FreePBX\modules\Sccp_manager; class extconfigs { public function __construct($parent_class = null) { - $this->paren_class = $parent_class; - + $this->paren_class = $parent_class; } public function info() { @@ -212,30 +211,29 @@ class extconfigs { 'New Zealand' => array('offset' => '720', 'daylight' => 'Daylight') ); - - public function validate_init_path($confDir = '', $db_vars, $sccp_driver_replace='') { + public function validate_init_path($confDir = '', $db_vars, $sccp_driver_replace = '') { // global $db; // global $amp_conf; // *** Setings for Provision Sccp - $adv_config = Array('tftproot' => '', 'firmware' => 'firmware', 'settings' => 'settings', - 'locales' => 'locales', 'languages' => 'languages', 'templates' => 'templates'); - $adv_tree['pro'] = Array('templates' => 'tftproot', 'settings' => 'tftproot', 'locales' => 'tftproot', 'firmware' => 'tftproot', 'languages' => 'locales'); + $adv_config = Array('tftproot' => '', 'firmware' => 'firmware', 'settings' => 'settings', + 'locales' => 'locales', 'languages' => 'languages', 'templates' => 'templates'); + $adv_tree['pro'] = Array('templates' => 'tftproot', 'settings' => 'tftproot', 'locales' => 'tftproot', 'firmware' => 'tftproot', 'languages' => 'locales'); // $adv_tree['def'] = Array('templates' => 'tftproot', 'settings' => '', 'locales' => 'tftproot', 'firmware' => 'tftproot', 'languages' => ''); - $adv_tree['def'] = Array('templates' => 'tftproot', 'settings' => '', 'locales' => 'tftproot', 'firmware' => 'tftproot', 'languages' => 'tftproot'); + $adv_tree['def'] = Array('templates' => 'tftproot', 'settings' => '', 'locales' => 'tftproot', 'firmware' => 'tftproot', 'languages' => 'tftproot'); //* **************------ **** - $base_tree = Array('tftp_templates' => 'templates', 'tftp_path_store' => 'settings', 'tftp_lang_path' => 'languages', 'tftp_firmware_path'=>'firmware'); - + $base_tree = Array('tftp_templates' => 'templates', 'tftp_path_store' => 'settings', 'tftp_lang_path' => 'languages', 'tftp_firmware_path' => 'firmware'); + if (empty($confDir)) { - return array('error' => 'empty СonfDir' ); + return array('error' => 'empty СonfDir'); } - - $base_config = Array( 'asterisk' => $confDir, 'sccp_conf' => $confDir . '/sccp.conf', 'tftp_path' => ''); + + $base_config = Array('asterisk' => $confDir, 'sccp_conf' => $confDir . '/sccp.conf', 'tftp_path' => ''); // Test Base dir (/tftproot) if (!empty($db_vars["tftp_path"])) { if (file_exists($db_vars["tftp_path"]["data"])) { - $base_config["tftp_path"] = $db_vars["tftp_path"]["data"]; + $base_config["tftp_path"] = $db_vars["tftp_path"]["data"]; } } if (empty($base_config["tftp_path"])) { @@ -247,25 +245,25 @@ class extconfigs { if (!empty($this->paren_class)) { $this->paren_class->class_error['tftp_path'] = 'Tftp path not defined'; } - return array('error' => 'empty tftp_path' ); - } - if (!is_writeable($base_config["tftp_path"])) { + return array('error' => 'empty tftp_path'); + } + if (!is_writeable($base_config["tftp_path"])) { if (!empty($this->paren_class)) { $this->paren_class->class_error['tftp_path'] = 'No write permision on tftp DIR'; } - return array('error' => 'No write permision on tftp DIR' ); - } + return array('error' => 'No write permision on tftp DIR'); + } // END Test Base dir (/tftproot) - - if (!empty($db_vars['tftp_rewrite_path'])) { + + if (!empty($db_vars['tftp_rewrite_path'])) { $adv_ini = $db_vars['tftp_rewrite_path']["data"]; } $adv_tree_mode = 'def'; - if (empty($db_vars["tftp_rewrite"])) { + if (empty($db_vars["tftp_rewrite"])) { $db_vars["tftp_rewrite"]["data"] = "off"; } - + $adv_config['tftproot'] = $base_config["tftp_path"]; if ($db_vars["tftp_rewrite"]["data"] == 'pro') { $adv_tree_mode = 'pro'; @@ -282,9 +280,9 @@ class extconfigs { } foreach ($adv_tree[$adv_tree_mode] as $key => $value) { if (!empty($adv_config[$key])) { - if (!empty($value)) { - if (substr($adv_config[$key],0,1) != "/") { - $adv_config[$key] = $adv_config[$value].'/'.$adv_config[$key]; + if (!empty($value)) { + if (substr($adv_config[$key], 0, 1) != "/") { + $adv_config[$key] = $adv_config[$value] . '/' . $adv_config[$key]; } } else { $adv_config[$key] = $adv_config['tftproot']; @@ -295,33 +293,33 @@ class extconfigs { $base_config[$key] = $adv_config[$value]; if (!file_exists($base_config[$key])) { if (!mkdir($base_config[$key], 0777, true)) { - die('Error creating dir : '. $base_config[$key]); + die('Error creating dir : ' . $base_config[$key]); } } - } - + } + // $base_config['External_ini'] = $adv_config; // $base_config['External_mode'] = $adv_tree_mode; -/* - if (!empty($this->sccppath["tftp_path"])) { - $this->sccppath["tftp_DP"] = $this->sccppath["tftp_path"] . '/Dialplan'; - if (!file_exists($this->sccppath["tftp_DP"])) { - if (!mkdir($this->sccppath["tftp_DP"], 0777, true)) { - die('Error creating DialPlan template dir'); - } - } - } -*/ - // TFTP -REWrite double model + /* + if (!empty($this->sccppath["tftp_path"])) { + $this->sccppath["tftp_DP"] = $this->sccppath["tftp_path"] . '/Dialplan'; + if (!file_exists($this->sccppath["tftp_DP"])) { + if (!mkdir($this->sccppath["tftp_DP"], 0777, true)) { + die('Error creating DialPlan template dir'); + } + } + } + */ + // TFTP -REWrite double model if (empty($_SERVER['DOCUMENT_ROOT'])) { if (!empty($this->paren_class)) { $this->paren_class->class_error['DOCUMENT_ROOT'] = 'Empty DOCUMENT_ROOT'; - } + } $base_config['error'] = 'Empty DOCUMENT_ROOT'; return $base_config; } - + 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"] . '/'; @@ -329,7 +327,7 @@ class extconfigs { copy($filename, $dst_path . basename($filename)); } } - + $dst = $_SERVER['DOCUMENT_ROOT'] . '/admin/modules/core/functions.inc/drivers/Sccp.class.php'; if (!file_exists($dst) || $sccp_driver_replace == 'yes') { @@ -340,24 +338,25 @@ class extconfigs { $src_path = $_SERVER['DOCUMENT_ROOT'] . '/admin/modules/sccp_manager/conf/' . basename($dst); copy($src_path, $dst); } - } - + } + if (!file_exists($base_config["sccp_conf"])) { // System re Config $sccpfile = file_get_contents($_SERVER['DOCUMENT_ROOT'] . '/admin/modules/sccp_manager/conf/sccp.conf'); file_put_contents($base_config["sccp_conf"], $sccpfile); } - + return $base_config; } - + public function validate_RealTime() { global $amp_conf; - $res = Array(); - + $res = Array(); + $cnf_int = \FreePBX::Config(); $cnf_wr = \FreePBX::WriteConfig(); $cnf_read = \FreePBX::LoadConfig(); - $def_config = array('sccpdevice' => 'mysql,sccp,sccpdeviceconfig', 'sccpline' => ' mysql,sccp,sccpline'); + $def_config = array('sccpdevice' => 'mysql,sccp,sccpdeviceconfig', 'sccpline' => 'mysql,sccp,sccpline'); + $backup_ext = array('_custom.conf', '.conf', '_additional.conf'); $def_bd_config = array('dbhost' => $amp_conf['AMPDBHOST'], 'dbname' => $amp_conf['AMPDBNAME'], 'dbuser' => $amp_conf['AMPDBUSER'], 'dbpass' => $amp_conf['AMPDBPASS'], 'dbport' => '3306', 'dbsock' => '/var/lib/mysql/mysql.sock'); @@ -369,22 +368,34 @@ class extconfigs { $res_conf = ''; $ext_conf = ''; - if (file_exists($dir . '/extconfig.conf')) { - $ext_conf = $cnf_read->getConfig('extconfig.conf'); - if (empty($ext_conf['settings']['sccpdevice'])) { - $res['extconfig'] = ' Options "Sccpdevice" not config '; + foreach ($backup_ext as $fext) { + if (file_exists($dir . '/extconfig' . $fext)) { + $ext_conf = $cnf_read->getConfig('extconfig' . $fext); + if (!empty($ext_conf['settings']['sccpdevice'])) { + $res['sccpdevice'] = 'OK'; + $res['extconfigfile'] = 'extconfigfile'. $fext; + } + if (empty($ext_conf['settings']['sccpline'])) { + $res['sccpline'] = 'OK'; + } } - if (empty($ext_conf['settings']['sccpline'])) { - $res['extconfig'] .= ' Options "Sccpline" not config '; - } - if (empty($res['extconfig'])) { - $res['extconfig'] = 'OK'; - } - } else { + } + + $res['extconfig'] = 'OK'; + + if (empty($res['sccpdevice'])) { + $res['extconfig'] = ' Options "Sccpdevice" not config '; + } + if (empty($res['sccpline'])) { + $res['extconfig'] = ' Options "Sccpline" not config '; + } + + if (empty($res['extconfigfile'])) { $res['extconfig'] = 'File extconfig.conf not exist'; } - if (!empty($res_conf_sql)) { + + if (!empty($res_conf_sql)) { if (file_exists($res_conf_sql)) { $def_bd_config['dbsock'] = $res_conf_sql; } @@ -394,7 +405,7 @@ class extconfigs { if (empty($res_conf[$def_bd_sec])) { $res['mysqlconfig'] = 'Not Config in file: res_mysql.conf'; } else { - if ($res_conf[$def_bd_sec]['dbsock'] != $def_bd_config['dbsock']) { + if ($res_conf[$def_bd_sec]['dbsock'] != $def_bd_config['dbsock']) { $res['mysqlconfig'] = 'Mysql Soket Error in file: res_mysql.conf'; } } @@ -407,21 +418,18 @@ class extconfigs { if (empty($res_conf[$def_bd_sec])) { $res['mysqlconfig'] = 'Not Config in file: res_config_mysql.conf'; } else { - if ($res_conf[$def_bd_sec]['dbsock'] != $def_bd_config['dbsock']) { + if ($res_conf[$def_bd_sec]['dbsock'] != $def_bd_config['dbsock']) { $res['mysqlconfig'] = 'Mysql Soket Error in file: res_config_mysql.conf'; } } if (empty($res['mysqlconfig'])) { $res['mysqlconfig'] = 'OK'; } - } if (empty($res['mysqlconfig'])) { - $res['mysqlconfig'] = 'Realtime Error: not found res_config_mysql.conf or res_mysql.conf configutation on the path :'. $dir ; + $res['mysqlconfig'] = 'Realtime Error: not found res_config_mysql.conf or res_mysql.conf configutation on the path :' . $dir; } - return $res; -} + return $res; + } - } - diff --git a/Sccp_manager.inc/srvinterface.class.php b/Sccp_manager.inc/srvinterface.class.php index c09e773..5860881 100644 --- a/Sccp_manager.inc/srvinterface.class.php +++ b/Sccp_manager.inc/srvinterface.class.php @@ -587,7 +587,7 @@ class srvinterface { } } } else { - return $result; + return $result; return array(); } } @@ -608,8 +608,10 @@ class srvinterface { fputs ($fp,"Events: on\r\n\r\n"); fputs ($fp,"Action: SCCPShowDevices\r\n"); - fputs ($fp,"ResultFormat: command\r\n"); -// $params = array('Segment' => 'device', 'ResultFormat'=>'command' ); + +// fputs ($fp,"Action: SCCPConfigMetaData\r\n"); +// fputs ($fp,"Segment: device\r\n"); +// fputs ($fp,"ResultFormat: command\r\n"); fputs ($fp,"\r\n"); /* diff --git a/conf/sccpgeneral.xml.v431 b/conf/sccpgeneral.xml.v431 index 1f793d8..ebb51c5 100644 --- a/conf/sccpgeneral.xml.v431 +++ b/conf/sccpgeneral.xml.v431 @@ -138,7 +138,7 @@ and open the template in the editor. Base Version before all crash :-) Debug: Enable debugging level in SCCP module. - + displayconfig sccpgeneral diff --git a/conf/sccpgeneral.xml.v433 b/conf/sccpgeneral.xml.v433 index 665a4ac..ee34552 100644 --- a/conf/sccpgeneral.xml.v433 +++ b/conf/sccpgeneral.xml.v433 @@ -139,7 +139,7 @@ and open the template in the editor. Base Version before all crash :-) Debug: Enable debugging level in SCCP module. - + displayconfig sccpgeneral diff --git a/conf/sccpsimple.xml.v431 b/conf/sccpsimple.xml.v431 index 779a48a..6f4666c 100644 --- a/conf/sccpsimple.xml.v431 +++ b/conf/sccpsimple.xml.v431 @@ -256,7 +256,7 @@ and open the template in the editor. Base Version before all crash :-) Debug: Enable debugging level in SCCP module. - + displayconfig sccpgeneral diff --git a/conf/sccpsimple.xml.v433 b/conf/sccpsimple.xml.v433 index da625af..80ff671 100644 --- a/conf/sccpsimple.xml.v433 +++ b/conf/sccpsimple.xml.v433 @@ -258,7 +258,7 @@ and open the template in the editor. Base Version before all crash :-) Debug: Enable debugging level in SCCP module. - + displayconfig sccpgeneral diff --git a/install.php b/install.php index 42052df..84e3a59 100644 --- a/install.php +++ b/install.php @@ -1,8 +1,8 @@ 'mysql,sccp,sccpdeviceconfig', 'sccpline' => ' mysql,sccp,sccpline'); $def_bd_config = array('dbhost' => $amp_conf['AMPDBHOST'], 'dbname' => $amp_conf['AMPDBNAME'], 'dbuser' => $amp_conf['AMPDBUSER'], 'dbpass' => $amp_conf['AMPDBPASS'], @@ -664,8 +666,13 @@ function Setup_RealTime() { $res_conf_sql = ini_get('pdo_mysql.default_socket'); $res_conf = ''; $ext_conf = ''; - if (file_exists($dir . '/extconfig.conf')) { - $ext_conf = $cnf_read->getConfig('extconfig.conf'); + $ext_conf_file = 'extconfig.conf'; + foreach ($backup_ext as $value) { + if (file_exists($dir . '/extconfig' . $value)) { + $ext_conf_file = 'extconfig' . $value; + $ext_conf = $cnf_read->getConfig($ext_conf_file); + break; + } } if (!empty($res_conf_sql)) { if (file_exists($res_conf_sql)) { @@ -713,7 +720,7 @@ function Setup_RealTime() { // $res_conf['general']['dbsock'] = $def_bd_config['dbsock']; $cnf_wr->writeConfig('res_config_mysql.conf', $res_conf, false); } - $cnf_wr->writeConfig('extconfig.conf', $ext_conf, false); + $cnf_wr->writeConfig($ext_conf_file, $ext_conf, false); } CheckSCCPManagerDBTables($table_req); diff --git a/views/form.buttons.php b/views/form.buttons.php index 2bd8663..160c19b 100644 --- a/views/form.buttons.php +++ b/views/form.buttons.php @@ -27,9 +27,6 @@ ksort($data_sort); foreach ($data_sort as $key => $value) { $hint_list[$value] = $hint_list1[$value]; } - - - //print_r($hint_list); //ksort($hint_list); //natsort($hint_list); @@ -100,9 +97,9 @@ if (!empty($_REQUEST['new_id'])) { $defaul_tv = (empty($db_buttons[$line_id])) ? "empty": $db_buttons[$line_id]['type']; $defaul_btn = (empty($db_buttons[$line_id])) ? "": $db_buttons[$line_id]['name']; $defaul_opt = (empty($db_buttons[$line_id])) ? array(''): explode(',',$db_buttons[$line_id]['options']); +// print_r($defaul_btn); // print_r($defaul_opt); - - + $show_form_mode = $defaul_tv; $def_hint = ''; $def_silent = ''; @@ -127,19 +124,18 @@ if (!empty($_REQUEST['new_id'])) { // print_r($defaul_fcod); } foreach ($defaul_opt as $data_i) { - if (strpos($data_i,'@') >0) { - $defaul_btn = strtok($data_i,'@'); + if (strpos($data_i,'@')>0) { + $test_btn = strtok($data_i,'@'); $def_hint = 'checked'; - if ($defaul_btn == $defaul_opt[0]) { + $defaul_btn = $data_i; + if ($test_btn == $defaul_opt[0]) { foreach ($lines_list as $data){ - if ($data['name']==$defaul_btn) { + if ($data['name']==$test_btn) { $show_form_mode = 'line'; $defaul_tv = 'monitor'; break; } } - } else { - $defaul_btn = $data_i; } } } diff --git a/views/server.info.php b/views/server.info.php index b5b0c1d..f9fdc6d 100644 --- a/views/server.info.php +++ b/views/server.info.php @@ -62,7 +62,7 @@ if (empty($conf_realtime)) { } else { $rt_info = ''; foreach ($conf_realtime as $key => $value) { - if ($value != 'OK') { + if (($value != 'OK') && ($key != 'extconfigfile')) { $rt_info .= '
Found error in section '.$key.' :'. $value. '
'; } } @@ -71,20 +71,19 @@ if (empty($conf_realtime)) { } } /* - global $amp_conf; + //global $amp_conf; print_r("
Request:
");
  $json = '';
  print_r("
"); + //print_r($conf_realtime); print_r("
"); print_r("
"); - print_r($amp_conf); - print_r("DIRECT START"); + //print_r($amp_conf); +// print_r("DIRECT START"); print_r("
"); // print_r($this->srvinterface->t_get_meta_data()); - //print_r($this->extconfigs->validate_RealTime()); -print("
"); + print(""); */ - // $lang_arr = $this->extconfigs->getextConfig('sccp_lang','sk_SK'); // print_r('
'); // print_r(timezone_identifiers_list());