<%doc> Interface for IP blocks (both addresses and subnets) % % <%attr> title => 'IP' section => 'Management' % % <%args> $id => undef $user => $ui->get_current_user($r) $search => undef $_action => 'SHOW_ROOTS' $delete => undef $recursivedel => undef $add_range_start => undef $add_range_end => undef $add_block_prefix => undef $add_block_parent => undef $range_owner => undef $range_status => undef $range_used_by => undef $range_description => undef $range_gen_dns => undef $range_fw_zone => undef $name_prefix => undef $name_suffix => undef $block_owner => undef $block_status => undef $block_used_by => undef $block_description => undef $newblock => undef $parent => undef $length => undef $edit => undef $edit_children => undef $editattr => undef $submit => undef $rootversion => 4 $view_format => Netdot->config->get('DEFAULT_IPBLOCK_VIEW') $rowsize => Netdot->config->get('DEFAULT_IPBLOCK_ROWSIZE') $dividefreespace => 'max' $arp_limit => 10 $ip_list_sort => 'Address' $show_ch_util => 0 $state_digest => undef @link_zones => undef @new_rev_zones => undef $new_a_name => undef $new_a_zone => undef $template_zone_for_rev => undef $new_blocks_list => undef $new_blocks_status => undef $tree_version => undef $view => 'Children' $add_access_type => undef $add_access_id => undef % % <%init> use integer; my $DEBUG = 0; my $o; my $ci = 0; my $title; my @list; my $edit_ip = ( $edit && $edit eq "ipinfo" ) ? 1 : 0; my $edit_block = ( $edit && $edit eq "blockinfo" ) ? 1 : 0; my $edit_comments = ( $edit && $edit eq "comments" ) ? 1 : 0; my $max_ips = Netdot->config->get('SHOW_COUNT_THRESHOLD'); my $added_ip = 0; my $added_block = 0; my $covering_block; my $BLOCK_VIEW_MAX; print '%ARGS is

    ', Dumper(%ARGS), '

