Huji has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/401410 )
Change subject: Maintenance script to generate fake login attemps from any IP ...................................................................... Maintenance script to generate fake login attemps from any IP Change-Id: I01221923387a9e94499efdda39b2e40ee207e27c --- A maintenance/loginAttempt.php 1 file changed, 56 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/LoginNotify refs/changes/10/401410/1 diff --git a/maintenance/loginAttempt.php b/maintenance/loginAttempt.php new file mode 100644 index 0000000..2c301e7 --- /dev/null +++ b/maintenance/loginAttempt.php @@ -0,0 +1,56 @@ +<?php + +namespace LoginNotify\Maintenance; + +use Maintenance; +use MediaWiki\MediaWikiServices; +use Message; +use MediaWiki\Auth\AuthenticationResponse; +use User; + +$IP = getenv( 'MW_INSTALL_PATH' ); +if ( $IP === false ) { + $IP = __DIR__ . '/../../..'; +} + +require_once "$IP/maintenance/Maintenance.php"; + +class LoginAttempt extends Maintenance { + public function __construct() { + parent::__construct(); + $this->addDescription( 'Registers a login attempt for a given user' ); + $this->addArg( 'user', 'Target user', true ); + $this->addArg( 'success', 'Whether login attempt was successful (true/false)', false ); + $this->addArg( 'ip', 'IP address of the login attempt', false ); + $this->addArg( 'ua', 'User-agent tsrign of the login attempt', false ); + + $this->requireExtension( 'LoginNotify' ); + } + + public function execute(){ + $username = $this->getArg( 0 ); + $success = $this->getArg( 1, false ) === 'true'; + $ip = $this->getArg( 2, '127.0.0.1' ); + $ua = $this->getArg( 3, 'Login attempt by LoginNotify maintenance script' ); + + $user = User::newFromName( $username, 'usable' ); + if ( !$user ) { + echo "User {$username} does not exist!"; + return; + } + + $user->getRequest()->setIP($ip); + + if ( $success ) { + $res = AuthenticationResponse::newPass( $username ); + } else { + $msg = new Message( 'Failed login from LoginNotify maintenance script' ); + $res = AuthenticationResponse::newFail( $msg ); + } + + \Hooks::run( 'AuthManagerLoginAuthenticateAudit', [ $res, $user, $username ] ); + } +} + +$maintClass = LoginAttempt::class; +require_once RUN_MAINTENANCE_IF_MAIN; -- To view, visit https://gerrit.wikimedia.org/r/401410 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I01221923387a9e94499efdda39b2e40ee207e27c Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/LoginNotify Gerrit-Branch: master Gerrit-Owner: Huji <huji.h...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits