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; charset=utf-8');
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";
113 print "<p>gid: ".$cgi->param('gid')." har blitt disablet.\n";
116 $senablegid->execute($gid);
117 print "<p>gid: ".$cgi->param('gid')." har blitt enablet.\n";
122 if ($action eq 'noconnect') {
123 print "<h3>Kunne ikke koble til disse switchene:</h3>\n";
124 $sgetnoconnect->execute();
126 while ((my $row = $sgetnoconnect->fetchrow_hashref())) {
127 print "$row->{'sysname'} : $row->{'cmd'} : Added: $row->{'added'} : Updated: $row->{'updated'}\n";
132 if ($action eq 'listgid') {
134 print "<a href=\"sshow.pl?action=noconnect\" />Kunne ikke koble til</a>\n\n\n";
135 print "<b>Ferdige:</b>\n";
136 $slistdonegid->execute();
139 while ((my $row = $slistdonegid->fetchrow_hashref())) {
140 $author = $row->{author};
141 if ($gid != $row->{gid}) {
143 print "GID: <a href=\"sshow.pl?action=showgid&gid=$gid\">$gid</a>\n";
144 print "Author: $author\n";
145 print "Added: ".$row->{added}."\n";
147 my $cmd = $row->{cmd};
151 print "<b>I kø:</b>\n";
152 $slistprocgid->execute();
154 while ((my $row = $slistprocgid->fetchrow_hashref())) {
155 $author = $row->{author};
156 if ($gid != $row->{gid}) {
158 print "GID: <a href=\"sshow.pl?action=showgid&gid=$gid\">$gid</a>\n";
159 print "Author: $author\n";
160 print "Added: ".$row->{added}."\n";
162 my $cmd = $row->{cmd};
169 if ($action eq 'showgid') {
171 $sgetgid->execute($cgi->param('gid'));
172 my $row = $sgetgid->fetchrow_hashref();
173 print "GID: ".$row->{gid}."\n";
174 print "Author: ".$row->{author}."\n";
176 print " <b>Name: ".$row->{sysname}." Addr: ".$row->{addr}."</b>\n";
177 print " `<b>".$row->{cmd}."`</b>\n";
178 print " <i>Added: ".$row->{added}." executed ".$row->{updated}."</i>\n";
179 my $data = $row->{result};
180 if (!defined($data)) {
181 $data = "Not executed yet!";
183 my @lines = split(/[\n\r]+/, $data);
184 foreach my $line (@lines) {
187 } while (($row = $sgetgid->fetchrow_hashref()));
191 if ($action eq 'done') {
192 print "<h3>Done</h3>\n";
196 if (defined($cgi->param('gid'))) {
197 my $gid = $cgi->param('gid');
198 $sgetdonegid->execute($gid);
199 $squery = $sgetdonegid;
202 $sgetdone->execute($limit);
206 while (my $row = $squery->fetchrow_hashref()) {
207 if ($sysname ne $row->{'sysname'}) {
208 $sysname = $row->{'sysname'};
209 print "$sysname (".$row->{addr}."):\n";
211 print " Author: ".$row->{author}."\n";
212 print " Cmd: ".$row->{cmd}."\n";
213 print " Added: ".$row->{added}." Updated: ".$row->{updated}."\n";
214 print " gID: ".$row->{gid}."\n";
215 my @result = split(/[\n\r]+/, $row->{result});
224 elsif ($action eq 'processing') {
225 print "<h3>Processing</h3>\n";
227 $sgetprocessing->execute();
228 while (my $row = $sgetprocessing->fetchrow_hashref()) {
229 my $sysname = $row->{'sysname'};
230 print "$sysname (".$row->{addr}."):\n";
231 print " Author: ".$row->{author}."\n";
232 print " Cmd: ".$row->{cmd}."\n";
234 if (defined($row->{updated})) { $updated = $row->{updated}; }
235 else { $updated = 'never'; }
236 print " Added: ".$row->{added}." Updated: ".$updated."\n";
237 print " Disabled: ".$row->{disabled}."\n";
238 print " Locked: ".$row->{locked}."\n";
239 print " gID: ".$row->{gid};
240 print " <form action=\"sshow.pl\" methos=\"POST\">";
241 print "<input type=\"hidden\" name=\"gid\" value=\"".$row->{gid}."\">";
242 print "<input type=\"hidden\" name=\"action\" value=\"processing\">";
243 if ($row->{disabled} == 0) {
244 print "<input type=\"submit\" name=\"agid\" value=\"Disable\">\n";
247 print "<input type=\"submit\" name=\"agid\" value=\"Enable\">\n";