Completed
Pull Request — newinternal (#285)
by Simon
07:17 queued 04:17
created
includes/Providers/CachedRDnsLookupProvider.php 1 patch
Indentation   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -20,40 +20,40 @@
 block discarded – undo
20 20
  */
21 21
 class CachedRDnsLookupProvider implements IRDnsProvider
22 22
 {
23
-    private $database;
23
+	private $database;
24 24
 
25
-    public function __construct(PdoDatabase $database)
26
-    {
27
-        $this->database = $database;
28
-    }
25
+	public function __construct(PdoDatabase $database)
26
+	{
27
+		$this->database = $database;
28
+	}
29 29
 
30
-    public function getReverseDNS($address)
31
-    {
32
-        $address = trim($address);
30
+	public function getReverseDNS($address)
31
+	{
32
+		$address = trim($address);
33 33
 
34
-        // lets look in our cache database first.
35
-        $rDns = RDnsCache::getByAddress($address, $this->database);
34
+		// lets look in our cache database first.
35
+		$rDns = RDnsCache::getByAddress($address, $this->database);
36 36
 
37
-        if ($rDns instanceof RDnsCache) {
38
-            // touch cache timer
39
-            $rDns->save();
37
+		if ($rDns instanceof RDnsCache) {
38
+			// touch cache timer
39
+			$rDns->save();
40 40
 
41
-            return $rDns->getData();
42
-        }
41
+			return $rDns->getData();
42
+		}
43 43
 
44
-        // OK, it's not there, let's do an rDNS lookup.
45
-        $result = @ gethostbyaddr($address);
44
+		// OK, it's not there, let's do an rDNS lookup.
45
+		$result = @ gethostbyaddr($address);
46 46
 
47
-        if ($result !== false) {
48
-            $rDns = new RDnsCache();
49
-            $rDns->setDatabase($this->database);
50
-            $rDns->setAddress($address);
51
-            $rDns->setData($result);
52
-            $rDns->save();
47
+		if ($result !== false) {
48
+			$rDns = new RDnsCache();
49
+			$rDns->setDatabase($this->database);
50
+			$rDns->setAddress($address);
51
+			$rDns->setData($result);
52
+			$rDns->save();
53 53
 
54
-            return $result;
55
-        }
54
+			return $result;
55
+		}
56 56
 
57
-        return null;
58
-    }
57
+		return null;
58
+	}
59 59
 }
Please login to merge, or discard this patch.
includes/Providers/GlobalState/GlobalStateProvider.php 1 patch
Indentation   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -18,35 +18,35 @@
 block discarded – undo
18 18
  */
19 19
 class GlobalStateProvider implements IGlobalStateProvider
20 20
 {
21
-    /**
22
-     * @return array
23
-     */
24
-    public function &getServerSuperGlobal()
25
-    {
26
-        return $_SERVER;
27
-    }
21
+	/**
22
+	 * @return array
23
+	 */
24
+	public function &getServerSuperGlobal()
25
+	{
26
+		return $_SERVER;
27
+	}
28 28
 
29
-    /**
30
-     * @return array
31
-     */
32
-    public function &getGetSuperGlobal()
33
-    {
34
-        return $_GET;
35
-    }
29
+	/**
30
+	 * @return array
31
+	 */
32
+	public function &getGetSuperGlobal()
33
+	{
34
+		return $_GET;
35
+	}
36 36
 
37
-    /**
38
-     * @return array
39
-     */
40
-    public function &getPostSuperGlobal()
41
-    {
42
-        return $_POST;
43
-    }
37
+	/**
38
+	 * @return array
39
+	 */
40
+	public function &getPostSuperGlobal()
41
+	{
42
+		return $_POST;
43
+	}
44 44
 
45
-    /**
46
-     * @return array
47
-     */
48
-    public function &getSessionSuperGlobal()
49
-    {
50
-        return $_SESSION;
51
-    }
45
+	/**
46
+	 * @return array
47
+	 */
48
+	public function &getSessionSuperGlobal()
49
+	{
50
+		return $_SESSION;
51
+	}
52 52
 }
53 53
\ No newline at end of file
Please login to merge, or discard this patch.
includes/Providers/GlobalState/IGlobalStateProvider.php 1 patch
Indentation   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -14,23 +14,23 @@
 block discarded – undo
14 14
  */
15 15
 interface IGlobalStateProvider
16 16
 {
17
-    /**
18
-     * @return array
19
-     */
20
-    public function getServerSuperGlobal();
17
+	/**
18
+	 * @return array
19
+	 */
20
+	public function getServerSuperGlobal();
21 21
 
22
-    /**
23
-     * @return array
24
-     */
25
-    public function getGetSuperGlobal();
22
+	/**
23
+	 * @return array
24
+	 */
25
+	public function getGetSuperGlobal();
26 26
 
27
-    /**
28
-     * @return array
29
-     */
30
-    public function getPostSuperGlobal();
27
+	/**
28
+	 * @return array
29
+	 */
30
+	public function getPostSuperGlobal();
31 31
 
32
-    /**
33
-     * @return array
34
-     */
35
-    public function getSessionSuperGlobal();
32
+	/**
33
+	 * @return array
34
+	 */
35
+	public function getSessionSuperGlobal();
36 36
 }
37 37
\ No newline at end of file
Please login to merge, or discard this patch.
includes/Providers/GlobalState/FakeGlobalStateProvider.php 1 patch
Indentation   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -18,28 +18,28 @@
 block discarded – undo
18 18
  */
19 19
 class FakeGlobalStateProvider extends GlobalStateProvider implements IGlobalStateProvider
20 20
 {
21
-    var $server = array();
22
-    var $get = array();
23
-    var $post = array();
24
-    var $session = array();
21
+	var $server = array();
22
+	var $get = array();
23
+	var $post = array();
24
+	var $session = array();
25 25
 
26
-    public function &getServerSuperGlobal()
27
-    {
28
-        return $this->server;
29
-    }
26
+	public function &getServerSuperGlobal()
27
+	{
28
+		return $this->server;
29
+	}
30 30
 
31
-    public function &getGetSuperGlobal()
32
-    {
33
-        return $this->get;
34
-    }
31
+	public function &getGetSuperGlobal()
32
+	{
33
+		return $this->get;
34
+	}
35 35
 
36
-    public function &getPostSuperGlobal()
37
-    {
38
-        return $this->post;
39
-    }
36
+	public function &getPostSuperGlobal()
37
+	{
38
+		return $this->post;
39
+	}
40 40
 
41
-    public function &getSessionSuperGlobal()
42
-    {
43
-        return $this->session;
44
-    }
41
+	public function &getSessionSuperGlobal()
42
+	{
43
+		return $this->session;
44
+	}
45 45
 }
46 46
\ No newline at end of file
Please login to merge, or discard this patch.
includes/Providers/TorExitProvider.php 1 patch
Indentation   +75 added lines, -75 removed lines patch added patch discarded remove patch
@@ -13,96 +13,96 @@
 block discarded – undo
13 13
 
14 14
 class TorExitProvider
15 15
 {
16
-    /** @var PdoDatabase */
17
-    private $database;
18
-
19
-    /**
20
-     * TorExitProvider constructor.
21
-     *
22
-     * @param PdoDatabase $database
23
-     */
24
-    public function __construct(PdoDatabase $database)
25
-    {
26
-        $this->database = $database;
27
-    }
28
-
29
-    /**
30
-     * Checks whether an IP address is a Tor exit node for one of the pre-cached IP addresses.
31
-     *
32
-     * @param string $ip IP Address
33
-     *
34
-     * @return bool
35
-     */
36
-    public function isTorExit($ip)
37
-    {
38
-        $statement = $this->database->prepare('SELECT COUNT(1) FROM tornodecache WHERE ipaddr = :ip');
39
-
40
-        $statement->execute(array(':ip' => $ip));
41
-
42
-        $count = $statement->fetchColumn();
43
-        $statement->closeCursor();
44
-
45
-        if ($count > 0) {
46
-            return true;
47
-        }
48
-        else {
49
-            return false;
50
-        }
51
-    }
52
-
53
-    public static function regenerate(PdoDatabase $database, HttpHelper $httpHelper, $destinationIps)
54
-    {
55
-        $query = <<<SQL
16
+	/** @var PdoDatabase */
17
+	private $database;
18
+
19
+	/**
20
+	 * TorExitProvider constructor.
21
+	 *
22
+	 * @param PdoDatabase $database
23
+	 */
24
+	public function __construct(PdoDatabase $database)
25
+	{
26
+		$this->database = $database;
27
+	}
28
+
29
+	/**
30
+	 * Checks whether an IP address is a Tor exit node for one of the pre-cached IP addresses.
31
+	 *
32
+	 * @param string $ip IP Address
33
+	 *
34
+	 * @return bool
35
+	 */
36
+	public function isTorExit($ip)
37
+	{
38
+		$statement = $this->database->prepare('SELECT COUNT(1) FROM tornodecache WHERE ipaddr = :ip');
39
+
40
+		$statement->execute(array(':ip' => $ip));
41
+
42
+		$count = $statement->fetchColumn();
43
+		$statement->closeCursor();
44
+
45
+		if ($count > 0) {
46
+			return true;
47
+		}
48
+		else {
49
+			return false;
50
+		}
51
+	}
52
+
53
+	public static function regenerate(PdoDatabase $database, HttpHelper $httpHelper, $destinationIps)
54
+	{
55
+		$query = <<<SQL
56 56
 INSERT INTO tornodecache (ipaddr, exitaddr, exitport)
57 57
 VALUES (:ipaddr, :exitaddr, :exitport)
58 58
 ON DUPLICATE KEY
59 59
 UPDATE touched = CURRENT_TIMESTAMP, updateversion = updateversion + 1
60 60
 SQL;
61 61
 
62
-        $statement = $database->prepare($query);
62
+		$statement = $database->prepare($query);
63 63
 
64
-        foreach ($destinationIps as $ip) {
65
-            echo 'Fetching data for ' . $ip . PHP_EOL;
64
+		foreach ($destinationIps as $ip) {
65
+			echo 'Fetching data for ' . $ip . PHP_EOL;
66 66
 
67
-            $statement->bindValue(':exitaddr', $ip);
67
+			$statement->bindValue(':exitaddr', $ip);
68 68
 
69
-            $http = $httpHelper->get(
70
-                'https://check.torproject.org/cgi-bin/TorBulkExitList.py',
71
-                array(
72
-                    'ip'   => $ip,
73
-                    'port' => 80,
74
-                ));
69
+			$http = $httpHelper->get(
70
+				'https://check.torproject.org/cgi-bin/TorBulkExitList.py',
71
+				array(
72
+					'ip'   => $ip,
73
+					'port' => 80,
74
+				));
75 75
 
76
-            $https = $httpHelper->get(
77
-                'https://check.torproject.org/cgi-bin/TorBulkExitList.py',
78
-                array(
79
-                    'ip'   => $ip,
80
-                    'port' => 443,
81
-                ));
76
+			$https = $httpHelper->get(
77
+				'https://check.torproject.org/cgi-bin/TorBulkExitList.py',
78
+				array(
79
+					'ip'   => $ip,
80
+					'port' => 443,
81
+				));
82 82
 
83
-            foreach (array(80 => $http, 443 => $https) as $port => $response) {
84
-                echo '  Running for port ' . $ip . ':' . $port . PHP_EOL;
83
+			foreach (array(80 => $http, 443 => $https) as $port => $response) {
84
+				echo '  Running for port ' . $ip . ':' . $port . PHP_EOL;
85 85
 
86
-                $statement->bindValue(':exitport', $port);
86
+				$statement->bindValue(':exitport', $port);
87 87
 
88
-                $lines = explode("\n", $response);
88
+				$lines = explode("\n", $response);
89 89
 
90
-                foreach ($lines as $line) {
91
-                    // line contains a comment char, just skip the line.
92
-                    // This is OK as of 2016-04-06  --stw
93
-                    if (strpos($line, '#') !== false) {
94
-                        continue;
95
-                    }
90
+				foreach ($lines as $line) {
91
+					// line contains a comment char, just skip the line.
92
+					// This is OK as of 2016-04-06  --stw
93
+					if (strpos($line, '#') !== false) {
94
+						continue;
95
+					}
96 96
 
97
-                    $statement->bindValue(':ipaddr', $line);
98
-                    $statement->execute();
99
-                }
100
-            }
97
+					$statement->bindValue(':ipaddr', $line);
98
+					$statement->execute();
99
+				}
100
+			}
101 101
 
102
-            echo 'Done for ' . $ip . PHP_EOL;
103
-        }
102
+			echo 'Done for ' . $ip . PHP_EOL;
103
+		}
104 104
 
105
-        // kill old cached entries
106
-        $database->exec('DELETE FROM tornodecache WHERE touched < DATE_SUB(CURRENT_TIMESTAMP, INTERVAL 1 DAY)');
107
-    }
105
+		// kill old cached entries
106
+		$database->exec('DELETE FROM tornodecache WHERE touched < DATE_SUB(CURRENT_TIMESTAMP, INTERVAL 1 DAY)');
107
+	}
108 108
 }
109 109
\ No newline at end of file
Please login to merge, or discard this patch.
includes/Providers/IpLocationProvider.php 1 patch
Indentation   +103 added lines, -103 removed lines patch added patch discarded remove patch
@@ -21,107 +21,107 @@
 block discarded – undo
21 21
  */
22 22
 class IpLocationProvider implements ILocationProvider
23 23
 {
24
-    /** @var string */
25
-    private $apiKey;
26
-    /** @var PdoDatabase */
27
-    private $database;
28
-    /** @var HttpHelper */
29
-    private $httpHelper;
30
-
31
-    /**
32
-     * IpLocationProvider constructor.
33
-     *
34
-     * @param PdoDatabase $database
35
-     * @param string      $apiKey
36
-     * @param HttpHelper  $httpHelper
37
-     */
38
-    public function __construct(PdoDatabase $database, $apiKey, HttpHelper $httpHelper)
39
-    {
40
-        $this->database = $database;
41
-        $this->apiKey = $apiKey;
42
-        $this->httpHelper = $httpHelper;
43
-    }
44
-
45
-    /**
46
-     * @param string $address
47
-     *
48
-     * @return array|null
49
-     * @throws Exception
50
-     * @throws OptimisticLockFailedException
51
-     */
52
-    public function getIpLocation($address)
53
-    {
54
-        $address = trim($address);
55
-
56
-        // lets look in our database first.
57
-        $location = GeoLocation::getByAddress($address, $this->database);
58
-
59
-        if ($location != null) {
60
-            // touch cache timer
61
-            $location->save();
62
-
63
-            return $location->getData();
64
-        }
65
-
66
-        // OK, it's not there, let's do an IP2Location lookup.
67
-        $result = $this->getResult($address);
68
-
69
-        if ($result != null) {
70
-            $location = new GeoLocation();
71
-            $location->setDatabase($this->database);
72
-            $location->setAddress($address);
73
-            $location->setData($result);
74
-            $location->save();
75
-
76
-            return $result;
77
-        }
78
-
79
-        return null;
80
-    }
81
-
82
-    // adapted from http://www.ipinfodb.com/ip_location_api.php
83
-
84
-    /**
85
-     * @param string $ip
86
-     *
87
-     * @return array|null
88
-     */
89
-    private function getResult($ip)
90
-    {
91
-        try {
92
-            if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
93
-                $xml = $this->httpHelper->get($this->getApiBase(), array(
94
-                    'key'    => $this->apiKey,
95
-                    'ip'     => $ip,
96
-                    'format' => 'xml',
97
-                ));
98
-
99
-                $response = @new SimpleXMLElement($xml);
100
-
101
-                $result = array();
102
-
103
-                foreach ($response as $field => $value) {
104
-                    $result[(string)$field] = (string)$value;
105
-                }
106
-
107
-                return $result;
108
-            }
109
-        }
110
-        catch (Exception $ex) {
111
-            return null;
112
-
113
-            // LOGME: do something smart here, or wherever we use this value.
114
-            // This is just a temp hack to squash errors on the UI for now.
115
-        }
116
-
117
-        return null;
118
-    }
119
-
120
-    /**
121
-     * @return string
122
-     */
123
-    protected function getApiBase()
124
-    {
125
-        return "http://api.ipinfodb.com/v3/ip-city/";
126
-    }
24
+	/** @var string */
25
+	private $apiKey;
26
+	/** @var PdoDatabase */
27
+	private $database;
28
+	/** @var HttpHelper */
29
+	private $httpHelper;
30
+
31
+	/**
32
+	 * IpLocationProvider constructor.
33
+	 *
34
+	 * @param PdoDatabase $database
35
+	 * @param string      $apiKey
36
+	 * @param HttpHelper  $httpHelper
37
+	 */
38
+	public function __construct(PdoDatabase $database, $apiKey, HttpHelper $httpHelper)
39
+	{
40
+		$this->database = $database;
41
+		$this->apiKey = $apiKey;
42
+		$this->httpHelper = $httpHelper;
43
+	}
44
+
45
+	/**
46
+	 * @param string $address
47
+	 *
48
+	 * @return array|null
49
+	 * @throws Exception
50
+	 * @throws OptimisticLockFailedException
51
+	 */
52
+	public function getIpLocation($address)
53
+	{
54
+		$address = trim($address);
55
+
56
+		// lets look in our database first.
57
+		$location = GeoLocation::getByAddress($address, $this->database);
58
+
59
+		if ($location != null) {
60
+			// touch cache timer
61
+			$location->save();
62
+
63
+			return $location->getData();
64
+		}
65
+
66
+		// OK, it's not there, let's do an IP2Location lookup.
67
+		$result = $this->getResult($address);
68
+
69
+		if ($result != null) {
70
+			$location = new GeoLocation();
71
+			$location->setDatabase($this->database);
72
+			$location->setAddress($address);
73
+			$location->setData($result);
74
+			$location->save();
75
+
76
+			return $result;
77
+		}
78
+
79
+		return null;
80
+	}
81
+
82
+	// adapted from http://www.ipinfodb.com/ip_location_api.php
83
+
84
+	/**
85
+	 * @param string $ip
86
+	 *
87
+	 * @return array|null
88
+	 */
89
+	private function getResult($ip)
90
+	{
91
+		try {
92
+			if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
93
+				$xml = $this->httpHelper->get($this->getApiBase(), array(
94
+					'key'    => $this->apiKey,
95
+					'ip'     => $ip,
96
+					'format' => 'xml',
97
+				));
98
+
99
+				$response = @new SimpleXMLElement($xml);
100
+
101
+				$result = array();
102
+
103
+				foreach ($response as $field => $value) {
104
+					$result[(string)$field] = (string)$value;
105
+				}
106
+
107
+				return $result;
108
+			}
109
+		}
110
+		catch (Exception $ex) {
111
+			return null;
112
+
113
+			// LOGME: do something smart here, or wherever we use this value.
114
+			// This is just a temp hack to squash errors on the UI for now.
115
+		}
116
+
117
+		return null;
118
+	}
119
+
120
+	/**
121
+	 * @return string
122
+	 */
123
+	protected function getApiBase()
124
+	{
125
+		return "http://api.ipinfodb.com/v3/ip-city/";
126
+	}
127 127
 }
