Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split "Exclude Private Data" checkbox into individual HINFO and TXT checkboxes #142

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions etc/Default.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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.
#
Expand Down
38 changes: 23 additions & 15 deletions htdocs/export/config_tasks.html
Original file line number Diff line number Diff line change
Expand Up @@ -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>
%
%
Expand Down Expand Up @@ -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">
Expand Down Expand Up @@ -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;
Expand Down
22 changes: 12 additions & 10 deletions lib/Netdot/Exporter/BIND.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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);
Expand All @@ -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

Expand Down Expand Up @@ -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};
Expand All @@ -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')} ){
Expand Down