summaryrefslogtreecommitdiffstats
path: root/inc/defaultdata.inc.php
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/defaultdata.inc.php
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/defaultdata.inc.php')
-rw-r--r--inc/defaultdata.inc.php148
1 files changed, 148 insertions, 0 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)");
+ }
+ }
+
+}