summaryrefslogtreecommitdiffstats
path: root/modules-available/roomplanner
diff options
context:
space:
mode:
Diffstat (limited to 'modules-available/roomplanner')
-rw-r--r--modules-available/roomplanner/baseconfig/getconfig.inc.php15
-rw-r--r--modules-available/roomplanner/clientscript.js40
-rw-r--r--modules-available/roomplanner/config.json2
-rw-r--r--modules-available/roomplanner/hooks/runmode/config.json6
-rw-r--r--modules-available/roomplanner/inc/pvsgenerator.inc.php48
-rw-r--r--modules-available/roomplanner/install.inc.php43
-rw-r--r--modules-available/roomplanner/js/grid.js9
-rw-r--r--modules-available/roomplanner/page.inc.php46
8 files changed, 153 insertions, 56 deletions
diff --git a/modules-available/roomplanner/baseconfig/getconfig.inc.php b/modules-available/roomplanner/baseconfig/getconfig.inc.php
deleted file mode 100644
index aa8721ef..00000000
--- a/modules-available/roomplanner/baseconfig/getconfig.inc.php
+++ /dev/null
@@ -1,15 +0,0 @@
-<?php
-
-ConfigHolder::add("SLX_PVS_CONFIG_URL", 'http://' . $_SERVER['SERVER_ADDR'] . $_SERVER['SCRIPT_NAME'] . '?do=roomplanner');
-
-$res = Database::queryFirst('SELECT dedicatedmgr FROM location_roomplan WHERE managerip = :ip LIMIT 1', ['ip' => $ip]);
-if ($res !== false) {
- if ((int)$res['dedicatedmgr'] !== 0) {
- // TODO: Runmode
- ConfigHolder::add("SLX_PVS_DEDICATED", 'yes');
- ConfigHolder::add("SLX_EXAM", false, 100000);
- ConfigHolder::add("SLX_SYSTEMD_TARGET", false, 100000);
- } else {
- ConfigHolder::add("SLX_PVS_HYBRID", 'yes');
- }
-} \ No newline at end of file
diff --git a/modules-available/roomplanner/clientscript.js b/modules-available/roomplanner/clientscript.js
index 1cd65132..722e3909 100644
--- a/modules-available/roomplanner/clientscript.js
+++ b/modules-available/roomplanner/clientscript.js
@@ -11,10 +11,16 @@ var selectMachinInitialized = false;
var placedMachines = [];
+function makeCombinedFieldSingle(item)
+{
+ item.combined = (item.machineuuid + " " + item.hostname + " " + item.clientip + " " + item.macaddr + " " + item.macaddr.replace(/-/g, ':')).toLocaleLowerCase();
+ item.sortField = (item.fixedlocationid === null ? 'a' : 'z') + item.hostname;
+}
+
function makeCombinedField(machineArray)
{
machineArray.forEach(function (v,i,a){
- machineArray[i].combined = (v.machineuuid + " " + v.hostname + " " + v.clientip + " " + v.macaddr + " " + v.macaddr.replace(/-/g, ':')).toLocaleLowerCase();
+ makeCombinedFieldSingle(machineArray[i]);
});
return machineArray;
}
@@ -25,15 +31,14 @@ function renderMachineEntry(item, escape) {
// console.log('used uuids is ');
// console.log(placedMachines);
- var isUsed = $.inArray(item.machineuuid, placedMachines) > -1;
var extraClass = '';
var extraText = '';
- if (isUsed) {
- extraText = ' (already placed)';
- extraClass = 'used';
- } else if (item.otherroom) {
+ if (item.otherroom) {
extraText = ' (in ' + item.otherroom + ')';
extraClass = 'used';
+ } else if (item.fixedlocationid !== null) {
+ extraText = ' (already placed)';
+ extraClass = 'used';
}
return '<div class="machine-entry ' + extraClass +'">'
//+ ' <div class="machine-logo"><i class="glyphicon glyphicon-hdd"></i></div>'
@@ -120,7 +125,7 @@ function initSelectize() {
render : { option : renderMachineEntry, item: renderMachineSelected},
load: loadMachines,
maxItems: 1,
- sortField: 'hostname',
+ sortField: 'sortField',
sortDirection: 'asc',
onChange: clearSubnetBox
});
@@ -136,7 +141,7 @@ function initSelectize() {
create: false,
render : { option : renderMachineEntry, item: renderMachineSelected},
maxItems: 1,
- sortField: 'hostname',
+ sortField: 'sortField',
sortDirection: 'asc',
onChange: clearSearchBox
});
@@ -148,13 +153,16 @@ function initSelectize() {
}
function onBtnSelect() {
/* check which one has a value */
- console.assert($selectizeSubnet.length == 1);
- console.assert($selectizeSearch.length == 1);
+ console.assert($selectizeSubnet.length === 1);
+ console.assert($selectizeSearch.length === 1);
var bySubnet = machineCache[$selectizeSubnet[0].selectize.getValue()];
var bySearch = machineCache[$selectizeSearch[0].selectize.getValue()];
- var value = (bySubnet === undefined || bySubnet == "") ? bySearch : bySubnet;
+ var value = !bySubnet ? bySearch : bySubnet;
+ value.fixedlocationid = -1;
+ makeCombinedFieldSingle(value);
+
var result = {muuid: value.machineuuid, ip: value.clientip, mac_address : value.macaddr, hostname: value.hostname};
currentCallback(result);
@@ -165,6 +173,14 @@ function onBtnSelect() {
clearSearchBox();
}
+function onPcDelete(muuid) {
+ var bySubnet = machineCache[muuid];
+ var bySearch = machineCache[muuid];
+ var value = !bySubnet ? bySearch : bySubnet;
+ value.fixedlocationid = null;
+ makeCombinedFieldSingle(value);
+}
+
/* to be called from berryous' code */
function selectMachine(usedUuids, callback) {
initSelectize();
@@ -172,7 +188,7 @@ function selectMachine(usedUuids, callback) {
placedMachines = usedUuids;
$modal.modal('show');
$modal.one('hidden.bs.modal', function () {
- if (currentCallback != null) {
+ if (currentCallback) {
currentCallback(false);
}
});
diff --git a/modules-available/roomplanner/config.json b/modules-available/roomplanner/config.json
index f620405a..537714c3 100644
--- a/modules-available/roomplanner/config.json
+++ b/modules-available/roomplanner/config.json
@@ -1,3 +1,3 @@
{
- "dependencies": ["js_jqueryui", "js_selectize", "bootstrap_dialog", "statistics", "locations"]
+ "dependencies": ["js_jqueryui", "js_selectize", "bootstrap_dialog", "statistics", "locations", "runmode"]
}
diff --git a/modules-available/roomplanner/hooks/runmode/config.json b/modules-available/roomplanner/hooks/runmode/config.json
new file mode 100644
index 00000000..0f2ce493
--- /dev/null
+++ b/modules-available/roomplanner/hooks/runmode/config.json
@@ -0,0 +1,6 @@
+{
+ "getModeName": "PvsGenerator::getManagerName",
+ "isClient": false,
+ "configHook": "PvsGenerator::runmodeConfigHook",
+ "allowGenericEditor": false
+} \ No newline at end of file
diff --git a/modules-available/roomplanner/inc/pvsgenerator.inc.php b/modules-available/roomplanner/inc/pvsgenerator.inc.php
index d61e826b..6df7c10e 100644
--- a/modules-available/roomplanner/inc/pvsgenerator.inc.php
+++ b/modules-available/roomplanner/inc/pvsgenerator.inc.php
@@ -54,9 +54,18 @@ class PvsGenerator
/* collect names and build room blocks - filter empty rooms while at it */
$roomNames = array();
$roomBlocks = '';
+ $overrides = [];
foreach ($rooms as $room) {
- if (is_null($room['notnull']) || isset($room['skip']) // Not leaf
- || empty($room['managerip'])) // rooms without managerips don't make sense
+ if (is_null($room['notnull']) || isset($room['skip'])) // Not leaf
+ continue;
+ if (Module::isAvailable('runmode')) {
+ $pc = RunMode::getForMode('roomplanner', $room['locationid']);
+ if (!empty($pc)) {
+ $pc = array_pop($pc);
+ $room['managerip'] = $pc['clientip'];
+ }
+ }
+ if (empty($room['managerip'])) // rooms without managerips don't make sense
continue;
$roomBlock = PvsGenerator::generateRoomBlock($room);
if ($roomBlock === false)
@@ -189,7 +198,7 @@ class PvsGenerator
private static function boundingBox($grid, &$minX, &$minY, &$maxX, &$maxY)
{
- $minX = PHP_INT_MAX; /* PHP_INT_MIN is only avaiable since PHP 7 */
+ $minX = PHP_INT_MAX; /* PHP_INT_MIN is only available since PHP 7 */
$maxX = ~PHP_INT_MAX;
$minY = PHP_INT_MAX;
$maxY = ~PHP_INT_MAX;
@@ -202,4 +211,37 @@ class PvsGenerator
}
}
+ public static function runmodeConfigHook($machineUuid, $locationId, $data)
+ {
+ if (!empty($data)) {
+ $data = json_decode($data, true);
+ }
+ if (!is_array($data)) {
+ $data = array();
+ }
+ ConfigHolder::add("SLX_PVS_CONFIG_URL", 'http://' . $_SERVER['SERVER_ADDR'] . $_SERVER['SCRIPT_NAME'] . '?do=roomplanner');
+
+ if (isset($data['dedicatedmgr']) && $data['dedicatedmgr']) {
+ ConfigHolder::add("SLX_ADDONS", false, 100000);
+ ConfigHolder::add("SLX_PVS_DEDICATED", 'yes');
+ ConfigHolder::add("SLX_EXAM", false, 100000);
+ ConfigHolder::add("SLX_AUTOLOGIN", 'ON', 100000);
+ } else {
+ ConfigHolder::add("SLX_PVS_HYBRID", 'yes');
+ }
+ }
+
+ /**
+ * Get display name for manager of given locationId.
+ * @param $locationId
+ * @return bool|string
+ */
+ public static function getManagerName($locationId)
+ {
+ $names = Location::getNameChain($locationId);
+ if ($names === false)
+ return false;
+ return implode(' / ', $names);
+ }
+
}
diff --git a/modules-available/roomplanner/install.inc.php b/modules-available/roomplanner/install.inc.php
index a6d98384..13365fe1 100644
--- a/modules-available/roomplanner/install.inc.php
+++ b/modules-available/roomplanner/install.inc.php
@@ -6,7 +6,6 @@ $res = array();
$res[] = tableCreate('location_roomplan', "
`locationid` INT(11) NOT NULL,
`managerip` varchar(45) CHARACTER SET ascii DEFAULT '',
- `dedicatedmgr` tinyint(1) NOT NULL DEFAULT 0,
`tutoruuid` char(36) CHARACTER SET ascii DEFAULT NULL,
`roomplan` BLOB DEFAULT NULL,
PRIMARY KEY (`locationid`),
@@ -29,24 +28,40 @@ if (!tableHasColumn('location_roomplan', 'tutoruuid')) {
}
$res[] = UPDATE_DONE;
}
-if (!tableHasColumn('location_roomplan', 'dedicatedmgr')) {
- $ret = Database::exec("ALTER TABLE `location_roomplan` ADD `dedicatedmgr` tinyint(1) NOT NULL DEFAULT 0 AFTER `managerip`") !== false;
- if ($ret === false) {
- finalResponse(UPDATE_FAILED, 'Adding dedicatedmgr to location_roomplan failed: ' . Database::lastError());
- }
- $res[] = UPDATE_DONE;
-}
if (in_array(UPDATE_DONE, $res)) {
Database::exec("ALTER TABLE `location_roomplan`
- ADD CONSTRAINT `location_roomplan_ibfk_1` FOREIGN KEY (`locationid`) REFERENCES `location` (`locationid`) ON DELETE CASCADE");
+ ADD CONSTRAINT `location_roomplan_ibfk_1` FOREIGN KEY (`locationid`) REFERENCES `location` (`locationid`) ON DELETE CASCADE");
Database::exec("ALTER TABLE `location_roomplan`
- ADD CONSTRAINT `location_roomplan_ibfk_2` FOREIGN KEY (`tutoruuid`) REFERENCES `machine` (`machineuuid`) ON DELETE SET NULL ON UPDATE CASCADE");
+ ADD CONSTRAINT `location_roomplan_ibfk_2` FOREIGN KEY (`tutoruuid`) REFERENCES `machine` (`machineuuid`) ON DELETE SET NULL ON UPDATE CASCADE");
}
-if (in_array(UPDATE_DONE, $res)) {
- finalResponse(UPDATE_DONE, 'Table created successfully');
+// 2017-11-30: Refactor to runmode
+// managerip, dedicatedmgr, --> runmode
+if (tableHasColumn('location_roomplan', 'dedicatedmgr')) {
+ if (!tableExists('runmode') || !tableExists('machine')) {
+ $res[] = UPDATE_RETRY;
+ } else {
+ $ret = Database::simpleQuery('SELECT lr.locationid, lr.managerip, lr.dedicatedmgr, m.machineuuid
+ FROM location_roomplan lr INNER JOIN machine m ON (m.clientip = lr.managerip)');
+ if ($ret === false) {
+ $res[] = UPDATE_FAILED;
+ } else {
+ while ($row = $ret->fetch(PDO::FETCH_ASSOC)) {
+ $dedi = $row['dedicatedmgr'] != 0;
+ $data = json_encode(array('dedicatedmgr' => $dedi));
+ Database::exec("INSERT IGNORE INTO runmode (machineuuid, module, modeid, modedata, isclient)
+ VALUES (:machineuuid, 'roomplanner', :locationid, :modedata, :isclient)", array(
+ 'machineuuid' => $row['machineuuid'],
+ 'locationid' => $row['locationid'],
+ 'modedata' => $data,
+ 'isclient' => ($dedi ? 0 : 1)
+ ));
+ }
+ Database::exec('ALTER TABLE location_roomplan DROP COLUMN dedicatedmgr');
+ $res[] = UPDATE_DONE;
+ }
+ }
}
-finalResponse(UPDATE_NOOP, 'Everything already up to date');
-
+responseFromArray($res);
diff --git a/modules-available/roomplanner/js/grid.js b/modules-available/roomplanner/js/grid.js
index 334057bf..466e42aa 100644
--- a/modules-available/roomplanner/js/grid.js
+++ b/modules-available/roomplanner/js/grid.js
@@ -74,10 +74,13 @@ if (!roomplanner) var roomplanner = {
initDelete: function(el) {
$(el).append('<div class="deleteHandle glyphicon glyphicon-remove-sign"></div>');
$(el).find('.deleteHandle').click(function() {
- if ($(this).parent().attr('itemtype') == "pc") {
+ if ($(this).parent().attr('itemtype') === "pc") {
var self = this;
BootstrapDialog.confirm(__('are you sure'),function(result) {
if (result) {
+ if (onPcDelete) {
+ onPcDelete($(self).parent().attr('muuid'));
+ }
$(self).parent().remove();
}
});
@@ -169,8 +172,8 @@ if (!roomplanner) var roomplanner = {
var mw = $(this).resizable("option","maxWidth");
var mh = $(this).resizable("option","maxHeight");
- var hLimit = ($(this).attr('scalable') == 'v');
- var vLimit = ($(this).attr('scalable') == 'h');
+ var hLimit = ($(this).attr('scalable') === 'v');
+ var vLimit = ($(this).attr('scalable') === 'h');
if(collides.length) {
$(collides).each(function(idx,item) {
diff --git a/modules-available/roomplanner/page.inc.php b/modules-available/roomplanner/page.inc.php
index 4e36d3ba..bae9db7b 100644
--- a/modules-available/roomplanner/page.inc.php
+++ b/modules-available/roomplanner/page.inc.php
@@ -58,7 +58,17 @@ class Page_Roomplanner extends Page
if ($this->action === 'show') {
/* do nothing */
Dashboard::disable();
- $config = Database::queryFirst('SELECT roomplan, managerip, dedicatedmgr, tutoruuid FROM location_roomplan WHERE locationid = :locationid', ['locationid' => $this->locationid]);
+ $config = Database::queryFirst('SELECT roomplan, managerip, tutoruuid FROM location_roomplan WHERE locationid = :locationid', ['locationid' => $this->locationid]);
+ $runmode = RunMode::getForMode(Page::getModule(), $this->locationid, true);
+ if (empty($runmode)) {
+ $config['dedicatedmgr'] = false;
+ } else {
+ $runmode = array_pop($runmode);
+ $config['managerip'] = $runmode['clientip'];
+ $config['manageruuid'] = $runmode['machineuuid'];
+ $data = json_decode($runmode['modedata'], true);
+ $config['dedicatedmgr'] = (isset($data['dedicatedmgr']) && $data['dedicatedmgr']);
+ }
if ($config !== false) {
$managerIp = $config['managerip'];
$dediMgr = $config['dedicatedmgr'] ? 'checked' : '';
@@ -90,7 +100,7 @@ class Page_Roomplanner extends Page
$query = Request::get('query', false, 'string');
$aquery = preg_replace('/[^\x01-\x7f]+/', '%', $query);
- $result = Database::simpleQuery('SELECT machineuuid, macaddr, clientip, hostname '
+ $result = Database::simpleQuery('SELECT machineuuid, macaddr, clientip, hostname, fixedlocationid '
. 'FROM machine '
. 'WHERE machineuuid LIKE :aquery '
. ' OR macaddr LIKE :aquery '
@@ -101,6 +111,9 @@ class Page_Roomplanner extends Page
$returnObject = ['machines' => []];
while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
+ if (empty($row['hostname'])) {
+ $row['hostname'] = $row['clientip'];
+ }
$returnObject['machines'][] = $row;
}
echo json_encode($returnObject);
@@ -207,16 +220,30 @@ class Page_Roomplanner extends Page
protected function saveRoomConfig($furniture, $tutorUuid)
{
$obj = json_encode(['furniture' => $furniture]);
- Database::exec('INSERT INTO location_roomplan (locationid, roomplan, managerip, tutoruuid, dedicatedmgr)'
- . ' VALUES (:locationid, :roomplan, :managerip, :tutoruuid, :dedicatedmgr)'
+ $managerIp = Request::post('managerip', '', 'string');
+ Database::exec('INSERT INTO location_roomplan (locationid, roomplan, managerip, tutoruuid)'
+ . ' VALUES (:locationid, :roomplan, :managerip, :tutoruuid)'
. ' ON DUPLICATE KEY UPDATE '
- . ' roomplan=VALUES(roomplan), managerip=VALUES(managerip), tutoruuid=VALUES(tutoruuid), dedicatedmgr=VALUES(dedicatedmgr)', [
+ . ' roomplan=VALUES(roomplan), managerip=VALUES(managerip), tutoruuid=VALUES(tutoruuid)', [
'locationid' => $this->locationid,
'roomplan' => $obj,
- 'managerip' => Request::post('managerip', '', 'string'),
- 'dedicatedmgr' => (Request::post('dedimgr') === 'on' ? 1 : 0),
+ 'managerip' => $managerIp,
'tutoruuid' => $tutorUuid
]);
+ // See if the client is known, set run-mode
+ if (empty($managerIp)) {
+ RunMode::deleteMode(Page::getModule(), $this->locationid);
+ } else {
+ RunMode::deleteMode(Page::getModule(), $this->locationid);
+ $pc = Statistics::getMachinesByIp($managerIp, Machine::NO_DATA, 'lastseen DESC');
+ if (!empty($pc)) {
+ $dedicated = (Request::post('dedimgr') === 'on');
+ $pc = array_shift($pc);
+ RunMode::setRunMode($pc->machineuuid, Page::getModule()->getIdentifier(), $this->locationid, json_encode([
+ 'dedicatedmgr' => $dedicated
+ ]), !$dedicated);
+ }
+ }
}
protected function getFurniture($config)
@@ -262,7 +289,7 @@ class Page_Roomplanner extends Page
protected function getPotentialMachines()
{
- $result = Database::simpleQuery('SELECT m.machineuuid, m.macaddr, m.clientip, m.hostname, l.locationname AS otherroom
+ $result = Database::simpleQuery('SELECT m.machineuuid, m.macaddr, m.clientip, m.hostname, l.locationname AS otherroom, m.fixedlocationid
FROM machine m
LEFT JOIN location l ON (m.fixedlocationid = l.locationid AND m.subnetlocationid <> m.fixedlocationid)
WHERE subnetlocationid = :locationid', ['locationid' => $this->locationid]);
@@ -270,6 +297,9 @@ class Page_Roomplanner extends Page
$machines = [];
while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
+ if (empty($row['hostname'])) {
+ $row['hostname'] = $row['clientip'];
+ }
$machines[] = $row;
}