@@ -37,108 +37,108 @@ |
||
| 37 | 37 | |
| 38 | 38 | trait NavigationMenuAccessControl |
| 39 | 39 | { |
| 40 | - protected abstract function assign($name, $value); |
|
| 40 | + protected abstract function assign($name, $value); |
|
| 41 | 41 | |
| 42 | - protected abstract function getSecurityManager(): ISecurityManager; |
|
| 42 | + protected abstract function getSecurityManager(): ISecurityManager; |
|
| 43 | 43 | |
| 44 | - public abstract function getDomainAccessManager(): IDomainAccessManager; |
|
| 44 | + public abstract function getDomainAccessManager(): IDomainAccessManager; |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * @param $currentUser |
|
| 48 | - */ |
|
| 49 | - protected function setupNavMenuAccess($currentUser) |
|
| 50 | - { |
|
| 51 | - $this->assign('nav__canRequests', $this->getSecurityManager() |
|
| 52 | - ->allows(PageMain::class, RoleConfigurationBase::MAIN, $currentUser) === ISecurityManager::ALLOWED); |
|
| 46 | + /** |
|
| 47 | + * @param $currentUser |
|
| 48 | + */ |
|
| 49 | + protected function setupNavMenuAccess($currentUser) |
|
| 50 | + { |
|
| 51 | + $this->assign('nav__canRequests', $this->getSecurityManager() |
|
| 52 | + ->allows(PageMain::class, RoleConfigurationBase::MAIN, $currentUser) === ISecurityManager::ALLOWED); |
|
| 53 | 53 | |
| 54 | - $this->assign('nav__canLogs', $this->getSecurityManager() |
|
| 55 | - ->allows(PageLog::class, RoleConfigurationBase::MAIN, $currentUser) === ISecurityManager::ALLOWED); |
|
| 56 | - $this->assign('nav__canUsers', $this->getSecurityManager() |
|
| 57 | - ->allows(StatsUsers::class, RoleConfigurationBase::MAIN, $currentUser) === ISecurityManager::ALLOWED); |
|
| 58 | - $this->assign('nav__canSearch', $this->getSecurityManager() |
|
| 59 | - ->allows(PageSearch::class, RoleConfigurationBase::MAIN, $currentUser) === ISecurityManager::ALLOWED); |
|
| 60 | - $this->assign('nav__canStats', $this->getSecurityManager() |
|
| 61 | - ->allows(StatsMain::class, RoleConfigurationBase::MAIN, $currentUser) === ISecurityManager::ALLOWED); |
|
| 54 | + $this->assign('nav__canLogs', $this->getSecurityManager() |
|
| 55 | + ->allows(PageLog::class, RoleConfigurationBase::MAIN, $currentUser) === ISecurityManager::ALLOWED); |
|
| 56 | + $this->assign('nav__canUsers', $this->getSecurityManager() |
|
| 57 | + ->allows(StatsUsers::class, RoleConfigurationBase::MAIN, $currentUser) === ISecurityManager::ALLOWED); |
|
| 58 | + $this->assign('nav__canSearch', $this->getSecurityManager() |
|
| 59 | + ->allows(PageSearch::class, RoleConfigurationBase::MAIN, $currentUser) === ISecurityManager::ALLOWED); |
|
| 60 | + $this->assign('nav__canStats', $this->getSecurityManager() |
|
| 61 | + ->allows(StatsMain::class, RoleConfigurationBase::MAIN, $currentUser) === ISecurityManager::ALLOWED); |
|
| 62 | 62 | |
| 63 | - $this->assign('nav__canBan', $this->getSecurityManager() |
|
| 64 | - ->allows(PageBan::class, RoleConfigurationBase::MAIN, $currentUser) === ISecurityManager::ALLOWED); |
|
| 65 | - $this->assign('nav__canEmailMgmt', $this->getSecurityManager() |
|
| 66 | - ->allows(PageEmailManagement::class, RoleConfigurationBase::MAIN, |
|
| 67 | - $currentUser) === ISecurityManager::ALLOWED); |
|
| 68 | - $this->assign('nav__canWelcomeMgmt', $this->getSecurityManager() |
|
| 69 | - ->allows(PageWelcomeTemplateManagement::class, RoleConfigurationBase::MAIN, |
|
| 70 | - $currentUser) === ISecurityManager::ALLOWED); |
|
| 71 | - $this->assign('nav__canSiteNoticeMgmt', $this->getSecurityManager() |
|
| 72 | - ->allows(PageSiteNotice::class, RoleConfigurationBase::MAIN, $currentUser) === ISecurityManager::ALLOWED); |
|
| 73 | - $this->assign('nav__canUserMgmt', $this->getSecurityManager() |
|
| 74 | - ->allows(PageUserManagement::class, RoleConfigurationBase::MAIN, |
|
| 75 | - $currentUser) === ISecurityManager::ALLOWED); |
|
| 76 | - $this->assign('nav__canJobQueue', $this->getSecurityManager() |
|
| 77 | - ->allows(PageJobQueue::class, RoleConfigurationBase::MAIN, |
|
| 78 | - $currentUser) === ISecurityManager::ALLOWED); |
|
| 79 | - $this->assign('nav__canDomainMgmt', $this->getSecurityManager() |
|
| 80 | - ->allows(PageDomainManagement::class, RoleConfigurationBase::MAIN, |
|
| 81 | - $currentUser) === ISecurityManager::ALLOWED); |
|
| 82 | - $this->assign('nav__canFlaggedComments', $this->getSecurityManager() |
|
| 83 | - ->allows(PageListFlaggedComments::class, RoleConfigurationBase::MAIN, |
|
| 84 | - $currentUser) === ISecurityManager::ALLOWED); |
|
| 85 | - $this->assign('nav__canQueueMgmt', $this->getSecurityManager() |
|
| 86 | - ->allows(PageQueueManagement::class, RoleConfigurationBase::MAIN, |
|
| 87 | - $currentUser) === ISecurityManager::ALLOWED); |
|
| 88 | - $this->assign('nav__canFormMgmt', $this->getSecurityManager() |
|
| 89 | - ->allows(PageRequestFormManagement::class, RoleConfigurationBase::MAIN, |
|
| 90 | - $currentUser) === ISecurityManager::ALLOWED); |
|
| 91 | - $this->assign('nav__canErrorLog', $this->getSecurityManager() |
|
| 92 | - ->allows(PageErrorLogViewer::class, RoleConfigurationBase::MAIN, $currentUser) === ISecurityManager::ALLOWED); |
|
| 63 | + $this->assign('nav__canBan', $this->getSecurityManager() |
|
| 64 | + ->allows(PageBan::class, RoleConfigurationBase::MAIN, $currentUser) === ISecurityManager::ALLOWED); |
|
| 65 | + $this->assign('nav__canEmailMgmt', $this->getSecurityManager() |
|
| 66 | + ->allows(PageEmailManagement::class, RoleConfigurationBase::MAIN, |
|
| 67 | + $currentUser) === ISecurityManager::ALLOWED); |
|
| 68 | + $this->assign('nav__canWelcomeMgmt', $this->getSecurityManager() |
|
| 69 | + ->allows(PageWelcomeTemplateManagement::class, RoleConfigurationBase::MAIN, |
|
| 70 | + $currentUser) === ISecurityManager::ALLOWED); |
|
| 71 | + $this->assign('nav__canSiteNoticeMgmt', $this->getSecurityManager() |
|
| 72 | + ->allows(PageSiteNotice::class, RoleConfigurationBase::MAIN, $currentUser) === ISecurityManager::ALLOWED); |
|
| 73 | + $this->assign('nav__canUserMgmt', $this->getSecurityManager() |
|
| 74 | + ->allows(PageUserManagement::class, RoleConfigurationBase::MAIN, |
|
| 75 | + $currentUser) === ISecurityManager::ALLOWED); |
|
| 76 | + $this->assign('nav__canJobQueue', $this->getSecurityManager() |
|
| 77 | + ->allows(PageJobQueue::class, RoleConfigurationBase::MAIN, |
|
| 78 | + $currentUser) === ISecurityManager::ALLOWED); |
|
| 79 | + $this->assign('nav__canDomainMgmt', $this->getSecurityManager() |
|
| 80 | + ->allows(PageDomainManagement::class, RoleConfigurationBase::MAIN, |
|
| 81 | + $currentUser) === ISecurityManager::ALLOWED); |
|
| 82 | + $this->assign('nav__canFlaggedComments', $this->getSecurityManager() |
|
| 83 | + ->allows(PageListFlaggedComments::class, RoleConfigurationBase::MAIN, |
|
| 84 | + $currentUser) === ISecurityManager::ALLOWED); |
|
| 85 | + $this->assign('nav__canQueueMgmt', $this->getSecurityManager() |
|
| 86 | + ->allows(PageQueueManagement::class, RoleConfigurationBase::MAIN, |
|
| 87 | + $currentUser) === ISecurityManager::ALLOWED); |
|
| 88 | + $this->assign('nav__canFormMgmt', $this->getSecurityManager() |
|
| 89 | + ->allows(PageRequestFormManagement::class, RoleConfigurationBase::MAIN, |
|
| 90 | + $currentUser) === ISecurityManager::ALLOWED); |
|
| 91 | + $this->assign('nav__canErrorLog', $this->getSecurityManager() |
|
| 92 | + ->allows(PageErrorLogViewer::class, RoleConfigurationBase::MAIN, $currentUser) === ISecurityManager::ALLOWED); |
|
| 93 | 93 | |
| 94 | - $this->assign('nav__canViewRequest', $this->getSecurityManager() |
|
| 95 | - ->allows(PageViewRequest::class, RoleConfigurationBase::MAIN, $currentUser) === ISecurityManager::ALLOWED); |
|
| 94 | + $this->assign('nav__canViewRequest', $this->getSecurityManager() |
|
| 95 | + ->allows(PageViewRequest::class, RoleConfigurationBase::MAIN, $currentUser) === ISecurityManager::ALLOWED); |
|
| 96 | 96 | |
| 97 | - $this->assign('nav__domainList', []); |
|
| 98 | - if ($this->getDomainAccessManager() !== null) { |
|
| 99 | - $this->assign('nav__domainList', $this->getDomainAccessManager()->getAllowedDomains($currentUser)); |
|
| 100 | - } |
|
| 101 | - } |
|
| 97 | + $this->assign('nav__domainList', []); |
|
| 98 | + if ($this->getDomainAccessManager() !== null) { |
|
| 99 | + $this->assign('nav__domainList', $this->getDomainAccessManager()->getAllowedDomains($currentUser)); |
|
| 100 | + } |
|
| 101 | + } |
|
| 102 | 102 | |
| 103 | - /** |
|
| 104 | - * Sets up the badges to draw attention to issues on various admin pages. |
|
| 105 | - * |
|
| 106 | - * This function checks to see if a user can access the pages, and if so checks the count of problem areas. |
|
| 107 | - * If problem areas are found, a number greater than 0 will cause the badge to show up. |
|
| 108 | - * |
|
| 109 | - * @param User $currentUser The current user |
|
| 110 | - * @param PdoDatabase $database Database instance |
|
| 111 | - * |
|
| 112 | - * @return void |
|
| 113 | - */ |
|
| 114 | - public function setUpNavBarBadges(User $currentUser, PdoDatabase $database) { |
|
| 115 | - // Set up some variables. |
|
| 116 | - // A size of 0 causes nothing to show up on the page (checked on navigation-menu.tpl) so leaving it 0 here is fine. |
|
| 117 | - $countOfFlagged = 0; |
|
| 118 | - $countOfJobQueue = 0; |
|
| 103 | + /** |
|
| 104 | + * Sets up the badges to draw attention to issues on various admin pages. |
|
| 105 | + * |
|
| 106 | + * This function checks to see if a user can access the pages, and if so checks the count of problem areas. |
|
| 107 | + * If problem areas are found, a number greater than 0 will cause the badge to show up. |
|
| 108 | + * |
|
| 109 | + * @param User $currentUser The current user |
|
| 110 | + * @param PdoDatabase $database Database instance |
|
| 111 | + * |
|
| 112 | + * @return void |
|
| 113 | + */ |
|
| 114 | + public function setUpNavBarBadges(User $currentUser, PdoDatabase $database) { |
|
| 115 | + // Set up some variables. |
|
| 116 | + // A size of 0 causes nothing to show up on the page (checked on navigation-menu.tpl) so leaving it 0 here is fine. |
|
| 117 | + $countOfFlagged = 0; |
|
| 118 | + $countOfJobQueue = 0; |
|
| 119 | 119 | |
| 120 | - // Count of flagged comments: |
|
| 121 | - if($this->barrierTest(RoleConfigurationBase::MAIN, $currentUser, PageListFlaggedComments::class)) { |
|
| 122 | - // We want all flagged comments that haven't been acknowledged if we can visit the page. |
|
| 123 | - $countOfFlagged = sizeof(Comment::getFlaggedComments($database, 1)); // FIXME: domains |
|
| 124 | - } |
|
| 120 | + // Count of flagged comments: |
|
| 121 | + if($this->barrierTest(RoleConfigurationBase::MAIN, $currentUser, PageListFlaggedComments::class)) { |
|
| 122 | + // We want all flagged comments that haven't been acknowledged if we can visit the page. |
|
| 123 | + $countOfFlagged = sizeof(Comment::getFlaggedComments($database, 1)); // FIXME: domains |
|
| 124 | + } |
|
| 125 | 125 | |
| 126 | - // Count of failed job queue changes: |
|
| 127 | - if($this->barrierTest(RoleConfigurationBase::MAIN, $currentUser, PageJobQueue::class)) { |
|
| 128 | - // We want all failed jobs that haven't been acknowledged if we can visit the page. |
|
| 129 | - JobQueueSearchHelper::get($database, 1) // FIXME: domains |
|
| 130 | - ->statusIn([JobQueue::STATUS_FAILED]) |
|
| 131 | - ->notAcknowledged() |
|
| 132 | - ->getRecordCount($countOfJobQueue); |
|
| 133 | - } |
|
| 126 | + // Count of failed job queue changes: |
|
| 127 | + if($this->barrierTest(RoleConfigurationBase::MAIN, $currentUser, PageJobQueue::class)) { |
|
| 128 | + // We want all failed jobs that haven't been acknowledged if we can visit the page. |
|
| 129 | + JobQueueSearchHelper::get($database, 1) // FIXME: domains |
|
| 130 | + ->statusIn([JobQueue::STATUS_FAILED]) |
|
| 131 | + ->notAcknowledged() |
|
| 132 | + ->getRecordCount($countOfJobQueue); |
|
| 133 | + } |
|
| 134 | 134 | |
| 135 | - // To generate the main badge, add both up. |
|
| 136 | - // If we add more badges in the future, don't forget to add them here! |
|
| 137 | - $countOfAll = $countOfFlagged + $countOfJobQueue; |
|
| 135 | + // To generate the main badge, add both up. |
|
| 136 | + // If we add more badges in the future, don't forget to add them here! |
|
| 137 | + $countOfAll = $countOfFlagged + $countOfJobQueue; |
|
| 138 | 138 | |
| 139 | - // Set badge variables |
|
| 140 | - $this->assign("nav__numFlaggedComments", $countOfFlagged); |
|
| 141 | - $this->assign("nav__numJobQueueFailed", $countOfJobQueue); |
|
| 142 | - $this->assign("nav__numAdmin", $countOfAll); |
|
| 143 | - } |
|
| 139 | + // Set badge variables |
|
| 140 | + $this->assign("nav__numFlaggedComments", $countOfFlagged); |
|
| 141 | + $this->assign("nav__numJobQueueFailed", $countOfJobQueue); |
|
| 142 | + $this->assign("nav__numAdmin", $countOfAll); |
|
| 143 | + } |
|
| 144 | 144 | } |
@@ -118,13 +118,13 @@ |
||
| 118 | 118 | $countOfJobQueue = 0; |
| 119 | 119 | |
| 120 | 120 | // Count of flagged comments: |
| 121 | - if($this->barrierTest(RoleConfigurationBase::MAIN, $currentUser, PageListFlaggedComments::class)) { |
|
| 121 | + if ($this->barrierTest(RoleConfigurationBase::MAIN, $currentUser, PageListFlaggedComments::class)) { |
|
| 122 | 122 | // We want all flagged comments that haven't been acknowledged if we can visit the page. |
| 123 | 123 | $countOfFlagged = sizeof(Comment::getFlaggedComments($database, 1)); // FIXME: domains |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | // Count of failed job queue changes: |
| 127 | - if($this->barrierTest(RoleConfigurationBase::MAIN, $currentUser, PageJobQueue::class)) { |
|
| 127 | + if ($this->barrierTest(RoleConfigurationBase::MAIN, $currentUser, PageJobQueue::class)) { |
|
| 128 | 128 | // We want all failed jobs that haven't been acknowledged if we can visit the page. |
| 129 | 129 | JobQueueSearchHelper::get($database, 1) // FIXME: domains |
| 130 | 130 | ->statusIn([JobQueue::STATUS_FAILED]) |
@@ -27,350 +27,350 @@ |
||
| 27 | 27 | |
| 28 | 28 | trait RequestData |
| 29 | 29 | { |
| 30 | - /** @return SiteConfiguration */ |
|
| 31 | - protected abstract function getSiteConfiguration(); |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * @var array Array of IP address classed as 'private' by RFC1918. |
|
| 35 | - */ |
|
| 36 | - protected static $rfc1918ips = array( |
|
| 37 | - "10.0.0.0" => "10.255.255.255", |
|
| 38 | - "172.16.0.0" => "172.31.255.255", |
|
| 39 | - "192.168.0.0" => "192.168.255.255", |
|
| 40 | - "169.254.0.0" => "169.254.255.255", |
|
| 41 | - "127.0.0.0" => "127.255.255.255", |
|
| 42 | - ); |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * Gets a request object |
|
| 46 | - * |
|
| 47 | - * @param PdoDatabase $database The database connection |
|
| 48 | - * @param int|null $requestId The ID of the request to retrieve |
|
| 49 | - * |
|
| 50 | - * @return Request |
|
| 51 | - * @throws ApplicationLogicException |
|
| 52 | - */ |
|
| 53 | - protected function getRequest(PdoDatabase $database, $requestId) |
|
| 54 | - { |
|
| 55 | - if ($requestId === null) { |
|
| 56 | - throw new ApplicationLogicException("No request specified"); |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - $request = Request::getById($requestId, $database); |
|
| 60 | - if ($request === false || !is_a($request, Request::class)) { |
|
| 61 | - throw new ApplicationLogicException('Could not load the requested request!'); |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - return $request; |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * Returns a value stating whether the user is allowed to see private data or not |
|
| 69 | - * |
|
| 70 | - * @param Request $request |
|
| 71 | - * @param User $currentUser |
|
| 72 | - * |
|
| 73 | - * @return bool |
|
| 74 | - * @category Security-Critical |
|
| 75 | - */ |
|
| 76 | - protected function isAllowedPrivateData(Request $request, User $currentUser) |
|
| 77 | - { |
|
| 78 | - // Test the main security barrier for private data access using SecurityManager |
|
| 79 | - if ($this->barrierTest('alwaysSeePrivateData', $currentUser, 'RequestData')) { |
|
| 80 | - // Tool admins/check-users can always see private data |
|
| 81 | - return true; |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - // reserving user is allowed to see the data |
|
| 85 | - if ($currentUser->getId() === $request->getReserved() |
|
| 86 | - && $request->getReserved() !== null |
|
| 87 | - && $this->barrierTest('seePrivateDataWhenReserved', $currentUser, 'RequestData') |
|
| 88 | - ) { |
|
| 89 | - return true; |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - // user has the reveal hash |
|
| 93 | - if (WebRequest::getString('hash') === $request->getRevealHash() |
|
| 94 | - && $this->barrierTest('seePrivateDataWithHash', $currentUser, 'RequestData') |
|
| 95 | - ) { |
|
| 96 | - return true; |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - // nope. Not allowed. |
|
| 100 | - return false; |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * Tests the security barrier for a specified action. |
|
| 105 | - * |
|
| 106 | - * Don't use within templates |
|
| 107 | - * |
|
| 108 | - * @param string $action |
|
| 109 | - * |
|
| 110 | - * @param User $user |
|
| 111 | - * @param null|string $pageName |
|
| 112 | - * |
|
| 113 | - * @return bool |
|
| 114 | - * @category Security-Critical |
|
| 115 | - */ |
|
| 116 | - abstract protected function barrierTest($action, User $user, $pageName = null); |
|
| 117 | - |
|
| 118 | - /** |
|
| 119 | - * Gets the name of the route that has been passed from the request router. |
|
| 120 | - * @return string |
|
| 121 | - */ |
|
| 122 | - abstract protected function getRouteName(); |
|
| 123 | - |
|
| 124 | - abstract protected function getSecurityManager(): ISecurityManager; |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * Sets the name of the template this page should display. |
|
| 128 | - * |
|
| 129 | - * @param string $name |
|
| 130 | - */ |
|
| 131 | - abstract protected function setTemplate($name); |
|
| 132 | - |
|
| 133 | - /** @return IXffTrustProvider */ |
|
| 134 | - abstract protected function getXffTrustProvider(); |
|
| 135 | - |
|
| 136 | - /** @return ILocationProvider */ |
|
| 137 | - abstract protected function getLocationProvider(); |
|
| 138 | - |
|
| 139 | - /** @return IRDnsProvider */ |
|
| 140 | - abstract protected function getRdnsProvider(); |
|
| 141 | - |
|
| 142 | - /** |
|
| 143 | - * Assigns a Smarty variable |
|
| 144 | - * |
|
| 145 | - * @param array|string $name the template variable name(s) |
|
| 146 | - * @param mixed $value the value to assign |
|
| 147 | - */ |
|
| 148 | - abstract protected function assign($name, $value); |
|
| 149 | - |
|
| 150 | - /** |
|
| 151 | - * @param int|null $requestReservationId |
|
| 152 | - * @param PdoDatabase $database |
|
| 153 | - * @param User $currentUser |
|
| 154 | - */ |
|
| 155 | - protected function setupReservationDetails($requestReservationId, PdoDatabase $database, User $currentUser) |
|
| 156 | - { |
|
| 157 | - $requestIsReserved = $requestReservationId !== null; |
|
| 158 | - $this->assign('requestIsReserved', $requestIsReserved); |
|
| 159 | - $this->assign('requestIsReservedByMe', false); |
|
| 160 | - |
|
| 161 | - if ($requestIsReserved) { |
|
| 162 | - $this->assign('requestReservedByName', User::getById($requestReservationId, $database)->getUsername()); |
|
| 163 | - $this->assign('requestReservedById', $requestReservationId); |
|
| 164 | - |
|
| 165 | - if ($requestReservationId === $currentUser->getId()) { |
|
| 166 | - $this->assign('requestIsReservedByMe', true); |
|
| 167 | - } |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - $this->assign('canBreakReservation', $this->barrierTest('force', $currentUser, PageBreakReservation::class)); |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - /** |
|
| 174 | - * Adds private request data to Smarty. DO NOT USE WITHOUT FIRST CHECKING THAT THE USER IS AUTHORISED! |
|
| 175 | - * |
|
| 176 | - * @param Request $request |
|
| 177 | - * @param SiteConfiguration $configuration |
|
| 178 | - */ |
|
| 179 | - protected function setupPrivateData( |
|
| 180 | - $request, |
|
| 181 | - SiteConfiguration $configuration |
|
| 182 | - ) { |
|
| 183 | - $xffProvider = $this->getXffTrustProvider(); |
|
| 184 | - |
|
| 185 | - $this->assign('requestEmail', $request->getEmail()); |
|
| 186 | - $emailDomain = explode("@", $request->getEmail())[1]; |
|
| 187 | - $this->assign("emailurl", $emailDomain); |
|
| 188 | - $this->assign('commonEmailDomain', in_array(strtolower($emailDomain), $configuration->getCommonEmailDomains()) |
|
| 189 | - || $request->getEmail() === $this->getSiteConfiguration()->getDataClearEmail()); |
|
| 190 | - |
|
| 191 | - $trustedIp = $xffProvider->getTrustedClientIp($request->getIp(), $request->getForwardedIp()); |
|
| 192 | - $this->assign('requestTrustedIp', $trustedIp); |
|
| 193 | - $this->assign('requestRealIp', $request->getIp()); |
|
| 194 | - $this->assign('requestForwardedIp', $request->getForwardedIp()); |
|
| 195 | - |
|
| 196 | - $trustedIpLocation = $this->getLocationProvider()->getIpLocation($trustedIp); |
|
| 197 | - $this->assign('requestTrustedIpLocation', $trustedIpLocation); |
|
| 198 | - |
|
| 199 | - $this->assign('requestHasForwardedIp', $request->getForwardedIp() !== null); |
|
| 200 | - |
|
| 201 | - $this->setupForwardedIpData($request); |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - /** |
|
| 205 | - * Adds related request data to Smarty. DO NOT USE WITHOUT FIRST CHECKING THAT THE USER IS AUTHORISED! |
|
| 206 | - * |
|
| 207 | - * @param Request $request |
|
| 208 | - * @param SiteConfiguration $configuration |
|
| 209 | - * @param PdoDatabase $database |
|
| 210 | - */ |
|
| 211 | - protected function setupRelatedRequests( |
|
| 212 | - Request $request, |
|
| 213 | - SiteConfiguration $configuration, |
|
| 214 | - PdoDatabase $database) |
|
| 215 | - { |
|
| 216 | - $this->assign('canSeeRelatedRequests', true); |
|
| 217 | - |
|
| 218 | - // TODO: Do we want to return results from other domains? |
|
| 219 | - $relatedEmailRequests = RequestSearchHelper::get($database, null) |
|
| 220 | - ->byEmailAddress($request->getEmail()) |
|
| 221 | - ->withConfirmedEmail() |
|
| 222 | - ->excludingPurgedData($configuration) |
|
| 223 | - ->excludingRequest($request->getId()) |
|
| 224 | - ->fetch(); |
|
| 225 | - |
|
| 226 | - $this->assign('requestRelatedEmailRequestsCount', count($relatedEmailRequests)); |
|
| 227 | - $this->assign('requestRelatedEmailRequests', $relatedEmailRequests); |
|
| 228 | - |
|
| 229 | - $trustedIp = $this->getXffTrustProvider()->getTrustedClientIp($request->getIp(), $request->getForwardedIp()); |
|
| 230 | - |
|
| 231 | - // TODO: Do we want to return results from other domains? |
|
| 232 | - $relatedIpRequests = RequestSearchHelper::get($database, null) |
|
| 233 | - ->byIp($trustedIp) |
|
| 234 | - ->withConfirmedEmail() |
|
| 235 | - ->excludingPurgedData($configuration) |
|
| 236 | - ->excludingRequest($request->getId()) |
|
| 237 | - ->fetch(); |
|
| 238 | - |
|
| 239 | - $this->assign('requestRelatedIpRequestsCount', count($relatedIpRequests)); |
|
| 240 | - $this->assign('requestRelatedIpRequests', $relatedIpRequests); |
|
| 241 | - } |
|
| 242 | - |
|
| 243 | - /** |
|
| 244 | - * Adds checkuser request data to Smarty. DO NOT USE WITHOUT FIRST CHECKING THAT THE USER IS AUTHORISED! |
|
| 245 | - * |
|
| 246 | - * @param Request $request |
|
| 247 | - */ |
|
| 248 | - protected function setupCheckUserData(Request $request) |
|
| 249 | - { |
|
| 250 | - $this->assign('requestUserAgent', $request->getUserAgent()); |
|
| 251 | - |
|
| 252 | - $data = \Waca\DataObjects\RequestData::getForRequest($request->getId(), $request->getDatabase(), \Waca\DataObjects\RequestData::TYPE_CLIENTHINT); |
|
| 253 | - $this->assign('requestClientHints', $data); |
|
| 254 | - } |
|
| 255 | - |
|
| 256 | - /** |
|
| 257 | - * Sets up the basic data for this request, and adds it to Smarty |
|
| 258 | - * |
|
| 259 | - * @param Request $request |
|
| 260 | - * @param SiteConfiguration $config |
|
| 261 | - */ |
|
| 262 | - protected function setupBasicData(Request $request, SiteConfiguration $config) |
|
| 263 | - { |
|
| 264 | - $this->assign('requestId', $request->getId()); |
|
| 265 | - $this->assign('updateVersion', $request->getUpdateVersion()); |
|
| 266 | - $this->assign('requestName', $request->getName()); |
|
| 267 | - $this->assign('requestDate', $request->getDate()); |
|
| 268 | - $this->assign('requestStatus', $request->getStatus()); |
|
| 269 | - |
|
| 270 | - $this->assign('requestQueue', null); |
|
| 271 | - if ($request->getQueue() !== null) { |
|
| 272 | - /** @var RequestQueue $queue */ |
|
| 273 | - $queue = RequestQueue::getById($request->getQueue(), $this->getDatabase()); |
|
| 274 | - $this->assign('requestQueue', $queue->getHeader()); |
|
| 275 | - $this->assign('requestQueueApiName', $queue->getApiName()); |
|
| 276 | - } |
|
| 277 | - |
|
| 278 | - $this->assign('canPreviewForm', $this->barrierTest('view', User::getCurrent($this->getDatabase()), PageRequestFormManagement::class)); |
|
| 279 | - $this->assign('originForm', $request->getOriginFormObject()); |
|
| 280 | - |
|
| 281 | - $isClosed = $request->getStatus() === RequestStatus::CLOSED || $request->getStatus() === RequestStatus::JOBQUEUE; |
|
| 282 | - $this->assign('requestIsClosed', $isClosed); |
|
| 30 | + /** @return SiteConfiguration */ |
|
| 31 | + protected abstract function getSiteConfiguration(); |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * @var array Array of IP address classed as 'private' by RFC1918. |
|
| 35 | + */ |
|
| 36 | + protected static $rfc1918ips = array( |
|
| 37 | + "10.0.0.0" => "10.255.255.255", |
|
| 38 | + "172.16.0.0" => "172.31.255.255", |
|
| 39 | + "192.168.0.0" => "192.168.255.255", |
|
| 40 | + "169.254.0.0" => "169.254.255.255", |
|
| 41 | + "127.0.0.0" => "127.255.255.255", |
|
| 42 | + ); |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * Gets a request object |
|
| 46 | + * |
|
| 47 | + * @param PdoDatabase $database The database connection |
|
| 48 | + * @param int|null $requestId The ID of the request to retrieve |
|
| 49 | + * |
|
| 50 | + * @return Request |
|
| 51 | + * @throws ApplicationLogicException |
|
| 52 | + */ |
|
| 53 | + protected function getRequest(PdoDatabase $database, $requestId) |
|
| 54 | + { |
|
| 55 | + if ($requestId === null) { |
|
| 56 | + throw new ApplicationLogicException("No request specified"); |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + $request = Request::getById($requestId, $database); |
|
| 60 | + if ($request === false || !is_a($request, Request::class)) { |
|
| 61 | + throw new ApplicationLogicException('Could not load the requested request!'); |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + return $request; |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * Returns a value stating whether the user is allowed to see private data or not |
|
| 69 | + * |
|
| 70 | + * @param Request $request |
|
| 71 | + * @param User $currentUser |
|
| 72 | + * |
|
| 73 | + * @return bool |
|
| 74 | + * @category Security-Critical |
|
| 75 | + */ |
|
| 76 | + protected function isAllowedPrivateData(Request $request, User $currentUser) |
|
| 77 | + { |
|
| 78 | + // Test the main security barrier for private data access using SecurityManager |
|
| 79 | + if ($this->barrierTest('alwaysSeePrivateData', $currentUser, 'RequestData')) { |
|
| 80 | + // Tool admins/check-users can always see private data |
|
| 81 | + return true; |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + // reserving user is allowed to see the data |
|
| 85 | + if ($currentUser->getId() === $request->getReserved() |
|
| 86 | + && $request->getReserved() !== null |
|
| 87 | + && $this->barrierTest('seePrivateDataWhenReserved', $currentUser, 'RequestData') |
|
| 88 | + ) { |
|
| 89 | + return true; |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + // user has the reveal hash |
|
| 93 | + if (WebRequest::getString('hash') === $request->getRevealHash() |
|
| 94 | + && $this->barrierTest('seePrivateDataWithHash', $currentUser, 'RequestData') |
|
| 95 | + ) { |
|
| 96 | + return true; |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + // nope. Not allowed. |
|
| 100 | + return false; |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * Tests the security barrier for a specified action. |
|
| 105 | + * |
|
| 106 | + * Don't use within templates |
|
| 107 | + * |
|
| 108 | + * @param string $action |
|
| 109 | + * |
|
| 110 | + * @param User $user |
|
| 111 | + * @param null|string $pageName |
|
| 112 | + * |
|
| 113 | + * @return bool |
|
| 114 | + * @category Security-Critical |
|
| 115 | + */ |
|
| 116 | + abstract protected function barrierTest($action, User $user, $pageName = null); |
|
| 117 | + |
|
| 118 | + /** |
|
| 119 | + * Gets the name of the route that has been passed from the request router. |
|
| 120 | + * @return string |
|
| 121 | + */ |
|
| 122 | + abstract protected function getRouteName(); |
|
| 123 | + |
|
| 124 | + abstract protected function getSecurityManager(): ISecurityManager; |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * Sets the name of the template this page should display. |
|
| 128 | + * |
|
| 129 | + * @param string $name |
|
| 130 | + */ |
|
| 131 | + abstract protected function setTemplate($name); |
|
| 132 | + |
|
| 133 | + /** @return IXffTrustProvider */ |
|
| 134 | + abstract protected function getXffTrustProvider(); |
|
| 135 | + |
|
| 136 | + /** @return ILocationProvider */ |
|
| 137 | + abstract protected function getLocationProvider(); |
|
| 138 | + |
|
| 139 | + /** @return IRDnsProvider */ |
|
| 140 | + abstract protected function getRdnsProvider(); |
|
| 141 | + |
|
| 142 | + /** |
|
| 143 | + * Assigns a Smarty variable |
|
| 144 | + * |
|
| 145 | + * @param array|string $name the template variable name(s) |
|
| 146 | + * @param mixed $value the value to assign |
|
| 147 | + */ |
|
| 148 | + abstract protected function assign($name, $value); |
|
| 149 | + |
|
| 150 | + /** |
|
| 151 | + * @param int|null $requestReservationId |
|
| 152 | + * @param PdoDatabase $database |
|
| 153 | + * @param User $currentUser |
|
| 154 | + */ |
|
| 155 | + protected function setupReservationDetails($requestReservationId, PdoDatabase $database, User $currentUser) |
|
| 156 | + { |
|
| 157 | + $requestIsReserved = $requestReservationId !== null; |
|
| 158 | + $this->assign('requestIsReserved', $requestIsReserved); |
|
| 159 | + $this->assign('requestIsReservedByMe', false); |
|
| 160 | + |
|
| 161 | + if ($requestIsReserved) { |
|
| 162 | + $this->assign('requestReservedByName', User::getById($requestReservationId, $database)->getUsername()); |
|
| 163 | + $this->assign('requestReservedById', $requestReservationId); |
|
| 164 | + |
|
| 165 | + if ($requestReservationId === $currentUser->getId()) { |
|
| 166 | + $this->assign('requestIsReservedByMe', true); |
|
| 167 | + } |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + $this->assign('canBreakReservation', $this->barrierTest('force', $currentUser, PageBreakReservation::class)); |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + /** |
|
| 174 | + * Adds private request data to Smarty. DO NOT USE WITHOUT FIRST CHECKING THAT THE USER IS AUTHORISED! |
|
| 175 | + * |
|
| 176 | + * @param Request $request |
|
| 177 | + * @param SiteConfiguration $configuration |
|
| 178 | + */ |
|
| 179 | + protected function setupPrivateData( |
|
| 180 | + $request, |
|
| 181 | + SiteConfiguration $configuration |
|
| 182 | + ) { |
|
| 183 | + $xffProvider = $this->getXffTrustProvider(); |
|
| 184 | + |
|
| 185 | + $this->assign('requestEmail', $request->getEmail()); |
|
| 186 | + $emailDomain = explode("@", $request->getEmail())[1]; |
|
| 187 | + $this->assign("emailurl", $emailDomain); |
|
| 188 | + $this->assign('commonEmailDomain', in_array(strtolower($emailDomain), $configuration->getCommonEmailDomains()) |
|
| 189 | + || $request->getEmail() === $this->getSiteConfiguration()->getDataClearEmail()); |
|
| 190 | + |
|
| 191 | + $trustedIp = $xffProvider->getTrustedClientIp($request->getIp(), $request->getForwardedIp()); |
|
| 192 | + $this->assign('requestTrustedIp', $trustedIp); |
|
| 193 | + $this->assign('requestRealIp', $request->getIp()); |
|
| 194 | + $this->assign('requestForwardedIp', $request->getForwardedIp()); |
|
| 195 | + |
|
| 196 | + $trustedIpLocation = $this->getLocationProvider()->getIpLocation($trustedIp); |
|
| 197 | + $this->assign('requestTrustedIpLocation', $trustedIpLocation); |
|
| 198 | + |
|
| 199 | + $this->assign('requestHasForwardedIp', $request->getForwardedIp() !== null); |
|
| 200 | + |
|
| 201 | + $this->setupForwardedIpData($request); |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + /** |
|
| 205 | + * Adds related request data to Smarty. DO NOT USE WITHOUT FIRST CHECKING THAT THE USER IS AUTHORISED! |
|
| 206 | + * |
|
| 207 | + * @param Request $request |
|
| 208 | + * @param SiteConfiguration $configuration |
|
| 209 | + * @param PdoDatabase $database |
|
| 210 | + */ |
|
| 211 | + protected function setupRelatedRequests( |
|
| 212 | + Request $request, |
|
| 213 | + SiteConfiguration $configuration, |
|
| 214 | + PdoDatabase $database) |
|
| 215 | + { |
|
| 216 | + $this->assign('canSeeRelatedRequests', true); |
|
| 217 | + |
|
| 218 | + // TODO: Do we want to return results from other domains? |
|
| 219 | + $relatedEmailRequests = RequestSearchHelper::get($database, null) |
|
| 220 | + ->byEmailAddress($request->getEmail()) |
|
| 221 | + ->withConfirmedEmail() |
|
| 222 | + ->excludingPurgedData($configuration) |
|
| 223 | + ->excludingRequest($request->getId()) |
|
| 224 | + ->fetch(); |
|
| 225 | + |
|
| 226 | + $this->assign('requestRelatedEmailRequestsCount', count($relatedEmailRequests)); |
|
| 227 | + $this->assign('requestRelatedEmailRequests', $relatedEmailRequests); |
|
| 228 | + |
|
| 229 | + $trustedIp = $this->getXffTrustProvider()->getTrustedClientIp($request->getIp(), $request->getForwardedIp()); |
|
| 230 | + |
|
| 231 | + // TODO: Do we want to return results from other domains? |
|
| 232 | + $relatedIpRequests = RequestSearchHelper::get($database, null) |
|
| 233 | + ->byIp($trustedIp) |
|
| 234 | + ->withConfirmedEmail() |
|
| 235 | + ->excludingPurgedData($configuration) |
|
| 236 | + ->excludingRequest($request->getId()) |
|
| 237 | + ->fetch(); |
|
| 238 | + |
|
| 239 | + $this->assign('requestRelatedIpRequestsCount', count($relatedIpRequests)); |
|
| 240 | + $this->assign('requestRelatedIpRequests', $relatedIpRequests); |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + /** |
|
| 244 | + * Adds checkuser request data to Smarty. DO NOT USE WITHOUT FIRST CHECKING THAT THE USER IS AUTHORISED! |
|
| 245 | + * |
|
| 246 | + * @param Request $request |
|
| 247 | + */ |
|
| 248 | + protected function setupCheckUserData(Request $request) |
|
| 249 | + { |
|
| 250 | + $this->assign('requestUserAgent', $request->getUserAgent()); |
|
| 251 | + |
|
| 252 | + $data = \Waca\DataObjects\RequestData::getForRequest($request->getId(), $request->getDatabase(), \Waca\DataObjects\RequestData::TYPE_CLIENTHINT); |
|
| 253 | + $this->assign('requestClientHints', $data); |
|
| 254 | + } |
|
| 255 | + |
|
| 256 | + /** |
|
| 257 | + * Sets up the basic data for this request, and adds it to Smarty |
|
| 258 | + * |
|
| 259 | + * @param Request $request |
|
| 260 | + * @param SiteConfiguration $config |
|
| 261 | + */ |
|
| 262 | + protected function setupBasicData(Request $request, SiteConfiguration $config) |
|
| 263 | + { |
|
| 264 | + $this->assign('requestId', $request->getId()); |
|
| 265 | + $this->assign('updateVersion', $request->getUpdateVersion()); |
|
| 266 | + $this->assign('requestName', $request->getName()); |
|
| 267 | + $this->assign('requestDate', $request->getDate()); |
|
| 268 | + $this->assign('requestStatus', $request->getStatus()); |
|
| 269 | + |
|
| 270 | + $this->assign('requestQueue', null); |
|
| 271 | + if ($request->getQueue() !== null) { |
|
| 272 | + /** @var RequestQueue $queue */ |
|
| 273 | + $queue = RequestQueue::getById($request->getQueue(), $this->getDatabase()); |
|
| 274 | + $this->assign('requestQueue', $queue->getHeader()); |
|
| 275 | + $this->assign('requestQueueApiName', $queue->getApiName()); |
|
| 276 | + } |
|
| 277 | + |
|
| 278 | + $this->assign('canPreviewForm', $this->barrierTest('view', User::getCurrent($this->getDatabase()), PageRequestFormManagement::class)); |
|
| 279 | + $this->assign('originForm', $request->getOriginFormObject()); |
|
| 280 | + |
|
| 281 | + $isClosed = $request->getStatus() === RequestStatus::CLOSED || $request->getStatus() === RequestStatus::JOBQUEUE; |
|
| 282 | + $this->assign('requestIsClosed', $isClosed); |
|
| 283 | 283 | $isHospital = $request->getStatus() === RequestStatus::HOSPITAL; |
| 284 | 284 | $this->assign('requestIsHospital', $isHospital); |
| 285 | - } |
|
| 286 | - |
|
| 287 | - /** |
|
| 288 | - * Sets up the forwarded IP data for this request and adds it to Smarty |
|
| 289 | - * |
|
| 290 | - * @param Request $request |
|
| 291 | - */ |
|
| 292 | - protected function setupForwardedIpData(Request $request) |
|
| 293 | - { |
|
| 294 | - if ($request->getForwardedIp() !== null) { |
|
| 295 | - $requestProxyData = array(); // Initialize array to store data to be output in Smarty template. |
|
| 296 | - $proxyIndex = 0; |
|
| 297 | - |
|
| 298 | - // Assuming [client] <=> [proxy1] <=> [proxy2] <=> [proxy3] <=> [us], we will see an XFF header of [client], |
|
| 299 | - // [proxy1], [proxy2], and our actual IP will be [proxy3] |
|
| 300 | - $proxies = explode(",", $request->getForwardedIp()); |
|
| 301 | - $proxies[] = $request->getIp(); |
|
| 302 | - |
|
| 303 | - // Origin is the supposed "client" IP. |
|
| 304 | - $origin = $proxies[0]; |
|
| 305 | - $this->assign("forwardedOrigin", $origin); |
|
| 306 | - |
|
| 307 | - // We step through the servers in reverse order, from closest to furthest |
|
| 308 | - $proxies = array_reverse($proxies); |
|
| 309 | - |
|
| 310 | - // By default, we have trust, because the first in the chain is now REMOTE_ADDR, which is hardest to spoof. |
|
| 311 | - $trust = true; |
|
| 312 | - |
|
| 313 | - /** |
|
| 314 | - * @var int $index The zero-based index of the proxy. |
|
| 315 | - * @var string $proxyData The proxy IP address (although possibly not!) |
|
| 316 | - */ |
|
| 317 | - foreach ($proxies as $index => $proxyData) { |
|
| 318 | - $proxyAddress = trim($proxyData); |
|
| 319 | - $requestProxyData[$proxyIndex]['ip'] = $proxyAddress; |
|
| 320 | - |
|
| 321 | - // get data on this IP. |
|
| 322 | - $thisProxyIsTrusted = $this->getXffTrustProvider()->isTrusted($proxyAddress); |
|
| 323 | - |
|
| 324 | - $proxyIsInPrivateRange = $this->getXffTrustProvider() |
|
| 325 | - ->ipInRange(self::$rfc1918ips, $proxyAddress); |
|
| 326 | - |
|
| 327 | - if (!$proxyIsInPrivateRange) { |
|
| 328 | - $proxyReverseDns = $this->getRdnsProvider()->getReverseDNS($proxyAddress); |
|
| 329 | - $proxyLocation = $this->getLocationProvider()->getIpLocation($proxyAddress); |
|
| 330 | - } |
|
| 331 | - else { |
|
| 332 | - // this is going to fail, so why bother trying? |
|
| 333 | - $proxyReverseDns = false; |
|
| 334 | - $proxyLocation = false; |
|
| 335 | - } |
|
| 336 | - |
|
| 337 | - // current trust chain status BEFORE this link |
|
| 338 | - $preLinkTrust = $trust; |
|
| 339 | - |
|
| 340 | - // is *this* link trusted? Note, this will be true even if there is an untrusted link before this! |
|
| 341 | - $requestProxyData[$proxyIndex]['trustedlink'] = $thisProxyIsTrusted; |
|
| 342 | - |
|
| 343 | - // set the trust status of the chain to this point |
|
| 344 | - $trust = $trust & $thisProxyIsTrusted; |
|
| 345 | - |
|
| 346 | - // If this is the origin address, and the chain was trusted before this point, then we can trust |
|
| 347 | - // the origin. |
|
| 348 | - if ($preLinkTrust && $proxyAddress == $origin) { |
|
| 349 | - // if this is the origin, then we are at the last point in the chain. |
|
| 350 | - // @todo: this is probably the cause of some bugs when an IP appears twice - we're missing a check |
|
| 351 | - // to see if this is *really* the last in the chain, rather than just the same IP as it. |
|
| 352 | - $trust = true; |
|
| 353 | - } |
|
| 354 | - |
|
| 355 | - $requestProxyData[$proxyIndex]['trust'] = $trust; |
|
| 356 | - |
|
| 357 | - $requestProxyData[$proxyIndex]['rdnsfailed'] = $proxyReverseDns === false; |
|
| 358 | - $requestProxyData[$proxyIndex]['rdns'] = $proxyReverseDns; |
|
| 359 | - $requestProxyData[$proxyIndex]['routable'] = !$proxyIsInPrivateRange; |
|
| 360 | - |
|
| 361 | - $requestProxyData[$proxyIndex]['location'] = $proxyLocation; |
|
| 362 | - |
|
| 363 | - if ($proxyReverseDns === $proxyAddress && $proxyIsInPrivateRange === false) { |
|
| 364 | - $requestProxyData[$proxyIndex]['rdns'] = null; |
|
| 365 | - } |
|
| 366 | - |
|
| 367 | - $showLinks = (!$trust || $proxyAddress == $origin) && !$proxyIsInPrivateRange; |
|
| 368 | - $requestProxyData[$proxyIndex]['showlinks'] = $showLinks; |
|
| 369 | - |
|
| 370 | - $proxyIndex++; |
|
| 371 | - } |
|
| 372 | - |
|
| 373 | - $this->assign("requestProxyData", $requestProxyData); |
|
| 374 | - } |
|
| 375 | - } |
|
| 285 | + } |
|
| 286 | + |
|
| 287 | + /** |
|
| 288 | + * Sets up the forwarded IP data for this request and adds it to Smarty |
|
| 289 | + * |
|
| 290 | + * @param Request $request |
|
| 291 | + */ |
|
| 292 | + protected function setupForwardedIpData(Request $request) |
|
| 293 | + { |
|
| 294 | + if ($request->getForwardedIp() !== null) { |
|
| 295 | + $requestProxyData = array(); // Initialize array to store data to be output in Smarty template. |
|
| 296 | + $proxyIndex = 0; |
|
| 297 | + |
|
| 298 | + // Assuming [client] <=> [proxy1] <=> [proxy2] <=> [proxy3] <=> [us], we will see an XFF header of [client], |
|
| 299 | + // [proxy1], [proxy2], and our actual IP will be [proxy3] |
|
| 300 | + $proxies = explode(",", $request->getForwardedIp()); |
|
| 301 | + $proxies[] = $request->getIp(); |
|
| 302 | + |
|
| 303 | + // Origin is the supposed "client" IP. |
|
| 304 | + $origin = $proxies[0]; |
|
| 305 | + $this->assign("forwardedOrigin", $origin); |
|
| 306 | + |
|
| 307 | + // We step through the servers in reverse order, from closest to furthest |
|
| 308 | + $proxies = array_reverse($proxies); |
|
| 309 | + |
|
| 310 | + // By default, we have trust, because the first in the chain is now REMOTE_ADDR, which is hardest to spoof. |
|
| 311 | + $trust = true; |
|
| 312 | + |
|
| 313 | + /** |
|
| 314 | + * @var int $index The zero-based index of the proxy. |
|
| 315 | + * @var string $proxyData The proxy IP address (although possibly not!) |
|
| 316 | + */ |
|
| 317 | + foreach ($proxies as $index => $proxyData) { |
|
| 318 | + $proxyAddress = trim($proxyData); |
|
| 319 | + $requestProxyData[$proxyIndex]['ip'] = $proxyAddress; |
|
| 320 | + |
|
| 321 | + // get data on this IP. |
|
| 322 | + $thisProxyIsTrusted = $this->getXffTrustProvider()->isTrusted($proxyAddress); |
|
| 323 | + |
|
| 324 | + $proxyIsInPrivateRange = $this->getXffTrustProvider() |
|
| 325 | + ->ipInRange(self::$rfc1918ips, $proxyAddress); |
|
| 326 | + |
|
| 327 | + if (!$proxyIsInPrivateRange) { |
|
| 328 | + $proxyReverseDns = $this->getRdnsProvider()->getReverseDNS($proxyAddress); |
|
| 329 | + $proxyLocation = $this->getLocationProvider()->getIpLocation($proxyAddress); |
|
| 330 | + } |
|
| 331 | + else { |
|
| 332 | + // this is going to fail, so why bother trying? |
|
| 333 | + $proxyReverseDns = false; |
|
| 334 | + $proxyLocation = false; |
|
| 335 | + } |
|
| 336 | + |
|
| 337 | + // current trust chain status BEFORE this link |
|
| 338 | + $preLinkTrust = $trust; |
|
| 339 | + |
|
| 340 | + // is *this* link trusted? Note, this will be true even if there is an untrusted link before this! |
|
| 341 | + $requestProxyData[$proxyIndex]['trustedlink'] = $thisProxyIsTrusted; |
|
| 342 | + |
|
| 343 | + // set the trust status of the chain to this point |
|
| 344 | + $trust = $trust & $thisProxyIsTrusted; |
|
| 345 | + |
|
| 346 | + // If this is the origin address, and the chain was trusted before this point, then we can trust |
|
| 347 | + // the origin. |
|
| 348 | + if ($preLinkTrust && $proxyAddress == $origin) { |
|
| 349 | + // if this is the origin, then we are at the last point in the chain. |
|
| 350 | + // @todo: this is probably the cause of some bugs when an IP appears twice - we're missing a check |
|
| 351 | + // to see if this is *really* the last in the chain, rather than just the same IP as it. |
|
| 352 | + $trust = true; |
|
| 353 | + } |
|
| 354 | + |
|
| 355 | + $requestProxyData[$proxyIndex]['trust'] = $trust; |
|
| 356 | + |
|
| 357 | + $requestProxyData[$proxyIndex]['rdnsfailed'] = $proxyReverseDns === false; |
|
| 358 | + $requestProxyData[$proxyIndex]['rdns'] = $proxyReverseDns; |
|
| 359 | + $requestProxyData[$proxyIndex]['routable'] = !$proxyIsInPrivateRange; |
|
| 360 | + |
|
| 361 | + $requestProxyData[$proxyIndex]['location'] = $proxyLocation; |
|
| 362 | + |
|
| 363 | + if ($proxyReverseDns === $proxyAddress && $proxyIsInPrivateRange === false) { |
|
| 364 | + $requestProxyData[$proxyIndex]['rdns'] = null; |
|
| 365 | + } |
|
| 366 | + |
|
| 367 | + $showLinks = (!$trust || $proxyAddress == $origin) && !$proxyIsInPrivateRange; |
|
| 368 | + $requestProxyData[$proxyIndex]['showlinks'] = $showLinks; |
|
| 369 | + |
|
| 370 | + $proxyIndex++; |
|
| 371 | + } |
|
| 372 | + |
|
| 373 | + $this->assign("requestProxyData", $requestProxyData); |
|
| 374 | + } |
|
| 375 | + } |
|
| 376 | 376 | } |
@@ -16,20 +16,20 @@ |
||
| 16 | 16 | |
| 17 | 17 | trait LogEntryLookup |
| 18 | 18 | { |
| 19 | - protected function getLogEntry(string $action, User $user, PdoDatabase $database): ?string |
|
| 20 | - { |
|
| 21 | - /** @var Log[] $logs */ |
|
| 22 | - $logs = LogSearchHelper::get($database, null) |
|
| 23 | - ->byAction($action) |
|
| 24 | - ->byObjectType('User') |
|
| 25 | - ->byObjectId($user->getId()) |
|
| 26 | - ->limit(1) |
|
| 27 | - ->fetch(); |
|
| 19 | + protected function getLogEntry(string $action, User $user, PdoDatabase $database): ?string |
|
| 20 | + { |
|
| 21 | + /** @var Log[] $logs */ |
|
| 22 | + $logs = LogSearchHelper::get($database, null) |
|
| 23 | + ->byAction($action) |
|
| 24 | + ->byObjectType('User') |
|
| 25 | + ->byObjectId($user->getId()) |
|
| 26 | + ->limit(1) |
|
| 27 | + ->fetch(); |
|
| 28 | 28 | |
| 29 | - if (count($logs) > 0) { |
|
| 30 | - return $logs[0]->getComment(); |
|
| 31 | - } |
|
| 29 | + if (count($logs) > 0) { |
|
| 30 | + return $logs[0]->getComment(); |
|
| 31 | + } |
|
| 32 | 32 | |
| 33 | - return null; |
|
| 34 | - } |
|
| 33 | + return null; |
|
| 34 | + } |
|
| 35 | 35 | } |
| 36 | 36 | \ No newline at end of file |
@@ -24,232 +24,232 @@ |
||
| 24 | 24 | |
| 25 | 25 | abstract class InternalPageBase extends PageBase |
| 26 | 26 | { |
| 27 | - use NavigationMenuAccessControl; |
|
| 28 | - |
|
| 29 | - /** @var ITypeAheadHelper */ |
|
| 30 | - private $typeAheadHelper; |
|
| 31 | - private ISecurityManager $securityManager; |
|
| 32 | - /** @var IBlacklistHelper */ |
|
| 33 | - private $blacklistHelper; |
|
| 34 | - |
|
| 35 | - private IDomainAccessManager $domainAccessManager; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * @return ITypeAheadHelper |
|
| 39 | - */ |
|
| 40 | - public function getTypeAheadHelper() |
|
| 41 | - { |
|
| 42 | - return $this->typeAheadHelper; |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * @param ITypeAheadHelper $typeAheadHelper |
|
| 47 | - */ |
|
| 48 | - public function setTypeAheadHelper(ITypeAheadHelper $typeAheadHelper) |
|
| 49 | - { |
|
| 50 | - $this->typeAheadHelper = $typeAheadHelper; |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * Runs the page code |
|
| 55 | - * |
|
| 56 | - * @throws Exception |
|
| 57 | - * @category Security-Critical |
|
| 58 | - */ |
|
| 59 | - final public function execute() |
|
| 60 | - { |
|
| 61 | - if ($this->getRouteName() === null) { |
|
| 62 | - throw new Exception("Request is unrouted."); |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - if ($this->getSiteConfiguration() === null) { |
|
| 66 | - throw new Exception("Page has no configuration!"); |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - $this->setupPage(); |
|
| 70 | - |
|
| 71 | - $this->touchUserLastActive(); |
|
| 72 | - |
|
| 73 | - $currentUser = User::getCurrent($this->getDatabase()); |
|
| 74 | - |
|
| 75 | - // Hey, this is also a security barrier, in addition to the below. Separated out for readability. |
|
| 76 | - if (!$this->isProtectedPage()) { |
|
| 77 | - // This page is /not/ a protected page, as such we can just run it. |
|
| 78 | - $this->runPage(); |
|
| 79 | - |
|
| 80 | - return; |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - // Security barrier. |
|
| 84 | - // |
|
| 85 | - // This code essentially doesn't care if the user is logged in or not, as the security manager hides all that |
|
| 86 | - // away for us |
|
| 87 | - $securityResult = $this->getSecurityManager()->allows(get_called_class(), $this->getRouteName(), $currentUser); |
|
| 88 | - if ($securityResult === ISecurityManager::ALLOWED) { |
|
| 89 | - // We're allowed to run the page, so let's run it. |
|
| 90 | - $this->runPage(); |
|
| 91 | - } |
|
| 92 | - else { |
|
| 93 | - $this->handleAccessDenied($securityResult); |
|
| 94 | - |
|
| 95 | - // Send the headers |
|
| 96 | - $this->sendResponseHeaders(); |
|
| 97 | - } |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - /** |
|
| 101 | - * Performs final tasks needed before rendering the page. |
|
| 102 | - */ |
|
| 103 | - final public function finalisePage() |
|
| 104 | - { |
|
| 105 | - parent::finalisePage(); |
|
| 106 | - |
|
| 107 | - $database = $this->getDatabase(); |
|
| 108 | - $currentUser = User::getCurrent($database); |
|
| 109 | - |
|
| 110 | - // Load in the badges for the navbar |
|
| 111 | - $this->setUpNavBarBadges($currentUser, $database); |
|
| 112 | - |
|
| 113 | - if ($this->barrierTest('viewSiteNotice', User::getCurrent($database), 'GlobalInfo')) { |
|
| 114 | - $siteNotice = SiteNotice::get($this->getDatabase()); |
|
| 115 | - $siteNoticeHash = sha1($siteNotice); |
|
| 116 | - |
|
| 117 | - if (WebRequest::testSiteNoticeCookieValue($siteNoticeHash)) { |
|
| 118 | - $this->assign('siteNoticeState', 'd-none'); |
|
| 119 | - } |
|
| 120 | - else { |
|
| 121 | - $this->assign('siteNoticeState', 'd-block'); |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - $this->assign('siteNoticeText', $siteNotice); |
|
| 125 | - $this->assign('siteNoticeVersion', $siteNoticeHash); |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - if ($this->barrierTest('viewOnlineUsers', User::getCurrent($database), 'GlobalInfo')) { |
|
| 129 | - $sql = 'SELECT * FROM user WHERE lastactive > DATE_SUB(CURRENT_TIMESTAMP(), INTERVAL 5 MINUTE);'; |
|
| 130 | - $statement = $database->query($sql); |
|
| 131 | - $activeUsers = $statement->fetchAll(PDO::FETCH_CLASS, User::class); |
|
| 132 | - $this->assign('onlineusers', $activeUsers); |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - $this->setupNavMenuAccess($currentUser); |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - /** |
|
| 139 | - * Configures whether the page respects roles or not. You probably want this to return true. |
|
| 140 | - * |
|
| 141 | - * Set to false for public pages. You probably want this to return true. |
|
| 142 | - * |
|
| 143 | - * This defaults to true unless you explicitly set it to false. Setting it to false means anybody can do anything |
|
| 144 | - * on this page, so you probably want this to return true. |
|
| 145 | - * |
|
| 146 | - * @return bool |
|
| 147 | - * @category Security-Critical |
|
| 148 | - */ |
|
| 149 | - protected function isProtectedPage() |
|
| 150 | - { |
|
| 151 | - return true; |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - protected function handleAccessDenied($denyReason) |
|
| 155 | - { |
|
| 156 | - $currentUser = User::getCurrent($this->getDatabase()); |
|
| 157 | - |
|
| 158 | - // Not allowed to access this resource. |
|
| 159 | - // Firstly, let's check if we're even logged in. |
|
| 160 | - if ($currentUser->isCommunityUser()) { |
|
| 161 | - // Not logged in, redirect to login page |
|
| 162 | - WebRequest::setPostLoginRedirect(); |
|
| 163 | - $this->redirect("login"); |
|
| 164 | - |
|
| 165 | - return; |
|
| 166 | - } |
|
| 167 | - else { |
|
| 168 | - // Decide whether this was a rights failure, or an identification failure. |
|
| 169 | - |
|
| 170 | - if ($denyReason === ISecurityManager::ERROR_NOT_IDENTIFIED) { |
|
| 171 | - // Not identified |
|
| 172 | - throw new NotIdentifiedException($this->getSecurityManager(), $this->getDomainAccessManager()); |
|
| 173 | - } |
|
| 174 | - elseif ($denyReason === ISecurityManager::ERROR_DENIED) { |
|
| 175 | - // Nope, plain old access denied |
|
| 176 | - throw new AccessDeniedException($this->getSecurityManager(), $this->getDomainAccessManager()); |
|
| 177 | - } |
|
| 178 | - else { |
|
| 179 | - throw new Exception('Unknown response from security manager.'); |
|
| 180 | - } |
|
| 181 | - } |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - /** |
|
| 185 | - * Tests the security barrier for a specified action. |
|
| 186 | - * |
|
| 187 | - * Don't use within templates |
|
| 188 | - * |
|
| 189 | - * @param string $action |
|
| 190 | - * |
|
| 191 | - * @param User $user |
|
| 192 | - * @param null|string $pageName |
|
| 193 | - * |
|
| 194 | - * @return bool |
|
| 195 | - * @category Security-Critical |
|
| 196 | - */ |
|
| 197 | - final public function barrierTest($action, User $user, $pageName = null) |
|
| 198 | - { |
|
| 199 | - $page = get_called_class(); |
|
| 200 | - if ($pageName !== null) { |
|
| 201 | - $page = $pageName; |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - $securityResult = $this->getSecurityManager()->allows($page, $action, $user); |
|
| 205 | - |
|
| 206 | - return $securityResult === ISecurityManager::ALLOWED; |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - /** |
|
| 210 | - * Updates the lastactive timestamp |
|
| 211 | - */ |
|
| 212 | - private function touchUserLastActive() |
|
| 213 | - { |
|
| 214 | - if (WebRequest::getSessionUserId() !== null) { |
|
| 215 | - $query = 'UPDATE user SET lastactive = CURRENT_TIMESTAMP() WHERE id = :id;'; |
|
| 216 | - $this->getDatabase()->prepare($query)->execute(array(":id" => WebRequest::getSessionUserId())); |
|
| 217 | - } |
|
| 218 | - } |
|
| 219 | - |
|
| 220 | - public function getSecurityManager(): ISecurityManager |
|
| 221 | - { |
|
| 222 | - return $this->securityManager; |
|
| 223 | - } |
|
| 224 | - |
|
| 225 | - public function setSecurityManager(ISecurityManager $securityManager) |
|
| 226 | - { |
|
| 227 | - $this->securityManager = $securityManager; |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - /** |
|
| 231 | - * @return IBlacklistHelper |
|
| 232 | - */ |
|
| 233 | - public function getBlacklistHelper() |
|
| 234 | - { |
|
| 235 | - return $this->blacklistHelper; |
|
| 236 | - } |
|
| 237 | - |
|
| 238 | - /** |
|
| 239 | - * @param IBlacklistHelper $blacklistHelper |
|
| 240 | - */ |
|
| 241 | - public function setBlacklistHelper(IBlacklistHelper $blacklistHelper) |
|
| 242 | - { |
|
| 243 | - $this->blacklistHelper = $blacklistHelper; |
|
| 244 | - } |
|
| 245 | - |
|
| 246 | - public function getDomainAccessManager(): IDomainAccessManager |
|
| 247 | - { |
|
| 248 | - return $this->domainAccessManager; |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - public function setDomainAccessManager(IDomainAccessManager $domainAccessManager): void |
|
| 252 | - { |
|
| 253 | - $this->domainAccessManager = $domainAccessManager; |
|
| 254 | - } |
|
| 27 | + use NavigationMenuAccessControl; |
|
| 28 | + |
|
| 29 | + /** @var ITypeAheadHelper */ |
|
| 30 | + private $typeAheadHelper; |
|
| 31 | + private ISecurityManager $securityManager; |
|
| 32 | + /** @var IBlacklistHelper */ |
|
| 33 | + private $blacklistHelper; |
|
| 34 | + |
|
| 35 | + private IDomainAccessManager $domainAccessManager; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * @return ITypeAheadHelper |
|
| 39 | + */ |
|
| 40 | + public function getTypeAheadHelper() |
|
| 41 | + { |
|
| 42 | + return $this->typeAheadHelper; |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * @param ITypeAheadHelper $typeAheadHelper |
|
| 47 | + */ |
|
| 48 | + public function setTypeAheadHelper(ITypeAheadHelper $typeAheadHelper) |
|
| 49 | + { |
|
| 50 | + $this->typeAheadHelper = $typeAheadHelper; |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * Runs the page code |
|
| 55 | + * |
|
| 56 | + * @throws Exception |
|
| 57 | + * @category Security-Critical |
|
| 58 | + */ |
|
| 59 | + final public function execute() |
|
| 60 | + { |
|
| 61 | + if ($this->getRouteName() === null) { |
|
| 62 | + throw new Exception("Request is unrouted."); |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + if ($this->getSiteConfiguration() === null) { |
|
| 66 | + throw new Exception("Page has no configuration!"); |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + $this->setupPage(); |
|
| 70 | + |
|
| 71 | + $this->touchUserLastActive(); |
|
| 72 | + |
|
| 73 | + $currentUser = User::getCurrent($this->getDatabase()); |
|
| 74 | + |
|
| 75 | + // Hey, this is also a security barrier, in addition to the below. Separated out for readability. |
|
| 76 | + if (!$this->isProtectedPage()) { |
|
| 77 | + // This page is /not/ a protected page, as such we can just run it. |
|
| 78 | + $this->runPage(); |
|
| 79 | + |
|
| 80 | + return; |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + // Security barrier. |
|
| 84 | + // |
|
| 85 | + // This code essentially doesn't care if the user is logged in or not, as the security manager hides all that |
|
| 86 | + // away for us |
|
| 87 | + $securityResult = $this->getSecurityManager()->allows(get_called_class(), $this->getRouteName(), $currentUser); |
|
| 88 | + if ($securityResult === ISecurityManager::ALLOWED) { |
|
| 89 | + // We're allowed to run the page, so let's run it. |
|
| 90 | + $this->runPage(); |
|
| 91 | + } |
|
| 92 | + else { |
|
| 93 | + $this->handleAccessDenied($securityResult); |
|
| 94 | + |
|
| 95 | + // Send the headers |
|
| 96 | + $this->sendResponseHeaders(); |
|
| 97 | + } |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + /** |
|
| 101 | + * Performs final tasks needed before rendering the page. |
|
| 102 | + */ |
|
| 103 | + final public function finalisePage() |
|
| 104 | + { |
|
| 105 | + parent::finalisePage(); |
|
| 106 | + |
|
| 107 | + $database = $this->getDatabase(); |
|
| 108 | + $currentUser = User::getCurrent($database); |
|
| 109 | + |
|
| 110 | + // Load in the badges for the navbar |
|
| 111 | + $this->setUpNavBarBadges($currentUser, $database); |
|
| 112 | + |
|
| 113 | + if ($this->barrierTest('viewSiteNotice', User::getCurrent($database), 'GlobalInfo')) { |
|
| 114 | + $siteNotice = SiteNotice::get($this->getDatabase()); |
|
| 115 | + $siteNoticeHash = sha1($siteNotice); |
|
| 116 | + |
|
| 117 | + if (WebRequest::testSiteNoticeCookieValue($siteNoticeHash)) { |
|
| 118 | + $this->assign('siteNoticeState', 'd-none'); |
|
| 119 | + } |
|
| 120 | + else { |
|
| 121 | + $this->assign('siteNoticeState', 'd-block'); |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + $this->assign('siteNoticeText', $siteNotice); |
|
| 125 | + $this->assign('siteNoticeVersion', $siteNoticeHash); |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + if ($this->barrierTest('viewOnlineUsers', User::getCurrent($database), 'GlobalInfo')) { |
|
| 129 | + $sql = 'SELECT * FROM user WHERE lastactive > DATE_SUB(CURRENT_TIMESTAMP(), INTERVAL 5 MINUTE);'; |
|
| 130 | + $statement = $database->query($sql); |
|
| 131 | + $activeUsers = $statement->fetchAll(PDO::FETCH_CLASS, User::class); |
|
| 132 | + $this->assign('onlineusers', $activeUsers); |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + $this->setupNavMenuAccess($currentUser); |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + /** |
|
| 139 | + * Configures whether the page respects roles or not. You probably want this to return true. |
|
| 140 | + * |
|
| 141 | + * Set to false for public pages. You probably want this to return true. |
|
| 142 | + * |
|
| 143 | + * This defaults to true unless you explicitly set it to false. Setting it to false means anybody can do anything |
|
| 144 | + * on this page, so you probably want this to return true. |
|
| 145 | + * |
|
| 146 | + * @return bool |
|
| 147 | + * @category Security-Critical |
|
| 148 | + */ |
|
| 149 | + protected function isProtectedPage() |
|
| 150 | + { |
|
| 151 | + return true; |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + protected function handleAccessDenied($denyReason) |
|
| 155 | + { |
|
| 156 | + $currentUser = User::getCurrent($this->getDatabase()); |
|
| 157 | + |
|
| 158 | + // Not allowed to access this resource. |
|
| 159 | + // Firstly, let's check if we're even logged in. |
|
| 160 | + if ($currentUser->isCommunityUser()) { |
|
| 161 | + // Not logged in, redirect to login page |
|
| 162 | + WebRequest::setPostLoginRedirect(); |
|
| 163 | + $this->redirect("login"); |
|
| 164 | + |
|
| 165 | + return; |
|
| 166 | + } |
|
| 167 | + else { |
|
| 168 | + // Decide whether this was a rights failure, or an identification failure. |
|
| 169 | + |
|
| 170 | + if ($denyReason === ISecurityManager::ERROR_NOT_IDENTIFIED) { |
|
| 171 | + // Not identified |
|
| 172 | + throw new NotIdentifiedException($this->getSecurityManager(), $this->getDomainAccessManager()); |
|
| 173 | + } |
|
| 174 | + elseif ($denyReason === ISecurityManager::ERROR_DENIED) { |
|
| 175 | + // Nope, plain old access denied |
|
| 176 | + throw new AccessDeniedException($this->getSecurityManager(), $this->getDomainAccessManager()); |
|
| 177 | + } |
|
| 178 | + else { |
|
| 179 | + throw new Exception('Unknown response from security manager.'); |
|
| 180 | + } |
|
| 181 | + } |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + /** |
|
| 185 | + * Tests the security barrier for a specified action. |
|
| 186 | + * |
|
| 187 | + * Don't use within templates |
|
| 188 | + * |
|
| 189 | + * @param string $action |
|
| 190 | + * |
|
| 191 | + * @param User $user |
|
| 192 | + * @param null|string $pageName |
|
| 193 | + * |
|
| 194 | + * @return bool |
|
| 195 | + * @category Security-Critical |
|
| 196 | + */ |
|
| 197 | + final public function barrierTest($action, User $user, $pageName = null) |
|
| 198 | + { |
|
| 199 | + $page = get_called_class(); |
|
| 200 | + if ($pageName !== null) { |
|
| 201 | + $page = $pageName; |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + $securityResult = $this->getSecurityManager()->allows($page, $action, $user); |
|
| 205 | + |
|
| 206 | + return $securityResult === ISecurityManager::ALLOWED; |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + /** |
|
| 210 | + * Updates the lastactive timestamp |
|
| 211 | + */ |
|
| 212 | + private function touchUserLastActive() |
|
| 213 | + { |
|
| 214 | + if (WebRequest::getSessionUserId() !== null) { |
|
| 215 | + $query = 'UPDATE user SET lastactive = CURRENT_TIMESTAMP() WHERE id = :id;'; |
|
| 216 | + $this->getDatabase()->prepare($query)->execute(array(":id" => WebRequest::getSessionUserId())); |
|
| 217 | + } |
|
| 218 | + } |
|
| 219 | + |
|
| 220 | + public function getSecurityManager(): ISecurityManager |
|
| 221 | + { |
|
| 222 | + return $this->securityManager; |
|
| 223 | + } |
|
| 224 | + |
|
| 225 | + public function setSecurityManager(ISecurityManager $securityManager) |
|
| 226 | + { |
|
| 227 | + $this->securityManager = $securityManager; |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + /** |
|
| 231 | + * @return IBlacklistHelper |
|
| 232 | + */ |
|
| 233 | + public function getBlacklistHelper() |
|
| 234 | + { |
|
| 235 | + return $this->blacklistHelper; |
|
| 236 | + } |
|
| 237 | + |
|
| 238 | + /** |
|
| 239 | + * @param IBlacklistHelper $blacklistHelper |
|
| 240 | + */ |
|
| 241 | + public function setBlacklistHelper(IBlacklistHelper $blacklistHelper) |
|
| 242 | + { |
|
| 243 | + $this->blacklistHelper = $blacklistHelper; |
|
| 244 | + } |
|
| 245 | + |
|
| 246 | + public function getDomainAccessManager(): IDomainAccessManager |
|
| 247 | + { |
|
| 248 | + return $this->domainAccessManager; |
|
| 249 | + } |
|
| 250 | + |
|
| 251 | + public function setDomainAccessManager(IDomainAccessManager $domainAccessManager): void |
|
| 252 | + { |
|
| 253 | + $this->domainAccessManager = $domainAccessManager; |
|
| 254 | + } |
|
| 255 | 255 | } |
@@ -88,8 +88,7 @@ discard block |
||
| 88 | 88 | if ($securityResult === ISecurityManager::ALLOWED) { |
| 89 | 89 | // We're allowed to run the page, so let's run it. |
| 90 | 90 | $this->runPage(); |
| 91 | - } |
|
| 92 | - else { |
|
| 91 | + } else { |
|
| 93 | 92 | $this->handleAccessDenied($securityResult); |
| 94 | 93 | |
| 95 | 94 | // Send the headers |
@@ -116,8 +115,7 @@ discard block |
||
| 116 | 115 | |
| 117 | 116 | if (WebRequest::testSiteNoticeCookieValue($siteNoticeHash)) { |
| 118 | 117 | $this->assign('siteNoticeState', 'd-none'); |
| 119 | - } |
|
| 120 | - else { |
|
| 118 | + } else { |
|
| 121 | 119 | $this->assign('siteNoticeState', 'd-block'); |
| 122 | 120 | } |
| 123 | 121 | |
@@ -163,19 +161,16 @@ discard block |
||
| 163 | 161 | $this->redirect("login"); |
| 164 | 162 | |
| 165 | 163 | return; |
| 166 | - } |
|
| 167 | - else { |
|
| 164 | + } else { |
|
| 168 | 165 | // Decide whether this was a rights failure, or an identification failure. |
| 169 | 166 | |
| 170 | 167 | if ($denyReason === ISecurityManager::ERROR_NOT_IDENTIFIED) { |
| 171 | 168 | // Not identified |
| 172 | 169 | throw new NotIdentifiedException($this->getSecurityManager(), $this->getDomainAccessManager()); |
| 173 | - } |
|
| 174 | - elseif ($denyReason === ISecurityManager::ERROR_DENIED) { |
|
| 170 | + } elseif ($denyReason === ISecurityManager::ERROR_DENIED) { |
|
| 175 | 171 | // Nope, plain old access denied |
| 176 | 172 | throw new AccessDeniedException($this->getSecurityManager(), $this->getDomainAccessManager()); |
| 177 | - } |
|
| 178 | - else { |
|
| 173 | + } else { |
|
| 179 | 174 | throw new Exception('Unknown response from security manager.'); |
| 180 | 175 | } |
| 181 | 176 | } |
@@ -13,23 +13,23 @@ |
||
| 13 | 13 | |
| 14 | 14 | abstract class TextApiPageBase extends ApiPageBase implements IRoutedTask |
| 15 | 15 | { |
| 16 | - final protected function main() |
|
| 17 | - { |
|
| 18 | - if (headers_sent()) { |
|
| 19 | - throw new ApiException('Headers have already been sent - this indicates a bug in the application!'); |
|
| 20 | - } |
|
| 16 | + final protected function main() |
|
| 17 | + { |
|
| 18 | + if (headers_sent()) { |
|
| 19 | + throw new ApiException('Headers have already been sent - this indicates a bug in the application!'); |
|
| 20 | + } |
|
| 21 | 21 | |
| 22 | - try { |
|
| 23 | - $responseData = $this->runApiPage(); |
|
| 24 | - } |
|
| 25 | - catch (ApiException $ex) { |
|
| 26 | - $responseData = $ex->getMessage(); |
|
| 27 | - } |
|
| 22 | + try { |
|
| 23 | + $responseData = $this->runApiPage(); |
|
| 24 | + } |
|
| 25 | + catch (ApiException $ex) { |
|
| 26 | + $responseData = $ex->getMessage(); |
|
| 27 | + } |
|
| 28 | 28 | |
| 29 | - header('Content-Type: text/plain'); |
|
| 29 | + header('Content-Type: text/plain'); |
|
| 30 | 30 | |
| 31 | - ob_end_clean(); |
|
| 32 | - print($responseData); |
|
| 33 | - ob_start(); |
|
| 34 | - } |
|
| 31 | + ob_end_clean(); |
|
| 32 | + print($responseData); |
|
| 33 | + ob_start(); |
|
| 34 | + } |
|
| 35 | 35 | } |
@@ -18,14 +18,14 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | interface IIdentificationVerifier |
| 20 | 20 | { |
| 21 | - /** |
|
| 22 | - * Checks if the given user is identified to the Wikimedia Foundation. |
|
| 23 | - * |
|
| 24 | - * @param string $onWikiName The Wikipedia username of the user |
|
| 25 | - * |
|
| 26 | - * @return bool |
|
| 27 | - * @throws EnvironmentException |
|
| 28 | - * @category Security-Critical |
|
| 29 | - */ |
|
| 30 | - public function isUserIdentified(string $onWikiName): bool; |
|
| 21 | + /** |
|
| 22 | + * Checks if the given user is identified to the Wikimedia Foundation. |
|
| 23 | + * |
|
| 24 | + * @param string $onWikiName The Wikipedia username of the user |
|
| 25 | + * |
|
| 26 | + * @return bool |
|
| 27 | + * @throws EnvironmentException |
|
| 28 | + * @category Security-Critical |
|
| 29 | + */ |
|
| 30 | + public function isUserIdentified(string $onWikiName): bool; |
|
| 31 | 31 | } |
| 32 | 32 | \ No newline at end of file |
@@ -22,47 +22,47 @@ discard block |
||
| 22 | 22 | */ |
| 23 | 23 | class CountAction extends XmlApiPageBase implements IXmlApiAction |
| 24 | 24 | { |
| 25 | - /** |
|
| 26 | - * The target user |
|
| 27 | - * @var User $user |
|
| 28 | - */ |
|
| 29 | - private $user; |
|
| 25 | + /** |
|
| 26 | + * The target user |
|
| 27 | + * @var User $user |
|
| 28 | + */ |
|
| 29 | + private $user; |
|
| 30 | 30 | |
| 31 | - public function executeApiAction(DOMElement $apiDocument) |
|
| 32 | - { |
|
| 33 | - $username = WebRequest::getString('user'); |
|
| 34 | - if ($username === null) { |
|
| 35 | - throw new ApiException("Please specify a username"); |
|
| 36 | - } |
|
| 31 | + public function executeApiAction(DOMElement $apiDocument) |
|
| 32 | + { |
|
| 33 | + $username = WebRequest::getString('user'); |
|
| 34 | + if ($username === null) { |
|
| 35 | + throw new ApiException("Please specify a username"); |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | - $userElement = $this->document->createElement("user"); |
|
| 39 | - $userElement->setAttribute("name", $username); |
|
| 40 | - $apiDocument->appendChild($userElement); |
|
| 38 | + $userElement = $this->document->createElement("user"); |
|
| 39 | + $userElement->setAttribute("name", $username); |
|
| 40 | + $apiDocument->appendChild($userElement); |
|
| 41 | 41 | |
| 42 | - $user = User::getByUsername($username, $this->getDatabase()); |
|
| 42 | + $user = User::getByUsername($username, $this->getDatabase()); |
|
| 43 | 43 | |
| 44 | - if ($user === false) { |
|
| 45 | - $userElement->setAttribute("missing", "true"); |
|
| 44 | + if ($user === false) { |
|
| 45 | + $userElement->setAttribute("missing", "true"); |
|
| 46 | 46 | |
| 47 | - return $apiDocument; |
|
| 48 | - } |
|
| 47 | + return $apiDocument; |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - $this->user = $user; |
|
| 50 | + $this->user = $user; |
|
| 51 | 51 | |
| 52 | - $userElement->setAttribute("level", $this->user->getStatus()); |
|
| 53 | - $userElement->setAttribute("created", $this->getAccountsCreated()); |
|
| 52 | + $userElement->setAttribute("level", $this->user->getStatus()); |
|
| 53 | + $userElement->setAttribute("created", $this->getAccountsCreated()); |
|
| 54 | 54 | |
| 55 | - $userElement->setAttribute("today", $this->getToday()); |
|
| 55 | + $userElement->setAttribute("today", $this->getToday()); |
|
| 56 | 56 | |
| 57 | - // Let the IRC bot handle the result of this. |
|
| 58 | - $this->fetchAdminData($userElement); |
|
| 57 | + // Let the IRC bot handle the result of this. |
|
| 58 | + $this->fetchAdminData($userElement); |
|
| 59 | 59 | |
| 60 | - return $apiDocument; |
|
| 61 | - } |
|
| 60 | + return $apiDocument; |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - private function getAccountsCreated() |
|
| 64 | - { |
|
| 65 | - $query = <<<QUERY |
|
| 63 | + private function getAccountsCreated() |
|
| 64 | + { |
|
| 65 | + $query = <<<QUERY |
|
| 66 | 66 | SELECT COUNT(*) AS count |
| 67 | 67 | FROM log |
| 68 | 68 | LEFT JOIN emailtemplate ON concat('Closed ', emailtemplate.id) = log.action |
@@ -73,17 +73,17 @@ discard block |
||
| 73 | 73 | AND user.username = :username; |
| 74 | 74 | QUERY; |
| 75 | 75 | |
| 76 | - $statement = $this->getDatabase()->prepare($query); |
|
| 77 | - $statement->execute(array(":username" => $this->user->getUsername(), ":created" => EmailTemplate::ACTION_CREATED)); |
|
| 78 | - $result = $statement->fetchColumn(); |
|
| 79 | - $statement->closeCursor(); |
|
| 76 | + $statement = $this->getDatabase()->prepare($query); |
|
| 77 | + $statement->execute(array(":username" => $this->user->getUsername(), ":created" => EmailTemplate::ACTION_CREATED)); |
|
| 78 | + $result = $statement->fetchColumn(); |
|
| 79 | + $statement->closeCursor(); |
|
| 80 | 80 | |
| 81 | - return $result; |
|
| 82 | - } |
|
| 81 | + return $result; |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | - private function getToday() |
|
| 85 | - { |
|
| 86 | - $query = <<<QUERY |
|
| 84 | + private function getToday() |
|
| 85 | + { |
|
| 86 | + $query = <<<QUERY |
|
| 87 | 87 | SELECT |
| 88 | 88 | COUNT(*) AS count |
| 89 | 89 | FROM log |
@@ -95,75 +95,75 @@ discard block |
||
| 95 | 95 | AND user.username = :username; |
| 96 | 96 | QUERY; |
| 97 | 97 | |
| 98 | - $statement = $this->getDatabase()->prepare($query); |
|
| 99 | - $statement->bindValue(":username", $this->user->getUsername()); |
|
| 100 | - $statement->bindValue(":date", date('Y-m-d') . "%"); |
|
| 101 | - $statement->bindValue(":created", EmailTemplate::ACTION_CREATED); |
|
| 102 | - $statement->execute(); |
|
| 103 | - $today = $statement->fetchColumn(); |
|
| 104 | - $statement->closeCursor(); |
|
| 98 | + $statement = $this->getDatabase()->prepare($query); |
|
| 99 | + $statement->bindValue(":username", $this->user->getUsername()); |
|
| 100 | + $statement->bindValue(":date", date('Y-m-d') . "%"); |
|
| 101 | + $statement->bindValue(":created", EmailTemplate::ACTION_CREATED); |
|
| 102 | + $statement->execute(); |
|
| 103 | + $today = $statement->fetchColumn(); |
|
| 104 | + $statement->closeCursor(); |
|
| 105 | 105 | |
| 106 | - return $today; |
|
| 107 | - } |
|
| 106 | + return $today; |
|
| 107 | + } |
|
| 108 | 108 | |
| 109 | - private function fetchAdminData(DOMElement $userElement) |
|
| 110 | - { |
|
| 111 | - $query = "SELECT COUNT(*) AS count FROM log WHERE log.user = :userid AND log.action = :action;"; |
|
| 109 | + private function fetchAdminData(DOMElement $userElement) |
|
| 110 | + { |
|
| 111 | + $query = "SELECT COUNT(*) AS count FROM log WHERE log.user = :userid AND log.action = :action;"; |
|
| 112 | 112 | |
| 113 | - $statement = $this->getDatabase()->prepare($query); |
|
| 114 | - $statement->bindValue(":userid", $this->user->getId()); |
|
| 113 | + $statement = $this->getDatabase()->prepare($query); |
|
| 114 | + $statement->bindValue(":userid", $this->user->getId()); |
|
| 115 | 115 | |
| 116 | - // Each entry is in the form [ database string, attribute name ] |
|
| 117 | - // and it happens to be that the attribute is just the lower case form of the database value |
|
| 118 | - $actions = [ |
|
| 119 | - ['Promoted', 'promoted'], |
|
| 120 | - ['Approved', 'approved'], |
|
| 121 | - ['Demoted', 'demoted'], |
|
| 122 | - ['Renamed', 'renamed'], |
|
| 123 | - ['Edited', 'edited'], |
|
| 124 | - ['Prefchange', 'prefchange'], |
|
| 125 | - ['DeactivatedUser', 'deactivateduser'], |
|
| 126 | - ]; |
|
| 127 | - foreach ($actions as $action) { |
|
| 128 | - $dbValue = $action[0]; |
|
| 129 | - $attributeName = $action[1]; |
|
| 116 | + // Each entry is in the form [ database string, attribute name ] |
|
| 117 | + // and it happens to be that the attribute is just the lower case form of the database value |
|
| 118 | + $actions = [ |
|
| 119 | + ['Promoted', 'promoted'], |
|
| 120 | + ['Approved', 'approved'], |
|
| 121 | + ['Demoted', 'demoted'], |
|
| 122 | + ['Renamed', 'renamed'], |
|
| 123 | + ['Edited', 'edited'], |
|
| 124 | + ['Prefchange', 'prefchange'], |
|
| 125 | + ['DeactivatedUser', 'deactivateduser'], |
|
| 126 | + ]; |
|
| 127 | + foreach ($actions as $action) { |
|
| 128 | + $dbValue = $action[0]; |
|
| 129 | + $attributeName = $action[1]; |
|
| 130 | 130 | |
| 131 | - $statement->bindValue(":action", $dbValue); |
|
| 132 | - $statement->execute(); |
|
| 133 | - $attributeValue = $statement->fetchColumn(); |
|
| 134 | - $userElement->setAttribute($attributeName, $attributeValue); |
|
| 135 | - $statement->closeCursor(); |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - // Combine all three actions affecting Welcome templates into one count. |
|
| 139 | - $combinedquery = $this->getDatabase()->prepare(<<<SQL |
|
| 131 | + $statement->bindValue(":action", $dbValue); |
|
| 132 | + $statement->execute(); |
|
| 133 | + $attributeValue = $statement->fetchColumn(); |
|
| 134 | + $userElement->setAttribute($attributeName, $attributeValue); |
|
| 135 | + $statement->closeCursor(); |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + // Combine all three actions affecting Welcome templates into one count. |
|
| 139 | + $combinedquery = $this->getDatabase()->prepare(<<<SQL |
|
| 140 | 140 | SELECT |
| 141 | 141 | COUNT(*) AS count |
| 142 | 142 | FROM log |
| 143 | 143 | WHERE log.user = :userid |
| 144 | 144 | AND log.action IN ('CreatedTemplate', 'EditedTemplate', 'DeletedTemplate'); |
| 145 | 145 | SQL |
| 146 | - ); |
|
| 146 | + ); |
|
| 147 | 147 | |
| 148 | - $combinedquery->bindValue(":userid", $this->user->getId()); |
|
| 149 | - $combinedquery->execute(); |
|
| 150 | - $dtc = $combinedquery->fetchColumn(); |
|
| 151 | - $userElement->setAttribute("welctempchange", $dtc); |
|
| 152 | - $combinedquery->closeCursor(); |
|
| 148 | + $combinedquery->bindValue(":userid", $this->user->getId()); |
|
| 149 | + $combinedquery->execute(); |
|
| 150 | + $dtc = $combinedquery->fetchColumn(); |
|
| 151 | + $userElement->setAttribute("welctempchange", $dtc); |
|
| 152 | + $combinedquery->closeCursor(); |
|
| 153 | 153 | |
| 154 | - // Combine both actions affecting Email templates into one count. |
|
| 155 | - $combinedquery = $this->getDatabase()->prepare(<<<SQL |
|
| 154 | + // Combine both actions affecting Email templates into one count. |
|
| 155 | + $combinedquery = $this->getDatabase()->prepare(<<<SQL |
|
| 156 | 156 | SELECT COUNT(*) AS count |
| 157 | 157 | FROM log |
| 158 | 158 | WHERE log.user = :userid |
| 159 | 159 | AND log.action IN ('CreatedEmail', 'EditedEmail'); |
| 160 | 160 | SQL |
| 161 | - ); |
|
| 162 | - |
|
| 163 | - $combinedquery->bindValue(":userid", $this->user->getId()); |
|
| 164 | - $combinedquery->execute(); |
|
| 165 | - $cec = $combinedquery->fetchColumn(); |
|
| 166 | - $userElement->setAttribute("emailtempchange", $cec); |
|
| 167 | - $combinedquery->closeCursor(); |
|
| 168 | - } |
|
| 161 | + ); |
|
| 162 | + |
|
| 163 | + $combinedquery->bindValue(":userid", $this->user->getId()); |
|
| 164 | + $combinedquery->execute(); |
|
| 165 | + $cec = $combinedquery->fetchColumn(); |
|
| 166 | + $userElement->setAttribute("emailtempchange", $cec); |
|
| 167 | + $combinedquery->closeCursor(); |
|
| 168 | + } |
|
| 169 | 169 | } |
@@ -18,57 +18,57 @@ discard block |
||
| 18 | 18 | */ |
| 19 | 19 | class MetricsAction extends TextApiPageBase implements IApiAction |
| 20 | 20 | { |
| 21 | - private array $metrics = []; |
|
| 21 | + private array $metrics = []; |
|
| 22 | 22 | |
| 23 | - private function defineMetric(string $name, string $help, string $type = 'gauge'): void |
|
| 24 | - { |
|
| 25 | - $this->metrics[$name] = ['help' => $help, 'type' => $type, 'values' => []]; |
|
| 26 | - } |
|
| 23 | + private function defineMetric(string $name, string $help, string $type = 'gauge'): void |
|
| 24 | + { |
|
| 25 | + $this->metrics[$name] = ['help' => $help, 'type' => $type, 'values' => []]; |
|
| 26 | + } |
|
| 27 | 27 | |
| 28 | - private function setMetric(string $name, array $labels = [], int $value = 0): void |
|
| 29 | - { |
|
| 30 | - $calculatedLabel = ''; |
|
| 28 | + private function setMetric(string $name, array $labels = [], int $value = 0): void |
|
| 29 | + { |
|
| 30 | + $calculatedLabel = ''; |
|
| 31 | 31 | |
| 32 | - if (count($labels) > 0) { |
|
| 33 | - ksort($labels); |
|
| 32 | + if (count($labels) > 0) { |
|
| 33 | + ksort($labels); |
|
| 34 | 34 | |
| 35 | - $labelData = []; |
|
| 36 | - foreach ($labels as $label => $labelValue) { |
|
| 37 | - $labelData[] = $label . '="' . $labelValue . '"'; |
|
| 38 | - } |
|
| 35 | + $labelData = []; |
|
| 36 | + foreach ($labels as $label => $labelValue) { |
|
| 37 | + $labelData[] = $label . '="' . $labelValue . '"'; |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - $calculatedLabel = '{' . implode(',', $labelData) . '}'; |
|
| 41 | - } |
|
| 40 | + $calculatedLabel = '{' . implode(',', $labelData) . '}'; |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - $this->metrics[$name]['values'][$calculatedLabel] = $value; |
|
| 44 | - } |
|
| 43 | + $this->metrics[$name]['values'][$calculatedLabel] = $value; |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - public function runApiPage(): string |
|
| 47 | - { |
|
| 48 | - $this->defineMetric('acc_users', 'Number of users'); |
|
| 49 | - $statement = $this->getDatabase()->query('SELECT status, COUNT(*) AS count FROM user GROUP BY status;'); |
|
| 46 | + public function runApiPage(): string |
|
| 47 | + { |
|
| 48 | + $this->defineMetric('acc_users', 'Number of users'); |
|
| 49 | + $statement = $this->getDatabase()->query('SELECT status, COUNT(*) AS count FROM user GROUP BY status;'); |
|
| 50 | 50 | |
| 51 | - foreach ($statement->fetchAll(PDO::FETCH_ASSOC) as $row) { |
|
| 52 | - $this->setMetric('acc_users', ['status' => $row['status']], $row['count']); |
|
| 53 | - } |
|
| 54 | - $statement->closeCursor(); |
|
| 51 | + foreach ($statement->fetchAll(PDO::FETCH_ASSOC) as $row) { |
|
| 52 | + $this->setMetric('acc_users', ['status' => $row['status']], $row['count']); |
|
| 53 | + } |
|
| 54 | + $statement->closeCursor(); |
|
| 55 | 55 | |
| 56 | - $this->defineMetric('acc_active_domain_users', 'Number of active users in each domain'); |
|
| 57 | - $statement = $this->getDatabase()->query(' |
|
| 56 | + $this->defineMetric('acc_active_domain_users', 'Number of active users in each domain'); |
|
| 57 | + $statement = $this->getDatabase()->query(' |
|
| 58 | 58 | SELECT d.shortname, COUNT(1) AS count FROM userdomain ud |
| 59 | 59 | INNER JOIN user u ON ud.user = u.id |
| 60 | 60 | INNER JOIN domain d on ud.domain = d.id |
| 61 | 61 | WHERE u.status = \'Active\' |
| 62 | 62 | GROUP BY d.shortname;'); |
| 63 | 63 | |
| 64 | - foreach ($statement->fetchAll(PDO::FETCH_ASSOC) as $row) { |
|
| 65 | - $this->setMetric('acc_active_domain_users', ['domain' => $row['shortname']], $row['count']); |
|
| 66 | - } |
|
| 67 | - $statement->closeCursor(); |
|
| 64 | + foreach ($statement->fetchAll(PDO::FETCH_ASSOC) as $row) { |
|
| 65 | + $this->setMetric('acc_active_domain_users', ['domain' => $row['shortname']], $row['count']); |
|
| 66 | + } |
|
| 67 | + $statement->closeCursor(); |
|
| 68 | 68 | |
| 69 | 69 | |
| 70 | - $this->defineMetric('acc_active_domain_roles', 'Number of active users in each role'); |
|
| 71 | - $statement = $this->getDatabase()->query(' |
|
| 70 | + $this->defineMetric('acc_active_domain_roles', 'Number of active users in each role'); |
|
| 71 | + $statement = $this->getDatabase()->query(' |
|
| 72 | 72 | SELECT coalesce(d.shortname, \'\') AS domain, ur.role, COUNT(1) AS count |
| 73 | 73 | FROM userrole ur |
| 74 | 74 | INNER JOIN user u ON ur.user = u.id |
@@ -76,53 +76,53 @@ discard block |
||
| 76 | 76 | WHERE u.status = \'Active\' AND ur.role <> \'user\' |
| 77 | 77 | GROUP BY d.shortname, ur.role;'); |
| 78 | 78 | |
| 79 | - foreach ($statement->fetchAll(PDO::FETCH_ASSOC) as $row) { |
|
| 80 | - $this->setMetric('acc_active_domain_roles', ['domain' => $row['domain'], 'role' => $row['role']], $row['count']); |
|
| 81 | - } |
|
| 82 | - $statement->closeCursor(); |
|
| 79 | + foreach ($statement->fetchAll(PDO::FETCH_ASSOC) as $row) { |
|
| 80 | + $this->setMetric('acc_active_domain_roles', ['domain' => $row['domain'], 'role' => $row['role']], $row['count']); |
|
| 81 | + } |
|
| 82 | + $statement->closeCursor(); |
|
| 83 | 83 | |
| 84 | 84 | |
| 85 | - $this->defineMetric('acc_active_domain_bans', 'Number of active bans in each domain'); |
|
| 86 | - $statement = $this->getDatabase()->query(' |
|
| 85 | + $this->defineMetric('acc_active_domain_bans', 'Number of active bans in each domain'); |
|
| 86 | + $statement = $this->getDatabase()->query(' |
|
| 87 | 87 | SELECT coalesce(d.shortname, \'\') AS domain, COUNT(1) AS count |
| 88 | 88 | FROM ban b LEFT JOIN domain d ON b.domain = d.id |
| 89 | 89 | WHERE (b.duration > UNIX_TIMESTAMP() OR b.duration is null) AND b.active = 1 |
| 90 | 90 | GROUP BY d.shortname;'); |
| 91 | 91 | |
| 92 | - foreach ($statement->fetchAll(PDO::FETCH_ASSOC) as $row) { |
|
| 93 | - $this->setMetric('acc_active_domain_bans', ['domain' => $row['domain'], 'role' => $row['role']], $row['count']); |
|
| 94 | - } |
|
| 95 | - $statement->closeCursor(); |
|
| 92 | + foreach ($statement->fetchAll(PDO::FETCH_ASSOC) as $row) { |
|
| 93 | + $this->setMetric('acc_active_domain_bans', ['domain' => $row['domain'], 'role' => $row['role']], $row['count']); |
|
| 94 | + } |
|
| 95 | + $statement->closeCursor(); |
|
| 96 | 96 | |
| 97 | 97 | |
| 98 | - $this->defineMetric('acc_queued_requests', 'Number of requests in each queue'); |
|
| 99 | - $statement = $this->getDatabase()->query(' |
|
| 98 | + $this->defineMetric('acc_queued_requests', 'Number of requests in each queue'); |
|
| 99 | + $statement = $this->getDatabase()->query(' |
|
| 100 | 100 | SELECT r.status, d.shortname, rq.header, COUNT(1) as count FROM request r |
| 101 | 101 | INNER JOIN domain d on r.domain = d.id |
| 102 | 102 | LEFT JOIN waca.requestqueue rq ON r.queue = rq.id |
| 103 | 103 | WHERE r.status <> \'Closed\' AND r.emailconfirm = \'Confirmed\' |
| 104 | 104 | GROUP BY r.status, d.shortname, rq.header;'); |
| 105 | 105 | |
| 106 | - foreach ($statement->fetchAll(PDO::FETCH_ASSOC) as $row) { |
|
| 107 | - $this->setMetric('acc_queued_requests', ['status' => $row['status'], 'shortname' => $row['shortname'], 'queue' => $row['header']], $row['count']); |
|
| 108 | - } |
|
| 109 | - $statement->closeCursor(); |
|
| 106 | + foreach ($statement->fetchAll(PDO::FETCH_ASSOC) as $row) { |
|
| 107 | + $this->setMetric('acc_queued_requests', ['status' => $row['status'], 'shortname' => $row['shortname'], 'queue' => $row['header']], $row['count']); |
|
| 108 | + } |
|
| 109 | + $statement->closeCursor(); |
|
| 110 | 110 | |
| 111 | - return $this->writeMetrics(); |
|
| 112 | - } |
|
| 111 | + return $this->writeMetrics(); |
|
| 112 | + } |
|
| 113 | 113 | |
| 114 | - private function writeMetrics() : string |
|
| 115 | - { |
|
| 116 | - $data = ''; |
|
| 114 | + private function writeMetrics() : string |
|
| 115 | + { |
|
| 116 | + $data = ''; |
|
| 117 | 117 | |
| 118 | - foreach ($this->metrics as $name => $metricData) { |
|
| 119 | - $data .= "# HELP {$name} {$metricData['help']}\n"; |
|
| 120 | - $data .= "# TYPE {$name} {$metricData['type']}\n"; |
|
| 121 | - foreach ($metricData['values'] as $label => $value) { |
|
| 122 | - $data .= "{$name}{$label} {$value}\n"; |
|
| 123 | - } |
|
| 124 | - } |
|
| 118 | + foreach ($this->metrics as $name => $metricData) { |
|
| 119 | + $data .= "# HELP {$name} {$metricData['help']}\n"; |
|
| 120 | + $data .= "# TYPE {$name} {$metricData['type']}\n"; |
|
| 121 | + foreach ($metricData['values'] as $label => $value) { |
|
| 122 | + $data .= "{$name}{$label} {$value}\n"; |
|
| 123 | + } |
|
| 124 | + } |
|
| 125 | 125 | |
| 126 | - return $data; |
|
| 127 | - } |
|
| 126 | + return $data; |
|
| 127 | + } |
|
| 128 | 128 | } |
@@ -16,169 +16,169 @@ |
||
| 16 | 16 | |
| 17 | 17 | final class SecurityManager implements ISecurityManager |
| 18 | 18 | { |
| 19 | - private IIdentificationVerifier $identificationVerifier; |
|
| 20 | - private RoleConfigurationBase $roleConfiguration; |
|
| 21 | - |
|
| 22 | - private array $cache = []; |
|
| 23 | - private IUserAccessLoader $userAccessLoader; |
|
| 24 | - |
|
| 25 | - public function __construct( |
|
| 26 | - IIdentificationVerifier $identificationVerifier, |
|
| 27 | - RoleConfigurationBase $roleConfiguration, |
|
| 28 | - IUserAccessLoader $userAccessLoader |
|
| 29 | - ) { |
|
| 30 | - $this->identificationVerifier = $identificationVerifier; |
|
| 31 | - $this->roleConfiguration = $roleConfiguration; |
|
| 32 | - $this->userAccessLoader = $userAccessLoader; |
|
| 33 | - } |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * Tests if a user is allowed to perform an action. |
|
| 37 | - * |
|
| 38 | - * This method should form a hard, deterministic security barrier, and only return true if it is absolutely sure |
|
| 39 | - * that a user should have access to something. |
|
| 40 | - * |
|
| 41 | - * @category Security-Critical |
|
| 42 | - */ |
|
| 43 | - public function allows(string $page, string $route, User $user): int |
|
| 44 | - { |
|
| 45 | - $this->getCachedActiveRoles($user, $activeRoles, $inactiveRoles); |
|
| 46 | - |
|
| 47 | - $availableRights = $this->roleConfiguration->getResultantRole($activeRoles); |
|
| 48 | - $testResult = $this->findResult($availableRights, $page, $route); |
|
| 49 | - |
|
| 50 | - if ($testResult !== null) { |
|
| 51 | - // We got a firm result here, so just return it. |
|
| 52 | - return $testResult; |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - // No firm result yet, so continue testing the inactive roles so we can give a better error. |
|
| 56 | - $inactiveRights = $this->roleConfiguration->getResultantRole($inactiveRoles); |
|
| 57 | - $testResult = $this->findResult($inactiveRights, $page, $route); |
|
| 58 | - |
|
| 59 | - if ($testResult === self::ALLOWED) { |
|
| 60 | - // The user is allowed to access this, but their role is inactive. |
|
| 61 | - return self::ERROR_NOT_IDENTIFIED; |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - // Other options from the secondary test are denied and inconclusive, which at this point defaults to denied. |
|
| 65 | - return self::ERROR_DENIED; |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - public function getActiveRoles(User $user, ?array &$activeRoles, ?array &$inactiveRoles) |
|
| 69 | - { |
|
| 70 | - // Default to the community user here, because the main user is logged out |
|
| 71 | - $identified = false; |
|
| 72 | - $userRoles = array('public'); |
|
| 73 | - |
|
| 74 | - // if we're not the community user, get our real rights. |
|
| 75 | - if (!$user->isCommunityUser()) { |
|
| 76 | - // Check the user's status - only active users are allowed the effects of roles |
|
| 77 | - |
|
| 78 | - $userRoles[] = 'loggedIn'; |
|
| 79 | - |
|
| 80 | - if ($user->isActive()) { |
|
| 81 | - // All active users get +user |
|
| 82 | - $userRoles[] = 'user'; |
|
| 83 | - |
|
| 84 | - $loadedRoles = $this->userAccessLoader->loadRolesForUser($user); |
|
| 85 | - |
|
| 86 | - // NOTE: public is still in this array. |
|
| 87 | - $userRoles = array_merge($userRoles, $loadedRoles); |
|
| 88 | - |
|
| 89 | - $identified = $this->userIsIdentified($user); |
|
| 90 | - } |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - $activeRoles = array(); |
|
| 94 | - $inactiveRoles = array(); |
|
| 95 | - |
|
| 96 | - foreach ($userRoles as $v) { |
|
| 97 | - if ($this->roleConfiguration->roleNeedsIdentification($v)) { |
|
| 98 | - if ($identified) { |
|
| 99 | - $activeRoles[] = $v; |
|
| 100 | - } |
|
| 101 | - else { |
|
| 102 | - $inactiveRoles[] = $v; |
|
| 103 | - } |
|
| 104 | - } |
|
| 105 | - else { |
|
| 106 | - $activeRoles[] = $v; |
|
| 107 | - } |
|
| 108 | - } |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - public function getCachedActiveRoles(User $user, ?array &$activeRoles, ?array &$inactiveRoles): void |
|
| 112 | - { |
|
| 113 | - if (!array_key_exists($user->getId(), $this->cache)) { |
|
| 114 | - $this->getActiveRoles($user, $retrievedActiveRoles, $retrievedInactiveRoles); |
|
| 115 | - $this->cache[$user->getId()] = ['active' => $retrievedActiveRoles, 'inactive' => $retrievedInactiveRoles]; |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - $activeRoles = $this->cache[$user->getId()]['active']; |
|
| 119 | - $inactiveRoles = $this->cache[$user->getId()]['inactive']; |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - public function getAvailableRoles(): array |
|
| 123 | - { |
|
| 124 | - return $this->roleConfiguration->getAvailableRoles(); |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * Tests a role for an ACL decision on a specific page/route |
|
| 129 | - * |
|
| 130 | - * @param array $pseudoRole The role (flattened) to check |
|
| 131 | - * @param string $page The page class to check |
|
| 132 | - * @param string $route The page route to check |
|
| 133 | - * |
|
| 134 | - * @return int|null |
|
| 135 | - */ |
|
| 136 | - private function findResult($pseudoRole, $page, $route) |
|
| 137 | - { |
|
| 138 | - if (isset($pseudoRole[$page])) { |
|
| 139 | - // check for deny on catch-all route |
|
| 140 | - if (isset($pseudoRole[$page][RoleConfigurationBase::ALL])) { |
|
| 141 | - if ($pseudoRole[$page][RoleConfigurationBase::ALL] === RoleConfigurationBase::ACCESS_DENY) { |
|
| 142 | - return self::ERROR_DENIED; |
|
| 143 | - } |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - // check normal route |
|
| 147 | - if (isset($pseudoRole[$page][$route])) { |
|
| 148 | - if ($pseudoRole[$page][$route] === RoleConfigurationBase::ACCESS_DENY) { |
|
| 149 | - return self::ERROR_DENIED; |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - if ($pseudoRole[$page][$route] === RoleConfigurationBase::ACCESS_ALLOW) { |
|
| 153 | - return self::ALLOWED; |
|
| 154 | - } |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - // check for allowed on catch-all route |
|
| 158 | - if (isset($pseudoRole[$page][RoleConfigurationBase::ALL])) { |
|
| 159 | - if ($pseudoRole[$page][RoleConfigurationBase::ALL] === RoleConfigurationBase::ACCESS_ALLOW) { |
|
| 160 | - return self::ALLOWED; |
|
| 161 | - } |
|
| 162 | - } |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - // return indeterminate result |
|
| 166 | - return null; |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - private function userIsIdentified(User $user): bool |
|
| 170 | - { |
|
| 171 | - if ($user->getForceIdentified() === false) { |
|
| 172 | - // User forced to be unidentified in the database. |
|
| 173 | - return false; |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - if ($user->getForceIdentified() === true) { |
|
| 177 | - // User forced to be identified in the database. |
|
| 178 | - return true; |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - // User not forced to any particular identified status; consult IdentificationVerifier |
|
| 182 | - return $this->identificationVerifier->isUserIdentified($user->getOnWikiName()); |
|
| 183 | - } |
|
| 19 | + private IIdentificationVerifier $identificationVerifier; |
|
| 20 | + private RoleConfigurationBase $roleConfiguration; |
|
| 21 | + |
|
| 22 | + private array $cache = []; |
|
| 23 | + private IUserAccessLoader $userAccessLoader; |
|
| 24 | + |
|
| 25 | + public function __construct( |
|
| 26 | + IIdentificationVerifier $identificationVerifier, |
|
| 27 | + RoleConfigurationBase $roleConfiguration, |
|
| 28 | + IUserAccessLoader $userAccessLoader |
|
| 29 | + ) { |
|
| 30 | + $this->identificationVerifier = $identificationVerifier; |
|
| 31 | + $this->roleConfiguration = $roleConfiguration; |
|
| 32 | + $this->userAccessLoader = $userAccessLoader; |
|
| 33 | + } |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * Tests if a user is allowed to perform an action. |
|
| 37 | + * |
|
| 38 | + * This method should form a hard, deterministic security barrier, and only return true if it is absolutely sure |
|
| 39 | + * that a user should have access to something. |
|
| 40 | + * |
|
| 41 | + * @category Security-Critical |
|
| 42 | + */ |
|
| 43 | + public function allows(string $page, string $route, User $user): int |
|
| 44 | + { |
|
| 45 | + $this->getCachedActiveRoles($user, $activeRoles, $inactiveRoles); |
|
| 46 | + |
|
| 47 | + $availableRights = $this->roleConfiguration->getResultantRole($activeRoles); |
|
| 48 | + $testResult = $this->findResult($availableRights, $page, $route); |
|
| 49 | + |
|
| 50 | + if ($testResult !== null) { |
|
| 51 | + // We got a firm result here, so just return it. |
|
| 52 | + return $testResult; |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + // No firm result yet, so continue testing the inactive roles so we can give a better error. |
|
| 56 | + $inactiveRights = $this->roleConfiguration->getResultantRole($inactiveRoles); |
|
| 57 | + $testResult = $this->findResult($inactiveRights, $page, $route); |
|
| 58 | + |
|
| 59 | + if ($testResult === self::ALLOWED) { |
|
| 60 | + // The user is allowed to access this, but their role is inactive. |
|
| 61 | + return self::ERROR_NOT_IDENTIFIED; |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + // Other options from the secondary test are denied and inconclusive, which at this point defaults to denied. |
|
| 65 | + return self::ERROR_DENIED; |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + public function getActiveRoles(User $user, ?array &$activeRoles, ?array &$inactiveRoles) |
|
| 69 | + { |
|
| 70 | + // Default to the community user here, because the main user is logged out |
|
| 71 | + $identified = false; |
|
| 72 | + $userRoles = array('public'); |
|
| 73 | + |
|
| 74 | + // if we're not the community user, get our real rights. |
|
| 75 | + if (!$user->isCommunityUser()) { |
|
| 76 | + // Check the user's status - only active users are allowed the effects of roles |
|
| 77 | + |
|
| 78 | + $userRoles[] = 'loggedIn'; |
|
| 79 | + |
|
| 80 | + if ($user->isActive()) { |
|
| 81 | + // All active users get +user |
|
| 82 | + $userRoles[] = 'user'; |
|
| 83 | + |
|
| 84 | + $loadedRoles = $this->userAccessLoader->loadRolesForUser($user); |
|
| 85 | + |
|
| 86 | + // NOTE: public is still in this array. |
|
| 87 | + $userRoles = array_merge($userRoles, $loadedRoles); |
|
| 88 | + |
|
| 89 | + $identified = $this->userIsIdentified($user); |
|
| 90 | + } |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + $activeRoles = array(); |
|
| 94 | + $inactiveRoles = array(); |
|
| 95 | + |
|
| 96 | + foreach ($userRoles as $v) { |
|
| 97 | + if ($this->roleConfiguration->roleNeedsIdentification($v)) { |
|
| 98 | + if ($identified) { |
|
| 99 | + $activeRoles[] = $v; |
|
| 100 | + } |
|
| 101 | + else { |
|
| 102 | + $inactiveRoles[] = $v; |
|
| 103 | + } |
|
| 104 | + } |
|
| 105 | + else { |
|
| 106 | + $activeRoles[] = $v; |
|
| 107 | + } |
|
| 108 | + } |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + public function getCachedActiveRoles(User $user, ?array &$activeRoles, ?array &$inactiveRoles): void |
|
| 112 | + { |
|
| 113 | + if (!array_key_exists($user->getId(), $this->cache)) { |
|
| 114 | + $this->getActiveRoles($user, $retrievedActiveRoles, $retrievedInactiveRoles); |
|
| 115 | + $this->cache[$user->getId()] = ['active' => $retrievedActiveRoles, 'inactive' => $retrievedInactiveRoles]; |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + $activeRoles = $this->cache[$user->getId()]['active']; |
|
| 119 | + $inactiveRoles = $this->cache[$user->getId()]['inactive']; |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + public function getAvailableRoles(): array |
|
| 123 | + { |
|
| 124 | + return $this->roleConfiguration->getAvailableRoles(); |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * Tests a role for an ACL decision on a specific page/route |
|
| 129 | + * |
|
| 130 | + * @param array $pseudoRole The role (flattened) to check |
|
| 131 | + * @param string $page The page class to check |
|
| 132 | + * @param string $route The page route to check |
|
| 133 | + * |
|
| 134 | + * @return int|null |
|
| 135 | + */ |
|
| 136 | + private function findResult($pseudoRole, $page, $route) |
|
| 137 | + { |
|
| 138 | + if (isset($pseudoRole[$page])) { |
|
| 139 | + // check for deny on catch-all route |
|
| 140 | + if (isset($pseudoRole[$page][RoleConfigurationBase::ALL])) { |
|
| 141 | + if ($pseudoRole[$page][RoleConfigurationBase::ALL] === RoleConfigurationBase::ACCESS_DENY) { |
|
| 142 | + return self::ERROR_DENIED; |
|
| 143 | + } |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + // check normal route |
|
| 147 | + if (isset($pseudoRole[$page][$route])) { |
|
| 148 | + if ($pseudoRole[$page][$route] === RoleConfigurationBase::ACCESS_DENY) { |
|
| 149 | + return self::ERROR_DENIED; |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + if ($pseudoRole[$page][$route] === RoleConfigurationBase::ACCESS_ALLOW) { |
|
| 153 | + return self::ALLOWED; |
|
| 154 | + } |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + // check for allowed on catch-all route |
|
| 158 | + if (isset($pseudoRole[$page][RoleConfigurationBase::ALL])) { |
|
| 159 | + if ($pseudoRole[$page][RoleConfigurationBase::ALL] === RoleConfigurationBase::ACCESS_ALLOW) { |
|
| 160 | + return self::ALLOWED; |
|
| 161 | + } |
|
| 162 | + } |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + // return indeterminate result |
|
| 166 | + return null; |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + private function userIsIdentified(User $user): bool |
|
| 170 | + { |
|
| 171 | + if ($user->getForceIdentified() === false) { |
|
| 172 | + // User forced to be unidentified in the database. |
|
| 173 | + return false; |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + if ($user->getForceIdentified() === true) { |
|
| 177 | + // User forced to be identified in the database. |
|
| 178 | + return true; |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + // User not forced to any particular identified status; consult IdentificationVerifier |
|
| 182 | + return $this->identificationVerifier->isUserIdentified($user->getOnWikiName()); |
|
| 183 | + } |
|
| 184 | 184 | } |