parent
c7ae8dc93c
commit
8eb6bbc8f0
|
@ -0,0 +1,107 @@
|
|||
<?php namespace pineapple;
|
||||
|
||||
/*
|
||||
* Author: trashbo4t (github.com/trashbo4t)
|
||||
*/
|
||||
|
||||
class Locate extends Module
|
||||
{
|
||||
// CONSTANTS
|
||||
private $IP_DIR = '/pineapple/modules/Locate/ips';
|
||||
private $ALL_IP_FILE = '/pineapple/modules/Locate/ips/all';
|
||||
|
||||
public function route()
|
||||
{
|
||||
switch ($this->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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
});
|
||||
|
||||
};
|
||||
}]);
|
|
@ -0,0 +1,171 @@
|
|||
<!-- Author -->
|
||||
<!-- trashbo4t -->
|
||||
<!-- (github.com/trashbo4t) -->
|
||||
|
||||
<div class="row" ng-controller="LocateController">
|
||||
<div class="panel-group" id="accordion">
|
||||
<div class="col-md-9">
|
||||
<!-- Library panel -->
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<h5 class="panel-title"><a href="javascript:;" data-toggle="collapse" data-parent="#accordion"
|
||||
data-target="#collapseLibrary" class="text-muted">Locate</a></h5>
|
||||
</div>
|
||||
|
||||
<div id="collapseLibrary" class="panel-collapse collapse in">
|
||||
<div class="panel-body">
|
||||
<div class="input-group" ng-show="currentIP == false">
|
||||
<input type="text" class="form-control" placeholder="IP" name="ipToLookup" ng-model="ipToLookup">
|
||||
<span class="input-group-btn">
|
||||
<button ng-disabled="ipToLookup == ''"
|
||||
data-toggle="modal"
|
||||
data-target="#loadingModal"
|
||||
class="btn btn-default"
|
||||
type="button"
|
||||
ng-click="lookupIP(ipToLookup)">Lookup</button>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<hr ng-show="currentIP == false"/>
|
||||
|
||||
<div ng-show="ips.length > 0 && currentIP == false">
|
||||
<div class="table-responsive">
|
||||
<table class="table table-striped" align="center">
|
||||
<thead>
|
||||
<th>History</th>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
<tr ng-repeat="ip in ips">
|
||||
<td>
|
||||
<a href="javascript:;" ng-click="getIPFromFile(ip)">
|
||||
<b>{{ ip }}</b>
|
||||
</a>
|
||||
</td>
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div ng-hide="ips.length != 0">
|
||||
<p class="text-muted text-center">
|
||||
<i>Looks like there are no IPs to display...</i>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div ng-show="currentIP != false">
|
||||
<button type="submit" class="btn btn-default btn-sm" ng-click="reloadPage()">Back</button>
|
||||
<hr />
|
||||
<h3>{{ currentIP }}</h3>
|
||||
|
||||
<div class="table-responsive">
|
||||
<table class="table table-striped" align="center">
|
||||
<thead>
|
||||
<th>Information</th>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>IP</td>
|
||||
<td> {{ currentIPData["ip"] }} </td>
|
||||
</tr>
|
||||
|
||||
<tr><td>City</td>
|
||||
<td> {{ currentIPData["city"] }} </td>
|
||||
</tr>
|
||||
|
||||
<tr><td>Region</td>
|
||||
<td> {{ currentIPData["region"] }} </td>
|
||||
</tr>
|
||||
|
||||
<tr><td>Region Code</td>
|
||||
<td> {{ currentIPData["region_code"] }} </td>
|
||||
</tr>
|
||||
|
||||
<tr><td>Country</td>
|
||||
<td> {{ currentIPData["country"] }} </td>
|
||||
</tr>
|
||||
|
||||
<tr><td>Country Name</td>
|
||||
<td> {{ currentIPData["country_name"] }} </td>
|
||||
</tr>
|
||||
|
||||
<tr><td>Continent Code</td>
|
||||
<td> {{ currentIPData["continent_code"] }} </td>
|
||||
</tr>
|
||||
|
||||
<tr><td>EU</td>
|
||||
<td> {{ currentIPData["in_eu"] }} </td>
|
||||
</tr>
|
||||
|
||||
<tr><td>Postal</td>
|
||||
<td> {{ currentIPData["postal"] }} </td>
|
||||
</tr>
|
||||
|
||||
<tr><td>Latitude</td>
|
||||
<td> {{ currentIPData["latitude"] }} </td>
|
||||
</tr>
|
||||
|
||||
<tr><td>Longitude</td>
|
||||
<td> {{ currentIPData["longitude"] }} </td>
|
||||
</tr>
|
||||
|
||||
<tr><td>Timezone</td>
|
||||
<td> {{ currentIPData["timezone"] }} </td>
|
||||
</tr>
|
||||
|
||||
<tr><td>UTC Offset</td>
|
||||
<td> {{ currentIPData["utc_offset"] }} </td>
|
||||
</tr>
|
||||
|
||||
<tr><td>Country Calling Code</td>
|
||||
<td> {{ currentIPData["country_calling_code"] }} </td>
|
||||
</tr>
|
||||
|
||||
<tr><td>Currency</td>
|
||||
<td> {{ currentIPData["currency"] }} </td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>Languages</td>
|
||||
<td> {{ currentIPData["languages"] }} </td>
|
||||
</tr>
|
||||
</tbody>
|
||||
<tr>
|
||||
<td>
|
||||
</td>
|
||||
</tr>
|
||||
</tr>
|
||||
|
||||
<div class="modal-footer">
|
||||
</div>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!--- Loading --->
|
||||
<div id="loadingModal" class="modal fade" role="dialog" >
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h4 class="modal-title"> {{ loading }} </h4>
|
||||
</div>
|
||||
|
||||
<div class="modal-body">
|
||||
<div class="panel-title"><img src="/img/throbber.gif" ng-show="throbber"/>
|
||||
<p><b>{{ working }}</b></p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"author": "trashbo4t",
|
||||
"devices": [
|
||||
"nano",
|
||||
"tetra"
|
||||
],
|
||||
"title": "Locate",
|
||||
"description": "geolocate IP addresses over HTTPS via ipapi",
|
||||
"version": "1.0"
|
||||
}
|
Loading…
Reference in New Issue