11 # Grab from .htaccess-authentication
12 my $user = $ENV{'REMOTE_USER'};
14 my $dbh = nms::db_connect();
15 $dbh->{AutoCommit} = 0;
17 my $sgetdone = $dbh->prepare(
21 ORDER BY updated DESC, sysname
23 or die "Could not prepare sgetdone";
25 my $sgetdonegid = $dbh->prepare(
28 WHERE processed = 't' AND gid = ?::text::int
29 ORDER BY updated DESC, sysname")
30 or die "Could not prepare sgetdonegid";
32 my $slistdonegid = $dbh->prepare(
33 "SELECT DISTINCT gid, cmd, author, added
37 or die "Could not prepare slistdonegid";
39 my $slistprocgid = $dbh->prepare(
40 "SELECT DISTINCT gid, cmd, author, added
44 or die "Could not prepare slistdonegid";
46 my $sgetgid = $dbh->prepare(
50 or die "Could not prepare sgetgid";
52 my $sgetprocessing = $dbh->prepare(
56 ORDER BY updated DESC, gid, sysname")
57 or die "Could not prepare sgetdone";
59 my $sgetnoconnect = $dbh->prepare(
62 WHERE result = 'Could not connect to switch, delaying...'")
63 or die "Could not prepare sgetnoconnect";
65 my $sdisablegid = $dbh->prepare("
66 UPDATE squeue SET disabled = 't'
67 WHERE gid = ?::text::int")
68 or die "Could not prepare sdisablegid";
69 my $senablegid = $dbh->prepare("
70 UPDATE squeue SET disabled = 'f'
71 WHERE gid = ?::text::int")
72 or die "Could not prepare sdisablegid";
77 print $cgi->header(-type=>'text/html');
82 <title>Switch managment</title>
85 <p>Du er logget inn som: $user</p>
86 <form method="POST" action="sshow.pl">
88 Vis <input type="text" name="count" size="4" value="10" /> siste<br />
89 Vis: <select name="action" />
90 <option value="listgid">Grupper</option>
91 <option value="done">Ferdige</option>
92 <option value="processing">I kø</option>
94 <input type="submit" value="Vis" /><br />
100 my $limit = $cgi->param('count');
101 if (!defined($limit)) {
104 my $action = $cgi->param('action');
105 if (!defined($action)) {
109 if (defined($cgi->param('agid'))) {
110 my $gid = $cgi->param('gid');
111 if (!defined($gid)) {
112 print "<font color=\"red\">Du har ikke valgt en gid å slette.</font>\n";
114 if ($cgi->param('agid') eq 'Disable') {
115 $sdisablegid->execute($gid);
116 print "<p>gid: ".$cgi->param('gid')." har blitt disablet.\n";
119 $senablegid->execute($gid);
120 print "<p>gid: ".$cgi->param('gid')." har blitt enablet.\n";
125 if ($action eq 'noconnect') {
126 print "<h3>Kunne ikke koble til disse switchene:</h3>\n";
127 $sgetnoconnect->execute();
129 while ((my $row = $sgetnoconnect->fetchrow_hashref())) {
130 print "$row->{'sysname'} : $row->{'cmd'} : Added: $row->{'added'} : Updated: $row->{'updated'}\n";
135 if ($action eq 'listgid') {
137 print "<a href=\"sshow.pl?action=noconnect\" />Kunne ikke koble til</a>\n\n\n";
138 print "<b>Ferdige:</b>\n";
139 $slistdonegid->execute();
142 while ((my $row = $slistdonegid->fetchrow_hashref())) {
143 $author = $row->{author};
144 if ($gid != $row->{gid}) {
146 print "GID: <a href=\"sshow.pl?action=showgid&gid=$gid\">$gid</a>\n";
147 print "Author: $author\n";
148 print "Added: ".$row->{added}."\n";
150 my $cmd = $row->{cmd};
154 print "<b>I kø:</b>\n";
155 $slistprocgid->execute();
157 while ((my $row = $slistprocgid->fetchrow_hashref())) {
158 $author = $row->{author};
159 if ($gid != $row->{gid}) {
161 print "GID: <a href=\"sshow.pl?action=showgid&gid=$gid\">$gid</a>\n";
162 print "Author: $author\n";
163 print "Added: ".$row->{added}."\n";
165 my $cmd = $row->{cmd};
172 if ($action eq 'showgid') {
174 $sgetgid->execute($cgi->param('gid'));
175 my $row = $sgetgid->fetchrow_hashref();
176 print "GID: ".$row->{gid}."\n";
177 print "Author: ".$row->{author}."\n";
179 print " <b>Name: ".$row->{sysname}." Addr: ".$row->{addr}."</b>\n";
180 print " `<b>".$row->{cmd}."`</b>\n";
181 print " <i>Added: ".$row->{added}." executed ".$row->{updated}."</i>\n";
182 my $data = $row->{result};
183 if (!defined($data)) {
184 $data = "Not executed yet!";
186 my @lines = split(/[\n\r]+/, $data);
187 foreach my $line (@lines) {
190 } while (($row = $sgetgid->fetchrow_hashref()));
194 if ($action eq 'done') {
195 print "<h3>Done</h3>\n";
199 if (defined($cgi->param('gid'))) {
200 my $gid = $cgi->param('gid');
201 $sgetdonegid->execute($gid);
202 $squery = $sgetdonegid;
205 $sgetdone->execute($limit);
209 while (my $row = $squery->fetchrow_hashref()) {
210 if ($sysname ne $row->{'sysname'}) {
211 $sysname = $row->{'sysname'};
212 print "$sysname (".$row->{addr}."):\n";
214 print " Author: ".$row->{author}."\n";
215 print " Cmd: ".$row->{cmd}."\n";
216 print " Added: ".$row->{added}." Updated: ".$row->{updated}."\n";
217 print " gID: ".$row->{gid}."\n";
218 my @result = split(/[\n\r]+/, $row->{result});
227 elsif ($action eq 'processing') {
228 print "<h3>Processing</h3>\n";
230 $sgetprocessing->execute();
231 while (my $row = $sgetprocessing->fetchrow_hashref()) {
232 my $sysname = $row->{'sysname'};
233 print "$sysname (".$row->{addr}."):\n";
234 print " Author: ".$row->{author}."\n";
235 print " Cmd: ".$row->{cmd}."\n";
237 if (defined($row->{updated})) { $updated = $row->{updated}; }
238 else { $updated = 'never'; }
239 print " Added: ".$row->{added}." Updated: ".$updated."\n";
240 print " Disabled: ".$row->{disabled}."\n";
241 print " Locked: ".$row->{locked}."\n";
242 print " gID: ".$row->{gid};
243 print " <form action=\"sshow.pl\" methos=\"POST\">";
244 print "<input type=\"hidden\" name=\"gid\" value=\"".$row->{gid}."\">";
245 print "<input type=\"hidden\" name=\"action\" value=\"processing\">";
246 if ($row->{disabled} == 0) {
247 print "<input type=\"submit\" name=\"agid\" value=\"Disable\">\n";
250 print "<input type=\"submit\" name=\"agid\" value=\"Enable\">\n";