2 # Actually create multiple zones
4 require './bind8-lib.pl';
6 &ui_print_unbuffered_header(undef, $text{'mass_title'}, "");
7 &error_setup($text{'mass_err'});
9 $access{'ro'} && &error($text{'master_ero'});
11 # Check if the template needs IPs
13 for($i=0; $config{"tmpl_$i"}; $i++) {
14 @c = split(/\s+/, $config{"tmpl_$i"}, 3);
15 if ($c[1] eq 'A' && !$c[2]) {
21 # Build map of taken zones
22 if ($in{'view'} ne '') {
24 @zones = grep { $_->{'viewindex'} eq $in{'view'} &&
25 $_->{'type'} ne 'view' }
27 $view = $conf->[$in{'view'}];
28 &can_edit_view($view) || &error($text{'mass_eviewcannot'});
29 $vn = $view->{'value'};
33 @zones = grep { !$_->{'view'} && $_->{'type'} ne 'view' }
37 %taken = map { $_->{'name'}, $_ } @zones;
40 &get_zone_defaults(\%zd);
43 &allowed_zone_file(\%access, $in{'local'}) ||
44 &error($text{'mass_elocalcannot'});
45 $local = &read_file_contents($in{'local'});
46 $local || &error($text{'mass_elocal'});
47 print "<b>",&text('mass_dolocal', "<tt>$in{'local'}</tt>"),"</b><br>\n";
48 &execute_batchfile($local);
49 print "<b>",$text{'mass_done'},"</b><p>\n";
52 print "<b>",&text('mass_doupload'),"</b><br>\n";
53 &execute_batchfile($in{'upload'});
54 print "<b>",$text{'mass_done'},"</b><p>\n";
57 print "<b>",&text('mass_dotext'),"</b><br>\n";
58 &execute_batchfile($in{'text'});
59 print "<b>",$text{'mass_done'},"</b><p>\n";
62 &webmin_log("mass", undef, $zonecount);
63 &ui_print_footer("", $text{'index_return'});
65 # execute_batchfile(data)
68 local @lines = split(/[\r\n]+/, $_[0]);
73 local @w = split(/:/, $l);
75 if ($dom !~ /^[a-z0-9\.\-\_]+$/) {
76 &line_error($l, $text{'mass_edom'});
80 if (&check_ipaddress($dom)) {
81 $dom = &ip_to_arpa($dom);
87 &line_error($l, $text{'mass_etaken'});
91 # Get the IP addresses
92 local @mips = split(/\s+/, $w[3]);
93 foreach $mip (@mips) {
94 if (!&check_ipaddress($mip)) {
95 &line_error($l, $text{'mass_eip'});
100 local $type = $w[1] || "master";
103 if ($type eq "master") {
104 # Creating a master zone
105 if (!$access{'master'}) {
106 &line_error($l, $text{'mcreate_ecannot'});
111 $base = $config{'master_dir'} ? $config{'master_dir'} :
112 $access{'dir'} eq '/' ? &base_directory($conf) :
114 if ($base !~ /^([a-z]:)?\//) {
115 # Master dir is relative .. make absolute
116 $base = &base_directory()."/".$base;
119 # Make sure a template IP was given, if needed
120 if ($tmpl_ip && !@mips) {
121 &line_error($l, $text{'mass_etmpl'});
125 # Work out the filename
127 if ($file !~ /^\//) {
128 $file = $base."/".$file;
130 if (!&allowed_zone_file(\%access, $file)) {
131 &line_error($l, &text('create_efile2', $file));
136 $file = &automatic_filename($dom, $isrev, $base, $vn);
138 if (-r &make_chroot($file)) {
139 &line_error($l, &text('create_efile4', $file));
143 # Create the zone file and initial records
144 local $master = $config{'default_prins'} ||
145 &get_system_hostname();
148 local $email = $config{'tmpl_email'} || "root\@$master";
149 $email = &email_to_dotted($email);
150 &create_master_records($file, $dom, $master, $email,
151 $zd{'refresh'}.$zd{'refunit'},
152 $zd{'retry'}.$zd{'retunit'},
153 $zd{'expiry'}.$zd{'expunit'},
154 $zd{'minimum'}.$zd{'minunit'},
156 $in{'onslave'} && $access{'remote'},
157 $in{'tmpl'}, $mips[0]);
159 # Create the zone directive
160 $dir = { 'name' => 'zone',
161 'values' => [ $dom ],
163 'members' => [ { 'name' => 'type',
164 'values' => [ 'master' ] },
166 'values' => [ $file ] } ]
169 elsif ($type eq "slave" || $type eq "stub") {
170 # Creating a slave or stub zone
171 if (!$access{'slave'}) {
172 &line_error($l, $text{'screate_ecannot1'});
177 $base = $config{'slave_dir'} ? $config{'slave_dir'} :
178 $access{'dir'} eq '/' ? &base_directory($conf) :
180 if ($base !~ /^([a-z]:)?\//) {
181 # Slave dir is relative .. make absolute
182 $base = &base_directory()."/".$base;
185 # Make sure some master IPs were given
187 &line_error($l, $text{'mass_emips'});
191 # Work out the filename
192 if ($file eq "none") {
193 $file = undef; # no file!
196 if ($file !~ /^\//) {
197 $file = $base."/".$file;
199 if (!&allowed_zone_file(\%access, $file)) {
200 &line_error($l, &text('create_efile2', $file));
205 $file = &automatic_filename($dom, $isrev, $base, $vn);
208 # Create the file now
210 if (!open(ZONE, ">".&make_chroot($file))) {
211 &line_error($l, &text('create_efile3',
216 &set_ownership(&make_chroot($file));
219 # Create the structure
220 local @mdirs = map { { 'name' => $_ } } @mips;
221 local $masters = { 'name' => 'masters',
223 'members' => \@mdirs };
224 $dir = { 'name' => 'zone',
225 'values' => [ $dom ],
227 'members' => [ { 'name' => 'type',
228 'values' => [ $type ] },
233 push(@{$dir->{'members'}},
235 'values' => [ $file ] });
238 elsif ($type eq "forward") {
240 if (!$access{'forward'}) {
241 &line_error($l, $text{'fcreate_ecannot'});
245 # Make sure some master IPs were given
247 &line_error($l, $text{'mass_emips'});
251 # Create the structure
252 local @mdirs = map { { 'name' => $_ } } @mips;
253 local $masters = { 'name' => 'forwarders',
255 'members' => \@mdirs };
256 $dir = { 'name' => 'zone',
257 'values' => [ $dom ],
259 'members' => [ { 'name' => 'type',
260 'values' => [ 'forward' ] },
267 &line_error($l, $text{'mass_etype'});
272 # Add the zone structure
273 &create_zone($dir, $conf, $in{'view'});
274 &set_ownership(&make_chroot($named_conf));
275 &add_zone_access($dom);
277 &line_ok($dom, $type);
281 if ($type eq "master" && $in{'onslave'} && $access{'remote'}) {
282 # Create on slave servers
283 local @slaveerrs = &create_on_slaves($dom,
284 $config{'this_ip'} || &to_ipaddress(&get_system_hostname()),
286 print " \n";
288 $serrs = join(", ", map { "$_->[0]->{'host'} : $_->[1]" } @slaveerrs);
289 print "<font color=#ff0000>",
290 &text('mass_eonslave', $serrs),"</font><br>\n";
293 print &text('mass_addedslaves', $dom),"<br>\n";
301 print "<font color=#ff0000>",&text('mass_eline', $lnum, $_[1], $_[0]),
307 print &text('mass_added'.$_[1], $_[0]),"<br>\n";