summaryrefslogtreecommitdiffstats
path: root/inc
diff options
context:
space:
mode:
authorSimon Rettberg2014-05-26 22:49:54 +0200
committerSimon Rettberg2014-05-26 22:49:54 +0200
commita4f4147b6fe5f2a003a61cf8a8f7508c94130b31 (patch)
treede34472a2b9bd83909469affb884619b4858efc1 /inc
parentWIP (diff)
downloadslx-admin-a4f4147b6fe5f2a003a61cf8a8f7508c94130b31.tar.gz
slx-admin-a4f4147b6fe5f2a003a61cf8a8f7508c94130b31.tar.xz
slx-admin-a4f4147b6fe5f2a003a61cf8a8f7508c94130b31.zip
WIP
Diffstat (limited to 'inc')
-rw-r--r--inc/property.inc.php47
-rw-r--r--inc/render.inc.php1
-rw-r--r--inc/taskmanager.inc.php41
-rw-r--r--inc/trigger.inc.php40
4 files changed, 114 insertions, 15 deletions
diff --git a/inc/property.inc.php b/inc/property.inc.php
index d186193a..5c316517 100644
--- a/inc/property.inc.php
+++ b/inc/property.inc.php
@@ -84,5 +84,52 @@ 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'] + 120 > time())
+ return $data;
+ $task = Taskmanager::submit('DownloadText', array(
+ 'url' => CONFIG_REMOTE_ML . '/list.php'
+ ));
+ if (!isset($task['id']))
+ return false;
+ if ($task['statusCode'] !== TASK_FINISHED) {
+ $task = Taskmanager::waitComplete($task['id']);
+ }
+ if ($task['statusCode'] !== TASK_FINISHED || !isset($task['data']['content'])) {
+ return $task['data']['error'];
+ }
+ $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));
+ }
+
+ public static function getVmStoreConfig()
+ {
+ return json_decode(self::get('vmstore-config'), true);
+ }
+
+ public static function setVmStoreConfig($value)
+ {
+ self::set('vmstore-config', json_encode($value));
+ }
}
diff --git a/inc/render.inc.php b/inc/render.inc.php
index cf0958c2..6853acde 100644
--- a/inc/render.inc.php
+++ b/inc/render.inc.php
@@ -48,7 +48,6 @@ class Render
<script type="text/javascript">
var TOKEN = "' . Session::get('token') . '";
</script>
- </body>
',
self::$header
,
diff --git a/inc/taskmanager.inc.php b/inc/taskmanager.inc.php
index e93cc696..99e35e94 100644
--- a/inc/taskmanager.inc.php
+++ b/inc/taskmanager.inc.php
@@ -5,12 +5,13 @@
*/
class Taskmanager
{
-
+
private static $sock = false;
-
+
private static function init()
{
- if (self::$sock !== false) return;
+ if (self::$sock !== false)
+ return;
self::$sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
socket_set_option(self::$sock, SOL_SOCKET, SO_RCVTIMEO, array('sec' => 0, 'usec' => 300000));
socket_set_option(self::$sock, SOL_SOCKET, SO_SNDTIMEO, array('sec' => 0, 'usec' => 200000));
@@ -20,7 +21,7 @@ class Taskmanager
public static function submit($task, $data, $async = false)
{
self::init();
- $seq = (string)mt_rand();
+ $seq = (string) mt_rand();
if (empty($data)) {
$data = '{}';
} else {
@@ -32,7 +33,8 @@ class Taskmanager
Message::addError('taskmanager-error');
return false;
}
- if ($async) return true;
+ if ($async)
+ return true;
$reply = self::readReply($seq);
if ($reply === false) {
Message::addError('taskmanager-error');
@@ -56,38 +58,50 @@ class Taskmanager
public static function status($taskId)
{
self::init();
- $seq = (string)mt_rand();
+ $seq = (string) mt_rand();
$message = "$seq, status, $taskId";
$sent = socket_send(self::$sock, $message, strlen($message), 0);
$reply = self::readReply($seq);
- if (!is_array($reply)) return false;
+ if (!is_array($reply))
+ return false;
return $reply;
}
-
+
public static function waitComplete($taskId)
{
$done = false;
for ($i = 0; $i < 10; ++$i) {
$status = self::status($taskId);
- if (!isset($status['statusCode'])) break;
+ if (!isset($status['statusCode']))
+ break;
if ($status['statusCode'] != TASK_PROCESSING && $status['statusCode'] != TASK_WAITING) {
$done = true;
break;
}
usleep(150000);
}
- if ($done) self::release ($taskId);
+ if ($done)
+ self::release($taskId);
return $status;
}
+ public static function isFailed($task)
+ {
+ if (!isset($task['statusCode']) || !isset($task['id']))
+ return true;
+ if ($task['statusCode'] !== TASK_WAITING && $task['statusCode'] !== TASK_PROCESSING && $task['statusCode'] !== TASK_FINISHED)
+ return true;
+ return false;
+ }
+
public static function release($taskId)
{
self::init();
- $seq = (string)mt_rand();
+ $seq = (string) mt_rand();
$message = "$seq, release, $taskId";
socket_send(self::$sock, $message, strlen($message), 0);
}
-
+
/**
*
* @param type $seq
@@ -101,7 +115,8 @@ class Taskmanager
if (count($parts) == 2 && $parts[0] == $seq) {
return json_decode($parts[1], true);
}
- if (++$tries > 10) return false;
+ if (++$tries > 10)
+ return false;
}
//error_log(socket_strerror(socket_last_error(self::$sock)));
return false;
diff --git a/inc/trigger.inc.php b/inc/trigger.inc.php
index af12955f..102f7987 100644
--- a/inc/trigger.inc.php
+++ b/inc/trigger.inc.php
@@ -36,5 +36,43 @@ class Trigger
Property::setIPxeTaskId($task['id']);
return $task['id'];
}
+
+ public static function ldadp()
+ {
+ $res = Database::simpleQuery("SELECT moduleid, filepath FROM configtgz_module"
+ . " INNER JOIN configtgz_x_module USING (moduleid)"
+ . " INNER JOIN configtgz USING (configid)"
+ . " WHERE moduletype = 'AD_AUTH'");
+ // TODO: Multiconfig support
+ $id = array();
+ while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ if (readlink('/srv/openslx/www/boot/default/config.tgz') === $row['filepath']) {
+ $id[] = (int)$row['moduleid'];
+ break;
+ }
+ }
+ $task = Taskmanager::submit('LdadpLauncher', array(
+ 'ids' => $id
+ ));
+ if (!isset($task['id']))
+ return false;
+ return $task['id'];
+ }
+
+ public static function mount()
+ {
+ $vmstore = Property::getVmStoreConfig();
+ if (!is_array($vmstore)) return;
+ $storetype = $vmstore['storetype'];
+ if ($storetype === 'nfs') $addr = $vmstore['nfsaddr'];
+ if ($storetype === 'cifs') $addr = $vmstore['nfsaddr'];
+ if ($storetype === 'internal') $addr = 'none';
+ $this->mountTask = Taskmanager::submit('MountVmStore', array(
+ 'address' => $addr,
+ 'type' => 'images',
+ 'username' => $vmstore['cifsuser'],
+ 'password' => $vmstore['cifspasswd']
+ ));
+ }
-} \ No newline at end of file
+}