summaryrefslogtreecommitdiffstats
path: root/modules-available/sysconfig/inc
diff options
context:
space:
mode:
authorSimon Rettberg2020-12-10 14:01:18 +0100
committerSimon Rettberg2020-12-10 14:01:18 +0100
commitcdf414bf6a999788d4d70e997f8c413e96ef7bb1 (patch)
tree3c05b78ffd5133fafaf110b4dd392294399d788e /modules-available/sysconfig/inc
parent[rebootcontrol] rename scheduler table and associated queries (diff)
downloadslx-admin-cdf414bf6a999788d4d70e997f8c413e96ef7bb1.tar.gz
slx-admin-cdf414bf6a999788d4d70e997f8c413e96ef7bb1.tar.xz
slx-admin-cdf414bf6a999788d4d70e997f8c413e96ef7bb1.zip
[sysconfig] CustomModule: Add check for file ownership, add "fix" option
The fix option will change the owner/group of every file and directory in the archive to root:root Previously, the client changed the ownership of the config.tgz contents to root when extracting, but in some cases it's desired to deliver files with specific owner and group settings. The version of the CustomModule module has been bumped to 2, so we can automatically convert old modules when upgrading or importing a backup, to be compatible to the old "root everything on the client" logic.
Diffstat (limited to 'modules-available/sysconfig/inc')
-rw-r--r--modules-available/sysconfig/inc/configmodule.inc.php5
-rw-r--r--modules-available/sysconfig/inc/configmodule/customodule.inc.php18
-rw-r--r--modules-available/sysconfig/inc/sysconfig.inc.php27
3 files changed, 48 insertions, 2 deletions
diff --git a/modules-available/sysconfig/inc/configmodule.inc.php b/modules-available/sysconfig/inc/configmodule.inc.php
index f3906378..580c15a0 100644
--- a/modules-available/sysconfig/inc/configmodule.inc.php
+++ b/modules-available/sysconfig/inc/configmodule.inc.php
@@ -262,6 +262,11 @@ abstract class ConfigModule
{
return $this->moduleStatus;
}
+
+ public final function currentVersion()
+ {
+ return $this->currentVersion;
+ }
/**
* Get the module type.
diff --git a/modules-available/sysconfig/inc/configmodule/customodule.inc.php b/modules-available/sysconfig/inc/configmodule/customodule.inc.php
index 3c10bada..8b968336 100644
--- a/modules-available/sysconfig/inc/configmodule/customodule.inc.php
+++ b/modules-available/sysconfig/inc/configmodule/customodule.inc.php
@@ -12,14 +12,27 @@ ConfigModule::registerModule(
class ConfigModule_CustomModule extends ConfigModule
{
const MODID = 'CustomModule';
- const VERSION = 1;
+ const VERSION = 2;
private $tmpFile = false;
protected function generateInternal($tgz, $parent)
{
if (!$this->validateConfig()) {
- return $this->archive() !== false && file_exists($this->archive()); // No new temp file given, old archive still exists, pretend it worked...
+ // No temp file given from wizard
+ // Old archive still exists? pretend it worked...
+ if ($this->archive() === false || !file_exists($this->archive()))
+ return false;
+ if ($this->currentVersion() == 1) {
+ // Need an upgrade
+ return Taskmanager::submit('RecompressArchive', array(
+ 'inputFiles' => [$this->archive() => false],
+ 'outputFile' => $tgz,
+ 'forceRoot' => true, // Force this for old modules for backward compat
+ ));
+ }
+ // Nothing to do
+ return true;
}
$task = Taskmanager::submit('MoveFile', array(
'source' => $this->tmpFile,
@@ -42,6 +55,7 @@ class ConfigModule_CustomModule extends ConfigModule
public function setData($key, $value)
{
+ // Sets the temp file from the wizard, where it stored the processed archive
if ($key !== 'tmpFile' || !file_exists($value))
return false;
$this->tmpFile = $value;
diff --git a/modules-available/sysconfig/inc/sysconfig.inc.php b/modules-available/sysconfig/inc/sysconfig.inc.php
index 15bd4104..9ad3a36f 100644
--- a/modules-available/sysconfig/inc/sysconfig.inc.php
+++ b/modules-available/sysconfig/inc/sysconfig.inc.php
@@ -14,4 +14,31 @@ class SysConfig
return $ret;
}
+ public static function archiveContentsFromTask($status, &$userGroupWarn = null) : array
+ {
+ // Sort files for better display
+ $dirs = array();
+ foreach ($status['data']['entries'] as $file) {
+ if ($file['isdir']) continue;
+ $dirs[dirname($file['name'])][] = $file;
+ if ($file['userId'] > 0 || $file['groupId'] > 0) {
+ $userGroupWarn = true;
+ }
+ }
+ ksort($dirs);
+ $list = array();
+ foreach ($dirs as $dir => $files) {
+ $list[] = array(
+ 'name' => $dir,
+ 'isdir' => true
+ );
+ sort($files);
+ foreach ($files as $file) {
+ $file['size'] = Util::readableFileSize($file['size']);
+ $list[] = $file;
+ }
+ }
+ return $list;
+ }
+
} \ No newline at end of file