1 | <?php |
||
25 | trait RequestData |
||
26 | { |
||
27 | /** |
||
28 | * @var array Array of IP address classed as 'private' by RFC1918. |
||
29 | */ |
||
30 | protected static $rfc1918ips = array( |
||
31 | "10.0.0.0" => "10.255.255.255", |
||
32 | "172.16.0.0" => "172.31.255.255", |
||
33 | "192.168.0.0" => "192.168.255.255", |
||
34 | "169.254.0.0" => "169.254.255.255", |
||
35 | "127.0.0.0" => "127.255.255.255", |
||
36 | ); |
||
37 | |||
38 | /** |
||
39 | * Gets a request object |
||
40 | * |
||
41 | * @param PdoDatabase $database The database connection |
||
42 | * @param int $requestId The ID of the request to retrieve |
||
43 | * |
||
44 | * @return Request |
||
45 | * @throws ApplicationLogicException |
||
46 | */ |
||
47 | protected function getRequest(PdoDatabase $database, $requestId) |
||
60 | |||
61 | /** |
||
62 | * Returns a value stating whether the user is allowed to see private data or not |
||
63 | * |
||
64 | * @param Request $request |
||
65 | * @param User $currentUser |
||
66 | * |
||
67 | * @return bool |
||
68 | * @category Security-Critical |
||
69 | */ |
||
70 | 6 | protected function isAllowedPrivateData(Request $request, User $currentUser) |
|
91 | |||
92 | /** |
||
93 | * Tests the security barrier for a specified action. |
||
94 | * |
||
95 | * Intended to be used from within templates |
||
96 | * |
||
97 | * @param string $action |
||
98 | * |
||
99 | * @return boolean |
||
100 | * @category Security-Critical |
||
101 | */ |
||
102 | abstract protected function barrierTest($action); |
||
103 | |||
104 | /** |
||
105 | * Gets the name of the route that has been passed from the request router. |
||
106 | * @return string |
||
107 | */ |
||
108 | abstract protected function getRouteName(); |
||
109 | |||
110 | /** @return SecurityManager */ |
||
111 | abstract protected function getSecurityManager(); |
||
112 | |||
113 | /** |
||
114 | * Sets the name of the template this page should display. |
||
115 | * |
||
116 | * @param string $name |
||
117 | */ |
||
118 | abstract protected function setTemplate($name); |
||
119 | |||
120 | /** @return IXffTrustProvider */ |
||
121 | abstract protected function getXffTrustProvider(); |
||
122 | |||
123 | /** @return ILocationProvider */ |
||
124 | abstract protected function getLocationProvider(); |
||
125 | |||
126 | /** @return IRDnsProvider */ |
||
127 | abstract protected function getRdnsProvider(); |
||
128 | |||
129 | /** |
||
130 | * Assigns a Smarty variable |
||
131 | * |
||
132 | * @param array|string $name the template variable name(s) |
||
133 | * @param mixed $value the value to assign |
||
134 | */ |
||
135 | abstract protected function assign($name, $value); |
||
136 | |||
137 | /** |
||
138 | * @param int $requestReservationId |
||
139 | * @param PdoDatabase $database |
||
140 | * @param User $currentUser |
||
141 | */ |
||
142 | protected function setupReservationDetails($requestReservationId, PdoDatabase $database, User $currentUser) |
||
143 | { |
||
144 | $requestIsReserved = $requestReservationId !== null; |
||
145 | $this->assign('requestIsReserved', $requestIsReserved); |
||
146 | $this->assign('requestIsReservedByMe', false); |
||
147 | |||
148 | if ($requestIsReserved) { |
||
149 | $this->assign('requestReservedByName', User::getById($requestReservationId, $database)->getUsername()); |
||
150 | $this->assign('requestReservedById', $requestReservationId); |
||
151 | |||
152 | if ($requestReservationId === $currentUser->getId()) { |
||
153 | $this->assign('requestIsReservedByMe', true); |
||
154 | } |
||
155 | } |
||
156 | } |
||
157 | |||
158 | /** |
||
159 | * Adds private request data to Smarty. DO NOT USE WITHOUT FIRST CHECKING THAT THE USER IS AUTHORISED! |
||
160 | * |
||
161 | * @param Request $request |
||
162 | * @param User $currentUser |
||
163 | * @param SiteConfiguration $configuration |
||
164 | * |
||
165 | * @param PdoDatabase $database |
||
166 | */ |
||
167 | protected function setupPrivateData( |
||
168 | $request, |
||
169 | User $currentUser, |
||
170 | SiteConfiguration $configuration, |
||
171 | PdoDatabase $database |
||
172 | ) { |
||
173 | $xffProvider = $this->getXffTrustProvider(); |
||
174 | |||
175 | $relatedEmailRequests = RequestSearchHelper::get($database) |
||
176 | ->byEmailAddress($request->getEmail()) |
||
177 | ->withConfirmedEmail() |
||
178 | ->excludingPurgedData($configuration) |
||
179 | ->excludingRequest($request->getId()) |
||
180 | ->fetch(); |
||
181 | |||
182 | $this->assign('requestEmail', $request->getEmail()); |
||
183 | $emailDomain = explode("@", $request->getEmail())[1]; |
||
184 | $this->assign("emailurl", $emailDomain); |
||
185 | $this->assign('requestRelatedEmailRequestsCount', count($relatedEmailRequests)); |
||
186 | $this->assign('requestRelatedEmailRequests', $relatedEmailRequests); |
||
187 | |||
188 | $trustedIp = $xffProvider->getTrustedClientIp($request->getIp(), $request->getForwardedIp()); |
||
189 | $this->assign('requestTrustedIp', $trustedIp); |
||
190 | $this->assign('requestRealIp', $request->getIp()); |
||
191 | $this->assign('requestForwardedIp', $request->getForwardedIp()); |
||
192 | |||
193 | $trustedIpLocation = $this->getLocationProvider()->getIpLocation($trustedIp); |
||
194 | $this->assign('requestTrustedIpLocation', $trustedIpLocation); |
||
195 | |||
196 | $this->assign('requestHasForwardedIp', $request->getForwardedIp() !== null); |
||
197 | |||
198 | $relatedIpRequests = RequestSearchHelper::get($database) |
||
199 | ->byIp($trustedIp) |
||
200 | ->withConfirmedEmail() |
||
201 | ->excludingPurgedData($configuration) |
||
202 | ->excludingRequest($request->getId()) |
||
203 | ->fetch(); |
||
204 | |||
205 | $this->assign('requestRelatedIpRequestsCount', count($relatedIpRequests)); |
||
206 | $this->assign('requestRelatedIpRequests', $relatedIpRequests); |
||
207 | |||
208 | $this->assign('showRevealLink', false); |
||
209 | if ($request->getReserved() === $currentUser->getId() || |
||
210 | $currentUser->isAdmin() || |
||
211 | $currentUser->isCheckuser() |
||
212 | ) { |
||
213 | $this->assign('showRevealLink', true); |
||
214 | |||
215 | $this->assign('revealHash', $request->getRevealHash()); |
||
216 | } |
||
217 | |||
218 | $this->setupForwardedIpData($request); |
||
219 | } |
||
220 | |||
221 | /** |
||
222 | * Adds checkuser request data to Smarty. DO NOT USE WITHOUT FIRST CHECKING THAT THE USER IS AUTHORISED! |
||
223 | * |
||
224 | * @param Request $request |
||
225 | */ |
||
226 | protected function setupCheckUserData(Request $request) |
||
230 | |||
231 | /** |
||
232 | * Sets up the basic data for this request, and adds it to Smarty |
||
233 | * |
||
234 | * @param Request $request |
||
235 | * @param SiteConfiguration $config |
||
236 | */ |
||
237 | protected function setupBasicData(Request $request, SiteConfiguration $config) |
||
247 | |||
248 | /** |
||
249 | * Sets up the forwarded IP data for this request and adds it to Smarty |
||
250 | * |
||
251 | * @param Request $request |
||
252 | */ |
||
253 | 6 | protected function setupForwardedIpData(Request $request) |
|
337 | |||
338 | /** |
||
339 | * Sets up the security for this page. If certain actions have different permissions, this should be reflected in |
||
340 | * the return value from this function. |
||
341 | * |
||
342 | * If this page even supports actions, you will need to check the route |
||
343 | * |
||
344 | * @return SecurityConfiguration |
||
345 | * @category Security-Critical |
||
346 | */ |
||
347 | protected function getSecurityConfiguration() |
||
358 | } |