From 317db874e7964231ac33b5646cc33b1b400a4f29 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Fri, 19 Feb 2016 15:01:56 +0100 Subject: [locations] New module for managing locations --- apis/getconfig.inc.php | 56 ++++++++++++++++++++++++++++++++++++++++++++++++-- apis/update.inc.php | 38 ++++++++++++++++++++++++++++++++-- 2 files changed, 90 insertions(+), 4 deletions(-) (limited to 'apis') diff --git a/apis/getconfig.inc.php b/apis/getconfig.inc.php index 5d5dbca8..2447d622 100644 --- a/apis/getconfig.inc.php +++ b/apis/getconfig.inc.php @@ -1,5 +1,10 @@ fetch(PDO::FETCH_ASSOC)) { + $tmp[(int)$row['locationid']][$row['setting']] = $row['value']; + } + // $matchingLocations contains the location ids sorted from closest to furthest, so we use it to make sure the order + // in which they override is correct (closest setting wins, e.g. room setting beats department setting) + foreach ($matchingLocations as $lid) { + if (!isset($tmp[$lid])) continue; + foreach ($tmp[$lid] as $setting => $value) { + if (!isset($configVars[$setting])) { + $configVars[$setting] = $value; + } + } + } + unset($tmp); +} + // Dump config from DB $res = Database::simpleQuery('SELECT setting.setting, setting.defaultvalue, tbl.value FROM setting LEFT JOIN setting_global AS tbl USING (setting) ORDER BY setting ASC'); // TODO: Add setting groups and sort order while ($row = $res->fetch(PDO::FETCH_ASSOC)) { - if (is_null($row['value'])) $row['value'] = $row['defaultvalue']; + if (isset($configVars[$row['setting']])) { + $row['value'] = $configVars[$row['setting']]; + } elseif (is_null($row['value'])) { + $row['value'] = $row['defaultvalue']; + } echo $row['setting'] . "='" . escape($row['value']) . "'\n"; } @@ -47,6 +98,7 @@ if (is_array($vmstore)) { } } + // 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'); \ No newline at end of file +if (file_exists('client_config_additional.php')) @include('client_config_additional.php'); diff --git a/apis/update.inc.php b/apis/update.inc.php index a7212961..0c91ab2d 100644 --- a/apis/update.inc.php +++ b/apis/update.inc.php @@ -52,6 +52,7 @@ if ($list === false) { Message::addSuccess('db-update-done'); if (tableExists('eventlog')) EventLog::info("Database updated to version $currentVersion"); +DefaultData::populate(); Util::redirect('index.php?do=Main'); //////////////// @@ -256,7 +257,7 @@ function update_10() } Database::exec("CREATE TABLE IF NOT EXISTS `machine` ( `machineuuid` char(36) CHARACTER SET ascii NOT NULL, - `roomid` int(10) unsigned DEFAULT NULL, + `locationid` int(11) DEFAULT NULL, `macaddr` char(17) CHARACTER SET ascii NOT NULL, `clientip` varchar(45) CHARACTER SET ascii NOT NULL, `firstseen` int(10) unsigned NOT NULL, @@ -281,10 +282,43 @@ function update_10() KEY `mbram` (`mbram`), KEY `kvmstate` (`kvmstate`), KEY `id44mb` (`id44mb`), - KEY `roomid` (`roomid`), + KEY `locationid` (`locationid`), KEY `lastseen` (`lastseen`), KEY `cpumodel` (`cpumodel`), KEY `systemmodel` (`systemmodel`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8"); return true; } + +function update_11() +{ + if (tableHasColumn('machine', 'roomid')) { + Database::exec("ALTER TABLE `machine` CHANGE `roomid` `locationid` INT(11) DEFAULT NULL"); + } + Database::exec("CREATE TABLE IF NOT EXISTS `setting_location` ( + `locationid` int(11) NOT NULL, + `setting` varchar(28) NOT NULL, + `value` text NOT NULL, + `displayvalue` text NOT NULL, + PRIMARY KEY (`locationid`,`setting`), + KEY `setting` (`setting`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8"); + Database::exec("CREATE TABLE IF NOT EXISTS `location` ( + `locationid` int(11) NOT NULL AUTO_INCREMENT, + `parentlocationid` int(11) NOT NULL, + `locationname` varchar(100) NOT NULL, + PRIMARY KEY (`locationid`), + KEY `locationname` (`locationname`), + KEY `parentlocationid` (`parentlocationid`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8;"); + Database::exec("CREATE TABLE IF NOT EXISTS `subnet` ( + `subnetid` int(11) NOT NULL AUTO_INCREMENT, + `startaddr` decimal(39,0) unsigned NOT NULL, + `endaddr` decimal(39,0) unsigned NOT NULL, + `locationid` int(11) NOT NULL, + PRIMARY KEY (`subnetid`), + KEY `startaddr` (`startaddr`,`endaddr`), + KEY `locationid` (`locationid`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8;"); + return true; +} \ No newline at end of file -- cgit v1.2.3-55-g7522