Failed Conditions
Push — smarty5 ( 853ee4...d2daf7 )
by Simon
05:17
created
includes/Pages/RequestAction/PageCreateRequest.php 1 patch
Indentation   +152 added lines, -152 removed lines patch added patch discarded remove patch
@@ -35,156 +35,156 @@
 block discarded – undo
35 35
  */
36 36
 class PageCreateRequest extends RequestActionBase
37 37
 {
38
-    /**
39
-     * Main function for this page, when no specific actions are called.
40
-     * @return void
41
-     * @throws AccessDeniedException
42
-     * @throws ApplicationLogicException
43
-     */
44
-    protected function main()
45
-    {
46
-        $this->checkPosted();
47
-
48
-        $database = $this->getDatabase();
49
-
50
-        $request = $this->getRequest($database);
51
-        $template = $this->getTemplate($database);
52
-        $creationMode = $this->getCreationMode();
53
-        $user = User::getCurrent($database);
54
-        $preferencesManager = PreferenceManager::getForCurrent($database);
55
-
56
-        $secMgr = $this->getSecurityManager();
57
-        if ($secMgr->allows('RequestCreation', PreferenceManager::CREATION_BOT, $user) !== ISecurityManager::ALLOWED
58
-            && $creationMode === 'bot'
59
-        ) {
60
-            throw new AccessDeniedException($secMgr, $this->getDomainAccessManager());
61
-        }
62
-        elseif ($secMgr->allows('RequestCreation', PreferenceManager::CREATION_OAUTH, $user) !== ISecurityManager::ALLOWED
63
-            && $creationMode === 'oauth'
64
-        ) {
65
-            throw new AccessDeniedException($secMgr, $this->getDomainAccessManager());
66
-        }
67
-
68
-        if ($request->getEmailSent()) {
69
-            throw new ApplicationLogicException('This requester has already had an email sent to them. Please fall back to manual creation or a custom close');
70
-        }
71
-
72
-        $request->setStatus(RequestStatus::JOBQUEUE);
73
-        $request->setReserved(null);
74
-        $request->save();
75
-
76
-        Logger::enqueuedJobQueue($database, $request);
77
-
78
-        $creationTaskId = $this->enqueueCreationTask($creationMode, $request, $template, $user, $database);
79
-
80
-        $welcomeTemplate = $preferencesManager->getPreference(PreferenceManager::PREF_WELCOMETEMPLATE);
81
-        if ($welcomeTemplate !== null && !WebRequest::postBoolean('skipAutoWelcome')) {
82
-            $this->enqueueWelcomeTask($request, $creationTaskId, $user, $database);
83
-        }
84
-
85
-        $this->getNotificationHelper()->requestCloseQueued($request, $template->getName());
86
-
87
-        SessionAlert::success("Request {$request->getId()} has been queued for autocreation");
88
-
89
-        $this->redirect();
90
-    }
91
-
92
-    protected function getCreationMode()
93
-    {
94
-        $creationMode = WebRequest::postString('mode');
95
-        if ($creationMode !== 'oauth' && $creationMode !== 'bot') {
96
-            throw new ApplicationLogicException('Unknown creation mode');
97
-        }
98
-
99
-        return $creationMode;
100
-    }
101
-
102
-    /**
103
-     * @param PdoDatabase $database
104
-     *
105
-     * @return EmailTemplate
106
-     * @throws ApplicationLogicException
107
-     */
108
-    protected function getTemplate(PdoDatabase $database)
109
-    {
110
-        $templateId = WebRequest::postInt('template');
111
-        if ($templateId === null) {
112
-            throw new ApplicationLogicException('No template specified');
113
-        }
114
-
115
-        /** @var EmailTemplate $template */
116
-        $template = EmailTemplate::getById($templateId, $database);
117
-        if ($template === false || !$template->getActive()) {
118
-            throw new ApplicationLogicException('Invalid or inactive template specified');
119
-        }
120
-
121
-        if ($template->getDefaultAction() !== EmailTemplate::ACTION_CREATED) {
122
-            throw new ApplicationLogicException('Specified template is not a creation template!');
123
-        }
124
-
125
-        return $template;
126
-    }
127
-
128
-    /**
129
-     * @param PdoDatabase $database
130
-     *
131
-     * @return Request
132
-     * @throws ApplicationLogicException
133
-     */
134
-    protected function getRequest(PdoDatabase $database)
135
-    {
136
-        $request = parent::getRequest($database);
137
-
138
-        if ($request->getStatus() == RequestStatus::CLOSED) {
139
-            throw new ApplicationLogicException('Request is already closed');
140
-        }
141
-
142
-        return $request;
143
-    }
144
-
145
-    /**
146
-     * @param               $creationMode
147
-     * @param Request       $request
148
-     * @param EmailTemplate $template
149
-     * @param User          $user
150
-     *
151
-     * @param PdoDatabase   $database
152
-     *
153
-     * @return int
154
-     * @throws ApplicationLogicException
155
-     */
156
-    protected function enqueueCreationTask(
157
-        $creationMode,
158
-        Request $request,
159
-        EmailTemplate $template,
160
-        User $user,
161
-        PdoDatabase $database
162
-    ) {
163
-        $creationTaskClass = null;
164
-
165
-        if ($creationMode == "oauth") {
166
-            $creationTaskClass = UserCreationTask::class;
167
-        }
168
-
169
-        if ($creationMode == "bot") {
170
-            $creationTaskClass = BotCreationTask::class;
171
-        }
172
-
173
-        if ($creationTaskClass === null) {
174
-            throw new ApplicationLogicException('Cannot determine creation mode');
175
-        }
176
-
177
-        $creationTask = new JobQueue();
178
-        $creationTask->setDomain(1); // FIXME: domains!
179
-        $creationTask->setTask($creationTaskClass);
180
-        $creationTask->setRequest($request->getId());
181
-        $creationTask->setEmailTemplate($template->getId());
182
-        $creationTask->setTriggerUserId($user->getId());
183
-        $creationTask->setDatabase($database);
184
-        $creationTask->save();
185
-
186
-        $creationTaskId = $creationTask->getId();
187
-
188
-        return $creationTaskId;
189
-    }
38
+	/**
39
+	 * Main function for this page, when no specific actions are called.
40
+	 * @return void
41
+	 * @throws AccessDeniedException
42
+	 * @throws ApplicationLogicException
43
+	 */
44
+	protected function main()
45
+	{
46
+		$this->checkPosted();
47
+
48
+		$database = $this->getDatabase();
49
+
50
+		$request = $this->getRequest($database);
51
+		$template = $this->getTemplate($database);
52
+		$creationMode = $this->getCreationMode();
53
+		$user = User::getCurrent($database);
54
+		$preferencesManager = PreferenceManager::getForCurrent($database);
55
+
56
+		$secMgr = $this->getSecurityManager();
57
+		if ($secMgr->allows('RequestCreation', PreferenceManager::CREATION_BOT, $user) !== ISecurityManager::ALLOWED
58
+			&& $creationMode === 'bot'
59
+		) {
60
+			throw new AccessDeniedException($secMgr, $this->getDomainAccessManager());
61
+		}
62
+		elseif ($secMgr->allows('RequestCreation', PreferenceManager::CREATION_OAUTH, $user) !== ISecurityManager::ALLOWED
63
+			&& $creationMode === 'oauth'
64
+		) {
65
+			throw new AccessDeniedException($secMgr, $this->getDomainAccessManager());
66
+		}
67
+
68
+		if ($request->getEmailSent()) {
69
+			throw new ApplicationLogicException('This requester has already had an email sent to them. Please fall back to manual creation or a custom close');
70
+		}
71
+
72
+		$request->setStatus(RequestStatus::JOBQUEUE);
73
+		$request->setReserved(null);
74
+		$request->save();
75
+
76
+		Logger::enqueuedJobQueue($database, $request);
77
+
78
+		$creationTaskId = $this->enqueueCreationTask($creationMode, $request, $template, $user, $database);
79
+
80
+		$welcomeTemplate = $preferencesManager->getPreference(PreferenceManager::PREF_WELCOMETEMPLATE);
81
+		if ($welcomeTemplate !== null && !WebRequest::postBoolean('skipAutoWelcome')) {
82
+			$this->enqueueWelcomeTask($request, $creationTaskId, $user, $database);
83
+		}
84
+
85
+		$this->getNotificationHelper()->requestCloseQueued($request, $template->getName());
86
+
87
+		SessionAlert::success("Request {$request->getId()} has been queued for autocreation");
88
+
89
+		$this->redirect();
90
+	}
91
+
92
+	protected function getCreationMode()
93
+	{
94
+		$creationMode = WebRequest::postString('mode');
95
+		if ($creationMode !== 'oauth' && $creationMode !== 'bot') {
96
+			throw new ApplicationLogicException('Unknown creation mode');
97
+		}
98
+
99
+		return $creationMode;
100
+	}
101
+
102
+	/**
103
+	 * @param PdoDatabase $database
104
+	 *
105
+	 * @return EmailTemplate
106
+	 * @throws ApplicationLogicException
107
+	 */
108
+	protected function getTemplate(PdoDatabase $database)
109
+	{
110
+		$templateId = WebRequest::postInt('template');
111
+		if ($templateId === null) {
112
+			throw new ApplicationLogicException('No template specified');
113
+		}
114
+
115
+		/** @var EmailTemplate $template */
116
+		$template = EmailTemplate::getById($templateId, $database);
117
+		if ($template === false || !$template->getActive()) {
118
+			throw new ApplicationLogicException('Invalid or inactive template specified');
119
+		}
120
+
121
+		if ($template->getDefaultAction() !== EmailTemplate::ACTION_CREATED) {
122
+			throw new ApplicationLogicException('Specified template is not a creation template!');
123
+		}
124
+
125
+		return $template;
126
+	}
127
+
128
+	/**
129
+	 * @param PdoDatabase $database
130
+	 *
131
+	 * @return Request
132
+	 * @throws ApplicationLogicException
133
+	 */
134
+	protected function getRequest(PdoDatabase $database)
135
+	{
136
+		$request = parent::getRequest($database);
137
+
138
+		if ($request->getStatus() == RequestStatus::CLOSED) {
139
+			throw new ApplicationLogicException('Request is already closed');
140
+		}
141
+
142
+		return $request;
143
+	}
144
+
145
+	/**
146
+	 * @param               $creationMode
147
+	 * @param Request       $request
148
+	 * @param EmailTemplate $template
149
+	 * @param User          $user
150
+	 *
151
+	 * @param PdoDatabase   $database
152
+	 *
153
+	 * @return int
154
+	 * @throws ApplicationLogicException
155
+	 */
156
+	protected function enqueueCreationTask(
157
+		$creationMode,
158
+		Request $request,
159
+		EmailTemplate $template,
160
+		User $user,
161
+		PdoDatabase $database
162
+	) {
163
+		$creationTaskClass = null;
164
+
165
+		if ($creationMode == "oauth") {
166
+			$creationTaskClass = UserCreationTask::class;
167
+		}
168
+
169
+		if ($creationMode == "bot") {
170
+			$creationTaskClass = BotCreationTask::class;
171
+		}
172
+
173
+		if ($creationTaskClass === null) {
174
+			throw new ApplicationLogicException('Cannot determine creation mode');
175
+		}
176
+
177
+		$creationTask = new JobQueue();
178
+		$creationTask->setDomain(1); // FIXME: domains!
179
+		$creationTask->setTask($creationTaskClass);
180
+		$creationTask->setRequest($request->getId());
181
+		$creationTask->setEmailTemplate($template->getId());
182
+		$creationTask->setTriggerUserId($user->getId());
183
+		$creationTask->setDatabase($database);
184
+		$creationTask->save();
185
+
186
+		$creationTaskId = $creationTask->getId();
187
+
188
+		return $creationTaskId;
189
+	}
190 190
 }
Please login to merge, or discard this patch.
includes/Pages/PageListFlaggedComments.php 1 patch
Indentation   +108 added lines, -108 removed lines patch added patch discarded remove patch
@@ -18,112 +18,112 @@
 block discarded – undo
18 18
 
19 19
 class PageListFlaggedComments extends InternalPageBase
20 20
 {
21
-    /**
22
-     * @inheritDoc
23
-     */
24
-    protected function main()
25
-    {
26
-        $this->setHtmlTitle('Flagged comments');
27
-        $this->setTemplate('flagged-comments.tpl');
28
-
29
-        $database = $this->getDatabase();
30
-        $this->assignCSRFToken();
31
-
32
-        /** @var Comment[] $commentObjects */
33
-        $commentObjects = Comment::getFlaggedComments($database, 1); // FIXME: domains
34
-        $comments = [];
35
-
36
-        $currentUser = User::getCurrent($database);
37
-
38
-        $seeRestrictedComments = $this->barrierTest('seeRestrictedComments', $currentUser, 'RequestData');
39
-        $seeCheckuserComments = $this->barrierTest('seeCheckuserComments', $currentUser, 'RequestData');
40
-        $alwaysSeePrivateData = $this->barrierTest('alwaysSeePrivateData', $currentUser, 'RequestData');
41
-
42
-        foreach ($commentObjects as $object) {
43
-            $data = [
44
-                'visibility'    => $object->getVisibility(),
45
-                'hidden'        => false,
46
-                'hiddenText'    => false,
47
-            ];
48
-
49
-            if (!$alwaysSeePrivateData) {
50
-                // tl;dr: This is a stupid configuration, but let's account for it anyway.
51
-                //
52
-                // Flagged comments are treated as private data. If you don't have the privilege
53
-                // RequestData::alwaysSeePrivateData, then we can't show you the content of the comments here.
54
-                // This page is forced to degrade into basically a list of requests, seriously hampering the usefulness
55
-                // of this page. Still, we need to handle the case where we have access to this page, but not access
56
-                // to private data.
57
-                // At the time of writing, this case does not exist in the current role configuration, but for the role
58
-                // configuration to be free of assumptions, we need this code.
59
-
60
-                /** @var Request $request */
61
-                $request = Request::getById($object->getRequest(), $database);
62
-
63
-                if ($request->getReserved() === $currentUser->getId()) {
64
-                    $data['hiddenText'] = false;
65
-                }
66
-                else {
67
-                    $data['hiddenText'] = true;
68
-                }
69
-            }
70
-
71
-            if ($object->getVisibility() == 'requester' || $object->getVisibility() == 'user') {
72
-                $data['hidden'] = false;
73
-            }
74
-            elseif ($object->getVisibility() == 'admin') {
75
-                if ($seeRestrictedComments) {
76
-                    $data['hidden'] = false;
77
-                }
78
-                else {
79
-                    $data['hidden'] = true;
80
-                }
81
-            }
82
-            elseif ($object->getVisibility() == 'checkuser') {
83
-                if ($seeCheckuserComments) {
84
-                    $data['hidden'] = false;
85
-                }
86
-                else {
87
-                    $data['hidden'] = true;
88
-                }
89
-            }
90
-
91
-            $this->copyCommentData($object, $data, $database);
92
-
93
-            $comments[] = $data;
94
-        }
95
-
96
-        $this->assign('comments', $comments);
97
-        $this->assign('seeRestrictedComments', $seeRestrictedComments);
98
-        $this->assign('seeCheckuserComments', $seeCheckuserComments);
99
-
100
-        $this->assign('editOthersComments', $this->barrierTest('editOthers', $currentUser, PageEditComment::class));
101
-        $this->assign('editComments', $this->barrierTest(RoleConfigurationBase::MAIN, $currentUser, PageEditComment::class));
102
-        $this->assign('canUnflag', $this->barrierTest('unflag', $currentUser, PageFlagComment::class) && $this->barrierTest(RoleConfigurationBase::MAIN, $currentUser, PageFlagComment::class));
103
-    }
104
-
105
-    private function copyCommentData(Comment $object, array &$data, PdoDatabase $database): void
106
-    {
107
-        if ($data['hidden']) {
108
-            // All details hidden, so don't copy anything.
109
-            return;
110
-        }
111
-
112
-        /** @var Request $request */
113
-        $request = Request::getById($object->getRequest(), $database);
114
-
115
-        if (!$data['hiddenText']) {
116
-            // Comment text is hidden, but presence of the comment is visible.
117
-            $data['comment'] = $object->getComment();
118
-        }
119
-
120
-        $data['id'] = $object->getId();
121
-        $data['updateversion'] = $object->getUpdateVersion();
122
-        $data['time'] = $object->getTime();
123
-        $data['requestid'] = $object->getRequest();
124
-        $data['request'] = $request->getName();
125
-        $data['requeststatus'] = $request->getStatus();
126
-        $data['userid'] = $object->getUser();
127
-        $data['user'] = User::getById($object->getUser(), $database)->getUsername();
128
-    }
21
+	/**
22
+	 * @inheritDoc
23
+	 */
24
+	protected function main()
25
+	{
26
+		$this->setHtmlTitle('Flagged comments');
27
+		$this->setTemplate('flagged-comments.tpl');
28
+
29
+		$database = $this->getDatabase();
30
+		$this->assignCSRFToken();
31
+
32
+		/** @var Comment[] $commentObjects */
33
+		$commentObjects = Comment::getFlaggedComments($database, 1); // FIXME: domains
34
+		$comments = [];
35
+
36
+		$currentUser = User::getCurrent($database);
37
+
38
+		$seeRestrictedComments = $this->barrierTest('seeRestrictedComments', $currentUser, 'RequestData');
39
+		$seeCheckuserComments = $this->barrierTest('seeCheckuserComments', $currentUser, 'RequestData');
40
+		$alwaysSeePrivateData = $this->barrierTest('alwaysSeePrivateData', $currentUser, 'RequestData');
41
+
42
+		foreach ($commentObjects as $object) {
43
+			$data = [
44
+				'visibility'    => $object->getVisibility(),
45
+				'hidden'        => false,
46
+				'hiddenText'    => false,
47
+			];
48
+
49
+			if (!$alwaysSeePrivateData) {
50
+				// tl;dr: This is a stupid configuration, but let's account for it anyway.
51
+				//
52
+				// Flagged comments are treated as private data. If you don't have the privilege
53
+				// RequestData::alwaysSeePrivateData, then we can't show you the content of the comments here.
54
+				// This page is forced to degrade into basically a list of requests, seriously hampering the usefulness
55
+				// of this page. Still, we need to handle the case where we have access to this page, but not access
56
+				// to private data.
57
+				// At the time of writing, this case does not exist in the current role configuration, but for the role
58
+				// configuration to be free of assumptions, we need this code.
59
+
60
+				/** @var Request $request */
61
+				$request = Request::getById($object->getRequest(), $database);
62
+
63
+				if ($request->getReserved() === $currentUser->getId()) {
64
+					$data['hiddenText'] = false;
65
+				}
66
+				else {
67
+					$data['hiddenText'] = true;
68
+				}
69
+			}
70
+
71
+			if ($object->getVisibility() == 'requester' || $object->getVisibility() == 'user') {
72
+				$data['hidden'] = false;
73
+			}
74
+			elseif ($object->getVisibility() == 'admin') {
75
+				if ($seeRestrictedComments) {
76
+					$data['hidden'] = false;
77
+				}
78
+				else {
79
+					$data['hidden'] = true;
80
+				}
81
+			}
82
+			elseif ($object->getVisibility() == 'checkuser') {
83
+				if ($seeCheckuserComments) {
84
+					$data['hidden'] = false;
85
+				}
86
+				else {
87
+					$data['hidden'] = true;
88
+				}
89
+			}
90
+
91
+			$this->copyCommentData($object, $data, $database);
92
+
93
+			$comments[] = $data;
94
+		}
95
+
96
+		$this->assign('comments', $comments);
97
+		$this->assign('seeRestrictedComments', $seeRestrictedComments);
98
+		$this->assign('seeCheckuserComments', $seeCheckuserComments);
99
+
100
+		$this->assign('editOthersComments', $this->barrierTest('editOthers', $currentUser, PageEditComment::class));
101
+		$this->assign('editComments', $this->barrierTest(RoleConfigurationBase::MAIN, $currentUser, PageEditComment::class));
102
+		$this->assign('canUnflag', $this->barrierTest('unflag', $currentUser, PageFlagComment::class) && $this->barrierTest(RoleConfigurationBase::MAIN, $currentUser, PageFlagComment::class));
103
+	}
104
+
105
+	private function copyCommentData(Comment $object, array &$data, PdoDatabase $database): void
106
+	{
107
+		if ($data['hidden']) {
108
+			// All details hidden, so don't copy anything.
109
+			return;
110
+		}
111
+
112
+		/** @var Request $request */
113
+		$request = Request::getById($object->getRequest(), $database);
114
+
115
+		if (!$data['hiddenText']) {
116
+			// Comment text is hidden, but presence of the comment is visible.
117
+			$data['comment'] = $object->getComment();
118
+		}
119
+
120
+		$data['id'] = $object->getId();
121
+		$data['updateversion'] = $object->getUpdateVersion();
122
+		$data['time'] = $object->getTime();
123
+		$data['requestid'] = $object->getRequest();
124
+		$data['request'] = $request->getName();
125
+		$data['requeststatus'] = $request->getStatus();
126
+		$data['userid'] = $object->getUser();
127
+		$data['user'] = User::getById($object->getUser(), $database)->getUsername();
128
+	}
129 129
 }
