diff --git a/Sccp_manager.class.php b/Sccp_manager.class.php
index a6a0e1d..36f5f4d 100644
--- a/Sccp_manager.class.php
+++ b/Sccp_manager.class.php
@@ -376,11 +376,7 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO {
public function myShowPage() {
$request = $_REQUEST;
$action = !empty($request['action']) ? $request['action'] : '';
- /*
- if ($this->sccpvalues['sccp_compatible']['data'] >= '433') {
- $this->sccp_metainfo = $this->srvinterface->getGlobalsFromMetaData('general');
- }
- */
+
if (!empty($this->sccpvalues['displayconfig'])) {
if (!empty($this->sccpvalues['displayconfig']['data']) && ($this->sccpvalues['displayconfig']['data'] == 'sccpsimple')) {
$this->pagedata = array(
@@ -517,11 +513,7 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO {
$request = $_REQUEST;
$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->getGlobalsFromMetaData('device');
- }
- */
+
if (empty($this->pagedata)) {
switch ($inputform) {
case "cisco":
@@ -699,7 +691,7 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO {
//$this->createDefaultSccpConfig();
$this->createDefaultSccpXml();
- $res = $this->srvinterface->sccp_reload();
+ $res = $this->aminterface->core_sccp_reload();
$msg [] = 'Config Saved: ' . $res['Response'];
$msg [] = 'Info :' . $res['data'];
// !TODO!: It is necessary in the future to check, and replace all server responses on correct messages. Use _(msg)
@@ -744,7 +736,7 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO {
$this->dbinterface->write('sccpdevice', array('name' => $idv), 'delete', "name");
$this->dbinterface->write('sccpbuttons', array(), 'delete', '', $idv);
$this->deleteSccpDeviceXML($idv); // Концы в вводу !!
- $this->srvinterface->sccpDeviceReset($idv);
+ $this->aminterface->sccpDeviceReset($idv, 'reset');
}
}
return array('status' => true, 'table_reload' => true, 'message' => 'Hardware device has been deleted! ');
@@ -789,24 +781,23 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO {
$msg = strpos($idv, 'SEP-');
if (!(strpos($idv, 'SEP') === false)) {
if ($cmd_id == 'reset_token') {
- $res = $this->srvinterface->sccp_reset_token($idv);
-
+ $res = $this->aminterface->sccpDeviceReset($idv, 'tokenack');
$msgr[] = $msg . ' ' . $res['Response'] . ' ' . $res['data'];
} else {
- $res = $this->srvinterface->sccpDeviceReset($idv);
+ $res = $this->aminterface->sccpDeviceReset($idv, 'reset');
$msgr[] = $msg . ' ' . $res['Response'] . ' ' . $res['data'];
}
}
if ($idv == 'all') {
- $dev_list = $this->srvinterface->sccp_get_active_device();
+ $dev_list = $this->aminterface->sccp_get_active_device();
foreach ($dev_list as $key => $data) {
if ($cmd_id == 'reset_token') {
if (($data['token'] == 'Rej') || ($data['status'] == 'Token ')) {
- $res = $this->srvinterface->sccp_reset_token($idv);
+ $res = $this->aminterface->sccpDeviceReset($idv, 'tokenack');
$msgr[] = 'Send Token reset to :' . $key;
}
} else {
- $res = $this->srvinterface->sccpDeviceReset($idv);
+ $res = $this->aminterface->sccpDeviceReset($idv, 'reset');
$msgr[] = $res['Response'] . ' ' . $res['data'];
}
}
@@ -893,7 +884,7 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO {
$id_name = $request['softkey'];
unset($this->sccp_conf_init[$id_name]);
$this->createDefaultSccpConfig();
- $msg = print_r($this->srvinterface->sccp_reload(), 1);
+ $msg = print_r($this->aminterface->core_sccp_reload(), 1);
return array('status' => true, 'table_reload' => true);
}
break;
@@ -910,7 +901,7 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO {
// !TODO!: -TODO-: Check SIP Support Enabled
$this->createSccpXmlSoftkey();
- $msg = print_r($this->srvinterface->sccp_reload(), 1);
+ $msg = print_r($this->aminterface->core_sccp_reload, 1);
return array('status' => true, 'table_reload' => true);
}
break;
@@ -918,7 +909,7 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO {
$result = array();
$i = 0;
$keyl = 'default';
- foreach ($this->srvinterface->sccp_list_keysets() as $keyl => $vall) {
+ foreach ($this->aminterface->sccp_list_keysets() as $keyl => $vall) {
$result[$i]['softkeys'] = $keyl;
if ($keyl == 'default') {
foreach ($this->extconfigs->getextConfig('keyset') as $key => $value) {
@@ -964,7 +955,7 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO {
if ($cmd_type == 'cisco-sip') {
return $result;
}
- $staus = $this->srvinterface->sccp_get_active_device();
+ $staus = $this->aminterface->sccp_get_active_device();
if (empty($result)) {
$result = array();
} else {
@@ -987,7 +978,7 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO {
foreach ($staus as $dev_ids) {
$id_name = $dev_ids['name'];
if (empty($dev_ids['news'])) {
- $dev_data = $this->srvinterface->sccp_getdevice_info($id_name);
+ $dev_data = $this->aminterface->sccp_getdevice_info($id_name);
if (!empty($dev_data['SCCP_Vendor']['model_id'])) {
$dev_addon = $dev_data['SCCP_Vendor']['model_addon'];
if (empty($dev_addon)) {
@@ -1302,9 +1293,9 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO {
$this->dbinterface->write('sccpbuttons', $save_buttons, $update_hw, '', $name_dev);
$this->createSccpDeviceXML($name_dev);
if ($hw_id == 'new') {
- $this->srvinterface->sccpDeviceReset($name_dev);
+ $this->aminterface->sccpDeviceReset($name_dev, 'reset');
} else {
- $this->srvinterface->sccpDeviceRestart($name_dev);
+ $this->aminterface->sccpDeviceReset($name_dev, 'restart');
}
return $save_settings;
@@ -1728,7 +1719,7 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO {
$this->sccppath["asterisk"] = $confDir;
}
}
- $ver_id = $this->srvinterface->get_compatible_sccp();
+ $ver_id = $this->aminterface->get_compatible_sccp();
if (!empty($this->sccpvalues['SccpDBmodel'])) {
$ver_id = $this->sccpvalues['SccpDBmodel']['data'];
}
@@ -1761,7 +1752,7 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO {
}
}
- $hint = $this->srvinterface->sccp_list_hints();
+ $hint = $this->aminterface->core_list_hints();
foreach ($hint as $key => $value) {
if ($this->hint_context['default'] != $value) {
$this->hint_context[$key] = $value;
@@ -1774,7 +1765,7 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO {
*/
function createSccpXmlSoftkey() {
- foreach ($this->srvinterface->sccp_list_keysets() as $keyl => $vall) {
+ foreach ($this->aminterface->sccp_list_keysets() as $keyl => $vall) {
$this->xmlinterface->create_xmlSoftkeyset($this->sccp_conf_init, $this->sccppath, $keyl);
}
}
@@ -2021,9 +2012,9 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO {
$dir_info['asterisk'] = $this->findAllFiles($amp_conf['ASTETCDIR']);
$dir_info['tftpdir'] = $this->findAllFiles($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();
- $dir_info['srvinterface'] = $this->srvinterface->info();
+ $dir_info['core'] = $this->aminterface->getSCCPVersion();
+ $dir_info['realtime'] = $this->aminterface->getRealTimeStatus();
+ //$dir_info['srvinterface'] = $this->srvinterface->info();
$dir_info['extconfigs'] = $this->extconfigs->info();
$dir_info['dbinterface'] = $this->dbinterface->info();
$dir_info['XML'] = $this->xmlinterface->info();
@@ -2196,7 +2187,7 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO {
if (empty($res)) {
// Old Req get all hints
- $tmp_data = $this->srvinterface->sccp_list_all_hints();
+ $tmp_data = $this->aminterface->core_list_all_hints();
foreach ($tmp_data as $value) {
$res[$value] = array('key' => $value, 'exten' => $this->before('@', $value), 'label' => $value);
}
diff --git a/Sccp_manager.inc/aminterface/aminterface.class.php b/Sccp_manager.inc/aminterface.class.php
similarity index 92%
rename from Sccp_manager.inc/aminterface/aminterface.class.php
rename to Sccp_manager.inc/aminterface.class.php
index 0389914..8d8b053 100644
--- a/Sccp_manager.inc/aminterface/aminterface.class.php
+++ b/Sccp_manager.inc/aminterface.class.php
@@ -33,10 +33,10 @@ class aminterface
$drivers = array('Message' => 'Message.class.php', 'Response' => 'Response.class.php', 'Event' => 'Event.class.php');
foreach ($drivers as $key => $value) {
$class = $driverNamespace . "\\" . $key;
- $driver = __DIR__ . "/" . $value;
+ $driver = __DIR__ . "/aminterface/" . $value;
if (!class_exists($class, false)) {
if (file_exists($driver)) {
- include(__DIR__ . "/" . $value);
+ include(__DIR__ . "/aminterface/" . $value);
} else {
throw new \Exception("Class required but file not found " . $driver);
}
@@ -69,6 +69,21 @@ class aminterface
if ($this->_config['enabled']) {
$this->load_subspace();
}
+
+ if ($this->status()) {
+ // Ami is not hard disabled in Amiinterface __construct line 54.
+ if ($this->open()) {
+ // Can open a connection. Now check compatibility with chan-sccp.
+ // will return true if compatible.
+ if (!$this->get_compatible_sccp(true)[1]) {
+ // Close the open socket as will not use
+ $this->close();
+ } else {
+ // is compatible so enable AMI mode
+ $this->ami_mode = true;
+ }
+ }
+ }
}
public function status()
@@ -515,4 +530,35 @@ class aminterface
}
return $cmd_res;
}
+
+ public function get_compatible_sccp($revNumComp=false) {
+ // only called with args from installer to get revision and compatibility
+ $res = $this->getSCCPVersion();
+ if (empty($res)) {
+ return 0;
+ }
+ switch ($res["vCode"]) {
+ case 0:
+ $retval = 0;
+ break;
+ case 433:
+ $retval = 433;
+ break;
+ case 432:
+ $retval = 430;
+ break;
+ case 431:
+ $retval = 431;
+ break;
+ default:
+ $retval = 430;
+ }
+ if ($res['RevisionNum'] < 11063) {
+ $this->useAmiInterface = false;
+ }
+ if ($revNumComp) {
+ return array($retval, true);
+ }
+ return $retval;
+ }
}
diff --git a/Sccp_manager.inc/aminterface/oldinterface.class.php b/Sccp_manager.inc/aminterface/oldinterface.class.php
deleted file mode 100644
index a8d8c86..0000000
--- a/Sccp_manager.inc/aminterface/oldinterface.class.php
+++ /dev/null
@@ -1,525 +0,0 @@
-paren_class = $parent_class;
- $this->error = "";
- }
-
- public function info()
- {
- $Ver = '13.0.4';
- return array('Version' => $Ver,
- 'about' => 'Old interface data ver: ' . $Ver);
- }
-
- /*
- Core Access Function
- */
-
-
- /*
- * 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' => ''),
- 'get_version' => array('cmd' => "sccp show version", 'param' => ''),
- 'get_device' => array('cmd' => "sccp show devices", 'param' => ''),
- 'get_dev_info' => array('cmd' => "sccp show device", 'param' => 'name'),
- 'get_hints' => array('cmd' => "core show hints", 'param' => ''),
- 'sccp_reload' => array('cmd' => "sccp reload force", 'param' => ''),
- 'reset_phone' => array('cmd' => "sccp reset ", 'param' => 'name'), // Жесткая перезагрузка
- 'restart_phone' => array('cmd' => "sccp restart ", 'param' => 'name'),
- 'reload_phone' => array('cmd' => "sccp reload device ", 'param' => 'name'),
- 'reload_line' => array('cmd' => "sccp reload line ", 'param' => 'name'),
- 'reset_token' => array('cmd' => "sccp tokenack ", 'param' => 'name'),
- 'get_realtime_status' => array('cmd' => "realtime mysql status", 'param' => ''),
- );
- $result = true;
- if (!empty($params['cmd'])) {
- $id_cmd = $params['cmd'];
- if (!empty($cmd_list[$id_cmd])) {
- $id_param = $cmd_list[$id_cmd]['param'];
- if (!empty($id_param)) {
- if (!empty($params[$id_param])) {
- $result = $astman->Command($cmd_list[$id_cmd]['cmd'] . ' ' . $params[$id_param]);
- }
- } else {
- $result = $astman->Command($cmd_list[$id_cmd]['cmd']);
- }
- } else {
- switch ($params['cmd']) {
- case 'phone_call':
- if (!empty($params['name'])) {
- $result = $astman->Command('sccp call ' . $params['name'] . ' ' . $params['call']);
- }
- break;
- case 'phone_message':
- if (!empty($params['msg'])) {
- $msg = $params['msg'];
- } else {
- $msg = $this->sccpvalues['servername']['data'];
- }
- if (!empty($params['name'])) {
- $astman->Command('sccp device ' . $params['name'] . ' ' . $msg);
- } else {
- }
- break;
- default:
- $result = false;
- break;
- }
- }
- }
- return $result;
- }
-
- public function sccp_getdevice_info($dev_id)
- {
- if (empty($dev_id)) {
- return array();
- }
- $res = $this->sccp_core_commands(array('cmd' => 'get_dev_info', 'name' => $dev_id));
- $res1 = str_replace(array("\r\n", "\r", "\n"), ';', strip_tags((string) $res['data']));
- if (strpos($res1, 'MAC-Address')) {
- $res2 = substr($res1, 0, strpos($res1, '+--- Buttons '));
- $res1 = explode(';', substr($res2, strpos($res2, 'MAC-Address')));
- foreach ($res1 as $data) {
- if (!empty($data)) {
- $tmp = explode(':', $data);
- $data_key = str_replace(array(" ", "-", "\t"), '_', trim($tmp[0]));
- $res3[$data_key] = $tmp[1];
- }
- }
-
- $res1 = $res3['Skinny_Phone_Type'];
- $res4 = $res3['Config_Phone_Type'];
- if (!empty($res3['Addons'])) {
- $res2 = $res3['Addons'];
- } else {
- $res2 = '';
- }
- $res3['SCCP_Vendor'] = array('vendor' => strtok($res1, ' '), 'model' => strtok('('), 'model_id' => strtok(')'), 'vendor_addon' => strtok($res2, ' '), 'model_addon' => strtok(' '));
- if (empty($res3['SCCP_Vendor']['vendor']) || $res3['SCCP_Vendor']['vendor'] == 'Undefined') {
- $res3['SCCP_Vendor'] = array('vendor' => 'Undefined', 'model' => $res4, 'model_id' => '', 'vendor_addon' => $res3['SCCP_Vendor']['vendor_addon'], 'model_addon' => $res3['SCCP_Vendor']['model_addon']);
-// return $res4;
-// return array();
- }
- return $res3;
- } else {
- return array();
- }
- }
-
- /* Current not use */
- /*
- * 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);
-// array_search($res, $hint_key)) != NULL)
- 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']);
- $ast_key = array();
- for ($i = 0; $i < 3; $i++) {
- $ast_out[$i] = "";
- }
- $i = count($ast_out) - 1;
- $ast_out[--$i] = "";
- $ast_out[--$i] = "";
- foreach ($ast_out as $line) {
- if (strlen($line) > 3) {
- list ($line, $junk) = explode(' ', $line);
- if (!is_bool(strpos($line, ':'))) {
- $line = trim(substr($line, 0, strpos($line, ':')));
- }
- if (isset($ast_key[$line])) {
- if (strlen($ast_key[$line]) < 1) {
- $ast_key[$line] = $line;
- }
- } else {
- $ast_key[$line] = $line;
- }
- }
- }
- return $ast_key;
- }
-
- public function sccp_realtime_status()
- {
- $ast_res = array();
- // Below added for compatibility with AMI result and modified server.info
- $ast_res = ['sccp' => ['message' => 'default value', 'realm' => '', 'status' => 'ERROR']];
- $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');
- }
- }
- return $ast_res;
- }
-
-// !TODO!: -TODO-: install.php is still using the other version number. This is actually where I use another method ?
-
-
- public function get_compatible_sccp()
- {
- $res = $this->getSCCPVersion();
- if (empty($res)) {
- return 0;
- }
- switch ($res["vCode"]) {
- case 0:
- return 0;
- case 433:
- return 433;
-
- case 432:
- case 431:
- return 431;
- default:
- return 430;
- }
- /* if ($res["vCode"] >= 433) {
-
- }
- if ($res["vCode"] >= 431) {
- return 431;
- } else {
- return 430;
- }
- *
- */
-// return $res["vCode"];
- }
-
- public function getSCCPVersion()
- {
- $res = $this->getChanSCCPVersion();
- if (empty($res)) {
- $res = $this->getCoreSCCPVersion();
- }
- return $res;
- }
-
- function getCoreSCCPVersion()
- {
- $result = array();
- $ast_out = $this->sccp_version();
- $result["Version"] = $ast_out[0];
- if ($ast_out[0] == '-1') {
- $result["vCode"] = 0;
- return $result;
- }
- $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;
-// !TODO!: This does not work as you might expect
- 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 $result;
- }
-
- private function sccp_version()
- {
- $ast_out = $this->sccp_core_commands(array('cmd' => 'get_version'));
- if (($ast_out['Response'] == 'Error') || (strpos($ast_out['data'], 'No such command') != false)) {
- return array('-1');
- }
- if (preg_match("/Release.*\(/", $ast_out['data'], $matches)) {
- $ast_out = substr($matches[0], 9, -1);
- return explode(' ', $ast_out);
- } else {
- return array('unknown');
- }
- }
-
- function getChanSCCPVersion()
- {
- global $astman;
- $result = array();
- if (!$astman) {
- return $result;
- }
- $metadata = $this->astman_retrieveJSFromMetaData("");
-// return $metadata;
- 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;
- } elseif ($version_parts[1] == "2") {
- $result["vCode"] = 420;
- } elseif ($version_parts[1] >= "3") {
- if ($version_parts[2] == "3"){
- $result["vCode"] = 433;
- } else {
- $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("RevisionHash", $metadata)) {
- $result["RevisionHash"] = $metadata["RevisionHash"];
- } else {
- $result["RevisionHash"] = '';
- }
- if (array_key_exists("RevisionNum", $metadata)) {
- $result["RevisionNum"] = $metadata["RevisionNum"];
- if ($metadata["RevisionNum"] >= "10403") { // new method, RevisionNum is incremental
- $result["vCode"] = 432;
- }
- if ($metadata["RevisionNum"] >= "10491") { // new method, RevisionNum is incremental
- $result["vCode"] = 433;
- }
- }
- if (array_key_exists("ConfigureEnabled", $metadata)) {
- $result["futures"] = implode(';', $metadata["ConfigureEnabled"]);
- }
- } else {
- return null;
- 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_commands(array('cmd' => 'get_softkey'));
-
- $ast_out = preg_split("/[\n]/", $ast_out['data']);
- $ast_key = array();
- for ($i = 0; $i < 5; $i++) {
- $ast_out[$i] = "";
- }
- $i = count($ast_out) - 1;
- $ast_out[--$i] = "";
- foreach ($ast_out as $line) {
- if (strlen($line) > 3) {
- $line = substr($line, 2);
- list ($line, $junk) = explode(' ', $line);
- if (isset($ast_key[$line])) {
- if (strlen($ast_key[$line]) < 1) {
- $ast_key[$line] = $line;
- }
- } else {
- $ast_key[$line] = $line;
- }
- }
- }
- return $ast_key;
- }
-
- public function sccp_get_active_device()
- {
- $ast_out = $this->sccp_core_commands(array('cmd' => 'get_device'));
-
- $ast_out = preg_split("/[\n]/", $ast_out['data']);
-
- $ast_key = array();
- for ($i = 0; $i < 5; $i++) {
- $ast_out[$i] = "";
- }
- $i = count($ast_out) - 1;
- $ast_out[--$i] = "";
- foreach ($ast_out as $line) {
- if (strlen($line) > 3) {
- $line = substr($line, 2);
- $line = preg_replace("/\s{2,}/", " ", $line);
- $line_arr = explode(' ', $line);
- $it = 1;
- do {
- if ($this->strpos_array($line_arr[$it + 1], array('SEP', 'ATA', 'VG')) === false) {
-// if (strpos($line_arr[$it + 1], 'SEP') === false) {
- $line_arr[0] .= ' ' . $line_arr[$it];
- unset($line_arr[$it]);
- } else {
- break;
- }
- $it++;
- } while ((count($line_arr) > 3) and ( $it < count($line_arr)));
- explode(";|", implode(";|", $line_arr));
- list ($descr, $address, $devname, $status, $token, $junk) = explode(";|", implode(";|", $line_arr));
-
-// list ($descr, $address, $devname, $status, $junk) = $line_arr;
-// if (strlen($ast_key[$devname]) < 1) {
- if (strlen($devname) > 1) {
- $ast_key[$devname] = array('name' => $devname, 'status' => $status, 'address' => $address, 'descr' => $descr, 'token' => $token);
- }
- /*
- if (isset($ast_key[$devname])) {
- if (strlen($ast_key[$devname]) < 1) {
- $ast_key[$devname] = Array('name' => $devname, 'status' => $status, 'address' => $address, 'descr' => $descr, 'token' => $descr);
- }
- } else {
- $ast_key[$devname] = Array('name' => $devname, 'status' => $status, 'address' => $address, 'descr' => $descr, 'token' => $token);
- }
- *
- */
- }
- }
- return $ast_key;
- }
-
- /*
- * Replace sccp_core_commands($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;
- }
- }
-
- private function strpos_array($haystack, $needles)
- {
- if (is_array($needles)) {
- foreach ($needles as $str) {
- if (is_array($str)) {
- $pos = $this->strpos_array($haystack, $str);
- } else {
- $pos = strpos($haystack, $str);
- }
- if ($pos !== false) {
- return $pos;
- }
- }
- } else {
- return strpos($haystack, $needles);
- }
- return false;
- }
-
- private function loc_after($value, $inthat)
- {
- if (!is_bool(strpos($inthat, $value))) {
- return substr($inthat, strpos($inthat, $value) + strlen($value));
- }
- }
-
- 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;
- }
-
- /*
- * [Segments] => ( [0] => general [1] => device [2] => line [3] => softkey )
- */
- function getGlobalsFromMetaData($Segment = '')
- {
- global $astman;
- $params = array();
-
- $action = 'SCCPConfigMetaData';
- if (empty($Segment)) {
- $Segment = 'general';
- }
- $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);
- $result = array();
- if (!empty($decode['Options'])) {
- foreach ($decode['Options'] as $value) {
- $result[$value['Name']] = $value;
- }
- return $result;
- }
- return $decode;
- }
- }
- return $metadata;
- }
-}
diff --git a/Sccp_manager.inc/srvinterface.class.php b/Sccp_manager.inc/srvinterface.class.php
deleted file mode 100644
index 982ecb1..0000000
--- a/Sccp_manager.inc/srvinterface.class.php
+++ /dev/null
@@ -1,350 +0,0 @@
-paren_class = $parent_class;
- if ($this->paren_class == null) {
- $this->paren_class = $this;
- }
- $this->error = "";
- $driverNamespace = "\\FreePBX\\Modules\\Sccp_manager";
- $drivers = array('aminterface' => 'aminterface.class.php', 'oldinterface' => 'oldinterface.class.php');
- $ami_mode = false;
- foreach ($drivers as $key => $value) {
- $class = $driverNamespace . "\\" . $key;
- $driver = __DIR__ . "/aminterface/" . $value;
- if (!class_exists($class, false)) {
- if (file_exists($driver)) {
- include($driver);
- } else {
- throw new \Exception("Class required but file not found " . $driver);
- }
- if (class_exists($class, false)) {
- $this->$key = new $class($this->paren_class);
- $parent_class->$key = $this->$key;
- $this->_info [] = $this->$key->info();
- } else {
- throw new \Exception("Invalid Class inside in the include folder" . $freepbx);
- }
- } else {
- if (is_null($this->$key)) {
- if (class_exists($class, false)) {
- $this->$key = new $class($this->paren_class);
- $this->_info [] = $this->$key->info();
- }
- }
- }
- }
- if ($this->aminterface->status()) {
- // Ami is not hard disabled in Amiinterface __construct line 54.
- if ($this->aminterface->open()) {
- // Can open a connection. Now check compatibility with chan-sccp.
- // will return true if compatible.
- if (!$this->get_compatible_sccp(true)[1]) {
- // Close the open socket as will not use
- $this->aminterface->close();
- } else {
- // is compatible so enable AMI mode
- $this->ami_mode = true;
- }
- }
- }
- }
-
- public function info() {
- $Ver = '14.0.1';
- $info = '';
- foreach ($this->_info as $key => $value) {
- $info .= $value['about'] . "\n ";
- }
- return array('Version' => $Ver,
- 'about' => 'Server interface data ver: ' . $Ver . "\n " . $info);
- }
-
- public function sccpDeviceReset($id = '') {
- if ($this->ami_mode) {
- return $this->aminterface->sccpDeviceReset($id, 'reset');
- } else {
- return $this->oldinterface->sccp_core_commands(array('cmd' => 'reset_phone', 'name' => $id));
- }
- }
-
- public function sccpDeviceRestart($id = '') {
- if ($this->ami_mode) {
- return $this->aminterface->sccpDeviceReset($id, 'restart');
- } else {
- return $this->oldinterface->sccp_core_commands(array('cmd' => 'reset_phone', 'name' => $id));
- }
- }
-
- public function sccp_device_reload($id = '') {
- if ($this->ami_mode) {
- return $this->aminterface->sccpDeviceReset($id, 'full');
- } else {
- return $this->oldinterface->sccp_core_commands(array('cmd' => 'reload_phone', 'name' => $id));
- }
- }
-
- public function sccp_reset_token($id = '') {
- if ($this->ami_mode) {
- return $this->aminterface->sccpDeviceReset($id, 'tokenack');
- } else {
- return $this->oldinterface->sccp_core_commands(array('cmd' => 'reset_token', 'name' => $id));
- }
- }
-
- public function sccp_reload() {
- if ($this->ami_mode) {
- return $this->aminterface->core_sccp_reload();
-// return $this->oldinterface->sccp_core_commands(array('cmd' => 'sccp_reload')); // !!!!!!!!!!!!!!!!!!!!!!!!!--------------------------- Remove
- } else {
- return $this->oldinterface->sccp_core_commands(array('cmd' => 'sccp_reload'));
- }
- }
-
- public function sccp_line_reload($id = '') {
- if ($this->ami_mode) {
- return $this->oldinterface->sccp_core_commands(array('cmd' => 'reload_line', 'name' => $id));
- } else {
- return $this->oldinterface->sccp_core_commands(array('cmd' => 'reload_line', 'name' => $id));
- }
- }
-
- private function sccp_core_commands($params = array()) {
-
- if (!$this->ami_mode) {
- return $this->oldinterface->sccp_core_commands($params);
- }
-
- if (!empty($params['cmd'])) {
- switch ($params['cmd']) {
- case 'reset_phone':
- return $this->aminterface->sccpDeviceReset($params['name'], 'reset');
- break;
- case 'restart_phone':
- return $this->aminterface->sccpDeviceReset($params['name'], 'restart');
- break;
- case 'reload_phone':
- return $this->aminterface->sccpDeviceReset($params['name'], 'full');
- break;
- case 'reset_token':
- return $this->aminterface->sccpDeviceReset($params['name'], 'tokenack');
- break;
- case 'reload_line':
-// return $this->aminterface->sccpDeviceReset($params['name'], 'full');
- break;
-// case 'get_version':
-// case 'sccp_reload':
-// break;
-// case 'get_realtime_status':
-// break;
-// case 'phone_call':
-// case 'phone_message':
-
- case 'get_softkey':
- case 'get_device':
- case 'get_hints':
- case 'get_dev_info':
- print_r($params);
- throw new \Exception("Invalid Class inside in the include folder" . $params['cmd']);
- die();
- break;
- default:
- return $this->oldinterface->sccp_core_commands($params);
- break;
- }
- }
-
- }
-
- public function sccp_getdevice_info($dev_id) {
- if (empty($dev_id)) {
- return array();
- }
- if ($this->ami_mode) {
- return $this->aminterface->sccp_getdevice_info($dev_id);
- } else {
- return $this->oldinterface->sccp_getdevice_info($dev_id);
- }
- }
-
- public function sccp_list_hints() {
- if ($this->ami_mode) {
- return $this->aminterface->core_list_hints();
- } else {
- return $this->oldinterface->sccp_list_hints();
- }
- }
-
- public function sccp_list_all_hints() {
-
- if ($this->ami_mode) {
- return $this->aminterface->core_list_all_hints();
- } else {
- return $this->oldinterface->sccp_list_all_hints();
- }
- }
-
- public function sccp_realtime_status() {
- if ($this->ami_mode) {
- return $this->aminterface->getRealTimeStatus();
- } else {
- return $this->oldinterface->sccp_realtime_status();
- }
- }
-
- public function get_compatible_sccp($revNumComp=false) {
- // only called with args from installer to get revision and compatibility
- $res = $this->getSCCPVersion();
- if (empty($res)) {
- return 0;
- }
- switch ($res["vCode"]) {
- case 0:
- $retval = 0;
- break;
- case 433:
- $retval = 433;
- break;
- case 432:
- $retval = 430;
- break;
- case 431:
- $retval = 431;
- break;
- default:
- $retval = 430;
- }
- if ($res['RevisionNum'] < 11063) {
- $this->useAmiInterface = false;
- }
- if ($revNumComp) {
- return array($retval, $this->useAmiInterface);
- }
- return $retval;
- }
-
- public function getSCCPVersion() {
- $res = $this->getChanSCCPVersion();
- if (empty($res)) {
- $res = $this->oldinterface->getCoreSCCPVersion();
- }
- return $res;
- }
-
- public function sccp_list_keysets() {
- if ($this->ami_mode) {
- return $this->aminterface->sccp_list_keysets();
- } else {
- return $this->oldinterface->sccp_list_keysets();
- }
-
- }
-
- public function sccp_get_active_device() {
- if ($this->ami_mode) {
- return $this->aminterface->sccp_get_active_device();
- } else {
- return $this->oldinterface->sccp_get_active_device();
- }
- }
-
- function getChanSCCPVersion() {
- if ($this->ami_mode) {
- return $this->aminterface->getSCCPVersion();
- } else {
- return $this->oldinterface->getChanSCCPVersion();
- }
- }
-
- // ---------------------------- Debug Data -------------------------------------------
- function t_get_ami_data() {
- global $amp_conf;
- $fp = fsockopen("127.0.0.1", "5038", $errno, $errstr, 10);
- if (!$fp) {
- echo "$errstr ($errno)
\n";
- } else {
- $time_connect = microtime_float();
- 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: SCCPShowDevice\r\n");
-// fputs($fp,"Segment: general\r\n");
-// fputs($fp,"DeviceName: SEP00070E36555C\r\n");
-// fputs ($fp,"Action: DeviceStateList\r\n");
- fputs($fp, "Action: SCCPShowDevices\r\n");
- fputs($fp, "Segment: general\r\n");
-
-// fputs ($fp,"Action: SCCPShowDevice\r\n");
-// fputs ($fp,"DeviceName: SEP00070E36555C\r\n");
-//
-// fputs($fp, "Action: ExtensionStateList\r\n");
-// fputs($fp, "Action: ExtensionStateList\r\n");
-// fputs($fp, "Command: sccp show version\r\n");
-// fputs($fp, "Command: core show hints\r\n");
-// fputs ($fp,"Segment: general\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");
- $time_send = microtime_float();
- /*
- 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");
- $time_logoff = microtime_float();
-
-// print_r(fgets($fp));
- $resp = '';
- while (!feof($fp)) {
- $resp .= fgets($fp);
- }
- $time_resp = microtime_float();
- $resp .= "\r\n\r\n Connect :" . ($time_send - $time_connect) . " Logoff :" . ($time_logoff - $time_send) . " Response :" . ($time_resp - $time_logoff) . "\r\n\r\n ";
-// print_r(fgets($fp));
-// print_r('
');
-// echo fgets($fp, 128);
- }
- fclose($fp);
- return $resp;
- }
-
-}
diff --git a/install.php b/install.php
index b4af832..966848d 100644
--- a/install.php
+++ b/install.php
@@ -15,17 +15,17 @@ global $db;
global $amp_conf;
global $astman;
global $version;
-global $srvinterface;
+global $aminterface;
global $mobile_hw;
global $useAmiForSoftKeys;
$mobile_hw = '0';
-$class = "\\FreePBX\\Modules\\Sccp_manager\\srvinterface";
+$class = "\\FreePBX\\Modules\\Sccp_manager\\aminterface";
if (!class_exists($class, false)) {
- include(__DIR__ . "/Sccp_manager.inc/srvinterface.class.php");
+ include(__DIR__ . "/Sccp_manager.inc/aminterface/amiinterface.class.php");
}
if (class_exists($class, false)) {
- $srvinterface = new $class();
+ $aminterface = new $class();
}
function Get_DB_config($sccp_compatible)
{
@@ -447,12 +447,12 @@ function CheckAsteriskVersion()
function CheckChanSCCPCompatible()
{
global $chanSCCPWarning;
- global $srvinterface, $astman;
+ global $aminterface, $astman;
if (!$astman) {
ie_freepbx('No asterisk manager connection provided!. Installation Failed');
}
// calling with true returns array with compatibility and RevisionNumber
- return $srvinterface->get_compatible_sccp(true);
+ return $aminterface->get_compatible_sccp(true);
}
function InstallDB_Buttons()
diff --git a/views/formShow.php b/views/formShow.php
index 8eb9117..847f66f 100644
--- a/views/formShow.php
+++ b/views/formShow.php
@@ -42,10 +42,10 @@ $sofkey_list = array();
$model_list = array();
$device_list = array();
$dialplan_list = array();
-
+
//$time_zone = \FreePBX::Sccp_manager()-> extconfigs-> getextConfig('cisco_time');
//$system_time_zone = \FreePBX::Sccp_manager()->getSysnemTimeZone();
-//$sofkey_list = \FreePBX::Sccp_manager()-> srvinterface -> sccp_list_keysets();
+//$sofkey_list = \FreePBX::Sccp_manager()-> aminterface->sccp_list_keysets();
//$model_list = \FreePBX::Sccp_manager()->dbinterface->HWextension_db_SccpTableData("HWDevice");
//$extension_list = \FreePBX::Sccp_manager()->dbinterface->HWextension_db_SccpTableData("HWextension");
//$device_list = \FreePBX::Sccp_manager()->dbinterface->HWextension_db_SccpTableData("SccpDevice");
@@ -109,24 +109,24 @@ foreach ($items as $child) {
if (!empty($child ->class)) {
$res_sec_class = (string)$child ->class;
}
-
+
if (empty($child->nameseparator)) {
$child->nameseparator = ' / ';
}
$i = 0;
-
+
echo '';
-
+
?>
"); - print_r(""); -// print_r("DIRECT START"); -// print_r($this->sccpvalues['ccm_address']); -//print_r($this->get_php_classes('\\FreePBX\\modules')); -// print_r(get_declared_classes()); -// $a = $this->aminterface->_config; -// print_r($a); -// print_r($this->aminterface->info()); -//print_r(get_declared_classes()); -// print_r($this->aminterface->open()); -// $time_start = microtime_float(); -// $this->aminterface->open(); -// $time_connect = microtime_float(); -// print_r($this->aminterface->send(new \FreePBX\modules\Sccp_manager\aminterface\SCCPShowSoftkeySetsAction())); -// $a = new \FreePBX\modules\Sccp_manager\aminterface\SCCPShowSoftkeySetsAction(); -// $a = new \FreePBX\modules\Sccp_manager\aminterface\ExtensionStateListAction(); -// $a = new \FreePBX\modules\Sccp_manager\aminterface\SCCPShowDeviceAction('SEP00070E36555C'); -// $a = new \FreePBX\modules\Sccp_manager\aminterface\SCCPDeviceRestartAction('SEP00070E36555C'); -// $a = new \FreePBX\modules\Sccp_manager\aminterface\ReloadAction('chan_sccp'); -//$a = new \FreePBX\modules\Sccp_manager\aminterface\CommandAction('core show hints'); -/* - $time_start = microtime_float(); - print_r($this->srvinterface->t_get_ami_data()); - $time_get_dl = microtime_float()-$time_start; - print_r('
"); -//print_r(array_column($timezone_abbreviations, 'timezone_id')); - print_r($Ts_set); - $tz_tmp = array(); - - foreach ($timezone_abbreviations as $subArray) { - $dddd = array_search($Ts_set, array_column($subArray, 'timezone_id')); - if (!empty($dddd)) { - $tz_tmp[] = $subArray[$dddd]; - } - } - - if (empty($tz_tmp)) { - print_r('erroe'); - } - if (count($tz_tmp)==1) { - $time_set = $tz_tmp[0]; - } else { - $tmp_dt = new DateTime(null, new DateTimeZone($Ts_set)); - $tmp_ofset = $tmp_dt->getOffset(); - foreach ($tz_tmp as $subArray) { - if ($subArray['offset'] == $tmp_ofset) { - $time_set = $subArray; - } - } - } - - print_r("
"); -//print_r($time_set); - print_r($this->sccpvalues['ntp_timezone']); -//print_r($tz_tmp); - print_r("
"); - print_r("
"); - - print_r("
"); -//print_r($timezone_abbreviations); -//print_r($timezone_identifiers); -//print_r($timezone); -//print_r($transitions); - - - print_r("
"); - print_r("
Function | Old Time | Ami Time |
---|---|---|
' . $key . ' | ' . $value['old'] . ' | ' . $value['ami'] . ' |