Passed
Push — master ( cbde1d...e57bca )
by Morris
11:36 queued 11s
created
lib/private/Security/Bruteforce/Throttler.php 1 patch
Indentation   +259 added lines, -259 removed lines patch added patch discarded remove patch
@@ -49,263 +49,263 @@
 block discarded – undo
49 49
  * @package OC\Security\Bruteforce
50 50
  */
51 51
 class Throttler {
52
-	public const LOGIN_ACTION = 'login';
53
-
54
-	/** @var IDBConnection */
55
-	private $db;
56
-	/** @var ITimeFactory */
57
-	private $timeFactory;
58
-	/** @var ILogger */
59
-	private $logger;
60
-	/** @var IConfig */
61
-	private $config;
62
-
63
-	/**
64
-	 * @param IDBConnection $db
65
-	 * @param ITimeFactory $timeFactory
66
-	 * @param ILogger $logger
67
-	 * @param IConfig $config
68
-	 */
69
-	public function __construct(IDBConnection $db,
70
-								ITimeFactory $timeFactory,
71
-								ILogger $logger,
72
-								IConfig $config) {
73
-		$this->db = $db;
74
-		$this->timeFactory = $timeFactory;
75
-		$this->logger = $logger;
76
-		$this->config = $config;
77
-	}
78
-
79
-	/**
80
-	 * Convert a number of seconds into the appropriate DateInterval
81
-	 *
82
-	 * @param int $expire
83
-	 * @return \DateInterval
84
-	 */
85
-	private function getCutoff($expire) {
86
-		$d1 = new \DateTime();
87
-		$d2 = clone $d1;
88
-		$d2->sub(new \DateInterval('PT' . $expire . 'S'));
89
-		return $d2->diff($d1);
90
-	}
91
-
92
-	/**
93
-	 *  Calculate the cut off timestamp
94
-	 *
95
-	 * @return int
96
-	 */
97
-	private function getCutoffTimestamp(): int {
98
-		return (new \DateTime())
99
-			->sub($this->getCutoff(43200))
100
-			->getTimestamp();
101
-	}
102
-
103
-	/**
104
-	 * Register a failed attempt to bruteforce a security control
105
-	 *
106
-	 * @param string $action
107
-	 * @param string $ip
108
-	 * @param array $metadata Optional metadata logged to the database
109
-	 * @suppress SqlInjectionChecker
110
-	 */
111
-	public function registerAttempt($action,
112
-									$ip,
113
-									array $metadata = []) {
114
-		// No need to log if the bruteforce protection is disabled
115
-		if ($this->config->getSystemValue('auth.bruteforce.protection.enabled', true) === false) {
116
-			return;
117
-		}
118
-
119
-		$ipAddress = new IpAddress($ip);
120
-		$values = [
121
-			'action' => $action,
122
-			'occurred' => $this->timeFactory->getTime(),
123
-			'ip' => (string)$ipAddress,
124
-			'subnet' => $ipAddress->getSubnet(),
125
-			'metadata' => json_encode($metadata),
126
-		];
127
-
128
-		$this->logger->notice(
129
-			sprintf(
130
-				'Bruteforce attempt from "%s" detected for action "%s".',
131
-				$ip,
132
-				$action
133
-			),
134
-			[
135
-				'app' => 'core',
136
-			]
137
-		);
138
-
139
-		$qb = $this->db->getQueryBuilder();
140
-		$qb->insert('bruteforce_attempts');
141
-		foreach ($values as $column => $value) {
142
-			$qb->setValue($column, $qb->createNamedParameter($value));
143
-		}
144
-		$qb->execute();
145
-	}
146
-
147
-	/**
148
-	 * Check if the IP is whitelisted
149
-	 *
150
-	 * @param string $ip
151
-	 * @return bool
152
-	 */
153
-	private function isIPWhitelisted($ip) {
154
-		if ($this->config->getSystemValue('auth.bruteforce.protection.enabled', true) === false) {
155
-			return true;
156
-		}
157
-
158
-		$keys = $this->config->getAppKeys('bruteForce');
159
-		$keys = array_filter($keys, function ($key) {
160
-			$regex = '/^whitelist_/S';
161
-			return preg_match($regex, $key) === 1;
162
-		});
163
-
164
-		if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
165
-			$type = 4;
166
-		} elseif (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
167
-			$type = 6;
168
-		} else {
169
-			return false;
170
-		}
171
-
172
-		$ip = inet_pton($ip);
173
-
174
-		foreach ($keys as $key) {
175
-			$cidr = $this->config->getAppValue('bruteForce', $key, null);
176
-
177
-			$cx = explode('/', $cidr);
178
-			$addr = $cx[0];
179
-			$mask = (int)$cx[1];
180
-
181
-			// Do not compare ipv4 to ipv6
182
-			if (($type === 4 && !filter_var($addr, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) ||
183
-				($type === 6 && !filter_var($addr, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6))) {
184
-				continue;
185
-			}
186
-
187
-			$addr = inet_pton($addr);
188
-
189
-			$valid = true;
190
-			for ($i = 0; $i < $mask; $i++) {
191
-				$part = ord($addr[(int)($i/8)]);
192
-				$orig = ord($ip[(int)($i/8)]);
193
-
194
-				$bitmask = 1 << (7 - ($i % 8));
195
-
196
-				$part = $part & $bitmask;
197
-				$orig = $orig & $bitmask;
198
-
199
-				if ($part !== $orig) {
200
-					$valid = false;
201
-					break;
202
-				}
203
-			}
204
-
205
-			if ($valid === true) {
206
-				return true;
207
-			}
208
-		}
209
-
210
-		return false;
211
-	}
212
-
213
-	/**
214
-	 * Get the throttling delay (in milliseconds)
215
-	 *
216
-	 * @param string $ip
217
-	 * @param string $action optionally filter by action
218
-	 * @return int
219
-	 */
220
-	public function getDelay($ip, $action = '') {
221
-		$ipAddress = new IpAddress($ip);
222
-		if ($this->isIPWhitelisted((string)$ipAddress)) {
223
-			return 0;
224
-		}
225
-
226
-		$cutoffTime = $this->getCutoffTimestamp();
227
-
228
-		$qb = $this->db->getQueryBuilder();
229
-		$qb->select('*')
230
-			->from('bruteforce_attempts')
231
-			->where($qb->expr()->gt('occurred', $qb->createNamedParameter($cutoffTime)))
232
-			->andWhere($qb->expr()->eq('subnet', $qb->createNamedParameter($ipAddress->getSubnet())));
233
-
234
-		if ($action !== '') {
235
-			$qb->andWhere($qb->expr()->eq('action', $qb->createNamedParameter($action)));
236
-		}
237
-
238
-		$attempts = count($qb->execute()->fetchAll());
239
-
240
-		if ($attempts === 0) {
241
-			return 0;
242
-		}
243
-
244
-		$maxDelay = 25;
245
-		$firstDelay = 0.1;
246
-		if ($attempts > (8 * PHP_INT_SIZE - 1)) {
247
-			// Don't ever overflow. Just assume the maxDelay time:s
248
-			$firstDelay = $maxDelay;
249
-		} else {
250
-			$firstDelay *= pow(2, $attempts);
251
-			if ($firstDelay > $maxDelay) {
252
-				$firstDelay = $maxDelay;
253
-			}
254
-		}
255
-		return (int) \ceil($firstDelay * 1000);
256
-	}
257
-
258
-	/**
259
-	 * Reset the throttling delay for an IP address, action and metadata
260
-	 *
261
-	 * @param string $ip
262
-	 * @param string $action
263
-	 * @param string $metadata
264
-	 */
265
-	public function resetDelay($ip, $action, $metadata) {
266
-		$ipAddress = new IpAddress($ip);
267
-		if ($this->isIPWhitelisted((string)$ipAddress)) {
268
-			return;
269
-		}
270
-
271
-		$cutoffTime = $this->getCutoffTimestamp();
272
-
273
-		$qb = $this->db->getQueryBuilder();
274
-		$qb->delete('bruteforce_attempts')
275
-			->where($qb->expr()->gt('occurred', $qb->createNamedParameter($cutoffTime)))
276
-			->andWhere($qb->expr()->eq('subnet', $qb->createNamedParameter($ipAddress->getSubnet())))
277
-			->andWhere($qb->expr()->eq('action', $qb->createNamedParameter($action)))
278
-			->andWhere($qb->expr()->eq('metadata', $qb->createNamedParameter(json_encode($metadata))));
279
-
280
-		$qb->execute();
281
-	}
282
-
283
-	/**
284
-	 * Reset the throttling delay for an IP address
285
-	 *
286
-	 * @param string $ip
287
-	 */
288
-	public function resetDelayForIP($ip) {
289
-		$cutoffTime = $this->getCutoffTimestamp();
290
-
291
-		$qb = $this->db->getQueryBuilder();
292
-		$qb->delete('bruteforce_attempts')
293
-			->where($qb->expr()->gt('occurred', $qb->createNamedParameter($cutoffTime)))
294
-			->andWhere($qb->expr()->eq('ip', $qb->createNamedParameter($ip)));
295
-
296
-		$qb->execute();
297
-	}
298
-
299
-	/**
300
-	 * Will sleep for the defined amount of time
301
-	 *
302
-	 * @param string $ip
303
-	 * @param string $action optionally filter by action
304
-	 * @return int the time spent sleeping
305
-	 */
306
-	public function sleepDelay($ip, $action = '') {
307
-		$delay = $this->getDelay($ip, $action);
308
-		usleep($delay * 1000);
309
-		return $delay;
310
-	}
52
+    public const LOGIN_ACTION = 'login';
53
+
54
+    /** @var IDBConnection */
55
+    private $db;
56
+    /** @var ITimeFactory */
57
+    private $timeFactory;
58
+    /** @var ILogger */
59
+    private $logger;
60
+    /** @var IConfig */
61
+    private $config;
62
+
63
+    /**
64
+     * @param IDBConnection $db
65
+     * @param ITimeFactory $timeFactory
66
+     * @param ILogger $logger
67
+     * @param IConfig $config
68
+     */
69
+    public function __construct(IDBConnection $db,
70
+                                ITimeFactory $timeFactory,
71
+                                ILogger $logger,
72
+                                IConfig $config) {
73
+        $this->db = $db;
74
+        $this->timeFactory = $timeFactory;
75
+        $this->logger = $logger;
76
+        $this->config = $config;
77
+    }
78
+
79
+    /**
80
+     * Convert a number of seconds into the appropriate DateInterval
81
+     *
82
+     * @param int $expire
83
+     * @return \DateInterval
84
+     */
85
+    private function getCutoff($expire) {
86
+        $d1 = new \DateTime();
87
+        $d2 = clone $d1;
88
+        $d2->sub(new \DateInterval('PT' . $expire . 'S'));
89
+        return $d2->diff($d1);
90
+    }
91
+
92
+    /**
93
+     *  Calculate the cut off timestamp
94
+     *
95
+     * @return int
96
+     */
97
+    private function getCutoffTimestamp(): int {
98
+        return (new \DateTime())
99
+            ->sub($this->getCutoff(43200))
100
+            ->getTimestamp();
101
+    }
102
+
103
+    /**
104
+     * Register a failed attempt to bruteforce a security control
105
+     *
106
+     * @param string $action
107
+     * @param string $ip
108
+     * @param array $metadata Optional metadata logged to the database
109
+     * @suppress SqlInjectionChecker
110
+     */
111
+    public function registerAttempt($action,
112
+                                    $ip,
113
+                                    array $metadata = []) {
114
+        // No need to log if the bruteforce protection is disabled
115
+        if ($this->config->getSystemValue('auth.bruteforce.protection.enabled', true) === false) {
116
+            return;
117
+        }
118
+
119
+        $ipAddress = new IpAddress($ip);
120
+        $values = [
121
+            'action' => $action,
122
+            'occurred' => $this->timeFactory->getTime(),
123
+            'ip' => (string)$ipAddress,
124
+            'subnet' => $ipAddress->getSubnet(),
125
+            'metadata' => json_encode($metadata),
126
+        ];
127
+
128
+        $this->logger->notice(
129
+            sprintf(
130
+                'Bruteforce attempt from "%s" detected for action "%s".',
131
+                $ip,
132
+                $action
133
+            ),
134
+            [
135
+                'app' => 'core',
136
+            ]
137
+        );
138
+
139
+        $qb = $this->db->getQueryBuilder();
140
+        $qb->insert('bruteforce_attempts');
141
+        foreach ($values as $column => $value) {
142
+            $qb->setValue($column, $qb->createNamedParameter($value));
143
+        }
144
+        $qb->execute();
145
+    }
146
+
147
+    /**
148
+     * Check if the IP is whitelisted
149
+     *
150
+     * @param string $ip
151
+     * @return bool
152
+     */
153
+    private function isIPWhitelisted($ip) {
154
+        if ($this->config->getSystemValue('auth.bruteforce.protection.enabled', true) === false) {
155
+            return true;
156
+        }
157
+
158
+        $keys = $this->config->getAppKeys('bruteForce');
159
+        $keys = array_filter($keys, function ($key) {
160
+            $regex = '/^whitelist_/S';
161
+            return preg_match($regex, $key) === 1;
162
+        });
163
+
164
+        if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
165
+            $type = 4;
166
+        } elseif (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
167
+            $type = 6;
168
+        } else {
169
+            return false;
170
+        }
171
+
172
+        $ip = inet_pton($ip);
173
+
174
+        foreach ($keys as $key) {
175
+            $cidr = $this->config->getAppValue('bruteForce', $key, null);
176
+
177
+            $cx = explode('/', $cidr);
178
+            $addr = $cx[0];
179
+            $mask = (int)$cx[1];
180
+
181
+            // Do not compare ipv4 to ipv6
182
+            if (($type === 4 && !filter_var($addr, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) ||
183
+                ($type === 6 && !filter_var($addr, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6))) {
184
+                continue;
185
+            }
186
+
187
+            $addr = inet_pton($addr);
188
+
189
+            $valid = true;
190
+            for ($i = 0; $i < $mask; $i++) {
191
+                $part = ord($addr[(int)($i/8)]);
192
+                $orig = ord($ip[(int)($i/8)]);
193
+
194
+                $bitmask = 1 << (7 - ($i % 8));
195
+
196
+                $part = $part & $bitmask;
197
+                $orig = $orig & $bitmask;
198
+
199
+                if ($part !== $orig) {
200
+                    $valid = false;
201
+                    break;
202
+                }
203
+            }
204
+
205
+            if ($valid === true) {
206
+                return true;
207
+            }
208
+        }
209
+
210
+        return false;
211
+    }
212
+
213
+    /**
214
+     * Get the throttling delay (in milliseconds)
215
+     *
216
+     * @param string $ip
217
+     * @param string $action optionally filter by action
218
+     * @return int
219
+     */
220
+    public function getDelay($ip, $action = '') {
221
+        $ipAddress = new IpAddress($ip);
222
+        if ($this->isIPWhitelisted((string)$ipAddress)) {
223
+            return 0;
224
+        }
225
+
226
+        $cutoffTime = $this->getCutoffTimestamp();
227
+
228
+        $qb = $this->db->getQueryBuilder();
229
+        $qb->select('*')
230
+            ->from('bruteforce_attempts')
231
+            ->where($qb->expr()->gt('occurred', $qb->createNamedParameter($cutoffTime)))
232
+            ->andWhere($qb->expr()->eq('subnet', $qb->createNamedParameter($ipAddress->getSubnet())));
233
+
234
+        if ($action !== '') {
235
+            $qb->andWhere($qb->expr()->eq('action', $qb->createNamedParameter($action)));
236
+        }
237
+
238
+        $attempts = count($qb->execute()->fetchAll());
239
+
240
+        if ($attempts === 0) {
241
+            return 0;
242
+        }
243
+
244
+        $maxDelay = 25;
245
+        $firstDelay = 0.1;
246
+        if ($attempts > (8 * PHP_INT_SIZE - 1)) {
247
+            // Don't ever overflow. Just assume the maxDelay time:s
248
+            $firstDelay = $maxDelay;
249
+        } else {
250
+            $firstDelay *= pow(2, $attempts);
251
+            if ($firstDelay > $maxDelay) {
252
+                $firstDelay = $maxDelay;
253
+            }
254
+        }
255
+        return (int) \ceil($firstDelay * 1000);
256
+    }
257
+
258
+    /**
259
+     * Reset the throttling delay for an IP address, action and metadata
260
+     *
261
+     * @param string $ip
262
+     * @param string $action
263
+     * @param string $metadata
264
+     */
265
+    public function resetDelay($ip, $action, $metadata) {
266
+        $ipAddress = new IpAddress($ip);
267
+        if ($this->isIPWhitelisted((string)$ipAddress)) {
268
+            return;
269
+        }
270
+
271
+        $cutoffTime = $this->getCutoffTimestamp();
272
+
273
+        $qb = $this->db->getQueryBuilder();
274
+        $qb->delete('bruteforce_attempts')
275
+            ->where($qb->expr()->gt('occurred', $qb->createNamedParameter($cutoffTime)))
276
+            ->andWhere($qb->expr()->eq('subnet', $qb->createNamedParameter($ipAddress->getSubnet())))
277
+            ->andWhere($qb->expr()->eq('action', $qb->createNamedParameter($action)))
278
+            ->andWhere($qb->expr()->eq('metadata', $qb->createNamedParameter(json_encode($metadata))));
279
+
280
+        $qb->execute();
281
+    }
282
+
283
+    /**
284
+     * Reset the throttling delay for an IP address
285
+     *
286
+     * @param string $ip
287
+     */
288
+    public function resetDelayForIP($ip) {
289
+        $cutoffTime = $this->getCutoffTimestamp();
290
+
291
+        $qb = $this->db->getQueryBuilder();
292
+        $qb->delete('bruteforce_attempts')
293
+            ->where($qb->expr()->gt('occurred', $qb->createNamedParameter($cutoffTime)))
294
+            ->andWhere($qb->expr()->eq('ip', $qb->createNamedParameter($ip)));
295
+
296
+        $qb->execute();
297
+    }
298
+
299
+    /**
300
+     * Will sleep for the defined amount of time
301
+     *
302
+     * @param string $ip
303
+     * @param string $action optionally filter by action
304
+     * @return int the time spent sleeping
305
+     */
306
+    public function sleepDelay($ip, $action = '') {
307
+        $delay = $this->getDelay($ip, $action);
308
+        usleep($delay * 1000);
309
+        return $delay;
310
+    }
311 311
 }
