summaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorSimon Rettberg2014-05-26 22:49:54 +0200
committerSimon Rettberg2014-05-26 22:49:54 +0200
commita4f4147b6fe5f2a003a61cf8a8f7508c94130b31 (patch)
treede34472a2b9bd83909469affb884619b4858efc1 /modules
parentWIP (diff)
downloadslx-admin-a4f4147b6fe5f2a003a61cf8a8f7508c94130b31.tar.gz
slx-admin-a4f4147b6fe5f2a003a61cf8a8f7508c94130b31.tar.xz
slx-admin-a4f4147b6fe5f2a003a61cf8a8f7508c94130b31.zip
WIP
Diffstat (limited to 'modules')
-rw-r--r--modules/main.inc.php9
-rw-r--r--modules/minilinux.inc.php73
-rw-r--r--modules/sysconfig.inc.php1
-rw-r--r--modules/vmstore.inc.php72
4 files changed, 145 insertions, 10 deletions
diff --git a/modules/main.inc.php b/modules/main.inc.php
index ddbc37a4..232d6a0a 100644
--- a/modules/main.inc.php
+++ b/modules/main.inc.php
@@ -20,7 +20,14 @@ class Page_Main extends Page
$ipxe = (Property::getServerIp() !== Property::getIPxeIp());
$sysconfig = !file_exists(CONFIG_HTTP_DIR . '/default/config.tgz');
$minilinux = !file_exists(CONFIG_HTTP_DIR . '/default/kernel') || !file_exists(CONFIG_HTTP_DIR . '/default/initramfs-stage31') || !file_exists(CONFIG_HTTP_DIR . '/default/stage32.sqfs');
- Render::addTemplate('page-main', array('user' => User::getName(), 'ipxe' => $ipxe, 'sysconfig' => $sysconfig, 'minilinux' => $minilinux));
+ $vmstore = !is_array(Property::getVmStoreConfig());
+ Render::addTemplate('page-main', array(
+ 'user' => User::getName(),
+ 'ipxe' => $ipxe,
+ 'sysconfig' => $sysconfig,
+ 'minilinux' => $minilinux,
+ 'vmstore' => $vmstore
+ ));
}
}
diff --git a/modules/minilinux.inc.php b/modules/minilinux.inc.php
index 6e68a34e..e2d85247 100644
--- a/modules/minilinux.inc.php
+++ b/modules/minilinux.inc.php
@@ -15,18 +15,73 @@ class Page_MiniLinux extends Page
protected function doRender()
{
- $files = array();
- mkdir(CONFIG_HTTP_DIR . "/default", 0755, true);
- $this->checkFile($files, 'kernel');
- $this->checkFile($files, 'initramfs-stage31');
- $this->checkFile($files, 'stage32.sqfs');
- $this->checkFile($files, 'vmware.sqfs');
- $this->checkFile($files, 'nvidia_libs.sqfs');
Render::addTemplate('page-minilinux', array(
- 'files' => $files,
- 'token' => Session::get('token')
+ 'listurl' => '?do=MiniLinux&async=true&action=list'
));
}
+
+ protected function doAjax()
+ {
+ $data = Property::getVersionCheckInformation();
+ if (!is_array($data) || !isset($data['systems'])) {
+ echo Render::parse('messagebox-error', array(
+ 'message' => 'Fehler beim Abrufen der Liste: ' . $data
+ ));
+ return;
+ }
+ $action = Request::any('action');
+ switch ($action) {
+ case 'list':
+ $count = 0;
+ foreach ($data['systems'] as &$system) {
+ foreach ($system['files'] as &$file) {
+ $file['uid'] = 'dlid' . $count++;
+ $local = CONFIG_HTTP_DIR . '/' . $system['id'] . '/' . $file['name'];
+ if (!file_exists($local) || md5_file($local) !== substr($file['md5'], 0, 32)) {
+ $file['changed'] = true;
+ }
+ }
+ }
+ echo Render::parse('minilinux/filelist', array(
+ 'systems' => $data['systems'],
+ 'token' => Session::get('token')
+ ));
+ return;
+ case 'download':
+ $id = Request::post('id');
+ $name = Request::post('name');
+ if (!$id || !$name || strpos("$id$name", '/') !== false) {
+ echo "Invalid download request";
+ return;
+ }
+ $found = false;
+ foreach ($data['systems'] as &$system) {
+ if ($system['id'] !== $id) continue;
+ foreach ($system['files'] as &$file) {
+ if ($file['name'] !== $name) continue;
+ $found = true;
+ break;
+ }
+ }
+ if (!$found) {
+ echo "Nonexistent system/file: $id / $name";
+ return;
+ }
+ $task = Taskmanager::submit('DownloadFile', array(
+ 'url' => CONFIG_REMOTE_ML . '/' . $id . '/' . $name,
+ 'destination' => CONFIG_HTTP_DIR . '/' . $id . '/' . $name
+ ));
+ if (!isset($task['id'])) {
+ echo 'Error launching download task: ' . $task['statusCode'];
+ return;
+ }
+ echo Render::parse('minilinux/download', array(
+ 'name' => $name,
+ 'task' => $task['id']
+ ));
+ return;
+ }
+ }
private function checkFile(&$files, $name)
{
diff --git a/modules/sysconfig.inc.php b/modules/sysconfig.inc.php
index ebccf036..06ceb618 100644
--- a/modules/sysconfig.inc.php
+++ b/modules/sysconfig.inc.php
@@ -119,6 +119,7 @@ class Page_SysConfig extends Page
Message::addError('task-error', $task['data']['error']);
} elseif ($task['statusCode'] === TASK_FINISHED) {
Message::addSuccess('config-activated', $row['title']);
+ Trigger::ldadp(); // TODO: Feedback
}
Util::redirect('?do=SysConfig');
}
diff --git a/modules/vmstore.inc.php b/modules/vmstore.inc.php
new file mode 100644
index 00000000..ab06b1af
--- /dev/null
+++ b/modules/vmstore.inc.php
@@ -0,0 +1,72 @@
+<?php
+
+class Page_VmStore extends Page
+{
+ private $mountTask = false;
+
+ protected function doPreprocess()
+ {
+ User::load();
+
+ if (!User::hasPermission('superadmin')) {
+ Message::addError('no-permission');
+ Util::redirect('?do=Main');
+ }
+
+ $action = Request::post('action');
+
+ if ($action === 'setstore') {
+ $this->setStore();
+ }
+ }
+
+ protected function doRender()
+ {
+ $action = Request::post('action');
+ if ($action === 'setstore' && !Taskmanager::isFailed($this->mountTask)) {
+ Render::addTemplate('vmstore/mount', array(
+ 'task' => $this->mountTask['id']
+ ));
+ return;
+ }
+ $vmstore = Property::getVmStoreConfig();
+ if (isset($vmstore['storetype'])) {
+ $vmstore['pre-' . $vmstore['storetype']] = 'checked';
+ }
+ $vmstore['token'] = Session::get('token');
+ Render::addTemplate('page-vmstore', $vmstore);
+ }
+
+ private function setStore()
+ {
+ foreach (array('storetype', 'nfsaddr', 'cifsaddr', 'cifsuser', 'cifspasswd') as $key) {
+ $vmstore[$key] = trim(Request::post($key, ''));
+ }
+ $storetype = $vmstore['storetype'];
+ if (!in_array($storetype, array('internal', 'nfs', 'cifs'))) {
+ Message::addError('value-invalid', 'type', $storetype);
+ Util::redirect('?do=VmStore');
+ }
+ // Validate syntax of nfs/cifs
+ if ($storetype === 'nfs' && !preg_match('#^\S+:\S+$#is', $vmstore['nfsaddr'])) {
+ Message::addError('value-invalid', 'nfsaddr', $vmstore['nfsaddr']);
+ Util::redirect('?do=VmStore');
+ }
+ $vmstore['cifsaddr'] = str_replace('\\', '/', $vmstore['cifsaddr']);
+ if ($storetype === 'cifs' && !preg_match('#^//\S+/.+$#is', $vmstore['cifsaddr'])) {
+ Message::addError('value-invalid', 'nfsaddr', $vmstore['nfsaddr']);
+ Util::redirect('?do=VmStore');
+ }
+ if ($storetype === 'nfs') $addr = $vmstore['nfsaddr'];
+ if ($storetype === 'cifs') $addr = $vmstore['nfsaddr'];
+ if ($storetype === 'internal') $addr = 'none';
+ $this->mountTask = Taskmanager::submit('MountVmStore', array(
+ 'address' => $addr,
+ 'type' => 'images',
+ 'username' => $vmstore['cifsuser'],
+ 'password' => $vmstore['cifspasswd']
+ ));
+ Property::setVmStoreConfig($vmstore);
+ }
+
+} \ No newline at end of file