Skip to content
Snippets Groups Projects
Commit a2be9737 authored by Radoslav Bodó's avatar Radoslav Bodó
Browse files

velmi nehezky alerter

parent 98f177cc
No related branches found
No related tags found
No related merge requests found
<?
require("./db.php");
$lastfile = "/var/cache/warden-last-id.txt";
#TODO: not very najs
$ownnet = json_decode(file_get_contents("listnetworks.json"), true);
$mynet = $ownnet["147.228.0.0/16"];
#var_dump($ownnet);
$last = @file_get_contents($lastfile);
#var_dump($last);
if($last == false) {
$res = mysql_query("select id from events order by id desc limit 1",$db);
$tmp = mysql_fetch_assoc($res);
#var_dump($tmp["id"]);
printf("WARN: no lastfile found, starting from now\n");
file_put_contents($lastfile, $tmp["id"]);
} else {
$res = mysql_query("select id from events order by id desc limit 1",$db);
$tmp = mysql_fetch_assoc($res);
$head = $tmp["id"];
$q ="select max(detected) as max_detected, hostname, service, type, source, sum(attack_scale) as sum_attack_scale from events where id>$last AND id<=$head AND inet_aton(source) BETWEEN ".$mynet['first'] ." AND ".$mynet['last']." group by hostname, service,type,source;";
#print "DEBUG: $q\n";
$res = mysql_query($q, $db);
if (!$res) {
die('Invalid query: ' . mysql_error());
}
while ($tmp = mysql_fetch_assoc($res)) {
#var_dump($tmp);
print json_encode($tmp)."\n";
}
file_put_contents($lastfile,$head);
}
?>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment