summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2014-05-21 18:41:25 +0200
committerSimon Rettberg2014-05-21 18:41:25 +0200
commit04123643da499bac9eed8e8d1198a4c69148075f (patch)
tree7da0dd36344624df67926b5f6312f11eca24e040
parentJS Stuff for Taskmanager interaction (diff)
downloadslx-admin-04123643da499bac9eed8e8d1198a4c69148075f.tar.gz
slx-admin-04123643da499bac9eed8e8d1198a4c69148075f.tar.xz
slx-admin-04123643da499bac9eed8e8d1198a4c69148075f.zip
Server Setup page
-rw-r--r--inc/message.inc.php1
-rw-r--r--inc/property.inc.php58
-rw-r--r--inc/taskmanager.inc.php6
-rw-r--r--inc/util.inc.php6
-rw-r--r--modules/serversetup.inc.php72
-rw-r--r--templates/main-menu.html7
-rw-r--r--templates/page-serversetup.html30
7 files changed, 175 insertions, 5 deletions
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 @@
+<?php
+
+/**
+ * Get or set simple key-value-pairs, backed by the database
+ * to make them persistent.
+ */
+class Property
+{
+ private static $cache = false;
+
+ /**
+ * Retrieve value from property store.
+ *
+ * @param string $key key to retrieve the value of
+ * @param mixed $default value to return if $key does not exist in the property store
+ * @return mixed the value attached to $key, or $default if $key does not exist
+ */
+ private static function get($key, $default = false)
+ {
+ if (self::$cache === false) {
+ $res = Database::simpleQuery("SELECT name, value FROM property");
+ while ($row = $res->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)) {
diff --git a/modules/serversetup.inc.php b/modules/serversetup.inc.php
new file mode 100644
index 00000000..3f2b8768
--- /dev/null
+++ b/modules/serversetup.inc.php
@@ -0,0 +1,72 @@
+<?php
+
+class Page_ServerSetup extends Page
+{
+ private $taskStatus;
+ private $currentAddress;
+
+ protected function doPreprocess()
+ {
+ User::load();
+
+ if (!User::hasPermission('superadmin')) {
+ Message::addError('no-permission');
+ Util::redirect('?do=Main');
+ }
+
+ $this->currentAddress = Property::getServerIp();
+ $newAddress = Request::post('ip', 'none');
+
+ $this->taskStatus = Taskmanager::submit('LocalAddressesList', array());
+
+ if ($this->taskStatus === false) {
+ Util::redirect('?do=Main');
+ }
+
+ if ($this->taskStatus['statusCode'] === TASK_WAITING) {
+ $this->taskStatus = Taskmanager::waitComplete($this->taskStatus['id']);
+ }
+
+ $sortIp = array();
+ foreach (array_keys($this->taskStatus['data']['addresses']) as $key) {
+ $item =& $this->taskStatus['data']['addresses'][$key];
+ if (!isset($item['ip'])
+ || !preg_match('/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/', $item['ip'])
+ || substr($item['ip'], 0, 4) === '127.') {
+ unset($this->taskStatus['data']['addresses'][$key]);
+ continue;
+ }
+ if ($this->currentAddress === $item['ip']) {
+ $item['default'] = true;
+ }
+ $sortIp[] = $item['ip'];
+ }
+ unset($item);
+ array_multisort($sortIp, SORT_STRING, $this->taskStatus['data']['addresses']);
+
+ if ($newAddress !== 'none') {
+ // New address is to be set - check if it is valid
+ $valid = false;
+ foreach ($this->taskStatus['data']['addresses'] as $item) {
+ if ($item['ip'] !== $newAddress) continue;
+ $valid = true;
+ break;
+ }
+ if ($valid) {
+ Property::setServerIp($newAddress);
+ } else {
+ Message::addError('invalid-ip', $newAddress);
+ }
+ Util::redirect();
+ }
+
+ }
+
+ protected function doRender()
+ {
+ Render::addTemplate('page-serversetup', array(
+ 'ips' => $this->taskStatus['data']['addresses'],
+ 'token' => Session::get('token')
+ ));
+ }
+} \ No newline at end of file
diff --git a/templates/main-menu.html b/templates/main-menu.html
index 733f901f..71800915 100644
--- a/templates/main-menu.html
+++ b/templates/main-menu.html
@@ -16,13 +16,14 @@
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Einstellungen<b class="caret"></b></a>
<ul class="dropdown-menu">
+ <li class="dropdown-header">Client</li>
<li><a href="?do=MiniLinux">MiniLinux</a></li>
<li><a href="?do=BaseConfig">KonfigurationsVariablen</a></li>
<li><a href="?do=SysConfig">SystemKonfiguration</a></li>
- <li><a href="?do=iPxe">iPXE</a></li>
<li class="divider"></li>
- <li class="dropdown-header">Nav header</li>
- <li><a href="#">1</a></li>
+ <li class="dropdown-header">Server</li>
+ <li><a href="?do=ServerSetup">Grundkonfiguration</a></li>
+ <li><a href="?do=iPxe">iPXE</a></li>
</ul>
</li>
</ul>
diff --git a/templates/page-serversetup.html b/templates/page-serversetup.html
new file mode 100644
index 00000000..2f900a03
--- /dev/null
+++ b/templates/page-serversetup.html
@@ -0,0 +1,30 @@
+<div class="panel panel-default">
+ <div class="panel-heading">
+ Boot-Adresse des Servers
+ </div>
+ <div class="panel-body">
+ <p>
+ Bitte wählen Sie die IP-Adresse, über die der Server von den Clients zum Booten angesprochen werden soll.
+ </p>
+ <form method="post">
+ <input type="hidden" name="token" value="{{token}}">
+ <table>
+ {{#ips}}
+ <tr>
+ <td>{{ip}}</td>
+ {{#default}}
+ <td>
+ <span class="btn btn-success btn-xs"><span class="glyphicon glyphicon-ok"></span> Aktiv</span>
+ </td>
+ {{/default}}
+ {{^default}}
+ <td>
+ <button class="btn btn-primary btn-xs" name="ip" value="{{ip}}"><span class="glyphicon glyphicon-flag"></span> Setzen</button>
+ </td>
+ {{/default}}
+ </tr>
+ {{/ips}}
+ </table>
+ </form>
+ </div>
+</div> \ No newline at end of file