initial commit
This commit is contained in:
commit
132432d825
87
README.md
Normal file
87
README.md
Normal file
@ -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.
|
73
print.pl
Executable file
73
print.pl
Executable file
@ -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 "<html>\n";
|
||||||
|
print "<head>\n";
|
||||||
|
print "<title>totoro!</title>\n";
|
||||||
|
# print "<script>if( window.location.href.match(/.*\?.*/) ) window.location = window.location.href.split(\"?\")[0];</script>";
|
||||||
|
print "</head>\n";
|
||||||
|
print "<body>\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 <br>\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 "<h2>print queue</h2>\n";
|
||||||
|
# TODO: format as table with buttons (cancel)
|
||||||
|
my @queue = $lp->queuestatus();
|
||||||
|
print join("<br />", @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 "<h2>jobs</h2>\n";
|
||||||
|
|
||||||
|
foreach my $file (@files) {
|
||||||
|
my $job = $file;
|
||||||
|
$job =~ s/^(.*)\.[^\.]*$/$1/;
|
||||||
|
$job =~ s/-bk-[24]x$//;
|
||||||
|
print "<form action=\"\" method=\"GET\">\n";
|
||||||
|
print "<span style=\"max-width:50%; width:10em;\"><label for=\"$job\">$job</label></span>";
|
||||||
|
print "<input type=\"hidden\" name=\"job\" value=\"$job\">";
|
||||||
|
print "<input type=\"hidden\" name=\"file\" value=\"$file\">";
|
||||||
|
print "<input type=\"number\" name=\"qty\" style=\"width: 4em;\" placeholder=\"qty\">\n";
|
||||||
|
print "<input type=\"submit\" value=\"print\">";
|
||||||
|
print "</form>\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
print "</body>\n";
|
||||||
|
print "</html>\n";
|
||||||
|
|
||||||
|
1;
|
Loading…
Reference in New Issue
Block a user