Browse Source

Move resources to own folder, add net/geoip

master
Skylar Ittner 2 months ago
parent
commit
f8e6983d23
  1. 1
      .gitignore
  2. 12
      apiconfig.php
  3. 3
      composer.json
  4. 250
      composer.lock
  5. 8
      endpoints/net.contactspam.php
  6. 39
      endpoints/net.geoip.php
  7. 5
      env.sample.php
  8. 10
      publicsite/index.html
  9. 0
      resources/net.contactspam/banneddomains.txt
  10. 0
      resources/net.contactspam/bannedips.txt
  11. 0
      resources/net.contactspam/bannedwords.txt
  12. 0
      resources/net.contactspam/toxic_ip_cidr.txt
  13. 0
      resources/net.contactspam/updatebannediplist.php

1
.gitignore

@ -1,3 +1,4 @@
/env.php
/vendor/
/nbproject/private/
/resources/net.geoip/GeoLite2-City.mmdb

12
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" => [

3
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"
}
}

250
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",

8
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"] ?? "";

39
endpoints/net.geoip.php

@ -0,0 +1,39 @@
<?php
$clientip = $_SERVER["REMOTE_ADDR"];
// Don't do this if the IP matters for security, unless you verify REMOTE_ADDR
// is an address inside Cloudflare's CDN. It's fine here though, since we're
// just turning it into a lat/lon using publicly-available data.
if (!empty($_SERVER["HTTP_CF_CONNECTING_IP"])) {
$clientip = $_SERVER["HTTP_CF_CONNECTING_IP"];
}
if (!empty($VARS["ip"])) {
$clientip = $VARS["ip"];
}
use GeoIp2\Database\Reader;
use GeoIp2\Exception\AddressNotFoundException;
try {
$reader = new Reader(env("geoip_database"));
$record = $reader->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 <a href=\"https://www.maxmind.com\">https://www.maxmind.com</a>."
]);
} catch (GeoIp2\Exception\AddressNotFoundException $ex) {
exitWithJson([
"status" => "ERROR",
"message" => "Location not found for IP address.",
"clientip" => $clientip
]);
}

5
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"
];

10
publicsite/index.html

@ -85,6 +85,11 @@
<br>latitude=23.45
<br>longitude=32.12
</li>
<li class="list-group-item">
<b>geoip</b>
<br><i>Find approximate coordinates for (by default) the client's IP address, or the IP address passed.</i>
<br>ip=10.0.0.1 (optional)
</li>
<li class="list-group-item">
<b>weather</b>
<br><i>Get the weather at a location.</i>
@ -110,6 +115,11 @@
<br>email=msgsender@gmail.com
<br>ipaddr=1.0.146.24
</li>
<li class="list-group-item">
<b>geoip</b>
<br><i>Find approximate coordinates for (by default) the client's IP address, or the IP address passed.</i>
<br>ip=10.0.0.1 (optional)
</li>
<li class="list-group-item">
<b>whois</b>
<br><i>Do a WHOIS lookup of a domain.</i>

0
endpoints/net.contactspam/banneddomains.txt → resources/net.contactspam/banneddomains.txt

0
endpoints/net.contactspam/bannedips.txt → resources/net.contactspam/bannedips.txt

0
endpoints/net.contactspam/bannedwords.txt → resources/net.contactspam/bannedwords.txt

0
endpoints/net.contactspam/toxic_ip_cidr.txt → resources/net.contactspam/toxic_ip_cidr.txt

0
endpoints/net.contactspam/updatebannediplist.php → resources/net.contactspam/updatebannediplist.php

Loading…
Cancel
Save