/usr/share/netdisco/html/ip_search.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 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 | <% $err %>
% $m->comp('SELF:show_age') if $cmd eq 'age';
<h1 class="pagehead">Report IP Inventory</h1>
<h2 class="subheader">Finds IP Addresses used by nodes</h2>
<FORM ACTION="<%$r->uri%>" METHOD="GET">
<DIV>
<INPUT TYPE="hidden" NAME="cmd" VALUE="age">
<TABLE CLASS="ips-search">
<TR>
<TH>Show:</TH>
<TD><INPUT TYPE="radio" name="type" value="all" <%$type eq 'all' ? ' CHECKED' : ''%>>All Entries
<INPUT TYPE="radio" name="type" value="age" <%$type eq 'age' ? ' CHECKED' : ''%>>Search by Age
</TD>
</TR>
<TR>
<TH>Age:</TH>
<TD>IPs not used in
<SELECT NAME="age_val">
% for (1..12) {
<OPTION VALUE="<%$_%>"<%$age_val eq $_ ? ' SELECTED' : ''%>><%$_%>
% }
</SELECT>
<SELECT NAME="age_mul">
% for (qw/days months years/) {
<OPTION VALUE="<%$_%>"<%$age_mul eq $_ ? ' SELECTED' : ''%>><%$_%>
% }
</SELECT>
<BR><SPAN CLASS="smaller">To find IP addresses that have never been used in a subnet, select "12 Years" and Check "IPs never discovered"</span>
</TD>
</TR>
<TR>
<TH>Sort By:</TH>
<TD><SELECT NAME="sort" SIZE=1>
% foreach my $s (sort @sorts){
<OPTION VALUE="<%$s%>" <% $sort eq $s ? 'SELECTED' : ''%>><%$s%>
% }
</SELECT>
</TD>
</TR>
<TR>
<TH VALIGN=TOP>Subnet:</TH>
<TD>
<INPUT TYPE="text" SIZE=20 NAME="subnet" VALUE="<%$subnet|h%>" TITLE="CIDR Format : 192.168.0.0/24">
<span class="smaller">(CIDR Format : <tt>192.168.0.0/24</tt>)</span>
<BR>
% if (@$subnets) {
<SELECT NAME="subnet_select">
<OPTION VALUE="">Enter above or select here
% foreach (@$subnets) {
<OPTION VALUE="<%$_|h%>"<%$subnet eq $_ ? ' SELECTED' : ''%>><%$_%>
% }
</SELECT>
<!-- <%$s2 - $s1%> seconds -->
<BR>
% } else {
<A CLASS="navbutton" HREF="<%$r->uri|h%>?subnet_show=1">Show Subnets</A>
<SPAN CLASS="smaller">(this can take a <i>long</i> time on big installs)</span>
% }
</TD>
</TR>
<TR>
<TH>Options</TH>
<TD>List IPs never discovered <INPUT TYPE="checkbox" NAME="never" VALUE=1<%$never ? ' CHECKED' : ''%>><BR>
Resolve IPs
<INPUT TYPE="radio" NAME="dns" VALUE=1<%$dns ? ' CHECKED': ''%>>On
<INPUT TYPE="radio" NAME="dns" VALUE=0<%!$dns ? ' CHECKED': ''%>>Off<BR>
Limit
<SELECT NAME="max" SIZE=1>
% for (qw/16 48 96 256 512 1024 4096 100000/){
<OPTION VALUE="<%$_%>"<%$max eq $_ ? ' SELECTED' : ''%>><%$_%>
%}
</SELECT>
</TD>
</TR>
<TR>
<TD> </TD>
<TD><INPUT TYPE="submit" CLASS="navbutton" VALUE="Find IPs"></TD>
</TR>
</TABLE>
</DIV>
</FORM>
<P>
<h1 class="pagehead">Netbios Inventory</h1>
% $m->comp('SELF:show_nbt') if $cmd eq 'nbt';
<FORM ACTION="<%$r->uri%>" METHOD=GET>
<DIV>
<INPUT TYPE="hidden" NAME="cmd" VALUE="nbt">
<TABLE CLASS="ips-search">
<TR>
<TH>Domain:</TH>
<TD><SELECT NAME="domain" MULTIPLE SIZE=8>
<OPTION VALUE="all"<%!scalar(@domain) ? ' SELECTED' : ''%>>[All]
<OPTION VALUE="blank" <%grep(/^\Qblank\E$/,@domain)?' SELECTED':''%>>(Blank Domain)
% foreach my $d (sort keys %$nbt_domains){
<OPTION VALUE="<%$d|u%>"<%grep(/^\Q$d\E$/,@domain)?' SELECTED':''%>><%$d|h%> (<%$nbt_domains->{$d} |h%>)
% }
</SELECT>
<!-- (<% $n2 - $n1 %> seconds.) -->
</TD>
</TR>
<TR>
<TH>Archive Data:</TH>
<TD><INPUT TYPE="checkbox" NAME="archive" VALUE=1<%$archive ? ' CHECKED' : ''%>></TD>
</TR>
<TR>
<TD COLSPAN=2><INPUT TYPE="submit" CLASS="navbutton" VALUE="Search">
<A CLASS="navbutton" HREF="<%$r->uri%>">Reset</A>
</TD>
</TR>
</TABLE>
</DIV>
</FORM>
<%args>
$subnet => ''
$subnet_select => ''
$subnet_show => 0
$sort => 'IP'
$age_val => 2
$age_mul => 'months'
$cmd => ''
$max => 256
@domain => ()
$archive => 0
$never => 0
$dns => 1
$type => 'all'
</%args>
<%shared>
my @sorts = qw/IP Age/;
my ($ips,$arg_sort,$odd,$arg_max,$arg_domain,$addrs,$err,$arg_dns);
my $nodes = []; my $domain_count = {}; my $nbt_domains={};
my $subnets = [];
my $domain = $netdisco::CONFIG{domain} || '';
my $have_nbt_names = 0;
</%shared>
<%init>
$arg_sort = $sort; $arg_max = $max; $arg_domain = \@domain; $arg_dns = $dns;
# If you're just visiting for the first time, set the never checkbox.
# If you've submitted a query, though, leave never alone. Can't
# default it to 1 in %args since it's a checkbox so no value is
# submitted if it's not checked.
if (%ARGS == 0) {
$never = 1;
}
# get some form filler
my $n1 = time;
# I admit, this 'group by' is an ugly kludge :) -m
$nbt_domains = sql_column('node_nbt group by domain',['distinct(domain)','count(*)']);
my $n2 = time;
delete $nbt_domains->{''};
# Get the rows from the subnets table that have
# node or device addresses.
my $s1 = time;
if ($subnet_show) {
#BROKEN ON NEWNOC maxb 4/27 -- takes too long at 96 seconds
$subnets = active_subnets();
}
my $s2 = time;
$subnet = $subnet_select if ($subnet_select ne '');
if ($cmd eq 'age' and !$subnet){
$err = "Subnet Required.";
$cmd = '';
}
if ($cmd eq 'age'){
# Make new column in sql results 'is_old' that is boolean and
# tells if we match the aging characteristic. Default to all
# matching for type eq 'all'.
my @col = ('true as is_old');
if ($type eq 'age') {
$age_val = 2 unless $age_val =~ m/^\d+$/;
$age_mul =~ s/[^a-z ]+//g;
@col = ("(age(now(),node_ip.time_last) >= interval '$age_val $age_mul') as is_old");
}
$subnet .= '/24' unless $subnet =~ /\//;
my $safenet = dbh_quote($subnet);
# Grab all node_ip entries in subnet
my $nodes = sql_rows('node_ip LEFT JOIN node_nbt ON node_nbt.ip=node_ip.ip',
[@col, 'age(now(),node_ip.time_last) as age',
'extract(epoch from node_ip.time_first) as time_first',
'extract(epoch from node_ip.time_last) as time_last',
'node_ip.ip','node_ip.active',
'node_nbt.domain','node_nbt.nbname',
'node_nbt.active as nbtactive'],
{ 'node_ip.ip' => \\"<< inet $safenet" }
);
# Add all the device / aliases in subnet
$col[0] =~ s/node_ip\.time_last/last_discover/;
my $devs_seen = sql_rows('device', ['age(now(),last_discover) as age',
'extract(epoch from creation) as time_first','true as active',
'extract(epoch from last_discover) as time_last','ip', @col],
{ 'ip' => \\"<< inet $safenet"});
$col[0] =~ s/last_discover/d.last_discover/;
my $aliases = sql_rows('device_ip a left join device d on a.ip=d.ip', ['age(now(),d.last_discover) as age',
'extract(epoch from a.creation) as time_first','true as active',
'extract(epoch from d.last_discover) as time_last','a.alias as ip',@col],
{ 'a.alias' => \\"<< inet $safenet"});
# Loop through to find newest entries
my %seen; my %results;
foreach my $r (@$devs_seen,@$aliases,@$nodes){
my $ip = $r->{ip};
my $is_old = $r->{is_old};
my $am_newest = 0;
# First entry
unless (defined $seen{$ip} ){
$am_newest++;
}
# Active entries, but dont overwrite device entries
# note that devs and aliases come first
elsif ($r->{active} and !$seen{$ip}->{active}) {
$am_newest++;
}
# newest archived data
elsif ( $r->{time_last} > $seen{$ip}->{time_last} ) {
$am_newest++;
}
next unless $am_newest;
$have_nbt_names ||= defined($r->{nbname});
# Mark down IP as the most relevant and seen
$seen{$ip}=$r;
next unless $is_old;
# Mark down the IP as a match
$results{$ip}=$r;
}
push (@$ips,values %results);
# Look for holes in our IP Space and report on that.
if ($never){
# Get all the possible IPs in a subnet
$addrs = dump_subnet($subnet) || {};
# Remove all the nodes seen in the subnet
foreach my $ip (keys %seen) {
delete $addrs->{$ip};
}
# Add our missing IPs to the results from above.
foreach my $ip (keys %$addrs){
push @$ips, { 'age' => 'Never', 'time_first' => 'Never',
'ip' => $ip, 'active' => 1, 'time_last' => 'Never',
};
}
}
# Do DNS lookups on results
if ($dns){
foreach my $i (@$ips){
my $ip = $i->{ip};
$i->{dns} = hostname($ip);
}
}
}
if ($cmd eq 'nbt'){
my $where = {};
foreach my $d (@domain) {
$d = '' if $d eq 'blank';
}
if (grep(/^all$/,@domain)){
@domain = ();
} else {
$where = {'domain' => [[@domain]]};
}
$where->{active} = 1 unless $archive;
$nodes = sql_rows('node_nbt',['ip','mac','nbname','domain','server','nbuser','active',
'extract(epoch from time_first) as time_first','extract(epoch from time_last) as time_last'],
$where);
# count domains
foreach my $n (@$nodes){
my $d = $n->{domain};
$domain_count->{$d}++;
}
}
</%init>
%#
%# show_nbt() - Show results from Netbios Search
%#
<%method show_nbt>
<h2 class="subheader">Results</h2>
% unless (scalar @$nodes) {
No Results Found.
% return; }
<TABLE CLASS="ips-res">
<TR>
<TH>Domain</TH>
<TH>Count</TH>
<TH>Domain</TH>
<TH>Count</TH>
</TR>
% my $cnt = 0;
% foreach my $d (sort keys %$domain_count){
% $cnt++;
% if ($cnt%2){
<TR CLASS="match-<%++$odd%2%>">
%}
<TD><A HREF="<%$r->uri%>?domain=<%$d||'blank'|u%>"><%$d || '[Blank]'|h%></A></TD>
<TD><%$domain_count->{$d}%></TD>
% if (($cnt+1)%2) {
</TR>
%}
%}
</TABLE>
<% scalar(keys %$domain_count) %> Domains.
<P>
<TABLE CLASS="ips-res">
<TR>
<TH>Domain</TH>
<TH>Node</TH>
<TH>Name</TH>
<TH>User</TH>
<TH>First Seen</TH>
<TH>Last Seen</TH>
</TR>
% my $last_domain = '';
% foreach my $n (sort {($a->{domain} cmp $b->{domain}) or
% (lc($a->{nbname}) cmp lc($b->{nbname}) )}
% @$nodes){
<TR CLASS="match-<%++$odd%2%>">
<TD><%$last_domain ne $n->{domain} ? $m->interp->apply_escapes($n->{domain}, 'h') : ' '%></TD>
<TD><A HREF="node.html?node=<%$n->{mac}|u%>"><%$n->{mac}%></A></TD>
<TD><%$n->{domain} ? "\\\\$n->{domain}\\" : '' |h%><A HREF="node.html?node=<%$n->{nbname} |u%>"><%$n->{nbname} || '[None]'|h%></A></TD>
<TD><%$n->{nbuser} || '[No User]' |h%> @
<A HREF="node.html?node=<%$n->{ip} |u%>"><%$n->{ip}%></A>
</TD>
<TD><& 'node.html:format_date', date=>$n->{time_first}&></TD>
<TD><& 'node.html:format_date', date=>$n->{time_last}&></TD>
</TR>
% $last_domain = $n->{domain};
% }
</TABLE>
<% scalar(@$nodes) %> Nodes.
<P>
</%method>
%#
%# show_age() - Show results from IP age inventory
%#
<%method show_age>
<h2 class="subheader">Results</h2>
% unless (scalar @$ips) {
No Results Found.
% return; }
<TABLE CLASS="ips-res">
<TR>
<TH>Node</TH>
% if ($arg_dns) {
<TH>Host Name</TH>
% }
% if ($have_nbt_names) {
<TH>NetBIOS<BR>Name</TH>
% }
<TH>Last Used</TH>
<TH>First<BR>Discovered</TH>
</TR>
<%perl>
my @rows;
if ($arg_sort eq 'Age'){
@rows = sort { $a->{time_last} <=> $b->{time_last} } @$ips;
} else {
@rows = sort sort_ip @$ips;
}
# Truncate the list if too long (too many results)
if (scalar @rows > $arg_max) {
splice(@rows,$arg_max);
$m->out("Found ".scalar(@$ips) ." matching IPs. Only showing $arg_max.<BR>\n");
}
$odd = 1;
foreach my $row (@rows){
my $ip = $row->{ip};
my $dns = $row->{dns};
$dns =~ s/\Q$domain\E//;
my $age = $m->comp('device_inv.html:.trim_age', age => $row->{age});
my $time_first = $row->{time_first} eq 'Never' ? ' ' : scalar(localtime($row->{time_first}));
my $active = $row->{active};
my $d = $row->{domain};
my $nbname = $row->{nbname};
my $nbtactive = $row->{nbtactive};
$odd++;
</%perl>
<TR>
<TD CLASS="match-<%$odd%2%>"><A HREF="node.html?node=<%$ip|u%><%!$active ? '&archive=1' : ''%>"><%$ip%></A><%!$active ? '*' : ''%></TD>
% if ($arg_dns) {
<TD CLASS="match-<%$odd%2%>">
% if ($dns) {
<A HREF="node.html?node=<%$dns|u%><%!$active ? '&archive=1' : ''%>"><%$dns%></A><%!$active ? '*' : ''%>
% } else {
% }
</TD>
% }
% if ($have_nbt_names) {
<TD CLASS="match-<%$odd%2%>">
% if ($nbname) {
\\<%$d%>\<%$nbname%><%!$nbtactive ? '*' : ''%>
% } else {
% }
</TD>
% }
<TD CLASS="match-<%$odd%2%>"><%$age%><%!$active ? '*' : ''%></TD>
<TD CLASS="match-<%$odd%2%>"><%$time_first%></TD>
</TR>
%}
</TABLE>
<% scalar @rows %> IPs Shown.
<BR><B>*</B> denotes archived data (not currently in use, but seen).
</%method>
<%method title>
- Node Inventory \
</%method>
%# $Id: ip_search.html,v 1.15 2008/09/28 09:43:26 olly_g Exp $
%# vim:syntax=mason
|