summaryrefslogtreecommitdiffstats
path: root/inc
diff options
context:
space:
mode:
authorSimon Rettberg2016-06-08 18:33:30 +0200
committerSimon Rettberg2016-06-08 18:33:30 +0200
commitffffab643e031524b6fdfe0c39adae1f6c8e9c4d (patch)
tree84e55c5a7ea0e02481b9f44730814ae788f05e12 /inc
parent[dashboard] Remove needsSchemaUpdate call (diff)
downloadslx-admin-ffffab643e031524b6fdfe0c39adae1f6c8e9c4d.tar.gz
slx-admin-ffffab643e031524b6fdfe0c39adae1f6c8e9c4d.tar.xz
slx-admin-ffffab643e031524b6fdfe0c39adae1f6c8e9c4d.zip
[install] Implement install scripts for most modules
Diffstat (limited to 'inc')
-rw-r--r--inc/database.inc.php29
-rw-r--r--inc/defaultdata.inc.php204
-rw-r--r--inc/dictionary.inc.php1
3 files changed, 23 insertions, 211 deletions
diff --git a/inc/database.inc.php b/inc/database.inc.php
index ee45f6c0..4a5821f4 100644
--- a/inc/database.inc.php
+++ b/inc/database.inc.php
@@ -8,19 +8,24 @@ class Database
{
/**
- *
* @var \PDO Database handle
*/
private static $dbh = false;
+ /*
+ * @var \PDOStatement[]
+ */
private static $statements = array();
+ private static $returnErrors;
+ private static $lastError = false;
/**
* Connect to the DB if not already connected.
*/
- public static function init($returnSuccess = false)
+ public static function init($returnErrors = false)
{
if (self::$dbh !== false)
return true;
+ self::$returnErrors = $returnErrors;
try {
if (CONFIG_SQL_FORCE_UTF8) {
self::$dbh = new PDO(CONFIG_SQL_DSN, CONFIG_SQL_USER, CONFIG_SQL_PASS, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
@@ -28,7 +33,7 @@ class Database
self::$dbh = new PDO(CONFIG_SQL_DSN, CONFIG_SQL_USER, CONFIG_SQL_PASS);
}
} catch (PDOException $e) {
- if ($returnSuccess)
+ if (self::$returnErrors)
return false;
Util::traceError('Connecting to the local database failed: ' . $e->getMessage());
}
@@ -77,6 +82,14 @@ class Database
}
/**
+ * @return string|bool return last error returned by query
+ */
+ public static function lastError()
+ {
+ return self::$lastError;
+ }
+
+ /**
* Execute the given query and return the corresponding PDOStatement object
* Note that this will re-use PDOStatements, so if you run the same
* query again with different params, do not rely on the first PDOStatement
@@ -94,15 +107,17 @@ class Database
self::$statements[$query]->closeCursor();
}
if (self::$statements[$query]->execute($args) === false) {
- if ($ignoreError)
+ self::$lastError = implode("\n", self::$statements[$query]->errorInfo());
+ if ($ignoreError || self::$returnErrors)
return false;
- Util::traceError("Database Error: \n" . implode("\n", self::$statements[$query]->errorInfo()));
+ Util::traceError("Database Error: \n" . self::$lastError);
}
return self::$statements[$query];
} catch (Exception $e) {
- if ($ignoreError)
+ self::$lastError = '(' . $e->getCode() . ') ' . $e->getMessage();
+ if ($ignoreError || self::$returnErrors)
return false;
- Util::traceError("Database Error: \n" . $e->getMessage());
+ Util::traceError("Database Error: \n" . self::$lastError);
}
return false;
}
diff --git a/inc/defaultdata.inc.php b/inc/defaultdata.inc.php
deleted file mode 100644
index 2d993e72..00000000
--- a/inc/defaultdata.inc.php
+++ /dev/null
@@ -1,204 +0,0 @@
-<?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(
- 1 => 30, // Inactivity/Shutdown
- 2 => 50, // Internet access
- 3 => 100, // Timesync
- 4 => 10, // System config
- //5 => 15, // Public Shared folder
- 6 => 20000, // Unassigned/no category
- 7 => 20,
- );
- 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' => '6',
- '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' => '2700',
- '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'
- ),
- 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' => 'list:socks4|socks5|http-connect|http-relay'
- ),
- array(
- 'setting' => 'SLX_REMOTE_LOG_SESSIONS',
- 'catid' => '6',
- '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_DEMO_PASS',
- 'catid' => '4',
- 'defaultvalue' => '',
- 'permissions' => '2',
- 'validator' => 'function:linuxPassword'
- ),
- array(
- 'setting' => 'SLX_BWIDM_AUTH',
- 'catid' => '4',
- 'defaultvalue' => 'no',
- 'permissions' => '2',
- 'validator' => 'list:yes|no'
- ),
- 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*$/'
- ),
- /*
- array(
- 'setting' => 'SLX_COMMON_SHARE_PATH',
- 'catid' => '5',
- 'defaultvalue' => '',
- 'permissions' => '2',
- 'validator' => 'function:networkShare'
- ),
- array(
- 'setting' => 'SLX_COMMON_SHARE_AUTH',
- 'catid' => '5',
- 'defaultvalue' => 'guest',
- 'permissions' => '2',
- 'validator' => 'list:guest|user'
- ),
- */
- array(
- 'setting' => 'SLX_BENCHMARK_VM',
- 'catid' => '6',
- 'defaultvalue' => '',
- 'permissions' => '2',
- 'validator' => ''
- ),
- array(
- 'setting' => 'SLX_VMCHOOSER_TAB',
- 'catid' => '7',
- 'defaultvalue' => 'AUTO',
- 'permissions' => '2',
- 'validator' => 'list:0|1|2|AUTO'
- ),
- array(
- 'setting' => 'SLX_VMCHOOSER_TEMPLATES',
- 'catid' => '7',
- 'defaultvalue' => 'IGNORE',
- 'permissions' => '2',
- 'validator' => 'list:IGNORE|BUMP'
- ),
- array(
- 'setting' => 'SLX_VMCHOOSER_FORLOCATION',
- 'catid' => '7',
- 'defaultvalue' => 'BUMP',
- 'permissions' => '2',
- 'validator' => 'list:IGNORE|BUMP|EXCLUSIVE'
- ),
- );
- }
-
-}
diff --git a/inc/dictionary.inc.php b/inc/dictionary.inc.php
index f5886bda..6ae8fb9b 100644
--- a/inc/dictionary.inc.php
+++ b/inc/dictionary.inc.php
@@ -79,6 +79,7 @@ class Dictionary
public static function translateFile($path, $tag)
{
+ // TODO: Handle case where we have no active module/no page class
return self::translateFileModule(Page::getModule()->getIdentifier(), $path, $tag);
}