From 04123643da499bac9eed8e8d1198a4c69148075f Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Wed, 21 May 2014 18:41:25 +0200 Subject: Server Setup page --- inc/message.inc.php | 1 + inc/property.inc.php | 58 +++++++++++++++++++++++++++++++++++++++++++++++++ inc/taskmanager.inc.php | 6 ++++- inc/util.inc.php | 6 ++++- 4 files changed, 69 insertions(+), 2 deletions(-) create mode 100644 inc/property.inc.php (limited to 'inc') diff --git a/inc/message.inc.php b/inc/message.inc.php index 8a3b5d4e..cab8fbd3 100644 --- a/inc/message.inc.php +++ b/inc/message.inc.php @@ -32,6 +32,7 @@ $error_text = array( 'taskmanager-error' => 'Verbindung zum Taskmanager fehlgeschlagen', 'taskmanager-format' => 'Taskmanager hat ungültige Daten zurückgeliefert', 'task-error' => 'Ausführung fehlgeschlagen: {{0}}', + 'invalid-ip' => 'Kein Interface ist auf die Adresse {{0}} konfiguriert' ); class Message diff --git a/inc/property.inc.php b/inc/property.inc.php new file mode 100644 index 00000000..a1c252a5 --- /dev/null +++ b/inc/property.inc.php @@ -0,0 +1,58 @@ +fetch(PDO::FETCH_ASSOC)) { + self::$cache[$row['name']] = $row['value']; + } + } + if (!isset(self::$cache[$key])) return $default; + return self::$cache[$key]; + } + + /** + * Set value in property store. + * + * @param string $key key of value to set + * @param type $value the value to store for $key + */ + private static function set($key, $value) + { + Database::exec("INSERT INTO property (name, value) VALUES (:key, :value)" + . " ON DUPLICATE KEY UPDATE value = VALUES(value)", array( + 'key' => $key, + 'value' => $value + )); + if (self::$cache !== false) { + self::$cache[$key] = $value; + } + } + + public static function getServerIp() + { + return self::get('server-ip', 'none'); + } + + public static function setServerIp($value) + { + self::set('server-ip', $value); + } + +} \ No newline at end of file diff --git a/inc/taskmanager.inc.php b/inc/taskmanager.inc.php index 3353050f..27e79dea 100644 --- a/inc/taskmanager.inc.php +++ b/inc/taskmanager.inc.php @@ -42,10 +42,14 @@ class Taskmanager Message::addError('taskmanager-format'); return false; } - if ($reply['statusCode'] === NO_SUCH_TASK) { + if (isset($reply['statusCode']) && $reply['statusCode'] === NO_SUCH_TASK) { Message::addError('task-error', 'Ungültiger Task: ' . $task); return false; } + if (!isset($reply['id'])) { + Message::addError('taskmanager-format'); + return false; + } return $reply; } diff --git a/inc/util.inc.php b/inc/util.inc.php index 8235edd0..4b974f6d 100644 --- a/inc/util.inc.php +++ b/inc/util.inc.php @@ -25,9 +25,13 @@ class Util * Redirects the user via a '302 Moved' header. * An active session will be saved, any messages that haven't * been displayed yet will be appended to the redirect. + * @param string $location Location to redirect to. "false" to redirect to same URL (useful after POSTs) */ - public static function redirect($location) + public static function redirect($location = false) { + if ($location === false) { + $location = preg_replace('/(&|\?)message\[\]\=[^&]*(&|$)/', '\1', $_SERVER['REQUEST_URI']); + } Session::save(); $messages = Message::toRequest(); if (!empty($messages)) { -- cgit v1.2.3-55-g7522