<?
/*
PHPtrace 0.3 by Karthik Arumugham - karthik at karthik.com
Copyright (C) 2007  Karthik Arumugham

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

// Set these to your local traceroute/mtr programs

// Using trACESroute/traceroute-nanog (ftp://ftp.login.com/pub/software/traceroute/)
// the -u flag enables microsecond timing and the -P flag enables parallel probing
$traceprog "/usr/sbin/traceroute -uP";

// If you don't have mtr installed or want to disable it, set $mtrprog to "NONE"
$mtrprog "/usr/bin/mtr --curses --report --report-cycles=15";
//$mtrprog = "NONE";
?>

<html>
<head>
<title>Psychosis.net PHPtrace Gateway</title>
</head>
<body bgcolor=white>

<?
if ($_GET['address'] != "")
{
    
$addr ereg_replace("[^A-Za-z0-9\.-]"""$_GET['address']);
    if ((
$addr != "") && ($addr[0] == "-"))
        
$addr "";
} else if (isset(
$_GET['address']))
    
$addr $_SERVER['REMOTE_ADDR'];

$type $_GET['type'];
if ((
$addr != "") && ((($type == "mtr") && ($mtrprog != "NONE")) || ($type == "traceroute")))
{
    
// abusive hosts with automated queries
    // Previously here, use an if on the hosts/domains to ignore them for now
    
{
        
//if ($type == "mtr")
        //    echo "Don't hit anything, this will take 15 - 30 seconds to complete!<p>";
        
echo "$type to <font color=blue>$addr</font><br><pre>";
        if (
$type == "traceroute")
            
system("$traceprog $addr 2> /dev/null"$result);
        else if (
$type == "mtr")
        {
            
system("$mtrprog $addr"$result);
        }
        if ((
$result != 0) && ($result != 255))
            echo 
"<font color=red>$type failed (host may not exist).</font>";
        echo 
"</pre><hr><p>";
    }
}
?>

<?
echo "<form method=get action=${_SERVER['REQUEST_URI']}>";
?>
Hostname:
<? 
if ($_GET['address'] != "")
    echo 
"<input type=text name=address value=${_GET['address']}>";
else
    echo 
"<input type=text name=address>";
?>
<input type=submit value=Traceroute>
<?
if ($mtrprog != "NONE")
{
    echo 
"<br>Please choose a trace type:";
    if (
$type == "mtr")
    {
        echo 
"<input type=radio name=type value=traceroute>traceroute";
        echo 
"<input type=radio name=type value=mtr checked>mtr (slower)";
    }
    else
    {
        echo 
"<input type=radio name=type value=traceroute checked>traceroute";
        echo 
"<input type=radio name=type value=mtr>mtr (slower)";
    }
} else
    echo 
"<input type=hidden name=type value=traceroute>";
?>
<p>Leave the hostname blank to traceroute to yourself.
<p>Note: Traceroute is currently in parallel-probing mode which may incorrectly display dropped packets (*s) and not display filtered endpoints.
</form>

<p><hr width=40 align=left>
<font size=-1>Questions: email karthik at karthik.com&nbsp;&nbsp;|&nbsp;&nbsp;<a href=http://www.psychosis.net/traceroute/trace.phps>View Source</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href=http://www.psychosis.net/traceroute/>PHPtrace Home</a>
<br>This page may not be used by any automated scripts without prior permission.</font>

</body>
</html>