Please login to merge, or discard this patch.
core/register_command.php 1 patch
Indentation   +118 added lines, -118 removed lines patch added patch discarded remove patch
@@ -49,133 +49,133 @@
 block discarded – undo
49 49
 $application->add(new OC\Core\Command\App\CheckCode());
50 50
 $application->add(new OC\Core\Command\L10n\CreateJs());
51 51
 $application->add(new \OC\Core\Command\Integrity\SignApp(
52
-		\OC::$server->getIntegrityCodeChecker(),
53
-		new \OC\IntegrityCheck\Helpers\FileAccessHelper(),
54
-		\OC::$server->getURLGenerator()
52
+        \OC::$server->getIntegrityCodeChecker(),
53
+        new \OC\IntegrityCheck\Helpers\FileAccessHelper(),
54
+        \OC::$server->getURLGenerator()
55 55
 ));
56 56
 $application->add(new \OC\Core\Command\Integrity\SignCore(
57
-		\OC::$server->getIntegrityCodeChecker(),
58
-		new \OC\IntegrityCheck\Helpers\FileAccessHelper()
57
+        \OC::$server->getIntegrityCodeChecker(),
58
+        new \OC\IntegrityCheck\Helpers\FileAccessHelper()
59 59
 ));
60 60
 $application->add(new \OC\Core\Command\Integrity\CheckApp(
61
-		\OC::$server->getIntegrityCodeChecker()
61
+        \OC::$server->getIntegrityCodeChecker()
62 62
 ));
