diff --git a/src/contrib/wardenweb/alerter.php b/src/contrib/wardenweb/alerter.php new file mode 100644 index 0000000000000000000000000000000000000000..8a0079683ee7eab11eb8962227cccafedceee070 --- /dev/null +++ b/src/contrib/wardenweb/alerter.php @@ -0,0 +1,35 @@ +<? +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); +} + +?>