From 3601ceb43aaa9f85c8036ee465a99c9aedaff1c3 Mon Sep 17 00:00:00 2001 From: Udo Walter Date: Wed, 10 Jan 2018 16:46:13 +0100 Subject: [locations] fixed root location not getting disabled in the dropdown if the user does not have permisson for location 0 --- modules-available/locations/page.inc.php | 1 - 1 file changed, 1 deletion(-) (limited to 'modules-available/locations/page.inc.php') diff --git a/modules-available/locations/page.inc.php b/modules-available/locations/page.inc.php index 0cfa5b90..9112e810 100644 --- a/modules-available/locations/page.inc.php +++ b/modules-available/locations/page.inc.php @@ -446,7 +446,6 @@ class Page_Locations extends Page } $addAllowedLocs = User::getAllowedLocations("location.add"); - $addAllowedLocs[] = 0; $addAllowedList = Location::getLocations(0, 0, true); foreach ($addAllowedList as &$loc) { if (!in_array($loc["locationid"], $addAllowedLocs)) { -- cgit v1.2.3-55-g7522 From 8aebf6191f0942b6e0fbdc5b07f8069a68d3ee70 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Wed, 14 Feb 2018 13:18:47 +0100 Subject: [locations] One permission for direct subnet editing; restructure handling a bit --- modules-available/locations/inc/location.inc.php | 2 +- modules-available/locations/page.inc.php | 217 ++++++++++----------- .../locations/permissions/permissions.json | 22 +-- .../locations/templates/location-subnets.html | 33 ++-- .../locations/templates/locations.html | 30 +-- 5 files changed, 150 insertions(+), 154 deletions(-) (limited to 'modules-available/locations/page.inc.php') diff --git a/modules-available/locations/inc/location.inc.php b/modules-available/locations/inc/location.inc.php index 0576e660..d43c36a7 100644 --- a/modules-available/locations/inc/location.inc.php +++ b/modules-available/locations/inc/location.inc.php @@ -251,7 +251,7 @@ class Location { $ids = array(); foreach ($tree as $node) { - $ids[] = $node['locationid']; + $ids[] = (int)$node['locationid']; if (!empty($node['children'])) { $ids = array_merge($ids, self::extractIds($node['children'])); } diff --git a/modules-available/locations/page.inc.php b/modules-available/locations/page.inc.php index 9112e810..ed541876 100644 --- a/modules-available/locations/page.inc.php +++ b/modules-available/locations/page.inc.php @@ -28,6 +28,7 @@ class Page_Locations extends Page private function updateSubnets() { + User::assertPermission('subnets.edit', NULL, '?do=locations'); $count = 0; $starts = Request::post('startaddr', false); $ends = Request::post('endaddr', false); @@ -47,12 +48,6 @@ class Page_Locations extends Page Message::addError('main.value-invalid', 'locationid', $loc); continue; } - - $oldLoc = Database::queryFirst("SELECT locationid FROM subnet WHERE subnetid = :subnetid", array("subnetid" => $subnetid))["locationid"]; - if (($loc == $oldLoc && !User::hasPermission("subnet.edit", $loc)) || - ($loc != $oldLoc && (!User::hasPermission("subnet.delete", $oldLoc) || !User::hasPermission("subnet.add", $loc)))) - continue; - $range = $this->rangeToLongVerbose($start, $end); if ($range === false) continue; @@ -63,7 +58,7 @@ class Page_Locations extends Page } AutoLocation::rebuildAll(); Message::addSuccess('subnets-updated', $count); - Util::redirect('?do=Locations&action=showsubnets'); + Util::redirect('?do=Locations'); } private function addLocations() @@ -81,8 +76,10 @@ class Page_Locations extends Page if (empty($name)) continue; $parent = isset($parents[$idx]) ? (int)$parents[$idx] : 0; - if (!User::hasPermission("location.add", $parent)) + if (!User::hasPermission("location.add", $parent)) { + Message::addError('no-permission-location', isset($locs[$parent]) ? $locs[$parent]['locationname'] : $parent); continue; + } if ($parent !== 0) { $ok = false; foreach ($locs as $loc) { @@ -123,24 +120,16 @@ class Page_Locations extends Page $change = false; // Delete location? if ($locationId === $del) { - if (!User::hasPermission("location.delete", $locationId)) { - Message::addError('main.no-permission', 'locationid', $locationId); - Util::redirect('?do=Locations'); - } + User::assertPermission("location.delete", $locationId, '?do=locations'); $this->deleteLocation($location); $change = true; } // Update subnets $change |= $this->updateLocationSubnets(); - - if (User::hasPermission("subnet.add", $locationId)) { - // Insert subnets - $change |= $this->addNewLocationSubnets($location); - } - if (User::hasPermission("location.edit", $locationId)) { - // Update location! - $change |= $this->updateLocationData($location); - } + // Insert subnets + $change |= $this->addNewLocationSubnets($location); + // Update location! + $change |= $this->updateLocationData($location); if ($change) { // In case subnets or tree layout changed, recalc this @@ -176,13 +165,17 @@ class Page_Locations extends Page $locationId = (int)$location['locationid']; $newParent = Request::post('parentlocationid', false, 'integer'); $newName = Request::post('locationname', false, 'string'); - if ($newName === false || preg_match('/^\s*$/', $newName)) { + if (!User::hasPermission('location.edit.name', $locationId)) { + $newName = $location['locationname']; + } elseif ($newName === false || preg_match('/^\s*$/', $newName)) { if ($newName !== false) { Message::addWarning('main.value-invalid', 'location name', $newName); } $newName = $location['locationname']; } - if ($newParent === false) { + if ($newParent === false || !User::hasPermission('location.edit.parent', $locationId) + || !User::hasPermission('location.edit.parent', $newParent) + || !User::hasPermission('location.edit.*', $location['parentlocationid'])) { $newParent = $location['parentlocationid']; } else if ($newParent !== 0) { $rows = Location::queryLocations(); @@ -213,13 +206,15 @@ class Page_Locations extends Page private function updateLocationSubnets() { - $change = false; - $locationId = Request::post('locationid', false, 'integer'); + if (!User::hasPermission('location.edit.subnets', $locationId)) + return false; + + $change = false; // Deletion first $dels = Request::post('deletesubnet', false); - if (is_array($dels) && User::hasPermission("subnet.delete", $locationId)) { + if (is_array($dels)) { $count = 0; $stmt = Database::prepare('DELETE FROM subnet WHERE subnetid = :id'); foreach ($dels as $key => $value) { @@ -234,8 +229,6 @@ class Page_Locations extends Page $change = true; } } - if (!User::hasPermission("subnet.edit", $locationId)) - return $change; // Now actual updates $starts = Request::post('startaddr', false); @@ -267,8 +260,11 @@ class Page_Locations extends Page private function addNewLocationSubnets($location) { - $change = false; $locationId = (int)$location['locationid']; + if (!User::hasPermission('location.edit.subnets', $locationId)) + return false; + + $change = false; $starts = Request::post('newstartaddr', false); $ends = Request::post('newendaddr', false); if (!is_array($starts) || !is_array($ends)) { @@ -316,28 +312,16 @@ class Page_Locations extends Page Util::redirect('?do=Locations&action=showlocations'); } if ($getAction === 'showsubnets') { - $res = Database::simpleQuery("SELECT subnetid, startaddr, endaddr, locationid FROM subnet - WHERE locationid IN (:locations) ORDER BY startaddr ASC", - array("locations" => User::getAllowedLocations("location.view"))); - $allowedLocs = User::getAllowedLocations("subnet.add"); + User::assertPermission('subnets.edit', NULL, '?do=locations'); + $res = Database::simpleQuery("SELECT subnetid, startaddr, endaddr, locationid FROM subnet"); $rows = array(); while ($row = $res->fetch(PDO::FETCH_ASSOC)) { $row['startaddr'] = long2ip($row['startaddr']); $row['endaddr'] = long2ip($row['endaddr']); $row['locations'] = Location::getLocations($row['locationid']); - - foreach ($row['locations'] as &$loc) { - if (!(in_array($loc["locationid"], $allowedLocs) || $loc["locationid"] == $row['locationid'])) { - $loc["disabled"] = "disabled"; - } - } - - $row['editThisSubnetAllowed'] = User::hasPermission("subnet.edit", $row['locationid']); - $row['deleteThisSubnetAllowed'] = User::hasPermission("subnet.delete", $row['locationid']); $rows[] = $row; } - - Render::addTemplate('subnets', array('list' => $rows, 'editSubnetAllowed' => User::hasPermission("subnet.edit"))); + Render::addTemplate('subnets', array('list' => $rows)); } elseif ($getAction === 'showlocations') { $this->showLocationList(); } @@ -349,38 +333,59 @@ class Page_Locations extends Page $overlapSelf = $overlapOther = true; Location::getOverlappingSubnets($overlapSelf, $overlapOther); //$locs = Location::getLocations(0, 0, false, true); - $locs = Location::getLocationsAssoc(); + $locationList = Location::getLocationsAssoc(); // Statistics: Count machines for each subnet $unassigned = false; + + // Filter view: Remove locations we can't reach at all, but show parents to locations + // we have permission to, so the tree doesn't look all weird + $visibleLocationIds = $allowedLocationIds = User::getAllowedLocations("location.view"); + foreach ($allowedLocationIds as $lid) { + $visibleLocationIds = array_merge($visibleLocationIds, $locationList[$lid]['parents']); + } + $visibleLocationIds = array_unique($visibleLocationIds); + foreach (array_keys($locationList) as $lid) { + if (!in_array($lid, $visibleLocationIds)) { + unset($locationList[$lid]); + } elseif (!in_array($lid, $allowedLocationIds)) { + $locationList[$lid]['show-only'] = true; + } + } + + // Client statistics if (Module::get('statistics') !== false) { - $DL = time() - 605; $unassigned = 0; - $res = Database::simpleQuery("SELECT locationid, Count(*) AS cnt, Sum(If(lastseen > $DL AND logintime <> 0, 1, 0)) AS used - FROM machine GROUP BY locationid"); + $res = Database::simpleQuery("SELECT locationid, Count(*) AS cnt, Sum(If(state = 'OCCUPIED', 1, 0)) AS used + FROM machine WHERE locationid IN (:allowedLocationIds) GROUP BY locationid", compact('allowedLocationIds')); while ($row = $res->fetch(PDO::FETCH_ASSOC)) { - $loc = (int)$row['locationid']; - if (isset($locs[$loc])) { - $locs[$loc]['clientCount'] = $row['cnt']; - $locs[$loc]['clientLoad'] = round(100 * $row['used'] / $row['cnt']) . '%'; + $locId = (int)$row['locationid']; + if (isset($locationList[$locId])) { + $locationList[$locId]['clientCount'] = $row['cnt']; + $locationList[$locId]['clientLoad'] = round(100 * $row['used'] / $row['cnt']) . '%'; } else { $unassigned += $row['cnt']; } } unset($loc); - foreach ($locs as &$loc) { + foreach ($locationList as &$loc) { + if (!in_array($loc['locationid'], $allowedLocationIds)) + continue; + if (!isset($loc['clientCountSum'])) { + $loc['clientCountSum'] = 0; + } if (!isset($loc['clientCount'])) { $loc['clientCount'] = 0; $loc['clientLoad'] = '0%'; + $loc['clientCountSum'] += $loc['clientCount']; } - $loc['clientCountSum'] = $loc['clientCount']; - } - unset($loc); - foreach ($locs as $loc) { foreach ($loc['parents'] as $pid) { - $locs[(int)$pid]['hasChild'] = true; - $locs[(int)$pid]['clientCountSum'] += $loc['clientCount']; + if (!in_array($pid, $allowedLocationIds)) + continue; + $locationList[(int)$pid]['hasChild'] = true; + $locationList[(int)$pid]['clientCountSum'] += $loc['clientCount']; } } + unset($loc); } // Show currently active sysconfig for each location $defaultConfig = false; @@ -390,18 +395,18 @@ class Page_Locations extends Page if (strlen($conf['locs']) === 0) continue; $confLocs = explode(',', $conf['locs']); - foreach ($confLocs as $loc) { - settype($loc, 'int'); - if ($loc === 0) { + foreach ($confLocs as $locId) { + settype($locId, 'int'); + if ($locId === 0) { $defaultConfig = $conf['title']; } - if (!isset($locs[$loc])) + if (!isset($locationList[$locId])) continue; - $locs[$loc] += array('configName' => $conf['title'], 'configClass' => 'slx-bold'); + $locationList[$locId] += array('configName' => $conf['title'], 'configClass' => 'slx-bold'); } } $depth = array(); - foreach ($locs as &$loc) { + foreach ($locationList as &$loc) { $d = $loc['depth']; if (!isset($loc['configName'])) { // Has no explicit config assignment @@ -419,32 +424,16 @@ class Page_Locations extends Page } // Count overridden config vars if (Module::get('baseconfig') !== false) { - $res = Database::simpleQuery("SELECT locationid, Count(*) AS cnt FROM `setting_location` GROUP BY locationid"); + $res = Database::simpleQuery("SELECT locationid, Count(*) AS cnt FROM `setting_location` + WHERE locationid IN (:allowedLocationIds) GROUP BY locationid", compact('allowedLocationIds')); while ($row = $res->fetch(PDO::FETCH_ASSOC)) { $lid = (int)$row['locationid']; - if (isset($locs[$lid])) { - $locs[$lid]['overriddenVars'] = $row['cnt']; + if (isset($locationList[$lid])) { + $locationList[$lid]['overriddenVars'] = $row['cnt']; } } } - $allowedLocs = User::getAllowedLocations("location.view"); - $withParents = array(); - foreach ($allowedLocs as $loc) { - $withParents = array_merge($withParents, Location::getLocationRootChain($loc)); - } - - foreach ($locs as $key => $loc) { - if (!in_array($loc["locationid"], $withParents)) { - unset($locs[$key]); - } elseif (!in_array($loc["locationid"], $allowedLocs)) { - $id = $locs[$key]["locationid"]; - $name = $locs[$key]["locationname"]; - $depth = $locs[$key]["depth"]; - $locs[$key] = array("locationid" => $id, "locationname" => $name, "depth" => $depth, "linkClass" => "not-allowed"); - } - } - $addAllowedLocs = User::getAllowedLocations("location.add"); $addAllowedList = Location::getLocations(0, 0, true); foreach ($addAllowedList as &$loc) { @@ -452,10 +441,11 @@ class Page_Locations extends Page $loc["disabled"] = "disabled"; } } + unset($loc); // Output - Render::addTemplate('locations', array( - 'list' => array_values($locs), + $data = array( + 'list' => array_values($locationList), 'havestatistics' => Module::get('statistics') !== false, 'havebaseconfig' => Module::get('baseconfig') !== false, 'havesysconfig' => Module::get('sysconfig') !== false, @@ -465,9 +455,12 @@ class Page_Locations extends Page 'haveOverlapOther' => !empty($overlapOther), 'unassignedCount' => $unassigned, 'defaultConfig' => $defaultConfig, - 'addAllowed' => User::hasPermission("location.add"), - 'addAllowedList' => array_values($addAllowedList) - )); + 'addAllowedList' => array_values($addAllowedList), + ); + // TODO: Buttons for config vars and sysconfig are currently always shown, as their availability + // depends on permissions in the according modules, not this one + Permission::addGlobalTags($data['perms'], NULL, ['subnets.edit', 'location.add']); + Render::addTemplate('locations', $data); } /* @@ -515,11 +508,16 @@ class Page_Locations extends Page 'parents' => Location::getLocations($loc['parentlocationid'], $locationId, true) ); - $allowedLocs = User::getAllowedLocations("location.edit"); - $allowedLocs[] = 0; - foreach ($data['parents'] as &$parent) { - if (!(in_array($parent["locationid"], $allowedLocs) || $parent["locationid"] == $loc['parentlocationid'])) { - $parent["disabled"] = "disabled"; + // Disable locations in the parent selector where the user cannot change to + if (!User::hasPermission('location.edit.*', $loc['parentlocationid']) + || !User::hasPermission('location.edit.parent', $locationId)) { + $allowedLocs = []; + } else { + $allowedLocs = User::getAllowedLocations("location.edit.*"); + foreach ($data['parents'] as &$parent) { + if (!(in_array($parent["locationid"], $allowedLocs) || $parent["locationid"] == $loc['parentlocationid'])) { + $parent["disabled"] = "disabled"; + } } } @@ -533,16 +531,16 @@ class Page_Locations extends Page // Get clients matching this location's subnet(s) $count = $online = $used = 0; if (Module::get('statistics') !== false) { - $mres = Database::simpleQuery("SELECT lastseen, logintime FROM machine" + $mres = Database::simpleQuery("SELECT state FROM machine" . " WHERE machine.locationid = :lid", array('lid' => $locationId)); - $DL = time() - 605; while ($row = $mres->fetch(PDO::FETCH_ASSOC)) { $count++; - if ($row['lastseen'] > $DL) { + if ($row['state'] === 'IDLE') { $online++; - if ($row['logintime'] != 0) { - $used++; - } + } + if ($row['state'] === 'OCCUPIED') { + $online++; + $used++; } } $data['haveStatistics'] = true; @@ -553,18 +551,13 @@ class Page_Locations extends Page $data['used_percent'] = $count === 0 ? 0 : round(($used / $count) * 100); - $data['havebaseconfig'] = Module::get('baseconfig') !== false; - $data['havesysconfig'] = Module::get('sysconfig') !== false; - $data['editAllowed'] = User::hasPermission("location.edit", $locationId); - $data['deleteAllowed'] = User::hasPermission("location.delete", $locationId); - $data['editSubnetAllowed'] = User::hasPermission("subnet.edit", $locationId); - $data['deleteSubnetAllowed'] = User::hasPermission("subnet.delete", $locationId); - $data['addSubnetAllowed'] = User::hasPermission("subnet.add", $locationId); - $data['saveButton'] = $data['editAllowed'] || $data['editSubnetAllowed'] || $data['deleteSubnetAllowed'] || $data['addSubnetAllowed']; + Permission::addGlobalTags($data['perms'], $locationId, ['location.edit.name', 'location.edit.subnets', 'location.delete', '.roomplanner.edit'], 'save_button'); + if (empty($allowedLocs)) { + $data['perms']['location']['edit']['parent']['disabled'] = 'disabled'; + } else { + unset($data['perms']['save_button']); + } - // echo '
';
-		// var_dump($data);
-		// echo '
'; echo Render::parse('location-subnets', $data); } diff --git a/modules-available/locations/permissions/permissions.json b/modules-available/locations/permissions/permissions.json index 06b01d2c..18b24a73 100644 --- a/modules-available/locations/permissions/permissions.json +++ b/modules-available/locations/permissions/permissions.json @@ -1,23 +1,23 @@ { "location.add": { - "location-aware": false + "location-aware": true }, "location.delete": { - "location-aware": false + "location-aware": true }, - "location.edit": { - "location-aware": false + "location.edit.name": { + "location-aware": true }, - "location.view": { - "location-aware": false + "location.edit.subnets": { + "location-aware": true }, - "subnet.add": { - "location-aware": false + "location.edit.parent": { + "location-aware": true }, - "subnet.delete": { - "location-aware": false + "location.view": { + "location-aware": true }, - "subnet.edit": { + "subnets.edit": { "location-aware": false } } \ No newline at end of file diff --git a/modules-available/locations/templates/location-subnets.html b/modules-available/locations/templates/location-subnets.html index 2cc8e98b..9db75f0b 100644 --- a/modules-available/locations/templates/location-subnets.html +++ b/modules-available/locations/templates/location-subnets.html @@ -8,17 +8,17 @@
-
+
{{lang_name}} - +
{{lang_parentLocation}} - {{#parents}} {{/parents}} @@ -40,11 +40,11 @@ {{#list}} {{subnetid}} - - + +
- +
@@ -52,7 +52,7 @@ {{/list}} - @@ -74,19 +74,16 @@ {{/haveStatistics}}
-
- {{#roomplanner}} - - {{lang_editRoomplan}} - - {{/roomplanner}} -
- + {{#roomplanner}} + + {{lang_editRoomplan}} + + {{/roomplanner}}
- - + +
diff --git a/modules-available/locations/templates/locations.html b/modules-available/locations/templates/locations.html index be3d5115..cd04b1c8 100644 --- a/modules-available/locations/templates/locations.html +++ b/modules-available/locations/templates/locations.html @@ -1,7 +1,13 @@

{{lang_locationsMainHeading}}

@@ -36,10 +42,17 @@
- {{locationname}}{{^linkClass}} {{/linkClass}} + {{#show-only}} + {{locationname}} + {{/show-only}} + {{^show-only}} + + {{locationname}} + + + {{/show-only}} - {{^linkClass}} {{#havestatistics}}  {{clientCount}}  @@ -48,17 +61,13 @@ {{/hasChild}} {{/havestatistics}} - {{/linkClass}} - {{^linkClass}} {{#havestatistics}} {{clientLoad}} {{/havestatistics}} - {{/linkClass}} - {{^linkClass}} {{#havebaseconfig}}
@@ -67,10 +76,8 @@ {{lang_overrideCount}}: {{overriddenVars}}   {{/overriddenVars}} {{/havebaseconfig}} - {{/linkClass}} - {{^linkClass}} {{#havesysconfig}}
@@ -79,7 +86,6 @@ {{configName}}   {{/havesysconfig}} - {{/linkClass}} {{/list}} @@ -106,7 +112,7 @@   -
- +

@@ -86,6 +86,8 @@ function updateShadows(e) { if (!rules) return; var currentValue = $(e).val(); for (var triggerVal in rules) { + if (!rules.hasOwnProperty(triggerVal)) + continue; var targets = rules[triggerVal]; for (var i = 0; i < targets.length; ++i) { var target = targets[i]; @@ -95,11 +97,11 @@ function updateShadows(e) { if (currentValue === triggerVal) { inp.prop('disabled', true); if (selitem) selitem.disable(); - $('#' + target + '.multilist').multiselect('disable'); + inp.filter('.multiselect').multiselect('disable'); } else { inp.prop('disabled', false); if (selitem) selitem.enable(); - $('#' + target + '.multilist').multiselect('enable'); + inp.filter('.multiselect').multiselect('enable'); } } } @@ -125,6 +127,7 @@ document.addEventListener("DOMContentLoaded", function () { buttonWidth: '100%', buttonClass: 'form-control' }); + $('select.multiselect').filter(':disabled').multiselect('disable'); /* data-shadowing bindings */ var $allShadowingFields = $('[data-shadows]'); diff --git a/modules-available/locations/page.inc.php b/modules-available/locations/page.inc.php index c4328b1b..08f9b518 100644 --- a/modules-available/locations/page.inc.php +++ b/modules-available/locations/page.inc.php @@ -347,6 +347,16 @@ class Page_Locations extends Page } $visibleLocationIds = array_unique($visibleLocationIds); foreach (array_keys($locationList) as $lid) { + if (User::hasPermission('.baseconfig.view', $lid)) { + $visibleLocationIds[] = $lid; + } else { + $locationList[$lid]['havebaseconfig'] = false; + } + if (User::hasPermission('.sysconfig.config.view-list', $lid)) { + $visibleLocationIds[] = $lid; + } else { + $locationList[$lid]['havesysconfig'] = false; + } if (!in_array($lid, $visibleLocationIds)) { unset($locationList[$lid]); } elseif (!in_array($lid, $allowedLocationIds)) { -- cgit v1.2.3-55-g7522 From 873d6af8bc843c6eea6049ace2f5218a371f01d4 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Tue, 27 Feb 2018 17:02:40 +0100 Subject: [roomplanner] Add permissions --- modules-available/locations/page.inc.php | 4 +- .../locations/templates/location-subnets.html | 6 +- .../roomplanner/hooks/runmode/config.json | 3 +- modules-available/roomplanner/js/grid.js | 85 ++--- modules-available/roomplanner/page.inc.php | 45 ++- .../roomplanner/permissions/permissions.json | 11 +- modules-available/roomplanner/style.css | 3 + .../roomplanner/templates/footer.html | 59 ++++ .../roomplanner/templates/header.html | 49 +++ .../roomplanner/templates/item-selector.html | 314 ++++++++++++++++++ .../roomplanner/templates/main-roomplan.html | 18 + modules-available/roomplanner/templates/page.html | 369 --------------------- 12 files changed, 534 insertions(+), 432 deletions(-) create mode 100644 modules-available/roomplanner/templates/footer.html create mode 100644 modules-available/roomplanner/templates/header.html create mode 100644 modules-available/roomplanner/templates/item-selector.html create mode 100644 modules-available/roomplanner/templates/main-roomplan.html delete mode 100644 modules-available/roomplanner/templates/page.html (limited to 'modules-available/locations/page.inc.php') diff --git a/modules-available/locations/page.inc.php b/modules-available/locations/page.inc.php index 08f9b518..0a6fdb10 100644 --- a/modules-available/locations/page.inc.php +++ b/modules-available/locations/page.inc.php @@ -495,9 +495,7 @@ class Page_Locations extends Page { $locationId = Request::any('locationid', 0, 'integer'); - if (!User::hasPermission("location.view", $locationId)) { - die('Permission denied'); - } + User::assertPermission("location.view", $locationId); $loc = Database::queryFirst('SELECT locationid, parentlocationid, locationname FROM location WHERE locationid = :lid', array('lid' => $locationId)); diff --git a/modules-available/locations/templates/location-subnets.html b/modules-available/locations/templates/location-subnets.html index 9db75f0b..db94be0a 100644 --- a/modules-available/locations/templates/location-subnets.html +++ b/modules-available/locations/templates/location-subnets.html @@ -75,9 +75,11 @@
diff --git a/modules-available/roomplanner/hooks/runmode/config.json b/modules-available/roomplanner/hooks/runmode/config.json index 27c601fd..3cbf4a6c 100644 --- a/modules-available/roomplanner/hooks/runmode/config.json +++ b/modules-available/roomplanner/hooks/runmode/config.json @@ -3,5 +3,6 @@ "isClient": false, "configHook": "PvsGenerator::runmodeConfigHook", "allowGenericEditor": false, - "deleteUrlSnippet": "locationid=" + "deleteUrlSnippet": "locationid=", + "permission": ".roomplanner.edit" } \ No newline at end of file diff --git a/modules-available/roomplanner/js/grid.js b/modules-available/roomplanner/js/grid.js index 466e42aa..ced76678 100644 --- a/modules-available/roomplanner/js/grid.js +++ b/modules-available/roomplanner/js/grid.js @@ -1,5 +1,9 @@ +var $gridInner = $('#draw-element-area'); +var $gridFrame = $('#drawpanel'); +var $grid = $('#drawarea'); + if (!roomplanner) var roomplanner = { - + getScaleFactor: function() { return this.settings.scale/100; }, @@ -280,7 +284,7 @@ if (!roomplanner) var roomplanner = { "computers": [] }; - var furniture = $('#draw-element-area div[itemtype="furniture"]'); + var furniture = $gridInner.find('div[itemtype="furniture"]'); furniture.each(function(idx,el) { objects.furniture.push({ "gridRow" : $(el).attr('gridRow'), @@ -291,7 +295,7 @@ if (!roomplanner) var roomplanner = { }); }); - var computers = $('#draw-element-area div[itemtype="pc"]'); + var computers = $gridInner.find('div[itemtype="pc"]'); computers.each(function(idx,el) { var object = { @@ -326,7 +330,7 @@ if (!roomplanner) var roomplanner = { var objects = object; } - $('#draw-element-area').html(''); + $gridInner.html(''); function itemToHtml(item, itemtype, obstacle) { var html = '
maxX) return; - var width = (maxX - minX) / $('#drawpanel .panel-body').width(); - var height = (maxY - minY) / $('#drawpanel .panel-body').height(); + var width = (maxX - minX) / $gridFrame.find('.panel-body').width(); + var height = (maxY - minY) / $gridFrame.find('.panel-body').height(); var scale; if (width > height) { scale = Math.floor(100 / width); @@ -461,7 +470,7 @@ roomplanner.fitContent = function() { top: -(minY * (scale / 100)) + "px" }; - $('#drawarea').css(opts); + $grid.css(opts); }; $(document).ready(function(){ @@ -480,12 +489,12 @@ $(document).ready(function(){ change: update, slide: update, stop: function(e, ui) { - $('#drawarea').trigger('checkposition'); + $grid.trigger('checkposition'); } }); - $('#drawarea').bind('checkposition', function() { + $grid.bind('checkposition', function() { if ($(this).offset().left > 0) { $(this).css('left',0); } @@ -502,7 +511,7 @@ $(document).ready(function(){ } }); - $('#drawarea').draggable({ + $grid.draggable({ stop: function() { $(this).trigger('checkposition'); } @@ -512,7 +521,7 @@ $(document).ready(function(){ * adds droppable functionality to the draw area for the elements. * drop event is only fired for elements added to the board from the toolbar. */ - $('#draw-element-area').droppable({ + $gridInner.droppable({ accept: ".draggable", drop: function(event, ui) { @@ -528,8 +537,8 @@ $(document).ready(function(){ if (ui.helper != ui.draggable) { - var leftPos = parseInt($(el).css('left'))-parseInt($('#drawarea').css('left'))-$('#drawpanel').offset().left; - var topPos = parseInt($(el).css('top'))-parseInt($('#drawarea').css('top'))-($('#drawpanel').offset().top + $('#drawpanel .panel-heading').height()); + var leftPos = parseInt($(el).css('left'))-parseInt($grid.css('left'))-$gridFrame.offset().left; + var topPos = parseInt($(el).css('top'))-parseInt($grid.css('top'))-($gridFrame.offset().top + $gridFrame.find('.panel-heading').height()); var cp = roomplanner.getCellPositionFromPixels(leftPos,topPos); leftPos = cp[0]; topPos = cp[1]; @@ -575,8 +584,8 @@ $(document).ready(function(){ $(el).css('opacity',1); if (ui.helper != ui.draggable) { - var l = parseInt($(el).css('left'))-parseInt($('#drawarea').css('left'))-$('#drawpanel').offset().left; - var t = parseInt($(el).css('top'))-parseInt($('#drawarea').css('top'))-($('#drawpanel').offset().top + $('#drawpanel .panel-heading').height()); + var l = parseInt($(el).css('left'))-parseInt($grid.css('left'))-$gridFrame.offset().left; + var t = parseInt($(el).css('top'))-parseInt($grid.css('top'))-($gridFrame.offset().top + $gridFrame.find('.panel-heading').height()); var cp = roomplanner.getCellPositionFromPixels(l,t); $(el).css('left',cp[0]); $(el).css('top',cp[1]); @@ -596,7 +605,7 @@ $(document).ready(function(){ if ($(el).attr('itemtype') == "pc") { var uuids = []; - var computers = $('#draw-element-area div[itemtype="pc"]'); + var computers = $gridInner.find('div[itemtype="pc"]'); computers.each(function(idx,el) { if ($(el).attr('muuid')) { uuids.push($(el).attr('muuid')); diff --git a/modules-available/roomplanner/page.inc.php b/modules-available/roomplanner/page.inc.php index 764d5cdb..2712560a 100644 --- a/modules-available/roomplanner/page.inc.php +++ b/modules-available/roomplanner/page.inc.php @@ -30,7 +30,7 @@ class Page_Roomplanner extends Page { User::load(); - if (!User::hasPermission('superadmin')) { + if (!User::isLoggedIn()) { Message::addError('main.no-permission'); Util::redirect('?do=Main'); } @@ -79,13 +79,22 @@ class Page_Roomplanner extends Page $subnetMachines = $this->getPotentialMachines(); $machinesOnPlan = $this->getMachinesOnPlan($config['tutoruuid']); $roomConfig = array_merge($furniture, $machinesOnPlan); - Render::addTemplate('page', [ + $canEdit = User::hasPermission('edit', $this->locationid); + $params = [ 'location' => $this->location, 'managerip' => $managerIp, 'dediMgrChecked' => $dediMgr, 'subnetMachines' => json_encode($subnetMachines), 'locationid' => $this->locationid, - 'roomConfiguration' => json_encode($roomConfig)]); + 'roomConfiguration' => json_encode($roomConfig), + 'edit_disabled' => $canEdit ? '' : 'disabled' + ]; + Render::addTemplate('header', $params); + if ($canEdit) { + Render::addTemplate('item-selector', $params); + } + Render::addTemplate('main-roomplan', $params); + Render::addTemplate('footer', $params); } else { Message::addError('main.invalid-action', $this->action); } @@ -97,16 +106,30 @@ class Page_Roomplanner extends Page $this->action = Request::any('action', false, 'string'); if ($this->action === 'getmachines') { + + $locations = User::getAllowedLocations('edit'); + if (empty($locations)) { + die('{"machines":[]}'); + } + $query = Request::get('query', false, 'string'); $aquery = preg_replace('/[^\x01-\x7f]+/', '%', $query); + if (strlen(str_replace('%', '', $aquery)) < 2) { + $aquery = $query; + } + + $condition = 'locationid IN (:locations)'; + if (in_array(0, $locations)) { + $condition .= ' OR locationid IS NULL'; + } - $result = Database::simpleQuery('SELECT machineuuid, macaddr, clientip, hostname, fixedlocationid ' - . 'FROM machine ' - . 'WHERE machineuuid LIKE :aquery ' - . ' OR macaddr LIKE :aquery ' - . ' OR clientip LIKE :aquery ' - . ' OR hostname LIKE :query ' - . ' LIMIT 100', ['query' => "%$query%", 'aquery' => "%$aquery%"]); + $result = Database::simpleQuery("SELECT machineuuid, macaddr, clientip, hostname, fixedlocationid + FROM machine + WHERE ($condition) AND machineuuid LIKE :aquery + OR macaddr LIKE :aquery + OR clientip LIKE :aquery + OR hostname LIKE :query + LIMIT 100", ['query' => "%$query%", 'aquery' => "%$aquery%", 'locations' => $locations]); $returnObject = ['machines' => []]; @@ -134,7 +157,7 @@ class Page_Roomplanner extends Page private function handleSaveRequest($isAjax) { - /* save */ + User::assertPermission('edit', $this->locationid); $machinesOnPlan = $this->getMachinesOnPlan('invalid'); $config = Request::post('serializedRoom', null, 'string'); $config = json_decode($config, true); diff --git a/modules-available/roomplanner/permissions/permissions.json b/modules-available/roomplanner/permissions/permissions.json index f7bc3479..6a520a89 100644 --- a/modules-available/roomplanner/permissions/permissions.json +++ b/modules-available/roomplanner/permissions/permissions.json @@ -1,10 +1,5 @@ { - "compilerOptions": { - "module": "commonjs", - "target": "es5", - "sourceMap": true - }, - "exclude": [ - "node_modules" - ] + "edit": { + "location-aware": true + } } \ No newline at end of file diff --git a/modules-available/roomplanner/style.css b/modules-available/roomplanner/style.css index 6a68a444..9359f82b 100644 --- a/modules-available/roomplanner/style.css +++ b/modules-available/roomplanner/style.css @@ -715,6 +715,9 @@ div.draggable:hover .deleteHandle { display:inline; cursor: pointer;} +.draggable.disabled { + pointer-events: none; +} [itemtype="furniture"], [itemtype="furniture_drag"] { z-index: 99; diff --git a/modules-available/roomplanner/templates/footer.html b/modules-available/roomplanner/templates/footer.html new file mode 100644 index 00000000..6e4e0783 --- /dev/null +++ b/modules-available/roomplanner/templates/footer.html @@ -0,0 +1,59 @@ +
+
+
{{lang_managerIp}}
+ +
+ + +
+
+
+
+ + +
+
+ + + diff --git a/modules-available/roomplanner/templates/header.html b/modules-available/roomplanner/templates/header.html new file mode 100644 index 00000000..5706c970 --- /dev/null +++ b/modules-available/roomplanner/templates/header.html @@ -0,0 +1,49 @@ + + + + +

{{lang_roomplanner}} – {{location.locationname}}

+ + + + \ No newline at end of file diff --git a/modules-available/roomplanner/templates/item-selector.html b/modules-available/roomplanner/templates/item-selector.html new file mode 100644 index 00000000..72607e7c --- /dev/null +++ b/modules-available/roomplanner/templates/item-selector.html @@ -0,0 +1,314 @@ +
+
+ +
+
+
    +
  • +
    +
  • +
  • +
    +
  • +
  • +
    +
  • +
  • +
    +
  • + + +
  • +
    +
  • +
  • +
    +
  • +
  • +
    +
  • +
  • +
    +
  • +
  • +
    +
  • +
  • +
    +
  • +
  • +
    +
  • +
  • +
    +
  • + +
+
+ + +
+
    +
  • +
    +
  • +
  • +
    +
  • +
  • +
    +
  • +
  • +
    +
  • +
+
+ +
+
    +
  • +
    +
  • +
  • +
    +
  • +
  • +
    +
  • +
+
+ +
+
    +
  • +
    +
  • +
  • +
    +
  • +
  • +
    +
  • + +
  • +
    +
  • +
  • +
    +
  • +
  • +
    +
  • +
  • +
    +
  • + +
  • +
    +
  • + + +
  • +
    +
  • +
  • +
    +
  • +
  • +
    +
  • +
  • +
    +
  • +
  • +
    +
  • +
  • +
    +
  • + + +
+ +
+ +
+
    +
  • +
    +
  • +
  • +
    +
  • +
  • +
    +
  • + + +
  • +
    +
  • +
  • +
    +
  • + +
  • +
    +
  • +
+
+ +
+
    +
  • +
    +
  • +
  • +
    +
  • + +
  • +
    +
  • +
  • +
    +
  • + + +
  • +
    +
  • +
  • +
    +
  • + +
+
+ +
+
    +
  • +
    +
  • +
  • +
    +
  • + +
+
+
+
    +
  • +
    +
  • +
  • +
    +
  • +
  • +
    +
  • +
+
+
+
    +
  • +
    +
  • +
+
+ +
+
+
\ No newline at end of file diff --git a/modules-available/roomplanner/templates/main-roomplan.html b/modules-available/roomplanner/templates/main-roomplan.html new file mode 100644 index 00000000..1fc49bea --- /dev/null +++ b/modules-available/roomplanner/templates/main-roomplan.html @@ -0,0 +1,18 @@ +
+
+

{{lang_roomplan}}

+
+
+
+
+
+
+ +
+
+ + +
+
+
+
\ No newline at end of file diff --git a/modules-available/roomplanner/templates/page.html b/modules-available/roomplanner/templates/page.html deleted file mode 100644 index e8544ce8..00000000 --- a/modules-available/roomplanner/templates/page.html +++ /dev/null @@ -1,369 +0,0 @@ - - - - -

{{lang_roomplanner}} – {{location.locationname}}

- - - - - -
-
- -
-
-
    -
  • -
    -
  • -
  • -
    -
  • -
  • -
    -
  • -
  • -
    -
  • - - -
  • -
    -
  • -
  • -
    -
  • -
  • -
    -
  • -
  • -
    -
  • -
  • -
    -
  • -
  • -
    -
  • -
  • -
    -
  • -
  • -
    -
  • - -
-
- - -
-
    -
  • -
    -
  • -
  • -
    -
  • -
  • -
    -
  • -
  • -
    -
  • -
-
- -
-
    -
  • -
    -
  • -
  • -
    -
  • -
  • -
    -
  • -
-
- -
-
    -
  • -
    -
  • -
  • -
    -
  • -
  • -
    -
  • - -
  • -
    -
  • -
  • -
    -
  • -
  • -
    -
  • -
  • -
    -
  • - -
  • -
    -
  • - - -
  • -
    -
  • -
  • -
    -
  • -
  • -
    -
  • -
  • -
    -
  • -
  • -
    -
  • -
  • -
    -
  • - - -
- -
- -
-
    -
  • -
    -
  • -
  • -
    -
  • -
  • -
    -
  • - - -
  • -
    -
  • -
  • -
    -
  • - -
  • -
    -
  • -
-
- -
-
    -
  • -
    -
  • -
  • -
    -
  • - -
  • -
    -
  • -
  • -
    -
  • - - -
  • -
    -
  • -
  • -
    -
  • - -
-
- -
-
    -
  • -
    -
  • -
  • -
    -
  • - -
-
-
-
    -
  • -
    -
  • -
  • -
    -
  • -
  • -
    -
  • -
-
-
-
    -
  • -
    -
  • -
-
- -
-
-
- - - -
-
-

{{lang_roomplan}}

-
-
-
-
-
-
- -
-
- - -
-
-
- - -
- -
-
-
{{lang_managerIp}}
- -
-
-
-
- - -
-
- - - -- cgit v1.2.3-55-g7522 From afee61496e9fa59d9e024339530b38c6652bba59 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Wed, 28 Mar 2018 14:55:54 +0200 Subject: [locations] Handle statistics permissions when showing/linking machine stats --- modules-available/locations/page.inc.php | 11 +++++++++++ modules-available/locations/templates/location-subnets.html | 9 ++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) (limited to 'modules-available/locations/page.inc.php') diff --git a/modules-available/locations/page.inc.php b/modules-available/locations/page.inc.php index 0a6fdb10..80a8076b 100644 --- a/modules-available/locations/page.inc.php +++ b/modules-available/locations/page.inc.php @@ -357,6 +357,11 @@ class Page_Locations extends Page } else { $locationList[$lid]['havesysconfig'] = false; } + if (User::hasPermission('.statistics.view.list', $lid)) { + $visibleLocationIds[] = $lid; + } else { + $locationList[$lid]['havestatistics'] = false; + } if (!in_array($lid, $visibleLocationIds)) { unset($locationList[$lid]); } elseif (!in_array($lid, $allowedLocationIds)) { @@ -554,6 +559,12 @@ class Page_Locations extends Page } } $data['haveStatistics'] = true; + // Link + if (User::hasPermission('.statistics.view.list')) { + $data['statsLink'] = 'list'; + } elseif (User::hasPermission('.statistics.view.summary')) { + $data['statsLink'] = 'summary'; + } } $data['machines'] = $count; $data['machines_online'] = $online; diff --git a/modules-available/locations/templates/location-subnets.html b/modules-available/locations/templates/location-subnets.html index db94be0a..69e369c2 100644 --- a/modules-available/locations/templates/location-subnets.html +++ b/modules-available/locations/templates/location-subnets.html @@ -69,7 +69,14 @@ {{/haveDozmod}} {{#haveStatistics}}
- {{lang_matchingMachines}}: {{machines}} / {{machines_online}} / {{machines_used}} ({{used_percent}}%) + {{lang_matchingMachines}}: + {{#statsLink}} + + {{/statsLink}} + {{machines}} / {{machines_online}} / {{machines_used}} ({{used_percent}}%) + {{#statsLink}} + + {{/statsLink}}
{{/haveStatistics}}
-- cgit v1.2.3-55-g7522 From 24815e16087b4b1b64e9f380d45d411af32daf42 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Mon, 9 Apr 2018 16:56:04 +0200 Subject: Permissions: Consistency: Make all pages require at least one permission to be accessible Closes #3340 --- modules-available/backup/page.inc.php | 1 + modules-available/exams/page.inc.php | 9 +-------- modules-available/locations/page.inc.php | 19 +++++++++++++++---- modules-available/news/page.inc.php | 10 ++-------- modules-available/news/permissions/permissions.json | 3 +++ modules-available/rebootcontrol/page.inc.php | 9 ++++++--- modules-available/serversetup-bwlp/page.inc.php | 6 ++++++ .../serversetup-bwlp/permissions/permissions.json | 3 +++ modules-available/statistics_reporting/page.inc.php | 1 + modules-available/sysconfig/page.inc.php | 2 +- modules-available/syslog/page.inc.php | 1 + modules-available/systemstatus/page.inc.php | 1 + modules-available/webinterface/page.inc.php | 4 ++++ .../webinterface/permissions/permissions.json | 3 +++ 14 files changed, 48 insertions(+), 24 deletions(-) (limited to 'modules-available/locations/page.inc.php') diff --git a/modules-available/backup/page.inc.php b/modules-available/backup/page.inc.php index 14522734..985f39ee 100644 --- a/modules-available/backup/page.inc.php +++ b/modules-available/backup/page.inc.php @@ -23,6 +23,7 @@ class Page_Backup extends Page User::assertPermission("restore"); $this->restore(); } + User::assertPermission('*'); } protected function doRender() diff --git a/modules-available/exams/page.inc.php b/modules-available/exams/page.inc.php index 51975052..15640a73 100644 --- a/modules-available/exams/page.inc.php +++ b/modules-available/exams/page.inc.php @@ -441,16 +441,9 @@ class Page_Exams extends Page protected function doRender() { - if (Request::isPost()) { - $examid = Request::post('examid', 0, 'int'); - } else if (Request::isGet()) { - $examid = Request::get('examid', 0, 'int'); - } else { - die('Neither Post nor Get Request send.'); - } - if ($this->action === "show") { + User::assertPermission('exams.view'); // General title and description Render::addTemplate('page-main-heading'); // List of defined exam periods diff --git a/modules-available/locations/page.inc.php b/modules-available/locations/page.inc.php index 80a8076b..4d5c6628 100644 --- a/modules-available/locations/page.inc.php +++ b/modules-available/locations/page.inc.php @@ -24,6 +24,9 @@ class Page_Locations extends Page } elseif ($this->action === 'updatesubnets') { $this->updateSubnets(); } + if (Request::isPost()) { + Util::redirect('?do=locations'); + } } private function updateSubnets() @@ -306,10 +309,16 @@ class Page_Locations extends Page protected function doRender() { - $getAction = Request::get('action'); - if (empty($getAction)) { - // Until we have a main landing page? - Util::redirect('?do=Locations&action=showlocations'); + $getAction = Request::get('action', false, 'string'); + if ($getAction === false) { + if (User::hasPermission('location.view')) { + Util::redirect('?do=locations&action=showlocations'); + } elseif (User::hasPermission('subnets.edit')) { + Util::redirect('?do=locations&action=showsubnets'); + } else { + // Trigger permission denied by asserting non-existent permission + User::assertPermission('location.view'); + } } if ($getAction === 'showsubnets') { User::assertPermission('subnets.edit', NULL, '?do=locations'); @@ -324,6 +333,8 @@ class Page_Locations extends Page Render::addTemplate('subnets', array('list' => $rows)); } elseif ($getAction === 'showlocations') { $this->showLocationList(); + } else { + Util::redirect('?do=locations'); } } diff --git a/modules-available/news/page.inc.php b/modules-available/news/page.inc.php index e7b70c0f..1e2e3eef 100644 --- a/modules-available/news/page.inc.php +++ b/modules-available/news/page.inc.php @@ -46,14 +46,8 @@ class Page_News extends Page // check which action we need to do $action = Request::any('action', 'show'); - if ($action === 'clear') { - // clear news input fields - // TODO: is this the right way? - $this->newsId = false; - $this->newsTitle = false; - $this->newsContent = false; - $this->newsDate = false; - } elseif ($action === 'show') { + if ($action === 'show') { + User::assertPermission('access-page'); /* load latest things */ $this->loadLatest('help'); $this->loadLatest('news'); diff --git a/modules-available/news/permissions/permissions.json b/modules-available/news/permissions/permissions.json index 0d9435d7..953599df 100644 --- a/modules-available/news/permissions/permissions.json +++ b/modules-available/news/permissions/permissions.json @@ -1,4 +1,7 @@ { + "access-page": { + "location-aware": false + }, "help.delete": { "location-aware": false }, diff --git a/modules-available/rebootcontrol/page.inc.php b/modules-available/rebootcontrol/page.inc.php index abbdb2c3..041ae74f 100644 --- a/modules-available/rebootcontrol/page.inc.php +++ b/modules-available/rebootcontrol/page.inc.php @@ -79,11 +79,14 @@ class Page_RebootControl extends Page //location you want to see, default are "not assigned" clients $requestedLocation = Request::get('location', false, 'int'); $allowedLocs = User::getAllowedLocations("action.*"); + if (empty($allowedLocs)) { + User::assertPermission('action.*'); + } if ($requestedLocation === false) { if (in_array(0, $allowedLocs)) { $requestedLocation = 0; - } elseif (!empty($allowedLocs)) { + } else { $requestedLocation = reset($allowedLocs); } } @@ -105,8 +108,8 @@ class Page_RebootControl extends Page Render::addTemplate('header', $data); // only fill table if user has at least one permission for the location - if ($requestedLocation === false) { - Message::addError('main.no-permission'); + if (!in_array($requestedLocation, $allowedLocs)) { + Message::addError('locations.no-permission-location', $requestedLocation); } else { $data['data'] = RebootQueries::getMachineTable($requestedLocation); Render::addTemplate('_page', $data); diff --git a/modules-available/serversetup-bwlp/page.inc.php b/modules-available/serversetup-bwlp/page.inc.php index ae709da7..78096d7b 100644 --- a/modules-available/serversetup-bwlp/page.inc.php +++ b/modules-available/serversetup-bwlp/page.inc.php @@ -43,6 +43,12 @@ class Page_ServerSetup extends Page // iPXE stuff changes $this->updatePxeMenu(); } + + if (Request::isPost()) { + Util::redirect('?do=serversetup'); + } + + User::assertPermission('access-page'); } protected function doRender() diff --git a/modules-available/serversetup-bwlp/permissions/permissions.json b/modules-available/serversetup-bwlp/permissions/permissions.json index 6bae5422..44927506 100644 --- a/modules-available/serversetup-bwlp/permissions/permissions.json +++ b/modules-available/serversetup-bwlp/permissions/permissions.json @@ -1,4 +1,7 @@ { + "access-page": { + "location-aware": false + }, "download": { "location-aware": false }, diff --git a/modules-available/statistics_reporting/page.inc.php b/modules-available/statistics_reporting/page.inc.php index af4b2b12..cc03e4d8 100644 --- a/modules-available/statistics_reporting/page.inc.php +++ b/modules-available/statistics_reporting/page.inc.php @@ -84,6 +84,7 @@ class Page_Statistics_Reporting extends Page die(json_encode($report)); } } + User::assertPermission('*'); } /** diff --git a/modules-available/sysconfig/page.inc.php b/modules-available/sysconfig/page.inc.php index 7bb3e599..8d1799af 100644 --- a/modules-available/sysconfig/page.inc.php +++ b/modules-available/sysconfig/page.inc.php @@ -160,7 +160,7 @@ class Page_SysConfig extends Page $pMods = User::hasPermission('module.view-list'); $pConfs = User::hasPermission('config.view-list'); if (!($pMods || $pConfs)) { - Message::addError('main.no-permission'); + User::assertPermission('config.view-list'); } Render::openTag('div', array('class' => 'row')); if ($pConfs) { diff --git a/modules-available/syslog/page.inc.php b/modules-available/syslog/page.inc.php index 3a7513b5..00c55a3f 100644 --- a/modules-available/syslog/page.inc.php +++ b/modules-available/syslog/page.inc.php @@ -25,6 +25,7 @@ class Page_SysLog extends Page } Util::redirect('?do=syslog'); } + User::assertPermission('*'); } protected function doRender() diff --git a/modules-available/systemstatus/page.inc.php b/modules-available/systemstatus/page.inc.php index 816caa05..66b30bcf 100644 --- a/modules-available/systemstatus/page.inc.php +++ b/modules-available/systemstatus/page.inc.php @@ -18,6 +18,7 @@ class Page_SystemStatus extends Page User::assertPermission("serverreboot"); $this->rebootTask = Taskmanager::submit('Reboot'); } + User::assertPermission('*'); } protected function doRender() diff --git a/modules-available/webinterface/page.inc.php b/modules-available/webinterface/page.inc.php index 806ffd59..ca52c2ab 100644 --- a/modules-available/webinterface/page.inc.php +++ b/modules-available/webinterface/page.inc.php @@ -28,6 +28,10 @@ class Page_WebInterface extends Page $this->actionCustomization(); break; } + if (Request::isPost()) { + Util::redirect('?do=webinterface'); + } + User::assertPermission('access-page'); } private function actionConfigureHttps() diff --git a/modules-available/webinterface/permissions/permissions.json b/modules-available/webinterface/permissions/permissions.json index fa6f493f..ed81602a 100644 --- a/modules-available/webinterface/permissions/permissions.json +++ b/modules-available/webinterface/permissions/permissions.json @@ -1,4 +1,7 @@ { + "access-page": { + "location-aware": false + }, "edit.design": { "location-aware": false }, -- cgit v1.2.3-55-g7522 From 3d3c4c8d62f8074935b69b7b002254fd0daf5945 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Wed, 25 Apr 2018 16:45:29 +0200 Subject: [locations] Fix machine counting --- modules-available/locations/page.inc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules-available/locations/page.inc.php') diff --git a/modules-available/locations/page.inc.php b/modules-available/locations/page.inc.php index 4d5c6628..5010c9ab 100644 --- a/modules-available/locations/page.inc.php +++ b/modules-available/locations/page.inc.php @@ -404,8 +404,8 @@ class Page_Locations extends Page if (!isset($loc['clientCount'])) { $loc['clientCount'] = 0; $loc['clientLoad'] = '0%'; - $loc['clientCountSum'] += $loc['clientCount']; } + $loc['clientCountSum'] += $loc['clientCount']; foreach ($loc['parents'] as $pid) { if (!in_array($pid, $allowedLocationIds)) continue; -- cgit v1.2.3-55-g7522 From 24a04871603b8307eb0af0f772dfe64af16c4ada Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Wed, 25 Apr 2018 17:20:57 +0200 Subject: [locations] Restore row with unassigned machines --- modules-available/locations/page.inc.php | 12 ++++++++++-- modules-available/locations/templates/locations.html | 3 ++- 2 files changed, 12 insertions(+), 3 deletions(-) (limited to 'modules-available/locations/page.inc.php') diff --git a/modules-available/locations/page.inc.php b/modules-available/locations/page.inc.php index 5010c9ab..9beae163 100644 --- a/modules-available/locations/page.inc.php +++ b/modules-available/locations/page.inc.php @@ -345,8 +345,10 @@ class Page_Locations extends Page Location::getOverlappingSubnets($overlapSelf, $overlapOther); //$locs = Location::getLocations(0, 0, false, true); $locationList = Location::getLocationsAssoc(); + unset($locationList[0]); // Statistics: Count machines for each subnet $unassigned = false; + $unassignedLoad = 0; // Filter view: Remove locations we can't reach at all, but show parents to locations // we have permission to, so the tree doesn't look all weird @@ -383,15 +385,20 @@ class Page_Locations extends Page // Client statistics if (Module::get('statistics') !== false) { $unassigned = 0; + $extra = ''; + if (in_array(0, $allowedLocationIds)) { + $extra = ' OR locationid IS NULL'; + } $res = Database::simpleQuery("SELECT locationid, Count(*) AS cnt, Sum(If(state = 'OCCUPIED', 1, 0)) AS used - FROM machine WHERE locationid IN (:allowedLocationIds) GROUP BY locationid", compact('allowedLocationIds')); + FROM machine WHERE (locationid IN (:allowedLocationIds) $extra) GROUP BY locationid", compact('allowedLocationIds')); while ($row = $res->fetch(PDO::FETCH_ASSOC)) { $locId = (int)$row['locationid']; if (isset($locationList[$locId])) { $locationList[$locId]['clientCount'] = $row['cnt']; - $locationList[$locId]['clientLoad'] = round(100 * $row['used'] / $row['cnt']) . '%'; + $locationList[$locId]['clientLoad'] = round(100 * $row['used'] / $row['cnt']) . ' %'; } else { $unassigned += $row['cnt']; + $unassignedLoad += $row['used']; } } unset($loc); @@ -482,6 +489,7 @@ class Page_Locations extends Page 'haveOverlapSelf' => !empty($overlapSelf), 'haveOverlapOther' => !empty($overlapOther), 'unassignedCount' => $unassigned, + 'unassignedLoad' => round(($unassignedLoad / $unassigned) * 100) . ' %', 'defaultConfig' => $defaultConfig, 'addAllowedList' => array_values($addAllowedList), ); diff --git a/modules-available/locations/templates/locations.html b/modules-available/locations/templates/locations.html index cd04b1c8..67f22744 100644 --- a/modules-available/locations/templates/locations.html +++ b/modules-available/locations/templates/locations.html @@ -96,9 +96,10 @@  {{unassignedCount}}  + - {{clientLoad}} + {{unassignedLoad}} {{defaultConfig}} -- cgit v1.2.3-55-g7522 From 59f6f89a2b7950e7b5fb4bdb0e2cdaf4998f1e9e Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Fri, 11 Jan 2019 16:49:58 +0100 Subject: [locations] Show current boot menu per location, add edit button --- .../locations/lang/de/template-tags.json | 1 + .../locations/lang/en/template-tags.json | 1 + modules-available/locations/page.inc.php | 60 ++++++++++++++++------ .../locations/templates/locations.html | 17 +++++- 4 files changed, 61 insertions(+), 18 deletions(-) (limited to 'modules-available/locations/page.inc.php') diff --git a/modules-available/locations/lang/de/template-tags.json b/modules-available/locations/lang/de/template-tags.json index 43142555..96273ce4 100644 --- a/modules-available/locations/lang/de/template-tags.json +++ b/modules-available/locations/lang/de/template-tags.json @@ -3,6 +3,7 @@ "lang_areYouSureNoUndo": "Sind Sie sicher? Diese Aktion kann nicht r\u00fcckg\u00e4ngig gemacht werden.", "lang_assignSubnetExplanation": "Rechner, die in einen der hier aufgef\u00fchrten Adressbereiche fallen, werden diesem Ort zugeschrieben und erhalten damit z.B. f\u00fcr diesen Raum angepasste Veranstaltungslisten.", "lang_assignedSubnets": "Zugeordnete Subnetze bzw. IP-Bereiche", + "lang_bootMenu": "Bootmen\u00fc", "lang_deleteChildLocations": "Untergeordnete Orte ebenfalls l\u00f6schen", "lang_deleteLocation": "Ort l\u00f6schen", "lang_deleteSubnet": "Bereich l\u00f6schen", diff --git a/modules-available/locations/lang/en/template-tags.json b/modules-available/locations/lang/en/template-tags.json index 41261726..64211e27 100644 --- a/modules-available/locations/lang/en/template-tags.json +++ b/modules-available/locations/lang/en/template-tags.json @@ -3,6 +3,7 @@ "lang_areYouSureNoUndo": "Are you sure? This cannot be undone!", "lang_assignSubnetExplanation": "Client machines which fall into an IP range listed below will be assigned to this location and will see an according lecture list (e.g. they will see lectures that are exclusively assigned to this location).", "lang_assignedSubnets": "Assigned subnets \/ IP ranges", + "lang_bootMenu": "Boot menu", "lang_deleteChildLocations": "Delete child locations aswell", "lang_deleteLocation": "Delete location", "lang_deleteSubnet": "Delete range", diff --git a/modules-available/locations/page.inc.php b/modules-available/locations/page.inc.php index 9beae163..2d8f5ff9 100644 --- a/modules-available/locations/page.inc.php +++ b/modules-available/locations/page.inc.php @@ -375,6 +375,11 @@ class Page_Locations extends Page } else { $locationList[$lid]['havestatistics'] = false; } + if (User::hasPermission('.serversetup.ipxe.menu.assign', $lid)) { + $visibleLocationIds[] = $lid; + } else { + $locationList[$lid]['haveipxe'] = false; + } if (!in_array($lid, $visibleLocationIds)) { unset($locationList[$lid]); } elseif (!in_array($lid, $allowedLocationIds)) { @@ -440,22 +445,7 @@ class Page_Locations extends Page $locationList[$locId] += array('configName' => $conf['title'], 'configClass' => 'slx-bold'); } } - $depth = array(); - foreach ($locationList as &$loc) { - $d = $loc['depth']; - if (!isset($loc['configName'])) { - // Has no explicit config assignment - if ($d === 0) { - $loc['configName'] = $defaultConfig; - } else { - $loc['configName'] = $depth[$d - 1]; - } - $loc['configClass'] = 'gray'; - } - $depth[$d] = $loc['configName']; - unset($depth[$d + 1]); - } - unset($loc); + $this->propagateFields($locationList, $defaultConfig, 'configName', 'configClass'); } // Count overridden config vars if (Module::get('baseconfig') !== false) { @@ -467,6 +457,24 @@ class Page_Locations extends Page $locationList[$lid]['overriddenVars'] = $row['cnt']; } } + // Confusing because the count might be inaccurate within a branch + //$this->propagateFields($locationList, '', 'overriddenVars', 'overriddenClass'); + } + // Show ipxe menu + if (Module::get('serversetup') !== false) { + $res = Database::simpleQuery("SELECT ml.locationid, m.title, ml.defaultentryid FROM serversetup_menu m + INNER JOIN serversetup_menu_location ml USING (menuid) + WHERE locationid IN (:allowedLocationIds) GROUP BY locationid", compact('allowedLocationIds')); + while ($row = $res->fetch(PDO::FETCH_ASSOC)) { + $lid = (int)$row['locationid']; + if (isset($locationList[$lid])) { + if ($row['defaultentryid'] !== null) { + $row['title'] .= '(*)'; + } + $locationList[$lid]['customMenu'] = $row['title']; + } + } + $this->propagateFields($locationList, '', 'customMenu', 'customMenuClass'); } $addAllowedLocs = User::getAllowedLocations("location.add"); @@ -484,6 +492,7 @@ class Page_Locations extends Page 'havestatistics' => Module::get('statistics') !== false, 'havebaseconfig' => Module::get('baseconfig') !== false, 'havesysconfig' => Module::get('sysconfig') !== false, + 'haveipxe' => Module::get('serversetup') !== false, 'overlapSelf' => $overlapSelf, 'overlapOther' => $overlapOther, 'haveOverlapSelf' => !empty($overlapSelf), @@ -637,4 +646,23 @@ class Page_Locations extends Page return $result; } + private function propagateFields(&$locationList, $defaultValue, $name, $class) + { + $depth = array(); + foreach ($locationList as &$loc) { + $d = $loc['depth']; + if (!isset($loc[$name])) { + // Has no explicit config assignment + if ($d === 0) { + $loc[$name] = $defaultValue; + } else { + $loc[$name] = $depth[$d - 1]; + } + $loc[$class] = 'gray'; + } + $depth[$d] = $loc[$name]; + unset($depth[$d + 1]); + } + } + } diff --git a/modules-available/locations/templates/locations.html b/modules-available/locations/templates/locations.html index 67f22744..06d32020 100644 --- a/modules-available/locations/templates/locations.html +++ b/modules-available/locations/templates/locations.html @@ -37,6 +37,9 @@ {{#havesysconfig}}{{lang_sysConfig}}{{/havesysconfig}} + + {{#haveipxe}}{{lang_bootMenu}}{{/haveipxe}} + {{#list}} @@ -67,7 +70,7 @@ {{clientLoad}} {{/havestatistics}} - + {{#havebaseconfig}}
@@ -87,6 +90,16 @@ {{/havesysconfig}} + + {{#haveipxe}} +
+ +
+ + {{customMenu}}   + + {{/haveipxe}} + {{/list}} {{#unassignedCount}} @@ -170,7 +183,7 @@ function slxOpenLocation(e, lid) { } return; } - var td = $('').attr('colspan', '5').css('padding', '0px 0px 12px'); + var td = $('').attr('colspan', '6').css('padding', '0px 0px 12px'); var tr = $('').attr('id', 'location-details-' + lid); tr.append(td); $(e).closest('tr').addClass('active slx-bold').after(tr); -- cgit v1.2.3-55-g7522