|
1
|
|
|
<?php
|
|
2
|
|
|
/**
|
|
3
|
|
|
* @author Semih Serhat Karakaya <[email protected]>
|
|
4
|
|
|
*
|
|
5
|
|
|
* @copyright Copyright (c) 2017, ownCloud GmbH
|
|
6
|
|
|
* @license AGPL-3.0
|
|
7
|
|
|
*
|
|
8
|
|
|
* This code is free software: you can redistribute it and/or modify
|
|
9
|
|
|
* it under the terms of the GNU Affero General Public License, version 3,
|
|
10
|
|
|
* as published by the Free Software Foundation.
|
|
11
|
|
|
*
|
|
12
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
15
|
|
|
* GNU Affero General Public License for more details.
|
|
16
|
|
|
*
|
|
17
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3,
|
|
18
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
|
19
|
|
|
*
|
|
20
|
|
|
*/
|
|
21
|
|
|
|
|
22
|
|
|
namespace OCA\Security;
|
|
23
|
|
|
|
|
24
|
|
|
use OCP\IDBConnection;
|
|
25
|
|
|
|
|
26
|
|
|
/**
|
|
27
|
|
|
* Class Throttle
|
|
28
|
|
|
* @package OCA\Secuity\Lib
|
|
29
|
|
|
*/
|
|
30
|
|
|
class Throttle {
|
|
31
|
|
|
|
|
32
|
|
|
/**
|
|
33
|
|
|
* @var \OCA\Security\Db\DbService $connection
|
|
34
|
|
|
*/
|
|
35
|
|
|
protected $dbConnection;
|
|
36
|
|
|
|
|
37
|
|
|
/**
|
|
38
|
|
|
* @param IDBConnection $dbConnection
|
|
39
|
|
|
*/
|
|
40
|
|
|
public function __construct($dbConnection) {
|
|
41
|
|
|
$this->dbConnection = $dbConnection;
|
|
|
|
|
|
|
42
|
|
|
}
|
|
43
|
|
|
|
|
44
|
|
|
/**
|
|
45
|
|
|
* @param string $uid
|
|
46
|
|
|
* @param string ip
|
|
47
|
|
|
* @return void
|
|
48
|
|
|
*/
|
|
49
|
|
|
public function addFailedLoginAttempt($uid, $ip) {
|
|
50
|
|
|
$this->dbConnection->addFailedLoginAttempt($uid, $ip);
|
|
51
|
|
|
}
|
|
52
|
|
|
|
|
53
|
|
|
/**
|
|
54
|
|
|
* @param string $uid
|
|
55
|
|
|
* @param string ip
|
|
56
|
|
|
* @return void
|
|
57
|
|
|
*/
|
|
58
|
|
|
public function putDelay($uid, $ip) {
|
|
|
|
|
|
|
59
|
|
|
//we determine appropriate delay time by using ip and username info
|
|
60
|
|
|
//initially it return count of failed attempts for ip
|
|
61
|
|
|
sleep($this->calculateDelayForIp($ip));
|
|
62
|
|
|
}
|
|
63
|
|
|
|
|
64
|
|
|
/**
|
|
65
|
|
|
* @param string $uid
|
|
66
|
|
|
* @return int
|
|
67
|
|
|
*/
|
|
68
|
|
|
public function calculateDelayForUid($uid) {
|
|
69
|
|
|
return $this->dbConnection->getSuspiciousActivityCountForUid($uid);
|
|
70
|
|
|
}
|
|
71
|
|
|
|
|
72
|
|
|
/**
|
|
73
|
|
|
* @param string ip
|
|
74
|
|
|
* @return int
|
|
75
|
|
|
*/
|
|
76
|
|
|
public function calculateDelayForIp($ip) {
|
|
77
|
|
|
return $this->dbConnection->getSuspiciousActivityCountForIp($ip);
|
|
78
|
|
|
}
|
|
79
|
|
|
|
|
80
|
|
|
/**
|
|
81
|
|
|
* @param string ip
|
|
82
|
|
|
* @return void
|
|
83
|
|
|
*/
|
|
84
|
|
|
public function clearSuspiciousAttemptsForIp($ip) {
|
|
85
|
|
|
$this->dbConnection->deleteSuspiciousAttemptsForIp($ip);
|
|
86
|
|
|
}
|
|
87
|
|
|
} |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..