63 63
 $application->add(new \OC\Core\Command\Integrity\CheckCore(
64
-		\OC::$server->getIntegrityCodeChecker()
64
+        \OC::$server->getIntegrityCodeChecker()
65 65
 ));
66 66
 
67 67
 
68 68
 if (\OC::$server->getConfig()->getSystemValue('installed', false)) {
69
-	$application->add(new OC\Core\Command\App\Disable(\OC::$server->getAppManager()));
70
-	$application->add(new OC\Core\Command\App\Enable(\OC::$server->getAppManager(), \OC::$server->getGroupManager()));
71
-	$application->add(new OC\Core\Command\App\Install());
72
-	$application->add(new OC\Core\Command\App\GetPath());
73
-	$application->add(new OC\Core\Command\App\ListApps(\OC::$server->getAppManager()));
74
-	$application->add(new OC\Core\Command\App\Remove(\OC::$server->getAppManager(), \OC::$server->query(\OC\Installer::class), \OC::$server->getLogger()));
75
-	$application->add(\OC::$server->query(\OC\Core\Command\App\Update::class));
76
-
77
-	$application->add(\OC::$server->query(\OC\Core\Command\TwoFactorAuth\Cleanup::class));
78
-	$application->add(\OC::$server->query(\OC\Core\Command\TwoFactorAuth\Enforce::class));
79
-	$application->add(\OC::$server->query(\OC\Core\Command\TwoFactorAuth\Enable::class));
80
-	$application->add(\OC::$server->query(\OC\Core\Command\TwoFactorAuth\Disable::class));
81
-	$application->add(\OC::$server->query(\OC\Core\Command\TwoFactorAuth\State::class));
82
-
83
-	$application->add(new OC\Core\Command\Background\Cron(\OC::$server->getConfig()));
84
-	$application->add(new OC\Core\Command\Background\WebCron(\OC::$server->getConfig()));
85
-	$application->add(new OC\Core\Command\Background\Ajax(\OC::$server->getConfig()));
86
-
87
-	$application->add(\OC::$server->query(\OC\Core\Command\Broadcast\Test::class));
88
-
89
-	$application->add(new OC\Core\Command\Config\App\DeleteConfig(\OC::$server->getConfig()));
90
-	$application->add(new OC\Core\Command\Config\App\GetConfig(\OC::$server->getConfig()));
91
-	$application->add(new OC\Core\Command\Config\App\SetConfig(\OC::$server->getConfig()));
92
-	$application->add(new OC\Core\Command\Config\Import(\OC::$server->getConfig()));
93
-	$application->add(new OC\Core\Command\Config\ListConfigs(\OC::$server->getSystemConfig(), \OC::$server->getAppConfig()));
94
-	$application->add(new OC\Core\Command\Config\System\DeleteConfig(\OC::$server->getSystemConfig()));
95
-	$application->add(new OC\Core\Command\Config\System\GetConfig(\OC::$server->getSystemConfig()));
96
-	$application->add(new OC\Core\Command\Config\System\SetConfig(\OC::$server->getSystemConfig()));
97
-
98
-	$application->add(new OC\Core\Command\Db\ConvertType(\OC::$server->getConfig(), new \OC\DB\ConnectionFactory(\OC::$server->getSystemConfig())));
99
-	$application->add(new OC\Core\Command\Db\ConvertMysqlToMB4(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection(), \OC::$server->getURLGenerator(), \OC::$server->getLogger()));
100
-	$application->add(new OC\Core\Command\Db\ConvertFilecacheBigInt(\OC::$server->getDatabaseConnection()));
101
-	$application->add(new OC\Core\Command\Db\AddMissingIndices(\OC::$server->getDatabaseConnection(), \OC::$server->getEventDispatcher()));
102
-	$application->add(new OC\Core\Command\Db\AddMissingColumns(\OC::$server->getDatabaseConnection(), \OC::$server->getEventDispatcher()));
103
-	$application->add(new OC\Core\Command\Db\Migrations\StatusCommand(\OC::$server->getDatabaseConnection()));
104
-	$application->add(new OC\Core\Command\Db\Migrations\MigrateCommand(\OC::$server->getDatabaseConnection()));
105
-	$application->add(new OC\Core\Command\Db\Migrations\GenerateCommand(\OC::$server->getDatabaseConnection(), \OC::$server->getAppManager()));
106
-	$application->add(new OC\Core\Command\Db\Migrations\GenerateFromSchemaFileCommand(\OC::$server->getConfig(), \OC::$server->getAppManager(), \OC::$server->getDatabaseConnection()));
107
-	$application->add(new OC\Core\Command\Db\Migrations\ExecuteCommand(\OC::$server->getDatabaseConnection(), \OC::$server->getAppManager(), \OC::$server->getConfig()));
108
-
109
-	$application->add(new OC\Core\Command\Encryption\Disable(\OC::$server->getConfig()));
110
-	$application->add(new OC\Core\Command\Encryption\Enable(\OC::$server->getConfig(), \OC::$server->getEncryptionManager()));
111
-	$application->add(new OC\Core\Command\Encryption\ListModules(\OC::$server->getEncryptionManager(), \OC::$server->getConfig()));
112
-	$application->add(new OC\Core\Command\Encryption\SetDefaultModule(\OC::$server->getEncryptionManager(), \OC::$server->getConfig()));
113
-	$application->add(new OC\Core\Command\Encryption\Status(\OC::$server->getEncryptionManager()));
114
-	$application->add(new OC\Core\Command\Encryption\EncryptAll(\OC::$server->getEncryptionManager(), \OC::$server->getAppManager(), \OC::$server->getConfig(), new \Symfony\Component\Console\Helper\QuestionHelper()));
115
-	$application->add(new OC\Core\Command\Encryption\DecryptAll(
116
-		\OC::$server->getEncryptionManager(),
117
-		\OC::$server->getAppManager(),
118
-		\OC::$server->getConfig(),
119
-		new \OC\Encryption\DecryptAll(\OC::$server->getEncryptionManager(), \OC::$server->getUserManager(), new \OC\Files\View()),
120
-		new \Symfony\Component\Console\Helper\QuestionHelper())
121
-	);
122
-
123
-	$application->add(new OC\Core\Command\Log\Manage(\OC::$server->getConfig()));
124
-	$application->add(new OC\Core\Command\Log\File(\OC::$server->getConfig()));
125
-
126
-	$view = new \OC\Files\View();
127
-	$util = new \OC\Encryption\Util(
128
-		$view,
129
-		\OC::$server->getUserManager(),
130
-		\OC::$server->getGroupManager(),
131
-		\OC::$server->getConfig()
132
-	);
133
-	$application->add(new OC\Core\Command\Encryption\ChangeKeyStorageRoot(
134
-			$view,
135
-			\OC::$server->getUserManager(),
136
-			\OC::$server->getConfig(),
137
-			$util,
138
-			new \Symfony\Component\Console\Helper\QuestionHelper()
139
-		)
140
-	);
141
-	$application->add(new OC\Core\Command\Encryption\ShowKeyStorageRoot($util));
142
-
143
-	$application->add(new OC\Core\Command\Maintenance\DataFingerprint(\OC::$server->getConfig(), new \OC\AppFramework\Utility\TimeFactory()));
144
-	$application->add(new OC\Core\Command\Maintenance\Mimetype\UpdateDB(\OC::$server->getMimeTypeDetector(), \OC::$server->getMimeTypeLoader()));
145
-	$application->add(new OC\Core\Command\Maintenance\Mimetype\UpdateJS(\OC::$server->getMimeTypeDetector()));
146
-	$application->add(new OC\Core\Command\Maintenance\Mode(\OC::$server->getConfig()));
147
-	$application->add(new OC\Core\Command\Maintenance\UpdateHtaccess());
148
-	$application->add(new OC\Core\Command\Maintenance\UpdateTheme(\OC::$server->getMimeTypeDetector(), \OC::$server->getMemCacheFactory()));
149
-
150
-	$application->add(new OC\Core\Command\Upgrade(\OC::$server->getConfig(), \OC::$server->getLogger(), \OC::$server->query(\OC\Installer::class)));
151
-	$application->add(new OC\Core\Command\Maintenance\Repair(
152
-		new \OC\Repair([], \OC::$server->getEventDispatcher()),
153
-		\OC::$server->getConfig(),
154
-		\OC::$server->getEventDispatcher(),
155
-		\OC::$server->getAppManager()
156
-	));
157
-
158
-	$application->add(new OC\Core\Command\User\Add(\OC::$server->getUserManager(), \OC::$server->getGroupManager()));
159
-	$application->add(new OC\Core\Command\User\Delete(\OC::$server->getUserManager()));
160
-	$application->add(new OC\Core\Command\User\Disable(\OC::$server->getUserManager()));
161
-	$application->add(new OC\Core\Command\User\Enable(\OC::$server->getUserManager()));
162
-	$application->add(new OC\Core\Command\User\LastSeen(\OC::$server->getUserManager()));
163
-	$application->add(new OC\Core\Command\User\Report(\OC::$server->getUserManager()));
164
-	$application->add(new OC\Core\Command\User\ResetPassword(\OC::$server->getUserManager()));
165
-	$application->add(new OC\Core\Command\User\Setting(\OC::$server->getUserManager(), \OC::$server->getConfig(), \OC::$server->getDatabaseConnection()));
166
-	$application->add(new OC\Core\Command\User\ListCommand(\OC::$server->getUserManager(), \OC::$server->getGroupManager()));
167
-	$application->add(new OC\Core\Command\User\Info(\OC::$server->getUserManager(), \OC::$server->getGroupManager()));
168
-
169
-	$application->add(new OC\Core\Command\Group\Add(\OC::$server->getGroupManager()));
170
-	$application->add(new OC\Core\Command\Group\Delete(\OC::$server->getGroupManager()));
171
-	$application->add(new OC\Core\Command\Group\ListCommand(\OC::$server->getGroupManager()));
172
-	$application->add(new OC\Core\Command\Group\AddUser(\OC::$server->getUserManager(), \OC::$server->getGroupManager()));
173
-	$application->add(new OC\Core\Command\Group\RemoveUser(\OC::$server->getUserManager(), \OC::$server->getGroupManager()));
174
-
175
-	$application->add(new OC\Core\Command\Security\ListCertificates(\OC::$server->getCertificateManager(null), \OC::$server->getL10N('core')));
176
-	$application->add(new OC\Core\Command\Security\ImportCertificate(\OC::$server->getCertificateManager(null)));
177
-	$application->add(new OC\Core\Command\Security\RemoveCertificate(\OC::$server->getCertificateManager(null)));
178
-	$application->add(new OC\Core\Command\Security\ResetBruteforceAttempts(\OC::$server->getBruteForceThrottler()));
69
+    $application->add(new OC\Core\Command\App\Disable(\OC::$server->getAppManager()));
70
+    $application->add(new OC\Core\Command\App\Enable(\OC::$server->getAppManager(), \OC::$server->getGroupManager()));
71
+    $application->add(new OC\Core\Command\App\Install());
72
+    $application->add(new OC\Core\Command\App\GetPath());
73
+    $application->add(new OC\Core\Command\App\ListApps(\OC::$server->getAppManager()));
74
+    $application->add(new OC\Core\Command\App\Remove(\OC::$server->getAppManager(), \OC::$server->query(\OC\Installer::class), \OC::$server->getLogger()));
75
+    $application->add(\OC::$server->query(\OC\Core\Command\App\Update::class));
76
+
77
+    $application->add(\OC::$server->query(\OC\Core\Command\TwoFactorAuth\Cleanup::class));
78
+    $application->add(\OC::$server->query(\OC\Core\Command\TwoFactorAuth\Enforce::class));
79
+    $application->add(\OC::$server->query(\OC\Core\Command\TwoFactorAuth\Enable::class));
80
+    $application->add(\OC::$server->query(\OC\Core\Command\TwoFactorAuth\Disable::class));
81
+    $application->add(\OC::$server->query(\OC\Core\Command\TwoFactorAuth\State::class));
82
+
83
+    $application->add(new OC\Core\Command\Background\Cron(\OC::$server->getConfig()));
84
+    $application->add(new OC\Core\Command\Background\WebCron(\OC::$server->getConfig()));
85
+    $application->add(new OC\Core\Command\Background\Ajax(\OC::$server->getConfig()));
86
+
87
+    $application->add(\OC::$server->query(\OC\Core\Command\Broadcast\Test::class));
88
+
89
+    $application->add(new OC\Core\Command\Config\App\DeleteConfig(\OC::$server->getConfig()));
90
+    $application->add(new OC\Core\Command\Config\App\GetConfig(\OC::$server->getConfig()));
91
+    $application->add(new OC\Core\Command\Config\App\SetConfig(\OC::$server->getConfig()));
92
+    $application->add(new OC\Core\Command\Config\Import(\OC::$server->getConfig()));
93
+    $application->add(new OC\Core\Command\Config\ListConfigs(\OC::$server->getSystemConfig(), \OC::$server->getAppConfig()));
94
+    $application->add(new OC\Core\Command\Config\System\DeleteConfig(\OC::$server->getSystemConfig()));
95
+    $application->add(new OC\Core\Command\Config\System\GetConfig(\OC::$server->getSystemConfig()));
96
+    $application->add(new OC\Core\Command\Config\System\SetConfig(\OC::$server->getSystemConfig()));
97
+
98
+    $application->add(new OC\Core\Command\Db\ConvertType(\OC::$server->getConfig(), new \OC\DB\ConnectionFactory(\OC::$server->getSystemConfig())));
99
+    $application->add(new OC\Core\Command\Db\ConvertMysqlToMB4(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection(), \OC::$server->getURLGenerator(), \OC::$server->getLogger()));
100
+    $application->add(new OC\Core\Command\Db\ConvertFilecacheBigInt(\OC::$server->getDatabaseConnection()));
101
+    $application->add(new OC\Core\Command\Db\AddMissingIndices(\OC::$server->getDatabaseConnection(), \OC::$server->getEventDispatcher()));
102
+    $application->add(new OC\Core\Command\Db\AddMissingColumns(\OC::$server->getDatabaseConnection(), \OC::$server->getEventDispatcher()));
103
+    $application->add(new OC\Core\Command\Db\Migrations\StatusCommand(\OC::$server->getDatabaseConnection()));
104
+    $application->add(new OC\Core\Command\Db\Migrations\MigrateCommand(\OC::$server->getDatabaseConnection()));
105
+    $application->add(new OC\Core\Command\Db\Migrations\GenerateCommand(\OC::$server->getDatabaseConnection(), \OC::$server->getAppManager()));
106
+    $application->add(new OC\Core\Command\Db\Migrations\GenerateFromSchemaFileCommand(\OC::$server->getConfig(), \OC::$server->getAppManager(), \OC::$server->getDatabaseConnection()));
107
+    $application->add(new OC\Core\Command\Db\Migrations\ExecuteCommand(\OC::$server->getDatabaseConnection(), \OC::$server->getAppManager(), \OC::$server->getConfig()));
108
+
109
+    $application->add(new OC\Core\Command\Encryption\Disable(\OC::$server->getConfig()));
110
+    $application->add(new OC\Core\Command\Encryption\Enable(\OC::$server->getConfig(), \OC::$server->getEncryptionManager()));
111
+    $application->add(new OC\Core\Command\Encryption\ListModules(\OC::$server->getEncryptionManager(), \OC::$server->getConfig()));
112
+    $application->add(new OC\Core\Command\Encryption\SetDefaultModule(\OC::$server->getEncryptionManager(), \OC::$server->getConfig()));
113
+    $application->add(new OC\Core\Command\Encryption\Status(\OC::$server->getEncryptionManager()));
114
+    $application->add(new OC\Core\Command\Encryption\EncryptAll(\OC::$server->getEncryptionManager(), \OC::$server->getAppManager(), \OC::$server->getConfig(), new \Symfony\Component\Console\Helper\QuestionHelper()));
115
+    $application->add(new OC\Core\Command\Encryption\DecryptAll(
116
+        \OC::$server->getEncryptionManager(),
117
+        \OC::$server->getAppManager(),
118
+        \OC::$server->getConfig(),
119
+        new \OC\Encryption\DecryptAll(\OC::$server->getEncryptionManager(), \OC::$server->getUserManager(), new \OC\Files\View()),
120
+        new \Symfony\Component\Console\Helper\QuestionHelper())
121
+    );
122
+
123
+    $application->add(new OC\Core\Command\Log\Manage(\OC::$server->getConfig()));
124
+    $application->add(new OC\Core\Command\Log\File(\OC::$server->getConfig()));
125
+
126
+    $view = new \OC\Files\View();
127
+    $util = new \OC\Encryption\Util(
128
+        $view,
129
+        \OC::$server->getUserManager(),
130
+        \OC::$server->getGroupManager(),
131
+        \OC::$server->getConfig()
132
+    );
133
+    $application->add(new OC\Core\Command\Encryption\ChangeKeyStorageRoot(
134
+            $view,
135
+            \OC::$server->getUserManager(),
136
+            \OC::$server->getConfig(),
137
+            $util,
138
+            new \Symfony\Component\Console\Helper\QuestionHelper()
139
+        )
140
+    );
141
+    $application->add(new OC\Core\Command\Encryption\ShowKeyStorageRoot($util));
142
+
143
+    $application->add(new OC\Core\Command\Maintenance\DataFingerprint(\OC::$server->getConfig(), new \OC\AppFramework\Utility\TimeFactory()));
144
+    $application->add(new OC\Core\Command\Maintenance\Mimetype\UpdateDB(\OC::$server->getMimeTypeDetector(), \OC::$server->getMimeTypeLoader()));
145
+    $application->add(new OC\Core\Command\Maintenance\Mimetype\UpdateJS(\OC::$server->getMimeTypeDetector()));
146
+    $application->add(new OC\Core\Command\Maintenance\Mode(\OC::$server->getConfig()));
147
+    $application->add(new OC\Core\Command\Maintenance\UpdateHtaccess());
148
+    $application->add(new OC\Core\Command\Maintenance\UpdateTheme(\OC::$server->getMimeTypeDetector(), \OC::$server->getMemCacheFactory()));
149
+
150
+    $application->add(new OC\Core\Command\Upgrade(\OC::$server->getConfig(), \OC::$server->getLogger(), \OC::$server->query(\OC\Installer::class)));
151
+    $application->add(new OC\Core\Command\Maintenance\Repair(
152
+        new \OC\Repair([], \OC::$server->getEventDispatcher()),
153
+        \OC::$server->getConfig(),
154
+        \OC::$server->getEventDispatcher(),
155
+        \OC::$server->getAppManager()
156
+    ));
157
+
158
+    $application->add(new OC\Core\Command\User\Add(\OC::$server->getUserManager(), \OC::$server->getGroupManager()));
159
+    $application->add(new OC\Core\Command\User\Delete(\OC::$server->getUserManager()));
160
+    $application->add(new OC\Core\Command\User\Disable(\OC::$server->getUserManager()));
161
+    $application->add(new OC\Core\Command\User\Enable(\OC::$server->getUserManager()));
162
+    $application->add(new OC\Core\Command\User\LastSeen(\OC::$server->getUserManager()));
163
+    $application->add(new OC\Core\Command\User\Report(\OC::$server->getUserManager()));
164
+    $application->add(new OC\Core\Command\User\ResetPassword(\OC::$server->getUserManager()));
165
+    $application->add(new OC\Core\Command\User\Setting(\OC::$server->getUserManager(), \OC::$server->getConfig(), \OC::$server->getDatabaseConnection()));
166
+    $application->add(new OC\Core\Command\User\ListCommand(\OC::$server->getUserManager(), \OC::$server->getGroupManager()));
167
+    $application->add(new OC\Core\Command\User\Info(\OC::$server->getUserManager(), \OC::$server->getGroupManager()));
168
+
169
+    $application->add(new OC\Core\Command\Group\Add(\OC::$server->getGroupManager()));
170
+    $application->add(new OC\Core\Command\Group\Delete(\OC::$server->getGroupManager()));
171
+    $application->add(new OC\Core\Command\Group\ListCommand(\OC::$server->getGroupManager()));
172
+    $application->add(new OC\Core\Command\Group\AddUser(\OC::$server->getUserManager(), \OC::$server->getGroupManager()));
173
+    $application->add(new OC\Core\Command\Group\RemoveUser(\OC::$server->getUserManager(), \OC::$server->getGroupManager()));
174
+
175
+    $application->add(new OC\Core\Command\Security\ListCertificates(\OC::$server->getCertificateManager(null), \OC::$server->getL10N('core')));
176
+    $application->add(new OC\Core\Command\Security\ImportCertificate(\OC::$server->getCertificateManager(null)));
177
+    $application->add(new OC\Core\Command\Security\RemoveCertificate(\OC::$server->getCertificateManager(null)));
178
+    $application->add(new OC\Core\Command\Security\ResetBruteforceAttempts(\OC::$server->getBruteForceThrottler()));
179 179
 } else {
180
-	$application->add(new OC\Core\Command\Maintenance\Install(\OC::$server->getSystemConfig()));
180
+    $application->add(new OC\Core\Command\Maintenance\Install(\OC::$server->getSystemConfig()));
181 181
 }
