summaryrefslogtreecommitdiffstats
path: root/modules-available/runmode
diff options
context:
space:
mode:
authorSimon Rettberg2017-11-30 14:24:55 +0100
committerSimon Rettberg2017-11-30 14:24:55 +0100
commitbb8976c9c16d80dbd677005694a4545f51c570b0 (patch)
treec3ffb5add12b2f205057aae969391bdcb0dd8815 /modules-available/runmode
parent[statistics] Handle runmode and its isclient flag (diff)
downloadslx-admin-bb8976c9c16d80dbd677005694a4545f51c570b0.tar.gz
slx-admin-bb8976c9c16d80dbd677005694a4545f51c570b0.tar.xz
slx-admin-bb8976c9c16d80dbd677005694a4545f51c570b0.zip
[runmode] Overhauled getRunMode with its params
Diffstat (limited to 'modules-available/runmode')
-rw-r--r--modules-available/runmode/inc/runmode.inc.php50
1 files changed, 39 insertions, 11 deletions
diff --git a/modules-available/runmode/inc/runmode.inc.php b/modules-available/runmode/inc/runmode.inc.php
index f3e7f3d5..59f8cf01 100644
--- a/modules-available/runmode/inc/runmode.inc.php
+++ b/modules-available/runmode/inc/runmode.inc.php
@@ -2,6 +2,9 @@
class RunMode
{
+ const DATA_DETAILED = 1;
+ const DATA_MACHINE_DATA = 2;
+ const DATA_STRINGS = 4;
private static $moduleConfigs = array();
@@ -64,23 +67,48 @@ class RunMode
/**
* @param string $machineuuid
- * @param bool $detailed whether to return meta data about machine, not just machineuuid
- * @param bool $assoc use machineuuid as array key
+ * @param int $returnData bitfield of data to return
* @return false|array {'machineuuid', 'isclient', 'module', 'modeid', 'modedata',
* <'hostname', 'clientip', 'macaddr', 'locationid', 'lastseen'>}
*/
- public static function getRunMode($machineuuid, $detailed = false)
+ public static function getRunMode($machineuuid, $returnData = self::DATA_MACHINE_DATA)
{
- if ($detailed) {
- $sel = ', m.hostname, m.clientip, m.macaddr, m.locationid, m.lastseen';
+ if ($returnData === true) {
+ $returnData = self::DATA_MACHINE_DATA | self::DATA_DETAILED;
+ }
+ if ($returnData & self::DATA_MACHINE_DATA) {
+ if ($returnData & self::DATA_DETAILED) {
+ $sel = ', m.hostname, m.clientip, m.macaddr, m.locationid, m.lastseen';
+ } else {
+ $sel = '';
+ }
+ $res = Database::queryFirst(
+ "SELECT m.machineuuid, r.isclient, r.module, r.modeid, r.modedata $sel
+ FROM machine m INNER JOIN runmode r USING (machineuuid)
+ WHERE m.machineuuid = :machineuuid LIMIT 1",
+ compact('machineuuid'));
} else {
- $sel = '';
+ $res = Database::queryFirst('SELECT r.machineuuid, r.isclient, r.module, r.modeid, r.modedata
+ FROM runmode r
+ WHERE r.machineuuid = :machineuuid LIMIT 1',
+ compact('machineuuid'));
+ }
+ if ($res === false)
+ return false;
+ if ($returnData & self::DATA_STRINGS) {
+ $module = Module::get($res['module']);
+ if ($module === false) {
+ $res['moduleName'] = $res['module'];
+ } else {
+ $res['moduleName'] = $module->getDisplayName();
+ }
+ $mode = self::getModeName($res['module'], $res['modeid']);
+ if ($mode === false) {
+ $mode = '???? unknown';
+ }
+ $res['modeName'] = $mode;
}
- return Database::queryFirst(
- "SELECT m.machineuuid, r.isclient, r.module, r.modeid, r.modedata $sel
- FROM machine m INNER JOIN runmode r USING (machineuuid)
- WHERE m.machineuuid = :machineuuid LIMIT 1",
- compact('machineuuid'));
+ return $res;
}
/**