diff options
26 files changed, 304 insertions, 65 deletions
diff --git a/inc/configmodule.inc.php b/inc/configmodule.inc.php index ae2201fc..31c19953 100644 --- a/inc/configmodule.inc.php +++ b/inc/configmodule.inc.php @@ -163,6 +163,14 @@ abstract class ConfigModule * @return boolean true if data was successfully set, false otherwise (i.e. invalid data being set) */ public abstract function setData($key, $value); + + /** + * Get module specific data + * + * @param string $key key, name or id of data to get + * @return mixed Module specific data + */ + public abstract function getData($key); /** * Module specific version of generate. @@ -260,6 +268,28 @@ abstract class ConfigModule )); return true; } + + /** + * Update the given module in database. This will not regenerate + * the module's tgz. + * + * @return boolean true on success, false otherwise + */ + public final function update() + { + if ($this->moduleId === 0) + Util::traceError('ConfigModule::update called when moduleId == 0'); + if (!$this->validateConfig()) + return false; + // Update + Database::exec("UPDATE configtgz_module SET contents = :contents, status = :status " + . " WHERE moduleid = :moduleid LIMIT 1", array( + 'moduleid' => $this->moduleId, + 'contents' => json_encode($this->moduleData), + 'status' => 'OUTDATED' + )); + return true; + } /** * Generate the module's tgz, don't wait for completion. @@ -283,7 +313,7 @@ abstract class ConfigModule if ($ret === true || (isset($ret['statusCode']) && $ret['statusCode'] === TASK_FINISHED)) { // Already Finished if (file_exists($this->moduleArchive) && !file_exists($tmpTgz)) - $tmpTgz = false; + $tmpTgz = false; // If generateInternal succeeded and there's no tmpTgz, it means the file didn't have to be updated return $this->markUpdated($tmpTgz); } if (!is_array($ret) || !isset($ret['id']) || Taskmanager::isFailed($ret)) { @@ -362,6 +392,7 @@ abstract class ConfigModule // Update related config.tgzs $configs = ConfigTgz::getAllForModule($this->moduleId); foreach ($configs as $config) { + $config->markOutdated(); $config->generate(); } return $retval; @@ -406,7 +437,6 @@ abstract class ConfigModule { self::loadDb(); // Quick hack: Hard code AdAuth, should be a property of the config module class.... $list = self::getAll('AdAuth'); - error_log('Changed: Telling ' - count($list) . ' modules'); foreach ($list as $mod) { $mod->event_serverIpChanged(); } diff --git a/inc/configmodule/adauth.inc.php b/inc/configmodule/adauth.inc.php index 828469c3..11087286 100644 --- a/inc/configmodule/adauth.inc.php +++ b/inc/configmodule/adauth.inc.php @@ -47,6 +47,13 @@ class ConfigModule_AdAuth extends ConfigModule return true; } + public function getData($key) + { + if (!is_array($this->moduleData) || !isset($this->moduleData[$key])) + return false; + return $this->moduleData[$key]; + } + // ############## Callbacks ############################# /** diff --git a/inc/configmodule/branding.inc.php b/inc/configmodule/branding.inc.php index 6e452a93..b2f28c2f 100644 --- a/inc/configmodule/branding.inc.php +++ b/inc/configmodule/branding.inc.php @@ -47,4 +47,9 @@ class ConfigModule_Branding extends ConfigModule $this->tmpFile = $value; } + public function getData($key) + { + return false; + } + } diff --git a/inc/configmodule/customodule.inc.php b/inc/configmodule/customodule.inc.php index 195f738f..89f63549 100644 --- a/inc/configmodule/customodule.inc.php +++ b/inc/configmodule/customodule.inc.php @@ -48,4 +48,10 @@ class ConfigModule_CustomModule extends ConfigModule return false; $this->tmpFile = $value; } + + public function getData($key) + { + return false; + } + } diff --git a/inc/configtgz.inc.php b/inc/configtgz.inc.php index 783f8b80..2082155c 100644 --- a/inc/configtgz.inc.php +++ b/inc/configtgz.inc.php @@ -22,6 +22,21 @@ class ConfigTgz { return $this->configTitle; } + + public function areAllModulesUpToDate() + { + if (!$this->configId > 0) + Util::traceError('ConfigTgz::areAllModulesUpToDate called on un-inserted config.tgz!'); + foreach ($this->modules as $module) { + if (!empty($module['filepath']) && file_exists($module['filepath'])) { + if ($module['status'] !== 'OK') + return false; + } else { + return false; + } + } + return true; + } public static function insert($title, $moduleIds) { @@ -104,21 +119,73 @@ class ConfigTgz } return $list; } + + /** + * Called when (re)generating a config tgz failed, so we can + * update the status in the DB and add a server log entry. + * + * @param array $task + * @param array $args contains 'configid' and optionally 'deleteOnError' + */ + public static function generateFailed($task, $args) + { + if (!isset($args['configid']) || !is_numeric($args['configid'])) { + EventLog::warning('Ignoring generateFailed event as it has no configid assigned.'); + return; + } + $config = self::get($args['configid']); + if ($config === false) { + EventLog::warning('generateFailed callback for config id ' . $args['configid'] . ', but no instance could be generated.'); + return; + } + if (isset($task['data']['error'])) + $error = $task['data']['error']; + elseif (isset($task['data']['messages'])) + $error = $task['data']['messages']; + else + $error = ''; + EventLog::failure("Generating config.tgz '" . $config->configTitle . "' failed.", $error); + if ($args['deleteOnError']) + $config->delete(); + else + $config->markFailed(); + } + + /** + * (Re)generating a config tgz succeeded. Update db entry. + * + * @param array $args contains 'configid' and optionally 'deleteOnError' + */ + public static function generateSucceeded($args) + { + if (!isset($args['configid']) || !is_numeric($args['configid'])) { + EventLog::warning('Ignoring generateSucceeded event as it has no configid assigned.'); + return; + } + $config = self::get($args['configid']); + if ($config === false) { + EventLog::warning('generateSucceeded callback for config id ' . $args['configid'] . ', but no instance could be generated.'); + return; + } + $config->markUpdated(); + } - public function generate() + /** + * + * @param type $deleteOnError + * @param type $timeoutMs + * @return string - OK (success) + * - OUTDATED (updating failed, but old version still exists) + * - MISSING (failed and no old version available) + */ + public function generate($deleteOnError = false, $timeoutMs = 0) { if (!($this->configId > 0) || !is_array($this->modules) || $this->file === false) Util::traceError ('configId <= 0 or modules not array in ConfigTgz::rebuild()'); $files = array(); - $successStatus = 'OK'; foreach ($this->modules as $module) { - if (!empty($module['filepath']) && file_exists($module['filepath'])) { + if (!empty($module['filepath']) && file_exists($module['filepath'])) $files[] = $module['filepath']; - if ($module['status'] !== 'OK') - $successStatus = 'OUTDATED'; - } else { - $successStatus = 'OUTDATED'; - } } // Hand over to tm $task = Taskmanager::submit('RecompressArchive', array( @@ -126,18 +193,28 @@ class ConfigTgz 'outputFile' => $this->file )); // Wait for completion - if (!Taskmanager::isFailed($task) && !Taskmanager::isFinished($task)) - $task = Taskmanager::waitComplete($task, 5000); - // Failed... - if (Taskmanager::isFailed($task)) { + if ($timeoutMs > 0 && !Taskmanager::isFailed($task) && !Taskmanager::isFinished($task)) + $task = Taskmanager::waitComplete($task, $timeoutMs); + if ($task === true || (isset($task['statusCode']) && $task['statusCode'] === TASK_FINISHED)) { + // Success! + $this->markUpdated(); + return true; + } + if (!is_array($task) || !isset($task['id']) || Taskmanager::isFailed($task)) { + // Failed... Taskmanager::addErrorMessage($task); - $successStatus = file_exists($this->file) ? 'OUTDATED' : 'MISSING'; + if (!$deleteOnError) + $this->markFailed(); + else + $this->delete(); + return false; } - Database::exec("UPDATE configtgz SET status = :status WHERE configid = :configid LIMIT 1", array( + // Still running, add callback + TaskmanagerCallback::addCallback($task, 'cbConfTgzCreated', array( 'configid' => $this->configId, - 'status' => $successStatus + 'deleteOnError' => $deleteOnError )); - return $successStatus; + return $task['id']; } public function delete() @@ -157,4 +234,38 @@ class ConfigTgz return $ret; } + public function markOutdated() + { + if ($this->configId === 0) + Util::traceError('ConfigTgz::markOutdated called with invalid config id!'); + return $this->mark('OUTDATED'); + } + + private function markUpdated() + { + if ($this->configId === 0) + Util::traceError('ConfigTgz::markUpdated called with invalid config id!'); + if ($this->areAllModulesUpToDate()) + return $this->mark('OK'); + return $this->mark('OUTDATED'); + } + + private function markFailed() + { + if ($this->configId === 0) + Util::traceError('ConfigTgz::markFailed called with invalid config id!'); + if ($this->file === false || !file_exists($this->file)) + return $this->mark('MISSING'); + return $this->mark('OUTDATED'); + } + + private function mark($status) + { + Database::exec("UPDATE configtgz SET status = :status WHERE configid = :configid LIMIT 1", array( + 'configid' => $this->configId, + 'status' => $status + )); + return $status; + } + } diff --git a/inc/taskmanagercallback.inc.php b/inc/taskmanagercallback.inc.php index 8550d845..546fbbc9 100644 --- a/inc/taskmanagercallback.inc.php +++ b/inc/taskmanagercallback.inc.php @@ -130,5 +130,20 @@ class TaskmanagerCallback ConfigModule::generateSucceeded($args); } } + + /** + * Generating a config.tgz has finished. + * + * @param array $task task obj + * @param array $args has keys 'configid' and optionally 'deleteOnError' + */ + public static function cbConfTgzCreated($task, $args) + { + if (Taskmanager::isFailed($task)) { + ConfigTgz::generateFailed($task, $args); + } else { + ConfigTgz::generateSucceeded($args); + } + } } diff --git a/inc/util.inc.php b/inc/util.inc.php index d2ecba6f..4378a084 100644 --- a/inc/util.inc.php +++ b/inc/util.inc.php @@ -2,6 +2,7 @@ class Util { + private static $redirectParams = array(); /** * Displays an error message and stops script execution. @@ -69,9 +70,21 @@ SADFACE; $location .= '&' . $messages; } } + if (!empty(self::$redirectParams)) { + if (strpos($location, '?') === false) { + $location .= '?' . implode('&', self::$redirectParams); + } else { + $location .= '&' . implode('&', self::$redirectParams); + } + } Header('Location: ' . $location); exit(0); } + + public static function addRedirectParam($key, $value) + { + self::$redirectParams[] = $key .= '=' . urlencode($value); + } /** * Verify the user's token that protects agains CSRF. diff --git a/lang/de/messages.json b/lang/de/messages.json index 51540c15..b344fd41 100644 --- a/lang/de/messages.json +++ b/lang/de/messages.json @@ -28,6 +28,7 @@ "missing-title": "Kein Titel eingegeben", "module-added": "Modul erfolgreich hinzugef\u00fcgt", "module-deleted": "Modul {{0}} wurde gel\u00f6scht", + "module-edited": "Modul wurde aktualisiert", "module-in-use": "Modul {{0}} wird noch durch Konfiguration {{1}} verwendet", "module-rebuild-failed": "Neubau des Moduls fehlgeschlagen", "module-rebuilding": "Modul wird neu generiert", diff --git a/lang/de/settings/setting.json b/lang/de/settings/setting.json index e2fbe145..63a4d881 100644 --- a/lang/de/settings/setting.json +++ b/lang/de/settings/setting.json @@ -11,7 +11,7 @@ "SLX_PROXY_IP": "Die Adresse des zu verwendenden Proxy Servers.", "SLX_PROXY_MODE": "Legt fest, ob zum Zugriff aufs Internet ein Proxy-Server ben\u00f6tigt wird.\r\n*off* = keinen Proxy benutzen.\r\n*on* = Proxy immer benutzen.\r\n*auto* = Proxy nur benutzen, wenn sich der Client-PC in einem privaten Adressbereich befindet.", "SLX_PROXY_PORT": "Der Port des zu verwendenden Proxy Servers.", - "SLX_PROXY_TYPE": "Art des Proxys: *socks4*, *socks5*, *http-connect* (HTTP Proxy mit Unterst\u00fctzung der CONNECT-Methode),*http-relay* (Klassischer HTTP Proxy)", + "SLX_PROXY_TYPE": "Art des Proxys: *socks4*, *socks5*, *http-connect* (HTTP Proxy mit Unterst\u00fctzung der CONNECT-Methode), *http-relay* (Klassischer HTTP Proxy)", "SLX_REMOTE_LOG_SESSIONS": "Legt fest, ob Logins und Logouts der Benutzer an den Satelliten gemeldet werden sollen.\r\n*yes* = Mit Benutzerkennung loggen\r\n*anonymous* = Anonym loggen\r\n*no* = Nicht loggen", "SLX_ROOT_PASS": "Das root-Passwort des Grundsystems. Wird nur f\u00fcr Diagnosezwecke am Client ben\u00f6tigt.\r\nFeld leer lassen, um root-Logins zu verbieten.\r\n\/Hinweis\/: Das Passwort wird im Klartext in der lokalen Datenbank hinterlegt, jedoch immer gehasht an die Clients \u00fcbermittelt (SHA-512 mit Salt). Wenn Sie das Passwort auch im Satelliten nicht im Klartext speichern wollen, k\u00f6nnen Sie hier auch ein vorgehashtes Passwort eintragen (im *$6$....*-Format).", "SLX_SHUTDOWN_SCHEDULE": "Feste Uhrzeit, zu der sich die Rechner ausschalten, auch wenn noch ein Benutzer aktiv ist.Mehrere Zeitpunkte k\u00f6nnen durch Leerzeichen getrennt angegeben werden.", diff --git a/lang/de/templates/sysconfig/cfg-start.json b/lang/de/templates/sysconfig/cfg-start.json index c5f4c5fa..c22a96c3 100644 --- a/lang/de/templates/sysconfig/cfg-start.json +++ b/lang/de/templates/sysconfig/cfg-start.json @@ -2,6 +2,6 @@ "lang_configuration": "Konfiguration", "lang_configurationChoose": "Bitte w\u00e4hlen Sie, welche Module f\u00fcr diese Konfiguration verwendet werden sollen.", "lang_name": "Name", - "lang_new": "Neu", - "lang_next": "Weiter" + "lang_next": "Weiter", + "lang_noModuleOfType": "Kein Modul dieser Art vorhanden." }
\ No newline at end of file diff --git a/lang/en/messages.json b/lang/en/messages.json index 8d3ac4df..889b5406 100644 --- a/lang/en/messages.json +++ b/lang/en/messages.json @@ -28,6 +28,7 @@ "missing-title": "No title given", "module-added": "Module successfully added", "module-deleted": "Module {{0}} was deleted", + "module-edited": "Module has been edited", "module-in-use": "Module {{0}} is still used by Configuration {{1}}", "module-rebuild-failed": "Rebuilding module failed", "module-rebuilding": "Module is rebuilding...", diff --git a/lang/en/settings/setting.json b/lang/en/settings/setting.json index 7a9db4a9..a17edfa6 100644 --- a/lang/en/settings/setting.json +++ b/lang/en/settings/setting.json @@ -11,7 +11,7 @@ "SLX_PROXY_IP": "The address to use for the proxy server.", "SLX_PROXY_MODE": "Determines whether a proxy server is required to access the Internet.\r\n*off* = do not use a Proxy.\r\n*on* = Always use proxy.\r\n*auto* = Only use proxy when the client PC is in a private address space.", "SLX_PROXY_PORT": "The port to use for the proxy server.", - "SLX_PROXY_TYPE": "Type of the proxy.*socks4*, *socks5*,*http-connect* (HTTP proxy with support from the CONNECT method),*http-relay* (Classic HTTP proxy)", + "SLX_PROXY_TYPE": "Type of the proxy.*socks4*, *socks5*, *http-connect* (HTTP proxy with support from the CONNECT method), *http-relay* (Classic HTTP proxy)", "SLX_REMOTE_LOG_SESSIONS": "Determines whether logins and logouts of the users should be reported to the satellite.\r\n*yes* = log with user ID\r\n*anonymous* = anonymous logging\r\n*no* = no logging", "SLX_ROOT_PASS": "The root password of the basic system. Only required for diagnostic purposes on the client.Leave field blank to disallow root logins.\/Hint\/: The password is encrypted with $6$ hash, so it is no longer readable after saving!", "SLX_SHUTDOWN_SCHEDULE": "Fixed time to turn off the computer, even if there is a user active.Several times can be specified, separated by spaces.", diff --git a/lang/en/templates/sysconfig/cfg-start.json b/lang/en/templates/sysconfig/cfg-start.json index 8ab46f37..a00a6720 100644 --- a/lang/en/templates/sysconfig/cfg-start.json +++ b/lang/en/templates/sysconfig/cfg-start.json @@ -2,6 +2,6 @@ "lang_configuration": "Configuration", "lang_configurationChoose": "Please select which modules will be used for this configuration.", "lang_name": "Name", - "lang_new": "New", - "lang_next": "Next" + "lang_next": "Next", + "lang_noModuleOfType": "No module of this type found." }
\ No newline at end of file diff --git a/lang/pt/templates/sysconfig/cfg-start.json b/lang/pt/templates/sysconfig/cfg-start.json index 7b980f3c..27260a59 100644 --- a/lang/pt/templates/sysconfig/cfg-start.json +++ b/lang/pt/templates/sysconfig/cfg-start.json @@ -2,6 +2,5 @@ "lang_configuration": "Configura\u00e7\u00e3o", "lang_configurationChoose": "Por favor, selecione qual os m\u00f3dulos ser\u00e3o usados \u200b\u200bpara esta configura\u00e7\u00e3o.", "lang_name": "Nome", - "lang_new": "Nova", "lang_next": "Pr\u00f3ximo" }
\ No newline at end of file diff --git a/modules/sysconfig.inc.php b/modules/sysconfig.inc.php index 94e2455a..e9b7e677 100644 --- a/modules/sysconfig.inc.php +++ b/modules/sysconfig.inc.php @@ -127,7 +127,8 @@ class Page_SysConfig extends Page } Render::addTemplate('sysconfig/_page', array( 'configs' => $configs, - 'modules' => $modules + 'modules' => $modules, + 'havemodules' => (count($modules) > 0) )); Render::addScriptTop('custom'); Render::addFooter('<script> $(window).load(function (e) { @@ -243,8 +244,7 @@ class Page_SysConfig extends Page Message::addError('config-invalid', $configid); Util::redirect('?do=SysConfig'); } - //$ret = $config->generate(false, 350); // TODO - $ret = $config->generate(false, 350) === 'OK'; // TODO + $ret = $config->generate(false, 350); // TODO if ($ret === true) Message::addSuccess('module-rebuilt', $config->title()); elseif ($ret === false) diff --git a/modules/sysconfig/addconfig.inc.php b/modules/sysconfig/addconfig.inc.php index 55194069..daa2cd58 100644 --- a/modules/sysconfig/addconfig.inc.php +++ b/modules/sysconfig/addconfig.inc.php @@ -153,7 +153,7 @@ class AddConfig_Finish extends AddConfig_Base Util::redirect('?do=SysConfig&action=addconfig'); } $this->config = ConfigTgz::insert($title, $modules); - if ($this->config === false || $this->config->generate() !== 'OK') { + if ($this->config === false || $this->config->generate(true, 10000) !== true) { Message::addError('unsuccessful-action'); Util::redirect('?do=SysConfig&action=addconfig'); } diff --git a/modules/sysconfig/addmodule.inc.php b/modules/sysconfig/addmodule.inc.php index 69160964..5e9ecb3a 100644 --- a/modules/sysconfig/addmodule.inc.php +++ b/modules/sysconfig/addmodule.inc.php @@ -12,6 +12,12 @@ abstract class AddModule_Base * @var \AddModule_Base */ private static $instance = false; + + /** + * Instance of ConfigModule we're editing. False if not editing but creating. + * @var \ConfigModule + */ + protected $edit = false; /** * @@ -25,6 +31,14 @@ abstract class AddModule_Base Util::redirect('?do=SysConfig'); } self::$instance = new $step(); + if (Request::any('edit')) { + self::$instance->edit = ConfigModule::get(Request::any('edit')); + if (self::$instance->edit === false) + Util::traceError('Invalid module id for editing'); + if (!preg_match('/^' . self::$instance->edit->moduleType() . '_/', $step)) + Util::traceError('Module to edit is of different type!'); + Util::addRedirectParam('edit', self::$instance->edit->id()); + } } protected function tmError() @@ -40,7 +54,7 @@ abstract class AddModule_Base } elseif (isset($status['statusCode'])) { $error = $status['statusCode']; } else { - $error = Dictionary::translate('lang_unknwonTaskManager'); // TODO: No text + $error = Dictionary::translate('lang_unknwonTaskManager'); } Message::addError('task-error', $error); Util::redirect('?do=SysConfig'); diff --git a/modules/sysconfig/addmodule_adauth.inc.php b/modules/sysconfig/addmodule_adauth.inc.php index 2418916e..26ca5b79 100644 --- a/modules/sysconfig/addmodule_adauth.inc.php +++ b/modules/sysconfig/addmodule_adauth.inc.php @@ -9,17 +9,28 @@ class AdAuth_Start extends AddModule_Base protected function renderInternal() { - Session::set('ad_check', false); - Session::save(); - Render::addDialog(Dictionary::translate('config-module', 'adAuth_title'), false, 'sysconfig/ad-start', array( - 'step' => 'AdAuth_CheckConnection', - 'title' => Request::post('title'), - 'server' => Request::post('server'), - 'searchbase' => Request::post('searchbase'), - 'binddn' => Request::post('binddn'), - 'bindpw' => Request::post('bindpw'), - 'home' => Request::post('home') - )); + if ($this->edit !== false) { + $data = array( + 'title' => $this->edit->title(), + 'server' => $this->edit->getData('server'), + 'searchbase' => $this->edit->getData('searchbase'), + 'binddn' => $this->edit->getData('binddn'), + 'bindpw' => $this->edit->getData('bindpw'), + 'home' => $this->edit->getData('home'), + 'edit' => $this->edit->id() + ); + } else { + $data = array( + 'title' => Request::post('title'), + 'server' => Request::post('server'), + 'searchbase' => Request::post('searchbase'), + 'binddn' => Request::post('binddn'), + 'bindpw' => Request::post('bindpw'), + 'home' => Request::post('home') + ); + } + $data['step'] = 'AdAuth_CheckConnection'; + Render::addDialog(Dictionary::translate('config-module', 'adAuth_title'), false, 'sysconfig/ad-start', $data); } } @@ -80,6 +91,7 @@ class AdAuth_CheckConnection extends AddModule_Base protected function renderInternal() { Render::addDialog(Dictionary::translate('config-module', 'adAuth_title'), false, 'sysconfig/ad-checkconnection', array_merge($this->taskIds, array( + 'edit' => Request::post('edit'), 'title' => Request::post('title'), 'server' => Request::post('server'), 'searchbase' => Request::post('searchbase'), @@ -125,17 +137,24 @@ class AdAuth_Finish extends AddModule_Base $title = Request::post('title'); if (empty($title)) $title = 'AD: ' . Request::post('server'); - $module = ConfigModule::getInstance('AdAuth'); + if ($this->edit === false) + $module = ConfigModule::getInstance('AdAuth'); + else + $module = $this->edit; $module->setData('server', Request::post('server')); $module->setData('searchbase', $searchbase); $module->setData('binddn', $binddn); $module->setData('bindpw', Request::post('bindpw')); $module->setData('home', Request::post('home')); - if (!$module->insert($title)) { + if ($this->edit !== false) + $ret = $module->update(); + else + $ret = $module->insert($title); + if (!$ret) { Message::addError('value-invalid', 'any', 'any'); $tgz = false; } else { - $tgz = $module->generate(true); + $tgz = $module->generate(true, NULL, 200); } if ($tgz === false) { AddModule_Base::setStep('AdAuth_Start'); // Continues with AdAuth_Start for render() diff --git a/modules/sysconfig/addmodule_branding.inc.php b/modules/sysconfig/addmodule_branding.inc.php index 7b7dace9..527b2e7b 100644 --- a/modules/sysconfig/addmodule_branding.inc.php +++ b/modules/sysconfig/addmodule_branding.inc.php @@ -11,6 +11,7 @@ class Branding_Start extends AddModule_Base { Render::addDialog(Dictionary::translate('config-module', 'branding_title'), false, 'sysconfig/branding-start', array( 'step' => 'Branding_ProcessFile', + 'edit' => $this->edit ? $this->edit->id() : false )); } @@ -79,6 +80,8 @@ class Branding_ProcessFile extends AddModule_Base 'svg' => $svg, 'error' => $this->task['data']['error'], 'step' => 'Branding_Finish', + 'edit' => $this->edit ? $this->edit->id() : false, + 'title' => $this->edit ? $this->edit->title() : false ) ); @unlink($this->svgFile); @@ -145,12 +148,12 @@ class Branding_ProcessFile extends AddModule_Base if (!empty($p["scheme"])) return $relative; - extract(parse_url($absolute)); - $path = dirname($path); + $parsed = parse_url($absolute); + $path = dirname($parsed['path']); if ($relative{0} === '/') { if ($relative{1} === '/') - return "$scheme:$relative"; + return "{$parsed['scheme']}:$relative"; $cparts = array_filter(explode("/", $relative)); } else { $aparts = array_filter(explode("/", $path)); @@ -169,17 +172,16 @@ class Branding_ProcessFile extends AddModule_Base } $path = implode("/", $cparts); $url = ""; - if ($scheme) - $url = "$scheme://"; - if (!empty($user)) { - $url .= "$user"; - if (!empty($pass)) { - $url .= ":$pass"; - } + if (!empty($parsed['scheme'])) + $url = $parsed['scheme'] . "://"; + if (!empty($parsed['user'])) { + $url .= $parsed['user']; + if (!empty($parsed['pass'])) + $url .= ":" . $parsed['pass']; $url .= "@"; } - if ($host) - $url .= "$host/"; + if ($parsed['host']) + $url .= $parsed['host'] . "/"; $url .= $path; return $url; } @@ -203,21 +205,31 @@ class Branding_Finish extends AddModule_Base Message::addError('error-read', $tgz); Util::redirect('?do=SysConfig&action=addmodule&step=Branding_Start'); } - $module = ConfigModule::getInstance('Branding'); + if ($this->edit === false) + $module = ConfigModule::getInstance('Branding'); + else + $module = $this->edit; if ($module === false) { Message::addError('error-read', 'branding.inc.php'); Util::redirect('?do=SysConfig&action=addmodule&step=Branding_Start'); } $module->setData('tmpFile', $tgz); - if (!$module->insert($title)) + if ($this->edit !== false) + $ret = $module->update(); + else + $ret = $module->insert($title); + if (!$ret) Util::redirect('?do=SysConfig&action=addmodule&step=Branding_Start'); - elseif (!$module->generate(true)) + elseif ($module->generate(true, NULL, 200) === false) Util::redirect('?do=SysConfig&action=addmodule&step=Branding_Start'); Session::set('logo_tgz', false); Session::set('logo_name', false); Session::save(); // Yay - Message::addSuccess('module-added'); + if ($this->edit !== false) + Message::addSuccess('module-edited'); + else + Message::addSuccess('module-added'); Util::redirect('?do=SysConfig'); } diff --git a/modules/sysconfig/addmodule_custommodule.inc.php b/modules/sysconfig/addmodule_custommodule.inc.php index 1be9c10f..bd66f417 100644 --- a/modules/sysconfig/addmodule_custommodule.inc.php +++ b/modules/sysconfig/addmodule_custommodule.inc.php @@ -131,7 +131,7 @@ class CustomModule_CompressModule extends AddModule_Base $module->setData('tmpFile', $destFile); if (!$module->insert($title)) Util::redirect('?do=SysConfig&action=addmodule&step=CustomModule_Start'); - elseif (!$module->generate(true)) + elseif (!$module->generate(true, NULL, 200)) Util::redirect('?do=SysConfig&action=addmodule&step=CustomModule_Start'); Session::set('mod_temp', false); Session::save(); diff --git a/templates/sysconfig/_page.html b/templates/sysconfig/_page.html index 0bc92215..93169e6a 100644 --- a/templates/sysconfig/_page.html +++ b/templates/sysconfig/_page.html @@ -55,9 +55,11 @@ {{/configs}} </form> </div> + {{#havemodules}} <div class="panel-footer"> <a class="btn btn-primary" href="?do=SysConfig&action=addconfig">{{lang_newConfiguration}}</a> </div> + {{/havemodules}} </div> </div> @@ -92,7 +94,7 @@ class="btn btn-default btn-xs" {{/needrebuild}} name="rebuild" value="{{moduleid}}" title="{{lang_rebuild}}"><span class="glyphicon glyphicon-refresh"></span></button> - <button class="btn btn-success btn-xs" name="edit" value="{{moduleid}}" title="{{lang_edit}}"><span class="glyphicon glyphicon-edit"></span></button> + <a class="btn btn-success btn-xs" href="?do=SysConfig&action=addmodule&step={{moduletype}}_Start&edit={{moduleid}}" title="{{lang_edit}}"><span class="glyphicon glyphicon-edit"></span></a> <button class="btn btn-danger btn-xs" name="del" value="{{moduleid}}" title="{{lang_delete}}"><span class="glyphicon glyphicon-trash"></span></button> </td> </tr> diff --git a/templates/sysconfig/ad-checkconnection.html b/templates/sysconfig/ad-checkconnection.html index 471208e8..17064db0 100644 --- a/templates/sysconfig/ad-checkconnection.html +++ b/templates/sysconfig/ad-checkconnection.html @@ -22,6 +22,7 @@ <div class="pull-right"> <form role="form" method="post" action="?do=SysConfig&action=addmodule&step={{step}}"> <input type="hidden" name="token" value="{{token}}"> + <input type="hidden" name="edit" value="{{edit}}"> <input name="title" value="{{title}}" type="hidden"> <input name="server" value="{{server}}" type="hidden"> <input name="searchbase" value="{{searchbase}}" type="hidden"> diff --git a/templates/sysconfig/ad-start.html b/templates/sysconfig/ad-start.html index 007bc8db..587f15af 100644 --- a/templates/sysconfig/ad-start.html +++ b/templates/sysconfig/ad-start.html @@ -12,6 +12,7 @@ <form role="form" method="post" action="?do=SysConfig&action=addmodule&step={{step}}"> <input type="hidden" name="token" value="{{token}}"> + <input type="hidden" name="edit" value="{{edit}}"> <div class="input-group"> <span class="input-group-addon slx-ga">{{lang_moduleTitle}}</span> <input tabindex="1" name="title" value="{{title}}" type="text" class="form-control"> @@ -32,7 +33,7 @@ </div> <div class="input-group"> <span class="input-group-addon slx-ga">{{lang_password}} *</span> - <input tabindex="4" name="bindpw" value="{{bindpw}}" type="text" class="form-control" placeholder="{{lang_password}}"> + <input tabindex="4" name="bindpw" value="{{bindpw}}" type="{{password_type}}" class="form-control" placeholder="{{lang_password}}"> <!--span class="input-group-btn"> <a class="btn btn-default"><span class="glyphicon glyphicon-question-sign"></span></a> </span--> diff --git a/templates/sysconfig/branding-check.html b/templates/sysconfig/branding-check.html index 52c70cd0..8f6ef055 100644 --- a/templates/sysconfig/branding-check.html +++ b/templates/sysconfig/branding-check.html @@ -16,9 +16,10 @@ <div> <form role="form" enctype="multipart/form-data" method="post" action="?do=SysConfig&action=addmodule&step={{step}}"> <input type="hidden" name="token" value="{{token}}"> + <input type="hidden" name="edit" value="{{edit}}"> <div class="form-group"> <label for="title-id">{{lang_title}}</label> - <input type="text" name="title" id ="title-id" class="form-control" placeholder="Name des Moduls"> + <input type="text" name="title" value="{{title}}" id ="title-id" class="form-control" placeholder="Name des Moduls"> </div> <button type="submit" class="btn btn-primary">{{lang_save}}</button> </form> diff --git a/templates/sysconfig/branding-start.html b/templates/sysconfig/branding-start.html index 7b22a3fd..1470929f 100644 --- a/templates/sysconfig/branding-start.html +++ b/templates/sysconfig/branding-start.html @@ -3,6 +3,7 @@ </p> <form role="form" enctype="multipart/form-data" method="post" action="?do=SysConfig&action=addmodule&step={{step}}"> <input type="hidden" name="token" value="{{token}}"> + <input type="hidden" name="edit" value="{{edit}}"> <div class="form-group"> <label for="input-url">{{lang_urlLoad}}</label> <input class="form-control" type="text" name="url" id="input-url"> diff --git a/templates/sysconfig/cfg-start.html b/templates/sysconfig/cfg-start.html index f01f46cd..7493bf55 100644 --- a/templates/sysconfig/cfg-start.html +++ b/templates/sysconfig/cfg-start.html @@ -27,7 +27,7 @@ </div> {{/modules}} {{^modules}} - <a class="btn btn-primary btn-xs" href="?do=SysConfig&action=addmodule&step={{wizardClass}}">{{lang_new}}..</a> + <div class="alert alert-info">{{lang_noModuleOfType}}</div> {{/modules}} </div> </div> |