Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F7436072
disableOATHAuthForUser.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
disableOATHAuthForUser.php
View Options
<?php
use
MediaWiki\Extension\OATHAuth\OATHAuthServices
;
use
MediaWiki\Maintenance\Maintenance
;
// @codeCoverageIgnoreStart
if
(
getenv
(
'MW_INSTALL_PATH'
)
)
{
$IP
=
getenv
(
'MW_INSTALL_PATH'
);
}
else
{
$IP
=
__DIR__
.
'/../../..'
;
}
require_once
"$IP/maintenance/Maintenance.php"
;
// @codeCoverageIgnoreEnd
class
DisableOATHAuthForUser
extends
Maintenance
{
public
function
__construct
()
{
parent
::
__construct
();
$this
->
addDescription
(
'Remove all two-factor authentication devices from a specific user'
);
$this
->
addArg
(
'user'
,
'The username to remove 2FA devices from.'
);
$this
->
requireExtension
(
'OATHAuth'
);
}
public
function
execute
()
{
$username
=
$this
->
getArg
(
0
);
$services
=
$this
->
getServiceContainer
();
$user
=
$services
->
getUserFactory
()->
newFromName
(
$username
);
if
(
$user
===
null
||
$user
->
getId
()
===
0
)
{
$this
->
fatalError
(
"User $username doesn't exist!"
);
}
$repo
=
OATHAuthServices
::
getInstance
()->
getUserRepository
();
$oathUser
=
$repo
->
findByUser
(
$user
);
if
(
!
$oathUser
->
isTwoFactorAuthEnabled
()
)
{
$this
->
fatalError
(
"User $username does not have two-factor authentication enabled!"
);
}
$repo
->
removeAll
(
$oathUser
,
'Maintenance script'
,
false
);
// Kill all existing sessions.
// If this request to disable 2FA was social-engineered by an attacker,
// the legitimate user will hopefully log in again to the wiki, and notice that the second factor
// is missing or different, and alert the operators.
$services
->
getSessionManager
()->
invalidateSessionsForUser
(
$user
);
$this
->
output
(
"Two-factor authentication disabled for $username.
\n
"
);
}
}
// @codeCoverageIgnoreStart
$maintClass
=
DisableOATHAuthForUser
::
class
;
require_once
RUN_MAINTENANCE_IF_MAIN
;
// @codeCoverageIgnoreEnd
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sun, Nov 22, 13:15 (2 h, 14 m ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
8a/dd/13a102ecd6871ee5e487511a44b8
Default Alt Text
disableOATHAuthForUser.php (1 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment