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
|
|
|
|
*/
|
|
|
|
|
2019-05-28 17:59:38 +01:00
|
|
|
class LogNet extends Extension
|
|
|
|
{
|
|
|
|
private $count = 0;
|
2012-03-19 21:15:54 +00:00
|
|
|
|
2019-05-28 17:59:38 +01:00
|
|
|
public function onLog(LogEvent $event)
|
|
|
|
{
|
|
|
|
global $user;
|
2012-02-26 15:24:37 +00:00
|
|
|
|
2019-05-28 17:59:38 +01:00
|
|
|
if ($event->priority > 10) {
|
|
|
|
$this->count++;
|
|
|
|
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);
|
|
|
|
$this->msg($str);
|
|
|
|
} elseif ($this->count == 10) {
|
|
|
|
$this->msg('suppressing flood, check the web log');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-06-22 19:19:13 +01:00
|
|
|
|
2019-05-28 17:59:38 +01:00
|
|
|
private function msg($data)
|
|
|
|
{
|
|
|
|
global $config;
|
|
|
|
$host = $config->get_string("log_net_host", "127.0.0.1:35353");
|
2012-06-22 19:19:13 +01:00
|
|
|
|
2019-05-28 17:59:38 +01:00
|
|
|
if (!$host) {
|
|
|
|
return;
|
|
|
|
}
|
2012-06-22 19:19:13 +01:00
|
|
|
|
2019-05-28 17:59:38 +01:00
|
|
|
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) {
|
|
|
|
/* logging errors shouldn't break everything */
|
|
|
|
}
|
|
|
|
}
|
2012-02-26 15:24:37 +00:00
|
|
|
}
|