diff options
Diffstat (limited to 'modules-available/sysconfig/inc/configmodule')
7 files changed, 228 insertions, 39 deletions
diff --git a/modules-available/sysconfig/inc/configmodule/adauth.inc.php b/modules-available/sysconfig/inc/configmodule/adauth.inc.php index ed7b318d..5e68f48c 100644 --- a/modules-available/sysconfig/inc/configmodule/adauth.inc.php +++ b/modules-available/sysconfig/inc/configmodule/adauth.inc.php @@ -12,5 +12,6 @@ ConfigModule::registerModule( Dictionary::translateFileModule('sysconfig', 'config-module', 'adAuth_title'), // Title Dictionary::translateFileModule('sysconfig', 'config-module', 'adAuth_description'), // Description Dictionary::translateFileModule('sysconfig', 'config-module', 'group_authentication'), // Group - false // Only one per config? + false, // Only one per config? + 300 ); diff --git a/modules-available/sysconfig/inc/configmodule/branding.inc.php b/modules-available/sysconfig/inc/configmodule/branding.inc.php index fd11dade..7013e3ae 100644 --- a/modules-available/sysconfig/inc/configmodule/branding.inc.php +++ b/modules-available/sysconfig/inc/configmodule/branding.inc.php @@ -5,7 +5,8 @@ ConfigModule::registerModule( Dictionary::translateFileModule('sysconfig', 'config-module', 'branding_title'), // Title Dictionary::translateFileModule('sysconfig', 'config-module', 'branding_description'), // Description Dictionary::translateFileModule('sysconfig', 'config-module', 'group_branding'), // Group - true // Only one per config? + true, // Only one per config? + 600 ); class ConfigModule_Branding extends ConfigModule @@ -13,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; @@ -48,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 336d794f..0b8e38d2 100644 --- a/modules-available/sysconfig/inc/configmodule/customodule.inc.php +++ b/modules-available/sysconfig/inc/configmodule/customodule.inc.php @@ -6,54 +6,68 @@ ConfigModule::registerModule( Dictionary::translateFileModule('sysconfig', 'config-module', 'custom_description'), // Description Dictionary::translateFileModule('sysconfig', 'config-module', 'group_generic'), // Group false, // Only one per config? - 100 // Sort order + 900 // Sort order ); 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 e8df2877..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 @@ -19,5 +19,6 @@ ConfigModule::registerModule( Dictionary::translateFileModule('sysconfig', 'config-module', 'ldapAuth_title'), // Title Dictionary::translateFileModule('sysconfig', 'config-module', 'ldapAuth_description'), // Description Dictionary::translateFileModule('sysconfig', 'config-module', 'group_authentication'), // Group - false // Only one per config? + false, // Only one per config? + 300 ); diff --git a/modules-available/sysconfig/inc/configmodule/screensaver.inc.php b/modules-available/sysconfig/inc/configmodule/screensaver.inc.php new file mode 100644 index 00000000..1797331c --- /dev/null +++ b/modules-available/sysconfig/inc/configmodule/screensaver.inc.php @@ -0,0 +1,102 @@ +<?php + +ConfigModule::registerModule( + ConfigModule_Screensaver::MODID, // ID + Dictionary::translateFileModule('sysconfig', 'config-module', 'screensaver_title'), // Title + Dictionary::translateFileModule('sysconfig', 'config-module', 'screensaver_description'), // Description + Dictionary::translateFileModule('sysconfig', 'config-module', 'group_screensaver'), // Group + true, // Only one per config? + 700 // Sort order +); + +class ConfigModule_Screensaver extends ConfigModule +{ + const MODID = 'Screensaver'; + const VERSION = 1; + + protected function generateInternal(string $tgz, ?string $parent) + { + /* Validate if all data are available */ + if (!$this->validateConfig()) + return false; + + /* Give the Taskmanager the job and create the tgz */ + $taskId = 'xscreensaver' . mt_rand() . '-' . microtime(true); + + return Taskmanager::submit('MakeTarball', array( + 'id' => $taskId, + 'files' => $this->getFileArray(), + 'destination' => $tgz, + ), false); + } + + protected function moduleVersion(): int + { + return self::VERSION; + } + + protected function validateConfig(): bool + { + 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(string $key, $value): bool + { + switch ($key) { + case 'qss': + case 'texts': + case 'messages': + break; + default: + return false; + } + $this->moduleData[$key] = $value; + return true; + } + + public function allowDownload(): bool + { + return false; + } + + /** + * Creates a map with filepath => file content + */ + private function getFileArray(): array + { + $files = array( + '/opt/openslx/xscreensaver/style.qss' => $this->moduleData['qss'], + '/opt/openslx/xscreensaver/text-idle-kill' => $this->wrapHtmlTags('text-idle-kill'), + '/opt/openslx/xscreensaver/text-no-timeout' => $this->wrapHtmlTags('text-no-timeout'), + '/opt/openslx/xscreensaver/text-shutdown' => $this->wrapHtmlTags('text-shutdown'), + ); + + /* Create the message.ini from the messages array */ + $messages = ''; + foreach ($this->moduleData['messages'] as $category => $array) { + $messages .= '[' . $category . ']' . "\n"; + foreach ($array as $key => $message) { + $messages .= $key . '="' . str_replace(['\\', '"', "\n", "\r"], '-', $message) . '"' . "\n"; + } + } + $files['/opt/openslx/xscreensaver/messages.ini'] = $messages; + + /* Add locked files if there are any */ + if (isset($this->moduleData['texts']['text-idle-kill-locked'])) + $files['/opt/openslx/xscreensaver/text-idle-kill-locked'] = $this->wrapHtmlTags('text-idle-kill-locked'); + if (isset($this->moduleData['texts']['text-no-timeout-locked'])) + $files['/opt/openslx/xscreensaver/text-no-timeout-locked'] = $this->wrapHtmlTags('text-no-timeout-locked'); + if (isset($this->moduleData['texts']['text-shutdown-locked'])) + $files['/opt/openslx/xscreensaver/text-shutdown-locked'] = $this->wrapHtmlTags('text-shutdown-locked'); + + return $files; + } + + 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 61f69581..a62d1035 100644 --- a/modules-available/sysconfig/inc/configmodule/sshconfig.inc.php +++ b/modules-available/sysconfig/inc/configmodule/sshconfig.inc.php @@ -5,7 +5,8 @@ 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 ); class ConfigModule_SshConfig extends ConfigModule @@ -13,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; @@ -22,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; + } + +} |