summaryrefslogtreecommitdiffstats
path: root/modules-available/baseconfig/api.inc.php
diff options
context:
space:
mode:
authorSimon Rettberg2016-05-17 18:14:13 +0200
committerSimon Rettberg2016-05-17 18:14:13 +0200
commit8e729913a8f6258762f4e8049caebc9dbb42a71e (patch)
tree48b1d27787847c012994248e32f5a79695221218 /modules-available/baseconfig/api.inc.php
parentGet baseconfig ready for modularization (diff)
downloadslx-admin-8e729913a8f6258762f4e8049caebc9dbb42a71e.tar.gz
slx-admin-8e729913a8f6258762f4e8049caebc9dbb42a71e.tar.xz
slx-admin-8e729913a8f6258762f4e8049caebc9dbb42a71e.zip
Modularized baseconfig fetching (api)
Diffstat (limited to 'modules-available/baseconfig/api.inc.php')
-rw-r--r--modules-available/baseconfig/api.inc.php69
1 files changed, 69 insertions, 0 deletions
diff --git a/modules-available/baseconfig/api.inc.php b/modules-available/baseconfig/api.inc.php
new file mode 100644
index 00000000..c692a0b2
--- /dev/null
+++ b/modules-available/baseconfig/api.inc.php
@@ -0,0 +1,69 @@
+<?php
+
+$ip = $_SERVER['REMOTE_ADDR'];
+if (substr($ip, 0, 7) === '::ffff:') {
+ $ip = substr($ip, 7);
+}
+
+// TODO: Handle UUID in appropriate modules (optional)
+$uuid = Request::post('uuid', '', 'string');
+if (strlen($uuid) !== 36) {
+ // Probably invalid UUID. What to do? Set empty or ignore?
+}
+
+/**
+ * Escape given string so it is a valid string in sh that can be surrounded
+ * by single quotes ('). This basically turns _'_ into _'"'"'_
+ *
+ * @param string $string input
+ * @return string escaped sh string
+ */
+function escape($string)
+{
+ return str_replace("'", "'\"'\"'", $string);
+}
+
+/*
+ * We gather all config variables here. First, let other modules generate
+ * their desired config vars. Afterwards, add the global config vars from
+ * db. If a variable is already set, it will not be overridden by the
+ * global setting.
+ */
+
+$configVars = array();
+
+// Handle any hooks by other modules first
+// other modules should generally only populate $configVars
+foreach (glob('modules/*/baseconfig/getconfig.inc.php') as $file) {
+ preg_match('#^modules/([^/]+)/#', $file, $out);
+ if (!Module::isAvailable($out[1]))
+ continue;
+ include $file;
+}
+
+// Rest is handled by module
+$defaults = BaseConfigUtil::getVariables();
+
+// Dump global config from DB
+$res = Database::simpleQuery('SELECT setting, value FROM setting_global'); // TODO: Add setting groups and sort order
+while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ if (isset($configVars[$row['setting']]) || !isset($defaults[$row['setting']]))
+ continue;
+ $configVars[$row['setting']] = $row['value'];
+}
+
+// Fallback to default values from json files
+foreach ($defaults as $setting => $value) {
+ if (isset($configVars[$setting]))
+ continue;
+ $configVars[$setting] = $value;
+}
+
+// Finally, output what we gathered
+foreach ($configVars as $setting => $value) {
+ echo $setting, "='", escape($value), "'\n";
+}
+
+// For quick testing or custom extensions: Include external file that should do nothing
+// more than outputting more key-value-pairs. It's expected in the webroot of slxadmin
+if (file_exists('client_config_additional.php')) @include('client_config_additional.php');