📄 b9ddns-lib.pl
字号:
print '<td><input name=value0 size=30 value="', $v[0], '"></td></tr>'; print '<td><b>', $text{'value_RP2'}, '</b></td>'; $display_name = &convert_fqdn(($config{'display_fqdn'} ? 1 : -1), $v[1], $origin, 0); print '<td><input name=value1 size=30 value="', $display_name, '"></td></tr>'; unless ($new) { print '<input type=hidden name=oldvalue value="', $v[1], '">'; } } elsif ($type eq 'PTR') { print '<tr><td><b>', $text{'value_PTR1'}, '</b></td>'; print '<td><input name=value0 size=30 value="', $v[0], '"></td></tr>'; unless ($new) { print '<input type=hidden name=oldvalue value="', $v[0], '">'; } } elsif ($type eq 'SRV') { print '<tr><td><b>', $text{'edit_serv'}, '</b></td>'; print '<td><input name=serv value="', $serv, "\" size=20></td>\n"; print '<td><b>', $text{'edit_proto'}, '</b></td>'; print '<td><select name=proto>'; printf '<option value=tcp %s>TCP', ($proto eq 'TCP') ? 'selected' : ''; printf '<option value=udp %s>UDP', ($proto eq 'UDP') ? 'selected' : ''; if ($proto && $proto ne 'TCP' && $proto ne 'UDP') { printf '<option value=%s selected>%s', $proto, $proto; } print '</select></td></tr>'; print '<tr><td><b>', $text{'value_SRV1'}, '</b></td>'; print '<td><input name=value0 size=8 value="', $v[0], '"></td>'; print '<td><b>', $text{'value_SRV2'}, '</b></td>'; print '<td><input name=value1 size=8 value="', $v[1], '"></td></tr>'; print '<td><b>', $text{'value_SRV3'}, '</b></td>'; print '<td><input name=value2 size=8 value="', $v[2], '"></td>'; $display_name = &convert_fqdn($config{'display_fqdn'}, $v[3], $origin, 0); print '<td><b>', $text{'value_SRV4'}, '</b></td>'; print '<td><input name=value3 size=30 value="', $display_name, '"></td></tr>'; unless ($new) { print '<input type=hidden name=oldvalue value="', $v[3], '">'; } } elsif ($type eq 'LOC') { print '<tr><td><b>', $text{'value_LOC1'}, '</b></td>'; print '<td colspan=3><input name=value0 size=45 value="', join(' ', @v), '"></td></tr>'; } elsif ($type eq 'KEY') { print '<tr><td><b>', $text{'value_KEY1'}, '</b></td>'; print '<td><input name=value0 size=15 value="', $v[0], '"></td>'; print '<td><b>', $text{'value_KEY2'}, '</b></td>'; print '<td><input name=value1 size=12 value="', $v[1], '"></td></tr>'; print '<tr><td><b>', $text{'value_KEY3'}, '</b></td>'; print '<td><input name=value2 size=15 value="', $v[2], '"></td></tr>'; print '<tr><td valign=top><b>', $text{'value_KEY4'}, '</b></td>'; print '<td colspan=3><textarea name=value3 rows=5 cols=80>'; print join("\n", &wrap_lines($v[3], 80)); print '</textarea></td></tr>'; } unless ($dynamic) { printf "<tr><td><b>%s</b></td>\n", $config{'allow_comments'} ? $text{'edit_comment'} : ''; printf "<td><input %s name=comment size=30 value=\"%s\"></td></tr>\n", ($config{'allow_comments'} ? '' : 'type=hidden'), $rec{'comment'}; } if ($address_rec) { print '<tr><td><b>', $text{'edit_uprev'}, '</b></td>'; printf '<td><input type=radio name=rev value=1 %s> %s', &checked($config{'rev_def'} == 1), $text{'yes'}; printf '<input type=radio name=rev value=2 %s> %s', &checked($config{'rev_def'} == 2), $text{'edit_over'}; printf "<input type=radio name=rev value=0 %s> %s</td>\n", &checked(! $config{'rev_def'}), $text{'no'}; } elsif ($type eq 'PTR') { print '<tr><td><b>', $text{'edit_upfwd'}, '</b></td>'; printf '<td><input type=radio name=fwd value=1 %s> %s', &checked($config{'rev_def'} == 1), $text{'yes'}; printf '<input type=radio name=fwd value=2 %s> %s', &checked($config{'rev_def'} == 2), $text{'edit_over'}; printf "<input type=radio name=fwd value=0 %s> %s</td>\n", &checked(! $config{'rev_def'}), $text{'no'}; } else { print '<tr><td colspan=2></td>'; } print "<td colspan=2 align=right>\n"; %access = &get_module_acl(); $disabled = ($access{'ro'} || $dynamic == 2) ? 'disabled' : ''; if ($new) { print "<input type=submit $disabled value=\"", $text{'create'}, '">'; } else { print "<input type=submit $disabled value=\"", $text{'save'}, '">'; print "<input type=submit $disabled name=delete value=\"", $text{'delete'}, '">'; } print '</td></tr></table></td></tr></table></form>', "\n"; return;}## Display a table of zones.## zones_table(@zone_link, @zone_title, @view_name, @zone_type)#sub zones_table { my $views = my $i = 0; my $title = my $rest = ''; print '<table border width=100%>'; print "<tr $tb><td><b>$text{'index_zone'}</b></td>"; # # The 'view' column only gets printed if there exists a view name in # the first element of the array. If there is no view name then we are # only seeing zones. # if ($_[2]->[0]) { $views++; print '<td><b>', $text{'View'}, '</b></td>'; } print "<td><b>$text{'index_type'}</b></td></tr>\n"; for ($i = 0; $i < @{ $_[0] }; $i++) { print "<tr $cb>\n"; ($title, $rest) = $_[1]->[$i] =~ /^([^&]+)(( )*.*)$/o; print '<td><a href="', $_[0]->[$i], '">', $title, '</a>', $rest, '</td>'; print '<td>', $_[2]->[$i], '</td>' if ($views); print '<td width=30%>', $_[3]->[$i], '</td></tr>'; } print "</table>\n"; return;}## Transform a compact (with ::) IPv6 address to its expanded form.# Optionally, any missing ':0' values will be appended for subnets.## NOTE: Any subnet containing '::' is by definition invalid since the '::'# symbol represents any missing components. This subroutine simply ignores the# fact that the subnet may be invalid, and expands the '::' accordingly - in# effect turning the subnet into a complete IPv6 address.## expand_ip6(ip, fill_subnet)#sub expand_ip6 { my $i = 0; my $addr = $_[0]; return $addr if ($addr =~ /[\da-f*]{5,}/io || $addr =~ /:::/o || $addr =~ /::.+::/o); # # First we change any subnet to a compacted address form simply by # appending '::' to the subnet. The following code will then treat # the subnet as it does any other IPv6 address and expand it. # $addr = lc($addr); if ($_[1] && $addr =~ /^([\da-f]{1,4}\:){0,6}[\da-f]{1,4}:?$/o) { $addr .= ':'; $addr .= ':' unless ($addr =~ /::$/o); } # # Expand any '::' by looking to see what components of the address # already exist. From that we can simply calculate the number of # missing elements. # if ($addr =~ /^(.*)::(.*)$/o) { $i = $1 =~ tr/:/:/; # Count the leading colons; $i += $2 =~ tr/:/:/; # Add the trailing colons; $i -= 1 unless ($2); # For example, '1::'. $i = ':0' x (6 - $i); $i .= ':' if ($2); $addr =~ s/::/$i/; $addr =~ s/^:/0:/o; $addr =~ s/:$/:0/o; } # # Now remove any leading zeros. If a wildcard is used, then the # specified leading zeros before it are required and will remain. If a # subnet has been given then the leading zeros of the final part of the # address are left alone. # $i = ($addr =~ s/:/:/go); if ($i == 7) { # A full IPv6 address. $addr =~ s/:0{1,3}([\da-f]+)$/:$1/o; } $addr =~ s/(^|:)0{1,3}([\da-f]+)(?=:)/$1$2/go; return $addr;}## Transform an IPv6 address to the expanded form containing all internal zeros.## expandall_ip6(ip)#sub expandall_ip6 { my $addr = $_[0]; $addr = &expand_ip6($addr, 0); $addr =~ s/(^|:)([\da-f]{3})(?=:|$)/${1}0$2/go; $addr =~ s/(^|:)([\da-f]{2})(?=:|$)/${1}00$2/go; $addr =~ s/(^|:)([\da-f])(?=:|$)/${1}000$2/go; return $addr;}## Check if an IPv6 address is properly formatted.## check_ip6address(ip)#sub check_ip6address { my $ipv6 = $_[0]; $ipv6 = &expand_ip6($ipv6, 0); if ($ipv6 =~ /\*/o) { return ($ipv6 =~ /^([\da-f]{1,4}:){0,7}[\da-f]{0,3}\*$/o); } else { return ($ipv6 =~ /^([\da-f]{1,4}:){0,7}[\da-f]{1,4}$/o); }}sub size_unit_choice { my $value = uc($_[1]); print '<select name=', $_[0], '>'; printf '<option %s value="">', ((! $value) ? 'selected' : ''); printf '<option %s value="Bytes">%s', (($value eq 'BYTES') ? 'selected' : ''), 'Bytes'; printf '<option %s value="KB">%s', (($value eq 'KB') ? 'selected' : ''), 'KB'; printf '<option %s value="MB">%s', (($value eq 'MB') ? 'selected' : ''), 'MB'; printf '<option %s value="GB">%s', (($value eq 'GB') ? 'selected' : ''), 'GB'; print "</select>\n"; return;}sub time_unit_choice { my $value = uc($_[1]); my $disabled = (defined($_[2]) && $_[2]) ? 'disabled' : ''; print "<select $disabled name=$_[0]>"; printf '<option %s value="">', ((! $value) ? 'selected' : ''); printf '<option %s value="S">%s', (($value eq 'S') ? 'selected' : ''), $text{'seconds'}; printf '<option %s value="M">%s', (($value eq 'M') ? 'selected' : ''), $text{'minutes'}; printf '<option %s value="H">%s', (($value eq 'H') ? 'selected' : ''), $text{'hours'}; printf '<option %s value="D">%s', (($value eq 'D') ? 'selected' : ''), $text{'days'}; printf '<option %s value="W">%s', (($value eq 'W') ? 'selected' : ''), $text{'weeks'}; print "</select>\n"; return;}## Convert a time value in seconds to/from an abbreviated format.# For example, 300 seconds <-> "5m" or "4d3h2s" <-> 356402 seconds.# A return value of zero indicates an error - bad data format.## convert_time(to_abbreviated, time)#sub convert_time { use integer; my $time = my $time_seconds = my $unit = my $mod = my $n = 0; my $time_str = ''; my @units = ('w', 'd', 'h', 'm'); if ($_[0]) { # Convert from seconds to abbreviated format. $time = $_[1]; if ($time =~ /^(\d+[SMHDW])+$/io) { # Make sure it is abbreviated! $time = &convert_time(0, $time); return &convert_time(1, $time); } return 0 if (! $time || $time =~ /\D/o); # Bad format. for $n (604800, 86400, 3600, 60) { $time_str .= $mod . $units[$unit] if (($mod = $time/$n)); $unit++; $time %= $n; } $time_str .= $time if (! $time_str || $time); $time_str .= 's' if ($time_str =~ /\d$/o); return $time_str; } else { # Convert from abbreviated format to seconds. $time_str = $_[1]; return $time_str if ($time_str !~ /\D/o); return 0 if ($time_str !~ /^(\d+[SMHDW])+$/io); # Bad format. while ($time_str =~ /^(\d+[SMHDW])(.*)$/io) { $time = $1; $time_str = $2; $time_seconds += $1 if ($time =~ /^(\d+)S$/io); $time_seconds += (60 * $1) if ($time =~ /^(\d+)M$/io); $time_seconds += (3600 * $1) if ($time =~ /^(\d+)H$/io); $time_seconds += (86400 * $1) if ($time =~ /^(\d+)D$/io); $time_seconds += (604800 * $1) if ($time =~ /^(\d+)W$/io); } return $time_seconds; }}## In the SOA and RP records the mailbox (email) address must have the '@'# replaced by a '.'. However, we must also cater for usernames that may contain# a dot - these will be escaped. For addresses that have no domain specified# we will add the given origin.## email_to_dotted(email_address, origin)#sub email_to_dotted { my $addr = my $user = my $domain = ''; $addr = $_[0]; if ($addr ne '.') { $addr .= '@' . $_[1] unless ($addr =~ /@/o); $addr .= '.' unless ($addr =~ /\.$/o); if ($addr =~ /^(.+)\@(.+)$/o) { $user = $1; $domain = $2; $user =~ s/\./\\\./go; $addr = $user . '.' . $domain; } } return $addr;}## Convert a mailbox (email) address to its usual format - that is, one that# contains the '@' symbol. Also remove any escape characters.## dotted_to_email(address)#sub dotted_to_email { my $addr = $_[0]; if ($addr ne '.') { $addr =~ s/([^\\])\./$1\@/; $addr =~ s/\\\./\./go; $addr =~ s/\.$//o; } return $addr;}## Set file ownership and permissions if allowed.## set_ownership(file, only_set_owner)#sub set_ownership { if ($config{'file_owner'}) { &system_logged("chown \"$config{'file_owner'}\" $_[0] >/dev/null 2>&1"); } if (! $_[1] && $config{'file_perms'}) { &system_logged("chmod \"$config{'file_perms'}\" $_[0] >/dev/null 2>&1"); } return;}## Simply return whether this option is checked or not.#sub checked { return $_[0] ? 'checked' : '';}## can_edit_view(&access, &view)#sub can_edit_view { my $ok = 0; my $vn = ''; $vn = lc($_[1]->{'value'}); return 1 if ($access{'vlist'} eq '*'); $ok = ($access{'vlist'} =~ /^!/o) ? 0 : 1; foreach (split(/\s+/, $access{'vlist'})) { if ($_ ne '!') { return $ok if (lc($_) eq $vn); } } return ! $ok;}## Given a multi-line string, return an array of lines# wrapped to the given width.## wrap_lines(text, width)#sub wrap_lines { my $rest = ''; my @lines = (); $rest = $_[0]; while (length($rest) > $_[1]) { push(@lines, substr($rest, 0, $_[1])); $rest = substr($rest, $_[1]); } push(@lines, $rest) if ($rest); return @lines;}## Add a new zone to the current user's access list.## add_zone_access(domain)#sub add_zone_access { if ($access{'zones'} ne '*' && $access{'zones'} !~ /^!/o) { $access{'zones'} = join(' ', &unique(split(/\s+/, $access{'zones'}), $_[0])); &save_module_acl(\%access); } return;}## Check to see if named is running or not. Later BIND versions can simply# use rndc for this; earlier versions will have to rely on the pid file.## Values returned are:# 1 - named running# 0 - named not running# -1 - control interface has been disabled# -2 - unknown rndc key error# -3 - unknown rndc error# -4 - unable to determine BIND version# -5 - invalid pid file contents - not a number# -6 - unable to open pid file# -7 - invalid rndc secret# -8 - unsupported rndc secret algorithm## named_running()#sub named_running { my $version = my $pid = 0; my $output = my $pidfile = ''; $version = &bind_version(0); return -4 unless ($version); if ($version >= 9.2) { $output = `$config{'rndc_cmd'} status 2>&1`; if ($output =~ /server is up and running/io) { return 1; } elsif ($output =~ /connect failed: connection refused/io) { return 0; } elsif ($output =~ /or the key is invalid/io) { my $conf = my $controls = ''; $conf = &get_config(); $controls = &find('controls', $conf); return (defined($controls) && ! @{ $controls->{'members'} }) ? -1 : -2; } elsif ($output =~ /bad base64 encoding/io) { return -7; } elsif ($output =~ /unsupported algorithm/io) { return -8; } else { return -3; } } else { $pidfile = $config{'chroot'} . &get_pidpath(); if (! -f $pidfile) { return 0; } elsif (! -s $pidfile) { return 0; } elsif (open(PID, $pidfile)) { $pid = <PID>; close(PID); if ($pid =~ /^\d+$/o) { return (kill(0, $pid)); } else { return -5; } } else { return -6; } }}## This subroutine returns a text string corresponding to the code.## named_err(code)#sub named_err { my $str = ''; my $code = $_[0]; return $str if ($code >= 0); if ($code == -1) { $str = 'named_ctrl_disabled'; } elsif ($code == -2) { $str = 'named_ctrl_rndc_key'; } elsif ($code == -3) { $str = 'named_ctrl_rndc'; } elsif ($code == -4) { $str = 'named_ctrl_bind_ver'; } elsif ($code == -5) { $str = 'named_ctrl_pid_contents'; } elsif ($code == -6) { $str = 'named_ctrl_pid_open'; } elsif ($code == -7) { $str = 'named_ctrl_key_encoding';
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -