From f800abeea4f6c68182c51cd4aaea19d7636431c8 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Wed, 9 Oct 2019 17:31:19 +0200 Subject: [minilinux] Rewrite for multiple version/sources handling * You can supply multiple sources for updates (URLs) * Sources can provide multiple branches * Each branch can supply multiple versions (eg. updates) TODO: Set global default version TODO: Supply hook to serversetup-ipxe to add specific boot entries TODO: UX polish TODO: phpdoc/polish --- inc/property.inc.php | 42 ----------------------------------------- inc/taskmanager.inc.php | 16 ++++++++++++++++ inc/taskmanagercallback.inc.php | 9 +++++++++ 3 files changed, 25 insertions(+), 42 deletions(-) (limited to 'inc') diff --git a/inc/property.inc.php b/inc/property.inc.php index b69be1f8..3911b0d4 100644 --- a/inc/property.inc.php +++ b/inc/property.inc.php @@ -145,43 +145,6 @@ class Property self::set('ipxe-menu', json_encode($value)); } - public static function getVersionCheckTaskId() - { - return self::get('versioncheck-task'); - } - - public static function setVersionCheckTaskId($value) - { - self::set('versioncheck-task', $value); - } - - public static function getVersionCheckInformation() - { - $data = json_decode(self::get('versioncheck-data', '[]'), true); - if (isset($data['time']) && $data['time'] + 60 > time()) - return $data; - $task = Taskmanager::submit('DownloadText', array( - 'url' => CONFIG_REMOTE_ML . '/list.php' - )); - if (!isset($task['id'])) - return 'Could not start list download (' . Message::asString() . ')'; - if (!Taskmanager::isFinished($task)) { - $task = Taskmanager::waitComplete($task['id'], 5000); - } - if ($task['statusCode'] !== Taskmanager::TASK_FINISHED || !isset($task['data']['content'])) { - return isset($task['data']['error']) ? $task['data']['error'] : 'Timeout'; - } - $data = json_decode($task['data']['content'], true); - $data['time'] = time(); - self::setVersionCheckInformation($data); - return $data; - } - - public static function setVersionCheckInformation($value) - { - self::set('versioncheck-data', json_encode($value), 1); - } - public static function getVmStoreConfig() { return json_decode(self::get('vmstore-config'), true); @@ -251,9 +214,4 @@ class Property return self::get('password-type', 'password'); } - public static function getIpxeDefault() - { - return self::get('default-ipxe'); - } - } diff --git a/inc/taskmanager.inc.php b/inc/taskmanager.inc.php index 8fe70d00..547a75d4 100644 --- a/inc/taskmanager.inc.php +++ b/inc/taskmanager.inc.php @@ -175,6 +175,22 @@ class Taskmanager return false; } + /** + * Check whether the given task is running, that is either waiting for execution + * or currently executing. + * + * @param array $task struct representing task, obtained by ::status + * @return boolean true if task is waiting or executing, false if waiting for execution or currently executing, no valid task, etc. + */ + public static function isRunning($task) + { + if (!is_array($task) || !isset($task['statusCode']) || !isset($task['id'])) + return false; + if ($task['statusCode'] === Taskmanager::TASK_WAITING || $task['statusCode'] === Taskmanager::TASK_PROCESSING) + return true; + return false; + } + public static function addErrorMessage($task) { static $failure = false; diff --git a/inc/taskmanagercallback.inc.php b/inc/taskmanagercallback.inc.php index 8e253962..d1152bfd 100644 --- a/inc/taskmanagercallback.inc.php +++ b/inc/taskmanagercallback.inc.php @@ -184,6 +184,15 @@ class TaskmanagerCallback } } + public static function mlDownload($task, $args) + { + $mod = Module::get('minilinux'); + if ($mod === false) + return; + $mod->activate(1, false); + MiniLinux::listDownloadCallback($task, $args); + } + public static function uploadimg($task) { //$string=var_export($task, true); -- cgit v1.2.3-55-g7522