<%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_parent => 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 => 22 $dividefreespace => 'max' $arp_limit => 10 $ip_list_sort => 'Address' $show_ch_util => 0 $state_digest => 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 $max_ips = Netdot->config->get('SHOW_COUNT_THRESHOLD'); my $added_ip = 0; my $added_block = 0; my $covering_block; my $BLOCK_VIEW_MAX; # Some regular expressions my $IPV4 = Netdot->get_ipv4_regex(); my $IPV6 = Netdot->get_ipv6_regex(); 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 = 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"); } @list = Ipblock->get_roots($rootversion);
Root Blocks: (<% scalar(@list) %>)
% my $show_checked = ($show_ch_util)? 'CHECKED' : ""; Show Utilization: > Version:
% if ( @list ){ <& ipblock_list.mhtml, parent=>0, objects=>\@list, type=>"block", show_utilization=>$show_ch_util &> % }
<%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 = 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 'Available' ){ eval { Ipblock->remove_range(start => $add_range_start, end => $add_range_end); }; }else{ eval { $o = Ipblock->add_range(start => $add_range_start, end => $add_range_end, status => $range_status, owner => $range_owner, used_by => $range_used_by, description => $range_description, parent => $range_parent, 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" ){ unless ( $add_block_prefix ){ $m->comp('/generic/error.mhtml', error=>"You need to specify IP/prefix"); } $add_block_prefix =~ s/\s+//g; # Remove spaces unless ( $add_block_prefix =~ /\// ){ $m->comp('/generic/error.mhtml', error=> "$add_block_prefix not a valid CIDR string."); } if ( $submit && (($submit eq 'confirm') || ($submit eq 'Save')) ){ undef($submit); my ($address, $prefix) = split /\//, $add_block_prefix; if ( (($address =~ $IPV4 && $prefix ne '32') || ($address =~ $IPV6 && $prefix ne '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 you selected does not yet exist. '. 'Are you sure that you want to create it?', ); } ####################################################################################### # ENABLE DHCP # ####################################################################################### }elsif ( $_action eq 'ENABLE_DHCP'){ unless ( $manager && $manager->can($user, "edit", $o) ){ $m->comp('/generic/error.mhtml', error=>"You don't have permission to edit this object"); } if ( $ARGS{dhcp_global_scope} ){ my %args = (container=>$ARGS{dhcp_global_scope}); # Grab all the dhcp options & declarations foreach my $arg ( %ARGS ){ if ( $arg =~ /^dhcp_/ ){ next if $arg eq 'dhcp_global_scope'; my $value = $ARGS{$arg}; if ( $arg =~ /^dhcp_(.*)_(\d+)$/ ){ my $attr = $1; my $sid = $2; $attr =~ s/^option_/option /; $attr =~ s/_/-/g; if ( $sid eq $id ){ $args{attributes}{$attr} = $value; }else{ $args{shared_nets}{$id}{$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"); } }else{ $m->comp('/generic/error.mhtml', error=>"You need to specify at least the global scope"); } ####################################################################################### # 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 = 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"); } } } ####################################################################################### # View # ####################################################################################### if ( $id && $view ){ if ( $edit ){ % my $digest = $o->get_digest(); % if ( $edit_ip || $edit_block ){ % } % } <%perl> my @line; if ( my @parents = $o->get_ancestors ){ foreach my $par ( reverse @parents ){ push (@line, "id . "\">" . $par->get_label . ""); } if( $view_format eq 'block' && !$o->is_address ) { push (@line, "id . "\">" . $o->get_label . ""); } else { 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','info', 'first_seen','last_seen'); $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%" &>
<%perl> if (!$edit){ my @rraddrs = $o->arecords(); my @rrs = map { $_->rr } @rraddrs; print '
'; print '
DNS A Records
'; print '
'; print "[add]"; print '
'; print '
'; $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 '
'; print "[add]"; 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 '
'; $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] % }
<%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 );
% } %################################################################ %# Custom Attributes %################################################################ % my @attributes = $o->attributes;
Custom Attributes
% if ( @attributes ) { [edit] % } [add]
<& /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"){ % if ($added_block) { % my @parents = $o->get_ancestors; % } else { % } % }elsif ( $edit ){ % }else{ [refresh] % if ( $manager && $manager->can($user, "access_section", 'ip.html:edit_blockinfo') ){ % if ( $manager && $manager->can($user, 'edit', $o) ){ [edit] % } % if ( $o->status->name eq 'Subnet' ){ % if ( $manager && $manager->can($user, 'edit', $o) ){ [range] % } % } % if ( $manager && $manager->can($user, 'delete', $o) ){ [delete] % } % } % }
% 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; }}); my @shared_subs = $o->shared_network_subnets(); my @subs = ($o); if ( @shared_subs ){ print "

(*) It looks like this is a shared network

"; push @subs, @shared_subs; } foreach my $s ( @subs ){ push @fields, " "; push @data, " "; push @fields, "Subnet:"; push @data, $s->get_label(); push @fields, 'Option routers:'; push @data, ''; } <& /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: 2em'"); 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 ); ################ # 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, ' '); } ################ # Description, Info (no link) { my @fields = ('description','info'); $ui->add_to_fields(o=>$o, edit=>$edit_block, fields=>\@fields, field_headers=>\@field_headers, cell_data=>\@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=>$edit_block, linkPage=>"view.html"); my $owner = $owner_tmp{value}; if ( ! $edit_block ){ if ( $manager && $manager->can($user, 'edit', $o) ){ $owner .= '[edit]'; } } push( @field_headers, $owner_tmp{label} ); push( @cell_data, $owner ); ################ # Used by my %usedby_tmp = $ui->form_field(object=>$o, column=>"used_by", edit=>$edit_block, linkPage=>"view.html"); push( @field_headers, $usedby_tmp{'label'} ); push( @cell_data, $usedby_tmp{'value'} ); <%perl> 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 = $ip->num; $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 ){ % } %################################################################ %# DHCP Scopes %################################################################ % if ( int($o->status) && $o->status->name eq 'Subnet' ){
DHCP Scope
% if ( my @scopes = $o->dhcp_scopes ){
<& /generic/sortresults.mhtml, object=>\@scopes &>
% }else{
[enable]
% } % }
%################################################################ %# Sites %################################################################ % my @ss = $o->sites;
Sites
% if ( $edit ne 'edit_sites' ){ % if ( $manager && $manager->can($user, 'edit', $o) ){ [edit] [add] % } % }
<& /generic/sortresults.mhtml, object=>\@ss, withedit=>($edit eq 'edit_sites')? 1 : 0 &>
%################################################################ %# Zones %################################################################ % if ( $manager && $manager->can($user, "access_section", 'ip.html:edit_zones') ){ % my @sz = $o->zones;
DNS Zones
% if ( $edit ne 'edit_zones' ){ % if ( $manager && $manager->can($user, 'edit', $o) ){ [edit] [add] % } % }
<& /generic/sortresults.mhtml, object=>\@sz, withedit=>($edit eq 'edit_zones')? 1 : 0 &>
% } %################################################################ %# Graphical Views %################################################################ % if( $view_format eq 'block' ) { % if( $o->status->name eq "Subnet" ) {
Choose an Address
Legend: Available Discovered Dynamic Static Reserved [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' ){ @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]'; % } % } % 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 %>