diff --git a/Sccp_manager.class.php b/Sccp_manager.class.php
index 6848920..a44940d 100644
--- a/Sccp_manager.class.php
+++ b/Sccp_manager.class.php
@@ -10,11 +10,11 @@
// http://chan-sccp-b.sourceforge.net/doc/_howto.xhtml#nf_adhoc_plar
// https://www.cisco.com/c/en/us/td/docs/voice_ip_comm/cuipph/all_models/xsi/9-1-1/CUIP_BK_P82B3B16_00_phones-services-application-development-notes/CUIP_BK_P82B3B16_00_phones-services-application-development-notes_chapter_011.html
// https://www.cisco.com/c/en/us/td/docs/voice_ip_comm/cuipph/7960g_7940g/sip/4_4/english/administration/guide/ver4_4/sipins44.html
+// http://usecallmanager.nz/
/* !TODO!:
* + Cisco Format Mac
* + Model Information
- * + Device Right Menu
-
+ * + Device Right Menu
@@ -38,14 +38,15 @@
* + Make Var elements from separate class
* + To make creating XML files in a separate class
* + Add Switch to select XML schema (display)
- * - Bootstrap encodeURI(row['type']) ???????
- * - Check Time zone ....
* + SRST Config
+ * + secondary_dialtone_digits = "" line config
+ * + secondary_dialtone_tone = 0x22 line config
+ * - deviceSecurityMode http://usecallmanager.nz//itl-file-tlv.html
+ * - transportLayerProtocol http://usecallmanager.nz//itl-file-tlv.html
+ * - Check Time zone ....
* - Failover config
* + Auto Addons!
* + DND Mode
- * + secondary_dialtone_digits = "" line config
- * + secondary_dialtone_tone = 0x22 line config
* - support kv-store ?????
* + Shared Line
* - bug Soft key set (empty keysets )
@@ -98,7 +99,7 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO {
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_metainfo = array();
+ public $sccp_metainfo = array();
private $cnf_wr = null;
public $sccppath = array();
public $sccpvalues = array();
@@ -238,7 +239,8 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO {
// $this->sccpvalues[] = array('keyword' => (string)$child->name, 'data' =>(string)$child-> default,'type'=>'0');
}
}
- if ($child['type'] == 'SLD' || $child['type'] == 'SLS' || $child['type'] == 'SLT' || $child['type'] == 'SL' || $child['type'] == 'SLM' || $child['type'] == 'SLZ' || $child['type'] == 'SLZN' || $child['type'] == 'SLA') {
+// if ($child['type'] == 'SLD' || $child['type'] == 'SLS' || $child['type'] == 'SLT' || $child['type'] == 'SL' || $child['type'] == 'SLM' || $child['type'] == 'SLZ' || $child['type'] == 'SLZN' || $child['type'] == 'SLA') {
+ if (in_array($child['type'], array('SLD','SLS','SLT','SL','SLM','SLZ','SLZN','SLA') )) {
if (empty($child->value)) {
$datav = (string) $child->default;
} else {
@@ -366,7 +368,7 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO {
$request = $_REQUEST;
$action = !empty($request['action']) ? $request['action'] : '';
if ($this->sccpvalues['sccp_compatible']['data'] >= '433') {
- $this->sccp_metainfo = $this->srvinterface->getеtestChanSCCP_GlablsInfo('general');
+// $this->sccp_metainfo = $this->srvinterface->getеtestChanSCCP_GlablsInfo('general');
}
if (!empty($this->sccpvalues['displayconfig'])) {
@@ -497,7 +499,7 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO {
$action = !empty($request['action']) ? $request['action'] : '';
$inputform = !empty($request['tech_hardware']) ? $request['tech_hardware'] : '';
if ($this->sccpvalues['sccp_compatible']['data'] >= '433') {
- $this->sccp_metainfo = $this->srvinterface->getеtestChanSCCP_GlablsInfo('device');
+// $this->sccp_metainfo = $this->srvinterface->getеtestChanSCCP_GlablsInfo('device');
}
// print_r($inputform);
@@ -524,6 +526,20 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO {
break;
+ case r_user:
+ $this->pagedata = array(
+ "general" => array(
+ "name" => _("Rouming User configuration"),
+ "page" => 'views/form.addruser.php'
+ ),
+ "buttons" => array(
+ "name" => _("Device Buttons"),
+ "page" => 'views/form.buttons.php'
+ ),
+ );
+
+ break;
+
default:
$this->pagedata = array(
"general" => array(
@@ -590,6 +606,7 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO {
case 'backupsettings':
case 'savesettings':
case 'save_hardware':
+ case 'save_ruser':
case 'save_dialplan_template':
case 'delete_hardware':
case 'getPhoneGrid':
@@ -644,6 +661,12 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO {
return $this->save_hw_phone($request);
break;
+ case 'save_ruser':
+// $res = $request;
+ $res = $this->save_rouming_users($request);
+ return array('status' => true, 'search' => '?display=sccp_phone', 'hash' => 'general');
+ return array('status' => false, 'message' => print_r($res));
+ break;
/* !TODO!: -TODO-: dialplan templates should be removed (only required for very old devices (like ATA) */
// ------------------------------- Old deviece suport - In the development---
case 'save_dialplan_template':
@@ -844,8 +867,23 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO {
case 'getExtensionGrid':
$result = $this->dbinterface->get_db_SccpTableData('SccpExtension');
if (empty($result)) {
- $result = array();
+ return array();
}
+/* $res_info = $this->aminterface->core_list_all_exten('exten');
+ if (!empty($res_info)) {
+ foreach ($result as $key => $value) {
+ $tpm_info = $res_info[$value['name']];
+ if (!empty($tpm_info)) {
+ $result[$key]['line_status'] = $tpm_info['status'];
+ $result[$key]['line_statustext'] = $tpm_info['statustext'];
+ } else {
+ $result[$key]['line_status'] = '';
+ $result[$key]['line_statustext'] = '';
+ }
+ }
+ }
+ *
+ */
return $result;
break;
case 'getPhoneGrid':
@@ -911,7 +949,7 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO {
readfile($filename);
unlink($filename);
-
+
// return array('status' => false, 'message' => $result);
// return $result;
break;
@@ -929,6 +967,111 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO {
* * Save Hardware Device Information to Db + ???? Create / update XML Profile
*
*/
+ function get_buttons_phone($get_settings, $ref_id = '', $ref_type = 'sccpdevice') {
+// Get Model Buttons info
+ $res = array();
+
+ $lines_list = $this->dbinterface->get_db_SccpTableData('SccpExtension');
+ $max_btn = ((!empty($get_settings['buttonscount']) ? $get_settings['buttonscount'] : 100));
+ $last_btn = $max_btn;
+ for ($it = $max_btn; $it >= 0; $it--) {
+ if (!empty($get_settings['button' . $it . '_type'])) {
+ $last_btn = $it;
+ $btn_t = $get_settings['button' . $it . '_type'];
+ if ($btn_t != 'empty') {
+ break;
+ }
+ }
+ }
+
+ for ($it = 0; $it <= $last_btn; $it++) {
+ if (!empty($get_settings['button' . $it . '_type'])) {
+ $btn_t = $get_settings['button' . $it . '_type'];
+
+ $btn_n = '';
+ $btn_opt = '';
+ if ($it == 0) {
+ $btn_opt = 'default';
+ }
+ switch ($btn_t) {
+ case 'feature':
+ $btn_f = $get_settings['button' . $it . '_feature'];
+// $btn_opt = (empty($get_settings['button' . $it . '_fvalue'])) ? '' : $get_settings['button' . $it . '_fvalue'];
+ $btn_n = (empty($get_settings['button' . $it . '_flabel'])) ? $def_feature[$btn_f]['name'] : $get_settings['button' . $it . '_flabel'];
+ $btn_opt = $btn_f;
+ if (!empty($def_feature[$btn_f]['value'])) {
+ if (empty($get_settings['button' . $it . '_fvalue'])) {
+ $btn_opt .= ',' . $def_feature[$btn_f]['value'];
+ } else {
+ $btn_opt .= ',' . $get_settings['button' . $it . '_fvalue'];
+ }
+ }
+ break;
+ case 'monitor':
+ $btn_t = 'speeddial';
+ $btn_opt = (string) $get_settings['button' . $it . '_line'];
+ $db_res = $this->dbinterface->get_db_SccpTableData('SccpExtension', array('name' => $btn_opt));
+ $btn_n = $db_res[0]['label'];
+ $btn_opt .= ',' . $btn_opt . $this->hint_context['default'];
+ break;
+ case 'speeddial':
+ if (!empty($get_settings['button' . $it . '_input'])) {
+ $btn_n = $get_settings['button' . $it . '_input'];
+ }
+ if (!empty($get_settings['button' . $it . '_phone'])) {
+ $btn_opt = $get_settings['button' . $it . '_phone'];
+ if (empty($btn_n)) {
+ $btn_n = $btn_opt;
+ }
+ }
+
+ if (!empty($get_settings['button' . $it . '_hint'])) {
+ if ($get_settings['button' . $it . '_hint'] == "hint") {
+ if (empty($btn_n)) {
+ $btn_t = 'line';
+ $btn_n = $get_settings['button' . $it . '_hline'] . '!silent';
+ $btn_opt = '';
+ } else {
+// $btn_opt .= ',' . $get_settings['button' . $it . '_hline'] . $this->hint_context['default'];
+ $btn_opt .= ',' . $get_settings['button' . $it . '_hline'];
+ }
+ }
+ }
+ break;
+ case 'adv.line':
+ $btn_t = 'line';
+ $btn_n = (string) $get_settings['button' . $it . '_line'];
+ $btn_n .= '@' . (string) $get_settings['button' . $it . '_advline'];
+ $btn_opt = (string) $get_settings['button' . $it . '_advopt'];
+
+ break;
+ case 'line':
+ case 'silent':
+ if (isset($get_settings['button' . $it . '_line'])) {
+ $btn_n = (string) $get_settings['button' . $it . '_line'];
+ if ($it > 0) {
+ if ($btn_t == 'silent') {
+ $btn_n .= '!silent';
+ $btn_t = 'line';
+ }
+ }
+ } else {
+ $btn_t = 'empty';
+ $btn_n = '';
+ }
+ break;
+ case 'empty':
+ $btn_t = 'empty';
+ break;
+ }
+ if (!empty($btn_t)) {
+ $res[] = array('ref' => $ref_id, 'reftype' => $ref_type, 'instance' => (string) ($it + 1), 'type' => $btn_t, 'name' => $btn_n, 'options' => $btn_opt);
+ }
+ }
+ }
+ return $res;
+
+ }
function save_hw_phone($get_settings, $validateonly = false) {
$hdr_prefix = 'sccp_hw_';
@@ -1055,105 +1198,8 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO {
$this->dbinterface->sccp_save_db("sccpdevice", $save_settings, 'replace');
// Get Model Buttons info
- $lines_list = $this->dbinterface->get_db_SccpTableData('SccpExtension');
- $max_btn = ((!empty($get_settings['buttonscount']) ? $get_settings['buttonscount'] : 100));
- $last_btn = $max_btn;
- for ($it = $max_btn; $it >= 0; $it--) {
- if (!empty($get_settings['button' . $it . '_type'])) {
- $last_btn = $it;
- $btn_t = $get_settings['button' . $it . '_type'];
- if ($btn_t != 'empty') {
- break;
- }
- }
- }
-
- for ($it = 0; $it <= $last_btn; $it++) {
- if (!empty($get_settings['button' . $it . '_type'])) {
- $btn_t = $get_settings['button' . $it . '_type'];
-
- $btn_n = '';
- $btn_opt = '';
- if ($it == 0) {
- $btn_opt = 'default';
- }
- switch ($btn_t) {
- case 'feature':
- $btn_f = $get_settings['button' . $it . '_feature'];
-// $btn_opt = (empty($get_settings['button' . $it . '_fvalue'])) ? '' : $get_settings['button' . $it . '_fvalue'];
- $btn_n = (empty($get_settings['button' . $it . '_flabel'])) ? $def_feature[$btn_f]['name'] : $get_settings['button' . $it . '_flabel'];
- $btn_opt = $btn_f;
- if (!empty($def_feature[$btn_f]['value'])) {
- if (empty($get_settings['button' . $it . '_fvalue'])) {
- $btn_opt .= ',' . $def_feature[$btn_f]['value'];
- } else {
- $btn_opt .= ',' . $get_settings['button' . $it . '_fvalue'];
- }
- }
- break;
- case 'monitor':
- $btn_t = 'speeddial';
- $btn_opt = (string) $get_settings['button' . $it . '_line'];
- $db_res = $this->dbinterface->get_db_SccpTableData('SccpExtension', array('name' => $btn_opt));
- $btn_n = $db_res[0]['label'];
- $btn_opt .= ',' . $btn_opt . $this->hint_context['default'];
- break;
- case 'speeddial':
- if (!empty($get_settings['button' . $it . '_input'])) {
- $btn_n = $get_settings['button' . $it . '_input'];
- }
- if (!empty($get_settings['button' . $it . '_phone'])) {
- $btn_opt = $get_settings['button' . $it . '_phone'];
- if (empty($btn_n)) {
- $btn_n = $btn_opt;
- }
- }
-
- if (!empty($get_settings['button' . $it . '_hint'])) {
- if ($get_settings['button' . $it . '_hint'] == "hint") {
- if (empty($btn_n)) {
- $btn_t = 'line';
- $btn_n = $get_settings['button' . $it . '_hline'] . '!silent';
- $btn_opt = '';
- } else {
-// $btn_opt .= ',' . $get_settings['button' . $it . '_hline'] . $this->hint_context['default'];
- $btn_opt .= ',' . $get_settings['button' . $it . '_hline'];
- }
- }
- }
- break;
- case 'adv.line':
- $btn_t = 'line';
- $btn_n = (string) $get_settings['button' . $it . '_line'];
- $btn_n .= '@' . (string) $get_settings['button' . $it . '_advline'];
- $btn_opt = (string) $get_settings['button' . $it . '_advopt'];
-
- break;
- case 'line':
- case 'silent':
- if (isset($get_settings['button' . $it . '_line'])) {
- $btn_n = (string) $get_settings['button' . $it . '_line'];
- if ($it > 0) {
- if ($btn_t == 'silent') {
- $btn_n .= '!silent';
- $btn_t = 'line';
- }
- }
- } else {
- $btn_t = 'empty';
- $btn_n = '';
- }
- break;
- case 'empty':
- $btn_t = 'empty';
- break;
- }
- if (!empty($btn_t)) {
- $save_buttons[] = array('device' => $name_dev, 'instance' => (string) ($it + 1), 'type' => $btn_t, 'name' => $btn_n, 'options' => $btn_opt);
- }
- }
- }
-
+ $save_buttons = $this-> get_buttons_phone($get_settings,$name_dev, 'sccpdevice');
+
// Sace Buttons config
$this->dbinterface->sccp_save_db("sccpbuttons", $save_buttons, $update_hw, '', $name_dev);
@@ -1259,6 +1305,111 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO {
return $save_settings;
}
+
+
+ function save_rouming_users($get_settings, $validateonly = false) {
+ $hdr_prefix = 'sccp_ru_';
+ $hdr_arprefix = 'sccp_ru-ar_';
+
+ $save_buttons = array();
+ $save_settings = array();
+/*
+ $def_feature = array('parkinglot' => array('name' => 'P.slot', 'value' => 'default'),
+ 'devstate' => array('name' => 'Coffee', 'value' => 'coffee'),
+ 'monitor' => array('name' => 'Record Calls', 'value' => '')
+ );
+ *
+ */
+ $name_dev = '';
+ $db_field = $this->dbinterface->get_db_SccpTableData("get_colums_sccpusers");
+// $hw_id = (empty($get_settings['sccp_deviceid'])) ? 'new' : $get_settings['sccp_deviceid'];
+// $update_hw = ($hw_id == 'new') ? 'update' : 'clear';
+ $hw_prefix = 'SEP';
+ $name_dev = $get_settings[$hdr_prefix . 'id'];
+
+ foreach ($db_field as $data) {
+ $key = (string) $data['Field'];
+ $value = "";
+ switch ($key) {
+ case 'name':
+ $value = $name_dev;
+ break;
+ case '_hwlang':
+ if (empty($get_settings[$hdr_prefix . 'netlang']) || empty($get_settings[$hdr_prefix . 'devlang'])) {
+ $value = 'null';
+ } else {
+ $value = $get_settings[$hdr_prefix . 'netlang'] . ':' . $get_settings[$hdr_prefix . 'devlang'];
+ }
+ break;
+ default :
+ if (!empty($get_settings[$hdr_prefix . $key])) {
+ $value = $get_settings[$hdr_prefix . $key];
+ }
+ if (!empty($get_settings[$hdr_arprefix . $key])) {
+ $arr_data = '';
+ $arr_clear = FALSE;
+ foreach ($get_settings[$hdr_arprefix . $key] as $vkey => $vval) {
+ $tmp_data = '';
+ foreach ($vval as $vkey => $vval) {
+ switch ($vkey) {
+ case 'inherit':
+ if ($vval == 'on') {
+ $arr_clear = TRUE;
+ // Злобный ХАК
+ if ($key == 'permit') {
+ $save_settings['deny'] = 'NONE';
+ }
+ }
+ break;
+ case 'internal':
+ if ($vval == 'on') {
+ $tmp_data .= 'internal;';
+ }
+ break;
+ default:
+ $tmp_data .= $vval . '/';
+ break;
+ }
+ }
+ if (strlen($tmp_data) > 2) {
+ while (substr($tmp_data, -1) == '/') {
+ $tmp_data = substr($tmp_data, 0, -1);
+ }
+ $arr_data .= $tmp_data . ';';
+ }
+ }
+ while (substr($arr_data, -1) == ';') {
+ $arr_data = substr($arr_data, 0, -1);
+ }
+ if ($arr_clear) {
+ $value = 'NONE';
+ } else {
+ $value = $arr_data;
+ }
+ }
+ }
+ if (!empty($value)) {
+ $save_settings[$key] = $value;
+ }
+ }
+// Save / Updade Base
+// return $save_settings;
+ // $update_hw = ($hw_id == 'new') ? 'update' : 'clear';
+
+ $this->dbinterface->sccp_save_db("sccpusers", $save_settings, 'replace', 'name');
+
+ $save_buttons = $this-> get_buttons_phone($get_settings,$name_dev, 'sccpline');
+// Sace Buttons config
+ $this->dbinterface->sccp_save_db("sccpbuttons", $save_buttons,'clear', '', $name_dev);
+ return $save_buttons;
+
+ return $save_settings;
+ }
+
+
+
+
+
public function getSccpSettingFromDB() {
$raw_data = $this->dbinterface->get_db_SccpSetting();
foreach ($raw_data as $var) {
@@ -1767,11 +1918,11 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO {
$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');
- $backup_info = $this->sccppath["tftp_path"].'/sccp_dir.info';
+ $backup_info = $this->sccppath["tftp_path"] . '/sccp_dir.info';
$result = $this->dbinterface->dump_sccp_tables($this->sccppath["tftp_path"], $amp_conf['AMPDBNAME'], $amp_conf['AMPDBUSER'], $amp_conf['AMPDBPASS']);
- $dir_info['asterisk'] = $this->find_all_files($amp_conf['ASTETCDIR']);
- $dir_info['tftpdir'] = $this-> find_all_files($this->sccppath["tftp_path"]);
+ $dir_info['asterisk'] = $this->find_all_files($amp_conf['ASTETCDIR']);
+ $dir_info['tftpdir'] = $this->find_all_files($this->sccppath["tftp_path"]);
$dir_info['driver'] = $this->FreePBX->Core->getAllDriversInfo();
$dir_info['core'] = $this->srvinterface->getSCCPVersion();
$dir_info['realtime'] = $this->srvinterface->sccp_realtime_status();
@@ -1780,23 +1931,23 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO {
$dir_info['dbinterface'] = $this->dbinterface->info();
$dir_info['XML'] = $this->xmlinterface->info();
-
+
$fh = fopen($backup_info, 'w');
$dir_str = "Begin JSON data ------------\r\n";
- fwrite($fh,$dir_str);
- fwrite($fh,json_encode($dir_info));
+ fwrite($fh, $dir_str);
+ fwrite($fh, json_encode($dir_info));
$dir_str = "\r\n\r\nBegin TEXT data ------------\r\n";
foreach ($dir_info['asterisk'] as $data) {
- $dir_str .= $data."\r\n";
+ $dir_str .= $data . "\r\n";
}
foreach ($dir_info['tftpdir'] as $data) {
- $dir_str .= $data."\r\n";
+ $dir_str .= $data . "\r\n";
}
fputs($fh, $dir_str);
fclose($fh);
-
+
$zip = new \ZipArchive();
- $filename = $result .".". gethostname().".zip";
+ $filename = $result . "." . gethostname() . ".zip";
if ($zip->open($filename, \ZIPARCHIVE::CREATE)) {
$zip->addFile($result);
$zip->addFile($backup_info);
@@ -1937,34 +2088,51 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO {
return $raw_settings;
}
- function get_hint_info($get = "all", $format_list = "all", $filter = array()) {
+ function get_hint_info($sort = true, $filter = array()) {
$res = array();
$default_hint = '@ext-local';
-// get all hints [101@ext-local] => 101@ext-local
- $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);
+
+// get all extension
+ $res = $this->aminterface->core_list_all_exten('hint', $filter);
+ if (empty($res)) {
+// Old Req get all hints
+ $tmp_data = $this->srvinterface->sccp_list_all_hints();
+ foreach ($tmp_data as $value) {
+ $res[$value] = array('key' => $value, 'exten' => before('@', $value), 'label' => $value);
+ }
}
+
// Update info from sccp_db
$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]['exten'] = $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('key' => $name_l . $default_hint, 'exten' => $name_l, 'label' => $value['label']);
}
}
+ if (!$sort) {
+ return $res;
+ }
+
+ foreach ($res as $key => $value) {
+ $data_sort[$value['exten']] = $key;
+ }
+ ksort($data_sort);
+ foreach ($data_sort as $key => $value) {
+ $res_sort[$value] = $res[$value];
+ }
+
// Update info from sip DB
/* !TODO!: Update Hint info from sip DB ??? */
- return $res;
+ return $res_sort;
}
function getIP_information2($type = '') {
- $interfaces= array();
+ $interfaces = array();
switch ($type) {
case 'ip4':
exec("/sbin/ip -4 -o addr", $result, $ret);
@@ -1983,18 +2151,16 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO {
continue;
if ($vals[2] != "inet" && $vals[2] != "inet6")
continue;
- if (preg_match("/(.+?)(?:@.+)?:$/", $vals[1], $res)) {
+ if (preg_match("/(.+?)(?:@.+)?:$/", $vals[1], $res)) {
continue;
}
- $ret = preg_match("/(\d*+.\d*+.\d*+.\d*+)[\/(\d*+)]*/", $vals[3], $ip);
-
- $interfaces[$vals[1].':'.$vals[2]] = Array('name' => $vals[1],'type' => $vals[2], 'ip' => ((empty($ip[1]) ? '' : $ip[1])));
+ $ret = preg_match("/(\d*+.\d*+.\d*+.\d*+)[\/(\d*+)]*/", $vals[3], $ip);
+
+ $interfaces[$vals[1] . ':' . $vals[2]] = Array('name' => $vals[1], 'type' => $vals[2], 'ip' => ((empty($ip[1]) ? '' : $ip[1])));
}
return $interfaces;
}
-
-
function getIP_information_old() {
$interfaces['auto'] = array('0.0.0.0', 'All', '0');
@@ -2122,5 +2288,4 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO {
}
return $result;
}
-
}
diff --git a/Sccp_manager.inc/aminterface.class.php b/Sccp_manager.inc/aminterface.class.php
new file mode 100644
index 0000000..f2e9f5a
--- /dev/null
+++ b/Sccp_manager.inc/aminterface.class.php
@@ -0,0 +1,792 @@
+_responseHandler) > 0) {
+ //throw new PAMIException('Hier:' . $this->_responseHandler);
+ return (string) $this->_responseHandler;
+ } else {
+ return "";
+ }
+ }
+
+ public function setResponseHandler($responseHandler) {
+ if (0 == strlen($responseHandler)) {
+ return ;
+ }
+ $className = '\\FreePBX\\modules\\Sccp_manager\\aminterface\\Message\\Response\\' . $responseHandler . 'Response';
+ if (class_exists($className, true)) {
+ $this->_responseHandler = $responseHandler;
+ } else {
+ return ;
+ }
+ }
+
+ public function setVariable($key, $value) {
+ $key = strtolower($key);
+ $this->variables[$key] = $value;
+ }
+
+ public function getVariable($key) {
+ $key = strtolower($key);
+ if (!isset($this->variables[$key])) {
+ return null;
+ }
+ return $this->variables[$key];
+ }
+
+ protected function setKey($key, $value) {
+ $key = strtolower((string) $key);
+ $this->keys[$key] = (string) $value;
+ }
+
+ public function getKey($key) {
+ $key = strtolower($key);
+ if (!isset($this->keys[$key])) {
+ return null;
+ }
+ //return (string)$this->keys[$key];
+ return $this->keys[$key];
+ }
+
+ public function getVariables() {
+ return $this->variables;
+ }
+
+ public function getActionID() {
+ return $this->getKey('ActionID');
+ }
+
+ public function getKeys() {
+ return $this->keys;
+ }
+
+ private function serializeVariable($key, $value) {
+ return "Variable: $key=$value";
+ }
+
+ protected function finishMessage($message) {
+ return $message . self::EOL . self::EOL;
+ }
+
+ public function serialize() {
+ $result = array();
+ foreach ($this->getKeys() as $k => $v) {
+ $result[] = $k . ': ' . $v;
+ }
+ foreach ($this->getVariables() as $k => $v) {
+ if (is_array($v)) {
+ foreach ($v as $singleValue) {
+ $result[] = $this->serializeVariable($k, $singleValue);
+ }
+ } else {
+ $result[] = $this->serializeVariable($k, $v);
+ }
+ }
+ $mStr = $this->finishMessage(implode(self::EOL, $result));
+ return $mStr;
+ }
+
+ public function setActionID($actionID) {
+ if (0 == strlen($actionID)) {
+// throw new PAMIException('ActionID cannot be empty.');
+ return;
+ }
+
+ if (strlen($actionID) > 69) {
+// throw new PAMIException('ActionID can be at most 69 characters long.');
+ return;
+ }
+
+ $this->setKey('ActionID', $actionID);
+ }
+
+ public function __construct() {
+ $this->lines = array();
+ $this->variables = array();
+ $this->keys = array();
+ $this->createdDate = time();
+ }
+
+}
+
+namespace FreePBX\modules\Sccp_manager\aminterface\Message;
+
+abstract class Response {
+
+ protected $_events;
+ protected $_completed;
+ protected $keys;
+
+ public function isSuccess() {
+ return stristr($this->getKey('Response'), 'Error') === false;
+ }
+
+ public function isComplete() {
+ return $this->_completed;
+ }
+
+ public function isList() {
+ return
+ stristr($this->getKey('EventList'), 'start') !== false || stristr($this->getMessage(), 'follow') !== false
+ ;
+ }
+
+ public function setActionId($actionId) {
+ $this->setKey('ActionId', $actionId);
+ }
+
+ public function getMessage() {
+ return $this->getKey('Message');
+ }
+
+ public function __construct($rawContent) {
+ parent::__construct($rawContent);
+
+ $this->_events = array();
+ $this->_eventsCount = 0;
+ $this->_completed = !$this->isList();
+ }
+
+}
+
+//namespace FreePBX\modules\Sccp_manager\aminterface\Message;
+
+class LoginAction extends \FreePBX\modules\Sccp_manager\aminterface\Message {
+
+ /**
+ * Constructor.
+ *
+ * @param string $user AMI username.
+ * @param string $password AMI password.
+ *
+ * @return void
+ */
+ public function __construct($user, $password) {
+ parent::__construct('Login');
+ $this->setKey('Action', $what);
+ $this->setKey('ActionID', microtime(true));
+ $this->setKey('Username', $user);
+ $this->setKey('Secret', $password);
+ }
+
+}
+
+namespace FreePBX\modules\Sccp_manager;
+
+class aminterface {
+
+ var $_socket;
+ var $_error;
+ var $_config;
+// var $ProcessingMessage;
+ private $_lastActionClass;
+ private $_lastActionId;
+ private $_lastRequestedResponseHandler;
+ private $_ProcessingMessage;
+ private $_responseFactory;
+
+ public function __construct($parent_class = null) {
+ global $amp_conf;
+ $this->paren_class = $parent_class;
+ $this->_socket = false;
+ $this->_error = array();
+ $this->_config = array('host' => 'localhost', 'user' => '', 'pass' => '', 'port' => '5038', 'tsoket' => 'tcp://', 'timeout' => 30, 'enabled' => false);
+ $fld_conf = array('user' => 'AMPMGRUSER', 'pass' => 'AMPMGRPASS');
+ if (isset($amp_conf['AMPMGRUSER'])) {
+ foreach ($fld_conf as $key => $value) {
+ if (isset($amp_conf[$value])) {
+ $this->_config[$key] = $amp_conf[$value];
+ }
+ }
+ }
+ }
+
+ public function info() {
+ $Ver = '13.0.4';
+ if ($this->_config['enabled']) {
+ return Array('Version' => $Ver,
+ 'about' => 'AMI data ver: ' . $Ver);
+ } else {
+ return Array('Version' => $Ver,
+ 'about' => 'Disabled AMI ver: ' . $Ver);
+ }
+ }
+
+ /**
+ * Opens a tcp connection to ami.
+ *
+ */
+ public function open() {
+ $cString = $this->_config['tsoket'] . $this->_config['host'] . ':' . $this->_config['port'];
+ $this->_context = stream_context_create();
+ $errno = 0;
+ $errstr = '';
+ $this->_socket = @stream_socket_client(
+ $cString, $errno, $errstr,
+ $this->_config['timeout'], STREAM_CLIENT_CONNECT, $this->_context
+ );
+ if ($this->_socket === false) {
+ $this->_errorException('Error connecting to ami: ' . $errstr . $cString);
+ return false;
+ }
+// FreePBX\modules\Sccp_manager\aminterface\Message\LoginAction::
+ $msg = new aminerface\Message\LoginAction($this->_config['user'], $this->_config['pass']);
+
+ $response = $this->send($msg);
+ return $response;
+ /*
+ $params = array('Action' => 'Login', 'UserName' => $this->_config['user'], 'Secret' => $this->_config['pass'], 'Events' => 'on');
+ $id = @stream_get_line($this->_socket, 1024, aminterface\Message::EOL);
+
+ if (strstr($id, 'Asterisk') === false) {
+ $this->_errorException('Unknown peer. Is this an ami?: ' . $id);
+ return false;
+ }
+ $response = $this->send($params);
+ if (!$response->isSuccess()) {
+ $this->_errorException('Could not connect: ' . $response->getMessage());
+ return false;
+ }
+ @stream_set_blocking($this->_socket, 0);
+ $this->_ProcessingMessage = '';
+ //register_tick_function(array($this, 'process'));
+ *
+ */
+ }
+
+ /**
+ * Closes the connection to ami.
+ */
+ public function close() {
+ @stream_socket_shutdown($this->_socket, STREAM_SHUT_RDWR);
+ }
+
+ public function send($message) {
+ $messageToSend = $message->serialize();
+ /* foreach ($params as $key => $value) {
+ $messageToSend .= $key . ': ' . $value . aminterface\Message::EOL;
+ }
+ $messageToSend .= aminterface\Message::EOL;
+ *
+ */
+ $length = strlen($messageToSend);
+
+ $this->_lastActionId = $message->getActionId();
+ $this->_lastRequestedResponseHandler = $message->getResponseHandler();
+ $this->_lastActionClass = $message;
+
+ if (@fwrite($this->_socket, $messageToSend) < $length) {
+ $this->_errorException('Could not send message');
+ return false;
+ }
+ while (1) {
+ stream_set_timeout($this->_socket, 1);
+// stream_set_timeout($this->_socket, (isset($this->socket_param['timeout']) ? $this->socket_param['timeout'] : 1));
+ $this->process();
+ $info = stream_get_meta_data($this->_socket);
+ if ($info['timed_out'] == false) {
+ $response = $this->getRelated($message);
+ if ($response != false) {
+ $this->_lastActionId = false;
+ return $response;
+ }
+ } else {
+ break;
+ }
+ }
+ $this->_errorException("Read waittime: " . ($this->socket_param['timeout']) . " exceeded (timeout).\n");
+ return false;
+ }
+
+ protected function getRelated($message) {
+ $ret = false;
+ $id = 0;
+// $id = $message->getActionID('ActionID');
+ if (isset($this->_incomingQueue[$id])) {
+ $response = $this->_incomingQueue[$id];
+ if ($response->isComplete()) {
+ unset($this->_incomingQueue[$id]);
+ $ret = $response;
+ }
+ }
+ return $ret;
+ }
+
+ protected function getMessages() {
+ $msgs = array();
+ // Read something.
+ $read = @fread($this->_socket, 65535);
+ if ($read === false || @feof($this->_socket)) {
+ $this->_errorException('Error reading');
+ }
+ $this->_ProcessingMessage .= $read;
+ // If we have a complete message, then return it. Save the rest for
+ // later.
+ return $msgs;
+ while (($marker = strpos($this->_ProcessingMessage, Message::EOM))) {
+ $msg = substr($this->_ProcessingMessage, 0, $marker);
+ $this->_ProcessingMessage = substr(
+ $this->_ProcessingMessage, $marker + strlen(Message::EOM)
+ );
+ $msgs[] = $msg;
+ }
+ return $msgs;
+ }
+
+ public function process() {
+ $msgs = $this->getMessages();
+ foreach ($msgs as $aMsg) {
+ $resPos = strpos($aMsg, 'Response:');
+ $evePos = strpos($aMsg, 'Event:');
+ if (($resPos !== false) && (($resPos < $evePos) || $evePos === false)) {
+ $response = $this->_msgToResponse($aMsg);
+ $this->_incomingQueue[$this->_lastActionId] = $response;
+ } else if ($evePos !== false) {
+ /* $event = $this->_messageToEvent($aMsg);
+ $response = $this->findResponse($event);
+ if ($response === false || $response->isComplete()) {
+ $this->dispatch($event);
+ } else {
+ $response->addEvent($event);
+ }
+ *
+ */
+ } else {
+ // broken ami.. sending a response with events without
+ // Event and ActionId
+ $bMsg = 'Event: ResponseEvent' . "\r\n";
+ $bMsg .= 'ActionId: ' . $this->_lastActionId . "\r\n" . $aMsg;
+ $event = $this->_messageToEvent($bMsg);
+ $response = $this->findResponse($event);
+ $response->addEvent($event);
+ }
+ }
+ }
+
+ private function _msgToResponse($msg) {
+ $response = $this->_msgFromRaw($msg, $this->_lastActionClass, $this->_lastRequestedResponseHandler);
+ /* $actionId = $response->getActionId();
+ if ($actionId === null) {
+ $actionId = $this->_lastActionId;
+ $response->setActionId($this->_lastActionId);
+ }
+ *
+ */
+ return $response;
+ }
+
+ public function _msgFromRaw($message, $requestingaction = false, $responseHandler = false) {
+
+ $_className = false;
+ if ($responseHandler != false) {
+ $_className = '\\FreePBX\\modules\\Sccp_manager\\aminterface\\Response';
+// $_className = '\\FreePBX\\modules\\Sccp_manager\\aminterface\\' . $responseHandler . 'Response';
+ } else if ($requestingaction != false) {
+ switch ($requestingaction) {
+ case 'login':
+
+ break;
+
+ default:
+ break;
+ }
+// $_className = '\\FreePBX\\modules\\Sccp_manager\\Response\\' . substr(get_class($requestingaction), 20, -6) . 'Response';
+ $_className = '\\FreePBX\\modules\\Sccp_manager\\Response';
+ }
+ if ($_className) {
+ if (class_exists($_className, true)) {
+ $responseclass = $_className;
+ } else if ($responseHandler != false) {
+ $this->_errorException('Response Class ' . $_className . ' requested via responseHandler, could not be found');
+ }
+ }
+// return new $responseclass($message);
+ }
+
+ protected function _errorException($msg) {
+ $this->_error[] = $msg;
+ }
+
+ /*
+ * Replace or dublicate to AMI interface
+ */
+
+//-------------------------------------------------------------------------------
+//-------------------------------------------------------------------------------
+ function core_list_all_exten($keyfld = '', $filter = array()) {
+ $result = array();
+ return $result;
+ }
+
+ /*
+ public function sccp_list_extnint() {
+ $hint_key = array();
+ $hint_all = $this->sccp_list_all_hints();
+ foreach ($hint_all as $value) {
+ $res = $this->loc_after('@', $value);
+ // array_search($res, $hint_key)) != NULL)
+ if (!isset($hint_key[$res])) {
+ $hint_key[$res] = '@' . $res;
+ }
+ }
+ return $hint_key;
+ }
+
+ 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;
+ }
+ }
+
+ function getеtestChanSCC() {
+ global $astman;
+ // $action = Array('SCCPShowGlobals',);
+ $params = array();
+ $action = 'SCCPShowSoftkeySets';
+ // $params = array('Segment' => 'device', 'ResultFormat'=>'command' );
+ // $params = array('Segment' => 'device');
+ // $params = array();
+ $metadata = $astman->send_request($action, $params);
+ return $metadata;
+ }
+
+
+ function core_list_all_exten($keyfld = '', $filter = array()) {
+ $result = array();
+ $fld_data = array('exten', 'context', 'statustext', 'status');
+ $row_data = $this->astman_GetRaw('ExtensionStateList');
+ if (empty($row_data) || empty($row_data['eventlist'])) {
+ return $result;
+ }
+ if ($row_data['eventlist'] == 'Complete') {
+ foreach ($row_data['list'] as $value) {
+ $exten = $value['exten'];
+ $context = $value['context'];
+ $exclude = empty($exten);
+ switch ($keyfld) {
+ case 'exten':
+ $store_key = $exten;
+ break;
+ case 'hint':
+ default:
+ $store_key = $exten . '@' . $context;
+ break;
+ }
+
+ if (!empty($filter)) {
+ foreach ($filter as $fkey => $fvalue) {
+ if (!empty($value[$fkey])) {
+ if (strpos(';' . $fvalue . ';', ';' . $value[$fkey] . ';') !== false) {
+ $exclude = true;
+ }
+ }
+ }
+ }
+ if (!$exclude) {
+ foreach ($fld_data as $key) {
+ $result[$store_key][$key] = (empty($value[$key]) ? '' : $value[$key] );
+ }
+ $result[$store_key]['key'] = $exten . '@' . $context;
+ $result[$store_key]['label'] = $exten . '@' . $context;
+ }
+ }
+ }
+ return $result;
+ }
+
+ private function astLogin($host = "", $username = "", $password = "") {
+ if ($this->Sok_param['enabled'] != true) {
+ return FALSE;
+ }
+
+ if (empty($host) || empty($username) || empty($password)) {
+ if (empty($this->Sok_param['host']) || empty($this->Sok_param['user']) || empty($this->Sok_param['pass'])) {
+ return FALSE;
+ }
+ $host = (empty($host) ? $this->Sok_param['host'] : $host);
+ $username = (empty($username) ? $this->Sok_param['user'] : $username);
+ $password = (empty($password) ? $this->Sok_param['pass'] : $password);
+ }
+ $this->socket = @fsockopen($host, "5038", $errno, $errstr, 1);
+
+ if (!$this->socket) {
+ $this->error = "Could not connect - $errstr ($errno)";
+ return FALSE;
+ } else {
+ stream_set_timeout($this->socket, 1);
+
+ // $wrets = $this->astQuery("Action: Login\r\nUserName: $username\r\nSecret: $password\r\nEvents: off\r\n\r\n");
+ $wrets = $this->astQuery("Action: Login\r\nUserName: $username\r\nSecret: $password\r\nEvents: on\r\n\r\n");
+
+ if (strpos($wrets['raw'], "Message: Authentication accepted") != FALSE) {
+ return TRUE;
+ } else {
+ $this->error = "Could not login - Authentication failed ";
+ fclose($this->socket);
+ $this->socket = FALSE;
+ return FALSE;
+ }
+ }
+ }
+
+ private function astLogout() {
+ if ($this->socket) {
+ fputs($this->socket, "Action: Logoff\r\n\r\n");
+ while (!feof($this->socket)) {
+ $wrets .= fread($this->socket, 8192);
+ }
+ fclose($this->socket);
+ $this->socket = "FALSE";
+ }
+ return;
+ }
+
+ private function astQuery($query, $rawdata = false) {
+ $wrets = "";
+ // return $this->socket;
+ if ($this->socket === FALSE) {
+ return FALSE;
+ }
+ $time_Query = microtime(true);
+ $parameters = array();
+ $parameters['raw'] = '';
+ $data_store = 'data';
+ $parameters[$data_store] = '';
+ fputs($this->socket, $query);
+ $parameters['raw_q'] = $query;
+ $stop_data = false;
+ $row_list = false;
+ $row_list_arr = Array();
+ $stop_data = false;
+ $row_list = !$rawdata;
+ do {
+ $line = fgets($this->socket, 4096);
+ $parameters['raw'] .= $line;
+ if (!$rawdata) {
+ // if (true) {
+ $a = strpos($line, ':');
+ if ($a) {
+ $key = trim(strtolower(substr($line, 0, $a)));
+ switch ($key) {
+ case 'eventlist':
+ if (strpos($line, 'start') !== false) {
+ $row_list = true;
+ } else {
+ $row_list = false;
+ }
+ case 'response':
+ case 'message':
+ $parameters[$key] = trim(substr($line, $a + 2));
+ if (!empty($parameters['response']) && !empty($parameters['message'])) {
+ if ($parameters['response'] == 'Error') {
+ $stop_data = true;
+ }
+ }
+ break;
+ case 'json':
+ $parameters[$key] = substr($line, $a + 2);
+ $data_store = $key;
+ break;
+ default:
+ if ($row_list) {
+ $row_list_arr[$key] = trim(str_replace("\r\n", "", substr($line, $a + 2)));
+ ;
+ }
+ $parameters[$data_store] .= $line;
+ break;
+ }
+ // store parameter in $parameters
+ } else {
+ if (!isset($parameters[$data_store])) {
+ $parameters[$data_store] = '';
+ }
+ $parameters[$data_store] .= $line;
+ }
+ }
+ if ($line == "\r\n") {
+ if ($row_list == false) {
+ $stop_data = true;
+ } else {
+ $parameters['list'][] = $row_list_arr;
+ $row_list_arr = array();
+ }
+ }
+ $info = stream_get_meta_data($this->socket);
+ } while ($stop_data == false && $info['timed_out'] == false);
+
+ $parameters['time_Query'] = microtime(true) - $time_Query;
+ $this->Sok_param['total'] = $this->Sok_param['total'] + $parameters['time_Query'];
+ // $this->astLogout();
+ return $parameters;
+ }
+
+ function GetError() {
+ return $this->error;
+ }
+
+ function astman_GetRaw($action = "", $parameters = array()) {
+ $option = "";
+ $result = array();
+
+ if ($this->_socket === FALSE) {
+ if (!$this->astLogin()) {
+ $result["Response"] = "Faild";
+ $result["Error"] = $this->error;
+ return $result;
+ }
+ }
+
+ $query = "Action: $action\r\n";
+
+ foreach ($parameters as $var => $val) {
+ if (is_array($val)) {
+ foreach ($val as $k => $v) {
+ $query .= "$var: $k=$v\r\n";
+ }
+ } else {
+ $query .= "$var: $val\r\n";
+ }
+ }
+ $result = $this->astQuery($query . "\r\n", true);
+ $result = $this->astQuery($query . "\r\n", false);
+ return $result;
+ }
+
+ /*
+ private function astman_retrieveMeta($action = "", $parameters=array(), $rawdata = false) {
+ // $parameters=array()
+ global $amp_conf;
+
+ if (empty($action)) {
+ $action = 'SCCPConfigMetaData';
+ }
+ $query = "Action: $action\r\n";
+
+ foreach($parameters as $var=>$val) {
+ if (is_array($val)) {
+ foreach($val as $k => $v) {
+ $query .= "$var: $k=$v\r\n";
+ }
+ } else {
+ $query .= "$var: $val\r\n";
+ }
+ }
+
+ $result = $this->astQuery($query."\r\n",$rawdata);
+
+ if ($result["Response"] == "Success") {
+ if ($rawdata) {
+ return $result;
+ } else {
+ if (!empty($result["JSON"])) {
+ $decode = json_decode($response["JSON"], true);
+ return $decode;
+ } else {
+ return $result;
+ }
+ }
+ } else {
+ return $result;
+ return array();
+ }
+ }
+ */
+
+ function t_get_meta_data() {
+ global $amp_conf;
+ $fp = fsockopen("127.0.0.1", "5038", $errno, $errstr, 10);
+
+ if (!$fp) {
+ echo "$errstr ($errno)
\n";
+ } else {
+ fputs($fp, "Action: login\r\n");
+ fputs($fp, "Username: " . $amp_conf[AMPMGRUSER] . "\r\n");
+// fputs ($fp,"Secret: secret\r\n");
+ fputs($fp, "Secret: " . $amp_conf[AMPMGRPASS] . "\r\n");
+ fputs($fp, "Events: on\r\n\r\n");
+
+// fputs ($fp,"Action: SCCPShowDevices\r\n");
+// fputs ($fp,"Action: DeviceStateList\r\n");
+ fputs($fp, "Action: ExtensionStateList\r\n");
+ fputs($fp, "Action: Status\r\n");
+
+// fputs ($fp,"Segment: general\r\n");
+// "Segments":["general","device","line","softkey"]}
+// fputs ($fp,"Segment: device\r\n");
+// fputs ($fp,"ResultFormat: command\r\n");
+ fputs($fp, "\r\n");
+
+ /*
+ fputs ($fp,"Action: SCCPConfigMetaData\r\n");
+ fputs ($fp,"\r\n");
+
+ fputs ($fp,"Action: SCCPConfigMetaData\r\n");
+ fputs ($fp,"Segment: general\r\n");
+ fputs ($fp,"\r\n");
+
+ fputs ($fp,"Action: SCCPConfigMetaData\r\n");
+ fputs ($fp,"Segment: general\r\n");
+ fputs ($fp,"ListResult: yes\r\n");
+ fputs ($fp,"Option: fallback\r\n");
+ fputs ($fp,"\r\n");
+
+ fputs ($fp,"Action: SCCPConfigMetaData\r\n");
+ fputs ($fp,"Segment: device\r\n");
+ fputs ($fp,"ListResult: freepbx\r\n");
+ fputs ($fp,"\r\n");
+
+ fputs ($fp,"Action: SCCPConfigMetaData\r\n");
+ fputs ($fp,"Segment: device\r\n");
+ fputs ($fp,"Option: dtmfmode\r\n");
+ fputs ($fp,"ListResult: yes\r\n");
+ fputs ($fp,"\r\n");
+ */
+
+ fputs($fp, "Action: logoff\r\n\r\n");
+// print_r(fgets($fp));
+ $resp = '';
+ while (!feof($fp)) {
+ $resp .= fgets($fp);
+ }
+// print_r(fgets($fp));
+// print_r('
');
+// echo fgets($fp, 128);
+ }
+ fclose($fp);
+ return $resp;
+ }
+
+}
diff --git a/Sccp_manager.inc/dbinterface.class.php b/Sccp_manager.inc/dbinterface.class.php
index ce2eb80..9cdcb0b 100644
--- a/Sccp_manager.inc/dbinterface.class.php
+++ b/Sccp_manager.inc/dbinterface.class.php
@@ -43,7 +43,7 @@ class dbinterface {
break;
case "SccpDevice":
// $sql = "SELECT * FROM `sccpdeviceconfig` ORDER BY `name`";
- $sql = "select `name`,`name` as `mac`, `type`, `button`, `addon` from `sccpdeviceconfig` ORDER BY `name`";
+ $sql = "select `name`,`name` as `mac`, `type`, `button`, `addon`, `_description` as description from `sccpdeviceconfig` ORDER BY `name`";
$raw_settings = sql($sql, "getAll", DB_FETCHMODE_ASSOC);
break;
case "HWDevice":
@@ -56,6 +56,10 @@ class dbinterface {
$sql = "DESCRIBE sccpdevice";
$raw_settings = sql($sql, "getAll", DB_FETCHMODE_ASSOC);
break;
+ case "get_colums_sccpusers":
+ $sql = "DESCRIBE sccpusers";
+ $raw_settings = sql($sql, "getAll", DB_FETCHMODE_ASSOC);
+ break;
case "get_sccpdevice_byid":
$sql = 'SELECT t1.*, types.dns, types.buttons, types.loadimage, types.nametemplate as nametemplate, '
. 'addon.buttons as addon_buttons FROM sccpdevice AS t1 '
@@ -63,8 +67,16 @@ class dbinterface {
. 'LEFT JOIN sccpdevmodel as addon ON t1.addon=addon.model WHERE name="' . $data['id'] . '";';
$raw_settings = sql($sql, "getRow", DB_FETCHMODE_ASSOC);
break;
+ case "get_sccpdusers":
+ $sql = "SELECT * FROM `sccpusers` ";
+ if (!empty($data['id'])) {
+ $sql .= 'WHERE name="' . $data['id'] . '" ';
+ }
+ $sql .= "ORDER BY `name`;";
+ $raw_settings = sql($sql, "getRow", DB_FETCHMODE_ASSOC);
+ break;
case "get_sccpdevice_buttons":
- $sql = 'SELECT * FROM buttonconfig WHERE device="' . $data['id'] . '";';
+ $sql = 'SELECT * FROM sccpbuttonconfig WHERE ref="' . $data['id'] . '" ORDER BY `instance`;';
$raw_settings = sql($sql, "getAll", DB_FETCHMODE_ASSOC);
break;
}
@@ -161,6 +173,7 @@ class dbinterface {
break;
case 'sccpdevmodel':
case 'sccpdevice':
+ case 'sccpusers':
$sql_db = $db_name;
$sql_key = "";
$sql_var = "";
@@ -193,7 +206,7 @@ class dbinterface {
break;
case 'sccpbuttons':
if (($mode == 'clear') || ($mode == 'delete')) {
- $sql = 'DELETE FROM `buttonconfig` WHERE device="' . $hwid . '";';
+ $sql = 'DELETE FROM `sccpbuttonconfig` WHERE ref="' . $hwid . '";';
$stmt = $db->prepare($sql);
$stmt->execute();
}
@@ -201,7 +214,8 @@ class dbinterface {
break;
}
if (!empty($save_value)) {
- $sql = 'INSERT INTO `buttonconfig` (`device`, `instance`, `type`, `name`, `options`) VALUES (?,?,?,?,?);';
+ $sql = 'INSERT INTO `sccpbuttonconfig` (`ref`, `reftype`,`instance`, `buttontype`, `name`, `options`) VALUES (?,?,?,?,?,?);';
+// die(print_r($save_value,1));
$stmt = $db->prepare($sql);
$res = $db->executeMultiple($stmt, $save_value);
}
diff --git a/Sccp_manager.inc/extconfigs.class.php b/Sccp_manager.inc/extconfigs.class.php
index 29e62ff..2ec9649 100644
--- a/Sccp_manager.inc/extconfigs.class.php
+++ b/Sccp_manager.inc/extconfigs.class.php
@@ -100,7 +100,6 @@ class extconfigs {
'holdconf' => 'resume,newcall,endcall,join',
'uriaction' => 'default');
// Cisco Language Code / Directory
-
private $cisco_language = array('ar_SA' => array('code' => 'ar', 'language' => 'Arabic', 'locale' => 'Arabic_Saudi_Arabia', 'codepage' => 'ISO8859-1'),
'bg_BG' => array('code' => 'bg', 'language' => 'Bulgarian', 'locale' => 'Bulgarian_Bulgaria', 'codepage' => 'ISO8859-1'),
'cz_CZ' => array('code' => 'cz', 'language' => 'Czech', 'locale' => 'Czech_Czech_Republic', 'codepage' => 'ISO8859-1'),
@@ -217,10 +216,22 @@ class extconfigs {
// *** Setings for Provision Sccp
$adv_config = Array('tftproot' => '', 'firmware' => 'firmware', 'settings' => 'settings',
'locales' => 'locales', 'languages' => 'languages', 'templates' => 'templates');
+// 'pro' /tftpboot - root dir
+// /tftpboot/locales/locales/%Languge_name%
+// /tftpboot/settings/XMLdefault.cnf.xml
+// /tftpboot/settings/SEP[MAC].cnf.xml
+// /tftpboot/firmware/79xx/SCCPxxxx.loads
$adv_tree['pro'] = Array('templates' => 'tftproot', 'settings' => 'tftproot', 'locales' => 'tftproot', 'firmware' => 'tftproot', 'languages' => 'locales');
+// 'def' /tftpboot - root dir
+// /tftpboot/languages/%Languge_name%
+// /tftpboot/XMLdefault.cnf.xml
+// /tftpboot/SEP[MAC].cnf.xml
+// /tftpboot/SCCPxxxx.loads
+ $adv_tree['def'] = Array('templates' => 'tftproot', 'settings' => '', 'locales' => '', 'firmware' => '', 'languages' => 'tftproot');
// $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');
diff --git a/Sccp_manager.inc/srvinterface.class.php b/Sccp_manager.inc/srvinterface.class.php
index f7fbe44..b3f0a36 100644
--- a/Sccp_manager.inc/srvinterface.class.php
+++ b/Sccp_manager.inc/srvinterface.class.php
@@ -11,24 +11,16 @@
namespace FreePBX\modules\Sccp_manager;
class srvinterface {
- var $socket;
+
var $error;
-
+
public function __construct($parent_class = null) {
- global $amp_conf;
- $this->paren_class = $parent_class;
- $this->socket = FALSE;
+ $this->paren_class = $parent_class;
$this->error = "";
-/*
- if (isset($amp_conf[AMPMGRUSER])) {
- $this->astLogin('localhost', $amp_conf[AMPMGRUSER],$amp_conf[AMPMGRPASS]);
- }
-
-*/
}
public function info() {
- $Ver = '13.0.3';
+ $Ver = '13.0.4';
return Array('Version' => $Ver,
'about' => 'Server interface data ver: ' . $Ver);
}
@@ -37,10 +29,11 @@ class srvinterface {
Core Access Function
*/
-
-/*
- * Replace or dublicate to AMI interface
- */
+
+ /*
+ * Replace or dublicate to AMI interface
+ */
+
public function sccp_core_commands($params = array()) {
global $astman;
$cmd_list = array('get_softkey' => array('cmd' => "sccp show softkeyssets", 'param' => ''),
@@ -134,19 +127,20 @@ class srvinterface {
/*
* A function should be used in the form of buttons for getting all hint. Not working. I don't know how to use properly.
*/
+
public function sccp_list_hints() {
$hint_key = array();
$hint_all = $this->sccp_list_all_hints();
foreach ($hint_all as $value) {
- $res = $this->loc_after('@', $value);
+ $res = $this->loc_after('@', $value);
// array_search($res, $hint_key)) != NULL)
- if (!isset($hint_key[$res])) {
- $hint_key[$res] = '@'.$res;
- }
+ if (!isset($hint_key[$res])) {
+ $hint_key[$res] = '@' . $res;
+ }
}
return $hint_key;
}
-
+
public function sccp_list_all_hints() {
$ast_out = $this->sccp_core_commands(array('cmd' => 'get_hints'));
$ast_out = preg_split("/[\n]/", $ast_out['data']);
@@ -160,7 +154,7 @@ class srvinterface {
foreach ($ast_out as $line) {
if (strlen($line) > 3) {
list ($line, $junk) = explode(' ', $line);
- if (!is_bool(strpos($line,':'))) {
+ if (!is_bool(strpos($line, ':'))) {
$line = trim(substr($line, 0, strpos($line, ':')));
}
if (isset($ast_key[$line])) {
@@ -177,15 +171,15 @@ class srvinterface {
public function sccp_realtime_status() {
$ast_res = array();
- $ast_out = $this->sccp_core_commands(array('cmd'=>'get_realtime_status'));
- $ast_out = preg_split("/[\n]/", $ast_out['data']);
- if (strpos($ast_out[0], 'Privilege') !== false){
+ $ast_out = $this->sccp_core_commands(array('cmd' => 'get_realtime_status'));
+ $ast_out = preg_split("/[\n]/", $ast_out['data']);
+ if (strpos($ast_out[0], 'Privilege') !== false) {
$ast_out[0] = "";
}
foreach ($ast_out as $line) {
if (strlen($line) > 3) {
- $ast_key = strstr(trim($line), ' ', true);
- $ast_res[$ast_key] = array('message' => $line, 'status'=> strpos($line, 'connected') ? 'OK' : 'ERROR');
+ $ast_key = strstr(trim($line), ' ', true);
+ $ast_res[$ast_key] = array('message' => $line, 'status' => strpos($line, 'connected') ? 'OK' : 'ERROR');
}
}
return $ast_res;
@@ -211,16 +205,16 @@ class srvinterface {
default:
return 430;
}
-/* if ($res["vCode"] >= 433) {
-
- }
- if ($res["vCode"] >= 431) {
- return 431;
- } else {
- return 430;
- }
- *
- */
+ /* if ($res["vCode"] >= 433) {
+
+ }
+ if ($res["vCode"] >= 431) {
+ return 431;
+ } else {
+ return 430;
+ }
+ *
+ */
// return $res["vCode"];
}
@@ -228,7 +222,7 @@ class srvinterface {
$res = $this->getChanSCCPVersion();
if (empty($res)) {
$res = $this->getCoreSCCPVersion();
- }
+ }
return $res;
}
@@ -246,7 +240,7 @@ class srvinterface {
$result["develop"] = $ast_out[1];
$res = 10;
// !TODO!: This does not work as you might expect
- if (base_convert($ast_out[3], 16, 10) == base_convert('702487a', 16, 10)) {
+ 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
@@ -437,26 +431,26 @@ class srvinterface {
return false;
}
}
+
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;
+ foreach ($needles as $str) {
+ if (is_array($str)) {
+ $pos = strpos_array($haystack, $str);
+ } else {
+ $pos = strpos($haystack, $str);
+ }
+ if ($pos !== FALSE) {
+ return $pos;
+ }
}
+ } else {
+ return strpos($haystack, $needles);
}
- } else {
- return strpos($haystack, $needles);
- }
- return FALSE;
+ return FALSE;
}
- private function loc_after($value, $inthat)
- {
+ private function loc_after($value, $inthat) {
if (!is_bool(strpos($inthat, $value)))
return substr($inthat, strpos($inthat, $value) + strlen($value));
}
@@ -472,234 +466,35 @@ class srvinterface {
$metadata = $astman->send_request($action, $params);
return $metadata;
}
- /*
- * [Segments] => ( [0] => general [1] => device [2] => line [3] => softkey )
- */
- function getеtestChanSCCP_GlablsInfo($Segment='') {
+
+ /*
+ * [Segments] => ( [0] => general [1] => device [2] => line [3] => softkey )
+ */
+ function getеtestChanSCCP_GlablsInfo($Segment = '') {
global $astman;
$params = array();
- $response = $astman->send_request('SCCPConfigMetaData', $params);
$action = 'SCCPConfigMetaData';
if (empty($Segment)) {
$Segment = 'general';
}
- $params = array('Segment' => $Segment, 'ResultFormat'=>'command' );
+ $params = array('Segment' => $Segment, 'ResultFormat' => 'command');
$metadata = $astman->send_request($action, $params);
if (!empty($metadata['data'])) {
- $tmp_data = $metadata['data'];
- if (strpos($tmp_data, 'JSON:')!==false ) {
- $decode = json_decode(substr ($tmp_data,strpos($tmp_data, 'JSON:') + 5), true);
+ $tmp_data = $metadata['data'];
+ if (strpos($tmp_data, 'JSON:') !== false) {
+ $decode = json_decode(substr($tmp_data, strpos($tmp_data, 'JSON:') + 5), true);
$result = array();
if (!empty($decode['Options'])) {
foreach ($decode['Options'] as $value) {
- $result[$value['Name']] = $value;
+ $result[$value['Name']] = $value;
}
return $result;
}
return $decode;
}
-
}
return $metadata;
}
-
- /*
- private function astLogin($host="localhost", $username="admin", $password="amp111"){
-
- $this->socket = @fsockopen("127.0.0.1","5038", $errno, $errstr, 1);
-
- if (!$this->socket) {
- $this->error = "Could not connect - $errstr ($errno)";
- return FALSE;
- }else{
- stream_set_timeout($this->socket, 1);
-
- $wrets = $this->astQuery("Action: Login\r\nUserName: $username\r\nSecret: $password\r\nEvents: off\r\n\r\n");
-
- if (strpos($wrets['raw'], "Message: Authentication accepted") != FALSE) {
- return TRUE;
- }else{
- $this->error = "Could not login - Authentication failed ";
- fclose($this->socket);
- $this->socket = FALSE;
- return FALSE;
- }
- }
- }
-
- private function astLogout(){
- if ($this->socket){
- fputs($this->socket, "Action: Logoff\r\n\r\n");
- while (!feof($this->socket)) {
- $wrets .= fread($this->socket, 8192);
- }
- fclose($this->socket);
- $this->socket = "FALSE";
- }
- return;
- }
-
- private function astQuery($query, $rawdata = false){
- $wrets = "";
-
- if ($this->socket === FALSE)
- return FALSE;
- $parameters = array();
- $data_store = 'data';
- fputs($this->socket, $query);
- $parameters['raw_q'] = $query;
- do
- {
- $line = fgets($this->socket, 4096);
- $parameters['raw'] .= $line;
- if (!$rawdata) {
- $a = strpos($line, ':');
- if($a) {
- $key = substr($line, 0, $a);
- switch ($key) {
- case 'Response':
- case 'Message':
- case 'EventList':
- $parameters[$key] = trim(substr($line, $a + 2));
- break;
- case 'JSON':
- $parameters[$key] = substr($line, $a + 2);
- $data_store = $key;
- break;
- default:
- $parameters[$data_store] .= $line;
- break;
- }
- // store parameter in $parameters
- } else {
- $parameters[$data_store] .= $line;
- }
- }
- $info = stream_get_meta_data($this->socket);
- }while ($line != "\r\n" && $info['timed_out'] == false );
-
- return $parameters;
- }
-
- function GetError(){
- return $this->error;
- }
-
- private function astman_retrieveMeta($action = "", $parameters=array(), $rawdata = false) {
- // $parameters=array()
- global $amp_conf;
- $option = "";
- $result = array();
- if ($this->socket === FALSE) {
- if (!$this->astLogin(localhost, $amp_conf[AMPMGRUSER],$amp_conf[AMPMGRPASS])) {
- $result["Response"] = "Faild";
- $result["Error"] = $this->error;
- return $result;
- }
- }
-
- if (empty($action)) {
- $action = 'SCCPConfigMetaData';
- }
- $query = "Action: $action\r\n";
-
- foreach($parameters as $var=>$val) {
- if (is_array($val)) {
- foreach($val as $k => $v) {
- $query .= "$var: $k=$v\r\n";
- }
- } else {
- $query .= "$var: $val\r\n";
- }
- }
-
- $result = $this->astQuery($query."\r\n",$rawdata);
-
- if ($result["Response"] == "Success") {
- if ($rawdata) {
- return $result;
- } else {
- if (!empty($result["JSON"])) {
- $decode = json_decode($response["JSON"], true);
- return $decode;
- } else {
- return $result;
- }
- }
- } else {
- return $result;
- return array();
- }
- }
-
- */
-
- function t_get_meta_data() {
- global $amp_conf;
- $fp = fsockopen("127.0.0.1", "5038", $errno, $errstr, 10);
-
- if (!$fp) {
- echo "$errstr ($errno)
\n";
- } else {
- fputs ($fp,"Action: login\r\n");
- fputs ($fp,"Username: ".$amp_conf[AMPMGRUSER]."\r\n");
-// fputs ($fp,"Secret: secret\r\n");
- fputs ($fp,"Secret: ".$amp_conf[AMPMGRPASS]."\r\n");
- fputs ($fp,"Events: on\r\n\r\n");
-
-// fputs ($fp,"Action: SCCPShowDevices\r\n");
-
- fputs ($fp,"Action: SCCPConfigMetaData\r\n");
-// fputs ($fp,"Segment: general\r\n");
-// "Segments":["general","device","line","softkey"]}
- fputs ($fp,"Segment: device\r\n");
- fputs ($fp,"ResultFormat: command\r\n");
- fputs ($fp,"\r\n");
-
-/*
- fputs ($fp,"Action: SCCPConfigMetaData\r\n");
- fputs ($fp,"\r\n");
-
- fputs ($fp,"Action: SCCPConfigMetaData\r\n");
- fputs ($fp,"Segment: general\r\n");
- fputs ($fp,"\r\n");
-
- fputs ($fp,"Action: SCCPConfigMetaData\r\n");
- fputs ($fp,"Segment: general\r\n");
- fputs ($fp,"ListResult: yes\r\n");
- fputs ($fp,"Option: fallback\r\n");
- fputs ($fp,"\r\n");
-
- fputs ($fp,"Action: SCCPConfigMetaData\r\n");
- fputs ($fp,"Segment: device\r\n");
- fputs ($fp,"ListResult: freepbx\r\n");
- fputs ($fp,"\r\n");
-
- fputs ($fp,"Action: SCCPConfigMetaData\r\n");
- fputs ($fp,"Segment: device\r\n");
- fputs ($fp,"Option: dtmfmode\r\n");
- fputs ($fp,"ListResult: yes\r\n");
- fputs ($fp,"\r\n");
-*/
-
- fputs ($fp,"Action: logoff\r\n\r\n");
-// print_r(fgets($fp));
- $resp = '';
- while (!feof($fp)) {
- $resp .= fgets($fp);
-
- }
-// print_r(fgets($fp));
-// print_r('
');
-
-// echo fgets($fp, 128);
- }
- fclose($fp);
- return $resp;
- }
-
-
-
}
diff --git a/Sccp_manager.inc/xmlinterface.class.php b/Sccp_manager.inc/xmlinterface.class.php
index 345c140..417c723 100644
--- a/Sccp_manager.inc/xmlinterface.class.php
+++ b/Sccp_manager.inc/xmlinterface.class.php
@@ -199,7 +199,7 @@ class xmlinterface {
}
$xnode->name = $tz_id;
$xnode->dateTemplate = $data_values['dateformat'];
- $xnode->timeZone = $TZdata['cisco_code'];
+ $xnode->timeZone = $TZdata['cisco_code'];
// $xnode->timeZone = $tz_id.' Standard'.((empty($TZdata['daylight']))? '': '/'.$TZdata['daylight']).' Time';
if ($data_values['ntp_config_enabled'] == 'yes') {
diff --git a/assets/js/sccp_manager.js b/assets/js/sccp_manager.js
index 84b3575..36bec58 100644
--- a/assets/js/sccp_manager.js
+++ b/assets/js/sccp_manager.js
@@ -58,12 +58,16 @@ $(document).ready(function () {
$('#ajaxsubmit2').on('click', function (e) {
var vdata = '';
var snd_command = 'savesettings';
+ console.log($('.fpbx-submit').data('id'));
$('.fpbx-submit').each(function () {
vdata = vdata + $(this).serialize() + '&';
});
if ($('.fpbx-submit').data('id') == "hw_edit") {
snd_command = 'save_hardware';
}
+ if ($('.fpbx-submit').data('id') == "ruser_edit") {
+ snd_command = 'save_ruser';
+ }
if ($('.fpbx-submit').data('id') == "dial_template") {
snd_command = 'save_dialplan_template';
}
@@ -99,6 +103,9 @@ $(document).ready(function () {
if ($('.fpbx-submit').data('id') == "hw_edit") {
snd_command = 'save_hardware';
}
+ if ($('.fpbx-submit').data('id') == "ruser_edit") {
+ snd_command = 'save_ruser';
+ }
if ($('.fpbx-submit').data('id') == "dial_template") {
snd_command = 'save_dialplan_template';
}
diff --git a/conf/sccpgeneral.xml.v433 b/conf/sccpgeneral.xml.v433
index f495bb4..e05a2dc 100644
--- a/conf/sccpgeneral.xml.v433
+++ b/conf/sccpgeneral.xml.v433
@@ -17,7 +17,7 @@ and open the template in the editor. Base Version before all crash :-)
* SLK - System KeySet
* * Input element Select SLS - System Language
* Input element Select SDM - Model List
- * SDE - Extension List
+ * SDE - Extension List tftp_rewrite
* Help elemen HLP - Help Element
-->
@@ -995,6 +995,15 @@ and open the template in the editor. Base Version before all crash :-)
"); $json = ''; print_r(""); +// ************************************************************************************ + // $lang_arr = $this->extconfigs->getextConfig('sccp_lang','sk_SK'); // print_r('
"); // print_r($conf_realtime); print_r("
"); print_r("
"); - print_r($this->dbinterface->validate()); // print_r("DIRECT START"); // print_r($this->sccpvalues['ccm_address']); + //print_r($this->get_php_classes('\\FreePBX\\modules\\')); +/* + print_r(get_declared_classes()); + print_r($this->aminterface->open()); + + + print_r($this->aminterface->_error); print_r("
"); -// print_r($this->getIP_information2()); + + */ + + + + //print_r($this->dbinterface->get_db_SccpTableData('SccpExtension')); // print_r($this->srvinterface->getеtestChanSCCP_GlablsInfo()); +// $test_data = $this->srvinterface-> astman_GetRaw('ExtensionStateList'); +// print_r($test_data); +// print_r($this->srvinterface-> core_list_all_exten()); +// print_r($this->get_hint_info()); +// print_r($this->aminterface-> core_list_all_exten('exten')); +// print_r($this->aminterface->Sok_param['total']); +// print_r($this->srvinterface->t_get_meta_data()); // print_r($this->sccp_metainfo); print("