From 7d66e655fe1eafcf7211309cf6c5d8b1314b8838 Mon Sep 17 00:00:00 2001 From: Chaoyi Zha Date: Thu, 29 Dec 2016 14:48:40 -0500 Subject: [PATCH] Add GeoIP configurations and setup hooks for adv analytics --- app/Console/Kernel.php | 2 +- app/Helpers/ClickHelper.php | 4 +- app/Http/Controllers/SetupController.php | 18 +- bootstrap/app.php | 6 +- composer.json | 4 +- composer.lock | 433 ++++++++++++++++++----- config/geoip.php | 143 ++++++++ 7 files changed, 522 insertions(+), 88 deletions(-) create mode 100644 config/geoip.php diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index ad6e311..35aca72 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -13,7 +13,7 @@ class Kernel extends ConsoleKernel * @var array */ protected $commands = [ - // + \Torann\GeoIP\Console\Update::class ]; /** diff --git a/app/Helpers/ClickHelper.php b/app/Helpers/ClickHelper.php index fbaf811..474103f 100644 --- a/app/Helpers/ClickHelper.php +++ b/app/Helpers/ClickHelper.php @@ -6,8 +6,8 @@ use Illuminate\Http\Request; class ClickHelper { static private function getCountry($ip) { - // TODO - return 'US'; + $country_iso = geoip()->getLocation($ip)->iso_code; + return $country_iso; } static private function getHost($url) { diff --git a/app/Http/Controllers/SetupController.php b/app/Http/Controllers/SetupController.php index 9528985..6b4338b 100644 --- a/app/Http/Controllers/SetupController.php +++ b/app/Http/Controllers/SetupController.php @@ -33,6 +33,13 @@ class SetupController extends Controller { return self::parseExitCode($exitCode); } + private static function updateGeoIP() { + // Output GeoIP database for advanced + // analytics + $exitCode = Artisan::call('geoip:update', []); + return self::parseExitCode($exitCode); + } + private static function createDatabase() { $exitCode = Artisan::call('migrate', [ '--force' => true, @@ -188,8 +195,8 @@ class SetupController extends Controller { // our app key changes and Laravel encrypts cookies. setcookie('setup_arguments', $setup_finish_arguments, time()+60); } - fclose($handle); + fclose($handle); return $response; } @@ -214,7 +221,14 @@ class SetupController extends Controller { $database_created = self::createDatabase(); if (!$database_created) { - return redirect(route('setup'))->with('error', 'Could not create database. Perhaps some credentials were incorrect?'); + return redirect(route('setup'))->with('error', 'Could not create database. Perhaps your credentials were incorrect?'); + } + + if (env('SETTING_ADV_ANALYTICS')) { + $geoip_db_created = self::updateGeoIP(); + if (!$geoip_db_created) { + return redirect(route('setup'))->with('error', 'Could not fetch GeoIP database for advanced analytics. Perhaps your server is not connected to the internet?'); + } } $user = UserFactory::createUser($setup_finish_args->acct_username, $setup_finish_args->acct_email, $setup_finish_args->acct_password, 1, $request->ip(), false, 0, UserHelper::$USER_ROLES['admin']); diff --git a/bootstrap/app.php b/bootstrap/app.php index b5a254a..ebf9dc2 100644 --- a/bootstrap/app.php +++ b/bootstrap/app.php @@ -20,9 +20,10 @@ $app = new Laravel\Lumen\Application( ); $app->withFacades(); - $app->withEloquent(); +$app->configure('geoip'); + /* |-------------------------------------------------------------------------- | Register Container Bindings @@ -79,7 +80,8 @@ $app->middleware([ */ $app->register(App\Providers\AppServiceProvider::class); -$app->register(Yajra\Datatables\DatatablesServiceProvider::class); +$app->register(\Yajra\Datatables\DatatablesServiceProvider::class); +$app->register(\Torann\GeoIP\GeoIPServiceProvider::class); // $app->register(App\Providers\EventServiceProvider::class); /* diff --git a/composer.json b/composer.json index c1a5c8b..e154d00 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,9 @@ "vlucas/phpdotenv": "~1.0", "illuminate/mail": "~5.1", "yajra/laravel-datatables-oracle": "~6.0", - "paragonie/random_compat": "^1.0.6" + "paragonie/random_compat": "^1.0.6", + "torann/geoip": "^1.0", + "geoip2/geoip2": "^2.4" }, "require-dev": { "fzaninotto/faker": "~1.0", diff --git a/composer.lock b/composer.lock index ea11e1a..6d4d48b 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,66 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "c9b3d1fae340ed50d76dbc8c5ec73ab2", + "content-hash": "4a670b1f52a5d12a2e5a8bf5074fd05d", "packages": [ + { + "name": "composer/ca-bundle", + "version": "1.0.6", + "source": { + "type": "git", + "url": "https://github.com/composer/ca-bundle.git", + "reference": "a795611394b3c05164fd0eb291b492b39339cba4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/composer/ca-bundle/zipball/a795611394b3c05164fd0eb291b492b39339cba4", + "reference": "a795611394b3c05164fd0eb291b492b39339cba4", + "shasum": "" + }, + "require": { + "ext-openssl": "*", + "ext-pcre": "*", + "php": "^5.3.2 || ^7.0" + }, + "require-dev": { + "psr/log": "^1.0", + "symfony/process": "^2.5 || ^3.0" + }, + "suggest": { + "symfony/process": "This is necessary to reliably check whether openssl_x509_parse is vulnerable on older php versions, but can be ignored on PHP 5.5.6+" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.x-dev" + } + }, + "autoload": { + "psr-4": { + "Composer\\CaBundle\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jordi Boggiano", + "email": "j.boggiano@seld.be", + "homepage": "http://seld.be" + } + ], + "description": "Lets you find a path to the system CA bundle, and includes a fallback to the Mozilla CA bundle.", + "keywords": [ + "cabundle", + "cacert", + "certificate", + "ssl", + "tls" + ], + "time": "2016-11-02T18:11:27+00:00" + }, { "name": "danielstjules/stringy", "version": "1.10.0", @@ -60,7 +118,7 @@ "utility", "utils" ], - "time": "2015-07-23 00:54:12" + "time": "2015-07-23T00:54:12+00:00" }, { "name": "doctrine/inflector", @@ -127,7 +185,7 @@ "singularize", "string" ], - "time": "2015-11-06 14:35:42" + "time": "2015-11-06T14:35:42+00:00" }, { "name": "dompdf/dompdf", @@ -168,7 +226,58 @@ ], "description": "DOMPDF is a CSS 2.1 compliant HTML to PDF converter", "homepage": "https://github.com/dompdf/dompdf", - "time": "2015-12-07 04:07:13" + "time": "2015-12-07T04:07:13+00:00" + }, + { + "name": "geoip2/geoip2", + "version": "v2.4.4", + "source": { + "type": "git", + "url": "https://github.com/maxmind/GeoIP2-php.git", + "reference": "57e0384a83d0935db4c4cdb3f411aa131481ae80" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/maxmind/GeoIP2-php/zipball/57e0384a83d0935db4c4cdb3f411aa131481ae80", + "reference": "57e0384a83d0935db4c4cdb3f411aa131481ae80", + "shasum": "" + }, + "require": { + "maxmind-db/reader": "~1.0", + "maxmind/web-service-common": "~0.3", + "php": ">=5.3.1" + }, + "require-dev": { + "phpunit/phpunit": "4.2.*", + "squizlabs/php_codesniffer": "2.*" + }, + "type": "library", + "autoload": { + "psr-4": { + "GeoIp2\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache-2.0" + ], + "authors": [ + { + "name": "Gregory J. Oschwald", + "email": "goschwald@maxmind.com", + "homepage": "http://www.maxmind.com/" + } + ], + "description": "MaxMind GeoIP2 PHP API", + "homepage": "https://github.com/maxmind/GeoIP2-php", + "keywords": [ + "IP", + "geoip", + "geoip2", + "geolocation", + "maxmind" + ], + "time": "2016-10-11T21:58:42+00:00" }, { "name": "illuminate/auth", @@ -218,7 +327,7 @@ ], "description": "The Illuminate Auth package.", "homepage": "http://laravel.com", - "time": "2015-12-08 14:38:44" + "time": "2015-12-08T14:38:44+00:00" }, { "name": "illuminate/broadcasting", @@ -265,7 +374,7 @@ ], "description": "The Illuminate Broadcasting package.", "homepage": "http://laravel.com", - "time": "2015-12-21 04:33:22" + "time": "2015-12-21T04:33:22+00:00" }, { "name": "illuminate/bus", @@ -310,7 +419,7 @@ ], "description": "The Illuminate Bus package.", "homepage": "http://laravel.com", - "time": "2015-12-24 19:50:28" + "time": "2015-12-24T19:50:28+00:00" }, { "name": "illuminate/cache", @@ -360,7 +469,7 @@ ], "description": "The Illuminate Cache package.", "homepage": "http://laravel.com", - "time": "2015-12-28 21:20:38" + "time": "2015-12-28T21:20:38+00:00" }, { "name": "illuminate/config", @@ -405,7 +514,7 @@ ], "description": "The Illuminate Config package.", "homepage": "http://laravel.com", - "time": "2015-06-18 02:16:31" + "time": "2015-06-18T02:16:31+00:00" }, { "name": "illuminate/console", @@ -456,7 +565,7 @@ ], "description": "The Illuminate Console package.", "homepage": "http://laravel.com", - "time": "2015-12-28 21:10:29" + "time": "2015-12-28T21:10:29+00:00" }, { "name": "illuminate/container", @@ -499,7 +608,7 @@ ], "description": "The Illuminate Container package.", "homepage": "http://laravel.com", - "time": "2015-12-07 20:20:37" + "time": "2015-12-07T20:20:37+00:00" }, { "name": "illuminate/contracts", @@ -541,7 +650,7 @@ ], "description": "The Illuminate Contracts package.", "homepage": "http://laravel.com", - "time": "2015-09-24 11:16:48" + "time": "2015-09-24T11:16:48+00:00" }, { "name": "illuminate/cookie", @@ -587,7 +696,7 @@ ], "description": "The Illuminate Cookie package.", "homepage": "http://laravel.com", - "time": "2015-12-05 16:40:16" + "time": "2015-12-05T16:40:16+00:00" }, { "name": "illuminate/database", @@ -647,7 +756,7 @@ "orm", "sql" ], - "time": "2015-12-30 23:14:26" + "time": "2015-12-30T23:14:26+00:00" }, { "name": "illuminate/encryption", @@ -696,7 +805,7 @@ ], "description": "The Illuminate Encryption package.", "homepage": "http://laravel.com", - "time": "2015-12-02 19:57:45" + "time": "2015-12-02T19:57:45+00:00" }, { "name": "illuminate/events", @@ -741,7 +850,7 @@ ], "description": "The Illuminate Events package.", "homepage": "http://laravel.com", - "time": "2015-11-29 16:58:05" + "time": "2015-11-29T16:58:05+00:00" }, { "name": "illuminate/filesystem", @@ -791,7 +900,7 @@ ], "description": "The Illuminate Filesystem package.", "homepage": "http://laravel.com", - "time": "2015-12-20 15:51:01" + "time": "2015-12-20T15:51:01+00:00" }, { "name": "illuminate/hashing", @@ -835,7 +944,7 @@ ], "description": "The Illuminate Hashing package.", "homepage": "http://laravel.com", - "time": "2015-11-29 16:58:05" + "time": "2015-11-29T16:58:05+00:00" }, { "name": "illuminate/http", @@ -881,7 +990,7 @@ ], "description": "The Illuminate Http package.", "homepage": "http://laravel.com", - "time": "2015-12-19 22:27:14" + "time": "2015-12-19T22:27:14+00:00" }, { "name": "illuminate/mail", @@ -932,7 +1041,7 @@ ], "description": "The Illuminate Mail package.", "homepage": "http://laravel.com", - "time": "2015-12-05 16:21:24" + "time": "2015-12-05T16:21:24+00:00" }, { "name": "illuminate/pagination", @@ -976,7 +1085,7 @@ ], "description": "The Illuminate Pagination package.", "homepage": "http://laravel.com", - "time": "2015-12-07 19:40:09" + "time": "2015-12-07T19:40:09+00:00" }, { "name": "illuminate/pipeline", @@ -1020,7 +1129,7 @@ ], "description": "The Illuminate Pipeline package.", "homepage": "http://laravel.com", - "time": "2015-10-05 21:58:27" + "time": "2015-10-05T21:58:27+00:00" }, { "name": "illuminate/queue", @@ -1078,7 +1187,7 @@ ], "description": "The Illuminate Queue package.", "homepage": "http://laravel.com", - "time": "2015-12-28 15:52:33" + "time": "2015-12-28T15:52:33+00:00" }, { "name": "illuminate/routing", @@ -1133,7 +1242,7 @@ ], "description": "The Illuminate Routing package.", "homepage": "http://laravel.com", - "time": "2016-07-22 13:25:32" + "time": "2016-07-22T13:25:32+00:00" }, { "name": "illuminate/session", @@ -1183,7 +1292,7 @@ ], "description": "The Illuminate Session package.", "homepage": "http://laravel.com", - "time": "2015-12-26 15:27:27" + "time": "2015-12-26T15:27:27+00:00" }, { "name": "illuminate/support", @@ -1237,7 +1346,7 @@ ], "description": "The Illuminate Support package.", "homepage": "http://laravel.com", - "time": "2015-12-28 21:10:29" + "time": "2015-12-28T21:10:29+00:00" }, { "name": "illuminate/translation", @@ -1282,7 +1391,7 @@ ], "description": "The Illuminate Translation package.", "homepage": "http://laravel.com", - "time": "2015-11-28 13:59:02" + "time": "2015-11-28T13:59:02+00:00" }, { "name": "illuminate/validation", @@ -1332,7 +1441,7 @@ ], "description": "The Illuminate Validation package.", "homepage": "http://laravel.com", - "time": "2015-12-09 15:24:53" + "time": "2015-12-09T15:24:53+00:00" }, { "name": "illuminate/view", @@ -1379,7 +1488,7 @@ ], "description": "The Illuminate View package.", "homepage": "http://laravel.com", - "time": "2015-11-29 16:58:05" + "time": "2015-11-29T16:58:05+00:00" }, { "name": "laravel/lumen-framework", @@ -1465,7 +1574,7 @@ "laravel", "lumen" ], - "time": "2015-10-28 22:19:15" + "time": "2015-10-28T22:19:15+00:00" }, { "name": "laravelcollective/html", @@ -1515,7 +1624,7 @@ "email": "adam@laravelcollective.com" } ], - "time": "2015-11-28 08:27:09" + "time": "2015-11-28T08:27:09+00:00" }, { "name": "league/fractal", @@ -1578,7 +1687,7 @@ "league", "rest" ], - "time": "2016-07-21 09:56:14" + "time": "2016-07-21T09:56:14+00:00" }, { "name": "maatwebsite/excel", @@ -1645,7 +1754,106 @@ "import", "laravel" ], - "time": "2016-09-15 21:03:21" + "time": "2016-09-15T21:03:21+00:00" + }, + { + "name": "maxmind-db/reader", + "version": "v1.1.2", + "source": { + "type": "git", + "url": "https://github.com/maxmind/MaxMind-DB-Reader-php.git", + "reference": "571279051c3339414dc91b422fb61af540c3431d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/maxmind/MaxMind-DB-Reader-php/zipball/571279051c3339414dc91b422fb61af540c3431d", + "reference": "571279051c3339414dc91b422fb61af540c3431d", + "shasum": "" + }, + "require": { + "php": ">=5.3.1" + }, + "require-dev": { + "phpunit/phpunit": "4.2.*", + "satooshi/php-coveralls": "1.0.*", + "squizlabs/php_codesniffer": "2.*" + }, + "suggest": { + "ext-bcmath": "bcmath or gmp is requred for decoding larger integers with the pure PHP decoder", + "ext-gmp": "bcmath or gmp is requred for decoding larger integers with the pure PHP decoder", + "ext-maxminddb": "A C-based database decoder that provides significantly faster lookups" + }, + "type": "library", + "autoload": { + "psr-4": { + "MaxMind\\Db\\": "src/MaxMind/Db" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache-2.0" + ], + "authors": [ + { + "name": "Gregory J. Oschwald", + "email": "goschwald@maxmind.com", + "homepage": "http://www.maxmind.com/" + } + ], + "description": "MaxMind DB Reader API", + "homepage": "https://github.com/maxmind/MaxMind-DB-Reader-php", + "keywords": [ + "database", + "geoip", + "geoip2", + "geolocation", + "maxmind" + ], + "time": "2016-11-21T21:33:24+00:00" + }, + { + "name": "maxmind/web-service-common", + "version": "v0.3.1", + "source": { + "type": "git", + "url": "https://github.com/maxmind/web-service-common-php.git", + "reference": "1fe780bcd6a9038b7e36b13fa0aeeeeca4cdb0a4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/maxmind/web-service-common-php/zipball/1fe780bcd6a9038b7e36b13fa0aeeeeca4cdb0a4", + "reference": "1fe780bcd6a9038b7e36b13fa0aeeeeca4cdb0a4", + "shasum": "" + }, + "require": { + "composer/ca-bundle": "^1.0.3", + "ext-curl": "*", + "ext-json": "*", + "php": ">=5.3" + }, + "require-dev": { + "phpunit/phpunit": "4.*", + "squizlabs/php_codesniffer": "2.*" + }, + "type": "library", + "autoload": { + "psr-4": { + "MaxMind\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache-2.0" + ], + "authors": [ + { + "name": "Gregory Oschwald", + "email": "goschwald@maxmind.com" + } + ], + "description": "Internal MaxMind Web Service API", + "homepage": "https://github.com/maxmind/mm-web-service-api-php", + "time": "2016-08-18T16:36:52+00:00" }, { "name": "monolog/monolog", @@ -1722,7 +1930,7 @@ "logging", "psr-3" ], - "time": "2015-10-14 12:51:02" + "time": "2015-10-14T12:51:02+00:00" }, { "name": "mtdowling/cron-expression", @@ -1766,7 +1974,7 @@ "cron", "schedule" ], - "time": "2016-01-26 21:23:30" + "time": "2016-01-26T21:23:30+00:00" }, { "name": "nesbot/carbon", @@ -1813,7 +2021,7 @@ "datetime", "time" ], - "time": "2015-11-04 20:07:17" + "time": "2015-11-04T20:07:17+00:00" }, { "name": "nikic/fast-route", @@ -1856,7 +2064,7 @@ "router", "routing" ], - "time": "2015-02-26 15:33:07" + "time": "2015-02-26T15:33:07+00:00" }, { "name": "paragonie/random_compat", @@ -1904,7 +2112,7 @@ "pseudorandom", "random" ], - "time": "2016-03-18 20:34:03" + "time": "2016-03-18T20:34:03+00:00" }, { "name": "phenx/php-font-lib", @@ -1938,7 +2146,7 @@ ], "description": "A library to read, parse, export and make subsets of different types of font files.", "homepage": "https://github.com/PhenX/php-font-lib", - "time": "2014-02-01 15:22:28" + "time": "2014-02-01T15:22:28+00:00" }, { "name": "phpoffice/phpexcel", @@ -1995,7 +2203,7 @@ "xls", "xlsx" ], - "time": "2015-05-01 07:00:55" + "time": "2015-05-01T07:00:55+00:00" }, { "name": "psr/log", @@ -2033,7 +2241,7 @@ "psr", "psr-3" ], - "time": "2012-12-21 11:40:51" + "time": "2012-12-21T11:40:51+00:00" }, { "name": "swiftmailer/swiftmailer", @@ -2086,7 +2294,7 @@ "mail", "mailer" ], - "time": "2015-06-06 14:19:39" + "time": "2015-06-06T14:19:39+00:00" }, { "name": "symfony/console", @@ -2145,7 +2353,7 @@ ], "description": "Symfony Console Component", "homepage": "https://symfony.com", - "time": "2016-01-14 08:26:43" + "time": "2016-01-14T08:26:43+00:00" }, { "name": "symfony/css-selector", @@ -2198,7 +2406,7 @@ ], "description": "Symfony CssSelector Component", "homepage": "https://symfony.com", - "time": "2016-01-27 05:14:46" + "time": "2016-01-27T05:14:46+00:00" }, { "name": "symfony/debug", @@ -2255,7 +2463,7 @@ ], "description": "Symfony Debug Component", "homepage": "https://symfony.com", - "time": "2016-01-13 10:28:07" + "time": "2016-01-13T10:28:07+00:00" }, { "name": "symfony/dom-crawler", @@ -2310,7 +2518,7 @@ ], "description": "Symfony DomCrawler Component", "homepage": "https://symfony.com", - "time": "2016-01-03 15:32:00" + "time": "2016-01-03T15:32:00+00:00" }, { "name": "symfony/event-dispatcher", @@ -2370,7 +2578,7 @@ ], "description": "Symfony EventDispatcher Component", "homepage": "https://symfony.com", - "time": "2016-01-13 10:28:07" + "time": "2016-01-13T10:28:07+00:00" }, { "name": "symfony/finder", @@ -2419,7 +2627,7 @@ ], "description": "Symfony Finder Component", "homepage": "https://symfony.com", - "time": "2016-01-14 08:26:43" + "time": "2016-01-14T08:26:43+00:00" }, { "name": "symfony/http-foundation", @@ -2474,7 +2682,7 @@ ], "description": "Symfony HttpFoundation Component", "homepage": "https://symfony.com", - "time": "2016-01-13 10:26:43" + "time": "2016-01-13T10:26:43+00:00" }, { "name": "symfony/http-kernel", @@ -2556,7 +2764,7 @@ ], "description": "Symfony HttpKernel Component", "homepage": "https://symfony.com", - "time": "2016-01-14 10:41:45" + "time": "2016-01-14T10:41:45+00:00" }, { "name": "symfony/process", @@ -2605,7 +2813,7 @@ ], "description": "Symfony Process Component", "homepage": "https://symfony.com", - "time": "2016-01-06 09:57:37" + "time": "2016-01-06T09:57:37+00:00" }, { "name": "symfony/routing", @@ -2679,7 +2887,7 @@ "uri", "url" ], - "time": "2016-08-16 10:55:04" + "time": "2016-08-16T10:55:04+00:00" }, { "name": "symfony/security-core", @@ -2744,7 +2952,7 @@ ], "description": "Symfony Security Component - Core Library", "homepage": "https://symfony.com", - "time": "2016-01-14 09:08:21" + "time": "2016-01-14T09:08:21+00:00" }, { "name": "symfony/translation", @@ -2807,7 +3015,7 @@ ], "description": "Symfony Translation Component", "homepage": "https://symfony.com", - "time": "2016-01-03 15:32:00" + "time": "2016-01-03T15:32:00+00:00" }, { "name": "symfony/var-dumper", @@ -2866,7 +3074,7 @@ "debug", "dump" ], - "time": "2016-01-07 11:12:32" + "time": "2016-01-07T11:12:32+00:00" }, { "name": "tijsverkoyen/css-to-inline-styles", @@ -2913,7 +3121,72 @@ ], "description": "CssToInlineStyles is a class that enables you to convert HTML-pages/files into HTML-pages/files with inline styles. This is very useful when you're sending emails.", "homepage": "https://github.com/tijsverkoyen/CssToInlineStyles", - "time": "2015-12-08 16:14:14" + "time": "2015-12-08T16:14:14+00:00" + }, + { + "name": "torann/geoip", + "version": "1.0.2", + "source": { + "type": "git", + "url": "https://github.com/Torann/laravel-geoip.git", + "reference": "ae77f4ad99926fa35c89378f00a6a7295a7246ea" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Torann/laravel-geoip/zipball/ae77f4ad99926fa35c89378f00a6a7295a7246ea", + "reference": "ae77f4ad99926fa35c89378f00a6a7295a7246ea", + "shasum": "" + }, + "require": { + "illuminate/console": "~5.0", + "illuminate/support": "~5.0", + "php": ">=5.5.9" + }, + "require-dev": { + "geoip2/geoip2": "~2.1", + "mockery/mockery": "^0.9.4", + "phpunit/phpunit": "^4.8" + }, + "suggest": { + "geoip2/geoip2": "Required to use the MaxMind database or web service with GeoIP (~2.1).", + "monolog/monolog": "Allows for storing location not found errors to the log" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "files": [ + "src/helpers.php" + ], + "psr-4": { + "Torann\\GeoIP\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD 2-Clause" + ], + "authors": [ + { + "name": "Daniel Stainback", + "email": "torann@gmail.com" + } + ], + "description": "Support for multiple GeoIP services.", + "keywords": [ + "IP API", + "geoip", + "geolocation", + "infoDB", + "laravel", + "laravel 5", + "location", + "maxmind" + ], + "time": "2016-10-17T17:29:40+00:00" }, { "name": "vlucas/phpdotenv", @@ -2959,7 +3232,7 @@ "env", "environment" ], - "time": "2015-05-30 15:59:26" + "time": "2015-05-30T15:59:26+00:00" }, { "name": "yajra/laravel-datatables-oracle", @@ -3019,7 +3292,7 @@ "laravel4", "laravel5" ], - "time": "2016-08-10 00:31:22" + "time": "2016-08-10T00:31:22+00:00" } ], "packages-dev": [ @@ -3075,7 +3348,7 @@ "constructor", "instantiate" ], - "time": "2015-06-14 21:17:01" + "time": "2015-06-14T21:17:01+00:00" }, { "name": "fzaninotto/faker", @@ -3127,7 +3400,7 @@ "faker", "fixtures" ], - "time": "2015-05-29 06:29:14" + "time": "2015-05-29T06:29:14+00:00" }, { "name": "myclabs/deep-copy", @@ -3169,7 +3442,7 @@ "object", "object graph" ], - "time": "2015-11-07 22:20:37" + "time": "2015-11-07T22:20:37+00:00" }, { "name": "phpdocumentor/reflection-docblock", @@ -3218,7 +3491,7 @@ "email": "mike.vanriel@naenius.com" } ], - "time": "2015-02-03 12:10:50" + "time": "2015-02-03T12:10:50+00:00" }, { "name": "phpspec/prophecy", @@ -3278,7 +3551,7 @@ "spy", "stub" ], - "time": "2015-08-13 10:07:40" + "time": "2015-08-13T10:07:40+00:00" }, { "name": "phpunit/php-code-coverage", @@ -3341,7 +3614,7 @@ "testing", "xunit" ], - "time": "2016-02-13 06:47:56" + "time": "2016-02-13T06:47:56+00:00" }, { "name": "phpunit/php-file-iterator", @@ -3388,7 +3661,7 @@ "filesystem", "iterator" ], - "time": "2015-06-21 13:08:43" + "time": "2015-06-21T13:08:43+00:00" }, { "name": "phpunit/php-text-template", @@ -3429,7 +3702,7 @@ "keywords": [ "template" ], - "time": "2015-06-21 13:50:34" + "time": "2015-06-21T13:50:34+00:00" }, { "name": "phpunit/php-timer", @@ -3470,7 +3743,7 @@ "keywords": [ "timer" ], - "time": "2015-06-21 08:01:12" + "time": "2015-06-21T08:01:12+00:00" }, { "name": "phpunit/php-token-stream", @@ -3519,7 +3792,7 @@ "keywords": [ "tokenizer" ], - "time": "2015-09-15 10:49:45" + "time": "2015-09-15T10:49:45+00:00" }, { "name": "phpunit/phpunit", @@ -3593,7 +3866,7 @@ "testing", "xunit" ], - "time": "2016-02-13 06:58:29" + "time": "2016-02-13T06:58:29+00:00" }, { "name": "phpunit/phpunit-mock-objects", @@ -3649,7 +3922,7 @@ "mock", "xunit" ], - "time": "2015-12-08 08:47:06" + "time": "2015-12-08T08:47:06+00:00" }, { "name": "sebastian/code-unit-reverse-lookup", @@ -3694,7 +3967,7 @@ ], "description": "Looks up which function or method a line of code belongs to", "homepage": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/", - "time": "2016-02-13 06:45:14" + "time": "2016-02-13T06:45:14+00:00" }, { "name": "sebastian/comparator", @@ -3758,7 +4031,7 @@ "compare", "equality" ], - "time": "2015-07-26 15:48:44" + "time": "2015-07-26T15:48:44+00:00" }, { "name": "sebastian/diff", @@ -3810,7 +4083,7 @@ "keywords": [ "diff" ], - "time": "2015-12-08 07:14:41" + "time": "2015-12-08T07:14:41+00:00" }, { "name": "sebastian/environment", @@ -3860,7 +4133,7 @@ "environment", "hhvm" ], - "time": "2015-12-02 08:37:27" + "time": "2015-12-02T08:37:27+00:00" }, { "name": "sebastian/exporter", @@ -3926,7 +4199,7 @@ "export", "exporter" ], - "time": "2015-06-21 07:55:53" + "time": "2015-06-21T07:55:53+00:00" }, { "name": "sebastian/global-state", @@ -3977,7 +4250,7 @@ "keywords": [ "global state" ], - "time": "2015-10-12 03:26:01" + "time": "2015-10-12T03:26:01+00:00" }, { "name": "sebastian/recursion-context", @@ -4030,7 +4303,7 @@ ], "description": "Provides functionality to recursively process PHP variables", "homepage": "http://www.github.com/sebastianbergmann/recursion-context", - "time": "2015-11-11 19:50:13" + "time": "2015-11-11T19:50:13+00:00" }, { "name": "sebastian/resource-operations", @@ -4072,7 +4345,7 @@ ], "description": "Provides a list of PHP built-in functions that operate on resources", "homepage": "https://www.github.com/sebastianbergmann/resource-operations", - "time": "2015-07-28 20:34:47" + "time": "2015-07-28T20:34:47+00:00" }, { "name": "sebastian/version", @@ -4115,7 +4388,7 @@ ], "description": "Library that helps with managing the version number of Git-hosted PHP projects", "homepage": "https://github.com/sebastianbergmann/version", - "time": "2016-02-04 12:56:52" + "time": "2016-02-04T12:56:52+00:00" }, { "name": "symfony/yaml", @@ -4164,7 +4437,7 @@ ], "description": "Symfony Yaml Component", "homepage": "https://symfony.com", - "time": "2016-02-02 13:44:19" + "time": "2016-02-02T13:44:19+00:00" } ], "aliases": [], diff --git a/config/geoip.php b/config/geoip.php new file mode 100644 index 0000000..7713d0d --- /dev/null +++ b/config/geoip.php @@ -0,0 +1,143 @@ + true, + + /* + |-------------------------------------------------------------------------- + | Include Currency in Results + |-------------------------------------------------------------------------- + | + | When enabled the system will do it's best in deciding the user's currency + | by matching their ISO code to a preset list of currencies. + | + */ + + 'include_currency' => true, + + /* + |-------------------------------------------------------------------------- + | Default Service + |-------------------------------------------------------------------------- + | + | Here you may specify the default storage driver that should be used + | by the framework. + | + | Supported: "maxmind_database", "maxmind_api", "ipapi" + | + */ + + 'service' => 'maxmind_database', + + /* + |-------------------------------------------------------------------------- + | Storage Specific Configuration + |-------------------------------------------------------------------------- + | + | Here you may configure as many storage drivers as you wish. + | + */ + + 'services' => [ + + 'maxmind_database' => [ + 'class' => \Torann\GeoIP\Services\MaxMindDatabase::class, + 'database_path' => storage_path('app/geoip.mmdb'), + 'update_url' => 'https://geolite.maxmind.com/download/geoip/database/GeoLite2-City.mmdb.gz', + 'locales' => ['en'], + ], + + 'maxmind_api' => [ + 'class' => \Torann\GeoIP\Services\MaxMindWebService::class, + 'user_id' => env('MAXMIND_USER_ID'), + 'license_key' => env('MAXMIND_LICENSE_KEY'), + 'locales' => ['en'], + ], + + 'ipapi' => [ + 'class' => \Torann\GeoIP\Services\IPApi::class, + 'secure' => true, + 'key' => env('IPAPI_KEY'), + 'continent_path' => storage_path('app/continents.json'), + ], + + ], + + /* + |-------------------------------------------------------------------------- + | Default Cache Driver + |-------------------------------------------------------------------------- + | + | Here you may specify the type of caching that should be used + | by the package. + | + | Options: + | + | all - All location are cached + | some - Cache only the requesting user + | none - Disable cached + | + */ + + 'cache' => 'none', + + /* + |-------------------------------------------------------------------------- + | Cache Tags + |-------------------------------------------------------------------------- + | + | Cache tags are not supported when using the file or database cache + | drivers in Laravel. This is done so that only locations can be cleared. + | + */ + + // 'cache_tags' => ['torann-geoip-location'], + + /* + |-------------------------------------------------------------------------- + | Cache Expiration + |-------------------------------------------------------------------------- + | + | Define how long cached location are valid. + | + */ + + 'cache_expires' => 30, + + /* + |-------------------------------------------------------------------------- + | Default Location + |-------------------------------------------------------------------------- + | + | Return when a location is not found. + | + */ + + 'default_location' => [ + 'ip' => '127.0.0.0', + 'iso_code' => 'US', + 'country' => 'United States', + 'city' => 'New Haven', + 'state' => 'CT', + 'state_name' => 'Connecticut', + 'postal_code' => '06510', + 'lat' => 41.31, + 'lon' => -72.92, + 'timezone' => 'America/New_York', + 'continent' => 'NA', + 'default' => true, + 'currency' => 'USD', + ], + +];