DNS Lookup"); if ($alias_exists) { $a_aliases[$id] = $newalias; } else { $a_aliases[] = $newalias; } write_config(); $createdalias = true; } } if ($_POST) { unset($input_errors); $reqdfields = explode(" ", "host"); $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 { // Test resolution speed of each DNS server. $dns_speeds = array(); $dns_servers = array(); 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 == "") { $query_time = gettext("No response"); } $new_qt = array(); $new_qt['dns_server'] = $dns_server; $new_qt['query_time'] = $query_time; $dns_speeds[] = $new_qt; unset($new_qt); } } $type = "unknown"; $resolved = ""; $ipaddr = ""; $hostname = ""; if (!$input_errors) { if (is_ipaddr($host)) { $type = "ip"; $resolved = gethostbyaddr($host); $ipaddr = $host; if ($host != $resolved) { $hostname = $resolved; } } elseif (is_hostname($host)) { $type = "hostname"; $resolved = gethostbyname($host); if ($resolved) { $resolved = resolve_host_addresses($host); } $hostname = $host; if ($host != $resolved) { $ipaddr = $resolved[0]; } } if ($host == $resolved) { $resolved = gettext("No record found"); } } } if (($_POST['host']) && ($_POST['dialog_output'])) { display_host_results ($host, $resolved, $dns_speeds); exit; } function display_host_results ($address, $hostname, $dns_speeds) { $map_lengths = function($element) { return strlen($element[0]); }; echo gettext("IP Address") . ": {$address} \n"; echo gettext("Host Name") . ": {$hostname} \n"; echo "\n"; $text_table = array(); $text_table[] = array(gettext("Server"), gettext("Query Time")); if (is_array($dns_speeds)) { foreach ($dns_speeds as $qt) { $text_table[] = array(trim($qt['dns_server']), trim($qt['query_time'])); } } $col0_padlength = max(array_map($map_lengths, $text_table)) + 4; foreach ($text_table as $text_row) { echo str_pad($text_row[0], $col0_padlength) . $text_row[1] . "\n"; } } include("head.inc"); /* Display any error messages resulting from user input */ if ($input_errors) { print_input_errors($input_errors); } else if (!$resolved && $type) { print_info_box(sprintf(gettext('Host "%s" could not be resolved.'), $host), 'warning', false); } if ($createdalias) { if ($alias_exists) { print_info_box(gettext("Alias was updated successfully."), 'success'); } else { print_info_box(gettext("Alias was created successfully."), 'success'); } } $form = new Form(false); $section = new Form_Section('DNS Lookup'); $section->addInput(new Form_Input( 'host', 'Hostname', 'text', $host, ['placeholder' => 'Hostname to look up.'] )); if (!empty($resolved)) { if ($alias_exists) { $button_text = gettext("Update alias"); } else { $button_text = gettext("Add alias"); } $form->addGlobal(new Form_Button( 'create_alias', $button_text, null, 'fa-plus' ))->removeClass('btn-primary')->addClass('btn-success'); } $form->add($section); $form->addGlobal(new Form_Button( 'Submit', 'Lookup', null, 'fa-search' ))->addClass('btn-primary'); print $form; if (!$input_errors && $type) { if ($resolved): ?>