From a4f4147b6fe5f2a003a61cf8a8f7508c94130b31 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Mon, 26 May 2014 22:49:54 +0200 Subject: WIP --- modules/minilinux.inc.php | 73 +++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 64 insertions(+), 9 deletions(-) (limited to 'modules/minilinux.inc.php') 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) { -- cgit v1.2.3-55-g7522