Skip to content

Commit

Permalink
Update AMI Response
Browse files Browse the repository at this point in the history
Bring branch up to level of previous Pull which can now be deleted
  • Loading branch information
steve-lad committed Jan 28, 2021
1 parent 48041fc commit c929649
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 33 deletions.
26 changes: 18 additions & 8 deletions Sccp_manager.inc/aminterface/Response.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,39 +130,47 @@ public function __construct($rawContent)
$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;

Expand Down Expand Up @@ -210,6 +218,8 @@ protected function ConvertTableData($_tablename, $_fkey, $_fields)
{
$_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)) {
Expand Down
37 changes: 23 additions & 14 deletions Sccp_manager.inc/aminterface/aminterface.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,13 @@ public function __construct($parent_class = null)
$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) {
Expand Down Expand Up @@ -259,16 +257,15 @@ public function process()
$response = $this->findResponse($event);
// print_r($response);
// print_r('<br>--- E2 Response Type 2 ----------<br>');

if ($response === false || $response->isComplete()) {
$this->dispatch($event); // не работает
} else {
$response->addEvent($event);
}
}
} 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;
Expand Down Expand Up @@ -543,17 +540,29 @@ function getSCCPVersion()

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;
}
}
2 changes: 2 additions & 0 deletions Sccp_manager.inc/aminterface/oldinterface.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ public function sccp_list_all_hints()
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) {
Expand Down
4 changes: 2 additions & 2 deletions Sccp_manager.inc/extconfigs.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -419,10 +419,10 @@ public function validate_RealTime($realm = '')
{
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();

Expand Down
13 changes: 7 additions & 6 deletions Sccp_manager.inc/srvinterface.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@ public function sccp_realtime_status() {
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);
Expand All @@ -203,7 +203,7 @@ public function sccp_realtime_status() {
}
}
return $ast_res;
}
*/ }
}

public function get_compatible_sccp() {
Expand Down Expand Up @@ -236,11 +236,12 @@ public function getSCCPVersion() {

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() {
Expand Down
8 changes: 5 additions & 3 deletions views/server.info.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
$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) {
Expand Down Expand Up @@ -70,13 +70,15 @@
if ($key == $ast_realm) {
if ($value['status'] == '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 {
$rt_sccp = 'SCCP ERROR';
$rt_info .= '<div class="alert signature alert-danger"> Error : ' . $value['message'] . '</div>';
}
} 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);
Expand Down

0 comments on commit c929649

Please sign in to comment.