From 7d916647e1b82fcc8a17b68d3ae0615af42f53e0 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Fri, 13 May 2016 18:24:08 +0200 Subject: Get baseconfig ready for modularization --- .../baseconfig-bwlp/baseconfig/categories.json | 8 + .../baseconfig-bwlp/baseconfig/settings.json | 122 +++++++++++ .../baseconfig/hooks/translation.inc.php | 16 +- .../baseconfig/inc/baseconfigutil.inc.php | 42 ++++ .../lang/de/config-variable-categories.json | 12 +- .../baseconfig/lang/de/template-tags.json | 11 +- .../lang/en/config-variable-categories.json | 13 +- .../baseconfig/lang/en/template-tags.json | 4 +- .../lang/pt/config-variable-categories.json | 10 +- .../baseconfig/lang/pt/template-tags.json | 1 - modules-available/baseconfig/page.inc.php | 229 +++++++++++++++------ modules-available/baseconfig/templates/_page.html | 158 ++------------ .../internetaccess/lang/de/messages.json | 4 + .../internetaccess/lang/en/messages.json | 4 + .../internetaccess/lang/pt/messages.json | 4 + modules-available/locations/baseconfig/hook.json | 5 + modules-available/locations/inc/location.inc.php | 157 ++++++++++++++ modules-available/main/lang/de/messages.json | 11 +- modules-available/main/lang/de/template-tags.json | 1 + modules-available/main/lang/en/template-tags.json | 1 + modules-available/main/lang/pt/global-tags.json | 3 +- 21 files changed, 572 insertions(+), 244 deletions(-) create mode 100644 modules-available/baseconfig-bwlp/baseconfig/categories.json create mode 100644 modules-available/baseconfig-bwlp/baseconfig/settings.json create mode 100644 modules-available/baseconfig/inc/baseconfigutil.inc.php create mode 100644 modules-available/internetaccess/lang/de/messages.json create mode 100644 modules-available/internetaccess/lang/en/messages.json create mode 100644 modules-available/internetaccess/lang/pt/messages.json create mode 100644 modules-available/locations/baseconfig/hook.json create mode 100644 modules-available/locations/inc/location.inc.php (limited to 'modules-available') diff --git a/modules-available/baseconfig-bwlp/baseconfig/categories.json b/modules-available/baseconfig-bwlp/baseconfig/categories.json new file mode 100644 index 00000000..c33c58ab --- /dev/null +++ b/modules-available/baseconfig-bwlp/baseconfig/categories.json @@ -0,0 +1,8 @@ +{ + "power": 30, + "networking": 50, + "timesync": 100, + "sysconfig": 10, + "other": 20000, + "vmchooser": 20 +} \ No newline at end of file diff --git a/modules-available/baseconfig-bwlp/baseconfig/settings.json b/modules-available/baseconfig-bwlp/baseconfig/settings.json new file mode 100644 index 00000000..b0cbf81c --- /dev/null +++ b/modules-available/baseconfig-bwlp/baseconfig/settings.json @@ -0,0 +1,122 @@ +{ + "SLX_ADDONS": { + "catid": "other", + "defaultvalue": "vmware", + "permissions": "2", + "validator": "" + }, + "SLX_BIOS_CLOCK": { + "catid": "timesync", + "defaultvalue": "off", + "permissions": "2", + "validator": "list:off|local|utc" + }, + "SLX_LOGOUT_TIMEOUT": { + "catid": "power", + "defaultvalue": "2700", + "permissions": "2", + "validator": "regex:\/^\\d*$\/" + }, + "SLX_NET_DOMAIN": { + "catid": "networking", + "defaultvalue": "", + "permissions": "2", + "validator": "" + }, + "SLX_NTP_SERVER": { + "catid": "timesync", + "defaultvalue": "0.de.pool.ntp.org 1.de.pool.ntp.org", + "permissions": "2", + "validator": "" + }, + "SLX_PROXY_BLACKLIST": { + "catid": "networking", + "defaultvalue": "", + "permissions": "2", + "validator": "" + }, + "SLX_PROXY_IP": { + "catid": "networking", + "defaultvalue": "", + "permissions": "2", + "validator": "" + }, + "SLX_PROXY_MODE": { + "catid": "networking", + "defaultvalue": "off", + "permissions": "2", + "validator": "list:off|on|auto" + }, + "SLX_PROXY_PORT": { + "catid": "networking", + "defaultvalue": "", + "permissions": "2", + "validator": "regex:\/^\\d*$\/" + }, + "SLX_PROXY_TYPE": { + "catid": "networking", + "defaultvalue": "socks5", + "permissions": "2", + "validator": "list:socks4|socks5|http-connect|http-relay" + }, + "SLX_REMOTE_LOG_SESSIONS": { + "catid": "other", + "defaultvalue": "anonymous", + "permissions": "2", + "validator": "list:yes|anonymous|no" + }, + "SLX_ROOT_PASS": { + "catid": "sysconfig", + "defaultvalue": "", + "permissions": "2", + "validator": "function:linuxPassword" + }, + "SLX_DEMO_PASS": { + "catid": "sysconfig", + "defaultvalue": "", + "permissions": "2", + "validator": "function:linuxPassword" + }, + "SLX_BWIDM_AUTH": { + "catid": "sysconfig", + "defaultvalue": "no", + "permissions": "2", + "validator": "list:yes|no" + }, + "SLX_SHUTDOWN_SCHEDULE": { + "catid": "power", + "defaultvalue": "22:10 00:00", + "permissions": "2", + "validator": "regex:\/^(\\s*\\d{1,2}:\\d{1,2})*\\s*$\/" + }, + "SLX_SHUTDOWN_TIMEOUT": { + "catid": "power", + "defaultvalue": "1200", + "permissions": "2", + "validator": "regex:\/^\\d*$\/" + }, + "SLX_BENCHMARK_VM": { + "catid": "other", + "defaultvalue": "", + "permissions": "2", + "validator": "" + }, + "SLX_VMCHOOSER_TAB": { + "catid": "vmchooser", + "defaultvalue": "AUTO", + "permissions": "2", + "validator": "list:0|1|2|AUTO" + }, + "SLX_VMCHOOSER_TEMPLATES": { + "catid": "vmchooser", + "defaultvalue": "IGNORE", + "permissions": "2", + "validator": "list:IGNORE|BUMP" + }, + "SLX_VMCHOOSER_FORLOCATION": { + "catid": "vmchooser", + "defaultvalue": "BUMP", + "permissions": "2", + "validator": "list:IGNORE|BUMP|EXCLUSIVE" + } +} diff --git a/modules-available/baseconfig/hooks/translation.inc.php b/modules-available/baseconfig/hooks/translation.inc.php index 4f2cd8f7..7588fe38 100644 --- a/modules-available/baseconfig/hooks/translation.inc.php +++ b/modules-available/baseconfig/hooks/translation.inc.php @@ -18,10 +18,10 @@ $HANDLER['subsections'] = array( * Configuration categories */ $HANDLER['grep_config-variable-categories'] = function($module) { - $want = array(); - $res = Database::simpleQuery("SELECT catid FROM cat_setting ORDER BY catid ASC"); - while ($row = $res->fetch(PDO::FETCH_ASSOC)) { - $want['cat_' . $row['catid']] = true; + $module->activate(); + $want = BaseConfigUtil::getCategories(); + foreach ($want as &$entry) { + $entry = true; } return $want; }; @@ -30,10 +30,10 @@ $HANDLER['grep_config-variable-categories'] = function($module) { * Configuration variables */ $HANDLER['grep_config-variables'] = function($module) { - $want = array(); - $res = Database::simpleQuery("SELECT setting FROM setting ORDER BY setting ASC"); - while ($row = $res->fetch(PDO::FETCH_ASSOC)) { - $want[$row['setting']] = true; + $module->activate(); + $want = BaseConfigUtil::getVariables(); + foreach ($want as &$entry) { + $entry = true; } return $want; }; diff --git a/modules-available/baseconfig/inc/baseconfigutil.inc.php b/modules-available/baseconfig/inc/baseconfigutil.inc.php new file mode 100644 index 00000000..33875156 --- /dev/null +++ b/modules-available/baseconfig/inc/baseconfigutil.inc.php @@ -0,0 +1,42 @@ + array( + * catid => xx, + * defaultvalue => xx, + * permissions => xx, + * validator => xx, + * ) + * + * @return array all known config variables + */ + public static function getVariables() + { + $settings = array(); + foreach (glob('modules/*/baseconfig/settings.json', GLOB_NOSORT) as $file) { + $data = json_decode(file_get_contents($file), true); + if (is_array($data)) { + $settings += $data; + } + } + return $settings; + } + + public static function getCategories() + { + $categories = array(); + foreach (glob('modules/*/baseconfig/categories.json', GLOB_NOSORT) as $file) { + $data = json_decode(file_get_contents($file), true); + if (is_array($data)) { + $categories += $data; + } + } + return $categories; + } + +} \ No newline at end of file diff --git a/modules-available/baseconfig/lang/de/config-variable-categories.json b/modules-available/baseconfig/lang/de/config-variable-categories.json index b8cb6935..d8d7e91f 100644 --- a/modules-available/baseconfig/lang/de/config-variable-categories.json +++ b/modules-available/baseconfig/lang/de/config-variable-categories.json @@ -1,9 +1,9 @@ { - "cat_1": "Inaktivit\u00e4t und Abschaltung", - "cat_2": "Internetzugriff", - "cat_3": "Zeitsynchronisation", - "cat_4": "Grundsystem", "cat_5": "Gemeinsames Netzlaufwerk", - "cat_6": "Unkategorisiert", - "cat_7": "vmchooser" + "networking": "Netzwerk-\/Internetzugriff", + "other": "Unkategorisiert", + "power": "Inaktivit\u00e4t und Abschaltung", + "sysconfig": "Grundsystem", + "timesync": "Zeitsynchronisation", + "vmchooser": "vmChooser" } \ No newline at end of file diff --git a/modules-available/baseconfig/lang/de/template-tags.json b/modules-available/baseconfig/lang/de/template-tags.json index de2007d9..1c71e174 100644 --- a/modules-available/baseconfig/lang/de/template-tags.json +++ b/modules-available/baseconfig/lang/de/template-tags.json @@ -1,13 +1,6 @@ { "lang_basicConfiguration": "Basiskonfiguration", - "lang_catUser": "Benutzerverwaltung", "lang_clientRelatedConfig": "Die Optionen auf dieser Seite beziehen sich auf das Verhalten der bwLehrpool-Clients.", - "lang_create": "Schaffen", - "lang_delete": "L\u00f6schen", - "lang_newUser": "Neuer Benutzer", - "lang_partitionMountPoint": "Mount Point", - "lang_reset": "Zur\u00fccksetzen", - "lang_save": "Speichern", - "lang_userName": "Benutzername", - "lang_userPasswd": "Passwort" + "lang_enableOverride": "\u00dcberschreiben", + "lang_reset": "Zur\u00fccksetzen" } \ No newline at end of file diff --git a/modules-available/baseconfig/lang/en/config-variable-categories.json b/modules-available/baseconfig/lang/en/config-variable-categories.json index 7c0ab654..f0324e6b 100644 --- a/modules-available/baseconfig/lang/en/config-variable-categories.json +++ b/modules-available/baseconfig/lang/en/config-variable-categories.json @@ -1,9 +1,8 @@ { - "cat_1": "Inactivity and Shutdown", - "cat_2": "Internet Access", - "cat_3": "Time Synchronization", - "cat_4": "Basic System", - "cat_5": "Common network share", - "cat_6": "Uncategorized", - "cat_7": "vmchooser" + "networking": "Internet Access", + "other": "Uncategorized", + "power": "Inactivity and Shutdown", + "sysconfig": "Basic System", + "timesync": "Time Synchronization", + "vmchooser": "vmChooser" } \ No newline at end of file diff --git a/modules-available/baseconfig/lang/en/template-tags.json b/modules-available/baseconfig/lang/en/template-tags.json index 369fa081..84eb01d7 100644 --- a/modules-available/baseconfig/lang/en/template-tags.json +++ b/modules-available/baseconfig/lang/en/template-tags.json @@ -4,8 +4,7 @@ "lang_catUser": "User Managment", "lang_clientRelatedConfig": "The options on this page are related to the bwLehrpool client machines.", "lang_confirm": "Would you like to save the settings on [ \/srv\/openslx\/www\/boot\/config ] ?", - "lang_create": "Create", - "lang_delete": "Delete", + "lang_enableOverride": "Override", "lang_helpId": "Partition Id", "lang_helpMountPoint": "Must be a directory: \/example\/directory\/", "lang_helpOptions": "Currently, only option 'bootable' is available", @@ -19,7 +18,6 @@ "lang_reset": "Reset", "lang_resetConfirm": "Do you really wish to reset the variable to their default values?", "lang_resetDefault": "Reset Default", - "lang_save": "Save", "lang_userName": "Username", "lang_userPasswd": "Password" } \ No newline at end of file diff --git a/modules-available/baseconfig/lang/pt/config-variable-categories.json b/modules-available/baseconfig/lang/pt/config-variable-categories.json index b04839e8..99819f51 100644 --- a/modules-available/baseconfig/lang/pt/config-variable-categories.json +++ b/modules-available/baseconfig/lang/pt/config-variable-categories.json @@ -1,7 +1,7 @@ { - "cat_1": "Inatividade e Desligamento", - "cat_2": "Acesso \u00e0 Internet", - "cat_3": "Sincroniza\u00e7\u00e3o de Tempo", - "cat_4": "Sistema B\u00e1sico", - "cat_7": "vmchooser" + "networking": "Acesso \u00e0 Internet", + "power": "Inatividade e Desligamento", + "sysconfig": "Sistema B\u00e1sico", + "timesync": "Sincroniza\u00e7\u00e3o de Tempo", + "vmchooser": "vmchooser" } \ No newline at end of file diff --git a/modules-available/baseconfig/lang/pt/template-tags.json b/modules-available/baseconfig/lang/pt/template-tags.json index f6037d65..79e3e911 100644 --- a/modules-available/baseconfig/lang/pt/template-tags.json +++ b/modules-available/baseconfig/lang/pt/template-tags.json @@ -18,7 +18,6 @@ "lang_reset": "Limpar", "lang_resetConfirm": "Voc\u00ea realmente deseja restaurar as vari\u00e1veis para seus valores padr\u00f5es?", "lang_resetDefault": "Restaurar Padr\u00e3o", - "lang_save": "Salvar", "lang_userName": "Nome", "lang_userPasswd": "Senha" } \ No newline at end of file diff --git a/modules-available/baseconfig/page.inc.php b/modules-available/baseconfig/page.inc.php index 356ee2ec..5e209f4e 100644 --- a/modules-available/baseconfig/page.inc.php +++ b/modules-available/baseconfig/page.inc.php @@ -4,61 +4,82 @@ class Page_BaseConfig extends Page { private $qry_extra = array(); + /** + * @var bool|string in case we're in module mode, set to the id of the module + */ + private $targetModule = false; + protected function doPreprocess() { User::load(); - // Determine if we're setting global, distro or location - if (isset($_REQUEST['distroid'])) { - // TODO: Everything - $this->qry_extra[] = array( - 'name' => 'distroid', - 'value' => (int)$_REQUEST['distroid'], - 'table' => 'setting_distro', - ); - if (isset($_REQUEST['locationid'])) { - $this->qry_extra[] = array( - 'name' => 'locationid', - 'value' => (int)$_REQUEST['locationid'], - 'table' => 'setting_location', - ); - } - } + // Determine if we're setting global or module specific + $this->getModuleSpecific(); - if (isset($_POST['setting']) && is_array($_POST['setting'])) { - if (User::hasPermission('superadmin')) { - // Build variables for specific sub-settings + $newValues = Request::post('setting'); + if (is_array($newValues)) { + if (!User::hasPermission('superadmin')) { + Message::addError('main.no-permission'); + Util::redirect('?do=baseconfig'); + } + // Build variables for specific sub-settings + if (empty($this->qry_extra['field'])) { $qry_insert = ''; $qry_values = ''; - foreach ($this->qry_extra as $item) { - $qry_insert = ', ' . $item['name']; - $qry_values = ', :' . $item['name']; + $params = array(); + } else { + $qry_insert = ', ' . $this->qry_extra['field']; + $qry_values = ', :field_value'; + $params = array('field_value' => $this->qry_extra['field_value']); + $delExtra = " AND {$this->qry_extra['field']} = :field_value "; + $delParams = array('field_value' => $this->qry_extra['field_value']); + } + if ($this->targetModule === false) { + $override = false; + } else { + // Not editing global settings + if ($this->getCurrentModuleName() === false) { + Message::addError('main.value-invalid', $this->qry_extra['field'], $this->qry_extra['field_value']); + Util::redirect('?do=BaseConfig'); } - // Load all existing config options to validate input - $res = Database::simpleQuery('SELECT setting, validator FROM setting'); - while ($row = $res->fetch(PDO::FETCH_ASSOC)) { - $key = $row['setting']; - $validator = $row['validator']; - $displayValue = (isset($_POST['setting'][$key]) ? $_POST['setting'][$key] : ''); - // Validate data first! - $mangledValue = Validator::validate($validator, $displayValue); - if ($mangledValue === false) { - Message::addWarning('main.value-invalid', $key, $displayValue); - continue; - } - // Now put into DB - Database::exec("INSERT INTO setting_global (setting, value, displayvalue $qry_insert) - VALUES (:key, :value, :displayvalue $qry_values) - ON DUPLICATE KEY UPDATE value = :value, displayvalue = :displayvalue", - $this->qry_extra + array( - 'key' => $key, - 'value' => $mangledValue, - 'displayvalue' => $displayValue - ) - ); + // Honor override checkbox + $override = Request::post('override', array()); + } + // Load all existing config options to validate input + $vars = BaseConfigUtil::getVariables(); + foreach ($vars as $key => $var) { + if (is_array($override) && (!isset($override[$key]) || $override[$key] !== 'on')) { + // module mode - override not set - delete + $delParams['key'] = $key; + Database::exec("DELETE FROM {$this->qry_extra['table']} WHERE setting = :key $delExtra", $delParams); + continue; } - Message::addSuccess('settings-updated'); + $validator = $var['validator']; + $displayValue = (isset($newValues[$key]) ? $newValues[$key] : ''); + // Validate data first! + $mangledValue = Validator::validate($validator, $displayValue); + if ($mangledValue === false) { + Message::addWarning('main.value-invalid', $key, $displayValue); + continue; + } + // Now put into DB + Database::exec("INSERT INTO {$this->qry_extra['table']} (setting, value, displayvalue $qry_insert)" + . " VALUES (:key, :value, :displayvalue $qry_values)" + . " ON DUPLICATE KEY UPDATE value = :value, displayvalue = :displayvalue", + array( + 'key' => $key, + 'value' => $mangledValue, + 'displayvalue' => $displayValue + ) + $params + ); + } + Message::addSuccess('settings-updated'); + if ($this->targetModule === false) { Util::redirect('?do=BaseConfig'); + } elseif (empty($this->qry_extra['field'])) { + Util::redirect('?do=BaseConfig&module=' . $this->targetModule); + } else { + Util::redirect('?do=BaseConfig&module=' . $this->targetModule . '&' . $this->qry_extra['field'] . '=' . $this->qry_extra['field_value']); } } } @@ -69,31 +90,117 @@ class Page_BaseConfig extends Page Message::addError('main.no-permission'); Util::redirect('?do=Main'); } - // Build left joins for specific settings - $joins = ''; - foreach ($this->qry_extra as $item) { - $joins .= " LEFT JOIN {$item['table']} "; + // Check if valid submodule mode, stire name if any + if ($this->targetModule !== false) { + $this->qry_extra['subheading'] = $this->getCurrentModuleName(); + if ($this->qry_extra['subheading'] === false) { + Message::addError('main.value-invalid', $this->qry_extra['field'], $this->qry_extra['field_value']); + Util::redirect('?do=BaseConfig'); + } } - // List global config option + // List config options $settings = array(); - $res = Database::simpleQuery('SELECT cat_setting.catid, setting.setting, setting.defaultvalue, setting.permissions, setting.validator, tbl.displayvalue - FROM setting - INNER JOIN cat_setting USING (catid) - LEFT JOIN setting_global AS tbl USING (setting) - ORDER BY cat_setting.sortval ASC, setting.setting ASC'); + $vars = BaseConfigUtil::getVariables(); + $cats = BaseConfigUtil::getCategories(); + // Get stuff that's set in DB already + if (isset($this->qry_extra['field'])) { + $where = " WHERE {$this->qry_extra['field']} = :field_value"; + $params = array('field_value' => $this->qry_extra['field_value']); + } else { + $where = ''; + $params = array(); + } + // Populate structure with existing config from db + $res = Database::simpleQuery("SELECT setting, displayvalue FROM {$this->qry_extra['table']} " + . " {$where} ORDER BY setting ASC", $params); while ($row = $res->fetch(PDO::FETCH_ASSOC)) { + if (!isset($vars[$row['setting']]) || !is_array($vars[$row['setting']])) { + $unknown[] = $row['setting']; + continue; + } + $row += $vars[$row['setting']]; $row['description'] = Util::markup(Dictionary::translateFile('config-variables', $row['setting'])); if (is_null($row['displayvalue'])) $row['displayvalue'] = $row['defaultvalue']; $row['item'] = $this->makeInput($row['validator'], $row['setting'], $row['displayvalue']); - $settings[$row['catid']]['settings'][] = $row; - if (!isset($settings[$row['catid']]['category_id'])) { - $settings[$row['catid']]['category_name'] = Dictionary::translateFile('config-variable-categories', 'cat_' . $row['catid']); - $settings[$row['catid']]['category_id'] = $row['catid']; + if (!isset($row['catid'])) { + $row['catid'] = 'unknown'; } + $settings[$row['catid']]['settings'][$row['setting']] = $row; } + // Add entries that weren't in the db (global), setup override checkbox (module specific) + foreach ($vars as $key => $var) { + if (isset($settings[$var['catid']]['settings'][$key])) { + // Value is set in DB + $settings[$var['catid']]['settings'][$key]['checked'] = 'checked'; + continue; + } + // Value is not set in DB + $settings[$var['catid']]['settings'][$key] = $var + array( + 'setting' => $key, + 'item' => $this->makeInput($var['validator'], $key, $var['defaultvalue']) + ); + } + // Sort categories + $sortvals = array(); + foreach ($settings as $catid => &$setting) { + $sortvals[] = isset($cats[$catid]) ? (int)$cats[$catid] : 99999; + $setting['category_id'] = $catid; + $setting['category_name'] = Dictionary::translateFile('config-variable-categories', 'cat_' . $catid); + if ($setting['category_name'] === false) { + $setting['category_name'] = $catid; + } + $setting['settings'] = array_values($setting['settings']); + } + unset($setting); + array_multisort($sortvals, SORT_ASC, SORT_NUMERIC, $settings); Render::addTemplate('_page', array( - 'categories' => array_values($settings) - )); + 'override' => $this->targetModule !== false, + 'categories' => array_values($settings), + 'target_module' => $this->targetModule, + ) + $this->qry_extra); + } + + private function getCurrentModuleName() + { + if (isset($this->qry_extra['tostring'])) { + $method = explode('::', $this->qry_extra['tostring']); + return call_user_func($method, $this->qry_extra['field_value']); + } + if (isset($this->qry_extra['field'])) { + return $this->targetModule . ' // ' . $this->qry_extra['field'] . '=' . $this->qry_extra['field_value']; + } + return $this->targetModule; + } + + private function getModuleSpecific() + { + $module = Request::any('module', '', 'string'); + if ($module === '') { + $this->qry_extra = array( + 'table' => 'setting_global', + ); + return; + } + //\\//\\//\\ + if (!Module::isAvailable($module)) { + Message::addError('main.no-such-module', $module); + Util::redirect('?do=baseconfig'); + } + $file = 'modules/' . $module . '/baseconfig/hook.json'; + if (!file_exists($file)) { + Message::addError('no-module-hook', $module); + Util::redirect('?do=baseconfig'); + } + $hook = json_decode(file_get_contents($file), true); + if (empty($hook['table'])) { + Message::addError('invalid-hook', $module); + Util::redirect('?do=baseconfig'); + } + if (isset($hook['field'])) { + $hook['field_value'] = Request::any($hook['field'], '0', 'string'); + } + $this->targetModule = $module; + $this->qry_extra = $hook; } /** diff --git a/modules-available/baseconfig/templates/_page.html b/modules-available/baseconfig/templates/_page.html index da155ad2..e8b85dd3 100644 --- a/modules-available/baseconfig/templates/_page.html +++ b/modules-available/baseconfig/templates/_page.html @@ -1,6 +1,12 @@

{{lang_basicConfiguration}}

+

{{subheading}}

{{lang_clientRelatedConfig}}

+ + {{#override}} + + + {{/override}}
@@ -15,11 +21,18 @@
{{#settings}} -
+
-
- {{setting}} -
{{defaultvalue}}
+
+
{{setting}}
+ {{^override}} +
+ {{defaultvalue}} +
+ {{/override}} + {{#override}} + + {{/override}}
{{{item}}} @@ -47,139 +60,8 @@
{{/categories}} - - - - -
- -
-
-
- {{#users}} -
-
-
- -
-
- -
- -
-
- {{/users}} -
-
-
-
- - - - Download + + + Download -

-

- - - -
-

- -
- - - -
- -
- - - -
- diff --git a/modules-available/internetaccess/lang/de/messages.json b/modules-available/internetaccess/lang/de/messages.json new file mode 100644 index 00000000..1b075f70 --- /dev/null +++ b/modules-available/internetaccess/lang/de/messages.json @@ -0,0 +1,4 @@ +{ + "settings-updated": "Einstellungen wurden aktualisiert", + "invalid-action": "Ung\u00fcltige Aktion: {{0}}" +} \ No newline at end of file diff --git a/modules-available/internetaccess/lang/en/messages.json b/modules-available/internetaccess/lang/en/messages.json new file mode 100644 index 00000000..6a1af968 --- /dev/null +++ b/modules-available/internetaccess/lang/en/messages.json @@ -0,0 +1,4 @@ +{ + "settings-updated": "Settings have been updated", + "invalid-action": "Invalid action: {{0}}" +} \ No newline at end of file diff --git a/modules-available/internetaccess/lang/pt/messages.json b/modules-available/internetaccess/lang/pt/messages.json new file mode 100644 index 00000000..af5b9b22 --- /dev/null +++ b/modules-available/internetaccess/lang/pt/messages.json @@ -0,0 +1,4 @@ +{ + "settings-updated": "As configura\u00e7\u00f5es foram atualizadas", + "invalid-action": "A\u00e7\u00e3o inv\u00e1lida: {{0}}" +} \ No newline at end of file diff --git a/modules-available/locations/baseconfig/hook.json b/modules-available/locations/baseconfig/hook.json new file mode 100644 index 00000000..c295e0f6 --- /dev/null +++ b/modules-available/locations/baseconfig/hook.json @@ -0,0 +1,5 @@ +{ + "table": "setting_location", + "field": "locationid", + "tostring": "Location::getName" +} \ No newline at end of file diff --git a/modules-available/locations/inc/location.inc.php b/modules-available/locations/inc/location.inc.php new file mode 100644 index 00000000..1a01ff24 --- /dev/null +++ b/modules-available/locations/inc/location.inc.php @@ -0,0 +1,157 @@ +fetch(PDO::FETCH_ASSOC)) { + $rows[] = $row; + } + return $rows; + } + + public static function getName($locationId) + { + self::getLocationsAssoc(); + $locationId = (int)$locationId; + if (!isset(self::$assocLocationCache[$locationId])) + return false; + return self::$assocLocationCache[$locationId]['locationname']; + } + + public static function getLocationsAssoc() + { + if (self::$assocLocationCache === false) { + $rows = self::queryLocations(); + $rows = self::buildTree($rows); + self::$assocLocationCache = self::flattenTreeAssoc($rows); + } + return self::$assocLocationCache; + } + + private static function flattenTreeAssoc($tree, $depth = 0) + { + $output = array(); + foreach ($tree as $node) { + $output[(int)$node['locationid']] = array( + 'parentlocationid' => (int)$node['parentlocationid'], + 'locationname' => $node['locationname'], + 'depth' => $depth + ); + if (!empty($node['children'])) { + $output += self::flattenTreeAssoc($node['children'], $depth + 1); + } + } + return $output; + } + + public static function getLocations($default = 0, $excludeId = 0, $addNoParent = false) + { + if (self::$flatLocationCache === false) { + $rows = self::queryLocations(); + $rows = self::buildTree($rows); + $rows = self::flattenTree($rows); + self::$flatLocationCache = $rows; + } else { + $rows = self::$flatLocationCache; + } + $del = false; + unset($row); + foreach ($rows as $key => &$row) { + if ($del === false && $row['locationid'] == $excludeId) { + $del = $row['depth']; + } elseif ($del !== false && $row['depth'] <= $del) { + $del = false; + } + if ($del !== false) { + unset($rows[$key]); + continue; + } + if ($row['locationid'] == $default) { + $row['selected'] = true; + } + } + if ($addNoParent) { + array_unshift($rows, array( + 'locationid' => 0, + 'locationname' => '-----', + 'selected' => $default == 0 + )); + } + return array_values($rows); + } + + public static function buildTree($elements, $parentId = 0) + { + $branch = array(); + $sort = array(); + foreach ($elements as $element) { + if ($element['locationid'] == 0 || $element['locationid'] == $parentId) + continue; + if ($element['parentlocationid'] == $parentId) { + $children = self::buildTree($elements, $element['locationid']); + if (!empty($children)) { + $element['children'] = $children; + } + $branch[] = $element; + $sort[] = $element['locationname']; + } + } + array_multisort($sort, SORT_ASC, $branch); + return $branch; + } + + private static function flattenTree($tree, $depth = 0) + { + $output = array(); + foreach ($tree as $node) { + $output[] = array( + 'locationid' => $node['locationid'], + 'locationname' => $node['locationname'], + 'locationpad' => str_repeat('--', $depth), + 'locationspan1' => $depth + 1, + 'locationspan2' => 10 - $depth, + 'depth' => $depth + ); + if (!empty($node['children'])) { + $output = array_merge($output, self::flattenTree($node['children'], $depth + 1)); + } + } + return $output; + } + + public static function extractIds($tree) + { + $ids = array(); + foreach ($tree as $node) { + $ids[] = $node['locationid']; + if (!empty($node['children'])) { + $ids = array_merge($ids, self::extractIds($node['children'])); + } + } + return $ids; + } + + public static function getFromIp($ip) + { + $locationId = false; + $long = sprintf('%u', ip2long($ip)); + $net = Database::simpleQuery('SELECT locationid FROM subnet' + . ' WHERE :ip BETWEEN startaddr AND endaddr', array('ip' => $long)); + while ($row = $net->fetch(PDO::FETCH_ASSOC)) { + $locations = self::getLocationsAssoc(); + $id = (int)$row['locationid']; + if (!isset($locations[$id])) continue; + if ($locationId !== false && $locations[$id]['depth'] <= $locations[$locationId]['depth']) continue; + $locationId = $id; + } + return $locationId; + } + +} diff --git a/modules-available/main/lang/de/messages.json b/modules-available/main/lang/de/messages.json index ec645d05..245d4871 100644 --- a/modules-available/main/lang/de/messages.json +++ b/modules-available/main/lang/de/messages.json @@ -1,12 +1,13 @@ { - "no-permission": "Keine ausreichenden Rechte, um auf diese Seite zuzugreifen", - "error-write": "Fehler beim Schreiben von {{0}}", + "debug-mode": "Der Debug-Modus ist aktiv!", "empty-field": "Ein Feld wurde nicht ausgef\u00fcllt", - "value-invalid": "Der Wert {{1}} ist ung\u00fcltig f\u00fcr die Option {{0}} und wurde ignoriert", "error-read": "Fehler beim Lesen von {{0}}", - "taskmanager-error": "Verbindung zum Taskmanager fehlgeschlagen", + "error-write": "Fehler beim Schreiben von {{0}}", + "no-permission": "Keine ausreichenden Rechte, um auf diese Seite zuzugreifen", + "no-such-module": "Modul {{0}} existiert nicht oder ist nicht aktiv", "task-error": "Ausf\u00fchrung fehlgeschlagen: {{0}}", + "taskmanager-error": "Verbindung zum Taskmanager fehlgeschlagen", "taskmanager-format": "Taskmanager hat ung\u00fcltige Daten zur\u00fcckgeliefert", "token": "Ung\u00fcltiges Token. CSRF Angriff?", - "debug-mode": "Der Debug-Modus ist aktiv!" + "value-invalid": "Der Wert {{1}} ist ung\u00fcltig f\u00fcr die Option {{0}} und wurde ignoriert" } \ No newline at end of file diff --git a/modules-available/main/lang/de/template-tags.json b/modules-available/main/lang/de/template-tags.json index 8a3120d3..b299cbad 100644 --- a/modules-available/main/lang/de/template-tags.json +++ b/modules-available/main/lang/de/template-tags.json @@ -19,5 +19,6 @@ "lang_translations": "\u00dcbersetzungen", "lang_vmLocationNotSet": "Es ist noch kein Speicherort f\u00fcr die Virtuellen Maschinen festgelegt.", "lang_warning": "Warnung", + "lang_warningDebug": "Debugmodus aktiv!", "lang_welcome": "Willkommen" } \ No newline at end of file diff --git a/modules-available/main/lang/en/template-tags.json b/modules-available/main/lang/en/template-tags.json index aeebc998..be03e53e 100644 --- a/modules-available/main/lang/en/template-tags.json +++ b/modules-available/main/lang/en/template-tags.json @@ -19,5 +19,6 @@ "lang_translations": "Translations", "lang_vmLocationNotSet": "A location for the virtual machine is not set yet.", "lang_warning": "Warning", + "lang_warningDebug": "Debug mode active!", "lang_welcome": "Welcome" } \ No newline at end of file diff --git a/modules-available/main/lang/pt/global-tags.json b/modules-available/main/lang/pt/global-tags.json index 7c1311ec..a462651b 100644 --- a/modules-available/main/lang/pt/global-tags.json +++ b/modules-available/main/lang/pt/global-tags.json @@ -1,4 +1,5 @@ { "lang_close": "Fechar", - "lang_next": "Pr\u00f3ximo" + "lang_next": "Pr\u00f3ximo", + "lang_save": "Salvar" } \ No newline at end of file -- cgit v1.2.3-55-g7522