Begin resample Sccp_manager

few Bugs, no Doc, maybe something is not working 16.10.2017 
    Fix mail box, sccp driver
This commit is contained in:
PhantomVl 2017-10-16 22:34:40 +03:00
parent ec5f214555
commit 6b68cba0ea
9 changed files with 267 additions and 75 deletions

View file

@ -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,21 +90,26 @@ 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
$this->init_sccp_path();

View file

@ -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($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;
}
}
}

View file

@ -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'];

View file

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

View file

@ -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 '<br><br>';
// 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 '<br><br>';
// print_r($sql);
// die(print_r($id));
// echo '<br><br>';
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');

View file

@ -800,6 +800,7 @@ and open the template in the editor. Base Version before all crash :-)
</item>
<item type="IS" id="8" seq="99"><name>directed_pickup</name> <label>Pickup/Gpickup</label>
<default>yes</default>
<option_hide class=".pickup_hide">no</option_hide>
<button value="yes">On</button>
<button value="no">Off</button>
<help>Enable Pickup function to direct pickup an extension. Default is On</help>
@ -808,6 +809,7 @@ and open the template in the editor. Base Version before all crash :-)
<name>conf_allow</name>
<label>Conference</label>
<default>yes</default>
<option_hide class=".conf_hide">no</option_hide>
<button value="yes">Yes</button>
<button value="no">No</button>
<help>Allow the use of conference</help>
@ -815,6 +817,7 @@ and open the template in the editor. Base Version before all crash :-)
</page_group>
<page_group name="sccp_hw_dev_pickup"><label>Pickup</label>
<class>pickup_hide</class>
<item type="IE" id="10" seq="99"><label>Context</label>
<input>
<name>directed_pickup_context</name>
@ -863,6 +866,7 @@ and open the template in the editor. Base Version before all crash :-)
</page_group>
<page_group name="sccp_hw_dev_conference">
<class>conf_hide</class>
<label>Conference</label>
<item type="IS" id="2" seq="99">
<name>conf_play_general_announce</name>

View file

@ -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("<li>" . _("Sccp model Version : ") . $sccp_ver . "</li>");
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,6 +272,7 @@ function CheckChanSCCPVersion($astman) {
outn("<li>" . _("Sccp Version : ") . $sccp_ver . "</li>");
return $sccp_ver;
}
*/
function InstallDB_sccpsettings() {
global $db;
@ -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("<br>");
// $ss->save_submit($request);
// $ss->sccp_create_sccp_init();
// $ss->sccp_db_save_setting();
//
//}

View file

@ -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;
}
?>
<div class="section-title" data-for="<?php echo $npref.$itm['name'];?>">
<h3><i class="fa fa-minus"></i><?php echo _($items ->label) ?></h3>
</div>
<div class="section" data-id="<?php echo $npref.$itm['name'];?>">
<div class="section <?php echo $sec_class;?>" data-id="<?php echo $npref.$itm['name'];?>">
<?php
}
@ -242,10 +246,11 @@ foreach ($items as $child) {
<label class="control-label" for="<?php echo $res_id; ?>"><?php echo _($child->label);?></label>
<i class="fa fa-question-circle fpbx-help-icon" data-for="<?php echo $res_id; ?>"></i>
</div>
<div class="col-md-9 radioset">
<div class="col-md-9 radioset " data-hide="on">
<?php
$i = 0;
// $res_v = 'no';
$opt_hide = '';
if (empty($child->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 '<input type="radio" name="' . $res_id . '" id="' . $res_id. '_' . $i .'" value="' . $value[@value] . '"' . (strtolower((string)$value[@value]) == strtolower($res_v) ? " checked" : "") . '>';
echo '<input type="radio" name="' . $res_id . '" id="' . $res_id. '_' . $i .'" value="' . $value[@value] . '"' . (strtolower((string)$value[@value]) == strtolower($res_v) ? " checked" : "") . $opt_hide.'>';
echo '<label for="' . $res_id. '_' . $i . '">' . _($value) . '</label>';
$i++;
}

View file

@ -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('<br>');
print_r($this->srvinterface->getCoreSCCPVersion());
// $lang_arr = $this->extconfigs->getextConfig('sccp_lang','sk_SK');
//print_r($this->sccpvalues);
print_r('<br>');
print_r($this->srvinterface->get_comatable_sccp());
print_r('<br>');
?>