130 130
\ No newline at end of file
Please login to merge, or discard this patch.
includes/SiteConfiguration.php 1 patch
Indentation   +1110 added lines, -1110 removed lines patch added patch discarded remove patch
@@ -18,1114 +18,1114 @@
 block discarded – undo
18 18
  */
19 19
 class SiteConfiguration
20 20
 {
21
-    private $baseUrl = 'https://accounts.wmflabs.org';
22
-    private $filePath = __DIR__ . '/..';
23
-    private $schemaVersion = 51;
24
-    private $debuggingTraceEnabled = false;
25
-    private $debuggingCssBreakpointsEnabled = false;
26
-    private $dataClearIp = '127.0.0.1';
27
-    private $dataClearEmail = '[email protected]';
28
-    private $dataClearInterval = '15 DAY';
29
-    private $forceIdentification = true;
30
-    private $identificationCacheExpiry = '1 DAY';
31
-    private $metaWikimediaWebServiceEndpoint = 'https://meta.wikimedia.org/w/api.php';
32
-    private $enforceOAuth = false;
33
-    private $emailConfirmationEnabled = true;
34
-    private $emailConfirmationExpiryDays = 7;
35
-    private $miserModeLimit = 25;
36
-    private $squidList = array();
37
-    private $useStrictTransportSecurity = false;
38
-    private $userAgent = 'Wikipedia-ACC Tool/0.1 (+https://accounts.wmflabs.org/internal.php/team)';
39
-    private $curlDisableVerifyPeer = false;
40
-    private $useOAuthSignup = true;
41
-    private $oauthConsumerToken;
42
-    /** @var array */
43
-    private $oauthLegacyConsumerTokens;
44
-    private $oauthConsumerSecret;
45
-    private $oauthIdentityGraceTime = '24 hours';
46
-    private $oauthMediaWikiCanonicalServer = 'https://en.wikipedia.org';
47
-    private $xffTrustedHostsFile = '../TrustedXFF/trusted-hosts.txt';
48
-    private $crossOriginResourceSharingHosts = array(
49
-        "https://en.wikipedia.org",
50
-        "https://meta.wikimedia.org",
51
-    );
52
-    private $ircNotificationsEnabled = true;
53
-    private $ircNotificationsInstance = 'Development';
54
-    private $errorLog = 'errorlog';
55
-    private $titleBlacklistEnabled = false;
56
-    /** @var null|string $locationProviderApiKey */
57
-    private $locationProviderApiKey = null;
58
-    private $torExitPaths = array();
59
-    private $creationBotUsername = '';
60
-    private $creationBotPassword = '';
61
-    private $curlCookieJar = __DIR__ . '/../../cookies.txt';
62
-    private $yubicoApiId = 0;
63
-    private $yubicoApiKey = "";
64
-    private $totpEncryptionKey = "1234";
65
-    private $identificationNoticeboardPage = 'Access to nonpublic personal data policy/Noticeboard';
66
-    private $identificationNoticeboardWebserviceEndpoint = 'https://meta.wikimedia.org/w/api.php';
67
-    private $registrationAllowed = true;
68
-    private $cspReportUri = null;
69
-    private $resourceCacheEpoch = 1;
70
-    private $commonEmailDomains = ['gmail.com', 'hotmail.com', 'outlook.com'];
71
-    private $banMaxIpBlockRange = [4 => 20, 6 => 48];
72
-    private $banMaxIpRange = [4 => 16, 6 => 32];
73
-    private $jobQueueBatchSize = 10;
74
-    private $amqpConfiguration = ['host' => 'localhost', 'port' => 5672, 'user' => 'guest', 'password' => 'guest', 'vhost' => '/', 'exchange' => '', 'tls' => false];
75
-    private $emailSender = '[email protected]';
76
-    private $acceptClientHints = [];
77
-    private string $cookiePath = '/';
78
-    private string $cookieSessionName = 'ACC';
79
-    private array $offline = ['offline' => false, 'reason' => '', 'culprit' => ''];
80
-    private array $databaseConfig = [
81
-        'datasource' => 'mysql:host=localhost;dbname=waca',
82
-        'username' => 'waca',
83
-        'password' => 'waca'
84
-    ];
85
-    private string $privacyStatementPath = '';
86
-
87
-    /**
88
-     * Gets the base URL of the tool
89
-     *
90
-     * If the internal page of the tool is at http://localhost/path/internal.php, this would be set to
91
-     * http://localhost/path
92
-     * @return string
93
-     */
94
-    public function getBaseUrl()
95
-    {
96
-        return $this->baseUrl;
97
-    }
98
-
99
-    /**
100
-     * @param string $baseUrl
101
-     *
102
-     * @return SiteConfiguration
103
-     */
104
-    public function setBaseUrl($baseUrl)
105
-    {
106
-        $this->baseUrl = $baseUrl;
107
-
108
-        return $this;
109
-    }
110
-
111
-    /**
112
-     * Path on disk to the directory containing the tool's code
113
-     * @return string
114
-     */
115
-    public function getFilePath()
116
-    {
117
-        return $this->filePath;
118
-    }
119
-
120
-    /**
121
-     * @param string $filePath
122
-     *
123
-     * @return SiteConfiguration
124
-     */
125
-    public function setFilePath($filePath)
126
-    {
127
-        $this->filePath = $filePath;
128
-
129
-        return $this;
130
-    }
131
-
132
-    /**
133
-     * @return int
134
-     */
135
-    public function getSchemaVersion()
136
-    {
137
-        return $this->schemaVersion;
138
-    }
139
-
140
-    /**
141
-     * @param int $schemaVersion
142
-     *
143
-     * @return SiteConfiguration
144
-     */
145
-    public function setSchemaVersion($schemaVersion)
146
-    {
147
-        $this->schemaVersion = $schemaVersion;
148
-
149
-        return $this;
150
-    }
151
-
152
-    /**
153
-     * @return mixed
154
-     */
155
-    public function getDebuggingTraceEnabled()
156
-    {
157
-        return $this->debuggingTraceEnabled;
158
-    }
159
-
160
-    /**
161
-     * @param mixed $debuggingTraceEnabled
162
-     *
163
-     * @return SiteConfiguration
164
-     */
165
-    public function setDebuggingTraceEnabled($debuggingTraceEnabled)
166
-    {
167
-        $this->debuggingTraceEnabled = $debuggingTraceEnabled;
168
-
169
-        return $this;
170
-    }
171
-
172
-    public function getDebuggingCssBreakpointsEnabled() : bool
173
-    {
174
-        return $this->debuggingCssBreakpointsEnabled;
175
-    }
176
-
177
-    public function setDebuggingCssBreakpointsEnabled(bool $debuggingCssBreakpointsEnabled) : SiteConfiguration
178
-    {
179
-        $this->debuggingCssBreakpointsEnabled = $debuggingCssBreakpointsEnabled;
180
-
181
-        return $this;
182
-    }
183
-
184
-    /**
185
-     * @return string
186
-     */
187
-    public function getDataClearIp()
188
-    {
189
-        return $this->dataClearIp;
190
-    }
191
-
192
-    /**
193
-     * @param string $dataClearIp
194
-     *
195
-     * @return SiteConfiguration
196
-     */
197
-    public function setDataClearIp($dataClearIp)
198
-    {
199
-        $this->dataClearIp = $dataClearIp;
200
-
201
-        return $this;
202
-    }
203
-
204
-    /**
205
-     * @return string
206
-     */
207
-    public function getDataClearEmail()
208
-    {
209
-        return $this->dataClearEmail;
210
-    }
211
-
212
-    /**
213
-     * @param string $dataClearEmail
214
-     *
215
-     * @return SiteConfiguration
216
-     */
217
-    public function setDataClearEmail($dataClearEmail)
218
-    {
219
-        $this->dataClearEmail = $dataClearEmail;
220
-
221
-        return $this;
222
-    }
223
-
224
-    /**
225
-     * @return boolean
226
-     */
227
-    public function getForceIdentification()
228
-    {
229
-        return $this->forceIdentification;
230
-    }
231
-
232
-    /**
233
-     * @param boolean $forceIdentification
234
-     *
235
-     * @return SiteConfiguration
236
-     */
237
-    public function setForceIdentification($forceIdentification)
238
-    {
239
-        $this->forceIdentification = $forceIdentification;
240
-
241
-        return $this;
242
-    }
243
-
244
-    /**
245
-     * @return string
246
-     */
247
-    public function getIdentificationCacheExpiry()
248
-    {
249
-        return $this->identificationCacheExpiry;
250
-    }
251
-
252
-    /**
253
-     * @param string $identificationCacheExpiry
254
-     *
255
-     * @return SiteConfiguration
256
-     */
257
-    public function setIdentificationCacheExpiry($identificationCacheExpiry)
258
-    {
259
-        $this->identificationCacheExpiry = $identificationCacheExpiry;
260
-
261
-        return $this;
262
-    }
263
-
264
-    /**
265
-     * @return string
266
-     */
267
-    public function getMetaWikimediaWebServiceEndpoint()
268
-    {
269
-        return $this->metaWikimediaWebServiceEndpoint;
270
-    }
271
-
272
-    /**
273
-     * @param string $metaWikimediaWebServiceEndpoint
274
-     *
275
-     * @return SiteConfiguration
276
-     */
277
-    public function setMetaWikimediaWebServiceEndpoint($metaWikimediaWebServiceEndpoint)
278
-    {
279
-        $this->metaWikimediaWebServiceEndpoint = $metaWikimediaWebServiceEndpoint;
280
-
281
-        return $this;
282
-    }
283
-
284
-    /**
285
-     * @return boolean
286
-     */
287
-    public function getEnforceOAuth()
288
-    {
289
-        return $this->enforceOAuth;
290
-    }
291
-
292
-    /**
293
-     * @param boolean $enforceOAuth
294
-     *
295
-     * @return SiteConfiguration
296
-     */
297
-    public function setEnforceOAuth($enforceOAuth)
298
-    {
299
-        $this->enforceOAuth = $enforceOAuth;
300
-
301
-        return $this;
302
-    }
303
-
304
-    /**
305
-     * @return boolean
306
-     */
307
-    public function getEmailConfirmationEnabled()
308
-    {
309
-        return $this->emailConfirmationEnabled;
310
-    }
311
-
312
-    /**
313
-     * @param boolean $emailConfirmationEnabled
314
-     *
315
-     * @return $this
316
-     */
317
-    public function setEmailConfirmationEnabled($emailConfirmationEnabled)
318
-    {
319
-        $this->emailConfirmationEnabled = $emailConfirmationEnabled;
320
-
321
-        return $this;
322
-    }
323
-
324
-    /**
325
-     * @return int
326
-     */
327
-    public function getMiserModeLimit()
328
-    {
329
-        return $this->miserModeLimit;
330
-    }
331
-
332
-    /**
333
-     * @param int $miserModeLimit
334
-     *
335
-     * @return SiteConfiguration
336
-     */
337
-    public function setMiserModeLimit($miserModeLimit)
338
-    {
339
-        $this->miserModeLimit = $miserModeLimit;
340
-
341
-        return $this;
342
-    }
343
-
344
-    /**
345
-     * @return array
346
-     */
347
-    public function getSquidList()
348
-    {
349
-        return $this->squidList;
350
-    }
351
-
352
-    /**
353
-     * @param array $squidList
354
-     *
355
-     * @return SiteConfiguration
356
-     */
357
-    public function setSquidList($squidList)
358
-    {
359
-        $this->squidList = $squidList;
360
-
361
-        return $this;
362
-    }
363
-
364
-    /**
365
-     * @return boolean
366
-     */
367
-    public function getUseStrictTransportSecurity()
368
-    {
369
-        return $this->useStrictTransportSecurity;
370
-    }
371
-
372
-    /**
373
-     * @param boolean $useStrictTransportSecurity
374
-     *
375
-     * @return SiteConfiguration
376
-     */
377
-    public function setUseStrictTransportSecurity($useStrictTransportSecurity)
378
-    {
379
-        $this->useStrictTransportSecurity = $useStrictTransportSecurity;
380
-
381
-        return $this;
382
-    }
383
-
384
-    /**
385
-     * @return string
386
-     */
387
-    public function getUserAgent()
388
-    {
389
-        return $this->userAgent;
390
-    }
391
-
392
-    /**
393
-     * @param string $userAgent
394
-     *
395
-     * @return SiteConfiguration
396
-     */
397
-    public function setUserAgent($userAgent)
398
-    {
399
-        $this->userAgent = $userAgent;
400
-
401
-        return $this;
402
-    }
403
-
404
-    /**
405
-     * @return boolean
406
-     */
407
-    public function getCurlDisableVerifyPeer()
408
-    {
409
-        return $this->curlDisableVerifyPeer;
410
-    }
411
-
412
-    /**
413
-     * @param boolean $curlDisableVerifyPeer
414
-     *
415
-     * @return SiteConfiguration
416
-     */
417
-    public function setCurlDisableVerifyPeer($curlDisableVerifyPeer)
418
-    {
419
-        $this->curlDisableVerifyPeer = $curlDisableVerifyPeer;
420
-
421
-        return $this;
422
-    }
423
-
424
-    /**
425
-     * @return boolean
426
-     */
427
-    public function getUseOAuthSignup()
428
-    {
429
-        return $this->useOAuthSignup;
430
-    }
431
-
432
-    /**
433
-     * @param boolean $useOAuthSignup
434
-     *
435
-     * @return SiteConfiguration
436
-     */
437
-    public function setUseOAuthSignup($useOAuthSignup)
438
-    {
439
-        $this->useOAuthSignup = $useOAuthSignup;
440
-
441
-        return $this;
442
-    }
443
-
444
-    /**
445
-     * @return mixed
446
-     */
447
-    public function getOAuthConsumerToken()
448
-    {
449
-        return $this->oauthConsumerToken;
450
-    }
451
-
452
-    /**
453
-     * @param mixed $oauthConsumerToken
454
-     *
455
-     * @return SiteConfiguration
456
-     */
457
-    public function setOAuthConsumerToken($oauthConsumerToken)
458
-    {
459
-        $this->oauthConsumerToken = $oauthConsumerToken;
460
-
461
-        return $this;
462
-    }
463
-
464
-    /**
465
-     * @return mixed
466
-     */
467
-    public function getOAuthConsumerSecret()
468
-    {
469
-        return $this->oauthConsumerSecret;
470
-    }
471
-
472
-    /**
473
-     * @param mixed $oauthConsumerSecret
474
-     *
475
-     * @return SiteConfiguration
476
-     */
477
-    public function setOAuthConsumerSecret($oauthConsumerSecret)
478
-    {
479
-        $this->oauthConsumerSecret = $oauthConsumerSecret;
480
-
481
-        return $this;
482
-    }
483
-
484
-    /**
485
-     * @return string
486
-     */
487
-    public function getDataClearInterval()
488
-    {
489
-        return $this->dataClearInterval;
490
-    }
491
-
492
-    /**
493
-     * @param string $dataClearInterval
494
-     *
495
-     * @return SiteConfiguration
496
-     */
497
-    public function setDataClearInterval($dataClearInterval)
498
-    {
499
-        $this->dataClearInterval = $dataClearInterval;
500
-
501
-        return $this;
502
-    }
503
-
504
-    /**
505
-     * @return string
506
-     */
507
-    public function getXffTrustedHostsFile()
508
-    {
509
-        return $this->xffTrustedHostsFile;
510
-    }
511
-
512
-    /**
513
-     * @param string $xffTrustedHostsFile
514
-     *
515
-     * @return SiteConfiguration
516
-     */
517
-    public function setXffTrustedHostsFile($xffTrustedHostsFile)
518
-    {
519
-        $this->xffTrustedHostsFile = $xffTrustedHostsFile;
520
-
521
-        return $this;
522
-    }
523
-
524
-    /**
525
-     * @return array
526
-     */
527
-    public function getCrossOriginResourceSharingHosts()
528
-    {
529
-        return $this->crossOriginResourceSharingHosts;
530
-    }
531
-
532
-    /**
533
-     * @param array $crossOriginResourceSharingHosts
534
-     *
535
-     * @return SiteConfiguration
536
-     */
537
-    public function setCrossOriginResourceSharingHosts($crossOriginResourceSharingHosts)
538
-    {
539
-        $this->crossOriginResourceSharingHosts = $crossOriginResourceSharingHosts;
540
-
541
-        return $this;
542
-    }
543
-
544
-    /**
545
-     * @return boolean
546
-     */
547
-    public function getIrcNotificationsEnabled()
548
-    {
549
-        return $this->ircNotificationsEnabled;
550
-    }
551
-
552
-    /**
553
-     * @param boolean $ircNotificationsEnabled
554
-     *
555
-     * @return SiteConfiguration
556
-     */
557
-    public function setIrcNotificationsEnabled($ircNotificationsEnabled)
558
-    {
559
-        $this->ircNotificationsEnabled = $ircNotificationsEnabled;
560
-
561
-        return $this;
562
-    }
563
-
564
-    /**
565
-     * @param string $errorLog
566
-     *
567
-     * @return SiteConfiguration
568
-     */
569
-    public function setErrorLog($errorLog)
570
-    {
571
-        $this->errorLog = $errorLog;
572
-
573
-        return $this;
574
-    }
575
-
576
-    /**
577
-     * @return string
578
-     */
579
-    public function getErrorLog()
580
-    {
581
-        return $this->errorLog;
582
-    }
583
-
584
-    /**
585
-     * @param int $emailConfirmationExpiryDays
586
-     *
587
-     * @return SiteConfiguration
588
-     */
589
-    public function setEmailConfirmationExpiryDays($emailConfirmationExpiryDays)
590
-    {
591
-        $this->emailConfirmationExpiryDays = $emailConfirmationExpiryDays;
592
-
593
-        return $this;
594
-    }
595
-
596
-    /**
597
-     * @return int
598
-     */
599
-    public function getEmailConfirmationExpiryDays()
600
-    {
601
-        return $this->emailConfirmationExpiryDays;
602
-    }
603
-
604
-    /**
605
-     * @param string $ircNotificationsInstance
606
-     *
607
-     * @return SiteConfiguration
608
-     */
609
-    public function setIrcNotificationsInstance($ircNotificationsInstance)
610
-    {
611
-        $this->ircNotificationsInstance = $ircNotificationsInstance;
612
-
613
-        return $this;
614
-    }
615
-
616
-    /**
617
-     * @return string
618
-     */
619
-    public function getIrcNotificationsInstance()
620
-    {
621
-        return $this->ircNotificationsInstance;
622
-    }
623
-
624
-    /**
625
-     * @param boolean $titleBlacklistEnabled
626
-     *
627
-     * @return SiteConfiguration
628
-     */
629
-    public function setTitleBlacklistEnabled($titleBlacklistEnabled)
630
-    {
631
-        $this->titleBlacklistEnabled = $titleBlacklistEnabled;
632
-
633
-        return $this;
634
-    }
635
-
636
-    /**
637
-     * @return boolean
638
-     */
639
-    public function getTitleBlacklistEnabled()
640
-    {
641
-        return $this->titleBlacklistEnabled;
642
-    }
643
-
644
-    /**
645
-     * @param string|null $locationProviderApiKey
646
-     *
647
-     * @return SiteConfiguration
648
-     */
649
-    public function setLocationProviderApiKey($locationProviderApiKey)
650
-    {
651
-        $this->locationProviderApiKey = $locationProviderApiKey;
652
-
653
-        return $this;
654
-    }
655
-
656
-    /**
657
-     * @return null|string
658
-     */
659
-    public function getLocationProviderApiKey()
660
-    {
661
-        return $this->locationProviderApiKey;
662
-    }
663
-
664
-    /**
665
-     * @param array $torExitPaths
666
-     *
667
-     * @return SiteConfiguration
668
-     */
669
-    public function setTorExitPaths($torExitPaths)
670
-    {
671
-        $this->torExitPaths = $torExitPaths;
672
-
673
-        return $this;
674
-    }
675
-
676
-    /**
677
-     * @return array
678
-     */
679
-    public function getTorExitPaths()
680
-    {
681
-        return $this->torExitPaths;
682
-    }
683
-
684
-    /**
685
-     * @param string $oauthIdentityGraceTime
686
-     *
687
-     * @return SiteConfiguration
688
-     */
689
-    public function setOauthIdentityGraceTime($oauthIdentityGraceTime)
690
-    {
691
-        $this->oauthIdentityGraceTime = $oauthIdentityGraceTime;
692
-
693
-        return $this;
694
-    }
695
-
696
-    /**
697
-     * @return string
698
-     */
699
-    public function getOauthIdentityGraceTime()
700
-    {
701
-        return $this->oauthIdentityGraceTime;
702
-    }
703
-
704
-    /**
705
-     * @param string $oauthMediaWikiCanonicalServer
706
-     *
707
-     * @return SiteConfiguration
708
-     */
709
-    public function setOauthMediaWikiCanonicalServer($oauthMediaWikiCanonicalServer)
710
-    {
711
-        $this->oauthMediaWikiCanonicalServer = $oauthMediaWikiCanonicalServer;
712
-
713
-        return $this;
714
-    }
715
-
716
-    /**
717
-     * @return string
718
-     */
719
-    public function getOauthMediaWikiCanonicalServer()
720
-    {
721
-        return $this->oauthMediaWikiCanonicalServer;
722
-    }
723
-
724
-    /**
725
-     * @param string $creationBotUsername
726
-     *
727
-     * @return SiteConfiguration
728
-     */
729
-    public function setCreationBotUsername($creationBotUsername)
730
-    {
731
-        $this->creationBotUsername = $creationBotUsername;
732
-
733
-        return $this;
734
-    }
735
-
736
-    /**
737
-     * @return string
738
-     */
739
-    public function getCreationBotUsername()
740
-    {
741
-        return $this->creationBotUsername;
742
-    }
743
-
744
-    /**
745
-     * @param string $creationBotPassword
746
-     *
747
-     * @return SiteConfiguration
748
-     */
749
-    public function setCreationBotPassword($creationBotPassword)
750
-    {
751
-        $this->creationBotPassword = $creationBotPassword;
752
-
753
-        return $this;
754
-    }
755
-
756
-    /**
757
-     * @return string
758
-     */
759
-    public function getCreationBotPassword()
760
-    {
761
-        return $this->creationBotPassword;
762
-    }
763
-
764
-    /**
765
-     * @param string|null $curlCookieJar
766
-     *
767
-     * @return SiteConfiguration
768
-     */
769
-    public function setCurlCookieJar($curlCookieJar)
770
-    {
771
-        $this->curlCookieJar = $curlCookieJar;
772
-
773
-        return $this;
774
-    }
775
-
776
-    /**
777
-     * @return string|null
778
-     */
779
-    public function getCurlCookieJar()
780
-    {
781
-        return $this->curlCookieJar;
782
-    }
783
-
784
-    public function getYubicoApiId()
785
-    {
786
-        return $this->yubicoApiId;
787
-    }
788
-
789
-    public function setYubicoApiId($id)
790
-    {
791
-        $this->yubicoApiId = $id;
792
-
793
-        return $this;
794
-    }
795
-
796
-    public function getYubicoApiKey()
797
-    {
798
-        return $this->yubicoApiKey;
799
-    }
800
-
801
-    public function setYubicoApiKey($key)
802
-    {
803
-        $this->yubicoApiKey = $key;
804
-
805
-        return $this;
806
-    }
807
-
808
-    /**
809
-     * @return string
810
-     */
811
-    public function getTotpEncryptionKey()
812
-    {
813
-        return $this->totpEncryptionKey;
814
-    }
815
-
816
-    /**
817
-     * @param string $totpEncryptionKey
818
-     *
819
-     * @return SiteConfiguration
820
-     */
821
-    public function setTotpEncryptionKey($totpEncryptionKey)
822
-    {
823
-        $this->totpEncryptionKey = $totpEncryptionKey;
824
-
825
-        return $this;
826
-    }
827
-
828
-    /**
829
-     * @return string
830
-     */
831
-    public function getIdentificationNoticeboardPage()
832
-    {
833
-        return $this->identificationNoticeboardPage;
834
-    }
835
-
836
-    /**
837
-     * @param string $identificationNoticeboardPage
838
-     *
839
-     * @return SiteConfiguration
840
-     */
841
-    public function setIdentificationNoticeboardPage($identificationNoticeboardPage)
842
-    {
843
-        $this->identificationNoticeboardPage = $identificationNoticeboardPage;
844
-
845
-        return $this;
846
-    }
847
-
848
-    public function setIdentificationNoticeboardWebserviceEndpoint(string $identificationNoticeboardWebserviceEndpoint
849
-    ): SiteConfiguration {
850
-        $this->identificationNoticeboardWebserviceEndpoint = $identificationNoticeboardWebserviceEndpoint;
851
-
852
-        return $this;
853
-    }
854
-
855
-    public function getIdentificationNoticeboardWebserviceEndpoint(): string
856
-    {
857
-        return $this->identificationNoticeboardWebserviceEndpoint;
858
-    }
859
-
860
-    public function isRegistrationAllowed(): bool
861
-    {
862
-        return $this->registrationAllowed;
863
-    }
864
-
865
-    public function setRegistrationAllowed(bool $registrationAllowed): SiteConfiguration
866
-    {
867
-        $this->registrationAllowed = $registrationAllowed;
868
-
869
-        return $this;
870
-    }
871
-
872
-    /**
873
-     * @return string|null
874
-     */
875
-    public function getCspReportUri()
876
-    {
877
-        return $this->cspReportUri;
878
-    }
879
-
880
-    /**
881
-     * @param string|null $cspReportUri
882
-     *
883
-     * @return SiteConfiguration
884
-     */
885
-    public function setCspReportUri($cspReportUri)
886
-    {
887
-        $this->cspReportUri = $cspReportUri;
888
-
889
-        return $this;
890
-    }
891
-
892
-    /**
893
-     * @return int
894
-     */
895
-    public function getResourceCacheEpoch(): int
896
-    {
897
-        return $this->resourceCacheEpoch;
898
-    }
899
-
900
-    /**
901
-     * @param int $resourceCacheEpoch
902
-     *
903
-     * @return SiteConfiguration
904
-     */
905
-    public function setResourceCacheEpoch(int $resourceCacheEpoch): SiteConfiguration
906
-    {
907
-        $this->resourceCacheEpoch = $resourceCacheEpoch;
908
-
909
-        return $this;
910
-    }
911
-
912
-    /**
913
-     * @return array
914
-     */
915
-    public function getCommonEmailDomains(): array
916
-    {
917
-        return $this->commonEmailDomains;
918
-    }
919
-
920
-    /**
921
-     * @param array $commonEmailDomains
922
-     *
923
-     * @return SiteConfiguration
924
-     */
925
-    public function setCommonEmailDomains(array $commonEmailDomains): SiteConfiguration
926
-    {
927
-        $this->commonEmailDomains = $commonEmailDomains;
928
-
929
-        return $this;
930
-    }
931
-
932
-    /**
933
-     * @param int[] $banMaxIpBlockRange
934
-     *
935
-     * @return SiteConfiguration
936
-     */
937
-    public function setBanMaxIpBlockRange(array $banMaxIpBlockRange): SiteConfiguration
938
-    {
939
-        $this->banMaxIpBlockRange = $banMaxIpBlockRange;
940
-
941
-        return $this;
942
-    }
943
-
944
-    /**
945
-     * @return int[]
946
-     */
947
-    public function getBanMaxIpBlockRange(): array
948
-    {
949
-        return $this->banMaxIpBlockRange;
950
-    }
951
-
952
-    /**
953
-     * @param int[] $banMaxIpRange
954
-     *
955
-     * @return SiteConfiguration
956
-     */
957
-    public function setBanMaxIpRange(array $banMaxIpRange): SiteConfiguration
958
-    {
959
-        $this->banMaxIpRange = $banMaxIpRange;
960
-
961
-        return $this;
962
-    }
963
-
964
-    /**
965
-     * @return int[]
966
-     */
967
-    public function getBanMaxIpRange(): array
968
-    {
969
-        return $this->banMaxIpRange;
970
-    }
971
-
972
-    /**
973
-     * @param array $oauthLegacyConsumerTokens
974
-     *
975
-     * @return SiteConfiguration
976
-     */
977
-    public function setOauthLegacyConsumerTokens(array $oauthLegacyConsumerTokens): SiteConfiguration
978
-    {
979
-        $this->oauthLegacyConsumerTokens = $oauthLegacyConsumerTokens;
980
-
981
-        return $this;
982
-    }
983
-
984
-    /**
985
-     * @return array
986
-     */
987
-    public function getOauthLegacyConsumerTokens(): array
988
-    {
989
-        return $this->oauthLegacyConsumerTokens;
990
-    }
991
-
992
-    /**
993
-     * @return int
994
-     */
995
-    public function getJobQueueBatchSize(): int
996
-    {
997
-        return $this->jobQueueBatchSize;
998
-    }
999
-
1000
-    /**
1001
-     * @param int $jobQueueBatchSize
1002
-     *
1003
-     * @return SiteConfiguration
1004
-     */
1005
-    public function setJobQueueBatchSize(int $jobQueueBatchSize): SiteConfiguration
1006
-    {
1007
-        $this->jobQueueBatchSize = $jobQueueBatchSize;
1008
-
1009
-        return $this;
1010
-    }
1011
-
1012
-    /**
1013
-     * @return array
1014
-     */
1015
-    public function getAmqpConfiguration(): array
1016
-    {
1017
-        return $this->amqpConfiguration;
1018
-    }
1019
-
1020
-    /**
1021
-     * @param array $amqpConfiguration
1022
-     *
1023
-     * @return SiteConfiguration
1024
-     */
1025
-    public function setAmqpConfiguration(array $amqpConfiguration): SiteConfiguration
1026
-    {
1027
-        $this->amqpConfiguration = $amqpConfiguration;
1028
-
1029
-        return $this;
1030
-    }
1031
-
1032
-    /**
1033
-     * @return string
1034
-     */
1035
-    public function getEmailSender(): string
1036
-    {
1037
-        return $this->emailSender;
1038
-    }
1039
-
1040
-    /**
1041
-     * @param string $emailSender
1042
-     *
1043
-     * @return SiteConfiguration
1044
-     */
1045
-    public function setEmailSender(string $emailSender): SiteConfiguration
1046
-    {
1047
-        $this->emailSender = $emailSender;
1048
-
1049
-        return $this;
1050
-    }
1051
-
1052
-    /**
1053
-     * @param array $acceptClientHints
1054
-     *
1055
-     * @return SiteConfiguration
1056
-     */
1057
-    public function setAcceptClientHints(array $acceptClientHints): SiteConfiguration
1058
-    {
1059
-        $this->acceptClientHints = $acceptClientHints;
1060
-
1061
-        return $this;
1062
-    }
1063
-
1064
-    /**
1065
-     * @return array
1066
-     */
1067
-    public function getAcceptClientHints(): array
1068
-    {
1069
-        return $this->acceptClientHints;
1070
-    }
1071
-
1072
-    public function setCookiePath(string $cookiePath): SiteConfiguration
1073
-    {
1074
-        $this->cookiePath = $cookiePath;
1075
-
1076
-        return $this;
1077
-    }
1078
-
1079
-    public function getCookiePath(): string
1080
-    {
1081
-        return $this->cookiePath;
1082
-    }
1083
-
1084
-    public function setCookieSessionName(string $cookieSessionName): SiteConfiguration
1085
-    {
1086
-        $this->cookieSessionName = $cookieSessionName;
1087
-
1088
-        return $this;
1089
-    }
1090
-
1091
-    public function getCookieSessionName(): string
1092
-    {
1093
-        return $this->cookieSessionName;
1094
-    }
1095
-
1096
-    public function setOffline(array $offline): SiteConfiguration
1097
-    {
1098
-        $this->offline = $offline;
1099
-
1100
-        return $this;
1101
-    }
1102
-
1103
-    public function getOffline(): array
1104
-    {
1105
-        return $this->offline;
1106
-    }
1107
-
1108
-    public function setDatabaseConfig(array $databaseConfig): SiteConfiguration
1109
-    {
1110
-        $this->databaseConfig = $databaseConfig;
1111
-
1112
-        return $this;
1113
-    }
1114
-
1115
-    public function getDatabaseConfig(): array
1116
-    {
1117
-        return $this->databaseConfig;
1118
-    }
1119
-
1120
-    public function getPrivacyStatementPath(): string
1121
-    {
1122
-        return $this->privacyStatementPath;
1123
-    }
1124
-
1125
-    public function setPrivacyStatementPath(string $privacyStatementPath): SiteConfiguration
1126
-    {
1127
-        $this->privacyStatementPath = $privacyStatementPath;
1128
-
1129
-        return $this;
1130
-    }
21
+	private $baseUrl = 'https://accounts.wmflabs.org';
22
+	private $filePath = __DIR__ . '/..';
23
+	private $schemaVersion = 51;
24
+	private $debuggingTraceEnabled = false;
25
+	private $debuggingCssBreakpointsEnabled = false;
26
+	private $dataClearIp = '127.0.0.1';
27
+	private $dataClearEmail = '[email protected]';
28
+	private $dataClearInterval = '15 DAY';
29
+	private $forceIdentification = true;
30
+	private $identificationCacheExpiry = '1 DAY';
31
+	private $metaWikimediaWebServiceEndpoint = 'https://meta.wikimedia.org/w/api.php';
32
+	private $enforceOAuth = false;
33
+	private $emailConfirmationEnabled = true;
34
+	private $emailConfirmationExpiryDays = 7;
35
+	private $miserModeLimit = 25;
36
+	private $squidList = array();
37
+	private $useStrictTransportSecurity = false;
38
+	private $userAgent = 'Wikipedia-ACC Tool/0.1 (+https://accounts.wmflabs.org/internal.php/team)';
39
+	private $curlDisableVerifyPeer = false;
40
+	private $useOAuthSignup = true;
41
+	private $oauthConsumerToken;
42
+	/** @var array */
43
+	private $oauthLegacyConsumerTokens;
44
+	private $oauthConsumerSecret;
45
+	private $oauthIdentityGraceTime = '24 hours';
46
+	private $oauthMediaWikiCanonicalServer = 'https://en.wikipedia.org';
47
+	private $xffTrustedHostsFile = '../TrustedXFF/trusted-hosts.txt';
48
+	private $crossOriginResourceSharingHosts = array(
49
+		"https://en.wikipedia.org",
50
+		"https://meta.wikimedia.org",
51
+	);
52
+	private $ircNotificationsEnabled = true;
53
+	private $ircNotificationsInstance = 'Development';
54
+	private $errorLog = 'errorlog';
55
+	private $titleBlacklistEnabled = false;
56
+	/** @var null|string $locationProviderApiKey */
57
+	private $locationProviderApiKey = null;
58
+	private $torExitPaths = array();
59
+	private $creationBotUsername = '';
60
+	private $creationBotPassword = '';
61
+	private $curlCookieJar = __DIR__ . '/../../cookies.txt';
62
+	private $yubicoApiId = 0;
63
+	private $yubicoApiKey = "";
64
+	private $totpEncryptionKey = "1234";
65
+	private $identificationNoticeboardPage = 'Access to nonpublic personal data policy/Noticeboard';
66
+	private $identificationNoticeboardWebserviceEndpoint = 'https://meta.wikimedia.org/w/api.php';
67
+	private $registrationAllowed = true;
68
+	private $cspReportUri = null;
69
+	private $resourceCacheEpoch = 1;
70
+	private $commonEmailDomains = ['gmail.com', 'hotmail.com', 'outlook.com'];
71
+	private $banMaxIpBlockRange = [4 => 20, 6 => 48];
72
+	private $banMaxIpRange = [4 => 16, 6 => 32];
73
+	private $jobQueueBatchSize = 10;
74
+	private $amqpConfiguration = ['host' => 'localhost', 'port' => 5672, 'user' => 'guest', 'password' => 'guest', 'vhost' => '/', 'exchange' => '', 'tls' => false];
75
+	private $emailSender = '[email protected]';
76
+	private $acceptClientHints = [];
77
+	private string $cookiePath = '/';
78
+	private string $cookieSessionName = 'ACC';
79
+	private array $offline = ['offline' => false, 'reason' => '', 'culprit' => ''];
80
+	private array $databaseConfig = [
81
+		'datasource' => 'mysql:host=localhost;dbname=waca',
82
+		'username' => 'waca',
83
+		'password' => 'waca'
84
+	];
85
+	private string $privacyStatementPath = '';
86
+
87
+	/**
88
+	 * Gets the base URL of the tool
89
+	 *
90
+	 * If the internal page of the tool is at http://localhost/path/internal.php, this would be set to
91
+	 * http://localhost/path
92
+	 * @return string
93
+	 */
94
+	public function getBaseUrl()
95
+	{
96
+		return $this->baseUrl;
97
+	}
98
+
99
+	/**
100
+	 * @param string $baseUrl
101
+	 *
102
+	 * @return SiteConfiguration
103
+	 */
104
+	public function setBaseUrl($baseUrl)
105
+	{
106
+		$this->baseUrl = $baseUrl;
107
+
108
+		return $this;
109
+	}
110
+
111
+	/**
112
+	 * Path on disk to the directory containing the tool's code
113
+	 * @return string
114
+	 */
115
+	public function getFilePath()
116
+	{
117
+		return $this->filePath;
118
+	}
119
+
120
+	/**
121
+	 * @param string $filePath
122
+	 *
123
+	 * @return SiteConfiguration
124
+	 */
125
+	public function setFilePath($filePath)
126
+	{
127
+		$this->filePath = $filePath;
128
+
129
+		return $this;
130
+	}
131
+
132
+	/**
133
+	 * @return int
134
+	 */
135
+	public function getSchemaVersion()
136
+	{
137
+		return $this->schemaVersion;
138
+	}
139
+
140
+	/**
141
+	 * @param int $schemaVersion
142
+	 *
143
+	 * @return SiteConfiguration
144
+	 */
145
+	public function setSchemaVersion($schemaVersion)
146
+	{
147
+		$this->schemaVersion = $schemaVersion;
148
+
149
+		return $this;
150
+	}
151
+
152
+	/**
153
+	 * @return mixed
154
+	 */
155
+	public function getDebuggingTraceEnabled()
156
+	{
157
+		return $this->debuggingTraceEnabled;
158
+	}
159
+
160
+	/**
161
+	 * @param mixed $debuggingTraceEnabled
162
+	 *
163
+	 * @return SiteConfiguration
164
+	 */
165
+	public function setDebuggingTraceEnabled($debuggingTraceEnabled)
166
+	{
167
+		$this->debuggingTraceEnabled = $debuggingTraceEnabled;
168
+
169
+		return $this;
170
+	}
171
+
172
+	public function getDebuggingCssBreakpointsEnabled() : bool
173
+	{
174
+		return $this->debuggingCssBreakpointsEnabled;
175
+	}
176
+
177
+	public function setDebuggingCssBreakpointsEnabled(bool $debuggingCssBreakpointsEnabled) : SiteConfiguration
178
+	{
179
+		$this->debuggingCssBreakpointsEnabled = $debuggingCssBreakpointsEnabled;
180
+
181
+		return $this;
182
+	}
183
+
184
+	/**
185
+	 * @return string
186
+	 */
187
+	public function getDataClearIp()
188
+	{
189
+		return $this->dataClearIp;
190
+	}
191
+
192
+	/**
193
+	 * @param string $dataClearIp
194
+	 *
195
+	 * @return SiteConfiguration
196
+	 */
197
+	public function setDataClearIp($dataClearIp)
198
+	{
199
+		$this->dataClearIp = $dataClearIp;
200
+
201
+		return $this;
202
+	}
203
+
204
+	/**
205
+	 * @return string
206
+	 */
207
+	public function getDataClearEmail()
208
+	{
209
+		return $this->dataClearEmail;
210
+	}
211
+
212
+	/**
213
+	 * @param string $dataClearEmail
214
+	 *
215
+	 * @return SiteConfiguration
216
+	 */
217
+	public function setDataClearEmail($dataClearEmail)
218
+	{
219
+		$this->dataClearEmail = $dataClearEmail;
220
+
221
+		return $this;
222
+	}
223
+
224
+	/**
225
+	 * @return boolean
226
+	 */
227
+	public function getForceIdentification()
228
+	{
229
+		return $this->forceIdentification;
230
+	}
231
+
232
+	/**
233
+	 * @param boolean $forceIdentification
234
+	 *
235
+	 * @return SiteConfiguration
236
+	 */
237
+	public function setForceIdentification($forceIdentification)
238
+	{
239
+		$this->forceIdentification = $forceIdentification;
240
+
241
+		return $this;
242
+	}
243
+
244
+	/**
245
+	 * @return string
246
+	 */
247
+	public function getIdentificationCacheExpiry()
248
+	{
249
+		return $this->identificationCacheExpiry;
250
+	}
251
+
252
+	/**
253
+	 * @param string $identificationCacheExpiry
254
+	 *
255
+	 * @return SiteConfiguration
256
+	 */
257
+	public function setIdentificationCacheExpiry($identificationCacheExpiry)
258
+	{
259
+		$this->identificationCacheExpiry = $identificationCacheExpiry;
260
+
261
+		return $this;
262
+	}
263
+
264
+	/**
265
+	 * @return string
266
+	 */
267
+	public function getMetaWikimediaWebServiceEndpoint()
268
+	{
269
+		return $this->metaWikimediaWebServiceEndpoint;
270
+	}
271
+
272
+	/**
273
+	 * @param string $metaWikimediaWebServiceEndpoint
274
+	 *
275
+	 * @return SiteConfiguration
276
+	 */
277
+	public function setMetaWikimediaWebServiceEndpoint($metaWikimediaWebServiceEndpoint)
278
+	{
279
+		$this->metaWikimediaWebServiceEndpoint = $metaWikimediaWebServiceEndpoint;
280
+
281
+		return $this;
282
+	}
283
+
284
+	/**
285
+	 * @return boolean
286
+	 */
287
+	public function getEnforceOAuth()
288
+	{
289
+		return $this->enforceOAuth;
290
+	}
291
+
292
+	/**
293
+	 * @param boolean $enforceOAuth
294
+	 *
295
+	 * @return SiteConfiguration
296
+	 */
297
+	public function setEnforceOAuth($enforceOAuth)
298
+	{
299
+		$this->enforceOAuth = $enforceOAuth;
300
+
301
+		return $this;
302
+	}
303
+
304
+	/**
305
+	 * @return boolean
306
+	 */
307
+	public function getEmailConfirmationEnabled()
308
+	{
309
+		return $this->emailConfirmationEnabled;
310
+	}
311
+
312
+	/**
313
+	 * @param boolean $emailConfirmationEnabled
314
+	 *
315
+	 * @return $this
316
+	 */
317
+	public function setEmailConfirmationEnabled($emailConfirmationEnabled)
318
+	{
319
+		$this->emailConfirmationEnabled = $emailConfirmationEnabled;
320
+
321
+		return $this;
322
+	}
323
+
324
+	/**
325
+	 * @return int
326
+	 */
327
+	public function getMiserModeLimit()
328
+	{
329
+		return $this->miserModeLimit;
330
+	}
331
+
332
+	/**
333
+	 * @param int $miserModeLimit
334
+	 *
335
+	 * @return SiteConfiguration
336
+	 */
337
+	public function setMiserModeLimit($miserModeLimit)
338
+	{
339
+		$this->miserModeLimit = $miserModeLimit;
340
+
341
+		return $this;
342
+	}
343
+
344
+	/**
345
+	 * @return array
346
+	 */
347
+	public function getSquidList()
348
+	{
349
+		return $this->squidList;
350
+	}
351
+
352
+	/**
353
+	 * @param array $squidList
354
+	 *
355
+	 * @return SiteConfiguration
356
+	 */
357
+	public function setSquidList($squidList)
358
+	{
359
+		$this->squidList = $squidList;
360
+
361
+		return $this;
362
+	}
363
+
364
+	/**
365
+	 * @return boolean
366
+	 */
367
+	public function getUseStrictTransportSecurity()
368
+	{
369
+		return $this->useStrictTransportSecurity;
370
+	}
371
+
372
+	/**
373
+	 * @param boolean $useStrictTransportSecurity
374
+	 *
375
+	 * @return SiteConfiguration
376
+	 */
377
+	public function setUseStrictTransportSecurity($useStrictTransportSecurity)
378
+	{
379
+		$this->useStrictTransportSecurity = $useStrictTransportSecurity;
380
+
381
+		return $this;
382
+	}
383
+
384
+	/**
385
+	 * @return string
386
+	 */
387
+	public function getUserAgent()
388
+	{
389
+		return $this->userAgent;
390
+	}
391
+
392
+	/**
393
+	 * @param string $userAgent
394
+	 *
395
+	 * @return SiteConfiguration
396
+	 */
397
+	public function setUserAgent($userAgent)
398
+	{
399
+		$this->userAgent = $userAgent;
400
+
401
+		return $this;
402
+	}
403
+
404
+	/**
405
+	 * @return boolean
406
+	 */
407
+	public function getCurlDisableVerifyPeer()
408
+	{
409
+		return $this->curlDisableVerifyPeer;
410
+	}
411
+
412
+	/**
413
+	 * @param boolean $curlDisableVerifyPeer
414
+	 *
415
+	 * @return SiteConfiguration
416
+	 */
417
+	public function setCurlDisableVerifyPeer($curlDisableVerifyPeer)
418
+	{
419
+		$this->curlDisableVerifyPeer = $curlDisableVerifyPeer;
420
+
421
+		return $this;
422
+	}
423
+
424
+	/**
425
+	 * @return boolean
426
+	 */
427
+	public function getUseOAuthSignup()
428
+	{
429
+		return $this->useOAuthSignup;
430
+	}
431
+
432
+	/**
433
+	 * @param boolean $useOAuthSignup
434
+	 *
435
+	 * @return SiteConfiguration
436
+	 */
437
+	public function setUseOAuthSignup($useOAuthSignup)
438
+	{
439
+		$this->useOAuthSignup = $useOAuthSignup;
440
+
441
+		return $this;
442
+	}
443
+
444
+	/**
445
+	 * @return mixed
446
+	 */
447
+	public function getOAuthConsumerToken()
448
+	{
449
+		return $this->oauthConsumerToken;
450
+	}
451
+
452
+	/**
453
+	 * @param mixed $oauthConsumerToken
454
+	 *
455
+	 * @return SiteConfiguration
456
+	 */
457
+	public function setOAuthConsumerToken($oauthConsumerToken)
458
+	{
459
+		$this->oauthConsumerToken = $oauthConsumerToken;
460
+
461
+		return $this;
462
+	}
463
+
464
+	/**
465
+	 * @return mixed
466
+	 */
467
+	public function getOAuthConsumerSecret()
468
+	{
469
+		return $this->oauthConsumerSecret;
470
+	}
471
+
472
+	/**
473
+	 * @param mixed $oauthConsumerSecret
474
+	 *
475
+	 * @return SiteConfiguration
476
+	 */
477
+	public function setOAuthConsumerSecret($oauthConsumerSecret)
478
+	{
479
+		$this->oauthConsumerSecret = $oauthConsumerSecret;
480
+
481
+		return $this;
482
+	}
483
+
484
+	/**
485
+	 * @return string
486
+	 */
487
+	public function getDataClearInterval()
488
+	{
489
+		return $this->dataClearInterval;
490
+	}
491
+
492
+	/**
493
+	 * @param string $dataClearInterval
494
+	 *
495
+	 * @return SiteConfiguration
496
+	 */
497
+	public function setDataClearInterval($dataClearInterval)
498
+	{
499
+		$this->dataClearInterval = $dataClearInterval;
500
+
501
+		return $this;
502
+	}
503
+
504
+	/**
505
+	 * @return string
506
+	 */
507
+	public function getXffTrustedHostsFile()
508
+	{
509
+		return $this->xffTrustedHostsFile;
510
+	}
511
+
512
+	/**
513
+	 * @param string $xffTrustedHostsFile
514
+	 *
515
+	 * @return SiteConfiguration
516
+	 */
517
+	public function setXffTrustedHostsFile($xffTrustedHostsFile)
518
+	{
519
+		$this->xffTrustedHostsFile = $xffTrustedHostsFile;
520
+
521
+		return $this;
522
+	}
523
+
524
+	/**
525
+	 * @return array
526
+	 */
527
+	public function getCrossOriginResourceSharingHosts()
528
+	{
529
+		return $this->crossOriginResourceSharingHosts;
530
+	}
531
+
532
+	/**
533
+	 * @param array $crossOriginResourceSharingHosts
534
+	 *
535
+	 * @return SiteConfiguration
536
+	 */
537
+	public function setCrossOriginResourceSharingHosts($crossOriginResourceSharingHosts)
538
+	{
539
+		$this->crossOriginResourceSharingHosts = $crossOriginResourceSharingHosts;
540
+
541
+		return $this;
542
+	}
543
+
544
+	/**
545
+	 * @return boolean
546
+	 */
547
+	public function getIrcNotificationsEnabled()
548
+	{
549
+		return $this->ircNotificationsEnabled;
550
+	}
551
+
552
+	/**
553
+	 * @param boolean $ircNotificationsEnabled
554
+	 *
555
+	 * @return SiteConfiguration
556
+	 */
557
+	public function setIrcNotificationsEnabled($ircNotificationsEnabled)
558
+	{
559
+		$this->ircNotificationsEnabled = $ircNotificationsEnabled;
560
+
561
+		return $this;
562
+	}
563
+
564
+	/**
565
+	 * @param string $errorLog
566
+	 *
567
+	 * @return SiteConfiguration
568
+	 */
569
+	public function setErrorLog($errorLog)
570
+	{
571
+		$this->errorLog = $errorLog;
572
+
573
+		return $this;
574
+	}
575
+
576
+	/**
577
+	 * @return string
578
+	 */
579
+	public function getErrorLog()
580
+	{
581
+		return $this->errorLog;
582
+	}
583
+
584
+	/**
585
+	 * @param int $emailConfirmationExpiryDays
586
+	 *
587
+	 * @return SiteConfiguration
588
+	 */
589
+	public function setEmailConfirmationExpiryDays($emailConfirmationExpiryDays)
590
+	{
591
+		$this->emailConfirmationExpiryDays = $emailConfirmationExpiryDays;
592
+
593
+		return $this;
594
+	}
595
+
596
+	/**
597
+	 * @return int
598
+	 */
599
+	public function getEmailConfirmationExpiryDays()
600
+	{
601
+		return $this->emailConfirmationExpiryDays;
602
+	}
603
+
604
+	/**
605
+	 * @param string $ircNotificationsInstance
606
+	 *
607
+	 * @return SiteConfiguration
608
+	 */
609
+	public function setIrcNotificationsInstance($ircNotificationsInstance)
610
+	{
611
+		$this->ircNotificationsInstance = $ircNotificationsInstance;
612
+
613
+		return $this;
614
+	}
615
+
616
+	/**
617
+	 * @return string
618
+	 */
619
+	public function getIrcNotificationsInstance()
620
+	{
621
+		return $this->ircNotificationsInstance;
622
+	}
623
+
624
+	/**
625
+	 * @param boolean $titleBlacklistEnabled
626
+	 *
627
+	 * @return SiteConfiguration
628
+	 */
629
+	public function setTitleBlacklistEnabled($titleBlacklistEnabled)
630
+	{
631
+		$this->titleBlacklistEnabled = $titleBlacklistEnabled;
632
+
633
+		return $this;
634
+	}
635
+
636
+	/**
637
+	 * @return boolean
638
+	 */
639
+	public function getTitleBlacklistEnabled()
640
+	{
641
+		return $this->titleBlacklistEnabled;
642
+	}
643
+
644
+	/**
645
+	 * @param string|null $locationProviderApiKey
646
+	 *
647
+	 * @return SiteConfiguration
648
+	 */
649
+	public function setLocationProviderApiKey($locationProviderApiKey)
650
+	{
651
+		$this->locationProviderApiKey = $locationProviderApiKey;
652
+
653
+		return $this;
654
+	}
655
+
656
+	/**
657
+	 * @return null|string
658
+	 */
659
+	public function getLocationProviderApiKey()
660
+	{
661
+		return $this->locationProviderApiKey;
662
+	}
663
+
664
+	/**
665
+	 * @param array $torExitPaths
666
+	 *
667
+	 * @return SiteConfiguration
668
+	 */
669
+	public function setTorExitPaths($torExitPaths)
670
+	{
671
+		$this->torExitPaths = $torExitPaths;
672
+
673
+		return $this;
674
+	}
675
+
676
+	/**
677
+	 * @return array
678
+	 */
679
+	public function getTorExitPaths()
680
+	{
681
+		return $this->torExitPaths;
682
+	}
683
+
684
+	/**
685
+	 * @param string $oauthIdentityGraceTime
686
+	 *
687
+	 * @return SiteConfiguration
688
+	 */
689
+	public function setOauthIdentityGraceTime($oauthIdentityGraceTime)
690
+	{
691
+		$this->oauthIdentityGraceTime = $oauthIdentityGraceTime;
692
+
693
+		return $this;
694
+	}
695
+
696
+	/**
697
+	 * @return string
698
+	 */
699
+	public function getOauthIdentityGraceTime()
700
+	{
701
+		return $this->oauthIdentityGraceTime;
702
+	}
703
+
704
+	/**
705
+	 * @param string $oauthMediaWikiCanonicalServer
706
+	 *
707
+	 * @return SiteConfiguration
708
+	 */
709
+	public function setOauthMediaWikiCanonicalServer($oauthMediaWikiCanonicalServer)
710
+	{
711
+		$this->oauthMediaWikiCanonicalServer = $oauthMediaWikiCanonicalServer;
712
+
713
+		return $this;
714
+	}
715
+
716
+	/**
717
+	 * @return string
718
+	 */
719
+	public function getOauthMediaWikiCanonicalServer()
720
+	{
721
+		return $this->oauthMediaWikiCanonicalServer;
722
+	}
723
+
724
+	/**
725
+	 * @param string $creationBotUsername
726
+	 *
727
+	 * @return SiteConfiguration
728
+	 */
729
+	public function setCreationBotUsername($creationBotUsername)
730
+	{
731
+		$this->creationBotUsername = $creationBotUsername;
732
+
733
+		return $this;
734
+	}
735
+
736
+	/**
737
+	 * @return string
738
+	 */
739
+	public function getCreationBotUsername()
740
+	{
741
+		return $this->creationBotUsername;
742
+	}
743
+
744
+	/**
745
+	 * @param string $creationBotPassword
746
+	 *
747
+	 * @return SiteConfiguration
748
+	 */
749
+	public function setCreationBotPassword($creationBotPassword)
750
+	{
751
+		$this->creationBotPassword = $creationBotPassword;
752
+
753
+		return $this;
754
+	}
755
+
756
+	/**
757
+	 * @return string
758
+	 */
759
+	public function getCreationBotPassword()
760
+	{
761
+		return $this->creationBotPassword;
762
+	}
763
+
764
+	/**
765
+	 * @param string|null $curlCookieJar
766
+	 *
767
+	 * @return SiteConfiguration
768
+	 */
769
+	public function setCurlCookieJar($curlCookieJar)
770
+	{
771
+		$this->curlCookieJar = $curlCookieJar;
772
+
773
+		return $this;
774
+	}
775
+
776
+	/**
777
+	 * @return string|null
778
+	 */
779
+	public function getCurlCookieJar()
780
+	{
781
+		return $this->curlCookieJar;
782
+	}
783
+
784
+	public function getYubicoApiId()
785
+	{
786
+		return $this->yubicoApiId;
787
+	}
788
+
789
+	public function setYubicoApiId($id)
790
+	{
791
+		$this->yubicoApiId = $id;
792
+
793
+		return $this;
794
+	}
795
+
796
+	public function getYubicoApiKey()
797
+	{
798
+		return $this->yubicoApiKey;
799
+	}
800
+
801
+	public function setYubicoApiKey($key)
802
+	{
803
+		$this->yubicoApiKey = $key;
804
+
805
+		return $this;
806
+	}
807
+
808
+	/**
809
+	 * @return string
810
+	 */
811
+	public function getTotpEncryptionKey()
812
+	{
813
+		return $this->totpEncryptionKey;
814
+	}
815
+
816
+	/**
817
+	 * @param string $totpEncryptionKey
818
+	 *
819
+	 * @return SiteConfiguration
820
+	 */
821
+	public function setTotpEncryptionKey($totpEncryptionKey)
822
+	{
823
+		$this->totpEncryptionKey = $totpEncryptionKey;
824
+
825
+		return $this;
826
+	}
827
+
828
+	/**
829
+	 * @return string
830
+	 */
831
+	public function getIdentificationNoticeboardPage()
832
+	{
833
+		return $this->identificationNoticeboardPage;
834
+	}
835
+
836
+	/**
837
+	 * @param string $identificationNoticeboardPage
838
+	 *
839
+	 * @return SiteConfiguration
840
+	 */
841
+	public function setIdentificationNoticeboardPage($identificationNoticeboardPage)
842
+	{
843
+		$this->identificationNoticeboardPage = $identificationNoticeboardPage;
844
+
845
+		return $this;
846
+	}
847
+
848
+	public function setIdentificationNoticeboardWebserviceEndpoint(string $identificationNoticeboardWebserviceEndpoint
849
+	): SiteConfiguration {
850
+		$this->identificationNoticeboardWebserviceEndpoint = $identificationNoticeboardWebserviceEndpoint;
851
+
852
+		return $this;
853
+	}
854
+
855
+	public function getIdentificationNoticeboardWebserviceEndpoint(): string
856
+	{
857
+		return $this->identificationNoticeboardWebserviceEndpoint;
858
+	}
859
+
860
+	public function isRegistrationAllowed(): bool
861
+	{
862
+		return $this->registrationAllowed;
863
+	}
864
+
865
+	public function setRegistrationAllowed(bool $registrationAllowed): SiteConfiguration
866
+	{
867
+		$this->registrationAllowed = $registrationAllowed;
868
+
869
+		return $this;
870
+	}
871
+
872
+	/**
873
+	 * @return string|null
874
+	 */
875
+	public function getCspReportUri()
876
+	{
877
+		return $this->cspReportUri;
878
+	}
879
+
880
+	/**
881
+	 * @param string|null $cspReportUri
882
+	 *
883
+	 * @return SiteConfiguration
884
+	 */
885
+	public function setCspReportUri($cspReportUri)
886
+	{
887
+		$this->cspReportUri = $cspReportUri;
888
+
889
+		return $this;
890
+	}
891
+
892
+	/**
893
+	 * @return int
894
+	 */
895
+	public function getResourceCacheEpoch(): int
896
+	{
897
+		return $this->resourceCacheEpoch;
898
+	}
899
+
900
+	/**
901
+	 * @param int $resourceCacheEpoch
902
+	 *
903
+	 * @return SiteConfiguration
904
+	 */
905
+	public function setResourceCacheEpoch(int $resourceCacheEpoch): SiteConfiguration
906
+	{
907
+		$this->resourceCacheEpoch = $resourceCacheEpoch;
908
+
909
+		return $this;
910
+	}
911
+
912
+	/**
913
+	 * @return array
914
+	 */
915
+	public function getCommonEmailDomains(): array
916
+	{
917
+		return $this->commonEmailDomains;
918
+	}
919
+
920
+	/**
921
+	 * @param array $commonEmailDomains
922
+	 *
923
+	 * @return SiteConfiguration
924
+	 */
925
+	public function setCommonEmailDomains(array $commonEmailDomains): SiteConfiguration
926
+	{
927
+		$this->commonEmailDomains = $commonEmailDomains;
928
+
929
+		return $this;
930
+	}
931
+
932
+	/**
933
+	 * @param int[] $banMaxIpBlockRange
934
+	 *
935
+	 * @return SiteConfiguration
936
+	 */
937
+	public function setBanMaxIpBlockRange(array $banMaxIpBlockRange): SiteConfiguration
938
+	{
939
+		$this->banMaxIpBlockRange = $banMaxIpBlockRange;
940
+
941
+		return $this;
942
+	}
943
+
944
+	/**
945
+	 * @return int[]
946
+	 */
947
+	public function getBanMaxIpBlockRange(): array
948
+	{
949
+		return $this->banMaxIpBlockRange;
950
+	}
951
+
952
+	/**
953
+	 * @param int[] $banMaxIpRange
954
+	 *
955
+	 * @return SiteConfiguration
956
+	 */
957
+	public function setBanMaxIpRange(array $banMaxIpRange): SiteConfiguration
958
+	{
959
+		$this->banMaxIpRange = $banMaxIpRange;
960
+
961
+		return $this;
962
+	}
963
+
964
+	/**
965
+	 * @return int[]
966
+	 */
967
+	public function getBanMaxIpRange(): array
968
+	{
969
+		return $this->banMaxIpRange;
970
+	}
971
+
972
+	/**
973
+	 * @param array $oauthLegacyConsumerTokens
974
+	 *
975
+	 * @return SiteConfiguration
976
+	 */
977
+	public function setOauthLegacyConsumerTokens(array $oauthLegacyConsumerTokens): SiteConfiguration
978
+	{
979
+		$this->oauthLegacyConsumerTokens = $oauthLegacyConsumerTokens;
980
+
981
+		return $this;
982
+	}
983
+
984
+	/**
985
+	 * @return array
986
+	 */
987
+	public function getOauthLegacyConsumerTokens(): array
988
+	{
989
+		return $this->oauthLegacyConsumerTokens;
990
+	}
991
+
992
+	/**
993
+	 * @return int
994
+	 */
995
+	public function getJobQueueBatchSize(): int
996
+	{
997
+		return $this->jobQueueBatchSize;
998
+	}
999
+
1000
+	/**
1001
+	 * @param int $jobQueueBatchSize
1002
+	 *
1003
+	 * @return SiteConfiguration
1004
+	 */
1005
+	public function setJobQueueBatchSize(int $jobQueueBatchSize): SiteConfiguration
1006
+	{
1007
+		$this->jobQueueBatchSize = $jobQueueBatchSize;
1008
+
1009
+		return $this;
1010
+	}
1011
+
1012
+	/**
1013
+	 * @return array
1014
+	 */
1015
+	public function getAmqpConfiguration(): array
1016
+	{
1017
+		return $this->amqpConfiguration;
1018
+	}
1019
+
1020
+	/**
1021
+	 * @param array $amqpConfiguration
1022
+	 *
1023
+	 * @return SiteConfiguration
1024
+	 */
1025
+	public function setAmqpConfiguration(array $amqpConfiguration): SiteConfiguration
1026
+	{
1027
+		$this->amqpConfiguration = $amqpConfiguration;
1028
+
1029
+		return $this;
1030
+	}
1031
+
1032
+	/**
1033
+	 * @return string
1034
+	 */
1035
+	public function getEmailSender(): string
1036
+	{
1037
+		return $this->emailSender;
1038
+	}
1039
+
1040
+	/**
1041
+	 * @param string $emailSender
1042
+	 *
1043
+	 * @return SiteConfiguration
1044
+	 */
1045
+	public function setEmailSender(string $emailSender): SiteConfiguration
1046
+	{
1047
+		$this->emailSender = $emailSender;
1048
+
1049
+		return $this;
1050
+	}
1051
+
1052
+	/**
1053
+	 * @param array $acceptClientHints
1054
+	 *
1055
+	 * @return SiteConfiguration
1056
+	 */
1057
+	public function setAcceptClientHints(array $acceptClientHints): SiteConfiguration
1058
+	{
1059
+		$this->acceptClientHints = $acceptClientHints;
1060
+
1061
+		return $this;
1062
+	}
1063
+
1064
+	/**
1065
+	 * @return array
1066
+	 */
1067
+	public function getAcceptClientHints(): array
1068
+	{
1069
+		return $this->acceptClientHints;
1070
+	}
1071
+
1072
+	public function setCookiePath(string $cookiePath): SiteConfiguration
1073
+	{
1074
+		$this->cookiePath = $cookiePath;
1075
+
1076
+		return $this;
1077
+	}
1078
+
1079
+	public function getCookiePath(): string
1080
+	{
1081
+		return $this->cookiePath;
1082
+	}
1083
+
1084
+	public function setCookieSessionName(string $cookieSessionName): SiteConfiguration
1085
+	{
1086
+		$this->cookieSessionName = $cookieSessionName;
1087
+
1088
+		return $this;
1089
+	}
1090
+
1091
+	public function getCookieSessionName(): string
1092
+	{
1093
+		return $this->cookieSessionName;
1094
+	}
1095
+
1096
+	public function setOffline(array $offline): SiteConfiguration
1097
+	{
1098
+		$this->offline = $offline;
1099
+
1100
+		return $this;
1101
+	}
1102
+
1103
+	public function getOffline(): array
1104
+	{
1105
+		return $this->offline;
1106
+	}
1107
+
1108
+	public function setDatabaseConfig(array $databaseConfig): SiteConfiguration
1109
+	{
1110
+		$this->databaseConfig = $databaseConfig;
1111
+
1112
+		return $this;
1113
+	}
1114
+
1115
+	public function getDatabaseConfig(): array
1116
+	{
1117
+		return $this->databaseConfig;
1118
+	}
1119
+
1120
+	public function getPrivacyStatementPath(): string
1121
+	{
1122
+		return $this->privacyStatementPath;
1123
+	}
1124
+
1125
+	public function setPrivacyStatementPath(string $privacyStatementPath): SiteConfiguration
1126
+	{
1127
+		$this->privacyStatementPath = $privacyStatementPath;
1128
+
1129
+		return $this;
1130
+	}
1131 1131
 }
