5 # Seconds to wait for connection
15 # Grab from .htaccess-authentication
16 my $user = $ENV{'REMOTE_USER'};
18 my $dbh = nms::db_connect();
19 $dbh->{AutoCommit} = 0;
21 my $sgetdone = $dbh->prepare(
25 ORDER BY updated DESC, sysname
27 or die "Could not prepare sgetdone";
29 my $sgetdonegid = $dbh->prepare(
32 WHERE processed = 't' AND gid = ?::text::int
33 ORDER BY updated DESC, sysname")
34 or die "Could not prepare sgetdonegid";
36 my $slistdonegid = $dbh->prepare(
37 "SELECT DISTINCT gid, cmd, author, added
41 or die "Could not prepare slistdonegid";
43 my $slistprocgid = $dbh->prepare(
44 "SELECT DISTINCT gid, cmd, author, added
48 or die "Could not prepare slistdonegid";
50 my $sgetgid = $dbh->prepare(
54 or die "Could not prepare sgetgid";
56 my $sgetprocessing = $dbh->prepare(
60 ORDER BY updated DESC, gid, sysname")
61 or die "Could not prepare sgetdone";
63 my $sgetnoconnect = $dbh->prepare(
66 WHERE result = 'Could not connect to switch, delaying...'")
67 or die "Could not prepare sgetnoconnect";
69 my $sdisablegid = $dbh->prepare("
70 UPDATE squeue SET disabled = 't'
71 WHERE gid = ?::text::int")
72 or die "Could not prepare sdisablegid";
73 my $senablegid = $dbh->prepare("
74 UPDATE squeue SET disabled = 'f'
75 WHERE gid = ?::text::int")
76 or die "Could not prepare sdisablegid";
81 print $cgi->header(-type=>'text/html');
86 <title>Switch managment</title>
89 <p>Du er logget inn som: $user</p>
90 <form method="POST" action="sshow.pl">
92 Vis <input type="text" name="count" size="4" value="10" /> siste<br />
93 Vis: <select name="action" />
94 <option value="listgid">Grupper</option>
95 <option value="done">Ferdige</option>
96 <option value="processing">I kø</option>
98 <input type="submit" value="Vis" /><br />
104 my $limit = $cgi->param('count');
105 if (!defined($limit)) {
108 my $action = $cgi->param('action');
109 if (!defined($action)) {
113 if (defined($cgi->param('agid'))) {
114 my $gid = $cgi->param('gid');
115 if (!defined($gid)) {
116 print "<font color=\"red\">Du har ikke valgt en gid å slette.</font>\n";
118 if ($cgi->param('agid') eq 'Disable') {
119 $sdisablegid->execute($gid);
120 print "<p>gid: ".$cgi->param('gid')." har blitt disablet.\n";
123 $senablegid->execute($gid);
124 print "<p>gid: ".$cgi->param('gid')." har blitt enablet.\n";
129 if ($action eq 'noconnect') {
130 print "<h3>Kunne ikke koble til disse switchene:</h3>\n";
131 $sgetnoconnect->execute();
133 while ((my $row = $sgetnoconnect->fetchrow_hashref())) {
134 print "$row->{'sysname'} : $row->{'cmd'} : Added: $row->{'added'} : Updated: $row->{'updated'}\n";
139 if ($action eq 'listgid') {
141 print "<a href=\"sshow.pl?action=noconnect\" />Kunne ikke koble til</a>\n\n\n";
142 print "<b>Ferdige:</b>\n";
143 $slistdonegid->execute();
146 while ((my $row = $slistdonegid->fetchrow_hashref())) {
147 $author = $row->{author};
148 if ($gid != $row->{gid}) {
150 print "GID: <a href=\"sshow.pl?action=showgid&gid=$gid\">$gid</a>\n";
151 print "Author: $author\n";
152 print "Added: ".$row->{added}."\n";
154 my $cmd = $row->{cmd};
158 print "<b>I kø:</b>\n";
159 $slistprocgid->execute();
161 while ((my $row = $slistprocgid->fetchrow_hashref())) {
162 $author = $row->{author};
163 if ($gid != $row->{gid}) {
165 print "GID: <a href=\"sshow.pl?action=showgid&gid=$gid\">$gid</a>\n";
166 print "Author: $author\n";
167 print "Added: ".$row->{added}."\n";
169 my $cmd = $row->{cmd};
176 if ($action eq 'showgid') {
178 $sgetgid->execute($cgi->param('gid'));
179 my $row = $sgetgid->fetchrow_hashref();
180 print "GID: ".$row->{gid}."\n";
181 print "Author: ".$row->{author}."\n";
183 print " <b>Name: ".$row->{sysname}." Addr: ".$row->{addr}."</b>\n";
184 print " `<b>".$row->{cmd}."`</b>\n";
185 print " <i>Added: ".$row->{added}." executed ".$row->{updated}."</i>\n";
186 my $data = $row->{result};
187 if (!defined($data)) {
188 $data = "Not executed yet!";
190 my @lines = split(/[\n\r]+/, $data);
191 foreach my $line (@lines) {
194 } while (($row = $sgetgid->fetchrow_hashref()));
198 if ($action eq 'done') {
199 print "<h3>Done</h3>\n";
203 if (defined($cgi->param('gid'))) {
204 my $gid = $cgi->param('gid');
205 $sgetdonegid->execute($gid);
206 $squery = $sgetdonegid;
209 $sgetdone->execute($limit);
213 while (my $row = $squery->fetchrow_hashref()) {
214 if ($sysname ne $row->{'sysname'}) {
215 $sysname = $row->{'sysname'};
216 print "$sysname (".$row->{addr}."):\n";
218 print " Author: ".$row->{author}."\n";
219 print " Cmd: ".$row->{cmd}."\n";
220 print " Added: ".$row->{added}." Updated: ".$row->{updated}."\n";
221 print " gID: ".$row->{gid}."\n";
222 my @result = split(/[\n\r]+/, $row->{result});
231 elsif ($action eq 'processing') {
232 print "<h3>Processing</h3>\n";
234 $sgetprocessing->execute();
235 while (my $row = $sgetprocessing->fetchrow_hashref()) {
236 my $sysname = $row->{'sysname'};
237 print "$sysname (".$row->{addr}."):\n";
238 print " Author: ".$row->{author}."\n";
239 print " Cmd: ".$row->{cmd}."\n";
241 if (defined($row->{updated})) { $updated = $row->{updated}; }
242 else { $updated = 'never'; }
243 print " Added: ".$row->{added}." Updated: ".$updated."\n";
244 print " Disabled: ".$row->{disabled}."\n";
245 print " Locked: ".$row->{locked}."\n";
246 print " gID: ".$row->{gid};
247 print " <form action=\"sshow.pl\" methos=\"POST\">";
248 print "<input type=\"hidden\" name=\"gid\" value=\"".$row->{gid}."\">";
249 print "<input type=\"hidden\" name=\"action\" value=\"processing\">";
250 if ($row->{disabled} == 0) {
251 print "<input type=\"submit\" name=\"agid\" value=\"Disable\">\n";
254 print "<input type=\"submit\" name=\"agid\" value=\"Enable\">\n";