28 use Wikimedia\IPUtils;
30 require_once __DIR__ .
'/Maintenance.php';
41 parent::__construct();
42 $this->
addDescription(
'Reset login/signup throttling for a specified user and/or IP. '
44 .
'When resetting signup only, provide the IP. When resetting login (or both), provide '
45 .
'both username (as entered in login screen) and IP. An easy way to obtain them is '
46 .
"the 'throttler' log channel." );
47 $this->
addOption(
'login',
'Reset login throttle' );
48 $this->
addOption(
'signup',
'Reset account creation throttle' );
49 $this->
addOption(
'user',
'Username to reset',
false,
true );
50 $this->
addOption(
'ip',
'IP to reset',
false,
true );
54 $forLogin = (bool)$this->
getOption(
'login' );
55 $forSignup = (bool)$this->
getOption(
'signup' );
59 if ( !$forLogin && !$forSignup ) {
60 $this->
fatalError(
'At least one of --login and --signup is required!' );
61 } elseif ( $forLogin && ( $ip ===
null || $username ===
null ) ) {
62 $this->
fatalError(
'--user and --ip are both required when using --login!' );
63 } elseif ( $forSignup && $ip ===
null ) {
64 $this->
fatalError(
'--ip is required when using --signup!' );
65 } elseif ( $ip !==
null && !IPUtils::isValid( $ip ) ) {
76 LoggerFactory::getInstance(
'throttler' )->info(
'Manually cleared {type} throttle', [
77 'type' => implode(
' and ', array_filter( [
78 $forLogin ?
'login' :
null,
79 $forSignup ?
'signup' :
null,
81 'username' => $username,
91 $this->
output(
'Clearing login throttle...' );
93 $passwordAttemptThrottle = $this->
getConfig()->get( MainConfigNames::PasswordAttemptThrottle );
94 if ( !$passwordAttemptThrottle ) {
95 $this->
output(
"none set\n" );
99 $throttler =
new Throttler( $passwordAttemptThrottle, [
100 'type' =>
'password',
103 if ( $rawUsername !==
null ) {
104 $usernames = MediaWikiServices::getInstance()->getAuthManager()
105 ->normalizeUsername( $rawUsername );
107 $this->
fatalError(
"Not a valid username: $rawUsername" );
110 $usernames = [ null ];
112 foreach ( $usernames as $username ) {
113 $throttler->clear( $username, $ip );
116 $botPasswordThrottler =
new Throttler( $passwordAttemptThrottle, [
117 'type' =>
'botpassword',
121 $botPasswordThrottler->clear( $username, $ip );
123 $this->
output(
"done\n" );
130 $this->
output(
'Clearing signup throttle...' );
132 $accountCreationThrottle = $this->
getConfig()->get( MainConfigNames::AccountCreationThrottle );
133 if ( !is_array( $accountCreationThrottle ) ) {
134 $accountCreationThrottle = [ [
135 'count' => $accountCreationThrottle,
139 if ( !$accountCreationThrottle ) {
140 $this->
output(
"none set\n" );
143 $throttler =
new Throttler( $accountCreationThrottle, [
144 'type' =>
'acctcreate',
148 $throttler->clear(
null, $ip );
150 $this->
output(
"done\n" );
156 require_once RUN_MAINTENANCE_IF_MAIN;
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
output( $out, $channel=null)
Throw some output to the user.
addDescription( $text)
Set the description text.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
getOption( $name, $default=null)
Get an option, or return the default.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
A class containing constants representing the names of configuration variables.
static getLocalClusterInstance()
Get the main cluster-local cache object.
Reset login/signup throttling for a specified user and/or IP.
execute()
Do the actual work.
clearSignupThrottle( $ip)
clearLoginThrottle( $rawUsername, $ip)
__construct()
Default constructor.