Please login to merge, or discard this patch.
includes/Fragments/TemplateOutput.php 1 patch
Indentation   +125 added lines, -125 removed lines patch added patch discarded remove patch
@@ -18,129 +18,129 @@
 block discarded – undo
18 18
 
19 19
 trait TemplateOutput
20 20
 {
21
-    /** @var Smarty */
22
-    private $smarty;
23
-
24
-    /**
25
-     * @param string $pluginsDir
26
-     *
27
-     * @return void
28
-     * @throws Exception
29
-     */
30
-    private function loadPlugins(string $pluginsDir): void
31
-    {
32
-        /** @var DirectoryIterator $file */
33
-        foreach (new DirectoryIterator($pluginsDir) as $file) {
34
-            if ($file->isDot()) {
35
-                continue;
36
-            }
37
-
38
-            if ($file->getExtension() != 'php') {
39
-                continue;
40
-            }
41
-
42
-            require_once $file->getPathname();
43
-
44
-            list($type, $name) = explode('.', $file->getBasename('.php'), 2);
45
-
46
-            switch ($type) {
47
-                case 'modifier':
48
-                    $this->smarty->registerPlugin(Smarty::PLUGIN_MODIFIER, $name, 'smarty_modifier_' . $name);
49
-                    break;
50
-                case 'function':
51
-                    $this->smarty->registerPlugin(Smarty::PLUGIN_FUNCTION, $name, 'smarty_function_' . $name);
52
-                    break;
53
-            }
54
-        }
55
-    }
56
-
57
-    /**
58
-     * @return SiteConfiguration
59
-     */
60
-    protected abstract function getSiteConfiguration();
61
-
62
-    /**
63
-     * Assigns a Smarty variable
64
-     *
65
-     * @param  array|string $name  the template variable name(s)
66
-     * @param  mixed        $value the value to assign
67
-     */
68
-    final protected function assign($name, $value)
69
-    {
70
-        $this->smarty->assign($name, $value);
71
-    }
72
-
73
-    /**
74
-     * Sets up the variables used by the main Smarty base template.
75
-     *
76
-     * This list is getting kinda long.
77
-     * @throws Exception
78
-     */
79
-    final protected function setUpSmarty()
80
-    {
81
-        $this->smarty = new Smarty();
82
-        $pluginsDir = $this->getSiteConfiguration()->getFilePath() . '/smarty-plugins';
83
-
84
-        // Dynamically load all plugins in the plugins directory
85
-        $this->loadPlugins($pluginsDir);
86
-
87
-        $this->assign('currentUser', User::getCommunity());
88
-        $this->assign('skin', 'auto');
89
-        $this->assign('currentDomain', null);
90
-        $this->assign('loggedIn', false);
91
-        $this->assign('baseurl', $this->getSiteConfiguration()->getBaseUrl());
92
-        $this->assign('resourceCacheEpoch', $this->getSiteConfiguration()->getResourceCacheEpoch());
93
-
94
-        $this->assign('siteNoticeText', '');
95
-        $this->assign('siteNoticeVersion', 0);
96
-        $this->assign('siteNoticeState', 'd-none');
97
-        $this->assign('toolversion', Environment::getToolVersion());
98
-
99
-        // default these
100
-        $this->assign('onlineusers', array());
101
-        $this->assign('typeAheadBlock', '');
102
-        $this->assign('extraJs', array());
103
-
104
-        // nav menu access control
105
-        $this->assign('nav__canRequests', false);
106
-        $this->assign('nav__canLogs', false);
107
-        $this->assign('nav__canUsers', false);
108
-        $this->assign('nav__canSearch', false);
109
-        $this->assign('nav__canStats', false);
110
-        $this->assign('nav__canBan', false);
111
-        $this->assign('nav__canEmailMgmt', false);
112
-        $this->assign('nav__canWelcomeMgmt', false);
113
-        $this->assign('nav__canSiteNoticeMgmt', false);
114
-        $this->assign('nav__canUserMgmt', false);
115
-        $this->assign('nav__canViewRequest', false);
116
-        $this->assign('nav__canJobQueue', false);
117
-        $this->assign('nav__canFlaggedComments', false);
118
-        $this->assign('nav__canDomainMgmt', false);
119
-        $this->assign('nav__canQueueMgmt', false);
120
-        $this->assign('nav__canFormMgmt', false);
121
-        $this->assign('nav__canErrorLog', false);
122
-
123
-        // Navigation badges for concern areas.
124
-        $this->assign("nav__numAdmin", 0);
125
-        $this->assign("nav__numFlaggedComments", 0);
126
-        $this->assign("nav__numJobQueueFailed", 0);
127
-
128
-        // debug helpers
129
-        $this->assign('showDebugCssBreakpoints', $this->getSiteConfiguration()->getDebuggingCssBreakpointsEnabled());
130
-
131
-        $this->assign('page', $this);
132
-    }
133
-
134
-    /**
135
-     * Fetches a rendered Smarty template
136
-     *
137
-     * @param $template string Template file path, relative to /templates/
138
-     *
139
-     * @return string Templated HTML
140
-     * @throws Exception
141
-     */
142
-    final protected function fetchTemplate($template)
143
-    {
144
-        return $this->smarty->fetch($template);
145
-    }
21
+	/** @var Smarty */
22
+	private $smarty;
23
+
24
+	/**
25
+	 * @param string $pluginsDir
26
+	 *
27
+	 * @return void
28
+	 * @throws Exception
29
+	 */
30
+	private function loadPlugins(string $pluginsDir): void
31
+	{
32
+		/** @var DirectoryIterator $file */
33
+		foreach (new DirectoryIterator($pluginsDir) as $file) {
34
+			if ($file->isDot()) {
35
+				continue;
36
+			}
37
+
38
+			if ($file->getExtension() != 'php') {
39
+				continue;
40
+			}
41
+
42
+			require_once $file->getPathname();
43
+
44
+			list($type, $name) = explode('.', $file->getBasename('.php'), 2);
45
+
46
+			switch ($type) {
47
+				case 'modifier':
48
+					$this->smarty->registerPlugin(Smarty::PLUGIN_MODIFIER, $name, 'smarty_modifier_' . $name);
49
+					break;
50
+				case 'function':
51
+					$this->smarty->registerPlugin(Smarty::PLUGIN_FUNCTION, $name, 'smarty_function_' . $name);
52
+					break;
53
+			}
54
+		}
55
+	}
56
+
57
+	/**
58
+	 * @return SiteConfiguration
59
+	 */
60
+	protected abstract function getSiteConfiguration();
61
+
62
+	/**
63
+	 * Assigns a Smarty variable
64
+	 *
65
+	 * @param  array|string $name  the template variable name(s)
66
+	 * @param  mixed        $value the value to assign
67
+	 */
68
+	final protected function assign($name, $value)
69
+	{
70
+		$this->smarty->assign($name, $value);
71
+	}
72
+
73
+	/**
74
+	 * Sets up the variables used by the main Smarty base template.
75
+	 *
76
+	 * This list is getting kinda long.
77
+	 * @throws Exception
78
+	 */
79
+	final protected function setUpSmarty()
80
+	{
81
+		$this->smarty = new Smarty();
82
+		$pluginsDir = $this->getSiteConfiguration()->getFilePath() . '/smarty-plugins';
83
+
84
+		// Dynamically load all plugins in the plugins directory
85
+		$this->loadPlugins($pluginsDir);
86
+
87
+		$this->assign('currentUser', User::getCommunity());
88
+		$this->assign('skin', 'auto');
89
+		$this->assign('currentDomain', null);
90
+		$this->assign('loggedIn', false);
91
+		$this->assign('baseurl', $this->getSiteConfiguration()->getBaseUrl());
92
+		$this->assign('resourceCacheEpoch', $this->getSiteConfiguration()->getResourceCacheEpoch());
93
+
94
+		$this->assign('siteNoticeText', '');
95
+		$this->assign('siteNoticeVersion', 0);
96
+		$this->assign('siteNoticeState', 'd-none');
97
+		$this->assign('toolversion', Environment::getToolVersion());
98
+
99
+		// default these
100
+		$this->assign('onlineusers', array());
101
+		$this->assign('typeAheadBlock', '');
102
+		$this->assign('extraJs', array());
103
+
104
+		// nav menu access control
105
+		$this->assign('nav__canRequests', false);
106
+		$this->assign('nav__canLogs', false);
107
+		$this->assign('nav__canUsers', false);
108
+		$this->assign('nav__canSearch', false);
109
+		$this->assign('nav__canStats', false);
110
+		$this->assign('nav__canBan', false);
111
+		$this->assign('nav__canEmailMgmt', false);
112
+		$this->assign('nav__canWelcomeMgmt', false);
113
+		$this->assign('nav__canSiteNoticeMgmt', false);
114
+		$this->assign('nav__canUserMgmt', false);
115
+		$this->assign('nav__canViewRequest', false);
116
+		$this->assign('nav__canJobQueue', false);
117
+		$this->assign('nav__canFlaggedComments', false);
118
+		$this->assign('nav__canDomainMgmt', false);
119
+		$this->assign('nav__canQueueMgmt', false);
120
+		$this->assign('nav__canFormMgmt', false);
121
+		$this->assign('nav__canErrorLog', false);
122
+
123
+		// Navigation badges for concern areas.
124
+		$this->assign("nav__numAdmin", 0);
125
+		$this->assign("nav__numFlaggedComments", 0);
126
+		$this->assign("nav__numJobQueueFailed", 0);
127
+
128
+		// debug helpers
129
+		$this->assign('showDebugCssBreakpoints', $this->getSiteConfiguration()->getDebuggingCssBreakpointsEnabled());
130
+
131
+		$this->assign('page', $this);
132
+	}
133
+
134
+	/**
135
+	 * Fetches a rendered Smarty template
136
+	 *
137
+	 * @param $template string Template file path, relative to /templates/
138
+	 *
139
+	 * @return string Templated HTML
140
+	 * @throws Exception
141
+	 */
142
+	final protected function fetchTemplate($template)
143
+	{
144
+		return $this->smarty->fetch($template);
145
+	}
146 146
 }
