From 8dcd56e0ec666cef529ae1a2dab338ae3d457388 Mon Sep 17 00:00:00 2001 From: Shish Date: Fri, 22 Jun 2012 19:19:13 +0100 Subject: [PATCH] udp log_net, because it's faster and more elegant --- ext/log_net/main.php | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/ext/log_net/main.php b/ext/log_net/main.php index 94d9d94c..56ee4c9e 100644 --- a/ext/log_net/main.php +++ b/ext/log_net/main.php @@ -19,12 +19,30 @@ class LogNet extends Extension { // TODO: colour based on event->priority $username = ($user && $user->name) ? $user->name : "Anonymous"; $str = sprintf("%-15s %-10s: %s", $_SERVER['REMOTE_ADDR'], $username, $event->message); - system("echo ".escapeshellarg($str)." | nc -q 0 localhost 5000"); + $this->msg($str); } else if($this->count == 10) { - system("echo 'suppressing flood, check the web log' | nc -q 0 localhost 5000"); + $this->msg('suppressing flood, check the web log'); } } } + + 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) { + } + } } ?>