Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F7413350
KnownIPPreAuthenticationProvider.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
KnownIPPreAuthenticationProvider.php
View Options
<?php
namespace
LoginNotify
;
use
MediaWiki\Api\ApiMessage
;
use
MediaWiki\Auth\AbstractPreAuthenticationProvider
;
use
MediaWiki\Auth\AuthenticationRequest
;
use
MediaWiki\Logger\LoggerFactory
;
use
MediaWiki\User\UserFactory
;
use
StatusValue
;
/**
* A pre-authentication provider that optionally denies login attempts from unknown IPs.
*
* This check matches the behavior of the audit hook in that it only considers IPs that have been used on the
* local wiki to be known if the request did not have a previous login cookie.
*/
class
KnownIPPreAuthenticationProvider
extends
AbstractPreAuthenticationProvider
{
private
LoginNotify
$loginNotify
;
private
UserFactory
$userFactory
;
public
function
__construct
(
LoginNotify
$loginNotify
,
UserFactory
$userFactory
)
{
$this
->
loginNotify
=
$loginNotify
;
$this
->
userFactory
=
$userFactory
;
}
public
function
testForAuthentication
(
array
$reqs
):
StatusValue
{
if
(
!
$this
->
config
->
get
(
'LoginNotifyDenyUnknownIPs'
)
)
{
return
StatusValue
::
newGood
();
}
$userName
=
AuthenticationRequest
::
getUsernameFromRequests
(
$reqs
);
$user
=
$this
->
userFactory
->
newFromName
(
$userName
);
if
(
$user
===
null
)
{
return
StatusValue
::
newGood
();
}
$request
=
$this
->
manager
->
getRequest
();
$known
=
$this
->
loginNotify
->
isKnownSystemFast
(
$user
,
$request
);
if
(
$known
===
LoginNotify
::
USER_KNOWN
)
{
return
StatusValue
::
newGood
();
}
LoggerFactory
::
getInstance
(
'LoginNotify'
)
->
warning
(
'Rejected login attempt from unknown IP for {name}'
,
[
'name'
=>
$user
->
getName
(),
'clientip'
=>
$request
->
getIP
(),
'ua'
=>
$request
->
getHeader
(
'User-Agent'
),
'xff'
=>
$request
->
getHeader
(
'X-Forwarded-For'
),
'geocookie'
=>
$request
->
getCookie
(
'GeoIP'
,
''
),
]
);
return
StatusValue
::
newFatal
(
ApiMessage
::
create
(
'loginnotify-unknown-ip'
,
'unknownip'
)
);
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sun, Nov 22, 01:00 (1 d, 18 h)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
4b/99/61cf8371dd353c515b1da96d4340
Default Alt Text
KnownIPPreAuthenticationProvider.php (1 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment