Handle hostnames with upper-case letters
[webmin.git] / bind8 / whois.cgi
1 #!/usr/local/bin/perl
2 # whois.cgi
3 # Call whois to get zone info
4
5 require './bind8-lib.pl';
6 &ReadParse();
7 $access{'whois'} || &error($text{'whois_ecannot'});
8 $zone = &get_zone_name($in{'index'}, $in{'view'});
9 $dom = $zone->{'name'};
10 $tv = $zone->{'type'};
11 $dom =~ s/\.$//;
12 &can_edit_zone($zone) ||
13         &error($text{'master_ecannot'});
14 $desc = &ip6int_to_net(&arpa_to_ip($dom));
15 &ui_print_header($desc, $text{'whois_title'}, "",
16                  undef, undef, undef, undef, &restart_links($zone));
17
18 # Find the best whois server for the domain
19 foreach $wf ("$module_root_directory/whois-servers",
20              "$module_config_directory/whois-servers") {
21         open(WHOIS, $wf);
22         while(<WHOIS>) {
23                 s/\r|\n//g;
24                 local ($wdom, $wserv) = split(/\s+/);
25                 $whois{$wdom} = $wserv;
26                 }
27         close(WHOIS);
28         }
29 foreach $d (sort { length($b) <=> length($a) } keys %whois) {
30         if ($dom =~ /\Q$d\E$/) {
31                 $server = "-h ".quotemeta($whois{$d});
32                 $pserver = "-h ".$whois{$d};
33                 last;
34                 }
35         }
36
37 $qdom = quotemeta($dom);
38 $cmd = "$config{'whois_cmd'} $server $qdom";
39 $pcmd = "$config{'whois_cmd'} $pserver $dom";
40 $out = `$cmd 2>&1`;
41 if ($out =~ /whois\s+server:\s+(\S+)/i) {
42         $cmd = "$config{'whois_cmd'} -h ".quotemeta($1)." $qdom";
43         $pcmd = "$config{'whois_cmd'} -h $1 $dom";
44         $out = `$cmd 2>&1`;
45         }
46 print &ui_table_start(&text('whois_header', "<tt>".&html_escape($pcmd)."</tt>"),
47                       "width=100%", 2);
48 print &ui_table_row(undef, "<pre>".&html_escape($out)."</pre>", 2);
49 print &ui_table_end();
50
51 &ui_print_footer(($tv eq "master" ? "edit_master.cgi" :
52          $tv eq "forward" ? "edit_forward.cgi" : "edit_slave.cgi").
53         "?index=$in{'index'}&view=$in{'view'}", $text{'master_return'});
54