Passed
Push — dependabot/npm_and_yarn/sass-1... ( dd05dd )
by
unknown
05:21
created
smarty-plugins/modifier.date.php 2 patches
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -16,16 +16,16 @@
 block discarded – undo
16 16
  */
17 17
 function smarty_modifier_date($input)
18 18
 {
19
-    if (gettype($input) === 'object'
20
-        && (get_class($input) === DateTime::class || get_class($input) === DateTimeImmutable::class)
21
-    ) {
22
-        /** @var $date DateTime|DateTimeImmutable */
23
-        $date = $input;
24
-        $dateString = $date->format('Y-m-d H:i:s');
19
+	if (gettype($input) === 'object'
20
+		&& (get_class($input) === DateTime::class || get_class($input) === DateTimeImmutable::class)
21
+	) {
22
+		/** @var $date DateTime|DateTimeImmutable */
23
+		$date = $input;
24
+		$dateString = $date->format('Y-m-d H:i:s');
25 25
 
26
-        return $dateString;
27
-    }
28
-    else {
29
-        return $input;
30
-    }
26
+		return $dateString;
27
+	}
28
+	else {
29
+		return $input;
30
+	}
31 31
 }
32 32
\ No newline at end of file
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -24,8 +24,7 @@
 block discarded – undo
24 24
         $dateString = $date->format('Y-m-d H:i:s');
25 25
 
26 26
         return $dateString;
27
-    }
28
-    else {
27
+    } else {
29 28
         return $input;
30 29
     }
31 30
 }
32 31
\ No newline at end of file
Please login to merge, or discard this patch.
includes/Fragments/RequestData.php 2 patches
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -295,8 +295,7 @@
 block discarded – undo
