<%doc> -- DNS Record Tasks -- <%attr> title => 'DNS Record Tasks' % % %####################################################################### %# %# Args section %# %####################################################################### <%args> $user => $ui->get_current_user($r) $view =>'search' $action => undef $search => undef $submit => undef $name => undef $show_tasks => undef $showheader => 1 $ipblock_id => undef $ip => undef $add_host_block => undef $add_host_address => undef $add_host_zone => undef $ethernet => undef $duid => undef $zone_id => undef % % % %####################################################################### %# %# INIT section %# %####################################################################### % <%init> my $DEBUG = 0; print '%ARGS is

    ', Dumper(%ARGS), '

' if $DEBUG; $show_tasks = $show_tasks || $user->getAttribute("SHOW_TASKS"); if ( $show_tasks eq "" ) { $user->setAttribute($r, "SHOW_TASKS", "show"); $show_tasks = "show"; } *print_showtaskslink = $m->comp('SELF:.sub_print_showtaskslink'); my $hideheader = 'style="display:none"' if ( !$showheader ); my $MAC = Netdot->get_mac_regex(); my @list; my @all_zones = Zone->retrieve_all(); my $manager = $ui->get_permission_manager($r);
>
DNS Record Tasks
% if ( $manager && $manager->can($user, 'access_admin_section', 'host_tasks:new') ){ % if ( $view eq 'search' ){ [new] % }elsif ( $view eq 'new' ){ [search] % } % } % print_showtaskslink($show_tasks);
">

% if ( $view eq 'search' ){
Search

Name/IP/MAC:

Names within:

% }elsif ( $view eq 'new' ){
Add New Host

Name*:

Zone*: % my $default_zone = Netdot->config->get('DEFAULT_DNSDOMAIN'); % my $zone_select = '
"; % print $zone_select;

A/AAAA records

You need to provide either a Subnet or an IP address.

Selecting a Subnet will tell Netdot to use the next available address

Subnet:

Address:

DHCP host

Ethernet:

DUID: (IPv6 only)

(*) Field is required

% }

<%perl> ####################################################################################### # Search # ####################################################################################### if ( $action eq "search" && $submit ){ # Remove trailing and leading spaces my %idx; # Remove trailing and leading spaces $search = $ui->rem_lt_sp($search); $search ||= '*'; if ( $search =~ /$MAC/ ){ @list = PhysAddr->search(address=>$search); }elsif ( Ipblock->matches_ip($search) ){ @list = Ipblock->search(address=>$search); }else{ my %args = (name=>$search); $args{zone} = $zone_id if ( $zone_id ); @list = RR->search_like(%args); } # Display search results if ( @list ){ if ( scalar @list == 1 ){ my $obj = $list[0]; my $class = $obj->short_class; if ( $class eq 'RR' ){ $m->comp('/management/host.html', id=>$obj->id); }elsif ( $class eq 'Ipblock' ){ $m->comp('/management/ip.html', id=>$obj->id); }elsif ( $class eq 'PhysAddr' ){ $m->comp('/management/mac.html', id=>$obj->id); } }else{ print '
'; print '
'; print "Query $search returned: ".scalar(@list)." matches"; print "
"; print '
'; $m->comp('/generic/sortresults.mhtml', object=>\@list, withedit=>1); print "
\n
"; } } else { $m->comp('/generic/no_search_results.html', search=>$search); } ####################################################################################### # Edit single IP # ####################################################################################### } elsif ( $action eq "edit" && $ipblock_id) { $m->comp('/management/host.html', ipblock=>$ipblock_id, edit=>1); ####################################################################################### # New host # ####################################################################################### } elsif ( $action eq "new" ) { if ( !defined $add_host_zone || $add_host_zone == 0 ) { $m->comp('/generic/error.mhtml', error=>"You need to specify a zone"); } if ( !(defined $name) ) { $m->comp('/generic/error.mhtml', error=>"You need to specify a hostname"); } my %args; if ( $add_host_block && !$add_host_address ){ my $block = Ipblock->retrieve($add_host_block); unless ( $block ){ $m->comp('/generic/error.mhtml', error=>"Could not retrieve Ipblock: $add_host_block"); } $args{subnet} = $block; }else{ $args{address} = $add_host_address; } my $zone = Zone->retrieve($add_host_zone); unless ( $zone ){ $m->comp('/generic/error.mhtml', error=>"Could not retrieve Zone: $add_host_zone"); } $args{name} = $name; $args{zone} = $zone; my $rr; if ( $args{subnet} || $args{address} ){ $args{ethernet} = $ethernet; $args{duid} = $duid if ($duid && !$ethernet); eval { $rr = RR->add_host(%args); }; }elsif ( $ethernet || $duid ){ $m->comp('/generic/error.mhtml', error=>"DHCP host requires an A/AAAA record!"); }else{ eval { $rr = RR->insert(\%args); }; } if ( my $e = $@ ){ $m->comp("/generic/error.mhtml", error=>$e); }else{ $m->comp("../management/host.html", rr=>$rr); } }