#!/usr/bin/perl
#^^^^^^^^^^^^^^^^^^^^ Update pathname appropriately to where you have Perl installed
# And update the path below of the configuration file as appropriate.
$lpinfo_ph = "/usr/local/lprng/info/lpinfo.ph";
#-------------- Should be fairly boilerplate from here on out --------------
# lpinfo_lprm - a Perl script to allow httpd to lprm selected jobs
# Copyright 1997, 1998, 1999, 2000 by Alek Komarnitsky,
# Use and distribution of this software is covered by the GNU GPL license.
# Please see the LICENSE file and http://www.gnu.org/
# Note: this will only work if the print server is running LPRng ...
$debug = 0;
require 5.002;
use Socket;
&ReadParse;
print "Content-type: text/html\n\n\n" ;
print $meta_tags if ( defined($meta_tags));
#Grab stuff from lpinfo.ph ...
if ( -r "$lpinfo_ph" ) {
require "$lpinfo_ph";
} else {
print "could not open $lpinfo_ph - serious error ... \n";
exit(2);
}
$| = 1;
$printer = $in{'printer'};
$jobnumber = $in{'jobnumber'};
if ( defined($in{'printserver'})) {
$printserver = $in{'printserver'};
} else {
$printserver = "unix";
}
$queue_is_nt = $in{'queue_is_nt'} if ( defined($in{'queue_is_nt'})) ;
$adminmode = 0;
$_ = get_env_variable("^SCRIPT_NAME");
if ( $_ eq $lprmURLadmin ) {
$_ = get_env_variable("^REMOTE_USER");
$adminmode = $_;
}
print "adminmode is $adminmode
" if ($debug);
$browserhost="localhost";
$_ = get_env_variable("^REMOTE_ADDR");
print "We got $_ as the REMOTE ADDR
" if ($debug);
if ( $queue_is_nt) {
$browserhost = $_;
} else {
if ( $_ ne "" ) {
s/^.*=//s;
@iplist = split(/\./,$_);
$ip = pack('C4',@iplist);
$browserhost = gethostbyaddr($ip,AF_INET);
}
}
$browserhost = get_env_variable("^REMOTE_ADDR") if ( $browserhost eq "");
print "We got $browserhost as the browserhost
" if ($debug);
if ( (! defined($in{'printer'}) ) || (! defined($in{'jobnumber'}) )) {
close_er_out ("Did not get everything in that we needed ...
printer was $printer and $jobnumber was $jobnumber and browserhost was $browserhost and adminmode was $adminmode");
exit();
}
print "
printer is $printer and jobnumber is $jobnumber and browserhost is $browserhost and printserver is $printserver and queue_is_nt is $queue_is_nt end
" if ( $debug );
$findjob = &find_job;
if ( $findjob =~ "FAILED" ) {
&close_er_out("$findjob");
}
print "
sending $lprm_suid $adminmode $browserhost $printer $printserver $jobnumber\n" if ($debug);
$lprmout = `$lprm_suid $adminmode $browserhost $printer $printserver $jobnumber`;
print "
from lprm_suid, we got $lprmout
" if ($debug);
if ( $lprmout eq "" ) {
&close_er_out("FAILED: lprm returned nothing, which typically means it failed");
} else {
#Lets see if it really got removed ...
if ($lprmout =~ /Queue Purged/ ) {
$findjob = "Could not find any job";
} else {
$findjob = &find_job;
}
print "
second findjob shows $findjob
" if ($debug);
if ("$findjob" =~ "Could not find any job" ) {
close_er_out("SUCCESS: Print job $jobnumber \@ $jobhost on $printer removed");
} else {
close_er_out("FAILED: lprm of job $jobnumber \@ jobhost on $printer failed from $browserhost");
}
}
print "at the end