updated-packages
This commit is contained in:
4
vendor/torann/geoip/src/Console/Clear.php
vendored
4
vendor/torann/geoip/src/Console/Clear.php
vendored
@@ -22,6 +22,7 @@ class Clear extends Command
|
||||
|
||||
/**
|
||||
* Execute the console command for Laravel 5.5 and newer.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
@@ -31,6 +32,7 @@ class Clear extends Command
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function fire()
|
||||
@@ -50,7 +52,7 @@ class Clear extends Command
|
||||
protected function isSupported()
|
||||
{
|
||||
return empty(app('geoip')->config('cache_tags')) === false
|
||||
&& in_array(config('cache.default'), ['file', 'database']) === false;
|
||||
&& in_array(config('cache.default'), ['file', 'database']) === false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
5
vendor/torann/geoip/src/Console/Update.php
vendored
5
vendor/torann/geoip/src/Console/Update.php
vendored
@@ -22,6 +22,7 @@ class Update extends Command
|
||||
|
||||
/**
|
||||
* Execute the console command for Laravel 5.5 and newer.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
@@ -42,6 +43,7 @@ class Update extends Command
|
||||
// Ensure the selected service supports updating
|
||||
if (method_exists($service, 'update') === false) {
|
||||
$this->info('The current service "' . get_class($service) . '" does not support updating.');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -50,7 +52,8 @@ class Update extends Command
|
||||
// Perform update
|
||||
if ($result = $service->update()) {
|
||||
$this->info($result);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
$this->error('Update failed!');
|
||||
}
|
||||
}
|
||||
|
||||
7
vendor/torann/geoip/src/GeoIP.php
vendored
7
vendor/torann/geoip/src/GeoIP.php
vendored
@@ -133,7 +133,7 @@ class GeoIP
|
||||
{
|
||||
// If IP not set, user remote IP
|
||||
$ip = $ip ?: $this->remote_ip;
|
||||
|
||||
|
||||
// Check cache for location
|
||||
if ($this->config('cache', 'none') !== 'none' && $location = $this->getCache()->get($ip)) {
|
||||
$location->cached = true;
|
||||
@@ -161,7 +161,7 @@ class GeoIP
|
||||
if ($this->config('log_failures', true) === true) {
|
||||
$log = new Logger('geoip');
|
||||
$log->pushHandler(new StreamHandler(storage_path('logs/geoip.log'), Logger::ERROR));
|
||||
$log->addError($e);
|
||||
$log->error($e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -232,6 +232,7 @@ class GeoIP
|
||||
$remotes_keys = [
|
||||
'HTTP_X_FORWARDED_FOR',
|
||||
'HTTP_CLIENT_IP',
|
||||
'HTTP_X_REAL_IP',
|
||||
'HTTP_X_FORWARDED',
|
||||
'HTTP_FORWARDED_FOR',
|
||||
'HTTP_FORWARDED',
|
||||
@@ -284,7 +285,7 @@ class GeoIP
|
||||
return false;
|
||||
}
|
||||
|
||||
switch($this->config('cache', 'none')) {
|
||||
switch ($this->config('cache', 'none')) {
|
||||
case 'all':
|
||||
return true;
|
||||
case 'some' && $ip === null:
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Torann\GeoIP;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class GeoIPServiceProvider extends ServiceProvider
|
||||
@@ -74,6 +75,6 @@ class GeoIPServiceProvider extends ServiceProvider
|
||||
*/
|
||||
protected function isLumen()
|
||||
{
|
||||
return str_contains($this->app->version(), 'Lumen') === true;
|
||||
return Str::contains($this->app->version(), 'Lumen') === true;
|
||||
}
|
||||
}
|
||||
|
||||
17
vendor/torann/geoip/src/Location.php
vendored
17
vendor/torann/geoip/src/Location.php
vendored
@@ -130,7 +130,8 @@ class Location implements ArrayAccess
|
||||
/**
|
||||
* Determine if the given attribute exists.
|
||||
*
|
||||
* @param mixed $offset
|
||||
* @param mixed $offset
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function offsetExists($offset)
|
||||
@@ -141,7 +142,8 @@ class Location implements ArrayAccess
|
||||
/**
|
||||
* Get the value for a given offset.
|
||||
*
|
||||
* @param mixed $offset
|
||||
* @param mixed $offset
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function offsetGet($offset)
|
||||
@@ -152,8 +154,9 @@ class Location implements ArrayAccess
|
||||
/**
|
||||
* Set the value for a given offset.
|
||||
*
|
||||
* @param mixed $offset
|
||||
* @param mixed $value
|
||||
* @param mixed $offset
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function offsetSet($offset, $value)
|
||||
@@ -164,7 +167,8 @@ class Location implements ArrayAccess
|
||||
/**
|
||||
* Unset the value for a given offset.
|
||||
*
|
||||
* @param mixed $offset
|
||||
* @param mixed $offset
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function offsetUnset($offset)
|
||||
@@ -187,7 +191,8 @@ class Location implements ArrayAccess
|
||||
/**
|
||||
* Unset an attribute on the location.
|
||||
*
|
||||
* @param string $key
|
||||
* @param string $key
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __unset($key)
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace Torann\GeoIP\Services;
|
||||
|
||||
use Torann\GeoIP\GeoIP;
|
||||
use Torann\GeoIP\Location;
|
||||
use Illuminate\Support\Arr;
|
||||
use Torann\GeoIP\Contracts\ServiceInterface;
|
||||
|
||||
2
vendor/torann/geoip/src/Services/IPApi.php
vendored
2
vendor/torann/geoip/src/Services/IPApi.php
vendored
@@ -98,7 +98,7 @@ class IPApi extends AbstractService
|
||||
*/
|
||||
public function update()
|
||||
{
|
||||
$data = $this->client->get('http://dev.maxmind.com/static/csv/codes/country_continent.csv');
|
||||
$data = $this->client->get('https://dev.maxmind.com/static/csv/codes/country_continent.csv');
|
||||
|
||||
// Verify server response
|
||||
if ($this->client->getErrors() !== null) {
|
||||
|
||||
20
vendor/torann/geoip/src/Services/IPData.php
vendored
20
vendor/torann/geoip/src/Services/IPData.php
vendored
@@ -3,6 +3,7 @@
|
||||
namespace Torann\GeoIP\Services;
|
||||
|
||||
use Exception;
|
||||
use Illuminate\Support\Arr;
|
||||
use Torann\GeoIP\Support\HttpClient;
|
||||
|
||||
/**
|
||||
@@ -47,6 +48,21 @@ class IPData extends AbstractService
|
||||
throw new Exception('Request failed (' . $this->client->getErrors() . ')');
|
||||
}
|
||||
|
||||
return $this->hydrate(json_decode($data[0], true));
|
||||
$json = json_decode($data[0], true);
|
||||
|
||||
return $this->hydrate([
|
||||
'ip' => $ip,
|
||||
'iso_code' => $json['country_code'],
|
||||
'country' => $json['country_name'],
|
||||
'city' => $json['city'],
|
||||
'state' => $json['region_code'],
|
||||
'state_name' => $json['region'],
|
||||
'postal_code' => $json['postal'],
|
||||
'lat' => $json['latitude'],
|
||||
'lon' => $json['longitude'],
|
||||
'timezone' => Arr::get($json, 'time_zone.name'),
|
||||
'continent' => Arr::get($json, 'continent_code'),
|
||||
'currency' => Arr::get($json, 'currency.code'),
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
58
vendor/torann/geoip/src/Services/IPFinder.php
vendored
Normal file
58
vendor/torann/geoip/src/Services/IPFinder.php
vendored
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace Torann\GeoIP\Services;
|
||||
|
||||
use Exception;
|
||||
use Illuminate\Support\Arr;
|
||||
use Torann\GeoIP\Support\HttpClient;
|
||||
|
||||
/**
|
||||
* Class GeoIP
|
||||
* @package Torann\GeoIP\Services
|
||||
*/
|
||||
class IPFinder extends AbstractService
|
||||
{
|
||||
/**
|
||||
* Http client instance.
|
||||
*
|
||||
* @var HttpClient
|
||||
*/
|
||||
protected $client;
|
||||
|
||||
/**
|
||||
* The "booting" method of the service.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
$this->client = new HttpClient([
|
||||
'base_uri' => 'https://api.ipfinder.io/v1/',
|
||||
'headers' => [
|
||||
'User-Agent' => 'Laravel-GeoIP-Torann',
|
||||
],
|
||||
'query' => [
|
||||
'token' => $this->config('key'),
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
* @throws Exception
|
||||
*/
|
||||
public function locate($ip)
|
||||
{
|
||||
// Get data from client
|
||||
$data = $this->client->get($ip);
|
||||
|
||||
// Verify server response
|
||||
if ($this->client->getErrors() !== null || empty($data[0])) {
|
||||
throw new Exception('Request failed (' . $this->client->getErrors() . ')');
|
||||
}
|
||||
|
||||
$json = json_decode($data[0], true);
|
||||
|
||||
return $this->hydrate($json);
|
||||
}
|
||||
}
|
||||
@@ -23,11 +23,11 @@ class IPGeoLocation extends AbstractService
|
||||
public function boot()
|
||||
{
|
||||
$base = [
|
||||
'base_uri' => 'https://api.ipgeolocation.io/'
|
||||
'base_uri' => 'https://api.ipgeolocation.io/',
|
||||
];
|
||||
|
||||
if ($this->config('key')) {
|
||||
$base['base_uri'] = $base['base_uri']."ipgeo?apiKey=". $this->config('key');
|
||||
$base['base_uri'] = "{$base['base_uri']}ipgeo?apiKey=" . $this->config('key');
|
||||
}
|
||||
|
||||
$this->client = new HttpClient($base);
|
||||
@@ -48,7 +48,7 @@ class IPGeoLocation extends AbstractService
|
||||
}
|
||||
|
||||
// Parse body content
|
||||
$json = json_decode($data[0],true);
|
||||
$json = json_decode($data[0], true);
|
||||
|
||||
return $this->hydrate($json);
|
||||
|
||||
|
||||
102
vendor/torann/geoip/src/Services/MaxMindDatabase.php
vendored
102
vendor/torann/geoip/src/Services/MaxMindDatabase.php
vendored
@@ -2,9 +2,9 @@
|
||||
|
||||
namespace Torann\GeoIP\Services;
|
||||
|
||||
use PharData;
|
||||
use Exception;
|
||||
use GeoIp2\Database\Reader;
|
||||
use GeoIp2\Exception\AddressNotFoundException;
|
||||
|
||||
class MaxMindDatabase extends AbstractService
|
||||
{
|
||||
@@ -67,27 +67,97 @@ class MaxMindDatabase extends AbstractService
|
||||
throw new Exception('Database path not set in config file.');
|
||||
}
|
||||
|
||||
// Get settings
|
||||
$url = $this->config('update_url');
|
||||
$path = $this->config('database_path');
|
||||
$this->withTemporaryDirectory(function ($directory) {
|
||||
$tarFile = sprintf('%s/maxmind.tar.gz', $directory);
|
||||
|
||||
// Get header response
|
||||
$headers = get_headers($url);
|
||||
file_put_contents($tarFile, fopen($this->config('update_url'), 'r'));
|
||||
|
||||
if (substr($headers[0], 9, 3) != '200') {
|
||||
throw new Exception('Unable to download database. ('. substr($headers[0], 13) .')');
|
||||
$archive = new PharData($tarFile);
|
||||
|
||||
$file = $this->findDatabaseFile($archive);
|
||||
|
||||
$relativePath = "{$archive->getFilename()}/{$file->getFilename()}";
|
||||
|
||||
$archive->extractTo($directory, $relativePath);
|
||||
|
||||
file_put_contents($this->config('database_path'), fopen("{$directory}/{$relativePath}", 'r'));
|
||||
});
|
||||
|
||||
return "Database file ({$this->config('database_path')}) updated.";
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide a temporary directory to perform operations in and and ensure
|
||||
* it is removed afterwards.
|
||||
*
|
||||
* @param callable $callback
|
||||
* @return void
|
||||
*/
|
||||
protected function withTemporaryDirectory(callable $callback)
|
||||
{
|
||||
$directory = tempnam(sys_get_temp_dir(), 'maxmind');
|
||||
|
||||
if (file_exists($directory)) {
|
||||
unlink($directory);
|
||||
}
|
||||
|
||||
// Download zipped database to a system temp file
|
||||
$tmpFile = tempnam(sys_get_temp_dir(), 'maxmind');
|
||||
file_put_contents($tmpFile, fopen($url, 'r'));
|
||||
mkdir($directory);
|
||||
|
||||
// Unzip and save database
|
||||
file_put_contents($path, gzopen($tmpFile, 'r'));
|
||||
try {
|
||||
$callback($directory);
|
||||
} finally {
|
||||
$this->deleteDirectory($directory);
|
||||
}
|
||||
}
|
||||
|
||||
// Remove temp file
|
||||
@unlink($tmpFile);
|
||||
/**
|
||||
* Recursively search the given archive to find the .mmdb file.
|
||||
*
|
||||
* @param \PharData $archive
|
||||
* @return mixed
|
||||
* @throws \Exception
|
||||
*/
|
||||
protected function findDatabaseFile($archive)
|
||||
{
|
||||
foreach ($archive as $file) {
|
||||
if ($file->isDir()) {
|
||||
return $this->findDatabaseFile(new PharData($file->getPathName()));
|
||||
}
|
||||
|
||||
return "Database file ({$path}) updated.";
|
||||
if (pathinfo($file, PATHINFO_EXTENSION) === 'mmdb') {
|
||||
return $file;
|
||||
}
|
||||
}
|
||||
|
||||
throw new Exception('Database file could not be found within archive.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursively delete the given directory.
|
||||
*
|
||||
* @param string $directory
|
||||
* @return mixed
|
||||
*/
|
||||
protected function deleteDirectory(string $directory)
|
||||
{
|
||||
if (!file_exists($directory)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!is_dir($directory)) {
|
||||
return unlink($directory);
|
||||
}
|
||||
|
||||
foreach (scandir($directory) as $item) {
|
||||
if ($item == '.' || $item == '..') {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!$this->deleteDirectory($directory . DIRECTORY_SEPARATOR . $item)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return rmdir($directory);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
namespace Torann\GeoIP\Services;
|
||||
|
||||
use GeoIp2\WebService\Client;
|
||||
use GeoIp2\Exception\AddressNotFoundException;
|
||||
|
||||
class MaxMindWebService extends AbstractService
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user