' if $DEBUG; my $manager = $ui->get_permission_manager($r); if ( $id ){ if ( $o = Ipblock->retrieve($id) ){ # Check if user can view this object my $manager = $ui->get_permission_manager($r); unless ( $manager && $manager->can($user, "view", $o) ){ $m->comp('/generic/error.mhtml', error=>"You don't have permission to view this object"); } $title = $o->get_label; }else{ $m->comp('/generic/error.mhtml', error => "Could not retrieve Ipblock id: $id"); } # Block View has some limits if ( $o->status->name eq 'Subnet' ){ $BLOCK_VIEW_MAX = Netdot->config->get('SUBNET_BLOCK_VIEW_MAX_PREFIX'); }elsif ( $o->status->name eq 'Container' ){ $BLOCK_VIEW_MAX = Netdot->config->get('CONTAINER_BLOCK_VIEW_MAX_PREFIX'); } if ( $o->version == 4 ){ if ( $view_format eq 'block' ){ if ( $BLOCK_VIEW_MAX && ($o->prefix < $BLOCK_VIEW_MAX) ){ $view_format = 'list'; } } }elsif ( $o->version == 6 ){ $view_format = 'list' if $view_format eq 'block'; } }else{ $title = "Search"; } # By default, view object after any operation # ( some exceptions will override ) my $view_object = 1; unless ( $view_format =~ /^block|list|tree$/ ){ $m->comp('/generic/error.mhtml', error => "Invalid view format: $view_format. Perhaps wrongly configured in etc/Site.conf?"); } %
<%perl> ####################################################################################### # Show Root Blocks # ####################################################################################### if( $_action eq "SHOW_ROOTS" && !$id && $rootversion ){ unless ( $manager && $manager->can($user, "access_section", 'ip.html:show_roots') ){ $m->comp('/generic/error.mhtml', error => "You do not have permission to view this section"); } my $get_roots = $ui->config->get('SHOW_ROOT_BLOCKS'); if ( $get_roots ){ @list = Ipblock->get_roots($rootversion); my $max = $ui->config->get('ROOT_BLOCK_SHOW_MAX');
Root Blocks: (<% scalar(@list) %>)
% my $show_checked = ($show_ch_util)? 'CHECKED' : ""; Show Utilization: > Version:
% if ( @list && scalar(@list) < $max ){ <& ipblock_list.mhtml, parent=>0, objects=>\@list, type=>"block", show_utilization=>$show_ch_util &> % }else{ The number of root blocks exceeds the configured threshold (<% $max %>). Please use the search boxes. % }
<%perl> } ####################################################################################### # Update # ####################################################################################### }elsif( $_action eq "UPDATE" ){ if ($submit eq "cancel") { # Get rid of the new block if ( $id != 0 ){ unless ( $o = Ipblock->retrieve($id) ){ $m->comp('/generic/error.mhtml', error => "Can't retrieve Ipblock id $id"); } $o->delete; } # Show parent block # reset all request variables to make this look like a view request $view_object = 1; $edit = 0; $id = $parent; if ( $id != 0 ){ unless ( $o = Ipblock->retrieve($id) ){ $m->comp('/generic/error.mhtml', error => "Can't retrieve Ipblock id $id"); } } } else { my $new_digest = $o->get_digest(); eval { Netdot::Model->do_transaction( sub{ if ( $state_digest && ($state_digest ne $new_digest) ){ $ui->throw_user("This IP changed while you were editing!"); } $ui->form_to_db(%ARGS); }); }; if ( my $e = $@ ){ $m->comp('/generic/error.mhtml', error=>$e); }else{ # Do this to 'flush' the values associated with the object # before redisplaying $o = undef; if ( $id ){ $o = Ipblock->retrieve($id); } } } ####################################################################################### # Update Children # ####################################################################################### }elsif( $_action eq "UPDATE_CHILDREN" ){ eval { $ui->form_to_db(%ARGS) }; if ( my $e = $@ ){ $m->comp('/generic/error.mhtml', error=>$e); }else{ # Do this to 'flush' the values associated with the object # before redisplaying $o = undef; if ( $id ){ $o = Ipblock->retrieve($id); } } ####################################################################################### # ADD/MODIFY RANGE # ####################################################################################### }elsif ( $_action eq 'EDIT_RANGE'){ unless ( $manager && $manager->can($user, "edit", $o) ){ $m->comp('/generic/error.mhtml', error=>"You don't have permission to edit this object"); } if ( $add_range_start && $add_range_end ){ if ( $range_status eq 'Delete' ){ eval { Netdot::Model->do_transaction( sub{ $o->remove_range(start => $add_range_start, end => $add_range_end); }); }; }else{ eval { Netdot::Model->do_transaction( sub{ $o->add_range(start => $add_range_start, end => $add_range_end, status => $range_status, owner => $range_owner, used_by => $range_used_by, description => $range_description, gen_dns => $range_gen_dns, name_prefix => $name_prefix, name_suffix => $name_suffix, fzone => $range_fw_zone, ); }); }; } if ( my $e = $@ ){ $m->comp('/generic/error.mhtml', error=>$e); }else{ $m->comp('.show_message', title=>"Action Message", msg=>"Address Range Modified Successfully"); $id = $o->id; } }else{ $m->comp('/generic/error.mhtml', error=>"You need to specify start and end addresses"); } ####################################################################################### # ADD/MODIFY BLOCK # ####################################################################################### }elsif ( $_action eq "ADD_BLOCK" ){ # We need the parent to determine if there are sufficient rights to add # a block, so if not passed, we require Admin my $parent; if ( $add_block_parent ){ $parent = Ipblock->retrieve($add_block_parent) || $m->comp('/generic/error.mhtml', error=>"Cannot retrieve IPblock id $add_block_parent"); unless ( $manager && $manager->can($user, 'edit', $parent) ){ $m->comp('/generic/error.mhtml', error=>"You don't have permission to add blocks here"); } }else{ unless ( $manager && $manager->can($user, 'access_admin_section', 'ip.html:add_block') ){ $m->comp('/generic/error.mhtml', error=>"You don't have permission to do this"); } } unless ( $add_block_prefix ){ $m->comp('/generic/error.mhtml', error=>"You need to specify IP/prefix"); } $add_block_prefix =~ s/\s+//g; # Remove spaces if ( $submit && (($submit eq 'confirm') || ($submit eq 'Save')) ){ undef($submit); my $nip = NetAddr::IP->new($add_block_prefix) || $m->comp('/generic/error.mhtml', error=>"Invalid block: $add_block_prefix"); my ($address, $prefix) = ($nip->addr, $nip->masklen); if ( (($nip->version == 4 && $prefix != 32) || ($nip->version == 6 && $prefix != 128)) && ($block_status eq 'Dynamic' || $block_status eq 'Static') ){ $m->comp('/generic/error.mhtml', error=>"IP block cannot be 'Dynamic' or 'Static'. Specify IP Range instead."); } my $block; # This has happened. Can't figure out why, but this should avoid errors if ( defined $block_owner && ref($block_owner) eq 'ARRAY' ){ $block_owner = $block_owner->[0]; } if ( defined $block_used_by && ref($block_used_by) eq 'ARRAY' ){ $block_used_by = $block_used_by->[0]; } eval { my %args = (status => $block_status, owner => $block_owner, used_by => $block_used_by, description => $block_description, ); if ( $block = Ipblock->search(address=>$address, prefix=>$prefix)->first ){ if ( $add_block_parent ) { $ui->throw_user("This IP has already been set to '" . $block->status->name . "', possibly by someone else."); }else{ $block->update(\%args); } }else{ $args{address} = $address; $args{prefix} = $prefix; $args{parent} = $add_block_parent if $add_block_parent; $block = Ipblock->insert(\%args); } }; if ( my $e = $@ ){ $m->comp('/generic/error.mhtml', error=>$e); }elsif ( $block ){ $o = $block; $id = $block->id; if( $o->is_address ) { $added_ip = 1; }else { $added_block = 1; } if ( $o->version == 6 ){ $view_format = 'list'; } } }else{ $m->comp('/generic/confirm.html', %ARGS, target =>'../management/ip.html', message =>'The IP address or block '.$add_block_prefix.' does not yet exist. '. 'Are you sure that you want to create it?', ); } ####################################################################################### # Add multiple blocks (from partitions in container.mhtml) # ####################################################################################### }elsif( $_action eq "ADD_BLOCKS" ){ unless ( $new_blocks_list && $new_blocks_status ){ $m->comp('/generic/error.mhtml', error=>"Missing list of blocks or desired status"); } my @new_blocks = split ',', $new_blocks_list; eval { Netdot::Model->do_transaction( sub{ foreach my $b ( @new_blocks ){ my ($addr, $pref) = split '/', $b; Ipblock->insert({address=>$addr, prefix=>$pref, status=>$new_blocks_status}); } }) }; if ( my $e = $@ ){ $m->comp('/generic/error.mhtml', error=>"$e"); }else{ $m->comp('.show_message', title=>"Action Message", msg=>"IP blocks created successfully"); } ####################################################################################### # ENABLE DHCP # ####################################################################################### }elsif ( $_action eq 'ENABLE_DHCP'){ unless ( $manager && $manager->can($user, 'access_admin_section', 'ip.html:enable_dhcp') ){ $m->comp('/generic/error.mhtml', error=>"You don't have permission to enable DHCP"); } unless ( $ARGS{dhcp_global_scope} ){ $m->comp('/generic/error.mhtml', error=>"You need to specify at least the global scope"); } my $container = delete $ARGS{dhcp_global_scope}; my %args = (container=>$container); # Active flag my $active = delete $ARGS{dhcp_active}; $args{active} = (defined $active && $active eq 'on')? 1 : 0; # Grab all the dhcp options & declarations foreach my $arg ( %ARGS ){ if ( $arg =~ /^dhcp_/ ){ my $value = $ARGS{$arg}; if ( $arg =~ /^dhcp_(.*)$/ ){ my $attr = $1; $attr =~ s/^option_/option /; $attr =~ s/_/-/g; $args{attributes}{$attr} = $value; }; } } eval { $o->enable_dhcp(%args); }; if ( my $e = $@ ){ $m->comp('/generic/error.mhtml', error=>$e); }else{ $m->comp('.show_message', title=>"Action Message", msg=>"DHCP enabled Successfully"); } ####################################################################################### # Delete # ####################################################################################### }elsif ( $_action eq "DELETE" ){ % unless ( $manager && $manager->can($user, "delete", $o) ){ % $m->comp('/generic/error.mhtml', error=>"You don't have permission to delete this object"); % }
Confirm

