update v 1.0.7.5
This commit is contained in:
4
vendor/torann/geoip/.gitignore
vendored
Normal file
4
vendor/torann/geoip/.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
/vendor
|
||||
composer.phar
|
||||
composer.lock
|
||||
.DS_Store
|
||||
12
vendor/torann/geoip/.travis.yml
vendored
Normal file
12
vendor/torann/geoip/.travis.yml
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
language: php
|
||||
|
||||
php:
|
||||
- 5.3
|
||||
- 5.4
|
||||
- 5.5
|
||||
|
||||
before_script:
|
||||
- curl -s http://getcomposer.org/installer | php
|
||||
- php composer.phar install --dev
|
||||
|
||||
script: phpunit
|
||||
11
vendor/torann/geoip/LICENCE
vendored
Normal file
11
vendor/torann/geoip/LICENCE
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
The BSD 2-Clause License
|
||||
Copyright (c) 2013, Daniel Stainback
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
115
vendor/torann/geoip/README.md
vendored
Normal file
115
vendor/torann/geoip/README.md
vendored
Normal file
@@ -0,0 +1,115 @@
|
||||
# GeoIP for Laravel 5
|
||||
|
||||
[](https://packagist.org/packages/torann/geoip) [](https://packagist.org/packages/torann/geoip)
|
||||
|
||||
Determine the geographical location of website visitors based on their IP addresses. [Homepage](http://lyften.com/projects/laravel-geoip/)
|
||||
|
||||
----------
|
||||
|
||||
## Installation
|
||||
|
||||
- [GeoIP for Laravel 5 on Packagist](https://packagist.org/packages/torann/geoip)
|
||||
- [GeoIP for Laravel 5 on GitHub](https://github.com/Torann/laravel-geoip)
|
||||
- [Laravel 4 Installation](https://github.com/Torann/laravel-geoip/tree/0.1.1)
|
||||
|
||||
To get the latest version of GeoIP simply require it in your `composer.json` file.
|
||||
|
||||
~~~
|
||||
"torann/geoip": "0.2.*@dev"
|
||||
~~~
|
||||
|
||||
You'll then need to run `composer install` to download it and have the autoloader updated.
|
||||
|
||||
Once GeoIP is installed you need to register the service provider with the application. Open up `config/app.php` and find the `providers` key.
|
||||
|
||||
~~~php
|
||||
'providers' => array(
|
||||
|
||||
'Torann\GeoIP\GeoIPServiceProvider',
|
||||
|
||||
)
|
||||
~~~
|
||||
|
||||
GeoIP also ships with a facade which provides the static syntax for creating collections. You can register the facade in the `aliases` key of your `config/app.php` file.
|
||||
|
||||
~~~php
|
||||
'aliases' => array(
|
||||
|
||||
'GeoIP' => 'Torann\GeoIP\GeoIPFacade',
|
||||
|
||||
)
|
||||
~~~
|
||||
|
||||
### Publish the configurations
|
||||
|
||||
Run this on the command line from the root of your project:
|
||||
|
||||
~~~
|
||||
$ php artisan vendor:publish
|
||||
~~~
|
||||
|
||||
A configuration file will be publish to `config/geoip.php`
|
||||
|
||||
### Update max mind cities database
|
||||
|
||||
~~~
|
||||
$ php artisan geoip:update
|
||||
~~~
|
||||
|
||||
**Database Service**: To use the database version of [MaxMind](http://www.maxmind.com) services download the `GeoLite2-City.mmdb` from [http://dev.maxmind.com/geoip/geoip2/geolite2/](http://dev.maxmind.com/geoip/geoip2/geolite2/) and extract it to `storage/app/geoip.mmdb`. And that's it.
|
||||
|
||||
## Usage
|
||||
|
||||
Get the location data for a website visitor:
|
||||
|
||||
```php
|
||||
$location = GeoIP::getLocation();
|
||||
```
|
||||
|
||||
> When an IP is not given the `$_SERVER["REMOTE_ADDR"]` is used.
|
||||
|
||||
Getting the location data for a given IP:
|
||||
|
||||
```php
|
||||
$location = GeoIP::getLocation('232.223.11.11');
|
||||
```
|
||||
|
||||
### Example Data
|
||||
|
||||
```php
|
||||
array (
|
||||
"ip" => "232.223.11.11",
|
||||
"isoCode" => "US",
|
||||
"country" => "United States",
|
||||
"city" => "New Haven",
|
||||
"state" => "CT",
|
||||
"postal_code" => "06510",
|
||||
"lat" => 41.28,
|
||||
"lon" => -72.88,
|
||||
"timezone" => "America/New_York",
|
||||
"continent" => "NA",
|
||||
"default" => false
|
||||
);
|
||||
```
|
||||
|
||||
#### Default Location
|
||||
|
||||
In the case that a location is not found the fallback location will be returned with the `default` parameter set to `true`. To set your own default change it in the configurations `config/geoip.php`
|
||||
|
||||
## Change Log
|
||||
|
||||
#### v0.2.1
|
||||
|
||||
- Add database_path to config
|
||||
- Add update_url to config
|
||||
- Add GeoIP database update command "php artisan geoip:update"
|
||||
- Add some test
|
||||
- Format code
|
||||
|
||||
#### v0.2.0
|
||||
|
||||
- Update to Laravel 5
|
||||
- Support IPv6
|
||||
- Log address not found exceptions
|
||||
- Supports a custom default location
|
||||
|
||||
35
vendor/torann/geoip/composer.json
vendored
Normal file
35
vendor/torann/geoip/composer.json
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
{
|
||||
"name": "torann/geoip",
|
||||
"description": "Supports the two main GeoIP services (infoDB and Maxmind).",
|
||||
"keywords": ["laravel", "laravel 5", "geoip", "location", "geolocation"],
|
||||
"license": "BSD 2-Clause",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Daniel Stainback",
|
||||
"email": "daniel@lyften.com"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=5.3.0",
|
||||
"illuminate/support": "~5.0",
|
||||
"illuminate/session": "~5.0",
|
||||
"illuminate/console": "~5.0",
|
||||
"illuminate/config": "~5.0",
|
||||
"monolog/monolog": "~1.11",
|
||||
"geoip2/geoip2": "~2.1"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "~4.0",
|
||||
"phpspec/phpspec": "~2.1"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Torann\\GeoIP\\": "src/Torann/GeoIP"
|
||||
}
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "0.2-dev"
|
||||
}
|
||||
}
|
||||
}
|
||||
18
vendor/torann/geoip/phpunit.xml
vendored
Normal file
18
vendor/torann/geoip/phpunit.xml
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<phpunit backupGlobals="false"
|
||||
backupStaticAttributes="false"
|
||||
bootstrap="vendor/autoload.php"
|
||||
colors="true"
|
||||
convertErrorsToExceptions="true"
|
||||
convertNoticesToExceptions="true"
|
||||
convertWarningsToExceptions="true"
|
||||
processIsolation="false"
|
||||
stopOnFailure="false"
|
||||
syntaxCheck="false"
|
||||
>
|
||||
<testsuites>
|
||||
<testsuite name="Package Test Suite">
|
||||
<directory suffix=".php">./tests/</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
</phpunit>
|
||||
57
vendor/torann/geoip/src/Torann/GeoIP/Console/UpdateCommand.php
vendored
Normal file
57
vendor/torann/geoip/src/Torann/GeoIP/Console/UpdateCommand.php
vendored
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php namespace Torann\GeoIP\Console;
|
||||
|
||||
use Illuminate\Config\Repository;
|
||||
use Illuminate\Console\Command;
|
||||
use Torann\GeoIP\GeoIPUpdater;
|
||||
|
||||
class UpdateCommand extends Command
|
||||
{
|
||||
/**
|
||||
* The console command name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'geoip:update';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Update geoip database files to the latest version';
|
||||
|
||||
/**
|
||||
* @var \Torann\GeoIP\GeoIPUpdater
|
||||
*/
|
||||
protected $geoIPUpdater;
|
||||
|
||||
/**
|
||||
* Create a new console command instance.
|
||||
*
|
||||
* @param \Illuminate\Config\Repository $config
|
||||
*/
|
||||
public function __construct(Repository $config)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->geoIPUpdater = new GeoIPUpdater($config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function fire()
|
||||
{
|
||||
$result = $this->geoIPUpdater->update();
|
||||
|
||||
if (!$result) {
|
||||
$this->error('Update failed!');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->info('New update file ('.$result.') installed.');
|
||||
}
|
||||
}
|
||||
282
vendor/torann/geoip/src/Torann/GeoIP/GeoIP.php
vendored
Normal file
282
vendor/torann/geoip/src/Torann/GeoIP/GeoIP.php
vendored
Normal file
@@ -0,0 +1,282 @@
|
||||
<?php namespace Torann\GeoIP;
|
||||
|
||||
use GeoIp2\Database\Reader;
|
||||
use GeoIp2\WebService\Client;
|
||||
|
||||
use Monolog\Logger;
|
||||
use Monolog\Handler\StreamHandler;
|
||||
|
||||
use GeoIp2\Exception\AddressNotFoundException;
|
||||
|
||||
use Illuminate\Config\Repository;
|
||||
use Illuminate\Session\Store as SessionStore;
|
||||
|
||||
class GeoIP {
|
||||
|
||||
/**
|
||||
* The session store.
|
||||
*
|
||||
* @var \Illuminate\Session\Store
|
||||
*/
|
||||
protected $session;
|
||||
|
||||
/**
|
||||
* Illuminate config repository instance.
|
||||
*
|
||||
* @var \Illuminate\Config\Repository
|
||||
*/
|
||||
protected $config;
|
||||
|
||||
/**
|
||||
* Remote Machine IP address.
|
||||
*
|
||||
* @var float
|
||||
*/
|
||||
protected $remote_ip = null;
|
||||
|
||||
/**
|
||||
* Location data.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $location = null;
|
||||
|
||||
/**
|
||||
* Reserved IP address.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $reserved_ips = array (
|
||||
array('0.0.0.0','2.255.255.255'),
|
||||
array('10.0.0.0','10.255.255.255'),
|
||||
array('127.0.0.0','127.255.255.255'),
|
||||
array('169.254.0.0','169.254.255.255'),
|
||||
array('172.16.0.0','172.31.255.255'),
|
||||
array('192.0.2.0','192.0.2.255'),
|
||||
array('192.168.0.0','192.168.255.255'),
|
||||
array('255.255.255.0','255.255.255.255'),
|
||||
);
|
||||
|
||||
/**
|
||||
* Default Location data.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $default_location = array (
|
||||
"ip" => "127.0.0.0",
|
||||
"isoCode" => "US",
|
||||
"country" => "United States",
|
||||
"city" => "New Haven",
|
||||
"state" => "CT",
|
||||
"postal_code" => "06510",
|
||||
"lat" => 41.31,
|
||||
"lon" => -72.92,
|
||||
"timezone" => "America/New_York",
|
||||
"continent" => "NA",
|
||||
"default" => true,
|
||||
);
|
||||
|
||||
/**
|
||||
* Create a new GeoIP instance.
|
||||
*
|
||||
* @param \Illuminate\Config\Repository $config
|
||||
* @param \Illuminate\Session\Store $session
|
||||
*/
|
||||
public function __construct(Repository $config, SessionStore $session)
|
||||
{
|
||||
$this->config = $config;
|
||||
$this->session = $session;
|
||||
|
||||
// Set custom default location
|
||||
$this->default_location = array_merge(
|
||||
$this->default_location,
|
||||
$this->config->get('geoip.default_location', array())
|
||||
);
|
||||
|
||||
// Set IP
|
||||
$this->remote_ip = $this->default_location['ip'] = $this->getClientIP();
|
||||
}
|
||||
|
||||
/**
|
||||
* Save location data in the session.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function saveLocation()
|
||||
{
|
||||
$this->session->set('geoip-location', $this->location);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get location from IP.
|
||||
*
|
||||
* @param string $ip Optional
|
||||
* @return array
|
||||
*/
|
||||
public function getLocation($ip = null)
|
||||
{
|
||||
// Get location data
|
||||
$this->location = $this->find($ip);
|
||||
|
||||
// Save user's location
|
||||
if ($ip === null) {
|
||||
$this->saveLocation();
|
||||
}
|
||||
|
||||
return $this->location;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find location from IP.
|
||||
*
|
||||
* @param string $ip Optional
|
||||
* @return array
|
||||
* @throws \Exception
|
||||
*/
|
||||
private function find($ip = null)
|
||||
{
|
||||
// Check Session
|
||||
if ($ip === null && $position = $this->session->get('geoip-location')) {
|
||||
return $position;
|
||||
}
|
||||
|
||||
// If IP not set, user remote IP
|
||||
if ($ip === null) {
|
||||
$ip = $this->remote_ip;
|
||||
}
|
||||
|
||||
// Check if the ip is not local or empty
|
||||
if ($this->checkIp($ip)) {
|
||||
// Get service name
|
||||
$service = 'locate_'.$this->config->get('geoip.service');
|
||||
|
||||
// Check for valid service
|
||||
if (! method_exists($this, $service)) {
|
||||
throw new \Exception("GeoIP Service not support or setup.");
|
||||
}
|
||||
|
||||
return $this->$service($ip);
|
||||
}
|
||||
|
||||
return $this->default_location;
|
||||
}
|
||||
|
||||
private $maxmind;
|
||||
|
||||
/**
|
||||
* Maxmind Service.
|
||||
*
|
||||
* @param string $ip
|
||||
* @return array
|
||||
*/
|
||||
private function locate_maxmind($ip)
|
||||
{
|
||||
$settings = $this->config->get('geoip.maxmind');
|
||||
|
||||
if (empty($this->maxmind)) {
|
||||
if ($settings['type'] === 'web_service') {
|
||||
$this->maxmind = new Client($settings['user_id'], $settings['license_key']);
|
||||
}
|
||||
else {
|
||||
$this->maxmind = new Reader($settings['database_path']);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
$record = $this->maxmind->city($ip);
|
||||
|
||||
$location = array(
|
||||
"ip" => $ip,
|
||||
"isoCode" => $record->country->isoCode,
|
||||
"country" => $record->country->name,
|
||||
"city" => $record->city->name,
|
||||
"state" => $record->mostSpecificSubdivision->isoCode,
|
||||
"postal_code" => $record->postal->code,
|
||||
"lat" => $record->location->latitude,
|
||||
"lon" => $record->location->longitude,
|
||||
"timezone" => $record->location->timeZone,
|
||||
"continent" => $record->continent->code,
|
||||
"default" => false,
|
||||
);
|
||||
}
|
||||
catch (AddressNotFoundException $e)
|
||||
{
|
||||
$location = $this->default_location;
|
||||
|
||||
$logFile = 'geoip';
|
||||
|
||||
$log = new Logger($logFile);
|
||||
$log->pushHandler(new StreamHandler(storage_path("logs/{$logFile}.log"), Logger::ERROR));
|
||||
$log->addError($e);
|
||||
}
|
||||
|
||||
unset($record);
|
||||
|
||||
return $location;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the client IP address.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getClientIP()
|
||||
{
|
||||
if (getenv('HTTP_CLIENT_IP')) {
|
||||
$ipaddress = getenv('HTTP_CLIENT_IP');
|
||||
}
|
||||
else if (getenv('HTTP_X_FORWARDED_FOR')) {
|
||||
$ipaddress = getenv('HTTP_X_FORWARDED_FOR');
|
||||
}
|
||||
else if (getenv('HTTP_X_FORWARDED')) {
|
||||
$ipaddress = getenv('HTTP_X_FORWARDED');
|
||||
}
|
||||
else if (getenv('HTTP_FORWARDED_FOR')) {
|
||||
$ipaddress = getenv('HTTP_FORWARDED_FOR');
|
||||
}
|
||||
else if (getenv('HTTP_FORWARDED')) {
|
||||
$ipaddress = getenv('HTTP_FORWARDED');
|
||||
}
|
||||
else if (getenv('REMOTE_ADDR')) {
|
||||
$ipaddress = getenv('REMOTE_ADDR');
|
||||
}
|
||||
else if (isset($_SERVER['REMOTE_ADDR'])) {
|
||||
$ipaddress = $_SERVER['REMOTE_ADDR'];
|
||||
}
|
||||
else {
|
||||
$ipaddress = '127.0.0.0';
|
||||
}
|
||||
|
||||
return $ipaddress;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the ip is not local or empty.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function checkIp($ip)
|
||||
{
|
||||
if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
|
||||
$longip = ip2long($ip);
|
||||
|
||||
if (! empty($ip)) {
|
||||
foreach ($this->reserved_ips as $r) {
|
||||
$min = ip2long($r[0]);
|
||||
$max = ip2long($r[1]);
|
||||
|
||||
if ($longip >= $min && $longip <= $max) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
} else if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
14
vendor/torann/geoip/src/Torann/GeoIP/GeoIPFacade.php
vendored
Normal file
14
vendor/torann/geoip/src/Torann/GeoIP/GeoIPFacade.php
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php namespace Torann\GeoIP;
|
||||
|
||||
use Illuminate\Support\Facades\Facade;
|
||||
|
||||
class GeoIPFacade extends Facade {
|
||||
|
||||
/**
|
||||
* Get the registered name of the component.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected static function getFacadeAccessor() { return 'geoip'; }
|
||||
|
||||
}
|
||||
57
vendor/torann/geoip/src/Torann/GeoIP/GeoIPServiceProvider.php
vendored
Normal file
57
vendor/torann/geoip/src/Torann/GeoIP/GeoIPServiceProvider.php
vendored
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php namespace Torann\GeoIP;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Torann\GeoIP\Console\UpdateCommand;
|
||||
|
||||
class GeoIPServiceProvider extends ServiceProvider {
|
||||
|
||||
/**
|
||||
* Indicates if loading of the provider is deferred.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $defer = false;
|
||||
|
||||
/**
|
||||
* Bootstrap the application events.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
$this->publishes([
|
||||
__DIR__.'/../../config/geoip.php' => config_path('geoip.php'),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the service provider.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
// Register providers.
|
||||
$this->app['geoip'] = $this->app->share(function($app)
|
||||
{
|
||||
return new GeoIP($app['config'], $app["session.store"]);
|
||||
});
|
||||
|
||||
$this->app['command.geoip.update'] = $this->app->share(function ($app)
|
||||
{
|
||||
return new UpdateCommand($app['config']);
|
||||
});
|
||||
$this->commands(['command.geoip.update']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the services provided by the provider.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function provides()
|
||||
{
|
||||
return array('geoip', 'command.geoip.update');
|
||||
}
|
||||
|
||||
}
|
||||
62
vendor/torann/geoip/src/Torann/GeoIP/GeoIPUpdater.php
vendored
Normal file
62
vendor/torann/geoip/src/Torann/GeoIP/GeoIPUpdater.php
vendored
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php namespace Torann\GeoIP;
|
||||
|
||||
use GuzzleHttp\Client as Client;
|
||||
use Illuminate\Config\Repository;
|
||||
|
||||
class GeoIPUpdater
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $config;
|
||||
|
||||
/**
|
||||
* @var Client
|
||||
*/
|
||||
protected $client;
|
||||
|
||||
/**
|
||||
* @param array $config
|
||||
*/
|
||||
public function __construct(Repository $config)
|
||||
{
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Main update function.
|
||||
*
|
||||
* @return bool|string
|
||||
*/
|
||||
public function update()
|
||||
{
|
||||
if ($this->config->get('geoip.maxmind.database_path', false)) {
|
||||
return $this->updateMaxMindDatabase();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update function for max mind database.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function updateMaxMindDatabase()
|
||||
{
|
||||
$maxMindDatabaseUrl = $this->config->get('geoip.maxmind.update_url');
|
||||
$databasePath = $this->config->get('geoip.maxmind.database_path');
|
||||
|
||||
// Download zipped database to a system temp file
|
||||
$tmpFile = tempnam(sys_get_temp_dir(), 'maxmind');
|
||||
file_put_contents($tmpFile, fopen($maxMindDatabaseUrl, 'r'));
|
||||
|
||||
// Unzip and save database
|
||||
file_put_contents($databasePath, gzopen($tmpFile, 'r'));
|
||||
|
||||
// Remove temp file
|
||||
@unlink($tmpFile);
|
||||
|
||||
return $databasePath;
|
||||
}
|
||||
}
|
||||
0
vendor/torann/geoip/src/config/.gitkeep
vendored
Normal file
0
vendor/torann/geoip/src/config/.gitkeep
vendored
Normal file
55
vendor/torann/geoip/src/config/geoip.php
vendored
Normal file
55
vendor/torann/geoip/src/config/geoip.php
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
return array(
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Service
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Current only supports 'maxmind'.
|
||||
|
|
||||
*/
|
||||
|
||||
'service' => 'maxmind',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Services settings
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Service specific settings.
|
||||
|
|
||||
*/
|
||||
|
||||
'maxmind' => array(
|
||||
'type' => env('GEOIP_DRIVER', 'database'), // database or web_service
|
||||
'user_id' => env('GEOIP_USER_ID'),
|
||||
'license_key' => env('GEOIP_LICENSE_KEY'),
|
||||
'database_path' => storage_path('app/geoip.mmdb'),
|
||||
'update_url' => 'https://geolite.maxmind.com/download/geoip/database/GeoLite2-City.mmdb.gz',
|
||||
),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Default Location
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Return when a location is not found.
|
||||
|
|
||||
*/
|
||||
|
||||
'default_location' => array (
|
||||
"ip" => "127.0.0.0",
|
||||
"isoCode" => "US",
|
||||
"country" => "United States",
|
||||
"city" => "New Haven",
|
||||
"state" => "CT",
|
||||
"postal_code" => "06510",
|
||||
"lat" => 41.31,
|
||||
"lon" => -72.92,
|
||||
"timezone" => "America/New_York",
|
||||
"continent" => "NA",
|
||||
),
|
||||
|
||||
);
|
||||
0
vendor/torann/geoip/tests/.gitkeep
vendored
Normal file
0
vendor/torann/geoip/tests/.gitkeep
vendored
Normal file
37
vendor/torann/geoip/tests/GeoIPUpdaterTest.php
vendored
Normal file
37
vendor/torann/geoip/tests/GeoIPUpdaterTest.php
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php namespace Torann\GeoIP\tests;
|
||||
|
||||
use Illuminate\Config\Repository;
|
||||
use \Torann\GeoIP\GeoIPUpdater;
|
||||
use PHPUnit_Framework_TestCase;
|
||||
|
||||
class GeoIPUpdaterTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
public function test_no_update()
|
||||
{
|
||||
$geoIPUpdater = new GeoIPUpdater(new Repository());
|
||||
$this->assertFalse($geoIPUpdater->update());
|
||||
}
|
||||
|
||||
public function test_max_mind_updater()
|
||||
{
|
||||
$database = __DIR__ . '/data/GeoLite2-City.mmdb';
|
||||
$config = new Repository([
|
||||
'geoip' => [
|
||||
'service' => 'maxmind',
|
||||
'maxmind' => [
|
||||
'type' => 'database',
|
||||
'database_path' => $database,
|
||||
'update_url' => 'https://geolite.maxmind.com/download/geoip/database/GeoLite2-Country.mmdb.gz',
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
$geoIPUpdater = new GeoIPUpdater($config);
|
||||
$this->assertEquals($geoIPUpdater->update(), $database);
|
||||
unlink($database);
|
||||
}
|
||||
}
|
||||
0
vendor/torann/geoip/tests/data/.gitkeep
vendored
Normal file
0
vendor/torann/geoip/tests/data/.gitkeep
vendored
Normal file
Reference in New Issue
Block a user