diff options
author | Petter Reinholdtsen <pere@hungry.com> | 2006-08-25 20:48:58 +0000 |
---|---|---|
committer | Petter Reinholdtsen <pere@hungry.com> | 2006-08-25 20:48:58 +0000 |
commit | 439020ef8b72a3a941342652d1aac45dae31c6d9 (patch) | |
tree | b8d2e8d335f9183ded5ba1bf888c5db70827b4d1 /sitesummary-collector.cgi | |
parent | 080b37d0ed5d04702452743bbeb7ae38a7f3d415 (diff) | |
download | sitesummary-439020ef8b72a3a941342652d1aac45dae31c6d9.tar.gz sitesummary-439020ef8b72a3a941342652d1aac45dae31c6d9.tar.bz2 sitesummary-439020ef8b72a3a941342652d1aac45dae31c6d9.tar.xz |
Get the collector working.
Diffstat (limited to 'sitesummary-collector.cgi')
-rw-r--r-- | sitesummary-collector.cgi | 36 |
1 files changed, 32 insertions, 4 deletions
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); +} |