Please login to merge, or discard this patch.
includes/Security/RoleConfigurationBase.php 1 patch
Indentation   +131 added lines, -131 removed lines patch added patch discarded remove patch
@@ -10,135 +10,135 @@
 block discarded – undo
10 10
 
11 11
 abstract class RoleConfigurationBase
12 12
 {
13
-    const ACCESS_ALLOW = 1;
14
-    const ACCESS_DENY = -1;
15
-    const ACCESS_DEFAULT = 0;
16
-    const MAIN = 'main';
17
-    const ALL = '*';
18
-
19
-    protected array $roleConfig;
20
-    protected array $identificationExempt;
21
-
22
-    protected function __construct(array $roleConfig, array $identificationExempt)
23
-    {
24
-        $this->roleConfig = $roleConfig;
25
-        $this->identificationExempt = $identificationExempt;
26
-    }
27
-
28
-    /**
29
-     * Takes an array of role names and flattens the values to a single
30
-     * resultant role configuration.
31
-     *
32
-     * @param string[] $activeRoles
33
-     * @category Security-Critical
34
-     */
35
-    public function getResultantRole(array $activeRoles): array
36
-    {
37
-        $result = array();
38
-
39
-        $roleConfig = $this->getApplicableRoles($activeRoles);
40
-
41
-        // Iterate over every page in every role
42
-        foreach ($roleConfig as $role) {
43
-            foreach ($role as $page => $pageRights) {
44
-                // Create holder in result for this page
45
-                if (!isset($result[$page])) {
46
-                    $result[$page] = array();
47
-                }
48
-
49
-                foreach ($pageRights as $action => $permission) {
50
-                    // Deny takes precedence, so if it's set, don't change it.
51
-                    if (isset($result[$page][$action])) {
52
-                        if ($result[$page][$action] === RoleConfigurationBase::ACCESS_DENY) {
53
-                            continue;
54
-                        }
55
-                    }
56
-
57
-                    if ($permission === RoleConfigurationBase::ACCESS_DEFAULT) {
58
-                        // Configured to do precisely nothing.
59
-                        continue;
60
-                    }
61
-
62
-                    $result[$page][$action] = $permission;
63
-                }
64
-            }
65
-        }
66
-
67
-        return $result;
68
-    }
69
-
70
-    /**
71
-     * Returns a set of all roles which are available to be set.
72
-     *
73
-     * Hidden roles and implicit roles are excluded.
74
-     */
75
-    public function getAvailableRoles(): array
76
-    {
77
-        // remove the implicit roles
78
-        $possible = array_diff(array_keys($this->roleConfig), array('public', 'loggedIn', 'user'));
79
-
80
-        $actual = array();
81
-
82
-        foreach ($possible as $role) {
83
-            if (!isset($this->roleConfig[$role]['_hidden'])) {
84
-                $actual[$role] = array(
85
-                    'description' => $this->roleConfig[$role]['_description'],
86
-                    'editableBy'  => $this->roleConfig[$role]['_editableBy'],
87
-                    'globalOnly'  => isset($this->roleConfig[$role]['_globalOnly']) && $this->roleConfig[$role]['_globalOnly'],
88
-                );
89
-            }
90
-        }
91
-
92
-        return $actual;
93
-    }
94
-
95
-    /**
96
-     * Returns a boolean for whether the provided role requires identification
97
-     * before being used by a user.
98
-     *
99
-     * @category Security-Critical
100
-     */
101
-    public function roleNeedsIdentification(string $role): bool
102
-    {
103
-        if (in_array($role, $this->identificationExempt)) {
104
-            return false;
105
-        }
106
-
107
-        return true;
108
-    }
109
-
110
-    /**
111
-     * Takes an array of role names, and returns all the relevant roles for that
112
-     * set, including any child roles found recursively.
113
-     *
114
-     * @param array $roles The names of roles to start searching with
115
-     */
116
-    private function getApplicableRoles(array $roles): array
117
-    {
118
-        $available = array();
119
-
120
-        foreach ($roles as $role) {
121
-            if (!isset($this->roleConfig[$role])) {
122
-                // wat
123
-                continue;
124
-            }
125
-
126
-            $available[$role] = $this->roleConfig[$role];
127
-
128
-            if (isset($available[$role]['_childRoles'])) {
129
-                $childRoles = $this->getApplicableRoles($available[$role]['_childRoles']);
130
-                $available = array_merge($available, $childRoles);
131
-
132
-                unset($available[$role]['_childRoles']);
133
-            }
134
-
135
-            foreach (array('_hidden', '_editableBy', '_description', '_globalOnly') as $item) {
136
-                if (isset($available[$role][$item])) {
137
-                    unset($available[$role][$item]);
138
-                }
139
-            }
140
-        }
141
-
142
-        return $available;
143
-    }
13
+	const ACCESS_ALLOW = 1;
14
+	const ACCESS_DENY = -1;
15
+	const ACCESS_DEFAULT = 0;
16
+	const MAIN = 'main';
17
+	const ALL = '*';
18
+
19
+	protected array $roleConfig;
20
+	protected array $identificationExempt;
21
+
22
+	protected function __construct(array $roleConfig, array $identificationExempt)
23
+	{
24
+		$this->roleConfig = $roleConfig;
25
+		$this->identificationExempt = $identificationExempt;
26
+	}
27
+
28
+	/**
29
+	 * Takes an array of role names and flattens the values to a single
30
+	 * resultant role configuration.
31
+	 *
32
+	 * @param string[] $activeRoles
33
+	 * @category Security-Critical
34
+	 */
35
+	public function getResultantRole(array $activeRoles): array
36
+	{
37
+		$result = array();
38
+
39
+		$roleConfig = $this->getApplicableRoles($activeRoles);
40
+
41
+		// Iterate over every page in every role
42
+		foreach ($roleConfig as $role) {
43
+			foreach ($role as $page => $pageRights) {
44
+				// Create holder in result for this page
45
+				if (!isset($result[$page])) {
46
+					$result[$page] = array();
47
+				}
48
+
49
+				foreach ($pageRights as $action => $permission) {
50
+					// Deny takes precedence, so if it's set, don't change it.
51
+					if (isset($result[$page][$action])) {
52
+						if ($result[$page][$action] === RoleConfigurationBase::ACCESS_DENY) {
53
+							continue;
54
+						}
55
+					}
56
+
57
+					if ($permission === RoleConfigurationBase::ACCESS_DEFAULT) {
58
+						// Configured to do precisely nothing.
59
+						continue;
60
+					}
61
+
62
+					$result[$page][$action] = $permission;
63
+				}
64
+			}
65
+		}
66
+
67
+		return $result;
68
+	}
69
+
70
+	/**
71
+	 * Returns a set of all roles which are available to be set.
72
+	 *
73
+	 * Hidden roles and implicit roles are excluded.
74
+	 */
75
+	public function getAvailableRoles(): array
76
+	{
77
+		// remove the implicit roles
78
+		$possible = array_diff(array_keys($this->roleConfig), array('public', 'loggedIn', 'user'));
79
+
80
+		$actual = array();
81
+
82
+		foreach ($possible as $role) {
83
+			if (!isset($this->roleConfig[$role]['_hidden'])) {
84
+				$actual[$role] = array(
85
+					'description' => $this->roleConfig[$role]['_description'],
86
+					'editableBy'  => $this->roleConfig[$role]['_editableBy'],
87
+					'globalOnly'  => isset($this->roleConfig[$role]['_globalOnly']) && $this->roleConfig[$role]['_globalOnly'],
88
+				);
89
+			}
90
+		}
91
+
92
+		return $actual;
93
+	}
94
+
95
+	/**
96
+	 * Returns a boolean for whether the provided role requires identification
97
+	 * before being used by a user.
98
+	 *
99
+	 * @category Security-Critical
100
+	 */
101
+	public function roleNeedsIdentification(string $role): bool
102
+	{
103
+		if (in_array($role, $this->identificationExempt)) {
104
+			return false;
105
+		}
106
+
107
+		return true;
108
+	}
109
+
110
+	/**
111
+	 * Takes an array of role names, and returns all the relevant roles for that
112
+	 * set, including any child roles found recursively.
113
+	 *
114
+	 * @param array $roles The names of roles to start searching with
115
+	 */
116
+	private function getApplicableRoles(array $roles): array
117
+	{
118
+		$available = array();
119
+
120
+		foreach ($roles as $role) {
121
+			if (!isset($this->roleConfig[$role])) {
122
+				// wat
123
+				continue;
124
+			}
125
+
126
+			$available[$role] = $this->roleConfig[$role];
127
+
128
+			if (isset($available[$role]['_childRoles'])) {
129
+				$childRoles = $this->getApplicableRoles($available[$role]['_childRoles']);
130
+				$available = array_merge($available, $childRoles);
131
+
132
+				unset($available[$role]['_childRoles']);
133
+			}
134
+
135
+			foreach (array('_hidden', '_editableBy', '_description', '_globalOnly') as $item) {
136
+				if (isset($available[$role][$item])) {
137
+					unset($available[$role][$item]);
138
+				}
139
+			}
140
+		}
141
+
142
+		return $available;
143
+	}
144 144
 }
