/usr/share/netdisco/html/port_report.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 | <h1 class="pagehead">Port Reporting</h1>
<FORM ACTION="<%$r->uri%>" METHOD=GET>
<DIV>
<INPUT TYPE="hidden" NAME="cmd" VALUE="search">
<TABLE class="port-key">
<TR>
<TH>Reason:</TH>
<TD>
<SELECT NAME="reason" MULTIPLE>
<OPTION VALUE=""<% (scalar @reason and grep(/\S+/,@reason)) ? '' : ' SELECTED'%>>All Reasons
% foreach my $reason (keys %$db_reasons) {
<OPTION VALUE="<%$reason|h%>" TITLE="<%$Reasons{$reason}->[1]||'' |h%>"<%grep(/^$reason$/,@reason) ? ' SELECTED' : ''%>><% $Reasons{$reason}->[0] || $reason %> (<%$db_reasons->{$reason}%>)
% }
</SELECT>
</TD>
</TR>
<TR>
<TH>Text Search:</TD>
<TD><INPUT TYPE="text" NAME="text" VALUE="<%$text|h%>">
<BR><span class="small">eg. <i>blaster</i>, <i>nachi</i></span>
</TD>
</TR>
<TR>
<TH>Action Type:
</TH>
<TD>
<INPUT TYPE="radio" NAME="dir" VALUE="enable"<%$dir eq 'enable' ? ' CHECKED' : ''%>>Port Enable
<INPUT TYPE="radio" NAME="dir" VALUE="disable"<%$dir eq 'disable' ? ' CHECKED' : ''%>>Port Disable
<INPUT TYPE="radio" NAME="dir" VALUE="vlan"<%$dir eq 'vlan' ? ' CHECKED' : ''%>>VLAN Switch
<INPUT TYPE="radio" NAME="dir" VALUE=""<%$dir eq '' ? ' CHECKED' : ''%>>All
<BR><span class="small">Limit search to the enabling or disabling of ports.</span>
</TD>
</TR>
<TR>
<TH>Report Type:</TH>
<TD>
<INPUT TYPE="radio" NAME="type" VALUE=""<%$type eq '' ? ' CHECKED' : ''%>>Historical Log Entries
<INPUT TYPE="radio" NAME="type" VALUE="now"<%$type eq 'now' ? ' CHECKED' : ''%>>Current Only <span class="smaller">(slow)</span>
<BR><span class="small">Choose to see a list of log entries, or to see currently disabled ports that
<i>also</i> have log entries.</span>
</TD>
</TR>
<TR>
<TH>User:</TH>
<TD><SELECT NAME="user" MULTIPLE SIZE=4>
<OPTION VALUE=""<%grep(/\S+/, @user) ? '' : ' SELECTED'%>>All Users
% foreach my $user (sort keys %$db_users) {
<OPTION VALUE="<%$user|h%>"<%grep(/^$user$/,@user) ? ' SELECTED' : ''%>><%$user%> (<%$db_users->{$user}%>)
% }
</SELECT>
</TD>
</TR>
<TR>
<TH>Sort By:</TH>
<TD>
<SELECT NAME="sort" SIZE=3>
% foreach (qw/Date User Reason Port/){
<OPTION VALUE="<%$_|h%>"<%$sort eq $_ ? ' SELECTED' : ''%>><%$_|h%>
% }
</SELECT>
</TD>
</TR>
<TR>
<TH>Time Frame:</TH>
<TD>
<INPUT TYPE="radio" NAME="timeframe" VALUE=""<%$timeframe eq '' ? ' CHECKED' : ''%> >All
<INPUT TYPE="radio" NAME="timeframe" VALUE="today"<%$timeframe eq 'today' ? ' CHECKED' : ''%>>Today
<INPUT TYPE="radio" NAME="timeframe" VALUE="week"<%$timeframe eq 'week' ? ' CHECKED' : ''%> >This Week
<INPUT TYPE="radio" NAME="timeframe" VALUE="month"<%$timeframe eq 'month' ? ' CHECKED' : ''%>>This Month
<BR>
<INPUT TYPE="radio" NAME="timeframe" VALUE="interval"<%$timeframe eq 'interval' ? ' CHECKED' : ''%>>Within the last
<SELECT NAME="timenumber">
% for (1..31) {
<OPTION VALUE="<%$_%>"<%$timelength eq $_ ? ' SELECTED' : ''%>><%$_%>
% }
</SELECT>
<SELECT NAME="timelength">
% for (qw/days months years/) {
<OPTION VALUE="<%$_%>"<%$timenumber eq $_ ? ' SELECTED' : ''%>><%$_%>
% }
</SELECT>
</TD>
</TR>
<TR>
<TD> </TD>
<TD>
<INPUT TYPE=SUBMIT VALUE="Generate Report" CLASS="navbutton">
<A CLASS="navbutton" href="<%$r->uri%>">Reset</A>
</TD>
</TR>
</TABLE>
</DIV>
</FORM>
<& SELF:report &>
<%args>
$cmd => ''
$text => ''
$dir => 'disable'
@reason => ()
$type => ''
$timeframe => 'month'
$timelength => 'days'
$timenumber => 1
@user => ()
$sort => 'Date'
</%args>
<%doc>
TODO:
- Implement Time frames for reports.
</%doc>
<%shared>
my %Reasons = %netdisco::PORT_CONTROL_REASONS;
my $matches = undef;
my $argsort = undef;
my $argtype = undef;
</%shared>
<%init>
# Get rid of \n's in the long reasons
foreach my $reason (keys %Reasons){
$Reasons{$reason}->[1] =~ s/\n//g;
}
$argsort = $sort;
$argtype = $type;
# Grab the reasons and people out of the port log
# todo: sql_column has no way of doing a 'group by', so this kludge
my $db_reasons = {};
my $db_temp = sql_rows('device_port_log',
['distinct(reason) as reason','count(reason) as count'],
{'action' => "!vlan"},
0,'group by reason');
foreach my $row (@$db_temp){
$db_reasons->{$row->{reason}}=$row->{count};
}
my $db_users = {};
$db_temp = sql_rows('device_port_log',['distinct(username) as username','count(username) as count'],undef,0,'group by username');
foreach my $row (@$db_temp){
$db_users->{$row->{username}}=$row->{count};
}
# Search for ports
if ($cmd eq 'search'){
#Get current time
my ($second, $minute, $hour, $day, $month, $year, $weekDay, $dayofyear, $isDST) = localtime;
if($day < 10) {
$day = "0" . $day;
}
$month++;
if($month < 10) {
$month = "0" . $month;
}
$year += 1900;
my $yearMonth = $year . "-" . $month;
my $yearMonthDay = $yearMonth . "-" . $day;
$timelength =~ s/[^a-z ]+//g;
$timenumber = 1 unless $timenumber =~ m/^\d+$/;
# Get ports from port device log
my $tables = 'device_port_log l left join device d on d.ip = l.ip';
my $cols = ['d.dns','l.reason','l.port','l.ip','l.log','l.username','l.userip','l.action','extract(epoch from l.creation) as creation'];
my $where = {};
$where->{'l.log'} = '%'.$text.'%' if $text;
$where->{'l.reason'} = [\@reason] if (scalar @reason and grep(/\S+/,@reason));
$where->{'l.action'} = $dir if $dir;
$where->{'l.username'} = [\@user] if (scalar @user and grep(/\S+/,@user));
if ($type eq 'now'){
$tables .= ' left join device_port p on l.ip = p.ip and l.port = p.port';
$where->{'p.up_admin'} = 'down';
}
if ($timeframe eq 'interval'){
if ($timelength eq 'days'){
$where->{'age(l.creation)'} = \\"<= interval \'$timenumber day\'";
} elsif ($timelength eq 'months'){
$where->{'age(l.creation)'} = \\"<= interval \'$timenumber mon\'";
} else {
$where->{'age(l.creation)'} = \\"<= interval \'$timenumber year\'";
}
} elsif ($timeframe eq 'today'){
$where->{'l.creation'} = '%'.$yearMonthDay.'%';
} elsif ($timeframe eq 'week'){
$where->{'age(l.creation)'} = \\"<= interval \'$weekDay day\'";
} elsif ($timeframe eq 'month'){
$where->{'l.creation'} = '%'.$yearMonth.'%';
}
#$netdisco::SQLCARP=1;
$matches = sql_rows($tables,$cols,$where) || [];
#$netdisco::SQLCARP=0;
}
</%init>
<%method report>
<%perl>
return unless defined $matches;
# Sort by routines
@$matches = sort { $b->{creation} <=> $a->{creation} } @$matches if $argsort eq 'Date';
if ($argsort eq 'User'){
@$matches = sort {
# Sort by username
if ($a->{username} ne $b->{username}) {
return ($a->{username} cmp $b->{username});
}
# Secondary sort by creation
return $b->{creation} <=> $a->{creation};
} @$matches;
}
if ($argsort eq 'Reason'){
@$matches = sort {
# Sort by Reason
if ($a->{reason} ne $b->{reason}){
return $a->{reason} cmp $b->{reason};
}
# 2nd Sort by Date
return $b->{creation} <=> $a->{creation};
} @$matches;
}
if ($argsort eq 'Port'){
@$matches = sort {
# Sort by IP
if ($a->{ip} ne $b->{ip}) {
# Anyone tell me why this will only work when I cast it to scalar???
return scalar &sort_ip;
}
# 2nd - Sort by Port
if ($a->{port} ne $b->{port}){
return scalar &sort_port;
}
# 3rd - Sort by date
return $b->{creation} <=> $a->{creation};
} @$matches;
}
</%perl>
<h1 class="pagehead">Matching Ports</h1>
% unless (scalar @$matches) {
No Ports Matching.<BR>
%return;}
<%scalar @$matches%> Ports matching.<BR>
% if ($argtype eq 'now'){
<B>Showing log entries for ports that are currently disabled only.</b><bR>
% }
<P>
<TABLE CLASS="port-rep">
<TR>
<TH>Port</TH>
<TH>Who</TH>
<TH>Reason/Action</TH>
<TH>Log</TH>
<TH>Date</TH>
</TR>
% my $count = 0;
% foreach my $port (@$matches) {
% my $dev = $port->{dns} || $port->{ip};
% $dev =~ s/\Q$netdisco::CONFIG{domain}\E//;
% $count++;
<TR>
<TD CLASS="match-<%$count%2%>"><span class="small"><A HREF="device.html?ip=<%$port->{ip}|u%>&port=<%$port->{port}|u%>"><%$dev%> [<%$port->{port}%>]</A></span></TD>
<TD CLASS="match-<%$count%2%>"><%$port->{username}%><BR><span class="small"><a href="node.html?node=<%$port->{userip}%>"><%$port->{userip}%></a></span></TD>
<TD CLASS="match-<%$count%2%>"><%$port->{reason}%>/<%$port->{action}%></TD>
<TD CLASS="match-<%$count%2%>"><span class="smaller"><%$port->{log} || ' '%></span></TD>
<TD CLASS="match-<%$count%2%>"><span class="nobr"><% scalar localtime($port->{creation})%></span></TD>
</TR>
% }
</TABLE>
</%method>
<%method title>
- Port Reporting \
</%method>
%# $Id: port_report.html,v 1.12 2009/06/11 00:22:33 maxbaker Exp $
%# vim:syntax=mason
|