summaryrefslogtreecommitdiffstats
path: root/inc
diff options
context:
space:
mode:
authorSimon Rettberg2014-10-06 19:30:06 +0200
committerSimon Rettberg2014-10-06 19:30:06 +0200
commit94cb6009866f4ebc16d92087c0440adb98f18299 (patch)
treefb7deffa2965f92c4561b5111c17a6a5bed270c4 /inc
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
Diffstat (limited to 'inc')
-rw-r--r--inc/defaultdata.inc.php148
-rw-r--r--inc/trigger.inc.php14
2 files changed, 157 insertions, 5 deletions
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;
}
/**