145 145
\ No newline at end of file
Please login to merge, or discard this patch.
includes/ExceptionHandler.php 1 patch
Indentation   +118 added lines, -118 removed lines patch added patch discarded remove patch
@@ -14,22 +14,22 @@  discard block
 block discarded – undo
14 14
 
15 15
 class ExceptionHandler
16 16
 {
17
-    /**
18
-     * Global exception handler
19
-     *
20
-     * Smarty would be nice to use, but it COULD BE smarty that throws the errors.
21
-     * Let's build something ourselves, and hope it works.
22
-     *
23
-     * @param $exception
24
-     *
25
-     * @category Security-Critical - has the potential to leak data when exception is thrown.
26
-     */
27
-    public static function exceptionHandler(Throwable $exception)
28
-    {
29
-        /** @global $siteConfiguration SiteConfiguration */
30
-        global $siteConfiguration;
31
-
32
-        $errorDocument = <<<HTML
17
+	/**
18
+	 * Global exception handler
19
+	 *
20
+	 * Smarty would be nice to use, but it COULD BE smarty that throws the errors.
21
+	 * Let's build something ourselves, and hope it works.
22
+	 *
23
+	 * @param $exception
24
+	 *
25
+	 * @category Security-Critical - has the potential to leak data when exception is thrown.
26
+	 */
27
+	public static function exceptionHandler(Throwable $exception)
28
+	{
29
+		/** @global $siteConfiguration SiteConfiguration */
30
+		global $siteConfiguration;
31
+
32
+		$errorDocument = <<<HTML
33 33
 <!DOCTYPE html>
34 34
 <html lang="en"><head>
35 35
 <meta charset="utf-8">
@@ -49,106 +49,106 @@  discard block
 block discarded – undo
49 49
 </div></body></html>
50 50
 HTML;
51 51
 
52
-        list($errorData, $errorId) = self::logExceptionToDisk($exception, $siteConfiguration, true);
53
-
54
-        error_log('Unhandled ' . get_class($exception) . ': ' . $exception->getMessage());
55
-
56
-        // clear and discard any content that's been saved to the output buffer
57
-        if (ob_get_level() > 0) {
58
-            ob_end_clean();
59
-        }
60
-
61
-        // push error ID into the document.
62
-        $message = str_replace('$1$', $errorId, $errorDocument);
63
-
64
-        if ($siteConfiguration->getDebuggingTraceEnabled()) {
65
-            ob_start();
66
-            var_dump($errorData);
67
-            $textErrorData = ob_get_contents();
68
-            ob_end_clean();
69
-
70
-            $message = str_replace('$2$', $textErrorData, $message);
71
-        }
72
-        else {
73
-            $message = str_replace('$2$', "", $message);
74
-        }
75
-
76
-        // While we *shouldn't* have sent headers by now due to the output buffering, PHPUnit does weird things.
77
-        // This is "only" needed for the tests, but it's a good idea to wrap this anyway.
78
-        if (!headers_sent()) {
79
-            header('HTTP/1.1 500 Internal Server Error');
80
-        }
81
-
82
-        // output the document
83
-        print $message;
84
-    }
85
-
86
-    /**
87
-     * @param int    $errorSeverity The severity level of the exception.
88
-     * @param string $errorMessage  The Exception message to throw.
89
-     * @param string $errorFile     The filename where the exception is thrown.
90
-     * @param int    $errorLine     The line number where the exception is thrown.
91
-     *
92
-     * @throws ErrorException
93
-     */
94
-    public static function errorHandler($errorSeverity, $errorMessage, $errorFile, $errorLine)
95
-    {
96
-        // call into the main exception handler above
97
-        throw new ErrorException($errorMessage, 0, $errorSeverity, $errorFile, $errorLine);
98
-    }
99
-
100
-    /**
101
-     * @param Throwable $exception
102
-     *
103
-     * @return null|array
104
-     */
105
-    public static function getExceptionData($exception)
106
-    {
107
-        if ($exception == null) {
108
-            return null;
109
-        }
110
-
111
-        $array = array(
112
-            'exception' => get_class($exception),
113
-            'message'   => $exception->getMessage(),
114
-            'stack'     => $exception->getTraceAsString(),
115
-        );
116
-
117
-        $array['previous'] = self::getExceptionData($exception->getPrevious());
118
-
119
-        return $array;
120
-    }
121
-
122
-    public static function logExceptionToDisk(
123
-        Throwable $exception,
124
-        SiteConfiguration $siteConfiguration,
125
-        bool $fromGlobalHandler = false
126
-    ): array {
127
-        $errorData = self::getExceptionData($exception);
128
-        $errorData['server'] = $_SERVER;
129
-        $errorData['get'] = $_GET;
130
-        $errorData['post'] = $_POST;
131
-
132
-        $redactions = ['password', 'newpassword', 'newpasswordconfirm', 'otp'];
133
-        foreach ($redactions as $redaction) {
134
-            if (isset($errorData['post'][$redaction])) {
135
-                $errorData['post'][$redaction] = '<redacted>';
136
-            }
137
-        }
138
-
139
-        if ($fromGlobalHandler) {
140
-            $errorData['globalHandler'] = true;
141
-        }
142
-        else {
143
-            $errorData['globalHandler'] = false;
144
-        }
145
-
146
-        $state = serialize($errorData);
147
-        $errorId = sha1($state);
148
-
149
-        // Save the error for later analysis
150
-        file_put_contents($siteConfiguration->getErrorLog() . '/' . $errorId . '.log', $state);
151
-
152
-        return array($errorData, $errorId);
153
-    }
52
+		list($errorData, $errorId) = self::logExceptionToDisk($exception, $siteConfiguration, true);
53
+
54
+		error_log('Unhandled ' . get_class($exception) . ': ' . $exception->getMessage());
55
+
56
+		// clear and discard any content that's been saved to the output buffer
57
+		if (ob_get_level() > 0) {
58
+			ob_end_clean();
59
+		}
60
+
61
+		// push error ID into the document.
62
+		$message = str_replace('$1$', $errorId, $errorDocument);
63
+
64
+		if ($siteConfiguration->getDebuggingTraceEnabled()) {
65
+			ob_start();
66
+			var_dump($errorData);
67
+			$textErrorData = ob_get_contents();
68
+			ob_end_clean();
69
+
70
+			$message = str_replace('$2$', $textErrorData, $message);
71
+		}
72
+		else {
73
+			$message = str_replace('$2$', "", $message);
74
+		}
75
+
76
+		// While we *shouldn't* have sent headers by now due to the output buffering, PHPUnit does weird things.
77
+		// This is "only" needed for the tests, but it's a good idea to wrap this anyway.
78
+		if (!headers_sent()) {
79
+			header('HTTP/1.1 500 Internal Server Error');
80
+		}
81
+
82
+		// output the document
83
+		print $message;
84
+	}
85
+
86
+	/**
87
+	 * @param int    $errorSeverity The severity level of the exception.
88
+	 * @param string $errorMessage  The Exception message to throw.
89
+	 * @param string $errorFile     The filename where the exception is thrown.
90
+	 * @param int    $errorLine     The line number where the exception is thrown.
91
+	 *
92
+	 * @throws ErrorException
93
+	 */
94
+	public static function errorHandler($errorSeverity, $errorMessage, $errorFile, $errorLine)
95
+	{
96
+		// call into the main exception handler above
97
+		throw new ErrorException($errorMessage, 0, $errorSeverity, $errorFile, $errorLine);
98
+	}
99
+
100
+	/**
101
+	 * @param Throwable $exception
102
+	 *
103
+	 * @return null|array
104
+	 */
105
+	public static function getExceptionData($exception)
106
+	{
107
+		if ($exception == null) {
108
+			return null;
109
+		}
110
+
111
+		$array = array(
112
+			'exception' => get_class($exception),
113
+			'message'   => $exception->getMessage(),
114
+			'stack'     => $exception->getTraceAsString(),
115
+		);
116
+
117
+		$array['previous'] = self::getExceptionData($exception->getPrevious());
118
+
119
+		return $array;
120
+	}
121
+
122
+	public static function logExceptionToDisk(
123
+		Throwable $exception,
124
+		SiteConfiguration $siteConfiguration,
125
+		bool $fromGlobalHandler = false
126
+	): array {
127
+		$errorData = self::getExceptionData($exception);
128
+		$errorData['server'] = $_SERVER;
129
+		$errorData['get'] = $_GET;
130
+		$errorData['post'] = $_POST;
131
+
132
+		$redactions = ['password', 'newpassword', 'newpasswordconfirm', 'otp'];
133
+		foreach ($redactions as $redaction) {
134
+			if (isset($errorData['post'][$redaction])) {
135
+				$errorData['post'][$redaction] = '<redacted>';
136
+			}
137
+		}
138
+
139
+		if ($fromGlobalHandler) {
140
+			$errorData['globalHandler'] = true;
141
+		}
142
+		else {
143
+			$errorData['globalHandler'] = false;
144
+		}
145
+
146
+		$state = serialize($errorData);
147
+		$errorId = sha1($state);
148
+
149
+		// Save the error for later analysis
150
+		file_put_contents($siteConfiguration->getErrorLog() . '/' . $errorId . '.log', $state);
151
+
152
+		return array($errorData, $errorId);
153
+	}
154 154
 }