295 295
                 if (!$proxyIsInPrivateRange) {
296 296
                     $proxyReverseDns = $this->getRdnsProvider()->getReverseDNS($proxyAddress);
297 297
                     $proxyLocation = $this->getLocationProvider()->getIpLocation($proxyAddress);
298
-                }
299
-                else {
298
+                } else {
300 299
                     // this is going to fail, so why bother trying?
301 300
                     $proxyReverseDns = false;
302 301
                     $proxyLocation = false;
Please login to merge, or discard this patch.
Indentation   +344 added lines, -344 removed lines patch added patch discarded remove patch
@@ -27,350 +27,350 @@
 block discarded – undo
27 27
 
28 28
 trait RequestData
29 29
 {
30
-    /** @return SiteConfiguration */
31
-    protected abstract function getSiteConfiguration();
32
-
33
-    /**
34
-     * @var array Array of IP address classed as 'private' by RFC1918.
35
-     */
36
-    protected static $rfc1918ips = array(
37
-        "10.0.0.0"    => "10.255.255.255",
38
-        "172.16.0.0"  => "172.31.255.255",
39
-        "192.168.0.0" => "192.168.255.255",
40
-        "169.254.0.0" => "169.254.255.255",
41
-        "127.0.0.0"   => "127.255.255.255",
42
-    );
43
-
44
-    /**
45
-     * Gets a request object
46
-     *
47
-     * @param PdoDatabase $database  The database connection
48
-     * @param int|null    $requestId The ID of the request to retrieve
49
-     *
50
-     * @return Request
51
-     * @throws ApplicationLogicException
52
-     */
53
-    protected function getRequest(PdoDatabase $database, $requestId)
54
-    {
55
-        if ($requestId === null) {
56
-            throw new ApplicationLogicException("No request specified");
57
-        }
58
-
59
-        $request = Request::getById($requestId, $database);
60
-        if ($request === false || !is_a($request, Request::class)) {
61
-            throw new ApplicationLogicException('Could not load the requested request!');
62
-        }
63
-
64
-        return $request;
65
-    }
66
-
67
-    /**
68
-     * Returns a value stating whether the user is allowed to see private data or not
69
-     *
70
-     * @param Request $request
71
-     * @param User    $currentUser
72
-     *
73
-     * @return bool
74
-     * @category Security-Critical
75
-     */
76
-    protected function isAllowedPrivateData(Request $request, User $currentUser)
77
-    {
78
-        // Test the main security barrier for private data access using SecurityManager
79
-        if ($this->barrierTest('alwaysSeePrivateData', $currentUser, 'RequestData')) {
80
-            // Tool admins/check-users can always see private data
81
-            return true;
82
-        }
83
-
84
-        // reserving user is allowed to see the data
85
-        if ($currentUser->getId() === $request->getReserved()
86
-            && $request->getReserved() !== null
87
-            && $this->barrierTest('seePrivateDataWhenReserved', $currentUser, 'RequestData')
88
-        ) {
89
-            return true;
90
-        }
91
-
92
-        // user has the reveal hash
93
-        if (WebRequest::getString('hash') === $request->getRevealHash()
94
-            && $this->barrierTest('seePrivateDataWithHash', $currentUser, 'RequestData')
95
-        ) {
96
-            return true;
97
-        }
98
-
99
-        // nope. Not allowed.
100
-        return false;
101
-    }
102
-
103
-    /**
104
-     * Tests the security barrier for a specified action.
105
-     *
106
-     * Don't use within templates
107
-     *
108
-     * @param string      $action
109
-     *
110
-     * @param User        $user
111
-     * @param null|string $pageName
112
-     *
113
-     * @return bool
114
-     * @category Security-Critical
115
-     */
116
-    abstract protected function barrierTest($action, User $user, $pageName = null);
117
-
118
-    /**
119
-     * Gets the name of the route that has been passed from the request router.
120
-     * @return string
121
-     */
122
-    abstract protected function getRouteName();
123
-
124
-    abstract protected function getSecurityManager(): ISecurityManager;
125
-
126
-    /**
127
-     * Sets the name of the template this page should display.
128
-     *
129
-     * @param string $name
130
-     */
131
-    abstract protected function setTemplate($name);
132
-
133
-    /** @return IXffTrustProvider */
134
-    abstract protected function getXffTrustProvider();
135
-
136
-    /** @return ILocationProvider */
137
-    abstract protected function getLocationProvider();
138
-
139
-    /** @return IRDnsProvider */
140
-    abstract protected function getRdnsProvider();
141
-
142
-    /**
143
-     * Assigns a Smarty variable
144
-     *
145
-     * @param  array|string $name  the template variable name(s)
146
-     * @param  mixed        $value the value to assign
147
-     */
148
-    abstract protected function assign($name, $value);
149
-
150
-    /**
151
-     * @param int|null    $requestReservationId
152
-     * @param PdoDatabase $database
153
-     * @param User        $currentUser
154
-     */
155
-    protected function setupReservationDetails($requestReservationId, PdoDatabase $database, User $currentUser)
156
-    {
157
-        $requestIsReserved = $requestReservationId !== null;
158
-        $this->assign('requestIsReserved', $requestIsReserved);
159
-        $this->assign('requestIsReservedByMe', false);
160
-
161
-        if ($requestIsReserved) {
162
-            $this->assign('requestReservedByName', User::getById($requestReservationId, $database)->getUsername());
163
-            $this->assign('requestReservedById', $requestReservationId);
164
-
165
-            if ($requestReservationId === $currentUser->getId()) {
166
-                $this->assign('requestIsReservedByMe', true);
167
-            }
168
-        }
169
-
170
-        $this->assign('canBreakReservation', $this->barrierTest('force', $currentUser, PageBreakReservation::class));
171
-    }
172
-
173
-    /**
174
-     * Adds private request data to Smarty. DO NOT USE WITHOUT FIRST CHECKING THAT THE USER IS AUTHORISED!
175
-     *
176
-     * @param Request           $request
177
-     * @param SiteConfiguration $configuration
178
-     */
179
-    protected function setupPrivateData(
180
-        $request,
181
-        SiteConfiguration $configuration
182
-    ) {
183
-        $xffProvider = $this->getXffTrustProvider();
184
-
185
-        $this->assign('requestEmail', $request->getEmail());
186
-        $emailDomain = explode("@", $request->getEmail())[1];
187
-        $this->assign("emailurl", $emailDomain);
188
-        $this->assign('commonEmailDomain', in_array(strtolower($emailDomain), $configuration->getCommonEmailDomains())
189
-            || $request->getEmail() === $this->getSiteConfiguration()->getDataClearEmail());
190
-
191
-        $trustedIp = $xffProvider->getTrustedClientIp($request->getIp(), $request->getForwardedIp());
192
-        $this->assign('requestTrustedIp', $trustedIp);
193
-        $this->assign('requestRealIp', $request->getIp());
194
-        $this->assign('requestForwardedIp', $request->getForwardedIp());
195
-
196
-        $trustedIpLocation = $this->getLocationProvider()->getIpLocation($trustedIp);
197
-        $this->assign('requestTrustedIpLocation', $trustedIpLocation);
198
-
199
-        $this->assign('requestHasForwardedIp', $request->getForwardedIp() !== null);
200
-
201
-        $this->setupForwardedIpData($request);
202
-    }
203
-
204
-    /**
205
-     * Adds related request data to Smarty. DO NOT USE WITHOUT FIRST CHECKING THAT THE USER IS AUTHORISED!
206
-     *
207
-     * @param Request           $request
208
-     * @param SiteConfiguration $configuration
209
-     * @param PdoDatabase       $database
210
-     */
211
-    protected function setupRelatedRequests(
212
-        Request $request,
213
-        SiteConfiguration $configuration,
214
-        PdoDatabase $database)
215
-    {
216
-        $this->assign('canSeeRelatedRequests', true);
217
-
218
-        // TODO: Do we want to return results from other domains?
219
-        $relatedEmailRequests = RequestSearchHelper::get($database, null)
220
-            ->byEmailAddress($request->getEmail())
221
-            ->withConfirmedEmail()
222
-            ->excludingPurgedData($configuration)
223
-            ->excludingRequest($request->getId())
224
-            ->fetch();
225
-
226
-        $this->assign('requestRelatedEmailRequestsCount', count($relatedEmailRequests));
227
-        $this->assign('requestRelatedEmailRequests', $relatedEmailRequests);
228
-
229
-        $trustedIp = $this->getXffTrustProvider()->getTrustedClientIp($request->getIp(), $request->getForwardedIp());
230
-
231
-        // TODO: Do we want to return results from other domains?
232
-        $relatedIpRequests = RequestSearchHelper::get($database, null)
233
-            ->byIp($trustedIp)
234
-            ->withConfirmedEmail()
235
-            ->excludingPurgedData($configuration)
236
-            ->excludingRequest($request->getId())
237
-            ->fetch();
238
-
239
-        $this->assign('requestRelatedIpRequestsCount', count($relatedIpRequests));
240
-        $this->assign('requestRelatedIpRequests', $relatedIpRequests);
241
-    }
242
-
243
-    /**
244
-     * Adds checkuser request data to Smarty. DO NOT USE WITHOUT FIRST CHECKING THAT THE USER IS AUTHORISED!
245
-     *
246
-     * @param Request $request
247
-     */
248
-    protected function setupCheckUserData(Request $request)
249
-    {
250
-        $this->assign('requestUserAgent', $request->getUserAgent());
251
-
252
-        $data = \Waca\DataObjects\RequestData::getForRequest($request->getId(), $request->getDatabase(), \Waca\DataObjects\RequestData::TYPE_CLIENTHINT);
253
-        $this->assign('requestClientHints', $data);
254
-    }
255
-
256
-    /**
257
-     * Sets up the basic data for this request, and adds it to Smarty
258
-     *
259
-     * @param Request           $request
260
-     * @param SiteConfiguration $config
261
-     */
262
-    protected function setupBasicData(Request $request, SiteConfiguration $config)
263
-    {
264
-        $this->assign('requestId', $request->getId());
265
-        $this->assign('updateVersion', $request->getUpdateVersion());
266
-        $this->assign('requestName', $request->getName());
267
-        $this->assign('requestDate', $request->getDate());
268
-        $this->assign('requestStatus', $request->getStatus());
269
-
270
-        $this->assign('requestQueue', null);
271
-        if ($request->getQueue() !== null) {
272
-            /** @var RequestQueue $queue */
273
-            $queue = RequestQueue::getById($request->getQueue(), $this->getDatabase());
274
-            $this->assign('requestQueue', $queue->getHeader());
275
-            $this->assign('requestQueueApiName', $queue->getApiName());
276
-        }
277
-
278
-        $this->assign('canPreviewForm', $this->barrierTest('view', User::getCurrent($this->getDatabase()), PageRequestFormManagement::class));
279
-        $this->assign('originForm', $request->getOriginFormObject());
280
-
281
-        $isClosed = $request->getStatus() === RequestStatus::CLOSED || $request->getStatus() === RequestStatus::JOBQUEUE;
282
-        $this->assign('requestIsClosed', $isClosed);
30
+	/** @return SiteConfiguration */
31
+	protected abstract function getSiteConfiguration();
32
+
33
+	/**
34
+	 * @var array Array of IP address classed as 'private' by RFC1918.
35
+	 */
36
+	protected static $rfc1918ips = array(
37
+		"10.0.0.0"    => "10.255.255.255",
38
+		"172.16.0.0"  => "172.31.255.255",
39
+		"192.168.0.0" => "192.168.255.255",
40
+		"169.254.0.0" => "169.254.255.255",
41
+		"127.0.0.0"   => "127.255.255.255",
42
+	);
43
+
44
+	/**
45
+	 * Gets a request object
46
+	 *
47
+	 * @param PdoDatabase $database  The database connection
48
+	 * @param int|null    $requestId The ID of the request to retrieve
49
+	 *
50
+	 * @return Request
51
+	 * @throws ApplicationLogicException
52
+	 */
53
+	protected function getRequest(PdoDatabase $database, $requestId)
54
+	{
55
+		if ($requestId === null) {
56
+			throw new ApplicationLogicException("No request specified");
57
+		}
58
+
59
+		$request = Request::getById($requestId, $database);
60
+		if ($request === false || !is_a($request, Request::class)) {
61
+			throw new ApplicationLogicException('Could not load the requested request!');
62
+		}
63
+
64
+		return $request;
65
+	}
66
+
67
+	/**
68
+	 * Returns a value stating whether the user is allowed to see private data or not
69
+	 *
70
+	 * @param Request $request
71
+	 * @param User    $currentUser
72
+	 *
73
+	 * @return bool
74
+	 * @category Security-Critical
75
+	 */
76
+	protected function isAllowedPrivateData(Request $request, User $currentUser)
77
+	{
78
+		// Test the main security barrier for private data access using SecurityManager
79
+		if ($this->barrierTest('alwaysSeePrivateData', $currentUser, 'RequestData')) {
80
+			// Tool admins/check-users can always see private data
81
+			return true;
82
+		}
83
+
84
+		// reserving user is allowed to see the data
85
+		if ($currentUser->getId() === $request->getReserved()
86
+			&& $request->getReserved() !== null
87
+			&& $this->barrierTest('seePrivateDataWhenReserved', $currentUser, 'RequestData')
88
+		) {
89
+			return true;
90
+		}
91
+
92
+		// user has the reveal hash
93
+		if (WebRequest::getString('hash') === $request->getRevealHash()
94
+			&& $this->barrierTest('seePrivateDataWithHash', $currentUser, 'RequestData')
95
+		) {
96
+			return true;
97
+		}
98
+
99
+		// nope. Not allowed.
100
+		return false;
101
+	}
102
+
103
+	/**
104
+	 * Tests the security barrier for a specified action.
105
+	 *
106
+	 * Don't use within templates
107
+	 *
108
+	 * @param string      $action
109
+	 *
110
+	 * @param User        $user
111
+	 * @param null|string $pageName
112
+	 *
113
+	 * @return bool
114
+	 * @category Security-Critical
115
+	 */
116
+	abstract protected function barrierTest($action, User $user, $pageName = null);
117
+
118
+	/**
119
+	 * Gets the name of the route that has been passed from the request router.
120
+	 * @return string
121
+	 */
122
+	abstract protected function getRouteName();
123
+
124
+	abstract protected function getSecurityManager(): ISecurityManager;
125
+
126
+	/**
127
+	 * Sets the name of the template this page should display.
128
+	 *
129
+	 * @param string $name
130
+	 */
131
+	abstract protected function setTemplate($name);
132
+
133
+	/** @return IXffTrustProvider */
134
+	abstract protected function getXffTrustProvider();
135
+
136
+	/** @return ILocationProvider */
137
+	abstract protected function getLocationProvider();
138
+
139
+	/** @return IRDnsProvider */
140
+	abstract protected function getRdnsProvider();
141
+
142
+	/**
143
+	 * Assigns a Smarty variable
144
+	 *
145
+	 * @param  array|string $name  the template variable name(s)
146
+	 * @param  mixed        $value the value to assign
147
+	 */
148
+	abstract protected function assign($name, $value);
149
+
150
+	/**
151
+	 * @param int|null    $requestReservationId
152
+	 * @param PdoDatabase $database
153
+	 * @param User        $currentUser
154
+	 */
155
+	protected function setupReservationDetails($requestReservationId, PdoDatabase $database, User $currentUser)
156
+	{
157
+		$requestIsReserved = $requestReservationId !== null;
158
+		$this->assign('requestIsReserved', $requestIsReserved);
159
+		$this->assign('requestIsReservedByMe', false);
160
+
161
+		if ($requestIsReserved) {
162
+			$this->assign('requestReservedByName', User::getById($requestReservationId, $database)->getUsername());
163
+			$this->assign('requestReservedById', $requestReservationId);
164
+
165
+			if ($requestReservationId === $currentUser->getId()) {
166
+				$this->assign('requestIsReservedByMe', true);
167
+			}
168
+		}
169
+
170
+		$this->assign('canBreakReservation', $this->barrierTest('force', $currentUser, PageBreakReservation::class));
171
+	}
172
+
173
+	/**
174
+	 * Adds private request data to Smarty. DO NOT USE WITHOUT FIRST CHECKING THAT THE USER IS AUTHORISED!
175
+	 *
176
+	 * @param Request           $request
177
+	 * @param SiteConfiguration $configuration
178
+	 */
179
+	protected function setupPrivateData(
180
+		$request,
181
+		SiteConfiguration $configuration
182
+	) {
183
+		$xffProvider = $this->getXffTrustProvider();
184
+
185
+		$this->assign('requestEmail', $request->getEmail());
186
+		$emailDomain = explode("@", $request->getEmail())[1];
187
+		$this->assign("emailurl", $emailDomain);
188
+		$this->assign('commonEmailDomain', in_array(strtolower($emailDomain), $configuration->getCommonEmailDomains())
189
+			|| $request->getEmail() === $this->getSiteConfiguration()->getDataClearEmail());
190
+
191
+		$trustedIp = $xffProvider->getTrustedClientIp($request->getIp(), $request->getForwardedIp());
192
+		$this->assign('requestTrustedIp', $trustedIp);
193
+		$this->assign('requestRealIp', $request->getIp());
194
+		$this->assign('requestForwardedIp', $request->getForwardedIp());
195
+
196
+		$trustedIpLocation = $this->getLocationProvider()->getIpLocation($trustedIp);
197
+		$this->assign('requestTrustedIpLocation', $trustedIpLocation);
198
+
199
+		$this->assign('requestHasForwardedIp', $request->getForwardedIp() !== null);
200
+
201
+		$this->setupForwardedIpData($request);
202
+	}
203
+
204
+	/**
205
+	 * Adds related request data to Smarty. DO NOT USE WITHOUT FIRST CHECKING THAT THE USER IS AUTHORISED!
206
+	 *
207
+	 * @param Request           $request
208
+	 * @param SiteConfiguration $configuration
209
+	 * @param PdoDatabase       $database
210
+	 */
211
+	protected function setupRelatedRequests(
212
+		Request $request,
213
+		SiteConfiguration $configuration,
214
+		PdoDatabase $database)
215
+	{
216
+		$this->assign('canSeeRelatedRequests', true);
217
+
218
+		// TODO: Do we want to return results from other domains?
219
+		$relatedEmailRequests = RequestSearchHelper::get($database, null)
220
+			->byEmailAddress($request->getEmail())
221
+			->withConfirmedEmail()
222
+			->excludingPurgedData($configuration)
223
+			->excludingRequest($request->getId())
224
+			->fetch();
225
+
226
+		$this->assign('requestRelatedEmailRequestsCount', count($relatedEmailRequests));
227
+		$this->assign('requestRelatedEmailRequests', $relatedEmailRequests);
228
+
229
+		$trustedIp = $this->getXffTrustProvider()->getTrustedClientIp($request->getIp(), $request->getForwardedIp());
230
+
231
+		// TODO: Do we want to return results from other domains?
232
+		$relatedIpRequests = RequestSearchHelper::get($database, null)
233
+			->byIp($trustedIp)
234
+			->withConfirmedEmail()
235
+			->excludingPurgedData($configuration)
236
+			->excludingRequest($request->getId())
237
+			->fetch();
238
+
239
+		$this->assign('requestRelatedIpRequestsCount', count($relatedIpRequests));
240
+		$this->assign('requestRelatedIpRequests', $relatedIpRequests);
241
+	}
242
+
243
+	/**
244
+	 * Adds checkuser request data to Smarty. DO NOT USE WITHOUT FIRST CHECKING THAT THE USER IS AUTHORISED!
245
+	 *
246
+	 * @param Request $request
247
+	 */
248
+	protected function setupCheckUserData(Request $request)
249
+	{
250
+		$this->assign('requestUserAgent', $request->getUserAgent());
251
+
252
+		$data = \Waca\DataObjects\RequestData::getForRequest($request->getId(), $request->getDatabase(), \Waca\DataObjects\RequestData::TYPE_CLIENTHINT);
253
+		$this->assign('requestClientHints', $data);
254
+	}
255
+
256
+	/**
257
+	 * Sets up the basic data for this request, and adds it to Smarty
258
+	 *
259
+	 * @param Request           $request
260
+	 * @param SiteConfiguration $config
261
+	 */
262
+	protected function setupBasicData(Request $request, SiteConfiguration $config)
263
+	{
264
+		$this->assign('requestId', $request->getId());
265
+		$this->assign('updateVersion', $request->getUpdateVersion());
266
+		$this->assign('requestName', $request->getName());
267
+		$this->assign('requestDate', $request->getDate());
268
+		$this->assign('requestStatus', $request->getStatus());
269
+
270
+		$this->assign('requestQueue', null);
271
+		if ($request->getQueue() !== null) {
272
+			/** @var RequestQueue $queue */
273
+			$queue = RequestQueue::getById($request->getQueue(), $this->getDatabase());
274
+			$this->assign('requestQueue', $queue->getHeader());
275
+			$this->assign('requestQueueApiName', $queue->getApiName());
276
+		}
277
+
278
+		$this->assign('canPreviewForm', $this->barrierTest('view', User::getCurrent($this->getDatabase()), PageRequestFormManagement::class));
279
+		$this->assign('originForm', $request->getOriginFormObject());
280
+
281
+		$isClosed = $request->getStatus() === RequestStatus::CLOSED || $request->getStatus() === RequestStatus::JOBQUEUE;
282
+		$this->assign('requestIsClosed', $isClosed);
283 283
 		$isHospital = $request->getStatus() === RequestStatus::HOSPITAL;
284 284
 		$this->assign('requestIsHospital', $isHospital);
285
-    }
286
-
287
-    /**
288
-     * Sets up the forwarded IP data for this request and adds it to Smarty
289
-     *
290
-     * @param Request $request
291
-     */
292
-    protected function setupForwardedIpData(Request $request)
293
-    {
294
-        if ($request->getForwardedIp() !== null) {
295
-            $requestProxyData = array(); // Initialize array to store data to be output in Smarty template.
296
-            $proxyIndex = 0;
297
-
298
-            // Assuming [client] <=> [proxy1] <=> [proxy2] <=> [proxy3] <=> [us], we will see an XFF header of [client],
299
-            // [proxy1], [proxy2], and our actual IP will be [proxy3]
300
-            $proxies = explode(",", $request->getForwardedIp());
301
-            $proxies[] = $request->getIp();
302
-
303
-            // Origin is the supposed "client" IP.
304
-            $origin = $proxies[0];
305
-            $this->assign("forwardedOrigin", $origin);
306
-
307
-            // We step through the servers in reverse order, from closest to furthest
308
-            $proxies = array_reverse($proxies);
309
-
310
-            // By default, we have trust, because the first in the chain is now REMOTE_ADDR, which is hardest to spoof.
311
-            $trust = true;
312
-
313
-            /**
314
-             * @var int    $index     The zero-based index of the proxy.
315
-             * @var string $proxyData The proxy IP address (although possibly not!)
316
-             */
317
-            foreach ($proxies as $index => $proxyData) {
318
-                $proxyAddress = trim($proxyData);
319
-                $requestProxyData[$proxyIndex]['ip'] = $proxyAddress;
320
-
321
-                // get data on this IP.
322
-                $thisProxyIsTrusted = $this->getXffTrustProvider()->isTrusted($proxyAddress);
323
-
324
-                $proxyIsInPrivateRange = $this->getXffTrustProvider()
325
-                    ->ipInRange(self::$rfc1918ips, $proxyAddress);
326
-
327
-                if (!$proxyIsInPrivateRange) {
328
-                    $proxyReverseDns = $this->getRdnsProvider()->getReverseDNS($proxyAddress);
329
-                    $proxyLocation = $this->getLocationProvider()->getIpLocation($proxyAddress);
330
-                }
331
-                else {
332
-                    // this is going to fail, so why bother trying?
333
-                    $proxyReverseDns = false;
334
-                    $proxyLocation = false;
335
-                }
336
-
337
-                // current trust chain status BEFORE this link
338
-                $preLinkTrust = $trust;
339
-
340
-                // is *this* link trusted? Note, this will be true even if there is an untrusted link before this!
341
-                $requestProxyData[$proxyIndex]['trustedlink'] = $thisProxyIsTrusted;
342
-
343
-                // set the trust status of the chain to this point
344
-                $trust = $trust & $thisProxyIsTrusted;
345
-
346
-                // If this is the origin address, and the chain was trusted before this point, then we can trust
347
-                // the origin.
348
-                if ($preLinkTrust && $proxyAddress == $origin) {
349
-                    // if this is the origin, then we are at the last point in the chain.
350
-                    // @todo: this is probably the cause of some bugs when an IP appears twice - we're missing a check
351
-                    // to see if this is *really* the last in the chain, rather than just the same IP as it.
352
-                    $trust = true;
353
-                }
354
-
355
-                $requestProxyData[$proxyIndex]['trust'] = $trust;
356
-
357
-                $requestProxyData[$proxyIndex]['rdnsfailed'] = $proxyReverseDns === false;
358
-                $requestProxyData[$proxyIndex]['rdns'] = $proxyReverseDns;
359
-                $requestProxyData[$proxyIndex]['routable'] = !$proxyIsInPrivateRange;
360
-
361
-                $requestProxyData[$proxyIndex]['location'] = $proxyLocation;
362
-
363
-                if ($proxyReverseDns === $proxyAddress && $proxyIsInPrivateRange === false) {
364
-                    $requestProxyData[$proxyIndex]['rdns'] = null;
365
-                }
366
-
367
-                $showLinks = (!$trust || $proxyAddress == $origin) && !$proxyIsInPrivateRange;
368
-                $requestProxyData[$proxyIndex]['showlinks'] = $showLinks;
369
-
370
-                $proxyIndex++;
371
-            }
372
-
373
-            $this->assign("requestProxyData", $requestProxyData);
374
-        }
375
-    }
285
+	}
286
+
287
+	/**
288
+	 * Sets up the forwarded IP data for this request and adds it to Smarty
289
+	 *
290
+	 * @param Request $request
291
+	 */
292
+	protected function setupForwardedIpData(Request $request)
293
+	{
294
+		if ($request->getForwardedIp() !== null) {
295
+			$requestProxyData = array(); // Initialize array to store data to be output in Smarty template.
296
+			$proxyIndex = 0;
297
+
298
+			// Assuming [client] <=> [proxy1] <=> [proxy2] <=> [proxy3] <=> [us], we will see an XFF header of [client],
299
+			// [proxy1], [proxy2], and our actual IP will be [proxy3]
300
+			$proxies = explode(",", $request->getForwardedIp());
301
+			$proxies[] = $request->getIp();
302
+
303
+			// Origin is the supposed "client" IP.
304
+			$origin = $proxies[0];
305
+			$this->assign("forwardedOrigin", $origin);
306
+
307
+			// We step through the servers in reverse order, from closest to furthest
308
+			$proxies = array_reverse($proxies);
309
+
310
+			// By default, we have trust, because the first in the chain is now REMOTE_ADDR, which is hardest to spoof.
311
+			$trust = true;
312
+
313
+			/**
314
+			 * @var int    $index     The zero-based index of the proxy.
315
+			 * @var string $proxyData The proxy IP address (although possibly not!)
316
+			 */
317
+			foreach ($proxies as $index => $proxyData) {
318
+				$proxyAddress = trim($proxyData);
319
+				$requestProxyData[$proxyIndex]['ip'] = $proxyAddress;
320
+
321
+				// get data on this IP.
322
+				$thisProxyIsTrusted = $this->getXffTrustProvider()->isTrusted($proxyAddress);
323
+
324
+				$proxyIsInPrivateRange = $this->getXffTrustProvider()
325
+					->ipInRange(self::$rfc1918ips, $proxyAddress);
326
+
327
+				if (!$proxyIsInPrivateRange) {
328
+					$proxyReverseDns = $this->getRdnsProvider()->getReverseDNS($proxyAddress);
329
+					$proxyLocation = $this->getLocationProvider()->getIpLocation($proxyAddress);
330
+				}
331
+				else {
332
+					// this is going to fail, so why bother trying?
333
+					$proxyReverseDns = false;
334
+					$proxyLocation = false;
335
+				}
336
+
337
+				// current trust chain status BEFORE this link
338
+				$preLinkTrust = $trust;
339
+
340
+				// is *this* link trusted? Note, this will be true even if there is an untrusted link before this!
341
+				$requestProxyData[$proxyIndex]['trustedlink'] = $thisProxyIsTrusted;
342
+
343
+				// set the trust status of the chain to this point
344
+				$trust = $trust & $thisProxyIsTrusted;
345
+
346
+				// If this is the origin address, and the chain was trusted before this point, then we can trust
347
+				// the origin.
348
+				if ($preLinkTrust && $proxyAddress == $origin) {
349
+					// if this is the origin, then we are at the last point in the chain.
350
+					// @todo: this is probably the cause of some bugs when an IP appears twice - we're missing a check
351
+					// to see if this is *really* the last in the chain, rather than just the same IP as it.
352
+					$trust = true;
353
+				}
354
+
355
+				$requestProxyData[$proxyIndex]['trust'] = $trust;
356
+
357
+				$requestProxyData[$proxyIndex]['rdnsfailed'] = $proxyReverseDns === false;
358
+				$requestProxyData[$proxyIndex]['rdns'] = $proxyReverseDns;
359
+				$requestProxyData[$proxyIndex]['routable'] = !$proxyIsInPrivateRange;
360
+
361
+				$requestProxyData[$proxyIndex]['location'] = $proxyLocation;
362
+
363
+				if ($proxyReverseDns === $proxyAddress && $proxyIsInPrivateRange === false) {
364
+					$requestProxyData[$proxyIndex]['rdns'] = null;
365
+				}
366
+
367
+				$showLinks = (!$trust || $proxyAddress == $origin) && !$proxyIsInPrivateRange;
368
+				$requestProxyData[$proxyIndex]['showlinks'] = $showLinks;
369
+
370
+				$proxyIndex++;
371
+			}
372
+
373
+			$this->assign("requestProxyData", $requestProxyData);
374
+		}
375
+	}
376 376
 }
Please login to merge, or discard this patch.
includes/IrcColourCode.php 1 patch
Indentation   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -10,27 +10,27 @@
 block discarded – undo
10 10
 
11 11
 class IrcColourCode
12 12
 {
13
-    const BOLD = "\x02";
14
-    const ITALIC = "\x09";
15
-    const STRIKE = "\x13";
16
-    const UNDERLINE = "\x15";
17
-    const UNDERLINE2 = "\x1f";
18
-    const REVERSE = "\x16";
19
-    const RESET = "\x0f";
20
-    const WHITE = "\x0300";
21
-    const BLACK = "\x0301";
22
-    const DARK_BLUE = "\x0302";
23
-    const DARK_GREEN = "\x0303";
24
-    const RED = "\x0304";
25
-    const DARK_RED = "\x0305";
26
-    const DARK_VIOLET = "\x0306";
27
-    const ORANGE = "\x0307";
28
-    const YELLOW = "\x0308";
29
-    const LIGHT_GREEN = "\x0309";
30
-    const CYAN = "\x0310";
31
-    const LIGHT_CYAN = "\x0311";
32
-    const BLUE = "\x0312";
33
-    const VIOLET = "\x0313";
34
-    const DARK_GREY = "\x0314";
35
-    const LIGHT_GREY = "\x0315";
13
+	const BOLD = "\x02";
14
+	const ITALIC = "\x09";
15
+	const STRIKE = "\x13";
16
+	const UNDERLINE = "\x15";
17
+	const UNDERLINE2 = "\x1f";
18
+	const REVERSE = "\x16";
19
+	const RESET = "\x0f";
20
+	const WHITE = "\x0300";
21
+	const BLACK = "\x0301";
22
+	const DARK_BLUE = "\x0302";
23
+	const DARK_GREEN = "\x0303";
24
+	const RED = "\x0304";
25
+	const DARK_RED = "\x0305";
26
+	const DARK_VIOLET = "\x0306";
27
+	const ORANGE = "\x0307";
28
+	const YELLOW = "\x0308";
29
+	const LIGHT_GREEN = "\x0309";
30
+	const CYAN = "\x0310";
31
+	const LIGHT_CYAN = "\x0311";
32
+	const BLUE = "\x0312";
33
+	const VIOLET = "\x0313";
34
+	const DARK_GREY = "\x0314";
35
+	const LIGHT_GREY = "\x0315";
36 36
 }
Please login to merge, or discard this patch.
includes/Session.php 1 patch
Indentation   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -17,25 +17,25 @@
 block discarded – undo
17 17
  */
18 18
 class Session
19 19
 {
20
-    public static function start()
21
-    {
22
-        ini_set('session.cookie_httponly', 1);
20
+	public static function start()
21
+	{
22
+		ini_set('session.cookie_httponly', 1);
23 23
 
24
-        if (WebRequest::isHttps()) {
25
-            ini_set('session.cookie_secure', 1);
26
-        }
24
+		if (WebRequest::isHttps()) {
25
+			ini_set('session.cookie_secure', 1);
26
+		}
27 27
 
28
-        session_start();
29
-    }
28
+		session_start();
29
+	}
30 30
 
31
-    public static function destroy()
32
-    {
33
-        session_destroy();
34
-    }
31
+	public static function destroy()
32
+	{
33
+		session_destroy();
34
+	}
35 35
 
36
-    public static function restart()
37
-    {
38
-        self::destroy();
39
-        self::start();
40
-    }
36
+	public static function restart()
37
+	{
38
+		self::destroy();
39
+		self::start();
40
+	}
41 41
 }
Please login to merge, or discard this patch.
includes/Helpers/DebugHelper.php 1 patch
Indentation   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -13,53 +13,53 @@
 block discarded – undo
13 13
  */
14 14
 class DebugHelper
15 15
 {
16
-    /**
17
-     * Internal mockable method wrapper for debug_backtrace.
18
-     *
19
-     * As mocking out debug_backtrace uses debug_backtrace internally, we need this in order to not cause a recursive
20
-     * cascade until the runtime explodes.
21
-     *
22
-     * Instead, we mock this method, which allows debug_backtrace to still be called correctly.
23
-     *
24
-     * @return array
25
-     */
26
-    public function get_debug_backtrace()
27
-    {
28
-        return debug_backtrace();
29
-    }
16
+	/**
17
+	 * Internal mockable method wrapper for debug_backtrace.
18
+	 *
19
+	 * As mocking out debug_backtrace uses debug_backtrace internally, we need this in order to not cause a recursive
20
+	 * cascade until the runtime explodes.
21
+	 *
22
+	 * Instead, we mock this method, which allows debug_backtrace to still be called correctly.
23
+	 *
24
+	 * @return array
25
+	 */
26
+	public function get_debug_backtrace()
27
+	{
28
+		return debug_backtrace();
29
+	}
30 30
 
31
-    /**
32
-     * Returns a string representation of the current backtrace for display.
33
-     *
34
-     * Note that this explicitly excludes the top two frames, which will be methods from this class.
35
-     *
36
-     * @return string
37
-     */
38
-    public function getBacktrace()
39
-    {
40
-        $backtrace = $this->get_debug_backtrace();
31
+	/**
32
+	 * Returns a string representation of the current backtrace for display.
33
+	 *
34
+	 * Note that this explicitly excludes the top two frames, which will be methods from this class.
35
+	 *
36
+	 * @return string
37
+	 */
38
+	public function getBacktrace()
39
+	{
40
+		$backtrace = $this->get_debug_backtrace();
41 41
 
42
-        $output = "";
42
+		$output = "";
43 43
 
44
-        $count = 0;
45
-        foreach ($backtrace as $line) {
46
-            if ($count <= 1) {
47
-                $count++;
48
-                continue;
49
-            }
44
+		$count = 0;
45
+		foreach ($backtrace as $line) {
46
+			if ($count <= 1) {
47
+				$count++;
48
+				continue;
49
+			}
50 50
 
51
-            $output .= "#{$count}: ";
51
+			$output .= "#{$count}: ";
52 52
 
53
-            if (isset($line['type']) && $line['type'] != "") {
54
-                $output .= $line['class'] . $line['type'];
55
-            }
53
+			if (isset($line['type']) && $line['type'] != "") {
54
+				$output .= $line['class'] . $line['type'];
55
+			}
56 56
 
57
-            $output .= $line['function'] . "(...)";
58
-            $output .= " [{$line['file']}#{$line['line']}\r\n";
57
+			$output .= $line['function'] . "(...)";
58
+			$output .= " [{$line['file']}#{$line['line']}\r\n";
59 59
 
60
-            $count++;
61
-        }
60
+			$count++;
61
+		}
62 62
 
63
-        return $output;
64
-    }
63
+		return $output;
64
+	}
65 65
 }
Please login to merge, or discard this patch.
includes/Helpers/FakeBlacklistHelper.php 1 patch
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -12,16 +12,16 @@
 block discarded – undo
12 12
 
13 13
 class FakeBlacklistHelper implements IBlacklistHelper
14 14
 {
15
-    /**
16
-     * Returns a value indicating whether the provided username is blacklisted by the on-wiki title blacklist
17
-     *
18
-     * @param string $username
19
-     *
20
-     * @return bool
21
-     */
22
-    public function isBlacklisted($username)
23
-    {
24
-        // Short-circuit
25
-        return false;
26
-    }
15
+	/**
16
+	 * Returns a value indicating whether the provided username is blacklisted by the on-wiki title blacklist
17
+	 *
18
+	 * @param string $username
19
+	 *
20
+	 * @return bool
21
+	 */
22
+	public function isBlacklisted($username)
23
+	{
24
+		// Short-circuit
25
+		return false;
26
+	}
27 27
 }
28 28
\ No newline at end of file
Please login to merge, or discard this patch.
includes/Helpers/BlacklistHelper.php 2 patches
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -66,8 +66,7 @@
 block discarded – undo
66 66
             $this->cache[$username] = false;
67 67
 
68 68
             return false;
69
-        }
70
-        else {
69
+        } else {
71 70
             $this->cache[$username] = $result;
72 71
 
73 72
             return $result['line'];
Please login to merge, or discard this patch.
Indentation   +88 added lines, -88 removed lines patch added patch discarded remove patch
@@ -18,92 +18,92 @@
 block discarded – undo
18 18
 
19 19
 class BlacklistHelper implements IBlacklistHelper
20 20
 {
21
-    private HttpHelper $httpHelper;
22
-
23
-    /**
24
-     * Cache of previously requested usernames
25
-     * @var array
26
-     */
27
-    private $cache = array();
28
-
29
-    private PdoDatabase $database;
30
-    private SiteConfiguration $siteConfiguration;
31
-
32
-    public function __construct(HttpHelper $httpHelper, PdoDatabase $database, SiteConfiguration $siteConfiguration)
33
-    {
34
-        $this->httpHelper = $httpHelper;
35
-        $this->database = $database;
36
-        $this->siteConfiguration = $siteConfiguration;
37
-    }
38
-
39
-    /**
40
-     * Returns a value indicating whether the provided username is blacklisted by the on-wiki title blacklist
41
-     *
42
-     * @param string $username
43
-     *
44
-     * @return false|string False if the username is not blacklisted, else the blacklist entry.
45
-     */
46
-    public function isBlacklisted($username)
47
-    {
48
-        if (isset($this->cache[$username])) {
49
-            $result = $this->cache[$username];
50
-            if ($result === false) {
51
-                return false;
52
-            }
53
-
54
-            return $result['line'];
55
-        }
56
-
57
-        try {
58
-            $result = $this->performWikiLookup($username);
59
-        }
60
-        catch (CurlException $ex) {
61
-            // log this, but fail gracefully.
62
-            ExceptionHandler::logExceptionToDisk($ex, $this->siteConfiguration);
63
-            return false;
64
-        }
65
-
66
-        if ($result['result'] === 'ok') {
67
-            // not blacklisted
68
-            $this->cache[$username] = false;
69
-
70
-            return false;
71
-        }
72
-        else {
73
-            $this->cache[$username] = $result;
74
-
75
-            return $result['line'];
76
-        }
77
-    }
78
-
79
-    /**
80
-     * Performs a fetch to MediaWiki for the relevant title blacklist entry
81
-     *
82
-     * @param string $username The username to look up
83
-     *
84
-     * @return array
85
-     * @throws CurlException
86
-     */
87
-    private function performWikiLookup($username)
88
-    {
89
-        // FIXME: domains!
90
-        /** @var Domain $domain */
91
-        $domain = Domain::getById(1, $this->database);
92
-
93
-        $endpoint = $domain->getWikiApiPath();
94
-
95
-        $parameters = array(
96
-            'action'       => 'titleblacklist',
97
-            'format'       => 'php',
98
-            'tbtitle'      => $username,
99
-            'tbaction'     => 'new-account',
100
-            'tbnooverride' => true,
101
-        );
102
-
103
-        $apiResult = $this->httpHelper->get($endpoint, $parameters);
104
-
105
-        $data = unserialize($apiResult);
106
-
107
-        return $data['titleblacklist'];
108
-    }
21
+	private HttpHelper $httpHelper;
22
+
23
+	/**
24
+	 * Cache of previously requested usernames
25
+	 * @var array
26
+	 */
27
+	private $cache = array();
28
+
29
+	private PdoDatabase $database;
30
+	private SiteConfiguration $siteConfiguration;
31
+
32
+	public function __construct(HttpHelper $httpHelper, PdoDatabase $database, SiteConfiguration $siteConfiguration)
33
+	{
34
+		$this->httpHelper = $httpHelper;
35
+		$this->database = $database;
36
+		$this->siteConfiguration = $siteConfiguration;
37
+	}
38
+
39
+	/**
40
+	 * Returns a value indicating whether the provided username is blacklisted by the on-wiki title blacklist
41
+	 *
42
+	 * @param string $username
43
+	 *
44
+	 * @return false|string False if the username is not blacklisted, else the blacklist entry.
45
+	 */
46
+	public function isBlacklisted($username)
47
+	{
48
+		if (isset($this->cache[$username])) {
49
+			$result = $this->cache[$username];
50
+			if ($result === false) {
51
+				return false;
52
+			}
53
+
54
+			return $result['line'];
55
+		}
56
+
57
+		try {
58
+			$result = $this->performWikiLookup($username);
59
+		}
60
+		catch (CurlException $ex) {
61
+			// log this, but fail gracefully.
62
+			ExceptionHandler::logExceptionToDisk($ex, $this->siteConfiguration);
63
+			return false;
64
+		}
65
+
66
+		if ($result['result'] === 'ok') {
67
+			// not blacklisted
68
+			$this->cache[$username] = false;
69
+
70
+			return false;
71
+		}
72
+		else {
73
+			$this->cache[$username] = $result;
74
+
75
+			return $result['line'];
76
+		}
77
+	}
78
+
79
+	/**
80
+	 * Performs a fetch to MediaWiki for the relevant title blacklist entry
81
+	 *
82
+	 * @param string $username The username to look up
83
+	 *
84
+	 * @return array
85
+	 * @throws CurlException
86
+	 */
87
+	private function performWikiLookup($username)
88
+	{
89
+		// FIXME: domains!
90
+		/** @var Domain $domain */
91
+		$domain = Domain::getById(1, $this->database);
92
+
93
+		$endpoint = $domain->getWikiApiPath();
94
+
95
+		$parameters = array(
96
+			'action'       => 'titleblacklist',
97
+			'format'       => 'php',
98
+			'tbtitle'      => $username,
99
+			'tbaction'     => 'new-account',
100
+			'tbnooverride' => true,
101
+		);
102
+
103
+		$apiResult = $this->httpHelper->get($endpoint, $parameters);
104
+
105
+		$data = unserialize($apiResult);
106
+
107
+		return $data['titleblacklist'];
108
+	}
109 109
 }
110 110
\ No newline at end of file
Please login to merge, or discard this patch.
includes/Helpers/Interfaces/ITypeAheadHelper.php 1 patch
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -10,16 +10,16 @@
 block discarded – undo
10 10
 
11 11
 interface ITypeAheadHelper
12 12
 {
13
-    /**
14
-     * @param string   $class     CSS class to apply this typeahead to.
15
-     * @param callable $generator Generator function taking no arguments to return an array of strings.
16
-     *
17
-     * @return void
18
-     */
19
-    public function defineTypeAheadSource($class, callable $generator);
13
+	/**
14
+	 * @param string   $class     CSS class to apply this typeahead to.
15
+	 * @param callable $generator Generator function taking no arguments to return an array of strings.
16
+	 *
17
+	 * @return void
18
+	 */
19
+	public function defineTypeAheadSource($class, callable $generator);
20 20
 
21
-    /**
22
-     * @return string HTML fragment containing a JS block for typeaheads.
23
-     */
24
-    public function getTypeAheadScriptBlock();
21
+	/**
22
+	 * @return string HTML fragment containing a JS block for typeaheads.
23
+	 */
24
+	public function getTypeAheadScriptBlock();
25 25
 }
26 26
\ No newline at end of file
Please login to merge, or discard this patch.
includes/Helpers/Interfaces/IBlacklistHelper.php 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -10,12 +10,12 @@
 block discarded – undo
10 10
 
11 11
 interface IBlacklistHelper
12 12
 {
13
-    /**
14
-     * Returns a value indicating whether the provided username is blacklisted by the on-wiki title blacklist
15
-     *
16
-     * @param string $username
17
-     *
18
-     * @return bool
19
-     */
20
-    public function isBlacklisted($username);
13
+	/**
14
+	 * Returns a value indicating whether the provided username is blacklisted by the on-wiki title blacklist
15
+	 *
16
+	 * @param string $username
17
+	 *
18
+	 * @return bool
19
+	 */
20
+	public function isBlacklisted($username);
21 21
 }
22 22
\ No newline at end of file
Please login to merge, or discard this patch.