mirror of
https://github.com/hak5/nano-tetra-modules.git
synced 2025-10-29 16:58:09 +00:00
committed by
Sebastian Kinne
parent
c7ae8dc93c
commit
8eb6bbc8f0
107
Locate/api/module.php
Normal file
107
Locate/api/module.php
Normal file
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user