From 8eb6bbc8f0a0463470b4b090120a1a7e011eccfa Mon Sep 17 00:00:00 2001 From: trashbo4t Date: Sun, 28 Oct 2018 19:38:47 -0400 Subject: [PATCH] added module "Locate" (#46) Geolocate IPs --- Locate/api/module.php | 107 ++++++++++++++++++++++++++ Locate/ips/all | 0 Locate/js/module.js | 93 +++++++++++++++++++++++ Locate/module.html | 171 ++++++++++++++++++++++++++++++++++++++++++ Locate/module.info | 10 +++ 5 files changed, 381 insertions(+) create mode 100644 Locate/api/module.php create mode 100644 Locate/ips/all create mode 100644 Locate/js/module.js create mode 100644 Locate/module.html create mode 100644 Locate/module.info diff --git a/Locate/api/module.php b/Locate/api/module.php new file mode 100644 index 0000000..4b2271d --- /dev/null +++ b/Locate/api/module.php @@ -0,0 +1,107 @@ +request->action) { + case 'lookupIP': + $this->lookupIP(); + break; + case 'getIPFromFile': + $this->getIPFromFile(); + break; + case 'getIPs': + $this->getIPs(); + break; + } + } + public function getJson($link, $file) + { + $cmd = "wget -q $link -O $file"; + exec($cmd); + + return $this->getIPFile($file); + } + public function makeLink($ip) + { + return "https://ipapi.co/{$ip}/json"; + } + public function addToIPFile($ip) + { + exec("echo {$ip} >> {$this->ALL_IP_FILE}"); + } + public function touchIPFile($ip) + { + if ($ip == null) + { + exec("touch {$this->ALL_IP_FILE}"); + return "{$this->ALL_IP_FILE}"; + } + else + { + exec("touch {$this->IP_DIR}/{$ip}"); + return "{$this->IP_DIR}/{$ip}"; + } + } + public function getIPFile($file) + { + return file_get_contents($file); + } + public function makeIPDir() + { + exec("mkdir {$this->IP_DIR}"); + } + /* + * getIP + * return the json blob associated with an IP via file contents + */ + public function getIPFromFile() + { + $this->makeIPDir(); + $file = $this->touchIPFile($this->request->ip); + $json = $this->getIPFile($file); + $this->response = $json; + } + /* + * lookupIP + * return the json blob associated with an IP via wget + */ + public function lookupIP() + { + $this->makeIPDir(); + + $file = $this->touchIPFile($this->request->ip); + $link = $this->makeLink($this->request->ip); + + $json = $this->getJson($link, $file); + + $this->addToIpFile($this->request->ip); + $this->response = $json; + } + /* + * getIPs + * return the ips file as an array + */ + public function getIPs() + { + $this->makeIPDir(); + $this->touchIPFile(); + + $this->response = array(); + + $lines = file($this->ALL_IP_FILE); + foreach ($lines as $line) + { + array_push($this->response, $line); + } + } +} diff --git a/Locate/ips/all b/Locate/ips/all new file mode 100644 index 0000000..e69de29 diff --git a/Locate/js/module.js b/Locate/js/module.js new file mode 100644 index 0000000..90a3638 --- /dev/null +++ b/Locate/js/module.js @@ -0,0 +1,93 @@ +registerController("LocateController", ['$api', '$scope','$window','$route', '$http', function ($api, $scope, $window, $route, $http) { + + /* + * Author: trashbo4t (github.com/trashbo4t) + */ + getIPs(); + + $scope.ips = []; + $scope.throbber = true; + $scope.loading = "Loading"; + $scope.working = "working..."; + $scope.library = true; + $scope.currentIP = false; + $scope.currentIPData = {}; + $scope.ipToLookup = ""; + + function getIPs() { + $api.request({ + module: "Locate", + action: "getIPs" + }, function (response) { + console.log("getIPs", response); + for (var i = 0; i < response.length; i++) { + var ok = $scope.ips.includes(response[i]) + if (!ok) + { + $scope.ips.push(response[i]); + } + } + }); + }; + + $scope.reloadPage = function () { + $scope.currentIP = false; + $window.location.reload() + }; + + $scope.getIPFromFile = function (ip) { + ip = ip.replace(/(\r\n\t|\n|\r\t)/gm,""); + $scope.ipToLookup = ip; + + $api.request({ + module: "Locate", + action: "getIPFromFile", + ip: $scope.ipToLookup + }, function (response) { + console.log("getIP", response); + $scope.currentIP = $scope.ipToLookup; + + if (response == false) + { + $scope.currentIPData = "Invalid IP address.."; + } + else + { + $scope.currentIPData = JSON.parse(response); + } + + $scope.library = false; + }); + }; + + $scope.lookupIP = function (ip) { + $scope.loading = "Loading"; + $scope.working = "working..."; + $scope.throbber = true; + + ip = ip.replace(/(\r\n\t|\n|\r\t)/gm,""); + $scope.ipToLookup = ip; + + $api.request({ + module: "Locate", + action: "lookupIP", + ip: $scope.ipToLookup + }, function (response) { + console.log("lookupIP", response); + $scope.currentIP = $scope.ipToLookup; + if (response == false) + { + $scope.currentIPData = "Invalid IP address...you may wish to verify you are connected to the internet as well"; + } + else + { + $scope.currentIPData = JSON.parse(response); + } + $scope.working = "click anywhere to continue"; + $scope.loading = "Done"; + $scope.library = false; + $scope.throbber = false; + }); + + }; +}]); diff --git a/Locate/module.html b/Locate/module.html new file mode 100644 index 0000000..aabf0e5 --- /dev/null +++ b/Locate/module.html @@ -0,0 +1,171 @@ + + + + +
+
+
+ +
+
+
Locate
+
+ +
+
+
+ + + + +
+ +
+ +
+
+ + + + + + + + + + + + +
History
+ + {{ ip }} + +
+
+
+ +
+

+ Looks like there are no IPs to display... +

+
+ +
+ +
+

{{ currentIP }}

+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Information
IP {{ currentIPData["ip"] }}
City {{ currentIPData["city"] }}
Region {{ currentIPData["region"] }}
Region Code {{ currentIPData["region_code"] }}
Country {{ currentIPData["country"] }}
Country Name {{ currentIPData["country_name"] }}
Continent Code {{ currentIPData["continent_code"] }}
EU {{ currentIPData["in_eu"] }}
Postal {{ currentIPData["postal"] }}
Latitude {{ currentIPData["latitude"] }}
Longitude {{ currentIPData["longitude"] }}
Timezone {{ currentIPData["timezone"] }}
UTC Offset {{ currentIPData["utc_offset"] }}
Country Calling Code {{ currentIPData["country_calling_code"] }}
Currency {{ currentIPData["currency"] }}
Languages {{ currentIPData["languages"] }}
+
+
+ +
+
+
+
+ +
+
+ + + + diff --git a/Locate/module.info b/Locate/module.info new file mode 100644 index 0000000..505a626 --- /dev/null +++ b/Locate/module.info @@ -0,0 +1,10 @@ +{ + "author": "trashbo4t", + "devices": [ + "nano", + "tetra" + ], + "title": "Locate", + "description": "geolocate IP addresses over HTTPS via ipapi", + "version": "1.0" +}