Are you sure you want to delete <% $o->get_label %> ? % if ( $o->children ){

Delete children blocks % }

<%perl> # Do not continue with object display $view_object = 0; ####################################################################################### # Confirm Delete # ####################################################################################### }elsif ( $_action eq "CONFIRM_DELETE" ){ unless ( $manager && $manager->can($user, "delete", $o) ){ $m->comp('/generic/error.mhtml', error=>"You don't have permission to delete this object"); } my ($address, $prefix, $version) = ($o->address, $o->prefix, $o->version); my $parentid = $o->parent->id if ( $o->parent ); # Remove from Database # my $rec = ($recursivedel)? 1 : 0; eval { $o->delete( recursive => $rec ) }; if ( my $e = $@ ){ $m->comp('/generic/error.mhtml', error=>$e); } if ($rec){ $m->comp('.show_message', title=>"Action Message", msg=>"

Block $address/$prefix and all its children blocks have been deleted"); }else{ $m->comp('.show_message', title=>"Action Message", msg=>"

Block $address/$prefix has been deleted"); } # Show parent block # after block has been deleted $id = $parentid; if ($id != 0){ unless ( $o = Ipblock->retrieve($id) ){ $m->comp('/generic/error.mhtml', error => "Can't retrieve Ipblock id $id"); } } ####################################################################################### # LINK ZONES # ####################################################################################### }elsif ( $_action eq 'LINK_ZONES' ){ if ( scalar @link_zones && $link_zones[0] ne "" ){ foreach my $z ( @link_zones ){ eval { SubnetZone->insert({subnet=>$o, zone=>$z}); }; if ( my $e = $@ ){ $m->comp('/generic/error.mhtml', error=>"Problem linking zones to this subnet: $e"); }else{ $m->comp('.show_message', title=>"Action Message", msg=>"

Zone(s) linked successfully"); } } }else{ $m->comp('/generic/error.mhtml', error=>"Please select one or more zones to link to this subnet"); } ####################################################################################### # ADD_REV_ZONE # ####################################################################################### }elsif ( $_action eq 'ADD_REV_ZONE' ){ if ( @new_rev_zones && ($new_rev_zones[0] ne "") ){ eval { Netdot::Model->do_transaction(sub{ foreach my $name ( @new_rev_zones ){ my %args = (name=>$name); $args{template} = $template_zone_for_rev if ( $template_zone_for_rev ); my $z = Zone->insert(\%args); } }); }; if ( my $e = $@ ){ $m->comp('/generic/error.mhtml', error=>"Problem creating new reverse zones: $e"); }else{ $m->comp('.show_message', title=>"Action Message", msg=>"

