<%doc> Device Interface UI % % <%attr> title => 'Interface' section => 'Management' % % <%args> $id $user => $ui->get_current_user($r) $view => undef $edit => undef % % <%init> my $DEBUG = 0; print '%ARGS is
', Dumper(%ARGS), '

' if $DEBUG; my $table = 'Interface'; # Check if user can access this page # We don't want average users seeing this page, its only for admins and operators. my $manager = $ui->get_permission_manager($r); unless ( $manager && $manager->can($user, "access_section", 'interface.html') ){ $m->comp('/generic/error.mhtml', error=>"You don't have permission to access this page"); } my $o = Interface->retrieve($id); my $dbh = Netdot::Model->db_Main(); my $fdb_tstamps; my %linksfrom = Interface->meta_data->get_links_from;
Interface
% if ( $manager && $manager->can($user, "access_admin_section", 'interface.html:new') ){ [new] % } % if ( $manager && $manager->can($user, 'delete', $o) ){ [delete] % } % if ( $manager && $manager->can($user, 'edit', $o) ){ [edit] % } [text]
<& /generic/form.mhtml, table=>"Interface", id=>$id, edit=>0 &>
View
% if ( $view eq "all" ){ [all] % }elsif ( keys %linksfrom > 1 ){ [all] % } % foreach my $i ( sort keys %linksfrom ){ % next if $i eq 'neighbors'; % if ( $view eq $i ){ [<% $i %>] % }else{ [<% $i %>] % } % } [audit]
%foreach my $i ( keys %linksfrom ){ % if ( ($view eq 'all' || $view eq $i ) ){ % # Special cases % next if $i eq 'neighbors'; % if( $i eq 'vlans' && (my @ivlans = $o->vlans) ){ % my @vlans = map { $_->vlan } @ivlans;
VLANs
<& /generic/sortresults.mhtml, object => \@vlans &>
% }elsif( $i eq 'fwt_entries' ){ <%perl> my $sth1 = $dbh->prepare("SELECT ft.tstamp FROM interface i, fwtable ft, fwtableentry fte WHERE fte.interface=i.id AND fte.fwtable=ft.id AND i.id=? GROUP BY ft.tstamp ORDER BY ft.tstamp DESC"); % $sth1->execute($id); % $fdb_tstamps = $sth1->fetchall_arrayref(); % my $fdb_count = scalar(@$fdb_tstamps); % my @headers = ("Timestamp"); % my @rows; % if ( $fdb_count ){
FWT entries
% foreach my $row (@$fdb_tstamps){ % my ($tstamp) = @$row; % push @rows, ["$tstamp"]; % } % $m->comp('/generic/data_table.mhtml', field_headers=>\@headers, data=>\@rows); % } % }elsif( $i eq 'arp_entries' ){ <%perl> my $sth2 = $dbh->prepare("SELECT arp.tstamp FROM interface i, arpcache arp, arpcacheentry arpe WHERE arpe.interface=i.id AND arpe.arpcache=arp.id AND i.id=? GROUP BY arp.tstamp ORDER BY arp.tstamp DESC"); % $sth2->execute($id); % my $arp_tstamps = $sth2->fetchall_arrayref(); % my $arp_count = scalar(@$arp_tstamps); % my @headers = ("Timestamp"); % my @rows = (); % if ( $arp_count ){
ARP entries
% foreach my $row (@$arp_tstamps){ % my ($tstamp) = @$row; % push @rows, ["$tstamp"]; % } % $m->comp('/generic/data_table.mhtml', field_headers=>\@headers, data=>\@rows); % } % }else{ % # 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 = $o->$i; % my $dtbl = $j; % my $ctbl = $j; % % my %args = ( table=>$dtbl, object=>\@robjs ); % my $num = scalar(@robjs); % my $title = $i; % $title .= " ($num)" if $num;
<% $title %>
% if ( $edit eq $i ){   % }else{ % if ( $num ){ [edit] % } [add] % }
% 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} = "?table=$table&id=$id&view=$view"; % $m->comp('/generic/sortresults.mhtml', %args); % }
% } #else % } # if view %}# foreach %if ( $view eq 'all' || $view eq 'audit' ){
% my @audit = $o->get_audit_records(table=>'Interface', id=>$o->id); <& /generic/sortresults.mhtml, object => \@audit , view => "row", sort => 0 &>
%}