17require_once __DIR__ .
'/Maintenance.php';
29 parent::__construct();
30 $this->
addDescription(
'Reset login/signup throttling for a specified user and/or IP. '
32 .
'When resetting signup or temp account, provide the IP. When resetting login (or both), provide '
33 .
'both username (as entered in login screen) and IP. An easy way to obtain them is '
34 .
"the 'throttler' log channel." );
35 $this->
addOption(
'login',
'Reset login throttle' );
36 $this->
addOption(
'signup',
'Reset account creation throttle' );
37 $this->
addOption(
'tempaccount',
'Reset temp account creation throttle' );
38 $this->
addOption(
'tempaccountnameacquisition',
'Reset temp account name acquisition throttle' );
39 $this->
addOption(
'user',
'Username to reset (when using --login)',
false,
true );
40 $this->
addOption(
'ip',
'IP to reset',
false,
true );
44 $forLogin = (bool)$this->
getOption(
'login' );
45 $forSignup = (bool)$this->
getOption(
'signup' );
46 $forTempAccount = (bool)$this->
getOption(
'tempaccount' );
47 $forTempAccountNameAcquisition = (bool)$this->
getOption(
'tempaccountnameacquisition' );
51 if ( !$forLogin && !$forSignup && !$forTempAccount && !$forTempAccountNameAcquisition ) {
53 'At least one of --login, --signup, --tempaccount, or --tempaccountnameacquisition is required!'
55 } elseif ( $ip ===
null ) {
57 } elseif ( !IPUtils::isValid( $ip ) ) {
67 if ( $forTempAccount ) {
70 if ( $forTempAccountNameAcquisition ) {
74 LoggerFactory::getInstance(
'throttler' )->info(
'Manually cleared {type} throttle', [
75 'type' => implode(
' and ', array_filter( [
76 $forLogin ?
'login' :
null,
77 $forSignup ?
'signup' :
null,
78 $forTempAccount ?
'tempaccount' :
null,
79 $forTempAccountNameAcquisition ?
'tempaccountnameacquisition' :
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" );
101 $throttler =
new Throttler( $passwordAttemptThrottle, [
102 'type' =>
'password',
103 'cache' => $objectCacheFactory->getLocalClusterInstance(),
105 if ( $rawUsername !==
null ) {
107 ->normalizeUsername( $rawUsername );
109 $this->
fatalError(
"Not a valid username: $rawUsername" );
112 $usernames = [ null ];
114 foreach ( $usernames as $username ) {
115 $throttler->clear( $username, $ip );
118 $botPasswordThrottler =
new Throttler( $passwordAttemptThrottle, [
119 'type' =>
'botpassword',
120 'cache' => $objectCacheFactory->getLocalClusterInstance(),
122 $botPasswordThrottler->clear( $username, $ip );
124 $this->
output(
"done\n" );
131 $this->
output(
'Clearing signup throttle...' );
133 $accountCreationThrottle = $this->
getConfig()->get( MainConfigNames::AccountCreationThrottle );
134 if ( !is_array( $accountCreationThrottle ) ) {
135 $accountCreationThrottle = [ [
136 'count' => $accountCreationThrottle,
140 if ( !$accountCreationThrottle ) {
141 $this->
output(
"none set\n" );
144 $throttler =
new Throttler( $accountCreationThrottle, [
145 'type' =>
'acctcreate',
147 ->getLocalClusterInstance(),
150 $throttler->clear(
null, $ip );
152 $this->
output(
"done\n" );
156 $this->
output(
'Clearing temp account creation throttle...' );
158 $tempAccountCreationThrottle = $this->
getConfig()->get( MainConfigNames::TempAccountCreationThrottle );
159 if ( !$tempAccountCreationThrottle ) {
160 $this->
output(
"none set\n" );
163 $throttler =
new Throttler( $tempAccountCreationThrottle, [
164 'type' =>
'tempacctcreate',
166 ->getLocalClusterInstance(),
169 $throttler->clear(
null, $ip );
171 $this->
output(
"done\n" );
175 $this->output(
'Clearing temp account name acquisition throttle...' );
177 $tempAccountNameAcquisitionThrottle = $this->getConfig()->get(
178 MainConfigNames::TempAccountNameAcquisitionThrottle
180 if ( !$tempAccountNameAcquisitionThrottle ) {
181 $this->output(
"none set\n" );
184 $throttler =
new Throttler( $tempAccountNameAcquisitionThrottle, [
185 'type' =>
'tempacctnameacquisition',
186 'cache' => $this->getServiceContainer()->getObjectCacheFactory()
187 ->getLocalClusterInstance(),
190 $throttler->clear(
null, $ip );
192 $this->output(
"done\n" );
199require_once RUN_MAINTENANCE_IF_MAIN;
A class containing constants representing the names of configuration variables.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
output( $out, $channel=null)
Throw some output to the user.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
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.
getServiceContainer()
Returns the main service container.
addDescription( $text)
Set the description text.
Reset login/signup throttling for a specified user and/or IP.
execute()
Do the actual work.
clearSignupThrottle( $ip)
clearTempAccountCreationThrottle(string $ip)
clearLoginThrottle( $rawUsername, $ip)
clearTempAccountNameAcquisitionThrottle(string $ip)
__construct()
Default constructor.