Handle hostnames with upper-case letters
[webmin.git] / dnsadmin / index.cgi
1 #!/usr/local/bin/perl
2
3 require './dns-lib.pl';
4
5 &header("BIND 4 DNS Server", "", undef, 1, 1);
6 print &ui_hr();
7 %access = &get_module_acl();
8
9 # Check if named exists
10 if (!-x $config{'named_pathname'}) {
11         print "<p>The BIND 4 DNS server <i>$config{'named_pathname'}</i>\n";
12         print "could not be found on your system. Maybe it is not installed,\n";
13         print "or your <a href=\"$gconfig{'webprefix'}/config.cgi?$module_name\">BIND 4 module\n";
14         print "configuration</a> is incorrect. <p>\n";
15         print &ui_hr();
16         &footer("/", "index");
17         exit;
18         }
19
20 # Check for future versions of BIND with the -v option
21 $out = `$config{'named_pathname'} -v 2>&1`;
22 if (0 && ($out =~ /bind\s+(\d+)\./i || $out =~ /named\s+(\d+)\./) && $1 >= 8) {
23         print "<p>The server <i>$config{'named_pathname'}</i> appears to\n";
24         print "be BIND 8. Maybe your should use the\n";
25         print "<a href=/bind8/>BIND 8 server module</a> instead. <p>\n";
26         print &ui_hr();
27         &footer("/", "index");
28         exit;
29         }
30
31 # Check if BIND is the right version.. Only BIND 8 offers the -f option
32 # Is there a better way to do this?
33 $out = `$config{'named_pathname'} -help 2>&1`;
34 if (0 && $out =~ /\[-f\]/) {
35         print "<p>The server <i>$config{'named_pathname'}</i> appears to\n";
36         print "be BIND 8. Maybe your should use the\n";
37         print "<a href=/bind8/>BIND 8 server module</a> instead. <p>\n";
38         print &ui_hr();
39         &footer("/", "index");
40         exit;
41         }
42
43 # If the named.boot file is empty or does not exist, offer to create it
44 if (!-r $config{named_boot_file}) { $need_create++; }
45 else {
46         $conf = &get_config();
47         if (!@$conf) { $need_create++; }
48         }
49
50 if ($need_create) {
51         # There is no nameserver boot file.. offer to create
52         print "<p>The primary configuration file\n";
53         print "<i>$config{named_boot_file}</i> does not exist,\n";
54         print "or is empty. Create it?<p>\n";
55         print "<form action=\"dns_boot.cgi\">\n";
56         print "<input type=radio name=real value=0> Setup nameserver for ",
57               "internal non-internet use only<p>\n";
58         print "<input type=radio name=real value=1 checked> Setup as an ",
59               "internet name server, and download root server information<p>\n";
60         print "<input type=radio name=real value=2> Setup as an internet name ",
61               "server, but use Webmin's older root server information<p>\n";
62         print "<center><input type=submit value=\"Create Primary Configuration File and Start Nameserver\"></center>\n";
63         print "</form>\n";
64         print &ui_hr();
65         &footer("/", "index");
66         exit;
67         }
68
69 @zlist = (&find_config("primary", $conf), &find_config("secondary", $conf));
70 if (!@zlist) {
71         # Nothing in named file..
72         print "<b>There are no DNS zones defined for this name server</b><p>\n";
73         }
74 else {
75         print &ui_subheading("Existing DNS Zones");
76         foreach $z (@zlist) {
77                 next if (!&can_edit_zone(\%access, $z->{'values'}->[0]));
78                 if ($z->{'name'} eq "primary") {
79                         push(@zlinks, "edit_master.cgi?index=$z->{'index'}");
80                         push(@ztitles, &arpa_to_ip($z->{'values'}->[0]));
81                         push(@zicons, "../bind8/images/master.gif");
82                         push(@ztypes, "Master");
83                         }
84                 else {
85                         push(@zlinks, "edit_slave.cgi?index=$z->{'index'}");
86                         push(@ztitles, &arpa_to_ip($z->{'values'}->[0]));
87                         push(@zicons, "../bind8/images/slave.gif");
88                         push(@ztypes, "Slave");
89                         }
90                 $len++;
91                 }
92
93         # sort list of zones
94         @zorder = sort { $ztitles[$a] cmp $ztitles[$b] } (0 .. $len-1);
95         @zlinks = map { $zlinks[$_] } @zorder;
96         @ztitles = map { $ztitles[$_] } @zorder;
97         @zicons = map { $zicons[$_] } @zorder;
98         @ztypes = map { $ztypes[$_] } @zorder;
99
100         if ($config{'show_list'}) {
101                 # display as list
102                 $mid = int((@zlinks+1)/2);
103                 print "<table width=100%><tr><td width=50% valign=top>\n";
104                 &zones_table([ @zlinks[0 .. $mid-1] ],
105                              [ @ztitles[0 .. $mid-1] ],
106                              [ @ztypes[0 .. $mid-1] ]);
107                 print "</td><td width=50% valign=top>\n";
108                 if ($mid < @zlinks) {
109                         &zones_table([ @zlinks[$mid .. $#zlinks] ],
110                                      [ @ztitles[$mid .. $#ztitles] ],
111                                      [ @ztypes[$mid .. $#ztypes] ]);
112                         }
113                 print "</td></tr></table>\n";
114                 }
115         else {
116                 # display as icons
117                 &icons_table(\@zlinks, \@ztitles, \@zicons);
118                 }
119         }
120 if ($access{'master'}) {
121         print "<a href=\"master_form.cgi\">Create a new ",
122               "master zone</a>&nbsp;&nbsp;\n";
123         }
124 if ($access{'slave'}) {
125         print "<a href=\"slave_form.cgi\">Create a new ",
126               "slave zone</a>&nbsp;&nbsp;\n";
127         }
128 print "<p>\n";
129
130 if ($access{'defaults'}) {
131         # Display form to set the defaults for new zones
132         &get_zone_defaults(\%zd);
133         print &ui_hr();
134         print &ui_subheading("New Master Zone Defaults");
135         print "<form action=save_zonedef.cgi>\n";
136         print "<table border>\n";
137         print "<tr $tb> <td><b>Defaults for new master zones</b></td> </tr>\n";
138         print "<tr $cb> <td><table cellpadding=5>\n";
139
140         print "<tr> <td><b>Refresh time</b></td>\n";
141         print "<td><input name=refresh size=10 value=$zd{'refresh'}> seconds</td>\n";
142         print "<td><b>Transfer retry time</b></td>\n";
143         print "<td><input name=retry size=10 value=$zd{'retry'}> seconds</td></tr>\n";
144
145         print "<tr> <td><b>Expiry time</b></td>\n";
146         print "<td><input name=expiry size=10 value=$zd{'expiry'}> seconds</td>\n";
147         print "<td><b>Default time-to-live</b></td>\n";
148         print "<td><input name=minimum size=10 value=$zd{'minimum'}> seconds</td>\n";
149         print "</tr> </table></td></tr></table><br>\n";
150         print "<input type=submit value=Update></form>\n";
151         }
152
153 # Display a form to start or restart named
154 print &ui_hr();
155 if ($config{'named_pid_file'}) {
156         if (open(PID, $config{'named_pid_file'})) {
157                 <PID> =~ /(\d+)/;
158                 $pid = $1;
159                 close(PID);
160                 }
161         }
162 else {
163         &foreign_require("proc", "proc-lib.pl");
164         foreach $p (&proc::list_processes()) {
165                 if ($p->{'args'} =~ /^\Q$config{'named_pathname'}\E/) {
166                         $pid = $p->{'pid'};
167                         last;
168                         }
169                 }
170         }
171 if ($pid && kill(0, $pid)) {
172         # named is running
173         print "<form action=restart.cgi>\n";
174         print "<input type=hidden name=pid value=$pid>\n";
175         print "<table width=100%><tr><td>\n";
176         print "<input type=submit value=\"Apply Changes\"></td>\n";
177         print "<td>Click this button to restart the running BIND 4 server.\n";
178         print "This will cause the current configuration to become\n";
179         print "active</td> </tr></table>\n";
180         print "</form>\n";
181         }
182 else {
183         # named is not running
184         print "<form action=start.cgi>\n";
185         print "<table width=100%><tr><td>\n";
186         print "<input type=submit value=\"Start Name Server\"></td>\n";
187         print "<td>Click this button to start the BIND 4 server, and load\n";
188         print "the current configuration</td> </tr></table>\n";
189         print "</form>\n";
190         }
191
192 print &ui_hr();
193 &footer("/", "index");
194
195 sub zones_table
196 {
197 local($i);
198 print "<table border width=100%>\n";
199 print "<tr $tb> <td><b>Zone</b></td> <td><b>Type</b></td> </tr>\n";
200 for($i=0; $i<@{$_[0]}; $i++) {
201         print "<tr $cb>\n";
202         print "<td><a href=\"$_[0]->[$i]\">$_[1]->[$i]</a></td>\n";
203         print "<td>$_[2]->[$i]</td>\n";
204         print "</tr>\n";
205         }
206 print "</table>\n";
207 }
208