<%doc> Interface for MAC addresses % % <%attr> title => 'MAC' section => 'Management' % % <%args> $id => undef $search => undef $search_live => undef $vlan => undef $delete => undef $fwt_limit => Netdot->config->get('SHOW_LAST_N_FTE') || 10 $arp_limit => Netdot->config->get('SHOW_LAST_N_ARP') || 10 $edit_attr => undef $user => $ui->get_current_user($r) $dowindow => undef % % <%init> my $DEBUG = 0; my $o; my @list; my (@interfaces, @devices); my $edge_port; my ($fwt, $arp); print "
", Dumper(%ARGS), "

" if $DEBUG; <%doc> ####################################################################################### # Search # ####################################################################################### % if ( defined($search) ){ % # Remove trailing and leading spaces % $search = $ui->rem_lt_sp($search); % @list = PhysAddr->search_like(address=>$search);
Query <% $search %> returned: <% scalar(@list) %> matches
% if ( scalar(@list) > 1 ){ <& /generic/sortresults.mhtml, object => \@list, dowindow => $dowindow &> % }elsif ( @list ){ % $o = $list[0]; % }else{

Would you like to perform a "live" search in the network? (It might take a while).

% }
<%perl> }elsif ( $search_live ){ if ( !$vlan ){ $m->comp('../generic/error.mhtml', error=>"Please select a VLAN ID"); } my $info; my $address = PhysAddr->format_address($search_live); eval { $info = Device->search_address_live(mac=>$address, vlan=>$vlan) }; if ( my $e = $@ ){ $m->comp('/generic/error.mhtml', error=>$e); } if ( $info ){ $m->comp('live_results.mhtml', info=>$info); }else{ print "Not found"; } } if ( $id && !$o ){ unless ( $o = PhysAddr->retrieve($id) ){ $m->comp('/generic/error.mhtml', error => "Could not retrieve PhysAddr id: $id"); } } if ( $o ){ 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"); } $id ||= $o->id; # Get latest forwarding table entries $fwt = $o->get_last_n_fte($fwt_limit); # Get latest arp entries $arp = $o->get_last_n_arp($arp_limit); # Devices whose base_mac address is this one @devices = $o->devices; # Interfaces with this address @interfaces = $o->interfaces; # Edge port $edge_port = $o->find_edge_port; my (@headers, @data) = (); my @fields = ('address'); $ui->add_to_fields(o=>$o, edit=>0, fields=>\@fields, field_headers=>\@headers, cell_data=>\@data); # Add Vendor push(@headers, 'Vendor'); my $vendor = $o->vendor; my $oui = $o->oui; my $srch = "$oui*"; my $slink = "$vendor ($oui)"; push(@data, $slink); @fields = ('static', 'first_seen', 'last_seen'); $ui->add_to_fields(o=>$o, edit=>0, fields=>\@fields, field_headers=>\@headers, cell_data=>\@data);
MAC Address
<& /generic/attribute_table.mhtml, field_headers=>\@headers, data=>\@data, width=>"1", headercolwidth=>"25%", datacolwidth=>"75%" &>
%if ( @devices ){
Devices using this address
<& /generic/sortresults.mhtml, object=>\@devices &>
%} %if ( @interfaces ){
Interfaces using this address
<& /generic/sortresults.mhtml, object=>\@interfaces &>
%} <%perl> if ( $edge_port ){ my $iface = Interface->retrieve($edge_port); my ($jack, $room); if ( $iface->jack ){ $jack = $iface->jack->jackid; $room = $iface->jack->room->name if $iface->jack->room; }else{ $jack = $iface->jack_char; $room = $iface->room_char; } $jack ||= 'n/a'; $room ||= 'n/a'; my $lbl = $iface->get_label; my $lnk = "$lbl";
Edge Port
<& /generic/data_table.mhtml, field_headers=>['Interface', 'Room', 'Jack', 'Description'], data=>[[$lnk, $room, $jack, $iface->description]] &>
% } <%perl> if ( $fwt && scalar @$fwt ){ my @rows; my %tstamps; foreach my $row ( @$fwt ){ my ($tstamp, $iid) = @$row; my $iface = Interface->retrieve($iid); my $lbl = $iface->get_label; my $lnk = "$lbl"; push @{$tstamps{$tstamp}}, $lnk; } foreach my $tstamp ( reverse sort keys %tstamps ){ push @rows, [$tstamp, join ', ', @{$tstamps{$tstamp}}]; }
Last <% $fwt_limit %> forwarding table entries
Last FWT entries
<& /generic/data_table.mhtml, field_headers=>['Time Seen', 'Interfaces'], data=>\@rows, style=>['', 'width: 80%'] &>
% } <%perl> if ( $arp && scalar @$arp ){ my @rows; my %tstamps; foreach my $row ( @$arp ){ my ($iid, $ipid, $tstamp) = @$row; my $lbl = Interface->retrieve($iid)->get_label; my $lnk = "$lbl"; push @{$tstamps{$tstamp}{$ipid}}, $lnk; } foreach my $tstamp ( reverse sort keys %tstamps ){ foreach my $ipid ( keys %{$tstamps{$tstamp}} ){ my $iplbl = Ipblock->retrieve($ipid)->get_label; my $iplnk = "$iplbl"; push @rows, [$tstamp, $iplnk, (join ', ', @{$tstamps{$tstamp}{$ipid}})]; } }
Last <% $arp_limit %> ARP entries
Last ARP entries
<& /generic/data_table.mhtml, field_headers=>['Time Seen', 'IP', 'Interfaces'], data=>\@rows, style=>['', '', 'width: 60%'] &>
% } % if ( my @scopes = $o->dhcp_hosts ){
DHCP Scopes
<& /generic/sortresults.mhtml, object=>\@scopes &>
% } % my @attributes = $o->attributes;
Custom Attributes
% if ( @attributes ) { [edit] % } [add]
<& /generic/sortresults.mhtml, object=>\@attributes, withedit=>$edit_attr, return_args=>"?id=$id" &>
% }