summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2019-10-31 15:15:03 +0100
committerSimon Rettberg2019-10-31 15:15:03 +0100
commite18b0b0c764652d6f77465082eb474330f43915b (patch)
tree7f3a3e588cc6a5f6a9d4c1c02a615d1ab3cb1c98
parent[statistics] Don't try to show room plan for non-leaf rooms (diff)
downloadslx-admin-e18b0b0c764652d6f77465082eb474330f43915b.tar.gz
slx-admin-e18b0b0c764652d6f77465082eb474330f43915b.tar.xz
slx-admin-e18b0b0c764652d6f77465082eb474330f43915b.zip
[statistics/baseconfig] Allow per-machine configvar overrides
-rw-r--r--modules-available/baseconfig/inc/validator.inc.php2
-rw-r--r--modules-available/baseconfig/page.inc.php24
-rw-r--r--modules-available/locations/baseconfig/hook.json3
-rw-r--r--modules-available/locations/inc/location.inc.php19
-rw-r--r--modules-available/locations/inc/locationhooks.inc.php31
-rw-r--r--modules-available/statistics/baseconfig/getconfig.inc.php15
-rw-r--r--modules-available/statistics/baseconfig/hook.json7
-rw-r--r--modules-available/statistics/inc/statisticshooks.inc.php37
-rw-r--r--modules-available/statistics/install.inc.php14
-rw-r--r--modules-available/statistics/lang/de/template-tags.json1
-rw-r--r--modules-available/statistics/lang/en/template-tags.json1
-rw-r--r--modules-available/statistics/page.inc.php7
-rw-r--r--modules-available/statistics/templates/machine-main.html13
13 files changed, 141 insertions, 33 deletions
diff --git a/modules-available/baseconfig/inc/validator.inc.php b/modules-available/baseconfig/inc/validator.inc.php
index 2dfeed7c..60cda5a4 100644
--- a/modules-available/baseconfig/inc/validator.inc.php
+++ b/modules-available/baseconfig/inc/validator.inc.php
@@ -47,7 +47,7 @@ class Validator
* Otherwise it it assumed that the value is a plain text
* password that is supposed to be hashed.
*/
- private static function linuxPassword(&$displayValue)
+ private static function linuxPassword($displayValue)
{
if (empty($displayValue))
return '';
diff --git a/modules-available/baseconfig/page.inc.php b/modules-available/baseconfig/page.inc.php
index 837a3b67..0c11d5e1 100644
--- a/modules-available/baseconfig/page.inc.php
+++ b/modules-available/baseconfig/page.inc.php
@@ -23,11 +23,7 @@ class Page_BaseConfig extends Page
$newValues = Request::post('setting');
if (is_array($newValues)) {
- if ($this->targetModule === 'locations') {
- User::assertPermission('edit', $this->qry_extra['field_value']);
- } else {
- User::assertPermission('edit', 0);
- }
+ User::assertPermission('edit', $this->getPermissionLocationId());
// Build variables for specific sub-settings
if ($this->targetModule === false || empty($this->qry_extra['field'])) {
// Global, or Module specific, but module doesn't have an extra field
@@ -118,13 +114,9 @@ class Page_BaseConfig extends Page
Util::redirect('?do=BaseConfig');
}
}
- if ($this->targetModule === 'locations') {
- User::assertPermission('view', $this->qry_extra['field_value']);
- $editForbidden = !User::hasPermission('edit', $this->qry_extra['field_value']);
- } else {
- User::assertPermission('view', 0);
- $editForbidden = !User::hasPermission('edit', 0);
- }
+ $lid = $this->getPermissionLocationId();
+ User::assertPermission('view', $lid);
+ $editForbidden = !User::hasPermission('edit', $lid);
// Get stuff that's set in DB already
if ($this->targetModule !== false && isset($this->qry_extra['field'])) {
$fields = '';
@@ -280,6 +272,14 @@ class Page_BaseConfig extends Page
$this->targetModule = $module;
$this->qry_extra = $hook;
}
+
+ private function getPermissionLocationId()
+ {
+ if (!isset($this->qry_extra['locationResolver']) || !isset($this->qry_extra['field_value']))
+ return 0;
+ $func = explode('::', $this->qry_extra['locationResolver']);
+ return (int)call_user_func($func, $this->qry_extra['field_value']);
+ }
/**
* Create html snippet for setting, based on given validator
diff --git a/modules-available/locations/baseconfig/hook.json b/modules-available/locations/baseconfig/hook.json
index b7b3581b..1d69647e 100644
--- a/modules-available/locations/baseconfig/hook.json
+++ b/modules-available/locations/baseconfig/hook.json
@@ -1,6 +1,7 @@
{
"table": "setting_location",
"field": "locationid",
+ "locationResolver": "LocationHooks::baseconfigLocationResolver",
"tostring": "Location::getName",
- "getfallback": "Location::getBaseconfigParent"
+ "getfallback": "LocationHooks::getBaseconfigParent"
} \ No newline at end of file
diff --git a/modules-available/locations/inc/location.inc.php b/modules-available/locations/inc/location.inc.php
index ac866cbc..a29be5c3 100644
--- a/modules-available/locations/inc/location.inc.php
+++ b/modules-available/locations/inc/location.inc.php
@@ -375,25 +375,6 @@ class Location
}
/**
- * Used for baseconfig hook
- * @param $locationId
- * @return bool|array ('value' => x, 'display' => y), false if no parent or unknown id
- */
- public static function getBaseconfigParent($locationId)
- {
- $locationId = (int)$locationId;
- if (self::$assocLocationCache === false) {
- self::getLocationsAssoc();
- }
- if (!isset(self::$assocLocationCache[$locationId]))
- return false;
- $locationId = (int)self::$assocLocationCache[$locationId]['parentlocationid'];
- if (!isset(self::$assocLocationCache[$locationId]))
- return false;
- return array('value' => $locationId, 'display' => self::$assocLocationCache[$locationId]['locationname']);
- }
-
- /**
* @return array list of subnets as numeric array
*/
public static function getSubnets()
diff --git a/modules-available/locations/inc/locationhooks.inc.php b/modules-available/locations/inc/locationhooks.inc.php
new file mode 100644
index 00000000..c15c34ab
--- /dev/null
+++ b/modules-available/locations/inc/locationhooks.inc.php
@@ -0,0 +1,31 @@
+<?php
+
+class LocationHooks
+{
+
+ /**
+ * Used for baseconfig hook
+ * @param $locationId
+ * @return bool|array ('value' => x, 'display' => y), false if no parent or unknown id
+ */
+ public static function getBaseconfigParent($locationId)
+ {
+ $locationId = (int)$locationId;
+ $assoc = Location::getLocationsAssoc();
+ if (!isset($assoc[$locationId]))
+ return false;
+ $locationId = (int)$assoc[$locationId]['parentlocationid'];
+ if (!isset($assoc[$locationId]))
+ return false;
+ return array('value' => $locationId, 'display' => $assoc[$locationId]['locationname']);
+ }
+
+ /**
+ * Resolve baseconfig id to locationid -- noop in this case
+ */
+ public static function baseconfigLocationResolver($id)
+ {
+ return $id;
+ }
+
+} \ No newline at end of file
diff --git a/modules-available/statistics/baseconfig/getconfig.inc.php b/modules-available/statistics/baseconfig/getconfig.inc.php
new file mode 100644
index 00000000..ea351d15
--- /dev/null
+++ b/modules-available/statistics/baseconfig/getconfig.inc.php
@@ -0,0 +1,15 @@
+<?php
+
+// Location handling: figure out location
+if (Request::any('force', 0, 'int') === 1 && Request::any('module', false, 'string') === 'statistics') {
+ // Force location for testing, but require logged in admin
+ if (User::load()) {
+ $uuid = Request::any('value', '', 'string');
+ }
+}
+
+// Query machine specific settings
+$res = Database::simpleQuery("SELECT setting, value FROM setting_machine WHERE machineuuid = :uuid", ['uuid' => $uuid]);
+while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ ConfigHolder::add($row['setting'], $row['value'], 500);
+}
diff --git a/modules-available/statistics/baseconfig/hook.json b/modules-available/statistics/baseconfig/hook.json
new file mode 100644
index 00000000..da28ad5d
--- /dev/null
+++ b/modules-available/statistics/baseconfig/hook.json
@@ -0,0 +1,7 @@
+{
+ "table": "setting_machine",
+ "field": "machineuuid",
+ "locationResolver": "StatisticsHooks::baseconfigLocationResolver",
+ "tostring": "StatisticsHooks::getBaseconfigName",
+ "getfallback": "StatisticsHooks::getBaseconfigParent"
+} \ No newline at end of file
diff --git a/modules-available/statistics/inc/statisticshooks.inc.php b/modules-available/statistics/inc/statisticshooks.inc.php
new file mode 100644
index 00000000..ead4917b
--- /dev/null
+++ b/modules-available/statistics/inc/statisticshooks.inc.php
@@ -0,0 +1,37 @@
+<?php
+
+class StatisticsHooks
+{
+
+ private static $row = false;
+
+ private static function getRow($machineuuid)
+ {
+ if (self::$row !== false)
+ return;
+ self::$row = Database::queryFirst('SELECT hostname, clientip, locationid FROM machine WHERE machineuuid = :machineuuid',
+ ['machineuuid' => $machineuuid]);
+ }
+
+ public static function getBaseconfigName($machineuuid)
+ {
+ self::getRow($machineuuid);
+ if (self::$row === false)
+ return false;
+ return self::$row['hostname'] ? self::$row['hostname'] : self::$row['clientip'];
+ }
+
+ public static function getBaseconfigParent($machineuuid)
+ {
+ return false; // TODO
+ }
+
+ public static function baseconfigLocationResolver($machineuuid)
+ {
+ self::getRow($machineuuid);
+ if (self::$row === false)
+ return 0;
+ return (int)self::$row['locationid'];
+ }
+
+} \ No newline at end of file
diff --git a/modules-available/statistics/install.inc.php b/modules-available/statistics/install.inc.php
index 2bcb6b8d..2831905d 100644
--- a/modules-available/statistics/install.inc.php
+++ b/modules-available/statistics/install.inc.php
@@ -107,6 +107,16 @@ $res[] = tableCreate('pciid', "
PRIMARY KEY (`category`,`id`)
");
+// baseconfig override per machine
+$res[] = tableCreate('setting_machine', '
+ `machineuuid` char(36) CHARACTER SET ascii NOT NULL,
+ `setting` VARCHAR(28) NOT NULL,
+ `value` TEXT NOT NULL,
+ `displayvalue` TEXT NOT NULL,
+ PRIMARY KEY (`machineuuid`,`setting`),
+ KEY `setting` (`setting`)
+');
+
// need trigger?
if ($machineCreate === UPDATE_DONE) {
$addTrigger = true;
@@ -259,5 +269,9 @@ while ($row = $res2->fetch(PDO::FETCH_ASSOC)) {
}
}
+// 2019-10-31: New table for per-machine config override
+$res[] = tableAddConstraint('setting_machine', 'machineuuid', 'machine', 'machineuuid',
+ 'ON UPDATE CASCADE ON DELETE CASCADE');
+
// Create response
responseFromArray($res);
diff --git a/modules-available/statistics/lang/de/template-tags.json b/modules-available/statistics/lang/de/template-tags.json
index 4b7ab8df..49e5b998 100644
--- a/modules-available/statistics/lang/de/template-tags.json
+++ b/modules-available/statistics/lang/de/template-tags.json
@@ -9,6 +9,7 @@
"lang_biosUpdateLink": "Zur Herstellerseite",
"lang_biosVersion": "BIOS-Version",
"lang_clientList": "Liste ausgew\u00e4hlter Rechner",
+ "lang_configVars": "Konfigurationsvariablen",
"lang_cores": "Kerne",
"lang_cpuCores": "CPU-Kerne",
"lang_cpuModel": "CPU",
diff --git a/modules-available/statistics/lang/en/template-tags.json b/modules-available/statistics/lang/en/template-tags.json
index 08b995cb..c2fb194e 100644
--- a/modules-available/statistics/lang/en/template-tags.json
+++ b/modules-available/statistics/lang/en/template-tags.json
@@ -9,6 +9,7 @@
"lang_biosUpdateLink": "Go to vendor's site",
"lang_biosVersion": "BIOS version",
"lang_clientList": "List of selected machines",
+ "lang_configVars": "Config Variables",
"lang_cores": "Cores",
"lang_cpuCores": "CPU cores",
"lang_cpuModel": "CPU",
diff --git a/modules-available/statistics/page.inc.php b/modules-available/statistics/page.inc.php
index c69198e8..441f0c25 100644
--- a/modules-available/statistics/page.inc.php
+++ b/modules-available/statistics/page.inc.php
@@ -906,6 +906,13 @@ class Page_Statistics extends Page
}
$client['rebootcontrol'] = $client['canReboot'] || $client['canShutdown'];
}
+ // Baseconfig
+ if (Module::get('baseconfig') !== false
+ && User::hasPermission('.baseconfig.view', (int)$client['locationid'])) {
+ $cvs = Database::queryFirst('SELECT Count(*) AS cnt FROM setting_machine WHERE machineuuid = :uuid', ['uuid' => $uuid]);
+ $client['overriddenVars'] = is_array($cvs) ? $cvs['cnt'] : 0;
+ $client['hasBaseconfig'] = true;
+ }
if (!isset($client['isclient'])) {
$client['isclient'] = true;
}
diff --git a/modules-available/statistics/templates/machine-main.html b/modules-available/statistics/templates/machine-main.html
index b1602239..66887499 100644
--- a/modules-available/statistics/templates/machine-main.html
+++ b/modules-available/statistics/templates/machine-main.html
@@ -176,6 +176,19 @@
</td>
</tr>
{{/rebootcontrol}}
+ {{#hasBaseconfig}}
+ <tr>
+ <td class="text-nowrap">
+ {{lang_configVars}}
+ </td>
+ <td>
+ <a class="btn btn-sm btn-default" href="?do=baseconfig&amp;module=statistics&amp;machineuuid={{machineuuid}}">
+ <span class="glyphicon glyphicon-edit"></span>
+ {{lang_edit}} ({{overriddenVars}})
+ </a>
+ </td>
+ </tr>
+ {{/hasBaseconfig}}
</table>
</div>
</div>