After a bit of digging, I figured it out and it's remarkably simple. Here's what you'll need:
- A web server capable of running PHP. I'm rocking XAMPP.
- A functioning bash script. Just make sure it's working when you run it from the command line. The output you see there is what you'll see when it's been web-app'd.
<html>
<head>
<title>Web Ping</title>
<style type='text/css'>
pre {
background:black;
border:1px lime solid;
color:lime;
}
td {
font-family:monospace;
}
</style>
</head>
<body>
<?php
# clean the strings to prevent injection attacks
$BADCHARS='/[^\.\w]/';
$HOST=preg_replace($BADCHARS, '', $_GET['host']);
$C=preg_replace($BADCHARS, '', $_GET['c']);
$I=preg_replace($BADCHARS, '', $_GET['i']);
if ($I=="") { $I=1; } # assign default values
if ($C=="") { $C=4; } # assign default values
if ($HOST!="") { # this is where the magic happens
echo '<pre>';
$last_line = system('/bin/ping '.$HOST.' -c '.$C.' -i '.$I, $retval);
echo '</pre>';
}
?>
<form action='ping.php' method='get'>
<table>
<tr>
<td>Hostname/IP:</td><td><input type='text' name='host' value='<?php echo $HOST ?>'/></td>
</tr>
<tr>
<td>count:</td><td><input type='text' name='c' value='<?php echo $C ?>' /></td>
</tr>
<tr>
<td>interval:</td><td><input type='text' name='i' value='<?php echo $I ?>' /></td>
</tr>
<tr>
<td colspan='2'>
<input type='submit' value='Ping It' /><br><br><br>
</td>
</tr>
</table>
</form>
</body>
</html>
Enjoy!


0 comments:
Post a Comment