commit 132432d825d662fd96918f177b92ba7f8b369a9b Author: sceox Date: Tue Dec 22 13:19:01 2020 -0800 initial commit diff --git a/README.md b/README.md new file mode 100644 index 0000000..069ef20 --- /dev/null +++ b/README.md @@ -0,0 +1,87 @@ +# totoro + +A simple web interface to line printer daemon (lpd) printing +on OpenBSD. + +May work on other unixes, or may not. + +## Installation + +These installation instructions assume OpenBSD. + +They also assume you've already set up lpd(8) and configured printcap(5). + +Copy the perl script to the cgi-bin directory: + + doas cp print.pl /var/www/cgi-bin/ + +### Perl + +Install perl packages: + + doas pkg_add p5-Any-URI-Escape p5-YAML p5-Clone + +As of this writing, `Net::Printer` and `URI::Query` are not in openbsd +packages, so we'll install them locally. You may want to check if this has +changed. + +To install them locally, first install `local::lib`: + + doas pkg_add p5-local-lib + +Then tell perl to install modules to `/var/www/perl5`: + + PATH="/var/www/perl5/bin${PATH:+:${PATH}}"; export PATH; + PERL5LIB="/var/www/perl5/lib/perl5${PERL5LIB:+:${PERL5LIB}}"; export PERL5LIB; + PERL_LOCAL_LIB_ROOT="/var/www/perl5${PERL_LOCAL_LIB_ROOT:+:${PERL_LOCAL_LIB_ROOT}}"; export PERL_LOCAL_LIB_ROOT; + PERL_MB_OPT="--install_base \"/var/www/perl5\""; export PERL_MB_OPT; + PERL_MM_OPT="INSTALL_BASE=/var/www/perl5"; export PERL_MM_OPT; + +Then install dependencies: + + perl -MCPAN -e "use local::lib '/var/www/perl5'; install Net::Printer;" + perl -MCPAN -e "use local::lib '/var/www/perl5'; install URI::Query;" + +### Daemons + +Set up httpd and slowcgi: + +NOTE: these instructions set up httpd and slowcgi without chroot. +Probably it can be made to work in a chroot. + +Add to `/etc/httpd.conf`: + + chroot "/" + logdir "/var/www/logs" + + server "totoro" { + listen on * port 80 + + # testing + root "/var/www/htdocs" + + + # cgi + location "/" { + fastcgi socket "/var/www/run/slowcgi.sock" + root "/var/www/cgi-bin/print.pl" + } + location "/" { + root "/var/www/print.pl" + fastcgi socket "/var/www/run/slowcgi.sock" + } + } + +Set daemon flags and start: + + $ doas rcctl set slowcgi flags "-p /" + $ doas rcctl enable httpd slowcgi + $ doas rcctl start httpd slowcgi + +If your printer is not already set up yet, read up on lpd(8) and printcap(5). + +## Usage + +Place any jobs files into `/var/www/jobs`. + +Visit the web interface in a web browser. diff --git a/print.pl b/print.pl new file mode 100755 index 0000000..cd1c0f9 --- /dev/null +++ b/print.pl @@ -0,0 +1,73 @@ +#!/usr/bin/env perl + +use strict; +use warnings; + +use local::lib '/var/www/perl5'; +use Net::Printer; +use URI::Query; + +my $jobs_dir = "/var/www/jobs"; + +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; +#print Dumper( \%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 ""; + print ""; + print ""; + print "\n"; + print ""; + print "
\n"; +} + +print "\n"; +print "\n"; + +1;