Add FW and Template availability to sccpdevmodel

Rename menu items
Add new fields to sccpdevmodel to show existence of firmware and template files, thereby reducing load times.
This commit is contained in:
stevenA 2022-01-18 16:05:49 +01:00
parent e9a3bf34df
commit 485ce3fe3a
8 changed files with 69 additions and 56 deletions

View file

@ -1005,10 +1005,24 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO {
return $filename;
}
function getSccpModelInformation($get = "all", $validate = false, $format_list = "all", $filter = array()) {
$modelList = $this->dbinterface->getModelInfoFromDb($get, $format_list, $filter);
if (!$validate) {
return $modelList;
}
// Here so want to see if FW and template files exist on TFTP server.
$needToCheckFw = array_search('no', array_column($modelList, 'fwfound'), true);
$needToCheckTemp = array_search('no', array_column($modelList, 'templatefound'), true);
if (!$needToCheckFw && !$needToCheckTemp) {
// in modellist, all firmware shows as being available (no not found for either)
return $modelList;
}
$file_ext = array('.loads', '.sbn', '.bin', '.zup', '.sbin', '.SBN', '.LOADS');
$dir = $this->sccpvalues['tftp_firmware_path']['data'];
$search_mode = $this->sccpvalues['tftp_rewrite']['data'];
switch ($search_mode) {
case 'pro':
case 'on':
@ -1020,47 +1034,39 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO {
$dir_list = $this->findAllFiles($dir, $file_ext, 'dirFileBaseName');
break;
}
$modelList = $this->dbinterface->getModelInfoFromDb($get, $format_list, $filter);
//dbug($modelList);
if ($validate) {
foreach ($modelList as &$raw_settings) {
if (!empty($raw_settings['loadimage'])) {
$raw_settings['fwFound'] = false;
switch ($search_mode) {
case 'pro':
case 'on':
case 'internal':
if (in_array($raw_settings['loadimage'], $dir_list, true)) {
$raw_settings['fwFound'] = true;
}
break;
case 'internal2':
break;
case 'off':
default: // Place in root TFTP dir
if (in_array("{$dir}/{$raw_settings['loadimage']}", $dir_list, true)) {
$raw_settings['fwFound'] = true;
}
break;
}
} //else {
//$raw_settings['validate'] = '-;';
//}
$raw_settings['templateFound'] = false;
if (!empty($raw_settings['nametemplate'])) {
$file = $this->sccppath['tftp_templates_path'] . '/' . $raw_settings['nametemplate'];
if (file_exists($file)) {
$raw_settings['templateFound'] = true;
} //else {
//$raw_settings['templateFound'] .= 'no';
//}
} //else {
//$raw_settings['validate'] .= '-';
//}
foreach ($modelList as &$raw_settings) {
if ((!empty($raw_settings['loadimage'])) && ($raw_settings['fwfound'] === 'no')) {
switch ($search_mode) {
case 'pro':
case 'on':
case 'internal':
if (in_array($raw_settings['loadimage'], $dir_list, true)) {
$raw_settings['fwfound'] = 'yes';
}
break;
case 'internal2':
break;
case 'off':
default: // Place in root TFTP dir
if (in_array("{$dir}/{$raw_settings['loadimage']}", $dir_list, true)) {
$raw_settings['fwfound'] = 'yes';
}
break;
}
}
if (!empty($raw_settings['nametemplate'])) {
$file = $this->sccppath['tftp_templates_path'] . '/' . $raw_settings['nametemplate'];
if (file_exists($file)) {
$raw_settings['templatefound'] = 'yes';
}
}
}
unset($raw_settings); // passed as reference so must unset.
dbug($modelList);
// Now need to update database to avoid checks in future
// // TODO: First pass - need to refine.
foreach ($modelList as $key => $value) {
$this->dbinterface->write('sccpdevmodel', $value, 'replace');
}
return $modelList;
}

View file

@ -182,7 +182,7 @@ function Get_DB_config($sccp_compatible)
'modify' => "enum('sccpdevice', 'sipdevice', 'sccpuser')" ),
)
);
// Hardware Mobile. Can switch Softwate to Hardware
// Hardware Mobile. Can switch Software to Hardware
$db_config_v4M = array(
'sccpdevmodel' => array(
'loadinformationid' => array('create' => "VARCHAR(30) NULL DEFAULT NULL")
@ -289,7 +289,7 @@ function Get_DB_config($sccp_compatible)
'_description' => array('rename' => 'description'),
'keepalive' => array('create' => "INT(11) DEFAULT '60'", 'modify' => 'INT(11)', 'def_modify' => "60")
),
'sccpline' => array (
'sccpline' => array(
'regcontext' => array('create' => "VARCHAR(20) NULL default 'sccpregistration'", 'modify' => "VARCHAR(20)"),
'transfer_on_hangup' => array('create' => "enum('on','off') NOT NULL default 'off'", 'modify' => "enum('on','off')"),
'autoselectline_enabled' => array('create' => "enum('on','off') NOT NULL default 'off'", 'modify' => "enum('on','off')"),
@ -303,9 +303,13 @@ function Get_DB_config($sccp_compatible)
'_backgroundImageAccess' => array('rename' => 'backgroundImageAccess'),
'_callLogBlfEnabled' => array('rename' => 'callLogBlfEnabled')
),
'sccpsettings' => array (
'sccpsettings' => array(
'systemdefault' => array('create' => "VARCHAR(255) NULL default ''")
)
),
'sccpdevmodel' => array(
'fwfound' => array('create' => "enum('yes','no') NOT NULL default 'no'", 'modify' => "enum('yes','no')"),
'templatefound' => array('create' => "enum('yes','no') NOT NULL default 'no'", 'modify' => "enum('yes','no')")
)
);
if ($sccp_compatible >= 433) {
@ -318,6 +322,7 @@ function Get_DB_config($sccp_compatible)
$db_config_v4['sccpdevice'] = array_merge($db_config_v4['sccpdevice'],$db_config_v5['sccpdevice']);
$db_config_v4['sccpline'] = array_merge($db_config_v4['sccpline'],$db_config_v5['sccpline']);
$db_config_v4['sccpsettings'] = $db_config_v5['sccpsettings'];
$db_config_v4['sccpdevmodel'] = $db_config_v5['sccpdevmodel'];
}
return $db_config_v4;
}

