31require_once __DIR__ .
'/Maintenance.php';
43 parent::__construct();
44 $this->
addDescription(
'Reset login/signup throttling for a specified user and/or IP. '
46 .
'When resetting signup or temp account, provide the IP. When resetting login (or both), provide '
47 .
'both username (as entered in login screen) and IP. An easy way to obtain them is '
48 .
"the 'throttler' log channel." );
49 $this->
addOption(
'login',
'Reset login throttle' );
50 $this->
addOption(
'signup',
'Reset account creation throttle' );
51 $this->
addOption(
'tempaccount',
'Reset temp account creation throttle' );
52 $this->
addOption(
'tempaccountnameacquisition',
'Reset temp account name acquisition throttle' );
53 $this->
addOption(
'user',
'Username to reset (when using --login)',
false,
true );
54 $this->
addOption(
'ip',
'IP to reset',
false,
true );
58 $forLogin = (bool)$this->
getOption(
'login' );
59 $forSignup = (bool)$this->
getOption(
'signup' );
60 $forTempAccount = (bool)$this->
getOption(
'tempaccount' );
61 $forTempAccountNameAcquisition = (bool)$this->
getOption(
'tempaccountnameacquisition' );
65 if ( !$forLogin && !$forSignup && !$forTempAccount && !$forTempAccountNameAcquisition ) {
67 'At least one of --login, --signup, --tempaccount, or --tempaccountnameacquisition is required!'
69 } elseif ( $ip ===
null ) {
71 } elseif ( !IPUtils::isValid( $ip ) ) {
81 if ( $forTempAccount ) {
84 if ( $forTempAccountNameAcquisition ) {
88 LoggerFactory::getInstance(
'throttler' )->info(
'Manually cleared {type} throttle', [
89 'type' => implode(
' and ', array_filter( [
90 $forLogin ?
'login' :
null,
91 $forSignup ?
'signup' :
null,
92 $forTempAccount ?
'tempaccount' :
null,
93 $forTempAccountNameAcquisition ?
'tempaccountnameacquisition' :
null,
95 'username' => $username,
105 $this->
output(
'Clearing login throttle...' );
107 $passwordAttemptThrottle = $this->
getConfig()->get( MainConfigNames::PasswordAttemptThrottle );
108 if ( !$passwordAttemptThrottle ) {
109 $this->
output(
"none set\n" );
113 $objectCacheFactory = $this->
getServiceContainer()->getInstance()->getObjectCacheFactory();
115 $throttler =
new Throttler( $passwordAttemptThrottle, [
116 'type' =>
'password',
117 'cache' => $objectCacheFactory->getLocalClusterInstance(),
119 if ( $rawUsername !==
null ) {
121 ->normalizeUsername( $rawUsername );
123 $this->
fatalError(
"Not a valid username: $rawUsername" );
126 $usernames = [ null ];
128 foreach ( $usernames as $username ) {
129 $throttler->clear( $username, $ip );
132 $botPasswordThrottler =
new Throttler( $passwordAttemptThrottle, [
133 'type' =>
'botpassword',
134 'cache' => $objectCacheFactory->getLocalClusterInstance(),
137 $botPasswordThrottler->clear( $username, $ip );
139 $this->
output(
"done\n" );
146 $this->
output(
'Clearing signup throttle...' );
148 $accountCreationThrottle = $this->
getConfig()->get( MainConfigNames::AccountCreationThrottle );
149 if ( !is_array( $accountCreationThrottle ) ) {
150 $accountCreationThrottle = [ [
151 'count' => $accountCreationThrottle,
155 if ( !$accountCreationThrottle ) {
156 $this->
output(
"none set\n" );
159 $throttler =
new Throttler( $accountCreationThrottle, [
160 'type' =>
'acctcreate',
162 ->getLocalClusterInstance(),
165 $throttler->clear(
null, $ip );
167 $this->
output(
"done\n" );
171 $this->
output(
'Clearing temp account creation throttle...' );
173 $tempAccountCreationThrottle = $this->
getConfig()->get( MainConfigNames::TempAccountCreationThrottle );
174 if ( !$tempAccountCreationThrottle ) {
175 $this->
output(
"none set\n" );
178 $throttler =
new Throttler( $tempAccountCreationThrottle, [
179 'type' =>
'tempacctcreate',
181 ->getLocalClusterInstance(),
184 $throttler->clear(
null, $ip );
186 $this->
output(
"done\n" );
190 $this->output(
'Clearing temp account name acquisition throttle...' );
192 $tempAccountNameAcquisitionThrottle = $this->getConfig()->get(
193 MainConfigNames::TempAccountNameAcquisitionThrottle
195 if ( !$tempAccountNameAcquisitionThrottle ) {
196 $this->output(
"none set\n" );
199 $throttler =
new Throttler( $tempAccountNameAcquisitionThrottle, [
200 'type' =>
'tempacctnameacquisition',
201 'cache' => $this->getServiceContainer()->getObjectCacheFactory()
202 ->getLocalClusterInstance(),
205 $throttler->clear(
null, $ip );
207 $this->output(
"done\n" );
214require_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.