Handle hostnames with upper-case letters
[webmin.git] / dnsadmin / edit_recs.cgi
1 #!/usr/local/bin/perl
2 # edit_recs.cgi
3 # Display records of some type from some domain
4
5 require './dns-lib.pl';
6 &ReadParse();
7 $conf = &get_config();
8 $zconf = $conf->[$in{'index'}];
9 $dom = $zconf->{'values'}->[0];
10 %access = &get_module_acl();
11 &can_edit_zone(\%access, $dom) ||
12         &error("You are not allowed to edit records in this zone");
13 &header("$code_map{$in{'type'}} Records", "");
14 print "<center><font size=+2>In ",&arpa_to_ip($dom),"</font></center>\n";
15 print "<hr><p>\n";
16
17 $file = $zconf->{'values'}->[1];
18 &foreign_call("bind8", "record_input", $in{'index'}, undef, $in{'type'}, $file, $dom);
19 @recs = &read_zone_file($file, $dom);
20 @recs = grep { $_->{'type'} eq $in{'type'} } @recs;
21 if (@recs) {
22         @recs = &sort_records(@recs);
23         %hmap = ( "A", [ "Address" ],
24                   "NS", [ "Name Server" ],
25                   "CNAME", [ "Real Name" ],
26                   "MX", [ "Priority", "Mail Server" ],
27                   "HINFO", [ "Hardware", "Operating System" ],
28                   "TXT", [ "Message" ],
29                   "WKS", [ "Address", "Protocol", "Service" ],
30                   "RP", [ "Email Address", "Text Record" ],
31                   "PTR", [ "Hostname" ] );
32         if ($in{'type'} =~ /HINFO|WKS|RP/) {
33                 &recs_table(@recs);
34                 }
35         else {
36                 $mid = int((@recs+1)/2);
37                 print "<table width=100%><tr><td width=50% valign=top>\n";
38                 &recs_table(@recs[0 .. $mid-1]);
39                 print "</td><td width=50% valign=top>\n";
40                 if ($mid < @recs) { &recs_table(@recs[$mid .. $#recs]); }
41                 print "</td></tr></table><p>\n";
42                 }
43         print "<p>\n";
44         }
45 print &ui_hr();
46 &footer("edit_master.cgi?index=$in{'index'}", "record types");
47
48 sub recs_table
49 {
50 print "<table border width=100%>\n";
51 print "<tr $tb> <td><b>",$in{'type'} eq "PTR" ? "Address" : "Name",
52       "</b></td> <td><b>TTL</b></td>\n";
53 @hmap = @{$hmap{$in{'type'}}};
54 foreach $h (@hmap) {
55         print "<td><b>$h</b></td>\n";
56         }
57 print "</tr>\n";
58 for($i=0; $i<@_; $i++) {
59         $r = $_[$i];
60         $name = &html_escape($in{'type'} eq "PTR" ? &arpa_to_ip($r->{'name'})
61                                                   : $r->{'name'});
62         print "<tr $cb> <td><a href=\"edit_record.cgi?index=",
63               "$in{'index'}&type=$in{'type'}&num=$r->{'num'}\">$name",
64               "</a></td>\n";
65         print "<td>",$r->{'ttl'} ? $r->{'ttl'} : "Default","</td>\n";
66         for($j=0; $j<@hmap; $j++) {
67                 print "<td>",&html_escape($r->{'values'}->[$j]),"</td>\n";
68                 }
69         print "</tr>\n";
70         }
71 print "</table>\n";
72 }
73