GeoIP add

This commit is contained in:
2024-01-19 19:15:14 +01:00
parent 670ae0c5e1
commit dc50d84d48
6 changed files with 267 additions and 4 deletions

View File

@@ -0,0 +1,14 @@
<?php
namespace App\Http\Controllers;
use App\Models\IkeaProducts;
use Illuminate\Http\Request;
class GeoIPController extends Controller
{
public function index(Request $request, $ip = null)
{
return (array)geoip($ip = null)->getLocation();
}
}

View File

@@ -19,7 +19,8 @@
"paquettg/php-html-parser": "^2.2", "paquettg/php-html-parser": "^2.2",
"pusher/pusher-php-server": "^7.0", "pusher/pusher-php-server": "^7.0",
"spatie/laravel-permission": "^5.5", "spatie/laravel-permission": "^5.5",
"tightenco/ziggy": "^1.0" "tightenco/ziggy": "^1.0",
"torann/geoip": "^3.0"
}, },
"require-dev": { "require-dev": {
"barryvdh/laravel-debugbar": "^3.7", "barryvdh/laravel-debugbar": "^3.7",

82
composer.lock generated
View File

@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "86cdd8c61f5c7ee9dee51ebeae179259", "content-hash": "f8f22c83d6734feaadd1beafe3a4b702",
"packages": [ "packages": [
{ {
"name": "bacon/bacon-qr-code", "name": "bacon/bacon-qr-code",
@@ -8422,6 +8422,86 @@
}, },
"time": "2023-01-03T09:29:04+00:00" "time": "2023-01-03T09:29:04+00:00"
}, },
{
"name": "torann/geoip",
"version": "3.0.5",
"source": {
"type": "git",
"url": "https://github.com/Torann/laravel-geoip.git",
"reference": "af934013bdc073c8f4775e62cac8cc89b3de3ce6"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/Torann/laravel-geoip/zipball/af934013bdc073c8f4775e62cac8cc89b3de3ce6",
"reference": "af934013bdc073c8f4775e62cac8cc89b3de3ce6",
"shasum": ""
},
"require": {
"illuminate/cache": "^8.0|^9.0|^10.0",
"illuminate/console": "^8.0|^9.0|^10.0",
"illuminate/support": "^8.0|^9.0|^10.0",
"php": "^8.0|^8.1"
},
"require-dev": {
"geoip2/geoip2": "~2.1",
"mockery/mockery": "^1.3",
"phpstan/phpstan": "^0.12.14",
"phpunit/phpunit": "^8.0|^9.0|^10.0",
"squizlabs/php_codesniffer": "^3.5",
"vlucas/phpdotenv": "^5.0"
},
"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"
},
"laravel": {
"providers": [
"Torann\\GeoIP\\GeoIPServiceProvider"
],
"aliases": {
"GeoIP": "Torann\\GeoIP\\Facades\\GeoIP"
}
}
},
"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",
"location",
"maxmind"
],
"support": {
"issues": "https://github.com/Torann/laravel-geoip/issues",
"source": "https://github.com/Torann/laravel-geoip/tree/3.0.5"
},
"time": "2023-02-21T14:02:27+00:00"
},
{ {
"name": "ua-parser/uap-php", "name": "ua-parser/uap-php",
"version": "v3.9.14", "version": "v3.9.14",

View File

@@ -185,7 +185,7 @@ return [
/* /*
* Package Service Providers... * Package Service Providers...
*/ */
/* /*
* Application Service Providers... * Application Service Providers...
*/ */
@@ -198,6 +198,7 @@ return [
App\Providers\JetstreamServiceProvider::class, App\Providers\JetstreamServiceProvider::class,
\hisorange\BrowserDetect\ServiceProvider::class, \hisorange\BrowserDetect\ServiceProvider::class,
\Torann\GeoIP\GeoIPServiceProvider::class,
], ],
/* /*
@@ -213,6 +214,7 @@ return [
'aliases' => Facade::defaultAliases()->merge([ 'aliases' => Facade::defaultAliases()->merge([
// 'ExampleClass' => App\Example\ExampleClass::class, // 'ExampleClass' => App\Example\ExampleClass::class,
'GeoIP' => \Torann\GeoIP\Facades\GeoIP::class,
])->toArray(), ])->toArray(),
]; ];

165
config/geoip.php Normal file
View File

@@ -0,0 +1,165 @@
<?php
return [
/*
|--------------------------------------------------------------------------
| Logging Configuration
|--------------------------------------------------------------------------
|
| Here you may configure the log settings for when a location is not found
| for the IP provided.
|
*/
'log_failures' => 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' => 'ipapi',
/*
|--------------------------------------------------------------------------
| 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' => sprintf('https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-City&license_key=%s&suffix=tar.gz', env('MAXMIND_LICENSE_KEY')),
'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'),
'lang' => 'en',
],
'ipgeolocation' => [
'class' => \Torann\GeoIP\Services\IPGeoLocation::class,
'secure' => true,
'key' => env('IPGEOLOCATION_KEY'),
'continent_path' => storage_path('app/continents.json'),
'lang' => 'en',
],
'ipdata' => [
'class' => \Torann\GeoIP\Services\IPData::class,
'key' => env('IPDATA_API_KEY'),
'secure' => true,
],
'ipfinder' => [
'class' => \Torann\GeoIP\Services\IPFinder::class,
'key' => env('IPFINDER_API_KEY'),
'secure' => true,
'locales' => ['en'],
],
],
/*
|--------------------------------------------------------------------------
| 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' => 'all',
/*
|--------------------------------------------------------------------------
| 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',
],
];

View File

@@ -5,6 +5,7 @@ use Inertia\Inertia;
use App\Http\Controllers\CountryCodeController; use App\Http\Controllers\CountryCodeController;
use App\Http\Controllers\CountryCompareController; use App\Http\Controllers\CountryCompareController;
use App\Http\Controllers\CurrencyRatesController; use App\Http\Controllers\CurrencyRatesController;
use App\Http\Controllers\GeoIPController;
use App\Http\Controllers\IkeaProductsController; use App\Http\Controllers\IkeaProductsController;
use App\Http\Controllers\ProductsCompareController; use App\Http\Controllers\ProductsCompareController;
@@ -31,7 +32,7 @@ Route::get('/exchange/', function () {
})->name('exchange'); })->name('exchange');
Route::get('/menu/get', [App\Http\Controllers\Superuser\UserMenuController::class, 'get'])->name('menu.user'); Route::get('/menu/get', [App\Http\Controllers\Superuser\UserMenuController::class, 'get'])->name('menu.user');
Route::get('/ip/get/{ip?}', [GeoIPController::class, 'index'])->name('geo.ip.get');
Route::get('/ccountry/', [CountryCodeController::class, 'index'])->name('ccountry.index'); Route::get('/ccountry/', [CountryCodeController::class, 'index'])->name('ccountry.index');
Route::get('/ccountry/codes/', [CountryCodeController::class, 'codes'])->name('ccountry.codes'); Route::get('/ccountry/codes/', [CountryCodeController::class, 'codes'])->name('ccountry.codes');
Route::get('/ccountry/active/', [CountryCodeController::class, 'active'])->name('ccountry.active'); Route::get('/ccountry/active/', [CountryCodeController::class, 'active'])->name('ccountry.active');