first commit
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"name": "yellowtree/geoip-detect-lib",
|
||||
"type": "library",
|
||||
"require": {
|
||||
"symfony/http-foundation": "^4.2"
|
||||
},
|
||||
"authors": [
|
||||
{
|
||||
"name": "Benjamin Pick",
|
||||
"email": "benjaminpick@github.com"
|
||||
}
|
||||
]
|
||||
}
|
||||
+131
@@ -0,0 +1,131 @@
|
||||
{
|
||||
"_readme": [
|
||||
"This file locks the dependencies of your project to a known state",
|
||||
"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": "689f4cbd126b0807e8268f1cfd775a98",
|
||||
"packages": [
|
||||
{
|
||||
"name": "symfony/http-foundation",
|
||||
"version": "v4.2.3",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/symfony/http-foundation.git",
|
||||
"reference": "8d2318b73e0a1bc75baa699d00ebe2ae8b595a39"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/symfony/http-foundation/zipball/8d2318b73e0a1bc75baa699d00ebe2ae8b595a39",
|
||||
"reference": "8d2318b73e0a1bc75baa699d00ebe2ae8b595a39",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": "^7.1.3",
|
||||
"symfony/polyfill-mbstring": "~1.1"
|
||||
},
|
||||
"require-dev": {
|
||||
"predis/predis": "~1.0",
|
||||
"symfony/expression-language": "~3.4|~4.0"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "4.2-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Symfony\\Component\\HttpFoundation\\": ""
|
||||
},
|
||||
"exclude-from-classmap": [
|
||||
"/Tests/"
|
||||
]
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Fabien Potencier",
|
||||
"email": "fabien@symfony.com"
|
||||
},
|
||||
{
|
||||
"name": "Symfony Community",
|
||||
"homepage": "https://symfony.com/contributors"
|
||||
}
|
||||
],
|
||||
"description": "Symfony HttpFoundation Component",
|
||||
"homepage": "https://symfony.com",
|
||||
"time": "2019-01-29T09:49:29+00:00"
|
||||
},
|
||||
{
|
||||
"name": "symfony/polyfill-mbstring",
|
||||
"version": "v1.10.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/symfony/polyfill-mbstring.git",
|
||||
"reference": "c79c051f5b3a46be09205c73b80b346e4153e494"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/c79c051f5b3a46be09205c73b80b346e4153e494",
|
||||
"reference": "c79c051f5b3a46be09205c73b80b346e4153e494",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.3.3"
|
||||
},
|
||||
"suggest": {
|
||||
"ext-mbstring": "For best performance"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.9-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Symfony\\Polyfill\\Mbstring\\": ""
|
||||
},
|
||||
"files": [
|
||||
"bootstrap.php"
|
||||
]
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Nicolas Grekas",
|
||||
"email": "p@tchwork.com"
|
||||
},
|
||||
{
|
||||
"name": "Symfony Community",
|
||||
"homepage": "https://symfony.com/contributors"
|
||||
}
|
||||
],
|
||||
"description": "Symfony polyfill for the Mbstring extension",
|
||||
"homepage": "https://symfony.com",
|
||||
"keywords": [
|
||||
"compatibility",
|
||||
"mbstring",
|
||||
"polyfill",
|
||||
"portable",
|
||||
"shim"
|
||||
],
|
||||
"time": "2018-09-21T13:07:52+00:00"
|
||||
}
|
||||
],
|
||||
"packages-dev": [],
|
||||
"aliases": [],
|
||||
"minimum-stability": "stable",
|
||||
"stability-flags": [],
|
||||
"prefer-stable": false,
|
||||
"prefer-lowest": false,
|
||||
"platform": [],
|
||||
"platform-dev": []
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,115 @@
|
||||
<?php
|
||||
/*
|
||||
Copyright 2013-2019 Yellow Tree, Siegen, Germany
|
||||
Author: Benjamin Pick (wp-geoip-detect| |posteo.de)
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
namespace YellowTree\GeoipDetect\Geonames;
|
||||
define ('GEOIP_DETECT_GEONAMES_COUNTRY_INFO', GEOIP_PLUGIN_DIR . '/lib/geonames/data/country-info.php');
|
||||
define ('GEOIP_DETECT_GEONAMES_COUNTRY_NAMES', GEOIP_PLUGIN_DIR . '/lib/geonames/data/country-names.php');
|
||||
define ('GEOIP_DETECT_GEONAMES_COUNTRY_FLAGS', GEOIP_PLUGIN_DIR . '/lib/geonames/data/country-flags.php');
|
||||
|
||||
class CountryInformation {
|
||||
|
||||
protected $data = array();
|
||||
|
||||
protected function lazyLoadInformation($filename) {
|
||||
if (!isset($this->data[$filename])) {
|
||||
$this->data[$filename] = require($filename);
|
||||
}
|
||||
return $this->data[$filename];
|
||||
}
|
||||
/**
|
||||
* Get all geonames Information that is known about the country with this ISO code.
|
||||
*
|
||||
* @param string $iso 2-letter ISO-Code of the country (e.g. 'DE')
|
||||
* @return array Information in record format
|
||||
*/
|
||||
public function getInformationAboutCountry($iso) {
|
||||
$data = $this->lazyLoadInformation(GEOIP_DETECT_GEONAMES_COUNTRY_INFO);
|
||||
|
||||
if ($iso == 'keys')
|
||||
return array_keys($data['countries']);
|
||||
|
||||
if (!isset($data['countries'][$iso]))
|
||||
return array();
|
||||
|
||||
$country = $data['countries'][$iso];
|
||||
if (isset($country['continent']) && is_string($country['continent']))
|
||||
$country['continent'] = $data['continents'][$country['continent']];
|
||||
return $country;
|
||||
}
|
||||
|
||||
/**
|
||||
* The Emoji representing the flag
|
||||
*
|
||||
* @param string $iso 2-letter ISO-Code of the country(e.g. 'DE')
|
||||
* @return string the emoji char
|
||||
*/
|
||||
public function getFlagEmoji($iso) {
|
||||
$data = $this->lazyLoadInformation(GEOIP_DETECT_GEONAMES_COUNTRY_FLAGS);
|
||||
|
||||
if ($iso == 'keys')
|
||||
return array_keys($data);
|
||||
|
||||
if (!isset($data[$iso]['emoji'])) return '';
|
||||
|
||||
return $data[$iso]['emoji'];
|
||||
}
|
||||
|
||||
/**
|
||||
* The tel code of a country
|
||||
*
|
||||
* @param string $iso 2-letter ISO-Code of the country(e.g. 'DE')
|
||||
* @return string the emoji char
|
||||
*/
|
||||
public function getTelephonePrefix($iso) {
|
||||
$data = $this->lazyLoadInformation(GEOIP_DETECT_GEONAMES_COUNTRY_FLAGS);
|
||||
|
||||
if ($iso == 'keys')
|
||||
return array_keys($data);
|
||||
|
||||
if (!isset($data[$iso]['tel'])) return '';
|
||||
|
||||
return $data[$iso]['tel'];
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get all country names
|
||||
* @param string/array $locales Locale of the label (if array: use the first locale available)
|
||||
* @return array ISO Codes => Label Pairs
|
||||
*/
|
||||
public function getAllCountries($locales = 'en') {
|
||||
$data = $this->lazyLoadInformation(GEOIP_DETECT_GEONAMES_COUNTRY_NAMES);
|
||||
|
||||
if ($locales === 'keys')
|
||||
return array_keys($data);
|
||||
|
||||
foreach ((array) $locales as $locale) {
|
||||
if (isset($data[$locale]))
|
||||
return $data[$locale];
|
||||
}
|
||||
return $data['en'];
|
||||
}
|
||||
}
|
||||
|
||||
// List of country names, iso, continent id.
|
||||
// List of continents
|
||||
|
||||
// List of timezones
|
||||
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
Copyright 2013-2019 Yellow Tree, Siegen, Germany
|
||||
Author: Benjamin Pick (wp-geoip-detect| |posteo.de)
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
namespace YellowTree\GeoipDetect\Lib;
|
||||
|
||||
class GetClientIp {
|
||||
protected $proxyWhitelist = [];
|
||||
protected $useProxyWhitelist = false;
|
||||
|
||||
public function __construct() {
|
||||
$this->proxyWhitelist[] = '::1';
|
||||
$this->proxyWhitelist[] = '127.0.0.1';
|
||||
}
|
||||
|
||||
public function addProxiesToWhitelist($trusted_proxies) {
|
||||
foreach ($trusted_proxies as $proxy) {
|
||||
$proxy = geoip_detect_normalize_ip($proxy);
|
||||
if ($proxy) {
|
||||
$this->proxyWhitelist[] = $proxy;
|
||||
$this->useProxyWhitelist = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function getIpsFromRemoteAddr() {
|
||||
if (!isset($_SERVER['REMOTE_ADDR']))
|
||||
return ['::1'];
|
||||
|
||||
// REMOTE_ADDR may contain multiple adresses
|
||||
$ip_list = explode(',', $_SERVER['REMOTE_ADDR']);
|
||||
|
||||
return $ip_list;
|
||||
}
|
||||
|
||||
protected function getIpsFromForwardedFor($currentIpList) {
|
||||
$ip_list_reverse = explode(',', isset($_SERVER["HTTP_X_FORWARDED_FOR"]) ? $_SERVER["HTTP_X_FORWARDED_FOR"] : '');
|
||||
|
||||
if ($this->useProxyWhitelist) {
|
||||
// Add the REMOTE_ADDR to the available IP pool
|
||||
$ip_list_reverse = array_merge($ip_list_reverse, $currentIpList);
|
||||
|
||||
$ip_list_reverse = array_filter($ip_list_reverse, function($value) {
|
||||
$value = trim($value);
|
||||
if (!$value) return false;
|
||||
return false === geoip_detect_is_ip_equal($value, $this->proxyWhitelist);
|
||||
});
|
||||
}
|
||||
|
||||
return $ip_list_reverse;
|
||||
}
|
||||
|
||||
public function getIp($useReverseProxy = false) {
|
||||
$ip_list = $this->getIpsFromRemoteAddr();
|
||||
|
||||
if ($useReverseProxy)
|
||||
{
|
||||
$ip_list = $this->getIpsFromForwardedFor($ip_list);
|
||||
}
|
||||
|
||||
// Each Proxy server append their information at the end, so the last IP is most trustworthy.
|
||||
$ip = end($ip_list);
|
||||
$ip = geoip_detect_normalize_ip($ip);
|
||||
|
||||
if (!geoip_detect_is_ip($ip))
|
||||
$ip = '::1'; // By default, use localhost
|
||||
|
||||
// this is the correct one!
|
||||
$ip = apply_filters('geoip_detect2_client_ip', $ip, $ip_list);
|
||||
|
||||
return $ip;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user