diff options
author | Simon Rettberg | 2016-05-03 19:03:09 +0200 |
---|---|---|
committer | Simon Rettberg | 2016-05-03 19:03:09 +0200 |
commit | 50404f3b23b7fd6aeae4c9d2f6df0ea25e984e66 (patch) | |
tree | 05e99fdffa696434960d7c77966c0bc36d6339e8 /modules-available/minilinux/page.inc.php | |
parent | Second half of merge.... (diff) | |
download | slx-admin-50404f3b23b7fd6aeae4c9d2f6df0ea25e984e66.tar.gz slx-admin-50404f3b23b7fd6aeae4c9d2f6df0ea25e984e66.tar.xz slx-admin-50404f3b23b7fd6aeae4c9d2f6df0ea25e984e66.zip |
WIP
Diffstat (limited to 'modules-available/minilinux/page.inc.php')
-rw-r--r-- | modules-available/minilinux/page.inc.php | 128 |
1 files changed, 128 insertions, 0 deletions
diff --git a/modules-available/minilinux/page.inc.php b/modules-available/minilinux/page.inc.php new file mode 100644 index 00000000..91be456e --- /dev/null +++ b/modules-available/minilinux/page.inc.php @@ -0,0 +1,128 @@ +<?php + +class Page_MiniLinux extends Page +{ + + protected function doPreprocess() + { + User::load(); + + if (!User::hasPermission('superadmin')) { + Message::addError('no-permission'); + Util::redirect('?do=Main'); + } + } + + protected function doRender() + { + Render::addTemplate('page-minilinux', array( + 'listurl' => '?do=MiniLinux&async=true&action=list' + )); + Render::addFooter('<script> $(window).load(function (e) { + loadSystemList(0); + }); // </script>'); + } + + protected function doAjax() + { + $data = Property::getVersionCheckInformation(); + if (!is_array($data) || !isset($data['systems'])) { + echo Render::parse('messagebox-error', array( + 'message' => 'Failed to retrieve the list: ' . print_r($data, true) + ),'main'); + return; + } + $action = Request::any('action'); + $selectedVersion = (int)Request::any('version', 0); + switch ($action) { + case 'list': + $count = 0; + foreach ($data['systems'] as &$system) { + // Get latest version, build simple array of all version numbers + $versionNumbers = array(); + $selected = false; + foreach ($system['versions'] as $version) { + if (!is_numeric($version['version']) || $version['version'] < 1) + continue; + if ($selectedVersion === 0 && ($selected === false || $selected['version'] < $version['version'])) + $selected = $version; + elseif ($version['version'] == $selectedVersion) + $selected = $version; + $versionNumbers[(int)$version['version']] = array( + 'version' => $version['version'] + ); + } + if ($selected === false) continue; // No versions for this system!? + ksort($versionNumbers); + // Mark latest version as selected + $versionNumbers[(int)$selected['version']]['selected'] = true; + // Add status information to system and its files + foreach ($selected['files'] as &$file) { + $file['uid'] = 'dlid' . $count++; + $local = CONFIG_HTTP_DIR . '/' . $system['id'] . '/' . $file['name']; + if (!file_exists($local) || filesize($local) !== $file['size'] || filemtime($local) < $file['mtime']) { + $file['fileChanged'] = true; + $system['systemChanged'] = true; + } + $taskId = Property::getDownloadTask($file['md5']); + if ($taskId !== false) { + $task = Taskmanager::status($taskId); + if (isset($task['data']['progress'])) { + $file['download'] = Render::parse('download', array( + 'task' => $taskId, + 'name' => $file['name'] + )); + } + } + } + unset($system['versions']); + $system['files'] = $selected['files']; + $system['version'] = $selected['version']; + } + $data['versions'] = array_values($versionNumbers); + echo Render::parse('filelist', $data); + return; + case 'download': + $id = Request::post('id'); + $name = Request::post('name'); + if (!$id || !$name || strpos("$id$name", '/') !== false) { + echo "Invalid download request"; + return; + } + $file = false; + $gpg = 'missing'; + foreach ($data['systems'] as &$system) { + if ($system['id'] !== $id) continue; + foreach ($system['versions'] as &$version) { + if ($version['version'] != $selectedVersion) continue; + foreach ($version['files'] as &$f) { + if ($f['name'] !== $name) continue; + $file = $f; + if (!empty($f['gpg'])) $gpg = $f['gpg']; + break; + } + } + } + if ($file === false) { + echo "Nonexistent system/file: $id / $name"; + return; + } + $task = Taskmanager::submit('DownloadFile', array( + 'url' => CONFIG_REMOTE_ML . '/' . $id . '/' . $selectedVersion . '/' . $name, + 'destination' => CONFIG_HTTP_DIR . '/' . $id . '/' . $name, + 'gpg' => $gpg + )); + if (!isset($task['id'])) { + echo 'Error launching download task: ' . $task['statusCode']; + return; + } + Property::setDownloadTask($file['md5'], $task['id']); + echo Render::parse('download', array( + 'name' => $name, + 'task' => $task['id'] + )); + return; + } + } + +} |