#!/usr/bin/perl -W

use strict;

select STDERR; $| = 1;
select STDIN;  $| = 1;
select STDOUT; $| = 1;

my $rip=$ENV{'REMOTE_ADDR'} || ' ';
my $rhost=$ENV{'REMOTE_HOST'} || ' ';

if ($rip =~ /^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})$/) { $rip=$1; } else { die 'No valid remote IP'; }

my @now=localtime(time);
$now[4]++;
$now[5]+=1900;
my $timestamp=sprintf "%04d-%02d-%02dT%02d:%02d:%02d+01:00", $now[5],$now[4],$now[3],$now[2],$now[1],$now[0];


print <<EOHTLM;
Content-type: text/html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta name="Content-Language" content="de" />
<meta name="Author" content="Sven Weise" />
<meta name="date" content="$timestamp" />
<meta name="robots" content="noindex,nofollow,noarchive" />
<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="expires" content="0" />
<title> Traceroute from news.unit0.net to you </title>
</head>
<body>
<h1>Traceroute from news.unit0.net to $rhost [$rip]</h1>

<p>
EOHTLM

if ($rip) {
	open(TR, '-|', "/usr/sbin/traceroute -m 25 -s 195.71.90.67 $rip 2>&1") or die ("Error executing traceroute: $!");
	while(<TR>) {
		chomp;
		$_ =~ s/\ /\&nbsp\;/g;
		print "$_<br />\n";
	}
	close TR;
} else {
	 print "Nothing to trace...<br />\n";
}

print <<EOHTLM;
</p>

</body>
</html>
EOHTLM
