3 # Display records of some type from some domain
5 require './bind8-lib.pl';
7 $zone = &get_zone_name($in{'index'}, $in{'view'});
8 $dom = $zone->{'name'};
9 &can_edit_zone($zone) ||
10 &error($text{'recs_ecannot'});
11 &can_edit_type($in{'type'}, \%access) ||
12 &error($text{'recs_ecannottype'});
13 $desc = &text('recs_header', &ip6int_to_net(&arpa_to_ip($dom)));
14 $typedesc = $text{"recs_$in{'type'}"} || $in{'type'};
15 &ui_print_header($desc, &text('recs_title', $typedesc), "",
16 undef, undef, undef, undef, &restart_links($zone));
18 # Show form for adding a record
19 $type = $zone->{'type'};
20 $file = $zone->{'file'};
22 if (!$access{'ro'} && $type eq 'master' && $in{'type'} ne 'ALL') {
23 &record_input($in{'index'}, $in{'view'}, $in{'type'}, $file, $dom,
24 undef, undef, $in{'newname'}, $in{'newvalue'});
26 $shown_create_form = 1;
29 if ($config{'largezones'}) {
31 print &ui_form_start("edit_recs.cgi");
32 print &ui_hidden("index", $in{'index'}),"\n";
33 print &ui_hidden("view", $in{'view'}),"\n";
34 print &ui_hidden("type", $in{'type'}),"\n";
35 print "<b>$text{'recs_find'}</b>\n";
36 print &ui_textbox("search", $in{'search'}, 20),"\n";
37 print &ui_submit($text{'recs_search'}),"\n";
42 if (!$config{'largezones'} || $in{'search'}) {
44 @allrecs = grep { !$_->{'generate'} && !$_->{'defttl'} }
45 &read_zone_file($file, $dom);
47 # Limit to records matching some search
48 foreach $r (@allrecs) {
49 if ($r->{'name'} =~ /\Q$in{'search'}\E/i) {
53 foreach $v (@{$r->{'values'}}) {
54 if ($v =~ /\Q$in{'search'}\E/i) {
68 # Actually show the records
69 if ($in{'type'} eq "ALL") {
70 @recs = grep { $_->{'type'} ne "SOA" } @recs
73 @recs = grep { $_->{'type'} eq $in{'type'} } @recs
76 @recs = &sort_records(@recs);
77 foreach $v (keys %text) {
78 if ($v =~ /^value_([A-Z]+)(\d+)/) {
79 $hmap{$1}->[$2-1] = $text{$v};
83 if (!$access{'ro'} && $type eq 'master') {
84 print &ui_form_start("delete_recs.cgi", "post");
85 print &ui_hidden("index", $in{'index'}),"\n";
86 print &ui_hidden("view", $in{'view'}),"\n";
87 print &ui_hidden("type", $in{'type'}),"\n";
88 print &ui_hidden("sort", $in{'sort'}),"\n";
89 @links = ( &select_all_link("d", $form),
90 &select_invert_link("d", $form) );
92 print &ui_links_row(\@links);
93 if ($in{'type'} =~ /HINFO|WKS|RP|KEY|LOC|SPF/ ||
94 $config{'allow_comments'}) {
96 print &recs_table(@recs);
100 $mid = int((@recs+1)/2);
102 push(@grid, &recs_table(@recs[0 .. $mid-1]));
104 push(@grid, &recs_table(@recs[$mid .. $#recs]));
106 print &ui_grid_table(\@grid, 2, 100,
107 [ "width=50%", "width=50%" ]);
109 print &ui_links_row(\@links);
110 if (!$access{'ro'} && $type eq 'master') {
111 print &ui_submit($text{'recs_delete'}),"\n";
112 if ($in{'type'} eq 'A' || $in{'type'} eq 'AAAA') {
113 print &ui_checkbox("rev", 1, $text{'recs_drev'},
114 $config{'rev_def'} != 1),"\n";
116 print &ui_form_end();
119 elsif (!$shown_create_form) {
121 print "<b>",&text('recs_none', $typedesc),"</b><p>\n";
124 &ui_print_footer("", $text{'index_return'},
125 "edit_$type.cgi?index=$in{'index'}&view=$in{'view'}",
126 $text{'recs_return'});
130 my ($r, $i, $j, $k, $h);
133 # Generate header, with correct columns for record type
134 local (@hcols, @tds);
135 if (!$access{'ro'} && $type eq 'master') {
137 push(@tds, "width=5");
139 push(@hcols, "<a href='edit_recs.cgi?index=$in{'index'}&view=$in{'view'}&type=$in{'type'}&sort=1'>".($in{'type'} eq "PTR" ? $text{'recs_addr'} : $text{'recs_name'})."</a>");
140 push(@hcols, "<a href='edit_recs.cgi?index=$in{'index'}&view=$in{'view'}&type=$in{'type'}&sort=5'>$text{'recs_type'}</a>") if ($in{'type'} eq "ALL");
141 push(@hcols, $text{'recs_ttl'});
142 @hmap = @{$hmap{$in{'type'}}};
144 push(@hcols, "<a href='edit_recs.cgi?index=$in{'index'}&view=$in{'view'}&type=$in{'type'}&sort=2'>$h</a>");
146 if ($in{'type'} eq "ALL" || $is_extra{$in{'type'}}) {
147 push(@hcols, $text{'recs_vals'});
149 if ($config{'allow_comments'} && $in{'type'} ne "WKS") {
150 push(@hcols, "<a href='edit_recs.cgi?index=$in{'index'}&view=$in{'view'}&type=$in{'type'}&sort=4'>$text{'recs_comment'}</a>");
152 $rv .= &ui_columns_start(\@hcols, 100);
154 # Show the actual records
155 for($i=0; $i<@_; $i++) {
157 if ($in{'type'} eq "PTR") {
158 $name = &ip6int_to_net(&arpa_to_ip($r->{'name'}));
160 elsif ($in{'type'} eq "SRV") {
161 $name = $r->{'name'};
166 $name = $r->{'name'};
169 $name = &html_escape($name);
170 $id = &record_id($r);
171 if (!$access{'ro'} && $type eq 'master') {
173 "<a href=\"edit_record.cgi?index=".
174 "$in{'index'}&id=".&urlize($id)."&num=$r->{'num'}&".
175 "type=$in{'type'}&sort=$in{'sort'}&view=$in{'view'}\">".
181 if ($in{'type'} eq 'ALL') {
182 push(@cols, $r->{'type'});
184 if ($r->{'ttl'} =~ /(\d+)([SMHDW]?)/i) {
185 $r->{'ttl'} =~ s/S//i;
186 if ($r->{'ttl'} =~ s/M//i) { $r->{'ttl'} *= 60; }
187 if ($r->{'ttl'} =~ s/H//i) { $r->{'ttl'} *= 3600; }
188 if ($r->{'ttl'} =~ s/D//i) { $r->{'ttl'} *= 86400; }
189 if ($r->{'ttl'} =~ s/W//i) { $r->{'ttl'} *= 604800; }
191 push(@cols, $r->{'ttl'} ? &html_escape($r->{'ttl'}) : $text{'default'});
192 for($j=0; $j<@hmap; $j++) {
194 if ($in{'type'} eq "RP" && $j == 0) {
195 $v .= &convert_illegal(
196 &dotted_to_email($r->{'values'}->[$j]));
198 elsif ($in{'type'} eq "WKS" && $j == @hmap-1) {
199 for($k=$j; $r->{'values'}->[$k]; $k++) {
200 $v .= &convert_illegal($r->{'values'}->[$k]);
204 elsif ($in{'type'} eq "LOC") {
205 $v = &convert_illegal(join(" ", @{$r->{'values'}}));
207 elsif ($in{'type'} eq "KEY" && $j == 3) {
208 $v = substr($r->{'values'}->[$j], 0, 20)."...";
211 $v = &convert_illegal($r->{'values'}->[$j]);
213 if (length($v) > 80) {
214 $v = substr($v, 0, 80)." ...";
218 if ($in{'type'} eq "ALL" || $is_extra{$in{'type'}}) {
219 $joined = join(" ", @{$r->{'values'}});
220 if (length($joined) > 80) {
221 $joined = substr($joined, 0, 80)." ...";
223 push(@cols, $joined);
225 if ($config{'allow_comments'} && $in{'type'} ne "WKS") {
226 push(@cols, &html_escape($r->{'comment'}));
228 if (!$access{'ro'} && $type eq 'master') {
229 $rv .= &ui_checked_columns_row(\@cols, \@tds,
230 "d", $r->{'num'}."/".$id);
233 $rv .= &ui_columns_row(\@cols, \@tds);
236 $rv .= &ui_columns_end();