diff options
Diffstat (limited to 'usr/local/www/diag_dns.php')
-rw-r--r-- | usr/local/www/diag_dns.php | 92 |
1 files changed, 50 insertions, 42 deletions
diff --git a/usr/local/www/diag_dns.php b/usr/local/www/diag_dns.php index cbce9aa..5ee7927 100644 --- a/usr/local/www/diag_dns.php +++ b/usr/local/www/diag_dns.php @@ -10,11 +10,11 @@ modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. + this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY @@ -38,7 +38,7 @@ require("guiconfig.inc"); $host = trim($_REQUEST['host'], " \t\n\r\0\x0B[];\"'"); $host_esc = escapeshellarg($host); -/* If this section of config.xml has not been populated yet we need to set it up +/* If this section of config.xml has not been populated yet we need to set it up */ if (!is_array($config['aliases']['alias'])) { $config['aliases']['alias'] = array(); @@ -48,43 +48,47 @@ $a_aliases = &$config['aliases']['alias']; $aliasname = str_replace(array(".","-"), "_", $host); $alias_exists = false; $counter=0; -foreach($a_aliases as $a) { - if($a['name'] == $aliasname) { +foreach ($a_aliases as $a) { + if ($a['name'] == $aliasname) { $alias_exists = true; $id=$counter; } $counter++; } -if(isset($_POST['create_alias']) && (is_hostname($host) || is_ipaddr($host))) { - if($_POST['override']) +if (isset($_POST['create_alias']) && (is_hostname($host) || is_ipaddr($host))) { + if ($_POST['override']) { $override = true; + } $resolved = gethostbyname($host); $type = "hostname"; - if($resolved) { + if ($resolved) { $resolved = array(); exec("/usr/bin/drill {$host_esc} A | /usr/bin/grep {$host_esc} | /usr/bin/grep -v ';' | /usr/bin/awk '{ print $5 }'", $resolved); $isfirst = true; - foreach($resolved as $re) { - if($re <> "") { - if(!$isfirst) + foreach ($resolved as $re) { + if ($re <> "") { + if (!$isfirst) { $addresses .= " "; + } $addresses .= rtrim($re) . "/32"; $isfirst = false; } } $newalias = array(); - if($override) + if ($override) { $alias_exists = false; - if($alias_exists == false) { + } + if ($alias_exists == false) { $newalias['name'] = $aliasname; $newalias['type'] = "network"; $newalias['address'] = $addresses; $newalias['descr'] = "Created from Diagnostics-> DNS Lookup"; - if($override) + if ($override) { $a_aliases[$id] = $newalias; - else + } else { $a_aliases[] = $newalias; + } write_config(); $createdalias = true; } @@ -98,7 +102,7 @@ if ($_POST) { $reqdfieldsn = explode(",", "Host"); do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors); - + if (!is_hostname($host) && !is_ipaddr($host)) { $input_errors[] = gettext("Host must be a valid hostname or IP address."); } else { @@ -108,8 +112,9 @@ if ($_POST) { exec("/usr/bin/grep nameserver /etc/resolv.conf | /usr/bin/cut -f2 -d' '", $dns_servers); foreach ($dns_servers as $dns_server) { $query_time = exec("/usr/bin/drill {$host_esc} " . escapeshellarg("@" . trim($dns_server)) . " | /usr/bin/grep Query | /usr/bin/cut -d':' -f2"); - if($query_time == "") + if ($query_time == "") { $query_time = gettext("No response"); + } $new_qt = array(); $new_qt['dns_server'] = $dns_server; $new_qt['query_time'] = $query_time; @@ -127,18 +132,20 @@ if ($_POST) { $type = "ip"; $resolved = gethostbyaddr($host); $ipaddr = $host; - if ($host != $resolved) + if ($host != $resolved) { $hostname = $resolved; + } } elseif (is_hostname($host)) { $type = "hostname"; $resolved = gethostbyname($host); - if($resolved) { + if ($resolved) { $resolved = array(); exec("/usr/bin/drill {$host_esc} A | /usr/bin/grep {$host_esc} | /usr/bin/grep -v ';' | /usr/bin/awk '{ print $5 }'", $resolved); } $hostname = $host; - if ($host != $resolved) + if ($host != $resolved) { $ipaddr = $resolved[0]; + } } if ($host == $resolved) { @@ -147,7 +154,7 @@ if ($_POST) { } } -if( ($_POST['host']) && ($_POST['dialog_output']) ) { +if (($_POST['host']) && ($_POST['dialog_output'])) { display_host_results ($host,$resolved,$dns_speeds); exit; } @@ -175,18 +182,18 @@ include("head.inc"); ?> <body link="#0000CC" vlink="#0000CC" alink="#0000CC"> <?php include("fbegin.inc"); ?> <table width="100%" border="0" cellpadding="0" cellspacing="0" summary="diag dns"> - <tr> - <td> + <tr> + <td> <?php if ($input_errors) print_input_errors($input_errors); ?> <form action="diag_dns.php" method="post" name="iform" id="iform"> <table width="100%" border="0" cellpadding="6" cellspacing="0" summary="tabcont"> <tr> <td colspan="2" valign="top" class="listtopic"> <?=gettext("Resolve DNS hostname or IP");?></td> </tr> - <tr> + <tr> <td width="22%" valign="top" class="vncellreq"><?=gettext("Hostname or IP");?></td> <td width="78%" class="vtable"> - <?=$mandfldhtml;?> + <?=$mandfldhtml;?> <table summary="results"> <tr><td valign="top"> <input name="host" type="text" class="formfld unknown" id="host" size="20" value="<?=htmlspecialchars($host);?>" /> @@ -196,28 +203,28 @@ include("head.inc"); ?> <font size="+1"> <?php $found = 0; - if(is_array($resolved)) { - foreach($resolved as $hostitem) { - if($hostitem <> "") { + if (is_array($resolved)) { + foreach ($resolved as $hostitem) { + if ($hostitem <> "") { echo $hostitem . "<br />"; $found++; } } } else { - echo $resolved; - } - if($found > 0) { ?> + echo $resolved; + } + if ($found > 0) { ?> <br/></font><font size='-2'> - <?PHP if($alias_exists) { ?> + <?php if ($alias_exists) { ?> An alias already exists for the hostname <?= htmlspecialchars($host) ?>. <br /> <input type="hidden" name="override" value="true"/> <input type="submit" name="create_alias" value="Overwrite Alias"/> - <?PHP } else { - if(!$createdalias) { ?> + <?php } else { + if (!$createdalias) { ?> <input type="submit" name="create_alias" value="Create Alias from These Entries"/> - <?PHP } else { ?> + <?php } else { ?> Alias created with name <?= htmlspecialchars($newalias['name']) ?> - <?PHP } + <?php } } } ?> @@ -226,7 +233,7 @@ include("head.inc"); ?> </font></td></tr></table> </td> </tr> -<?php if($_POST): ?> +<?php if ($_POST): ?> <tr> <td width="22%" valign="top" class="vncell"><?=gettext("Resolution time per server");?></td> <td width="78%" class="vtable"> @@ -240,8 +247,8 @@ include("head.inc"); ?> </td> </tr> <?php - if(is_array($dns_speeds)) - foreach($dns_speeds as $qt): + if (is_array($dns_speeds)) { + foreach ($dns_speeds as $qt): ?> <tr> <td class="listlr"> @@ -252,7 +259,8 @@ include("head.inc"); ?> </td> </tr> <?php - endforeach; + endforeach; + } ?> </table> </td> @@ -276,7 +284,7 @@ include("head.inc"); ?> <td width="22%" valign="top"> </td> <td width="78%"> <br /> - <input name="Submit" type="submit" class="formbtn" value="<?=gettext("DNS Lookup");?>" /> + <input name="Submit" type="submit" class="formbtn" value="<?=gettext("DNS Lookup");?>" /> </td> </tr> </table> |