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