@@ -129,7 +129,7 @@ |
||
129 | 129 | /** |
130 | 130 | * Assigns a Smarty variable |
131 | 131 | * |
132 | - * @param array|string $name the template variable name(s) |
|
132 | + * @param string $name the template variable name(s) |
|
133 | 133 | * @param mixed $value the value to assign |
134 | 134 | */ |
135 | 135 | abstract protected function assign($name, $value); |
@@ -23,322 +23,322 @@ |
||
23 | 23 | |
24 | 24 | trait RequestData |
25 | 25 | { |
26 | - /** |
|
27 | - * @var array Array of IP address classed as 'private' by RFC1918. |
|
28 | - */ |
|
29 | - protected static $rfc1918ips = array( |
|
30 | - "10.0.0.0" => "10.255.255.255", |
|
31 | - "172.16.0.0" => "172.31.255.255", |
|
32 | - "192.168.0.0" => "192.168.255.255", |
|
33 | - "169.254.0.0" => "169.254.255.255", |
|
34 | - "127.0.0.0" => "127.255.255.255", |
|
35 | - ); |
|
36 | - |
|
37 | - /** |
|
38 | - * Gets a request object |
|
39 | - * |
|
40 | - * @param PdoDatabase $database The database connection |
|
41 | - * @param int $requestId The ID of the request to retrieve |
|
42 | - * |
|
43 | - * @return Request |
|
44 | - * @throws ApplicationLogicException |
|
45 | - */ |
|
46 | - protected function getRequest(PdoDatabase $database, $requestId) |
|
47 | - { |
|
48 | - if ($requestId === null) { |
|
49 | - throw new ApplicationLogicException("No request specified"); |
|
50 | - } |
|
51 | - |
|
52 | - $request = Request::getById($requestId, $database); |
|
53 | - if ($request === false || !is_a($request, Request::class)) { |
|
54 | - throw new ApplicationLogicException('Could not load the requested request!'); |
|
55 | - } |
|
56 | - |
|
57 | - return $request; |
|
58 | - } |
|
59 | - |
|
60 | - /** |
|
61 | - * Returns a value stating whether the user is allowed to see private data or not |
|
62 | - * |
|
63 | - * @param Request $request |
|
64 | - * @param User $currentUser |
|
65 | - * |
|
66 | - * @return bool |
|
67 | - * @category Security-Critical |
|
68 | - */ |
|
69 | - protected function isAllowedPrivateData(Request $request, User $currentUser) |
|
70 | - { |
|
71 | - // Test the main security barrier for private data access using SecurityManager |
|
72 | - if ($this->barrierTest('alwaysSeePrivateData', $currentUser, 'RequestData')) { |
|
73 | - // Tool admins/check-users can always see private data |
|
74 | - return true; |
|
75 | - } |
|
76 | - |
|
77 | - // reserving user is allowed to see the data |
|
78 | - if ($currentUser->getId() === $request->getReserved() |
|
79 | - && $request->getReserved() !== null |
|
80 | - && $this->barrierTest('seePrivateDataWhenReserved', $currentUser, 'RequestData') |
|
81 | - ) { |
|
82 | - return true; |
|
83 | - } |
|
84 | - |
|
85 | - // user has the reveal hash |
|
86 | - if (WebRequest::getString('hash') === $request->getRevealHash() |
|
87 | - && $this->barrierTest('seePrivateDataWithHash', $currentUser, 'RequestData') |
|
88 | - ) { |
|
89 | - return true; |
|
90 | - } |
|
91 | - |
|
92 | - // nope. Not allowed. |
|
93 | - return false; |
|
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * Tests the security barrier for a specified action. |
|
98 | - * |
|
99 | - * Don't use within templates |
|
100 | - * |
|
101 | - * @param string $action |
|
102 | - * |
|
103 | - * @param User $user |
|
104 | - * @param null|string $pageName |
|
105 | - * |
|
106 | - * @return bool |
|
107 | - * @category Security-Critical |
|
108 | - */ |
|
109 | - abstract protected function barrierTest($action, User $user, $pageName = null); |
|
110 | - |
|
111 | - /** |
|
112 | - * Gets the name of the route that has been passed from the request router. |
|
113 | - * @return string |
|
114 | - */ |
|
115 | - abstract protected function getRouteName(); |
|
116 | - |
|
117 | - /** @return SecurityManager */ |
|
118 | - abstract protected function getSecurityManager(); |
|
119 | - |
|
120 | - /** |
|
121 | - * Sets the name of the template this page should display. |
|
122 | - * |
|
123 | - * @param string $name |
|
124 | - */ |
|
125 | - abstract protected function setTemplate($name); |
|
126 | - |
|
127 | - /** @return IXffTrustProvider */ |
|
128 | - abstract protected function getXffTrustProvider(); |
|
129 | - |
|
130 | - /** @return ILocationProvider */ |
|
131 | - abstract protected function getLocationProvider(); |
|
132 | - |
|
133 | - /** @return IRDnsProvider */ |
|
134 | - abstract protected function getRdnsProvider(); |
|
135 | - |
|
136 | - /** |
|
137 | - * Assigns a Smarty variable |
|
138 | - * |
|
139 | - * @param array|string $name the template variable name(s) |
|
140 | - * @param mixed $value the value to assign |
|
141 | - */ |
|
142 | - abstract protected function assign($name, $value); |
|
143 | - |
|
144 | - /** |
|
145 | - * @param int $requestReservationId |
|
146 | - * @param PdoDatabase $database |
|
147 | - * @param User $currentUser |
|
148 | - */ |
|
149 | - protected function setupReservationDetails($requestReservationId, PdoDatabase $database, User $currentUser) |
|
150 | - { |
|
151 | - $requestIsReserved = $requestReservationId !== null; |
|
152 | - $this->assign('requestIsReserved', $requestIsReserved); |
|
153 | - $this->assign('requestIsReservedByMe', false); |
|
154 | - |
|
155 | - if ($requestIsReserved) { |
|
156 | - $this->assign('requestReservedByName', User::getById($requestReservationId, $database)->getUsername()); |
|
157 | - $this->assign('requestReservedById', $requestReservationId); |
|
158 | - |
|
159 | - if ($requestReservationId === $currentUser->getId()) { |
|
160 | - $this->assign('requestIsReservedByMe', true); |
|
161 | - } |
|
162 | - } |
|
163 | - |
|
164 | - $this->assign('canBreakReservation', $this->barrierTest('force', $currentUser, PageBreakReservation::class)); |
|
165 | - } |
|
166 | - |
|
167 | - /** |
|
168 | - * Adds private request data to Smarty. DO NOT USE WITHOUT FIRST CHECKING THAT THE USER IS AUTHORISED! |
|
169 | - * |
|
170 | - * @param Request $request |
|
171 | - * @param User $currentUser |
|
172 | - * @param SiteConfiguration $configuration |
|
173 | - * |
|
174 | - * @param PdoDatabase $database |
|
175 | - */ |
|
176 | - protected function setupPrivateData( |
|
177 | - $request, |
|
178 | - User $currentUser, |
|
179 | - SiteConfiguration $configuration, |
|
180 | - PdoDatabase $database |
|
181 | - ) { |
|
182 | - $xffProvider = $this->getXffTrustProvider(); |
|
183 | - |
|
184 | - $relatedEmailRequests = RequestSearchHelper::get($database) |
|
185 | - ->byEmailAddress($request->getEmail()) |
|
186 | - ->withConfirmedEmail() |
|
187 | - ->excludingPurgedData($configuration) |
|
188 | - ->excludingRequest($request->getId()) |
|
189 | - ->fetch(); |
|
190 | - |
|
191 | - $this->assign('requestEmail', $request->getEmail()); |
|
192 | - $emailDomain = explode("@", $request->getEmail())[1]; |
|
193 | - $this->assign("emailurl", $emailDomain); |
|
194 | - $this->assign('requestRelatedEmailRequestsCount', count($relatedEmailRequests)); |
|
195 | - $this->assign('requestRelatedEmailRequests', $relatedEmailRequests); |
|
196 | - |
|
197 | - $trustedIp = $xffProvider->getTrustedClientIp($request->getIp(), $request->getForwardedIp()); |
|
198 | - $this->assign('requestTrustedIp', $trustedIp); |
|
199 | - $this->assign('requestRealIp', $request->getIp()); |
|
200 | - $this->assign('requestForwardedIp', $request->getForwardedIp()); |
|
201 | - |
|
202 | - $trustedIpLocation = $this->getLocationProvider()->getIpLocation($trustedIp); |
|
203 | - $this->assign('requestTrustedIpLocation', $trustedIpLocation); |
|
204 | - |
|
205 | - $this->assign('requestHasForwardedIp', $request->getForwardedIp() !== null); |
|
206 | - |
|
207 | - $relatedIpRequests = RequestSearchHelper::get($database) |
|
208 | - ->byIp($trustedIp) |
|
209 | - ->withConfirmedEmail() |
|
210 | - ->excludingPurgedData($configuration) |
|
211 | - ->excludingRequest($request->getId()) |
|
212 | - ->fetch(); |
|
213 | - |
|
214 | - $this->assign('requestRelatedIpRequestsCount', count($relatedIpRequests)); |
|
215 | - $this->assign('requestRelatedIpRequests', $relatedIpRequests); |
|
216 | - |
|
217 | - $this->assign('showRevealLink', false); |
|
218 | - if ($request->getReserved() === $currentUser->getId() || |
|
219 | - $this->barrierTest('alwaysSeeHash', $currentUser, 'RequestData') |
|
220 | - ) { |
|
221 | - $this->assign('showRevealLink', true); |
|
222 | - $this->assign('revealHash', $request->getRevealHash()); |
|
223 | - } |
|
224 | - |
|
225 | - $this->setupForwardedIpData($request); |
|
226 | - } |
|
227 | - |
|
228 | - /** |
|
229 | - * Adds checkuser request data to Smarty. DO NOT USE WITHOUT FIRST CHECKING THAT THE USER IS AUTHORISED! |
|
230 | - * |
|
231 | - * @param Request $request |
|
232 | - */ |
|
233 | - protected function setupCheckUserData(Request $request) |
|
234 | - { |
|
235 | - $this->assign('requestUserAgent', $request->getUserAgent()); |
|
236 | - } |
|
237 | - |
|
238 | - /** |
|
239 | - * Sets up the basic data for this request, and adds it to Smarty |
|
240 | - * |
|
241 | - * @param Request $request |
|
242 | - * @param SiteConfiguration $config |
|
243 | - */ |
|
244 | - protected function setupBasicData(Request $request, SiteConfiguration $config) |
|
245 | - { |
|
246 | - $this->assign('requestId', $request->getId()); |
|
247 | - $this->assign('updateVersion', $request->getUpdateVersion()); |
|
248 | - $this->assign('requestName', $request->getName()); |
|
249 | - $this->assign('requestDate', $request->getDate()); |
|
250 | - $this->assign('requestStatus', $request->getStatus()); |
|
251 | - |
|
252 | - $this->assign('requestIsClosed', !array_key_exists($request->getStatus(), $config->getRequestStates())); |
|
253 | - } |
|
254 | - |
|
255 | - /** |
|
256 | - * Sets up the forwarded IP data for this request and adds it to Smarty |
|
257 | - * |
|
258 | - * @param Request $request |
|
259 | - */ |
|
260 | - protected function setupForwardedIpData(Request $request) |
|
261 | - { |
|
262 | - if ($request->getForwardedIp() !== null) { |
|
263 | - $requestProxyData = array(); // Initialize array to store data to be output in Smarty template. |
|
264 | - $proxyIndex = 0; |
|
265 | - |
|
266 | - // Assuming [client] <=> [proxy1] <=> [proxy2] <=> [proxy3] <=> [us], we will see an XFF header of [client], |
|
267 | - // [proxy1], [proxy2], and our actual IP will be [proxy3] |
|
268 | - $proxies = explode(",", $request->getForwardedIp()); |
|
269 | - $proxies[] = $request->getIp(); |
|
270 | - |
|
271 | - // Origin is the supposed "client" IP. |
|
272 | - $origin = $proxies[0]; |
|
273 | - $this->assign("forwardedOrigin", $origin); |
|
274 | - |
|
275 | - // We step through the servers in reverse order, from closest to furthest |
|
276 | - $proxies = array_reverse($proxies); |
|
277 | - |
|
278 | - // By default, we have trust, because the first in the chain is now REMOTE_ADDR, which is hardest to spoof. |
|
279 | - $trust = true; |
|
280 | - |
|
281 | - /** |
|
282 | - * @var int $index The zero-based index of the proxy. |
|
283 | - * @var string $proxyData The proxy IP address (although possibly not!) |
|
284 | - */ |
|
285 | - foreach ($proxies as $index => $proxyData) { |
|
286 | - $proxyAddress = trim($proxyData); |
|
287 | - $requestProxyData[$proxyIndex]['ip'] = $proxyAddress; |
|
288 | - |
|
289 | - // get data on this IP. |
|
290 | - $thisProxyIsTrusted = $this->getXffTrustProvider()->isTrusted($proxyAddress); |
|
291 | - |
|
292 | - $proxyIsInPrivateRange = $this->getXffTrustProvider() |
|
293 | - ->ipInRange(self::$rfc1918ips, $proxyAddress); |
|
294 | - |
|
295 | - if (!$proxyIsInPrivateRange) { |
|
296 | - $proxyReverseDns = $this->getRdnsProvider()->getReverseDNS($proxyAddress); |
|
297 | - $proxyLocation = $this->getLocationProvider()->getIpLocation($proxyAddress); |
|
298 | - } |
|
299 | - else { |
|
300 | - // this is going to fail, so why bother trying? |
|
301 | - $proxyReverseDns = false; |
|
302 | - $proxyLocation = false; |
|
303 | - } |
|
304 | - |
|
305 | - // current trust chain status BEFORE this link |
|
306 | - $preLinkTrust = $trust; |
|
307 | - |
|
308 | - // is *this* link trusted? Note, this will be true even if there is an untrusted link before this! |
|
309 | - $requestProxyData[$proxyIndex]['trustedlink'] = $thisProxyIsTrusted; |
|
310 | - |
|
311 | - // set the trust status of the chain to this point |
|
312 | - $trust = $trust & $thisProxyIsTrusted; |
|
313 | - |
|
314 | - // If this is the origin address, and the chain was trusted before this point, then we can trust |
|
315 | - // the origin. |
|
316 | - if ($preLinkTrust && $proxyAddress == $origin) { |
|
317 | - // if this is the origin, then we are at the last point in the chain. |
|
318 | - // @todo: this is probably the cause of some bugs when an IP appears twice - we're missing a check |
|
319 | - // to see if this is *really* the last in the chain, rather than just the same IP as it. |
|
320 | - $trust = true; |
|
321 | - } |
|
322 | - |
|
323 | - $requestProxyData[$proxyIndex]['trust'] = $trust; |
|
324 | - |
|
325 | - $requestProxyData[$proxyIndex]['rdnsfailed'] = $proxyReverseDns === false; |
|
326 | - $requestProxyData[$proxyIndex]['rdns'] = $proxyReverseDns; |
|
327 | - $requestProxyData[$proxyIndex]['routable'] = !$proxyIsInPrivateRange; |
|
328 | - |
|
329 | - $requestProxyData[$proxyIndex]['location'] = $proxyLocation; |
|
330 | - |
|
331 | - if ($proxyReverseDns === $proxyAddress && $proxyIsInPrivateRange === false) { |
|
332 | - $requestProxyData[$proxyIndex]['rdns'] = null; |
|
333 | - } |
|
334 | - |
|
335 | - $showLinks = (!$trust || $proxyAddress == $origin) && !$proxyIsInPrivateRange; |
|
336 | - $requestProxyData[$proxyIndex]['showlinks'] = $showLinks; |
|
337 | - |
|
338 | - $proxyIndex++; |
|
339 | - } |
|
340 | - |
|
341 | - $this->assign("requestProxyData", $requestProxyData); |
|
342 | - } |
|
343 | - } |
|
26 | + /** |
|
27 | + * @var array Array of IP address classed as 'private' by RFC1918. |
|
28 | + */ |
|
29 | + protected static $rfc1918ips = array( |
|
30 | + "10.0.0.0" => "10.255.255.255", |
|
31 | + "172.16.0.0" => "172.31.255.255", |
|
32 | + "192.168.0.0" => "192.168.255.255", |
|
33 | + "169.254.0.0" => "169.254.255.255", |
|
34 | + "127.0.0.0" => "127.255.255.255", |
|
35 | + ); |
|
36 | + |
|
37 | + /** |
|
38 | + * Gets a request object |
|
39 | + * |
|
40 | + * @param PdoDatabase $database The database connection |
|
41 | + * @param int $requestId The ID of the request to retrieve |
|
42 | + * |
|
43 | + * @return Request |
|
44 | + * @throws ApplicationLogicException |
|
45 | + */ |
|
46 | + protected function getRequest(PdoDatabase $database, $requestId) |
|
47 | + { |
|
48 | + if ($requestId === null) { |
|
49 | + throw new ApplicationLogicException("No request specified"); |
|
50 | + } |
|
51 | + |
|
52 | + $request = Request::getById($requestId, $database); |
|
53 | + if ($request === false || !is_a($request, Request::class)) { |
|
54 | + throw new ApplicationLogicException('Could not load the requested request!'); |
|
55 | + } |
|
56 | + |
|
57 | + return $request; |
|
58 | + } |
|
59 | + |
|
60 | + /** |
|
61 | + * Returns a value stating whether the user is allowed to see private data or not |
|
62 | + * |
|
63 | + * @param Request $request |
|
64 | + * @param User $currentUser |
|
65 | + * |
|
66 | + * @return bool |
|
67 | + * @category Security-Critical |
|
68 | + */ |
|
69 | + protected function isAllowedPrivateData(Request $request, User $currentUser) |
|
70 | + { |
|
71 | + // Test the main security barrier for private data access using SecurityManager |
|
72 | + if ($this->barrierTest('alwaysSeePrivateData', $currentUser, 'RequestData')) { |
|
73 | + // Tool admins/check-users can always see private data |
|
74 | + return true; |
|
75 | + } |
|
76 | + |
|
77 | + // reserving user is allowed to see the data |
|
78 | + if ($currentUser->getId() === $request->getReserved() |
|
79 | + && $request->getReserved() !== null |
|
80 | + && $this->barrierTest('seePrivateDataWhenReserved', $currentUser, 'RequestData') |
|
81 | + ) { |
|
82 | + return true; |
|
83 | + } |
|
84 | + |
|
85 | + // user has the reveal hash |
|
86 | + if (WebRequest::getString('hash') === $request->getRevealHash() |
|
87 | + && $this->barrierTest('seePrivateDataWithHash', $currentUser, 'RequestData') |
|
88 | + ) { |
|
89 | + return true; |
|
90 | + } |
|
91 | + |
|
92 | + // nope. Not allowed. |
|
93 | + return false; |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * Tests the security barrier for a specified action. |
|
98 | + * |
|
99 | + * Don't use within templates |
|
100 | + * |
|
101 | + * @param string $action |
|
102 | + * |
|
103 | + * @param User $user |
|
104 | + * @param null|string $pageName |
|
105 | + * |
|
106 | + * @return bool |
|
107 | + * @category Security-Critical |
|
108 | + */ |
|
109 | + abstract protected function barrierTest($action, User $user, $pageName = null); |
|
110 | + |
|
111 | + /** |
|
112 | + * Gets the name of the route that has been passed from the request router. |
|
113 | + * @return string |
|
114 | + */ |
|
115 | + abstract protected function getRouteName(); |
|
116 | + |
|
117 | + /** @return SecurityManager */ |
|
118 | + abstract protected function getSecurityManager(); |
|
119 | + |
|
120 | + /** |
|
121 | + * Sets the name of the template this page should display. |
|
122 | + * |
|
123 | + * @param string $name |
|
124 | + */ |
|
125 | + abstract protected function setTemplate($name); |
|
126 | + |
|
127 | + /** @return IXffTrustProvider */ |
|
128 | + abstract protected function getXffTrustProvider(); |
|
129 | + |
|
130 | + /** @return ILocationProvider */ |
|
131 | + abstract protected function getLocationProvider(); |
|
132 | + |
|
133 | + /** @return IRDnsProvider */ |
|
134 | + abstract protected function getRdnsProvider(); |
|
135 | + |
|
136 | + /** |
|
137 | + * Assigns a Smarty variable |
|
138 | + * |
|
139 | + * @param array|string $name the template variable name(s) |
|
140 | + * @param mixed $value the value to assign |
|
141 | + */ |
|
142 | + abstract protected function assign($name, $value); |
|
143 | + |
|
144 | + /** |
|
145 | + * @param int $requestReservationId |
|
146 | + * @param PdoDatabase $database |
|
147 | + * @param User $currentUser |
|
148 | + */ |
|
149 | + protected function setupReservationDetails($requestReservationId, PdoDatabase $database, User $currentUser) |
|
150 | + { |
|
151 | + $requestIsReserved = $requestReservationId !== null; |
|
152 | + $this->assign('requestIsReserved', $requestIsReserved); |
|
153 | + $this->assign('requestIsReservedByMe', false); |
|
154 | + |
|
155 | + if ($requestIsReserved) { |
|
156 | + $this->assign('requestReservedByName', User::getById($requestReservationId, $database)->getUsername()); |
|
157 | + $this->assign('requestReservedById', $requestReservationId); |
|
158 | + |
|
159 | + if ($requestReservationId === $currentUser->getId()) { |
|
160 | + $this->assign('requestIsReservedByMe', true); |
|
161 | + } |
|
162 | + } |
|
163 | + |
|
164 | + $this->assign('canBreakReservation', $this->barrierTest('force', $currentUser, PageBreakReservation::class)); |
|
165 | + } |
|
166 | + |
|
167 | + /** |
|
168 | + * Adds private request data to Smarty. DO NOT USE WITHOUT FIRST CHECKING THAT THE USER IS AUTHORISED! |
|
169 | + * |
|
170 | + * @param Request $request |
|
171 | + * @param User $currentUser |
|
172 | + * @param SiteConfiguration $configuration |
|
173 | + * |
|
174 | + * @param PdoDatabase $database |
|
175 | + */ |
|
176 | + protected function setupPrivateData( |
|
177 | + $request, |
|
178 | + User $currentUser, |
|
179 | + SiteConfiguration $configuration, |
|
180 | + PdoDatabase $database |
|
181 | + ) { |
|
182 | + $xffProvider = $this->getXffTrustProvider(); |
|
183 | + |
|
184 | + $relatedEmailRequests = RequestSearchHelper::get($database) |
|
185 | + ->byEmailAddress($request->getEmail()) |
|
186 | + ->withConfirmedEmail() |
|
187 | + ->excludingPurgedData($configuration) |
|
188 | + ->excludingRequest($request->getId()) |
|
189 | + ->fetch(); |
|
190 | + |
|
191 | + $this->assign('requestEmail', $request->getEmail()); |
|
192 | + $emailDomain = explode("@", $request->getEmail())[1]; |
|
193 | + $this->assign("emailurl", $emailDomain); |
|
194 | + $this->assign('requestRelatedEmailRequestsCount', count($relatedEmailRequests)); |
|
195 | + $this->assign('requestRelatedEmailRequests', $relatedEmailRequests); |
|
196 | + |
|
197 | + $trustedIp = $xffProvider->getTrustedClientIp($request->getIp(), $request->getForwardedIp()); |
|
198 | + $this->assign('requestTrustedIp', $trustedIp); |
|
199 | + $this->assign('requestRealIp', $request->getIp()); |
|
200 | + $this->assign('requestForwardedIp', $request->getForwardedIp()); |
|
201 | + |
|
202 | + $trustedIpLocation = $this->getLocationProvider()->getIpLocation($trustedIp); |
|
203 | + $this->assign('requestTrustedIpLocation', $trustedIpLocation); |
|
204 | + |
|
205 | + $this->assign('requestHasForwardedIp', $request->getForwardedIp() !== null); |
|
206 | + |
|
207 | + $relatedIpRequests = RequestSearchHelper::get($database) |
|
208 | + ->byIp($trustedIp) |
|
209 | + ->withConfirmedEmail() |
|
210 | + ->excludingPurgedData($configuration) |
|
211 | + ->excludingRequest($request->getId()) |
|
212 | + ->fetch(); |
|
213 | + |
|
214 | + $this->assign('requestRelatedIpRequestsCount', count($relatedIpRequests)); |
|
215 | + $this->assign('requestRelatedIpRequests', $relatedIpRequests); |
|
216 | + |
|
217 | + $this->assign('showRevealLink', false); |
|
218 | + if ($request->getReserved() === $currentUser->getId() || |
|
219 | + $this->barrierTest('alwaysSeeHash', $currentUser, 'RequestData') |
|
220 | + ) { |
|
221 | + $this->assign('showRevealLink', true); |
|
222 | + $this->assign('revealHash', $request->getRevealHash()); |
|
223 | + } |
|
224 | + |
|
225 | + $this->setupForwardedIpData($request); |
|
226 | + } |
|
227 | + |
|
228 | + /** |
|
229 | + * Adds checkuser request data to Smarty. DO NOT USE WITHOUT FIRST CHECKING THAT THE USER IS AUTHORISED! |
|
230 | + * |
|
231 | + * @param Request $request |
|
232 | + */ |
|
233 | + protected function setupCheckUserData(Request $request) |
|
234 | + { |
|
235 | + $this->assign('requestUserAgent', $request->getUserAgent()); |
|
236 | + } |
|
237 | + |
|
238 | + /** |
|
239 | + * Sets up the basic data for this request, and adds it to Smarty |
|
240 | + * |
|
241 | + * @param Request $request |
|
242 | + * @param SiteConfiguration $config |
|
243 | + */ |
|
244 | + protected function setupBasicData(Request $request, SiteConfiguration $config) |
|
245 | + { |
|
246 | + $this->assign('requestId', $request->getId()); |
|
247 | + $this->assign('updateVersion', $request->getUpdateVersion()); |
|
248 | + $this->assign('requestName', $request->getName()); |
|
249 | + $this->assign('requestDate', $request->getDate()); |
|
250 | + $this->assign('requestStatus', $request->getStatus()); |
|
251 | + |
|
252 | + $this->assign('requestIsClosed', !array_key_exists($request->getStatus(), $config->getRequestStates())); |
|
253 | + } |
|
254 | + |
|
255 | + /** |
|
256 | + * Sets up the forwarded IP data for this request and adds it to Smarty |
|
257 | + * |
|
258 | + * @param Request $request |
|
259 | + */ |
|
260 | + protected function setupForwardedIpData(Request $request) |
|
261 | + { |
|
262 | + if ($request->getForwardedIp() !== null) { |
|
263 | + $requestProxyData = array(); // Initialize array to store data to be output in Smarty template. |
|
264 | + $proxyIndex = 0; |
|
265 | + |
|
266 | + // Assuming [client] <=> [proxy1] <=> [proxy2] <=> [proxy3] <=> [us], we will see an XFF header of [client], |
|
267 | + // [proxy1], [proxy2], and our actual IP will be [proxy3] |
|
268 | + $proxies = explode(",", $request->getForwardedIp()); |
|
269 | + $proxies[] = $request->getIp(); |
|
270 | + |
|
271 | + // Origin is the supposed "client" IP. |
|
272 | + $origin = $proxies[0]; |
|
273 | + $this->assign("forwardedOrigin", $origin); |
|
274 | + |
|
275 | + // We step through the servers in reverse order, from closest to furthest |
|
276 | + $proxies = array_reverse($proxies); |
|
277 | + |
|
278 | + // By default, we have trust, because the first in the chain is now REMOTE_ADDR, which is hardest to spoof. |
|
279 | + $trust = true; |
|
280 | + |
|
281 | + /** |
|
282 | + * @var int $index The zero-based index of the proxy. |
|
283 | + * @var string $proxyData The proxy IP address (although possibly not!) |
|
284 | + */ |
|
285 | + foreach ($proxies as $index => $proxyData) { |
|
286 | + $proxyAddress = trim($proxyData); |
|
287 | + $requestProxyData[$proxyIndex]['ip'] = $proxyAddress; |
|
288 | + |
|
289 | + // get data on this IP. |
|
290 | + $thisProxyIsTrusted = $this->getXffTrustProvider()->isTrusted($proxyAddress); |
|
291 | + |
|
292 | + $proxyIsInPrivateRange = $this->getXffTrustProvider() |
|
293 | + ->ipInRange(self::$rfc1918ips, $proxyAddress); |
|
294 | + |
|
295 | + if (!$proxyIsInPrivateRange) { |
|
296 | + $proxyReverseDns = $this->getRdnsProvider()->getReverseDNS($proxyAddress); |
|
297 | + $proxyLocation = $this->getLocationProvider()->getIpLocation($proxyAddress); |
|
298 | + } |
|
299 | + else { |
|
300 | + // this is going to fail, so why bother trying? |
|
301 | + $proxyReverseDns = false; |
|
302 | + $proxyLocation = false; |
|
303 | + } |
|
304 | + |
|
305 | + // current trust chain status BEFORE this link |
|
306 | + $preLinkTrust = $trust; |
|
307 | + |
|
308 | + // is *this* link trusted? Note, this will be true even if there is an untrusted link before this! |
|
309 | + $requestProxyData[$proxyIndex]['trustedlink'] = $thisProxyIsTrusted; |
|
310 | + |
|
311 | + // set the trust status of the chain to this point |
|
312 | + $trust = $trust & $thisProxyIsTrusted; |
|
313 | + |
|
314 | + // If this is the origin address, and the chain was trusted before this point, then we can trust |
|
315 | + // the origin. |
|
316 | + if ($preLinkTrust && $proxyAddress == $origin) { |
|
317 | + // if this is the origin, then we are at the last point in the chain. |
|
318 | + // @todo: this is probably the cause of some bugs when an IP appears twice - we're missing a check |
|
319 | + // to see if this is *really* the last in the chain, rather than just the same IP as it. |
|
320 | + $trust = true; |
|
321 | + } |
|
322 | + |
|
323 | + $requestProxyData[$proxyIndex]['trust'] = $trust; |
|
324 | + |
|
325 | + $requestProxyData[$proxyIndex]['rdnsfailed'] = $proxyReverseDns === false; |
|
326 | + $requestProxyData[$proxyIndex]['rdns'] = $proxyReverseDns; |
|
327 | + $requestProxyData[$proxyIndex]['routable'] = !$proxyIsInPrivateRange; |
|
328 | + |
|
329 | + $requestProxyData[$proxyIndex]['location'] = $proxyLocation; |
|
330 | + |
|
331 | + if ($proxyReverseDns === $proxyAddress && $proxyIsInPrivateRange === false) { |
|
332 | + $requestProxyData[$proxyIndex]['rdns'] = null; |
|
333 | + } |
|
334 | + |
|
335 | + $showLinks = (!$trust || $proxyAddress == $origin) && !$proxyIsInPrivateRange; |
|
336 | + $requestProxyData[$proxyIndex]['showlinks'] = $showLinks; |
|
337 | + |
|
338 | + $proxyIndex++; |
|
339 | + } |
|
340 | + |
|
341 | + $this->assign("requestProxyData", $requestProxyData); |
|
342 | + } |
|
343 | + } |
|
344 | 344 | } |
@@ -47,7 +47,7 @@ |
||
47 | 47 | /** |
48 | 48 | * Gets the default route if no explicit route is requested. |
49 | 49 | * |
50 | - * @return callable |
|
50 | + * @return string[] |
|
51 | 51 | */ |
52 | 52 | protected function getDefaultRoute() |
53 | 53 | { |
@@ -15,42 +15,42 @@ |
||
15 | 15 | |
16 | 16 | class PublicRequestRouter extends RequestRouter |
17 | 17 | { |
18 | - /** |
|
19 | - * Gets the route map to be used by this request router. |
|
20 | - * |
|
21 | - * @return array |
|
22 | - */ |
|
23 | - protected function getRouteMap() |
|
24 | - { |
|
25 | - return array( |
|
26 | - // Page showing a message stating the request has been submitted to our internal queues |
|
27 | - 'requestSubmitted' => |
|
28 | - array( |
|
29 | - 'class' => PageRequestSubmitted::class, |
|
30 | - 'actions' => array(), |
|
31 | - ), |
|
32 | - // Page showing a message stating that email confirmation is required to continue |
|
33 | - 'emailConfirmationRequired' => |
|
34 | - array( |
|
35 | - 'class' => PageEmailConfirmationRequired::class, |
|
36 | - 'actions' => array(), |
|
37 | - ), |
|
38 | - // Action page which handles email confirmation |
|
39 | - 'confirmEmail' => |
|
40 | - array( |
|
41 | - 'class' => PageConfirmEmail::class, |
|
42 | - 'actions' => array(), |
|
43 | - ), |
|
44 | - ); |
|
45 | - } |
|
18 | + /** |
|
19 | + * Gets the route map to be used by this request router. |
|
20 | + * |
|
21 | + * @return array |
|
22 | + */ |
|
23 | + protected function getRouteMap() |
|
24 | + { |
|
25 | + return array( |
|
26 | + // Page showing a message stating the request has been submitted to our internal queues |
|
27 | + 'requestSubmitted' => |
|
28 | + array( |
|
29 | + 'class' => PageRequestSubmitted::class, |
|
30 | + 'actions' => array(), |
|
31 | + ), |
|
32 | + // Page showing a message stating that email confirmation is required to continue |
|
33 | + 'emailConfirmationRequired' => |
|
34 | + array( |
|
35 | + 'class' => PageEmailConfirmationRequired::class, |
|
36 | + 'actions' => array(), |
|
37 | + ), |
|
38 | + // Action page which handles email confirmation |
|
39 | + 'confirmEmail' => |
|
40 | + array( |
|
41 | + 'class' => PageConfirmEmail::class, |
|
42 | + 'actions' => array(), |
|
43 | + ), |
|
44 | + ); |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * Gets the default route if no explicit route is requested. |
|
49 | - * |
|
50 | - * @return callable |
|
51 | - */ |
|
52 | - protected function getDefaultRoute() |
|
53 | - { |
|
54 | - return array(PageRequestAccount::class, 'main'); |
|
55 | - } |
|
47 | + /** |
|
48 | + * Gets the default route if no explicit route is requested. |
|
49 | + * |
|
50 | + * @return callable |
|
51 | + */ |
|
52 | + protected function getDefaultRoute() |
|
53 | + { |
|
54 | + return array(PageRequestAccount::class, 'main'); |
|
55 | + } |
|
56 | 56 | } |
57 | 57 | \ No newline at end of file |
@@ -435,7 +435,7 @@ |
||
435 | 435 | } |
436 | 436 | |
437 | 437 | /** |
438 | - * @return callable |
|
438 | + * @return string[] |
|
439 | 439 | */ |
440 | 440 | protected function getDefaultRoute() |
441 | 441 | { |
@@ -358,7 +358,7 @@ |
||
358 | 358 | $routeMap = $this->routePathSegments($classSegment, $requestedAction); |
359 | 359 | |
360 | 360 | if ($routeMap[0] === Page404::class) { |
361 | - $routeMap = $this->routeSinglePathSegment($classSegment . '/' . $requestedAction); |
|
361 | + $routeMap = $this->routeSinglePathSegment($classSegment.'/'.$requestedAction); |
|
362 | 362 | } |
363 | 363 | |
364 | 364 | return $routeMap; |
@@ -21,14 +21,14 @@ |
||
21 | 21 | use Waca\Pages\PageMain; |
22 | 22 | use Waca\Pages\PageOAuth; |
23 | 23 | use Waca\Pages\PagePreferences; |
24 | -use Waca\Pages\Registration\PageRegisterStandard; |
|
25 | -use Waca\Pages\Registration\PageRegisterOption; |
|
26 | 24 | use Waca\Pages\PageSearch; |
27 | 25 | use Waca\Pages\PageSiteNotice; |
28 | 26 | use Waca\Pages\PageTeam; |
29 | 27 | use Waca\Pages\PageUserManagement; |
30 | 28 | use Waca\Pages\PageViewRequest; |
31 | 29 | use Waca\Pages\PageWelcomeTemplateManagement; |
30 | +use Waca\Pages\Registration\PageRegisterOption; |
|
31 | +use Waca\Pages\Registration\PageRegisterStandard; |
|
32 | 32 | use Waca\Pages\RequestAction\PageBreakReservation; |
33 | 33 | use Waca\Pages\RequestAction\PageCloseRequest; |
34 | 34 | use Waca\Pages\RequestAction\PageComment; |
@@ -55,395 +55,395 @@ |
||
55 | 55 | */ |
56 | 56 | class RequestRouter implements IRequestRouter |
57 | 57 | { |
58 | - /** |
|
59 | - * This is the core routing table for the application. The basic idea is: |
|
60 | - * |
|
61 | - * array( |
|
62 | - * "foo" => |
|
63 | - * array( |
|
64 | - * "class" => PageFoo::class, |
|
65 | - * "actions" => array("bar", "other") |
|
66 | - * ), |
|
67 | - * ); |
|
68 | - * |
|
69 | - * Things to note: |
|
70 | - * - If no page is requested, we go to PageMain. PageMain can't have actions defined. |
|
71 | - * |
|
72 | - * - If a page is defined and requested, but no action is requested, go to that page's main() method |
|
73 | - * - If a page is defined and requested, and an action is defined and requested, go to that action's method. |
|
74 | - * - If a page is defined and requested, and an action NOT defined and requested, go to Page404 and it's main() |
|
75 | - * method. |
|
76 | - * - If a page is NOT defined and requested, go to Page404 and it's main() method. |
|
77 | - * |
|
78 | - * - Query parameters are ignored. |
|
79 | - * |
|
80 | - * The key point here is request routing with validation that this is allowed, before we start hitting the |
|
81 | - * filesystem through the AutoLoader, and opening random files. Also, so that we validate the action requested |
|
82 | - * before we start calling random methods through the web UI. |
|
83 | - * |
|
84 | - * Examples: |
|
85 | - * /internal.php => returns instance of PageMain, routed to main() |
|
86 | - * /internal.php?query => returns instance of PageMain, routed to main() |
|
87 | - * /internal.php/foo => returns instance of PageFoo, routed to main() |
|
88 | - * /internal.php/foo?query => returns instance of PageFoo, routed to main() |
|
89 | - * /internal.php/foo/bar => returns instance of PageFoo, routed to bar() |
|
90 | - * /internal.php/foo/bar?query => returns instance of PageFoo, routed to bar() |
|
91 | - * /internal.php/foo/baz => returns instance of Page404, routed to main() |
|
92 | - * /internal.php/foo/baz?query => returns instance of Page404, routed to main() |
|
93 | - * /internal.php/bar => returns instance of Page404, routed to main() |
|
94 | - * /internal.php/bar?query => returns instance of Page404, routed to main() |
|
95 | - * /internal.php/bar/baz => returns instance of Page404, routed to main() |
|
96 | - * /internal.php/bar/baz?query => returns instance of Page404, routed to main() |
|
97 | - * |
|
98 | - * Take care when changing this - a lot of places rely on the array key for redirects and other links. If you need |
|
99 | - * to change the key, then you'll likely have to update a lot of files. |
|
100 | - * |
|
101 | - * @var array |
|
102 | - */ |
|
103 | - private $routeMap = array( |
|
104 | - |
|
105 | - ////////////////////////////////////////////////////////////////////////////////////////////////// |
|
106 | - // Login and registration |
|
107 | - 'logout' => |
|
108 | - array( |
|
109 | - 'class' => PageLogout::class, |
|
110 | - 'actions' => array(), |
|
111 | - ), |
|
112 | - 'login' => |
|
113 | - array( |
|
114 | - 'class' => PageLogin::class, |
|
115 | - 'actions' => array(), |
|
116 | - ), |
|
117 | - 'forgotPassword' => |
|
118 | - array( |
|
119 | - 'class' => PageForgotPassword::class, |
|
120 | - 'actions' => array('reset'), |
|
121 | - ), |
|
122 | - 'register' => |
|
123 | - array( |
|
124 | - 'class' => PageRegisterOption::class, |
|
125 | - 'actions' => array(), |
|
126 | - ), |
|
127 | - 'register/standard' => |
|
128 | - array( |
|
129 | - 'class' => PageRegisterStandard::class, |
|
130 | - 'actions' => array('done'), |
|
131 | - ), |
|
132 | - |
|
133 | - ////////////////////////////////////////////////////////////////////////////////////////////////// |
|
134 | - // Discovery |
|
135 | - 'search' => |
|
136 | - array( |
|
137 | - 'class' => PageSearch::class, |
|
138 | - 'actions' => array(), |
|
139 | - ), |
|
140 | - 'logs' => |
|
141 | - array( |
|
142 | - 'class' => PageLog::class, |
|
143 | - 'actions' => array(), |
|
144 | - ), |
|
145 | - |
|
146 | - ////////////////////////////////////////////////////////////////////////////////////////////////// |
|
147 | - // Administration |
|
148 | - 'bans' => |
|
149 | - array( |
|
150 | - 'class' => PageBan::class, |
|
151 | - 'actions' => array('set', 'remove'), |
|
152 | - ), |
|
153 | - 'userManagement' => |
|
154 | - array( |
|
155 | - 'class' => PageUserManagement::class, |
|
156 | - 'actions' => array( |
|
157 | - 'approve', |
|
158 | - 'decline', |
|
159 | - 'rename', |
|
160 | - 'editUser', |
|
161 | - 'suspend', |
|
162 | - 'editRoles', |
|
163 | - ), |
|
164 | - ), |
|
165 | - 'siteNotice' => |
|
166 | - array( |
|
167 | - 'class' => PageSiteNotice::class, |
|
168 | - 'actions' => array(), |
|
169 | - ), |
|
170 | - 'emailManagement' => |
|
171 | - array( |
|
172 | - 'class' => PageEmailManagement::class, |
|
173 | - 'actions' => array('create', 'edit', 'view'), |
|
174 | - ), |
|
175 | - |
|
176 | - ////////////////////////////////////////////////////////////////////////////////////////////////// |
|
177 | - // Personal preferences |
|
178 | - 'preferences' => |
|
179 | - array( |
|
180 | - 'class' => PagePreferences::class, |
|
181 | - 'actions' => array('changePassword'), |
|
182 | - ), |
|
183 | - 'oauth' => |
|
184 | - array( |
|
185 | - 'class' => PageOAuth::class, |
|
186 | - 'actions' => array('detach', 'attach'), |
|
187 | - ), |
|
188 | - |
|
189 | - ////////////////////////////////////////////////////////////////////////////////////////////////// |
|
190 | - // Welcomer configuration |
|
191 | - 'welcomeTemplates' => |
|
192 | - array( |
|
193 | - 'class' => PageWelcomeTemplateManagement::class, |
|
194 | - 'actions' => array('select', 'edit', 'delete', 'add', 'view'), |
|
195 | - ), |
|
196 | - |
|
197 | - ////////////////////////////////////////////////////////////////////////////////////////////////// |
|
198 | - // Statistics |
|
199 | - 'statistics' => |
|
200 | - array( |
|
201 | - 'class' => StatsMain::class, |
|
202 | - 'actions' => array(), |
|
203 | - ), |
|
204 | - 'statistics/fastCloses' => |
|
205 | - array( |
|
206 | - 'class' => StatsFastCloses::class, |
|
207 | - 'actions' => array(), |
|
208 | - ), |
|
209 | - 'statistics/inactiveUsers' => |
|
210 | - array( |
|
211 | - 'class' => StatsInactiveUsers::class, |
|
212 | - 'actions' => array(), |
|
213 | - ), |
|
214 | - 'statistics/monthlyStats' => |
|
215 | - array( |
|
216 | - 'class' => StatsMonthlyStats::class, |
|
217 | - 'actions' => array(), |
|
218 | - ), |
|
219 | - 'statistics/reservedRequests' => |
|
220 | - array( |
|
221 | - 'class' => StatsReservedRequests::class, |
|
222 | - 'actions' => array(), |
|
223 | - ), |
|
224 | - 'statistics/templateStats' => |
|
225 | - array( |
|
226 | - 'class' => StatsTemplateStats::class, |
|
227 | - 'actions' => array(), |
|
228 | - ), |
|
229 | - 'statistics/topCreators' => |
|
230 | - array( |
|
231 | - 'class' => StatsTopCreators::class, |
|
232 | - 'actions' => array(), |
|
233 | - ), |
|
234 | - 'statistics/users' => |
|
235 | - array( |
|
236 | - 'class' => StatsUsers::class, |
|
237 | - 'actions' => array('detail'), |
|
238 | - ), |
|
239 | - |
|
240 | - ////////////////////////////////////////////////////////////////////////////////////////////////// |
|
241 | - // Zoom page |
|
242 | - 'viewRequest' => |
|
243 | - array( |
|
244 | - 'class' => PageViewRequest::class, |
|
245 | - 'actions' => array(), |
|
246 | - ), |
|
247 | - 'viewRequest/reserve' => |
|
248 | - array( |
|
249 | - 'class' => PageReservation::class, |
|
250 | - 'actions' => array(), |
|
251 | - ), |
|
252 | - 'viewRequest/breakReserve' => |
|
253 | - array( |
|
254 | - 'class' => PageBreakReservation::class, |
|
255 | - 'actions' => array(), |
|
256 | - ), |
|
257 | - 'viewRequest/defer' => |
|
258 | - array( |
|
259 | - 'class' => PageDeferRequest::class, |
|
260 | - 'actions' => array(), |
|
261 | - ), |
|
262 | - 'viewRequest/comment' => |
|
263 | - array( |
|
264 | - 'class' => PageComment::class, |
|
265 | - 'actions' => array(), |
|
266 | - ), |
|
267 | - 'viewRequest/sendToUser' => |
|
268 | - array( |
|
269 | - 'class' => PageSendToUser::class, |
|
270 | - 'actions' => array(), |
|
271 | - ), |
|
272 | - 'viewRequest/close' => |
|
273 | - array( |
|
274 | - 'class' => PageCloseRequest::class, |
|
275 | - 'actions' => array(), |
|
276 | - ), |
|
277 | - 'viewRequest/drop' => |
|
278 | - array( |
|
279 | - 'class' => PageDropRequest::class, |
|
280 | - 'actions' => array(), |
|
281 | - ), |
|
282 | - 'viewRequest/custom' => |
|
283 | - array( |
|
284 | - 'class' => PageCustomClose::class, |
|
285 | - 'actions' => array(), |
|
286 | - ), |
|
287 | - 'editComment' => |
|
288 | - array( |
|
289 | - 'class' => PageEditComment::class, |
|
290 | - 'actions' => array(), |
|
291 | - ), |
|
292 | - |
|
293 | - ////////////////////////////////////////////////////////////////////////////////////////////////// |
|
294 | - // Misc stuff |
|
295 | - 'team' => |
|
296 | - array( |
|
297 | - 'class' => PageTeam::class, |
|
298 | - 'actions' => array(), |
|
299 | - ), |
|
300 | - 'requestList' => |
|
301 | - array( |
|
302 | - 'class' => PageExpandedRequestList::class, |
|
303 | - 'actions' => array(), |
|
304 | - ), |
|
305 | - ); |
|
306 | - |
|
307 | - /** |
|
308 | - * @return IRoutedTask |
|
309 | - * @throws Exception |
|
310 | - */ |
|
311 | - final public function route() |
|
312 | - { |
|
313 | - $pathInfo = WebRequest::pathInfo(); |
|
314 | - |
|
315 | - list($pageClass, $action) = $this->getRouteFromPath($pathInfo); |
|
316 | - |
|
317 | - /** @var IRoutedTask $page */ |
|
318 | - $page = new $pageClass(); |
|
319 | - |
|
320 | - // Dynamic creation, so we've got to be careful here. We can't use built-in language type protection, so |
|
321 | - // let's use our own. |
|
322 | - if (!($page instanceof IRoutedTask)) { |
|
323 | - throw new Exception('Expected a page, but this is not a page.'); |
|
324 | - } |
|
325 | - |
|
326 | - // OK, I'm happy at this point that we know we're running a page, and we know it's probably what we want if it |
|
327 | - // inherits PageBase and has been created from the routing map. |
|
328 | - $page->setRoute($action); |
|
329 | - |
|
330 | - return $page; |
|
331 | - } |
|
332 | - |
|
333 | - /** |
|
334 | - * @param $pathInfo |
|
335 | - * |
|
336 | - * @return array |
|
337 | - */ |
|
338 | - protected function getRouteFromPath($pathInfo) |
|
339 | - { |
|
340 | - if (count($pathInfo) === 0) { |
|
341 | - // No pathInfo, so no page to load. Load the main page. |
|
342 | - return $this->getDefaultRoute(); |
|
343 | - } |
|
344 | - elseif (count($pathInfo) === 1) { |
|
345 | - // Exactly one path info segment, it's got to be a page. |
|
346 | - $classSegment = $pathInfo[0]; |
|
347 | - |
|
348 | - return $this->routeSinglePathSegment($classSegment); |
|
349 | - } |
|
350 | - |
|
351 | - // OK, we have two or more segments now. |
|
352 | - if (count($pathInfo) > 2) { |
|
353 | - // Let's handle more than two, and collapse it down into two. |
|
354 | - $requestedAction = array_pop($pathInfo); |
|
355 | - $classSegment = implode('/', $pathInfo); |
|
356 | - } |
|
357 | - else { |
|
358 | - // Two path info segments. |
|
359 | - $classSegment = $pathInfo[0]; |
|
360 | - $requestedAction = $pathInfo[1]; |
|
361 | - } |
|
362 | - |
|
363 | - $routeMap = $this->routePathSegments($classSegment, $requestedAction); |
|
364 | - |
|
365 | - if ($routeMap[0] === Page404::class) { |
|
366 | - $routeMap = $this->routeSinglePathSegment($classSegment . '/' . $requestedAction); |
|
367 | - } |
|
368 | - |
|
369 | - return $routeMap; |
|
370 | - } |
|
371 | - |
|
372 | - /** |
|
373 | - * @param $classSegment |
|
374 | - * |
|
375 | - * @return array |
|
376 | - */ |
|
377 | - final protected function routeSinglePathSegment($classSegment) |
|
378 | - { |
|
379 | - $routeMap = $this->getRouteMap(); |
|
380 | - if (array_key_exists($classSegment, $routeMap)) { |
|
381 | - // Route exists, but we don't have an action in path info, so default to main. |
|
382 | - $pageClass = $routeMap[$classSegment]['class']; |
|
383 | - $action = 'main'; |
|
384 | - |
|
385 | - return array($pageClass, $action); |
|
386 | - } |
|
387 | - else { |
|
388 | - // Doesn't exist in map. Fall back to 404 |
|
389 | - $pageClass = Page404::class; |
|
390 | - $action = "main"; |
|
391 | - |
|
392 | - return array($pageClass, $action); |
|
393 | - } |
|
394 | - } |
|
395 | - |
|
396 | - /** |
|
397 | - * @param $classSegment |
|
398 | - * @param $requestedAction |
|
399 | - * |
|
400 | - * @return array |
|
401 | - */ |
|
402 | - final protected function routePathSegments($classSegment, $requestedAction) |
|
403 | - { |
|
404 | - $routeMap = $this->getRouteMap(); |
|
405 | - if (array_key_exists($classSegment, $routeMap)) { |
|
406 | - // Route exists, but we don't have an action in path info, so default to main. |
|
407 | - |
|
408 | - if (isset($routeMap[$classSegment]['actions']) |
|
409 | - && array_search($requestedAction, $routeMap[$classSegment]['actions']) !== false |
|
410 | - ) { |
|
411 | - // Action exists in allowed action list. Allow both the page and the action |
|
412 | - $pageClass = $routeMap[$classSegment]['class']; |
|
413 | - $action = $requestedAction; |
|
414 | - |
|
415 | - return array($pageClass, $action); |
|
416 | - } |
|
417 | - else { |
|
418 | - // Valid page, invalid action. 404 our way out. |
|
419 | - $pageClass = Page404::class; |
|
420 | - $action = 'main'; |
|
421 | - |
|
422 | - return array($pageClass, $action); |
|
423 | - } |
|
424 | - } |
|
425 | - else { |
|
426 | - // Class doesn't exist in map. Fall back to 404 |
|
427 | - $pageClass = Page404::class; |
|
428 | - $action = 'main'; |
|
429 | - |
|
430 | - return array($pageClass, $action); |
|
431 | - } |
|
432 | - } |
|
433 | - |
|
434 | - /** |
|
435 | - * @return array |
|
436 | - */ |
|
437 | - protected function getRouteMap() |
|
438 | - { |
|
439 | - return $this->routeMap; |
|
440 | - } |
|
441 | - |
|
442 | - /** |
|
443 | - * @return callable |
|
444 | - */ |
|
445 | - protected function getDefaultRoute() |
|
446 | - { |
|
447 | - return array(PageMain::class, "main"); |
|
448 | - } |
|
58 | + /** |
|
59 | + * This is the core routing table for the application. The basic idea is: |
|
60 | + * |
|
61 | + * array( |
|
62 | + * "foo" => |
|
63 | + * array( |
|
64 | + * "class" => PageFoo::class, |
|
65 | + * "actions" => array("bar", "other") |
|
66 | + * ), |
|
67 | + * ); |
|
68 | + * |
|
69 | + * Things to note: |
|
70 | + * - If no page is requested, we go to PageMain. PageMain can't have actions defined. |
|
71 | + * |
|
72 | + * - If a page is defined and requested, but no action is requested, go to that page's main() method |
|
73 | + * - If a page is defined and requested, and an action is defined and requested, go to that action's method. |
|
74 | + * - If a page is defined and requested, and an action NOT defined and requested, go to Page404 and it's main() |
|
75 | + * method. |
|
76 | + * - If a page is NOT defined and requested, go to Page404 and it's main() method. |
|
77 | + * |
|
78 | + * - Query parameters are ignored. |
|
79 | + * |
|
80 | + * The key point here is request routing with validation that this is allowed, before we start hitting the |
|
81 | + * filesystem through the AutoLoader, and opening random files. Also, so that we validate the action requested |
|
82 | + * before we start calling random methods through the web UI. |
|
83 | + * |
|
84 | + * Examples: |
|
85 | + * /internal.php => returns instance of PageMain, routed to main() |
|
86 | + * /internal.php?query => returns instance of PageMain, routed to main() |
|
87 | + * /internal.php/foo => returns instance of PageFoo, routed to main() |
|
88 | + * /internal.php/foo?query => returns instance of PageFoo, routed to main() |
|
89 | + * /internal.php/foo/bar => returns instance of PageFoo, routed to bar() |
|
90 | + * /internal.php/foo/bar?query => returns instance of PageFoo, routed to bar() |
|
91 | + * /internal.php/foo/baz => returns instance of Page404, routed to main() |
|
92 | + * /internal.php/foo/baz?query => returns instance of Page404, routed to main() |
|
93 | + * /internal.php/bar => returns instance of Page404, routed to main() |
|
94 | + * /internal.php/bar?query => returns instance of Page404, routed to main() |
|
95 | + * /internal.php/bar/baz => returns instance of Page404, routed to main() |
|
96 | + * /internal.php/bar/baz?query => returns instance of Page404, routed to main() |
|
97 | + * |
|
98 | + * Take care when changing this - a lot of places rely on the array key for redirects and other links. If you need |
|
99 | + * to change the key, then you'll likely have to update a lot of files. |
|
100 | + * |
|
101 | + * @var array |
|
102 | + */ |
|
103 | + private $routeMap = array( |
|
104 | + |
|
105 | + ////////////////////////////////////////////////////////////////////////////////////////////////// |
|
106 | + // Login and registration |
|
107 | + 'logout' => |
|
108 | + array( |
|
109 | + 'class' => PageLogout::class, |
|
110 | + 'actions' => array(), |
|
111 | + ), |
|
112 | + 'login' => |
|
113 | + array( |
|
114 | + 'class' => PageLogin::class, |
|
115 | + 'actions' => array(), |
|
116 | + ), |
|
117 | + 'forgotPassword' => |
|
118 | + array( |
|
119 | + 'class' => PageForgotPassword::class, |
|
120 | + 'actions' => array('reset'), |
|
121 | + ), |
|
122 | + 'register' => |
|
123 | + array( |
|
124 | + 'class' => PageRegisterOption::class, |
|
125 | + 'actions' => array(), |
|
126 | + ), |
|
127 | + 'register/standard' => |
|
128 | + array( |
|
129 | + 'class' => PageRegisterStandard::class, |
|
130 | + 'actions' => array('done'), |
|
131 | + ), |
|
132 | + |
|
133 | + ////////////////////////////////////////////////////////////////////////////////////////////////// |
|
134 | + // Discovery |
|
135 | + 'search' => |
|
136 | + array( |
|
137 | + 'class' => PageSearch::class, |
|
138 | + 'actions' => array(), |
|
139 | + ), |
|
140 | + 'logs' => |
|
141 | + array( |
|
142 | + 'class' => PageLog::class, |
|
143 | + 'actions' => array(), |
|
144 | + ), |
|
145 | + |
|
146 | + ////////////////////////////////////////////////////////////////////////////////////////////////// |
|
147 | + // Administration |
|
148 | + 'bans' => |
|
149 | + array( |
|
150 | + 'class' => PageBan::class, |
|
151 | + 'actions' => array('set', 'remove'), |
|
152 | + ), |
|
153 | + 'userManagement' => |
|
154 | + array( |
|
155 | + 'class' => PageUserManagement::class, |
|
156 | + 'actions' => array( |
|
157 | + 'approve', |
|
158 | + 'decline', |
|
159 | + 'rename', |
|
160 | + 'editUser', |
|
161 | + 'suspend', |
|
162 | + 'editRoles', |
|
163 | + ), |
|
164 | + ), |
|
165 | + 'siteNotice' => |
|
166 | + array( |
|
167 | + 'class' => PageSiteNotice::class, |
|
168 | + 'actions' => array(), |
|
169 | + ), |
|
170 | + 'emailManagement' => |
|
171 | + array( |
|
172 | + 'class' => PageEmailManagement::class, |
|
173 | + 'actions' => array('create', 'edit', 'view'), |
|
174 | + ), |
|
175 | + |
|
176 | + ////////////////////////////////////////////////////////////////////////////////////////////////// |
|
177 | + // Personal preferences |
|
178 | + 'preferences' => |
|
179 | + array( |
|
180 | + 'class' => PagePreferences::class, |
|
181 | + 'actions' => array('changePassword'), |
|
182 | + ), |
|
183 | + 'oauth' => |
|
184 | + array( |
|
185 | + 'class' => PageOAuth::class, |
|
186 | + 'actions' => array('detach', 'attach'), |
|
187 | + ), |
|
188 | + |
|
189 | + ////////////////////////////////////////////////////////////////////////////////////////////////// |
|
190 | + // Welcomer configuration |
|
191 | + 'welcomeTemplates' => |
|
192 | + array( |
|
193 | + 'class' => PageWelcomeTemplateManagement::class, |
|
194 | + 'actions' => array('select', 'edit', 'delete', 'add', 'view'), |
|
195 | + ), |
|
196 | + |
|
197 | + ////////////////////////////////////////////////////////////////////////////////////////////////// |
|
198 | + // Statistics |
|
199 | + 'statistics' => |
|
200 | + array( |
|
201 | + 'class' => StatsMain::class, |
|
202 | + 'actions' => array(), |
|
203 | + ), |
|
204 | + 'statistics/fastCloses' => |
|
205 | + array( |
|
206 | + 'class' => StatsFastCloses::class, |
|
207 | + 'actions' => array(), |
|
208 | + ), |
|
209 | + 'statistics/inactiveUsers' => |
|
210 | + array( |
|
211 | + 'class' => StatsInactiveUsers::class, |
|
212 | + 'actions' => array(), |
|
213 | + ), |
|
214 | + 'statistics/monthlyStats' => |
|
215 | + array( |
|
216 | + 'class' => StatsMonthlyStats::class, |
|
217 | + 'actions' => array(), |
|
218 | + ), |
|
219 | + 'statistics/reservedRequests' => |
|
220 | + array( |
|
221 | + 'class' => StatsReservedRequests::class, |
|
222 | + 'actions' => array(), |
|
223 | + ), |
|
224 | + 'statistics/templateStats' => |
|
225 | + array( |
|
226 | + 'class' => StatsTemplateStats::class, |
|
227 | + 'actions' => array(), |
|
228 | + ), |
|
229 | + 'statistics/topCreators' => |
|
230 | + array( |
|
231 | + 'class' => StatsTopCreators::class, |
|
232 | + 'actions' => array(), |
|
233 | + ), |
|
234 | + 'statistics/users' => |
|
235 | + array( |
|
236 | + 'class' => StatsUsers::class, |
|
237 | + 'actions' => array('detail'), |
|
238 | + ), |
|
239 | + |
|
240 | + ////////////////////////////////////////////////////////////////////////////////////////////////// |
|
241 | + // Zoom page |
|
242 | + 'viewRequest' => |
|
243 | + array( |
|
244 | + 'class' => PageViewRequest::class, |
|
245 | + 'actions' => array(), |
|
246 | + ), |
|
247 | + 'viewRequest/reserve' => |
|
248 | + array( |
|
249 | + 'class' => PageReservation::class, |
|
250 | + 'actions' => array(), |
|
251 | + ), |
|
252 | + 'viewRequest/breakReserve' => |
|
253 | + array( |
|
254 | + 'class' => PageBreakReservation::class, |
|
255 | + 'actions' => array(), |
|
256 | + ), |
|
257 | + 'viewRequest/defer' => |
|
258 | + array( |
|
259 | + 'class' => PageDeferRequest::class, |
|
260 | + 'actions' => array(), |
|
261 | + ), |
|
262 | + 'viewRequest/comment' => |
|
263 | + array( |
|
264 | + 'class' => PageComment::class, |
|
265 | + 'actions' => array(), |
|
266 | + ), |
|
267 | + 'viewRequest/sendToUser' => |
|
268 | + array( |
|
269 | + 'class' => PageSendToUser::class, |
|
270 | + 'actions' => array(), |
|
271 | + ), |
|
272 | + 'viewRequest/close' => |
|
273 | + array( |
|
274 | + 'class' => PageCloseRequest::class, |
|
275 | + 'actions' => array(), |
|
276 | + ), |
|
277 | + 'viewRequest/drop' => |
|
278 | + array( |
|
279 | + 'class' => PageDropRequest::class, |
|
280 | + 'actions' => array(), |
|
281 | + ), |
|
282 | + 'viewRequest/custom' => |
|
283 | + array( |
|
284 | + 'class' => PageCustomClose::class, |
|
285 | + 'actions' => array(), |
|
286 | + ), |
|
287 | + 'editComment' => |
|
288 | + array( |
|
289 | + 'class' => PageEditComment::class, |
|
290 | + 'actions' => array(), |
|
291 | + ), |
|
292 | + |
|
293 | + ////////////////////////////////////////////////////////////////////////////////////////////////// |
|
294 | + // Misc stuff |
|
295 | + 'team' => |
|
296 | + array( |
|
297 | + 'class' => PageTeam::class, |
|
298 | + 'actions' => array(), |
|
299 | + ), |
|
300 | + 'requestList' => |
|
301 | + array( |
|
302 | + 'class' => PageExpandedRequestList::class, |
|
303 | + 'actions' => array(), |
|
304 | + ), |
|
305 | + ); |
|
306 | + |
|
307 | + /** |
|
308 | + * @return IRoutedTask |
|
309 | + * @throws Exception |
|
310 | + */ |
|
311 | + final public function route() |
|
312 | + { |
|
313 | + $pathInfo = WebRequest::pathInfo(); |
|
314 | + |
|
315 | + list($pageClass, $action) = $this->getRouteFromPath($pathInfo); |
|
316 | + |
|
317 | + /** @var IRoutedTask $page */ |
|
318 | + $page = new $pageClass(); |
|
319 | + |
|
320 | + // Dynamic creation, so we've got to be careful here. We can't use built-in language type protection, so |
|
321 | + // let's use our own. |
|
322 | + if (!($page instanceof IRoutedTask)) { |
|
323 | + throw new Exception('Expected a page, but this is not a page.'); |
|
324 | + } |
|
325 | + |
|
326 | + // OK, I'm happy at this point that we know we're running a page, and we know it's probably what we want if it |
|
327 | + // inherits PageBase and has been created from the routing map. |
|
328 | + $page->setRoute($action); |
|
329 | + |
|
330 | + return $page; |
|
331 | + } |
|
332 | + |
|
333 | + /** |
|
334 | + * @param $pathInfo |
|
335 | + * |
|
336 | + * @return array |
|
337 | + */ |
|
338 | + protected function getRouteFromPath($pathInfo) |
|
339 | + { |
|
340 | + if (count($pathInfo) === 0) { |
|
341 | + // No pathInfo, so no page to load. Load the main page. |
|
342 | + return $this->getDefaultRoute(); |
|
343 | + } |
|
344 | + elseif (count($pathInfo) === 1) { |
|
345 | + // Exactly one path info segment, it's got to be a page. |
|
346 | + $classSegment = $pathInfo[0]; |
|
347 | + |
|
348 | + return $this->routeSinglePathSegment($classSegment); |
|
349 | + } |
|
350 | + |
|
351 | + // OK, we have two or more segments now. |
|
352 | + if (count($pathInfo) > 2) { |
|
353 | + // Let's handle more than two, and collapse it down into two. |
|
354 | + $requestedAction = array_pop($pathInfo); |
|
355 | + $classSegment = implode('/', $pathInfo); |
|
356 | + } |
|
357 | + else { |
|
358 | + // Two path info segments. |
|
359 | + $classSegment = $pathInfo[0]; |
|
360 | + $requestedAction = $pathInfo[1]; |
|
361 | + } |
|
362 | + |
|
363 | + $routeMap = $this->routePathSegments($classSegment, $requestedAction); |
|
364 | + |
|
365 | + if ($routeMap[0] === Page404::class) { |
|
366 | + $routeMap = $this->routeSinglePathSegment($classSegment . '/' . $requestedAction); |
|
367 | + } |
|
368 | + |
|
369 | + return $routeMap; |
|
370 | + } |
|
371 | + |
|
372 | + /** |
|
373 | + * @param $classSegment |
|
374 | + * |
|
375 | + * @return array |
|
376 | + */ |
|
377 | + final protected function routeSinglePathSegment($classSegment) |
|
378 | + { |
|
379 | + $routeMap = $this->getRouteMap(); |
|
380 | + if (array_key_exists($classSegment, $routeMap)) { |
|
381 | + // Route exists, but we don't have an action in path info, so default to main. |
|
382 | + $pageClass = $routeMap[$classSegment]['class']; |
|
383 | + $action = 'main'; |
|
384 | + |
|
385 | + return array($pageClass, $action); |
|
386 | + } |
|
387 | + else { |
|
388 | + // Doesn't exist in map. Fall back to 404 |
|
389 | + $pageClass = Page404::class; |
|
390 | + $action = "main"; |
|
391 | + |
|
392 | + return array($pageClass, $action); |
|
393 | + } |
|
394 | + } |
|
395 | + |
|
396 | + /** |
|
397 | + * @param $classSegment |
|
398 | + * @param $requestedAction |
|
399 | + * |
|
400 | + * @return array |
|
401 | + */ |
|
402 | + final protected function routePathSegments($classSegment, $requestedAction) |
|
403 | + { |
|
404 | + $routeMap = $this->getRouteMap(); |
|
405 | + if (array_key_exists($classSegment, $routeMap)) { |
|
406 | + // Route exists, but we don't have an action in path info, so default to main. |
|
407 | + |
|
408 | + if (isset($routeMap[$classSegment]['actions']) |
|
409 | + && array_search($requestedAction, $routeMap[$classSegment]['actions']) !== false |
|
410 | + ) { |
|
411 | + // Action exists in allowed action list. Allow both the page and the action |
|
412 | + $pageClass = $routeMap[$classSegment]['class']; |
|
413 | + $action = $requestedAction; |
|
414 | + |
|
415 | + return array($pageClass, $action); |
|
416 | + } |
|
417 | + else { |
|
418 | + // Valid page, invalid action. 404 our way out. |
|
419 | + $pageClass = Page404::class; |
|
420 | + $action = 'main'; |
|
421 | + |
|
422 | + return array($pageClass, $action); |
|
423 | + } |
|
424 | + } |
|
425 | + else { |
|
426 | + // Class doesn't exist in map. Fall back to 404 |
|
427 | + $pageClass = Page404::class; |
|
428 | + $action = 'main'; |
|
429 | + |
|
430 | + return array($pageClass, $action); |
|
431 | + } |
|
432 | + } |
|
433 | + |
|
434 | + /** |
|
435 | + * @return array |
|
436 | + */ |
|
437 | + protected function getRouteMap() |
|
438 | + { |
|
439 | + return $this->routeMap; |
|
440 | + } |
|
441 | + |
|
442 | + /** |
|
443 | + * @return callable |
|
444 | + */ |
|
445 | + protected function getDefaultRoute() |
|
446 | + { |
|
447 | + return array(PageMain::class, "main"); |
|
448 | + } |
|
449 | 449 | } |
@@ -196,24 +196,24 @@ discard block |
||
196 | 196 | |
197 | 197 | // request states |
198 | 198 | $availableRequestStates = array( |
199 | - 'Open' => array( |
|
200 | - 'defertolog' => 'users', // don't change or you'll break old logs |
|
201 | - 'deferto' => 'users', |
|
202 | - 'header' => 'Open requests', |
|
203 | - 'api' => "open", |
|
204 | - ), |
|
205 | - 'Flagged users' => array( |
|
206 | - 'defertolog' => 'flagged users', // don't change or you'll break old logs |
|
207 | - 'deferto' => 'flagged users', |
|
208 | - 'header' => 'Flagged user needed', |
|
209 | - 'api' => "admin", |
|
210 | - ), |
|
211 | - 'Checkuser' => array( |
|
212 | - 'defertolog' => 'checkusers', // don't change or you'll break old logs |
|
213 | - 'deferto' => 'checkusers', |
|
214 | - 'header' => 'Checkuser needed', |
|
215 | - 'api' => "checkuser", |
|
216 | - ), |
|
199 | + 'Open' => array( |
|
200 | + 'defertolog' => 'users', // don't change or you'll break old logs |
|
201 | + 'deferto' => 'users', |
|
202 | + 'header' => 'Open requests', |
|
203 | + 'api' => "open", |
|
204 | + ), |
|
205 | + 'Flagged users' => array( |
|
206 | + 'defertolog' => 'flagged users', // don't change or you'll break old logs |
|
207 | + 'deferto' => 'flagged users', |
|
208 | + 'header' => 'Flagged user needed', |
|
209 | + 'api' => "admin", |
|
210 | + ), |
|
211 | + 'Checkuser' => array( |
|
212 | + 'defertolog' => 'checkusers', // don't change or you'll break old logs |
|
213 | + 'deferto' => 'checkusers', |
|
214 | + 'header' => 'Checkuser needed', |
|
215 | + 'api' => "checkuser", |
|
216 | + ), |
|
217 | 217 | ); |
218 | 218 | |
219 | 219 | $defaultRequestStateKey = 'Open'; |
@@ -252,21 +252,21 @@ discard block |
||
252 | 252 | require_once('config.local.inc.php'); |
253 | 253 | |
254 | 254 | $cDatabaseConfig = array( |
255 | - "acc" => array( |
|
256 | - "dsrcname" => "mysql:host=" . $toolserver_host . ";dbname=" . $toolserver_database, |
|
257 | - "username" => $toolserver_username, |
|
258 | - "password" => $toolserver_password, |
|
259 | - ), |
|
260 | - "wikipedia" => array( |
|
261 | - "dsrcname" => "mysql:host=" . $antispoof_host . ";dbname=" . $antispoof_db, |
|
262 | - "username" => $toolserver_username, |
|
263 | - "password" => $toolserver_password, |
|
264 | - ), |
|
265 | - "notifications" => array( |
|
266 | - "dsrcname" => "mysql:host=" . $toolserver_notification_dbhost . ";dbname=" . $toolserver_notification_database, |
|
267 | - "username" => $notifications_username, |
|
268 | - "password" => $notifications_password, |
|
269 | - ), |
|
255 | + "acc" => array( |
|
256 | + "dsrcname" => "mysql:host=" . $toolserver_host . ";dbname=" . $toolserver_database, |
|
257 | + "username" => $toolserver_username, |
|
258 | + "password" => $toolserver_password, |
|
259 | + ), |
|
260 | + "wikipedia" => array( |
|
261 | + "dsrcname" => "mysql:host=" . $antispoof_host . ";dbname=" . $antispoof_db, |
|
262 | + "username" => $toolserver_username, |
|
263 | + "password" => $toolserver_password, |
|
264 | + ), |
|
265 | + "notifications" => array( |
|
266 | + "dsrcname" => "mysql:host=" . $toolserver_notification_dbhost . ";dbname=" . $toolserver_notification_database, |
|
267 | + "username" => $notifications_username, |
|
268 | + "password" => $notifications_password, |
|
269 | + ), |
|
270 | 270 | ); |
271 | 271 | |
272 | 272 | // //Keep the included files from being executed. |
@@ -278,18 +278,18 @@ discard block |
||
278 | 278 | ini_set('user_agent', $toolUserAgent); |
279 | 279 | |
280 | 280 | foreach (array( |
281 | - "mbstring", // unicode and stuff |
|
282 | - "pdo", |
|
283 | - "pdo_mysql", // new database module |
|
284 | - "session", |
|
285 | - "date", |
|
286 | - "pcre", // core stuff |
|
287 | - "curl", // mediawiki api access etc |
|
288 | - "openssl", // token generation |
|
281 | + "mbstring", // unicode and stuff |
|
282 | + "pdo", |
|
283 | + "pdo_mysql", // new database module |
|
284 | + "session", |
|
285 | + "date", |
|
286 | + "pcre", // core stuff |
|
287 | + "curl", // mediawiki api access etc |
|
288 | + "openssl", // token generation |
|
289 | 289 | ) as $x) { |
290 | - if (!extension_loaded($x)) { |
|
291 | - die("extension $x is required."); |
|
292 | - } |
|
290 | + if (!extension_loaded($x)) { |
|
291 | + die("extension $x is required."); |
|
292 | + } |
|
293 | 293 | } |
294 | 294 | |
295 | 295 | // Set up the AutoLoader |
@@ -316,32 +316,32 @@ discard block |
||
316 | 316 | $siteConfiguration = new \Waca\SiteConfiguration(); |
317 | 317 | |
318 | 318 | $siteConfiguration->setBaseUrl($baseurl) |
319 | - ->setFilePath(__DIR__) |
|
320 | - ->setDebuggingTraceEnabled($enableErrorTrace) |
|
321 | - ->setForceIdentification($forceIdentification) |
|
322 | - ->setIdentificationCacheExpiry($identificationCacheExpiry) |
|
323 | - ->setMediawikiScriptPath($mediawikiScriptPath) |
|
324 | - ->setMediawikiWebServiceEndpoint($mediawikiWebServiceEndpoint) |
|
325 | - ->setMetaWikimediaWebServiceEndpoint($metaWikimediaWebServiceEndpoint) |
|
326 | - ->setEnforceOAuth($enforceOAuth) |
|
327 | - ->setEmailConfirmationEnabled($enableEmailConfirm == 1) |
|
328 | - ->setEmailConfirmationExpiryDays($emailConfirmationExpiryDays) |
|
329 | - ->setMiserModeLimit($requestLimitShowOnly) |
|
330 | - ->setRequestStates($availableRequestStates) |
|
331 | - ->setSquidList($squidIpList) |
|
332 | - ->setDefaultCreatedTemplateId($createdid) |
|
333 | - ->setDefaultRequestStateKey($defaultRequestStateKey) |
|
334 | - ->setUseStrictTransportSecurity($strictTransportSecurityExpiry) |
|
335 | - ->setUserAgent($toolUserAgent) |
|
336 | - ->setCurlDisableVerifyPeer($curlDisableSSLVerifyPeer) |
|
337 | - ->setUseOAuthSignup($useOauthSignup) |
|
338 | - ->setOAuthBaseUrl($oauthBaseUrl) |
|
339 | - ->setOAuthConsumerToken($oauthConsumerToken) |
|
340 | - ->setOAuthConsumerSecret($oauthSecretToken) |
|
341 | - ->setDataClearInterval($dataclear_interval) |
|
342 | - ->setXffTrustedHostsFile($xff_trusted_hosts_file) |
|
343 | - ->setIrcNotificationsEnabled($ircBotNotificationsEnabled == 1) |
|
344 | - ->setIrcNotificationType($ircBotNotificationType) |
|
345 | - ->setIrcNotificationsInstance($whichami) |
|
346 | - ->setTitleBlacklistEnabled($enableTitleblacklist == 1) |
|
347 | - ->setTorExitPaths(array_merge(gethostbynamel('en.wikipedia.org'), gethostbynamel('accounts.wmflabs.org'))); |
|
319 | + ->setFilePath(__DIR__) |
|
320 | + ->setDebuggingTraceEnabled($enableErrorTrace) |
|
321 | + ->setForceIdentification($forceIdentification) |
|
322 | + ->setIdentificationCacheExpiry($identificationCacheExpiry) |
|
323 | + ->setMediawikiScriptPath($mediawikiScriptPath) |
|
324 | + ->setMediawikiWebServiceEndpoint($mediawikiWebServiceEndpoint) |
|
325 | + ->setMetaWikimediaWebServiceEndpoint($metaWikimediaWebServiceEndpoint) |
|
326 | + ->setEnforceOAuth($enforceOAuth) |
|
327 | + ->setEmailConfirmationEnabled($enableEmailConfirm == 1) |
|
328 | + ->setEmailConfirmationExpiryDays($emailConfirmationExpiryDays) |
|
329 | + ->setMiserModeLimit($requestLimitShowOnly) |
|
330 | + ->setRequestStates($availableRequestStates) |
|
331 | + ->setSquidList($squidIpList) |
|
332 | + ->setDefaultCreatedTemplateId($createdid) |
|
333 | + ->setDefaultRequestStateKey($defaultRequestStateKey) |
|
334 | + ->setUseStrictTransportSecurity($strictTransportSecurityExpiry) |
|
335 | + ->setUserAgent($toolUserAgent) |
|
336 | + ->setCurlDisableVerifyPeer($curlDisableSSLVerifyPeer) |
|
337 | + ->setUseOAuthSignup($useOauthSignup) |
|
338 | + ->setOAuthBaseUrl($oauthBaseUrl) |
|
339 | + ->setOAuthConsumerToken($oauthConsumerToken) |
|
340 | + ->setOAuthConsumerSecret($oauthSecretToken) |
|
341 | + ->setDataClearInterval($dataclear_interval) |
|
342 | + ->setXffTrustedHostsFile($xff_trusted_hosts_file) |
|
343 | + ->setIrcNotificationsEnabled($ircBotNotificationsEnabled == 1) |
|
344 | + ->setIrcNotificationType($ircBotNotificationType) |
|
345 | + ->setIrcNotificationsInstance($whichami) |
|
346 | + ->setTitleBlacklistEnabled($enableTitleblacklist == 1) |
|
347 | + ->setTorExitPaths(array_merge(gethostbynamel('en.wikipedia.org'), gethostbynamel('accounts.wmflabs.org'))); |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | |
131 | 131 | $BUbasefile = "backup"; // The basefile's name. |
132 | 132 | $BUdir = "/home/project/a/c/c/acc/backups"; // The directory where backups should be stored. |
133 | -$BUmonthdir = $BUdir . "/monthly"; // The directory where monthly backups should be stored. |
|
133 | +$BUmonthdir = $BUdir."/monthly"; // The directory where monthly backups should be stored. |
|
134 | 134 | $BUdumper = "/opt/ts/mysql/5.1/bin/mysqldump --defaults-file=~/.my.cnf p_acc_live"; // Add parameters here if they are needed. |
135 | 135 | $BUgzip = "/usr/bin/gzip"; // Add the gzip parameters here if needed. |
136 | 136 | $BUtar = "/bin/tar -cvf"; // Add the tar parameters here if needed. |
@@ -253,17 +253,17 @@ discard block |
||
253 | 253 | |
254 | 254 | $cDatabaseConfig = array( |
255 | 255 | "acc" => array( |
256 | - "dsrcname" => "mysql:host=" . $toolserver_host . ";dbname=" . $toolserver_database, |
|
256 | + "dsrcname" => "mysql:host=".$toolserver_host.";dbname=".$toolserver_database, |
|
257 | 257 | "username" => $toolserver_username, |
258 | 258 | "password" => $toolserver_password, |
259 | 259 | ), |
260 | 260 | "wikipedia" => array( |
261 | - "dsrcname" => "mysql:host=" . $antispoof_host . ";dbname=" . $antispoof_db, |
|
261 | + "dsrcname" => "mysql:host=".$antispoof_host.";dbname=".$antispoof_db, |
|
262 | 262 | "username" => $toolserver_username, |
263 | 263 | "password" => $toolserver_password, |
264 | 264 | ), |
265 | 265 | "notifications" => array( |
266 | - "dsrcname" => "mysql:host=" . $toolserver_notification_dbhost . ";dbname=" . $toolserver_notification_database, |
|
266 | + "dsrcname" => "mysql:host=".$toolserver_notification_dbhost.";dbname=".$toolserver_notification_database, |
|
267 | 267 | "username" => $notifications_username, |
268 | 268 | "password" => $notifications_password, |
269 | 269 | ), |
@@ -293,13 +293,13 @@ discard block |
||
293 | 293 | } |
294 | 294 | |
295 | 295 | // Set up the AutoLoader |
296 | -require_once(__DIR__ . "/includes/AutoLoader.php"); |
|
296 | +require_once(__DIR__."/includes/AutoLoader.php"); |
|
297 | 297 | spl_autoload_register('Waca\\AutoLoader::load'); |
298 | -require_once(__DIR__ . '/vendor/autoload.php'); |
|
298 | +require_once(__DIR__.'/vendor/autoload.php'); |
|
299 | 299 | |
300 | 300 | // Extra includes which are just plain awkward wherever they are. |
301 | -require_once(__DIR__ . '/lib/mediawiki-extensions-OAuth/lib/OAuth.php'); |
|
302 | -require_once(__DIR__ . '/lib/mediawiki-extensions-OAuth/lib/JWT.php'); |
|
301 | +require_once(__DIR__.'/lib/mediawiki-extensions-OAuth/lib/OAuth.php'); |
|
302 | +require_once(__DIR__.'/lib/mediawiki-extensions-OAuth/lib/JWT.php'); |
|
303 | 303 | |
304 | 304 | // Crap that's needed for libraries. >:( |
305 | 305 | /** |
@@ -22,521 +22,521 @@ |
||
22 | 22 | */ |
23 | 23 | class WebRequest |
24 | 24 | { |
25 | - /** |
|
26 | - * @var \Waca\Providers\GlobalState\IGlobalStateProvider Provides access to the global state. |
|
27 | - */ |
|
28 | - private static $globalStateProvider; |
|
29 | - |
|
30 | - /** |
|
31 | - * Returns a boolean value if the request was submitted with the HTTP POST method. |
|
32 | - * @return bool |
|
33 | - */ |
|
34 | - public static function wasPosted() |
|
35 | - { |
|
36 | - return self::method() === 'POST'; |
|
37 | - } |
|
38 | - |
|
39 | - /** |
|
40 | - * Gets the HTTP Method used |
|
41 | - * @return string|null |
|
42 | - */ |
|
43 | - public static function method() |
|
44 | - { |
|
45 | - $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
46 | - |
|
47 | - if (isset($server['REQUEST_METHOD'])) { |
|
48 | - return $server['REQUEST_METHOD']; |
|
49 | - } |
|
50 | - |
|
51 | - return null; |
|
52 | - } |
|
53 | - |
|
54 | - /** |
|
55 | - * Gets a boolean value stating whether the request was served over HTTPS or not. |
|
56 | - * @return bool |
|
57 | - */ |
|
58 | - public static function isHttps() |
|
59 | - { |
|
60 | - $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
61 | - |
|
62 | - if (isset($server['HTTP_X_FORWARDED_PROTO'])) { |
|
63 | - if ($server['HTTP_X_FORWARDED_PROTO'] === 'https') { |
|
64 | - // Client <=> Proxy is encrypted |
|
65 | - return true; |
|
66 | - } |
|
67 | - else { |
|
68 | - // Proxy <=> Server link unknown, Client <=> Proxy is not encrypted. |
|
69 | - return false; |
|
70 | - } |
|
71 | - } |
|
72 | - |
|
73 | - if (isset($server['HTTPS'])) { |
|
74 | - if ($server['HTTPS'] === 'off') { |
|
75 | - // ISAPI on IIS breaks the spec. :( |
|
76 | - return false; |
|
77 | - } |
|
78 | - |
|
79 | - if ($server['HTTPS'] !== '') { |
|
80 | - // Set to a non-empty value |
|
81 | - return true; |
|
82 | - } |
|
83 | - } |
|
84 | - |
|
85 | - return false; |
|
86 | - } |
|
87 | - |
|
88 | - /** |
|
89 | - * Gets the path info |
|
90 | - * |
|
91 | - * @return array Array of path info segments |
|
92 | - */ |
|
93 | - public static function pathInfo() |
|
94 | - { |
|
95 | - $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
96 | - if (!isset($server['PATH_INFO'])) { |
|
97 | - return array(); |
|
98 | - } |
|
99 | - |
|
100 | - $exploded = explode('/', $server['PATH_INFO']); |
|
101 | - |
|
102 | - // filter out empty values, and reindex from zero. Notably, the first element is always zero, since it starts |
|
103 | - // with a / |
|
104 | - return array_values(array_filter($exploded)); |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * Gets the remote address of the web request |
|
109 | - * @return null|string |
|
110 | - */ |
|
111 | - public static function remoteAddress() |
|
112 | - { |
|
113 | - $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
114 | - |
|
115 | - if (isset($server['REMOTE_ADDR'])) { |
|
116 | - return $server['REMOTE_ADDR']; |
|
117 | - } |
|
118 | - |
|
119 | - return null; |
|
120 | - } |
|
121 | - |
|
122 | - /** |
|
123 | - * Gets the XFF header contents for the web request |
|
124 | - * @return null|string |
|
125 | - */ |
|
126 | - public static function forwardedAddress() |
|
127 | - { |
|
128 | - $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
129 | - |
|
130 | - if (isset($server['HTTP_X_FORWARDED_FOR'])) { |
|
131 | - return $server['HTTP_X_FORWARDED_FOR']; |
|
132 | - } |
|
133 | - |
|
134 | - return null; |
|
135 | - } |
|
136 | - |
|
137 | - /** |
|
138 | - * Sets the global state provider. |
|
139 | - * |
|
140 | - * Almost guaranteed this is not the method you want in production code. |
|
141 | - * |
|
142 | - * @param \Waca\Providers\GlobalState\IGlobalStateProvider $globalState |
|
143 | - */ |
|
144 | - public static function setGlobalStateProvider($globalState) |
|
145 | - { |
|
146 | - self::$globalStateProvider = $globalState; |
|
147 | - } |
|
148 | - |
|
149 | - #region POST variables |
|
150 | - |
|
151 | - /** |
|
152 | - * @param string $key |
|
153 | - * |
|
154 | - * @return null|string |
|
155 | - */ |
|
156 | - public static function postString($key) |
|
157 | - { |
|
158 | - $post = &self::$globalStateProvider->getPostSuperGlobal(); |
|
159 | - if (!array_key_exists($key, $post)) { |
|
160 | - return null; |
|
161 | - } |
|
162 | - |
|
163 | - if ($post[$key] === "") { |
|
164 | - return null; |
|
165 | - } |
|
166 | - |
|
167 | - return (string)$post[$key]; |
|
168 | - } |
|
169 | - |
|
170 | - /** |
|
171 | - * @param string $key |
|
172 | - * |
|
173 | - * @return null|string |
|
174 | - */ |
|
175 | - public static function postEmail($key) |
|
176 | - { |
|
177 | - $post = &self::$globalStateProvider->getPostSuperGlobal(); |
|
178 | - if (!array_key_exists($key, $post)) { |
|
179 | - return null; |
|
180 | - } |
|
181 | - |
|
182 | - $filteredValue = filter_var($post[$key], FILTER_SANITIZE_EMAIL); |
|
183 | - |
|
184 | - if ($filteredValue === false) { |
|
185 | - return null; |
|
186 | - } |
|
187 | - |
|
188 | - return (string)$filteredValue; |
|
189 | - } |
|
190 | - |
|
191 | - /** |
|
192 | - * @param string $key |
|
193 | - * |
|
194 | - * @return int|null |
|
195 | - */ |
|
196 | - public static function postInt($key) |
|
197 | - { |
|
198 | - $post = &self::$globalStateProvider->getPostSuperGlobal(); |
|
199 | - if (!array_key_exists($key, $post)) { |
|
200 | - return null; |
|
201 | - } |
|
202 | - |
|
203 | - $filteredValue = filter_var($post[$key], FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE); |
|
204 | - |
|
205 | - if ($filteredValue === null) { |
|
206 | - return null; |
|
207 | - } |
|
208 | - |
|
209 | - return (int)$filteredValue; |
|
210 | - } |
|
211 | - |
|
212 | - /** |
|
213 | - * @param string $key |
|
214 | - * |
|
215 | - * @return bool |
|
216 | - */ |
|
217 | - public static function postBoolean($key) |
|
218 | - { |
|
219 | - $get = &self::$globalStateProvider->getPostSuperGlobal(); |
|
220 | - if (!array_key_exists($key, $get)) { |
|
221 | - return false; |
|
222 | - } |
|
223 | - |
|
224 | - // presence of parameter only |
|
225 | - if ($get[$key] === "") { |
|
226 | - return true; |
|
227 | - } |
|
228 | - |
|
229 | - if (in_array($get[$key], array(false, 'no', 'off', 0, 'false'), true)) { |
|
230 | - return false; |
|
231 | - } |
|
232 | - |
|
233 | - return true; |
|
234 | - } |
|
235 | - |
|
236 | - #endregion |
|
237 | - |
|
238 | - #region GET variables |
|
239 | - |
|
240 | - /** |
|
241 | - * @param string $key |
|
242 | - * |
|
243 | - * @return bool |
|
244 | - */ |
|
245 | - public static function getBoolean($key) |
|
246 | - { |
|
247 | - $get = &self::$globalStateProvider->getGetSuperGlobal(); |
|
248 | - if (!array_key_exists($key, $get)) { |
|
249 | - return false; |
|
250 | - } |
|
251 | - |
|
252 | - // presence of parameter only |
|
253 | - if ($get[$key] === "") { |
|
254 | - return true; |
|
255 | - } |
|
256 | - |
|
257 | - if (in_array($get[$key], array(false, 'no', 'off', 0, 'false'), true)) { |
|
258 | - return false; |
|
259 | - } |
|
260 | - |
|
261 | - return true; |
|
262 | - } |
|
263 | - |
|
264 | - /** |
|
265 | - * @param string $key |
|
266 | - * |
|
267 | - * @return int|null |
|
268 | - */ |
|
269 | - public static function getInt($key) |
|
270 | - { |
|
271 | - $get = &self::$globalStateProvider->getGetSuperGlobal(); |
|
272 | - if (!array_key_exists($key, $get)) { |
|
273 | - return null; |
|
274 | - } |
|
275 | - |
|
276 | - $filteredValue = filter_var($get[$key], FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE); |
|
277 | - |
|
278 | - if ($filteredValue === null) { |
|
279 | - return null; |
|
280 | - } |
|
281 | - |
|
282 | - return (int)$filteredValue; |
|
283 | - } |
|
284 | - |
|
285 | - /** |
|
286 | - * @param string $key |
|
287 | - * |
|
288 | - * @return null|string |
|
289 | - */ |
|
290 | - public static function getString($key) |
|
291 | - { |
|
292 | - $get = &self::$globalStateProvider->getGetSuperGlobal(); |
|
293 | - if (!array_key_exists($key, $get)) { |
|
294 | - return null; |
|
295 | - } |
|
296 | - |
|
297 | - if ($get[$key] === "") { |
|
298 | - return null; |
|
299 | - } |
|
300 | - |
|
301 | - return (string)$get[$key]; |
|
302 | - } |
|
303 | - |
|
304 | - #endregion |
|
305 | - |
|
306 | - /** |
|
307 | - * Sets the logged-in user to the specified user. |
|
308 | - * |
|
309 | - * @param User $user |
|
310 | - */ |
|
311 | - public static function setLoggedInUser(User $user) |
|
312 | - { |
|
313 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
314 | - |
|
315 | - $session['userID'] = $user->getId(); |
|
316 | - unset($session['partialLogin']); |
|
317 | - } |
|
318 | - |
|
319 | - /** |
|
320 | - * Sets the post-login redirect |
|
321 | - */ |
|
322 | - public static function setPostLoginRedirect() |
|
323 | - { |
|
324 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
325 | - $session['returnTo'] = self::requestUri(); |
|
326 | - } |
|
327 | - |
|
328 | - /** |
|
329 | - * @return string|null |
|
330 | - */ |
|
331 | - public static function requestUri() |
|
332 | - { |
|
333 | - $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
334 | - |
|
335 | - if (isset($server['REQUEST_URI'])) { |
|
336 | - return $server['REQUEST_URI']; |
|
337 | - } |
|
338 | - |
|
339 | - return null; |
|
340 | - } |
|
341 | - |
|
342 | - /** |
|
343 | - * Clears the post-login redirect |
|
344 | - * @return string |
|
345 | - */ |
|
346 | - public static function clearPostLoginRedirect() |
|
347 | - { |
|
348 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
349 | - if (array_key_exists('returnTo', $session)) { |
|
350 | - $path = $session['returnTo']; |
|
351 | - unset($session['returnTo']); |
|
352 | - |
|
353 | - return $path; |
|
354 | - } |
|
355 | - |
|
356 | - return null; |
|
357 | - } |
|
358 | - |
|
359 | - /** |
|
360 | - * @return string|null |
|
361 | - */ |
|
362 | - public static function serverName() |
|
363 | - { |
|
364 | - $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
365 | - |
|
366 | - if (isset($server['SERVER_NAME'])) { |
|
367 | - return $server['SERVER_NAME']; |
|
368 | - } |
|
369 | - |
|
370 | - return null; |
|
371 | - } |
|
372 | - |
|
373 | - /** |
|
374 | - * You probably only want to deal with this through SessionAlert. |
|
375 | - * @return void |
|
376 | - */ |
|
377 | - public static function clearSessionAlertData() |
|
378 | - { |
|
379 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
380 | - if (array_key_exists('alerts', $session)) { |
|
381 | - unset($session['alerts']); |
|
382 | - } |
|
383 | - } |
|
384 | - |
|
385 | - /** |
|
386 | - * You probably only want to deal with this through SessionAlert. |
|
387 | - * |
|
388 | - * @return string[] |
|
389 | - */ |
|
390 | - public static function getSessionAlertData() |
|
391 | - { |
|
392 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
393 | - if (array_key_exists('alerts', $session)) { |
|
394 | - return $session['alerts']; |
|
395 | - } |
|
396 | - |
|
397 | - return array(); |
|
398 | - } |
|
399 | - |
|
400 | - /** |
|
401 | - * You probably only want to deal with this through SessionAlert. |
|
402 | - * |
|
403 | - * @param string[] $data |
|
404 | - */ |
|
405 | - public static function setSessionAlertData($data) |
|
406 | - { |
|
407 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
408 | - $session['alerts'] = $data; |
|
409 | - } |
|
410 | - |
|
411 | - /** |
|
412 | - * You probably only want to deal with this through TokenManager. |
|
413 | - * |
|
414 | - * @return string[] |
|
415 | - */ |
|
416 | - public static function getSessionTokenData() |
|
417 | - { |
|
418 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
419 | - if (array_key_exists('tokens', $session)) { |
|
420 | - return $session['tokens']; |
|
421 | - } |
|
422 | - |
|
423 | - return array(); |
|
424 | - } |
|
425 | - |
|
426 | - /** |
|
427 | - * You probably only want to deal with this through TokenManager. |
|
428 | - * |
|
429 | - * @param string[] $data |
|
430 | - */ |
|
431 | - public static function setSessionTokenData($data) |
|
432 | - { |
|
433 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
434 | - $session['tokens'] = $data; |
|
435 | - } |
|
436 | - |
|
437 | - /** |
|
438 | - * @param string $key |
|
439 | - * |
|
440 | - * @return mixed |
|
441 | - */ |
|
442 | - public static function getSessionContext($key) |
|
443 | - { |
|
444 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
445 | - |
|
446 | - if (!isset($session['context'])) { |
|
447 | - $session['context'] = array(); |
|
448 | - } |
|
449 | - |
|
450 | - if (!isset($session['context'][$key])) { |
|
451 | - return null; |
|
452 | - } |
|
453 | - |
|
454 | - return $session['context'][$key]; |
|
455 | - } |
|
456 | - |
|
457 | - /** |
|
458 | - * @param string $key |
|
459 | - * @param mixed $data |
|
460 | - */ |
|
461 | - public static function setSessionContext($key, $data) |
|
462 | - { |
|
463 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
464 | - |
|
465 | - if (!isset($session['context'])) { |
|
466 | - $session['context'] = array(); |
|
467 | - } |
|
468 | - |
|
469 | - $session['context'][$key] = $data; |
|
470 | - } |
|
471 | - |
|
472 | - /** |
|
473 | - * @return int|null |
|
474 | - */ |
|
475 | - public static function getSessionUserId() |
|
476 | - { |
|
477 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
478 | - |
|
479 | - return isset($session['userID']) ? (int)$session['userID'] : null; |
|
480 | - } |
|
481 | - |
|
482 | - /** |
|
483 | - * @param User $user |
|
484 | - */ |
|
485 | - public static function setPartialLogin(User $user) |
|
486 | - { |
|
487 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
488 | - $session['partialLogin'] = $user->getId(); |
|
489 | - } |
|
490 | - |
|
491 | - /** |
|
492 | - * @return int|null |
|
493 | - */ |
|
494 | - public static function getPartialLogin() |
|
495 | - { |
|
496 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
497 | - |
|
498 | - return isset($session['partialLogin']) ? (int)$session['partialLogin'] : null; |
|
499 | - } |
|
500 | - |
|
501 | - /** |
|
502 | - * @return null|string |
|
503 | - */ |
|
504 | - public static function userAgent() |
|
505 | - { |
|
506 | - $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
507 | - |
|
508 | - if (isset($server['HTTP_USER_AGENT'])) { |
|
509 | - return $server['HTTP_USER_AGENT']; |
|
510 | - } |
|
511 | - |
|
512 | - return null; |
|
513 | - } |
|
514 | - |
|
515 | - /** |
|
516 | - * @return null|string |
|
517 | - */ |
|
518 | - public static function scriptName() |
|
519 | - { |
|
520 | - $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
521 | - |
|
522 | - if (isset($server['SCRIPT_NAME'])) { |
|
523 | - return $server['SCRIPT_NAME']; |
|
524 | - } |
|
525 | - |
|
526 | - return null; |
|
527 | - } |
|
528 | - |
|
529 | - /** |
|
530 | - * @return null|string |
|
531 | - */ |
|
532 | - public static function origin() |
|
533 | - { |
|
534 | - $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
535 | - |
|
536 | - if (isset($server['HTTP_ORIGIN'])) { |
|
537 | - return $server['HTTP_ORIGIN']; |
|
538 | - } |
|
539 | - |
|
540 | - return null; |
|
541 | - } |
|
25 | + /** |
|
26 | + * @var \Waca\Providers\GlobalState\IGlobalStateProvider Provides access to the global state. |
|
27 | + */ |
|
28 | + private static $globalStateProvider; |
|
29 | + |
|
30 | + /** |
|
31 | + * Returns a boolean value if the request was submitted with the HTTP POST method. |
|
32 | + * @return bool |
|
33 | + */ |
|
34 | + public static function wasPosted() |
|
35 | + { |
|
36 | + return self::method() === 'POST'; |
|
37 | + } |
|
38 | + |
|
39 | + /** |
|
40 | + * Gets the HTTP Method used |
|
41 | + * @return string|null |
|
42 | + */ |
|
43 | + public static function method() |
|
44 | + { |
|
45 | + $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
46 | + |
|
47 | + if (isset($server['REQUEST_METHOD'])) { |
|
48 | + return $server['REQUEST_METHOD']; |
|
49 | + } |
|
50 | + |
|
51 | + return null; |
|
52 | + } |
|
53 | + |
|
54 | + /** |
|
55 | + * Gets a boolean value stating whether the request was served over HTTPS or not. |
|
56 | + * @return bool |
|
57 | + */ |
|
58 | + public static function isHttps() |
|
59 | + { |
|
60 | + $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
61 | + |
|
62 | + if (isset($server['HTTP_X_FORWARDED_PROTO'])) { |
|
63 | + if ($server['HTTP_X_FORWARDED_PROTO'] === 'https') { |
|
64 | + // Client <=> Proxy is encrypted |
|
65 | + return true; |
|
66 | + } |
|
67 | + else { |
|
68 | + // Proxy <=> Server link unknown, Client <=> Proxy is not encrypted. |
|
69 | + return false; |
|
70 | + } |
|
71 | + } |
|
72 | + |
|
73 | + if (isset($server['HTTPS'])) { |
|
74 | + if ($server['HTTPS'] === 'off') { |
|
75 | + // ISAPI on IIS breaks the spec. :( |
|
76 | + return false; |
|
77 | + } |
|
78 | + |
|
79 | + if ($server['HTTPS'] !== '') { |
|
80 | + // Set to a non-empty value |
|
81 | + return true; |
|
82 | + } |
|
83 | + } |
|
84 | + |
|
85 | + return false; |
|
86 | + } |
|
87 | + |
|
88 | + /** |
|
89 | + * Gets the path info |
|
90 | + * |
|
91 | + * @return array Array of path info segments |
|
92 | + */ |
|
93 | + public static function pathInfo() |
|
94 | + { |
|
95 | + $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
96 | + if (!isset($server['PATH_INFO'])) { |
|
97 | + return array(); |
|
98 | + } |
|
99 | + |
|
100 | + $exploded = explode('/', $server['PATH_INFO']); |
|
101 | + |
|
102 | + // filter out empty values, and reindex from zero. Notably, the first element is always zero, since it starts |
|
103 | + // with a / |
|
104 | + return array_values(array_filter($exploded)); |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * Gets the remote address of the web request |
|
109 | + * @return null|string |
|
110 | + */ |
|
111 | + public static function remoteAddress() |
|
112 | + { |
|
113 | + $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
114 | + |
|
115 | + if (isset($server['REMOTE_ADDR'])) { |
|
116 | + return $server['REMOTE_ADDR']; |
|
117 | + } |
|
118 | + |
|
119 | + return null; |
|
120 | + } |
|
121 | + |
|
122 | + /** |
|
123 | + * Gets the XFF header contents for the web request |
|
124 | + * @return null|string |
|
125 | + */ |
|
126 | + public static function forwardedAddress() |
|
127 | + { |
|
128 | + $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
129 | + |
|
130 | + if (isset($server['HTTP_X_FORWARDED_FOR'])) { |
|
131 | + return $server['HTTP_X_FORWARDED_FOR']; |
|
132 | + } |
|
133 | + |
|
134 | + return null; |
|
135 | + } |
|
136 | + |
|
137 | + /** |
|
138 | + * Sets the global state provider. |
|
139 | + * |
|
140 | + * Almost guaranteed this is not the method you want in production code. |
|
141 | + * |
|
142 | + * @param \Waca\Providers\GlobalState\IGlobalStateProvider $globalState |
|
143 | + */ |
|
144 | + public static function setGlobalStateProvider($globalState) |
|
145 | + { |
|
146 | + self::$globalStateProvider = $globalState; |
|
147 | + } |
|
148 | + |
|
149 | + #region POST variables |
|
150 | + |
|
151 | + /** |
|
152 | + * @param string $key |
|
153 | + * |
|
154 | + * @return null|string |
|
155 | + */ |
|
156 | + public static function postString($key) |
|
157 | + { |
|
158 | + $post = &self::$globalStateProvider->getPostSuperGlobal(); |
|
159 | + if (!array_key_exists($key, $post)) { |
|
160 | + return null; |
|
161 | + } |
|
162 | + |
|
163 | + if ($post[$key] === "") { |
|
164 | + return null; |
|
165 | + } |
|
166 | + |
|
167 | + return (string)$post[$key]; |
|
168 | + } |
|
169 | + |
|
170 | + /** |
|
171 | + * @param string $key |
|
172 | + * |
|
173 | + * @return null|string |
|
174 | + */ |
|
175 | + public static function postEmail($key) |
|
176 | + { |
|
177 | + $post = &self::$globalStateProvider->getPostSuperGlobal(); |
|
178 | + if (!array_key_exists($key, $post)) { |
|
179 | + return null; |
|
180 | + } |
|
181 | + |
|
182 | + $filteredValue = filter_var($post[$key], FILTER_SANITIZE_EMAIL); |
|
183 | + |
|
184 | + if ($filteredValue === false) { |
|
185 | + return null; |
|
186 | + } |
|
187 | + |
|
188 | + return (string)$filteredValue; |
|
189 | + } |
|
190 | + |
|
191 | + /** |
|
192 | + * @param string $key |
|
193 | + * |
|
194 | + * @return int|null |
|
195 | + */ |
|
196 | + public static function postInt($key) |
|
197 | + { |
|
198 | + $post = &self::$globalStateProvider->getPostSuperGlobal(); |
|
199 | + if (!array_key_exists($key, $post)) { |
|
200 | + return null; |
|
201 | + } |
|
202 | + |
|
203 | + $filteredValue = filter_var($post[$key], FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE); |
|
204 | + |
|
205 | + if ($filteredValue === null) { |
|
206 | + return null; |
|
207 | + } |
|
208 | + |
|
209 | + return (int)$filteredValue; |
|
210 | + } |
|
211 | + |
|
212 | + /** |
|
213 | + * @param string $key |
|
214 | + * |
|
215 | + * @return bool |
|
216 | + */ |
|
217 | + public static function postBoolean($key) |
|
218 | + { |
|
219 | + $get = &self::$globalStateProvider->getPostSuperGlobal(); |
|
220 | + if (!array_key_exists($key, $get)) { |
|
221 | + return false; |
|
222 | + } |
|
223 | + |
|
224 | + // presence of parameter only |
|
225 | + if ($get[$key] === "") { |
|
226 | + return true; |
|
227 | + } |
|
228 | + |
|
229 | + if (in_array($get[$key], array(false, 'no', 'off', 0, 'false'), true)) { |
|
230 | + return false; |
|
231 | + } |
|
232 | + |
|
233 | + return true; |
|
234 | + } |
|
235 | + |
|
236 | + #endregion |
|
237 | + |
|
238 | + #region GET variables |
|
239 | + |
|
240 | + /** |
|
241 | + * @param string $key |
|
242 | + * |
|
243 | + * @return bool |
|
244 | + */ |
|
245 | + public static function getBoolean($key) |
|
246 | + { |
|
247 | + $get = &self::$globalStateProvider->getGetSuperGlobal(); |
|
248 | + if (!array_key_exists($key, $get)) { |
|
249 | + return false; |
|
250 | + } |
|
251 | + |
|
252 | + // presence of parameter only |
|
253 | + if ($get[$key] === "") { |
|
254 | + return true; |
|
255 | + } |
|
256 | + |
|
257 | + if (in_array($get[$key], array(false, 'no', 'off', 0, 'false'), true)) { |
|
258 | + return false; |
|
259 | + } |
|
260 | + |
|
261 | + return true; |
|
262 | + } |
|
263 | + |
|
264 | + /** |
|
265 | + * @param string $key |
|
266 | + * |
|
267 | + * @return int|null |
|
268 | + */ |
|
269 | + public static function getInt($key) |
|
270 | + { |
|
271 | + $get = &self::$globalStateProvider->getGetSuperGlobal(); |
|
272 | + if (!array_key_exists($key, $get)) { |
|
273 | + return null; |
|
274 | + } |
|
275 | + |
|
276 | + $filteredValue = filter_var($get[$key], FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE); |
|
277 | + |
|
278 | + if ($filteredValue === null) { |
|
279 | + return null; |
|
280 | + } |
|
281 | + |
|
282 | + return (int)$filteredValue; |
|
283 | + } |
|
284 | + |
|
285 | + /** |
|
286 | + * @param string $key |
|
287 | + * |
|
288 | + * @return null|string |
|
289 | + */ |
|
290 | + public static function getString($key) |
|
291 | + { |
|
292 | + $get = &self::$globalStateProvider->getGetSuperGlobal(); |
|
293 | + if (!array_key_exists($key, $get)) { |
|
294 | + return null; |
|
295 | + } |
|
296 | + |
|
297 | + if ($get[$key] === "") { |
|
298 | + return null; |
|
299 | + } |
|
300 | + |
|
301 | + return (string)$get[$key]; |
|
302 | + } |
|
303 | + |
|
304 | + #endregion |
|
305 | + |
|
306 | + /** |
|
307 | + * Sets the logged-in user to the specified user. |
|
308 | + * |
|
309 | + * @param User $user |
|
310 | + */ |
|
311 | + public static function setLoggedInUser(User $user) |
|
312 | + { |
|
313 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
314 | + |
|
315 | + $session['userID'] = $user->getId(); |
|
316 | + unset($session['partialLogin']); |
|
317 | + } |
|
318 | + |
|
319 | + /** |
|
320 | + * Sets the post-login redirect |
|
321 | + */ |
|
322 | + public static function setPostLoginRedirect() |
|
323 | + { |
|
324 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
325 | + $session['returnTo'] = self::requestUri(); |
|
326 | + } |
|
327 | + |
|
328 | + /** |
|
329 | + * @return string|null |
|
330 | + */ |
|
331 | + public static function requestUri() |
|
332 | + { |
|
333 | + $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
334 | + |
|
335 | + if (isset($server['REQUEST_URI'])) { |
|
336 | + return $server['REQUEST_URI']; |
|
337 | + } |
|
338 | + |
|
339 | + return null; |
|
340 | + } |
|
341 | + |
|
342 | + /** |
|
343 | + * Clears the post-login redirect |
|
344 | + * @return string |
|
345 | + */ |
|
346 | + public static function clearPostLoginRedirect() |
|
347 | + { |
|
348 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
349 | + if (array_key_exists('returnTo', $session)) { |
|
350 | + $path = $session['returnTo']; |
|
351 | + unset($session['returnTo']); |
|
352 | + |
|
353 | + return $path; |
|
354 | + } |
|
355 | + |
|
356 | + return null; |
|
357 | + } |
|
358 | + |
|
359 | + /** |
|
360 | + * @return string|null |
|
361 | + */ |
|
362 | + public static function serverName() |
|
363 | + { |
|
364 | + $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
365 | + |
|
366 | + if (isset($server['SERVER_NAME'])) { |
|
367 | + return $server['SERVER_NAME']; |
|
368 | + } |
|
369 | + |
|
370 | + return null; |
|
371 | + } |
|
372 | + |
|
373 | + /** |
|
374 | + * You probably only want to deal with this through SessionAlert. |
|
375 | + * @return void |
|
376 | + */ |
|
377 | + public static function clearSessionAlertData() |
|
378 | + { |
|
379 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
380 | + if (array_key_exists('alerts', $session)) { |
|
381 | + unset($session['alerts']); |
|
382 | + } |
|
383 | + } |
|
384 | + |
|
385 | + /** |
|
386 | + * You probably only want to deal with this through SessionAlert. |
|
387 | + * |
|
388 | + * @return string[] |
|
389 | + */ |
|
390 | + public static function getSessionAlertData() |
|
391 | + { |
|
392 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
393 | + if (array_key_exists('alerts', $session)) { |
|
394 | + return $session['alerts']; |
|
395 | + } |
|
396 | + |
|
397 | + return array(); |
|
398 | + } |
|
399 | + |
|
400 | + /** |
|
401 | + * You probably only want to deal with this through SessionAlert. |
|
402 | + * |
|
403 | + * @param string[] $data |
|
404 | + */ |
|
405 | + public static function setSessionAlertData($data) |
|
406 | + { |
|
407 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
408 | + $session['alerts'] = $data; |
|
409 | + } |
|
410 | + |
|
411 | + /** |
|
412 | + * You probably only want to deal with this through TokenManager. |
|
413 | + * |
|
414 | + * @return string[] |
|
415 | + */ |
|
416 | + public static function getSessionTokenData() |
|
417 | + { |
|
418 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
419 | + if (array_key_exists('tokens', $session)) { |
|
420 | + return $session['tokens']; |
|
421 | + } |
|
422 | + |
|
423 | + return array(); |
|
424 | + } |
|
425 | + |
|
426 | + /** |
|
427 | + * You probably only want to deal with this through TokenManager. |
|
428 | + * |
|
429 | + * @param string[] $data |
|
430 | + */ |
|
431 | + public static function setSessionTokenData($data) |
|
432 | + { |
|
433 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
434 | + $session['tokens'] = $data; |
|
435 | + } |
|
436 | + |
|
437 | + /** |
|
438 | + * @param string $key |
|
439 | + * |
|
440 | + * @return mixed |
|
441 | + */ |
|
442 | + public static function getSessionContext($key) |
|
443 | + { |
|
444 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
445 | + |
|
446 | + if (!isset($session['context'])) { |
|
447 | + $session['context'] = array(); |
|
448 | + } |
|
449 | + |
|
450 | + if (!isset($session['context'][$key])) { |
|
451 | + return null; |
|
452 | + } |
|
453 | + |
|
454 | + return $session['context'][$key]; |
|
455 | + } |
|
456 | + |
|
457 | + /** |
|
458 | + * @param string $key |
|
459 | + * @param mixed $data |
|
460 | + */ |
|
461 | + public static function setSessionContext($key, $data) |
|
462 | + { |
|
463 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
464 | + |
|
465 | + if (!isset($session['context'])) { |
|
466 | + $session['context'] = array(); |
|
467 | + } |
|
468 | + |
|
469 | + $session['context'][$key] = $data; |
|
470 | + } |
|
471 | + |
|
472 | + /** |
|
473 | + * @return int|null |
|
474 | + */ |
|
475 | + public static function getSessionUserId() |
|
476 | + { |
|
477 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
478 | + |
|
479 | + return isset($session['userID']) ? (int)$session['userID'] : null; |
|
480 | + } |
|
481 | + |
|
482 | + /** |
|
483 | + * @param User $user |
|
484 | + */ |
|
485 | + public static function setPartialLogin(User $user) |
|
486 | + { |
|
487 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
488 | + $session['partialLogin'] = $user->getId(); |
|
489 | + } |
|
490 | + |
|
491 | + /** |
|
492 | + * @return int|null |
|
493 | + */ |
|
494 | + public static function getPartialLogin() |
|
495 | + { |
|
496 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
497 | + |
|
498 | + return isset($session['partialLogin']) ? (int)$session['partialLogin'] : null; |
|
499 | + } |
|
500 | + |
|
501 | + /** |
|
502 | + * @return null|string |
|
503 | + */ |
|
504 | + public static function userAgent() |
|
505 | + { |
|
506 | + $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
507 | + |
|
508 | + if (isset($server['HTTP_USER_AGENT'])) { |
|
509 | + return $server['HTTP_USER_AGENT']; |
|
510 | + } |
|
511 | + |
|
512 | + return null; |
|
513 | + } |
|
514 | + |
|
515 | + /** |
|
516 | + * @return null|string |
|
517 | + */ |
|
518 | + public static function scriptName() |
|
519 | + { |
|
520 | + $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
521 | + |
|
522 | + if (isset($server['SCRIPT_NAME'])) { |
|
523 | + return $server['SCRIPT_NAME']; |
|
524 | + } |
|
525 | + |
|
526 | + return null; |
|
527 | + } |
|
528 | + |
|
529 | + /** |
|
530 | + * @return null|string |
|
531 | + */ |
|
532 | + public static function origin() |
|
533 | + { |
|
534 | + $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
535 | + |
|
536 | + if (isset($server['HTTP_ORIGIN'])) { |
|
537 | + return $server['HTTP_ORIGIN']; |
|
538 | + } |
|
539 | + |
|
540 | + return null; |
|
541 | + } |
|
542 | 542 | } |
543 | 543 | \ No newline at end of file |
@@ -12,21 +12,21 @@ |
||
12 | 12 | |
13 | 13 | interface IRoutedTask extends ITask |
14 | 14 | { |
15 | - /** |
|
16 | - * Sets the route the request will take. Only should be called from the request router. |
|
17 | - * |
|
18 | - * @param $routeName string |
|
19 | - * |
|
20 | - * @return void |
|
21 | - * |
|
22 | - * @throws Exception |
|
23 | - * @category Security-Critical |
|
24 | - */ |
|
25 | - public function setRoute($routeName); |
|
15 | + /** |
|
16 | + * Sets the route the request will take. Only should be called from the request router. |
|
17 | + * |
|
18 | + * @param $routeName string |
|
19 | + * |
|
20 | + * @return void |
|
21 | + * |
|
22 | + * @throws Exception |
|
23 | + * @category Security-Critical |
|
24 | + */ |
|
25 | + public function setRoute($routeName); |
|
26 | 26 | |
27 | - /** |
|
28 | - * Gets the name of the route that has been passed from the request router. |
|
29 | - * @return string |
|
30 | - */ |
|
31 | - public function getRouteName(); |
|
27 | + /** |
|
28 | + * Gets the name of the route that has been passed from the request router. |
|
29 | + * @return string |
|
30 | + */ |
|
31 | + public function getRouteName(); |
|
32 | 32 | } |
33 | 33 | \ No newline at end of file |
@@ -23,149 +23,149 @@ |
||
23 | 23 | |
24 | 24 | interface ITask |
25 | 25 | { |
26 | - /** |
|
27 | - * @return IEmailHelper |
|
28 | - */ |
|
29 | - public function getEmailHelper(); |
|
30 | - |
|
31 | - /** |
|
32 | - * @param IEmailHelper $emailHelper |
|
33 | - * |
|
34 | - * @return void |
|
35 | - */ |
|
36 | - public function setEmailHelper($emailHelper); |
|
37 | - |
|
38 | - /** |
|
39 | - * @return HttpHelper |
|
40 | - */ |
|
41 | - public function getHttpHelper(); |
|
42 | - |
|
43 | - /** |
|
44 | - * @param HttpHelper $httpHelper |
|
45 | - * |
|
46 | - * @return void |
|
47 | - */ |
|
48 | - public function setHttpHelper($httpHelper); |
|
49 | - |
|
50 | - /** |
|
51 | - * @return WikiTextHelper |
|
52 | - */ |
|
53 | - public function getWikiTextHelper(); |
|
54 | - |
|
55 | - /** |
|
56 | - * @param WikiTextHelper $wikiTextHelper |
|
57 | - * |
|
58 | - * @return void |
|
59 | - */ |
|
60 | - public function setWikiTextHelper($wikiTextHelper); |
|
61 | - |
|
62 | - /** |
|
63 | - * @return ILocationProvider |
|
64 | - */ |
|
65 | - public function getLocationProvider(); |
|
66 | - |
|
67 | - /** |
|
68 | - * @param ILocationProvider $locationProvider |
|
69 | - * |
|
70 | - * @return void |
|
71 | - */ |
|
72 | - public function setLocationProvider(ILocationProvider $locationProvider); |
|
73 | - |
|
74 | - /** |
|
75 | - * @return IXffTrustProvider |
|
76 | - */ |
|
77 | - public function getXffTrustProvider(); |
|
78 | - |
|
79 | - /** |
|
80 | - * @param IXffTrustProvider $xffTrustProvider |
|
81 | - * |
|
82 | - * @return void |
|
83 | - */ |
|
84 | - public function setXffTrustProvider(IXffTrustProvider $xffTrustProvider); |
|
85 | - |
|
86 | - /** |
|
87 | - * @return IRDnsProvider |
|
88 | - */ |
|
89 | - public function getRdnsProvider(); |
|
90 | - |
|
91 | - /** |
|
92 | - * @param IRDnsProvider $rdnsProvider |
|
93 | - * |
|
94 | - * @return void |
|
95 | - */ |
|
96 | - public function setRdnsProvider($rdnsProvider); |
|
97 | - |
|
98 | - /** |
|
99 | - * @return IAntiSpoofProvider |
|
100 | - */ |
|
101 | - public function getAntiSpoofProvider(); |
|
102 | - |
|
103 | - /** |
|
104 | - * @param IAntiSpoofProvider $antiSpoofProvider |
|
105 | - * |
|
106 | - * @return void |
|
107 | - */ |
|
108 | - public function setAntiSpoofProvider($antiSpoofProvider); |
|
109 | - |
|
110 | - /** |
|
111 | - * @return PdoDatabase |
|
112 | - */ |
|
113 | - public function getDatabase(); |
|
114 | - |
|
115 | - /** |
|
116 | - * @param PdoDatabase $database |
|
117 | - * |
|
118 | - * @return void |
|
119 | - */ |
|
120 | - public function setDatabase($database); |
|
121 | - |
|
122 | - /** |
|
123 | - * @return IOAuthHelper |
|
124 | - */ |
|
125 | - public function getOAuthHelper(); |
|
126 | - |
|
127 | - /** |
|
128 | - * @param IOAuthHelper $oauthHelper |
|
129 | - * |
|
130 | - * @return void |
|
131 | - */ |
|
132 | - public function setOAuthHelper($oauthHelper); |
|
133 | - |
|
134 | - /** |
|
135 | - * @return void |
|
136 | - */ |
|
137 | - public function execute(); |
|
138 | - |
|
139 | - /** |
|
140 | - * Sets the site configuration object for this page |
|
141 | - * |
|
142 | - * @param SiteConfiguration $configuration |
|
143 | - * |
|
144 | - * @return void |
|
145 | - */ |
|
146 | - public function setSiteConfiguration($configuration); |
|
147 | - |
|
148 | - /** |
|
149 | - * @return IrcNotificationHelper |
|
150 | - */ |
|
151 | - public function getNotificationHelper(); |
|
152 | - |
|
153 | - /** |
|
154 | - * @param IrcNotificationHelper $notificationHelper |
|
155 | - * |
|
156 | - * @return void |
|
157 | - */ |
|
158 | - public function setNotificationHelper($notificationHelper); |
|
159 | - |
|
160 | - /** |
|
161 | - * @return TorExitProvider |
|
162 | - */ |
|
163 | - public function getTorExitProvider(); |
|
164 | - |
|
165 | - /** |
|
166 | - * @param TorExitProvider $torExitProvider |
|
167 | - * |
|
168 | - * @return void |
|
169 | - */ |
|
170 | - public function setTorExitProvider($torExitProvider); |
|
26 | + /** |
|
27 | + * @return IEmailHelper |
|
28 | + */ |
|
29 | + public function getEmailHelper(); |
|
30 | + |
|
31 | + /** |
|
32 | + * @param IEmailHelper $emailHelper |
|
33 | + * |
|
34 | + * @return void |
|
35 | + */ |
|
36 | + public function setEmailHelper($emailHelper); |
|
37 | + |
|
38 | + /** |
|
39 | + * @return HttpHelper |
|
40 | + */ |
|
41 | + public function getHttpHelper(); |
|
42 | + |
|
43 | + /** |
|
44 | + * @param HttpHelper $httpHelper |
|
45 | + * |
|
46 | + * @return void |
|
47 | + */ |
|
48 | + public function setHttpHelper($httpHelper); |
|
49 | + |
|
50 | + /** |
|
51 | + * @return WikiTextHelper |
|
52 | + */ |
|
53 | + public function getWikiTextHelper(); |
|
54 | + |
|
55 | + /** |
|
56 | + * @param WikiTextHelper $wikiTextHelper |
|
57 | + * |
|
58 | + * @return void |
|
59 | + */ |
|
60 | + public function setWikiTextHelper($wikiTextHelper); |
|
61 | + |
|
62 | + /** |
|
63 | + * @return ILocationProvider |
|
64 | + */ |
|
65 | + public function getLocationProvider(); |
|
66 | + |
|
67 | + /** |
|
68 | + * @param ILocationProvider $locationProvider |
|
69 | + * |
|
70 | + * @return void |
|
71 | + */ |
|
72 | + public function setLocationProvider(ILocationProvider $locationProvider); |
|
73 | + |
|
74 | + /** |
|
75 | + * @return IXffTrustProvider |
|
76 | + */ |
|
77 | + public function getXffTrustProvider(); |
|
78 | + |
|
79 | + /** |
|
80 | + * @param IXffTrustProvider $xffTrustProvider |
|
81 | + * |
|
82 | + * @return void |
|
83 | + */ |
|
84 | + public function setXffTrustProvider(IXffTrustProvider $xffTrustProvider); |
|
85 | + |
|
86 | + /** |
|
87 | + * @return IRDnsProvider |
|
88 | + */ |
|
89 | + public function getRdnsProvider(); |
|
90 | + |
|
91 | + /** |
|
92 | + * @param IRDnsProvider $rdnsProvider |
|
93 | + * |
|
94 | + * @return void |
|
95 | + */ |
|
96 | + public function setRdnsProvider($rdnsProvider); |
|
97 | + |
|
98 | + /** |
|
99 | + * @return IAntiSpoofProvider |
|
100 | + */ |
|
101 | + public function getAntiSpoofProvider(); |
|
102 | + |
|
103 | + /** |
|
104 | + * @param IAntiSpoofProvider $antiSpoofProvider |
|
105 | + * |
|
106 | + * @return void |
|
107 | + */ |
|
108 | + public function setAntiSpoofProvider($antiSpoofProvider); |
|
109 | + |
|
110 | + /** |
|
111 | + * @return PdoDatabase |
|
112 | + */ |
|
113 | + public function getDatabase(); |
|
114 | + |
|
115 | + /** |
|
116 | + * @param PdoDatabase $database |
|
117 | + * |
|
118 | + * @return void |
|
119 | + */ |
|
120 | + public function setDatabase($database); |
|
121 | + |
|
122 | + /** |
|
123 | + * @return IOAuthHelper |
|
124 | + */ |
|
125 | + public function getOAuthHelper(); |
|
126 | + |
|
127 | + /** |
|
128 | + * @param IOAuthHelper $oauthHelper |
|
129 | + * |
|
130 | + * @return void |
|
131 | + */ |
|
132 | + public function setOAuthHelper($oauthHelper); |
|
133 | + |
|
134 | + /** |
|
135 | + * @return void |
|
136 | + */ |
|
137 | + public function execute(); |
|
138 | + |
|
139 | + /** |
|
140 | + * Sets the site configuration object for this page |
|
141 | + * |
|
142 | + * @param SiteConfiguration $configuration |
|
143 | + * |
|
144 | + * @return void |
|
145 | + */ |
|
146 | + public function setSiteConfiguration($configuration); |
|
147 | + |
|
148 | + /** |
|
149 | + * @return IrcNotificationHelper |
|
150 | + */ |
|
151 | + public function getNotificationHelper(); |
|
152 | + |
|
153 | + /** |
|
154 | + * @param IrcNotificationHelper $notificationHelper |
|
155 | + * |
|
156 | + * @return void |
|
157 | + */ |
|
158 | + public function setNotificationHelper($notificationHelper); |
|
159 | + |
|
160 | + /** |
|
161 | + * @return TorExitProvider |
|
162 | + */ |
|
163 | + public function getTorExitProvider(); |
|
164 | + |
|
165 | + /** |
|
166 | + * @param TorExitProvider $torExitProvider |
|
167 | + * |
|
168 | + * @return void |
|
169 | + */ |
|
170 | + public function setTorExitProvider($torExitProvider); |
|
171 | 171 | } |
172 | 172 | \ No newline at end of file |
@@ -23,229 +23,229 @@ |
||
23 | 23 | |
24 | 24 | abstract class TaskBase implements ITask |
25 | 25 | { |
26 | - /** @var SiteConfiguration */ |
|
27 | - private $siteConfiguration; |
|
28 | - /** @var IEmailHelper */ |
|
29 | - private $emailHelper; |
|
30 | - /** @var HttpHelper */ |
|
31 | - private $httpHelper; |
|
32 | - /** @var WikiTextHelper */ |
|
33 | - private $wikiTextHelper; |
|
34 | - /** @var ILocationProvider */ |
|
35 | - private $locationProvider; |
|
36 | - /** @var IXffTrustProvider */ |
|
37 | - private $xffTrustProvider; |
|
38 | - /** @var IRDnsProvider */ |
|
39 | - private $rdnsProvider; |
|
40 | - /** @var IAntiSpoofProvider */ |
|
41 | - private $antiSpoofProvider; |
|
42 | - /** @var IOAuthHelper */ |
|
43 | - private $oauthHelper; |
|
44 | - /** @var PdoDatabase */ |
|
45 | - private $database; |
|
46 | - /** @var IrcNotificationHelper */ |
|
47 | - private $notificationHelper; |
|
48 | - /** @var TorExitProvider */ |
|
49 | - private $torExitProvider; |
|
50 | - |
|
51 | - /** |
|
52 | - * @return IEmailHelper |
|
53 | - */ |
|
54 | - final public function getEmailHelper() |
|
55 | - { |
|
56 | - return $this->emailHelper; |
|
57 | - } |
|
58 | - |
|
59 | - /** |
|
60 | - * @param IEmailHelper $emailHelper |
|
61 | - */ |
|
62 | - final public function setEmailHelper($emailHelper) |
|
63 | - { |
|
64 | - $this->emailHelper = $emailHelper; |
|
65 | - } |
|
66 | - |
|
67 | - /** |
|
68 | - * @return HttpHelper |
|
69 | - */ |
|
70 | - final public function getHttpHelper() |
|
71 | - { |
|
72 | - return $this->httpHelper; |
|
73 | - } |
|
74 | - |
|
75 | - /** |
|
76 | - * @param HttpHelper $httpHelper |
|
77 | - */ |
|
78 | - final public function setHttpHelper($httpHelper) |
|
79 | - { |
|
80 | - $this->httpHelper = $httpHelper; |
|
81 | - } |
|
82 | - |
|
83 | - /** |
|
84 | - * @return WikiTextHelper |
|
85 | - */ |
|
86 | - final public function getWikiTextHelper() |
|
87 | - { |
|
88 | - return $this->wikiTextHelper; |
|
89 | - } |
|
90 | - |
|
91 | - /** |
|
92 | - * @param WikiTextHelper $wikiTextHelper |
|
93 | - */ |
|
94 | - final public function setWikiTextHelper($wikiTextHelper) |
|
95 | - { |
|
96 | - $this->wikiTextHelper = $wikiTextHelper; |
|
97 | - } |
|
98 | - |
|
99 | - /** |
|
100 | - * @return ILocationProvider |
|
101 | - */ |
|
102 | - final public function getLocationProvider() |
|
103 | - { |
|
104 | - return $this->locationProvider; |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * @param ILocationProvider $locationProvider |
|
109 | - */ |
|
110 | - final public function setLocationProvider(ILocationProvider $locationProvider) |
|
111 | - { |
|
112 | - $this->locationProvider = $locationProvider; |
|
113 | - } |
|
114 | - |
|
115 | - /** |
|
116 | - * @return IXffTrustProvider |
|
117 | - */ |
|
118 | - final public function getXffTrustProvider() |
|
119 | - { |
|
120 | - return $this->xffTrustProvider; |
|
121 | - } |
|
122 | - |
|
123 | - /** |
|
124 | - * @param IXffTrustProvider $xffTrustProvider |
|
125 | - */ |
|
126 | - final public function setXffTrustProvider(IXffTrustProvider $xffTrustProvider) |
|
127 | - { |
|
128 | - $this->xffTrustProvider = $xffTrustProvider; |
|
129 | - } |
|
130 | - |
|
131 | - /** |
|
132 | - * @return IRDnsProvider |
|
133 | - */ |
|
134 | - final public function getRdnsProvider() |
|
135 | - { |
|
136 | - return $this->rdnsProvider; |
|
137 | - } |
|
138 | - |
|
139 | - /** |
|
140 | - * @param IRDnsProvider $rdnsProvider |
|
141 | - */ |
|
142 | - public function setRdnsProvider($rdnsProvider) |
|
143 | - { |
|
144 | - $this->rdnsProvider = $rdnsProvider; |
|
145 | - } |
|
146 | - |
|
147 | - /** |
|
148 | - * @return IAntiSpoofProvider |
|
149 | - */ |
|
150 | - public function getAntiSpoofProvider() |
|
151 | - { |
|
152 | - return $this->antiSpoofProvider; |
|
153 | - } |
|
154 | - |
|
155 | - /** |
|
156 | - * @param IAntiSpoofProvider $antiSpoofProvider |
|
157 | - */ |
|
158 | - public function setAntiSpoofProvider($antiSpoofProvider) |
|
159 | - { |
|
160 | - $this->antiSpoofProvider = $antiSpoofProvider; |
|
161 | - } |
|
162 | - |
|
163 | - /** |
|
164 | - * @return PdoDatabase |
|
165 | - */ |
|
166 | - final public function getDatabase() |
|
167 | - { |
|
168 | - return $this->database; |
|
169 | - } |
|
170 | - |
|
171 | - /** |
|
172 | - * @param PdoDatabase $database |
|
173 | - */ |
|
174 | - final public function setDatabase($database) |
|
175 | - { |
|
176 | - $this->database = $database; |
|
177 | - } |
|
178 | - |
|
179 | - /** |
|
180 | - * @return IOAuthHelper |
|
181 | - */ |
|
182 | - public function getOAuthHelper() |
|
183 | - { |
|
184 | - return $this->oauthHelper; |
|
185 | - } |
|
186 | - |
|
187 | - /** |
|
188 | - * @param IOAuthHelper $oauthHelper |
|
189 | - */ |
|
190 | - public function setOAuthHelper($oauthHelper) |
|
191 | - { |
|
192 | - $this->oauthHelper = $oauthHelper; |
|
193 | - } |
|
194 | - |
|
195 | - /** |
|
196 | - * @return void |
|
197 | - */ |
|
198 | - abstract public function execute(); |
|
199 | - |
|
200 | - /** |
|
201 | - * @return IrcNotificationHelper |
|
202 | - */ |
|
203 | - public function getNotificationHelper() |
|
204 | - { |
|
205 | - return $this->notificationHelper; |
|
206 | - } |
|
207 | - |
|
208 | - /** |
|
209 | - * @param IrcNotificationHelper $notificationHelper |
|
210 | - */ |
|
211 | - public function setNotificationHelper($notificationHelper) |
|
212 | - { |
|
213 | - $this->notificationHelper = $notificationHelper; |
|
214 | - } |
|
215 | - |
|
216 | - /** |
|
217 | - * @return TorExitProvider |
|
218 | - */ |
|
219 | - public function getTorExitProvider() |
|
220 | - { |
|
221 | - return $this->torExitProvider; |
|
222 | - } |
|
223 | - |
|
224 | - /** |
|
225 | - * @param TorExitProvider $torExitProvider |
|
226 | - */ |
|
227 | - public function setTorExitProvider($torExitProvider) |
|
228 | - { |
|
229 | - $this->torExitProvider = $torExitProvider; |
|
230 | - } |
|
231 | - |
|
232 | - /** |
|
233 | - * Gets the site configuration object |
|
234 | - * |
|
235 | - * @return SiteConfiguration |
|
236 | - */ |
|
237 | - final protected function getSiteConfiguration() |
|
238 | - { |
|
239 | - return $this->siteConfiguration; |
|
240 | - } |
|
241 | - |
|
242 | - /** |
|
243 | - * Sets the site configuration object for this page |
|
244 | - * |
|
245 | - * @param SiteConfiguration $configuration |
|
246 | - */ |
|
247 | - final public function setSiteConfiguration($configuration) |
|
248 | - { |
|
249 | - $this->siteConfiguration = $configuration; |
|
250 | - } |
|
26 | + /** @var SiteConfiguration */ |
|
27 | + private $siteConfiguration; |
|
28 | + /** @var IEmailHelper */ |
|
29 | + private $emailHelper; |
|
30 | + /** @var HttpHelper */ |
|
31 | + private $httpHelper; |
|
32 | + /** @var WikiTextHelper */ |
|
33 | + private $wikiTextHelper; |
|
34 | + /** @var ILocationProvider */ |
|
35 | + private $locationProvider; |
|
36 | + /** @var IXffTrustProvider */ |
|
37 | + private $xffTrustProvider; |
|
38 | + /** @var IRDnsProvider */ |
|
39 | + private $rdnsProvider; |
|
40 | + /** @var IAntiSpoofProvider */ |
|
41 | + private $antiSpoofProvider; |
|
42 | + /** @var IOAuthHelper */ |
|
43 | + private $oauthHelper; |
|
44 | + /** @var PdoDatabase */ |
|
45 | + private $database; |
|
46 | + /** @var IrcNotificationHelper */ |
|
47 | + private $notificationHelper; |
|
48 | + /** @var TorExitProvider */ |
|
49 | + private $torExitProvider; |
|
50 | + |
|
51 | + /** |
|
52 | + * @return IEmailHelper |
|
53 | + */ |
|
54 | + final public function getEmailHelper() |
|
55 | + { |
|
56 | + return $this->emailHelper; |
|
57 | + } |
|
58 | + |
|
59 | + /** |
|
60 | + * @param IEmailHelper $emailHelper |
|
61 | + */ |
|
62 | + final public function setEmailHelper($emailHelper) |
|
63 | + { |
|
64 | + $this->emailHelper = $emailHelper; |
|
65 | + } |
|
66 | + |
|
67 | + /** |
|
68 | + * @return HttpHelper |
|
69 | + */ |
|
70 | + final public function getHttpHelper() |
|
71 | + { |
|
72 | + return $this->httpHelper; |
|
73 | + } |
|
74 | + |
|
75 | + /** |
|
76 | + * @param HttpHelper $httpHelper |
|
77 | + */ |
|
78 | + final public function setHttpHelper($httpHelper) |
|
79 | + { |
|
80 | + $this->httpHelper = $httpHelper; |
|
81 | + } |
|
82 | + |
|
83 | + /** |
|
84 | + * @return WikiTextHelper |
|
85 | + */ |
|
86 | + final public function getWikiTextHelper() |
|
87 | + { |
|
88 | + return $this->wikiTextHelper; |
|
89 | + } |
|
90 | + |
|
91 | + /** |
|
92 | + * @param WikiTextHelper $wikiTextHelper |
|
93 | + */ |
|
94 | + final public function setWikiTextHelper($wikiTextHelper) |
|
95 | + { |
|
96 | + $this->wikiTextHelper = $wikiTextHelper; |
|
97 | + } |
|
98 | + |
|
99 | + /** |
|
100 | + * @return ILocationProvider |
|
101 | + */ |
|
102 | + final public function getLocationProvider() |
|
103 | + { |
|
104 | + return $this->locationProvider; |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * @param ILocationProvider $locationProvider |
|
109 | + */ |
|
110 | + final public function setLocationProvider(ILocationProvider $locationProvider) |
|
111 | + { |
|
112 | + $this->locationProvider = $locationProvider; |
|
113 | + } |
|
114 | + |
|
115 | + /** |
|
116 | + * @return IXffTrustProvider |
|
117 | + */ |
|
118 | + final public function getXffTrustProvider() |
|
119 | + { |
|
120 | + return $this->xffTrustProvider; |
|
121 | + } |
|
122 | + |
|
123 | + /** |
|
124 | + * @param IXffTrustProvider $xffTrustProvider |
|
125 | + */ |
|
126 | + final public function setXffTrustProvider(IXffTrustProvider $xffTrustProvider) |
|
127 | + { |
|
128 | + $this->xffTrustProvider = $xffTrustProvider; |
|
129 | + } |
|
130 | + |
|
131 | + /** |
|
132 | + * @return IRDnsProvider |
|
133 | + */ |
|
134 | + final public function getRdnsProvider() |
|
135 | + { |
|
136 | + return $this->rdnsProvider; |
|
137 | + } |
|
138 | + |
|
139 | + /** |
|
140 | + * @param IRDnsProvider $rdnsProvider |
|
141 | + */ |
|
142 | + public function setRdnsProvider($rdnsProvider) |
|
143 | + { |
|
144 | + $this->rdnsProvider = $rdnsProvider; |
|
145 | + } |
|
146 | + |
|
147 | + /** |
|
148 | + * @return IAntiSpoofProvider |
|
149 | + */ |
|
150 | + public function getAntiSpoofProvider() |
|
151 | + { |
|
152 | + return $this->antiSpoofProvider; |
|
153 | + } |
|
154 | + |
|
155 | + /** |
|
156 | + * @param IAntiSpoofProvider $antiSpoofProvider |
|
157 | + */ |
|
158 | + public function setAntiSpoofProvider($antiSpoofProvider) |
|
159 | + { |
|
160 | + $this->antiSpoofProvider = $antiSpoofProvider; |
|
161 | + } |
|
162 | + |
|
163 | + /** |
|
164 | + * @return PdoDatabase |
|
165 | + */ |
|
166 | + final public function getDatabase() |
|
167 | + { |
|
168 | + return $this->database; |
|
169 | + } |
|
170 | + |
|
171 | + /** |
|
172 | + * @param PdoDatabase $database |
|
173 | + */ |
|
174 | + final public function setDatabase($database) |
|
175 | + { |
|
176 | + $this->database = $database; |
|
177 | + } |
|
178 | + |
|
179 | + /** |
|
180 | + * @return IOAuthHelper |
|
181 | + */ |
|
182 | + public function getOAuthHelper() |
|
183 | + { |
|
184 | + return $this->oauthHelper; |
|
185 | + } |
|
186 | + |
|
187 | + /** |
|
188 | + * @param IOAuthHelper $oauthHelper |
|
189 | + */ |
|
190 | + public function setOAuthHelper($oauthHelper) |
|
191 | + { |
|
192 | + $this->oauthHelper = $oauthHelper; |
|
193 | + } |
|
194 | + |
|
195 | + /** |
|
196 | + * @return void |
|
197 | + */ |
|
198 | + abstract public function execute(); |
|
199 | + |
|
200 | + /** |
|
201 | + * @return IrcNotificationHelper |
|
202 | + */ |
|
203 | + public function getNotificationHelper() |
|
204 | + { |
|
205 | + return $this->notificationHelper; |
|
206 | + } |
|
207 | + |
|
208 | + /** |
|
209 | + * @param IrcNotificationHelper $notificationHelper |
|
210 | + */ |
|
211 | + public function setNotificationHelper($notificationHelper) |
|
212 | + { |
|
213 | + $this->notificationHelper = $notificationHelper; |
|
214 | + } |
|
215 | + |
|
216 | + /** |
|
217 | + * @return TorExitProvider |
|
218 | + */ |
|
219 | + public function getTorExitProvider() |
|
220 | + { |
|
221 | + return $this->torExitProvider; |
|
222 | + } |
|
223 | + |
|
224 | + /** |
|
225 | + * @param TorExitProvider $torExitProvider |
|
226 | + */ |
|
227 | + public function setTorExitProvider($torExitProvider) |
|
228 | + { |
|
229 | + $this->torExitProvider = $torExitProvider; |
|
230 | + } |
|
231 | + |
|
232 | + /** |
|
233 | + * Gets the site configuration object |
|
234 | + * |
|
235 | + * @return SiteConfiguration |
|
236 | + */ |
|
237 | + final protected function getSiteConfiguration() |
|
238 | + { |
|
239 | + return $this->siteConfiguration; |
|
240 | + } |
|
241 | + |
|
242 | + /** |
|
243 | + * Sets the site configuration object for this page |
|
244 | + * |
|
245 | + * @param SiteConfiguration $configuration |
|
246 | + */ |
|
247 | + final public function setSiteConfiguration($configuration) |
|
248 | + { |
|
249 | + $this->siteConfiguration = $configuration; |
|
250 | + } |
|
251 | 251 | } |
252 | 252 | \ No newline at end of file |
@@ -16,97 +16,97 @@ |
||
16 | 16 | |
17 | 17 | abstract class ApiPageBase extends TaskBase implements IRoutedTask, IApiAction |
18 | 18 | { |
19 | - /** |
|
20 | - * API result document |
|
21 | - * @var DOMDocument |
|
22 | - */ |
|
23 | - protected $document; |
|
24 | - |
|
25 | - public function __construct() |
|
26 | - { |
|
27 | - $this->document = new DOMDocument('1.0'); |
|
28 | - } |
|
29 | - |
|
30 | - final public function execute() |
|
31 | - { |
|
32 | - $this->main(); |
|
33 | - } |
|
34 | - |
|
35 | - /** |
|
36 | - * @param string $routeName |
|
37 | - */ |
|
38 | - public function setRoute($routeName) |
|
39 | - { |
|
40 | - // no-op |
|
41 | - } |
|
42 | - |
|
43 | - /** |
|
44 | - * @return string |
|
45 | - */ |
|
46 | - public function getRouteName() |
|
47 | - { |
|
48 | - return 'main'; |
|
49 | - } |
|
50 | - |
|
51 | - /** |
|
52 | - * Main function for this page, when no specific actions are called. |
|
53 | - * |
|
54 | - * @throws ApiException |
|
55 | - * @return void |
|
56 | - */ |
|
57 | - final protected function main() |
|
58 | - { |
|
59 | - if (headers_sent()) { |
|
60 | - throw new ApiException('Headers have already been sent - this indicates a bug in the application!'); |
|
61 | - } |
|
62 | - |
|
63 | - header("Content-Type: text/xml"); |
|
64 | - |
|
65 | - // javascript access control |
|
66 | - $httpOrigin = WebRequest::origin(); |
|
67 | - |
|
68 | - if ($httpOrigin !== null) { |
|
69 | - $CORSallowed = $this->getSiteConfiguration()->getCrossOriginResourceSharingHosts(); |
|
70 | - |
|
71 | - if (in_array($httpOrigin, $CORSallowed)) { |
|
72 | - header("Access-Control-Allow-Origin: " . $httpOrigin); |
|
73 | - } |
|
74 | - } |
|
75 | - |
|
76 | - $responseData = $this->runApiPage(); |
|
77 | - |
|
78 | - ob_end_clean(); |
|
79 | - print($responseData); |
|
80 | - ob_start(); |
|
81 | - } |
|
82 | - |
|
83 | - /** |
|
84 | - * Method that runs API action |
|
85 | - * |
|
86 | - * @param DOMElement $apiDocument |
|
87 | - * |
|
88 | - * @return DOMElement |
|
89 | - */ |
|
90 | - abstract public function executeApiAction(DOMElement $apiDocument); |
|
91 | - |
|
92 | - /** |
|
93 | - * @return string |
|
94 | - */ |
|
95 | - final public function runApiPage() |
|
96 | - { |
|
97 | - $apiDocument = $this->document->createElement("api"); |
|
98 | - |
|
99 | - try { |
|
100 | - $apiDocument = $this->executeApiAction($apiDocument); |
|
101 | - } |
|
102 | - catch (ApiException $ex) { |
|
103 | - $exception = $this->document->createElement("error"); |
|
104 | - $exception->setAttribute("message", $ex->getMessage()); |
|
105 | - $apiDocument->appendChild($exception); |
|
106 | - } |
|
107 | - |
|
108 | - $this->document->appendChild($apiDocument); |
|
109 | - |
|
110 | - return $this->document->saveXML(); |
|
111 | - } |
|
19 | + /** |
|
20 | + * API result document |
|
21 | + * @var DOMDocument |
|
22 | + */ |
|
23 | + protected $document; |
|
24 | + |
|
25 | + public function __construct() |
|
26 | + { |
|
27 | + $this->document = new DOMDocument('1.0'); |
|
28 | + } |
|
29 | + |
|
30 | + final public function execute() |
|
31 | + { |
|
32 | + $this->main(); |
|
33 | + } |
|
34 | + |
|
35 | + /** |
|
36 | + * @param string $routeName |
|
37 | + */ |
|
38 | + public function setRoute($routeName) |
|
39 | + { |
|
40 | + // no-op |
|
41 | + } |
|
42 | + |
|
43 | + /** |
|
44 | + * @return string |
|
45 | + */ |
|
46 | + public function getRouteName() |
|
47 | + { |
|
48 | + return 'main'; |
|
49 | + } |
|
50 | + |
|
51 | + /** |
|
52 | + * Main function for this page, when no specific actions are called. |
|
53 | + * |
|
54 | + * @throws ApiException |
|
55 | + * @return void |
|
56 | + */ |
|
57 | + final protected function main() |
|
58 | + { |
|
59 | + if (headers_sent()) { |
|
60 | + throw new ApiException('Headers have already been sent - this indicates a bug in the application!'); |
|
61 | + } |
|
62 | + |
|
63 | + header("Content-Type: text/xml"); |
|
64 | + |
|
65 | + // javascript access control |
|
66 | + $httpOrigin = WebRequest::origin(); |
|
67 | + |
|
68 | + if ($httpOrigin !== null) { |
|
69 | + $CORSallowed = $this->getSiteConfiguration()->getCrossOriginResourceSharingHosts(); |
|
70 | + |
|
71 | + if (in_array($httpOrigin, $CORSallowed)) { |
|
72 | + header("Access-Control-Allow-Origin: " . $httpOrigin); |
|
73 | + } |
|
74 | + } |
|
75 | + |
|
76 | + $responseData = $this->runApiPage(); |
|
77 | + |
|
78 | + ob_end_clean(); |
|
79 | + print($responseData); |
|
80 | + ob_start(); |
|
81 | + } |
|
82 | + |
|
83 | + /** |
|
84 | + * Method that runs API action |
|
85 | + * |
|
86 | + * @param DOMElement $apiDocument |
|
87 | + * |
|
88 | + * @return DOMElement |
|
89 | + */ |
|
90 | + abstract public function executeApiAction(DOMElement $apiDocument); |
|
91 | + |
|
92 | + /** |
|
93 | + * @return string |
|
94 | + */ |
|
95 | + final public function runApiPage() |
|
96 | + { |
|
97 | + $apiDocument = $this->document->createElement("api"); |
|
98 | + |
|
99 | + try { |
|
100 | + $apiDocument = $this->executeApiAction($apiDocument); |
|
101 | + } |
|
102 | + catch (ApiException $ex) { |
|
103 | + $exception = $this->document->createElement("error"); |
|
104 | + $exception->setAttribute("message", $ex->getMessage()); |
|
105 | + $apiDocument->appendChild($exception); |
|
106 | + } |
|
107 | + |
|
108 | + $this->document->appendChild($apiDocument); |
|
109 | + |
|
110 | + return $this->document->saveXML(); |
|
111 | + } |
|
112 | 112 | } |
113 | 113 | \ No newline at end of file |
@@ -69,7 +69,7 @@ |
||
69 | 69 | $CORSallowed = $this->getSiteConfiguration()->getCrossOriginResourceSharingHosts(); |
70 | 70 | |
71 | 71 | if (in_array($httpOrigin, $CORSallowed)) { |
72 | - header("Access-Control-Allow-Origin: " . $httpOrigin); |
|
72 | + header("Access-Control-Allow-Origin: ".$httpOrigin); |
|
73 | 73 | } |
74 | 74 | } |
75 | 75 |