@@ -183,56 +183,56 @@ |
||
183 | 183 | // Initialise the site configuration object |
184 | 184 | global $siteConfiguration; |
185 | 185 | $siteConfiguration->setBaseUrl($baseurl) |
186 | - ->setFilePath(__DIR__) |
|
187 | - ->setDebuggingTraceEnabled($enableErrorTrace) |
|
188 | - ->setDebuggingCssBreakpointsEnabled($enableCssBreakpoints) |
|
189 | - ->setForceIdentification($forceIdentification) |
|
190 | - ->setIdentificationCacheExpiry($identificationCacheExpiry) |
|
191 | - ->setMetaWikimediaWebServiceEndpoint($metaWikimediaWebServiceEndpoint) |
|
192 | - ->setEnforceOAuth($enforceOAuth) |
|
193 | - ->setEmailConfirmationEnabled($enableEmailConfirm == 1) |
|
194 | - ->setEmailConfirmationExpiryDays($emailConfirmationExpiryDays) |
|
195 | - ->setMiserModeLimit($requestLimitShowOnly) |
|
196 | - ->setSquidList($squidIpList) |
|
197 | - ->setUseStrictTransportSecurity($strictTransportSecurityExpiry) |
|
198 | - ->setUserAgent($toolUserAgent) |
|
199 | - ->setCurlDisableVerifyPeer($curlDisableSSLVerifyPeer) |
|
200 | - ->setUseOAuthSignup($useOauthSignup) |
|
201 | - ->setOAuthConsumerToken($oauthConsumerToken) |
|
202 | - ->setOAuthLegacyConsumerTokens($oauthLegacyTokens) |
|
203 | - ->setOAuthConsumerSecret($oauthSecretToken) |
|
204 | - ->setOauthMediaWikiCanonicalServer($oauthMediaWikiCanonicalServer) |
|
205 | - ->setDataClearInterval($dataclear_interval) |
|
206 | - ->setXffTrustedHostsFile($xff_trusted_hosts_file) |
|
207 | - ->setIrcNotificationsEnabled($ircBotNotificationsEnabled == 1) |
|
208 | - ->setIrcNotificationsInstance($whichami) |
|
209 | - ->setTitleBlacklistEnabled($enableTitleblacklist == 1) |
|
210 | - ->setTorExitPaths(array_merge(gethostbynamel('en.wikipedia.org'), gethostbynamel('accounts.wmflabs.org'))) |
|
211 | - ->setCreationBotUsername($creationBotUsername) |
|
212 | - ->setCreationBotPassword($creationBotPassword) |
|
213 | - ->setCurlCookieJar($curlCookieJar) |
|
214 | - ->setYubicoApiId($yubicoApiId) |
|
215 | - ->setYubicoApiKey($yubicoApiKey) |
|
216 | - ->setTotpEncryptionKey($totpEncryptionKey) |
|
217 | - ->setRegistrationAllowed($allowRegistration) |
|
218 | - ->setCspReportUri($cspReportUri) |
|
219 | - ->setResourceCacheEpoch($resourceCacheEpoch) |
|
220 | - ->setLocationProviderApiKey($locationProviderApiKey) |
|
221 | - ->setCommonEmailDomains($commonEmailDomains) |
|
222 | - ->setBanMaxIpRange($banMaxIpRange) |
|
223 | - ->setBanMaxIpBlockRange($banMaxIpBlockRange) |
|
224 | - ->setJobQueueBatchSize($jobQueueBatchSize) |
|
225 | - ->setAmqpConfiguration($amqpConfiguration) |
|
226 | - ->setEmailSender($emailSender) |
|
227 | - ->setIdentificationNoticeboardPage($identificationNoticeboardPage) |
|
228 | - ->setIdentificationNoticeboardWebserviceEndpoint($identificationNoticeboardApi) |
|
229 | - ->setAcceptClientHints($acceptClientHints) |
|
230 | - ->setOffline(['offline' => $dontUseDb == 1, 'reason' => $dontUseDbReason, 'culprit' => $dontUseDbCulprit]) |
|
231 | - ->setDatabaseConfig([ |
|
232 | - 'datasource' => 'mysql:host=' . $toolserver_host . ';dbname=' . $toolserver_database, |
|
233 | - 'username' => $toolserver_username, |
|
234 | - 'password' => $toolserver_password, |
|
235 | - ]) |
|
236 | - ->setCookiePath($cookiepath) |
|
237 | - ->setCookieSessionName($sessionname) |
|
186 | + ->setFilePath(__DIR__) |
|
187 | + ->setDebuggingTraceEnabled($enableErrorTrace) |
|
188 | + ->setDebuggingCssBreakpointsEnabled($enableCssBreakpoints) |
|
189 | + ->setForceIdentification($forceIdentification) |
|
190 | + ->setIdentificationCacheExpiry($identificationCacheExpiry) |
|
191 | + ->setMetaWikimediaWebServiceEndpoint($metaWikimediaWebServiceEndpoint) |
|
192 | + ->setEnforceOAuth($enforceOAuth) |
|
193 | + ->setEmailConfirmationEnabled($enableEmailConfirm == 1) |
|
194 | + ->setEmailConfirmationExpiryDays($emailConfirmationExpiryDays) |
|
195 | + ->setMiserModeLimit($requestLimitShowOnly) |
|
196 | + ->setSquidList($squidIpList) |
|
197 | + ->setUseStrictTransportSecurity($strictTransportSecurityExpiry) |
|
198 | + ->setUserAgent($toolUserAgent) |
|
199 | + ->setCurlDisableVerifyPeer($curlDisableSSLVerifyPeer) |
|
200 | + ->setUseOAuthSignup($useOauthSignup) |
|
201 | + ->setOAuthConsumerToken($oauthConsumerToken) |
|
202 | + ->setOAuthLegacyConsumerTokens($oauthLegacyTokens) |
|
203 | + ->setOAuthConsumerSecret($oauthSecretToken) |
|
204 | + ->setOauthMediaWikiCanonicalServer($oauthMediaWikiCanonicalServer) |
|
205 | + ->setDataClearInterval($dataclear_interval) |
|
206 | + ->setXffTrustedHostsFile($xff_trusted_hosts_file) |
|
207 | + ->setIrcNotificationsEnabled($ircBotNotificationsEnabled == 1) |
|
208 | + ->setIrcNotificationsInstance($whichami) |
|
209 | + ->setTitleBlacklistEnabled($enableTitleblacklist == 1) |
|
210 | + ->setTorExitPaths(array_merge(gethostbynamel('en.wikipedia.org'), gethostbynamel('accounts.wmflabs.org'))) |
|
211 | + ->setCreationBotUsername($creationBotUsername) |
|
212 | + ->setCreationBotPassword($creationBotPassword) |
|
213 | + ->setCurlCookieJar($curlCookieJar) |
|
214 | + ->setYubicoApiId($yubicoApiId) |
|
215 | + ->setYubicoApiKey($yubicoApiKey) |
|
216 | + ->setTotpEncryptionKey($totpEncryptionKey) |
|
217 | + ->setRegistrationAllowed($allowRegistration) |
|
218 | + ->setCspReportUri($cspReportUri) |
|
219 | + ->setResourceCacheEpoch($resourceCacheEpoch) |
|
220 | + ->setLocationProviderApiKey($locationProviderApiKey) |
|
221 | + ->setCommonEmailDomains($commonEmailDomains) |
|
222 | + ->setBanMaxIpRange($banMaxIpRange) |
|
223 | + ->setBanMaxIpBlockRange($banMaxIpBlockRange) |
|
224 | + ->setJobQueueBatchSize($jobQueueBatchSize) |
|
225 | + ->setAmqpConfiguration($amqpConfiguration) |
|
226 | + ->setEmailSender($emailSender) |
|
227 | + ->setIdentificationNoticeboardPage($identificationNoticeboardPage) |
|
228 | + ->setIdentificationNoticeboardWebserviceEndpoint($identificationNoticeboardApi) |
|
229 | + ->setAcceptClientHints($acceptClientHints) |
|
230 | + ->setOffline(['offline' => $dontUseDb == 1, 'reason' => $dontUseDbReason, 'culprit' => $dontUseDbCulprit]) |
|
231 | + ->setDatabaseConfig([ |
|
232 | + 'datasource' => 'mysql:host=' . $toolserver_host . ';dbname=' . $toolserver_database, |
|
233 | + 'username' => $toolserver_username, |
|
234 | + 'password' => $toolserver_password, |
|
235 | + ]) |
|
236 | + ->setCookiePath($cookiepath) |
|
237 | + ->setCookieSessionName($sessionname) |
|
238 | 238 | ; |
@@ -26,663 +26,663 @@ |
||
26 | 26 | |
27 | 27 | class PageBan extends InternalPageBase |
28 | 28 | { |
29 | - /** |
|
30 | - * Main function for this page, when no specific actions are called. |
|
31 | - */ |
|
32 | - protected function main(): void |
|
33 | - { |
|
34 | - $this->assignCSRFToken(); |
|
35 | - $this->setHtmlTitle('Bans'); |
|
36 | - |
|
37 | - $database = $this->getDatabase(); |
|
38 | - $currentDomain = Domain::getCurrent($database); |
|
39 | - $bans = Ban::getActiveBans($database, $currentDomain->getId()); |
|
40 | - |
|
41 | - $this->setupBanList($bans); |
|
42 | - |
|
43 | - $this->assign('isFiltered', false); |
|
44 | - $this->setTemplate('bans/main.tpl'); |
|
45 | - } |
|
46 | - |
|
47 | - protected function show(): void |
|
48 | - { |
|
49 | - $this->assignCSRFToken(); |
|
50 | - $this->setHtmlTitle('Bans'); |
|
51 | - |
|
52 | - $rawIdList = WebRequest::getString('id'); |
|
53 | - if ($rawIdList === null) { |
|
54 | - $this->redirect('bans'); |
|
55 | - |
|
56 | - return; |
|
57 | - } |
|
58 | - |
|
59 | - $idList = explode(',', $rawIdList); |
|
60 | - |
|
61 | - $database = $this->getDatabase(); |
|
62 | - $currentDomain = Domain::getCurrent($database); |
|
63 | - $bans = Ban::getByIdList($idList, $database, $currentDomain->getId()); |
|
64 | - |
|
65 | - $this->setupBanList($bans); |
|
66 | - $this->assign('isFiltered', true); |
|
67 | - $this->setTemplate('bans/main.tpl'); |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * Entry point for the ban set action |
|
72 | - * @throws SmartyException |
|
73 | - * @throws Exception |
|
74 | - */ |
|
75 | - protected function set(): void |
|
76 | - { |
|
77 | - $this->setHtmlTitle('Bans'); |
|
78 | - |
|
79 | - // dual-mode action |
|
80 | - if (WebRequest::wasPosted()) { |
|
81 | - try { |
|
82 | - $this->handlePostMethodForSetBan(); |
|
83 | - } |
|
84 | - catch (ApplicationLogicException $ex) { |
|
85 | - SessionAlert::error($ex->getMessage()); |
|
86 | - $this->redirect("bans", "set"); |
|
87 | - } |
|
88 | - } |
|
89 | - else { |
|
90 | - $this->handleGetMethodForSetBan(); |
|
91 | - |
|
92 | - $user = User::getCurrent($this->getDatabase()); |
|
93 | - $banType = WebRequest::getString('type'); |
|
94 | - $banRequest = WebRequest::getInt('request'); |
|
95 | - |
|
96 | - // if the parameters are null, skip loading a request. |
|
97 | - if ($banType !== null && $banRequest !== null && $banRequest !== 0) { |
|
98 | - $this->preloadFormForRequest($banRequest, $banType, $user); |
|
99 | - } |
|
100 | - } |
|
101 | - } |
|
102 | - |
|
103 | - protected function replace(): void |
|
104 | - { |
|
105 | - $this->setHtmlTitle('Bans'); |
|
106 | - |
|
107 | - $database = $this->getDatabase(); |
|
108 | - $domain = Domain::getCurrent($database); |
|
109 | - |
|
110 | - // dual-mode action |
|
111 | - if (WebRequest::wasPosted()) { |
|
112 | - try { |
|
113 | - $originalBanId = WebRequest::postInt('replaceBanId'); |
|
114 | - $originalBanUpdateVersion = WebRequest::postInt('replaceBanUpdateVersion'); |
|
115 | - |
|
116 | - $originalBan = Ban::getActiveId($originalBanId, $database, $domain->getId()); |
|
117 | - |
|
118 | - if ($originalBan === false) { |
|
119 | - throw new ApplicationLogicException("The specified ban is not currently active, or doesn't exist."); |
|
120 | - } |
|
121 | - |
|
122 | - // Discard original ban; we're replacing it. |
|
123 | - $originalBan->setUpdateVersion($originalBanUpdateVersion); |
|
124 | - $originalBan->setActive(false); |
|
125 | - $originalBan->save(); |
|
126 | - |
|
127 | - Logger::banReplaced($database, $originalBan); |
|
128 | - |
|
129 | - // Proceed as normal to save the new ban. |
|
130 | - $this->handlePostMethodForSetBan(); |
|
131 | - } |
|
132 | - catch (ApplicationLogicException $ex) { |
|
133 | - $database->rollback(); |
|
134 | - SessionAlert::error($ex->getMessage()); |
|
135 | - $this->redirect("bans", "set"); |
|
136 | - } |
|
137 | - } |
|
138 | - else { |
|
139 | - $this->handleGetMethodForSetBan(); |
|
140 | - |
|
141 | - $user = User::getCurrent($database); |
|
142 | - $originalBanId = WebRequest::getString('id'); |
|
143 | - |
|
144 | - $originalBan = Ban::getActiveId($originalBanId, $database, $domain->getId()); |
|
145 | - |
|
146 | - if ($originalBan === false) { |
|
147 | - throw new ApplicationLogicException("The specified ban is not currently active, or doesn't exist."); |
|
148 | - } |
|
149 | - |
|
150 | - if ($originalBan->getName() !== null) { |
|
151 | - if (!$this->barrierTest('name', $user, 'BanType')) { |
|
152 | - SessionAlert::error("You are not allowed to set this type of ban."); |
|
153 | - $this->redirect("bans", "set"); |
|
154 | - return; |
|
155 | - } |
|
156 | - |
|
157 | - $this->assign('banName', $originalBan->getName()); |
|
158 | - } |
|
159 | - |
|
160 | - if ($originalBan->getEmail() !== null) { |
|
161 | - if (!$this->barrierTest('email', $user, 'BanType')) { |
|
162 | - SessionAlert::error("You are not allowed to set this type of ban."); |
|
163 | - $this->redirect("bans", "set"); |
|
164 | - return; |
|
165 | - } |
|
166 | - |
|
167 | - $this->assign('banEmail', $originalBan->getEmail()); |
|
168 | - } |
|
169 | - |
|
170 | - if ($originalBan->getUseragent() !== null) { |
|
171 | - if (!$this->barrierTest('useragent', $user, 'BanType')) { |
|
172 | - SessionAlert::error("You are not allowed to set this type of ban."); |
|
173 | - $this->redirect("bans", "set"); |
|
174 | - return; |
|
175 | - } |
|
176 | - |
|
177 | - $this->assign('banUseragent', $originalBan->getUseragent()); |
|
178 | - } |
|
179 | - |
|
180 | - if ($originalBan->getIp() !== null) { |
|
181 | - if (!$this->barrierTest('ip', $user, 'BanType')) { |
|
182 | - SessionAlert::error("You are not allowed to set this type of ban."); |
|
183 | - $this->redirect("bans", "set"); |
|
184 | - return; |
|
185 | - } |
|
186 | - |
|
187 | - $this->assign('banIP', $originalBan->getIp() . '/' . $originalBan->getIpMask()); |
|
188 | - } |
|
189 | - |
|
190 | - $banIsGlobal = $originalBan->getDomain() === null; |
|
191 | - if ($banIsGlobal) { |
|
192 | - if (!$this->barrierTest('global', $user, 'BanType')) { |
|
193 | - SessionAlert::error("You are not allowed to set this type of ban."); |
|
194 | - $this->redirect("bans", "set"); |
|
195 | - return; |
|
196 | - } |
|
197 | - } |
|
198 | - |
|
199 | - if (!$this->barrierTest($originalBan->getVisibility(), $user, 'BanVisibility')) { |
|
200 | - SessionAlert::error("You are not allowed to set this type of ban."); |
|
201 | - $this->redirect("bans", "set"); |
|
202 | - return; |
|
203 | - } |
|
204 | - |
|
205 | - $this->assign('banGlobal', $banIsGlobal); |
|
206 | - $this->assign('banVisibility', $originalBan->getVisibility()); |
|
207 | - |
|
208 | - if ($originalBan->getDuration() !== null) { |
|
209 | - $this->assign('banDuration', date('c', $originalBan->getDuration())); |
|
210 | - } |
|
211 | - |
|
212 | - $this->assign('banReason', $originalBan->getReason()); |
|
213 | - $this->assign('banAction', $originalBan->getAction()); |
|
214 | - $this->assign('banQueue', $originalBan->getTargetQueue()); |
|
215 | - |
|
216 | - $this->assign('replaceBanId', $originalBan->getId()); |
|
217 | - $this->assign('replaceBanUpdateVersion', $originalBan->getUpdateVersion()); |
|
218 | - } |
|
219 | - } |
|
220 | - |
|
221 | - /** |
|
222 | - * Entry point for the ban remove action |
|
223 | - * |
|
224 | - * @throws AccessDeniedException |
|
225 | - * @throws ApplicationLogicException |
|
226 | - * @throws SmartyException |
|
227 | - */ |
|
228 | - protected function remove(): void |
|
229 | - { |
|
230 | - $this->setHtmlTitle('Bans'); |
|
231 | - |
|
232 | - $ban = $this->getBanForUnban(); |
|
233 | - |
|
234 | - $banHelper = new BanHelper($this->getDatabase(), $this->getXffTrustProvider(), $this->getSecurityManager()); |
|
235 | - if (!$banHelper->canUnban($ban)) { |
|
236 | - // triggered when a user tries to unban a ban they can't see the entirety of. |
|
237 | - // there's no UI way to get to this, so a raw exception is fine. |
|
238 | - throw new AccessDeniedException($this->getSecurityManager(), $this->getDomainAccessManager()); |
|
239 | - } |
|
240 | - |
|
241 | - // dual mode |
|
242 | - if (WebRequest::wasPosted()) { |
|
243 | - $this->validateCSRFToken(); |
|
244 | - $unbanReason = WebRequest::postString('unbanreason'); |
|
245 | - |
|
246 | - if ($unbanReason === null || trim($unbanReason) === "") { |
|
247 | - SessionAlert::error('No unban reason specified'); |
|
248 | - $this->redirect("bans", "remove", array('id' => $ban->getId())); |
|
249 | - } |
|
250 | - |
|
251 | - // set optimistic locking from delete form page load |
|
252 | - $updateVersion = WebRequest::postInt('updateversion'); |
|
253 | - $ban->setUpdateVersion($updateVersion); |
|
254 | - |
|
255 | - $database = $this->getDatabase(); |
|
256 | - $ban->setActive(false); |
|
257 | - $ban->save(); |
|
258 | - |
|
259 | - Logger::unbanned($database, $ban, $unbanReason); |
|
260 | - |
|
261 | - SessionAlert::quick('Disabled ban.'); |
|
262 | - $this->getNotificationHelper()->unbanned($ban, $unbanReason); |
|
263 | - |
|
264 | - $this->redirect('bans'); |
|
265 | - } |
|
266 | - else { |
|
267 | - $this->assignCSRFToken(); |
|
268 | - $this->assign('ban', $ban); |
|
269 | - $this->setTemplate('bans/unban.tpl'); |
|
270 | - } |
|
271 | - } |
|
272 | - |
|
273 | - /** |
|
274 | - * Retrieves the requested ban duration from the WebRequest |
|
275 | - * |
|
276 | - * @throws ApplicationLogicException |
|
277 | - */ |
|
278 | - private function getBanDuration(): ?int |
|
279 | - { |
|
280 | - $duration = WebRequest::postString('duration'); |
|
281 | - if ($duration === "other") { |
|
282 | - $duration = strtotime(WebRequest::postString('otherduration')); |
|
283 | - |
|
284 | - if (!$duration) { |
|
285 | - throw new ApplicationLogicException('Invalid ban time'); |
|
286 | - } |
|
287 | - elseif (time() > $duration) { |
|
288 | - throw new ApplicationLogicException('Ban time has already expired!'); |
|
289 | - } |
|
290 | - |
|
291 | - return $duration; |
|
292 | - } |
|
293 | - elseif ($duration === "-1") { |
|
294 | - return null; |
|
295 | - } |
|
296 | - else { |
|
297 | - return WebRequest::postInt('duration') + time(); |
|
298 | - } |
|
299 | - } |
|
300 | - |
|
301 | - /** |
|
302 | - * Handles the POST method on the set action |
|
303 | - * |
|
304 | - * @throws ApplicationLogicException |
|
305 | - * @throws Exception |
|
306 | - */ |
|
307 | - private function handlePostMethodForSetBan() |
|
308 | - { |
|
309 | - $this->validateCSRFToken(); |
|
310 | - $database = $this->getDatabase(); |
|
311 | - $user = User::getCurrent($database); |
|
312 | - $currentDomain = Domain::getCurrent($database); |
|
313 | - |
|
314 | - // Checks whether there is a reason entered for ban. |
|
315 | - $reason = WebRequest::postString('banreason'); |
|
316 | - if ($reason === null || trim($reason) === "") { |
|
317 | - throw new ApplicationLogicException('You must specify a ban reason'); |
|
318 | - } |
|
319 | - |
|
320 | - // ban targets |
|
321 | - list($targetName, $targetIp, $targetEmail, $targetUseragent) = $this->getRawBanTargets($user); |
|
322 | - |
|
323 | - $visibility = $this->getBanVisibility(); |
|
324 | - |
|
325 | - // Validate ban duration |
|
326 | - $duration = $this->getBanDuration(); |
|
327 | - |
|
328 | - $action = WebRequest::postString('banAction') ?? Ban::ACTION_NONE; |
|
329 | - |
|
330 | - $global = WebRequest::postBoolean('banGlobal'); |
|
331 | - if (!$this->barrierTest('global', $user, 'BanType')) { |
|
332 | - $global = false; |
|
333 | - } |
|
334 | - |
|
335 | - if ($action === Ban::ACTION_DEFER && $global) { |
|
336 | - throw new ApplicationLogicException("Cannot set a global ban in defer-to-queue mode."); |
|
337 | - } |
|
338 | - |
|
339 | - // handle CIDR ranges |
|
340 | - $targetMask = null; |
|
341 | - if ($targetIp !== null) { |
|
342 | - list($targetIp, $targetMask) = $this->splitCidrRange($targetIp); |
|
343 | - $this->validateIpBan($targetIp, $targetMask, $user, $action); |
|
344 | - } |
|
345 | - |
|
346 | - $banHelper = new BanHelper($this->getDatabase(), $this->getXffTrustProvider(), $this->getSecurityManager()); |
|
347 | - |
|
348 | - $bansByTarget = $banHelper->getBansByTarget( |
|
349 | - $targetName, |
|
350 | - $targetEmail, |
|
351 | - $targetIp, |
|
352 | - $targetMask, |
|
353 | - $targetUseragent, |
|
354 | - $currentDomain->getId()); |
|
355 | - |
|
356 | - if (count($bansByTarget) > 0) { |
|
357 | - throw new ApplicationLogicException('This target is already banned!'); |
|
358 | - } |
|
359 | - |
|
360 | - $ban = new Ban(); |
|
361 | - $ban->setDatabase($database); |
|
362 | - $ban->setActive(true); |
|
363 | - |
|
364 | - $ban->setName($targetName); |
|
365 | - $ban->setIp($targetIp, $targetMask); |
|
366 | - $ban->setEmail($targetEmail); |
|
367 | - $ban->setUseragent($targetUseragent); |
|
368 | - |
|
369 | - $ban->setUser($user->getId()); |
|
370 | - $ban->setReason($reason); |
|
371 | - $ban->setDuration($duration); |
|
372 | - $ban->setVisibility($visibility); |
|
373 | - |
|
374 | - $ban->setDomain($global ? null : $currentDomain->getId()); |
|
375 | - |
|
376 | - $ban->setAction($action); |
|
377 | - if ($ban->getAction() === Ban::ACTION_DEFER) { |
|
378 | - //FIXME: domains |
|
379 | - $queue = RequestQueue::getByApiName($database, WebRequest::postString('banActionTarget'), 1); |
|
380 | - if ($queue === false) { |
|
381 | - throw new ApplicationLogicException("Unknown target queue"); |
|
382 | - } |
|
383 | - |
|
384 | - if (!$queue->isEnabled()) { |
|
385 | - throw new ApplicationLogicException("Target queue is not enabled"); |
|
386 | - } |
|
387 | - |
|
388 | - $ban->setTargetQueue($queue->getId()); |
|
389 | - } |
|
390 | - |
|
391 | - $ban->save(); |
|
392 | - |
|
393 | - Logger::banned($database, $ban, $reason); |
|
394 | - |
|
395 | - $this->getNotificationHelper()->banned($ban); |
|
396 | - SessionAlert::quick('Ban has been set.'); |
|
397 | - |
|
398 | - $this->redirect('bans'); |
|
399 | - } |
|
400 | - |
|
401 | - /** |
|
402 | - * Handles the GET method on the set action |
|
403 | - * @throws Exception |
|
404 | - */ |
|
405 | - private function handleGetMethodForSetBan() |
|
406 | - { |
|
407 | - $this->setTemplate('bans/banform.tpl'); |
|
408 | - $this->assignCSRFToken(); |
|
409 | - |
|
410 | - $this->assign('maxIpRange', $this->getSiteConfiguration()->getBanMaxIpRange()); |
|
411 | - $this->assign('maxIpBlockRange', $this->getSiteConfiguration()->getBanMaxIpBlockRange()); |
|
412 | - |
|
413 | - $this->assign('banVisibility', 'user'); |
|
414 | - $this->assign('banGlobal', false); |
|
415 | - $this->assign('banQueue', false); |
|
416 | - $this->assign('banAction', Ban::ACTION_BLOCK); |
|
417 | - $this->assign('banDuration', ''); |
|
418 | - $this->assign('banReason', ''); |
|
419 | - |
|
420 | - $this->assign('banEmail', ''); |
|
421 | - $this->assign('banIP', ''); |
|
422 | - $this->assign('banName', ''); |
|
423 | - $this->assign('banUseragent', ''); |
|
424 | - |
|
425 | - $this->assign('replaceBanId', null); |
|
426 | - |
|
427 | - |
|
428 | - |
|
429 | - $database = $this->getDatabase(); |
|
430 | - |
|
431 | - $user = User::getCurrent($database); |
|
432 | - $this->setupSecurity($user); |
|
433 | - |
|
434 | - $queues = RequestQueue::getEnabledQueues($database); |
|
435 | - |
|
436 | - $this->assign('requestQueues', $queues); |
|
437 | - } |
|
438 | - |
|
439 | - /** |
|
440 | - * Finds the Ban object referenced in the WebRequest if it is valid |
|
441 | - * |
|
442 | - * @return Ban |
|
443 | - * @throws ApplicationLogicException |
|
444 | - */ |
|
445 | - private function getBanForUnban(): Ban |
|
446 | - { |
|
447 | - $banId = WebRequest::getInt('id'); |
|
448 | - if ($banId === null || $banId === 0) { |
|
449 | - throw new ApplicationLogicException("The ban ID appears to be missing. This is probably a bug."); |
|
450 | - } |
|
451 | - |
|
452 | - $database = $this->getDatabase(); |
|
453 | - $this->setupSecurity(User::getCurrent($database)); |
|
454 | - $currentDomain = Domain::getCurrent($database); |
|
455 | - $ban = Ban::getActiveId($banId, $database, $currentDomain->getId()); |
|
456 | - |
|
457 | - if ($ban === false) { |
|
458 | - throw new ApplicationLogicException("The specified ban is not currently active, or doesn't exist."); |
|
459 | - } |
|
460 | - |
|
461 | - return $ban; |
|
462 | - } |
|
463 | - |
|
464 | - /** |
|
465 | - * Sets up Smarty variables for access control |
|
466 | - */ |
|
467 | - private function setupSecurity(User $user): void |
|
468 | - { |
|
469 | - $this->assign('canSeeIpBan', $this->barrierTest('ip', $user, 'BanType')); |
|
470 | - $this->assign('canSeeNameBan', $this->barrierTest('name', $user, 'BanType')); |
|
471 | - $this->assign('canSeeEmailBan', $this->barrierTest('email', $user, 'BanType')); |
|
472 | - $this->assign('canSeeUseragentBan', $this->barrierTest('useragent', $user, 'BanType')); |
|
473 | - |
|
474 | - $this->assign('canGlobalBan', $this->barrierTest('global', $user, 'BanType')); |
|
475 | - |
|
476 | - $this->assign('canSeeUserVisibility', $this->barrierTest('user', $user, 'BanVisibility')); |
|
477 | - $this->assign('canSeeAdminVisibility', $this->barrierTest('admin', $user, 'BanVisibility')); |
|
478 | - $this->assign('canSeeCheckuserVisibility', $this->barrierTest('checkuser', $user, 'BanVisibility')); |
|
479 | - } |
|
480 | - |
|
481 | - /** |
|
482 | - * Validates that the provided IP is acceptable for a ban of this type |
|
483 | - * |
|
484 | - * @param string $targetIp IP address |
|
485 | - * @param int $targetMask CIDR prefix length |
|
486 | - * @param User $user User performing the ban |
|
487 | - * @param string $action Ban action to take |
|
488 | - * |
|
489 | - * @throws ApplicationLogicException |
|
490 | - */ |
|
491 | - private function validateIpBan(string $targetIp, int $targetMask, User $user, string $action): void |
|
492 | - { |
|
493 | - // validate this is an IP |
|
494 | - if (!filter_var($targetIp, FILTER_VALIDATE_IP)) { |
|
495 | - throw new ApplicationLogicException("Not a valid IP address"); |
|
496 | - } |
|
497 | - |
|
498 | - $canLargeIpBan = $this->barrierTest('ip-largerange', $user, 'BanType'); |
|
499 | - $maxIpBlockRange = $this->getSiteConfiguration()->getBanMaxIpBlockRange(); |
|
500 | - $maxIpRange = $this->getSiteConfiguration()->getBanMaxIpRange(); |
|
501 | - |
|
502 | - // validate CIDR ranges |
|
503 | - if (filter_var($targetIp, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) { |
|
504 | - if ($targetMask < 0 || $targetMask > 128) { |
|
505 | - throw new ApplicationLogicException("CIDR mask out of range for IPv6"); |
|
506 | - } |
|
507 | - |
|
508 | - // prevent setting the ban if: |
|
509 | - // * the user isn't allowed to set large bans, AND |
|
510 | - // * the ban is a drop or a block (preventing human review of the request), AND |
|
511 | - // * the mask is too wide-reaching |
|
512 | - if (!$canLargeIpBan && ($action == Ban::ACTION_BLOCK || $action == Ban::ACTION_DROP) && $targetMask < $maxIpBlockRange[6]) { |
|
513 | - throw new ApplicationLogicException("The requested IP range for this ban is too wide for the block/drop action."); |
|
514 | - } |
|
515 | - |
|
516 | - if (!$canLargeIpBan && $targetMask < $maxIpRange[6]) { |
|
517 | - throw new ApplicationLogicException("The requested IP range for this ban is too wide."); |
|
518 | - } |
|
519 | - } |
|
520 | - |
|
521 | - if (filter_var($targetIp, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) { |
|
522 | - if ($targetMask < 0 || $targetMask > 32) { |
|
523 | - throw new ApplicationLogicException("CIDR mask out of range for IPv4"); |
|
524 | - } |
|
525 | - |
|
526 | - if (!$canLargeIpBan && ($action == Ban::ACTION_BLOCK || $action == Ban::ACTION_DROP) && $targetMask < $maxIpBlockRange[4]) { |
|
527 | - throw new ApplicationLogicException("The IP range for this ban is too wide for the block/drop action."); |
|
528 | - } |
|
529 | - |
|
530 | - if (!$canLargeIpBan && $targetMask < $maxIpRange[4]) { |
|
531 | - throw new ApplicationLogicException("The requested IP range for this ban is too wide."); |
|
532 | - } |
|
533 | - } |
|
534 | - |
|
535 | - $squidIpList = $this->getSiteConfiguration()->getSquidList(); |
|
536 | - if (in_array($targetIp, $squidIpList)) { |
|
537 | - throw new ApplicationLogicException("This IP address is on the protected list of proxies, and cannot be banned."); |
|
538 | - } |
|
539 | - } |
|
540 | - |
|
541 | - /** |
|
542 | - * Configures a ban list template for display |
|
543 | - * |
|
544 | - * @param Ban[] $bans |
|
545 | - */ |
|
546 | - private function setupBanList(array $bans): void |
|
547 | - { |
|
548 | - $userIds = array_map(fn(Ban $entry) => $entry->getUser(), $bans); |
|
549 | - $userList = UserSearchHelper::get($this->getDatabase())->inIds($userIds)->fetchMap('username'); |
|
550 | - |
|
551 | - $domainIds = array_filter(array_unique(array_map(fn(Ban $entry) => $entry->getDomain(), $bans))); |
|
552 | - $domains = []; |
|
553 | - foreach ($domainIds as $d) { |
|
554 | - if ($d === null) { |
|
555 | - continue; |
|
556 | - } |
|
557 | - $domains[$d] = Domain::getById($d, $this->getDatabase()); |
|
558 | - } |
|
559 | - |
|
560 | - $this->assign('domains', $domains); |
|
561 | - |
|
562 | - $user = User::getCurrent($this->getDatabase()); |
|
563 | - $this->assign('canSet', $this->barrierTest('set', $user)); |
|
564 | - $this->assign('canRemove', $this->barrierTest('remove', $user)); |
|
565 | - |
|
566 | - $this->setupSecurity($user); |
|
567 | - |
|
568 | - $this->assign('usernames', $userList); |
|
569 | - $this->assign('activebans', $bans); |
|
570 | - |
|
571 | - $banHelper = new BanHelper($this->getDatabase(), $this->getXffTrustProvider(), $this->getSecurityManager()); |
|
572 | - $this->assign('banHelper', $banHelper); |
|
573 | - } |
|
574 | - |
|
575 | - /** |
|
576 | - * Converts a plain IP or CIDR mask into an IP and a CIDR suffix |
|
577 | - * |
|
578 | - * @param string $targetIp IP or CIDR range |
|
579 | - * |
|
580 | - * @return array |
|
581 | - */ |
|
582 | - private function splitCidrRange(string $targetIp): array |
|
583 | - { |
|
584 | - if (strpos($targetIp, '/') !== false) { |
|
585 | - $ipParts = explode('/', $targetIp, 2); |
|
586 | - $targetIp = $ipParts[0]; |
|
587 | - $targetMask = (int)$ipParts[1]; |
|
588 | - } |
|
589 | - else { |
|
590 | - // Default the CIDR range based on the IP type |
|
591 | - $targetMask = filter_var($targetIp, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) ? 128 : 32; |
|
592 | - } |
|
593 | - |
|
594 | - return array($targetIp, $targetMask); |
|
29 | + /** |
|
30 | + * Main function for this page, when no specific actions are called. |
|
31 | + */ |
|
32 | + protected function main(): void |
|
33 | + { |
|
34 | + $this->assignCSRFToken(); |
|
35 | + $this->setHtmlTitle('Bans'); |
|
36 | + |
|
37 | + $database = $this->getDatabase(); |
|
38 | + $currentDomain = Domain::getCurrent($database); |
|
39 | + $bans = Ban::getActiveBans($database, $currentDomain->getId()); |
|
40 | + |
|
41 | + $this->setupBanList($bans); |
|
42 | + |
|
43 | + $this->assign('isFiltered', false); |
|
44 | + $this->setTemplate('bans/main.tpl'); |
|
45 | + } |
|
46 | + |
|
47 | + protected function show(): void |
|
48 | + { |
|
49 | + $this->assignCSRFToken(); |
|
50 | + $this->setHtmlTitle('Bans'); |
|
51 | + |
|
52 | + $rawIdList = WebRequest::getString('id'); |
|
53 | + if ($rawIdList === null) { |
|
54 | + $this->redirect('bans'); |
|
55 | + |
|
56 | + return; |
|
57 | + } |
|
58 | + |
|
59 | + $idList = explode(',', $rawIdList); |
|
60 | + |
|
61 | + $database = $this->getDatabase(); |
|
62 | + $currentDomain = Domain::getCurrent($database); |
|
63 | + $bans = Ban::getByIdList($idList, $database, $currentDomain->getId()); |
|
64 | + |
|
65 | + $this->setupBanList($bans); |
|
66 | + $this->assign('isFiltered', true); |
|
67 | + $this->setTemplate('bans/main.tpl'); |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * Entry point for the ban set action |
|
72 | + * @throws SmartyException |
|
73 | + * @throws Exception |
|
74 | + */ |
|
75 | + protected function set(): void |
|
76 | + { |
|
77 | + $this->setHtmlTitle('Bans'); |
|
78 | + |
|
79 | + // dual-mode action |
|
80 | + if (WebRequest::wasPosted()) { |
|
81 | + try { |
|
82 | + $this->handlePostMethodForSetBan(); |
|
83 | + } |
|
84 | + catch (ApplicationLogicException $ex) { |
|
85 | + SessionAlert::error($ex->getMessage()); |
|
86 | + $this->redirect("bans", "set"); |
|
87 | + } |
|
88 | + } |
|
89 | + else { |
|
90 | + $this->handleGetMethodForSetBan(); |
|
91 | + |
|
92 | + $user = User::getCurrent($this->getDatabase()); |
|
93 | + $banType = WebRequest::getString('type'); |
|
94 | + $banRequest = WebRequest::getInt('request'); |
|
95 | + |
|
96 | + // if the parameters are null, skip loading a request. |
|
97 | + if ($banType !== null && $banRequest !== null && $banRequest !== 0) { |
|
98 | + $this->preloadFormForRequest($banRequest, $banType, $user); |
|
99 | + } |
|
100 | + } |
|
101 | + } |
|
102 | + |
|
103 | + protected function replace(): void |
|
104 | + { |
|
105 | + $this->setHtmlTitle('Bans'); |
|
106 | + |
|
107 | + $database = $this->getDatabase(); |
|
108 | + $domain = Domain::getCurrent($database); |
|
109 | + |
|
110 | + // dual-mode action |
|
111 | + if (WebRequest::wasPosted()) { |
|
112 | + try { |
|
113 | + $originalBanId = WebRequest::postInt('replaceBanId'); |
|
114 | + $originalBanUpdateVersion = WebRequest::postInt('replaceBanUpdateVersion'); |
|
115 | + |
|
116 | + $originalBan = Ban::getActiveId($originalBanId, $database, $domain->getId()); |
|
117 | + |
|
118 | + if ($originalBan === false) { |
|
119 | + throw new ApplicationLogicException("The specified ban is not currently active, or doesn't exist."); |
|
120 | + } |
|
121 | + |
|
122 | + // Discard original ban; we're replacing it. |
|
123 | + $originalBan->setUpdateVersion($originalBanUpdateVersion); |
|
124 | + $originalBan->setActive(false); |
|
125 | + $originalBan->save(); |
|
126 | + |
|
127 | + Logger::banReplaced($database, $originalBan); |
|
128 | + |
|
129 | + // Proceed as normal to save the new ban. |
|
130 | + $this->handlePostMethodForSetBan(); |
|
131 | + } |
|
132 | + catch (ApplicationLogicException $ex) { |
|
133 | + $database->rollback(); |
|
134 | + SessionAlert::error($ex->getMessage()); |
|
135 | + $this->redirect("bans", "set"); |
|
136 | + } |
|
137 | + } |
|
138 | + else { |
|
139 | + $this->handleGetMethodForSetBan(); |
|
140 | + |
|
141 | + $user = User::getCurrent($database); |
|
142 | + $originalBanId = WebRequest::getString('id'); |
|
143 | + |
|
144 | + $originalBan = Ban::getActiveId($originalBanId, $database, $domain->getId()); |
|
145 | + |
|
146 | + if ($originalBan === false) { |
|
147 | + throw new ApplicationLogicException("The specified ban is not currently active, or doesn't exist."); |
|
148 | + } |
|
149 | + |
|
150 | + if ($originalBan->getName() !== null) { |
|
151 | + if (!$this->barrierTest('name', $user, 'BanType')) { |
|
152 | + SessionAlert::error("You are not allowed to set this type of ban."); |
|
153 | + $this->redirect("bans", "set"); |
|
154 | + return; |
|
155 | + } |
|
156 | + |
|
157 | + $this->assign('banName', $originalBan->getName()); |
|
158 | + } |
|
159 | + |
|
160 | + if ($originalBan->getEmail() !== null) { |
|
161 | + if (!$this->barrierTest('email', $user, 'BanType')) { |
|
162 | + SessionAlert::error("You are not allowed to set this type of ban."); |
|
163 | + $this->redirect("bans", "set"); |
|
164 | + return; |
|
165 | + } |
|
166 | + |
|
167 | + $this->assign('banEmail', $originalBan->getEmail()); |
|
168 | + } |
|
169 | + |
|
170 | + if ($originalBan->getUseragent() !== null) { |
|
171 | + if (!$this->barrierTest('useragent', $user, 'BanType')) { |
|
172 | + SessionAlert::error("You are not allowed to set this type of ban."); |
|
173 | + $this->redirect("bans", "set"); |
|
174 | + return; |
|
175 | + } |
|
176 | + |
|
177 | + $this->assign('banUseragent', $originalBan->getUseragent()); |
|
178 | + } |
|
179 | + |
|
180 | + if ($originalBan->getIp() !== null) { |
|
181 | + if (!$this->barrierTest('ip', $user, 'BanType')) { |
|
182 | + SessionAlert::error("You are not allowed to set this type of ban."); |
|
183 | + $this->redirect("bans", "set"); |
|
184 | + return; |
|
185 | + } |
|
186 | + |
|
187 | + $this->assign('banIP', $originalBan->getIp() . '/' . $originalBan->getIpMask()); |
|
188 | + } |
|
189 | + |
|
190 | + $banIsGlobal = $originalBan->getDomain() === null; |
|
191 | + if ($banIsGlobal) { |
|
192 | + if (!$this->barrierTest('global', $user, 'BanType')) { |
|
193 | + SessionAlert::error("You are not allowed to set this type of ban."); |
|
194 | + $this->redirect("bans", "set"); |
|
195 | + return; |
|
196 | + } |
|
197 | + } |
|
198 | + |
|
199 | + if (!$this->barrierTest($originalBan->getVisibility(), $user, 'BanVisibility')) { |
|
200 | + SessionAlert::error("You are not allowed to set this type of ban."); |
|
201 | + $this->redirect("bans", "set"); |
|
202 | + return; |
|
203 | + } |
|
204 | + |
|
205 | + $this->assign('banGlobal', $banIsGlobal); |
|
206 | + $this->assign('banVisibility', $originalBan->getVisibility()); |
|
207 | + |
|
208 | + if ($originalBan->getDuration() !== null) { |
|
209 | + $this->assign('banDuration', date('c', $originalBan->getDuration())); |
|
210 | + } |
|
211 | + |
|
212 | + $this->assign('banReason', $originalBan->getReason()); |
|
213 | + $this->assign('banAction', $originalBan->getAction()); |
|
214 | + $this->assign('banQueue', $originalBan->getTargetQueue()); |
|
215 | + |
|
216 | + $this->assign('replaceBanId', $originalBan->getId()); |
|
217 | + $this->assign('replaceBanUpdateVersion', $originalBan->getUpdateVersion()); |
|
218 | + } |
|
219 | + } |
|
220 | + |
|
221 | + /** |
|
222 | + * Entry point for the ban remove action |
|
223 | + * |
|
224 | + * @throws AccessDeniedException |
|
225 | + * @throws ApplicationLogicException |
|
226 | + * @throws SmartyException |
|
227 | + */ |
|
228 | + protected function remove(): void |
|
229 | + { |
|
230 | + $this->setHtmlTitle('Bans'); |
|
231 | + |
|
232 | + $ban = $this->getBanForUnban(); |
|
233 | + |
|
234 | + $banHelper = new BanHelper($this->getDatabase(), $this->getXffTrustProvider(), $this->getSecurityManager()); |
|
235 | + if (!$banHelper->canUnban($ban)) { |
|
236 | + // triggered when a user tries to unban a ban they can't see the entirety of. |
|
237 | + // there's no UI way to get to this, so a raw exception is fine. |
|
238 | + throw new AccessDeniedException($this->getSecurityManager(), $this->getDomainAccessManager()); |
|
239 | + } |
|
240 | + |
|
241 | + // dual mode |
|
242 | + if (WebRequest::wasPosted()) { |
|
243 | + $this->validateCSRFToken(); |
|
244 | + $unbanReason = WebRequest::postString('unbanreason'); |
|
245 | + |
|
246 | + if ($unbanReason === null || trim($unbanReason) === "") { |
|
247 | + SessionAlert::error('No unban reason specified'); |
|
248 | + $this->redirect("bans", "remove", array('id' => $ban->getId())); |
|
249 | + } |
|
250 | + |
|
251 | + // set optimistic locking from delete form page load |
|
252 | + $updateVersion = WebRequest::postInt('updateversion'); |
|
253 | + $ban->setUpdateVersion($updateVersion); |
|
254 | + |
|
255 | + $database = $this->getDatabase(); |
|
256 | + $ban->setActive(false); |
|
257 | + $ban->save(); |
|
258 | + |
|
259 | + Logger::unbanned($database, $ban, $unbanReason); |
|
260 | + |
|
261 | + SessionAlert::quick('Disabled ban.'); |
|
262 | + $this->getNotificationHelper()->unbanned($ban, $unbanReason); |
|
263 | + |
|
264 | + $this->redirect('bans'); |
|
265 | + } |
|
266 | + else { |
|
267 | + $this->assignCSRFToken(); |
|
268 | + $this->assign('ban', $ban); |
|
269 | + $this->setTemplate('bans/unban.tpl'); |
|
270 | + } |
|
271 | + } |
|
272 | + |
|
273 | + /** |
|
274 | + * Retrieves the requested ban duration from the WebRequest |
|
275 | + * |
|
276 | + * @throws ApplicationLogicException |
|
277 | + */ |
|
278 | + private function getBanDuration(): ?int |
|
279 | + { |
|
280 | + $duration = WebRequest::postString('duration'); |
|
281 | + if ($duration === "other") { |
|
282 | + $duration = strtotime(WebRequest::postString('otherduration')); |
|
283 | + |
|
284 | + if (!$duration) { |
|
285 | + throw new ApplicationLogicException('Invalid ban time'); |
|
286 | + } |
|
287 | + elseif (time() > $duration) { |
|
288 | + throw new ApplicationLogicException('Ban time has already expired!'); |
|
289 | + } |
|
290 | + |
|
291 | + return $duration; |
|
292 | + } |
|
293 | + elseif ($duration === "-1") { |
|
294 | + return null; |
|
295 | + } |
|
296 | + else { |
|
297 | + return WebRequest::postInt('duration') + time(); |
|
298 | + } |
|
299 | + } |
|
300 | + |
|
301 | + /** |
|
302 | + * Handles the POST method on the set action |
|
303 | + * |
|
304 | + * @throws ApplicationLogicException |
|
305 | + * @throws Exception |
|
306 | + */ |
|
307 | + private function handlePostMethodForSetBan() |
|
308 | + { |
|
309 | + $this->validateCSRFToken(); |
|
310 | + $database = $this->getDatabase(); |
|
311 | + $user = User::getCurrent($database); |
|
312 | + $currentDomain = Domain::getCurrent($database); |
|
313 | + |
|
314 | + // Checks whether there is a reason entered for ban. |
|
315 | + $reason = WebRequest::postString('banreason'); |
|
316 | + if ($reason === null || trim($reason) === "") { |
|
317 | + throw new ApplicationLogicException('You must specify a ban reason'); |
|
318 | + } |
|
319 | + |
|
320 | + // ban targets |
|
321 | + list($targetName, $targetIp, $targetEmail, $targetUseragent) = $this->getRawBanTargets($user); |
|
322 | + |
|
323 | + $visibility = $this->getBanVisibility(); |
|
324 | + |
|
325 | + // Validate ban duration |
|
326 | + $duration = $this->getBanDuration(); |
|
327 | + |
|
328 | + $action = WebRequest::postString('banAction') ?? Ban::ACTION_NONE; |
|
329 | + |
|
330 | + $global = WebRequest::postBoolean('banGlobal'); |
|
331 | + if (!$this->barrierTest('global', $user, 'BanType')) { |
|
332 | + $global = false; |
|
333 | + } |
|
334 | + |
|
335 | + if ($action === Ban::ACTION_DEFER && $global) { |
|
336 | + throw new ApplicationLogicException("Cannot set a global ban in defer-to-queue mode."); |
|
337 | + } |
|
338 | + |
|
339 | + // handle CIDR ranges |
|
340 | + $targetMask = null; |
|
341 | + if ($targetIp !== null) { |
|
342 | + list($targetIp, $targetMask) = $this->splitCidrRange($targetIp); |
|
343 | + $this->validateIpBan($targetIp, $targetMask, $user, $action); |
|
344 | + } |
|
345 | + |
|
346 | + $banHelper = new BanHelper($this->getDatabase(), $this->getXffTrustProvider(), $this->getSecurityManager()); |
|
347 | + |
|
348 | + $bansByTarget = $banHelper->getBansByTarget( |
|
349 | + $targetName, |
|
350 | + $targetEmail, |
|
351 | + $targetIp, |
|
352 | + $targetMask, |
|
353 | + $targetUseragent, |
|
354 | + $currentDomain->getId()); |
|
355 | + |
|
356 | + if (count($bansByTarget) > 0) { |
|
357 | + throw new ApplicationLogicException('This target is already banned!'); |
|
358 | + } |
|
359 | + |
|
360 | + $ban = new Ban(); |
|
361 | + $ban->setDatabase($database); |
|
362 | + $ban->setActive(true); |
|
363 | + |
|
364 | + $ban->setName($targetName); |
|
365 | + $ban->setIp($targetIp, $targetMask); |
|
366 | + $ban->setEmail($targetEmail); |
|
367 | + $ban->setUseragent($targetUseragent); |
|
368 | + |
|
369 | + $ban->setUser($user->getId()); |
|
370 | + $ban->setReason($reason); |
|
371 | + $ban->setDuration($duration); |
|
372 | + $ban->setVisibility($visibility); |
|
373 | + |
|
374 | + $ban->setDomain($global ? null : $currentDomain->getId()); |
|
375 | + |
|
376 | + $ban->setAction($action); |
|
377 | + if ($ban->getAction() === Ban::ACTION_DEFER) { |
|
378 | + //FIXME: domains |
|
379 | + $queue = RequestQueue::getByApiName($database, WebRequest::postString('banActionTarget'), 1); |
|
380 | + if ($queue === false) { |
|
381 | + throw new ApplicationLogicException("Unknown target queue"); |
|
382 | + } |
|
383 | + |
|
384 | + if (!$queue->isEnabled()) { |
|
385 | + throw new ApplicationLogicException("Target queue is not enabled"); |
|
386 | + } |
|
387 | + |
|
388 | + $ban->setTargetQueue($queue->getId()); |
|
389 | + } |
|
390 | + |
|
391 | + $ban->save(); |
|
392 | + |
|
393 | + Logger::banned($database, $ban, $reason); |
|
394 | + |
|
395 | + $this->getNotificationHelper()->banned($ban); |
|
396 | + SessionAlert::quick('Ban has been set.'); |
|
397 | + |
|
398 | + $this->redirect('bans'); |
|
399 | + } |
|
400 | + |
|
401 | + /** |
|
402 | + * Handles the GET method on the set action |
|
403 | + * @throws Exception |
|
404 | + */ |
|
405 | + private function handleGetMethodForSetBan() |
|
406 | + { |
|
407 | + $this->setTemplate('bans/banform.tpl'); |
|
408 | + $this->assignCSRFToken(); |
|
409 | + |
|
410 | + $this->assign('maxIpRange', $this->getSiteConfiguration()->getBanMaxIpRange()); |
|
411 | + $this->assign('maxIpBlockRange', $this->getSiteConfiguration()->getBanMaxIpBlockRange()); |
|
412 | + |
|
413 | + $this->assign('banVisibility', 'user'); |
|
414 | + $this->assign('banGlobal', false); |
|
415 | + $this->assign('banQueue', false); |
|
416 | + $this->assign('banAction', Ban::ACTION_BLOCK); |
|
417 | + $this->assign('banDuration', ''); |
|
418 | + $this->assign('banReason', ''); |
|
419 | + |
|
420 | + $this->assign('banEmail', ''); |
|
421 | + $this->assign('banIP', ''); |
|
422 | + $this->assign('banName', ''); |
|
423 | + $this->assign('banUseragent', ''); |
|
424 | + |
|
425 | + $this->assign('replaceBanId', null); |
|
426 | + |
|
427 | + |
|
428 | + |
|
429 | + $database = $this->getDatabase(); |
|
430 | + |
|
431 | + $user = User::getCurrent($database); |
|
432 | + $this->setupSecurity($user); |
|
433 | + |
|
434 | + $queues = RequestQueue::getEnabledQueues($database); |
|
435 | + |
|
436 | + $this->assign('requestQueues', $queues); |
|
437 | + } |
|
438 | + |
|
439 | + /** |
|
440 | + * Finds the Ban object referenced in the WebRequest if it is valid |
|
441 | + * |
|
442 | + * @return Ban |
|
443 | + * @throws ApplicationLogicException |
|
444 | + */ |
|
445 | + private function getBanForUnban(): Ban |
|
446 | + { |
|
447 | + $banId = WebRequest::getInt('id'); |
|
448 | + if ($banId === null || $banId === 0) { |
|
449 | + throw new ApplicationLogicException("The ban ID appears to be missing. This is probably a bug."); |
|
450 | + } |
|
451 | + |
|
452 | + $database = $this->getDatabase(); |
|
453 | + $this->setupSecurity(User::getCurrent($database)); |
|
454 | + $currentDomain = Domain::getCurrent($database); |
|
455 | + $ban = Ban::getActiveId($banId, $database, $currentDomain->getId()); |
|
456 | + |
|
457 | + if ($ban === false) { |
|
458 | + throw new ApplicationLogicException("The specified ban is not currently active, or doesn't exist."); |
|
459 | + } |
|
460 | + |
|
461 | + return $ban; |
|
462 | + } |
|
463 | + |
|
464 | + /** |
|
465 | + * Sets up Smarty variables for access control |
|
466 | + */ |
|
467 | + private function setupSecurity(User $user): void |
|
468 | + { |
|
469 | + $this->assign('canSeeIpBan', $this->barrierTest('ip', $user, 'BanType')); |
|
470 | + $this->assign('canSeeNameBan', $this->barrierTest('name', $user, 'BanType')); |
|
471 | + $this->assign('canSeeEmailBan', $this->barrierTest('email', $user, 'BanType')); |
|
472 | + $this->assign('canSeeUseragentBan', $this->barrierTest('useragent', $user, 'BanType')); |
|
473 | + |
|
474 | + $this->assign('canGlobalBan', $this->barrierTest('global', $user, 'BanType')); |
|
475 | + |
|
476 | + $this->assign('canSeeUserVisibility', $this->barrierTest('user', $user, 'BanVisibility')); |
|
477 | + $this->assign('canSeeAdminVisibility', $this->barrierTest('admin', $user, 'BanVisibility')); |
|
478 | + $this->assign('canSeeCheckuserVisibility', $this->barrierTest('checkuser', $user, 'BanVisibility')); |
|
479 | + } |
|
480 | + |
|
481 | + /** |
|
482 | + * Validates that the provided IP is acceptable for a ban of this type |
|
483 | + * |
|
484 | + * @param string $targetIp IP address |
|
485 | + * @param int $targetMask CIDR prefix length |
|
486 | + * @param User $user User performing the ban |
|
487 | + * @param string $action Ban action to take |
|
488 | + * |
|
489 | + * @throws ApplicationLogicException |
|
490 | + */ |
|
491 | + private function validateIpBan(string $targetIp, int $targetMask, User $user, string $action): void |
|
492 | + { |
|
493 | + // validate this is an IP |
|
494 | + if (!filter_var($targetIp, FILTER_VALIDATE_IP)) { |
|
495 | + throw new ApplicationLogicException("Not a valid IP address"); |
|
496 | + } |
|
497 | + |
|
498 | + $canLargeIpBan = $this->barrierTest('ip-largerange', $user, 'BanType'); |
|
499 | + $maxIpBlockRange = $this->getSiteConfiguration()->getBanMaxIpBlockRange(); |
|
500 | + $maxIpRange = $this->getSiteConfiguration()->getBanMaxIpRange(); |
|
501 | + |
|
502 | + // validate CIDR ranges |
|
503 | + if (filter_var($targetIp, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) { |
|
504 | + if ($targetMask < 0 || $targetMask > 128) { |
|
505 | + throw new ApplicationLogicException("CIDR mask out of range for IPv6"); |
|
506 | + } |
|
507 | + |
|
508 | + // prevent setting the ban if: |
|
509 | + // * the user isn't allowed to set large bans, AND |
|
510 | + // * the ban is a drop or a block (preventing human review of the request), AND |
|
511 | + // * the mask is too wide-reaching |
|
512 | + if (!$canLargeIpBan && ($action == Ban::ACTION_BLOCK || $action == Ban::ACTION_DROP) && $targetMask < $maxIpBlockRange[6]) { |
|
513 | + throw new ApplicationLogicException("The requested IP range for this ban is too wide for the block/drop action."); |
|
514 | + } |
|
515 | + |
|
516 | + if (!$canLargeIpBan && $targetMask < $maxIpRange[6]) { |
|
517 | + throw new ApplicationLogicException("The requested IP range for this ban is too wide."); |
|
518 | + } |
|
519 | + } |
|
520 | + |
|
521 | + if (filter_var($targetIp, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) { |
|
522 | + if ($targetMask < 0 || $targetMask > 32) { |
|
523 | + throw new ApplicationLogicException("CIDR mask out of range for IPv4"); |
|
524 | + } |
|
525 | + |
|
526 | + if (!$canLargeIpBan && ($action == Ban::ACTION_BLOCK || $action == Ban::ACTION_DROP) && $targetMask < $maxIpBlockRange[4]) { |
|
527 | + throw new ApplicationLogicException("The IP range for this ban is too wide for the block/drop action."); |
|
528 | + } |
|
529 | + |
|
530 | + if (!$canLargeIpBan && $targetMask < $maxIpRange[4]) { |
|
531 | + throw new ApplicationLogicException("The requested IP range for this ban is too wide."); |
|
532 | + } |
|
533 | + } |
|
534 | + |
|
535 | + $squidIpList = $this->getSiteConfiguration()->getSquidList(); |
|
536 | + if (in_array($targetIp, $squidIpList)) { |
|
537 | + throw new ApplicationLogicException("This IP address is on the protected list of proxies, and cannot be banned."); |
|
538 | + } |
|
539 | + } |
|
540 | + |
|
541 | + /** |
|
542 | + * Configures a ban list template for display |
|
543 | + * |
|
544 | + * @param Ban[] $bans |
|
545 | + */ |
|
546 | + private function setupBanList(array $bans): void |
|
547 | + { |
|
548 | + $userIds = array_map(fn(Ban $entry) => $entry->getUser(), $bans); |
|
549 | + $userList = UserSearchHelper::get($this->getDatabase())->inIds($userIds)->fetchMap('username'); |
|
550 | + |
|
551 | + $domainIds = array_filter(array_unique(array_map(fn(Ban $entry) => $entry->getDomain(), $bans))); |
|
552 | + $domains = []; |
|
553 | + foreach ($domainIds as $d) { |
|
554 | + if ($d === null) { |
|
555 | + continue; |
|
556 | + } |
|
557 | + $domains[$d] = Domain::getById($d, $this->getDatabase()); |
|
558 | + } |
|
559 | + |
|
560 | + $this->assign('domains', $domains); |
|
561 | + |
|
562 | + $user = User::getCurrent($this->getDatabase()); |
|
563 | + $this->assign('canSet', $this->barrierTest('set', $user)); |
|
564 | + $this->assign('canRemove', $this->barrierTest('remove', $user)); |
|
565 | + |
|
566 | + $this->setupSecurity($user); |
|
567 | + |
|
568 | + $this->assign('usernames', $userList); |
|
569 | + $this->assign('activebans', $bans); |
|
570 | + |
|
571 | + $banHelper = new BanHelper($this->getDatabase(), $this->getXffTrustProvider(), $this->getSecurityManager()); |
|
572 | + $this->assign('banHelper', $banHelper); |
|
573 | + } |
|
574 | + |
|
575 | + /** |
|
576 | + * Converts a plain IP or CIDR mask into an IP and a CIDR suffix |
|
577 | + * |
|
578 | + * @param string $targetIp IP or CIDR range |
|
579 | + * |
|
580 | + * @return array |
|
581 | + */ |
|
582 | + private function splitCidrRange(string $targetIp): array |
|
583 | + { |
|
584 | + if (strpos($targetIp, '/') !== false) { |
|
585 | + $ipParts = explode('/', $targetIp, 2); |
|
586 | + $targetIp = $ipParts[0]; |
|
587 | + $targetMask = (int)$ipParts[1]; |
|
588 | + } |
|
589 | + else { |
|
590 | + // Default the CIDR range based on the IP type |
|
591 | + $targetMask = filter_var($targetIp, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) ? 128 : 32; |
|
592 | + } |
|
593 | + |
|
594 | + return array($targetIp, $targetMask); |
|
595 | 595 | } |
596 | 596 | |
597 | - /** |
|
598 | - * Returns the validated ban visibility from WebRequest |
|
599 | - * |
|
600 | - * @throws ApplicationLogicException |
|
601 | - */ |
|
602 | - private function getBanVisibility(): string |
|
603 | - { |
|
604 | - $visibility = WebRequest::postString('banVisibility'); |
|
605 | - if ($visibility !== 'user' && $visibility !== 'admin' && $visibility !== 'checkuser') { |
|
606 | - throw new ApplicationLogicException('Invalid ban visibility'); |
|
607 | - } |
|
608 | - |
|
609 | - return $visibility; |
|
610 | - } |
|
611 | - |
|
612 | - /** |
|
613 | - * Returns array of [username, ip, email, ua] as ban targets from WebRequest, |
|
614 | - * filtered for whether the user is allowed to set bans including those types. |
|
615 | - * |
|
616 | - * @return string[] |
|
617 | - * @throws ApplicationLogicException |
|
618 | - */ |
|
619 | - private function getRawBanTargets(User $user): array |
|
620 | - { |
|
621 | - $targetName = WebRequest::postString('banName'); |
|
622 | - $targetIp = WebRequest::postString('banIP'); |
|
623 | - $targetEmail = WebRequest::postString('banEmail'); |
|
624 | - $targetUseragent = WebRequest::postString('banUseragent'); |
|
625 | - |
|
626 | - // check the user is allowed to use provided targets |
|
627 | - if (!$this->barrierTest('name', $user, 'BanType')) { |
|
628 | - $targetName = null; |
|
629 | - } |
|
630 | - if (!$this->barrierTest('ip', $user, 'BanType')) { |
|
631 | - $targetIp = null; |
|
632 | - } |
|
633 | - if (!$this->barrierTest('email', $user, 'BanType')) { |
|
634 | - $targetEmail = null; |
|
635 | - } |
|
636 | - if (!$this->barrierTest('useragent', $user, 'BanType')) { |
|
637 | - $targetUseragent = null; |
|
638 | - } |
|
639 | - |
|
640 | - // Checks whether there is a target entered to ban. |
|
641 | - if ($targetName === null && $targetIp === null && $targetEmail === null && $targetUseragent === null) { |
|
642 | - throw new ApplicationLogicException('You must specify a target to be banned'); |
|
643 | - } |
|
644 | - |
|
645 | - return array($targetName, $targetIp, $targetEmail, $targetUseragent); |
|
646 | - } |
|
647 | - |
|
648 | - private function preloadFormForRequest(int $banRequest, string $banType, User $user): void |
|
649 | - { |
|
650 | - $database = $this->getDatabase(); |
|
651 | - |
|
652 | - // Attempt to resolve the correct target |
|
653 | - /** @var Request|false $request */ |
|
654 | - $request = Request::getById($banRequest, $database); |
|
655 | - if ($request === false) { |
|
656 | - $this->assign('bantarget', ''); |
|
657 | - |
|
658 | - return; |
|
659 | - } |
|
660 | - |
|
661 | - switch ($banType) { |
|
662 | - case 'EMail': |
|
663 | - if ($this->barrierTest('email', $user, 'BanType')) { |
|
664 | - $this->assign('banEmail', $request->getEmail()); |
|
665 | - } |
|
666 | - break; |
|
667 | - case 'IP': |
|
668 | - if ($this->barrierTest('ip', $user, 'BanType')) { |
|
669 | - $trustedIp = $this->getXffTrustProvider()->getTrustedClientIp( |
|
670 | - $request->getIp(), |
|
671 | - $request->getForwardedIp()); |
|
672 | - |
|
673 | - $this->assign('banIP', $trustedIp); |
|
674 | - } |
|
675 | - break; |
|
676 | - case 'Name': |
|
677 | - if ($this->barrierTest('name', $user, 'BanType')) { |
|
678 | - $this->assign('banName', $request->getName()); |
|
679 | - } |
|
680 | - break; |
|
681 | - case 'UA': |
|
682 | - if ($this->barrierTest('useragent', $user, 'BanType')) { |
|
683 | - $this->assign('banUseragent', $request->getEmail()); |
|
684 | - } |
|
685 | - break; |
|
686 | - } |
|
687 | - } |
|
597 | + /** |
|
598 | + * Returns the validated ban visibility from WebRequest |
|
599 | + * |
|
600 | + * @throws ApplicationLogicException |
|
601 | + */ |
|
602 | + private function getBanVisibility(): string |
|
603 | + { |
|
604 | + $visibility = WebRequest::postString('banVisibility'); |
|
605 | + if ($visibility !== 'user' && $visibility !== 'admin' && $visibility !== 'checkuser') { |
|
606 | + throw new ApplicationLogicException('Invalid ban visibility'); |
|
607 | + } |
|
608 | + |
|
609 | + return $visibility; |
|
610 | + } |
|
611 | + |
|
612 | + /** |
|
613 | + * Returns array of [username, ip, email, ua] as ban targets from WebRequest, |
|
614 | + * filtered for whether the user is allowed to set bans including those types. |
|
615 | + * |
|
616 | + * @return string[] |
|
617 | + * @throws ApplicationLogicException |
|
618 | + */ |
|
619 | + private function getRawBanTargets(User $user): array |
|
620 | + { |
|
621 | + $targetName = WebRequest::postString('banName'); |
|
622 | + $targetIp = WebRequest::postString('banIP'); |
|
623 | + $targetEmail = WebRequest::postString('banEmail'); |
|
624 | + $targetUseragent = WebRequest::postString('banUseragent'); |
|
625 | + |
|
626 | + // check the user is allowed to use provided targets |
|
627 | + if (!$this->barrierTest('name', $user, 'BanType')) { |
|
628 | + $targetName = null; |
|
629 | + } |
|
630 | + if (!$this->barrierTest('ip', $user, 'BanType')) { |
|
631 | + $targetIp = null; |
|
632 | + } |
|
633 | + if (!$this->barrierTest('email', $user, 'BanType')) { |
|
634 | + $targetEmail = null; |
|
635 | + } |
|
636 | + if (!$this->barrierTest('useragent', $user, 'BanType')) { |
|
637 | + $targetUseragent = null; |
|
638 | + } |
|
639 | + |
|
640 | + // Checks whether there is a target entered to ban. |
|
641 | + if ($targetName === null && $targetIp === null && $targetEmail === null && $targetUseragent === null) { |
|
642 | + throw new ApplicationLogicException('You must specify a target to be banned'); |
|
643 | + } |
|
644 | + |
|
645 | + return array($targetName, $targetIp, $targetEmail, $targetUseragent); |
|
646 | + } |
|
647 | + |
|
648 | + private function preloadFormForRequest(int $banRequest, string $banType, User $user): void |
|
649 | + { |
|
650 | + $database = $this->getDatabase(); |
|
651 | + |
|
652 | + // Attempt to resolve the correct target |
|
653 | + /** @var Request|false $request */ |
|
654 | + $request = Request::getById($banRequest, $database); |
|
655 | + if ($request === false) { |
|
656 | + $this->assign('bantarget', ''); |
|
657 | + |
|
658 | + return; |
|
659 | + } |
|
660 | + |
|
661 | + switch ($banType) { |
|
662 | + case 'EMail': |
|
663 | + if ($this->barrierTest('email', $user, 'BanType')) { |
|
664 | + $this->assign('banEmail', $request->getEmail()); |
|
665 | + } |
|
666 | + break; |
|
667 | + case 'IP': |
|
668 | + if ($this->barrierTest('ip', $user, 'BanType')) { |
|
669 | + $trustedIp = $this->getXffTrustProvider()->getTrustedClientIp( |
|
670 | + $request->getIp(), |
|
671 | + $request->getForwardedIp()); |
|
672 | + |
|
673 | + $this->assign('banIP', $trustedIp); |
|
674 | + } |
|
675 | + break; |
|
676 | + case 'Name': |
|
677 | + if ($this->barrierTest('name', $user, 'BanType')) { |
|
678 | + $this->assign('banName', $request->getName()); |
|
679 | + } |
|
680 | + break; |
|
681 | + case 'UA': |
|
682 | + if ($this->barrierTest('useragent', $user, 'BanType')) { |
|
683 | + $this->assign('banUseragent', $request->getEmail()); |
|
684 | + } |
|
685 | + break; |
|
686 | + } |
|
687 | + } |
|
688 | 688 | } |
@@ -85,8 +85,7 @@ discard block |
||
85 | 85 | SessionAlert::error($ex->getMessage()); |
86 | 86 | $this->redirect("bans", "set"); |
87 | 87 | } |
88 | - } |
|
89 | - else { |
|
88 | + } else { |
|
90 | 89 | $this->handleGetMethodForSetBan(); |
91 | 90 | |
92 | 91 | $user = User::getCurrent($this->getDatabase()); |
@@ -134,8 +133,7 @@ discard block |
||
134 | 133 | SessionAlert::error($ex->getMessage()); |
135 | 134 | $this->redirect("bans", "set"); |
136 | 135 | } |
137 | - } |
|
138 | - else { |
|
136 | + } else { |
|
139 | 137 | $this->handleGetMethodForSetBan(); |
140 | 138 | |
141 | 139 | $user = User::getCurrent($database); |
@@ -262,8 +260,7 @@ discard block |
||
262 | 260 | $this->getNotificationHelper()->unbanned($ban, $unbanReason); |
263 | 261 | |
264 | 262 | $this->redirect('bans'); |
265 | - } |
|
266 | - else { |
|
263 | + } else { |
|
267 | 264 | $this->assignCSRFToken(); |
268 | 265 | $this->assign('ban', $ban); |
269 | 266 | $this->setTemplate('bans/unban.tpl'); |
@@ -283,17 +280,14 @@ discard block |
||
283 | 280 | |
284 | 281 | if (!$duration) { |
285 | 282 | throw new ApplicationLogicException('Invalid ban time'); |
286 | - } |
|
287 | - elseif (time() > $duration) { |
|
283 | + } elseif (time() > $duration) { |
|
288 | 284 | throw new ApplicationLogicException('Ban time has already expired!'); |
289 | 285 | } |
290 | 286 | |
291 | 287 | return $duration; |
292 | - } |
|
293 | - elseif ($duration === "-1") { |
|
288 | + } elseif ($duration === "-1") { |
|
294 | 289 | return null; |
295 | - } |
|
296 | - else { |
|
290 | + } else { |
|
297 | 291 | return WebRequest::postInt('duration') + time(); |
298 | 292 | } |
299 | 293 | } |
@@ -585,8 +579,7 @@ discard block |
||
585 | 579 | $ipParts = explode('/', $targetIp, 2); |
586 | 580 | $targetIp = $ipParts[0]; |
587 | 581 | $targetMask = (int)$ipParts[1]; |
588 | - } |
|
589 | - else { |
|
582 | + } else { |
|
590 | 583 | // Default the CIDR range based on the IP type |
591 | 584 | $targetMask = filter_var($targetIp, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) ? 128 : 32; |
592 | 585 | } |
@@ -15,70 +15,70 @@ |
||
15 | 15 | |
16 | 16 | class ConsoleStart extends ApplicationBase |
17 | 17 | { |
18 | - /** |
|
19 | - * @var ConsoleTaskBase |
|
20 | - */ |
|
21 | - private $consoleTask; |
|
18 | + /** |
|
19 | + * @var ConsoleTaskBase |
|
20 | + */ |
|
21 | + private $consoleTask; |
|
22 | 22 | |
23 | - /** |
|
24 | - * ConsoleStart constructor. |
|
25 | - * |
|
26 | - * @param SiteConfiguration $configuration |
|
27 | - * @param ConsoleTaskBase $consoleTask |
|
28 | - */ |
|
29 | - public function __construct(SiteConfiguration $configuration, ConsoleTaskBase $consoleTask) |
|
30 | - { |
|
31 | - parent::__construct($configuration); |
|
32 | - $this->consoleTask = $consoleTask; |
|
33 | - } |
|
23 | + /** |
|
24 | + * ConsoleStart constructor. |
|
25 | + * |
|
26 | + * @param SiteConfiguration $configuration |
|
27 | + * @param ConsoleTaskBase $consoleTask |
|
28 | + */ |
|
29 | + public function __construct(SiteConfiguration $configuration, ConsoleTaskBase $consoleTask) |
|
30 | + { |
|
31 | + parent::__construct($configuration); |
|
32 | + $this->consoleTask = $consoleTask; |
|
33 | + } |
|
34 | 34 | |
35 | - protected function setupEnvironment() |
|
36 | - { |
|
37 | - // initialise super-global providers |
|
38 | - WebRequest::setGlobalStateProvider(new FakeGlobalStateProvider()); |
|
35 | + protected function setupEnvironment() |
|
36 | + { |
|
37 | + // initialise super-global providers |
|
38 | + WebRequest::setGlobalStateProvider(new FakeGlobalStateProvider()); |
|
39 | 39 | |
40 | - if (WebRequest::method() !== null) { |
|
41 | - throw new EnvironmentException('This is a console task, which cannot be executed via the web.'); |
|
42 | - } |
|
40 | + if (WebRequest::method() !== null) { |
|
41 | + throw new EnvironmentException('This is a console task, which cannot be executed via the web.'); |
|
42 | + } |
|
43 | 43 | |
44 | - if (Offline::isOffline($this->getConfiguration())) { |
|
45 | - throw new EnvironmentException('The tool is currently disabled.'); |
|
46 | - } |
|
44 | + if (Offline::isOffline($this->getConfiguration())) { |
|
45 | + throw new EnvironmentException('The tool is currently disabled.'); |
|
46 | + } |
|
47 | 47 | |
48 | - return parent::setupEnvironment(); |
|
49 | - } |
|
48 | + return parent::setupEnvironment(); |
|
49 | + } |
|
50 | 50 | |
51 | - protected function cleanupEnvironment() |
|
52 | - { |
|
53 | - } |
|
51 | + protected function cleanupEnvironment() |
|
52 | + { |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * Main application logic |
|
57 | - */ |
|
58 | - protected function main() |
|
59 | - { |
|
60 | - $database = PdoDatabase::getDatabaseConnection($this->getConfiguration()); |
|
55 | + /** |
|
56 | + * Main application logic |
|
57 | + */ |
|
58 | + protected function main() |
|
59 | + { |
|
60 | + $database = PdoDatabase::getDatabaseConnection($this->getConfiguration()); |
|
61 | 61 | |
62 | - $this->setupHelpers($this->consoleTask, $this->getConfiguration(), $database); |
|
62 | + $this->setupHelpers($this->consoleTask, $this->getConfiguration(), $database); |
|
63 | 63 | |
64 | - // initialise a database transaction |
|
65 | - if (!$database->beginTransaction()) { |
|
66 | - throw new Exception('Failed to start transaction on primary database.'); |
|
67 | - } |
|
64 | + // initialise a database transaction |
|
65 | + if (!$database->beginTransaction()) { |
|
66 | + throw new Exception('Failed to start transaction on primary database.'); |
|
67 | + } |
|
68 | 68 | |
69 | - try { |
|
70 | - // run the task |
|
71 | - $this->consoleTask->execute(); |
|
69 | + try { |
|
70 | + // run the task |
|
71 | + $this->consoleTask->execute(); |
|
72 | 72 | |
73 | - if ($database->hasActiveTransaction()) { |
|
74 | - $database->commit(); |
|
75 | - } |
|
76 | - } |
|
77 | - finally { |
|
78 | - // Catch any hanging on transactions |
|
79 | - if ($database->hasActiveTransaction()) { |
|
80 | - $database->rollBack(); |
|
81 | - } |
|
82 | - } |
|
83 | - } |
|
73 | + if ($database->hasActiveTransaction()) { |
|
74 | + $database->commit(); |
|
75 | + } |
|
76 | + } |
|
77 | + finally { |
|
78 | + // Catch any hanging on transactions |
|
79 | + if ($database->hasActiveTransaction()) { |
|
80 | + $database->rollBack(); |
|
81 | + } |
|
82 | + } |
|
83 | + } |
|
84 | 84 | } |
85 | 85 | \ No newline at end of file |
@@ -15,9 +15,9 @@ |
||
15 | 15 | */ |
16 | 16 | function smarty_modifier_nlimplode($list, $conjunction = 'or') |
17 | 17 | { |
18 | - $last = array_pop($list); |
|
19 | - if ($list) { |
|
20 | - return implode(', ', $list) . ', ' . $conjunction . ' ' . $last; |
|
21 | - } |
|
22 | - return $last; |
|
18 | + $last = array_pop($list); |
|
19 | + if ($list) { |
|
20 | + return implode(', ', $list) . ', ' . $conjunction . ' ' . $last; |
|
21 | + } |
|
22 | + return $last; |
|
23 | 23 | } |
24 | 24 | \ No newline at end of file |
@@ -14,10 +14,10 @@ |
||
14 | 14 | |
15 | 15 | class PagePublicPrivacy extends PublicInterfacePageBase |
16 | 16 | { |
17 | - use PrivacyStatement; |
|
17 | + use PrivacyStatement; |
|
18 | 18 | |
19 | - protected function templatePath() |
|
20 | - { |
|
21 | - return 'markdown/public.tpl'; |
|
22 | - } |
|
19 | + protected function templatePath() |
|
20 | + { |
|
21 | + return 'markdown/public.tpl'; |
|
22 | + } |
|
23 | 23 | } |
@@ -14,10 +14,10 @@ |
||
14 | 14 | |
15 | 15 | class PagePrivacy extends InternalPageBase |
16 | 16 | { |
17 | - use PrivacyStatement; |
|
17 | + use PrivacyStatement; |
|
18 | 18 | |
19 | - protected function templatePath() |
|
20 | - { |
|
21 | - return 'markdown/private.tpl'; |
|
22 | - } |
|
19 | + protected function templatePath() |
|
20 | + { |
|
21 | + return 'markdown/private.tpl'; |
|
22 | + } |
|
23 | 23 | } |
@@ -18,47 +18,47 @@ |
||
18 | 18 | |
19 | 19 | class MarkdownRenderingHelper |
20 | 20 | { |
21 | - private $config = [ |
|
22 | - 'html_input' => 'escape', |
|
23 | - 'allow_unsafe_links' => false, |
|
24 | - 'max_nesting_level' => 10, |
|
25 | - 'table' => [ |
|
26 | - 'wrap' => [ |
|
27 | - 'enabled' => true, |
|
28 | - 'tag' => 'div', |
|
29 | - 'attributes' => ['class' => 'markdown-table'], |
|
30 | - ], |
|
31 | - 'alignment_attributes' => [ |
|
32 | - 'left' => ['class' => 'text-left'], |
|
33 | - 'center' => ['class' => 'text-center'], |
|
34 | - 'right' => ['class' => 'text-right'], |
|
35 | - ], |
|
36 | - ], |
|
37 | - ]; |
|
21 | + private $config = [ |
|
22 | + 'html_input' => 'escape', |
|
23 | + 'allow_unsafe_links' => false, |
|
24 | + 'max_nesting_level' => 10, |
|
25 | + 'table' => [ |
|
26 | + 'wrap' => [ |
|
27 | + 'enabled' => true, |
|
28 | + 'tag' => 'div', |
|
29 | + 'attributes' => ['class' => 'markdown-table'], |
|
30 | + ], |
|
31 | + 'alignment_attributes' => [ |
|
32 | + 'left' => ['class' => 'text-left'], |
|
33 | + 'center' => ['class' => 'text-center'], |
|
34 | + 'right' => ['class' => 'text-right'], |
|
35 | + ], |
|
36 | + ], |
|
37 | + ]; |
|
38 | 38 | |
39 | - private $blockRenderer; |
|
40 | - private $inlineRenderer; |
|
39 | + private $blockRenderer; |
|
40 | + private $inlineRenderer; |
|
41 | 41 | |
42 | - public function __construct() |
|
43 | - { |
|
44 | - $blockEnvironment = new Environment($this->config); |
|
45 | - $blockEnvironment->addExtension(new CommonMarkCoreExtension()); |
|
46 | - $blockEnvironment->addExtension(new AttributesExtension()); |
|
47 | - $blockEnvironment->addExtension(new TableExtension()); |
|
48 | - $this->blockRenderer = new MarkdownConverter($blockEnvironment); |
|
42 | + public function __construct() |
|
43 | + { |
|
44 | + $blockEnvironment = new Environment($this->config); |
|
45 | + $blockEnvironment->addExtension(new CommonMarkCoreExtension()); |
|
46 | + $blockEnvironment->addExtension(new AttributesExtension()); |
|
47 | + $blockEnvironment->addExtension(new TableExtension()); |
|
48 | + $this->blockRenderer = new MarkdownConverter($blockEnvironment); |
|
49 | 49 | |
50 | - $inlineEnvironment = new Environment($this->config); |
|
51 | - $inlineEnvironment->addExtension(new AttributesExtension()); |
|
52 | - $inlineEnvironment->addExtension(new InlinesOnlyExtension()); |
|
53 | - $this->inlineRenderer = new MarkdownConverter($inlineEnvironment); |
|
54 | - } |
|
50 | + $inlineEnvironment = new Environment($this->config); |
|
51 | + $inlineEnvironment->addExtension(new AttributesExtension()); |
|
52 | + $inlineEnvironment->addExtension(new InlinesOnlyExtension()); |
|
53 | + $this->inlineRenderer = new MarkdownConverter($inlineEnvironment); |
|
54 | + } |
|
55 | 55 | |
56 | - public function doRender(string $content): string { |
|
57 | - return $this->blockRenderer->convert($content)->getContent(); |
|
58 | - } |
|
56 | + public function doRender(string $content): string { |
|
57 | + return $this->blockRenderer->convert($content)->getContent(); |
|
58 | + } |
|
59 | 59 | |
60 | - public function doRenderInline(string $content): string { |
|
61 | - return $this->inlineRenderer->convert($content)->getContent(); |
|
62 | - } |
|
60 | + public function doRenderInline(string $content): string { |
|
61 | + return $this->inlineRenderer->convert($content)->getContent(); |
|
62 | + } |
|
63 | 63 | |
64 | 64 | } |
65 | 65 | \ No newline at end of file |
@@ -13,31 +13,31 @@ |
||
13 | 13 | |
14 | 14 | trait PrivacyStatement |
15 | 15 | { |
16 | - protected abstract function assign($name, $value); |
|
17 | - protected abstract function templatePath(); |
|
18 | - protected abstract function setTemplate($name); |
|
19 | - protected abstract function skipAlerts(); |
|
20 | - protected abstract function getSiteConfiguration(); |
|
16 | + protected abstract function assign($name, $value); |
|
17 | + protected abstract function templatePath(); |
|
18 | + protected abstract function setTemplate($name); |
|
19 | + protected abstract function skipAlerts(); |
|
20 | + protected abstract function getSiteConfiguration(); |
|
21 | 21 | |
22 | - protected function main() |
|
23 | - { |
|
24 | - $path = $this->getSiteConfiguration()->getPrivacyStatementPath(); |
|
22 | + protected function main() |
|
23 | + { |
|
24 | + $path = $this->getSiteConfiguration()->getPrivacyStatementPath(); |
|
25 | 25 | |
26 | - if ($path == null || !file_exists($path)) { |
|
27 | - if (!headers_sent()) { |
|
28 | - header('HTTP/1.1 404 Not Found'); |
|
29 | - } |
|
26 | + if ($path == null || !file_exists($path)) { |
|
27 | + if (!headers_sent()) { |
|
28 | + header('HTTP/1.1 404 Not Found'); |
|
29 | + } |
|
30 | 30 | |
31 | - $this->skipAlerts(); |
|
32 | - $this->setTemplate('404.tpl'); |
|
33 | - return; |
|
34 | - } |
|
31 | + $this->skipAlerts(); |
|
32 | + $this->setTemplate('404.tpl'); |
|
33 | + return; |
|
34 | + } |
|
35 | 35 | |
36 | - $markdown = file_get_contents($path); |
|
36 | + $markdown = file_get_contents($path); |
|
37 | 37 | |
38 | - $renderer = new MarkdownRenderingHelper(); |
|
39 | - $this->assign('content', $renderer->doRender($markdown)); |
|
38 | + $renderer = new MarkdownRenderingHelper(); |
|
39 | + $this->assign('content', $renderer->doRender($markdown)); |
|
40 | 40 | |
41 | - $this->setTemplate($this->templatePath()); |
|
42 | - } |
|
41 | + $this->setTemplate($this->templatePath()); |
|
42 | + } |
|
43 | 43 | } |
44 | 44 | \ No newline at end of file |
@@ -111,8 +111,7 @@ discard block |
||
111 | 111 | if ($amqpSiteConfig['tls']) { |
112 | 112 | $amqpConnectionConfig->setIsSecure(true); |
113 | 113 | $amqpConnectionConfig->setSslVerify(true); |
114 | - } |
|
115 | - else { |
|
114 | + } else { |
|
116 | 115 | $amqpConnectionConfig->setIsSecure(false); |
117 | 116 | } |
118 | 117 | |
@@ -268,8 +267,7 @@ discard block |
||
268 | 267 | { |
269 | 268 | if ($ban->getDuration() === null) { |
270 | 269 | $duration = "indefinitely"; |
271 | - } |
|
272 | - else { |
|
270 | + } else { |
|
273 | 271 | $duration = "until " . date("F j, Y, g:i a", $ban->getDuration()); |
274 | 272 | } |
275 | 273 | |
@@ -277,8 +275,7 @@ discard block |
||
277 | 275 | |
278 | 276 | if ($ban->getVisibility() == 'user') { |
279 | 277 | $this->send("Ban {$ban->getId()} set by {$username} for '{$ban->getReason()}' {$duration}"); |
280 | - } |
|
281 | - else { |
|
278 | + } else { |
|
282 | 279 | $this->send("Ban {$ban->getId()} set by {$username} {$duration}"); |
283 | 280 | } |
284 | 281 | } |
@@ -32,500 +32,500 @@ |
||
32 | 32 | */ |
33 | 33 | class IrcNotificationHelper |
34 | 34 | { |
35 | - /** @var bool $notificationsEnabled */ |
|
36 | - private $notificationsEnabled; |
|
37 | - /** @var User $currentUser */ |
|
38 | - private $currentUser; |
|
39 | - /** @var string $instanceName */ |
|
40 | - private $instanceName; |
|
41 | - /** @var string */ |
|
42 | - private $baseUrl; |
|
43 | - /** @var SiteConfiguration */ |
|
44 | - private $siteConfiguration; |
|
45 | - /** @var PdoDatabase */ |
|
46 | - private $primaryDatabase; |
|
47 | - |
|
48 | - /** |
|
49 | - * IrcNotificationHelper constructor. |
|
50 | - * |
|
51 | - * @param SiteConfiguration $siteConfiguration |
|
52 | - * @param PdoDatabase $primaryDatabase |
|
53 | - */ |
|
54 | - public function __construct( |
|
55 | - SiteConfiguration $siteConfiguration, |
|
56 | - PdoDatabase $primaryDatabase |
|
57 | - ) { |
|
58 | - $this->siteConfiguration = $siteConfiguration; |
|
59 | - $this->primaryDatabase = $primaryDatabase; |
|
60 | - |
|
61 | - $this->notificationsEnabled = $siteConfiguration->getIrcNotificationsEnabled(); |
|
62 | - $this->instanceName = $siteConfiguration->getIrcNotificationsInstance(); |
|
63 | - $this->baseUrl = $siteConfiguration->getBaseUrl(); |
|
64 | - |
|
65 | - $this->currentUser = User::getCurrent($primaryDatabase); |
|
66 | - } |
|
67 | - |
|
68 | - /** |
|
69 | - * Send a notification |
|
70 | - * |
|
71 | - * This method does some *basic* filtering for IRC safety, and then delivers the message to an AMQP queue manager. |
|
72 | - * It is the responsibility of the queue manager and consumer to handle message delivery to IRC, message routing to |
|
73 | - * the correct channel, and message expiry. |
|
74 | - * |
|
75 | - * It's also arguably the responsibility of the consumer to ensure the message is *safe* for delivery to IRC. |
|
76 | - * |
|
77 | - * As of Feb 2022, the message consumer is stwalkerster's IRC bot Helpmebot. |
|
78 | - * |
|
79 | - * @param string $message The text to send |
|
80 | - */ |
|
81 | - protected function send($message) |
|
82 | - { |
|
83 | - $instanceName = $this->instanceName; |
|
84 | - |
|
85 | - if (!$this->notificationsEnabled) { |
|
86 | - return; |
|
87 | - } |
|
88 | - |
|
89 | - $blacklist = array("DCC", "CCTP", "PRIVMSG"); |
|
90 | - $message = str_replace($blacklist, "(IRC Blacklist)", $message); // Lets stop DCC etc |
|
91 | - |
|
92 | - $msg = $message; |
|
93 | - if ($instanceName !== null && mb_strlen($instanceName) > 0) { |
|
94 | - $msg = IrcColourCode::RESET . IrcColourCode::BOLD . "[$instanceName]" . IrcColourCode::RESET . ": $message"; |
|
95 | - } |
|
96 | - |
|
97 | - // FIXME: domains! |
|
98 | - /** @var Domain $domain */ |
|
99 | - $domain = Domain::getById(1, $this->primaryDatabase); |
|
100 | - |
|
101 | - try { |
|
102 | - $amqpSiteConfig = $this->siteConfiguration->getAmqpConfiguration(); |
|
103 | - |
|
104 | - $amqpConnectionConfig = new AMQPConnectionConfig(); |
|
105 | - $amqpConnectionConfig->setHost($amqpSiteConfig['host']); |
|
106 | - $amqpConnectionConfig->setPort($amqpSiteConfig['port']); |
|
107 | - $amqpConnectionConfig->setUser($amqpSiteConfig['user']); |
|
108 | - $amqpConnectionConfig->setPassword($amqpSiteConfig['password']); |
|
109 | - $amqpConnectionConfig->setVhost($amqpSiteConfig['vhost']); |
|
110 | - |
|
111 | - if ($amqpSiteConfig['tls']) { |
|
112 | - $amqpConnectionConfig->setIsSecure(true); |
|
113 | - $amqpConnectionConfig->setSslVerify(true); |
|
114 | - } |
|
115 | - else { |
|
116 | - $amqpConnectionConfig->setIsSecure(false); |
|
117 | - } |
|
118 | - |
|
119 | - $connection = AMQPConnectionFactory::create($amqpConnectionConfig); |
|
120 | - $channel = $connection->channel(); |
|
121 | - |
|
122 | - $msg = new AMQPMessage(substr($msg, 0, 512)); |
|
123 | - $msg->set('user_id', $amqpSiteConfig['user']); |
|
124 | - $msg->set('app_id', $this->siteConfiguration->getUserAgent()); |
|
125 | - $msg->set('content_type', 'text/plain'); |
|
35 | + /** @var bool $notificationsEnabled */ |
|
36 | + private $notificationsEnabled; |
|
37 | + /** @var User $currentUser */ |
|
38 | + private $currentUser; |
|
39 | + /** @var string $instanceName */ |
|
40 | + private $instanceName; |
|
41 | + /** @var string */ |
|
42 | + private $baseUrl; |
|
43 | + /** @var SiteConfiguration */ |
|
44 | + private $siteConfiguration; |
|
45 | + /** @var PdoDatabase */ |
|
46 | + private $primaryDatabase; |
|
47 | + |
|
48 | + /** |
|
49 | + * IrcNotificationHelper constructor. |
|
50 | + * |
|
51 | + * @param SiteConfiguration $siteConfiguration |
|
52 | + * @param PdoDatabase $primaryDatabase |
|
53 | + */ |
|
54 | + public function __construct( |
|
55 | + SiteConfiguration $siteConfiguration, |
|
56 | + PdoDatabase $primaryDatabase |
|
57 | + ) { |
|
58 | + $this->siteConfiguration = $siteConfiguration; |
|
59 | + $this->primaryDatabase = $primaryDatabase; |
|
60 | + |
|
61 | + $this->notificationsEnabled = $siteConfiguration->getIrcNotificationsEnabled(); |
|
62 | + $this->instanceName = $siteConfiguration->getIrcNotificationsInstance(); |
|
63 | + $this->baseUrl = $siteConfiguration->getBaseUrl(); |
|
64 | + |
|
65 | + $this->currentUser = User::getCurrent($primaryDatabase); |
|
66 | + } |
|
67 | + |
|
68 | + /** |
|
69 | + * Send a notification |
|
70 | + * |
|
71 | + * This method does some *basic* filtering for IRC safety, and then delivers the message to an AMQP queue manager. |
|
72 | + * It is the responsibility of the queue manager and consumer to handle message delivery to IRC, message routing to |
|
73 | + * the correct channel, and message expiry. |
|
74 | + * |
|
75 | + * It's also arguably the responsibility of the consumer to ensure the message is *safe* for delivery to IRC. |
|
76 | + * |
|
77 | + * As of Feb 2022, the message consumer is stwalkerster's IRC bot Helpmebot. |
|
78 | + * |
|
79 | + * @param string $message The text to send |
|
80 | + */ |
|
81 | + protected function send($message) |
|
82 | + { |
|
83 | + $instanceName = $this->instanceName; |
|
84 | + |
|
85 | + if (!$this->notificationsEnabled) { |
|
86 | + return; |
|
87 | + } |
|
88 | + |
|
89 | + $blacklist = array("DCC", "CCTP", "PRIVMSG"); |
|
90 | + $message = str_replace($blacklist, "(IRC Blacklist)", $message); // Lets stop DCC etc |
|
91 | + |
|
92 | + $msg = $message; |
|
93 | + if ($instanceName !== null && mb_strlen($instanceName) > 0) { |
|
94 | + $msg = IrcColourCode::RESET . IrcColourCode::BOLD . "[$instanceName]" . IrcColourCode::RESET . ": $message"; |
|
95 | + } |
|
96 | + |
|
97 | + // FIXME: domains! |
|
98 | + /** @var Domain $domain */ |
|
99 | + $domain = Domain::getById(1, $this->primaryDatabase); |
|
100 | + |
|
101 | + try { |
|
102 | + $amqpSiteConfig = $this->siteConfiguration->getAmqpConfiguration(); |
|
103 | + |
|
104 | + $amqpConnectionConfig = new AMQPConnectionConfig(); |
|
105 | + $amqpConnectionConfig->setHost($amqpSiteConfig['host']); |
|
106 | + $amqpConnectionConfig->setPort($amqpSiteConfig['port']); |
|
107 | + $amqpConnectionConfig->setUser($amqpSiteConfig['user']); |
|
108 | + $amqpConnectionConfig->setPassword($amqpSiteConfig['password']); |
|
109 | + $amqpConnectionConfig->setVhost($amqpSiteConfig['vhost']); |
|
110 | + |
|
111 | + if ($amqpSiteConfig['tls']) { |
|
112 | + $amqpConnectionConfig->setIsSecure(true); |
|
113 | + $amqpConnectionConfig->setSslVerify(true); |
|
114 | + } |
|
115 | + else { |
|
116 | + $amqpConnectionConfig->setIsSecure(false); |
|
117 | + } |
|
118 | + |
|
119 | + $connection = AMQPConnectionFactory::create($amqpConnectionConfig); |
|
120 | + $channel = $connection->channel(); |
|
121 | + |
|
122 | + $msg = new AMQPMessage(substr($msg, 0, 512)); |
|
123 | + $msg->set('user_id', $amqpSiteConfig['user']); |
|
124 | + $msg->set('app_id', $this->siteConfiguration->getUserAgent()); |
|
125 | + $msg->set('content_type', 'text/plain'); |
|
126 | 126 | |
127 | - $channel->basic_publish($msg, $amqpSiteConfig['exchange'], $domain->getNotificationTarget()); |
|
128 | - $channel->close(); |
|
129 | - } |
|
130 | - catch (Exception $ex) { |
|
131 | - // OK, so we failed to send the notification - that db might be down? |
|
132 | - // This is non-critical, so silently fail. |
|
133 | - ExceptionHandler::logExceptionToDisk($ex, $this->siteConfiguration); |
|
134 | - |
|
135 | - // Disable notifications for remainder of request. |
|
136 | - $this->notificationsEnabled = false; |
|
137 | - } |
|
138 | - } |
|
139 | - |
|
140 | - #region user management |
|
141 | - |
|
142 | - /** |
|
143 | - * send a new user notification |
|
144 | - * |
|
145 | - * @param User $user |
|
146 | - */ |
|
147 | - public function userNew(User $user) |
|
148 | - { |
|
149 | - $this->send("New user: {$user->getUsername()}"); |
|
150 | - } |
|
151 | - |
|
152 | - /** |
|
153 | - * send an approved notification |
|
154 | - * |
|
155 | - * @param User $user |
|
156 | - */ |
|
157 | - public function userApproved(User $user) |
|
158 | - { |
|
159 | - $this->send("{$user->getUsername()} approved by " . $this->currentUser->getUsername()); |
|
160 | - } |
|
161 | - |
|
162 | - /** |
|
163 | - * send a deactivated notification |
|
164 | - * |
|
165 | - * @param User $user |
|
166 | - */ |
|
167 | - public function userDeactivated(User $user) |
|
168 | - { |
|
169 | - $this->send("{$user->getUsername()} deactivated by " . $this->currentUser->getUsername()); |
|
170 | - } |
|
171 | - |
|
172 | - /** |
|
173 | - * Send a preference change notification |
|
174 | - * |
|
175 | - * @param User $user |
|
176 | - */ |
|
177 | - public function userPrefChange(User $user) |
|
178 | - { |
|
179 | - $this->send("{$user->getUsername()}'s preferences were changed by " . $this->currentUser->getUsername()); |
|
180 | - } |
|
181 | - |
|
182 | - /** |
|
183 | - * Send a user renamed notification |
|
184 | - * |
|
185 | - * @param User $user |
|
186 | - * @param string $old |
|
187 | - */ |
|
188 | - public function userRenamed(User $user, $old) |
|
189 | - { |
|
190 | - $this->send($this->currentUser->getUsername() . " renamed $old to {$user->getUsername()}"); |
|
191 | - } |
|
192 | - |
|
193 | - /** |
|
194 | - * @param User $user |
|
195 | - * @param string $reason |
|
196 | - */ |
|
197 | - public function userRolesEdited(User $user, $reason) |
|
198 | - { |
|
199 | - $currentUser = $this->currentUser->getUsername(); |
|
200 | - $this->send("Active roles for {$user->getUsername()} changed by " . $currentUser . " ($reason)"); |
|
201 | - } |
|
202 | - |
|
203 | - #endregion |
|
204 | - |
|
205 | - #region Site Notice |
|
206 | - |
|
207 | - /** |
|
208 | - * Summary of siteNoticeEdited |
|
209 | - */ |
|
210 | - public function siteNoticeEdited() |
|
211 | - { |
|
212 | - $this->send("Site notice edited by " . $this->currentUser->getUsername()); |
|
213 | - } |
|
214 | - #endregion |
|
215 | - |
|
216 | - #region Welcome Templates |
|
217 | - /** |
|
218 | - * Summary of welcomeTemplateCreated |
|
219 | - * |
|
220 | - * @param WelcomeTemplate $template |
|
221 | - */ |
|
222 | - public function welcomeTemplateCreated(WelcomeTemplate $template) |
|
223 | - { |
|
224 | - $this->send("Welcome template {$template->getId()} created by " . $this->currentUser->getUsername()); |
|
225 | - } |
|
226 | - |
|
227 | - /** |
|
228 | - * Summary of welcomeTemplateDeleted |
|
229 | - * |
|
230 | - * @param int $templateid |
|
231 | - */ |
|
232 | - public function welcomeTemplateDeleted($templateid) |
|
233 | - { |
|
234 | - $this->send("Welcome template {$templateid} deleted by " . $this->currentUser->getUsername()); |
|
235 | - } |
|
236 | - |
|
237 | - /** |
|
238 | - * Summary of welcomeTemplateEdited |
|
239 | - * |
|
240 | - * @param WelcomeTemplate $template |
|
241 | - */ |
|
242 | - public function welcomeTemplateEdited(WelcomeTemplate $template) |
|
243 | - { |
|
244 | - $this->send("Welcome template {$template->getId()} edited by " . $this->currentUser->getUsername()); |
|
245 | - } |
|
246 | - |
|
247 | - #endregion |
|
248 | - |
|
249 | - #region bans |
|
250 | - /** |
|
251 | - * Summary of banned |
|
252 | - * |
|
253 | - * @param Ban $ban |
|
254 | - */ |
|
255 | - public function banned(Ban $ban) |
|
256 | - { |
|
257 | - if ($ban->getDuration() === null) { |
|
258 | - $duration = "indefinitely"; |
|
259 | - } |
|
260 | - else { |
|
261 | - $duration = "until " . date("F j, Y, g:i a", $ban->getDuration()); |
|
262 | - } |
|
263 | - |
|
264 | - $username = $this->currentUser->getUsername(); |
|
265 | - |
|
266 | - if ($ban->getVisibility() == 'user') { |
|
267 | - $this->send("Ban {$ban->getId()} set by {$username} for '{$ban->getReason()}' {$duration}"); |
|
268 | - } |
|
269 | - else { |
|
270 | - $this->send("Ban {$ban->getId()} set by {$username} {$duration}"); |
|
271 | - } |
|
272 | - } |
|
273 | - |
|
274 | - /** |
|
275 | - * Summary of unbanned |
|
276 | - * |
|
277 | - * @param Ban $ban |
|
278 | - * @param string $unbanReason |
|
279 | - */ |
|
280 | - public function unbanned(Ban $ban, $unbanReason) |
|
281 | - { |
|
282 | - $this->send("Ban {$ban->getId()} unbanned by " . $this->currentUser |
|
283 | - ->getUsername() . " (" . $unbanReason . ")"); |
|
284 | - } |
|
285 | - |
|
286 | - #endregion |
|
287 | - |
|
288 | - #region request management |
|
289 | - |
|
290 | - /** |
|
291 | - * Summary of requestReceived |
|
292 | - * |
|
293 | - * @param Request $request |
|
294 | - */ |
|
295 | - public function requestReceived(Request $request) |
|
296 | - { |
|
297 | - $this->send( |
|
298 | - IrcColourCode::DARK_GREY . "[[" |
|
299 | - . IrcColourCode::DARK_GREEN . "acc:" |
|
300 | - . IrcColourCode::ORANGE . $request->getId() |
|
301 | - . IrcColourCode::DARK_GREY . "]]" |
|
302 | - . IrcColourCode::RED . " N " |
|
303 | - . IrcColourCode::DARK_BLUE . $this->baseUrl . "/internal.php/viewRequest?id={$request->getId()} " |
|
304 | - . IrcColourCode::DARK_RED . "* " |
|
305 | - . IrcColourCode::DARK_GREEN . $request->getName() |
|
306 | - . IrcColourCode::DARK_RED . " * " |
|
307 | - . IrcColourCode::RESET |
|
308 | - ); |
|
309 | - } |
|
310 | - |
|
311 | - /** |
|
312 | - * Summary of requestDeferred |
|
313 | - * |
|
314 | - * @param Request $request |
|
315 | - */ |
|
316 | - public function requestDeferred(Request $request) |
|
317 | - { |
|
318 | - /** @var RequestQueue $queue */ |
|
319 | - $queue = RequestQueue::getById($request->getQueue(), $request->getDatabase()); |
|
320 | - |
|
321 | - $deferTo = $queue->getDisplayName(); |
|
322 | - $username = $this->currentUser->getUsername(); |
|
323 | - |
|
324 | - $this->send("Request {$request->getId()} ({$request->getName()}) deferred to {$deferTo} by {$username}"); |
|
325 | - } |
|
326 | - |
|
327 | - /** |
|
328 | - * |
|
329 | - * Summary of requestDeferredWithMail |
|
330 | - * |
|
331 | - * @param Request $request |
|
332 | - */ |
|
333 | - public function requestDeferredWithMail(Request $request) |
|
334 | - { |
|
335 | - /** @var RequestQueue $queue */ |
|
336 | - $queue = RequestQueue::getById($request->getQueue(), $request->getDatabase()); |
|
337 | - |
|
338 | - $deferTo = $queue->getDisplayName(); |
|
339 | - $username = $this->currentUser->getUsername(); |
|
340 | - $id = $request->getId(); |
|
341 | - $name = $request->getName(); |
|
342 | - |
|
343 | - $this->send("Request {$id} ({$name}) deferred to {$deferTo} with an email by {$username}"); |
|
344 | - } |
|
345 | - |
|
346 | - /** |
|
347 | - * Summary of requestClosed |
|
348 | - * |
|
349 | - * @param Request $request |
|
350 | - * @param string $closetype |
|
351 | - */ |
|
352 | - public function requestClosed(Request $request, $closetype) |
|
353 | - { |
|
354 | - $username = $this->currentUser->getUsername(); |
|
355 | - |
|
356 | - $this->send("Request {$request->getId()} ({$request->getName()}) closed ($closetype) by {$username}"); |
|
357 | - } |
|
358 | - |
|
359 | - /** |
|
360 | - * Summary of requestClosed |
|
361 | - * |
|
362 | - * @param Request $request |
|
363 | - * @param string $closetype |
|
364 | - */ |
|
365 | - public function requestCloseQueued(Request $request, $closetype) |
|
366 | - { |
|
367 | - $username = $this->currentUser->getUsername(); |
|
368 | - |
|
369 | - $this->send("Request {$request->getId()} ({$request->getName()}) queued for creation ($closetype) by {$username}"); |
|
370 | - } |
|
371 | - |
|
372 | - /** |
|
373 | - * Summary of requestClosed |
|
374 | - * |
|
375 | - * @param Request $request |
|
376 | - * @param User $triggerUser |
|
377 | - */ |
|
378 | - public function requestCreationFailed(Request $request, User $triggerUser) |
|
379 | - { |
|
380 | - $this->send("Request {$request->getId()} ({$request->getName()}) failed auto-creation for {$triggerUser->getUsername()}, and was sent to the hospital queue."); |
|
381 | - } |
|
382 | - |
|
383 | - /** |
|
384 | - * @param Request $request |
|
385 | - * @param User $triggerUser |
|
386 | - */ |
|
387 | - public function requestWelcomeFailed(Request $request, User $triggerUser) |
|
388 | - { |
|
389 | - $this->send("Request {$request->getId()} ({$request->getName()}) failed welcome for {$triggerUser->getUsername()}."); |
|
390 | - } |
|
391 | - |
|
392 | - /** |
|
393 | - * Summary of sentMail |
|
394 | - * |
|
395 | - * @param Request $request |
|
396 | - */ |
|
397 | - public function sentMail(Request $request) |
|
398 | - { |
|
399 | - $this->send($this->currentUser->getUsername() |
|
400 | - . " sent an email related to Request {$request->getId()} ({$request->getName()})"); |
|
401 | - } |
|
402 | - |
|
403 | - #endregion |
|
404 | - |
|
405 | - #region reservations |
|
406 | - |
|
407 | - /** |
|
408 | - * Summary of requestReserved |
|
409 | - * |
|
410 | - * @param Request $request |
|
411 | - */ |
|
412 | - public function requestReserved(Request $request) |
|
413 | - { |
|
414 | - $username = $this->currentUser->getUsername(); |
|
415 | - |
|
416 | - $this->send("Request {$request->getId()} ({$request->getName()}) reserved by {$username}"); |
|
417 | - } |
|
418 | - |
|
419 | - /** |
|
420 | - * Summary of requestReserveBroken |
|
421 | - * |
|
422 | - * @param Request $request |
|
423 | - */ |
|
424 | - public function requestReserveBroken(Request $request) |
|
425 | - { |
|
426 | - $username = $this->currentUser->getUsername(); |
|
427 | - |
|
428 | - $this->send("Reservation on request {$request->getId()} ({$request->getName()}) broken by {$username}"); |
|
429 | - } |
|
430 | - |
|
431 | - /** |
|
432 | - * Summary of requestUnreserved |
|
433 | - * |
|
434 | - * @param Request $request |
|
435 | - */ |
|
436 | - public function requestUnreserved(Request $request) |
|
437 | - { |
|
438 | - $this->send("Request {$request->getId()} ({$request->getName()}) is no longer being handled."); |
|
439 | - } |
|
440 | - |
|
441 | - /** |
|
442 | - * Summary of requestReservationSent |
|
443 | - * |
|
444 | - * @param Request $request |
|
445 | - * @param User $target |
|
446 | - */ |
|
447 | - public function requestReservationSent(Request $request, User $target) |
|
448 | - { |
|
449 | - $username = $this->currentUser->getUsername(); |
|
450 | - |
|
451 | - $this->send( |
|
452 | - "Reservation of request {$request->getId()} ({$request->getName()}) sent to {$target->getUsername()} by " |
|
453 | - . $username); |
|
454 | - } |
|
455 | - |
|
456 | - #endregion |
|
457 | - |
|
458 | - #region comments |
|
459 | - |
|
460 | - /** |
|
461 | - * Summary of commentCreated |
|
462 | - * |
|
463 | - * @param Comment $comment |
|
464 | - * @param Request $request |
|
465 | - */ |
|
466 | - public function commentCreated(Comment $comment, Request $request) |
|
467 | - { |
|
468 | - $username = $this->currentUser->getUsername(); |
|
469 | - switch ($comment->getVisibility()) { |
|
470 | - case 'admin': |
|
471 | - $visibility = " with visibility 'admin'"; |
|
472 | - break; |
|
473 | - case 'checkuser': |
|
474 | - $visibility = " with visibility 'checkuser'"; |
|
475 | - break; |
|
476 | - default: |
|
477 | - $visibility = ""; |
|
478 | - break; |
|
479 | - } |
|
480 | - |
|
481 | - $this->send("{$username} posted a comment on request {$request->getId()} ({$request->getName()}){$visibility}"); |
|
482 | - } |
|
483 | - |
|
484 | - /** |
|
485 | - * Summary of commentEdited |
|
486 | - * |
|
487 | - * @param Comment $comment |
|
488 | - * @param Request $request |
|
489 | - */ |
|
490 | - public function commentEdited(Comment $comment, Request $request) |
|
491 | - { |
|
492 | - $username = $this->currentUser->getUsername(); |
|
493 | - |
|
494 | - $this->send(<<<TAG |
|
127 | + $channel->basic_publish($msg, $amqpSiteConfig['exchange'], $domain->getNotificationTarget()); |
|
128 | + $channel->close(); |
|
129 | + } |
|
130 | + catch (Exception $ex) { |
|
131 | + // OK, so we failed to send the notification - that db might be down? |
|
132 | + // This is non-critical, so silently fail. |
|
133 | + ExceptionHandler::logExceptionToDisk($ex, $this->siteConfiguration); |
|
134 | + |
|
135 | + // Disable notifications for remainder of request. |
|
136 | + $this->notificationsEnabled = false; |
|
137 | + } |
|
138 | + } |
|
139 | + |
|
140 | + #region user management |
|
141 | + |
|
142 | + /** |
|
143 | + * send a new user notification |
|
144 | + * |
|
145 | + * @param User $user |
|
146 | + */ |
|
147 | + public function userNew(User $user) |
|
148 | + { |
|
149 | + $this->send("New user: {$user->getUsername()}"); |
|
150 | + } |
|
151 | + |
|
152 | + /** |
|
153 | + * send an approved notification |
|
154 | + * |
|
155 | + * @param User $user |
|
156 | + */ |
|
157 | + public function userApproved(User $user) |
|
158 | + { |
|
159 | + $this->send("{$user->getUsername()} approved by " . $this->currentUser->getUsername()); |
|
160 | + } |
|
161 | + |
|
162 | + /** |
|
163 | + * send a deactivated notification |
|
164 | + * |
|
165 | + * @param User $user |
|
166 | + */ |
|
167 | + public function userDeactivated(User $user) |
|
168 | + { |
|
169 | + $this->send("{$user->getUsername()} deactivated by " . $this->currentUser->getUsername()); |
|
170 | + } |
|
171 | + |
|
172 | + /** |
|
173 | + * Send a preference change notification |
|
174 | + * |
|
175 | + * @param User $user |
|
176 | + */ |
|
177 | + public function userPrefChange(User $user) |
|
178 | + { |
|
179 | + $this->send("{$user->getUsername()}'s preferences were changed by " . $this->currentUser->getUsername()); |
|
180 | + } |
|
181 | + |
|
182 | + /** |
|
183 | + * Send a user renamed notification |
|
184 | + * |
|
185 | + * @param User $user |
|
186 | + * @param string $old |
|
187 | + */ |
|
188 | + public function userRenamed(User $user, $old) |
|
189 | + { |
|
190 | + $this->send($this->currentUser->getUsername() . " renamed $old to {$user->getUsername()}"); |
|
191 | + } |
|
192 | + |
|
193 | + /** |
|
194 | + * @param User $user |
|
195 | + * @param string $reason |
|
196 | + */ |
|
197 | + public function userRolesEdited(User $user, $reason) |
|
198 | + { |
|
199 | + $currentUser = $this->currentUser->getUsername(); |
|
200 | + $this->send("Active roles for {$user->getUsername()} changed by " . $currentUser . " ($reason)"); |
|
201 | + } |
|
202 | + |
|
203 | + #endregion |
|
204 | + |
|
205 | + #region Site Notice |
|
206 | + |
|
207 | + /** |
|
208 | + * Summary of siteNoticeEdited |
|
209 | + */ |
|
210 | + public function siteNoticeEdited() |
|
211 | + { |
|
212 | + $this->send("Site notice edited by " . $this->currentUser->getUsername()); |
|
213 | + } |
|
214 | + #endregion |
|
215 | + |
|
216 | + #region Welcome Templates |
|
217 | + /** |
|
218 | + * Summary of welcomeTemplateCreated |
|
219 | + * |
|
220 | + * @param WelcomeTemplate $template |
|
221 | + */ |
|
222 | + public function welcomeTemplateCreated(WelcomeTemplate $template) |
|
223 | + { |
|
224 | + $this->send("Welcome template {$template->getId()} created by " . $this->currentUser->getUsername()); |
|
225 | + } |
|
226 | + |
|
227 | + /** |
|
228 | + * Summary of welcomeTemplateDeleted |
|
229 | + * |
|
230 | + * @param int $templateid |
|
231 | + */ |
|
232 | + public function welcomeTemplateDeleted($templateid) |
|
233 | + { |
|
234 | + $this->send("Welcome template {$templateid} deleted by " . $this->currentUser->getUsername()); |
|
235 | + } |
|
236 | + |
|
237 | + /** |
|
238 | + * Summary of welcomeTemplateEdited |
|
239 | + * |
|
240 | + * @param WelcomeTemplate $template |
|
241 | + */ |
|
242 | + public function welcomeTemplateEdited(WelcomeTemplate $template) |
|
243 | + { |
|
244 | + $this->send("Welcome template {$template->getId()} edited by " . $this->currentUser->getUsername()); |
|
245 | + } |
|
246 | + |
|
247 | + #endregion |
|
248 | + |
|
249 | + #region bans |
|
250 | + /** |
|
251 | + * Summary of banned |
|
252 | + * |
|
253 | + * @param Ban $ban |
|
254 | + */ |
|
255 | + public function banned(Ban $ban) |
|
256 | + { |
|
257 | + if ($ban->getDuration() === null) { |
|
258 | + $duration = "indefinitely"; |
|
259 | + } |
|
260 | + else { |
|
261 | + $duration = "until " . date("F j, Y, g:i a", $ban->getDuration()); |
|
262 | + } |
|
263 | + |
|
264 | + $username = $this->currentUser->getUsername(); |
|
265 | + |
|
266 | + if ($ban->getVisibility() == 'user') { |
|
267 | + $this->send("Ban {$ban->getId()} set by {$username} for '{$ban->getReason()}' {$duration}"); |
|
268 | + } |
|
269 | + else { |
|
270 | + $this->send("Ban {$ban->getId()} set by {$username} {$duration}"); |
|
271 | + } |
|
272 | + } |
|
273 | + |
|
274 | + /** |
|
275 | + * Summary of unbanned |
|
276 | + * |
|
277 | + * @param Ban $ban |
|
278 | + * @param string $unbanReason |
|
279 | + */ |
|
280 | + public function unbanned(Ban $ban, $unbanReason) |
|
281 | + { |
|
282 | + $this->send("Ban {$ban->getId()} unbanned by " . $this->currentUser |
|
283 | + ->getUsername() . " (" . $unbanReason . ")"); |
|
284 | + } |
|
285 | + |
|
286 | + #endregion |
|
287 | + |
|
288 | + #region request management |
|
289 | + |
|
290 | + /** |
|
291 | + * Summary of requestReceived |
|
292 | + * |
|
293 | + * @param Request $request |
|
294 | + */ |
|
295 | + public function requestReceived(Request $request) |
|
296 | + { |
|
297 | + $this->send( |
|
298 | + IrcColourCode::DARK_GREY . "[[" |
|
299 | + . IrcColourCode::DARK_GREEN . "acc:" |
|
300 | + . IrcColourCode::ORANGE . $request->getId() |
|
301 | + . IrcColourCode::DARK_GREY . "]]" |
|
302 | + . IrcColourCode::RED . " N " |
|
303 | + . IrcColourCode::DARK_BLUE . $this->baseUrl . "/internal.php/viewRequest?id={$request->getId()} " |
|
304 | + . IrcColourCode::DARK_RED . "* " |
|
305 | + . IrcColourCode::DARK_GREEN . $request->getName() |
|
306 | + . IrcColourCode::DARK_RED . " * " |
|
307 | + . IrcColourCode::RESET |
|
308 | + ); |
|
309 | + } |
|
310 | + |
|
311 | + /** |
|
312 | + * Summary of requestDeferred |
|
313 | + * |
|
314 | + * @param Request $request |
|
315 | + */ |
|
316 | + public function requestDeferred(Request $request) |
|
317 | + { |
|
318 | + /** @var RequestQueue $queue */ |
|
319 | + $queue = RequestQueue::getById($request->getQueue(), $request->getDatabase()); |
|
320 | + |
|
321 | + $deferTo = $queue->getDisplayName(); |
|
322 | + $username = $this->currentUser->getUsername(); |
|
323 | + |
|
324 | + $this->send("Request {$request->getId()} ({$request->getName()}) deferred to {$deferTo} by {$username}"); |
|
325 | + } |
|
326 | + |
|
327 | + /** |
|
328 | + * |
|
329 | + * Summary of requestDeferredWithMail |
|
330 | + * |
|
331 | + * @param Request $request |
|
332 | + */ |
|
333 | + public function requestDeferredWithMail(Request $request) |
|
334 | + { |
|
335 | + /** @var RequestQueue $queue */ |
|
336 | + $queue = RequestQueue::getById($request->getQueue(), $request->getDatabase()); |
|
337 | + |
|
338 | + $deferTo = $queue->getDisplayName(); |
|
339 | + $username = $this->currentUser->getUsername(); |
|
340 | + $id = $request->getId(); |
|
341 | + $name = $request->getName(); |
|
342 | + |
|
343 | + $this->send("Request {$id} ({$name}) deferred to {$deferTo} with an email by {$username}"); |
|
344 | + } |
|
345 | + |
|
346 | + /** |
|
347 | + * Summary of requestClosed |
|
348 | + * |
|
349 | + * @param Request $request |
|
350 | + * @param string $closetype |
|
351 | + */ |
|
352 | + public function requestClosed(Request $request, $closetype) |
|
353 | + { |
|
354 | + $username = $this->currentUser->getUsername(); |
|
355 | + |
|
356 | + $this->send("Request {$request->getId()} ({$request->getName()}) closed ($closetype) by {$username}"); |
|
357 | + } |
|
358 | + |
|
359 | + /** |
|
360 | + * Summary of requestClosed |
|
361 | + * |
|
362 | + * @param Request $request |
|
363 | + * @param string $closetype |
|
364 | + */ |
|
365 | + public function requestCloseQueued(Request $request, $closetype) |
|
366 | + { |
|
367 | + $username = $this->currentUser->getUsername(); |
|
368 | + |
|
369 | + $this->send("Request {$request->getId()} ({$request->getName()}) queued for creation ($closetype) by {$username}"); |
|
370 | + } |
|
371 | + |
|
372 | + /** |
|
373 | + * Summary of requestClosed |
|
374 | + * |
|
375 | + * @param Request $request |
|
376 | + * @param User $triggerUser |
|
377 | + */ |
|
378 | + public function requestCreationFailed(Request $request, User $triggerUser) |
|
379 | + { |
|
380 | + $this->send("Request {$request->getId()} ({$request->getName()}) failed auto-creation for {$triggerUser->getUsername()}, and was sent to the hospital queue."); |
|
381 | + } |
|
382 | + |
|
383 | + /** |
|
384 | + * @param Request $request |
|
385 | + * @param User $triggerUser |
|
386 | + */ |
|
387 | + public function requestWelcomeFailed(Request $request, User $triggerUser) |
|
388 | + { |
|
389 | + $this->send("Request {$request->getId()} ({$request->getName()}) failed welcome for {$triggerUser->getUsername()}."); |
|
390 | + } |
|
391 | + |
|
392 | + /** |
|
393 | + * Summary of sentMail |
|
394 | + * |
|
395 | + * @param Request $request |
|
396 | + */ |
|
397 | + public function sentMail(Request $request) |
|
398 | + { |
|
399 | + $this->send($this->currentUser->getUsername() |
|
400 | + . " sent an email related to Request {$request->getId()} ({$request->getName()})"); |
|
401 | + } |
|
402 | + |
|
403 | + #endregion |
|
404 | + |
|
405 | + #region reservations |
|
406 | + |
|
407 | + /** |
|
408 | + * Summary of requestReserved |
|
409 | + * |
|
410 | + * @param Request $request |
|
411 | + */ |
|
412 | + public function requestReserved(Request $request) |
|
413 | + { |
|
414 | + $username = $this->currentUser->getUsername(); |
|
415 | + |
|
416 | + $this->send("Request {$request->getId()} ({$request->getName()}) reserved by {$username}"); |
|
417 | + } |
|
418 | + |
|
419 | + /** |
|
420 | + * Summary of requestReserveBroken |
|
421 | + * |
|
422 | + * @param Request $request |
|
423 | + */ |
|
424 | + public function requestReserveBroken(Request $request) |
|
425 | + { |
|
426 | + $username = $this->currentUser->getUsername(); |
|
427 | + |
|
428 | + $this->send("Reservation on request {$request->getId()} ({$request->getName()}) broken by {$username}"); |
|
429 | + } |
|
430 | + |
|
431 | + /** |
|
432 | + * Summary of requestUnreserved |
|
433 | + * |
|
434 | + * @param Request $request |
|
435 | + */ |
|
436 | + public function requestUnreserved(Request $request) |
|
437 | + { |
|
438 | + $this->send("Request {$request->getId()} ({$request->getName()}) is no longer being handled."); |
|
439 | + } |
|
440 | + |
|
441 | + /** |
|
442 | + * Summary of requestReservationSent |
|
443 | + * |
|
444 | + * @param Request $request |
|
445 | + * @param User $target |
|
446 | + */ |
|
447 | + public function requestReservationSent(Request $request, User $target) |
|
448 | + { |
|
449 | + $username = $this->currentUser->getUsername(); |
|
450 | + |
|
451 | + $this->send( |
|
452 | + "Reservation of request {$request->getId()} ({$request->getName()}) sent to {$target->getUsername()} by " |
|
453 | + . $username); |
|
454 | + } |
|
455 | + |
|
456 | + #endregion |
|
457 | + |
|
458 | + #region comments |
|
459 | + |
|
460 | + /** |
|
461 | + * Summary of commentCreated |
|
462 | + * |
|
463 | + * @param Comment $comment |
|
464 | + * @param Request $request |
|
465 | + */ |
|
466 | + public function commentCreated(Comment $comment, Request $request) |
|
467 | + { |
|
468 | + $username = $this->currentUser->getUsername(); |
|
469 | + switch ($comment->getVisibility()) { |
|
470 | + case 'admin': |
|
471 | + $visibility = " with visibility 'admin'"; |
|
472 | + break; |
|
473 | + case 'checkuser': |
|
474 | + $visibility = " with visibility 'checkuser'"; |
|
475 | + break; |
|
476 | + default: |
|
477 | + $visibility = ""; |
|
478 | + break; |
|
479 | + } |
|
480 | + |
|
481 | + $this->send("{$username} posted a comment on request {$request->getId()} ({$request->getName()}){$visibility}"); |
|
482 | + } |
|
483 | + |
|
484 | + /** |
|
485 | + * Summary of commentEdited |
|
486 | + * |
|
487 | + * @param Comment $comment |
|
488 | + * @param Request $request |
|
489 | + */ |
|
490 | + public function commentEdited(Comment $comment, Request $request) |
|
491 | + { |
|
492 | + $username = $this->currentUser->getUsername(); |
|
493 | + |
|
494 | + $this->send(<<<TAG |
|
495 | 495 | Comment {$comment->getId()} on request {$request->getId()} ({$request->getName()}) edited by {$username} |
496 | 496 | TAG |
497 | - ); |
|
498 | - } |
|
499 | - |
|
500 | - public function alertFlaggedComments(int $count) |
|
501 | - { |
|
502 | - $this->send("There are ${count} flagged comments on closed requests currently awaiting redaction."); |
|
503 | - } |
|
504 | - |
|
505 | - #endregion |
|
506 | - |
|
507 | - #region email management (close reasons) |
|
508 | - |
|
509 | - /** |
|
510 | - * Summary of emailCreated |
|
511 | - * |
|
512 | - * @param EmailTemplate $template |
|
513 | - */ |
|
514 | - public function emailCreated(EmailTemplate $template) |
|
515 | - { |
|
516 | - $username = $this->currentUser->getUsername(); |
|
517 | - $this->send("Email {$template->getId()} ({$template->getName()}) created by " . $username); |
|
518 | - } |
|
519 | - |
|
520 | - /** |
|
521 | - * Summary of emailEdited |
|
522 | - * |
|
523 | - * @param EmailTemplate $template |
|
524 | - */ |
|
525 | - public function emailEdited(EmailTemplate $template) |
|
526 | - { |
|
527 | - $username = $this->currentUser->getUsername(); |
|
528 | - $this->send("Email {$template->getId()} ({$template->getName()}) edited by " . $username); |
|
529 | - } |
|
530 | - #endregion |
|
497 | + ); |
|
498 | + } |
|
499 | + |
|
500 | + public function alertFlaggedComments(int $count) |
|
501 | + { |
|
502 | + $this->send("There are ${count} flagged comments on closed requests currently awaiting redaction."); |
|
503 | + } |
|
504 | + |
|
505 | + #endregion |
|
506 | + |
|
507 | + #region email management (close reasons) |
|
508 | + |
|
509 | + /** |
|
510 | + * Summary of emailCreated |
|
511 | + * |
|
512 | + * @param EmailTemplate $template |
|
513 | + */ |
|
514 | + public function emailCreated(EmailTemplate $template) |
|
515 | + { |
|
516 | + $username = $this->currentUser->getUsername(); |
|
517 | + $this->send("Email {$template->getId()} ({$template->getName()}) created by " . $username); |
|
518 | + } |
|
519 | + |
|
520 | + /** |
|
521 | + * Summary of emailEdited |
|
522 | + * |
|
523 | + * @param EmailTemplate $template |
|
524 | + */ |
|
525 | + public function emailEdited(EmailTemplate $template) |
|
526 | + { |
|
527 | + $username = $this->currentUser->getUsername(); |
|
528 | + $this->send("Email {$template->getId()} ({$template->getName()}) edited by " . $username); |
|
529 | + } |
|
530 | + #endregion |
|
531 | 531 | } |