2012-02-26 15:24:37 +00:00
|
|
|
<?php
|
|
|
|
/*
|
|
|
|
* Name: Logging (Network)
|
|
|
|
* Author: Shish <webmaster@shishnet.org>
|
|
|
|
* Link: http://code.shishnet.org/shimmie2/
|
|
|
|
* Description: Send log events to a network port.
|
|
|
|
* Visibility: admin
|
|
|
|
*/
|
|
|
|
|
|
|
|
class LogNet extends Extension {
|
2016-06-19 23:05:57 +01:00
|
|
|
private $count = 0;
|
2012-03-19 21:15:54 +00:00
|
|
|
|
2012-02-26 15:24:37 +00:00
|
|
|
public function onLog(LogEvent $event) {
|
|
|
|
global $user;
|
|
|
|
|
2012-03-19 21:19:50 +00:00
|
|
|
if($event->priority > 10) {
|
2012-03-19 22:25:57 +00:00
|
|
|
$this->count++;
|
2012-03-19 21:19:50 +00:00
|
|
|
if($this->count < 10) {
|
|
|
|
// TODO: colour based on event->priority
|
|
|
|
$username = ($user && $user->name) ? $user->name : "Anonymous";
|
|
|
|
$str = sprintf("%-15s %-10s: %s", $_SERVER['REMOTE_ADDR'], $username, $event->message);
|
2012-06-22 19:19:13 +01:00
|
|
|
$this->msg($str);
|
2012-03-19 21:19:50 +00:00
|
|
|
}
|
2012-03-19 22:25:57 +00:00
|
|
|
else if($this->count == 10) {
|
2012-06-22 19:19:13 +01:00
|
|
|
$this->msg('suppressing flood, check the web log');
|
2012-03-19 21:19:50 +00:00
|
|
|
}
|
2012-02-26 15:24:37 +00:00
|
|
|
}
|
|
|
|
}
|
2012-06-22 19:19:13 +01:00
|
|
|
|
|
|
|
private function msg($data) {
|
|
|
|
global $config;
|
|
|
|
$host = $config->get_string("log_net_host", "127.0.0.1:35353");
|
|
|
|
|
|
|
|
if(!$host) { return; }
|
|
|
|
|
|
|
|
try {
|
|
|
|
$parts = explode(":", $host);
|
|
|
|
$host = $parts[0];
|
|
|
|
$port = $parts[1];
|
|
|
|
$fp = fsockopen("udp://$host", $port, $errno, $errstr);
|
|
|
|
if (! $fp) { return; }
|
|
|
|
fwrite($fp, "$data\n");
|
|
|
|
fclose($fp);
|
|
|
|
} catch (Exception $e) {
|
2014-04-06 20:47:01 +01:00
|
|
|
/* logging errors shouldn't break everything */
|
2012-06-22 19:19:13 +01:00
|
|
|
}
|
|
|
|
}
|
2012-02-26 15:24:37 +00:00
|
|
|
}
|
2014-04-25 22:54:51 -04:00
|
|
|
|