aboutsummaryrefslogtreecommitdiff
path: root/admin/api
diff options
context:
space:
mode:
authorMinteck <nekostarfan@gmail.com>2021-08-08 18:27:46 +0200
committerMinteck <nekostarfan@gmail.com>2021-08-08 18:27:46 +0200
commita20dff82a7e2602738f847fa4f1428af3235aafc (patch)
treee607db59fd59561c055a1b68b29d1cf3c6c99d4e /admin/api
parentc69d44149f544cc80fbe32c26dc4c34266d97bf6 (diff)
downloadmain-a20dff82a7e2602738f847fa4f1428af3235aafc.tar.gz
main-a20dff82a7e2602738f847fa4f1428af3235aafc.tar.bz2
main-a20dff82a7e2602738f847fa4f1428af3235aafc.zip
Updating... the update... that updates
Diffstat (limited to 'admin/api')
-rw-r--r--admin/api/getIpLocation.php38
1 files changed, 38 insertions, 0 deletions
diff --git a/admin/api/getIpLocation.php b/admin/api/getIpLocation.php
new file mode 100644
index 0000000..fe34438
--- /dev/null
+++ b/admin/api/getIpLocation.php
@@ -0,0 +1,38 @@
+<?php
+
+require_once $_SERVER['DOCUMENT_ROOT'] . "/admin/private/header.api.php";
+
+if (isset($_GET['_']) && strpos($_GET['_'], "/") === false) {
+ $arg = $_GET['_'];
+} else {
+ die();
+}
+
+if (!file_exists($_SERVER['DOCUMENT_ROOT'] . "/admin/private/ipcache.json")) {
+ file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/admin/private/ipcache.json", "[]");
+}
+
+$ipCache = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/admin/private/ipcache.json"), true);
+
+$data = null;
+foreach ($ipCache as $ip => $item) {
+ if ($ip === $_GET['_']) {
+ $data = $item;
+ }
+}
+
+if ($data === null) {
+ $data = unserialize(file_get_contents('http://www.geoplugin.net/php.gp?ip=' . $arg));
+ $ipCache[$_GET['_']] = $data;
+ file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/admin/private/ipcache.json", json_encode($ipCache));
+}
+
+if ($data["geoplugin_status"] === 404) {
+ die("<span class='text-muted'>Local IP address</span>");
+} else {
+ if ($data["geoplugin_inEU"]) {
+ die($data["geoplugin_countryName"] . " <span class='badge text-light border-light' style='border:1px solid;vertical-align: middle;'>EU</span>");
+ } else {
+ die($data["geoplugin_countryName"]);
+ }
+} \ No newline at end of file