Skip to content
Permalink
Browse files

Split "Exclude Private Data" checkbox into individual HINFO and TXT c…

…heckboxes

Allow HINFO and TXT records to be individually included in the export of
BIND zones. Additionally, provide configurable "default state" for the
checkboxes on the Export page.
  • Loading branch information
mzagrabe committed May 1, 2019
1 parent 099ae98 commit 4441c059b8aa94459eaf88bb46067ee612589294
Showing with 40 additions and 25 deletions.
  1. +5 −0 etc/Default.conf
  2. +23 −15 htdocs/export/config_tasks.html
  3. +12 −10 lib/Netdot/Exporter/BIND.pm
@@ -746,6 +746,11 @@ DNS_NAME_USER_INPUT_REGEX => '[^A-Za-z0-9\.\-]',
# list of patterns to match in the whole record.
TXT_RECORD_EXCEPTIONS => ['\._domainkey\.', 'v=spf' ],

# Optionally allow the site administrator to override the
# default state of the "exclude private data" check boxes.
CHECKBOX_CHECKED_EXCLUDE_HINFO_PRIVATE_DATA => 1,
CHECKBOX_CHECKED_EXCLUDE_TXT_PRIVATE_DATA => 1,

#
# Default values for HINFO records.
#
@@ -15,16 +15,17 @@
%#
%#######################################################################
<%args>
@config_types => undef
$user => $ui->get_current_user($r)
$submit => undef
$showheader => 1
$hideheader => undef
@zones => undef
$bind_force => undef
$dhcpd_force => undef
$bind_no_priv => undef
@scopes => undef
@config_types => undef
$user => $ui->get_current_user($r)
$submit => undef
$showheader => 1
$hideheader => undef
@zones => undef
$bind_force => undef
$dhcpd_force => undef
$bind_no_priv_txt => undef
$bind_no_priv_hinfo => undef
@scopes => undef
</%args>
%
%
@@ -84,9 +85,15 @@
<input type="checkbox" name="bind_force">
<label for="bind_force">Force export even if no pending changes</label>
</p>
% my $exclude_hinfo_checked_state = Netdot->config->get('CHECKBOX_CHECKED_EXCLUDE_HINFO_PRIVATE_DATA') == 1 ? ' CHECKED' : '';
<p>
<input type="checkbox" name="bind_no_priv" CHECKED>
<label for="bind_no_priv">Exclude Private Data (HINFO and TXT records)</label>
<input type="checkbox" name="bind_no_priv_hinfo"<% $exclude_hinfo_checked_state%>>
<label for="bind_no_priv_hinfo">Exclude HINFO private data</label>
</p>
% my $exclude_txt_checked_state = Netdot->config->get('CHECKBOX_CHECKED_EXCLUDE_TXT_PRIVATE_DATA') == 1 ? ' CHECKED' : '';
<p>
<input type="checkbox" name="bind_no_priv_txt"<% $exclude_txt_checked_state%>>
<label for="bind_no_priv_txt">Exclude TXT private data</label>
</p>
</fieldset>
<fieldset class="small">
@@ -132,9 +139,10 @@
foreach my $type ( @config_types ){
my %args;
if ( $type eq 'BIND' ){
$args{zone_ids} = \@zones if ( scalar @zones && $zones[0] ne "" );
$args{force} = 1 if ($bind_force);
$args{nopriv} = 1 if ($bind_no_priv);
$args{zone_ids} = \@zones if ( scalar @zones && $zones[0] ne "" );
$args{force} = 1 if ($bind_force);
$args{nopriv_hinfo} = 1 if ($bind_no_priv_hinfo);
$args{nopriv_txt} = 1 if ($bind_no_priv_txt);
}elsif ( $type eq 'DHCPD' ){
$args{force} = 1 if ($dhcpd_force);
$args{scopes} = \@scopes if @scopes;
@@ -45,8 +45,9 @@ sub new{
Arguments:
Hashref with the following keys:
zones - Array ref. List of zone names to export.
nopriv - Exclude private data from zone file (TXT and HINFO)
zones - Array ref. List of zone names to export.
nopriv_txt - Exclude TXT private data from zone file
nopriv_hinfo - Exclude HINFO private data from zone file
Returns:
True if successful
Examples:
@@ -91,7 +92,7 @@ sub generate_configs {
my @pending = HostAudit->search(zone=>$zone->name, pending=>1);
Netdot::Model->do_transaction(sub{
if ( @pending || $argv{force} ){
my $path = $self->print_zone_to_file(zone=>$zone, nopriv=>$argv{nopriv});
my $path = $self->print_zone_to_file(zone=>$zone, nopriv_txt=>$argv{nopriv_txt}, nopriv_hinfo=>$argv{nopriv_hinfo});
# Need to query again because the above method updates the serial
# which creates another hostaudit record
@pending = HostAudit->search(zone=>$zone->name, pending=>1);
@@ -114,14 +115,15 @@ sub generate_configs {

=head2 print_zone_to_file - Print the zone file using BIND syntax
Args:
Args:
Hashref with following key/value pairs:
zone - Zone object
nopriv - Flag. Exclude private data (TXT and HINFO)
Returns:
zone - Zone object
nopriv_txt - Flag. Exclude TXT private data from zone file
nopriv_hinfo - Flag. Exclude HINFO private data from zone file
Returns:
Path of file written to
Examples:
my $path = $bind->print_to_file(zone=>$zone, nopriv=>1);
my $path = $bind->print_to_file(zone=>$zone, nopriv_txt=>1, nopriv_hinfo=>1);
=cut

@@ -175,7 +177,7 @@ sub print_zone_to_file {
}
}else{
foreach my $data ( sort keys %{$rec->{$name}->{$type}} ){
if ( $argv{nopriv} && $type eq 'HINFO' ){
if ( $argv{nopriv_hinfo} && $type eq 'HINFO' ){
next;
}
my $ttl = $rec->{$name}->{$type}->{$data};
@@ -190,7 +192,7 @@ sub print_zone_to_file {

my $line = "$name\t$ttl\tIN\t$type\t$data\n";

if ( $argv{nopriv} && $type eq 'TXT' ){
if ( $argv{nopriv_txt} && $type eq 'TXT' ){
# We're told to exclude TXT records
# Allow exceptions from config
if ( my @patterns = @{$self->config->get('TXT_RECORD_EXCEPTIONS')} ){

0 comments on commit 4441c05

Please sign in to comment.
You can’t perform that action at this time.