Please login to merge, or discard this patch.
includes/Providers/FakeLocationProvider.php 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -15,8 +15,8 @@
 block discarded – undo
15 15
  */
16 16
 class FakeLocationProvider implements ILocationProvider
17 17
 {
18
-    public function getIpLocation($address)
19
-    {
20
-        return null;
21
-    }
18
+	public function getIpLocation($address)
19
+	{
20
+		return null;
21
+	}
22 22
 }
Please login to merge, or discard this patch.
includes/Providers/Interfaces/ILocationProvider.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -13,10 +13,10 @@
 block discarded – undo
13 13
  */
14 14
 interface ILocationProvider
15 15
 {
16
-    /**
17
-     * @param string $address IP address
18
-     *
19
-     * @return array
20
-     */
21
-    public function getIpLocation($address);
16
+	/**
17
+	 * @param string $address IP address
18
+	 *
19
+	 * @return array
20
+	 */
21
+	public function getIpLocation($address);
22 22
 }
Please login to merge, or discard this patch.
includes/Providers/Interfaces/IRDnsProvider.php 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -13,12 +13,12 @@
 block discarded – undo
13 13
  */
14 14
 interface IRDnsProvider
15 15
 {
16
-    /**
17
-     * Gets the reverse DNS address for an IP
18
-     *
19
-     * @param string $address
20
-     *
21
-     * @return string
22
-     */
23
-    public function getReverseDNS($address);
16
+	/**
17
+	 * Gets the reverse DNS address for an IP
18
+	 *
19
+	 * @param string $address
20
+	 *
21
+	 * @return string
22
+	 */
23
+	public function getReverseDNS($address);
24 24
 }
Please login to merge, or discard this patch.