summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2014-10-06 19:30:06 +0200
committerSimon Rettberg2014-10-06 19:30:06 +0200
commit94cb6009866f4ebc16d92087c0440adb98f18299 (patch)
treefb7deffa2965f92c4561b5111c17a6a5bed270c4
parentuse eventlog when creating users; show info on main page if no user was creat... (diff)
downloadslx-admin-94cb6009866f4ebc16d92087c0440adb98f18299.tar.gz
slx-admin-94cb6009866f4ebc16d92087c0440adb98f18299.tar.xz
slx-admin-94cb6009866f4ebc16d92087c0440adb98f18299.zip
Use eventlog in init and update API, populate database with default values on init
-rw-r--r--apis/init.inc.php61
-rw-r--r--apis/update.inc.php12
-rw-r--r--inc/defaultdata.inc.php148
-rw-r--r--inc/trigger.inc.php14
4 files changed, 223 insertions, 12 deletions
diff --git a/apis/init.inc.php b/apis/init.inc.php
index 3e948330..a1344fc4 100644
--- a/apis/init.inc.php
+++ b/apis/init.inc.php
@@ -3,7 +3,60 @@
if (!isLocalExecution())
exit(0);
-Trigger::ldadp();
-Trigger::mount();
-Trigger::autoUpdateServerIp();
-Trigger::ipxe();
+EventLog::info('System boot...');
+$everythingFine = true;
+
+DefaultData::populate();
+
+// Tasks: fire away
+$mountId = Trigger::mount();
+$ldadpId = Trigger::ldadp();
+$autoIp = Trigger::autoUpdateServerIp();
+$ipxeId = Trigger::ipxe();
+
+// Check status of all tasks
+// Mount vm store
+if ($mountId === false) {
+ EventLog::info('No VM store type defined.');
+ $everythingFine = false;
+} else {
+ $res = Taskmanager::waitComplete($mountId, 5000);
+ if (Taskmanager::isFailed($res)) {
+ EventLog::failure('Mounting VM store failed: ' . $res['data']['messages']);
+ $everythingFine = false;
+ }
+}
+// LDAP AD Proxy
+if ($ldadpId === false) {
+ EventLog::failure('Cannot start LDAP-AD-Proxy: Taskmanager unreachable!');
+ $everythingFine = false;
+} else {
+ $res = Taskmanager::waitComplete($ldadpId, 5000);
+ if (Taskmanager::isFailed($res)) {
+ EventLog::failure('Starting LDAP-AD-Proxy failed: ' . $res['data']['messages']);
+ $everythingFine = false;
+ }
+}
+// Primary IP address
+if (!$autoIp) {
+ EventLog::failure("The server's IP address could not be determined automatically, and there is no active address configured.");
+ $everythingFine = false;
+}
+// iPXE generation
+if ($ipxeId === false) {
+ EventLog::failure('Cannot generate PXE menu: Taskmanager unreachable!');
+ $everythingFine = false;
+} else {
+ $res = Taskmanager::waitComplete($ipxeId, 5000);
+ if (Taskmanager::isFailed($res)) {
+ EventLog::failure('Update PXE Menu failed: ' . $res['data']['error']);
+ $everythingFine = false;
+ }
+}
+
+// Just so we know booting is done (and we don't expect any more errors from booting up)
+if ($everythingFine) {
+ EventLog::info('Bootup finished without errors.');
+} else {
+ EventLog::info('There were errors during bootup. Maybe the server is not fully configured yet.');
+}
diff --git a/apis/update.inc.php b/apis/update.inc.php
index 3c8984b6..4fb4b3fb 100644
--- a/apis/update.inc.php
+++ b/apis/update.inc.php
@@ -2,6 +2,12 @@
$targetVersion = Database::getExpectedSchemaVersion();
+function fatal($message)
+{
+ EventLog::failure($message);
+ die("$message\n");
+}
+
// #######################
$res = Database::queryFirst("SELECT value FROM property WHERE name = 'webif-version' LIMIT 1", array(), true);
@@ -16,16 +22,16 @@ while ($currentVersion < $targetVersion) {
$function = 'update_' . $currentVersion;
if (!function_exists($function))
- die("Don't know how to update from version $currentVersion to $targetVersion :-(");
+ fatal("Don't know how to update from version $currentVersion to $targetVersion :-(");
if (!$function())
- die("Update from $currentVersion to $targetVersion failed! :-(");
+ fatal("Update from $currentVersion to $targetVersion failed! :-(");
$currentVersion++;
$ret = Database::exec("INSERT INTO property (name, value) VALUES ('webif-version', :version) ON DUPLICATE KEY UPDATE value = VALUES(value)", array('version' => $currentVersion), false);
if ($ret === false)
- die('Writing version information back to DB failed. Next update will probably break.');
+ fatal('Writing version information back to DB failed. Next update will probably break.');
if ($currentVersion < $targetVersion) {
echo("Updated to $currentVersion...\n");
diff --git a/inc/defaultdata.inc.php b/inc/defaultdata.inc.php
new file mode 100644
index 00000000..12a304f6
--- /dev/null
+++ b/inc/defaultdata.inc.php
@@ -0,0 +1,148 @@
+<?php
+
+/**
+ * This class is supposed to fill the database with default entries (where required).
+ * The insertion should be non-destructive, so if an entry already exists (and
+ * possibly changed), it should be skipped.
+ */
+class DefaultData
+{
+
+ public static function populate()
+ {
+ self::addSettingCategories();
+ self::addSettings();
+ }
+
+ /**
+ * Categories for basic system config / config variables
+ */
+ private static function addSettingCategories()
+ {
+ $cats = array(
+ 0 => 20000, // Unassigned/no category
+ 1 => 30, // Inactivity/Shutdown
+ 2 => 20, // Internet access
+ 3 => 100, // Timesync
+ 4 => 10, // System config
+ );
+ foreach ($cats as $cat => $sort) {
+ Database::exec("INSERT IGNORE INTO cat_setting (catid, sortval) VALUES (:catid, :sortval)", array(
+ 'catid' => $cat,
+ 'sortval' => $sort
+ ));
+ }
+ }
+
+ /**
+ * Settings for basic system config
+ */
+ private static function addSettings()
+ {
+ $data = array(
+ array(
+ 'setting' => 'SLX_ADDONS',
+ 'catid' => '0',
+ 'defaultvalue' => 'vmware',
+ 'permissions' => '2',
+ 'validator' => ''
+ ),
+ array(
+ 'setting' => 'SLX_BIOS_CLOCK',
+ 'catid' => '3',
+ 'defaultvalue' => 'off',
+ 'permissions' => '2',
+ 'validator' => 'list:off|local|utc'
+ ),
+ array(
+ 'setting' => 'SLX_LOGOUT_TIMEOUT',
+ 'catid' => '1',
+ 'defaultvalue' => '1800',
+ 'permissions' => '2',
+ 'validator' => 'regex:/^\d*$/'
+ ),
+ array(
+ 'setting' => 'SLX_NET_DOMAIN',
+ 'catid' => '2',
+ 'defaultvalue' => '',
+ 'permissions' => '2',
+ 'validator' => ''
+ ),
+ array(
+ 'setting' => 'SLX_NTP_SERVER',
+ 'catid' => '3',
+ 'defaultvalue' => '0.de.pool.ntp.org 1.de.pool.ntp.org',
+ 'permissions' => '2',
+ 'validator' => ''
+ ),
+ array(
+ 'setting' => 'SLX_PROXY_BLACKLIST',
+ 'catid' => '2',
+ 'defaultvalue' => '',
+ 'permissions' => '2',
+ 'validator' => ''
+ ),
+ array(
+ 'setting' => 'SLX_PROXY_IP',
+ 'catid' => '2',
+ 'defaultvalue' => '',
+ 'permissions' => '2',
+ 'validator' => ''
+ ),
+ array(
+ 'setting' => 'SLX_PROXY_MODE',
+ 'catid' => '2',
+ 'defaultvalue' => 'off',
+ 'permissions' => '2',
+ 'validator' => 'list:off|on|auto|wpad'
+ ),
+ array(
+ 'setting' => 'SLX_PROXY_PORT',
+ 'catid' => '2',
+ 'defaultvalue' => '',
+ 'permissions' => '2',
+ 'validator' => 'regex:/^\d*$/'
+ ),
+ array(
+ 'setting' => 'SLX_PROXY_TYPE',
+ 'catid' => '2',
+ 'defaultvalue' => 'socks5',
+ 'permissions' => '2',
+ 'validator' => ''
+ ),
+ array(
+ 'setting' => 'SLX_REMOTE_LOG_SESSIONS',
+ 'catid' => '0',
+ 'defaultvalue' => 'anonymous',
+ 'permissions' => '2',
+ 'validator' => 'list:yes|anonymous|no'
+ ),
+ array(
+ 'setting' => 'SLX_ROOT_PASS',
+ 'catid' => '4',
+ 'defaultvalue' => '',
+ 'permissions' => '2',
+ 'validator' => 'function:linuxPassword'
+ ),
+ array(
+ 'setting' => 'SLX_SHUTDOWN_SCHEDULE',
+ 'catid' => '1',
+ 'defaultvalue' => '22:10 00:00',
+ 'permissions' => '2',
+ 'validator' => 'regex:/^(\s*\d{1,2}:\d{1,2})*\s*$/'
+ ),
+ array(
+ 'setting' => 'SLX_SHUTDOWN_TIMEOUT',
+ 'catid' => '1',
+ 'defaultvalue' => '1200',
+ 'permissions' => '2',
+ 'validator' => 'regex:/^\d*$/'
+ )
+ );
+ foreach ($data as $entry) {
+ Database::exec("INSERT IGNORE INTO setting (setting, catid, defaultvalue, permissions, validator)"
+ . "VALUES (:setting, :catid, :defaultvalue, :permissions, :validator)");
+ }
+ }
+
+}
diff --git a/inc/trigger.inc.php b/inc/trigger.inc.php
index e6f7cd31..0b31c7b3 100644
--- a/inc/trigger.inc.php
+++ b/inc/trigger.inc.php
@@ -31,22 +31,25 @@ class Trigger
* Try to automatically determine the primary IP address of the server.
* This only works if the server has either one public IPv4 address (and potentially
* one or more non-public addresses), or one private address.
+ *
+ * @return boolean true if current configured IP address is still valid, or if a new address could
+ * successfully be determined, false otherwise
*/
public static function autoUpdateServerIp()
{
$task = Taskmanager::submit('LocalAddressesList');
if ($task === false)
- return;
+ return false;
$task = Taskmanager::waitComplete($task, 10000);
if (!isset($task['data']['addresses']) || empty($task['data']['addresses']))
- return;
+ return false;
$serverIp = Property::getServerIp();
$publicCandidate = 'none';
$privateCandidate = 'none';
foreach ($task['data']['addresses'] as $addr) {
if ($addr['ip'] === $serverIp)
- return;
+ return true;
if (substr($addr['ip'], 0, 4) === '127.')
continue;
if (Util::isPublicIpv4($addr['ip'])) {
@@ -63,12 +66,13 @@ class Trigger
}
if ($publicCandidate !== 'none' && $publicCandidate !== 'many') {
Property::setServerIp($publicCandidate);
- return;
+ return true;
}
if ($privateCandidate !== 'none' && $privateCandidate !== 'many') {
Property::setServerIp($privateCandidate);
- return;
+ return true;
}
+ return false;
}
/**