2017-06-16 21:21:18 +00:00
|
|
|
<?php
|
|
|
|
|
2018-11-21 03:55:17 +00:00
|
|
|
use MediaWiki\Session\SessionManager;
|
2019-03-14 14:39:10 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
|
|
|
use MediaWiki\Extension\OATHAuth\IModule;
|
2018-11-21 03:55:17 +00:00
|
|
|
|
2017-06-16 21:21:18 +00:00
|
|
|
if ( getenv( 'MW_INSTALL_PATH' ) ) {
|
|
|
|
$IP = getenv( 'MW_INSTALL_PATH' );
|
|
|
|
} else {
|
2017-08-11 04:08:50 +00:00
|
|
|
$IP = __DIR__ . '/../../..';
|
2017-06-16 21:21:18 +00:00
|
|
|
}
|
|
|
|
require_once "$IP/maintenance/Maintenance.php";
|
|
|
|
|
|
|
|
class DisableOATHAuthForUser extends Maintenance {
|
2018-11-02 10:26:41 +00:00
|
|
|
public function __construct() {
|
2017-06-16 21:21:18 +00:00
|
|
|
parent::__construct();
|
|
|
|
$this->mDescription = 'Remove OATHAuth from a specific user';
|
|
|
|
$this->addArg( 'user', 'The username to remove OATHAuth from.' );
|
|
|
|
$this->requireExtension( 'OATHAuth' );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function execute() {
|
|
|
|
$username = $this->getArg( 0 );
|
|
|
|
|
|
|
|
$user = User::newFromName( $username );
|
|
|
|
if ( $user && $user->getId() === 0 ) {
|
|
|
|
$this->error( "User $username doesn't exist!", 1 );
|
|
|
|
}
|
|
|
|
|
2019-03-14 14:39:10 +00:00
|
|
|
$repo = MediaWikiServices::getInstance()->getService( 'OATHUserRepository' );
|
2017-06-16 21:21:18 +00:00
|
|
|
$oathUser = $repo->findByUser( $user );
|
2019-03-14 14:39:10 +00:00
|
|
|
$module = $oathUser->getModule();
|
|
|
|
if ( !( $module instanceof IModule ) || $module->isEnabled( $oathUser ) === false ) {
|
2017-06-16 21:21:18 +00:00
|
|
|
$this->error( "User $username doesn't have OATHAuth enabled!", 1 );
|
|
|
|
}
|
|
|
|
|
2018-12-17 23:56:47 +00:00
|
|
|
$repo->remove( $oathUser, 'Maintenance script' );
|
2018-11-21 03:55:17 +00:00
|
|
|
// Kill all existing sessions. If this disable was social-engineered by an attacker,
|
|
|
|
// the legitimate user will hopefully login again and notice that the second factor
|
|
|
|
// is missing or different, and alert the operators.
|
|
|
|
SessionManager::singleton()->invalidateSessionsForUser( $user );
|
|
|
|
|
2017-06-16 21:21:18 +00:00
|
|
|
$this->output( "OATHAuth disabled for $username.\n" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-03 01:05:56 +00:00
|
|
|
$maintClass = DisableOATHAuthForUser::class;
|
2017-06-16 21:21:18 +00:00
|
|
|
require_once RUN_MAINTENANCE_IF_MAIN;
|