summaryrefslogtreecommitdiffstats
path: root/modules/minilinux.inc.php
diff options
context:
space:
mode:
authorSimon Rettberg2013-11-16 15:42:16 +0100
committerSimon Rettberg2013-11-16 15:42:16 +0100
commit633e43127c6d1a96d47587eed2739bdaff6c3d4f (patch)
treeafe22b5cef77a5a054388d05f6a2c106dcb4d60b /modules/minilinux.inc.php
parentAdd custom config.tgz upload functionality (diff)
downloadslx-admin-633e43127c6d1a96d47587eed2739bdaff6c3d4f.tar.gz
slx-admin-633e43127c6d1a96d47587eed2739bdaff6c3d4f.tar.xz
slx-admin-633e43127c6d1a96d47587eed2739bdaff6c3d4f.zip
Add minilinux download functionality and ipxe compilation scripts
Diffstat (limited to 'modules/minilinux.inc.php')
-rw-r--r--modules/minilinux.inc.php86
1 files changed, 86 insertions, 0 deletions
diff --git a/modules/minilinux.inc.php b/modules/minilinux.inc.php
new file mode 100644
index 00000000..3508fb43
--- /dev/null
+++ b/modules/minilinux.inc.php
@@ -0,0 +1,86 @@
+<?php
+
+User::load();
+
+if (!User::hasPermission('superadmin')) {
+ Message::addError('no-permission');
+ Util::redirect('?do=main');
+}
+
+function render_module()
+{
+ $files = array();
+ checkFile($files, 'kernel');
+ checkFile($files, 'initramfs-stage31');
+ checkFile($files, 'stage32.sqfs');
+ checkFile($files, 'vmware.sqfs');
+ Render::addTemplate('page-minilinux', array('files' => $files, 'token' => Session::get('token')));
+}
+
+function checkFile(&$files, $name)
+{
+ static $someId = 0;
+ $remote = CONFIG_REMOTE_ML . "/${name}.md5";
+ $localTarget = CONFIG_HTTP_DIR . "/default/${name}";
+ $local = "${localTarget}.md5";
+ $localLock = "${localTarget}.lck";
+
+ // Maybe already in progress?
+ if (file_exists($localLock)) {
+ $data = explode(' ', file_get_contents($localLock));
+ if (count($data) == 2) {
+ $pid = (int)$data[0];
+ if (posix_kill($pid, 0)) {
+ $files[] = array(
+ 'file' => $name,
+ 'id' => 'id' . $someId++,
+ 'pid' => $pid,
+ 'progress' => $data[1]
+ );
+ return true;
+ } else {
+ unlink($localLock);
+ }
+ } else {
+ unlink($localLock);
+ }
+ }
+
+ // Not in progress, normal display
+ if (!file_exists($local) || filemtime($local) + 300 < time()) {
+ if (file_exists($localTarget)) {
+ $existingMd5 = md5_file($localTarget);
+ } else {
+ $existingMd5 = '<missing>';
+ }
+ if (file_put_contents($local, $existingMd5) === false) {
+ @unlink($local);
+ Message::addWarning('error-write', $local);
+ }
+ } else {
+ $existingMd5 = file_get_contents($local);
+ }
+ $existingMd5 = strtolower(preg_replace('/[^0-9a-f]/is', '', $existingMd5));
+ $remoteMd5 = Util::download($remote, 3, $code);
+ $remoteMd5 = strtolower(preg_replace('/[^0-9a-f]/is', '', $existingMd5));
+ if ($code != 200) {
+ Message::addError('remote-timeout', $remote);
+ return false;
+ }
+ if ($existingMd5 === $remoteMd5) {
+ // Up to date
+ $files[] = array(
+ 'file' => $name,
+ 'id' => 'id' . $someId++,
+ );
+ return true;
+ }
+ // New version on server
+ $files[] = array(
+ 'file' => $name,
+ 'id' => 'id' . $someId++,
+ 'update' => true
+ );
+ return true;
+}
+