Please login to merge, or discard this patch.
includes/Pages/PageBan.php 1 patch
Indentation   +659 added lines, -659 removed lines patch added patch discarded remove patch
@@ -27,665 +27,665 @@
 block discarded – undo
27 27
 
28 28
 class PageBan extends InternalPageBase
29 29
 {
30
-    /**
31
-     * Main function for this page, when no specific actions are called.
32
-     */
33
-    protected function main(): void
34
-    {
35
-        $this->assignCSRFToken();
36
-        $this->setHtmlTitle('Bans');
37
-
38
-        $database = $this->getDatabase();
39
-        $currentDomain = Domain::getCurrent($database);
40
-        $bans = Ban::getActiveBans($database, $currentDomain->getId());
41
-
42
-        $this->setupBanList($bans);
43
-
44
-        $this->assign('isFiltered', false);
45
-        $this->assign('currentUnixTime', time());
46
-        $this->setTemplate('bans/main.tpl');
47
-    }
48
-
49
-    protected function show(): void
50
-    {
51
-        $this->assignCSRFToken();
52
-        $this->setHtmlTitle('Bans');
53
-
54
-        $rawIdList = WebRequest::getString('id');
55
-        if ($rawIdList === null) {
56
-            $this->redirect('bans');
57
-
58
-            return;
59
-        }
60
-
61
-        $idList = explode(',', $rawIdList);
62
-
63
-        $database = $this->getDatabase();
64
-        $currentDomain = Domain::getCurrent($database);
65
-        $bans = Ban::getByIdList($idList, $database, $currentDomain->getId());
66
-
67
-        $this->setupBanList($bans);
68
-        $this->assign('isFiltered', true);
69
-        $this->assign('currentUnixTime', time());
70
-        $this->setTemplate('bans/main.tpl');
71
-    }
72
-
73
-    /**
74
-     * Entry point for the ban set action
75
-     * @throws SmartyException
76
-     * @throws Exception
77
-     */
78
-    protected function set(): void
79
-    {
80
-        $this->setHtmlTitle('Bans');
81
-
82
-        // dual-mode action
83
-        if (WebRequest::wasPosted()) {
84
-            try {
85
-                $this->handlePostMethodForSetBan();
86
-            }
87
-            catch (ApplicationLogicException $ex) {
88
-                SessionAlert::error($ex->getMessage());
89
-                $this->redirect("bans", "set");
90
-            }
91
-        }
92
-        else {
93
-            $this->handleGetMethodForSetBan();
94
-
95
-            $user = User::getCurrent($this->getDatabase());
96
-            $banType = WebRequest::getString('type');
97
-            $banRequest = WebRequest::getInt('request');
98
-
99
-            // if the parameters are null, skip loading a request.
100
-            if ($banType !== null && $banRequest !== null && $banRequest !== 0) {
101
-                $this->preloadFormForRequest($banRequest, $banType, $user);
102
-            }
103
-        }
104
-    }
105
-
106
-    protected function replace(): void
107
-    {
108
-        $this->setHtmlTitle('Bans');
109
-
110
-        $database = $this->getDatabase();
111
-        $domain = Domain::getCurrent($database);
112
-
113
-        // dual-mode action
114
-        if (WebRequest::wasPosted()) {
115
-            try {
116
-                $originalBanId = WebRequest::postInt('replaceBanId');
117
-                $originalBanUpdateVersion = WebRequest::postInt('replaceBanUpdateVersion');
118
-
119
-                $originalBan = Ban::getActiveId($originalBanId, $database, $domain->getId());
120
-
121
-                if ($originalBan === false) {
122
-                    throw new ApplicationLogicException("The specified ban is not currently active, or doesn't exist.");
123
-                }
124
-
125
-                // Discard original ban; we're replacing it.
126
-                $originalBan->setUpdateVersion($originalBanUpdateVersion);
127
-                $originalBan->setActive(false);
128
-                $originalBan->save();
129
-
130
-                Logger::banReplaced($database, $originalBan);
131
-
132
-                // Proceed as normal to save the new ban.
133
-                $this->handlePostMethodForSetBan();
134
-            }
135
-            catch (ApplicationLogicException $ex) {
136
-                $database->rollback();
137
-                SessionAlert::error($ex->getMessage());
138
-                $this->redirect("bans", "set");
139
-            }
140
-        }
141
-        else {
142
-            $this->handleGetMethodForSetBan();
143
-
144
-            $user = User::getCurrent($database);
145
-            $originalBanId = WebRequest::getString('id');
146
-
147
-            $originalBan = Ban::getActiveId($originalBanId, $database, $domain->getId());
148
-
149
-            if ($originalBan === false) {
150
-                throw new ApplicationLogicException("The specified ban is not currently active, or doesn't exist.");
151
-            }
152
-
153
-            if ($originalBan->getName() !== null) {
154
-                if (!$this->barrierTest('name', $user, 'BanType')) {
155
-                    SessionAlert::error("You are not allowed to set this type of ban.");
156
-                    $this->redirect("bans", "set");
157
-                    return;
158
-                }
159
-
160
-                $this->assign('banName', $originalBan->getName());
161
-            }
162
-
163
-            if ($originalBan->getEmail() !== null) {
164
-                if (!$this->barrierTest('email', $user, 'BanType')) {
165
-                    SessionAlert::error("You are not allowed to set this type of ban.");
166
-                    $this->redirect("bans", "set");
167
-                    return;
168
-                }
169
-
170
-                $this->assign('banEmail', $originalBan->getEmail());
171
-            }
172
-
173
-            if ($originalBan->getUseragent() !== null) {
174
-                if (!$this->barrierTest('useragent', $user, 'BanType')) {
175
-                    SessionAlert::error("You are not allowed to set this type of ban.");
176
-                    $this->redirect("bans", "set");
177
-                    return;
178
-                }
179
-
180
-                $this->assign('banUseragent', $originalBan->getUseragent());
181
-            }
182
-
183
-            if ($originalBan->getIp() !== null) {
184
-                if (!$this->barrierTest('ip', $user, 'BanType')) {
185
-                    SessionAlert::error("You are not allowed to set this type of ban.");
186
-                    $this->redirect("bans", "set");
187
-                    return;
188
-                }
189
-
190
-                $this->assign('banIP', $originalBan->getIp() . '/' . $originalBan->getIpMask());
191
-            }
192
-
193
-            $banIsGlobal = $originalBan->getDomain() === null;
194
-            if ($banIsGlobal) {
195
-                if (!$this->barrierTest('global', $user, 'BanType')) {
196
-                    SessionAlert::error("You are not allowed to set this type of ban.");
197
-                    $this->redirect("bans", "set");
198
-                    return;
199
-                }
200
-            }
201
-
202
-            if (!$this->barrierTest($originalBan->getVisibility(), $user, 'BanVisibility')) {
203
-                SessionAlert::error("You are not allowed to set this type of ban.");
204
-                $this->redirect("bans", "set");
205
-                return;
206
-            }
207
-
208
-            $this->assign('banGlobal', $banIsGlobal);
209
-            $this->assign('banVisibility', $originalBan->getVisibility());
210
-
211
-            if ($originalBan->getDuration() !== null) {
212
-                $this->assign('banDuration', date('c', $originalBan->getDuration()));
213
-            }
214
-
215
-            $this->assign('banReason', $originalBan->getReason());
216
-            $this->assign('banAction', $originalBan->getAction());
217
-            $this->assign('banQueue', $originalBan->getTargetQueue());
218
-
219
-            $this->assign('replaceBanId', $originalBan->getId());
220
-            $this->assign('replaceBanUpdateVersion', $originalBan->getUpdateVersion());
221
-        }
222
-    }
223
-
224
-    /**
225
-     * Entry point for the ban remove action
226
-     *
227
-     * @throws AccessDeniedException
228
-     * @throws ApplicationLogicException
229
-     * @throws SmartyException
230
-     */
231
-    protected function remove(): void
232
-    {
233
-        $this->setHtmlTitle('Bans');
234
-
235
-        $ban = $this->getBanForUnban();
236
-
237
-        $banHelper = new BanHelper($this->getDatabase(), $this->getXffTrustProvider(), $this->getSecurityManager());
238
-        if (!$banHelper->canUnban($ban)) {
239
-            // triggered when a user tries to unban a ban they can't see the entirety of.
240
-            // there's no UI way to get to this, so a raw exception is fine.
241
-            throw new AccessDeniedException($this->getSecurityManager(), $this->getDomainAccessManager());
242
-        }
243
-
244
-        // dual mode
245
-        if (WebRequest::wasPosted()) {
246
-            $this->validateCSRFToken();
247
-            $unbanReason = WebRequest::postString('unbanreason');
248
-
249
-            if ($unbanReason === null || trim($unbanReason) === "") {
250
-                SessionAlert::error('No unban reason specified');
251
-                $this->redirect("bans", "remove", array('id' => $ban->getId()));
252
-            }
253
-
254
-            // set optimistic locking from delete form page load
255
-            $updateVersion = WebRequest::postInt('updateversion');
256
-            $ban->setUpdateVersion($updateVersion);
257
-
258
-            $database = $this->getDatabase();
259
-            $ban->setActive(false);
260
-            $ban->save();
261
-
262
-            Logger::unbanned($database, $ban, $unbanReason);
263
-
264
-            SessionAlert::quick('Disabled ban.');
265
-            $this->getNotificationHelper()->unbanned($ban, $unbanReason);
266
-
267
-            $this->redirect('bans');
268
-        }
269
-        else {
270
-            $this->assignCSRFToken();
271
-            $this->assign('ban', $ban);
272
-            $this->setTemplate('bans/unban.tpl');
273
-        }
274
-    }
275
-
276
-    /**
277
-     * Retrieves the requested ban duration from the WebRequest
278
-     *
279
-     * @throws ApplicationLogicException
280
-     */
281
-    private function getBanDuration(): ?int
282
-    {
283
-        $duration = WebRequest::postString('duration');
284
-        if ($duration === "other") {
285
-            $duration = strtotime(WebRequest::postString('otherduration'));
286
-
287
-            if (!$duration) {
288
-                throw new ApplicationLogicException('Invalid ban time');
289
-            }
290
-            elseif (time() > $duration) {
291
-                throw new ApplicationLogicException('Ban time has already expired!');
292
-            }
293
-
294
-            return $duration;
295
-        }
296
-        elseif ($duration === "-1") {
297
-            return null;
298
-        }
299
-        else {
300
-            return WebRequest::postInt('duration') + time();
301
-        }
302
-    }
303
-
304
-    /**
305
-     * Handles the POST method on the set action
306
-     *
307
-     * @throws ApplicationLogicException
308
-     * @throws Exception
309
-     */
310
-    private function handlePostMethodForSetBan()
311
-    {
312
-        $this->validateCSRFToken();
313
-        $database = $this->getDatabase();
314
-        $user = User::getCurrent($database);
315
-        $currentDomain = Domain::getCurrent($database);
316
-
317
-        // Checks whether there is a reason entered for ban.
318
-        $reason = WebRequest::postString('banreason');
319
-        if ($reason === null || trim($reason) === "") {
320
-            throw new ApplicationLogicException('You must specify a ban reason');
321
-        }
322
-
323
-        // ban targets
324
-        list($targetName, $targetIp, $targetEmail, $targetUseragent) = $this->getRawBanTargets($user);
325
-
326
-        $visibility = $this->getBanVisibility();
327
-
328
-        // Validate ban duration
329
-        $duration = $this->getBanDuration();
330
-
331
-        $action = WebRequest::postString('banAction') ?? Ban::ACTION_NONE;
332
-
333
-        $global = WebRequest::postBoolean('banGlobal');
334
-        if (!$this->barrierTest('global', $user, 'BanType')) {
335
-            $global = false;
336
-        }
337
-
338
-        if ($action === Ban::ACTION_DEFER && $global) {
339
-            throw new ApplicationLogicException("Cannot set a global ban in defer-to-queue mode.");
340
-        }
341
-
342
-        // handle CIDR ranges
343
-        $targetMask = null;
344
-        if ($targetIp !== null) {
345
-            list($targetIp, $targetMask) = $this->splitCidrRange($targetIp);
346
-            $this->validateIpBan($targetIp, $targetMask, $user, $action);
347
-        }
348
-
349
-        $banHelper = new BanHelper($this->getDatabase(), $this->getXffTrustProvider(), $this->getSecurityManager());
350
-
351
-        $bansByTarget = $banHelper->getBansByTarget(
352
-            $targetName,
353
-            $targetEmail,
354
-            $targetIp,
355
-            $targetMask,
356
-            $targetUseragent,
357
-            $currentDomain->getId());
358
-
359
-        if (count($bansByTarget) > 0) {
360
-            throw new ApplicationLogicException('This target is already banned!');
361
-        }
362
-
363
-        $ban = new Ban();
364
-        $ban->setDatabase($database);
365
-        $ban->setActive(true);
366
-
367
-        $ban->setName($targetName);
368
-        $ban->setIp($targetIp, $targetMask);
369
-        $ban->setEmail($targetEmail);
370
-        $ban->setUseragent($targetUseragent);
371
-
372
-        $ban->setUser($user->getId());
373
-        $ban->setReason($reason);
374
-        $ban->setDuration($duration);
375
-        $ban->setVisibility($visibility);
376
-
377
-        $ban->setDomain($global ? null : $currentDomain->getId());
378
-
379
-        $ban->setAction($action);
380
-        if ($ban->getAction() === Ban::ACTION_DEFER) {
381
-            //FIXME: domains
382
-            $queue = RequestQueue::getByApiName($database, WebRequest::postString('banActionTarget'), 1);
383
-            if ($queue === false) {
384
-                throw new ApplicationLogicException("Unknown target queue");
385
-            }
386
-
387
-            if (!$queue->isEnabled()) {
388
-                throw new ApplicationLogicException("Target queue is not enabled");
389
-            }
390
-
391
-            $ban->setTargetQueue($queue->getId());
392
-        }
393
-
394
-        $ban->save();
395
-
396
-        Logger::banned($database, $ban, $reason);
397
-
398
-        $this->getNotificationHelper()->banned($ban);
399
-        SessionAlert::quick('Ban has been set.');
400
-
401
-        $this->redirect('bans');
402
-    }
403
-
404
-    /**
405
-     * Handles the GET method on the set action
406
-     * @throws Exception
407
-     */
408
-    private function handleGetMethodForSetBan()
409
-    {
410
-        $this->setTemplate('bans/banform.tpl');
411
-        $this->assignCSRFToken();
412
-
413
-        $this->assign('maxIpRange', $this->getSiteConfiguration()->getBanMaxIpRange());
414
-        $this->assign('maxIpBlockRange', $this->getSiteConfiguration()->getBanMaxIpBlockRange());
415
-
416
-        $this->assign('banVisibility', 'user');
417
-        $this->assign('banGlobal', false);
418
-        $this->assign('banQueue', false);
419
-        $this->assign('banAction', Ban::ACTION_BLOCK);
420
-        $this->assign('banDuration', '');
421
-        $this->assign('banReason', '');
422
-
423
-        $this->assign('banEmail', '');
424
-        $this->assign('banIP', '');
425
-        $this->assign('banName', '');
426
-        $this->assign('banUseragent', '');
427
-
428
-        $this->assign('replaceBanId', null);
429
-
430
-
431
-
432
-        $database = $this->getDatabase();
433
-
434
-        $user = User::getCurrent($database);
435
-        $this->setupSecurity($user);
436
-
437
-        $queues = RequestQueue::getEnabledQueues($database);
438
-
439
-        $this->assign('requestQueues', $queues);
440
-    }
441
-
442
-    /**
443
-     * Finds the Ban object referenced in the WebRequest if it is valid
444
-     *
445
-     * @return Ban
446
-     * @throws ApplicationLogicException
447
-     */
448
-    private function getBanForUnban(): Ban
449
-    {
450
-        $banId = WebRequest::getInt('id');
451
-        if ($banId === null || $banId === 0) {
452
-            throw new ApplicationLogicException("The ban ID appears to be missing. This is probably a bug.");
453
-        }
454
-
455
-        $database = $this->getDatabase();
456
-        $this->setupSecurity(User::getCurrent($database));
457
-        $currentDomain = Domain::getCurrent($database);
458
-        $ban = Ban::getActiveId($banId, $database, $currentDomain->getId());
459
-
460
-        if ($ban === false) {
461
-            throw new ApplicationLogicException("The specified ban is not currently active, or doesn't exist.");
462
-        }
463
-
464
-        return $ban;
465
-    }
466
-
467
-    /**
468
-     * Sets up Smarty variables for access control
469
-     */
470
-    private function setupSecurity(User $user): void
471
-    {
472
-        $this->assign('canSeeIpBan', $this->barrierTest('ip', $user, 'BanType'));
473
-        $this->assign('canSeeNameBan', $this->barrierTest('name', $user, 'BanType'));
474
-        $this->assign('canSeeEmailBan', $this->barrierTest('email', $user, 'BanType'));
475
-        $this->assign('canSeeUseragentBan', $this->barrierTest('useragent', $user, 'BanType'));
476
-
477
-        $this->assign('canGlobalBan', $this->barrierTest('global', $user, 'BanType'));
478
-
479
-        $this->assign('canSeeUserVisibility', $this->barrierTest('user', $user, 'BanVisibility'));
480
-        $this->assign('canSeeAdminVisibility', $this->barrierTest('admin', $user, 'BanVisibility'));
481
-        $this->assign('canSeeCheckuserVisibility', $this->barrierTest('checkuser', $user, 'BanVisibility'));
482
-    }
483
-
484
-    /**
485
-     * Validates that the provided IP is acceptable for a ban of this type
486
-     *
487
-     * @param string $targetIp   IP address
488
-     * @param int    $targetMask CIDR prefix length
489
-     * @param User   $user       User performing the ban
490
-     * @param string $action     Ban action to take
491
-     *
492
-     * @throws ApplicationLogicException
493
-     */
494
-    private function validateIpBan(string $targetIp, int $targetMask, User $user, string $action): void
495
-    {
496
-        // validate this is an IP
497
-        if (!filter_var($targetIp, FILTER_VALIDATE_IP)) {
498
-            throw new ApplicationLogicException("Not a valid IP address");
499
-        }
500
-
501
-        $canLargeIpBan = $this->barrierTest('ip-largerange', $user, 'BanType');
502
-        $maxIpBlockRange = $this->getSiteConfiguration()->getBanMaxIpBlockRange();
503
-        $maxIpRange = $this->getSiteConfiguration()->getBanMaxIpRange();
504
-
505
-        // validate CIDR ranges
506
-        if (filter_var($targetIp, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
507
-            if ($targetMask < 0 || $targetMask > 128) {
508
-                throw new ApplicationLogicException("CIDR mask out of range for IPv6");
509
-            }
510
-
511
-            // prevent setting the ban if:
512
-            //  * the user isn't allowed to set large bans, AND
513
-            //  * the ban is a drop or a block (preventing human review of the request), AND
514
-            //  * the mask is too wide-reaching
515
-            if (!$canLargeIpBan && ($action == Ban::ACTION_BLOCK || $action == Ban::ACTION_DROP) && $targetMask < $maxIpBlockRange[6]) {
516
-                throw new ApplicationLogicException("The requested IP range for this ban is too wide for the block/drop action.");
517
-            }
518
-
519
-            if (!$canLargeIpBan && $targetMask < $maxIpRange[6]) {
520
-                throw new ApplicationLogicException("The requested IP range for this ban is too wide.");
521
-            }
522
-        }
523
-
524
-        if (filter_var($targetIp, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
525
-            if ($targetMask < 0 || $targetMask > 32) {
526
-                throw new ApplicationLogicException("CIDR mask out of range for IPv4");
527
-            }
528
-
529
-            if (!$canLargeIpBan && ($action == Ban::ACTION_BLOCK || $action == Ban::ACTION_DROP) && $targetMask < $maxIpBlockRange[4]) {
530
-                throw new ApplicationLogicException("The IP range for this ban is too wide for the block/drop action.");
531
-            }
532
-
533
-            if (!$canLargeIpBan && $targetMask < $maxIpRange[4]) {
534
-                throw new ApplicationLogicException("The requested IP range for this ban is too wide.");
535
-            }
536
-        }
537
-
538
-        $squidIpList = $this->getSiteConfiguration()->getSquidList();
539
-        if (in_array($targetIp, $squidIpList)) {
540
-            throw new ApplicationLogicException("This IP address is on the protected list of proxies, and cannot be banned.");
541
-        }
542
-    }
543
-
544
-    /**
545
-     * Configures a ban list template for display
546
-     *
547
-     * @param Ban[] $bans
548
-     */
549
-    private function setupBanList(array $bans): void
550
-    {
551
-        $userIds = array_map(fn(Ban $entry) => $entry->getUser(), $bans);
552
-        $userList = UserSearchHelper::get($this->getDatabase())->inIds($userIds)->fetchMap('username');
553
-
554
-        $domainIds = array_filter(array_unique(array_map(fn(Ban $entry) => $entry->getDomain(), $bans)));
555
-        $domains = [];
556
-        foreach ($domainIds as $d) {
557
-            if ($d === null) {
558
-                continue;
559
-            }
560
-            $domains[$d] = Domain::getById($d, $this->getDatabase());
561
-        }
562
-
563
-        $this->assign('domains', $domains);
564
-
565
-        $user = User::getCurrent($this->getDatabase());
566
-        $this->assign('canSet', $this->barrierTest('set', $user));
567
-        $this->assign('canRemove', $this->barrierTest('remove', $user));
568
-
569
-        $this->setupSecurity($user);
570
-
571
-        $this->assign('usernames', $userList);
572
-        $this->assign('activebans', $bans);
573
-
574
-        $banHelper = new BanHelper($this->getDatabase(), $this->getXffTrustProvider(), $this->getSecurityManager());
575
-        $this->assign('banHelper', $banHelper);
576
-    }
577
-
578
-    /**
579
-     * Converts a plain IP or CIDR mask into an IP and a CIDR suffix
580
-     *
581
-     * @param string $targetIp IP or CIDR range
582
-     *
583
-     * @return array
584
-     */
585
-    private function splitCidrRange(string $targetIp): array
586
-    {
587
-        if (strpos($targetIp, '/') !== false) {
588
-            $ipParts = explode('/', $targetIp, 2);
589
-            $targetIp = $ipParts[0];
590
-            $targetMask = (int)$ipParts[1];
591
-        }
592
-        else {
593
-            // Default the CIDR range based on the IP type
594
-            $targetMask = filter_var($targetIp, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) ? 128 : 32;
595
-        }
596
-
597
-        return array($targetIp, $targetMask);
30
+	/**
31
+	 * Main function for this page, when no specific actions are called.
32
+	 */
33
+	protected function main(): void
34
+	{
35
+		$this->assignCSRFToken();
36
+		$this->setHtmlTitle('Bans');
37
+
38
+		$database = $this->getDatabase();
39
+		$currentDomain = Domain::getCurrent($database);
40
+		$bans = Ban::getActiveBans($database, $currentDomain->getId());
41
+
42
+		$this->setupBanList($bans);
43
+
44
+		$this->assign('isFiltered', false);
45
+		$this->assign('currentUnixTime', time());
46
+		$this->setTemplate('bans/main.tpl');
47
+	}
48
+
49
+	protected function show(): void
50
+	{
51
+		$this->assignCSRFToken();
52
+		$this->setHtmlTitle('Bans');
53
+
54
+		$rawIdList = WebRequest::getString('id');
55
+		if ($rawIdList === null) {
56
+			$this->redirect('bans');
57
+
58
+			return;
59
+		}
60
+
61
+		$idList = explode(',', $rawIdList);
62
+
63
+		$database = $this->getDatabase();
64
+		$currentDomain = Domain::getCurrent($database);
65
+		$bans = Ban::getByIdList($idList, $database, $currentDomain->getId());
66
+
67
+		$this->setupBanList($bans);
68
+		$this->assign('isFiltered', true);
69
+		$this->assign('currentUnixTime', time());
70
+		$this->setTemplate('bans/main.tpl');
71
+	}
72
+
73
+	/**
74
+	 * Entry point for the ban set action
75
+	 * @throws SmartyException
76
+	 * @throws Exception
77
+	 */
78
+	protected function set(): void
79
+	{
80
+		$this->setHtmlTitle('Bans');
81
+
82
+		// dual-mode action
83
+		if (WebRequest::wasPosted()) {
84
+			try {
85
+				$this->handlePostMethodForSetBan();
86
+			}
87
+			catch (ApplicationLogicException $ex) {
88
+				SessionAlert::error($ex->getMessage());
89
+				$this->redirect("bans", "set");
90
+			}
91
+		}
92
+		else {
93
+			$this->handleGetMethodForSetBan();
94
+
95
+			$user = User::getCurrent($this->getDatabase());
96
+			$banType = WebRequest::getString('type');
97
+			$banRequest = WebRequest::getInt('request');
98
+
99
+			// if the parameters are null, skip loading a request.
100
+			if ($banType !== null && $banRequest !== null && $banRequest !== 0) {
101
+				$this->preloadFormForRequest($banRequest, $banType, $user);
102
+			}
103
+		}
104
+	}
105
+
106
+	protected function replace(): void
107
+	{
108
+		$this->setHtmlTitle('Bans');
109
+
110
+		$database = $this->getDatabase();
111
+		$domain = Domain::getCurrent($database);
112
+
113
+		// dual-mode action
114
+		if (WebRequest::wasPosted()) {
115
+			try {
116
+				$originalBanId = WebRequest::postInt('replaceBanId');
117
+				$originalBanUpdateVersion = WebRequest::postInt('replaceBanUpdateVersion');
118
+
119
+				$originalBan = Ban::getActiveId($originalBanId, $database, $domain->getId());
120
+
121
+				if ($originalBan === false) {
122
+					throw new ApplicationLogicException("The specified ban is not currently active, or doesn't exist.");
123
+				}
124
+
125
+				// Discard original ban; we're replacing it.
126
+				$originalBan->setUpdateVersion($originalBanUpdateVersion);
127
+				$originalBan->setActive(false);
128
+				$originalBan->save();
129
+
130
+				Logger::banReplaced($database, $originalBan);
131
+
132
+				// Proceed as normal to save the new ban.
133
+				$this->handlePostMethodForSetBan();
134
+			}
135
+			catch (ApplicationLogicException $ex) {
136
+				$database->rollback();
137
+				SessionAlert::error($ex->getMessage());
138
+				$this->redirect("bans", "set");
139
+			}
140
+		}
141
+		else {
142
+			$this->handleGetMethodForSetBan();
143
+
144
+			$user = User::getCurrent($database);
145
+			$originalBanId = WebRequest::getString('id');
146
+
147
+			$originalBan = Ban::getActiveId($originalBanId, $database, $domain->getId());
148
+
149
+			if ($originalBan === false) {
150
+				throw new ApplicationLogicException("The specified ban is not currently active, or doesn't exist.");
151
+			}
152
+
153
+			if ($originalBan->getName() !== null) {
154
+				if (!$this->barrierTest('name', $user, 'BanType')) {
155
+					SessionAlert::error("You are not allowed to set this type of ban.");
156
+					$this->redirect("bans", "set");
157
+					return;
158
+				}
159
+
160
+				$this->assign('banName', $originalBan->getName());
161
+			}
162
+
163
+			if ($originalBan->getEmail() !== null) {
164
+				if (!$this->barrierTest('email', $user, 'BanType')) {
165
+					SessionAlert::error("You are not allowed to set this type of ban.");
166
+					$this->redirect("bans", "set");
167
+					return;
168
+				}
169
+
170
+				$this->assign('banEmail', $originalBan->getEmail());
171
+			}
172
+
173
+			if ($originalBan->getUseragent() !== null) {
174
+				if (!$this->barrierTest('useragent', $user, 'BanType')) {
175
+					SessionAlert::error("You are not allowed to set this type of ban.");
176
+					$this->redirect("bans", "set");
177
+					return;
178
+				}
179
+
180
+				$this->assign('banUseragent', $originalBan->getUseragent());
181
+			}
182
+
183
+			if ($originalBan->getIp() !== null) {
184
+				if (!$this->barrierTest('ip', $user, 'BanType')) {
185
+					SessionAlert::error("You are not allowed to set this type of ban.");
186
+					$this->redirect("bans", "set");
187
+					return;
188
+				}
189
+
190
+				$this->assign('banIP', $originalBan->getIp() . '/' . $originalBan->getIpMask());
191
+			}
192
+
193
+			$banIsGlobal = $originalBan->getDomain() === null;
194
+			if ($banIsGlobal) {
195
+				if (!$this->barrierTest('global', $user, 'BanType')) {
196
+					SessionAlert::error("You are not allowed to set this type of ban.");
197
+					$this->redirect("bans", "set");
198
+					return;
199
+				}
200
+			}
201
+
202
+			if (!$this->barrierTest($originalBan->getVisibility(), $user, 'BanVisibility')) {
203
+				SessionAlert::error("You are not allowed to set this type of ban.");
204
+				$this->redirect("bans", "set");
205
+				return;
206
+			}
207
+
208
+			$this->assign('banGlobal', $banIsGlobal);
209
+			$this->assign('banVisibility', $originalBan->getVisibility());
210
+
211
+			if ($originalBan->getDuration() !== null) {
212
+				$this->assign('banDuration', date('c', $originalBan->getDuration()));
213
+			}
214
+
215
+			$this->assign('banReason', $originalBan->getReason());
216
+			$this->assign('banAction', $originalBan->getAction());
217
+			$this->assign('banQueue', $originalBan->getTargetQueue());
218
+
219
+			$this->assign('replaceBanId', $originalBan->getId());
220
+			$this->assign('replaceBanUpdateVersion', $originalBan->getUpdateVersion());
221
+		}
222
+	}
223
+
224
+	/**
225
+	 * Entry point for the ban remove action
226
+	 *
227
+	 * @throws AccessDeniedException
228
+	 * @throws ApplicationLogicException
229
+	 * @throws SmartyException
230
+	 */
231
+	protected function remove(): void
232
+	{
233
+		$this->setHtmlTitle('Bans');
234
+
235
+		$ban = $this->getBanForUnban();
236
+
237
+		$banHelper = new BanHelper($this->getDatabase(), $this->getXffTrustProvider(), $this->getSecurityManager());
238
+		if (!$banHelper->canUnban($ban)) {
239
+			// triggered when a user tries to unban a ban they can't see the entirety of.
240
+			// there's no UI way to get to this, so a raw exception is fine.
241
+			throw new AccessDeniedException($this->getSecurityManager(), $this->getDomainAccessManager());
242
+		}
243
+
244
+		// dual mode
245
+		if (WebRequest::wasPosted()) {
246
+			$this->validateCSRFToken();
247
+			$unbanReason = WebRequest::postString('unbanreason');
248
+
249
+			if ($unbanReason === null || trim($unbanReason) === "") {
250
+				SessionAlert::error('No unban reason specified');
251
+				$this->redirect("bans", "remove", array('id' => $ban->getId()));
252
+			}
253
+
254
+			// set optimistic locking from delete form page load
255
+			$updateVersion = WebRequest::postInt('updateversion');
256
+			$ban->setUpdateVersion($updateVersion);
257
+
258
+			$database = $this->getDatabase();
259
+			$ban->setActive(false);
260
+			$ban->save();
261
+
262
+			Logger::unbanned($database, $ban, $unbanReason);
263
+
264
+			SessionAlert::quick('Disabled ban.');
265
+			$this->getNotificationHelper()->unbanned($ban, $unbanReason);
266
+
267
+			$this->redirect('bans');
268
+		}
269
+		else {
270
+			$this->assignCSRFToken();
271
+			$this->assign('ban', $ban);
272
+			$this->setTemplate('bans/unban.tpl');
273
+		}
274
+	}
275
+
276
+	/**
277
+	 * Retrieves the requested ban duration from the WebRequest
278
+	 *
279
+	 * @throws ApplicationLogicException
280
+	 */
281
+	private function getBanDuration(): ?int
282
+	{
283
+		$duration = WebRequest::postString('duration');
284
+		if ($duration === "other") {
285
+			$duration = strtotime(WebRequest::postString('otherduration'));
286
+
287
+			if (!$duration) {
288
+				throw new ApplicationLogicException('Invalid ban time');
289
+			}
290
+			elseif (time() > $duration) {
291
+				throw new ApplicationLogicException('Ban time has already expired!');
292
+			}
293
+
294
+			return $duration;
295
+		}
296
+		elseif ($duration === "-1") {
297
+			return null;
298
+		}
299
+		else {
300
+			return WebRequest::postInt('duration') + time();
301
+		}
302
+	}
303
+
304
+	/**
305
+	 * Handles the POST method on the set action
306
+	 *
307
+	 * @throws ApplicationLogicException
308
+	 * @throws Exception
309
+	 */
310
+	private function handlePostMethodForSetBan()
311
+	{
312
+		$this->validateCSRFToken();
313
+		$database = $this->getDatabase();
314
+		$user = User::getCurrent($database);
315
+		$currentDomain = Domain::getCurrent($database);
316
+
317
+		// Checks whether there is a reason entered for ban.
318
+		$reason = WebRequest::postString('banreason');
319
+		if ($reason === null || trim($reason) === "") {
320
+			throw new ApplicationLogicException('You must specify a ban reason');
321
+		}
322
+
323
+		// ban targets
324
+		list($targetName, $targetIp, $targetEmail, $targetUseragent) = $this->getRawBanTargets($user);
325
+
326
+		$visibility = $this->getBanVisibility();
327
+
328
+		// Validate ban duration
329
+		$duration = $this->getBanDuration();
330
+
331
+		$action = WebRequest::postString('banAction') ?? Ban::ACTION_NONE;
332
+
333
+		$global = WebRequest::postBoolean('banGlobal');
334
+		if (!$this->barrierTest('global', $user, 'BanType')) {
335
+			$global = false;
336
+		}
337
+
338
+		if ($action === Ban::ACTION_DEFER && $global) {
339
+			throw new ApplicationLogicException("Cannot set a global ban in defer-to-queue mode.");
340
+		}
341
+
342
+		// handle CIDR ranges
343
+		$targetMask = null;
344
+		if ($targetIp !== null) {
345
+			list($targetIp, $targetMask) = $this->splitCidrRange($targetIp);
346
+			$this->validateIpBan($targetIp, $targetMask, $user, $action);
347
+		}
348
+
349
+		$banHelper = new BanHelper($this->getDatabase(), $this->getXffTrustProvider(), $this->getSecurityManager());
350
+
351
+		$bansByTarget = $banHelper->getBansByTarget(
352
+			$targetName,
353
+			$targetEmail,
354
+			$targetIp,
355
+			$targetMask,
356
+			$targetUseragent,
357
+			$currentDomain->getId());
358
+
359
+		if (count($bansByTarget) > 0) {
360
+			throw new ApplicationLogicException('This target is already banned!');
361
+		}
362
+
363
+		$ban = new Ban();
364
+		$ban->setDatabase($database);
365
+		$ban->setActive(true);
366
+
367
+		$ban->setName($targetName);
368
+		$ban->setIp($targetIp, $targetMask);
369
+		$ban->setEmail($targetEmail);
370
+		$ban->setUseragent($targetUseragent);
371
+
372
+		$ban->setUser($user->getId());
373
+		$ban->setReason($reason);
374
+		$ban->setDuration($duration);
375
+		$ban->setVisibility($visibility);
376
+
377
+		$ban->setDomain($global ? null : $currentDomain->getId());
378
+
379
+		$ban->setAction($action);
380
+		if ($ban->getAction() === Ban::ACTION_DEFER) {
381
+			//FIXME: domains
382
+			$queue = RequestQueue::getByApiName($database, WebRequest::postString('banActionTarget'), 1);
383
+			if ($queue === false) {
384
+				throw new ApplicationLogicException("Unknown target queue");
385
+			}
386
+
387
+			if (!$queue->isEnabled()) {
388
+				throw new ApplicationLogicException("Target queue is not enabled");
389
+			}
390
+
391
+			$ban->setTargetQueue($queue->getId());
392
+		}
393
+
394
+		$ban->save();
395
+
396
+		Logger::banned($database, $ban, $reason);
397
+
398
+		$this->getNotificationHelper()->banned($ban);
399
+		SessionAlert::quick('Ban has been set.');
400
+
401
+		$this->redirect('bans');
402
+	}
403
+
404
+	/**
405
+	 * Handles the GET method on the set action
406
+	 * @throws Exception
407
+	 */
408
+	private function handleGetMethodForSetBan()
409
+	{
410
+		$this->setTemplate('bans/banform.tpl');
411
+		$this->assignCSRFToken();
412
+
413
+		$this->assign('maxIpRange', $this->getSiteConfiguration()->getBanMaxIpRange());
414
+		$this->assign('maxIpBlockRange', $this->getSiteConfiguration()->getBanMaxIpBlockRange());
415
+
416
+		$this->assign('banVisibility', 'user');
417
+		$this->assign('banGlobal', false);
418
+		$this->assign('banQueue', false);
419
+		$this->assign('banAction', Ban::ACTION_BLOCK);
420
+		$this->assign('banDuration', '');
421
+		$this->assign('banReason', '');
422
+
423
+		$this->assign('banEmail', '');
424
+		$this->assign('banIP', '');
425
+		$this->assign('banName', '');
426
+		$this->assign('banUseragent', '');
427
+
428
+		$this->assign('replaceBanId', null);
429
+
430
+
431
+
432
+		$database = $this->getDatabase();
433
+
434
+		$user = User::getCurrent($database);
435
+		$this->setupSecurity($user);
436
+
437
+		$queues = RequestQueue::getEnabledQueues($database);
438
+
439
+		$this->assign('requestQueues', $queues);
440
+	}
441
+
442
+	/**
443
+	 * Finds the Ban object referenced in the WebRequest if it is valid
444
+	 *
445
+	 * @return Ban
446
+	 * @throws ApplicationLogicException
447
+	 */
448
+	private function getBanForUnban(): Ban
449
+	{
450
+		$banId = WebRequest::getInt('id');
451
+		if ($banId === null || $banId === 0) {
452
+			throw new ApplicationLogicException("The ban ID appears to be missing. This is probably a bug.");
453
+		}
454
+
455
+		$database = $this->getDatabase();
456
+		$this->setupSecurity(User::getCurrent($database));
457
+		$currentDomain = Domain::getCurrent($database);
458
+		$ban = Ban::getActiveId($banId, $database, $currentDomain->getId());
459
+
460
+		if ($ban === false) {
461
+			throw new ApplicationLogicException("The specified ban is not currently active, or doesn't exist.");
462
+		}
463
+
464
+		return $ban;
465
+	}
466
+
467
+	/**
468
+	 * Sets up Smarty variables for access control
469
+	 */
470
+	private function setupSecurity(User $user): void
471
+	{
472
+		$this->assign('canSeeIpBan', $this->barrierTest('ip', $user, 'BanType'));
473
+		$this->assign('canSeeNameBan', $this->barrierTest('name', $user, 'BanType'));
474
+		$this->assign('canSeeEmailBan', $this->barrierTest('email', $user, 'BanType'));
475
+		$this->assign('canSeeUseragentBan', $this->barrierTest('useragent', $user, 'BanType'));
476
+
477
+		$this->assign('canGlobalBan', $this->barrierTest('global', $user, 'BanType'));
478
+
479
+		$this->assign('canSeeUserVisibility', $this->barrierTest('user', $user, 'BanVisibility'));
480
+		$this->assign('canSeeAdminVisibility', $this->barrierTest('admin', $user, 'BanVisibility'));
481
+		$this->assign('canSeeCheckuserVisibility', $this->barrierTest('checkuser', $user, 'BanVisibility'));
482
+	}
483
+
484
+	/**
485
+	 * Validates that the provided IP is acceptable for a ban of this type
486
+	 *
487
+	 * @param string $targetIp   IP address
488
+	 * @param int    $targetMask CIDR prefix length
489
+	 * @param User   $user       User performing the ban
490
+	 * @param string $action     Ban action to take
491
+	 *
492
+	 * @throws ApplicationLogicException
493
+	 */
494
+	private function validateIpBan(string $targetIp, int $targetMask, User $user, string $action): void
495
+	{
496
+		// validate this is an IP
497
+		if (!filter_var($targetIp, FILTER_VALIDATE_IP)) {
498
+			throw new ApplicationLogicException("Not a valid IP address");
499
+		}
500
+
501
+		$canLargeIpBan = $this->barrierTest('ip-largerange', $user, 'BanType');
502
+		$maxIpBlockRange = $this->getSiteConfiguration()->getBanMaxIpBlockRange();
503
+		$maxIpRange = $this->getSiteConfiguration()->getBanMaxIpRange();
504
+
505
+		// validate CIDR ranges
506
+		if (filter_var($targetIp, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
507
+			if ($targetMask < 0 || $targetMask > 128) {
508
+				throw new ApplicationLogicException("CIDR mask out of range for IPv6");
509
+			}
510
+
511
+			// prevent setting the ban if:
512
+			//  * the user isn't allowed to set large bans, AND
513
+			//  * the ban is a drop or a block (preventing human review of the request), AND
514
+			//  * the mask is too wide-reaching
515
+			if (!$canLargeIpBan && ($action == Ban::ACTION_BLOCK || $action == Ban::ACTION_DROP) && $targetMask < $maxIpBlockRange[6]) {
516
+				throw new ApplicationLogicException("The requested IP range for this ban is too wide for the block/drop action.");
517
+			}
518
+
519
+			if (!$canLargeIpBan && $targetMask < $maxIpRange[6]) {
520
+				throw new ApplicationLogicException("The requested IP range for this ban is too wide.");
521
+			}
522
+		}
523
+
524
+		if (filter_var($targetIp, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
525
+			if ($targetMask < 0 || $targetMask > 32) {
526
+				throw new ApplicationLogicException("CIDR mask out of range for IPv4");
527
+			}
528
+
529
+			if (!$canLargeIpBan && ($action == Ban::ACTION_BLOCK || $action == Ban::ACTION_DROP) && $targetMask < $maxIpBlockRange[4]) {
530
+				throw new ApplicationLogicException("The IP range for this ban is too wide for the block/drop action.");
531
+			}
532
+
533
+			if (!$canLargeIpBan && $targetMask < $maxIpRange[4]) {
534
+				throw new ApplicationLogicException("The requested IP range for this ban is too wide.");
535
+			}
536
+		}
537
+
538
+		$squidIpList = $this->getSiteConfiguration()->getSquidList();
539
+		if (in_array($targetIp, $squidIpList)) {
540
+			throw new ApplicationLogicException("This IP address is on the protected list of proxies, and cannot be banned.");
541
+		}
542
+	}
543
+
544
+	/**
545
+	 * Configures a ban list template for display
546
+	 *
547
+	 * @param Ban[] $bans
548
+	 */
549
+	private function setupBanList(array $bans): void
550
+	{
551
+		$userIds = array_map(fn(Ban $entry) => $entry->getUser(), $bans);
552
+		$userList = UserSearchHelper::get($this->getDatabase())->inIds($userIds)->fetchMap('username');
553
+
554
+		$domainIds = array_filter(array_unique(array_map(fn(Ban $entry) => $entry->getDomain(), $bans)));
555
+		$domains = [];
556
+		foreach ($domainIds as $d) {
557
+			if ($d === null) {
558
+				continue;
559
+			}
560
+			$domains[$d] = Domain::getById($d, $this->getDatabase());
561
+		}
562
+
563
+		$this->assign('domains', $domains);
564
+
565
+		$user = User::getCurrent($this->getDatabase());
566
+		$this->assign('canSet', $this->barrierTest('set', $user));
567
+		$this->assign('canRemove', $this->barrierTest('remove', $user));
568
+
569
+		$this->setupSecurity($user);
570
+
571
+		$this->assign('usernames', $userList);
572
+		$this->assign('activebans', $bans);
573
+
574
+		$banHelper = new BanHelper($this->getDatabase(), $this->getXffTrustProvider(), $this->getSecurityManager());
575
+		$this->assign('banHelper', $banHelper);
576
+	}
577
+
578
+	/**
579
+	 * Converts a plain IP or CIDR mask into an IP and a CIDR suffix
580
+	 *
581
+	 * @param string $targetIp IP or CIDR range
582
+	 *
583
+	 * @return array
584
+	 */
585
+	private function splitCidrRange(string $targetIp): array
586
+	{
587
+		if (strpos($targetIp, '/') !== false) {
588
+			$ipParts = explode('/', $targetIp, 2);
589
+			$targetIp = $ipParts[0];
590
+			$targetMask = (int)$ipParts[1];
591
+		}
592
+		else {
593
+			// Default the CIDR range based on the IP type
594
+			$targetMask = filter_var($targetIp, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) ? 128 : 32;
595
+		}
596
+
597
+		return array($targetIp, $targetMask);
598 598
 }
599 599
 
600
-    /**
601
-     * Returns the validated ban visibility from WebRequest
602
-     *
603
-     * @throws ApplicationLogicException
604
-     */
605
-    private function getBanVisibility(): string
606
-    {
607
-        $visibility = WebRequest::postString('banVisibility');
608
-        if ($visibility !== 'user' && $visibility !== 'admin' && $visibility !== 'checkuser') {
609
-            throw new ApplicationLogicException('Invalid ban visibility');
610
-        }
611
-
612
-        return $visibility;
613
-    }
614
-
615
-    /**
616
-     * Returns array of [username, ip, email, ua] as ban targets from WebRequest,
617
-     * filtered for whether the user is allowed to set bans including those types.
618
-     *
619
-     * @return string[]
620
-     * @throws ApplicationLogicException
621
-     */
622
-    private function getRawBanTargets(User $user): array
623
-    {
624
-        $targetName = WebRequest::postString('banName');
625
-        $targetIp = WebRequest::postString('banIP');
626
-        $targetEmail = WebRequest::postString('banEmail');
627
-        $targetUseragent = WebRequest::postString('banUseragent');
628
-
629
-        // check the user is allowed to use provided targets
630
-        if (!$this->barrierTest('name', $user, 'BanType')) {
631
-            $targetName = null;
632
-        }
633
-        if (!$this->barrierTest('ip', $user, 'BanType')) {
634
-            $targetIp = null;
635
-        }
636
-        if (!$this->barrierTest('email', $user, 'BanType')) {
637
-            $targetEmail = null;
638
-        }
639
-        if (!$this->barrierTest('useragent', $user, 'BanType')) {
640
-            $targetUseragent = null;
641
-        }
642
-
643
-        // Checks whether there is a target entered to ban.
644
-        if ($targetName === null && $targetIp === null && $targetEmail === null && $targetUseragent === null) {
645
-            throw new ApplicationLogicException('You must specify a target to be banned');
646
-        }
647
-
648
-        return array($targetName, $targetIp, $targetEmail, $targetUseragent);
649
-    }
650
-
651
-    private function preloadFormForRequest(int $banRequest, string $banType, User $user): void
652
-    {
653
-        $database = $this->getDatabase();
654
-
655
-        // Attempt to resolve the correct target
656
-        /** @var Request|false $request */
657
-        $request = Request::getById($banRequest, $database);
658
-        if ($request === false) {
659
-            $this->assign('bantarget', '');
660
-
661
-            return;
662
-        }
663
-
664
-        switch ($banType) {
665
-            case 'EMail':
666
-                if ($this->barrierTest('email', $user, 'BanType')) {
667
-                    $this->assign('banEmail', $request->getEmail());
668
-                }
669
-                break;
670
-            case 'IP':
671
-                if ($this->barrierTest('ip', $user, 'BanType')) {
672
-                    $trustedIp = $this->getXffTrustProvider()->getTrustedClientIp(
673
-                        $request->getIp(),
674
-                        $request->getForwardedIp());
675
-
676
-                    $this->assign('banIP', $trustedIp);
677
-                }
678
-                break;
679
-            case 'Name':
680
-                if ($this->barrierTest('name', $user, 'BanType')) {
681
-                    $this->assign('banName', $request->getName());
682
-                }
683
-                break;
684
-            case 'UA':
685
-                if ($this->barrierTest('useragent', $user, 'BanType')) {
686
-                    $this->assign('banUseragent', $request->getEmail());
687
-                }
688
-                break;
689
-        }
690
-    }
600
+	/**
601
+	 * Returns the validated ban visibility from WebRequest
602
+	 *
603
+	 * @throws ApplicationLogicException
604
+	 */
605
+	private function getBanVisibility(): string
606
+	{
607
+		$visibility = WebRequest::postString('banVisibility');
608
+		if ($visibility !== 'user' && $visibility !== 'admin' && $visibility !== 'checkuser') {
609
+			throw new ApplicationLogicException('Invalid ban visibility');
610
+		}
611
+
612
+		return $visibility;
613
+	}
614
+
615
+	/**
616
+	 * Returns array of [username, ip, email, ua] as ban targets from WebRequest,
617
+	 * filtered for whether the user is allowed to set bans including those types.
618
+	 *
619
+	 * @return string[]
620
+	 * @throws ApplicationLogicException
621
+	 */
622
+	private function getRawBanTargets(User $user): array
623
+	{
624
+		$targetName = WebRequest::postString('banName');
625
+		$targetIp = WebRequest::postString('banIP');
626
+		$targetEmail = WebRequest::postString('banEmail');
627
+		$targetUseragent = WebRequest::postString('banUseragent');
628
+
629
+		// check the user is allowed to use provided targets
630
+		if (!$this->barrierTest('name', $user, 'BanType')) {
631
+			$targetName = null;
632
+		}
633
+		if (!$this->barrierTest('ip', $user, 'BanType')) {
634
+			$targetIp = null;
635
+		}
636
+		if (!$this->barrierTest('email', $user, 'BanType')) {
637
+			$targetEmail = null;
638
+		}
639
+		if (!$this->barrierTest('useragent', $user, 'BanType')) {
640
+			$targetUseragent = null;
641
+		}
642
+
643
+		// Checks whether there is a target entered to ban.
644
+		if ($targetName === null && $targetIp === null && $targetEmail === null && $targetUseragent === null) {
645
+			throw new ApplicationLogicException('You must specify a target to be banned');
646
+		}
647
+
648
+		return array($targetName, $targetIp, $targetEmail, $targetUseragent);
649
+	}
650
+
651
+	private function preloadFormForRequest(int $banRequest, string $banType, User $user): void
652
+	{
653
+		$database = $this->getDatabase();
654
+
655
+		// Attempt to resolve the correct target
656
+		/** @var Request|false $request */
657
+		$request = Request::getById($banRequest, $database);
658
+		if ($request === false) {
659
+			$this->assign('bantarget', '');
660
+
661
+			return;
662
+		}
663
+
664
+		switch ($banType) {
665
+			case 'EMail':
666
+				if ($this->barrierTest('email', $user, 'BanType')) {
667
+					$this->assign('banEmail', $request->getEmail());
668
+				}
669
+				break;
670
+			case 'IP':
671
+				if ($this->barrierTest('ip', $user, 'BanType')) {
672
+					$trustedIp = $this->getXffTrustProvider()->getTrustedClientIp(
673
+						$request->getIp(),
674
+						$request->getForwardedIp());
675
+
676
+					$this->assign('banIP', $trustedIp);
677
+				}
678
+				break;
679
+			case 'Name':
680
+				if ($this->barrierTest('name', $user, 'BanType')) {
681
+					$this->assign('banName', $request->getName());
682
+				}
683
+				break;
684
+			case 'UA':
685
+				if ($this->barrierTest('useragent', $user, 'BanType')) {
686
+					$this->assign('banUseragent', $request->getEmail());
687
+				}
688
+				break;
689
+		}
690
+	}
691 691
 }
Please login to merge, or discard this patch.