summaryrefslogtreecommitdiffstats
path: root/modules/minilinux.inc.php
diff options
context:
space:
mode:
authorSimon Rettberg2014-05-19 15:30:59 +0200
committerSimon Rettberg2014-05-19 15:30:59 +0200
commitf6ceaa03052e6878afd53a4bbb7f4429849fe25a (patch)
tree9f5582c8c275494728f6d6dcf656479714688934 /modules/minilinux.inc.php
parentWorking on config.tgz composition through config modules (diff)
downloadslx-admin-f6ceaa03052e6878afd53a4bbb7f4429849fe25a.tar.gz
slx-admin-f6ceaa03052e6878afd53a4bbb7f4429849fe25a.tar.xz
slx-admin-f6ceaa03052e6878afd53a4bbb7f4429849fe25a.zip
OO style modules
Diffstat (limited to 'modules/minilinux.inc.php')
-rw-r--r--modules/minilinux.inc.php153
1 files changed, 81 insertions, 72 deletions
diff --git a/modules/minilinux.inc.php b/modules/minilinux.inc.php
index 72af0eb4..6e68a34e 100644
--- a/modules/minilinux.inc.php
+++ b/modules/minilinux.inc.php
@@ -1,88 +1,97 @@
<?php
-User::load();
+class Page_MiniLinux extends Page
+{
-if (!User::hasPermission('superadmin')) {
- Message::addError('no-permission');
- Util::redirect('?do=main');
-}
+ protected function doPreprocess()
+ {
+ User::load();
-function render_module()
-{
- $files = array();
- mkdir(CONFIG_HTTP_DIR . "/default", 0755, true);
- checkFile($files, 'kernel');
- checkFile($files, 'initramfs-stage31');
- checkFile($files, 'stage32.sqfs');
- checkFile($files, 'vmware.sqfs');
- checkFile($files, 'nvidia_libs.sqfs');
- Render::addTemplate('page-minilinux', array('files' => $files, 'token' => Session::get('token')));
-}
+ if (!User::hasPermission('superadmin')) {
+ Message::addError('no-permission');
+ Util::redirect('?do=Main');
+ }
+ }
-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";
+ 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')
+ ));
+ }
- // 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 {
+ private 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);
- }
- } else {
- unlink($localLock);
- }
- }
+ }
+ }
- // Not in progress, normal display
- if (!file_exists($local) || filemtime($local) + 300 < time()) {
- if (file_exists($localTarget)) {
- $existingMd5 = md5_file($localTarget);
+ // 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 = '<missing>';
+ $existingMd5 = file_get_contents($local);
}
- if (file_put_contents($local, $existingMd5) === false) {
- @unlink($local);
- Message::addWarning('error-write', $local);
+ $existingMd5 = strtolower(preg_replace('/[^0-9a-f]/is', '', $existingMd5));
+ $remoteMd5 = Util::download($remote, 3, $code);
+ $remoteMd5 = strtolower(preg_replace('/[^0-9a-f]/is', '', $remoteMd5));
+ if ($code != 200) {
+ Message::addError('remote-timeout', $remote, $code);
+ return false;
}
- } 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', '', $remoteMd5));
- if ($code != 200) {
- Message::addError('remote-timeout', $remote, $code);
- return false;
- }
- if ($existingMd5 === $remoteMd5) {
- // Up to date
+ 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++,
+ 'file' => $name,
+ 'id' => 'id' . $someId++,
+ 'update' => true
);
return true;
}
- // New version on server
- $files[] = array(
- 'file' => $name,
- 'id' => 'id' . $someId++,
- 'update' => true
- );
- return true;
}
-