#!/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 - a Web/command line "printtool" for LPRng # 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/ # Script to provide misc. info on LPRng from the Web and command line. # Perhaps more bloated than we need ... $version="2.63"; $updatetime = 5 ; # Number of seconds between autoupdates $testpageupdatetime = 3; # Number of seconds betwen auto-update on printing test page $timeout = 35; # Number of seconds for lpq's and other system stuff to timeout $| = 1; # This seems to be needed so system calls don't write "too fast" to STDOUT require 5.002; use Socket; # These are how I color code what is returned from the lpq status # It is used in both the "middle" and "bottom" displays, so I put it here. @orange = ("spooling disabled" , "who knows - NT Q" , "who knows - A-T Q" , "who knows - forward" , "appears busy" , "appears waiting" ); @red = ("WARNING" , "not in printcap","printing disabled","cannot open conn", "Connection refused" , "No Access" ,"unknown printer" , "paper jam" , "P-S does not know" , "No AppleTalk printer status", "queue not enabled" , "bad queue name" , "Stopped - NT Q" , "queue is turned off" , "ink low" , "cannot chdir" , "remove media" , "lpq timed out" , "out of ink" , "(Paused)" ); @green = ("0 jobs", "no printable jobs" , "Ready" , "No Status" ); @blue = ("job" ); # Grab stuff from lpinfo.ph ... if ( -r "$lpinfo_ph" ) { require "$lpinfo_ph"; } else { print "could not open $lpinfo_ph - serious error ... \n"; exit(2); } if ( ! ( ($lpq_all_dir) and ( -r "$lpq_all_dir/current" ) and ( ! -z "$lpq_all_dir/current") ) ) { $lpq_all_dir = 0 ; } # See if we are running in a command line or as a CGI $html = 1 if (length($ENV{GATEWAY_INTERFACE})); $lookup_info = 1 if ( -d $info_dir ); $locations_file = 0 if ( ! -r $locations_file ); # Here we determine if hacks are allowed ... ;-) if (( -r "/etc/resolv.conf" ) && (`cat /etc/resolv.conf` =~ "SITE.com" )) { $site_hacks = 1; } if ( $html ) { print "Content-type: text/html\n\n\n" ; print $meta_tags if (defined($meta_tags)); &ReadParse; # Turn on admin mode as appropriate ... $adminmode = 1; $_ = &get_env_variable("^SCRIPT_NAME"); if ( $_ eq $thisURLadmin ) { $thisURL = $thisURLadmin; $_ = &get_env_variable("^REMOTE_USER"); $adminmode = $_; $adminmode = "nobody" if ($adminmode eq ""); } $counter2 = &Increment_Accumulator($count_file2) if (($count_file2) && (-w $count_file2)); $lpqlevel = -1; $lpqlevel = $in{'lpqlevel'} if (defined($in{'lpqlevel'})); # Generate some JavaScript to fire up new mode of operation ... if (( defined($in{'poweruseron'}) ) || ( defined($in{'normaluseron'})) || ( defined($in{'adminmodeon'})) ) { print ""; exit(); } # Show the middle frame at startup ... if ( defined($in{'show_middle_frame'}) ) { if ( $webservers_subnets_file) { print "Other Web Servers "; ### print "debug"; } $counter0 = &Get_Accumulator($count_file0) if (($count_file0) && (-r $count_file0)); $counter1 = &Increment_Accumulator($count_file1) if (($count_file1) && ( -w $count_file1)); $tempvar = "$counter1-$counter2" if (($counter1) && ($counter2)); $tempvar = "$counter0-$counter1-$counter2" if (( $counter0) && ($counter1) && ($counter2)); $_ = `uname -n`; $tempvar = "($version: $tempvar - $_)"; print "
Questions/suggestions on this web page can be directed to $email_address $tempvar"; exit(); } # show initial page if ( (!defined($in{'location'})) && ( !defined($in{'showqueue'})) && ( !defined($in{'printer'} )) && ( !defined($in{'auto'})) && ( !defined($in{'show_web_servers'})) && ( !defined($in{'getinfo'})) ) { $counter0 = &Increment_Accumulator($count_file0) if (($count_file0) && (-w $count_file0) && ($adminmode)); print "
"; &clear_window("bottom"); # Generate admin table of contents in middle frame } elsif ( defined($in{'adminsetup'})) { print ""; &clear_window("bottom"); # Various lpc commands ... } elsif ( (defined($in{'lpc_restart'})) || (defined($in{'lpc_release'})) || (defined($in{'lpc_enable'})) || (defined($in{'lpc_disable'})) || (defined($in{'lpc_pause'})) || (defined($in{'lpc_resume'})) ) { if ($adminmode ) { $_ = &get_env_variable("^REMOTE_ADDR"); if ( $_ ne "" ) { @iplist = split(/\./,$_); $ip = pack('C4',@iplist); $browserhost = gethostbyaddr($ip,AF_INET); } $browserhost = &get_env_variable("^REMOTE_ADDR") if ( $browserhost eq "" ); if (defined($in{'lpc_restart'})) { $lpc_options = "kill"; } elsif (defined($in{'lpc_release'})) { $lpc_options = "release"; } elsif (defined($in{'lpc_enable'})) { $lpc_options = "enable"; } elsif (defined($in{'lpc_disable'})) { $lpc_options = "disable"; } elsif (defined($in{'lpc_pause'})) { $lpc_options = "PA"; } elsif (defined($in{'lpc_resume'})) { $lpc_options = "RE"; } else { print "Could not figure out option to pass to lpc ..."; exit(2); } $printserver = "unix"; $queue_is_nt = &check_if_nt_queue($in{'printer'}); if ( $queue_is_nt) { $printserver = &get_printserver($in{'printer'}); } $_ = `$lpc_suid $adminmode $browserhost $in{'printer'} $printserver $lpc_options`; print "$_ "; } else { print "You have not enabled adminmode ..."; } # Misc. Admin fucntions/documentation ... } elsif ( defined($in{'showactivebroke'})) { if ( $lpq_all_dir ) { $days = -M "$lpq_all_dir/current"; $minutes = int (60 * 24 * $days); print ""; print "\"active/broke\" printers from an \"lpq-all\" run $minutes minutes ago
"; print "Transient Network and/or Print Server outages may result in reds
"; print "Queue Status Printer Name Description
"; print "
"; open (LPQALL,"<$lpq_all_dir/current") || ( print "Can't open $lpq_all_dir/current: $!" || die() ) ; while () { chomp (); ($color,$results,$printer) = split(" +"); printf "%s%-22s%s%s%-24s" ,"" , $results , "" ,"", "$printer"; if ( $lookup_info ) { $description = &get_shortinfo($printer); } print "
"; } close (LPQALL); } else { print "Does not appear to be active/broke queue data available
"; } # Show mis-configured queues ... } elsif ( defined($in{'misconfigured'})) { print ""; open (MISCONFIGURED,"<$misconfigured") || ( print "Can't open $misconfigured: $!" || die() ) ; while ("; print "List of queues that are mis-configured"; print " ) { print $_; } close (MISCONFIGURED); # Check LPRng print servers } elsif ( defined($in{'checkprintservers'})) { print " Checking status of LPRng print servers
"; printf "Print Server Status
"; open (SERVERS,"<$lprng_print_servers") || print "Can't open $lprng_print_servers: $!" ; while () { chomp($printer = $_ ); $results = `$lpc -Plp\@$printer lpd`; chomp ($results); if (( "$results" =~ "Server PID" ) || ( "$results" =~ "lpd server pid") ) { printf "%s%-16s%s" ,"" , "$printer" , "OK - $results"; } else { printf "%s%-16s%s" ,"" , "$printer", "$results"; } print "
"; } close (SERVERS); # Print a test page ... } elsif ( defined($in{'testpage'})) { print "Printing test page to $in{'printer'}
\n"; $banner = "echo" if ( ! -x $banner ); $testpage = "/tmp/lp-testpage-$$"; open(TESTPAGE,">$testpage") || print "Can't open $testpage: $!" ; $_ = `$banner -w40 "lpinfo"`; print TESTPAGE "$_ \n\n"; $_ = `$banner -w40"test\ page"`; print TESTPAGE "$_ \n\n\n\n\n"; $_ = `date`; print TESTPAGE "printed to queue $in{'printer'} on $_ \n\n\014"; close(TESTPAGE); system ("$lpr -h -P$in{'printer'} $testpage"); system ("rm $testpage"); print "