From 6b68cba0eac233193c66668a079a4e73fa34beaf Mon Sep 17 00:00:00 2001 From: PhantomVl Date: Mon, 16 Oct 2017 22:34:40 +0300 Subject: [PATCH] Begin resample Sccp_manager few Bugs, no Doc, maybe something is not working 16.10.2017 Fix mail box, sccp driver --- Sccp_manager.class.php | 31 +++--- Sccp_manager.inc/srvinterface.class.php | 124 +++++++++++++++++++++--- assets/js/sccp_manager.js | 44 +++++++-- conf/Sccp.class.php | 8 +- conf/Sccp.class.php.v11 | 39 ++++++-- conf/sccpgeneral.xml.v11 | 4 + install.php | 67 ++++++++----- views/formShow.php | 15 ++- views/server.setting.php | 10 +- 9 files changed, 267 insertions(+), 75 deletions(-) diff --git a/Sccp_manager.class.php b/Sccp_manager.class.php index 6ddd14f..8ce4b99 100644 --- a/Sccp_manager.class.php +++ b/Sccp_manager.class.php @@ -68,7 +68,7 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO { // private $SCCP_LANG_DICTIONARY = 'SCCP-dictionary.xml'; // CISCO LANG file search in /tftp-path private $SCCP_LANG_DICTIONARY = 'be-sccp.jar'; // CISCO LANG file search in /tftp-path private $pagedata = null; - private $sccp_driver_ver = '11.1'; + private $sccp_driver_ver = '11.2'; private $tftpLang = array(); private $hint_context = '@ext-local'; /// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Get it from Config !!! public $sccp_model_list = array(); @@ -90,20 +90,25 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO { $this->v = new \Respect\Validation\Validator(); $driverNamespace = "\\FreePBX\\Modules\\Sccp_manager"; - foreach(glob(__DIR__."/Sccp_manager.inc/*.class.php") as $driver) { - if(preg_match("/\/([a-z1-9]*)\.class\.php$/i",$driver,$matches)) { - $name = $matches[1]; - $class = $driverNamespace . "\\" . $name; - if(!class_exists($class,false)) { - include($driver); - } - if(class_exists($class,false)) { - $this->$name = new $class(); - } else { - throw new \Exception("Invalid Class inside in the include folder"); - } + if(class_exists($driverNamespace,false)) { + foreach(glob(__DIR__."/Sccp_manager.inc/*.class.php") as $driver) { + if(preg_match("/\/([a-z1-9]*)\.class\.php$/i",$driver,$matches)) { + $name = $matches[1]; + $class = $driverNamespace . "\\" . $name; + if(!class_exists($class,false)) { + include($driver); + } + if(class_exists($class,false)) { + $this->$name = new $class(); + } else { + throw new \Exception("Invalid Class inside in the include folder".print_r($freepbx)); + } + } } + } else { + return; } + $this->getSccpSettingFromDB(); // Overwrite Exist // $this->getSccpSetingINI(false); // get from sccep.ini diff --git a/Sccp_manager.inc/srvinterface.class.php b/Sccp_manager.inc/srvinterface.class.php index e1cbf38..7bb8b8a 100644 --- a/Sccp_manager.inc/srvinterface.class.php +++ b/Sccp_manager.inc/srvinterface.class.php @@ -7,6 +7,7 @@ */ namespace FreePBX\modules\Sccp_manager; + class srvinterface { public function __construct() { @@ -126,24 +127,42 @@ class srvinterface { } public function get_comatable_sccp() { - $res = 0; - $ast_out = $this->sccp_version(); - if ($ast_out[0] >= '4.3.0'){ - $res = 1; + $res = $this-> getChanSCCPVersion(); + if (empty($res)) { + $res = $this-> getChanSCCPVersion(); } - if (!empty($ast_out[1]) && $ast_out[1] == 'develop'){ + if (empty($res)) { + return 0; + } + if ($res["vCode"] >= 431) { + return 11; + } else { + return 10; + } +// return $res["vCode"]; + } + + function getCoreSCCPVersion() { + $result = array(); + $ast_out = $this->sccp_version(); + $result["Version"] = $ast_out[0]; + $version_parts=explode(".", $ast_out[0]); + $result["vCode"] = implode('', $version_parts); + if (!empty($ast_out[1]) && $ast_out[1] == 'develop'){ + $result["develop"] = $ast_out[1]; $res = 10; - if (!empty($ast_out[3])) { - if (base_convert($ast_out[3],16,10) >= base_convert('702487a',16,10)){ - $res += 1; - } + if (base_convert($ast_out[3],16,10) == base_convert('702487a',16,10)) { + $result["vCode"] = 431; + } + if (base_convert($ast_out[3],16,10) >= "10403") { // new method, RevisionNum is incremental + $result["vCode"] = 432; } } - return $res; + return $result; } // rename public - > privat - public function sccp_version() { + private function sccp_version() { $ast_out = $this->sccp_core_comands(array('cmd' => 'get_version')); if (preg_match("/Release.*\(/", $ast_out['data'] , $matches)) { $ast_out = substr($matches[0],9,-1); @@ -153,6 +172,69 @@ class srvinterface { } } + + function getChanSCCPVersion() { + global $astman; + $result = array(); + if (!$astman) { + return $result; + } + $metadata = $this->astman_retrieveJSFromMetaData(""); + if ($metadata && array_key_exists("Version",$metadata)) { + $result["Version"] = $metadata["Version"]; + $version_parts=explode(".", $metadata["Version"]); + $result["vCode"] = 0; + + # not sure about this sccp_ver numbering. Might be better to just check "Version" and Revision + # $result["vCode"] = implode('', $version_parts); + $result["vCode"] = 0; + if ($version_parts[0] == "4") { + $result["vCode"] = 400; + if ($version_parts[1] == "1") { + $result["vCode"] = 410; + } else + if ($version_parts[1] == "2") { + $result["vCode"] = 420; + } else + if ($version_parts[1] >= "3") { + $result["vCode"] = 430; + } + } + + /* + if (array_key_exists("Branch",$metadata)) { + if ($metadata["Branch"] == "master") { + + } else + if ($metadata["Branch"] == "develop") { + + } + } + */ + + /* Revision got replaced by RevisionHash in 10404 (using the hash does not work)*/ + if (array_key_exists("Revision",$metadata)) { + if (base_convert($metadata["Revision"],16,10) == base_convert('702487a',16,10)) { + $result["vCode"] = 431; + } + if (base_convert($metadata["Revision"],16,10) >= "10403") { + $result["vCode"] = 431; + } + } + if (array_key_exists("RevisionNum",$metadata)) { + if ($metadata["RevisionNum"] >= "10403") { // new method, RevisionNum is incremental + $result["vCode"] = 432; + } + } + if (array_key_exists("ConfigureEnabled",$metadata)) { + $result["futures"] = implode(';', $metadata["ConfigureEnabled"]); + } + } else { + die_freepbx("Version information could not be retrieved from chan-sccp, via astman::SCCPConfigMetaData"); + } + return $result; +} + public function sccp_list_keysets() { $ast_out = $this->sccp_core_comands(array('cmd' => 'get_softkey')); @@ -228,6 +310,24 @@ class srvinterface { } return $ast_key; } - +/* + * Replace sccp_core_comands($params = array()) { + */ + + private function astman_retrieveJSFromMetaData($segment = "") { + global $astman; + $params = array(); + if ($segment != "") { + $params["Segment"] = $segment; + } + $response = $astman->send_request('SCCPConfigMetaData', $params); + if ($response["Response"] == "Success") { + //outn(_("JSON-content:").$response["JSON"]); + $decode=json_decode($response["JSON"], true); + return $decode; + } else { + return false; + } + } } \ No newline at end of file diff --git a/assets/js/sccp_manager.js b/assets/js/sccp_manager.js index ba50225..ea56346 100644 --- a/assets/js/sccp_manager.js +++ b/assets/js/sccp_manager.js @@ -304,6 +304,38 @@ $(document).ready(function () { }); }); + + $('.sccp_button_hide').each(function () { // On page create !! + var dev_id = $(this).data('vhide'); + var dev_class = $(this).data('clhide'); + var dev_val = $(this).val(); + var dev_state = $(this).attr('checked'); + if (dev_state == 'checked'){ + $(dev_class).each(function () { + if (dev_val != dev_id) { + $(this).removeClass('hidden'); + $(this).removeAttr('hidden') + } else { + $(this).addClass('hidden'); + } + }); + } + }); + + $('.sccp_button_hide').on('click', function (e) { + var dev_id = $(this).data('vhide'); + var dev_class = $(this).data('clhide'); + var dev_val = $(this).val(); + $(dev_class).each(function () { + if (dev_val != dev_id) { + $(this).removeClass('hidden'); + $(this).removeAttr('hidden') + } else { + $(this).addClass('hidden'); + } + }); + }); + // ----------------------- TEST Validate ---------------- $('.need-validate').on('change', function (e) { var dev_class = $(this).attr('class'); @@ -314,17 +346,15 @@ $(document).ready(function () { // confirm(dev_id); }); -// $('.sccp_test').on('click', function (e) { -// var dev_id = []; + $('.sccp_test').on('click', function (e) { + var dev_id = []; // $('table').bootstrapTable('getSelections').forEach(function (entry) { // dev_id.push(entry['name']); // }); -// dv = dev_id; -// confirm(dv); -// }); + dv = dev_id; + confirm(dv); + }); // ----------------------- TEST ---------------- - - $('.test').on('click', function (e) { var dev_fld = ['onhook', 'connected', 'onhold', 'ringin', 'offhook', 'conntrans', 'digitsfoll', 'connconf', 'ringout', 'offhookfeat', 'onhint', 'onstealable', 'holdconf', 'uriaction']; diff --git a/conf/Sccp.class.php b/conf/Sccp.class.php index 148aafa..1896bc1 100644 --- a/conf/Sccp.class.php +++ b/conf/Sccp.class.php @@ -22,7 +22,7 @@ class Sccp extends \FreePBX\modules\Core\Driver { "prettyName" => _("Sccp Custom Driver"), "shortName" => "SCCP", "description" => _("Sccp Device"), - "sccp_driver_ver" => "11.1" + "sccp_driver_ver" => "11.2" ); } @@ -69,7 +69,7 @@ class Sccp extends \FreePBX\modules\Core\Driver { } public function delDevice($id) { - $sql = "DELETE FROM sccpline WHERE id = ?"; + $sql = "DELETE FROM sccpline WHERE name = ?"; $sth = $this->database->prepare($sql); $sth->execute(array($id)); return true; @@ -78,11 +78,11 @@ class Sccp extends \FreePBX\modules\Core\Driver { public function getDevice($id) { $sccp_line = array(); - $sql = "SELECT id"; + $sql = "SELECT name as id"; foreach($this->data_fld as $key => $val) { $sql .= ',`'. $key .'` as '.$val; } - $sql .= " FROM sccpline WHERE id = ?"; + $sql .= " FROM sccpline WHERE name = ?"; $sth = $this->database->prepare($sql); $result = array(); $tech = array(); diff --git a/conf/Sccp.class.php.v11 b/conf/Sccp.class.php.v11 index 17d6c54..2a2418e 100644 --- a/conf/Sccp.class.php.v11 +++ b/conf/Sccp.class.php.v11 @@ -10,7 +10,7 @@ class Sccp extends \FreePBX\modules\Core\Driver { "callgroup"=>'callgroup',"pickupgroup"=>'pickupgroup', "transfer" => 'transfer', "echocancel" => 'echocancel', "language" => 'language', "description" => 'callerid', - "cid_num" => 'cid_num', "cid_name" => 'label', "mailbox" => 'description', + "cid_num" => 'cid_num', "cid_name" => 'label', "mailbox" => 'mailbox', "musicclass" => 'musicclass', "dnd" => 'dnd', "silencesuppression" => 'silencesuppression', "secondary_dialtone_digits" => 'secondary_dialtone_digits', "secondary_dialtone_tone" => 'secondary_dialtone_tone', @@ -29,7 +29,7 @@ class Sccp extends \FreePBX\modules\Core\Driver { "prettyName" => _("Sccp Custom Driver"), "shortName" => "SCCP", "description" => _("Sccp Device"), - "sccp_driver_ver" => "11.1" + "sccp_driver_ver" => "11.2" ); } public function addDevice1($id, $settings) { @@ -43,11 +43,12 @@ class Sccp extends \FreePBX\modules\Core\Driver { } public function addDevice($id, $settings) { - $add_fld = array ("name"=>'label',"outboundcid"=>'cid_num',"langcode"=>'language',"extdisplay"=>'description'); + $add_fld = array ("name"=>'label',"outboundcid"=>'cid_num',"langcode"=>'language',"extdisplay"=>'description','devinfo_mailbox'=>'mailbox'); // print_r($_REQUEST); // echo '

'; // die(print_r($settings)); $settings['cid_num']['value']=''; + $settings['mailbox']['value']= ''; if (isset($_REQUEST)){ foreach($add_fld as $key => $val) { if (!empty($_REQUEST[$key])){ @@ -58,7 +59,16 @@ class Sccp extends \FreePBX\modules\Core\Driver { if (empty($settings['cid_num']['value'])) { $settings['cid_num']['value']= $id; } - $sql = 'INSERT INTO sccpline (name, id'; + + if (!empty($_REQUEST['vm']) && ($_REQUEST['vm'] =='enabled')){ // mailbox + if (empty($settings['mailbox']['value'])) { + $settings['mailbox']['value']= $id; + } + } + +// die(print_r($settings)); + + $sql = 'REPLACE INTO sccpline (name, id'; $sqlv = 'values ("'.$id.'", "'.$id.'"'; foreach($this->data_fld as $key => $val) { switch ($key) { @@ -84,13 +94,15 @@ class Sccp extends \FreePBX\modules\Core\Driver { } } $sql .= ") ".$sqlv.");"; +// die(print_r($sql)); $sth = $this->database->prepare($sql); $sth->execute(); return true; } public function delDevice($id) { - $sql = "DELETE FROM sccpline WHERE id = ?"; +// $sql = "DELETE FROM sccpline WHERE id = ?"; + $sql = "DELETE FROM sccpline WHERE name = ?"; $sth = $this->database->prepare($sql); $sth->execute(array($id)); return true; @@ -99,11 +111,12 @@ class Sccp extends \FreePBX\modules\Core\Driver { public function getDevice($id) { $sccp_line = array(); - $sql = "SELECT id"; + $sql = "SELECT name as id"; foreach($this->data_fld as $key => $val) { $sql .= ',`'. $key .'` as '.$val; } - $sql .= " FROM sccpline WHERE id = ?"; +// $sql .= " FROM sccpline WHERE id = ?"; + $sql .= " FROM sccpline WHERE name = ?"; $sth = $this->database->prepare($sql); $result = array(); $tech = array(); @@ -114,6 +127,12 @@ class Sccp extends \FreePBX\modules\Core\Driver { $tech['dial']='SCCP/'.$id; } catch(\Exception $e) {} +// print_r($tech); +// echo '

'; +// print_r($sql); +// die(print_r($id)); +// echo '

'; + return $tech; } @@ -147,6 +166,10 @@ class Sccp extends \FreePBX\modules\Core\Driver { public function getDefaultDeviceSettings($id, $displayname, &$flag) { $dial = 'SCCP'; $settings = array( + "mailbox" => array( + "value" => "", + "flag" => $flag++ + ), "incominglimit" => array( "value" => "2", "flag" => $flag++ @@ -220,6 +243,8 @@ class Sccp extends \FreePBX\modules\Core\Driver { // Assigned DID/CID $named_group = $this->getNamedGroup(); $tmparr = array(); + $tt = _("Name or id of lincked maibox"); + $tmparr['mailbox'] = array('prompttext' => _('Mailbox'), 'value' => '', 'tt' => $tt, 'level' => 1, 'section' => $section); $tt = _("The SCCP channel number for this port. If you plaining to use this line as 'Shared' or use on several devices - leave this field blank or set limit to 10 calls."); // $tmparr['incominglimit'] = array('prompttext' => _('Incoming Call Limit'), 'value' => '2', 'tt' => $tt, 'level' => 0, 'jsvalidation' => 'isEmpty()', 'failvalidationmsg' => $msgInvalidChannel); // $tmparr['incominglimit'] = array('prompttext' => _('Incoming Call Limit'), 'value' => '', 'tt' => $tt, 'level' => 1, 'section' => $section, 'category' => 'general'); diff --git a/conf/sccpgeneral.xml.v11 b/conf/sccpgeneral.xml.v11 index db5fd75..54b124b 100644 --- a/conf/sccpgeneral.xml.v11 +++ b/conf/sccpgeneral.xml.v11 @@ -800,6 +800,7 @@ and open the template in the editor. Base Version before all crash :-) directed_pickup yes + no Enable Pickup function to direct pickup an extension. Default is On @@ -808,6 +809,7 @@ and open the template in the editor. Base Version before all crash :-) conf_allow yes + no Allow the use of conference @@ -815,6 +817,7 @@ and open the template in the editor. Base Version before all crash :-) + pickup_hide directed_pickup_context @@ -863,6 +866,7 @@ and open the template in the editor. Base Version before all crash :-) + conf_hide conf_play_general_announce diff --git a/install.php b/install.php index c4c011a..733d163 100644 --- a/install.php +++ b/install.php @@ -8,6 +8,17 @@ global $db; global $amp_conf; global $astman; global $version; +global $srvinterface; + + + +$class = "\\FreePBX\\Modules\\Sccp_manager\\srvinterface"; +if(!class_exists($class,false)) { + include(__DIR__."/Sccp_manager.inc/srvinterface.class.php"); +} +if(class_exists($class,false)) { + $srvinterface = new $class(); +} // // Helper function to retrieve SCCPConfigMetaData via ASTMan @@ -78,6 +89,7 @@ $db_config_v0 = array( 'musicclass' =>array('def_modify' => "default"), 'echocancel' =>array('def_modify' => "on"), 'silencesuppression' =>array('def_modify' => "off"), + 'id' =>array('create' => 'VARCHAR( 20 ) NULL DEFAULT NULL', 'modify' => "VARCHAR(20)", 'def_modify' =>"NULL"), 'dnd' =>array('create' => 'VARCHAR( 12 ) DEFAULT "reject" AFTER `amaflags`', 'modify' => "VARCHAR(12)", 'def_modify' =>"reject") ) ); @@ -198,8 +210,24 @@ function CheckAsteriskVersion() { return $ver_compatible; } -function CheckChanSCCPVersion($astman) { - global $db_config, $db_config_v0, $db_config_v3; +function CheckChanSCCPVersion() { + global $db_config, $db_config_v0, $db_config_v3, $srvinterface,$astman; + if (!$astman) { + ie_freepbx('No asterisk manager connection provided!. Installation Failed'); + } + $sccp_ver = $srvinterface->get_comatable_sccp(); + outn("
  • " . _("Sccp model Version : ") . $sccp_ver . "
  • "); + if ($sccp_ver >= 11) { + $db_config = $db_config_v3; + } else { + $db_config = $db_config_v0; + } + return $sccp_ver; +} + +/* +function CheckChanSCCPVersion() { + global $db_config, $db_config_v0, $db_config_v3, $astman; if (!$astman) { ie_freepbx('No asterisk manager connection provided!. Installation Failed'); } @@ -226,28 +254,17 @@ function CheckChanSCCPVersion($astman) { $sccp_ver = 430; } } - - /* - if (array_key_exists("Branch",$metadata)) { - if ($metadata["Branch"] == "master") { - - } else - if ($metadata["Branch"] == "develop") { - + if (array_key_exists("Revision",$metadata)) { // old method + if (base_convert($metadata["Revision"],16,10) == base_convert('702487a',16,10)) { // hash values are random, not incrementa + $sccp_ver = 431; + $db_config = $db_config_v3; } } - */ - - /* Revision got replaced by RevisionHash in 10404 (using the hash does not work)*/ - if (array_key_exists("Revision",$metadata) && // old method - (base_convert($metadata["Revision"],16,10) == base_convert('702487a',16,10)) // hash values are random, not incremental - ) { - $sccp_ver = 431; - $db_config = $db_config_v3; - } else - if (array_key_exists("RevisionNum",$metadata) && $metadata["RevisionNum"] >= "10403") { // new method, RevisionNum is incremental - $sccp_ver = 432; - $db_config = $db_config_v3; + if (array_key_exists("RevisionNum",$metadata)) { + if ($metadata["RevisionNum"] >= "10403") { // new method, RevisionNum is incremental + $sccp_ver = 432; + $db_config = $db_config_v3; + } } } else { die_freepbx("Version information could not be retrieved from chan-sccp, via astman::SCCPConfigMetaData"); @@ -255,7 +272,8 @@ function CheckChanSCCPVersion($astman) { outn("
  • " . _("Sccp Version : ") . $sccp_ver . "
  • "); return $sccp_ver; } - +*/ + function InstallDB_sccpsettings() { global $db; outn("
  • " . _("Creating sccpsettings table...") . "
  • "); @@ -483,7 +501,7 @@ function InstallDB_CreateSccpDeviceConfigView($sccp_ver) { CheckSCCPManagerDBTables($table_req); CheckPermissions(); CheckAsteriskVersion(); -$sccp_ver = CheckChanSCCPVersion($astman); +$sccp_ver = CheckChanSCCPVersion(); InstallDB_sccpsettings(); InstallDB_sccpdevmodel(); InstallDB_updateSchema($db_config); @@ -496,4 +514,5 @@ outn("
    "); // $ss->save_submit($request); // $ss->sccp_create_sccp_init(); // $ss->sccp_db_save_setting(); +// //} \ No newline at end of file diff --git a/views/formShow.php b/views/formShow.php index c09e7b8..78feeb8 100644 --- a/views/formShow.php +++ b/views/formShow.php @@ -55,12 +55,16 @@ $items = $itm -> children(); //print_r($syslangs); //print_r($moh_list); if ($h_show==1) { + $sec_class =''; + if (!empty($items ->class)){ + $sec_class = (string)$items ->class; + } ?>

    label) ?>

    -
    +
    ">label);?>
    -
    +
    default)) { $res_v = 'no'; } else { @@ -259,9 +264,11 @@ foreach ($items as $child) { $res_v = (string)$fvalues[$res_n]['data']; } } - + if (!empty($child->option_hide)) { + $opt_hide = ' class="sccp_button_hide" data-vhide="'.$child->option_hide.'" data-clhide="'.$child->option_hide['class'].'" '; + } foreach ($child->xpath('button') as $value) { - echo ''; + echo ''; echo ''; $i++; } diff --git a/views/server.setting.php b/views/server.setting.php index 4a76783..88cc977 100644 --- a/views/server.setting.php +++ b/views/server.setting.php @@ -8,11 +8,13 @@ // print_r($this->sccpvalues['sccp_comatable']); // print_r($this->sccpvalues); // $id_name = 'SEP000A8A5C5F25'; -// $dev_data = $this->srvinterface->sccp_getdevice_info($id_name); - -// print_r($dev_data); + print_r($this->srvinterface->getChanSCCPVersion()); + print_r('
    '); + print_r($this->srvinterface->getCoreSCCPVersion()); // $lang_arr = $this->extconfigs->getextConfig('sccp_lang','sk_SK'); - //print_r($this->sccpvalues); + print_r('
    '); + print_r($this->srvinterface->get_comatable_sccp()); + print_r('
    '); ?>