Please login to merge, or discard this patch.
core/Command/Security/ResetBruteforceAttempts.php 2 patches
Indentation   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -30,33 +30,33 @@
 block discarded – undo
30 30
 
31 31
 class ResetBruteforceAttempts extends Base {
32 32
 
33
-	/** @var Throttler */
34
-	protected $throttler;
35
-
36
-	public function __construct(Throttler $throttler) {
37
-		$this->throttler = $throttler;
38
-		parent::__construct();
39
-	}
40
-
41
-	protected function configure() {
42
-		$this
43
-			->setName('security:bruteforce:reset')
44
-			->setDescription('resets bruteforce attemps for given IP address')
45
-			->addArgument(
46
-				'ipaddress',
47
-				InputArgument::REQUIRED,
48
-				'IP address for which the attempts are to be reset'
49
-			);
50
-	}
51
-
52
-	protected function execute(InputInterface $input, OutputInterface $output) {
53
-		$ip = $input->getArgument('ipaddress');
54
-
55
-		if (!filter_var($ip, FILTER_VALIDATE_IP)) {
56
-			$output->writeln('<error>"' . $ip . '" is not a valid IP address</error>');
57
-			return 1;
58
-		}
59
-
60
-		$this->throttler->resetDelayForIP($ip);
61
-	}
33
+    /** @var Throttler */
34
+    protected $throttler;
35
+
36
+    public function __construct(Throttler $throttler) {
37
+        $this->throttler = $throttler;
38
+        parent::__construct();
39
+    }
40
+
41
+    protected function configure() {
42
+        $this
43
+            ->setName('security:bruteforce:reset')
44
+            ->setDescription('resets bruteforce attemps for given IP address')
45
+            ->addArgument(
46
+                'ipaddress',
47
+                InputArgument::REQUIRED,
48
+                'IP address for which the attempts are to be reset'
49
+            );
50
+    }
51
+
52
+    protected function execute(InputInterface $input, OutputInterface $output) {
53
+        $ip = $input->getArgument('ipaddress');
54
+
55
+        if (!filter_var($ip, FILTER_VALIDATE_IP)) {
56
+            $output->writeln('<error>"' . $ip . '" is not a valid IP address</error>');
57
+            return 1;
58
+        }
59
+
60
+        $this->throttler->resetDelayForIP($ip);
61
+    }
62 62
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -53,7 +53,7 @@
 block discarded – undo
53 53
 		$ip = $input->getArgument('ipaddress');
54 54
 
55 55
 		if (!filter_var($ip, FILTER_VALIDATE_IP)) {
56
-			$output->writeln('<error>"' . $ip . '" is not a valid IP address</error>');
56
+			$output->writeln('<error>"'.$ip.'" is not a valid IP address</error>');
57 57
 			return 1;
58 58
 		}
59 59
 
Please login to merge, or discard this patch.