From 1d5366f45f50202021e8108f6ff3779d6e5b9d9c Mon Sep 17 00:00:00 2001 From: Jannik Schönartz Date: Wed, 15 Jan 2020 20:58:53 +0100 Subject: [sysconfig] Add screensaver customization module --- .../sysconfig/inc/configmodule/screensaver.inc.php | 107 +++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 modules-available/sysconfig/inc/configmodule/screensaver.inc.php (limited to 'modules-available/sysconfig/inc/configmodule/screensaver.inc.php') 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..813b040d --- /dev/null +++ b/modules-available/sysconfig/inc/configmodule/screensaver.inc.php @@ -0,0 +1,107 @@ +validateConfig()) + return false; + + /* Give the Taskmanager the job and create the tgz */ + $taskId = 'xscreensaver' . mt_rand() . '-' . microtime(true); + + $task = Taskmanager::submit('MakeTarball', array( + 'id' => $taskId, + 'files' => $this->getFileArray(), + 'destination' => $tgz, + ), false); + + return $task; + } + + protected function moduleVersion() + { + return self::VERSION; + } + + protected function validateConfig() + { + 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']); + } + + public function setData($key, $value) + { + switch ($key) { + case 'qss': + case 'texts': + case 'messages': + break; + default: + return false; + } + $this->moduleData[$key] = $value; + return true; + } + + public function allowDownload() + { + return true; + } + + /** + * Creates a map with filepath => file content + * + * @return array in the form of Map + */ + private function getFileArray() + { + $files = array( + '/opt/openslx/xscreensaver/style.qss' => array_values(unpack('C*', $this->moduleData['qss'])), + '/opt/openslx/xscreensaver/text-idle-kill' => array_values(unpack('C*', $this->wrapHtmlTags('text-idle-kill'))), + '/opt/openslx/xscreensaver/text-no-timeout' => array_values(unpack('C*', $this->wrapHtmlTags('text-no-timeout'))), + '/opt/openslx/xscreensaver/text-shutdown' => array_values(unpack('C*', $this->wrapHtmlTags('text-shutdown'))), + ); + + /* Create the message.ini from the messages array */ + $messages = ''; + foreach ($this->moduleData['messages'] as $categorie => $array) { + $messages = $messages . '[' . $categorie . ']' . "\n"; + foreach ($array as $key => $message) { + $messages = $messages . $key . '="' . $message . '"' . "\n"; + } + } + $files['/opt/openslx/xscreensaver/messages.ini'] = array_values(unpack('C*', $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'] = array_values(unpack('C*', $this->wrapHtmlTags('text-idle-kill-locked'))); + if (isset($this->moduleData['texts']['text-no-timeout-locked'])) + $files['/opt/openslx/xscreensaver/text-no-timeout-locked'] = array_values(unpack('C*', $this->wrapHtmlTags('text-no-timeout-locked'))); + if (isset($this->moduleData['texts']['text-shutdown-locked'])) + $files['/opt/openslx/xscreensaver/text-shutdown-locked'] = array_values(unpack('C*', $this->wrapHtmlTags('text-shutdown-locked'))); + + return $files; + } + + private function wrapHtmlTags($text_name) + { + return '' . $this->moduleData['texts'][$text_name] . ''; + } +} -- cgit v1.2.3-55-g7522