From a2217e6e371e0d2787ec77bc71228bda84d9ef90 Mon Sep 17 00:00:00 2001
From: steve-lad <72376554+steve-lad@users.noreply.github.com>
Date: Mon, 27 Dec 2021 11:09:42 +0100
Subject: [PATCH] Fix issue #39
Get masterFilesList at install direct from Provisioner. If not available, install a copy from the module
---
Sccp_manager.class.php | 3 +--
install.php | 20 ++++++++++++++++++++
module.xml | 3 ++-
sccpManTraits/ajaxHelper.php | 3 ++-
sccpManTraits/helperFunctions.php | 4 ++--
views/advserver.model.php | 8 ++++++++
6 files changed, 35 insertions(+), 6 deletions(-)
diff --git a/Sccp_manager.class.php b/Sccp_manager.class.php
index 04b6474..4fca918 100644
--- a/Sccp_manager.class.php
+++ b/Sccp_manager.class.php
@@ -616,13 +616,12 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO {
private function findInstLangs() {
//locales and country tones are installed in the tftp_lang_path
//Available packs from provisioner are in masterFilesStructure.xml in tftpRoot Path
- // TODO: Need to include this file as part of module in case download not allowed/available
$searchDir = '/'; //set default for when called by installer on virgin system
$result = array();
if (!file_exists("{$this->sccppath['tftp_path']}/masterFilesStructure.xml")) {
- if (!$this->getFileListFromProvisioner()) {
+ if (!$this->getFileListFromProvisioner($this->sccppath['tftp_path'])) {
// File does not exist and cannot get from internet.
return $result;
};
diff --git a/install.php b/install.php
index f033599..a852db1 100644
--- a/install.php
+++ b/install.php
@@ -1035,9 +1035,29 @@ function checkTftpServer() {
die_freepbx(_("Error updating sccpsettings. $sql"));
}
}
+ getMasterFileList($tftpRootPath);
return;
}
+function getMasterFileList(string $tftpRootPath) {
+ global $thisInstaller;
+ global $amp_conf;
+ outn("
" . _("Checking TFTP server path and availability ...") . "");
+ if (file_exists("{$tftpRootPath}/masterFilesStructure.xml")) {
+ outn("" . _("Backing up existing masterFilesList ...") . "");
+ rename("{$tftpRootPath}/masterFilesStructure.xml","{$tftpRootPath}/masterFilesStructure.xml.old");
+ }
+ outn("" . _("Getting latest master file list from provisioner ...") . "");
+ if (!$thisInstaller->getFileListFromProvisioner($tftpRootPath)) {
+ outn("" . _("Unable to fetch master file list from provisioner, installing local copy ...") . "");
+ // Cannot get file from internet, so use copy with this dist which may be older.
+ if (!copy($amp_conf['AMPWEBROOT'] . '/admin/modules/sccp_manager/contrib/masterFilesStructure.xml',"{$tftpRootPath}/masterFilesStructure.xml")) {
+ return false;
+ };
+ return true;
+ };
+}
+
function cleanUpSccpSettings() {
global $thisInstaller;
global $settingsFromDb;
diff --git a/module.xml b/module.xml
index 6806b99..2118171 100644
--- a/module.xml
+++ b/module.xml
@@ -1,7 +1,7 @@
sccp_manager
SCCP Manager
- 14.3.0.14a
+ 14.3.0.15
setup
SCCP Connectivity
Steve Lad, Alex GP
@@ -24,6 +24,7 @@
* Version 14.2.0.9 * - Bug Fix - incorrect response class for Reset Token Device
* Version 14.2.0.10 * - Bug Fix - line not assigned on device creation
* Version 14.3.0.0 * - New Minor Version - Change DB and add new settings
+ * Version 14.3.0.15 * - Get masterFilesList from provisoner via installer Fix Issue 39
https://github.com/chan-sccp/sccp_manager
diff --git a/sccpManTraits/ajaxHelper.php b/sccpManTraits/ajaxHelper.php
index c7d7e05..77c5dc6 100644
--- a/sccpManTraits/ajaxHelper.php
+++ b/sccpManTraits/ajaxHelper.php
@@ -554,8 +554,9 @@ trait ajaxHelper {
$filesToGet = array();
$totalFiles = 0;
$provisionerUrl = "https://github.com/dkgroot/provision_sccp/raw/master/";
+ // TODO: Maybe should always fetch to ensure have latest, backing up old version
if (!file_exists("{$this->sccppath['tftp_path']}/masterFilesStructure.xml")) {
- if (!$this->getFileListFromProvisioner()) {
+ if (!$this->getFileListFromProvisioner($this->sccppath['tftp_path'])) {
return array('status' => false,
'message' => "{$provisionerUrl}tools/tftpbootFiles.xml cannot be found. Check your internet connection, and that this path exists",
'reload' => false);
diff --git a/sccpManTraits/helperFunctions.php b/sccpManTraits/helperFunctions.php
index e6fa71b..f081c57 100644
--- a/sccpManTraits/helperFunctions.php
+++ b/sccpManTraits/helperFunctions.php
@@ -253,12 +253,12 @@ trait helperfunctions {
$dom->save($filename);
}
- public function getFileListFromProvisioner() {
+ public function getFileListFromProvisioner(string $tftpRootPath) {
$provisionerUrl = "https://github.com/dkgroot/provision_sccp/raw/master/";
// Get master tftpboot directory structure
try {
- file_put_contents("{$this->sccppath['tftp_path']}/masterFilesStructure.xml",file_get_contents("{$provisionerUrl}tools/tftpbootFiles.xml"));
+ file_put_contents("{$tftpRootPath}/masterFilesStructure.xml",file_get_contents("{$provisionerUrl}tools/tftpbootFiles.xml"));
} catch (\Exception $e) {
return false;
}
diff --git a/views/advserver.model.php b/views/advserver.model.php
index 081cebb..8445c18 100644
--- a/views/advserver.model.php
+++ b/views/advserver.model.php
@@ -152,6 +152,14 @@ global $amp_conf;
sccppath['tftp_path']}/masterFilesStructure.xml")) {
+ if (!$this->getFileListFromProvisioner($this->sccppath['tftp_path'])) {
+ // File does not exist and cannot get from internet.
+ return $result;
+ };
+}
$tftpBootXml = simplexml_load_file("{$this->sccppath['tftp_path']}/masterFilesStructure.xml");
$firmwareDir = $tftpBootXml->xpath("//Directory[@name='firmware']");