View file

@ -1,7 +1,7 @@
<module>
<rawname>sccp_manager</rawname>
<name>SCCP Manager</name>
<version>16.0.0.1</version>
<version>16.0.0.2</version>
<type>setup</type>
<category>SCCP Connectivity</category>
<publisher>Steve Lad, Alex GP</publisher>
@ -9,8 +9,8 @@
<description>SCCP Phone and Extension Manager</description>
<menuitems>
<sccpsettings sort="1">Server Config</sccpsettings>
<sccp_adv sort="2">System Parameters</sccp_adv>
<sccp_phone sort="3">Phones Manager</sccp_phone>
<sccp_adv sort="2">Phone Types</sccp_adv>
<sccp_phone sort="3">Lines and Devices</sccp_phone>
</menuitems>
<changelog>
* Version 13.0.0.1 * - Alfa Release tested on freepbx v.13.0.192.16, v.14.0.1.5
@ -250,6 +250,8 @@
<field name="loadinformationid" type="string" length="30" notnull="false"/>
<field name="enabled" type="integer" default="0" notnull="false"/>
<field name="nametemplate" type="string" length="50" notnull="false"/>
<field name="fwfound" type="string" length="50" notnull="false"/>
<field name="templatefound" type="string" length="50" notnull="false"/>
<key name="model" type="index">
<column name="model"/>
</key>

View file

@ -17,7 +17,7 @@ if (!defined('FREEPBX_IS_AUTH')) {
$spage = FreePBX::create()->Sccp_manager;
if (empty($spage->class_error)) {
$display_page = $spage->advServerShowPage();
$display_info = _("SCCP Advance Server Configuration");
$display_info = _("Phone Management");
} else {
$display_page = $spage->infoServerShowPage();
$display_info = _("SCCP Server Configuration");

View file

@ -202,9 +202,9 @@ class dbinterface
function getModelInfoFromDb($get = 'all', $format_list = 'all', $filter = array())
{
$sel_inf = "*, model, false as fwFound, false as templateFound";
$sel_inf = "*, model";
if ($format_list === 'model') {
$sel_inf = "model, vendor, dns, buttons, false as fwFound, false as templateFound";
$sel_inf = "model, vendor, dns, buttons";
}
switch ($get) {
case 'byciscoid':

View file

@ -25,7 +25,6 @@ trait bmoFunctions {
$this->dialTemplateData = json_encode($this->getDialTemplate());
$this->softKeyData = json_encode($this->getSoftKey());
$this->deviceModelData = json_encode($this->ajaxHandler($_REQUEST = array('command'=>'getDeviceModel', 'type'=>'enabled')));
dbug($this->deviceModelData);
break;
default:
break;
@ -33,7 +32,7 @@ trait bmoFunctions {
}
function getPhoneGrid(string $type, $activeDevices =array()){
$dbDevices = array();
// Find all devices defined in the database.
$dbDevices = $this->dbinterface->getSccpDeviceTableData('phoneGrid', array('type' => $type));

View file

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

View file

@ -56,6 +56,7 @@ if (!empty($_REQUEST['id'])) {
}
}
}
// TODO: dev_id should always be set so do not need this??
if (empty($dev_id)) {
$dev_id = 'new';
} else {
@ -69,10 +70,10 @@ if (!empty($def_val['type']['data'])) {
if (isset($tmp_raw[$def_val['type']['data']])) {
$tmp_raw = $tmp_raw[$def_val['type']['data']];
}
if (!$tmp_raw['fwFound']) {
if ($tmp_raw['fwfound'] === 'no') {
$device_warning['Image'] = array('Device firmware not found : '.$tmp_raw['loadimage']);
}
if (!$tmp_raw['templateFound']) {
if ($tmp_raw['templatefound'] === 'no') {
$device_warning['Template'] = array('Missing device configuration template : '. $tmp_raw['nametemplate']);
}
if (!empty($device_warning)) {