summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--apis/getconfig.inc.php14
-rw-r--r--inc/configmodule.inc.php2
-rw-r--r--inc/trigger.inc.php43
3 files changed, 52 insertions, 7 deletions
diff --git a/apis/getconfig.inc.php b/apis/getconfig.inc.php
index 0a8db6be..84393dbc 100644
--- a/apis/getconfig.inc.php
+++ b/apis/getconfig.inc.php
@@ -1,8 +1,15 @@
<?php
+/**
+ * Escape given string so it is a valid string in sh that can be surrounded
+ * by single quotes ('). This basically turns _'_ into _'"'"'_
+ *
+ * @param string $string input
+ * @return string escaped sh string
+ */
function escape($string)
{
- return str_replace("'", "\\'", $string);
+ return str_replace("'", "'\"'\"'", $string);
}
// Dump config from DB
@@ -12,12 +19,15 @@ $res = Database::simpleQuery('SELECT setting.setting, setting.defaultvalue, sett
ORDER BY setting ASC'); // TODO: Add setting groups and sort order
while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
if (is_null($row['value'])) $row['value'] = $row['defaultvalue'];
- echo $row['setting'] . "='" . str_replace("'", "'\"'\"'", $row['value']) . "'\n";
+ echo $row['setting'] . "='" . escape($row['value']) . "'\n";
}
+
// Additional "intelligent" config
// Remote log URL
echo "SLX_REMOTE_LOG='http://" . escape($_SERVER['SERVER_ADDR']) . "/slxadmin/api.php?do=clientlog'\n";
+// vm list url
+echo "SLX_VMCHOOSER_BASE_URL='http://" . escape($_SERVER['SERVER_ADDR']) . "/vmchooser/'\n";
// VMStore path and type
$vmstore = Property::getVmStoreConfig();
diff --git a/inc/configmodule.inc.php b/inc/configmodule.inc.php
index e9fa40bb..5c789275 100644
--- a/inc/configmodule.inc.php
+++ b/inc/configmodule.inc.php
@@ -40,7 +40,7 @@ class ConfigModule
Database::exec("UPDATE configtgz_module SET filepath = :filename, contents = :contents WHERE moduleid = :id LIMIT 1", array(
'id' => $id,
'filename' => $name,
- 'contents' => json_encode($ownEntry)
+ 'contents' => $data
));
// Add archive file name to array before returning it
$ownEntry['moduleid'] = $id;
diff --git a/inc/trigger.inc.php b/inc/trigger.inc.php
index 7ab7d5b1..e6f7cd31 100644
--- a/inc/trigger.inc.php
+++ b/inc/trigger.inc.php
@@ -72,10 +72,12 @@ class Trigger
}
/**
- *
+ * Launch all ldadp instances that need to be running.
+ *
+ * @param string $parent if not NULL, this will be the parent task of the launch-task
* @return boolean|string false on error, id of task otherwise
*/
- public static function ldadp()
+ public static function ldadp($parent = NULL)
{
$res = Database::simpleQuery("SELECT moduleid, configtgz.filepath FROM configtgz_module"
. " INNER JOIN configtgz_x_module USING (moduleid)"
@@ -90,17 +92,50 @@ class Trigger
}
}
$task = Taskmanager::submit('LdadpLauncher', array(
- 'ids' => $id
+ 'ids' => $id,
+ 'parentTask' => $parent,
+ 'failOnParentFail' => false
));
if (!isset($task['id']))
return false;
return $task['id'];
}
+ /**
+ * To be called if the server ip changes, as it's embedded in the AD module configs.
+ * This will then recreate all AD tgz modules.
+ */
+ public static function rebuildAdModules()
+ {
+ $res = Database::simpleQuery("SELECT moduleid, filepath, content FROM configtgz_module"
+ . " WHERE moduletype = 'AD_AUTH'");
+ if ($res->rowCount() === 0)
+ return;
+
+ $task = Taskmanager::submit('LdadpLauncher', array('ids' => array())); // Stop all running instances
+ $parent = isset($task['id']) ? $task['id'] : NULL;
+ while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ $config = json_decode($row['contents']);
+ $config['proxyip'] = Property::getServerIp();
+ $config['moduleid'] = $row['moduleid'];
+ $config['filename'] = $row['filepath'];
+ $config['parentTask'] = $parent;
+ $config['failOnParentFail'] = false;
+ $task = Taskmanager::submit('CreateAdConfig', $config);
+ $parent = isset($task['id']) ? $task['id'] : NULL;
+ }
+
+ }
+
+ /**
+ * Mount the VM store into the server.
+ *
+ * @return array task status of mount procedure, or false on error
+ */
public static function mount()
{
$vmstore = Property::getVmStoreConfig();
- if (!is_array($vmstore)) return;
+ if (!is_array($vmstore)) return false;
$storetype = $vmstore['storetype'];
if ($storetype === 'nfs') $addr = $vmstore['nfsaddr'];
if ($storetype === 'cifs') $addr = $vmstore['cifsaddr'];