Reverse zone(s) created successfully"); } }else{ $m->comp('/generic/error.mhtml', error=>"Please provide a name for at least one reverse zone"); } ####################################################################################### # ADD_A_RECORD # ####################################################################################### }elsif ( $_action eq 'ADD_A_RECORD' ){ unless ( $manager && $manager->can($user, "edit", $o) ){ $m->comp('/generic/error.mhtml', error=>"You don't have permission to edit this object"); } unless ( $new_a_name && $new_a_zone ){ $m->comp('/generic/error.mhtml', error=>"Adding a DNS record requires both a name and a zone"); } eval { RR->insert({type=>"A", name=>$new_a_name, zone=>$new_a_zone, ipblock=>$o}); }; if ( my $e = $@ ){ $m->comp('/generic/error.mhtml', error=>$e); }else{ $m->comp('.show_message', title=>"Action Message", msg=>"A or AAAA record added successfully"); } ####################################################################################### # REBUILD_TREE # ####################################################################################### }elsif ( $_action eq 'REBUILD_TREE' ){ if ( $tree_version eq '4' || $tree_version eq 'all' ){ Ipblock->build_tree(4); }elsif ( $tree_version eq '6' || $tree_version eq 'all' ){ Ipblock->build_tree(6); } $m->comp('.show_message', title=>"Action Message", msg=>"IP Tree Rebuilt Successfully"); } ####################################################################################### # View # ####################################################################################### if ( $id && $view_object ){ if ( $edit ){ % my $digest = $o->get_digest(); % if ( $edit_ip || $edit_block || $edit_comments ){ % } % } <%perl> my @line; if ( my @parents = $o->get_ancestors ){ foreach my $par ( reverse @parents ){ push (@line, "id . "\">" . $par->get_label . ""); } push (@line, ''.$o->get_label.''); }

