From 5543b9ed4f082918c805e72f69e857475e1363b0 Mon Sep 17 00:00:00 2001 From: Scott Ullrich Date: Mon, 12 Sep 2005 19:39:53 +0000 Subject: Sync w/ 1.2b10 --- usr/local/www/diag_ping.php | 72 +++++++++++++++++++++++++++++++++------------ 1 file changed, 53 insertions(+), 19 deletions(-) (limited to 'usr/local/www/diag_ping.php') diff --git a/usr/local/www/diag_ping.php b/usr/local/www/diag_ping.php index 788753e..89ef3b4 100755 --- a/usr/local/www/diag_ping.php +++ b/usr/local/www/diag_ping.php @@ -1,13 +1,10 @@ #!/usr/local/bin/php . + Copyright (C) 2003-2005 Bob Zoller (bob@kludgebox.com) and Manuel Kasper . All rights reserved. Redistribution and use in source and binary forms, with or without @@ -32,6 +29,7 @@ POSSIBILITY OF SUCH DAMAGE. */ +$pgtitle = array("Diagnostics", "Ping"); require("guiconfig.inc"); define('MAX_COUNT', 10); @@ -52,9 +50,9 @@ if ($_POST) { if (!$input_errors) { $do_ping = true; - $host = preg_replace ("/[^A-Za-z0-9.]/","",$_POST['host']); + $host = $_POST['host']; + $interface = $_POST['interface']; $count = $_POST['count']; - } } if (!isset($do_ping)) { @@ -63,26 +61,60 @@ if (!isset($do_ping)) { $count = DEFAULT_COUNT; } -$pgtitle = "Diagnostics: Ping"; -include("head.inc"); - +function get_interface_addr($ifdescr) { + + global $config, $g; + + /* find out interface name */ + if ($ifdescr == "wan") + $if = get_real_wan_interface(); + else + $if = $config['interfaces'][$ifdescr]['if']; + + /* try to determine IP address and netmask with ifconfig */ + unset($ifconfiginfo); + exec("/sbin/ifconfig " . $if, $ifconfiginfo); + + foreach ($ifconfiginfo as $ici) { + if (preg_match("/inet (\S+)/", $ici, $matches)) { + return $matches[1]; + } + } + + return false; +} ?> - - -

+ + + + + + - @@ -100,7 +132,11 @@ include("head.inc"); echo("Ping output:
"); echo('
');
 					ob_end_flush();
-					system("/sbin/ping -c$count " . escapeshellarg($host));
+					$ifaddr = get_interface_addr($interface);
+					if ($ifaddr)
+						system("/sbin/ping -S$ifaddr -c$count " . escapeshellarg($host));
+					else
+						system("/sbin/ping -c$count " . escapeshellarg($host));
 					echo('
'); } ?> @@ -109,5 +145,3 @@ include("head.inc");
Host +
Interface -
Count - @@ -90,7 +122,7 @@ include("head.inc");
  +
- - -- cgit v1.1