Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 22 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
DisableOATHAuthForUser | |
0.00% |
0 / 16 |
|
0.00% |
0 / 2 |
30 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
execute | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
20 |
1 | <?php |
2 | |
3 | use MediaWiki\Extension\OATHAuth\OATHAuthServices; |
4 | use MediaWiki\Maintenance\Maintenance; |
5 | use MediaWiki\MediaWikiServices; |
6 | use MediaWiki\Session\SessionManager; |
7 | |
8 | if ( getenv( 'MW_INSTALL_PATH' ) ) { |
9 | $IP = getenv( 'MW_INSTALL_PATH' ); |
10 | } else { |
11 | $IP = __DIR__ . '/../../..'; |
12 | } |
13 | require_once "$IP/maintenance/Maintenance.php"; |
14 | |
15 | class DisableOATHAuthForUser extends Maintenance { |
16 | public function __construct() { |
17 | parent::__construct(); |
18 | $this->addDescription( 'Remove all two-factor authentication devices from a specific user' ); |
19 | $this->addArg( 'user', 'The username to remove 2FA devices from.' ); |
20 | $this->requireExtension( 'OATHAuth' ); |
21 | } |
22 | |
23 | public function execute() { |
24 | $username = $this->getArg( 0 ); |
25 | |
26 | $user = MediaWikiServices::getInstance()->getUserFactory() |
27 | ->newFromName( $username ); |
28 | if ( $user === null || $user->getId() === 0 ) { |
29 | $this->fatalError( "User $username doesn't exist!" ); |
30 | } |
31 | |
32 | $repo = OATHAuthServices::getInstance()->getUserRepository(); |
33 | $oathUser = $repo->findByUser( $user ); |
34 | if ( !$oathUser->isTwoFactorAuthEnabled() ) { |
35 | $this->fatalError( "User $username does not have two-factor authentication enabled!" ); |
36 | } |
37 | |
38 | $repo->removeAll( $oathUser, 'Maintenance script', false ); |
39 | // Kill all existing sessions. |
40 | // If this request to disable 2FA was social-engineered by an attacker, |
41 | // the legitimate user will hopefully log in again to the wiki, and notice that the second factor |
42 | // is missing or different, and alert the operators. |
43 | SessionManager::singleton()->invalidateSessionsForUser( $user ); |
44 | |
45 | $this->output( "Two-factor authentication disabled for $username.\n" ); |
46 | } |
47 | } |
48 | |
49 | $maintClass = DisableOATHAuthForUser::class; |
50 | require_once RUN_MAINTENANCE_IF_MAIN; |