MediaWiki  1.33.0
resetAuthenticationThrottle.php
Go to the documentation of this file.
1 <?php
27 
28 require_once __DIR__ . '/Maintenance.php';
29 
37 
38  public function __construct() {
39  parent::__construct();
40  $this->addDescription( 'Reset login/signup throttling for a specified user and/or IP. '
41  . "\n\n"
42  . 'When resetting signup only, provide the IP. When resetting login (or both), provide '
43  . 'both username (as entered in login screen) and IP. An easy way to obtain them is '
44  . "the 'throttler' log channel." );
45  $this->addOption( 'login', 'Reset login throttle' );
46  $this->addOption( 'signup', 'Reset account creation throttle' );
47  $this->addOption( 'user', 'Username to reset', false, true );
48  $this->addOption( 'ip', 'IP to reset', false, true );
49  }
50 
51  public function execute() {
52  $forLogin = (bool)$this->getOption( 'login' );
53  $forSignup = (bool)$this->getOption( 'signup' );
54  $username = $this->getOption( 'user' );
55  $ip = $this->getOption( 'ip' );
56 
57  if ( !$forLogin && !$forSignup ) {
58  $this->fatalError( 'At least one of --login and --signup is required!' );
59  } elseif ( $forLogin && ( $ip === null || $username === null ) ) {
60  $this->fatalError( '--usename and --ip are both required when using --login!' );
61  } elseif ( $forSignup && $ip === null ) {
62  $this->fatalError( '--ip is required when using --signup!' );
63  } elseif ( $ip !== null && !IP::isValid( $ip ) ) {
64  $this->fatalError( "Not a valid IP: $ip" );
65  }
66 
67  if ( $forLogin ) {
68  $this->clearLoginThrottle( $username, $ip );
69  }
70  if ( $forSignup ) {
71  $this->clearSignupThrottle( $ip );
72  }
73 
74  LoggerFactory::getInstance( 'throttler' )->notice( 'Manually cleared {type} throttle', [
75  'type' => implode( ' and ', array_filter( [
76  $forLogin ? 'login' : null,
77  $forSignup ? 'signup' : null,
78  ] ) ),
79  'username' => $username,
80  'ipKey' => $ip,
81  ] );
82  }
83 
88  protected function clearLoginThrottle( $rawUsername, $ip ) {
89  $this->output( 'Clearing login throttle... ' );
90 
91  $passwordAttemptThrottle = $this->getConfig()->get( 'PasswordAttemptThrottle' );
92  if ( !$passwordAttemptThrottle ) {
93  $this->output( "none set\n" );
94  return;
95  }
96 
97  $throttler = new Throttler( $passwordAttemptThrottle, [
98  'type' => 'password',
100  ] );
101  if ( $rawUsername !== null ) {
102  $usernames = AuthManager::singleton()->normalizeUsername( $rawUsername );
103  if ( !$usernames ) {
104  $this->fatalError( "Not a valid username: $rawUsername" );
105  }
106  } else {
107  $usernames = [ null ];
108  }
109  foreach ( $usernames as $username ) {
110  $throttler->clear( $username, $ip );
111  }
112 
113  $botPasswordThrottler = new Throttler( $passwordAttemptThrottle, [
114  'type' => 'botpassword',
116  ] );
117  $botPasswordThrottler->clear( $username, $ip );
118 
119  $this->output( "done\n" );
120  }
121 
125  protected function clearSignupThrottle( $ip ) {
126  $this->output( 'Clearing signup throttle... ' );
127 
128  $accountCreationThrottle = $this->getConfig()->get( 'AccountCreationThrottle' );
129  if ( !is_array( $accountCreationThrottle ) ) {
130  $accountCreationThrottle = [ [
131  'count' => $accountCreationThrottle,
132  'seconds' => 86400,
133  ] ];
134  }
135  if ( !$accountCreationThrottle ) {
136  $this->output( "none set\n" );
137  return;
138  }
139  $throttler = new Throttler( $accountCreationThrottle, [
140  'type' => 'acctcreate',
142  ] );
143 
144  $throttler->clear( null, $ip );
145 
146  $this->output( "done\n" );
147  }
148 
149 }
150 
152 require_once RUN_MAINTENANCE_IF_MAIN;
ObjectCache\getLocalClusterInstance
static getLocalClusterInstance()
Get the main cluster-local cache object.
Definition: ObjectCache.php:356
Maintenance\fatalError
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
Definition: Maintenance.php:485
Maintenance\addDescription
addDescription( $text)
Set the description text.
Definition: Maintenance.php:329
ResetAuthenticationThrottle
Reset login/signup throttling for a specified user and/or IP.
Definition: resetAuthenticationThrottle.php:36
RUN_MAINTENANCE_IF_MAIN
require_once RUN_MAINTENANCE_IF_MAIN
Definition: maintenance.txt:50
ResetAuthenticationThrottle\clearSignupThrottle
clearSignupThrottle( $ip)
Definition: resetAuthenticationThrottle.php:125
MediaWiki\Auth\Throttler
Definition: Throttler.php:37
Maintenance
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition: maintenance.txt:39
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
Maintenance\getConfig
getConfig()
Definition: Maintenance.php:594
ResetAuthenticationThrottle\clearLoginThrottle
clearLoginThrottle( $rawUsername, $ip)
Definition: resetAuthenticationThrottle.php:88
ResetAuthenticationThrottle\execute
execute()
Do the actual work.
Definition: resetAuthenticationThrottle.php:51
Maintenance\addOption
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
Definition: Maintenance.php:248
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
$maintClass
$maintClass
Definition: resetAuthenticationThrottle.php:151
null
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not null
Definition: hooks.txt:780
IP\isValid
static isValid( $ip)
Validate an IP address.
Definition: IP.php:111
MediaWiki\Auth\AuthManager
This serves as the entry point to the authentication system.
Definition: AuthManager.php:84
Maintenance\getOption
getOption( $name, $default=null)
Get an option, or return the default.
Definition: Maintenance.php:283
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
LoggerFactory
MediaWiki Logger LoggerFactory implements a PSR[0] compatible message logging system Named Psr Log LoggerInterface instances can be obtained from the MediaWiki Logger LoggerFactory::getInstance() static method. MediaWiki\Logger\LoggerFactory expects a class implementing the MediaWiki\Logger\Spi interface to act as a factory for new Psr\Log\LoggerInterface instances. The "Spi" in MediaWiki\Logger\Spi stands for "service provider interface". An SPI is an API intended to be implemented or extended by a third party. This software design pattern is intended to enable framework extension and replaceable components. It is specifically used in the MediaWiki\Logger\LoggerFactory service to allow alternate PSR-3 logging implementations to be easily integrated with MediaWiki. The service provider interface allows the backend logging library to be implemented in multiple ways. The $wgMWLoggerDefaultSpi global provides the classname of the default MediaWiki\Logger\Spi implementation to be loaded at runtime. This can either be the name of a class implementing the MediaWiki\Logger\Spi with a zero argument const ructor or a callable that will return an MediaWiki\Logger\Spi instance. Alternately the MediaWiki\Logger\LoggerFactory MediaWiki Logger LoggerFactory
Definition: logger.txt:5
ResetAuthenticationThrottle\__construct
__construct()
Default constructor.
Definition: resetAuthenticationThrottle.php:38
Maintenance\output
output( $out, $channel=null)
Throw some output to the user.
Definition: Maintenance.php:434
class
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:52
$username
this hook is for auditing only or null if authentication failed before getting that far $username
Definition: hooks.txt:780