MediaWiki REL1_39
ProxyLookup.php
Go to the documentation of this file.
1<?php
2
24use Wikimedia\IPSet;
25
30
32 private $proxyServers;
33
35 private $proxyServersComplex;
36
38 private $proxyIPSet;
39
41 private $hookRunner;
42
48 public function __construct(
49 $proxyServers,
50 $proxyServersComplex,
51 HookContainer $hookContainer
52 ) {
53 $this->proxyServers = $proxyServers;
54 $this->proxyServersComplex = $proxyServersComplex;
55 $this->hookRunner = new HookRunner( $hookContainer );
56 }
57
64 public function isConfiguredProxy( $ip ) {
65 // Quick check of known singular proxy servers
66 if ( in_array( $ip, $this->proxyServers, true ) ) {
67 return true;
68 }
69
70 // Check against addresses and CIDR nets in the complex list
71 if ( !$this->proxyIPSet ) {
72 $this->proxyIPSet = new IPSet( $this->proxyServersComplex );
73 }
74 return $this->proxyIPSet->match( $ip );
75 }
76
85 public function isTrustedProxy( $ip ) {
86 $trusted = $this->isConfiguredProxy( $ip );
87 $this->hookRunner->onIsTrustedProxy( $ip, $trusted );
88 return $trusted;
89 }
90}
This class provides an implementation of the core hook interfaces, forwarding hook calls to HookConta...
__construct( $proxyServers, $proxyServersComplex, HookContainer $hookContainer)
isTrustedProxy( $ip)
Checks if an IP is a trusted proxy provider.
isConfiguredProxy( $ip)
Checks if an IP matches a proxy we've configured.