From 48041fc62c79594c61e42b3e3bb45b460c1e3123 Mon Sep 17 00:00:00 2001
From: steve-lad <72376554+steve-lad@users.noreply.github.com>
Date: Thu, 28 Jan 2021 10:25:02 +0100
Subject: [PATCH 1/2] Cleaned up messages
Improved message readability. Atom removed extraneous white spaces and lines
---
.../aminterface/Message.class.php | 2 +-
.../aminterface/Response.class.php | 19 ++++++++----------
.../aminterface/aminterface.class.php | 8 ++++----
Sccp_manager.inc/extconfigs.class.php | 20 +++++++++----------
views/server.info.php | 20 +++++++++----------
5 files changed, 33 insertions(+), 36 deletions(-)
diff --git a/Sccp_manager.inc/aminterface/Message.class.php b/Sccp_manager.inc/aminterface/Message.class.php
index f52178b..aedabc4 100644
--- a/Sccp_manager.inc/aminterface/Message.class.php
+++ b/Sccp_manager.inc/aminterface/Message.class.php
@@ -12,7 +12,7 @@ namespace FreePBX\modules\Sccp_manager\aminterface;
class AMIException extends \Exception
{
-
+
}
abstract class Message
diff --git a/Sccp_manager.inc/aminterface/Response.class.php b/Sccp_manager.inc/aminterface/Response.class.php
index c4bd495..2b524bf 100644
--- a/Sccp_manager.inc/aminterface/Response.class.php
+++ b/Sccp_manager.inc/aminterface/Response.class.php
@@ -72,7 +72,6 @@ abstract class Response extends IncomingMessage
$this->setKey('ActionId', $actionId);
}
-
public function getVariable($_rawContent, $_fields = '')
{
$lines = explode(Message::EOL, $_rawContent);
@@ -119,7 +118,6 @@ class Login_Response extends Response
class Command_Response extends Response
{
private $_temptable;
-
public function __construct($rawContent)
{
// print_r('
---- r --
');
@@ -127,7 +125,6 @@ class Command_Response extends Response
// print_r('
---- re --
');
$this->_temptable = array();
parent::__construct($rawContent);
-
$lines = explode(Message::EOL, $rawContent);
foreach ($lines as $line) {
$content = explode(':', $line);
@@ -148,7 +145,7 @@ class Command_Response extends Response
if (!empty($this->_temptable)) {
$this->setKey('output', 'array');
}
-
+
$this->_completed = $this->isSuccess();
// return $this->isSuccess();
}
@@ -165,7 +162,7 @@ class Command_Response extends Response
class SCCPGeneric_Response extends Response
{
-
+
protected $_tables;
private $_temptable;
@@ -208,7 +205,7 @@ class SCCPGeneric_Response extends Response
$this->_completed = true;
}
}
-
+
protected function ConvertTableData($_tablename, $_fkey, $_fields)
{
$_rawtable = $this->Table2Array($_tablename);
@@ -278,8 +275,8 @@ class SCCPGeneric_Response extends Response
}
return $result;
}
-
-
+
+
public function hasTable()
{
if (is_array($this->_tables)) {
@@ -291,7 +288,7 @@ class SCCPGeneric_Response extends Response
{
return (is_array($this->_tables)) ? array_keys($this->_tables) : null;
}
-
+
public function Table2Array($tablename = '')
{
$result =array();
@@ -324,7 +321,7 @@ class SCCPGeneric_Response extends Response
return false;
}
}
-
+
public function getTable($tablename)
{
if ($this->hasTable() && array_key_exists($tablename, $this->_tables)) {
@@ -349,7 +346,7 @@ class SCCPGeneric_Response extends Response
// $this->getVariable($rawContent, $_fields);
$this->_completed = !$this->isList();
}
-
+
public function getResult()
{
if ($this->getKey('JSON') != null) {
diff --git a/Sccp_manager.inc/aminterface/aminterface.class.php b/Sccp_manager.inc/aminterface/aminterface.class.php
index 31d24e7..cbbb102 100644
--- a/Sccp_manager.inc/aminterface/aminterface.class.php
+++ b/Sccp_manager.inc/aminterface/aminterface.class.php
@@ -55,8 +55,8 @@ class aminterface
$this->_connect_state = false;
$this->_error = array();
$this->_config = array('host' => 'localhost', 'user' => '', 'pass' => '', 'port' => '5038', 'tsoket' => 'tcp://', 'timeout' => 30, 'enabled' => false);
-
-
+
+
$this->_eventListeners = array();
// $this->_eventFactory = new EventFactoryImpl(\Logger::getLogger('EventFactory'));
// $this->_responseFactory = new ResponseFactoryImpl(\Logger::getLogger('ResponseFactory'));
@@ -259,7 +259,7 @@ class aminterface
$response = $this->findResponse($event);
// print_r($response);
// print_r('
--- E2 Response Type 2 ----------
');
-
+
if ($response === false || $response->isComplete()) {
$this->dispatch($event); // не работает
} else {
@@ -409,7 +409,7 @@ class aminterface
$listener = $data[0];
$predicate = $data[1];
print_r($data);
-
+
if (is_callable($predicate) && !call_user_func($predicate, $message)) {
continue;
}
diff --git a/Sccp_manager.inc/extconfigs.class.php b/Sccp_manager.inc/extconfigs.class.php
index c04eda7..58665c9 100644
--- a/Sccp_manager.inc/extconfigs.class.php
+++ b/Sccp_manager.inc/extconfigs.class.php
@@ -45,11 +45,11 @@ class extconfigs
$tmp_dt = new \DateTime(null, new \DateTimeZone($index));
$tmp_ofset = $tmp_dt->getOffset();
return $tmp_ofset / 60;
-
+
break;
case 'sccp_timezone': // Sccp manafer: 1400 (+ Id) :2007 (+ Id)
$result = array();
-
+
if (empty($index)) {
return array('offset' => '00', 'daylight' => '', 'cisco_code' => 'Greenwich');
}
@@ -57,7 +57,7 @@ class extconfigs
return $this->get_cisco_time_zone($index);
} else {
$timezone_abbreviations = \DateTimeZone::listAbbreviations();
-
+
$tz_tmp = array();
foreach ($timezone_abbreviations as $subArray) {
$tf_idt = array_search($index, array_column($subArray, 'timezone_id'));
@@ -109,7 +109,7 @@ class extconfigs
private function get_cisco_time_zone($tzc)
{
-
+
if ((empty($tzc)) or (!array_key_exists($tzc, $this->cisco_timezone))) {
// return array('offset' => '00', 'daylight' => '', 'cisco_code' => 'Greenwich');
return array();
@@ -464,14 +464,14 @@ class extconfigs
$res['extconfig'] = 'OK';
if (empty($res['sccpdevice'])) {
- $res['extconfig'] = ' Options "Sccpdevice" not config ';
+ $res['extconfig'] = ' Option "Sccpdevice" is not configured ';
}
if (empty($res['sccpline'])) {
- $res['extconfig'] = ' Options "Sccpline" not config ';
+ $res['extconfig'] = ' Option "Sccpline" is not configured ';
}
if (empty($res['extconfigfile'])) {
- $res['extconfig'] = 'File extconfig.conf not exist';
+ $res['extconfig'] = 'File extconfig.conf does not exist';
}
@@ -483,10 +483,10 @@ class extconfigs
if (file_exists($dir . '/res_mysql.conf')) {
$res_conf = $cnf_read->getConfig('res_mysql.conf');
if (empty($res_conf[$realm])) {
- $res['mysqlconfig'] = 'Not Config in file: res_mysql.conf';
+ $res['mysqlconfig'] = 'Config not found in file: res_mysql.conf';
} else {
if ($res_conf[$realm]['dbsock'] != $def_bd_config['dbsock']) {
- $res['mysqlconfig'] = 'Mysql Soket Error in file: res_mysql.conf';
+ $res['mysqlconfig'] = 'Mysql Socket Error in file: res_mysql.conf';
}
}
if (empty($res['mysqlconfig'])) {
@@ -500,7 +500,7 @@ class extconfigs
$res['mysqlconfig'] = 'Not Config in file: res_config_mysql.conf';
} else {
if ($res_conf[$realm]['dbsock'] != $def_bd_config['dbsock']) {
- $res['mysqlconfig'] = 'Mysql Soket Error in file: res_config_mysql.conf';
+ $res['mysqlconfig'] = 'Mysql Socket Error in file: res_config_mysql.conf';
}
}
if (empty($res['mysqlconfig'])) {
diff --git a/views/server.info.php b/views/server.info.php
index b227895..2785b4c 100644
--- a/views/server.info.php
+++ b/views/server.info.php
@@ -14,6 +14,7 @@ $ast_realtime = $this->srvinterface->sccp_realtime_status();
$ast_realm = (empty($ast_realtime['sccp']) ? '' : 'sccp');
+// if there are multiple connections, this will only return the first.
foreach ($ast_realtime as $key => $value) {
if (empty($ast_realm)) {
if ($value['status'] == 'OK') {
@@ -61,7 +62,7 @@ if ($db_Schema == 0) {
}
if (empty($ast_realtime)) {
- $info['RealTime'] = array('Version' => 'Error', 'about' => '
info_warning as $key => $value) { @@ -472,12 +473,12 @@ if (!empty($this->info_warning)) { } if (!empty($this->class_error)) { - ?> + ?>Diagnostic information about SCCP Manager errors
-+
There is an error in the :class_error); ?>@@ -493,7 +494,7 @@ if (!empty($this->class_error)) {Sccp Manager V.sccp_manager_ver); ?> Info
-+
@@ -517,4 +518,3 @@ foreach ($info as $key => $value) { showGroup('sccp_info', 0); ?> - From c929649909811dd38f398a1386ea7ffaeaaf9c07 Mon Sep 17 00:00:00 2001 From: steve-lad <72376554+steve-lad@users.noreply.github.com> Date: Thu, 28 Jan 2021 11:18:48 +0100 Subject: [PATCH 2/2] Update AMI Response Bring branch up to level of previous Pull which can now be deleted --- .../aminterface/Response.class.php | 26 +++++++++---- .../aminterface/aminterface.class.php | 37 ++++++++++++------- .../aminterface/oldinterface.class.php | 2 + Sccp_manager.inc/extconfigs.class.php | 4 +- Sccp_manager.inc/srvinterface.class.php | 13 ++++--- views/server.info.php | 8 ++-- 6 files changed, 57 insertions(+), 33 deletions(-) diff --git a/Sccp_manager.inc/aminterface/Response.class.php b/Sccp_manager.inc/aminterface/Response.class.php index 2b524bf..48582af 100644 --- a/Sccp_manager.inc/aminterface/Response.class.php +++ b/Sccp_manager.inc/aminterface/Response.class.php @@ -130,39 +130,47 @@ class Command_Response extends Response $content = explode(':', $line); if (is_array($content)) { switch (strtolower($content[0])) { + case 'actionid': + $this->_temptable['ActionID'] = trim($content[1]); + break; + case 'response': + $this->_temptable['Response'] = trim($content[1]); + break; + case 'privilege': + $this->_temptable['Privilege'] = trim($content[1]); + break; case 'output': - $_tmp_str = trim(substr($line, 7)); - if (!empty($_tmp_str)) { - $this->_temptable['output'][]= trim(substr($line, 7)); - } + // included for backward compatibility with earlier versions of chan_sccp_b. AMI api does not precede command output with Output + $this->_temptable['Output'] = explode(PHP_EOL,str_replace(PHP_EOL.'--END COMMAND--', '',trim($content[1]))); break; default: - $this->_temptable[$content[0]][]= trim(substr($line, strlen($content[0])+1)); + $this->_temptable['Output'] = explode(PHP_EOL,str_replace(PHP_EOL.'--END COMMAND--', '', trim($line))); break; } } } +/* Not required $_temptable cannot be empty as has at least an actionID - see also getResult if (!empty($this->_temptable)) { $this->setKey('output', 'array'); } - +*/ $this->_completed = $this->isSuccess(); // return $this->isSuccess(); } public function getResult() { +/* Below test no longer valid as key no longer set if (stristr($this->getKey('output'), 'array') !== false) { $result = $this->_temptable; } else { $result = $this->getMessage(); } - return $result; +*/ return $this->_temptable; } } class SCCPGeneric_Response extends Response { - protected $_tables; private $_temptable; @@ -210,6 +218,8 @@ class SCCPGeneric_Response extends Response { $_rawtable = $this->Table2Array($_tablename); $result = array(); + // Check that there is actually data to be converted + if (empty($_rawtable)) { return $result;} foreach ($_rawtable as $_row) { $all_key_ok = true; if (is_array($_fkey)) { diff --git a/Sccp_manager.inc/aminterface/aminterface.class.php b/Sccp_manager.inc/aminterface/aminterface.class.php index cbbb102..4ad5f19 100644 --- a/Sccp_manager.inc/aminterface/aminterface.class.php +++ b/Sccp_manager.inc/aminterface/aminterface.class.php @@ -54,15 +54,13 @@ class aminterface $this->_socket = false; $this->_connect_state = false; $this->_error = array(); - $this->_config = array('host' => 'localhost', 'user' => '', 'pass' => '', 'port' => '5038', 'tsoket' => 'tcp://', 'timeout' => 30, 'enabled' => false); - - + $this->_config = array('host' => 'localhost', 'user' => '', 'pass' => '', 'port' => '5038', 'tsoket' => 'tcp://', 'timeout' => 30, 'enabled' => true); $this->_eventListeners = array(); // $this->_eventFactory = new EventFactoryImpl(\Logger::getLogger('EventFactory')); // $this->_responseFactory = new ResponseFactoryImpl(\Logger::getLogger('ResponseFactory')); $this->_incomingQueue = array(); $this->_lastActionId = false; - + $fld_conf = array('user' => 'AMPMGRUSER', 'pass' => 'AMPMGRPASS'); if (isset($amp_conf['AMPMGRUSER'])) { foreach ($fld_conf as $key => $value) { @@ -259,7 +257,6 @@ class aminterface $response = $this->findResponse($event); // print_r($response); // print_r('
--- E2 Response Type 2 ----------
'); - if ($response === false || $response->isComplete()) { $this->dispatch($event); // не работает } else { @@ -267,8 +264,8 @@ class aminterface } } } else { - // broken ami.. sending a response with events without - // Event and ActionId + // broken ami most probably through changes in chan_sccp_b. + //sending a response with events without Event and ActionId $this->_msgToDebug(1, 'resp broken ami'); $bMsg = 'Event: ResponseEvent' . "\r\n"; $bMsg .= 'ActionId: ' . $this->_lastActionId . "\r\n" . $aMsg; @@ -543,17 +540,29 @@ class aminterface function getRealTimeStatus() { + // Initialise array with default values to eliminate testing later $result = array(); + $cmd_res = array(); + $cmd_res = ['sccp' => ['message' => 'default value', 'realm' => '', 'status' => 'ERROR']]; if ($this->_connect_state) { $_action = new \FreePBX\modules\Sccp_manager\aminterface\CommandAction('realtime mysql status'); - $_response = $this->send($_action); - $res = $_response->getResult(); - if (!empty($res['output'])) { - $result = $res['output']; - } else { - $result = $_response->getMessage(); + $result = $this->send($_action)->getResult(); + } + if (is_array($result['Output'])) { + foreach ($result['Output'] as $aline) { + if (strlen($aline) > 3) { + $temp_strings = explode(' ', $aline); + $cmd_res_key = $temp_strings[0]; + foreach ($temp_strings as $test_string) { + if (strpos($test_string, '@')) { + $this_realm = $test_string; + break; + } + } + $cmd_res[$cmd_res_key] = array('message' => $aline, 'realm' => $this_realm, 'status' => strpos($aline, 'connected') ? 'OK' : 'ERROR'); + } } } - return $result; + return $cmd_res; } } diff --git a/Sccp_manager.inc/aminterface/oldinterface.class.php b/Sccp_manager.inc/aminterface/oldinterface.class.php index bf3ca10..519495e 100644 --- a/Sccp_manager.inc/aminterface/oldinterface.class.php +++ b/Sccp_manager.inc/aminterface/oldinterface.class.php @@ -180,6 +180,8 @@ class oldinterface 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) { diff --git a/Sccp_manager.inc/extconfigs.class.php b/Sccp_manager.inc/extconfigs.class.php index 58665c9..78ddb6a 100644 --- a/Sccp_manager.inc/extconfigs.class.php +++ b/Sccp_manager.inc/extconfigs.class.php @@ -419,10 +419,10 @@ class extconfigs { global $amp_conf; $res = array(); - if (empty($realm)) { +/* if (empty($realm)) { $realm = 'sccp'; } - $cnf_int = \FreePBX::Config(); +*/ $cnf_int = \FreePBX::Config(); $cnf_wr = \FreePBX::WriteConfig(); $cnf_read = \FreePBX::LoadConfig(); diff --git a/Sccp_manager.inc/srvinterface.class.php b/Sccp_manager.inc/srvinterface.class.php index 5c26ddc..f2e50cc 100644 --- a/Sccp_manager.inc/srvinterface.class.php +++ b/Sccp_manager.inc/srvinterface.class.php @@ -193,8 +193,8 @@ class srvinterface { if (!$this->ami_mode) { return $this->oldinterface->sccp_realtime_status(); } else { - $ast_out = $this->aminterface->getRealTimeStatus(); - if (is_array($ast_out)) { + return $this->aminterface->getRealTimeStatus(); +/* if (is_array($ast_out)) { foreach ($ast_out as $aline) { if (strlen($aline) > 3) { $ast_key = strstr(trim($aline), ' ', true); @@ -203,7 +203,7 @@ class srvinterface { } } return $ast_res; - } +*/ } } public function get_compatible_sccp() { @@ -236,11 +236,12 @@ class srvinterface { public function sccp_list_keysets() { - if ($this->ami_mode) { +/* if ($this->ami_mode) { return $this->aminterface->sccp_list_keysets(); } else { - return $this->oldinterface->sccp_list_keysets(); - } +*/ return $this->oldinterface->sccp_list_keysets(); +// } + } public function sccp_get_active_device() { diff --git a/views/server.info.php b/views/server.info.php index 2785b4c..3982fed 100644 --- a/views/server.info.php +++ b/views/server.info.php @@ -12,7 +12,7 @@ $driver = $this->FreePBX->Core->getAllDriversInfo(); $core = $this->srvinterface->getSCCPVersion(); $ast_realtime = $this->srvinterface->sccp_realtime_status(); -$ast_realm = (empty($ast_realtime['sccp']) ? '' : 'sccp'); +//$ast_realm = (empty($ast_realtime['sccp']) ? '' : 'sccp'); // if there are multiple connections, this will only return the first. foreach ($ast_realtime as $key => $value) { @@ -70,13 +70,15 @@ if (empty($ast_realtime)) { if ($key == $ast_realm) { if ($value['status'] == 'OK') { $rt_sccp = 'TEST OK'; - $rt_info .= 'SCCP Connections found'; + $rt_info .= 'Using SCCP connection found to database: '.$value['realm'] . ' with connector: ['. $key .']'; } else { $rt_sccp = 'SCCP ERROR'; $rt_info .= 'Error : ' . $value['message'] . ''; } } elseif ($value['status'] == 'ERROR') { - $rt_info .= 'Found error in realtime sectoin [' . $key . '] : ' . $value['message'] . ''; + $rt_info .= 'No connector found for [' . $key . '] : ' . $value['message'] . ''; + } elseif ($value['status'] == 'OK') { + $rt_info .= 'Alternative connector found to database '.$value['realm'] . ' with connector: ['. $key . ']'; } } $info['RealTime'] = array('Version' => $rt_sccp, 'about' => $rt_info);