From 94cb6009866f4ebc16d92087c0440adb98f18299 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Mon, 6 Oct 2014 19:30:06 +0200 Subject: Use eventlog in init and update API, populate database with default values on init --- inc/defaultdata.inc.php | 148 ++++++++++++++++++++++++++++++++++++++++++++++++ inc/trigger.inc.php | 14 +++-- 2 files changed, 157 insertions(+), 5 deletions(-) create mode 100644 inc/defaultdata.inc.php (limited to 'inc') 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 @@ + 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; } /** -- cgit v1.2.3-55-g7522