#!/usr/bin/env perl
use strict;
use warnings;
my $jobs_dir = "/var/www/jobs";
use OpenBSD::Pledge;
use OpenBSD::Unveil;
pledge( qw(unveil rpath dns inet) ) || die "Unable to pledge: $!";
unveil( $jobs_dir, "r" ) || die "Unable to unveil: $!";
unveil() || die "Unable to lock unveil: $!";
use local::lib '/var/www/perl5';
use Net::Printer;
use URI::Query;
print "content-type:text/html; charset=utf-8\n\n";
print "\n";
print "
\n";
print "totoro!\n";
# print "";
print "\n";
print "\n";
my $lp = new Net::Printer();
# generate hash from query string
my $q = URI::Query->new( $ENV{'QUERY_STRING'} );
my %hash = $q->hash;
if($hash{'file'}) {
my $file = "$jobs_dir/$hash{'file'}";
if(-e $file) {
for (my $i=0; $i <= $hash{'qty'}; $i++) {
my $result = $lp->printfile("$file");
print "$result
\n";
# TODO: handle errors in finding file and printing
#$errstr = $printer->printerror();
}
}
}
# display print queue
# TODO: check if "lp@localhost: JetDirect lpd: no jobs queued on the port Auto"
print "print queue
\n";
# TODO: format as table with buttons (cancel)
my @queue = $lp->queuestatus();
print join("
", @queue);
# display jobs available to print
opendir(my $dh, "$jobs_dir") || die "Can't opendir $jobs_dir: $!";
my @files = grep { /^[^\.]/ && -f "$jobs_dir/$_" } readdir($dh);
closedir $dh;
print "jobs
\n";
foreach my $file (@files) {
my $job = $file;
$job =~ s/^(.*)\.[^\.]*$/$1/;
$job =~ s/-bk-[24]x$//;
print "\n";
}
print "\n";
print "\n";
1;