diff options
| author | Jonathan Bauer | 2014-06-04 18:11:24 +0200 |
|---|---|---|
| committer | Jonathan Bauer | 2014-06-04 18:11:24 +0200 |
| commit | 9f14e302af77b5a8f72b4785e7376cc346519ef7 (patch) | |
| tree | aa3be844d8b879b3eab06793c4ae33ac0e6c233b | |
| parent | listing of module's content (diff) | |
| parent | Add RO-Credentials to CIFS VMStore (diff) | |
| download | slx-admin-9f14e302af77b5a8f72b4785e7376cc346519ef7.tar.gz slx-admin-9f14e302af77b5a8f72b4785e7376cc346519ef7.tar.xz slx-admin-9f14e302af77b5a8f72b4785e7376cc346519ef7.zip | |
Merge branch 'master' of git.openslx.org:openslx-ng/slx-admin
| -rw-r--r-- | apis/exec.inc.php | 80 | ||||
| -rw-r--r-- | apis/getconfig.inc.php | 19 | ||||
| -rw-r--r-- | apis/taskmanager.inc.php | 4 | ||||
| -rw-r--r-- | inc/message.inc.php | 20 | ||||
| -rw-r--r-- | inc/property.inc.php | 16 | ||||
| -rw-r--r-- | inc/trigger.inc.php | 2 | ||||
| -rw-r--r-- | modules/minilinux.inc.php | 21 | ||||
| -rw-r--r-- | modules/serversetup.inc.php | 2 | ||||
| -rw-r--r-- | modules/vmstore.inc.php | 2 | ||||
| -rw-r--r-- | script/taskmanager.js | 10 | ||||
| -rw-r--r-- | style/default.css | 6 | ||||
| -rw-r--r-- | templates/exec-error.html | 1 | ||||
| -rw-r--r-- | templates/exec-progress.html | 4 | ||||
| -rw-r--r-- | templates/helloworld.html | 5 | ||||
| -rw-r--r-- | templates/minilinux/filelist.html | 5 | ||||
| -rw-r--r-- | templates/page-vmstore.html | 32 |
16 files changed, 100 insertions, 129 deletions
diff --git a/apis/exec.inc.php b/apis/exec.inc.php deleted file mode 100644 index 60ca679f..00000000 --- a/apis/exec.inc.php +++ /dev/null @@ -1,80 +0,0 @@ -<?php - -User::load(); - -if (!User::hasPermission('superadmin')) die('No permission'); - -require_once('inc/render.inc.php'); - -error_log('**URI: '. $_SERVER['REQUEST_URI']); - -if (!isset($_REQUEST['id'])) die('No id'); -$id = $_REQUEST['id']; - -// Progress update only - -if (isset($_REQUEST['progress'])) { - $progress = preg_replace('/[^a-z0-9\-]/', '', $_REQUEST['progress']); - $pid = (isset($_REQUEST['pid']) ? (int)$_REQUEST['pid'] : 0); - $log = '/tmp/' . $progress . '.log'; - if (!file_exists($log)) { - echo Render::parse('exec-error'); - exit(0); - } - $lastLines = array(); - $fh = fopen($log, 'r'); - while (!feof($fh)) { - $line = fgets($fh); - $lastLines[] = $line; - if (count($lastLines) > 10) array_shift($lastLines); - } - fclose($fh); - $running = ($pid == 0 || posix_kill($pid, 0)); - echo Render::parse('exec-progress', array('progress' => $progress, 'id' => $id, 'pid' => $pid, 'running' => $running, 'text' => implode('', $lastLines))); - if (!$running) unlink($log); - exit(0); -} - -// Actual download request -// type ip id - -if (!isset($_REQUEST['type'])) die('No type'); - - -$type = $_REQUEST['type']; - -switch ($type) { -case 'ipxe': - if (!isset($_REQUEST['ip'])) die('No IP given'); - $ip = preg_replace('/[^0-9\.]/', '', $_REQUEST['ip']); - $default = $_REQUEST['default']; - if (!preg_match('/openslx|hddboot/', $default)) $default = 'openslx'; - $command = '/opt/openslx/build_ipxe.sh "' . CONFIG_IPXE_DIR . '/last-ip" "' . $ip . '"'; - $conf = Render::parse('txt-ipxeconfig', array( - 'SERVER' => $ip - )); - if (false === file_put_contents('/opt/openslx/ipxe/ipxelinux.ipxe', $conf)) die('Error writing iPXE Config'); - $conf = Render::parse('txt-pxeconfig', array( - 'SERVER' => $ip, - 'DEFAULT' => $default, - $default => 'MENU DEFAULT' - )); - if (false === file_put_contents(CONFIG_TFTP_DIR . '/pxelinux.cfg/default', $conf)) die('Error writing PXE Menu'); - Database::exec("INSERT IGNORE INTO setting_global (setting, value) VALUES ('SLX_VM_NFS', :value)", array(':value' => "$ip:/srv/openslx/nfs")); - Database::exec("UPDATE setting_global SET value = :value WHERE setting = 'SLX_VM_NFS' AND value LIKE '%:/srv/openslx/nfs' LIMIT 1", array(':value' => "$ip:/srv/openslx/nfs")); - break; -default: - die('Invalid exec type'); -} - -$logfile = 'slx-' . mt_rand() . '-' . time(); -error_log('**EXEC: ' . "$command '/tmp/${logfile}.log'"); -exec("$command '/tmp/${logfile}.log'", $retstr, $retval); -if ($retval != 0) { - echo Render::parse('exec-error', array('error' => implode(' // ', $retstr) . ' - ' . $retval)); - exit(0); -} -$pid = 0; -foreach ($retstr as $line) if (preg_match('/PID: (\d+)\./', $line, $out)) $pid = $out[1]; -echo Render::parse('exec-progress', array('progress' => $logfile, 'id' => $id, 'pid' => $pid, 'running' => true)); - diff --git a/apis/getconfig.inc.php b/apis/getconfig.inc.php index f29118c8..0a8db6be 100644 --- a/apis/getconfig.inc.php +++ b/apis/getconfig.inc.php @@ -1,6 +1,9 @@ <?php -require_once 'inc/property.inc.php'; +function escape($string) +{ + return str_replace("'", "\\'", $string); +} // Dump config from DB $res = Database::simpleQuery('SELECT setting.setting, setting.defaultvalue, setting.permissions, setting.description, tbl.value @@ -12,20 +15,24 @@ while ($row = $res->fetch(PDO::FETCH_ASSOC)) { echo $row['setting'] . "='" . str_replace("'", "'\"'\"'", $row['value']) . "'\n"; } // Additional "intelligent" config -echo "SLX_REMOTE_LOG='http://${_SERVER['SERVER_ADDR']}/slxadmin/api.php?do=clientlog'\n"; -$vmstore = Property::getVmStoreConfig(); +// Remote log URL +echo "SLX_REMOTE_LOG='http://" . escape($_SERVER['SERVER_ADDR']) . "/slxadmin/api.php?do=clientlog'\n"; +// VMStore path and type +$vmstore = Property::getVmStoreConfig(); if (is_array($vmstore)) { switch ($vmstore['storetype']) { case 'internal'; - echo "SLX_VM_NFS='{$_SERVER['SERVER_ADDR']}:/srv/openslx/nfs'\n"; + echo "SLX_VM_NFS='" . escape($_SERVER['SERVER_ADDR']) . ":/srv/openslx/nfs'\n"; break; case 'nfs'; - echo "SLX_VM_NFS='{$vmstore['nfsaddr']}'\n"; + echo "SLX_VM_NFS='" . escape($vmstore['nfsaddr']) . "'\n"; break; case 'cifs'; - echo "SLX_VM_NFS='{$vmstore['cifsaddr']}'\n"; + echo "SLX_VM_NFS='" . escape($vmstore['cifsaddr']) . "'\n"; + echo "SLX_VM_NFS_USER='" . escape($vmstore['cifsuserro']) . "'\n"; + echo "SLX_VM_NFS_PASSWD='" . escape($vmstore['cifspasswdro']) . "'\n"; break; } } diff --git a/apis/taskmanager.inc.php b/apis/taskmanager.inc.php index 7bb38a98..f7ee6ac1 100644 --- a/apis/taskmanager.inc.php +++ b/apis/taskmanager.inc.php @@ -20,10 +20,6 @@ foreach ($_POST['ids'] as $id) { && $id === Property::getIPxeTaskId() && Property::getServerIp() !== Property::getIPxeIp()) { Property::setIPxeIp(Property::getServerIp()); } - if (isset($status['statusCode']) && $status['statusCode'] === TASK_FINISHED // MiniLinux Version check - && $id === Property::getVersionCheckTaskId()) { - Property::setVersionCheckInformation(Property::getServerIp()); - } // -- END HACKS -- if (!isset($status['statusCode']) || ($status['statusCode'] !== TASK_WAITING && $status['statusCode'] !== TASK_PROCESSING)) { Taskmanager::release($id); diff --git a/inc/message.inc.php b/inc/message.inc.php index b62f234f..9405457d 100644 --- a/inc/message.inc.php +++ b/inc/message.inc.php @@ -108,6 +108,26 @@ class Message } /** + * Get all queued messages, flushing the queue. + * Useful in api/ajax mode. + */ + public static function asString() + { + global $error_text; + $return = ''; + foreach (self::$list as $item) { + $message = $error_text[$item['id']]; + foreach ($item['params'] as $index => $text) { + $message = str_replace('{{' . $index . '}}', $text, $message); + } + $return .= '[' . $item['type'] . ']: ' . $message . "\n"; + self::$alreadyDisplayed[] = $item; + } + self::$list = array(); + return $return; + } + + /** * Deserialize any messages from the current HTTP request and * place them in the message queue. */ diff --git a/inc/property.inc.php b/inc/property.inc.php index 77d2b985..d62bbcb9 100644 --- a/inc/property.inc.php +++ b/inc/property.inc.php @@ -45,7 +45,7 @@ class Property . " ON DUPLICATE KEY UPDATE value = VALUES(value), dateline = VALUES(dateline)", array( 'key' => $key, 'value' => $value, - 'dateline' => time() + ($minage * 60) + 'dateline' => ($minage === 0 ? 0 : time() + ($minage * 60)) )); if (self::$cache !== false) { self::$cache[$key] = $value; @@ -111,7 +111,7 @@ class Property 'url' => CONFIG_REMOTE_ML . '/list.php' )); if (!isset($task['id'])) - return false; + return 'Could not start list download (' . Message::asString() . ')'; if ($task['statusCode'] !== TASK_FINISHED) { $task = Taskmanager::waitComplete($task['id']); } @@ -126,7 +126,7 @@ class Property public static function setVersionCheckInformation($value) { - self::set('versioncheck-data', json_encode($value)); + self::set('versioncheck-data', json_encode($value), 1); } public static function getVmStoreConfig() @@ -139,4 +139,14 @@ class Property self::set('vmstore-config', json_encode($value)); } + public static function getDownloadTask($name) + { + return self::get('dl-' . $name); + } + + public static function setDownloadTask($name, $taskId) + { + self::set('dl-' . $name, $taskId, 5); + } + } diff --git a/inc/trigger.inc.php b/inc/trigger.inc.php index b7cc67cc..c22f8c5b 100644 --- a/inc/trigger.inc.php +++ b/inc/trigger.inc.php @@ -67,7 +67,7 @@ class Trigger if ($storetype === 'nfs') $addr = $vmstore['nfsaddr']; if ($storetype === 'cifs') $addr = $vmstore['cifsaddr']; if ($storetype === 'internal') $addr = 'none'; - $this->mountTask = Taskmanager::submit('MountVmStore', array( + return Taskmanager::submit('MountVmStore', array( 'address' => $addr, 'type' => 'images', 'username' => $vmstore['cifsuser'], diff --git a/modules/minilinux.inc.php b/modules/minilinux.inc.php index f3fb6dce..f947ef41 100644 --- a/modules/minilinux.inc.php +++ b/modules/minilinux.inc.php @@ -40,6 +40,16 @@ class Page_MiniLinux extends Page if (!file_exists($local) || filesize($local) !== $file['size'] || md5_file($local) !== substr($file['md5'], 0, 32)) { $file['changed'] = true; } + $taskId = Property::getDownloadTask($file['md5']); + if ($taskId !== false) { + $task = Taskmanager::status($taskId); + if (isset($task['data']['progress'])) { + $file['download'] = Render::parse('minilinux/download', array( + 'task' => $taskId, + 'name' => $file['name'] + )); + } + } } } echo Render::parse('minilinux/filelist', array( @@ -54,16 +64,16 @@ class Page_MiniLinux extends Page echo "Invalid download request"; return; } - $found = false; + $file = false; foreach ($data['systems'] as &$system) { if ($system['id'] !== $id) continue; - foreach ($system['files'] as &$file) { - if ($file['name'] !== $name) continue; - $found = true; + foreach ($system['files'] as &$f) { + if ($f['name'] !== $name) continue; + $file = $f; break; } } - if (!$found) { + if ($file === false) { echo "Nonexistent system/file: $id / $name"; return; } @@ -75,6 +85,7 @@ class Page_MiniLinux extends Page echo 'Error launching download task: ' . $task['statusCode']; return; } + Property::setDownloadTask($file['md5'], $task['id']); echo Render::parse('minilinux/download', array( 'name' => $name, 'task' => $task['id'] diff --git a/modules/serversetup.inc.php b/modules/serversetup.inc.php index 73a1a8fc..46a8fb4e 100644 --- a/modules/serversetup.inc.php +++ b/modules/serversetup.inc.php @@ -48,6 +48,8 @@ class Page_ServerSetup extends Page $data = $this->currentMenu; $data['token'] = Session::get('token'); $data['taskid'] = Property::getIPxeTaskId(); + if (!isset($data['defaultentry'])) + $data['defaultentry'] = 'net'; if ($data['defaultentry'] === 'net') $data['active-net'] = 'checked'; if ($data['defaultentry'] === 'hdd') diff --git a/modules/vmstore.inc.php b/modules/vmstore.inc.php index a8f2ec48..602ab258 100644 --- a/modules/vmstore.inc.php +++ b/modules/vmstore.inc.php @@ -39,7 +39,7 @@ class Page_VmStore extends Page private function setStore() { - foreach (array('storetype', 'nfsaddr', 'cifsaddr', 'cifsuser', 'cifspasswd') as $key) { + foreach (array('storetype', 'nfsaddr', 'cifsaddr', 'cifsuser', 'cifspasswd', 'cifsuserro', 'cifspasswdro') as $key) { $vmstore[$key] = trim(Request::post($key, '')); } $storetype = $vmstore['storetype']; diff --git a/script/taskmanager.js b/script/taskmanager.js index 822d1421..c2305a2b 100644 --- a/script/taskmanager.js +++ b/script/taskmanager.js @@ -20,8 +20,9 @@ function tmInit() } item.prepend('<span class="data-tm-icon" />'); }); - if (!tmIsRunning) + if (!tmIsRunning) { setTimeout(tmUpdate, 50); + } tmIsRunning = true; } @@ -35,8 +36,10 @@ function tmUpdate() return; active.push(id); }); - if (active.length === 0) + if (active.length === 0) { + tmIsRunning = false; return; + } $.post('api.php?do=taskmanager', {'ids[]': active, token: TOKEN}, function(data, status) { // POST success tmIsRunning = tmResult(data, status); @@ -47,8 +50,9 @@ function tmUpdate() // POST failure console.log("TaskManager Error: " + textStatus + " - " + errorThrown); tmIsRunning = (++tmErrors < TM_MAX_ERRORS); - if (tmIsRunning) + if (tmIsRunning) { setTimeout(tmUpdate, 2000); + } }); } diff --git a/style/default.css b/style/default.css index 3e5f1a56..813e54c2 100644 --- a/style/default.css +++ b/style/default.css @@ -98,4 +98,8 @@ body { .input-group { margin-bottom: 2px; -}
\ No newline at end of file +} + +.slx-md-width { + max-width: 600px; +} diff --git a/templates/exec-error.html b/templates/exec-error.html deleted file mode 100644 index 0a82e1df..00000000 --- a/templates/exec-error.html +++ /dev/null @@ -1 +0,0 @@ -<div class="alert alert-danger"><p>Ausführung fehlgeschlagen!</p>{{error}}</div> diff --git a/templates/exec-progress.html b/templates/exec-progress.html deleted file mode 100644 index 0583a74a..00000000 --- a/templates/exec-progress.html +++ /dev/null @@ -1,4 +0,0 @@ -<div class="well well-sm"> - <pre>{{text}}</pre> - {{#running}}<script> setTimeout(function() { $('#{{id}}').load('api.php?do=exec&progress={{progress}}&id={{id}}&pid={{pid}}'); }, 2000); // </script>{{/running}} -</div> diff --git a/templates/helloworld.html b/templates/helloworld.html deleted file mode 100644 index 752f1e83..00000000 --- a/templates/helloworld.html +++ /dev/null @@ -1,5 +0,0 @@ -<div> - Hello World!<br /> - Variable wurst set to {{wurst}} -</div> - diff --git a/templates/minilinux/filelist.html b/templates/minilinux/filelist.html index abb28aad..fdc3f14e 100644 --- a/templates/minilinux/filelist.html +++ b/templates/minilinux/filelist.html @@ -10,7 +10,9 @@ {{#files}} <li class="list-group-item" id="{{uid}}"> {{name}} - {{#changed}}<span class="btn btn-primary btn-sm" onclick="slxUpdate('{{uid}}', '{{id}}', '{{name}}')">Aktualisieren</span>{{/changed}} + {{#changed}}<span class="btn btn-success btn-sm" onclick="slxUpdate('{{uid}}', '{{id}}', '{{name}}')">Aktualisieren</span>{{/changed}} + {{^changed}}<span class="btn btn-default btn-sm" onclick="slxUpdate('{{uid}}', '{{id}}', '{{name}}')">Erneut herunterladen</span>{{/changed}} + {{{download}}} </li> {{/files}} </ul> @@ -36,4 +38,5 @@ function slxUpdate(uid, id, name) } }); } +tmInit(); </script>
\ No newline at end of file diff --git a/templates/page-vmstore.html b/templates/page-vmstore.html index 8732276f..1dde2734 100644 --- a/templates/page-vmstore.html +++ b/templates/page-vmstore.html @@ -6,7 +6,7 @@ <div class="panel-heading"> VM Speicherort <a class="btn btn-default" data-toggle="modal" data-target="#help-store"><span class="glyphicon glyphicon-question-sign"></span></a> </div> - <div class="panel-body"> + <div class="panel-body slx-md-width"> <p>Bitte wählen Sie, wo die Images der Virtuellen Maschinen gespeichert werden sollen.</p> <div class="panel panel-default"> <div class="panel-heading"> @@ -21,12 +21,8 @@ <input type="radio" name="storetype" value="nfs" {{pre-nfs}}> NFS </div> <div class="panel-body"> - <div class="input-group"> - <span class="input-group-addon slx-ga"> - NFS-Export - </span> - <input type="text" class="form-control" name="nfsaddr" value="{{nfsaddr}}" placeholder="1.2.3.4:/export/bwlp"> - </div> + <label for="nfsaddr">NFS-Export</label> + <input type="text" class="form-control" name="nfsaddr" value="{{nfsaddr}}" placeholder="1.2.3.4:/export/bwlp" id="nfsaddr"> </div> </div> <div class="panel panel-default"> @@ -34,23 +30,31 @@ <input type="radio" name="storetype" value="cifs" {{pre-cifs}}> CIFS </div> <div class="panel-body"> + <label for="cifsaddr">UNC-Pfad</label> + <input type="text" class="form-control" name="cifsaddr" value="{{cifsaddr}}" placeholder="\\samba.server.example.com\bwlp" id="cifsaddr"> + <br> + <label for="cifsuser">Lese/Schreib-Zugangsdaten</label> <div class="input-group"> <span class="input-group-addon slx-ga"> - UNC-Pfad + Benutzername + </span> + <input type="text" class="form-control" name="cifsuser" value="{{cifsuser}}" placeholder="Benutzername" id="cifsuser"> + <span class="input-group-addon"> + Passwort </span> - <input type="text" class="form-control" name="cifsaddr" value="{{cifsaddr}}" placeholder="\\samba.server.example.com\bwlp"> + <input type="text" class="form-control" name="cifspasswd" value="{{cifspasswd}}" placeholder="Passwort"> </div> + <br> + <label for="cifsuserro">Nur-Lese-Zugangsdaten</label> <div class="input-group"> <span class="input-group-addon slx-ga"> Benutzername </span> - <input type="text" class="form-control" name="cifsuser" value="{{cifsuser}}" placeholder="Benutzername"> - </div> - <div class="input-group"> - <span class="input-group-addon slx-ga"> + <input type="text" class="form-control" name="cifsuserro" value="{{cifsuserro}}" placeholder="Benutzername" id="cifsuserro"> + <span class="input-group-addon"> Passwort </span> - <input type="text" class="form-control" name="cifspasswd" value="{{cifspasswd}}" placeholder="Passwort"> + <input type="text" class="form-control" name="cifspasswdro" value="{{cifspasswdro}}" placeholder="Passwort"> </div> </div> </div> |
