1
|
|
|
<?php |
2
|
|
|
namespace Aoe\FeloginBruteforceProtection\System; |
3
|
|
|
|
4
|
|
|
/*************************************************************** |
5
|
|
|
* Copyright notice |
6
|
|
|
* |
7
|
|
|
* (c) 2019 AOE GmbH <[email protected]> |
8
|
|
|
* |
9
|
|
|
* All rights reserved |
10
|
|
|
* |
11
|
|
|
* This script is part of the TYPO3 project. The TYPO3 project is |
12
|
|
|
* free software; you can redistribute it and/or modify |
13
|
|
|
* it under the terms of the GNU General Public License as published by |
14
|
|
|
* the Free Software Foundation; either version 3 of the License, or |
15
|
|
|
* (at your option) any later version. |
16
|
|
|
* |
17
|
|
|
* The GNU General Public License can be found at |
18
|
|
|
* http://www.gnu.org/copyleft/gpl.html. |
19
|
|
|
* |
20
|
|
|
* This script is distributed in the hope that it will be useful, |
21
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
22
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
23
|
|
|
* GNU General Public License for more details. |
24
|
|
|
* |
25
|
|
|
* This copyright notice MUST APPEAR in all copies of the script! |
26
|
|
|
***************************************************************/ |
27
|
|
|
|
28
|
|
|
use TYPO3\CMS\Core\Configuration\ExtensionConfiguration; |
29
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
30
|
|
|
use TYPO3\CMS\Extbase\Configuration\Exception; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Class Configuration |
34
|
|
|
*/ |
35
|
|
|
class Configuration |
36
|
|
|
{ |
37
|
|
|
/** |
38
|
|
|
* @var string |
39
|
|
|
*/ |
40
|
|
|
const CONF_MAX_FAILURES = 'max_failures'; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @var string |
44
|
|
|
*/ |
45
|
|
|
const CONF_DISABLED = 'disabled'; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @var string |
49
|
|
|
*/ |
50
|
|
|
const CONF_RESTRICTION_TIME = 'restriction_time'; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @var string |
54
|
|
|
*/ |
55
|
|
|
const CONF_SECONDS_TILL_RESET = 'seconds_till_reset'; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @var string |
59
|
|
|
*/ |
60
|
|
|
const LOGGING_ENABLED = 'logging_enabled'; |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @var string |
64
|
|
|
*/ |
65
|
|
|
const LOGGING_LEVEL = 'logging_level'; |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @var string |
69
|
|
|
*/ |
70
|
|
|
const EXCLUDED_IPS = 'exclude_ips'; |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @var string |
74
|
|
|
*/ |
75
|
|
|
const X_FORWARDED_FOR = 'x_forwarded_for'; |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @var string |
79
|
|
|
*/ |
80
|
|
|
const CONF_IDENTIFICATION_IDENTIFIER = 'identification_identifier'; |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @var array |
84
|
|
|
*/ |
85
|
|
|
private $configuration = array(); |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Initialize configuration array |
89
|
|
|
*/ |
90
|
37 |
|
public function __construct() |
91
|
|
|
{ |
92
|
37 |
|
$conf = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['felogin_bruteforce_protection']); |
93
|
37 |
|
if (is_array($conf)) { |
94
|
10 |
|
$this->configuration = $conf; |
95
|
|
|
} |
96
|
37 |
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Tells if the protection is enabled. |
100
|
|
|
* |
101
|
|
|
* @return boolean |
102
|
|
|
*/ |
103
|
2 |
|
public function isEnabled() |
104
|
|
|
{ |
105
|
2 |
|
if ('1' === $this->get(self::CONF_DISABLED)) { |
106
|
1 |
|
return false; |
107
|
|
|
} |
108
|
1 |
|
return true; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Returns the maximum number of allowed failures for an ip. |
113
|
|
|
* |
114
|
|
|
* @return integer |
115
|
|
|
*/ |
116
|
1 |
|
public function getMaximumNumberOfFailures() |
117
|
|
|
{ |
118
|
1 |
|
return (integer)$this->get(self::CONF_MAX_FAILURES); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* Returns the number of seconds of the restriction time. |
123
|
|
|
* |
124
|
|
|
* @return integer |
125
|
|
|
*/ |
126
|
1 |
|
public function getRestrictionTime() |
127
|
|
|
{ |
128
|
1 |
|
return (integer)$this->get(self::CONF_RESTRICTION_TIME); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* Returns the number of seconds after an entry is resetted. |
133
|
|
|
* |
134
|
|
|
* @return integer |
135
|
|
|
*/ |
136
|
1 |
|
public function getResetTime() |
137
|
|
|
{ |
138
|
1 |
|
return (integer)$this->get(self::CONF_SECONDS_TILL_RESET); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* @return boolean |
143
|
|
|
*/ |
144
|
|
|
public function isLoggingEnabled() |
145
|
|
|
{ |
146
|
|
|
return (boolean)$this->get(self::LOGGING_ENABLED) == 1; |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* @return int |
151
|
|
|
*/ |
152
|
|
|
public function getLogLevel() |
153
|
|
|
{ |
154
|
|
|
return (integer)$this->get(self::LOGGING_LEVEL); |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* @return array |
159
|
|
|
*/ |
160
|
2 |
|
public function getExcludedIps() |
161
|
|
|
{ |
162
|
2 |
|
return explode(',', $this->get(self::EXCLUDED_IPS)); |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
/** |
166
|
|
|
* @return boolean |
167
|
|
|
*/ |
168
|
2 |
|
public function getXForwardedFor() |
169
|
|
|
{ |
170
|
2 |
|
return (boolean)$this->get(self::X_FORWARDED_FOR); |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
/** |
174
|
|
|
* @return integer |
175
|
|
|
**/ |
176
|
1 |
|
public function getIdentificationIdentifier() |
177
|
|
|
{ |
178
|
1 |
|
return (integer)$this->get(self::CONF_IDENTIFICATION_IDENTIFIER); |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
/** |
182
|
|
|
* @param string $key |
183
|
|
|
* @return mixed |
184
|
|
|
* @throws Exception |
185
|
|
|
*/ |
186
|
11 |
|
public function get($key) |
187
|
|
|
{ |
188
|
11 |
|
if (array_key_exists($key, $this->configuration)) { |
189
|
10 |
|
return $this->configuration[$key]; |
190
|
|
|
} |
191
|
1 |
|
throw new Exception('Configuration key "' . $key . '" does not exist.'); |
192
|
|
|
} |
193
|
|
|
} |
194
|
|
|
|