Merge pull request #97 from steve-lad/Update-AMI-getRealTimeStatus
Update ami get real time status
This commit is contained in:
commit
c0cf0b15d7
|
@ -72,7 +72,6 @@ abstract class Response extends IncomingMessage
|
||||||
$this->setKey('ActionId', $actionId);
|
$this->setKey('ActionId', $actionId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function getVariable($_rawContent, $_fields = '')
|
public function getVariable($_rawContent, $_fields = '')
|
||||||
{
|
{
|
||||||
$lines = explode(Message::EOL, $_rawContent);
|
$lines = explode(Message::EOL, $_rawContent);
|
||||||
|
@ -119,7 +118,6 @@ class Login_Response extends Response
|
||||||
class Command_Response extends Response
|
class Command_Response extends Response
|
||||||
{
|
{
|
||||||
private $_temptable;
|
private $_temptable;
|
||||||
|
|
||||||
public function __construct($rawContent)
|
public function __construct($rawContent)
|
||||||
{
|
{
|
||||||
// print_r('<br>---- r --<br>');
|
// print_r('<br>---- r --<br>');
|
||||||
|
@ -127,45 +125,52 @@ class Command_Response extends Response
|
||||||
// print_r('<br>---- re --<br>');
|
// print_r('<br>---- re --<br>');
|
||||||
$this->_temptable = array();
|
$this->_temptable = array();
|
||||||
parent::__construct($rawContent);
|
parent::__construct($rawContent);
|
||||||
|
|
||||||
$lines = explode(Message::EOL, $rawContent);
|
$lines = explode(Message::EOL, $rawContent);
|
||||||
foreach ($lines as $line) {
|
foreach ($lines as $line) {
|
||||||
$content = explode(':', $line);
|
$content = explode(':', $line);
|
||||||
if (is_array($content)) {
|
if (is_array($content)) {
|
||||||
switch (strtolower($content[0])) {
|
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':
|
case 'output':
|
||||||
$_tmp_str = trim(substr($line, 7));
|
// included for backward compatibility with earlier versions of chan_sccp_b. AMI api does not precede command output with Output
|
||||||
if (!empty($_tmp_str)) {
|
$this->_temptable['Output'] = explode(PHP_EOL,str_replace(PHP_EOL.'--END COMMAND--', '',trim($content[1])));
|
||||||
$this->_temptable['output'][]= trim(substr($line, 7));
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
default:
|
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;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/* Not required $_temptable cannot be empty as has at least an actionID - see also getResult
|
||||||
if (!empty($this->_temptable)) {
|
if (!empty($this->_temptable)) {
|
||||||
$this->setKey('output', 'array');
|
$this->setKey('output', 'array');
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
$this->_completed = $this->isSuccess();
|
$this->_completed = $this->isSuccess();
|
||||||
// return $this->isSuccess();
|
// return $this->isSuccess();
|
||||||
}
|
}
|
||||||
public function getResult()
|
public function getResult()
|
||||||
{
|
{
|
||||||
|
/* Below test no longer valid as key no longer set
|
||||||
if (stristr($this->getKey('output'), 'array') !== false) {
|
if (stristr($this->getKey('output'), 'array') !== false) {
|
||||||
$result = $this->_temptable;
|
$result = $this->_temptable;
|
||||||
} else {
|
} else {
|
||||||
$result = $this->getMessage();
|
$result = $this->getMessage();
|
||||||
}
|
}
|
||||||
return $result;
|
*/ return $this->_temptable;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class SCCPGeneric_Response extends Response
|
class SCCPGeneric_Response extends Response
|
||||||
{
|
{
|
||||||
|
|
||||||
protected $_tables;
|
protected $_tables;
|
||||||
private $_temptable;
|
private $_temptable;
|
||||||
|
|
||||||
|
@ -213,6 +218,8 @@ class SCCPGeneric_Response extends Response
|
||||||
{
|
{
|
||||||
$_rawtable = $this->Table2Array($_tablename);
|
$_rawtable = $this->Table2Array($_tablename);
|
||||||
$result = array();
|
$result = array();
|
||||||
|
// Check that there is actually data to be converted
|
||||||
|
if (empty($_rawtable)) { return $result;}
|
||||||
foreach ($_rawtable as $_row) {
|
foreach ($_rawtable as $_row) {
|
||||||
$all_key_ok = true;
|
$all_key_ok = true;
|
||||||
if (is_array($_fkey)) {
|
if (is_array($_fkey)) {
|
||||||
|
|
|
@ -54,9 +54,7 @@ class aminterface
|
||||||
$this->_socket = false;
|
$this->_socket = false;
|
||||||
$this->_connect_state = false;
|
$this->_connect_state = false;
|
||||||
$this->_error = array();
|
$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->_eventListeners = array();
|
||||||
// $this->_eventFactory = new EventFactoryImpl(\Logger::getLogger('EventFactory'));
|
// $this->_eventFactory = new EventFactoryImpl(\Logger::getLogger('EventFactory'));
|
||||||
// $this->_responseFactory = new ResponseFactoryImpl(\Logger::getLogger('ResponseFactory'));
|
// $this->_responseFactory = new ResponseFactoryImpl(\Logger::getLogger('ResponseFactory'));
|
||||||
|
@ -259,7 +257,6 @@ class aminterface
|
||||||
$response = $this->findResponse($event);
|
$response = $this->findResponse($event);
|
||||||
// print_r($response);
|
// print_r($response);
|
||||||
// print_r('<br>--- E2 Response Type 2 ----------<br>');
|
// print_r('<br>--- E2 Response Type 2 ----------<br>');
|
||||||
|
|
||||||
if ($response === false || $response->isComplete()) {
|
if ($response === false || $response->isComplete()) {
|
||||||
$this->dispatch($event); // не работает
|
$this->dispatch($event); // не работает
|
||||||
} else {
|
} else {
|
||||||
|
@ -267,8 +264,8 @@ class aminterface
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// broken ami.. sending a response with events without
|
// broken ami most probably through changes in chan_sccp_b.
|
||||||
// Event and ActionId
|
//sending a response with events without Event and ActionId
|
||||||
$this->_msgToDebug(1, 'resp broken ami');
|
$this->_msgToDebug(1, 'resp broken ami');
|
||||||
$bMsg = 'Event: ResponseEvent' . "\r\n";
|
$bMsg = 'Event: ResponseEvent' . "\r\n";
|
||||||
$bMsg .= 'ActionId: ' . $this->_lastActionId . "\r\n" . $aMsg;
|
$bMsg .= 'ActionId: ' . $this->_lastActionId . "\r\n" . $aMsg;
|
||||||
|
@ -543,17 +540,29 @@ class aminterface
|
||||||
|
|
||||||
function getRealTimeStatus()
|
function getRealTimeStatus()
|
||||||
{
|
{
|
||||||
|
// Initialise array with default values to eliminate testing later
|
||||||
$result = array();
|
$result = array();
|
||||||
|
$cmd_res = array();
|
||||||
|
$cmd_res = ['sccp' => ['message' => 'default value', 'realm' => '', 'status' => 'ERROR']];
|
||||||
if ($this->_connect_state) {
|
if ($this->_connect_state) {
|
||||||
$_action = new \FreePBX\modules\Sccp_manager\aminterface\CommandAction('realtime mysql status');
|
$_action = new \FreePBX\modules\Sccp_manager\aminterface\CommandAction('realtime mysql status');
|
||||||
$_response = $this->send($_action);
|
$result = $this->send($_action)->getResult();
|
||||||
$res = $_response->getResult();
|
}
|
||||||
if (!empty($res['output'])) {
|
if (is_array($result['Output'])) {
|
||||||
$result = $res['output'];
|
foreach ($result['Output'] as $aline) {
|
||||||
} else {
|
if (strlen($aline) > 3) {
|
||||||
$result = $_response->getMessage();
|
$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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -180,6 +180,8 @@ class oldinterface
|
||||||
public function sccp_realtime_status()
|
public function sccp_realtime_status()
|
||||||
{
|
{
|
||||||
$ast_res = array();
|
$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 = $this->sccp_core_commands(array('cmd' => 'get_realtime_status'));
|
||||||
$ast_out = preg_split("/[\n]/", $ast_out['data']);
|
$ast_out = preg_split("/[\n]/", $ast_out['data']);
|
||||||
if (strpos($ast_out[0], 'Privilege') !== false) {
|
if (strpos($ast_out[0], 'Privilege') !== false) {
|
||||||
|
|
|
@ -419,10 +419,10 @@ class extconfigs
|
||||||
{
|
{
|
||||||
global $amp_conf;
|
global $amp_conf;
|
||||||
$res = array();
|
$res = array();
|
||||||
if (empty($realm)) {
|
/* if (empty($realm)) {
|
||||||
$realm = 'sccp';
|
$realm = 'sccp';
|
||||||
}
|
}
|
||||||
$cnf_int = \FreePBX::Config();
|
*/ $cnf_int = \FreePBX::Config();
|
||||||
$cnf_wr = \FreePBX::WriteConfig();
|
$cnf_wr = \FreePBX::WriteConfig();
|
||||||
$cnf_read = \FreePBX::LoadConfig();
|
$cnf_read = \FreePBX::LoadConfig();
|
||||||
|
|
||||||
|
@ -464,14 +464,14 @@ class extconfigs
|
||||||
$res['extconfig'] = 'OK';
|
$res['extconfig'] = 'OK';
|
||||||
|
|
||||||
if (empty($res['sccpdevice'])) {
|
if (empty($res['sccpdevice'])) {
|
||||||
$res['extconfig'] = ' Options "Sccpdevice" not config ';
|
$res['extconfig'] = ' Option "Sccpdevice" is not configured ';
|
||||||
}
|
}
|
||||||
if (empty($res['sccpline'])) {
|
if (empty($res['sccpline'])) {
|
||||||
$res['extconfig'] = ' Options "Sccpline" not config ';
|
$res['extconfig'] = ' Option "Sccpline" is not configured ';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($res['extconfigfile'])) {
|
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')) {
|
if (file_exists($dir . '/res_mysql.conf')) {
|
||||||
$res_conf = $cnf_read->getConfig('res_mysql.conf');
|
$res_conf = $cnf_read->getConfig('res_mysql.conf');
|
||||||
if (empty($res_conf[$realm])) {
|
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 {
|
} else {
|
||||||
if ($res_conf[$realm]['dbsock'] != $def_bd_config['dbsock']) {
|
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'])) {
|
if (empty($res['mysqlconfig'])) {
|
||||||
|
@ -500,7 +500,7 @@ class extconfigs
|
||||||
$res['mysqlconfig'] = 'Not Config in file: res_config_mysql.conf';
|
$res['mysqlconfig'] = 'Not Config in file: res_config_mysql.conf';
|
||||||
} else {
|
} else {
|
||||||
if ($res_conf[$realm]['dbsock'] != $def_bd_config['dbsock']) {
|
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'])) {
|
if (empty($res['mysqlconfig'])) {
|
||||||
|
|
|
@ -193,8 +193,8 @@ class srvinterface {
|
||||||
if (!$this->ami_mode) {
|
if (!$this->ami_mode) {
|
||||||
return $this->oldinterface->sccp_realtime_status();
|
return $this->oldinterface->sccp_realtime_status();
|
||||||
} else {
|
} else {
|
||||||
$ast_out = $this->aminterface->getRealTimeStatus();
|
return $this->aminterface->getRealTimeStatus();
|
||||||
if (is_array($ast_out)) {
|
/* if (is_array($ast_out)) {
|
||||||
foreach ($ast_out as $aline) {
|
foreach ($ast_out as $aline) {
|
||||||
if (strlen($aline) > 3) {
|
if (strlen($aline) > 3) {
|
||||||
$ast_key = strstr(trim($aline), ' ', true);
|
$ast_key = strstr(trim($aline), ' ', true);
|
||||||
|
@ -203,7 +203,7 @@ class srvinterface {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $ast_res;
|
return $ast_res;
|
||||||
}
|
*/ }
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get_compatible_sccp() {
|
public function get_compatible_sccp() {
|
||||||
|
@ -236,11 +236,12 @@ class srvinterface {
|
||||||
|
|
||||||
public function sccp_list_keysets() {
|
public function sccp_list_keysets() {
|
||||||
|
|
||||||
if ($this->ami_mode) {
|
/* if ($this->ami_mode) {
|
||||||
return $this->aminterface->sccp_list_keysets();
|
return $this->aminterface->sccp_list_keysets();
|
||||||
} else {
|
} else {
|
||||||
return $this->oldinterface->sccp_list_keysets();
|
*/ return $this->oldinterface->sccp_list_keysets();
|
||||||
}
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function sccp_get_active_device() {
|
public function sccp_get_active_device() {
|
||||||
|
|
|
@ -12,8 +12,9 @@ $driver = $this->FreePBX->Core->getAllDriversInfo();
|
||||||
$core = $this->srvinterface->getSCCPVersion();
|
$core = $this->srvinterface->getSCCPVersion();
|
||||||
$ast_realtime = $this->srvinterface->sccp_realtime_status();
|
$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) {
|
foreach ($ast_realtime as $key => $value) {
|
||||||
if (empty($ast_realm)) {
|
if (empty($ast_realm)) {
|
||||||
if ($value['status'] == 'OK') {
|
if ($value['status'] == 'OK') {
|
||||||
|
@ -61,7 +62,7 @@ if ($db_Schema == 0) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($ast_realtime)) {
|
if (empty($ast_realtime)) {
|
||||||
$info['RealTime'] = array('Version' => 'Error', 'about' => '<div class="alert signature alert-danger"> No found Real Time connections</div>');
|
$info['RealTime'] = array('Version' => 'Error', 'about' => '<div class="alert signature alert-danger"> No RealTime connections found</div>');
|
||||||
} else {
|
} else {
|
||||||
$rt_info = '';
|
$rt_info = '';
|
||||||
$rt_sccp = 'Failed';
|
$rt_sccp = 'Failed';
|
||||||
|
@ -69,20 +70,22 @@ if (empty($ast_realtime)) {
|
||||||
if ($key == $ast_realm) {
|
if ($key == $ast_realm) {
|
||||||
if ($value['status'] == 'OK') {
|
if ($value['status'] == 'OK') {
|
||||||
$rt_sccp = 'TEST OK';
|
$rt_sccp = 'TEST OK';
|
||||||
$rt_info .= 'SCCP Connections found';
|
$rt_info .= '<div> Using SCCP connection found to database: '.$value['realm'] . ' with connector: ['. $key .']</div>';
|
||||||
} else {
|
} else {
|
||||||
$rt_sccp = 'SCCP ERROR';
|
$rt_sccp = 'SCCP ERROR';
|
||||||
$rt_info .= '<div class="alert signature alert-danger"> Error : ' . $value['message'] . '</div>';
|
$rt_info .= '<div class="alert signature alert-danger"> Error : ' . $value['message'] . '</div>';
|
||||||
}
|
}
|
||||||
} elseif ($value['status'] == 'ERROR') {
|
} elseif ($value['status'] == 'ERROR') {
|
||||||
$rt_info .= '<div> Found error in realtime sectoin [' . $key . '] : ' . $value['message'] . '</div>';
|
$rt_info .= '<div> No connector found for [' . $key . '] : ' . $value['message'] . '</div>';
|
||||||
|
} elseif ($value['status'] == 'OK') {
|
||||||
|
$rt_info .= '<div> Alternative connector found to database '.$value['realm'] . ' with connector: ['. $key . '] </div>';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$info['RealTime'] = array('Version' => $rt_sccp, 'about' => $rt_info);
|
$info['RealTime'] = array('Version' => $rt_sccp, 'about' => $rt_info);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($conf_realtime)) {
|
if (empty($conf_realtime)) {
|
||||||
$info['ConfigsRealTime'] = array('Version' => 'Error', 'about' => '<div class="alert signature alert-danger"> No found Real Time Configs</div>');
|
$info['ConfigsRealTime'] = array('Version' => 'Error', 'about' => '<div class="alert signature alert-danger"> Realtime configuration was not found</div>');
|
||||||
} else {
|
} else {
|
||||||
$rt_info = '';
|
$rt_info = '';
|
||||||
foreach ($conf_realtime as $key => $value) {
|
foreach ($conf_realtime as $key => $value) {
|
||||||
|
@ -517,4 +520,3 @@ foreach ($info as $key => $value) {
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<?php echo $this->showGroup('sccp_info', 0); ?>
|
<?php echo $this->showGroup('sccp_info', 0); ?>
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue