6 my $password = 'removed';
8 # Seconds to wait for connection
18 # Grab from .htaccess-authentication
19 my $user = $ENV{'REMOTE_USER'};
21 my $dbh = DBI->connect("dbi:Pg:dbname=snmpfetch;host=violet.tg05.gathering.org",
22 "snmpfetch", "removed")
23 or die "Couldn't connect to database";
24 $dbh->{AutoCommit} = 0;
26 my $sgetdone = $dbh->prepare(
30 ORDER BY updated DESC, sysname
32 or die "Could not prepare sgetdone";
34 my $sgetdonegid = $dbh->prepare(
37 WHERE processed = 't' AND gid = ?::text::int
38 ORDER BY updated DESC, sysname")
39 or die "Could not prepare sgetdonegid";
41 my $slistdonegid = $dbh->prepare(
42 "SELECT DISTINCT gid, cmd, author, added
46 or die "Could not prepare slistdonegid";
48 my $slistprocgid = $dbh->prepare(
49 "SELECT DISTINCT gid, cmd, author, added
53 or die "Could not prepare slistdonegid";
55 my $sgetgid = $dbh->prepare(
59 or die "Could not prepare sgetgid";
61 my $sgetprocessing = $dbh->prepare(
65 ORDER BY updated DESC, gid, sysname")
66 or die "Could not prepare sgetdone";
68 my $sgetnoconnect = $dbh->prepare(
71 WHERE result = 'Could not connect to switch, delaying...'")
72 or die "Could not prepare sgetnoconnect";
74 my $sdisablegid = $dbh->prepare("
75 UPDATE squeue SET disabled = 't'
76 WHERE gid = ?::text::int")
77 or die "Could not prepare sdisablegid";
78 my $senablegid = $dbh->prepare("
79 UPDATE squeue SET disabled = 'f'
80 WHERE gid = ?::text::int")
81 or die "Could not prepare sdisablegid";
86 print $cgi->header(-type=>'text/html');
91 <title>Switch managment</title>
94 <p>Du er logget inn som: $user</p>
95 <form method="POST" action="sshow.pl">
97 Vis <input type="text" name="count" size="4" value="10" /> siste<br />
98 Vis: <select name="action" />
99 <option value="listgid">Grupper</option>
100 <option value="done">Ferdige</option>
101 <option value="processing">I kø</option>
103 <input type="submit" value="Vis" /><br />
109 my $limit = $cgi->param('count');
110 if (!defined($limit)) {
113 my $action = $cgi->param('action');
114 if (!defined($action)) {
118 if (defined($cgi->param('agid'))) {
119 my $gid = $cgi->param('gid');
120 if (!defined($gid)) {
121 print "<font color=\"red\">Du har ikke valgt en gid å slette.</font>\n";
123 if ($cgi->param('agid') eq 'Disable') {
124 $sdisablegid->execute($gid);
125 print "<p>gid: ".$cgi->param('gid')." har blitt disablet.\n";
128 $senablegid->execute($gid);
129 print "<p>gid: ".$cgi->param('gid')." har blitt enablet.\n";
134 if ($action eq 'noconnect') {
135 print "<h3>Kunne ikke koble til disse switchene:</h3>\n";
136 $sgetnoconnect->execute();
138 while ((my $row = $sgetnoconnect->fetchrow_hashref())) {
139 print "$row->{'sysname'} : $row->{'cmd'} : Added: $row->{'added'} : Updated: $row->{'updated'}\n";
144 if ($action eq 'listgid') {
146 print "<a href=\"sshow.pl?action=noconnect\" />Kunne ikke koble til</a>\n\n\n";
147 print "<b>Ferdige:</b>\n";
148 $slistdonegid->execute();
151 while ((my $row = $slistdonegid->fetchrow_hashref())) {
152 $author = $row->{author};
153 if ($gid != $row->{gid}) {
155 print "GID: <a href=\"sshow.pl?action=showgid&gid=$gid\">$gid</a>\n";
156 print "Author: $author\n";
157 print "Added: ".$row->{added}."\n";
159 my $cmd = $row->{cmd};
163 print "<b>I kø:</b>\n";
164 $slistprocgid->execute();
166 while ((my $row = $slistprocgid->fetchrow_hashref())) {
167 $author = $row->{author};
168 if ($gid != $row->{gid}) {
170 print "GID: <a href=\"sshow.pl?action=showgid&gid=$gid\">$gid</a>\n";
171 print "Author: $author\n";
172 print "Added: ".$row->{added}."\n";
174 my $cmd = $row->{cmd};
181 if ($action eq 'showgid') {
183 $sgetgid->execute($cgi->param('gid'));
184 my $row = $sgetgid->fetchrow_hashref();
185 print "GID: ".$row->{gid}."\n";
186 print "Author: ".$row->{author}."\n";
188 print " <b>Name: ".$row->{sysname}." Addr: ".$row->{addr}."</b>\n";
189 print " `<b>".$row->{cmd}."`</b>\n";
190 print " <i>Added: ".$row->{added}." executed ".$row->{updated}."</i>\n";
191 my $data = $row->{result};
192 if (!defined($data)) {
193 $data = "Not executed yet!";
195 my @lines = split(/[\n\r]+/, $data);
196 foreach my $line (@lines) {
199 } while (($row = $sgetgid->fetchrow_hashref()));
203 if ($action eq 'done') {
204 print "<h3>Done</h3>\n";
208 if (defined($cgi->param('gid'))) {
209 my $gid = $cgi->param('gid');
210 $sgetdonegid->execute($gid);
211 $squery = $sgetdonegid;
214 $sgetdone->execute($limit);
218 while (my $row = $squery->fetchrow_hashref()) {
219 if ($sysname ne $row->{'sysname'}) {
220 $sysname = $row->{'sysname'};
221 print "$sysname (".$row->{addr}."):\n";
223 print " Author: ".$row->{author}."\n";
224 print " Cmd: ".$row->{cmd}."\n";
225 print " Added: ".$row->{added}." Updated: ".$row->{updated}."\n";
226 print " gID: ".$row->{gid}."\n";
227 my @result = split(/[\n\r]+/, $row->{result});
236 elsif ($action eq 'processing') {
237 print "<h3>Processing</h3>\n";
239 $sgetprocessing->execute();
240 while (my $row = $sgetprocessing->fetchrow_hashref()) {
241 my $sysname = $row->{'sysname'};
242 print "$sysname (".$row->{addr}."):\n";
243 print " Author: ".$row->{author}."\n";
244 print " Cmd: ".$row->{cmd}."\n";
246 if (defined($row->{updated})) { $updated = $row->{updated}; }
247 else { $updated = 'never'; }
248 print " Added: ".$row->{added}." Updated: ".$updated."\n";
249 print " Disabled: ".$row->{disabled}."\n";
250 print " Locked: ".$row->{locked}."\n";
251 print " gID: ".$row->{gid};
252 print " <form action=\"sshow.pl\" methos=\"POST\">";
253 print "<input type=\"hidden\" name=\"gid\" value=\"".$row->{gid}."\">";
254 print "<input type=\"hidden\" name=\"action\" value=\"processing\">";
255 if ($row->{disabled} == 0) {
256 print "<input type=\"submit\" name=\"agid\" value=\"Disable\">\n";
259 print "<input type=\"submit\" name=\"agid\" value=\"Enable\">\n";