1 | <?php |
||
13 | class HtaccessFirewall |
||
14 | { |
||
15 | /** |
||
16 | * @var string |
||
17 | */ |
||
18 | public static $sectionLabel = 'Firewall'; |
||
19 | |||
20 | /** |
||
21 | * @var string |
||
22 | */ |
||
23 | private $path; |
||
24 | |||
25 | /** |
||
26 | * @var Filesystem |
||
27 | */ |
||
28 | private $fileSystem; |
||
29 | |||
30 | /** |
||
31 | * Initialize HtaccessFirewall. |
||
32 | * |
||
33 | * @param $path |
||
34 | * @param Filesystem $fileSystem |
||
35 | */ |
||
36 | public function __construct($path, Filesystem $fileSystem = null) |
||
42 | |||
43 | /** |
||
44 | * Deny host. |
||
45 | * |
||
46 | * @param Host $host |
||
47 | */ |
||
48 | public function deny(Host $host) |
||
52 | |||
53 | /** |
||
54 | * Undeny host. |
||
55 | * |
||
56 | * @param Host $host |
||
57 | */ |
||
58 | public function undeny(Host $host) |
||
62 | |||
63 | /** |
||
64 | * Get all denied hosts. |
||
65 | * |
||
66 | * @return string[] |
||
67 | */ |
||
68 | public function getDenied() |
||
79 | |||
80 | /** |
||
81 | * Deactivate all denials. |
||
82 | */ |
||
83 | public function deactivate() |
||
94 | |||
95 | /** |
||
96 | * Reactivate all deactivated denials. |
||
97 | */ |
||
98 | public function reactivate() |
||
111 | |||
112 | /** |
||
113 | * Set 403 error message. |
||
114 | * |
||
115 | * @param string $message |
||
116 | */ |
||
117 | public function set403Message($message) |
||
134 | |||
135 | /** |
||
136 | * Remove 403 error message. |
||
137 | */ |
||
138 | public function remove403Message() |
||
142 | |||
143 | /** |
||
144 | * Check whether Htaccess file exists. |
||
145 | * |
||
146 | * @return bool |
||
147 | */ |
||
148 | public function exists() |
||
152 | |||
153 | /** |
||
154 | * Check whether Htaccess file exists and is readable. |
||
155 | * |
||
156 | * @return bool |
||
157 | */ |
||
158 | public function readable() |
||
162 | |||
163 | /** |
||
164 | * Check whether Htaccess file exists and is writable. |
||
165 | * |
||
166 | * @return bool |
||
167 | */ |
||
168 | public function writable() |
||
172 | |||
173 | /** |
||
174 | * Add single line. |
||
175 | * |
||
176 | * @param string $line |
||
177 | */ |
||
178 | private function addLine($line) |
||
189 | |||
190 | /** |
||
191 | * Remove single line. |
||
192 | * |
||
193 | * @param string $content |
||
194 | */ |
||
195 | private function removeLine($content) |
||
208 | |||
209 | /** |
||
210 | * Get array of prefixed lines in section. |
||
211 | * |
||
212 | * @param string|string[] $prefixes |
||
213 | * |
||
214 | * @return string[] |
||
215 | */ |
||
216 | private function readLinesWithPrefix($prefixes) |
||
235 | |||
236 | /** |
||
237 | * Get array of all lines in section. |
||
238 | * |
||
239 | * @return string[] |
||
240 | */ |
||
241 | private function readLines() |
||
261 | |||
262 | /** |
||
263 | * Write array of lines to section. |
||
264 | * |
||
265 | * @param string[] $lines |
||
266 | * |
||
267 | * @throws FileException |
||
268 | */ |
||
269 | private function writeLines($lines) |
||
311 | |||
312 | /** |
||
313 | * Check whether line is the begin of the section. |
||
314 | * |
||
315 | * @param $line |
||
316 | * |
||
317 | * @return bool |
||
318 | */ |
||
319 | private function isBeginOfSection($line) |
||
323 | |||
324 | /** |
||
325 | * Check whether line is the end of the section. |
||
326 | * |
||
327 | * @param $line |
||
328 | * |
||
329 | * @return bool |
||
330 | */ |
||
331 | private function isEndOfSection($line) |
||
335 | } |
||
336 |