<%doc> -- HOST tasks -- % <%attr> title => 'Host Tasks' % % %####################################################################### %# %# Args section %# %####################################################################### <%args> $action => undef $search => undef $user => $ui->get_current_user($r) $submit => undef $show_tasks => undef $ipblock => undef $ipblock_action => undef $showheader => 1 % % % %####################################################################### %# %# 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();
>
DNS/DHCP Tasks
% print_showtaskslink($show_tasks);
"> <%perl> my (@ipblocks, @zones); my $ao = $ui->get_allowed_objects($r, $user); print '

    ', Dumper($ao), '' if $DEBUG;
    if ( exists $ao->{Ipblock} ){
        foreach my $id ( keys %{$ao->{Ipblock}} ){
    	if ( my $ip = Ipblock->retrieve($id) ){
    	    push @ipblocks, $ip;
    	}else{
    	    delete $ao->{Ipblock}->{$id};
    	}
        }
    }
    if ( exists $ao->{Zone} ){
        foreach my $id ( keys %{$ao->{Zone}} ){
    	if ( my $zone = Zone->retrieve($id) ){
    	    push @zones, $zone;
    	}else{
    	    delete $ao->{Zone}->{$id};
    	}
        }
    }

    my %ipb_actions = (
        'show_block'     => 'Show Subnet',
        'browse_records' => 'Browse Records',
        'add_host'       => 'Add New Host',
        );

            Search (regular expression)

            Name/IP/MAC:

    % if ( @ipblocks ){

            IP Block Actions

    % }

    % if ( @zones ){

            My Zones

    % }

<%perl> if ( $submit && $ipblock ){ if ( $ipblock_action eq 'browse_records' ){ my $ipblock = Ipblock->retrieve($ipblock); if ( my $zone = $ipblock->forward_zone ){ my $records = $zone->get_hosts($ipblock->id); $m->comp('/management/hostlist.mhtml', records=>$records, withedit=>1, return_args=>"?ipblock=$ipblock&ipblock_action='browse_records'"); }else{ $m->comp('/generic/error.mhtml', error=>$ipblock->get_label." not associated with a zone"); } }elsif ( $ipblock_action eq 'show_block' ){ $m->comp('../management/ip.html', id=>$ipblock, user=>$user); }elsif ( $ipblock_action eq 'add_host' ){ $m->comp('add_host.html', add_host_block=>$ipblock); } }elsif ( $search ){ $search =~ s/^\s*(.*)\s*$/$1/g; my %rrids; my @allrecords; foreach my $ipblock ( @ipblocks ){ if ( my $zone = $ipblock->forward_zone ){ my $records = $zone->get_hosts($ipblock->id); push @allrecords, @$records; } } # If user has permissions on whole zones, add those records if ( @zones ){ foreach my $z ( @zones ){ my $records = $z->get_hosts(); push @allrecords, @$records; } } # @allrecords contains arrayrefs containing: # rr.id, rr.name, ip.id, ip.address, ip.version, physaddr.id, physaddr.address foreach my $row ( @allrecords ){ my ($rrid, $rrname, $ipid, $ipaddr, $ipver, undef, $physaddr) = @$row; my $regex = eval { qr/$search/i }; if ( defined $regex ){ if ( $rrname =~ /$regex/ ){ $rrids{$rrid} = $row; }elsif ( $physaddr =~ /$regex/ ){ $rrids{$rrid} = $row; }elsif ( $ipaddr && $ipver ){ my $ip = Ipblock->int2ip($ipaddr, $ipver); if ( $ip =~ /$regex/ ){ $rrids{$rrid} = $row; } } }else{ $m->comp('/generic/error.mhtml', error=>"Invalid regular expression: $search"); } } # Display search results if ( my @list = values %rrids ){ if ( scalar(@list) == 1 ){ my $row = $list[0]; my $id = $row->[0]; $m->comp('/management/host.html', id=>$id); }else{ print '
'; print '
'; print "Query $search returned: ".scalar(@list)." matches"; print "
"; print '
'; $m->comp('/management/hostlist.mhtml', records=>\@list, withedit=>0); print "
\n
"; } } else { $m->comp('/generic/no_search_results.html', search=>$search); } }