display last printer status
[Printer-Zebra.git] / status.cgi
1 #!/usr/bin/perl
2 use warnings;
3 use strict;
4
5 use CGI::Carp qw(fatalsToBrowser);
6 use autodie;
7 use POSIX qw(strftime);
8
9 print "Content-type: text/html\r\n\r\n";
10
11 print qq{
12 <html>
13 <head>
14 <title>Zebra printers status</title>
15 </head>
16 <body>
17
18 };
19
20 foreach my $filename ( glob '/tmp/zebra/*.status' ) {
21         my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
22         $atime,$mtime,$ctime,$blksize,$blocks)
23                 = stat($filename);
24
25         my $date = strftime "%Y-%m-%d %H:%M:%S", localtime($mtime);
26
27
28
29         local $/ = undef;
30         open(my $fh, $filename);
31         my $status = <$fh>;
32         close $fh;
33
34         my $style = '';
35         $style=' style="color:#c00"' if $status =~ m/error/;
36
37         print "<h1$style>$filename $date</h1>\n\n";
38         print "<pre$style>$status</pre>\n\n";
39 }
40
41 print qq{
42 </body>
43 </html>
44 };