1 | <?php |
||
13 | class HtaccessFirewall implements Firewall |
||
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) |
||
37 | { |
||
38 | $this->fileSystem = $fileSystem ?: new BuiltInFilesystem(); |
||
39 | |||
40 | $this->path = $path; |
||
41 | } |
||
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) |
||
132 | |||
133 | /** |
||
134 | * Remove 403 error message. |
||
135 | */ |
||
136 | public function remove403Message() |
||
140 | |||
141 | /** |
||
142 | * Add single line. |
||
143 | * |
||
144 | * @param string $line |
||
145 | */ |
||
146 | private function addLine($line) |
||
157 | |||
158 | /** |
||
159 | * Remove single line. |
||
160 | * |
||
161 | * @param string $content |
||
162 | */ |
||
163 | private function removeLine($content) |
||
176 | |||
177 | /** |
||
178 | * Get array of prefixed lines in section. |
||
179 | * |
||
180 | * @param string|string[] $prefixes |
||
181 | * |
||
182 | * @return string[] |
||
183 | */ |
||
184 | private function readLinesWithPrefix($prefixes) |
||
203 | |||
204 | /** |
||
205 | * Get array of all lines in section. |
||
206 | * |
||
207 | * @return string[] |
||
208 | */ |
||
209 | private function readLines() |
||
229 | |||
230 | /** |
||
231 | * Write array of lines to section. |
||
232 | * |
||
233 | * @param string[] $lines |
||
234 | * |
||
235 | * @throws FileException |
||
236 | */ |
||
237 | private function writeLines($lines) |
||
279 | |||
280 | /** |
||
281 | * Check whether line is the begin of the section. |
||
282 | * |
||
283 | * @param $line |
||
284 | * |
||
285 | * @return bool |
||
286 | */ |
||
287 | private function isBeginOfSection($line) |
||
291 | |||
292 | /** |
||
293 | * Check whether line is the end of the section. |
||
294 | * |
||
295 | * @param $line |
||
296 | * |
||
297 | * @return bool |
||
298 | */ |
||
299 | private function isEndOfSection($line) |
||
303 | } |
||
304 |