Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

acl: prioritize dashboard and ui routes for landing page #8222

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions src/opnsense/mvc/app/models/OPNsense/Core/ACL.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,24 @@ private function loadUserGroupRights()
{
$pageMap = $this->loadPageMap();

// prioritized acl names that, if configured, will be used first for getLandingPage
$priorityPrivileges = ['page-system-login-logout'];

// create privilege mappings
$this->userDatabase = [];
$this->allGroupPrivs = [];

$groupmap = [];

$privilegeSort = function($a, $b) use ($priorityPrivileges) {
$posA = array_search($a, $priorityPrivileges);
$posB = array_search($b, $priorityPrivileges);
if ($posA === false && $posB !== false) return 1;
if ($posA !== false && $posB === false) return -1;
if ($posA === false && $posB === false) return 0;
return $posA <=> $posB;
};

// gather user / group data from config.xml
$config = Config::getInstance()->object();
$userUidMap = [];
Expand All @@ -115,7 +127,9 @@ private function loadUserGroupRights()
$this->userDatabase[$username]['landing_page'] = (string)$node->landing_page;
}
foreach ($node->priv as $priv) {
foreach (array_filter(explode(',', $priv)) as $privname) {
$privileges = array_filter(explode(',', $priv));
usort($privileges, $privilegeSort);
foreach ($privileges as $privname) {
if (array_key_exists($privname, $pageMap)) {
$this->userDatabase[$username]['priv'][] = $pageMap[$privname];
}
Expand Down Expand Up @@ -144,7 +158,9 @@ private function loadUserGroupRights()
}
}
} elseif ($itemKey == "priv") {
foreach (array_filter(explode(',', $node_data)) as $privname) {
$privileges = array_filter(explode(',', $node_data));
usort($privileges, $privilegeSort);
foreach ($privileges as $privname) {
if (array_key_exists($privname, $pageMap)) {
$this->allGroupPrivs[$groupkey][] = $pageMap[$privname];
}
Expand Down Expand Up @@ -370,6 +386,10 @@ public function getLandingPage($username)
} elseif (!empty($this->userDatabase[$username])) {
// default behaviour, find first accessible location from configured privileges
foreach ($this->urlMasks($username) as $pattern) {
if (str_starts_with('api', $pattern)) {
continue;
}

if ($pattern == "*") {
return "index.php";
} elseif (!empty($pattern)) {
Expand Down