/usr/share/netdisco/html/traceroute.html is in netdisco-frontend 1.0-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 | <FORM ACTION="<%$r->uri%>" METHOD="get">
<h1 class="pagehead">L2 Trace Route</h1>
<%$err%>
<& SELF:results &>
From: <INPUT TYPE="text" NAME="from" VALUE="<%$from%>">
To: <INPUT TYPE="text" NAME="to" VALUE="<%$to%>">
<BR>
<INPUT TYPE="submit" CLASS="navbutton" Value="Trace Route">
<A HREF="<%$r->uri%>">[Clear]</A>
<h2 class="subheader">Hints</h2>
<UL>
<LI>L2 Traceroute only finds a <i>Possible</i> route through the
network, using Dykstra's shortest path algorithm. The
<i>Actual</i> path of packets may well be very different .
<LI>Enter the MAC Address, IP Address or Hostname of a node or device for the
<TT>to</TT> and <tt>from</tt> fields.
<LI>For segments of the network missing topology info, no path
may be found. See <i>Devices Orphaned by Missing Topology Info</i> in
[<a href="device_search.html">Device Search</A>].
</UL>
</FORM>
<%args>
$from => undef
$to => undef
</%args>
<%method title>
- Trace Route (L2)\
</%method>
<%shared>
my ($sentto,$sentfrom,$G,$H,$err);
my $path = [];
my (%from,%to);
my $have_path=0;
my $domain = $netdisco::CONFIG{domain};
my $timeout = $netdisco::CONFIG{graph_timeout} || 60;
</%shared>
<%init>
$sentto = $to;
$sentfrom = $from;
# Check FROM for node-mac,device,node-host
if ($from and &is_mac($from)){
my $dev = sql_hash('node',['mac','switch','port'],{'mac'=>$from,'active'=>1});
if (defined $dev){
$from{mac} = $from;
$from{ip} = sql_scalar('node_ip',['ip'],{'mac'=>$from,'active'=>1});
$from{type} = 'node';
$from{next} = $dev->{switch};
$from{to_port} = $dev->{port};
}
} elsif ($from) {
$from{ip} = getip($from);
# Check if device
if (my $devip = &root_device($from{ip})){
$from{ip}=$devip;
$from{type} = 'device';
} else {
# Check if node
my $devmac = sql_scalar('node_ip',['mac'],{'ip'=>$from{ip}, 'active' => 1});
my $dev = sql_hash('node',['mac','switch','port'],{'mac'=>$devmac,'active'=>1});
if (defined $dev){
$from{mac} = $devmac;
$from{type} = 'node';
$from{next} = $dev->{switch};
$from{to_port} = $dev->{port};
}
}
}
# Check TO for node-mac,device,node-host
if ($to and &is_mac($to)){
my $dev = sql_hash('node',['mac','switch','port'],{'mac'=>$to,'active'=>1});
if (defined $dev){
$to{mac} = $to;
$to{ip} = sql_scalar('node_ip',['ip'],{'mac'=>$from,'active'=>1});
$to{type} = 'node';
$to{next} = $dev->{switch};
$to{from_port} = $dev->{port};
}
} elsif ($to) {
$to{ip} = getip($to);
# Check if device
if (my $devip = &root_device($to{ip})){
$to{ip}=$devip;
$to{type} = 'device';
} else {
# Check if node
my $devmac = sql_scalar('node_ip',['mac'],{ 'ip'=>$to{ip},'active'=>1 } );
my $dev = sql_hash('node',['mac','switch','port'],{'mac'=>$devmac,'active'=>1});
if (defined $dev){
$to{mac} = $devmac;
$to{type} = 'node';
$to{next} = $dev->{switch};
$to{from_port} = $dev->{port};
}
}
}
if (defined $from{type} and defined $to{type}) {
# this could take a while
$m->flush_buffer;
$G = make_graph();
my $fromip = $from{type} eq 'node' ? $from{next} : $from{ip};
my $toip = $to{type} eq 'node' ? $to{next} : $to{ip};
# Check to see if we have a path
my @S = $G->connected_components;
for (my $i; $i < @S; $i++){
next unless grep(/^\Q$fromip\E$/,@{$S[$i]});
next unless grep(/^\Q$toip\E$/,@{$S[$i]});
$have_path++;
# Found path, delete all the other subgraphs to speed up the search
for (my $j; $j < @S; $j++){
next if $i == $j;
$G->delete_vertices(@{$S[$j]})
}
# We should only be in one connected graph, so first found is the only
# sub graph. multiple paths in that one subgraph will exist.
last;
}
if ($have_path){
local $SIG{ALRM} = sub { die "timeout"; };
eval {
alarm($timeout);
$H = $G->SSSP_Dijkstra($fromip);
$path = [ $H->path_vertices($fromip,$toip) ];
alarm(0);
};
if ($@ =~ /timeout/) {
$err = "Shortest Path Algorithm timed out in $timeout sec.<BR>";
$have_path=0;
} elsif ($@) {
$err = "Error w/ SSSP. $@";
$have_path=0;
}
}
}
</%init>
<%method results>
%return unless (length($sentfrom) and length($sentto));
<h2 class="subheader"> Route </h2>
<%perl>
unless (defined $from{type}){
$m->out("No matching device or node found for $sentfrom.<BR>\n");
}
unless (defined $to{type}){
$m->out("No matching device or node found for $sentto.<BR>\n");
}
return unless (defined $from{type} and defined $to{type});
unless ($have_path){
$m->out("No Path found between $sentfrom and $sentto. <BR>\n");
return;
}
my %path_info;
for (my $i=0; $i < @$path; $i++){
my $this = $path->[$i];
my $dns = sql_scalar('device',['dns'],{'ip'=>$this});
$dns = defined $dns ? $dns : $this;
$dns =~ s/\Q$domain\E//;
$path_info{$this}->{dns} = $dns;
last if ($i == scalar(@$path)-1);
my $that = $path->[$i+1];
# remote_ip of port may be set to an alias, so we check for connections to alias ips.
my $aliases = sql_rows('device_ip',['alias'],{'ip'=>$that});
# Add our root device to the list of ips to check first
unshift (@$aliases, {'alias'=>$that});
my $port;
foreach my $alias (@$aliases){
my $alias_ip = $alias->{alias};
$port = sql_hash('device_port',['port','remote_port'],{'ip'=>$this,'remote_ip'=>$alias_ip});
# take the first one we find.
last if defined $port;
}
$path_info{$this}->{type}='device';
$path_info{$this}->{next}=$that;
$path_info{$this}->{to_port} = $port->{port};
$path_info{$that}->{from_port} = $port->{remote_port};
}
# Add node to beg
if ($from{type} eq 'node'){
my $this = defined $from{ip} ? $from{ip} : $from{mac};
my $dns = defined $from{ip} ? &hostname($from{ip}) : $this;
$dns = defined $dns ? $dns : $this;
$dns =~ s/\Q$domain\E//;
my $that = $from{next};
$path_info{$this}->{next} = $that;
$path_info{$this}->{dns} = $dns ;
$path_info{$that}->{from_port} = $from{to_port};
$path_info{$this}->{type} = 'node';
unshift(@$path,$this);
}
# Add node to end
if ($to{type} eq 'node'){
my $this = defined $to{ip} ? $to{ip} : $to{mac};
my $dns = defined $to{ip} ? &hostname($to{ip}) : $this;
$dns = $dns ? $dns : $this;
$dns =~ s/\Q$domain\E//;
$path_info{$this}->{type} = 'node';
$path_info{$this}->{dns} = $dns ;
my $that = $to{next};
$path_info{$that}->{next} = $this;
$path_info{$that}->{to_port} = $to{from_port};
push(@$path,$this);
}
my $odd = 0;
</%perl>
<P>
<%$sentfrom%> --> <%$sentto%>
<P>
<TABLE CELLSPACING=2 CELLPADDING=2 BORDER=0 CLASS="box">
<TR>
<TH> </TH>
<TH class="tr-head">Port<BR>In</TH>
<TH class="tr-head"> Device </TH>
<TH class="tr-head">Port<BR>Out</TH>
</TR>
<TR><TD COLSPAN=4><hr class="noshade"></TD></TR>
<%perl>
while (my $this = shift(@$path)){
my $that = $path_info{$this}->{next};
my $from_port = $path_info{$this}->{from_port};
my $to_port = $path_info{$this}->{to_port};
my $link = $path_info{$this}->{type} eq 'node' ?
"node.html?node=$this" :
"device.html?ip=$this";
$link .= "\&port=$from_port" if defined $from_port;
$link .= "\&port=$to_port" if defined $to_port;
$odd++;
</%perl>
<TR class="tr-data-<%$odd % 2 %>">
<TD class="tr-data-<%$odd % 2 %>"><%$odd%>.</TD>
<TD class="tr-data-<%$odd % 2 %>"><% defined $from_port ? "[$from_port]" : ' ' %></TD>
<TD class="tr-data-<%$odd % 2 %>"><A HREF="<%$link%>"><%$path_info{$this}->{dns}%></A></TD>
<TD class="tr-data-<%$odd % 2 %>"><% defined $to_port ? "[$to_port]" : ' ' %></TD>
</TR>
%}
</TABLE>
<P>
</%method>
%# $Id: traceroute.html,v 1.9 2009/03/25 22:25:19 fenner Exp $
%# vim:syntax=mason
|