<?
/*
#============================================================================
# Program: Nodes-Toolbox.php
# Programmer: Eli Gill (based off of NeDi framework by Remo Rickli)
#
# DATE     COMMENT
# -------- ------------------------------------------------------------------
#08/01/07	Basic functionality works.  Need to output the results to a seperate table, clean up existing tables.
#08/02/07	Output goes into new table, but need to find a way to cleanup output.
#18/09/07	Adjustments to fit themes (Remo Rickli)
# 20/09/07	implemented language support (Remo Rickli)
*/

include_once ("inc/header.php");

$_GET = sanitize($_GET);
$ping_host  = isset($_GET['Host']) ? $_GET['Host'] : $_SERVER['REMOTE_ADDR'];
$ping_count = isset($_GET['Count']) ? $_GET['Count'] : 5;
$ping_size  = isset($_GET['Size']) ? $_GET['Size'] : 32;

$ping_start = isset($_GET['Start']) ? $_GET['Start'] : $_SERVER['REMOTE_ADDR'];
$ping_end   = isset($_GET['End']) ? $_GET['End'] : $_SERVER['REMOTE_ADDR'];

$lookup   = isset($_GET['Lookup']) ? $_GET['Lookup'] : $_SERVER['REMOTE_ADDR'];
$trace   = isset($_GET['Trace']) ? $_GET['Trace'] : $_SERVER['REMOTE_ADDR'];

$do = isset($_GET['Do']) ? $_GET['Do'] : "";

?>
<h1><?=$netlbl?> Tool Box</h1>

<form method="get" action="<?=$self?>.php" name="nettools">
<table class="content" ><tr class="<?=$modgroup[$self]?>1">
<th width=80><a href="<?=$self?>.php"><img src="img/32/glof.png"></a></th>
<th>
<?=$dstlbl?> <input type="text" name="Host" value="<?=$ping_host?>" size="15" />
<?=$numlbl?> <input type="text" name="Count" value="<?=$ping_count?>" size="4" />
<?=$sizlbl?> <input type="text" name="Size" value="<?=$ping_size?>" size="4" />
<input type="submit" value="Ping Host" name="Do"/>
<th>
Start IP: <input type="text" name="Start" value="<?=$ping_start?>" size="15" />
End IP: <input type="text" name="End" value="<?=$ping_end?>" size="15" />
<input type="submit" value="Ping Range" size="15" name="Do"/>
<tr class="<?=$modgroup[$self]?>1">
<th width=80 class="<?=$modgroup[$self]?>2"><a href="log/putty.exe"><img src="img/16/loko.png" title="Download Putty"></a>
<th>
Host <input type="text" name="Lookup" value="<?=$lookup?>" size="15" />
<input type="submit" value="Lookup" name="Do"/>
</th>
<th>
<?=$dstlbl?> <input type="text" name="Trace" value="<?=$trace?>" size"15" />
<input type="submit" value="Traceroute" name="Do"/>
</table>
</form>

<?php
flush();

if($do == "Ping Host"){
	echo "<h2>$ping_count Ping(s) with $ping_size bytes to $ping_host</h2><div class=\"textpad code txta\">";
	system("ping -c $ping_count -s $ping_size $ping_host");
}elseif($do == "Ping Range"){
	echo "<h2>Responding hosts from $ping_start to $ping_end</h2><div class=\"textpad code txta\">";
	flush();
	echo system("/usr/local/sbin/fping -a -g $ping_start $ping_end");
}elseif($do == "Lookup"){
	echo "<h2>DNS Lookup for $lookup</h2><div class=\"textpad code txtb\">";
	system("nslookup $lookup");
}elseif($do == "Traceroute"){
	echo "<h2>Traceroute to $trace</h2><div class=\"textpad code txtb\">";
	system("traceroute $trace");
}
?>
</div>
<?
include_once ("inc/footer.php");
?>