Continued Optimisations and Cleaning

Optimise return values from AMI to avoid reformatting
Simplify validate logic
Optimise treatment of ami raw message
Optimise return values from getDb_model_info and clean up method name
Optimize add device moving functions outside of loop
Define unique names for script methods between SIP and SCCP as in same page
This commit is contained in:
stevenA 2022-01-18 13:11:13 +01:00
parent 4fb0ec58b1
commit e9a3bf34df
15 changed files with 184 additions and 206 deletions

View file

@ -919,7 +919,7 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO {
$dev_config = array_merge($dev_config, $this->sccppath); $dev_config = array_merge($dev_config, $this->sccppath);
$dev_config['tftp_firmware'] = ''; $dev_config['tftp_firmware'] = '';
$dev_config['addon_info'] = array(); $dev_config['addon_info'] = array();
if (!empty($dev_config['addon'])) { if ($dev_config['addon'] !== 'NONE') {
$hw_addon = explode(',', $dev_config['addon']); $hw_addon = explode(',', $dev_config['addon']);
foreach ($hw_addon as $key) { foreach ($hw_addon as $key) {
$hw_data = $this->getSccpModelInformation('byid', false, "all", array('model' => $key)); $hw_data = $this->getSccpModelInformation('byid', false, "all", array('model' => $key));
@ -1004,10 +1004,9 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO {
unlink($result); unlink($result);
return $filename; return $filename;
} }
function getSccpModelInformation($get = "all", $validate = false, $format_list = "all", $filter = array()) { function getSccpModelInformation($get = "all", $validate = false, $format_list = "all", $filter = array()) {
$file_ext = array('.loads', '.sbn', '.bin', '.zup', '.sbin', '.SBN', '.LOADS'); $file_ext = array('.loads', '.sbn', '.bin', '.zup', '.sbin', '.SBN', '.LOADS');
$dir = $this->sccppath['tftp_firmware_path']; $dir = $this->sccpvalues['tftp_firmware_path']['data'];
$search_mode = $this->sccpvalues['tftp_rewrite']['data']; $search_mode = $this->sccpvalues['tftp_rewrite']['data'];
switch ($search_mode) { switch ($search_mode) {
@ -1021,17 +1020,18 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO {
$dir_list = $this->findAllFiles($dir, $file_ext, 'dirFileBaseName'); $dir_list = $this->findAllFiles($dir, $file_ext, 'dirFileBaseName');
break; break;
} }
$modelList = $this->dbinterface->getDb_model_info($get, $format_list, $filter); $modelList = $this->dbinterface->getModelInfoFromDb($get, $format_list, $filter);
//dbug($modelList);
if ($validate) { if ($validate) {
foreach ($modelList as &$raw_settings) { foreach ($modelList as &$raw_settings) {
if (!empty($raw_settings['loadimage'])) { if (!empty($raw_settings['loadimage'])) {
$raw_settings['validate'] = 'no;'; $raw_settings['fwFound'] = false;
switch ($search_mode) { switch ($search_mode) {
case 'pro': case 'pro':
case 'on': case 'on':
case 'internal': case 'internal':
if (in_array($raw_settings['loadimage'], $dir_list, true)) { if (in_array($raw_settings['loadimage'], $dir_list, true)) {
$raw_settings['validate'] = 'yes;'; $raw_settings['fwFound'] = true;
} }
break; break;
case 'internal2': case 'internal2':
@ -1039,26 +1039,28 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO {
case 'off': case 'off':
default: // Place in root TFTP dir default: // Place in root TFTP dir
if (in_array("{$dir}/{$raw_settings['loadimage']}", $dir_list, true)) { if (in_array("{$dir}/{$raw_settings['loadimage']}", $dir_list, true)) {
$raw_settings['validate'] = 'yes;'; $raw_settings['fwFound'] = true;
} }
break; break;
} }
} else { } //else {
$raw_settings['validate'] = '-;'; //$raw_settings['validate'] = '-;';
} //}
$raw_settings['templateFound'] = false;
if (!empty($raw_settings['nametemplate'])) { if (!empty($raw_settings['nametemplate'])) {
$file = $this->sccppath['tftp_templates_path'] . '/' . $raw_settings['nametemplate']; $file = $this->sccppath['tftp_templates_path'] . '/' . $raw_settings['nametemplate'];
if (file_exists($file)) { if (file_exists($file)) {
$raw_settings['validate'] .= 'yes'; $raw_settings['templateFound'] = true;
} else { } //else {
$raw_settings['validate'] .= 'no'; //$raw_settings['templateFound'] .= 'no';
} //}
} else { } //else {
$raw_settings['validate'] .= '-'; //$raw_settings['validate'] .= '-';
} //}
} }
} }
unset($raw_settings); // passed as reference so must unset. unset($raw_settings); // passed as reference so must unset.
dbug($modelList);
return $modelList; return $modelList;
} }

View file

@ -86,7 +86,7 @@ class SCCPDeviceEntry_Event extends Event
{ {
// This is a list of tables, each table is an entry // This is a list of tables, each table is an entry
} }
/*
class SCCPShowDevice_Event extends Event class SCCPShowDevice_Event extends Event
{ {
// This is a list of tables // This is a list of tables
@ -101,7 +101,7 @@ class SCCPShowDevice_Event extends Event
} }
return $ret; return $ret;
} }
*/ }
/* /*
public function getCodecsPreference() public function getCodecsPreference()
{ {

View file

@ -117,15 +117,15 @@ abstract class Message
{ {
return "Variable: $key=$value"; return "Variable: $key=$value";
} }
/*
// Obsolete - integrated into single method that calls for performance
protected function setSanitizedKey($key, $value) protected function setSanitizedKey($key, $value)
{ {
// TODO: Need to handle JSON here rather than in getVariable as have // Handle JSON here rather than in getVariable as have already broken data into array.
// already broken data into array. // Force preference here rather than test later as is faster.
$key = strtolower($key); $key = strtolower($key);
switch ($key) { switch ($key) {
case 'json': case 'json':
//$this->keys['JSONRAW'] = (string) $value;
$this->keys['json'] = (string) $value; $this->keys['json'] = (string) $value;
break; break;
case 'response': case 'response':
@ -133,48 +133,38 @@ abstract class Message
case 'desc': case 'desc':
$this->keys[$key] = (string) $value; $this->keys[$key] = (string) $value;
break; break;
case 'listitems';
$this->keys[$key] = $this->sanitizeInput($value,'numeric');
break;
default: default:
$this->keys[$key] = $this->sanitizeInput($value); $this->keys[$key] = $this->sanitizeInput($value);
break; break;
} }
/*
$_string_key = array('actionid', 'descr');
if (array_search($key, $_string_key) !== false) {
$this->keys[$key] = (string) $this->sanitizeInput($value, 'string');
} else {
$this->keys[$key] = $this->sanitizeInput($value);
}
*/
} }
*/
protected function sanitizeInput($value, $prefered_type = '') protected function sanitizeInput($value, $prefered_type = '')
{ {
if ($prefered_type == '') { if ($prefered_type === '') {
// No longer send empty values // Find numeric first as this is coersion - is_string will always match!
//if (!isset($value) || $value === null || strlen($value) == 0) {
//return null;
//} elseif (is_numeric($value)) {
if (is_numeric($value)) { if (is_numeric($value)) {
$prefered_type = 'numeric'; $prefered_type = 'numeric';
} elseif (is_string($value)) {
$prefered_type = 'string';
} else { } else {
throw new AMIException("Don't know how to convert: '" . $value . "'\n"); $prefered_type = 'string';
} }
} }
//if ($prefered_type !== '') { //if ($prefered_type !== '') {
switch ($prefered_type) { switch ($prefered_type) {
case 'string': case 'string':
//if (!isset($value) || $value === null || strlen($value) == 0) {
//return '';
//}
if (filter_var($value, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE)) { if (filter_var($value, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE)) {
return (boolean) $value; return (boolean) $value;
} elseif (filter_var($value, FILTER_SANITIZE_STRING, FILTER_NULL_ON_FAILURE)) { } elseif (filter_var($value, FILTER_SANITIZE_STRING, FILTER_NULL_ON_FAILURE)) {
return (string) $value; return (string) $value;
} elseif (filter_var($value, FILTER_SANITIZE_FULL_SPECIAL_CHARS, FILTER_NULL_ON_FAILURE)) { } elseif (filter_var($value, FILTER_SANITIZE_FULL_SPECIAL_CHARS, FILTER_NULL_ON_FAILURE)) {
return (string) htmlspecialchars($value, ENT_QUOTES); return (string) htmlspecialchars($value, ENT_QUOTES);
} elseif (empty($value)) {
// In rare cases, $value will be empty, and so treated as a string. Trap here
// to avoid performance hit on all message lines if testing earlier.
return;
} else { } else {
throw new AMIException("Incoming String is not sanitary. Skipping: '" . $value . "'\n"); throw new AMIException("Incoming String is not sanitary. Skipping: '" . $value . "'\n");
} }
@ -244,6 +234,42 @@ abstract class Message
abstract class IncomingMessage extends Message abstract class IncomingMessage extends Message
{ {
public function __construct($rawContent)
{
parent::__construct();
$this->rawContent = $rawContent;
$lines = explode(Message::EOL, $rawContent);
foreach ($lines as $line) {
$content = explode(':', $line);
$key = strtolower(array_shift($content));
// May now have an empty array, or an array with just ' ', both of which
// are rare and will be turned into an empty string below.
// Do not test for here, as most times will not be empty, and testing here
// would mean a performance hit given the number of lines handled
// Performance - integrate method here as is only called from here!
//$this->setSanitizedKey($name, trim(implode(':', $content)));
$value = trim(implode(':', $content));
// Handle JSON here rather than in old getVariable as have already broken data into array.
// Force preference here rather than test later as is faster.
switch ($key) {
case 'json':
$this->keys['json'] = (string) $value;
break;
case 'response':
case 'actionid':
case 'desc':
$this->keys[$key] = (string) $value;
break;
case 'listitems';
$this->keys[$key] = $this->sanitizeInput($value,'numeric');
break;
default:
$this->keys[$key] = $this->sanitizeInput($value);
break;
}
}
}
protected $rawContent; protected $rawContent;
@ -268,33 +294,6 @@ abstract class IncomingMessage extends Message
$ret[] = 'rawContent'; $ret[] = 'rawContent';
return $ret; return $ret;
} }
public function __construct($rawContent)
{
parent::__construct();
//dbug($rawContent);
$this->rawContent = $rawContent;
$lines = explode(Message::EOL, $rawContent);
foreach ($lines as $line) {
$content = explode(':', $line);
//$content = preg_split("/: /",$line);
//$name = strtolower(trim($content[0]));
// do strtolower in setSanitizedKey
$name = array_shift($content);
//unset($content[0]);
if (!isset($content[0])) {
continue;
}
//$value = isset($content[0]) ? trim(implode(':', $content)) : '';
try {
$this->setSanitizedKey($name, trim(implode(':', $content)));
} catch (AMIException $e) {
throw new AMIException("Error: '" . $e . "'\n Dump RawContent:\n" . $this->rawContent . "\n");
}
//dbug($this->keys);
}
//dbug($this->keys);
}
} }
// namespace FreePBX\modules\Sccp_manager\aminterface\Message; // namespace FreePBX\modules\Sccp_manager\aminterface\Message;

View file

@ -378,7 +378,6 @@ class SCCPShowDevice_Response extends SCCPGeneric_Response
{ {
// This object has a list of events _events, and a list of tables _tables. // This object has a list of events _events, and a list of tables _tables.
$result = array(); $result = array();
foreach ($this->_events as $trow) { foreach ($this->_events as $trow) {
$result = array_merge($result, $trow->getKeys()); $result = array_merge($result, $trow->getKeys());
} }

View file

@ -200,56 +200,52 @@ class dbinterface
* Get Sccp Device Model information * Get Sccp Device Model information
*/ */
function getDb_model_info($get = 'all', $format_list = 'all', $filter = array()) function getModelInfoFromDb($get = 'all', $format_list = 'all', $filter = array())
{ {
$sel_inf = '*, 0 as validate'; $sel_inf = "*, model, false as fwFound, false as templateFound";
if ($format_list === 'model') { if ($format_list === 'model') {
$sel_inf = "model, vendor, dns, buttons, '-;-' as validate"; $sel_inf = "model, vendor, dns, buttons, false as fwFound, false as templateFound";
} }
switch ($get) { switch ($get) {
case 'byciscoid': case 'byciscoid':
if (!empty($filter)) { if (isset($filter['model'])) {
if (!empty($filter['model'])) { if (!strpos($filter['model'], 'loadInformation')) {
if (!strpos($filter['model'], 'loadInformation')) { $filter['model'] = 'loadInformation' . $filter['model'];
$filter['model'] = 'loadInformation' . $filter['model'];
}
$stmt = $this->db->prepare("SELECT {$sel_inf} FROM sccpdevmodel WHERE (loadinformationid = :model ) ORDER BY model");
$stmt->bindParam(':model', $filter['model'], \PDO::PARAM_STR);
} else {
$stmt = $this->db->prepare("SELECT {$sel_inf} FROM sccpdevmodel ORDER BY model");
} }
break; $stmt = $this->db->prepare("SELECT ${sel_inf} FROM sccpdevmodel WHERE (loadinformationid = :model ) ORDER BY model");
$stmt->bindParam(':model', $filter['model'], \PDO::PARAM_STR);
} else {
$stmt = $this->db->prepare("SELECT ${sel_inf} FROM sccpdevmodel ORDER BY model");
} }
break; break;
case 'byid': case 'byid':
if (!empty($filter)) { if (isset($filter['model'])) {
if (!empty($filter['model'])) { $stmtU = $this->db->prepare("SELECT ${sel_inf} FROM sccpdevmodel WHERE model = :model ORDER BY model");
$stmt = $this->db->prepare("SELECT {$sel_inf} FROM sccpdevmodel WHERE model = :model ORDER BY model"); $stmtU->bindParam(':model', $filter['model'],\PDO::PARAM_STR);
$stmt->bindParam(':model', $filter['model'],\PDO::PARAM_STR); } else {
} else { $stmtU = $this->db->prepare("SELECT ${sel_inf} FROM sccpdevmodel ORDER BY model");
$stmt = $this->db->prepare("SELECT {$sel_inf} FROM sccpdevmodel ORDER BY model");
}
break;
} }
$stmtU->execute();
return $stmtU->fetchAll(\PDO::FETCH_ASSOC|\PDO::FETCH_UNIQUE);
break; break;
case 'extension': case 'extension':
$stmt = $this->db->prepare("SELECT {$sel_inf} FROM sccpdevmodel WHERE (dns = 0) and (enabled = 1) ORDER BY model"); $stmt = $this->db->prepare("SELECT ${sel_inf} FROM sccpdevmodel WHERE (dns = 0) and (enabled = 1) ORDER BY model");
break; break;
case 'enabled': case 'enabled':
//$stmt = $db->prepare('SELECT ' . {$sel_inf} . ' FROM sccpdevmodel WHERE enabled = 1 ORDER BY model'); //previously this fell through to phones. //$stmt = $db->prepare('SELECT ' . {$sel_inf} . ' FROM sccpdevmodel WHERE enabled = 1 ORDER BY model'); //previously this fell through to phones.
//break; // above includes expansion modules but was not original behaviour so commented out. Falls through to phones. //break; // above includes expansion modules but was not original behaviour so commented out. Falls through to phones.
case 'phones': case 'phones':
$stmt = $this->db->prepare("SELECT {$sel_inf} FROM sccpdevmodel WHERE (dns != 0) and (enabled = 1) ORDER BY model"); $stmt = $this->db->prepare("SELECT ${sel_inf} FROM sccpdevmodel WHERE (dns != 0) and (enabled = 1) ORDER BY model");
break; break;
case 'ciscophones': case 'ciscophones':
$stmt = $this->db->prepare("SELECT {$sel_inf} FROM sccpdevmodel WHERE (dns > 0) and (enabled = 1) AND RIGHT(vendor,4) != '-sip' ORDER BY model"); $stmt = $this->db->prepare("SELECT ${sel_inf} FROM sccpdevmodel WHERE (dns > 0) and (enabled = 1) AND RIGHT(vendor,4) != '-sip' ORDER BY model");
break; break;
case 'sipphones': case 'sipphones':
$stmt = $this->db->prepare("SELECT {$sel_inf} FROM sccpdevmodel WHERE (dns > 0) and (enabled = 1) AND RIGHT(vendor,4) = '-sip' ORDER BY model"); $stmt = $this->db->prepare("SELECT ${sel_inf} FROM sccpdevmodel WHERE (dns > 0) and (enabled = 1) AND RIGHT(vendor,4) = '-sip' ORDER BY model");
break; break;
case 'all': // Fall through to default case 'all': // Fall through to default
default: default:
$stmt = $this->db->prepare("SELECT {$sel_inf} FROM sccpdevmodel ORDER BY model"); $stmt = $this->db->prepare("SELECT ${sel_inf} FROM sccpdevmodel ORDER BY model");
break; break;
} }
$stmt->execute(); $stmt->execute();

View file

@ -719,11 +719,11 @@ class formcreate
} }
switch ($child['type']) { switch ($child['type']) {
case 'SDM': case 'SDM':
$model_list = \FreePBX::Sccp_manager()->dbinterface->getDb_model_info('ciscophones', 'model'); $model_list = \FreePBX::Sccp_manager()->dbinterface->getModelInfoFromDb('ciscophones', 'model');
$select_opt= $model_list; $select_opt= $model_list;
break; break;
case 'SDMS': case 'SDMS':
$model_list = \FreePBX::Sccp_manager()->dbinterface->getDb_model_info('sipphones', 'model'); $model_list = \FreePBX::Sccp_manager()->dbinterface->getModelInfoFromDb('sipphones', 'model');
$select_opt= $model_list; $select_opt= $model_list;
break; break;
case 'SDML': case 'SDML':
@ -741,7 +741,7 @@ class formcreate
$child->default = $fvalues['defaultLine']; $child->default = $fvalues['defaultLine'];
break; break;
case 'SDE': case 'SDE':
$extension_list = \FreePBX::Sccp_manager()->dbinterface->getDb_model_info('extension', 'model'); $extension_list = \FreePBX::Sccp_manager()->dbinterface->getModelInfoFromDb('extension', 'model');
$extension_list[] = array( 'model' => 'NONE', 'vendor' => 'CISCO', 'dns' => '0'); $extension_list[] = array( 'model' => 'NONE', 'vendor' => 'CISCO', 'dns' => '0');
foreach ($extension_list as &$data) { foreach ($extension_list as &$data) {
$d_name = explode(';', $data['model']); $d_name = explode(';', $data['model']);

View file

@ -223,9 +223,9 @@ trait ajaxHelper {
$devices = $this->getSccpModelInformation($request['type'], $validate = true); $devices = $this->getSccpModelInformation($request['type'], $validate = true);
break; break;
} }
if (empty($devices)) { //if (empty($devices)) {
return array(); //return array();
} //}
return $devices; return $devices;
break; break;
@ -550,7 +550,6 @@ trait ajaxHelper {
$nonJavaPhones = array( $nonJavaPhones = array(
'6901', '6911', '6921', '6945', '7902', '7905', '7910', '7911', '7912', '7914', '7915', '7916', '7920', '7925', '7926', '7931', '7935', '7936', '7937', '7940', '7960' '6901', '6911', '6921', '6945', '7902', '7905', '7910', '7911', '7912', '7914', '7915', '7916', '7920', '7925', '7926', '7931', '7935', '7936', '7937', '7940', '7960'
); );
dbug($get_settings); //[sccp_hw_type]
if (!empty($get_settings["{$hdr_prefix}devlang"])) { if (!empty($get_settings["{$hdr_prefix}devlang"])) {
switch ($get_settings["{$hdr_prefix}devlang"]) { switch ($get_settings["{$hdr_prefix}devlang"]) {
case 'Russian_Russian_Federation': case 'Russian_Russian_Federation':

View file

@ -25,6 +25,7 @@ trait bmoFunctions {
$this->dialTemplateData = json_encode($this->getDialTemplate()); $this->dialTemplateData = json_encode($this->getDialTemplate());
$this->softKeyData = json_encode($this->getSoftKey()); $this->softKeyData = json_encode($this->getSoftKey());
$this->deviceModelData = json_encode($this->ajaxHandler($_REQUEST = array('command'=>'getDeviceModel', 'type'=>'enabled'))); $this->deviceModelData = json_encode($this->ajaxHandler($_REQUEST = array('command'=>'getDeviceModel', 'type'=>'enabled')));
dbug($this->deviceModelData);
break; break;
default: default:
break; break;
@ -32,6 +33,7 @@ trait bmoFunctions {
} }
function getPhoneGrid(string $type, $activeDevices =array()){ function getPhoneGrid(string $type, $activeDevices =array()){
$dbDevices = array(); $dbDevices = array();
// Find all devices defined in the database. // Find all devices defined in the database.
$dbDevices = $this->dbinterface->getSccpDeviceTableData('phoneGrid', array('type' => $type)); $dbDevices = $this->dbinterface->getSccpDeviceTableData('phoneGrid', array('type' => $type));
@ -40,8 +42,6 @@ trait bmoFunctions {
if ($type == 'cisco-sip') { if ($type == 'cisco-sip') {
return $dbDevices; //this may be empty return $dbDevices; //this may be empty
} }
// Find all devices currently connected
//$activeDevices = $this->aminterface->sccp_get_active_device();
foreach ($dbDevices as &$dev_id) { foreach ($dbDevices as &$dev_id) {
if (!empty($activeDevices[$dev_id['name']])) { if (!empty($activeDevices[$dev_id['name']])) {

View file

@ -90,17 +90,10 @@ trait helperfunctions {
return $def_val; return $def_val;
} }
private function getTableEnums($table, $trim_underscore = true) { private function getTableEnums($table) {
$enumFields = array(); $enumFields = array();
$sccpTableDesc = $this->dbinterface->getSccpDeviceTableData("get_columns_{$table}"); $sccpTableDesc = $this->dbinterface->getSccpDeviceTableData("get_columns_${table}");
foreach ($sccpTableDesc as $key => $data) { foreach ($sccpTableDesc as $key => $data) {
// function has 2 roles: return actual table keys (trim_underscore = false)
// return sanitised keys to add defaults (trim_underscore = true)
if ($trim_underscore) {
// Remove any leading (or trailing but should be none) underscore
// These are only used to hide fields from chan-sccp for compatibility
$key = trim($key,'_');
}
$typeArray = explode('(', $data['Type']); $typeArray = explode('(', $data['Type']);
if ($typeArray[0] == 'enum') { if ($typeArray[0] == 'enum') {
$enumOptions = explode(',', trim($typeArray[1],')')); $enumOptions = explode(',', trim($typeArray[1],')'));

View file

@ -301,13 +301,15 @@ include($amp_conf['AMPWEBROOT'] . '/admin/modules/sccp_manager/views/getFileModa
} }
function SetColFirmNf(value, row, index) { function SetColFirmNf(value, row, index) {
if (row['validate'].split(';')[0] === 'no') { //if (row['validate'].split(';')[0] === 'no') {
if (!row['fwFound']) {
return "File not found<br />" + value; return "File not found<br />" + value;
} }
return value; return value;
} }
function SetColTemplNf(value, row, index) { function SetColTemplNf(value, row, index) {
if (row['validate'].split(';')[1] === 'no') { //if (row['validate'].split(';')[1] === 'no') {
if (!row['templateFound']) {
return "File not found<br /> " + value ; return "File not found<br /> " + value ;
} }
return value; return value;
@ -318,7 +320,7 @@ include($amp_conf['AMPWEBROOT'] . '/admin/modules/sccp_manager/views/getFileModa
if (row['enabled'] === 1) { if (row['enabled'] === 1) {
tclass = (index % 2 === 0) ? "info" : "info"; tclass = (index % 2 === 0) ? "info" : "info";
} }
if ((row['validate'] === 'yes;yes') || (row['validate'] === 'yes;-')) { if (row['fwFound']) {
// tclass = (row['enabled'] === '1') ? "danger" : "warning"; // tclass = (row['enabled'] === '1') ? "danger" : "warning";
} else { } else {
tclass = (row['enabled'] === '1') ? "danger" : "warning"; tclass = (row['enabled'] === '1') ? "danger" : "warning";

View file

@ -29,74 +29,77 @@ if (!empty($_REQUEST['id'])) {
$dev_id = $_REQUEST['id']; $dev_id = $_REQUEST['id'];
$db_res = $this->dbinterface->getSccpDeviceTableData('get_sccpdevice_byid', array("id" => $dev_id)); $db_res = $this->dbinterface->getSccpDeviceTableData('get_sccpdevice_byid', array("id" => $dev_id));
$enumFields = $this->getTableEnums('sccpdevice');
$def_val['defaultLine'] = $this->dbinterface->getSccpDeviceTableData('getDefaultLine', array('id' => $dev_id))['name'];
foreach ($db_res as $key => $val) { foreach ($db_res as $key => $val) {
if (!empty($val)) { if (empty($val)) {
switch ($key) { continue;
case 'phonepersonalization': }
$def_val['phonepersonalization'] = array("keyword" => 'phonepersonalization', "data" => $val, "seq" => "99"); switch ($key) {
break; case 'phonepersonalization':
default: $def_val['phonepersonalization'] = array("keyword" => 'phonepersonalization', "data" => $val, "seq" => "99");
// Overwrite existing defaults after checking that data is still valid after schema updates break;
// Do not strip underscores as these fields are new in the schema and so should be valid. default:
$enumFields = $this->getTableEnums('sccpdevice', false); // Overwrite existing defaults after checking that data is still valid after schema updates
if (array_key_exists($key, $enumFields)){ if (array_key_exists($key, $enumFields)){
// This field is (now) an enum. Check the current value is acceptable. // This field is (now) an enum. Check the current value is acceptable.
// Quote value as enum values are quoted. // Quote value as enum values are quoted.
if (in_array("'{$val}'", $enumFields[$key])) { if (in_array("'${val}'", $enumFields[$key])) {
// The value is valid so will keep // The value is valid so will keep
$def_val[$key] = array('keyword' => $key, 'data' => $val, 'seq' => 99); $def_val[$key] = array('keyword' => $key, 'data' => $val, 'seq' => 99);
}
// Do not store value and let defaults apply
break;
} }
$def_val[$key] = array("keyword" => $key, "data" => $val, "seq" => "99"); // Do not store (invalid) value and let defaults apply
// Need to assign defaultLine as not set in the db.
$def_val['defaultLine'] = $this->dbinterface->getSccpDeviceTableData('getDefaultLine', array('id' => $dev_id))['name'];
break; break;
} }
$def_val[$key] = array("keyword" => $key, "data" => $val, "seq" => "99");
break;
} }
} }
} }
if (empty($dev_id)) {
$dev_id = 'new';
} else {
$val = str_replace(array('SEP','ATA','VG'), '', $dev_id);
$val = implode(':', sscanf($val, '%2s%2s%2s%2s%2s%2s')); // Convert to Cisco display Format
$def_val['mac'] = array("keyword" => 'mac', "data" => $val, "seq" => "99");
}
if (!empty($def_val['type'])) { if (!empty($def_val['type']['data'])) {
$tmp_raw = $this->getSccpModelInformation('byid', true, 'all', array('model'=>$def_val['type'])); $tmp_raw = $this->getSccpModelInformation('byid', true, 'all', array('model'=>$def_val['type']['data']));
if (!empty($tmp_raw[0])) { if (isset($tmp_raw[$def_val['type']['data']])) {
$tmp_raw = $tmp_raw[0]; $tmp_raw = $tmp_raw[$def_val['type']['data']];
} }
if (!empty($tmp_raw['validate'])) { if (!$tmp_raw['fwFound']) {
$tmpar = explode(";", $tmp_raw['validate']); $device_warning['Image'] = array('Device firmware not found : '.$tmp_raw['loadimage']);
if ($tmpar[0] != 'yes') { }
$device_warning['Image'] = array('Device firmware not found : '.$tmp_raw['loadimage']); if (!$tmp_raw['templateFound']) {
} $device_warning['Template'] = array('Missing device configuration template : '. $tmp_raw['nametemplate']);
if ($tmpar[1] != 'yes') { }
$device_warning['Template'] = array('Missing device configuration template : '. $tmp_raw['nametemplate']); if (!empty($device_warning)) {
} ?>
if (!empty($device_warning)) { <div class="fpbx-container container-fluid">
?> <div class="row">
<div class="fpbx-container container-fluid"> <div class="container">
<div class="row"> <h2 style="border:2px solid Tomato;color:Tomato;" >Warning in the SCCP Device</h2>
<div class="container"> <div class="table-responsive">
<h2 style="border:2px solid Tomato;color:Tomato;" >Warning in the SCCP Device</h2> <pre>
<div class="table-responsive"> <?php
<pre> foreach ($device_warning as $key => $value) {
<?php echo '<h3>'.$key.'</h3>';
foreach ($device_warning as $key => $value) { if (is_array($value)) {
echo '<h3>'.$key.'</h3>'; echo '<li>'._(implode('</li><li>', $value)).'</li>';
if (is_array($value)) { } else {
echo '<li>'._(implode('</li><li>', $value)).'</li>'; echo '<li>'. _($value).'</li>';
} else {
echo '<li>'. _($value).'</li>';
}
} }
?> }
</pre> ?>
</div> </pre>
</div> </div>
</div> </div>
</div> </div>
<br> </div>
<br>
<?php } <?php }
}
} ?> } ?>
<form autocomplete="off" name="frm_adddevice" id="frm_adddevice" class="fpbx-submit" action="" method="post" data-id="hw_edit"> <form autocomplete="off" name="frm_adddevice" id="frm_adddevice" class="fpbx-submit" action="" method="post" data-id="hw_edit">
@ -105,18 +108,11 @@ if (!empty($def_val['type'])) {
<?php <?php
if (empty($dev_id)) { echo '<input type="hidden" name="sccp_device_id" value="'.$dev_id.'">';
echo '<input type="hidden" name="sccp_deviceid" value="new">';
} else {
$val = str_replace(array('SEP','ATA','VG'), '', $dev_id);
$val = implode(':', sscanf($val, '%2s%2s%2s%2s%2s%2s')); // Convert to Cisco display Format
$def_val['mac'] = array("keyword" => 'mac', "data" => $val, "seq" => "99");
echo '<input type="hidden" name="sccp_device_id" value="'.$dev_id.'">';
}
if ($_REQUEST['tech_hardware'] == 'cisco') { if ($_REQUEST['tech_hardware'] == 'cisco') {
echo '<input type="hidden" name="sccp_device_typeid" value="sccpdevice">'; echo '<input type="hidden" name="sccp_device_typeid" value="sccpdevice">';
if (empty($dev_id)) { if ($dev_id === 'new') {
echo $this->showGroup('sccp_hw_dev', 1, 'sccp_hw', $def_val); echo $this->showGroup('sccp_hw_dev', 1, 'sccp_hw', $def_val);
} else { } else {
echo $this->showGroup('sccp_hw_dev_edit', 1, 'sccp_hw', $def_val); echo $this->showGroup('sccp_hw_dev_edit', 1, 'sccp_hw', $def_val);
@ -124,21 +120,13 @@ if (!empty($def_val['type'])) {
echo $this->showGroup('sccp_hw_dev2', 1, 'sccp_hw', $def_val); echo $this->showGroup('sccp_hw_dev2', 1, 'sccp_hw', $def_val);
echo $this->showGroup('sccp_hw_dev_advance', 1, 'sccp_hw', $def_val); echo $this->showGroup('sccp_hw_dev_advance', 1, 'sccp_hw', $def_val);
echo $this->showGroup('sccp_hw_dev_softkey', 1, 'sccp_hw', $def_val); echo $this->showGroup('sccp_hw_dev_softkey', 1, 'sccp_hw', $def_val);
// echo $this->showGroup('sccp_hw_dev_pickup', 1, 'sccp_hw', $def_val); This are line properties and does not exist!
echo $this->showGroup('sccp_hw_dev_conference', 1, 'sccp_hw', $def_val); echo $this->showGroup('sccp_hw_dev_conference', 1, 'sccp_hw', $def_val);
echo $this->showGroup('sccp_dev_vendor_conf', 1, 'vendorconfig', $def_val); echo $this->showGroup('sccp_dev_vendor_conf', 1, 'vendorconfig', $def_val);
echo $this->showGroup('sccp_hw_dev_network', 1, 'sccp_hw', $def_val); echo $this->showGroup('sccp_hw_dev_network', 1, 'sccp_hw', $def_val);
} else if ($_REQUEST['tech_hardware'] == 'cisco-sip') { } else if ($_REQUEST['tech_hardware'] == 'cisco-sip') {
echo '<input type="hidden" name="sccp_device_typeid" value="sipdevice">'; echo '<input type="hidden" name="sccp_device_typeid" value="sipdevice">';
/* if ($dev_id === 'new') {
if (empty($dev_new)) {
echo '<input type="hidden" name="sccp_deviceid" value="new">';
} else {
echo '<input type="hidden" name="sccp_deviceid" value="'.$dev_id.'">';
}
*/
if (empty($dev_id)) {
echo $this->showGroup('sccp_hw_sip_dev', 1, 'sccp_hw', $def_val); echo $this->showGroup('sccp_hw_sip_dev', 1, 'sccp_hw', $def_val);
} else { } else {
echo $this->showGroup('sccp_hw_dev_edit', 1, 'sccp_hw', $def_val); echo $this->showGroup('sccp_hw_dev_edit', 1, 'sccp_hw', $def_val);

View file

@ -27,7 +27,7 @@ if (!empty($this->sccpvalues['system_rouminguser'])) {
<th data-sortable="true" data-field="label"><?php echo _('Display Name') ?></th> <th data-sortable="true" data-field="label"><?php echo _('Display Name') ?></th>
<th data-sortable="true" data-field="mac"><?php echo _('Device') ?></th> <th data-sortable="true" data-field="mac"><?php echo _('Device') ?></th>
<th data-sortable="true" data-field="line_status" class="text-center"><?php echo _('Status | Active') ?></th> <th data-sortable="true" data-field="line_status" class="text-center"><?php echo _('Status | Active') ?></th>
<th data-field="actions" data-formatter="DispayPhoneActionsKeyFormatter"><?php echo _('Actions') ?></th> <th data-field="actions" data-formatter="DisplayPhoneActionsKeyFormatter"><?php echo _('Actions') ?></th>
</tr> </tr>
</thead> </thead>
</table> </table>
@ -41,7 +41,7 @@ if (!empty($this->sccpvalues['system_rouminguser'])) {
$('#table-sccp-extension').bootstrapTable({data: <?php echo $this->extensionData ?>}); $('#table-sccp-extension').bootstrapTable({data: <?php echo $this->extensionData ?>});
}) })
function DispayPhoneActionsKeyFormatter(value, row, index) { function DisplayPhoneActionsKeyFormatter(value, row, index) {
var exp_dev = ''; var exp_dev = '';
var rmn_dev = '<?php echo $roming_enable ?>'; var rmn_dev = '<?php echo $roming_enable ?>';
exp_dev += '<a href="config.php?display=extensions&amp;extdisplay=' + row['name'] + '"><i class="fa fa-pencil"></i></a> &nbsp;'; exp_dev += '<a href="config.php?display=extensions&amp;extdisplay=' + row['name'] + '"><i class="fa fa-pencil"></i></a> &nbsp;';

View file

@ -39,12 +39,12 @@
<tr> <tr>
<th data-checkbox="true"></th> <th data-checkbox="true"></th>
<th data-sortable="true" data-field="name"><?php echo _('Device ID') ?></th> <th data-sortable="true" data-field="name"><?php echo _('Device ID') ?></th>
<th data-sortable="true" data-field="description"><?php echo _('Device Description') ?></th> <th data-sortable="true" data-field="description"><?php echo _('Device Description') ?></th>
<th data-sortable="true" data-formatter="DispayTypeFormatter" data-field="type"><?php echo _('Device type') ?></th> <th data-sortable="true" data-formatter="DisplayTypeFormatter" data-field="type"><?php echo _('Device type') ?></th>
<th data-sortable="true" data-field="button" data-formatter="LineFormatter"><?php echo _('Line') ?></th> <th data-sortable="true" data-field="button" data-formatter="LineFormatter"><?php echo _('Line') ?></th>
<th data-sortable="true" data-field="status"><?php echo _('Status') ?></th> <th data-sortable="true" data-field="status"><?php echo _('Status') ?></th>
<th data-sortable="true" data-field="address"><?php echo _('Address') ?></th> <th data-sortable="true" data-field="address"><?php echo _('Address') ?></th>
<th data-field="actions" data-formatter="DispayDeviceActionsKeyFormatter"><?php echo _('Actions') ?></th> <th data-field="actions" data-formatter="DisplayDeviceActionsKeyFormatter"><?php echo _('Actions') ?></th>
</tr> </tr>
</thead> </thead>
</table> </table>
@ -59,9 +59,9 @@
$('#table-sccp-phone').bootstrapTable({data: <?php echo $this->sccpPhoneData ?>}); $('#table-sccp-phone').bootstrapTable({data: <?php echo $this->sccpPhoneData ?>});
}) })
function DispayTypeFormatter(value, row, index) { function DisplayTypeFormatter(value, row, index) {
var exp_model = value; var exp_model = value;
if (row['addon'] !== null ) { if (row['addon'] !== 'NONE' ) {
var posd = row['addon'].indexOf(';'); var posd = row['addon'].indexOf(';');
if (posd >0) { if (posd >0) {
exp_model += ' + 2x ' + row['addon'].substring(0, posd); exp_model += ' + 2x ' + row['addon'].substring(0, posd);
@ -72,7 +72,7 @@
return exp_model; return exp_model;
} }
function DispayDeviceActionsKeyFormatter(value, row, index) { function DisplayDeviceActionsKeyFormatter(value, row, index) {
var exp_model = ''; var exp_model = '';
if (row['new_hw'] == "Y") { if (row['new_hw'] == "Y") {
exp_model += '<a href="?display=sccp_phone&tech_hardware=cisco&new_id=' + row['name'] + '&type='+ row['type']; exp_model += '<a href="?display=sccp_phone&tech_hardware=cisco&new_id=' + row['name'] + '&type='+ row['type'];

View file

@ -30,11 +30,11 @@
<th data-checkbox="true"></th> <th data-checkbox="true"></th>
<th data-sortable="true" data-field="name"><?php echo _('Device ID') ?></th> <th data-sortable="true" data-field="name"><?php echo _('Device ID') ?></th>
<th data-sortable="true" data-field="description"><?php echo _('Device Description') ?></th> <th data-sortable="true" data-field="description"><?php echo _('Device Description') ?></th>
<th data-sortable="true" data-formatter="DispayTypeFormatter" data-field="type"><?php echo _('Device type') ?></th> <th data-sortable="true" data-formatter="SipDisplayTypeFormatter" data-field="type"><?php echo _('Device type') ?></th>
<th data-sortable="true" data-field="button" data-formatter="LineFormatter"><?php echo _('Line') ?></th> <th data-sortable="true" data-field="button" data-formatter="LineFormatter"><?php echo _('Line') ?></th>
<th data-sortable="true" data-field="status"><?php echo _('Status') ?></th> <th data-sortable="true" data-field="status"><?php echo _('Status') ?></th>
<th data-sortable="true" data-field="address"><?php echo _('Address') ?></th> <th data-sortable="true" data-field="address"><?php echo _('Address') ?></th>
<th data-field="actions" data-formatter="DispayDeviceActionsKeyFormatterS"><?php echo _('Actions') ?></th> <th data-field="actions" data-formatter="SipDisplayDeviceActionsKeyFormatterS"><?php echo _('Actions') ?></th>
</tr> </tr>
</thead> </thead>
</table> </table>
@ -49,7 +49,7 @@
$('#table-sip-phone').bootstrapTable({data: <?php echo $this->sipPhoneData ?>}); $('#table-sip-phone').bootstrapTable({data: <?php echo $this->sipPhoneData ?>});
}) })
function DispayTypeFormatter(value, row, index) { function SipDisplayTypeFormatter(value, row, index) {
var exp_model = value; var exp_model = value;
if (row['addon'] !== null ) { if (row['addon'] !== null ) {
var posd = row['addon'].indexOf(';'); var posd = row['addon'].indexOf(';');
@ -61,7 +61,7 @@
} }
return exp_model; return exp_model;
} }
function DispayDeviceActionsKeyFormatterS(value, row, index) { function SipDisplayDeviceActionsKeyFormatterS(value, row, index) {
var exp_model = ''; var exp_model = '';
if (row['new_hw'] == "Y") { if (row['new_hw'] == "Y") {
exp_model += '<a href="?display=sccp_phone&tech_hardware=cisco-sip&new_id=' + row['name'] + '&type='+ row['type']; exp_model += '<a href="?display=sccp_phone&tech_hardware=cisco-sip&new_id=' + row['name'] + '&type='+ row['type'];