diff --git a/.gitignore b/.gitignore
index 4725742..25edffd 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
/env.php
/vendor/
/nbproject/private/
+/resources/net.geoip/GeoLite2-City.mmdb
diff --git a/apiconfig.php b/apiconfig.php
index 0dafcb0..e385158 100644
--- a/apiconfig.php
+++ b/apiconfig.php
@@ -27,6 +27,12 @@ $APIS = [
"longitude" => "/\-?[0-9]{1,3}(\.[0-9]{0,10})?/"
]
],
+ "gis/geoip" => [
+ "load" => "net.geoip.php",
+ "vars" => [
+ "ip (optional)" => ""
+ ]
+ ],
"gis/weather" => [
"load" => "gis.weather.php",
"vars" => [
@@ -44,6 +50,12 @@ $APIS = [
"domain (optional)" => ""
]
],
+ "net/geoip" => [
+ "load" => "net.geoip.php",
+ "vars" => [
+ "ip (optional)" => ""
+ ]
+ ],
"net/whois" => [
"load" => "net.whois.php",
"vars" => [
diff --git a/composer.json b/composer.json
index 3f0a8ba..27348a9 100644
--- a/composer.json
+++ b/composer.json
@@ -1,6 +1,7 @@
{
"require": {
"catfan/medoo": "^2.0",
- "io-developer/php-whois": "^4.0"
+ "io-developer/php-whois": "^4.0",
+ "geoip2/geoip2": "^2.11"
}
}
diff --git a/composer.lock b/composer.lock
index cb1f413..8bd0eb4 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
- "content-hash": "917e5c74de9bfe78539a7be4bb0588bc",
+ "content-hash": "38ec51243dee8ea8089b161e1f20d30f",
"packages": [
{
"name": "catfan/medoo",
@@ -78,6 +78,139 @@
],
"time": "2021-05-12T17:55:47+00:00"
},
+ {
+ "name": "composer/ca-bundle",
+ "version": "1.2.9",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/composer/ca-bundle.git",
+ "reference": "78a0e288fdcebf92aa2318a8d3656168da6ac1a5"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/composer/ca-bundle/zipball/78a0e288fdcebf92aa2318a8d3656168da6ac1a5",
+ "reference": "78a0e288fdcebf92aa2318a8d3656168da6ac1a5",
+ "shasum": ""
+ },
+ "require": {
+ "ext-openssl": "*",
+ "ext-pcre": "*",
+ "php": "^5.3.2 || ^7.0 || ^8.0"
+ },
+ "require-dev": {
+ "phpstan/phpstan": "^0.12.55",
+ "psr/log": "^1.0",
+ "symfony/phpunit-bridge": "^4.2 || ^5",
+ "symfony/process": "^2.5 || ^3.0 || ^4.0 || ^5.0"
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-main": "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"
+ ],
+ "support": {
+ "irc": "irc://irc.freenode.org/composer",
+ "issues": "https://github.com/composer/ca-bundle/issues",
+ "source": "https://github.com/composer/ca-bundle/tree/1.2.9"
+ },
+ "funding": [
+ {
+ "url": "https://packagist.com",
+ "type": "custom"
+ },
+ {
+ "url": "https://github.com/composer",
+ "type": "github"
+ },
+ {
+ "url": "https://tidelift.com/funding/github/packagist/composer/composer",
+ "type": "tidelift"
+ }
+ ],
+ "time": "2021-01-12T12:10:35+00:00"
+ },
+ {
+ "name": "geoip2/geoip2",
+ "version": "v2.11.0",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/maxmind/GeoIP2-php.git",
+ "reference": "d01be5894a5c1a3381c58c9b1795cd07f96c30f7"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/maxmind/GeoIP2-php/zipball/d01be5894a5c1a3381c58c9b1795cd07f96c30f7",
+ "reference": "d01be5894a5c1a3381c58c9b1795cd07f96c30f7",
+ "shasum": ""
+ },
+ "require": {
+ "ext-json": "*",
+ "maxmind-db/reader": "~1.8",
+ "maxmind/web-service-common": "~0.8",
+ "php": ">=7.2"
+ },
+ "require-dev": {
+ "friendsofphp/php-cs-fixer": "2.*",
+ "phpunit/phpunit": "^8.0 || ^9.0",
+ "squizlabs/php_codesniffer": "3.*"
+ },
+ "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": "https://www.maxmind.com/"
+ }
+ ],
+ "description": "MaxMind GeoIP2 PHP API",
+ "homepage": "https://github.com/maxmind/GeoIP2-php",
+ "keywords": [
+ "IP",
+ "geoip",
+ "geoip2",
+ "geolocation",
+ "maxmind"
+ ],
+ "support": {
+ "issues": "https://github.com/maxmind/GeoIP2-php/issues",
+ "source": "https://github.com/maxmind/GeoIP2-php/tree/v2.11.0"
+ },
+ "time": "2020-10-01T18:48:34+00:00"
+ },
{
"name": "io-developer/php-whois",
"version": "4.0.0",
@@ -140,6 +273,121 @@
},
"time": "2020-03-22T21:36:05+00:00"
},
+ {
+ "name": "maxmind-db/reader",
+ "version": "v1.10.1",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/maxmind/MaxMind-DB-Reader-php.git",
+ "reference": "569bd44d97d30a4ec12c7793a33004a76d4caf18"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/maxmind/MaxMind-DB-Reader-php/zipball/569bd44d97d30a4ec12c7793a33004a76d4caf18",
+ "reference": "569bd44d97d30a4ec12c7793a33004a76d4caf18",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=7.2"
+ },
+ "conflict": {
+ "ext-maxminddb": "<1.10.1,>=2.0.0"
+ },
+ "require-dev": {
+ "friendsofphp/php-cs-fixer": "*",
+ "php-coveralls/php-coveralls": "^2.1",
+ "phpstan/phpstan": "*",
+ "phpunit/phpcov": ">=6.0.0",
+ "phpunit/phpunit": ">=8.0.0,<10.0.0",
+ "squizlabs/php_codesniffer": "3.*"
+ },
+ "suggest": {
+ "ext-bcmath": "bcmath or gmp is required for decoding larger integers with the pure PHP decoder",
+ "ext-gmp": "bcmath or gmp is required 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": "https://www.maxmind.com/"
+ }
+ ],
+ "description": "MaxMind DB Reader API",
+ "homepage": "https://github.com/maxmind/MaxMind-DB-Reader-php",
+ "keywords": [
+ "database",
+ "geoip",
+ "geoip2",
+ "geolocation",
+ "maxmind"
+ ],
+ "support": {
+ "issues": "https://github.com/maxmind/MaxMind-DB-Reader-php/issues",
+ "source": "https://github.com/maxmind/MaxMind-DB-Reader-php/tree/v1.10.1"
+ },
+ "time": "2021-04-14T17:49:35+00:00"
+ },
+ {
+ "name": "maxmind/web-service-common",
+ "version": "v0.8.1",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/maxmind/web-service-common-php.git",
+ "reference": "32f274051c543fc865e5a84d3a2c703913641ea8"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/maxmind/web-service-common-php/zipball/32f274051c543fc865e5a84d3a2c703913641ea8",
+ "reference": "32f274051c543fc865e5a84d3a2c703913641ea8",
+ "shasum": ""
+ },
+ "require": {
+ "composer/ca-bundle": "^1.0.3",
+ "ext-curl": "*",
+ "ext-json": "*",
+ "php": ">=7.2"
+ },
+ "require-dev": {
+ "friendsofphp/php-cs-fixer": "2.*",
+ "phpunit/phpunit": "^8.0 || ^9.0",
+ "squizlabs/php_codesniffer": "3.*"
+ },
+ "type": "library",
+ "autoload": {
+ "psr-4": {
+ "MaxMind\\Exception\\": "src/Exception",
+ "MaxMind\\WebService\\": "src/WebService"
+ }
+ },
+ "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/web-service-common-php",
+ "support": {
+ "issues": "https://github.com/maxmind/web-service-common-php/issues",
+ "source": "https://github.com/maxmind/web-service-common-php/tree/v0.8.1"
+ },
+ "time": "2020-11-02T17:00:53+00:00"
+ },
{
"name": "symfony/polyfill-mbstring",
"version": "v1.22.1",
diff --git a/endpoints/net.contactspam.php b/endpoints/net.contactspam.php
index 2ccc526..a93263a 100644
--- a/endpoints/net.contactspam.php
+++ b/endpoints/net.contactspam.php
@@ -4,12 +4,12 @@
const MSG_MIN_CHARS = 20;
const MSG_MIN_WORDS = 5;
// Banned words check, file should be one match (word or phrase) per line
-const BANNED_WORDLIST = __DIR__ . "/net.contactspam/bannedwords.txt";
+const BANNED_WORDLIST = __DIR__ . "/../resources/net.contactspam/bannedwords.txt";
// Banned email domain check, one domain per line, useful if you get lots of spam from
// a domain your customers probably won't legitimately use
-const BANNED_DOMAINS = __DIR__ . "/net.contactspam/banneddomains.txt";
-const BANNED_IP_LIST = __DIR__ . "/net.contactspam/bannedips.txt";
-const BANNED_IP_CIDR = __DIR__ . "/net.contactspam/toxic_ip_cidr.txt";
+const BANNED_DOMAINS = __DIR__ . "/../resources/net.contactspam/banneddomains.txt";
+const BANNED_IP_LIST = __DIR__ . "/../resources/net.contactspam/bannedips.txt";
+const BANNED_IP_CIDR = __DIR__ . "/../resources/net.contactspam/toxic_ip_cidr.txt";
$message = $VARS["message"] ?? "";
$fromemail = $VARS["email"] ?? "";
diff --git a/endpoints/net.geoip.php b/endpoints/net.geoip.php
new file mode 100644
index 0000000..e3a1939
--- /dev/null
+++ b/endpoints/net.geoip.php
@@ -0,0 +1,39 @@
+city($clientip);
+
+ exitWithJson([
+ "status" => "OK",
+ "location" => [
+ "latitude" => $record->location->latitude,
+ "longitude" => $record->location->longitude
+ ],
+ "clientip" => $clientip,
+ "postcode" => $record->postal->code,
+ "attribution" => "This product includes GeoLite2 data created by MaxMind, available from https://www.maxmind.com."
+ ]);
+} catch (GeoIp2\Exception\AddressNotFoundException $ex) {
+ exitWithJson([
+ "status" => "ERROR",
+ "message" => "Location not found for IP address.",
+ "clientip" => $clientip
+ ]);
+}
diff --git a/env.sample.php b/env.sample.php
index b4fe4fd..c1f8d2c 100644
--- a/env.sample.php
+++ b/env.sample.php
@@ -39,5 +39,8 @@ $SETTINGS = [
"openweathermap_appid" => "",
"weather_summary_hours" => 8,
- "mapquest_key" => ""
+ "mapquest_key" => "",
+
+ // MaxMind GeoIP2 database
+ "geoip_database" => __DIR__ . "/resources/net.geoip/GeoLite2-City.mmdb"
];
\ No newline at end of file
diff --git a/publicsite/index.html b/publicsite/index.html
index 892038e..2169c9b 100644
--- a/publicsite/index.html
+++ b/publicsite/index.html
@@ -85,6 +85,11 @@
latitude=23.45
longitude=32.12
+