Completed
Pull Request — newinternal (#285)
by Simon
06:16 queued 03:05
created
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.
includes/Providers/Interfaces/IXffTrustProvider.php 1 patch
Indentation   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -19,41 +19,41 @@
 block discarded – undo
19 19
  */
20 20
 interface IXffTrustProvider
21 21
 {
22
-    /**
23
-     * Returns a value if the IP address is a trusted proxy
24
-     *
25
-     * @param string $ip
26
-     *
27
-     * @return bool
28
-     */
29
-    public function isTrusted($ip);
22
+	/**
23
+	 * Returns a value if the IP address is a trusted proxy
24
+	 *
25
+	 * @param string $ip
26
+	 *
27
+	 * @return bool
28
+	 */
29
+	public function isTrusted($ip);
30 30
 
31
-    /**
32
-     * Gets the last trusted IP in the proxy chain.
33
-     *
34
-     * @param string $ip      The IP address from REMOTE_ADDR
35
-     * @param string $proxyIp The contents of the XFF header.
36
-     *
37
-     * @return string Trusted source IP address
38
-     */
39
-    public function getTrustedClientIp($ip, $proxyIp);
31
+	/**
32
+	 * Gets the last trusted IP in the proxy chain.
33
+	 *
34
+	 * @param string $ip      The IP address from REMOTE_ADDR
35
+	 * @param string $proxyIp The contents of the XFF header.
36
+	 *
37
+	 * @return string Trusted source IP address
38
+	 */
39
+	public function getTrustedClientIp($ip, $proxyIp);
40 40
 
41
-    /**
42
-     * Takes an array( "low" => "high" ) values, and returns true if $needle is in at least one of them.
43
-     *
44
-     * @param array  $haystack
45
-     * @param string $ip
46
-     *
47
-     * @return bool
48
-     */
49
-    public function ipInRange($haystack, $ip);
41
+	/**
42
+	 * Takes an array( "low" => "high" ) values, and returns true if $needle is in at least one of them.
43
+	 *
44
+	 * @param array  $haystack
45
+	 * @param string $ip
46
+	 *
47
+	 * @return bool
48
+	 */
49
+	public function ipInRange($haystack, $ip);
50 50
 
51
-    /**
52
-     * Explodes a CIDR range into an array of addresses
53
-     *
54
-     * @param string $range A CIDR-format range
55
-     *
56
-     * @return array An array containing every IP address in the range
57
-     */
58
-    public function explodeCidr($range);
51
+	/**
52
+	 * Explodes a CIDR range into an array of addresses
53
+	 *
54
+	 * @param string $range A CIDR-format range
55
+	 *
56
+	 * @return array An array containing every IP address in the range
57
+	 */
58
+	public function explodeCidr($range);
59 59
 }
Please login to merge, or discard this patch.
includes/Providers/Interfaces/IAntiSpoofProvider.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 IAntiSpoofProvider
15 15
 {
16
-    /**
17
-     * @param string $username
18
-     *
19
-     * @return array
20
-     */
21
-    public function getSpoofs($username);
16
+	/**
17
+	 * @param string $username
18
+	 *
19
+	 * @return array
20
+	 */
21
+	public function getSpoofs($username);
22 22
 }
Please login to merge, or discard this patch.
includes/ConsoleStart.php 1 patch
Indentation   +57 added lines, -57 removed lines patch added patch discarded remove patch
@@ -15,72 +15,72 @@
 block discarded – undo
15 15
 
16 16
 class ConsoleStart extends ApplicationBase
17 17
 {
18
-    /**
19
-     * @var ConsoleTaskBase
20
-     */
21
-    private $consoleTask;
18
+	/**
19
+	 * @var ConsoleTaskBase
20
+	 */
21
+	private $consoleTask;
22 22
 
23
-    /**
24
-     * ConsoleStart constructor.
25
-     *
26
-     * @param SiteConfiguration $configuration
27
-     * @param ConsoleTaskBase   $consoleTask
28
-     */
29
-    public function __construct(SiteConfiguration $configuration, ConsoleTaskBase $consoleTask)
30
-    {
31
-        parent::__construct($configuration);
32
-        $this->consoleTask = $consoleTask;
33
-    }
23
+	/**
24
+	 * ConsoleStart constructor.
25
+	 *
26
+	 * @param SiteConfiguration $configuration
27
+	 * @param ConsoleTaskBase   $consoleTask
28
+	 */
29
+	public function __construct(SiteConfiguration $configuration, ConsoleTaskBase $consoleTask)
30
+	{
31
+		parent::__construct($configuration);
32
+		$this->consoleTask = $consoleTask;
33
+	}
34 34
 
35
-    protected function setupEnvironment()
36
-    {
37
-        // initialise super-global providers
38
-        WebRequest::setGlobalStateProvider(new FakeGlobalStateProvider());
35
+	protected function setupEnvironment()
36
+	{
37
+		// initialise super-global providers
38
+		WebRequest::setGlobalStateProvider(new FakeGlobalStateProvider());
39 39
 
40
-        if (WebRequest::method() !== null) {
41
-            throw new EnvironmentException('This is a console task, which cannot be executed via the web.');
42
-        }
40
+		if (WebRequest::method() !== null) {
41
+			throw new EnvironmentException('This is a console task, which cannot be executed via the web.');
42
+		}
43 43
 
44
-        return parent::setupEnvironment();
45
-    }
44
+		return parent::setupEnvironment();
45
+	}
46 46
 
47
-    protected function cleanupEnvironment()
48
-    {
49
-    }
47
+	protected function cleanupEnvironment()
48
+	{
49
+	}
50 50
 
51
-    /**
52
-     * Main application logic
53
-     */
54
-    protected function main()
55
-    {
56
-        $database = PdoDatabase::getDatabaseConnection('acc');
51
+	/**
52
+	 * Main application logic
53
+	 */
54
+	protected function main()
55
+	{
56
+		$database = PdoDatabase::getDatabaseConnection('acc');
57 57
 
58
-        if ($this->getConfiguration()->getIrcNotificationsEnabled()) {
59
-            $notificationsDatabase = PdoDatabase::getDatabaseConnection('notifications');
60
-        }
61
-        else {
62
-            // pass through null
63
-            $notificationsDatabase = null;
64
-        }
58
+		if ($this->getConfiguration()->getIrcNotificationsEnabled()) {
59
+			$notificationsDatabase = PdoDatabase::getDatabaseConnection('notifications');
60
+		}
61
+		else {
62
+			// pass through null
63
+			$notificationsDatabase = null;
64
+		}
65 65
 
66
-        $this->setupHelpers($this->consoleTask, $this->getConfiguration(), $database, $notificationsDatabase);
66
+		$this->setupHelpers($this->consoleTask, $this->getConfiguration(), $database, $notificationsDatabase);
67 67
 
68
-        // initialise a database transaction
69
-        if (!$database->beginTransaction()) {
70
-            throw new Exception('Failed to start transaction on primary database.');
71
-        }
68
+		// initialise a database transaction
69
+		if (!$database->beginTransaction()) {
70
+			throw new Exception('Failed to start transaction on primary database.');
71
+		}
72 72
 
73
-        try {
74
-            // run the task
75
-            $this->consoleTask->execute();
73
+		try {
74
+			// run the task
75
+			$this->consoleTask->execute();
76 76
 
77
-            $database->commit();
78
-        }
79
-        finally {
80
-            // Catch any hanging on transactions
81
-            if ($database->hasActiveTransaction()) {
82
-                $database->rollBack();
83
-            }
84
-        }
85
-    }
77
+			$database->commit();
78
+		}
79
+		finally {
80
+			// Catch any hanging on transactions
81
+			if ($database->hasActiveTransaction()) {
82
+				$database->rollBack();
83
+			}
84
+		}
85
+	}
86 86
 }
87 87
\ No newline at end of file
Please login to merge, or discard this patch.
includes/Environment.php 1 patch
Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -13,21 +13,21 @@
 block discarded – undo
13 13
  */
14 14
 class Environment
15 15
 {
16
-    /**
17
-     * @var string Cached copy of the tool version
18
-     */
19
-    private static $toolVersion = null;
16
+	/**
17
+	 * @var string Cached copy of the tool version
18
+	 */
19
+	private static $toolVersion = null;
20 20
 
21
-    /**
22
-     * Gets the tool version, using cached data if available.
23
-     * @return string
24
-     */
25
-    public static function getToolVersion()
26
-    {
27
-        if (self::$toolVersion === null) {
28
-            self::$toolVersion = exec("git describe --always --dirty");
29
-        }
21
+	/**
22
+	 * Gets the tool version, using cached data if available.
23
+	 * @return string
24
+	 */
25
+	public static function getToolVersion()
26
+	{
27
+		if (self::$toolVersion === null) {
28
+			self::$toolVersion = exec("git describe --always --dirty");
29
+		}
30 30
 
31
-        return self::$toolVersion;
32
-    }
31
+		return self::$toolVersion;
32
+	}
33 33
 }
Please login to merge, or discard this patch.
backup.php 1 patch
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
  ******************************************************************************/
8 8
 
9 9
 if (isset($_SERVER['REQUEST_METHOD'])) {
10
-    die();
10
+	die();
11 11
 } //Web clients die.
12 12
 
13 13
 // Get all the classes.
@@ -19,12 +19,12 @@  discard block
 block discarded – undo
19 19
 
20 20
 $arg = $argv['1'];
21 21
 if ($arg == "--monthly") {
22
-    echo "running monthly backups.\n";
23
-    $dateModifier = date("FY");
24
-    $cmdLine = "$BUtar $BUmonthdir/mBackup-$dateModifier.tar $BUdir/*.sql.gz; rm $BUdir/*.sql.gz";
25
-    echo "running command $cmdLine\n";
26
-    shell_exec($cmdLine);
27
-    die("done.");
22
+	echo "running monthly backups.\n";
23
+	$dateModifier = date("FY");
24
+	$cmdLine = "$BUtar $BUmonthdir/mBackup-$dateModifier.tar $BUdir/*.sql.gz; rm $BUdir/*.sql.gz";
25
+	echo "running command $cmdLine\n";
26
+	shell_exec($cmdLine);
27
+	die("done.");
28 28
 }
29 29
 
30 30
 echo "running nightly backups\n";
Please login to merge, or discard this patch.