%doc>
-- HOST tasks --
%doc>
<%attr>
title => 'DNS Record Tasks'
%attr>
%
%
%#######################################################################
%#
%# Args section
%#
%#######################################################################
<%args>
$user => $ui->get_current_user($r)
$view =>'search'
$action => undef
$search => undef
$submit => undef
$hostname => undef
$show_tasks => undef
$showheader => 1
$ipblock_id => undef
$ip => undef
$add_host_block => undef
$ethernet => undef
$zone_id => undef
%args>
%
%
%
%#######################################################################
%#
%# 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 $IPV4 = Netdot->get_ipv4_regex();
my $IPV6 = Netdot->get_ipv6_regex();
my $MAC = Netdot->get_mac_regex();
my @list;
my @all_zones = Zone->retrieve_all();
%init>
<%perl>
#######################################################################################
# Search
#
#######################################################################################
if ( $action eq "search" && $submit ){
# Remove trailing and leading spaces
my %idx;
if ( $search ){
$search =~ s/^\s*(.*)\s*$/$1/g;
if ( $search =~ /$MAC/ ){
@list = PhysAddr->search(address=>$search);
}elsif ( $search =~ /$IPV4|$IPV6/ ){
@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);
}
} else {
$m->comp('/generic/no_search_criteria.html');
}
#######################################################################################
# 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_block || $add_host_block == 0 ) {
$m->comp('/generic/error.mhtml', error=>"You need to specify a subnet");
}
if ( !(defined $hostname) ) {
$m->comp('/generic/error.mhtml', error=>"You need to specify a hostname");
}
my $block = Ipblock->retrieve($add_host_block);
unless ( $block ){
$m->comp('/generic/error.mhtml', error=>"Could not retrieve Ipblock: $add_host_block");
}
my $ip_strategy = Netdot->config->get("IP_ALLOCATION_STRATEGY");
my $address;
unless ( $address = $block->get_next_free(strategy=>$ip_strategy) ){
$m->comp('/generic/error.mhtml', error=>"Could not get an available address from ".$block->get_label);
}
my %args;
$args{block} = $block;
unless ( $args{zone} = $block->forward_zone() ){
$m->comp("/generic/error.mhtml", error=>"Subnet ".$block->get_label." is not associated with a zone.");
}
$args{address} = $address;
$args{hostname} = $hostname;
$args{ethernet} = $ethernet;
my $rr;
eval {
$rr = RR->add_host(%args);
};
if ( my $e = $@ ){
$m->comp("/generic/error.mhtml", error=>$e);
}else{
$m->comp("../management/host.html", rr=>$rr);
}
}
%perl>