MediaWiki  1.34.0
disableOATHAuthForUser.php
Go to the documentation of this file.
1 <?php
2 
6 
7 if ( getenv( 'MW_INSTALL_PATH' ) ) {
8  $IP = getenv( 'MW_INSTALL_PATH' );
9 } else {
10  $IP = __DIR__ . '/../../..';
11 }
12 require_once "$IP/maintenance/Maintenance.php";
13 
15  public function __construct() {
16  parent::__construct();
17  $this->addDescription( 'Remove OATHAuth from a specific user' );
18  $this->addArg( 'user', 'The username to remove OATHAuth from.' );
19  $this->requireExtension( 'OATHAuth' );
20  }
21 
22  public function execute() {
23  $username = $this->getArg( 0 );
24 
25  $user = User::newFromName( $username );
26  if ( $user && $user->getId() === 0 ) {
27  $this->error( "User $username doesn't exist!", 1 );
28  }
29 
30  $repo = MediaWikiServices::getInstance()->getService( 'OATHUserRepository' );
31  $oathUser = $repo->findByUser( $user );
32  $module = $oathUser->getModule();
33  if ( !( $module instanceof IModule ) || $module->isEnabled( $oathUser ) === false ) {
34  $this->error( "User $username doesn't have OATHAuth enabled!", 1 );
35  }
36 
37  $repo->remove( $oathUser, 'Maintenance script' );
38  // Kill all existing sessions. If this disable was social-engineered by an attacker,
39  // the legitimate user will hopefully login again and notice that the second factor
40  // is missing or different, and alert the operators.
41  SessionManager::singleton()->invalidateSessionsForUser( $user );
42 
43  $this->output( "OATHAuth disabled for $username.\n" );
44  }
45 }
46 
47 $maintClass = DisableOATHAuthForUser::class;
48 require_once RUN_MAINTENANCE_IF_MAIN;
RUN_MAINTENANCE_IF_MAIN
const RUN_MAINTENANCE_IF_MAIN
Definition: Maintenance.php:39
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:117
Maintenance\addDescription
addDescription( $text)
Set the description text.
Definition: Maintenance.php:348
User\newFromName
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
Definition: User.php:515
Maintenance
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition: Maintenance.php:82
$maintClass
$maintClass
Definition: disableOATHAuthForUser.php:47
DisableOATHAuthForUser\execute
execute()
Do the actual work.
Definition: disableOATHAuthForUser.php:22
DisableOATHAuthForUser
Definition: disableOATHAuthForUser.php:14
$IP
$IP
Definition: update.php:3
Maintenance\requireExtension
requireExtension( $name)
Indicate that the specified extension must be loaded before the script can run.
Definition: Maintenance.php:638
MediaWiki\Session\SessionManager
This serves as the entry point to the MediaWiki session handling system.
Definition: SessionManager.php:50
DisableOATHAuthForUser\__construct
__construct()
Default constructor.
Definition: disableOATHAuthForUser.php:15
Maintenance\addArg
addArg( $arg, $description, $required=true)
Add some args that are needed.
Definition: Maintenance.php:319
Maintenance\error
error( $err, $die=0)
Throw an error to the user.
Definition: Maintenance.php:481
Maintenance\output
output( $out, $channel=null)
Throw some output to the user.
Definition: Maintenance.php:453
Maintenance\getArg
getArg( $argId=0, $default=null)
Get an argument.
Definition: Maintenance.php:371
MediaWiki\Extension\OATHAuth\IModule
Definition: IModule.php:9