Add timer on TFTP read; Get Metadata
TFTP read caused a hang if no server available Set to DONTWAIT and loop and then check for valid data Use metadat to set system defaults
This commit is contained in:
parent
7721e7a8a0
commit
f74978c1b3
41
install.php
41
install.php
|
@ -98,6 +98,7 @@ if ($chanSCCPWarning) {
|
||||||
Setup_RealTime();
|
Setup_RealTime();
|
||||||
addDriver($sccp_compatible);
|
addDriver($sccp_compatible);
|
||||||
checkTftpServer();
|
checkTftpServer();
|
||||||
|
getConfigMetaData('general');
|
||||||
outn("<br>");
|
outn("<br>");
|
||||||
outn("Install Complete !");
|
outn("Install Complete !");
|
||||||
outn("<br>");
|
outn("<br>");
|
||||||
|
@ -293,7 +294,10 @@ function Get_DB_config($sccp_compatible)
|
||||||
'_autocall_select' => array('create' => "enum('on','off') NOT NULL default 'off'", 'modify' => "enum('on','off')"),
|
'_autocall_select' => array('create' => "enum('on','off') NOT NULL default 'off'", 'modify' => "enum('on','off')"),
|
||||||
'_backgroundImageAccess' => array('create' => "enum('on','off') NOT NULL default 'off'", 'modify' => "enum('on','off')"),
|
'_backgroundImageAccess' => array('create' => "enum('on','off') NOT NULL default 'off'", 'modify' => "enum('on','off')"),
|
||||||
'_callLogBlfEnabled' => array('create' => "enum('3','2') NOT NULL default '2'", 'modify' => "enum('3','2')")
|
'_callLogBlfEnabled' => array('create' => "enum('3','2') NOT NULL default '2'", 'modify' => "enum('3','2')")
|
||||||
)
|
),
|
||||||
|
'sccpsettings' => array (
|
||||||
|
'systemdefault' => array('create' => "VARCHAR(255) NULL default ''")
|
||||||
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
if ($sccp_compatible >= 433) {
|
if ($sccp_compatible >= 433) {
|
||||||
|
@ -305,6 +309,7 @@ function Get_DB_config($sccp_compatible)
|
||||||
if ($sccp_compatible >= 433) {
|
if ($sccp_compatible >= 433) {
|
||||||
$db_config_v4['sccpdevice'] = array_merge($db_config_v4['sccpdevice'],$db_config_v5['sccpdevice']);
|
$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['sccpline'] = array_merge($db_config_v4['sccpline'],$db_config_v5['sccpline']);
|
||||||
|
$db_config_v4['sccpsettings'] = $db_config_v5['sccpsettings'];
|
||||||
}
|
}
|
||||||
return $db_config_v4;
|
return $db_config_v4;
|
||||||
}
|
}
|
||||||
|
@ -456,6 +461,8 @@ function InstallDB_updateSchema($db_config)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!empty($sql_update)) {
|
if (!empty($sql_update)) {
|
||||||
|
outn("<li>" . _("Updating table rows :") . $affected_rows . "</li>");
|
||||||
|
dbug('create', $sql_update);
|
||||||
$sql_update = 'BEGIN; ' . $sql_update . ' COMMIT;';
|
$sql_update = 'BEGIN; ' . $sql_update . ' COMMIT;';
|
||||||
sql($sql_update);
|
sql($sql_update);
|
||||||
$affected_rows = $db->affectedRows();
|
$affected_rows = $db->affectedRows();
|
||||||
|
@ -463,16 +470,17 @@ function InstallDB_updateSchema($db_config)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($sql_create)) {
|
if (!empty($sql_create)) {
|
||||||
outn("<li>" . _("Adding new FILTER_VALIDATE_INT") . "</li>");
|
outn("<li>" . _("Adding new columns ...") . "</li>");
|
||||||
$sql_create = "ALTER TABLE {$tabl_name} " .substr($sql_create, 0, -2);
|
$sql_create = "ALTER TABLE {$tabl_name} " .substr($sql_create, 0, -2);
|
||||||
|
dbug('create', $sql_create);
|
||||||
try {
|
try {
|
||||||
$check = $db->query($sql_create);
|
$check = $db->query($sql_create);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
die_freepbx("Can add column to {$tabl_name}. SQL: {$sql_create} \n");
|
die_freepbx("Can't add column to {$tabl_name}. SQL: {$sql_create} \n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!empty($sql_modify)) {
|
if (!empty($sql_modify)) {
|
||||||
outn("<li>" . _("Modifying table ") . $tabl_name ."</li>");
|
outn("<li>" . _("Modifying table columns") . $tabl_name ."</li>");
|
||||||
|
|
||||||
$sql_modify = "ALTER TABLE {$tabl_name} " . substr($sql_modify, 0, -2);
|
$sql_modify = "ALTER TABLE {$tabl_name} " . substr($sql_modify, 0, -2);
|
||||||
try {
|
try {
|
||||||
|
@ -881,6 +889,7 @@ function addDriver($sccp_compatible) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function checkTftpServer() {
|
function checkTftpServer() {
|
||||||
|
outn("<li>" . _("Checking TFTP server path and availability ...") . "</li>");
|
||||||
global $db;
|
global $db;
|
||||||
global $cnf_int;
|
global $cnf_int;
|
||||||
global $settingsFromDb;
|
global $settingsFromDb;
|
||||||
|
@ -928,6 +937,7 @@ function checkTftpServer() {
|
||||||
}
|
}
|
||||||
|
|
||||||
$settingsToDb['asterisk_etc_path'] =array( 'keyword' => 'asterisk_etc_path', 'seq' => 20, 'type' => 0, 'data' => $confDir);
|
$settingsToDb['asterisk_etc_path'] =array( 'keyword' => 'asterisk_etc_path', 'seq' => 20, 'type' => 0, 'data' => $confDir);
|
||||||
|
$settingsFromDb['asterisk_etc_path']['data'] = $confDir;
|
||||||
|
|
||||||
foreach ($settingsToDb as $settingToSave) {
|
foreach ($settingsToDb as $settingToSave) {
|
||||||
$sql = "REPLACE INTO sccpsettings (keyword, data, seq, type) VALUES ('{$settingToSave['keyword']}', '{$settingToSave['data']}', {$settingToSave['seq']}, {$settingToSave['type']});";
|
$sql = "REPLACE INTO sccpsettings (keyword, data, seq, type) VALUES ('{$settingToSave['keyword']}', '{$settingToSave['data']}', {$settingToSave['seq']}, {$settingToSave['type']});";
|
||||||
|
@ -941,6 +951,7 @@ function checkTftpServer() {
|
||||||
$settingsToDb = $extconfigs->updateTftpStructure($settingsFromDb);
|
$settingsToDb = $extconfigs->updateTftpStructure($settingsFromDb);
|
||||||
|
|
||||||
foreach ($settingsToDb as $settingKey => $settingVal) {
|
foreach ($settingsToDb as $settingKey => $settingVal) {
|
||||||
|
$settingsFromDb[$settingKey]['data'] = $settingVal;
|
||||||
$sql = "REPLACE INTO sccpsettings (keyword, data, seq, type) VALUES ('{$settingKey}', '{$settingVal}', 20, 0)";
|
$sql = "REPLACE INTO sccpsettings (keyword, data, seq, type) VALUES ('{$settingKey}', '{$settingVal}', 20, 0)";
|
||||||
$results = $db->query($sql);
|
$results = $db->query($sql);
|
||||||
if (DB::IsError($results)) {
|
if (DB::IsError($results)) {
|
||||||
|
@ -950,4 +961,26 @@ function checkTftpServer() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getConfigMetaData($segment) {
|
||||||
|
global $aminterface;
|
||||||
|
global $db;
|
||||||
|
global $settingsFromDb;
|
||||||
|
$sysConfiguration = $aminterface->getSCCPConfigMetaData($segment);
|
||||||
|
foreach ($sysConfiguration['Options'] as $key => $valueArray) {
|
||||||
|
if ($valueArray['Flags'][0] == 'Obsolete' || $valueArray['Flags'][0] == 'Deprecated') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$sysConfiguration[$valueArray['Name']] = $valueArray;
|
||||||
|
if (array_key_exists($valueArray['Name'],$settingsFromDb)) {
|
||||||
|
if (!empty($sysConfiguration[$valueArray['Name']]['DefaultValue'])) {
|
||||||
|
$sql = "REPLACE INTO sccpsettings (keyword, systemdefault) VALUES ('{$valueArray['Name']}', '{$valueArray['DefaultValue']}');";
|
||||||
|
$results = $db->query($sql);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
unset($sysConfiguration[$key]);
|
||||||
|
}
|
||||||
|
unset($sysConfiguration['Options']);
|
||||||
|
dbug('sysconfig', $sysConfiguration);
|
||||||
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
|
@ -431,14 +431,19 @@ class aminterface
|
||||||
}
|
}
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
function getSCCPConfigMetaData($segment = '') {
|
||||||
|
if ($this->_connect_state) {
|
||||||
|
$_action = new \FreePBX\modules\Sccp_manager\aminterface\SCCPConfigMetaDataAction($segment);
|
||||||
|
$metadata = $this->send($_action)->getResult();
|
||||||
|
}
|
||||||
|
return $metadata;
|
||||||
|
}
|
||||||
|
|
||||||
function getSCCPVersion()
|
function getSCCPVersion()
|
||||||
{
|
{
|
||||||
//Initialise result array
|
//Initialise result array
|
||||||
$result = array( 'RevisionHash' => '', 'vCode' => 0, 'RevisionNum' => 0, 'futures' => '', 'Version' => 0);
|
$result = array( 'RevisionHash' => '', 'vCode' => 0, 'RevisionNum' => 0, 'futures' => '', 'Version' => 0);
|
||||||
if ($this->_connect_state) {
|
$metadata = $this->getSCCPConfigMetaData();
|
||||||
$_action = new \FreePBX\modules\Sccp_manager\aminterface\SCCPConfigMetaDataAction();
|
|
||||||
$metadata = $this->send($_action)->getResult();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($metadata['Version'])) {
|
if (isset($metadata['Version'])) {
|
||||||
$result['Version'] = $metadata['Version'];
|
$result['Version'] = $metadata['Version'];
|
||||||
|
|
|
@ -179,11 +179,21 @@ trait helperfunctions {
|
||||||
$ret = "";
|
$ret = "";
|
||||||
|
|
||||||
// fetch file content
|
// fetch file content
|
||||||
$numbytes = socket_recvfrom($socket, $buffer, 84, MSG_WAITALL, $host, $port);
|
$count = 0;
|
||||||
|
while ( 0 == $numbytes = socket_recvfrom($socket, $buffer, 84, MSG_DONTWAIT, $host, $port)) {
|
||||||
|
sleep(1);
|
||||||
|
$count ++;
|
||||||
|
if ($count > 5) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// unpack the returned buffer and discard the first two bytes
|
// unpack the returned buffer and discard the first two bytes
|
||||||
$pkt = unpack("nopcode/nblockno/a*data", $buffer);
|
try {
|
||||||
|
$pkt = unpack("nopcode/nblockno/a*data", $buffer);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
die_freepbx("TFTP server is not responding. Check that it is running and then reload this page \n");
|
||||||
|
}
|
||||||
// send ack
|
// send ack
|
||||||
$packet = chr(4) . chr($pkt["blockno"]);
|
$packet = chr(4) . chr($pkt["blockno"]);
|
||||||
socket_sendto($socket, $packet, strlen($packet), MSG_EOR, $host, $port);
|
socket_sendto($socket, $packet, strlen($packet), MSG_EOR, $host, $port);
|
||||||
|
|
Loading…
Reference in a new issue