Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F2751284
ProxyLookup.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
ProxyLookup.php
View Options
<?php
/**
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* http://www.gnu.org/copyleft/gpl.html
*
* @file
*/
namespace
MediaWiki\Request
;
use
MediaWiki\HookContainer\HookContainer
;
use
MediaWiki\HookContainer\HookRunner
;
use
Wikimedia\IPSet
;
/**
* @since 1.28
*/
class
ProxyLookup
{
/** @var string[] */
private
$proxyServers
;
/** @var string[] */
private
$proxyServersComplex
;
/** @var IPSet|null */
private
$proxyIPSet
;
/** @var HookRunner */
private
$hookRunner
;
/**
* @param string[] $proxyServers Simple list of IPs
* @param string[] $proxyServersComplex Complex list of IPs/ranges
* @param HookContainer $hookContainer
*/
public
function
__construct
(
$proxyServers
,
$proxyServersComplex
,
HookContainer
$hookContainer
)
{
$this
->
proxyServers
=
$proxyServers
;
$this
->
proxyServersComplex
=
$proxyServersComplex
;
$this
->
hookRunner
=
new
HookRunner
(
$hookContainer
);
}
/**
* Checks if an IP matches a proxy we've configured
*
* @param string $ip
* @return bool
*/
public
function
isConfiguredProxy
(
$ip
)
{
// Quick check of known singular proxy servers
if
(
in_array
(
$ip
,
$this
->
proxyServers
,
true
)
)
{
return
true
;
}
// Check against addresses and CIDR nets in the complex list
if
(
!
$this
->
proxyIPSet
)
{
$this
->
proxyIPSet
=
new
IPSet
(
$this
->
proxyServersComplex
);
}
return
$this
->
proxyIPSet
->
match
(
$ip
);
}
/**
* Checks if an IP is a trusted proxy provider.
* Useful to tell if X-Forwarded-For data is possibly bogus.
* CDN cache servers for the site are allowed.
*
* @param string $ip
* @return bool
*/
public
function
isTrustedProxy
(
$ip
)
{
$trusted
=
$this
->
isConfiguredProxy
(
$ip
);
$this
->
hookRunner
->
onIsTrustedProxy
(
$ip
,
$trusted
);
return
$trusted
;
}
}
/** @deprecated class alias since 1.41 */
class_alias
(
ProxyLookup
::
class
,
'ProxyLookup'
);
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Fri, Jul 3, 18:14 (1 d, 9 h)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
aa/46/f41c9bd2cece6a08db4df5cdd75c
Default Alt Text
ProxyLookup.php (2 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment