aboutsummaryrefslogtreecommitdiffstats
path: root/examples/historical/web/nms.gathering.org/sshow.pl
blob: 64663a225cd91ec71a707d3a7fa7c908ae1604df (plain)
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
#!/usr/bin/perl
use lib '../../include';
use nms;

use warnings;
use strict;
use Switch;
use CGI;
use DBI;
use HTML::Entities;

# Grab from .htaccess-authentication
my $user = $ENV{'REMOTE_USER'};

my $dbh = nms::db_connect();
$dbh->{AutoCommit} = 0;

my $sgetdone = $dbh->prepare(
"SELECT * 
FROM  squeue 
WHERE processed = 't' 
ORDER BY updated DESC, sysname
LIMIT ?::text::int")
	or die "Could not prepare sgetdone";

my $sgetdonegid = $dbh->prepare(
"SELECT * 
FROM  squeue 
WHERE processed = 't' AND gid = ?::text::int 
ORDER BY updated DESC, sysname")
	or die "Could not prepare sgetdonegid";

my $slistdonegid = $dbh->prepare(
"SELECT DISTINCT gid, cmd, author, added
FROM squeue
WHERE processed = 't'
ORDER BY gid DESC
LIMIT ?::text::int")
	or die "Could not prepare slistdonegid";

my $slistprocgid = $dbh->prepare(
"SELECT DISTINCT gid, cmd, author, added
FROM squeue
WHERE processed = 'f'
ORDER BY gid")
	or die "Could not prepare slistprocgid";

my $sgetgid = $dbh->prepare(
"SELECT *
FROM squeue
WHERE gid = ?")
	or die "Could not prepare sgetgid";

my $sgetprocessing = $dbh->prepare(
"SELECT *
FROM  squeue
WHERE processed = 'f'
ORDER BY updated DESC, gid, sysname")
	or die "Could not prepare sgetprocessing";

my $sgetnoconnect = $dbh->prepare(
"SELECT *
FROM squeue
WHERE result = 'Could not connect to switch, delaying...'")
	or die "Could not prepare sgetnoconnect";

my $sdisablegid = $dbh->prepare("
UPDATE squeue SET disabled = 't'
WHERE gid = ?::text::int")
	or die "Could not prepare sdisablegid";
my $senablegid = $dbh->prepare("
UPDATE squeue SET disabled = 'f'
WHERE gid = ?::text::int")
	or die "Could not prepare sdisablegid";


my $cgi = new CGI;

print $cgi->header(-type=>'text/html; charset=utf-8');

print << "EOF";
<html>
  <head>
    <title>Switch managment</title>
  </head>
  <body>
  <p>Du er logget inn som: $user</p>
    <form method="POST" action="sshow.pl">
    <p>
      Vis <input type="text" name="count" size="4" value="10" /> siste<br />
      Vis: <select name="action" />
       <option value="listgid">Grupper</option>
       <option value="done">Ferdige</option>
       <option value="processing">I </option>
      </select>
      <input type="submit" value="Vis" /><br />
    </p>
    </form>
    <br />
EOF

my $limit = $cgi->param('count');
if (!defined($limit)) {
	$limit = 10;
}
my $action = $cgi->param('action');
if (!defined($action)) {
	$action = 'listgid';
}

if (defined($cgi->param('agid'))) {
	my $gid = $cgi->param('gid');
	if (!defined($gid)) {
		print "<font color=\"red\">Du har ikke valgt en gid å slette.</font>\n";
		print "<p>gid: ".$cgi->param('gid')." har blitt disablet.\n";
	}
	else {
		$senablegid->execute($gid);
		print "<p>gid: ".$cgi->param('gid')." har blitt enablet.\n";
	}
	$dbh->commit();
}

if ($action eq 'noconnect') {
	print "<h3>Kunne ikke koble til disse switchene:</h3>\n";
	$sgetnoconnect->execute();
	print "<pre>\n";
	while ((my $row = $sgetnoconnect->fetchrow_hashref())) {
		print "$row->{'sysname'} : $row->{'cmd'} : Added: $row->{'added'} : Updated: $row->{'updated'}\n";
	}
	print "</pre>\n";
}

if ($action eq 'listgid') {
	print "<pre>\n";
	print "<a href=\"sshow.pl?action=noconnect\" />Kunne ikke koble til</a>\n\n\n";
	print "<b>Ferdige:</b>\n";
	$slistdonegid->execute($limit);
	my ($gid, $author);
	$gid = -1;
	while ((my $row = $slistdonegid->fetchrow_hashref())) {
		$author = $row->{author};
		if ($gid != $row->{gid}) {
			$gid = $row->{gid};
			print "GID: <a href=\"sshow.pl?action=showgid&gid=$gid\">$gid</a>\n";
			print "Author: $author\n";
			print "Added: ".$row->{added}."\n";
		}
		my $cmd = $row->{cmd};
		print "$cmd\n\n";
	}
	print "\n\n";
	print "<b>I kø:</b>\n";
	$slistprocgid->execute();
	$gid = -1;
	while ((my $row = $slistprocgid->fetchrow_hashref())) {
		$author = $row->{author};
		if ($gid != $row->{gid}) {
			$gid = $row->{gid};
			print "GID: <a href=\"sshow.pl?action=showgid&gid=$gid\">$gid</a>\n";
			print "Author: $author\n";
			print "Added: ".$row->{added}."\n";
		}
		my $cmd = $row->{cmd};
		print "$cmd\n\n";
	}
	$dbh->commit();
	print "</pre>\n";
}

if ($action eq 'showgid') {
	print "<pre>\n";
	$sgetgid->execute($cgi->param('gid'));
	my $row = $sgetgid->fetchrow_hashref();
	print "GID: ".$row->{gid}."\n";
	print "Author: ".$row->{author}."\n";
	do {
		print "    <b>Name: ".$row->{sysname}." Addr: ".$row->{addr}."</b>\n";
		print "    `<b>".$row->{cmd}."`</b>\n";
		print "    <i>Added: ".$row->{added}." executed ".$row->{updated}."</i>\n";
		my $data = $row->{result};
		if (!defined($data)) {
			$data = "Not executed yet!";
		}
		my @lines = split(/[\n\r]+/, $data);
		foreach my $line (@lines) {
			print "\t", encode_entities($line), "\n";
		}
	} while (($row = $sgetgid->fetchrow_hashref()));
	print "</pre>\n";
}

if ($action eq 'done') {
	print "<h3>Done</h3>\n";
	print "<pre>\n";

	my $squery;
	if (defined($cgi->param('gid'))) {
		my $gid = $cgi->param('gid');
		$sgetdonegid->execute($gid);
		$squery = $sgetdonegid;
	} else {
		$sgetdone->execute($limit);
		$squery = $sgetdone;
	}
	my $sysname = '';
	while (my $row = $squery->fetchrow_hashref()) {
		if ($sysname ne $row->{'sysname'}) {
			$sysname = $row->{'sysname'};
			print "$sysname (".$row->{addr}."):\n";
		}
		print "   Author: ".$row->{author}."\n";
		print "   Cmd: ".$row->{cmd}."\n";
		print "   Added: ".$row->{added}." Updated: ".$row->{updated}."\n";
		print "   GID: ".$row->{gid}."\n";
		my @result = split(/[\n\r]+/, $row->{result});
		foreach (@result) {
			print "\t", encode_entities($_), "\n";
		}
		print "\n";
	}
	$dbh->commit();
	print "</pre>\n";
}
elsif ($action eq 'processing') {
	print "<h3>Processing</h3>\n";
	print "<pre>\n";
	$sgetprocessing->execute();
	while (my $row = $sgetprocessing->fetchrow_hashref()) {
		my $sysname = $row->{'sysname'};
		print "$sysname (".$row->{addr}."):\n";
		print "   Author: ".$row->{author}."\n";
		print "   Cmd: ".$row->{cmd}."\n";
		my $updated;
		if (defined($row->{updated})) { $updated = $row->{updated}; }
		else { $updated = 'never'; }
		print "   Added: ".$row->{added}." Updated: ".$updated."\n";
		print "   Disabled: ".$row->{disabled}."\n";
		print "   Locked: ".$row->{locked}."\n";
		print "   gID: ".$row->{gid};
		print "   <form action=\"sshow.pl\" methos=\"POST\">";
		print "<input type=\"hidden\" name=\"gid\" value=\"".$row->{gid}."\">";
		print "<input type=\"hidden\" name=\"action\" value=\"processing\">";
		if ($row->{disabled} == 0) {
			print "<input type=\"submit\" name=\"agid\" value=\"Disable\">\n";
		}
		else {
			print "<input type=\"submit\" name=\"agid\" value=\"Enable\">\n";
		}
	}
	$dbh->commit();
	print "</pre>\n";
}

print << "EOF";
  </body>
</html>
EOF
an class="p">> </tr> <tr> <td>k</td> <td>Step 5 minutes forward in time</td> </tr> <tr> <td>l</td> <td>Step 1 hour forward in time</td> </tr> <tr> <td>p</td> <td>Toggle playback (1 hour per second)</td> </tr> <tr> <td>r</td> <td>Return to real time</td> </tr> </table> </div> </div> <div id="nowPickerBox" style="position: absolute; display: none; z-index: 130;" class="col-sm-6 col-md-5"> <div class="panel panel-default"> <div class="panel-heading"> <h3 class="panel-title">Time travel <button type="button" class="close" aria-labe="Close" onclick="document.getElementById('nowPickerBox').style.display = 'none';" style="float: right;"> <span aria-hidden="true">&times;</span> </button> </h3> </div> <div class="panel-body row"> <div class="col-sm-12"> <div class="form-group"> <input type="text" class="form-control" placeholder="YYYY-MM-DDThh:mm:ss" id="nowPicker"> <div class="button-group"> <button class="btn btn-primary" onclick="nms.playback.setNow(document.getElementById('nowPicker').dataset.iso);hideLayer('nowPickerBox');">Travel</button> <button class="btn btn-danger" onclick="startNowPicker(Date.now());nms.playback.setNow(false);nms.playback.play();">Back to reality</button> <button class="btn btn-info" data-toggle="button" onclick="toggleLayer('nowPickerInfo');">Info</button> </div> </div> </div> <div id="nowPickerInfo" class="col-sm-12" style="display:none;"> <p>Some features do not have time travel support (comment spotting and DHCP map at the moment). We also lack compatible SNMP data for the first day or so, so you'll only have ping data for the first day of TG15.</p> <p>It could take some time to load a specific point in time for the first time. See "About performance" under the help menu for more information.</p> <p>You can also step backwards and forwards in time, stop and start replay and go back to real time using keyboard shortcuts. See the help menu for an overview of keyboard shortcuts.</p> </div> </div> </div> </div> <div id="info-box-container" class="col-md-5 hidden" style="position: absolute; z-index: 120;"> </div> </div> <h1 id="map-mode-title" class="map-mode-title"></h1> <div class="map-mode-legend form-group"> <button class="btn btn-default btn-sm" id="legend-1"></button> <button class="btn btn-default btn-sm" id="legend-2"></button> <button class="btn btn-default btn-sm" id="legend-3"></button> <button class="btn btn-default btn-sm" id="legend-4"></button> <button class="btn btn-default btn-sm" id="legend-5"></button> </div> <canvas id="bgCanvas" width="1920" height="1032" style="position: absolute; z-index: 1;"> </canvas> <canvas id="linkCanvas" width="1920" height="1032" style="position: absolute; z-index: 10; display: none;"> </canvas> <canvas id="blurCanvas" width="1920" height="1032" style="position: absolute; z-index: 20;"> </canvas> <canvas id="switchCanvas" width="1920" height="1032" style="position: absolute; z-index: 30;"> </canvas> <canvas id="textCanvas" width="1920" height="1032" style="position: absolute; z-index: 40;"> </canvas> <canvas id="textInfoCanvas" width="1920" height="1032" style="position: absolute; z-index: 45;"> </canvas> <canvas id="topCanvas" width="1920" height="1032" style="position: absolute; z-index: 50;"> </canvas> <canvas id="inputCanvas" width="1920" height="1032" style="position: absolute; z-index: 60; cursor: pointer;" onmousedown="nmsMap.canvasClick(event)"> </canvas> <canvas id="hiddenCanvas" width="1000" height="10" style="display: none; position: absolute; z-index: 1000 "></canvas> <div class="logbook gondul-is-private" style="position: absolute; right: 10px; width: 20%; z-index: 70; float: right;"> <div id="oplog-parent-mini" class="logbook" style="border-color: transparent;"> <table id="oplog-table-mini" class="table table-condensed"> </table> </div> </div> <div style="display:none;"><img id="source" src="img/tg16-salkart-clean-big.png" ></div> </div> </div><!--/.fluid-container--> <script src="js/jquery.min.js" type="text/javascript"></script> <script src="js/bootstrap.min.js" type="text/javascript"></script> <script type="text/javascript" src="js/nms-data.js"></script> <script type="text/javascript" src="js/nms-map.js"></script> <script type="text/javascript" src="js/nms-info-box.js"></script> <script type="text/javascript" src="js/nms.js"></script> <script type="text/javascript" src="js/nms-color-util.js"></script> <script type="text/javascript" src="js/nms-map-handlers.js"></script> <script type="text/javascript" src="js/nms-ui.js"></script> <script type="text/javascript" src="js/nms-admin-pane.js"></script> <script type="text/javascript" src="js/nms-oplog.js"></script> <script type="text/javascript" src="js/nms-search.js"></script> <script src="js/jquery.datetimepicker.full.js" type="text/javascript"></script> <script type="text/javascript"> initNMS(); </script> </body> </html>