[*]: % if ( @line ){ % print join ' : ', @line; % }else{ <% $o->get_label %> % }
% if ( $o->is_address ){ %####################################################################################### %# View IP address %#######################################################################################
% if ($edit eq "ipinfo"){ % if ($added_ip) { % my @parents = $o->get_ancestors; % } else { % } % }else{ [refresh] % if ( $manager && $manager->can($user, 'access_section', 'ip.html:edit_ipinfo') ){ % if ( $manager && $manager->can($user, 'edit', $o) ){ [edit] % } % if ( $manager && $manager->can($user, 'delete', $o) ){ [delete] % } % } % }
<%perl> my @field_headers; my @cell_data; ################################################################ # Address my %addr_tmp = $ui->form_field(object=>$o, column=>"address", edit=>$edit_ip, htmlExtra=>"style='width: 15em'"); push( @field_headers, $addr_tmp{'label'} ); push( @cell_data, $addr_tmp{'value'} ); push( @field_headers, $ui->col_descr_link('Ipblock', 'status', 'Status: ') ); my $status; my @valid_block_status = qw ( Static Dynamic Reserved ); if ( my $sn = $o->status->name ){ if ( $edit eq "ipinfo" ){ $status = qq(
"; }else{ $status = qq($sn); } } push( @cell_data, $status ); my @fields = ('description', 'first_seen', 'last_seen', 'owner', 'used_by'); $ui->add_to_fields(o=>$o, edit=>$edit_ip, fields=>\@fields, field_headers=>\@field_headers, cell_data=>\@cell_data); push( @field_headers, "Interface:" ); push( @cell_data, $ui->select_lookup(object=>$o, table=>"Ipblock", column=>'interface', lookup=>"Interface", edit=>$edit_ip, returnAsVar=>1, linkPage=>1) ); push( @field_headers, "Device:" ); push( @cell_data, eval { my $device; $device = $o->interface->device if ($o->interface); $device ||= ($o->snmp_devices)[0]; if ( $device ){ qq().$device->get_label().""; }else{ " "; } } ); %# actually output the table to the browser <& /generic/attribute_table.mhtml, field_headers=>\@field_headers, data=>\@cell_data, width=>"2", headercolwidth=>"15%", datacolwidth=>"35%" &>
%################################################################ %# Comments section
Comments
% if ( $edit eq 'comments' ){ % }else{ % if ( $manager && $manager->can($user, "edit", $o) ){ [edit] % }else{ % } % }
<%perl> my $edit_comments = ($edit eq 'comments') ? 1 : 0; my %tmp; %tmp = $ui->form_field(object=>$o, column=>"info", edit=>$edit_comments); print $tmp{value};
%################################################################ <%perl> if (!$edit){ print '
'; print '
DNS A Records
'; print '
'; if ( ($_action ne 'VIEW_ADD_A_RECORD') && $manager && $manager->can($user, 'edit', $o) ){ print "[add]"; }else{ print ' '; } print '
'; print '
'; if ( $_action eq 'VIEW_ADD_A_RECORD' ){ my $zone = $o->forward_zone(); # Make sure that user does not add a record to a zone for which # they don't have permissions my @zone_list; if ( $zone ){ @zone_list = ( $zone ); } foreach my $z ( sort { $a->name cmp $b->name } Zone->retrieve_all ){ next if $z->is_dot_arpa; next unless $z->active; next if $zone && ($z->id == $zone->id); if ( $manager && $manager->can($user, 'edit', $z) ){ push @zone_list, $z; } }
Name:

<%perl> }else{ my @rraddrs = $o->a_records(); my @rrs = map { $_->rr } @rraddrs; $m->comp('/generic/sortresults.mhtml', object=>\@rrs); } print '
'; print '
'; my @ptrs = $o->ptr_records(); my @prrs = map { $_->rr } @ptrs; print '
'; print '
DNS PTR Records
'; print '
'; if ( $manager && $manager->can($user, 'edit', $o) ){ print "[add]"; }else{ print ' '; } print '
'; print '
'; $m->comp('/generic/sortresults.mhtml', object=>\@prrs); print '
'; print '
'; } # Do not show DHCP scope unless the subnet has DHCP enabled if ($o->parent && $o->parent->dhcp_scopes) { my $gscope = $o->parent->dhcp_scopes->first->container; my @scopes = $o->dhcp_scopes; print '
'; print '
DHCP Host
'; print '
'; if ( @scopes ){ print ' '; }else{ # Let user add a scope (takes user to another page) print ' '; if ( !$edit ){ if ( $manager && $manager->can($user, 'edit', $o) ){ print '[add]'; } } } print '
'; print '
'; $m->comp('/generic/sortresults.mhtml', object=>\@scopes); print '
'; #close containerbody of DHCP print '
'; #close container of DHCP } if ( $edit ){ print ''; } % if ( $manager && $manager->can($user, "access_section", 'ip.html:edit_ipinfo') ){ %################################################################
Services
% if ( $manager && $manager->can($user, 'edit', $o) ){ [add] % }else{ % }
<%perl> my @headers = ("Service", "Contact List"); my @rows = (); foreach my $ipservice ($o->services){ push( @rows, [ eval { if ($edit eq "ipinfo"){ $ui->form_field(object=>$ipservice, column=>"service", edit=>$edit_ip, returnValOnly=>1); }else{ qq().$ipservice->service->name.""; } } , eval { if ($edit eq "ipinfo"){ $ui->form_field(object=>$ipservice, column=>"contactlist", edit=>$edit_ip, returnValOnly=>1); }elsif ($o->used_by){ qq().$ipservice->contactlist->name.""; } } ] ); } $m->comp('/generic/data_table.mhtml', field_headers=>\@headers, data=>\@rows ) if ( $o->services );
% } %################################################################ % my @attributes = $o->attributes;
Custom Attributes
% if ( @attributes ) { [edit] % } % if ( $manager && $manager->can($user, 'edit', $o) ){ [add] % }else{ % }
<& /generic/sortresults.mhtml, object=>\@attributes, withedit=>$editattr, return_args=>"?id=$id" &>
%################################################################ <%perl> # Get latest arp entries if ( my $arp = $o->get_last_n_arp($arp_limit) ){ my @rows; my %tstamps; foreach my $row ( @$arp ){ my ($iid, $macid, $tstamp) = @$row; my $lbl = Interface->retrieve($iid)->get_label; my $lnk = "$lbl"; push @{$tstamps{$tstamp}{$macid}}, $lnk; } foreach my $tstamp ( reverse sort keys %tstamps ){ foreach my $macid ( keys %{$tstamps{$tstamp}} ){ my $maclbl = PhysAddr->retrieve($macid)->get_label; my $maclnk = "$maclbl"; push @rows, [$tstamp, $maclnk, (join ', ', @{$tstamps{$tstamp}{$macid}})]; } }
Last <% $arp_limit %> ARP entries
Last ARP entries
<& /generic/data_table.mhtml, field_headers=>['Time Seen', 'MAC', 'Interfaces'], data=>\@rows, style=>['', '', 'width: 60%'] &>
% }
%} else { %####################################################################################### %# View Block %#######################################################################################
% if ( $edit eq "blockinfo" || $edit eq 'address_range' || $edit eq 'enable_dhcp' ){ % if ( $added_block ) { % my @parents = $o->get_ancestors; % } else { % } % }else{ [refresh] % if ( $manager && $manager->can($user, "access_section", 'ip.html:edit_blockinfo') ){ % if ( $manager && $manager->can($user, 'access_admin_section', 'ip.html:edit_block') ){ [edit] % } % if ( $o->status->name eq 'Subnet' ){ % if ( $manager && $manager->can($user, 'edit', $o) ){ [range] % } % } % if ( $manager && $manager->can($user, 'access_admin_section', 'ip.html:delete_block') ){ [delete] % } % } % }
%####################################################################### %# Navigation Bar %####################################################################### % if ( $manager && $manager->can($user, "access_section", 'ip.html:sites') ){
% } %####################################################################### %# Body %#######################################################################
% if ( $edit eq 'address_range' ){ % unless ( $manager && $manager->can($user, 'edit', $o) ){ % $m->comp('/generic/error.mhtml', error=>"You don't have permission to edit this object"); % }

Add/Modify Address Range <%perl> my @fields; my @data; push @fields,'IP Range:'; if ( $o->version == 4 ){ push @data, ' - '; }elsif ( $o->version == 6 ){ push @data, ' - '; } push @fields, 'Status:'; push (@data, &{sub{ my $x; $x .= '
'; $x; }}); my @allents = sort { $a->name cmp $b->name } Entity->retrieve_all; push @fields, 'Owner:'; push (@data, &{sub{ my $x; $x .= '
'; $x .= '[new]'; $x; }}); push @fields, 'Used By:'; push (@data, &{sub{ my $x; $x .= '
'; $x .= '[new]'; $x; }}); push @fields, 'Description:'; push @data, ''; push @fields, 'Auto-generate DNS records:'; push @data, ''; push @fields, 'DNS name prefix/suffix:'; push @data, ' '; my $fwzone = $o->forward_zone(); my $revzone = $o->reverse_zone(); my @allzones = Zone->retrieve_all(); push @fields, 'Forward Zone'; push (@data, &{sub{ my $x; $x .= '
'; $x .= '[new]'; $x; }}); <& /generic/attribute_table.mhtml, field_headers=>\@fields, data=>\@data, width=>"2", headercolwidth=>"15%", datacolwidth=>"35%" &> % }elsif ( $edit eq 'enable_dhcp' ){

Create a DHCP Scope for this subnet <%perl> my @fields; my @data; push @fields,'Global Scope:'; push (@data, &{sub{ my $x; $x .= '
'; $x .= '[new]'; $x; }}); push @fields, " "; push @data, " "; push @fields, "Subnet:"; push @data, $o->get_label(); unless ( $o->version == 6 ){ push @fields, 'Option routers:'; push @data, ''; } push @fields, 'Active?:'; push @data, ' (Uncheck if you do not want this scope'. ' included in the DHCP configuration)'; <& /generic/attribute_table.mhtml, field_headers=>\@fields, data=>\@data, width=>"1", headercolwidth=>"15%", datacolwidth=>"35%" &> <%perl> }else{ my @field_headers = ( ); my @cell_data = ( ); ################ # Address: my %addr_tmp = $ui->form_field(object=>$o, column=>"address", edit=>$edit_block, htmlExtra=>"style='width: 15em'"); my %pref_tmp = $ui->form_field(object=>$o, column=>"prefix", edit=>$edit_block, htmlExtra =>"style='width: 3em'"); push( @field_headers, $addr_tmp{'label'} ); push( @cell_data, $addr_tmp{'value'}."/".$pref_tmp{'value'} ); ################ # Status: push( @field_headers, $ui->col_descr_link('Ipblock', 'status', 'Status: ') ); my $status; my @valid_block_status = qw ( Container Subnet Reserved ); if ( my $sn = $o->status->name ){ if ( $edit eq "blockinfo" ){ $status .= "
"; }else{ $status .= "".$sn.""; } } push( @cell_data, $status ); ################ # Description $ui->add_to_fields(o=>$o, edit=>$edit_block, fields=>['description'], field_headers=>\@field_headers, cell_data=>\@cell_data); ################ # Use Network Broadcast if ( $o->status->name eq 'Subnet' ){ $ui->add_to_fields(o=>$o, edit=>$edit_block, fields=>['use_network_broadcast'], field_headers=>\@field_headers, cell_data=>\@cell_data); } ################ # Created, Modified push (@field_headers, "First Created", "Last Modified"); my %createdtmp = $ui->form_field(object=>$o, column=>'first_seen', edit=>0); my %modtmp = $ui->form_field(object=>$o, column=>'last_seen', edit=>0); push( @cell_data, $createdtmp{'value'}, $modtmp{'value'} ); ################ # Vlan if ( $o->status->name eq 'Subnet' ){ my %tmp = $ui->form_field(object=>$o, column=>'vlan', edit=>$edit_block, linkPage=>'view.html'); push( @field_headers, $tmp{'label'} ); push( @cell_data, $tmp{'value'} ); # }else{ # push( @field_headers, ' '); # push( @cell_data, ' '); } ################ # Owner # For some fields, we will provide a way to update the values recursively in all # descendant blocks. my %owner_tmp = $ui->form_field(object=>$o, column=>"owner", edit=>0, linkPage=>"view.html"); my $owner = $owner_tmp{value}; if ( ! $edit_block ){ if ( $manager && $manager->can($user, 'access_admin_section', 'ip.html:edit_owner') ){ $owner .= '[edit]'; } } push( @field_headers, $owner_tmp{label} ); push( @cell_data, $owner ); ################ # Used by my %used_by_tmp = $ui->form_field(object=>$o, column=>"used_by", edit=>0, linkPage=>"view.html"); my $used_by = $used_by_tmp{value}; if ( ! $edit_block ){ if ( $manager && $manager->can($user, 'access_admin_section', 'ip.html:edit_used_by') ){ $used_by .= '[edit]'; } } push( @field_headers, $used_by_tmp{'label'} ); push( @cell_data, $used_by ); ################ # Netmask/broadcast my $ip = new NetAddr::IP($o->address, $o->prefix); push( @field_headers, "Netmask:", "Broadcast:" ); push( @cell_data, $ip->mask); push( @cell_data, ($ip->version == 4 ? $ip->broadcast->addr : "n/a") ); ################ # Usable address range push( @field_headers, "Usable Addresses:" ); my ($num_addresses, $first_address, $last_address); if ( $o->version == 4 ){ if ( $o->prefix == 31 ){ $num_addresses = 2; $first_address = $ip->addr; $last_address = $ip->broadcast->addr; }else{ $num_addresses = $o->num_addr; $first_address = $ip->first->addr; $last_address = $ip->last->addr; } }else{ $num_addresses = $o->num_addr; $first_address = $ip->network->addr; $last_address = $ip->broadcast->addr; } push( @cell_data, ($num_addresses." (". $first_address." - ".$last_address.")") ); if ($o->status->name eq "Subnet") { my $used = new Math::BigInt($o->num_children); my $total = $o->num_addr; my $avail = $total - $used; my $avail_percent = $ui->friendly_percent(value=>$avail,total=>$total); my $used_percent = $ui->friendly_percent(value=>$used,total=>$total); my $percent = ($used*100)/$total; my $available_text; { my $used_text; if ($used <= $max_ips) { $used_text = 'Used: '.$used; if ($total <= $max_ips) { $used_text .= ' of '.$total; } $used_text .= ' '; } my $avail_text = 'Available: '; if ($avail <= $max_ips) { $avail_text .= $avail.' ('; } $avail_text .= $ui->friendly_percent(value=>$avail,total=>$total); if ($avail <= $max_ips) { $avail_text .= ')'; } $available_text = $used_text.$avail_text; } ################ # Utilization push( @field_headers, "Utilization:" ); push( @cell_data, ($ui->percent_bar(percent=>$percent)) .'

'.$available_text.'
' ); } elsif( $o->status->name eq "Container" ) { my $total = new Math::BigInt($o->num_addr); my $used_a = new Math::BigInt($o->address_usage); my $avail_a = $total - $used_a; my $used_s = new Math::BigInt($o->subnet_usage); my $avail_s = $total - $used_s; my $address_percent = $used_a*100/$total; my $subnet_percent = $used_s*100/$total; my $address_text; my $subnet_text; $subnet_text = 'Available: '.($ui->friendly_percent(value=>$avail_s,total=>$total)); if( $used_a <= $max_ips ) { $address_text .= 'Used: '.$used_a; if( $total <= $max_ips ) { $address_text .= ' of '.$total; } $address_text .= ' Available: '; if( $total <= $max_ips ) { $address_text .= $avail_a.' ('; } $address_text .= $ui->friendly_percent(value=>$avail_a,total=>$total); if ($total <= $max_ips) { $address_text .= ')'; } } else { if( $avail_a <= $max_ips ) { $address_text .= 'Available: '.$avail_a.' ('.(100-$address_percent).'%)'; } else { $address_text .= 'Available: '.(100-$address_percent).'%'; } } ################ # Address Utilization push( @field_headers, "Address Utilization:" ); push( @cell_data, $ui->percent_bar(percent=>$address_percent).'
'.$address_text.'
' ); ################ # Space allocated push( @field_headers, "Space Allocated:" ); push( @cell_data, $ui->percent_bar(percent=>$subnet_percent).'
'.$subnet_text.'
' ); } %# actually output the table to the browser <& /generic/attribute_table.mhtml, field_headers=>\@field_headers, data=>\@cell_data, width=>"2", headercolwidth=>"15%", datacolwidth=>"35%" &> % } % if ( $edit ){ % } %################################################################ %# Comments %################################################################ % if ( $view eq 'Comments' || $view eq 'All' ){
Comments
% if ( $edit eq 'comments' ){ % }else{ % if ( $manager && $manager->can($user, "edit", $o) ){ [edit] % }else{ % } % }
<%perl> my $edit_comments = ($edit eq 'comments') ? 1 : 0; my %tmp; %tmp = $ui->form_field(object=>$o, column=>"info", edit=>$edit_comments); print $tmp{value};
% } %################################################################ %# DHCP Scopes %################################################################ % if ( $view eq 'DHCP' || $view eq 'All' ){
DHCP Scope
% if ( my @scopes = $o->dhcp_scopes ){
<& /generic/sortresults.mhtml, object=>\@scopes &>
% }else{
% if ( !($edit eq 'enable_dhcp') && % $manager && $manager->can($user, 'access_admin_section', 'ip.html:enable_dhcp') ){ [enable] % }else{ % }
% }
% } % if ( $view eq 'Sites' || $view eq 'All'){ %################################################################ %# Sites %################################################################ % if ( $manager && $manager->can($user, "access_section", 'ip.html:sites') ){ % my @ss = $o->sites;
Sites
% if ( $edit ne 'edit_sites' ){ % if ( $manager && $manager->can($user, 'edit', $o) ){ % if ( @ss ){ [edit] % } [add] % } % }
<& /generic/sortresults.mhtml, object=>\@ss, return_args=>"?id=$id&view=$view", withedit=>($edit eq 'edit_sites')? 1 : 0 &>
% } % } % if ( $view eq 'Zones' || $view eq 'All' ){ %################################################################ %# Forward Zones %################################################################ % if ( $manager && $manager->can($user, "access_section", 'ip.html:edit_fzones') ){ % my @sz = $o->zones;
Forward DNS Zones
% if ( $edit ne 'edit_fzones' ){ % if ( $manager && $manager->can($user, 'edit', $o) ){ % if ( @sz ){ [edit] % } [add] % } % }
% if ( $_action eq 'VIEW_ADD_FZONES' ){ % my $czone = ($o->forward_zone)? $o->forward_zone->name : "none"; % my @all_zones = sort { $a->name cmp $b->name } Zone->retrieve_all; % my %cur_zones; % map { $cur_zones{$_->zone->id} = 1 } @sz;

Zones are inherited from superior blocks. The current forward zone for this block is:

% print " $czone";

Link this block with existing forward zones:

% }else{ <& /generic/sortresults.mhtml, object=>\@sz, return_args=>"?id=$id&view=$view", withedit=>($edit eq 'edit_fzones')? 1 : 0 &> % }
% } %################################################################ %# Reverse Zones %################################################################ % if ( $manager && $manager->can($user, "access_section", 'ip.html:edit_rzones') ){ % my %all_zones; % map { $all_zones{$_->name} = $_ } Zone->retrieve_all; % my %reverse_zones; % foreach my $n ( $o->get_dot_arpa_names ){ % if ( exists $all_zones{$n} ){ % $reverse_zones{$n} = $all_zones{$n}; % } % }
Reverse DNS Zones
% if ( $edit ne 'edit_fzones' ){ % if ( $manager && $manager->can($user, 'edit', $o) ){ % if ( %reverse_zones ){ [edit] % } [add] % } % }
% if ( $_action eq 'VIEW_ADD_RZONES' ){ % my @all_zones = sort { $a->name cmp $b->name } Zone->retrieve_all; Create reverse zones for this block (existing zones not included):

Use template zone (optional):

% }else{ % my @z = values %reverse_zones; <& /generic/sortresults.mhtml, object=>\@z, return_args=>"?id=$id&view=$view", withedit=>($edit eq 'edit_rzones')? 1 : 0 &> % }
% } % } %################################################################ %# Access Rights %################################################################ % if ( $view eq 'Rights' || $view eq 'All' ){ % if ( $manager && $manager->can($user, "access_section", 'ip.html:edit_rights') ){ <%perl> my @arights = AccessRight->search(object_class=>'Ipblock', object_id=>"$o"); my @urights = map { $_->user_rights } @arights; my @grights = map { $_->group_rights } @arights; my @all_rights = ( @urights, @grights);
Access Rights
% if ( $edit ne 'edit_rights' ){ % if ( $manager && $manager->can($user, 'edit', $o) ){ % if ( @all_rights ){ [edit] % } [add] % } % }
<%perl> if ( $_action eq 'VIEW_ADD_RIGHTS' ){ my $user_type = $user->getAttribute('USER_TYPE'); if ( $user_type eq "Admin" ) { my %ar = (showheader=>1, object_class=>'Ipblock', object_id=>$o->id, return_comp=>$m->current_comp->path, return_id=>$o->id, return_view=>$view); if ( $add_access_type && $add_access_id ){ $ar{$add_access_type} = $add_access_id; } $m->comp('/generic/access_right_form.html', %ar); }else { $m->comp('/generic/error.mhtml', error=>"You don't have permission to manage rights!"); } }elsif ( $edit eq 'edit_rights' ){ $m->comp('/generic/sortresults.mhtml', object=>\@urights, withedit=>1, return_args=>"?id=$id&view=$view"); $m->comp('/generic/sortresults.mhtml', object=>\@grights, withedit=>1, return_args=>"?id=$id&view=$view"); }elsif ( @all_rights ) { $m->comp('/management/list_rights.mhtml', rights=>\@all_rights, show_object=>0, add=>"ip.html?id=$id&view=Rights&_action=VIEW_ADD_RIGHTS&add_access_type=SUBJECT&add_access_id=ID"); }
% } % } %################################################################ % if ( $view eq 'Attributes' || $view eq 'All' ){ % if ( $manager && $manager->can($user, "access_section", 'ip.html:edit_attributes') ){ % my @attributes = $o->attributes;
Custom Attributes
% if ( @attributes ) { [edit] % } % if ( $manager && $manager->can($user, 'edit', $o) ){ [add] % }else{ % }
<& /generic/sortresults.mhtml, object=>\@attributes, withedit=>$editattr, return_args=>"?id=$id" &>
% } %} %################################################################ %# Graphical Views %################################################################ % if ( ($view eq 'Children' || $view eq 'All') && ($edit eq 'address_range' || !$edit) ){ % if( $view_format eq 'block' ) { % if( $o->status->name eq "Subnet" ) {
Subnet Block View
[List View]
<& subnet.mhtml, network => $o &>
% } % if( $o->status->name eq "Container") {
Usage for <% $o->get_label %>
Legend: Available Container Static Reserved [List View] [Tree View]
<& container.mhtml, network => $o, rowsize => $rowsize, dividefreespace => $dividefreespace &>
% } % }elsif( $view_format eq 'tree' ) { % if( $o->status->name eq "Subnet" || $o->status->name eq "Container" ) {
Tree View
Legend: Container Static Reserved % if ( $o->version == 4 ){ % if ( $BLOCK_VIEW_MAX && ($o->prefix >= $BLOCK_VIEW_MAX) ){ [Block View] % } % } [List View]
<& tree.mhtml, network => $o &>
% } <%perl> } elsif ( $view_format eq 'list' ) { my @children; if ( $o->status->name eq 'Subnet' && $ip_list_sort ne "Device" ){ @children = $o->get_addresses_by($ip_list_sort); }else{ @children = $o->children; }
% if ( $edit_children ){ % }
% if ( $o->status->name eq 'Subnet' ){ Addresses % }else{ Contained IP blocks % }
% if ( $edit_children ){ % }else{ % if ( @children && $manager && $manager->can($user, 'access_section', 'ip.html:edit_children') ){ % if ( $manager && $manager->can($user, 'edit', $o) ){ % print '[edit] '; % } % } % if ( $o->version == 4 ) { % if ( $BLOCK_VIEW_MAX && ($o->prefix >= $BLOCK_VIEW_MAX) ){ % print '[Block View]'; % } % }elsif ( $o->version == 6 ){ % } % if ( $o->status->name eq 'Container' ){ [Tree View] % } % }
% if ( @children ){ <& ipblock_list.mhtml, parent=>$o, objects=>\@children, edit=>$edit_children, sort=>$ip_list_sort &> % } % if ( $edit_children ){ % }
% if ( $edit_children ){ % }
% }else{ % $m->comp('/generic/error.mhtml', error => "Unknown view format: $view_format"); % } % } % } % }
<%def .show_message> <%args> $title => undef $msg => undef
<% $title %>

<% $msg %>