diff options
Diffstat (limited to 'modules-available/sysconfig/inc/configmodule')
6 files changed, 130 insertions, 52 deletions
diff --git a/modules-available/sysconfig/inc/configmodule/branding.inc.php b/modules-available/sysconfig/inc/configmodule/branding.inc.php index 8990dbec..7013e3ae 100644 --- a/modules-available/sysconfig/inc/configmodule/branding.inc.php +++ b/modules-available/sysconfig/inc/configmodule/branding.inc.php @@ -14,34 +14,34 @@ class ConfigModule_Branding extends ConfigModule const MODID = 'Branding'; const VERSION = 1; - + + /** @var false|string */ private $tmpFile = false; - protected function generateInternal($tgz, $parent) + protected function generateInternal(string $tgz, ?string $parent) { if (!$this->validateConfig()) { - return $this->archive() !== false && file_exists($this->archive()); // No new temp file given, old archive still exists, pretend it worked... + return !empty($this->archive()) && file_exists($this->archive()); // No new temp file given, old archive still exists, pretend it worked... } - $task = Taskmanager::submit('MoveFile', array( + return Taskmanager::submit('MoveFile', array( 'source' => $this->tmpFile, 'destination' => $tgz, 'parentTask' => $parent, 'failOnParentFail' => false )); - return $task; } - protected function moduleVersion() + protected function moduleVersion(): int { return self::VERSION; } - protected function validateConfig() + protected function validateConfig(): bool { return $this->tmpFile !== false && file_exists($this->tmpFile); } - public function setData($key, $value) + public function setData(string $key, $value): bool { if ($key !== 'tmpFile' || !is_string($value) || !file_exists($value)) return false; @@ -49,12 +49,12 @@ class ConfigModule_Branding extends ConfigModule return true; } - public function getData($key) + public function getData(?string $key): bool { return false; } - public function allowDownload() + public function allowDownload(): bool { return true; } diff --git a/modules-available/sysconfig/inc/configmodule/customodule.inc.php b/modules-available/sysconfig/inc/configmodule/customodule.inc.php index 3c10bada..0b8e38d2 100644 --- a/modules-available/sysconfig/inc/configmodule/customodule.inc.php +++ b/modules-available/sysconfig/inc/configmodule/customodule.inc.php @@ -12,48 +12,62 @@ ConfigModule::registerModule( class ConfigModule_CustomModule extends ConfigModule { const MODID = 'CustomModule'; - const VERSION = 1; - + const VERSION = 2; + + /** @var false|string */ private $tmpFile = false; - protected function generateInternal($tgz, $parent) + protected function generateInternal(string $tgz, ?string $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() === '' || !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( + return Taskmanager::submit('MoveFile', array( 'source' => $this->tmpFile, 'destination' => $tgz, 'parentTask' => $parent, 'failOnParentFail' => false )); - return $task; } - protected function moduleVersion() + protected function moduleVersion(): int { return self::VERSION; } - protected function validateConfig() + protected function validateConfig(): bool { return $this->tmpFile !== false && file_exists($this->tmpFile); } - public function setData($key, $value) + public function setData(string $key, $value): bool { + // Sets the temp file from the wizard, where it stored the processed archive if ($key !== 'tmpFile' || !file_exists($value)) return false; $this->tmpFile = $value; return true; } - public function getData($key) + public function getData(?string $key): bool { return false; } - public function allowDownload() + public function allowDownload(): bool { return true; } diff --git a/modules-available/sysconfig/inc/configmodule/ldapauth.inc.php b/modules-available/sysconfig/inc/configmodule/ldapauth.inc.php index 7af4671e..64af4c0e 100644 --- a/modules-available/sysconfig/inc/configmodule/ldapauth.inc.php +++ b/modules-available/sysconfig/inc/configmodule/ldapauth.inc.php @@ -5,7 +5,7 @@ class ConfigModule_LdapAuth extends ConfigModuleBaseLdap const MODID = 'LdapAuth'; - protected function preTaskmanagerHook(&$config) + protected function preTaskmanagerHook(array &$config) { // Just set the flag so the taskmanager job knows we're dealing with a normal ldap server, // not AD scheme diff --git a/modules-available/sysconfig/inc/configmodule/screensaver.inc.php b/modules-available/sysconfig/inc/configmodule/screensaver.inc.php index ed97941e..1797331c 100644 --- a/modules-available/sysconfig/inc/configmodule/screensaver.inc.php +++ b/modules-available/sysconfig/inc/configmodule/screensaver.inc.php @@ -14,7 +14,7 @@ class ConfigModule_Screensaver extends ConfigModule const MODID = 'Screensaver'; const VERSION = 1; - protected function generateInternal($tgz, $parent) + protected function generateInternal(string $tgz, ?string $parent) { /* Validate if all data are available */ if (!$this->validateConfig()) @@ -23,30 +23,27 @@ class ConfigModule_Screensaver extends ConfigModule /* Give the Taskmanager the job and create the tgz */ $taskId = 'xscreensaver' . mt_rand() . '-' . microtime(true); - $task = Taskmanager::submit('MakeTarball', array( + return Taskmanager::submit('MakeTarball', array( 'id' => $taskId, 'files' => $this->getFileArray(), 'destination' => $tgz, ), false); - - return $task; } - protected function moduleVersion() + protected function moduleVersion(): int { return self::VERSION; } - protected function validateConfig() + protected function validateConfig(): bool { - return isset($this->moduleData['qss']) && - isset($this->moduleData['texts']) && - isset($this->moduleData['texts']['text-idle-kill']) && - isset($this->moduleData['texts']['text-no-timeout']) && - isset($this->moduleData['texts']['text-shutdown']); + return isset($this->moduleData['texts']['text-no-timeout']) + && isset($this->moduleData['texts']['text-idle-kill']) + && isset($this->moduleData['texts']['text-shutdown']) + && isset($this->moduleData['qss']); } - public function setData($key, $value) + public function setData(string $key, $value): bool { switch ($key) { case 'qss': @@ -60,17 +57,15 @@ class ConfigModule_Screensaver extends ConfigModule return true; } - public function allowDownload() + public function allowDownload(): bool { return false; } /** * Creates a map with filepath => file content - * - * @return array in the form of Map<String, byte[]> */ - private function getFileArray() + private function getFileArray(): array { $files = array( '/opt/openslx/xscreensaver/style.qss' => $this->moduleData['qss'], @@ -100,7 +95,7 @@ class ConfigModule_Screensaver extends ConfigModule return $files; } - private function wrapHtmlTags($text_name) + private function wrapHtmlTags(string $text_name): string { return '<html><body>' . $this->moduleData['texts'][$text_name] . '</body></html>'; } diff --git a/modules-available/sysconfig/inc/configmodule/sshconfig.inc.php b/modules-available/sysconfig/inc/configmodule/sshconfig.inc.php index 9975f789..a62d1035 100644 --- a/modules-available/sysconfig/inc/configmodule/sshconfig.inc.php +++ b/modules-available/sysconfig/inc/configmodule/sshconfig.inc.php @@ -5,7 +5,7 @@ ConfigModule::registerModule( Dictionary::translateFileModule('sysconfig', 'config-module', 'sshconfig_title'), // Title Dictionary::translateFileModule('sysconfig', 'config-module', 'sshconfig_description'), // Description Dictionary::translateFileModule('sysconfig', 'config-module', 'group_sshconfig'), // Group - false, // Only one per config? + true, // Only one per config? 500 ); @@ -14,7 +14,7 @@ class ConfigModule_SshConfig extends ConfigModule const MODID = 'SshConfig'; const VERSION = 1; - protected function generateInternal($tgz, $parent) + protected function generateInternal(string $tgz, ?string $parent) { if (!$this->validateConfig()) return false; @@ -23,36 +23,50 @@ class ConfigModule_SshConfig extends ConfigModule 'failOnParentFail' => false, 'parent' => $parent ); - // Create config module, which will also check if the pubkey is valid return Taskmanager::submit('SshdConfigGenerator', $config); } - protected function moduleVersion() + protected function moduleVersion(): int { return self::VERSION; } - protected function validateConfig() + protected function validateConfig(): bool { - return isset($this->moduleData['publicKey']) && isset($this->moduleData['allowPasswordLogin']) && isset($this->moduleData['listenPort']); + // UPGRADE + if (isset($this->moduleData['allowPasswordLogin']) && !isset($this->moduleData['allowedUsersLogin'])) { + $this->moduleData['allowPasswordLogin'] = strtoupper($this->moduleData['allowPasswordLogin']); + if (!in_array($this->moduleData['allowPasswordLogin'], ['NO', 'USER_ONLY', 'YES'])) { + $this->moduleData['allowPasswordLogin'] = 'NO'; + } + $this->moduleData['allowedUsersLogin'] = 'ALL'; + } + return isset($this->moduleData['allowPasswordLogin']) && isset($this->moduleData['allowedUsersLogin']) + && isset($this->moduleData['listenPort']); } - public function setData($key, $value) + public function setData(string $key, $value): bool { switch ($key) { case 'publicKey': - break; + if ($value === false) { + error_log('Unsetting publicKey'); + unset($this->moduleData[$key]); + return true; + } + return false; case 'allowPasswordLogin': - if ($value === true || $value === 'yes') - $value = 'yes'; - elseif ($value === false || $value === 'no') - $value = 'no'; - else + if (!in_array($value, ['NO', 'USER_ONLY', 'YES'])) + return false; + break; + case 'allowedUsersLogin'; + if (!in_array($value, ['ROOT_ONLY', 'USER_ONLY', 'ALL'])) return false; break; case 'listenPort': if (!is_numeric($value) || $value < 1 || $value > 65535) return false; + $value = (int)$value; break; default: return false; diff --git a/modules-available/sysconfig/inc/configmodule/sshkey.inc.php b/modules-available/sysconfig/inc/configmodule/sshkey.inc.php new file mode 100644 index 00000000..e4a55ad7 --- /dev/null +++ b/modules-available/sysconfig/inc/configmodule/sshkey.inc.php @@ -0,0 +1,55 @@ +<?php + +ConfigModule::registerModule( + ConfigModule_SshKey::MODID, // ID + Dictionary::translateFileModule('sysconfig', 'config-module', 'sshkey_title'), // Title + Dictionary::translateFileModule('sysconfig', 'config-module', 'sshkey_description'), // Description + Dictionary::translateFileModule('sysconfig', 'config-module', 'group_sshkey'), // Group + false, // Only one per config? + 510 +); + +class ConfigModule_SshKey extends ConfigModule +{ + const MODID = 'SshKey'; + const VERSION = 1; + + protected function generateInternal(string $tgz, ?string $parent) + { + if (!$this->validateConfig()) + return false; + $config = array( + 'files' => [ + '/root/.ssh/authorized_keys.d/sshkey_' . $this->id() . '_' . Util::sanitizeFilename($this->title()) . '.pub' + => $this->moduleData['publicKey']], + 'destination' => $tgz, + 'failOnParentFail' => false, + 'parent' => $parent + ); + // Create config module, which will also check if the pubkey is valid + return Taskmanager::submit('MakeTarball', $config); + } + + protected function moduleVersion(): int + { + return self::VERSION; + } + + protected function validateConfig(): bool + { + return isset($this->moduleData['publicKey']); + } + + public function setData(string $key, $value): bool + { + switch ($key) { + case 'publicKey': + break; + default: + return false; + } + $this->moduleData[$key] = $value; + return true; + } + +} |