diff options
-rw-r--r-- | collect.d/system | 6 | ||||
-rw-r--r-- | sitesummary-collector.cgi | 36 |
2 files changed, 36 insertions, 6 deletions
diff --git a/collect.d/system b/collect.d/system index 8ccfc58..2843731 100644 --- a/collect.d/system +++ b/collect.d/system @@ -1,14 +1,16 @@ #!/bin/sh +PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/sbin:/usr/local/bin + set -e mkdir system && cd system -if type dmidecode 2>/dev/null; then +if type dmidecode >/dev/null; then dmidecode > dmidecode fi -if type lspci 2>/dev/null; then +if type lspci >/dev/null; then lspci > lspci lspci -n > lspci-n fi diff --git a/sitesummary-collector.cgi b/sitesummary-collector.cgi index fa47e08..5318dac 100644 --- a/sitesummary-collector.cgi +++ b/sitesummary-collector.cgi @@ -8,6 +8,8 @@ use strict; use CGI; +use POSIX qw(strftime); +use Socket; my $basedir = "/var/lib/sitesummary"; @@ -44,7 +46,7 @@ if (exists $ENV{CONTENT_TYPE} && $ENV{CONTENT_TYPE} =~ m%multipart/form-data%){ $data = Compress::Zlib::memGunzip($data); @entry = ($data); } else { # Pass throught - print "Identity encoding detected.\n"; + print STDERR "Identity encoding detected.\n"; @entry = <$fh>; } } @@ -58,10 +60,10 @@ Unsupported submission method. EOF } -my $ip "127.0.0.1"; -my $timestamp = "2006-08-25T11:30:30"; +my ($peeripaddr, $peername) = get_peerinfo(\*STDIN); +my $timestamp = strftime("%Y-%m-%dT%H:%M:%S", gmtime()); -open(SITESUMMARY, "$basedir/tmpstorage/storage-$ip-$timestamp") or die "Unable to write to storage"; +open(SITESUMMARY, ">$basedir/tmpstorage/storage-$peeripaddr-$timestamp") or die "Unable to write to storage"; print SITESUMMARY @entry; close SITESUMMARY; @@ -69,3 +71,29 @@ print "Thanks for your submission to site-summary!\n"; print "SITESUMMARY HTTP-POST OK\n"; exit 0; + + +sub get_peerinfo { + my $sockethandle = shift; + + # Return something while this function do not work. + return ("127.0.0.1", "localhost"); + + # XXX The call to sockaddr_in trigger "Bad arg length for + # Socket::unpack_sockaddr_in, length is 2, should be 16 at + # /usr/lib/perl/5.8/Socket.pm line 198." No idea why. + my ($peerport, $peeripaddr) = sockaddr_in(getpeername($sockethandle)); + if ($peerport) { + my $peername = gethostbyaddr($peeripaddr, AF_INET); + + if ("" eq $peername) { + syslog('warning', "client without DNS entry connected from \[$peeripaddr\]"); + $peername = "$peeripaddr"; + } + } else { + # Running on the command line, use test host + $peeripaddr = "127.0.0.1"; + $peername = "localhost"; + } + return ($peeripaddr, $peername); +} |