= $go_live) ? 1 : 2; } } return 1; } // Gets the minimum user level required to access a page function get_page_level($page) { global $auth, $max_level; // If you're resetting your password you won't be logged in and $auth['deny_public_access'] // should not apply. (change_password.php 同样放行:页面自身强制要求已登录,未登录会引导登录) if (in_array($page, array('reset_password.php', 'reset_password_handler.php', 'change_password.php'))) { return 0; } // Otherwise ... switch ($page) { // These pages are open to the public by default as they only contain // read features. case 'help.php': case 'index.php': $result = 0; break; // These pages reveal usernames, which could be of assistance to someone trying to // break into the system, so users are required to be logged in before viewing them. case 'search.php': $result = 1; break; case 'view_entry.php': $result = ($auth['allow_anonymous_booking']) ? 0 : 1; break; // These pages are set to have a minimum access level of 1 as ordinary users // should be able to access them because they will have read access and in some // cases write access for their own entries. Where necessary further checks are // made within the page to prevent ordinary users gaining access to admin features. case 'admin.php': case 'approve_entry_handler.php': // Ordinary users are allowed to remind admins case 'edit_message.php': // Booking admins can edit messages case 'edit_message_handler.php': // Booking admins can edit messages case 'edit_room.php': // Ordinary users can view room details case 'edit_users.php': // Ordinary users can edit their own details case 'pending.php': // Ordinary users can view their own entries case 'registration_handler.php': // Ordinary users can register for an event case 'usernames.php': // Ajax page for getting a list of users (booking admins can use this) $result = 1; break; // These pages allow users to create and delete entries case 'check_slot.php': // Ajax page used by edit_entry.php case 'del_entry.php': case 'edit_entry.php': case 'edit_entry_handler.php': return booking_level(); break; // Everything else is for admins only default: $result = (isset($max_level)) ? $max_level : 2; break; } if ($auth['deny_public_access']) { $result = max($result, 1); } // Can always access index.php when in kiosk mode if ($page == 'index.php' && is_kiosk_mode()) { $result = 0; } return $result; } /* getAuthorised($level) * * Check to see if the current user has a certain level of rights * * $level - The access level required * $returl - The URL to return to eventually * * Returns: * false - The user does not have the required access * true - The user has the required access */ function getAuthorised($level, $returl) : bool { // If the minimum level is zero (or not set) then they are // authorised, whoever they are if (empty($level)) { return true; } // Otherwise we need to check who they are $mrbs_user = session()->getCurrentUser(); if(!isset($mrbs_user)) { // Ask them to authenticate, if the session scheme supports it if (method_exists(session(), 'authGet')) { session()->authGet(null, $returl); } return false; } return ($mrbs_user->level >= $level); } /* checkAuthorised() * * Checks to see that a user is authorised to access a page. * If they are not, then shows an "Access Denied" message and exits. * */ function checkAuthorised($page, $just_check=false) { global $view, $view_all, $year, $month, $day, $area, $room; global $returl; // Get the minimum authorisation level for this page $required_level = get_page_level($page); if ($just_check) { if ($required_level == 0) { return true; } $mrbs_user = session()->getCurrentUser(); return (isset($mrbs_user) && ($mrbs_user->level >= $required_level)); } // Check that the user has this level if (getAuthorised($required_level, $returl)) { return true; } // If we don't know the right date then use today's if (!isset($day) or !isset($month) or !isset($year)) { $day = date('d'); $month = date('m'); $year = date('Y'); } if (empty($area)) { $area = get_default_area(); } showAccessDenied($view, $view_all, $year, $month, $day, $area, isset($room) ? $room : null); exit(); } /* getWritable($creator, $room) * * Determines if the current user is able to modify an entry * * $creator - The creator of the entry * $rooms - The id(s) of the room(s) that the entries are in. Can * be a scalar or an array. * $all - Whether to check that the creator has write access * for all ($all=true) or just some ($all=false) of the * rooms. * * Returns: * false - The user does not have the required access * true - The user has the required access */ function getWritable($creator, $rooms=null, $all=true) : bool { if (is_array($rooms) && (count($rooms) > 0)) { if ($all) { // We want the user to have write access for all the rooms, // so if for any one room they are not, then return false. foreach ($rooms as $room) { if (!getWritable($creator, $room)) { return false; } } return true; } else { // We want the user to have write access for at least one room, // so if there are no rooms for which they do, then return false. foreach ($rooms as $room) { if (getWritable($creator, $room)) { return true; } } return false; } } if (is_null($rooms) && !$all) { // Not yet supported. Could support it but need to decide what $rooms=null means. // Does it mean all rooms in the system or just all rooms in the current area? throw new \Exception('$rooms===null and $all===false not yet supported.'); } // You can't make bookings in rooms which are invisible if (!is_visible($rooms)) { return false; } // Always allowed to modify your own stuff $mrbs_user = session()->getCurrentUser(); if (isset($mrbs_user) && isset($creator) && (compare_usernames($creator, $mrbs_user->username) === 0)) { return true; } // Otherwise you have to be a (booking) admin for this room if (is_book_admin($rooms)) { return true; } // Unauthorised access return false; } /* showAccessDenied() * * Displays an appropriate message when access has been denied * * Returns: Nothing */ function showAccessDenied($view=null, $view_all=null, $year=null, $month=null, $day=null, $area=null, $room=null) { global $server; $context = array( 'view' => $view, 'view_all' => $view_all, 'year' => $year, 'month' => $month, 'day' => $day, 'area' => $area, 'room' => isset($room) ? $room : null ); print_header($context); // Wrap the contents in a
" . get_vocab("norights") . "
\n"; $referrer = session()->getReferrer(); if (isset($referrer)) { echo "\n"; echo "\n" . get_vocab("returnprev") . "\n"; echo "
\n"; } echo "