diff --git a/Sccp_manager.inc/aminterface/Response.class.php b/Sccp_manager.inc/aminterface/Response.class.php index d898efa..ad6dedc 100644 --- a/Sccp_manager.inc/aminterface/Response.class.php +++ b/Sccp_manager.inc/aminterface/Response.class.php @@ -184,19 +184,17 @@ class SCCPGeneric_Response extends Response public function addEvent($event) { - // not eventlist (start/complete) - // print_r('
---- addEvent --
'); - // print_r($event); - // print_r('
---- Event List--
'); - // print_r($event->getEventList()); + if ($event->getEventList() === 'start') { + // Have started a list of events; this may include tables + // Nothing to do with this event, only need to handle + // the events that follow + return; + } - // Nothing to do with this - we need a table start - if (stristr($event->getEventList(), 'start')) { return; } - - // This is empty as soon as we have received a TableStart. - // The next message is the first of the data sets - // We use this variable in the switch to add set entries if ( empty($thisSetEventEntryType)) { + // This is empty as soon as we have received a TableStart. + // The next message is the first of the data sets + // We use this variable in the switch to add set entries if (strpos($event->getName(), 'Entry')) { $thisSetEventEntryType = $event->getName(); } else { @@ -204,44 +202,44 @@ class SCCPGeneric_Response extends Response } } $unknownevent = "FreePBX\\modules\\Sccp_manager\\aminterface\\UnknownEvent"; - if (!($event instanceof $unknownevent)) { - switch ( $event->getName()) { - case $thisSetEventEntryType : - $this->_temptable['Entries'][] = $event; - break; - case 'TableStart': - //initialise - $this->_temptable = array(); - $this->_temptable['Name'] = $event->getTableName(); - $this->_temptable['Entries'] = array(); - $thisSetEventEntryType = ''; - break; - case 'TableEnd': - //Close - if (!is_array($this->_tables)) { - $this->_tables = array(); - } - $this->_tables[$event->getTableName()] = $this->_temptable; - unset($this->_temptable); - $thisSetEventEntryType = ''; - - // Finished the table. Now check to see if everything was received - // If counts do not match return false and table will not be - //loaded - if ($event->getKey('TableEntries') != count($this->_tables[$event->getTableName()]['Entries'])) { - return $this->_completed = false; - } - break; - default: - // add regular event - $this->_events[] = $event; + if ($event instanceof $unknownevent) { + $this->_events[] = $event; + return; + } + switch ( $event->getName()) { + case $thisSetEventEntryType : + $this->_temptable['Entries'][] = $event; + break; + case 'TableStart': + //initialise + $this->_temptable = array(); + $this->_temptable['Name'] = $event->getTableName(); + $this->_temptable['Entries'] = array(); + $thisSetEventEntryType = ''; + break; + case 'TableEnd': + //Close + if (!is_array($this->_tables)) { + $this->_tables = array(); } - } else { - // add unknown event + $this->_tables[$event->getTableName()] = $this->_temptable; + $this->_temptable = array(); + $thisSetEventEntryType = 'undefinedAsThisIsNotASet'; + + // Finished the table. Now check to see if everything was received + // If counts do not match return false and table will not be + //loaded + if ($event->getKey('TableEntries') != count($this->_tables[$event->getTableName()]['Entries'])) { + return $this->_completed = false; + } + break; + default: + // add regular list event $this->_events[] = $event; - } - // Received a complete eventList outside of a table. - if (stristr($event->getEventList(), 'complete') || stristr($event->getName(), 'complete')) { + } + + if ($event->getEventList() === 'Complete') { + // Received a complete eventList. return $this->_completed = true; } } @@ -252,7 +250,6 @@ class SCCPGeneric_Response extends Response $_rawtable = $this->Table2Array($_tablename); // Check that there is actually data to be converted if (empty($_rawtable)) { return $result;} - foreach ($_rawtable as $_row) { $all_key_ok = true; // No need to test if $_fkey is arrray as array required @@ -264,11 +261,12 @@ class SCCPGeneric_Response extends Response } } $Data = &$result; + if ($all_key_ok) { foreach ($set_name as $value_id) { $Data = &$Data[$value_id]; } - // Label converter in case labels and keys are different - not actually required. + // Label converter in case labels and keys are different foreach ($_fields as $value_key => $value_id) { $Data[$value_id] = $_row[$value_key]; } @@ -421,7 +419,7 @@ class SCCPShowDevices_Response extends SCCPGeneric_Response return $this->ConvertTableData( 'Devices', array('mac'), - array('mac'=>'mac','address'=>'address','descr'=>'descr','regstate'=>'status', + array('mac'=>'name','address'=>'address','descr'=>'descr','regstate'=>'status', 'token'=>'token','act'=>'act', 'lines'=>'lines','nat'=>'nat','regtime'=>'regtime') ); // return $result; @@ -437,7 +435,9 @@ class SCCPShowDevice_Response extends SCCPGeneric_Response public function getResult() { $result = array(); + foreach ($this->_events as $trow) { + dbug('keys are',$trow->getKeys()); $result = array_merge($result, $trow->getKeys()); } $result['Buttons'] = $this->ConvertTableData( diff --git a/Sccp_manager.inc/aminterface/aminterface.class.php b/Sccp_manager.inc/aminterface/aminterface.class.php index e9fdaf0..428717f 100644 --- a/Sccp_manager.inc/aminterface/aminterface.class.php +++ b/Sccp_manager.inc/aminterface/aminterface.class.php @@ -530,8 +530,59 @@ class aminterface $result = array(); if ($this->_connect_state) { $_action = new \FreePBX\modules\Sccp_manager\aminterface\SCCPConfigMetaDataAction(); - $_response = $this->send($_action); - $result = $_response->getResult(); + $metadata = $this->send($_action)->getResult(); + } + //return $result; + if ($metadata && array_key_exists("Version", $metadata)) { + $result["Version"] = $metadata["Version"]; + $version_parts = explode(".", $metadata["Version"]); + $result["vCode"] = 0; + if ($version_parts[0] == "4") { + switch ($version_parts[1]) { + case "1": + $result["vCode"] = 410; + break; + case "2": + $result["vCode"] = 420; + break; + case 3. . .5: + if($version_parts[2] == "3"){ + $result["vCode"] = 433; + } else { + $result["vCode"] = 430; + } + break; + default: + $result["vCode"] = 400; + break; + } + } + /* 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"]); + } } return $result; } diff --git a/Sccp_manager.inc/srvinterface.class.php b/Sccp_manager.inc/srvinterface.class.php index cf8eea5..0321aa2 100644 --- a/Sccp_manager.inc/srvinterface.class.php +++ b/Sccp_manager.inc/srvinterface.class.php @@ -117,24 +117,27 @@ class srvinterface { private function sccp_core_commands($params = array()) { - if ($this->ami_mode) { - 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': + 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; + break; // case 'get_version': // case 'sccp_reload': // break; @@ -143,22 +146,20 @@ class srvinterface { // 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; - } + 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; } - } else { - return $this->oldinterface->sccp_core_commands($params); } + } public function sccp_getdevice_info($dev_id) { @@ -190,20 +191,11 @@ class srvinterface { } public function sccp_realtime_status() { - if (!$this->ami_mode) { - return $this->oldinterface->sccp_realtime_status(); - } else { + if ($this->ami_mode) { return $this->aminterface->getRealTimeStatus(); -/* if (is_array($ast_out)) { - foreach ($ast_out as $aline) { - if (strlen($aline) > 3) { - $ast_key = strstr(trim($aline), ' ', true); - $ast_res[$ast_key] = array('message' => $aline, 'status' => strpos($aline, 'connected') ? 'OK' : 'ERROR'); - } - } - } - return $ast_res; -*/ } + } else { + return $this->oldinterface->sccp_realtime_status(); + } } public function get_compatible_sccp() { @@ -253,68 +245,10 @@ class srvinterface { } function getChanSCCPVersion() { - if (!$this->ami_mode) { - return $this->oldinterface->getChanSCCPVersion(); + if ($this->ami_mode) { + return $this->aminterface->getSCCPVersion(); } else { - $result = array(); - $metadata = $this->aminterface->getSCCPVersion(); - - if ($metadata && array_key_exists("Version", $metadata)) { - $result["Version"] = $metadata["Version"]; - $version_parts = explode(".", $metadata["Version"]); - $result["vCode"] = 0; - if ($version_parts[0] == "4") { - switch ($version_parts[1]) { - case "1": - $result["vCode"] = 410; - break; - case "2": - $result["vCode"] = 420; - break; - case 3. . .5: - if($version_parts[2] == "3"){ - $result["vCode"] = 433; - } else { - $result["vCode"] = 430; - } - break; - default: - $result["vCode"] = 400; - break; - } - } - - /* 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; + return $this->oldinterface->getChanSCCPVersion(); } }