<%doc> Specific page for DhcpScope objects <%args> $id => undef $user => $ui->get_current_user($r) $view => undef $edit => undef $submit => undef $bulk_import_data => undef $import_overwrite => undef @scope_type_box => () #used for narrowing down types of scopes you're intrested in in contained_scopes $scope_text_filter => undef #used to filter scope types based on a keyword. <%attr> title => 'View Object' <%init> my $table = 'DhcpScope'; my $DEBUG = 0; my($o, $prevobj ); my %ftables; if(! $id){ return; } my %explanation_hash = ( 'templates' => 'When using a template, the scope will inherit all attributes of the template', 'contained_scopes' => 'Scopes that inherit attributes from this scope.' ); unless ( $o = $table->retrieve($id) ){ $m->comp('error.mhtml', error => "Nonexistent record: $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"); } my $labelstr = $o->get_label; my $type = $o->type->name; my %linksfrom = $table->meta_data->get_links_from; # Override tags from metadata in certain cases my %tags; if ( $type eq 'subnet' ){ $tags{ipblock} = 'Subnet'; }elsif($type eq 'host'){ $tags{ipblock} = 'IP Address'; } if ( $DEBUG ){ print '%ARGS is
', Dumper(%ARGS), '

'; print '%linksfrom is
', Dumper(%linksfrom), '

'; print '$type is '."$type
"; } if ( $submit ){ if ($edit eq 'bulk_import'){ unless ( $manager && $manager->can($user, 'access_admin_section', 'scope:bulk_import') ){ $m->comp('/generic/error.mhtml', error=>"You don't have permission to perform this operation"); } unless ( $bulk_import_data ){ $m->comp('/generic/error.mhtml', error=>"Empty import data"); } # Do this atomically eval { Netdot::Model->do_transaction( sub{ $o->import_hosts(text=>$bulk_import_data, overwrite=>$import_overwrite); }); }; if ( my $e = $@ ){ $m->comp('/generic/error.mhtml', error=>$e); }else{ $submit = 0; # So we display stuff below } } }
<% $table %>
% if ( $manager && $manager->can($user, 'access_admin_section', 'scope:new') ){ [new] % } % if ( $manager && $manager->can($user, 'edit', $o) ){ [edit] % } % if ( $manager && $manager->can($user, 'delete', $o) ){ [delete] % } [text]
<& "/generic/form.mhtml", table=>$table, id=>$id, edit=>0, view=>$type, tags=>\%tags &>
% if ( keys %linksfrom ){
View
% if ( $view eq "all" ){ [all] % }elsif ( keys %linksfrom > 1 ){ [all] % } % foreach my $i ( sort keys %linksfrom ){ % next if ($i eq 'derived_scopes' && $type ne 'template'); % next if ($i eq 'contained_scopes' && ($type eq 'host' || $type eq 'subnet' || $type eq 'template')); % next if ($i eq 'audit_records' && $type ne 'global'); % next if ($i eq 'templates' && $type eq 'template'); % if ( $view eq $i ){ [<% $i %>] % }else{ [<% $i %>] % } % } % if ( $type eq 'global' || $type eq 'group' ){ % if ( $manager && $manager->can($user, 'access_admin_section', 'scope:bulk_import') ){ [bulk import] % } % }
% } <%perl> my @all_types = DhcpScopeType->retrieve_all(); foreach my $i ( keys %linksfrom ){ next if ($i eq "derived_scopes" && $type ne "template"); next if ($i eq 'contained_scopes' && ($type eq 'host' || $type eq 'subnet' || $type eq 'template')); next if ($i eq 'audit_records' && $type ne 'global'); next if ($i eq 'templates' && $type eq 'template'); if ( ($view eq 'all' || $view eq $i ) ){ # Table that points to us my $j = (keys %{ $linksfrom{$i} })[0]; # Column in the other table that points to this table my $ffield = $linksfrom{$i}{$j}; # Determine if the has_many method returns ordered data from the db my $ffattrs = $j->meta_data->get_column($ffield)->links_to_attrs(); my $ffield_order = $ffattrs->{order_by} if ( defined $ffattrs && exists $ffattrs->{order_by} ); my @robjs; if($i ne 'contained_scopes' || $scope_text_filter || @scope_type_box){ @robjs = $o->$i; } else{ @robjs = (); #no need to preform this expensvie query if the user hasn't selected filters } my $dtbl = $j; my $ctbl = $j; my %args; #since the amount of returned values in contained_scopes is sometimes big, #lets filter down our result list here. Performance is better and the results #are more readable, but might need to figure out how to move this filtering to db if($i eq 'contained_scopes' && ($scope_text_filter || @scope_type_box)){ my @tmp_row_objects; foreach $r (@robjs){ if (!@scope_type_box || grep{$_ eq $r->type->name} @scope_type_box){ if(!$scope_text_filter || $r->name =~ /$scope_text_filter/){ push(@tmp_row_objects, $r); } } } @robjs = sort {$a->name cmp $b->name} @tmp_row_objects; } my $num = scalar(@robjs);
% my $title = $i; % $title .= " ($num)" if $num; % $title .= "   ".$explanation_hash{$i};
<% $title %>
  % if ( $edit ne $i ){ % if($i eq "templates"){ #we have a special edit page for templates. % if ( $num ){ % my @temps = DhcpScopeUse->search(scope=>$o); % my $space_seperated_list = ""; % for my $s (@temps){ % $space_seperated_list.=$s." " % } % if ( $manager && $manager->can($user, 'edit', $o) ){ [edit] % } % } % if ( $manager && $manager->can($user, 'edit', $o) ){ [add] % } % }else{ #for everything BUT templates: % if ( $manager && $manager->can($user, 'edit', $o) ){ % if ( $num ){ [edit] % } [add] % } % } % }
% if($i eq 'contained_scopes'){ % # present a form to the user allowing them to only display certian types of scopes

Select Scope type(s) keyword:
% } % %args = ( table=>$dtbl, object=>\@robjs ); % if ( $edit eq $i ){ % $args{withedit} = 1; % } % else{ % # If data came ordered from the db, tell sortresults not to bother sorting % $args{sort} = 0 if ( $ffield_order ); % } % if ($num){ % $args{return_args} = "?id=$id&view=$view"; % $m->comp('/generic/sortresults.mhtml', %args); % } %
% } %} % if ( $view eq 'bulk_import' ){
Bulk Import
% if ( $o->type->name ne 'global' && $o->type->name ne 'group' ){

At this time, only host scopes can be imported, which can only be contained in global or group scopes % }else{

Create fixed-address host scopes in bulk by adding lines containing ethernet and IP address, separated by spaces.
For example:

00:23:45:67:89:AB 192.168.0.1
00:23:45:67:89:CD 192.168.0.2

Overwrite existing records

% }
% }