/usr/share/netdisco/html/portcontrol.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 | <h1 class="pagehead">Device Port Control</h1>
% $m->comp('SELF:switch') if $cmd =~ /^(up|down)$/;
% $m->comp('SELF:log') if $cmd eq 'log';
% $m->comp('SELF:err') if $cmd eq 'err';
% $m->comp('SELF:vlan') if $cmd eq 'vlan';
% $m->comp('SELF:reasons') unless $cmd eq 'err' or $cmd eq 'vlan';
<%args>
$debug => 0
$cmd => undef
$type => undef
$ip => undef
$port => undef
$log => undef
$log_num => 5
$reason => ''
$vlan => undef
</%args>
<%shared>
# scope
my ($arg_ip,$arg_port,$log,$arg_cmd,$port,$err,$db_port,$arg_reason,$arg_log_num,$arg_vlan);
my $user = $m->session->{user};
my $userip = $r->connection->remote_ip;
my $port_ctl = $m->session->{user_port_ctl};
my $secure = &is_secure;
my $timeout = $netdisco::CONFIG{portctl_timeout} || 60;
my $odd = 1 ;
my %Reasons = ( '' => ['Select a Reason',''],
%netdisco::PORT_CONTROL_REASONS);
</%shared>
<%init>
# Check Authorization - User in portcontrol list in config file, and connected via https
if ($cmd =~ /^(up|down|switch|vlan)$/ and !$secure) {
my $url = url_secure($r->uri);
$m->redirect($url);
}
if ($cmd =~ /^(up|down|switch|vlan)$/ and !$port_ctl) {
$m->session->{_login_msg} = "Please log in as a user with port control privileges.";
my $url = $m->interp->apply_escapes( $r->uri, 'u' );
$m->redirect("login.html?done=$url");
}
$arg_cmd = $cmd; $arg_ip = $ip; $arg_port = $port;
$arg_reason = $reason; $arg_log_num = $log_num;
$arg_vlan = $vlan;
if ($cmd eq 'switch' and !$reason and $type ne 'vlan' ){
$cmd = 'err';
$err .= "You must select a reason for bringing the port $type <BR>\n";
}
my $dbport;
if ($cmd =~ /^(up|down|switch|vlan)$/){
$dbport = sql_hash('device_port',['*'],{'ip'=>$ip, 'port'=>$port});
my $remote_ip = $dbport->{remote_ip};
my $remote_type = $dbport->{remote_type};
my $is_uplink = (defined $remote_ip and !(defined $remote_type and $remote_type =~ /ip.phone/i)) ? 1 : 0;
unless (defined $dbport and scalar(keys %$dbport)){
$cmd = 'err';
$err .= "That Port doesn't exist!<BR>\n";
}
if ($is_uplink) {
$cmd = 'err';
$err .= "You cannot shutoff uplink ports. <BR>\n";
}
}
if ($cmd eq 'switch' and $type =~ /^(up|down|vlan)$/) {
my $dir = $type;
$dir = 'enable' if $type eq 'up';
$dir = 'disable' if $type eq 'down';
my ($action,$subaction);
if ($type =~ /(up|down)/) {
$action = 'portcontrol';
$subaction = "$type-$reason";
}
if ($type eq 'vlan') {
$action = 'vlan';
$subaction = $vlan;
}
# Add to admin queue
insert_or_update('admin',{},
{'device'=>$ip,'action'=>$action,'status'=>'queued','port'=>$port,
'username' => $user, 'userip', $userip, 'debug' => $debug, 'subaction' => $subaction,
'log' => $log}
);
my $job_id = sql_scalar('admin',["currval('admin_job_seq')"]);
# Wait for a response from admin daemon
my $now = time; my $job;
my $timeout_time = $now + $timeout;
my $done = 0;
my $status;
while (!$done){
# Poll every two seconds
sleep(2);
# Check to see if daemon done
$job = sql_hash('admin',['job','extract(epoch from entered) as entered','extract(epoch from finished) as finished',
'extract(epoch from started) as started','status','log'],
{'job'=>$job_id}
);
if (! defined $job || !defined($job->{job})){
$err = "Problem entering job $job_id into admin queue.<BR>\n";
last;
}
$status = $job->{status};
$done++ if $status =~ /^(done|error)$/;
$done++ if $status !~ /^(running|queued)$/;
$now = time;
if (!$done and $now >= $timeout_time and $status =~ /^(running|queued)$/){
my $url = $r->uri . "?ip=$ip&port=$port&cmd=log";
$err = "Timeout! Job is $status in the admin queue. Check the <A HREF=\"$url\">port log entry</A> in a couple minutes to double-check it worked.<BR>\n";
$cmd = 'err';
last;
} elsif (!$done and $now >= $timeout_time){
$err = "Error. There was a problem with entering the job in the admin queue. Check to see the admin daemon is running, then check it's log file for problems.\n";
$cmd = 'err';
last;
}
}
if (!$err and $status eq 'done'){
$cmd = 'log';
$err = "Port was successfully $dir.<BR>\n";
} elsif (!$err and $status eq 'error'){
$cmd = 'err';
$err = "[Failed] <P>$job->{log}<BR>\n";
} else {
$cmd = 'err';
$err = "[Failed] I don't know what happened to the job. Status: $job->{status}. <P>Log: $job->{log}<BR>.\n" unless ($err);
}
}
</%init>
<%method log>
% my $logs = sql_rows('device_port_log', ['id','log','reason','username','userip','action','extract(epoch from creation) as creation'] ,
% {'ip'=>$arg_ip, 'port'=>$arg_port} );
% my $queue = sql_rows('admin', ['extract(epoch from entered) as entered','extract(epoch from started) as started','action','subaction','username','userip'],
% {'device'=>$arg_ip, 'port'=>$arg_port, 'status'=>'queued'} );
% my $count = 0;
% if ($err) {
<h2 class="subheader"><%$err%></h2>
% }
<h2 class="subheader">Log Entries for <A HREF="device.html?ip=<%$arg_ip |u%>&port=<% $arg_port|u%>"><%$arg_ip%>/<%$arg_port%></A>
<& SELF:back &></h2>
% if (@$queue) {
<h2 class="subheader">Queued Actions for <%$arg_ip%>/<%$arg_port%>
(Check admin daemon status)</h2>
<TABLE WIDTH=85% CELLSPACING=0 CELLPADDING=2 BORDER=0>
<TR>
<TH>User</TH>
<TH>Action</TH>
<TH>Queued</TH>
<TH>Started</TH>
</TR>
% foreach my $entry (@$queue) {
<TR>
<TD><%$entry->{username}%> @ <%$entry->{userip}%></TD>
<TD><%$entry->{action}%> <%$entry->{subaction}%></TD>
<TD><%scalar localtime($entry->{entered})%></TD>
<TD><%$entry->{started} ? scalar localtime($entry->{started}) : "No"%></TD>
</TR>
% }
</TABLE>
% }
<FORM ACTION="<%$r->uri%>" METHOD=GET>
<INPUT TYPE="HIDDEN" NAME="cmd" VALUE="log">
<INPUT TYPE="HIDDEN" NAME="ip" VALUE="<%$arg_ip |h%>">
<INPUT TYPE="HIDDEN" NAME="port" VALUE="<%$arg_port|h%>">
<TABLE WIDTH=85% CELLSPACING=0 CELLPADDING=2 BORDER=0>
<TR>
<TH>User</TH>
<TH>Action</TH>
<TH>Date</TH>
<TH>Reason / VLAN</TH>
<TH>Log</TH>
</TR>
% foreach my $entry (sort {$b->{creation} <=> $a->{creation} } @$logs) {
<TR CLASS="match-<% ++$odd % 2 %>">
<TD><%$entry->{username}%> @ <%$entry->{userip}%></TD>
<TD><%$entry->{action}%></TD>
<TD><%scalar localtime($entry->{creation})%></TD>
% if ( $entry->{action} eq 'vlan' ) {
<TD><%$entry->{reason}%></TD>
% } else {
<TD><A HREF="#<%$entry->{reason}%>"><%$Reasons{$entry->{reason}}->[0]%></A></TD>
% }
<TD><TEXTAREA ROWS=3 COLS=30 WRAP=soft><%$entry->{log}%></TEXTAREA>
</TD>
</TR>
% $count++;
% last unless ($arg_log_num eq 'All' or $count < $arg_log_num);
%}
</TABLE>
Log Entires to Show : <SELECT NAME="log_num">
% foreach my $num (qw/1 3 5 10 20 50 100 All/){
<OPTION VALUE="<%$num%>" <%$num eq $arg_log_num ? 'SELECTED' : ''%>><%$num%>
% }
</SELECT>
<INPUT TYPE="submit" CLASS="navbutton" VALUE="Refresh">
</FORM>
</%method>
%#
%# switch()
%#
<%method switch>
<FORM ACTION="<%$r->uri%>" METHOD="post">
<INPUT TYPE="HIDDEN" NAME="cmd" VALUE="switch">
<INPUT TYPE="HIDDEN" NAME="type" VALUE="<%$arg_cmd |h%>">
<INPUT TYPE="HIDDEN" NAME="port" VALUE="<%$arg_port |h%>">
<INPUT TYPE="HIDDEN" NAME="ip" VALUE="<%$arg_ip |h%>">
<TABLE BORDER=0 CELLSPACING=0 CLASS="box">
<TR CLASS="match-1">
<TD>Port :</TD>
<TD CLASS="tr-data-1"><A HREF="device.html?ip=<%$arg_ip |u%>&port=<% $arg_port|u%>"><% $arg_ip %>[<% $arg_port %>]</A></TD>
</TR>
<TR CLASS="match-0">
<TD>User :</TD>
<TD CLASS="tr-data-0"><U><%$user%></U> at <%$userip%> <BR><u><% scalar localtime %></u>
</TD>
</TR>
<TR CLASS="match-1">
<TD>Reason :<BR> </TD>
<TD CLASS="tr-data-1"><SELECT NAME="reason" SIZE=1>
% $arg_reason = 'other' if $arg_cmd eq 'up';
% foreach my $this_r (sort keys %Reasons){
<OPTION VALUE="<%$this_r |h%>" <%$this_r eq $arg_reason ? 'SELECTED' : ''%>> \
% if ($this_r){
[<%$this_r%>] \
% }
<%$Reasons{$this_r}->[0]%>
%}
</SELECT>
<BR><FONT SIZE=-3>See below for descriptions.</FONT>
</TD>
</TR>
<TR CLASS="match-0">
<TD>Log:</TD>
<TD CLASS="tr-data-0"><TEXTAREA NAME="log" ROWS=3 COLS=40 WRAP=soft></TEXTAREA>
<BR>Enter a useful description why the port is being turned <% $arg_cmd eq 'down' ? 'off' : 'on' %>.
</TD>
</TR>
<TR CLASS="match-1">
<TD COLSPAN=2 CLASS="tr-data-1">
<INPUT TYPE="submit" CLASS="navbutton" VALUE="Turn Port <%$arg_cmd eq 'down' ? 'off' : 'on'%>">
Debug: <INPUT TYPE="checkbox" NAME="debug" VALUE="1">
<P><I>Note</I>: This can take up to 1 minute. Do not hit refresh on your browser.
</TD>
</TR>
</TABLE>
</FORM>
<& SELF:back &>
</%method>
%#
%# vlan()
%#
<%method vlan>
<FORM ACTION="<%$r->uri%>" METHOD="post">
<INPUT TYPE="HIDDEN" NAME="cmd" VALUE="switch">
<INPUT TYPE="HIDDEN" NAME="type" VALUE="vlan">
<INPUT TYPE="HIDDEN" NAME="port" VALUE="<%$arg_port |h%>">
<INPUT TYPE="HIDDEN" NAME="ip" VALUE="<%$arg_ip |h%>">
<TABLE BORDER=0 CELLSPACING=0 CLASS="box">
<TR CLASS="match-1">
<TD>Port :</TD>
<TD CLASS="tr-data-1"><A HREF="device.html?ip=<%$arg_ip |u%>&port=<% $arg_port|u%>"><% $arg_ip %>[<% $arg_port %>]</A></TD>
</TR>
<TR CLASS="match-0">
<TD>User :</TD>
<TD CLASS="tr-data-0"><U><%$user%></U> at <%$userip%> <BR><u><% scalar localtime %></u>
</TD>
</TR>
<TR CLASS="match-1">
<TD>Log:</TD>
<TD CLASS="tr-data-0"><TEXTAREA NAME="log" ROWS=3 COLS=40 WRAP=soft></TEXTAREA>
<BR>Enter a useful description why the VLAN is being changed.
</TD>
</TR>
<TR CLASS="match-0">
<TD>VLAN:</TD>
%# TODO - need to list VLANs
<TD CLASS="tr-data-0"><INPUT NAME="vlan" SIZE=5 MAXLENGTH=5> Enter new VLAN </TD>
</TR>
<TR CLASS="match-1">
<TD COLSPAN=2 CLASS="tr-data-1">
<INPUT TYPE="submit" CLASS="navbutton" VALUE="Change VLAN">
Debug: <INPUT TYPE="checkbox" NAME="debug" VALUE="1">
<P><I>Note</I>: This can take up to 1 minute. Do not hit refresh on your browser.
</TD>
</TR>
</TABLE>
</FORM>
<& SELF:back &>
</%method>
%#
%# reasons()
%#
<%method reasons>
<h2 class="subheader">Reason Descriptions</h2>
<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=3>
<TR>
<TH>Reason</TH>
<TH>Description</TH>
</TR>
<TR>
<TD COLSPAN=2><HR NOSHADE></TD>
</TR>
% foreach my $this_r (sort keys %Reasons){
% next unless $this_r;
% my $long = $Reasons{$this_r}->[1];
% $long =~ s!\s+! !g;
<TR>
<TD><A NAME="<%$this_r%>"><B><%$this_r%></B></A></TD>
<TD><%$long%></TD>
</TR>
% }
</TABLE>
</%method>
<%method err>
% $err =~ s/\n/<BR>\n/g;
<% $err %>
<& SELF:back &>
</%method>
<%method back>
<FORM ACTION="device.html" METHOD="get">
<INPUT TYPE="hidden" NAME="ip" VALUE="<%$arg_ip |h%>">
<INPUT TYPE="hidden" NAME="port" VALUE="all">
<INPUT TYPE="submit" CLASS="navbutton" VALUE="Back to Device View">
</FORM>
</%method>
%#
%# title()
%#
<%method title>
- Port Control \
</%method>
%# $Id: portcontrol.html,v 1.22 2007/12/14 02:18:25 maxbaker Exp $
%# vim:syntax=mason
|