Handle hostnames with upper-case letters
[webmin.git] / bind8 / dns_boot.cgi
1 #!/usr/local/bin/perl
2 # dns_boot.cgi
3 # Create an empty named.conf file and start the name server
4
5 require './bind8-lib.pl';
6 &error_setup($text{'boot_err'});
7 &ReadParse();
8
9 $config{'named_conf'} =~ /^(\S+)\/([^\/]+)$/;
10 $conf_directory = $1;
11 $pid_file = $config{'pid_file'} || "/var/run/named.pid";
12 &lock_file(&make_chroot($config{'named_conf'}));
13 &lock_file(&make_chroot("$conf_directory/db.cache"));
14 $conf_temp = &transname("webmin.named.conf");
15 open(BOOT, ">$conf_temp");
16 print BOOT "options {\n";
17 print BOOT "\tdirectory \"$conf_directory\";\n";
18 print BOOT "\tpid-file \"$pid_file\";\n";
19 print BOOT "\t};\n";
20 print BOOT "\n";
21 $chroot = &get_chroot();
22 if ($chroot && !-d $chroot) {
23         mkdir($chroot, 0755);
24         }
25 if (!-d &make_chroot($conf_directory)) {
26         mkdir(&make_chroot($conf_directory), 0755);
27         }
28 if ($config{'master_dir'} && !-d &make_chroot($config{'master_dir'})) {
29         mkdir(&make_chroot($config{'master_dir'}), 0755);
30         }
31 if ($config{'slave_dir'} && !-d &make_chroot($config{'slave_dir'})) {
32         mkdir(&make_chroot($config{'slave_dir'}), 0777);
33         }
34 if ($pid_file =~ /^(.*)\//) {
35         $pid_dir = $1;
36         if (!-d &make_chroot($pid_dir)) {
37                 mkdir(&make_chroot($pid_dir), 0777);
38                 }
39         }
40 if (!-r &make_chroot($pid_file)) {
41         &open_tempfile(PID, ">".&make_chroot($pid_file));
42         &close_tempfile(PID);
43         &set_ownership(&make_chroot($pid_file));
44         }
45 if ($in{real} == 0) {
46         # Create an empty root domain file... no need to do anything here
47         }
48 elsif ($in{real} == 1) {
49         # Try to download the root servers file from
50         # ftp://rs.internic.net/domain/named.root
51         $err = &download_root_zone("$conf_directory/db.cache");
52         &error($err) if ($err);
53         print BOOT "zone \".\" {\n";
54         print BOOT "\ttype hint;\n";
55         print BOOT "\tfile \"$conf_directory/db.cache\";\n";
56         print BOOT "\t};\n";
57         print BOOT "\n";
58         }
59 elsif ($in{real} == 2) {
60         # Use builtin db.cache
61         &execute_command("cp ./db.cache ".&make_chroot("$conf_directory/db.cache"));
62         print BOOT "zone \".\" {\n";
63         print BOOT "\ttype hint;\n";
64         print BOOT "\tfile \"$conf_directory/db.cache\";\n";
65         print BOOT "\t};\n";
66         print BOOT "\n";
67         }
68 close(BOOT);
69 &copy_source_dest($conf_temp, &make_chroot($config{'named_conf'}));
70 unlink($conf_temp);
71 &unlock_file(&make_chroot("$conf_directory/db.cache"));
72 &unlock_file(&make_chroot($config{'named_conf'}));
73 &set_ownership(&make_chroot("$conf_directory/db.cache"))
74         if ($in{'real'} == 2 || $in{'real'} == 1);
75 &set_ownership(&make_chroot($config{'named_conf'}));
76 &webmin_log("boot");
77 &redirect("start.cgi");
78