diff options
author | Simon Rettberg | 2014-05-19 15:30:59 +0200 |
---|---|---|
committer | Simon Rettberg | 2014-05-19 15:30:59 +0200 |
commit | f6ceaa03052e6878afd53a4bbb7f4429849fe25a (patch) | |
tree | 9f5582c8c275494728f6d6dcf656479714688934 /modules/sysconfig | |
parent | Working on config.tgz composition through config modules (diff) | |
download | slx-admin-f6ceaa03052e6878afd53a4bbb7f4429849fe25a.tar.gz slx-admin-f6ceaa03052e6878afd53a4bbb7f4429849fe25a.tar.xz slx-admin-f6ceaa03052e6878afd53a4bbb7f4429849fe25a.zip |
OO style modules
Diffstat (limited to 'modules/sysconfig')
-rw-r--r-- | modules/sysconfig/addmodule.inc.php | 188 | ||||
-rw-r--r-- | modules/sysconfig/addmodule_ad.inc.php | 57 | ||||
-rw-r--r-- | modules/sysconfig/addmodule_custom.inc.php | 142 |
3 files changed, 255 insertions, 132 deletions
diff --git a/modules/sysconfig/addmodule.inc.php b/modules/sysconfig/addmodule.inc.php index aca2f762..924f18fa 100644 --- a/modules/sysconfig/addmodule.inc.php +++ b/modules/sysconfig/addmodule.inc.php @@ -8,30 +8,47 @@ abstract class AddModule_Base { /** + * Holds all the known configuration modules, with title, description, start class for their wizard, etc. + * @var array + */ + protected static $moduleTypes = array(); + + /** + * Holds the instance for the currently executing step + * @var \AddModule_Base + */ + private static $instance = false; + + public static function addModule($id, $startClass, $title, $description, $sortOrder = 0) + { + self::$moduleTypes[] = array( + 'startClass' => $startClass, + 'title' => $title, + 'description' => $description, + 'sortOrder' => $sortOrder + ); + } + + /** * * @param type $step * @return \AddModule_Base */ - public static function get($step) + public static function setStep($step) { - switch ($step) { - case 0: // Upload form - return new AddModule_UploadForm(); - case 1: // Handle config module uploading - return new AddModule_ProcessUpload(); - case 2: // ? - return new AddModule_CompressModule(); + if (empty($step) || !class_exists($step) || get_parent_class($step) !== 'AddModule_Base') { + Message::addError('invalid-action', $step); + Util::redirect('?do=SysConfig'); } - Message::addError('invalid-action', $step); - Util::redirect('?do=sysconfig'); + self::$instance = new $step(); } - + protected function tmError() { Message::addError('taskmanager-error'); - Util::redirect('?do=sysconfig'); + Util::redirect('?do=SysConfig'); } - + protected function taskError($status) { if (isset($status['data']['error'])) { @@ -42,7 +59,7 @@ abstract class AddModule_Base $error = 'Unbekannter Taskmanager-Fehler'; // TODO: No text } Message::addError('task-error', $error); - Util::redirect('?do=sysconfig'); + Util::redirect('?do=SysConfig'); } /** @@ -51,146 +68,53 @@ abstract class AddModule_Base * early if something is wrong, or you received post * data etc. */ - public function preprocess() + protected function preprocessInternal() { // void } /** - * Do page rendering + * Do page rendering. */ - public function render() + protected function renderInternal() { // void } - -} - -class AddModule_UploadForm extends AddModule_Base -{ - - public function render() - { - global $nextStep; - Session::set('mod_temp', false); - Render::addDialog('Eigenes Modul hinzufügen', false, 'sysconfig/custom-upload', array('step' => $nextStep)); - } - -} - -/** - * Some file has just been uploaded. Try to store it, then try to unpack/analyze it. - * If this succeeds, we proceed to the next step where we present the user our findings - * and ask what to do with this. - */ -class AddModule_ProcessUpload extends AddModule_Base -{ - private $taskId = false; - - public function preprocess() + public static function preprocess() { - if (!isset($_FILES['modulefile'])) { - Message::addError('missing-file'); - return; + if (self::$instance === false) { + Util::traceError('No step instance yet'); } - if ($_FILES['modulefile']['error'] != UPLOAD_ERR_OK) { - Message::addError('upload-failed', $_FILE['modulefile']['name']); - return; - } - $tempfile = $_FILES['modulefile']['tmp_name'] . '.tmp'; - if (!move_uploaded_file($_FILES['modulefile']['tmp_name'], $tempfile)) { - Message:addError('error-write', $tempfile); - return; - } - $this->taskId = 'tgzmod' . mt_rand() . '-' . microtime(true); - Taskmanager::submit('ListArchive', array( - 'id' => $this->taskId, - 'file' => $tempfile - ), true); - Session::set('mod_temp', $tempfile); + self::$instance->preprocessInternal(); } - public function render() + public static function render() { - $status = Taskmanager::waitComplete($this->taskId); - Taskmanager::release($this->taskId); - $tempfile = Session::get('mod_temp'); - if (!isset($status['statusCode'])) { - unlink($tempfile); - $this->tmError(); - } - if ($status['statusCode'] != TASK_FINISHED) { - unlink($tempfile); - $this->taskError($status); - } - // Sort files for better display - $dirs = array(); - foreach ($status['data']['entries'] as $file) { - if ($file['isdir']) continue; - $dirs[dirname($file['name'])][] = $file; - } - 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; - } + if (self::$instance === false) { + Util::traceError('No step instance yet'); } - global $nextStep; - Render::addDialog('Eigenes Modul hinzufügen', false, 'sysconfig/custom-fileselect', array( - 'step' => $nextStep, - 'files' => $list, - )); - Session::save(); + self::$instance->renderInternal(); } } -class AddModule_CompressModule extends AddModule_Base +/** + * Start dialog for adding module. Here the user + * selects which kind of module they want to add. + */ +class AddModule_Start extends AddModule_Base { - - private $taskId = false; - - public function preprocess() + + protected function renderInternal() { - $title = Request::post('title'); - $tempfile = Session::get('mod_temp'); - if (empty($title) || empty($tempfile) || !file_exists($tempfile)) { - Message::addError('empty-field'); - return; + $title = $order = array(); + foreach (AddModule_Base::$moduleTypes as $module) { + $title[] = $module['title']; + $order[] = $module['sortOrder']; } - // Recompress using task manager - $this->taskId = 'tgzmod' . mt_rand() . '-' . microtime(true); - $destFile = CONFIG_TGZ_LIST_DIR . '/modules/mod-' . preg_replace('/[^a-z0-9_\-]+/is', '_', $title) . '-' . microtime(true) . '.tgz'; - Taskmanager::submit('RecompressArchive', array( - 'id' => $this->taskId, - 'inputFiles' => array($tempfile), - 'outputFile' => $destFile - ), true); - $status = Taskmanager::waitComplete($this->taskId); - unlink($tempfile); - if (!isset($status['statusCode'])) { - $this->tmError(); - } - if ($status['statusCode'] != TASK_FINISHED) { - $this->taskError($status); - } - // Seems ok, create entry in DB - $ret = Database::exec("INSERT INTO configtgz_module (title, moduletype, filename, contents) VALUES (:title, 'custom', :file, '')", - array('title' => $title, 'file' => $destFile)); - if ($ret === false) { - unlink($destFile); - Util::traceError("Could not insert module into Database"); - } - Message::addSuccess('module-added'); - Util::redirect('?do=sysconfig'); + array_multisort($order, SORT_ASC, $title, SORT_ASC, self::$moduleTypes); + Render::addDialog('Modul hinzufügen', false, 'sysconfig/start', array('modules' => self::$moduleTypes)); } - + } diff --git a/modules/sysconfig/addmodule_ad.inc.php b/modules/sysconfig/addmodule_ad.inc.php new file mode 100644 index 00000000..abc55df5 --- /dev/null +++ b/modules/sysconfig/addmodule_ad.inc.php @@ -0,0 +1,57 @@ +<?php + +/* + * Wizard for setting up active directory integration for authentication. + */ + +AddModule_Base::addModule('active_directory', 'AdModule_Start', 'Active Directory Authentifizierung', + 'Mit diesem Modul ist die Anmeldung an den Client PCs mit den Benutzerkonten eines Active Directory' + . ' möglich. Je nach Konfiguration ist auch die Nutzung eines Benutzerverzeichnisses auf dem Client möglich.' +); + +class AdModule_Start extends AddModule_Base +{ + + protected function renderInternal() + { + Session::set('ad_stuff', false); + Render::addDialog('Active Directory Authentifizierung', false, 'sysconfig/ad-start', array( + 'step' => 'AdModule_CheckConnection', + 'server' => Request::post('server'), + 'searchbase' => Request::post('searchbase'), + 'binddn' => Request::post('binddn'), + 'bindpw' => Request::post('bindpw'), + )); + } + +} + +class AdModule_CheckConnection extends AddModule_Base +{ + + private $taskId = false; + + protected function preprocessInternal() + { + $server = Request::post('server'); + $searchbase = Request::post('searchbase'); + $binddn = Request::post('binddn'); + $bindpw = Request::post('bindpw'); + if (empty($server) || empty($searchbase) || empty($binddn)) { + Message::addError('empty-field'); + AddModule_Base::setStep('AdModule_Start'); + return; + } + $this->taskId = 'ad_' . mt_rand() . '-' . microtime(true); + Taskmanager::submit('LdapSearch', array( + 'id' => $this->taskId, + 'uri' => '' + ), true); + } + + protected function renderInternal() + { + Message::addInfo('missing-file'); + } + +}
\ No newline at end of file diff --git a/modules/sysconfig/addmodule_custom.inc.php b/modules/sysconfig/addmodule_custom.inc.php new file mode 100644 index 00000000..ec2c8af7 --- /dev/null +++ b/modules/sysconfig/addmodule_custom.inc.php @@ -0,0 +1,142 @@ +<?php + +/* + * Wizard for adding a custom module. A custom module is a plain archive that gets + * included into a config.tgz the way itz is. No handling, sanity checks or anything + * fancy is happening. + */ + +AddModule_Base::addModule('custom', 'CustomModule_UploadForm', 'Erweitertes Modul', + 'Mit einem Erweiterten Modul ist es möglich, beliebige Dateien zum Grundsystem hinzuzufügen.' + . ' Nutzen Sie dieses Modul, um z.B. spezielle Konfigurationsdateien auf den Client PCs zu' + . ' verwenden, die sich nicht mit einem der anderen Wizards erstellen lässt.' + . ' Das Hinzufügen eines Erweiterten Moduls erfordert in der Regel zumindest grundlegende' + . ' Systemkenntnisse im Linuxbereich.', 100 +); + +class CustomModule_UploadForm extends AddModule_Base +{ + + protected function renderInternal() + { + Session::set('mod_temp', false); + Render::addDialog('Eigenes Modul hinzufügen', false, 'sysconfig/custom-upload', array('step' => 'CustomModule_ProcessUpload')); + } + +} + +/** + * Some file has just been uploaded. Try to store it, then try to unpack/analyze it. + * If this succeeds, we proceed to the next step where we present the user our findings + * and ask what to do with this. + */ +class CustomModule_ProcessUpload extends AddModule_Base +{ + + private $taskId = false; + + protected function preprocessInternal() + { + if (!isset($_FILES['modulefile'])) { + Message::addError('missing-file'); + Util::redirect('?do=SysConfig'); + } + if ($_FILES['modulefile']['error'] != UPLOAD_ERR_OK) { + Message::addError('upload-failed', $_FILES['modulefile']['name']); + Util::redirect('?do=SysConfig'); + } + $tempfile = $_FILES['modulefile']['tmp_name'] . '.tmp'; + if (!move_uploaded_file($_FILES['modulefile']['tmp_name'], $tempfile)) { + Message:addError('error-write', $tempfile); + Util::redirect('?do=SysConfig'); + } + $this->taskId = 'tgzmod' . mt_rand() . '-' . microtime(true); + Taskmanager::submit('ListArchive', array( + 'id' => $this->taskId, + 'file' => $tempfile + ), true); + Session::set('mod_temp', $tempfile); + } + + protected function renderInternal() + { + $status = Taskmanager::waitComplete($this->taskId); + Taskmanager::release($this->taskId); + $tempfile = Session::get('mod_temp'); + if (!isset($status['statusCode'])) { + unlink($tempfile); + $this->tmError(); + } + if ($status['statusCode'] != TASK_FINISHED) { + unlink($tempfile); + $this->taskError($status); + } + // Sort files for better display + $dirs = array(); + foreach ($status['data']['entries'] as $file) { + if ($file['isdir']) continue; + $dirs[dirname($file['name'])][] = $file; + } + 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; + } + } + Render::addDialog('Eigenes Modul hinzufügen', false, 'sysconfig/custom-fileselect', array( + 'step' => 'CustomModule_CompressModule', + 'files' => $list, + )); + Session::save(); + } + +} + +class CustomModule_CompressModule extends AddModule_Base +{ + + private $taskId = false; + + protected function preprocessInternal() + { + $title = Request::post('title'); + $tempfile = Session::get('mod_temp'); + if (empty($title) || empty($tempfile) || !file_exists($tempfile)) { + Message::addError('empty-field'); + return; + } + // Recompress using task manager + $this->taskId = 'tgzmod' . mt_rand() . '-' . microtime(true); + $destFile = CONFIG_TGZ_LIST_DIR . '/modules/mod-' . preg_replace('/[^a-z0-9_\-]+/is', '_', $title) . '-' . microtime(true) . '.tgz'; + Taskmanager::submit('RecompressArchive', array( + 'id' => $this->taskId, + 'inputFiles' => array($tempfile), + 'outputFile' => $destFile + ), true); + $status = Taskmanager::waitComplete($this->taskId); + unlink($tempfile); + if (!isset($status['statusCode'])) { + $this->tmError(); + } + if ($status['statusCode'] != TASK_FINISHED) { + $this->taskError($status); + } + // Seems ok, create entry in DB + $ret = Database::exec("INSERT INTO configtgz_module (title, moduletype, filename, contents) VALUES (:title, 'custom', :file, '')", + array('title' => $title, 'file' => $destFile)); + if ($ret === false) { + unlink($destFile); + Util::traceError("Could not insert module into Database"); + } + Message::addSuccess('module-added'); + Util::redirect('?do=SysConfig'); + } + +} |