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') 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 a8b0095b335780ae0bb950bc44021215d43a6b2d Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Mon, 12 Feb 2018 14:17:07 +0100 Subject: [permissionmanager] Introduce "location-aware" flag for permissions This flag tells wether the permission can be restricted to certain locations in a meaningful way. This flag has to be set in the permissions.json of the according module. For example, the permission to reboot the server cannot be limited to certain locations in a meaningful way, while the view of the client log can be filtered to only show log entries for clients in specific locations. --- .../backup/permissions/permissions.json | 12 +++-- .../permissions/permissions.json | 24 +++++++--- .../dozmod/permissions/permissions.json | 52 ++++++++++++++++------ .../eventlog/permissions/permissions.json | 8 ++-- .../exams/permissions/permissions.json | 13 +++--- .../internetaccess/permissions/permissions.json | 8 ++-- .../locations/permissions/permissions.json | 32 +++++++++---- .../minilinux/permissions/permissions.json | 12 +++-- .../news/permissions/permissions.json | 20 ++++++--- .../permissionmanager/inc/permissionutil.inc.php | 9 ++-- modules-available/permissionmanager/page.inc.php | 21 +++++---- modules-available/permissionmanager/style.css | 28 ++++++------ .../permissionmanager/templates/roleeditor.html | 42 +++++++---------- .../permissionmanager/templates/treenode.html | 23 +++++----- .../permissionmanager/templates/treepanel.html | 2 +- .../rebootcontrol/permissions/permissions.json | 16 ++++--- .../serversetup-bwlp/permissions/permissions.json | 16 ++++--- .../statistics/permissions/permissions.json | 16 ++++--- .../permissions/permissions.json | 36 ++++++++++----- .../syslog/permissions/permissions.json | 8 ++-- .../systemstatus/permissions/permissions.json | 48 ++++++++++++++------ .../vmstore/permissions/permissions.json | 16 ++++--- .../webinterface/permissions/permissions.json | 16 ++++--- 23 files changed, 309 insertions(+), 169 deletions(-) (limited to 'modules-available/locations') diff --git a/modules-available/backup/permissions/permissions.json b/modules-available/backup/permissions/permissions.json index feeffe33..1f778ab6 100644 --- a/modules-available/backup/permissions/permissions.json +++ b/modules-available/backup/permissions/permissions.json @@ -1,4 +1,8 @@ -[ - "create", - "restore" -] \ No newline at end of file +{ + "create": { + "location-aware": false + }, + "restore": { + "location-aware": false + } +} \ No newline at end of file diff --git a/modules-available/baseconfig_partitions_cdn/permissions/permissions.json b/modules-available/baseconfig_partitions_cdn/permissions/permissions.json index 286a975b..3acd5230 100644 --- a/modules-available/baseconfig_partitions_cdn/permissions/permissions.json +++ b/modules-available/baseconfig_partitions_cdn/permissions/permissions.json @@ -1,7 +1,17 @@ -[ - "show", - "partitions.add", - "partitions.delete", - "partitions.edit", - "partitions.reset" -] \ No newline at end of file +{ + "partitions.add": { + "location-aware": false + }, + "partitions.delete": { + "location-aware": false + }, + "partitions.edit": { + "location-aware": false + }, + "partitions.reset": { + "location-aware": false + }, + "show": { + "location-aware": false + } +} \ No newline at end of file diff --git a/modules-available/dozmod/permissions/permissions.json b/modules-available/dozmod/permissions/permissions.json index e8dfb558..b4ff034b 100644 --- a/modules-available/dozmod/permissions/permissions.json +++ b/modules-available/dozmod/permissions/permissions.json @@ -1,14 +1,38 @@ -[ - "images.delete", - "mail.save", - "mail.testmail", - "runtimeconfig.save", - "templates.save", - "templates.reset", - "users.setmail", - "users.setlogin", - "users.setsu", - "users.orglogin", - "log.showuser", - "log.showtarget" -] \ No newline at end of file +{ + "images.delete": { + "location-aware": false + }, + "log.showtarget": { + "location-aware": false + }, + "log.showuser": { + "location-aware": false + }, + "mail.save": { + "location-aware": false + }, + "mail.testmail": { + "location-aware": false + }, + "runtimeconfig.save": { + "location-aware": false + }, + "templates.reset": { + "location-aware": false + }, + "templates.save": { + "location-aware": false + }, + "users.orglogin": { + "location-aware": false + }, + "users.setlogin": { + "location-aware": false + }, + "users.setmail": { + "location-aware": false + }, + "users.setsu": { + "location-aware": false + } +} \ No newline at end of file diff --git a/modules-available/eventlog/permissions/permissions.json b/modules-available/eventlog/permissions/permissions.json index f04ea714..a1748957 100644 --- a/modules-available/eventlog/permissions/permissions.json +++ b/modules-available/eventlog/permissions/permissions.json @@ -1,3 +1,5 @@ -[ - "view" -] \ No newline at end of file +{ + "view": { + "location-aware": false + } +} \ No newline at end of file diff --git a/modules-available/exams/permissions/permissions.json b/modules-available/exams/permissions/permissions.json index 215b3399..e44974b6 100644 --- a/modules-available/exams/permissions/permissions.json +++ b/modules-available/exams/permissions/permissions.json @@ -1,5 +1,8 @@ -[ - "exams.add", - "exams.delete", - "exams.edit" -] \ No newline at end of file +{ + "exams.edit": { + "location-aware": true + }, + "exams.view": { + "location-aware": true + } +} \ No newline at end of file diff --git a/modules-available/internetaccess/permissions/permissions.json b/modules-available/internetaccess/permissions/permissions.json index 67998da7..09652e51 100644 --- a/modules-available/internetaccess/permissions/permissions.json +++ b/modules-available/internetaccess/permissions/permissions.json @@ -1,3 +1,5 @@ -[ - "configuration.safe" -] \ No newline at end of file +{ + "configuration.safe": { + "location-aware": false + } +} \ No newline at end of file diff --git a/modules-available/locations/permissions/permissions.json b/modules-available/locations/permissions/permissions.json index 609a673a..06b01d2c 100644 --- a/modules-available/locations/permissions/permissions.json +++ b/modules-available/locations/permissions/permissions.json @@ -1,9 +1,23 @@ -[ - "location.view", - "location.edit", - "location.add", - "location.delete", - "subnet.edit", - "subnet.add", - "subnet.delete" -] \ No newline at end of file +{ + "location.add": { + "location-aware": false + }, + "location.delete": { + "location-aware": false + }, + "location.edit": { + "location-aware": false + }, + "location.view": { + "location-aware": false + }, + "subnet.add": { + "location-aware": false + }, + "subnet.delete": { + "location-aware": false + }, + "subnet.edit": { + "location-aware": false + } +} \ No newline at end of file diff --git a/modules-available/minilinux/permissions/permissions.json b/modules-available/minilinux/permissions/permissions.json index 457d9810..650f7e71 100644 --- a/modules-available/minilinux/permissions/permissions.json +++ b/modules-available/minilinux/permissions/permissions.json @@ -1,4 +1,8 @@ -[ - "show", - "update" -] \ No newline at end of file +{ + "show": { + "location-aware": false + }, + "update": { + "location-aware": false + } +} \ No newline at end of file diff --git a/modules-available/news/permissions/permissions.json b/modules-available/news/permissions/permissions.json index 321e73ea..0d9435d7 100644 --- a/modules-available/news/permissions/permissions.json +++ b/modules-available/news/permissions/permissions.json @@ -1,6 +1,14 @@ -[ - "news.save", - "news.delete", - "help.save", - "help.delete" -] \ No newline at end of file +{ + "help.delete": { + "location-aware": false + }, + "help.save": { + "location-aware": false + }, + "news.delete": { + "location-aware": false + }, + "news.save": { + "location-aware": false + } +} \ No newline at end of file diff --git a/modules-available/permissionmanager/inc/permissionutil.inc.php b/modules-available/permissionmanager/inc/permissionutil.inc.php index 5ff41046..3daf422e 100644 --- a/modules-available/permissionmanager/inc/permissionutil.inc.php +++ b/modules-available/permissionmanager/inc/permissionutil.inc.php @@ -100,9 +100,9 @@ class PermissionUtil if (!is_array($data)) continue; preg_match('#^modules/([^/]+)/#', $file, $out); - foreach( $data as $p ) { + foreach( $data as $p => $data) { $description = Dictionary::translateFileModule($out[1], "permissions", $p); - self::putInPermissionTree($out[1].".".$p, $description, $permissions); + self::putInPermissionTree($out[1].".".$p, $data['location-aware'], $description, $permissions); } } ksort($permissions); @@ -120,10 +120,11 @@ class PermissionUtil * Place a permission into the given permission tree. * * @param string $permission the permission to place in the tree + * @param bool $locationAware whether this permissions can be restricted to specific locations only * @param string $description the description of the permission * @param array $tree the permission tree to modify */ - private static function putInPermissionTree($permission, $description, &$tree) + private static function putInPermissionTree($permission, $locationAware, $description, &$tree) { $subPermissions = explode('.', $permission); foreach ($subPermissions as $subPermission) { @@ -134,6 +135,6 @@ class PermissionUtil $tree =& $tree[$subPermission]; } } - $tree = $description; + $tree = array('description' => $description, 'location-aware' => $locationAware, 'isLeaf' => true); } } \ No newline at end of file diff --git a/modules-available/permissionmanager/page.inc.php b/modules-available/permissionmanager/page.inc.php index 13d81c6a..bb8482af 100644 --- a/modules-available/permissionmanager/page.inc.php +++ b/modules-available/permissionmanager/page.inc.php @@ -100,18 +100,21 @@ class Page_PermissionManager extends Page $toplevel = $permString == ""; if ($toplevel && in_array("*", $selectedPermissions)) $selectAll = true; foreach ($permissions as $k => $v) { - $leaf = !is_array($v); + $leaf = isset($v['isLeaf']) && $v['isLeaf']; $nextPermString = $permString ? $permString.".".$k : $k; $id = $leaf ? $nextPermString : $nextPermString.".*"; $selected = $selectAll || in_array($id, $selectedPermissions); - $res .= Render::parse("treenode", - array("id" => $id, - "name" => $toplevel ? Module::get($k)->getDisplayName() : $k, - "toplevel" => $toplevel, - "checkboxname" => "permissions", - "selected" => $selected, - "HTML" => $leaf ? "" : self::generatePermissionHTML($v, $selectedPermissions, $selected, $nextPermString), - "description" => $leaf ? $v : "")); + $data = array("id" => $id, + "name" => $toplevel ? Module::get($k)->getDisplayName() : $k, + "toplevel" => $toplevel, + "checkboxname" => "permissions", + "selected" => $selected, + "HTML" => $leaf ? "" : self::generatePermissionHTML($v, $selectedPermissions, $selected, $nextPermString), + ); + if ($leaf) { + $data += $v; + } + $res .= Render::parse("treenode", $data); } if ($toplevel) { $res = Render::parse("treepanel", diff --git a/modules-available/permissionmanager/style.css b/modules-available/permissionmanager/style.css index 49d631a8..9c39af64 100644 --- a/modules-available/permissionmanager/style.css +++ b/modules-available/permissionmanager/style.css @@ -55,28 +55,28 @@ background-color: rgba(0, 182, 41, 0.23); } -.tree-container { - -moz-column-gap: 20px; - -webkit-column-gap: 20px; - column-gap: 20px; -} - - .tree-container > ul { display: inline-block; width: 100%; padding: 0; } -@media (max-width: 767px) { - .tree-container { - -moz-column-count: 1; - -webkit-column-count: 1; - column-count: 1; - } +.tree-container > ul > li > div > label { + font-weight: bold; +} + +.tree-container { + -moz-column-gap: 20px; + -webkit-column-gap: 20px; + column-gap: 20px; + -moz-column-count: 1; + -webkit-column-count: 1; + column-count: 1; + padding-left: 20px; + padding-right: 20px; } -@media (min-width: 768px) and (max-width: 991px) { +@media (min-width: 768px) { .tree-container { -moz-column-count: 2; -webkit-column-count: 2; diff --git a/modules-available/permissionmanager/templates/roleeditor.html b/modules-available/permissionmanager/templates/roleeditor.html index 871fd0cc..eadce027 100644 --- a/modules-available/permissionmanager/templates/roleeditor.html +++ b/modules-available/permissionmanager/templates/roleeditor.html @@ -4,32 +4,24 @@ -
-
- + +
+
+ {{{permissionHTML}}}
-
-
-
-
-
- {{{permissionHTML}}} -
-
- {{{locationHTML}}} -
-
+
+ {{{locationHTML}}}
diff --git a/modules-available/permissionmanager/templates/treenode.html b/modules-available/permissionmanager/templates/treenode.html index ced973ca..43509237 100644 --- a/modules-available/permissionmanager/templates/treenode.html +++ b/modules-available/permissionmanager/templates/treenode.html @@ -1,11 +1,14 @@ {{#toplevel}}
    {{/toplevel}} -
  • -
    - - -
    -
      - {{{HTML}}} -
    -
  • -{{#toplevel}}
{{/toplevel}} +
  • +
    + + +
    +
      + {{{HTML}}} +
    +
  • +{{#toplevel}}{{/toplevel}} \ No newline at end of file diff --git a/modules-available/permissionmanager/templates/treepanel.html b/modules-available/permissionmanager/templates/treepanel.html index 6f358825..8b510407 100644 --- a/modules-available/permissionmanager/templates/treepanel.html +++ b/modules-available/permissionmanager/templates/treepanel.html @@ -6,7 +6,7 @@
    -
    +
    {{{HTML}}}
    diff --git a/modules-available/rebootcontrol/permissions/permissions.json b/modules-available/rebootcontrol/permissions/permissions.json index 5230c9bd..5de9b633 100644 --- a/modules-available/rebootcontrol/permissions/permissions.json +++ b/modules-available/rebootcontrol/permissions/permissions.json @@ -1,5 +1,11 @@ -[ - "shutdown", - "reboot", - "newkeypair" -] \ No newline at end of file +{ + "newkeypair": { + "location-aware": false + }, + "reboot": { + "location-aware": true + }, + "shutdown": { + "location-aware": true + } +} \ No newline at end of file diff --git a/modules-available/serversetup-bwlp/permissions/permissions.json b/modules-available/serversetup-bwlp/permissions/permissions.json index 2166cf8e..6bae5422 100644 --- a/modules-available/serversetup-bwlp/permissions/permissions.json +++ b/modules-available/serversetup-bwlp/permissions/permissions.json @@ -1,5 +1,11 @@ -[ - "edit.address", - "edit.menu", - "download" -] \ No newline at end of file +{ + "download": { + "location-aware": false + }, + "edit.address": { + "location-aware": false + }, + "edit.menu": { + "location-aware": false + } +} \ No newline at end of file diff --git a/modules-available/statistics/permissions/permissions.json b/modules-available/statistics/permissions/permissions.json index 97a49036..c9dca9f3 100644 --- a/modules-available/statistics/permissions/permissions.json +++ b/modules-available/statistics/permissions/permissions.json @@ -1,5 +1,11 @@ -[ - "view", - "note", - "delete" -] \ No newline at end of file +{ + "machine.delete": { + "location-aware": true + }, + "machine.note": { + "location-aware": true + }, + "machine.view": { + "location-aware": true + } +} \ No newline at end of file diff --git a/modules-available/statistics_reporting/permissions/permissions.json b/modules-available/statistics_reporting/permissions/permissions.json index d967b75d..1244027e 100644 --- a/modules-available/statistics_reporting/permissions/permissions.json +++ b/modules-available/statistics_reporting/permissions/permissions.json @@ -1,10 +1,26 @@ -[ - "table.view.total", - "table.view.location", - "table.view.client", - "table.view.user", - "table.view.vm", - "table.export", - "reporting.download", - "reporting.change" -] \ No newline at end of file +{ + "reporting.change": { + "location-aware": false + }, + "reporting.download": { + "location-aware": false + }, + "table.export": { + "location-aware": false + }, + "table.view.client": { + "location-aware": true + }, + "table.view.location": { + "location-aware": true + }, + "table.view.total": { + "location-aware": false + }, + "table.view.user": { + "location-aware": false + }, + "table.view.vm": { + "location-aware": false + } +} \ No newline at end of file diff --git a/modules-available/syslog/permissions/permissions.json b/modules-available/syslog/permissions/permissions.json index f04ea714..fcf530c5 100644 --- a/modules-available/syslog/permissions/permissions.json +++ b/modules-available/syslog/permissions/permissions.json @@ -1,3 +1,5 @@ -[ - "view" -] \ No newline at end of file +{ + "view": { + "location-aware": true + } +} \ No newline at end of file diff --git a/modules-available/systemstatus/permissions/permissions.json b/modules-available/systemstatus/permissions/permissions.json index 0333564b..8324f708 100644 --- a/modules-available/systemstatus/permissions/permissions.json +++ b/modules-available/systemstatus/permissions/permissions.json @@ -1,13 +1,35 @@ -[ - "show.overview.diskstat", - "show.overview.services", - "show.overview.adresses", - "show.overview.systeminfo", - "show.overview.dmsdusers", - "show.logs.bwlpserver", - "show.logs.netstat", - "show.logs.pslist", - "show.logs.ldapad", - "show.logs.lighttpd", - "serverreboot" -] \ No newline at end of file +{ + "serverreboot": { + "location-aware": false + }, + "show.logs.bwlpserver": { + "location-aware": false + }, + "show.logs.ldapad": { + "location-aware": false + }, + "show.logs.lighttpd": { + "location-aware": false + }, + "show.logs.netstat": { + "location-aware": false + }, + "show.logs.pslist": { + "location-aware": false + }, + "show.overview.adresses": { + "location-aware": false + }, + "show.overview.diskstat": { + "location-aware": false + }, + "show.overview.dmsdusers": { + "location-aware": false + }, + "show.overview.services": { + "location-aware": false + }, + "show.overview.systeminfo": { + "location-aware": false + } +} \ No newline at end of file diff --git a/modules-available/vmstore/permissions/permissions.json b/modules-available/vmstore/permissions/permissions.json index f2c22c72..29ee6a51 100644 --- a/modules-available/vmstore/permissions/permissions.json +++ b/modules-available/vmstore/permissions/permissions.json @@ -1,5 +1,11 @@ -[ - "choose.internal", - "choose.nfs", - "choose.cifs" -] \ No newline at end of file +{ + "choose.cifs": { + "location-aware": false + }, + "choose.internal": { + "location-aware": false + }, + "choose.nfs": { + "location-aware": false + } +} \ No newline at end of file diff --git a/modules-available/webinterface/permissions/permissions.json b/modules-available/webinterface/permissions/permissions.json index 45b5395d..fa6f493f 100644 --- a/modules-available/webinterface/permissions/permissions.json +++ b/modules-available/webinterface/permissions/permissions.json @@ -1,5 +1,11 @@ -[ - "edit.https", - "edit.password", - "edit.design" -] \ No newline at end of file +{ + "edit.design": { + "location-aware": false + }, + "edit.https": { + "location-aware": false + }, + "edit.password": { + "location-aware": false + } +} \ No newline at end of file -- 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') 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') 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 d5166e77fbb1dc034a421da868f9539fc455e490 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Wed, 21 Mar 2018 11:30:29 +0100 Subject: Update translations --- modules-available/locations/lang/de/template-tags.json | 4 ++-- modules-available/locations/lang/en/template-tags.json | 4 ++-- modules-available/rebootcontrol/page.inc.php | 2 +- modules-available/runmode/lang/de/messages.json | 1 + modules-available/runmode/lang/de/template-tags.json | 1 + modules-available/runmode/lang/en/messages.json | 1 + modules-available/runmode/lang/en/template-tags.json | 1 + modules-available/statistics/page.inc.php | 2 +- 8 files changed, 10 insertions(+), 6 deletions(-) (limited to 'modules-available/locations') diff --git a/modules-available/locations/lang/de/template-tags.json b/modules-available/locations/lang/de/template-tags.json index 04d10d06..43142555 100644 --- a/modules-available/locations/lang/de/template-tags.json +++ b/modules-available/locations/lang/de/template-tags.json @@ -6,7 +6,7 @@ "lang_deleteChildLocations": "Untergeordnete Orte ebenfalls l\u00f6schen", "lang_deleteLocation": "Ort l\u00f6schen", "lang_deleteSubnet": "Bereich l\u00f6schen", - "lang_deleteSubnetWarning": "Alle zum L\u00f6schen markierten Subnetze werden gelöscht. Diese Aktion kann nicht r\u00fcckg\u00e4ngig gemacht werden.", + "lang_deleteSubnetWarning": "Alle zum L\u00f6schen markierten Subnetze werden gel\u00f6scht. Diese Aktion kann nicht r\u00fcckg\u00e4ngig gemacht werden.", "lang_editConfigVariables": "Konfig.-Variablen", "lang_editRoomplan": "Raumplan bearbeiten", "lang_endAddress": "Endadresse", @@ -22,10 +22,10 @@ "lang_machineLoad": "Besetzt", "lang_matchingMachines": "Enthaltene Rechner", "lang_name": "Name", - "lang_noParent": "Kein \u00fcbergeordneter Ort", "lang_overrideCount": "Angepasst", "lang_parentLocation": "\u00dcbergeordneter Ort", "lang_referencingLectures": "Veranstaltungen", + "lang_showRoomplan": "Raumplan anzeigen", "lang_startAddress": "Startadresse", "lang_subnet": "IP-Bereich", "lang_sysConfig": "Lokalisierung", diff --git a/modules-available/locations/lang/en/template-tags.json b/modules-available/locations/lang/en/template-tags.json index ddb90f83..41261726 100644 --- a/modules-available/locations/lang/en/template-tags.json +++ b/modules-available/locations/lang/en/template-tags.json @@ -22,14 +22,14 @@ "lang_machineLoad": "In use", "lang_matchingMachines": "Matching clients", "lang_name": "Name", - "lang_noParent": "No parent", "lang_overrideCount": "Overridden", "lang_parentLocation": "Parent location", "lang_referencingLectures": "Assigned Lectures", + "lang_showRoomplan": "Show room plan", "lang_startAddress": "Start address", "lang_subnet": "IP range", "lang_sysConfig": "Localization\/Integration", "lang_thisListByLocation": "Locations", "lang_thisListBySubnet": "Subnets", "lang_unassignedMachines": "Machines not matching any location" -} +} \ No newline at end of file diff --git a/modules-available/rebootcontrol/page.inc.php b/modules-available/rebootcontrol/page.inc.php index fa7688d8..abbdb2c3 100644 --- a/modules-available/rebootcontrol/page.inc.php +++ b/modules-available/rebootcontrol/page.inc.php @@ -38,7 +38,7 @@ class Page_RebootControl extends Page // Filter ones with no permission foreach (array_keys($actualClients) as $idx) { if (!User::hasPermission('action.' . $this->action, $actualClients[$idx]['locationid'])) { - Message::addWarning('main.location-no-permission', $actualClients[$idx]['locationid']); + Message::addWarning('locations.no-permission-location', $actualClients[$idx]['locationid']); unset($actualClients[$idx]); } else { $locationId = $actualClients[$idx]['locationid']; diff --git a/modules-available/runmode/lang/de/messages.json b/modules-available/runmode/lang/de/messages.json index 911d48d4..bca70019 100644 --- a/modules-available/runmode/lang/de/messages.json +++ b/modules-available/runmode/lang/de/messages.json @@ -2,6 +2,7 @@ "cannot-edit-module": "Modul {{0}} kann nicht direkt editiert werden", "enabled-removed-save": "{{0}} Rechner gespeichert, {{1}} entfernt", "invalid-modeid": "{{1}} ist kein g\u00fcltiger Betriebsmodus f\u00fcr Modul {{0}}", + "machine-no-permission": "Keine Berechtigung f\u00fcr client {{0}}", "machine-not-found": "Rechner {{0}} nicht gefunden", "machine-not-runmode": "Rechner {{0}} hatte keinen speziellen Betriebsmodus aktiviert", "machine-removed": "Rechner {{0}} entfernt", diff --git a/modules-available/runmode/lang/de/template-tags.json b/modules-available/runmode/lang/de/template-tags.json index 6b45b82c..989e5b1d 100644 --- a/modules-available/runmode/lang/de/template-tags.json +++ b/modules-available/runmode/lang/de/template-tags.json @@ -3,6 +3,7 @@ "lang_assignMachineIntroText": "Definieren Sie hier Clients, die in einem speziellen Betriebsmodus gestartet werden sollen. Sie k\u00f6nnen Rechner anhand der UUID, IP, Hostname oder MAC-Adresse suchen.", "lang_assignRunmodeToMachine": "Betriebsmodus", "lang_confirmDelete": "Wollen Sie den Betriebsmodus f\u00fcr diesen Client entfernen?", + "lang_existingClients": "Vorhandene Clients mit diesem Betriebsmodus", "lang_isclient": "Pool-Client", "lang_machine": "Client", "lang_mode": "Modus", diff --git a/modules-available/runmode/lang/en/messages.json b/modules-available/runmode/lang/en/messages.json index 6d890428..1ca1567a 100644 --- a/modules-available/runmode/lang/en/messages.json +++ b/modules-available/runmode/lang/en/messages.json @@ -2,6 +2,7 @@ "cannot-edit-module": "Module {{0}} cannot be edited directly", "enabled-removed-save": "Saved {{0}} clients, deleted {{1}}", "invalid-modeid": "Module {{0}} doesn't provide mode {{1}}", + "machine-no-permission": "No permission for client {{0}}", "machine-not-found": "Client {{0}} not found", "machine-not-runmode": "No special mode of operation configured for client {{0}}", "machine-removed": "Removed client {{0}}", diff --git a/modules-available/runmode/lang/en/template-tags.json b/modules-available/runmode/lang/en/template-tags.json index 43fd3da5..89cf6b15 100644 --- a/modules-available/runmode/lang/en/template-tags.json +++ b/modules-available/runmode/lang/en/template-tags.json @@ -3,6 +3,7 @@ "lang_assignMachineIntroText": "Define the clients which should start a special runmode configuration. You can search for clients by UUID, IP address, host name or MAC address.", "lang_assignRunmodeToMachine": "Runmode", "lang_confirmDelete": "Do you want to delete the runmode for this client?", + "lang_existingClients": "Existing clients with this run mode", "lang_isclient": "Pool-Client", "lang_machine": "Client", "lang_mode": "Mode", diff --git a/modules-available/statistics/page.inc.php b/modules-available/statistics/page.inc.php index 3baac190..60743fb6 100644 --- a/modules-available/statistics/page.inc.php +++ b/modules-available/statistics/page.inc.php @@ -227,7 +227,7 @@ class Page_Statistics extends Page if (in_array($row['locationid'], $allowedLocations)) { $delete[] = $row['machineuuid']; } else { - Message::addError('no-permission-location', $row['locationid']); + Message::addError('locations.no-permission-location', $row['locationid']); } } if (!empty($delete)) { -- cgit v1.2.3-55-g7522 From 7a31ef5d902489cc508bbce4f7193392fecf1fd2 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Wed, 28 Mar 2018 14:35:24 +0200 Subject: [locations] Make subnet list editable again :) Closes #3331 --- modules-available/locations/templates/subnets.html | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'modules-available/locations') diff --git a/modules-available/locations/templates/subnets.html b/modules-available/locations/templates/subnets.html index cb7fb758..d027d800 100644 --- a/modules-available/locations/templates/subnets.html +++ b/modules-available/locations/templates/subnets.html @@ -17,9 +17,9 @@ {{#list}} {{subnetid}} - - - + + +