initial commit of file from CVS for smeserver-print-monitor on Sat Sep 7 20:55:37 AEST 2024

This commit is contained in:
Trevor Batley
2024-09-07 20:55:37 +10:00
parent 204cbf06cf
commit 66b2b136f2
35 changed files with 3779 additions and 2 deletions

View File

@@ -0,0 +1,20 @@
<html>
<head>
<META NAME="CONTACT" CONTENT="Komarnitsky, Alek O">
<META NAME="SENSITIVITY" CONTENT="UNRESTRICTED">
</head>
<a href="http://www-sa.SOMEDOMAIN/Presentations/lprng/" target=new>LPRng presentation</a>
<br>
<a href="http://www.SOMEDOMAIN:8080/printflow" target=new>Printing Info/Standards</a>
<br>
<a href="/LPRng/HOWTO/LPRng.html" target = new>LPRng Technical Info</a>
<br>
<a href="http:/LPRng/pprdist" target=new>Pprdist documentation</a>
<br>
<a href="/LPRng/admin/cgi-bin/lpinfo?printer=bogus&checkprintservers=1" target=adminout>Check LPRng Print Servers</a>
<br>
<a href="/LPRng/admin/cgi-bin/lpinfo?printer=bogus&showactivebroke=1" target="adminout">Show Active/Broke Queues</a>
<br>
<a href="/LPRng/admin/cgi-bin/lpinfo?printer=bogus&misconfigured=1" target=adminout>Mis-configured NT Queues</a>
<br><br>
</html>

View File

@@ -0,0 +1,68 @@
#!/usr/bin/perl
#^^^^^^^^^^^^^^^^^^^^ Update pathname appropriately to where you have Perl installed
# And update the path below of the configuration file as appropriate.
$suid_ph = "/var/www/html/LPRng/admin/cgi-bin/suid.ph";
#-------------- Should be fairly boilerplate from here on out --------------
# lpc.suid - a setUID script to allow httpd to issue lpc commands ...
# This script would be setUID root and in a directory readable by httpd ONLY
# and protected via a .htaccess file
# Copyright 1997, 1998, 1999, 2000 by Alek Komarnitsky, alek@komar.org, http://www.komar.org/
# Use and distribution of this software is covered by the GNU GPL license.
# Please see the LICENSE file and http://www.gnu.org/
# Grab stuff from suid.ph ...
if ( -r "$suid_ph" ) {
require "$suid_ph";
} else {
print "could not open $suid_ph - serious error ... \n";
exit(2);
}
if ($#ARGV < 4) {
print ("Usage: lpc_suid adminmode browserhost queuename printserver lpc-options\n");
exit(1);
}
# LPRng requires setting UID to EUID ...
$< = $>;
$ARGV[0] =~ /^(\S+)$/;
$_ = $1; # Not tainted
$adminmode = sanitize($_);
$adminmode = nobody if ($adminmode eq 0 ) ;
$ARGV[1] =~ /^(\S+)$/;
$_ = $1; # Not tainted
$browserhost = sanitize($_);
$ARGV[2] =~ /^(\S+)$/;
$_ = $1; # Not tainted
$queuename = sanitize($_);
$ARGV[3] =~ /^(\S+)$/;
$_ = $1; # Not tainted
$printserver = sanitize($_);
$temp = "@ARGV[4 .. $#ARGV]";
$temp =~ /^(.+)$/;
$_ = $1; # Not tainted
$lpc_options = sanitize($_);
if ( $printserver =~ /unix/ ) {
$command = "$lpc -P$queuename $lpc_options";
$command = "$lpc release $queuename all" if ( $lpc_options eq "release");
} else {
$< = "$lprng_uid";
$command = "rsh $printserver \"$nt_lpc $queuename /$lpc_options\"" ;
}
print "<h2>Executing: &nbsp; $command <br><br>\n";
$_ = `$command`;
print "Results: &nbsp; &nbsp; &nbsp; $_";
&openlog("lpc_suid","cons,pid","local2");
&syslog('info',"lpc -P$queuename $lpc_options from browserhost $browserhost by $adminmode");
&closelog();
exit();

View File

@@ -0,0 +1,60 @@
#!/usr/bin/perl
#^^^^^^^^^^^^^^^^^^^^ Update pathname appropriately to where you have Perl installed
# And update the path below of the configuration file as appropriate.
$suid_ph = "/var/www/html/LPRng/admin/cgi-bin/suid.ph";
#-------------- Should be fairly boilerplate from here on out --------------
# lpq_nt - a setUID script to determine NT queue status via a direct rsh
# The ONLY reason this exists is because the NT LPD server truncates the
# IP address when queried via an lpq ... and it is setUID because we restrict
# rsh's to a certain named user
# This script would be setUID root and in a directory readable by httpd ONLY
# and protected via a .htaccess file
# Copyright 1997, 1998, 1999, 2000 by Alek Komarnitsky, alek@komar.org, http://www.komar.org/
# Use and distribution of this software is covered by the GNU GPL license.
# Please see the LICENSE file and http://www.gnu.org/
# Grab stuff from suid.ph ...
if ( -r "$suid_ph" ) {
require "$suid_ph";
} else {
print "could not open $suid_ph - serious error ... \n";
exit(2);
}
if ($#ARGV != 1) {
print ("Usage: lpq_nt queuename printserver\n");
exit(1);
}
$< = "$lprng_uid";
$ARGV[0] =~ /^(\S+)$/;
$_ = $1; # Not tainted
$queuename = sanitize($_);
$ARGV[1] =~ /^(\S+)$/;
$_ = $1; # Not tainted
$printserver = sanitize($_);
$command = "rsh $printserver \"$nt_lpc $queuename /JL\"" ;
$output = `$command`;
print " Windows NT LPD Server \n Rank Owner/NT-ID Class Job Files Size\n";
print "----------------------------------------------------------------------------------------\n";
if ( ! ($output =~ /There are no print jobs for printer/) ) {
@lpqout = split(/\n/,$output);
$count = 1;
foreach $line (@lpqout) {
if ( ($line =~ /JOB LOG FOR PRINTER/) || ($line =~ /^Job:/) || ($line =~ /--------------------/) || ($line =~ /^\s*$/)) {
next;
} else {
($jobid,$owner,$_,$jobname,$size) = split(/\s+/,$line);
s/\(// ; s/\)//;
$owner = "$owner" . "@" . "$_" . "+1";
printf "%-2s%5s%-31s%3s%5s%2s%-30s%9s%s",$count," ",$owner,"NT",$jobid," ",$jobname,$size,"\n";
$count++;
}
}
}
exit();

View File

@@ -0,0 +1,66 @@
#!/usr/bin/perl
#^^^^^^^^^^^^^^^^^^^^ Update pathname appropriately to where you have Perl installed
# And update the path below of the configuration file as appropriate.
$suid_ph = "/var/www/html/LPRng/admin/cgi-bin/suid.ph";
#-------------- Should be fairly boilerplate from here on out --------------
# lprm_suid - a setUID script to allow httpd to lprm selected jobs
# This script would be setUID root and in a directory readable by httpd ONLY
# and protected via a .htaccess file
# Copyright 1997, 1998, 1999, 2000 by Alek Komarnitsky, alek@komar.org, http://www.komar.org/
# Use and distribution of this software is covered by the GNU GPL license.
# Please see the LICENSE file and http://www.gnu.org/
# Grab stuff from suid.ph ...
if ( -r "$suid_ph" ) {
require "$suid_ph";
} else {
print "could not open $suid_ph - serious error ... \n";
exit(2);
}
if ($#ARGV != 4) {
print ("Usage: lprm_suid adminmode browserhost queuename printserver jobnumber\n");
exit(1);
}
# LPRng requires setting UID to EUID ...
$< = $>;
$ARGV[0] =~ /^(\S+)$/;
$_ = $1; # Not tainted
$adminmode = sanitize($_);
$adminmode = nobody if ($adminmode eq 0 ) ;
$ARGV[1] =~ /^(\S+)$/;
$_ = $1; # Not tainted
$browserhost = sanitize($_);
$ARGV[2] =~ /^(\S+)$/;
$_ = $1;
$queuename = sanitize($_);
$ARGV[3] =~ /^(\S+)$/;
$_ = $1;
$printserver = sanitize($_);
$ARGV[4] =~ /^(\S+)$/;
$_ = $1;
$jobnumber = sanitize($_);
if ( $printserver =~ /unix/ ) {
$command = "$lprm -P$queuename $jobnumber";
} else {
$< = "$lprng_uid";
if ($jobnumber eq "all") {
$command = "rsh $printserver \"$nt_lpc $queuename /PG\"";
} else {
$command = "rsh $printserver \"$nt_lpc $queuename /JK$jobnumber\"" ;
}
}
$_ = `$command`;
print "$_";
&openlog("lprm_suid","cons,pid","local2");
&syslog('info',"lprm -P$queuename $jobnumber from browserhost $browserhost by $adminmode");
&closelog();
exit();

View File

@@ -0,0 +1,27 @@
# suid.ph ... misc. stuff needed for setUID (be careful!) programs with LPRng lpinfo
# Copyright 1997, 1998, 1999, 2000 by Alek Komarnitsky, alek@komar.org, http://www.komar.org/
# Use and distribution of this software is covered by the GNU GPL license.
# Please see the LICENSE file and http://www.gnu.org/
$ENV{'PATH'} = "/bin:/usr/bin:/usr/ucb:/usr/etc";
require Sys::Syslog;
import Sys::Syslog;
$lpc = "/usr/sbin/lpc";
$lprm = "/usr/bin/lprm";
$nt_lpc = "c:\\ent\\util\\ntp\\release\\ntp.exe" ;
$lprng_uid = "6743";
$| = 1;
sub sanitize {
local ($OK_CHARS);
$OK_CHARS=' \-\.a-zA-Z0-9_';
s/[^$OK_CHARS]/_/go;
/^(.*)$/;
return $1;
}
1;

View File

@@ -0,0 +1,20 @@
<html>
<head>
<META NAME="CONTACT" CONTENT="Komarnitsky, Alek O">
<META NAME="SENSITIVITY" CONTENT="UNRESTRICTED">
</head>
<a href="http://www.SOMEDOMAIN/Presentations/lprng/" target=new>LPRng presentation</a>
<br>
<a href="http://www.SOMEDOMAIN:8080/printflow" target=new>Printing Info/Standards</a>
<br>
<a href="/LPRng/HOWTO/LPRng.html" target = new>LPRng Technical Info</a>
<br>
<a href="http:/LPRng/pprdist" target=new>Pprdist documentation</a>
<br>
<a href="/LPRng/cgi-bin/lpinfo?printer=bogus&checkprintservers=1" target=adminout>Check LPRng Print Servers</a>
<br>
<a href="/LPRng/cgi-bin/lpinfo?printer=bogus&showactivebroke=1" target="adminout">Show Active/Broke Queues</a>
<br>
<a href="/LPRng/cgi-bin/lpinfo?printer=bogus&misconfigured=1" target=adminout>Mis-configured NT Queues</a>
<br><br>
</html>

View File

@@ -0,0 +1,6 @@
<HTML>
<head>
<META NAME="CONTACT" CONTENT="Komarnitsky, Alek O">
<META NAME="SENSITIVITY" CONTENT="UNRESTRICTED">
</head>
</HTML>

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,216 @@
#!/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 <br> " if ($debug);
$browserhost="localhost";
$_ = get_env_variable("^REMOTE_ADDR");
print "We got $_ as the REMOTE ADDR <br> " 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 <br> " if ($debug);
if ( (! defined($in{'printer'}) ) || (! defined($in{'jobnumber'}) )) {
close_er_out ("Did not get everything in that we needed ... <br> printer was $printer and $jobnumber was $jobnumber and browserhost was $browserhost and adminmode was $adminmode");
exit();
}
print "<br><br> printer is $printer and jobnumber is $jobnumber and browserhost is $browserhost and printserver is $printserver and queue_is_nt is $queue_is_nt end <br>" if ( $debug );
$findjob = &find_job;
if ( $findjob =~ "FAILED" ) {
&close_er_out("$findjob");
}
print "<br>sending $lprm_suid $adminmode $browserhost $printer $printserver $jobnumber\n" if ($debug);
$lprmout = `$lprm_suid $adminmode $browserhost $printer $printserver $jobnumber`;
print "<br><br>from lprm_suid, we got $lprmout <br> " 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 "<br>second findjob shows $findjob <br>" 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</html>";
exit();
sub find_job {
local(@lpqout,@jobs,$foundrank,$foundjob);
if ( defined($in{'queue_is_nt'})) {
$command = "$lpq_nt $printer $printserver" ;
} else {
$command = "$lpq -P$printer $jobnumber";
}
print "executing $command <br> " if ($debug);
@lpqout = `$command`;
# Parse output and stuff everything below "Rank Owner/ID" into @jobs
foreach $_ (@lpqout) {
next if ($_ =~ /^\s*$/);
if ($foundrank ) {
push (@jobs,$_);
}
$foundrank = 1 if ( $_ =~ "Rank Owner/ID") ;
if ($queue_is_nt) {
$foundrank = 1 if ( $_ =~ /--------------------/) ;
}
}
# Make sure that we can find the job ... in case user goofs we can tell them that ...
foreach $_ (@jobs) {
($rank,$owner,$class,$job,$misc) = split();
print "<br>rank is $rank owner is $owner class is $class job is $job misc is $misc\n" if ($debug);
$foundjob = 1 if (($queue_is_nt) && ( $jobnumber eq "all"));
if ( $job eq $jobnumber ) {
$foundjob = 1;
last;
}
}
if ( ($jobnumber eq "all") && ( $foundrank) ) {
return("SUCCESS: all found some jobs");
}
if (! $foundjob ) {
return ("FAILED: Could not find any job $jobnumber in $printer");
}
# Lets see if it truly comes from your machine ...
$_ = $owner;
s/^.*@(.*)\+.*$/$1/s;
tr/A-Z/a-z/;
$jobhost = $_;
print "jobhost is $jobhost \n" if ( $debug );
if (($jobhost ne $browserhost ) && ( ! ($adminmode) ) ){
close_er_out("FAILED: Print job $jobnumber on $printer came from $jobhost, not your machine $browserhost");
}
return ("at the end of findjob");
}
sub close_er_out {
print "<br><br> @_ ";
if ( $adminmode ) {
print "<form method=\"post\" action=\"$thisURLadmin?printer=$printer\" target=bottom>";
} else {
print "<form method=\"post\" action=\"$thisURL?printer=$printer\" target=bottom>";
}
print "<input type=\"hidden\" name=\"printer\" value=\"$printer\">";
print "<input type=\"hidden\" name=\"auto\" value=\"0\">";
print "<br><br><center><input type=\"submit\" value=\"Go back to queue status\">";
print "</form></html>";
exit();
}
# HTML parsing ...
sub ReadParse {
if (@_) { local (*in) = @_; }
local ($i, $loc, $key, $val);
# Read in text
if ($ENV{'REQUEST_METHOD'} eq "GET") {
$in = $ENV{'QUERY_STRING'};
} elsif ($ENV{'REQUEST_METHOD'} eq "POST") {
for ($i = 0; $i < $ENV{'CONTENT_LENGTH'}; $i++) {
$in .= getc; }
}
@in = split(/&/,$in);
foreach $i (0 .. $#in) {
# Convert plus's to spaces
$_ = $in[$i];
$in[$i] = &sanitize($_);
$in[$i] =~ s/\+/ /g;
# Convert %XX from hex numbers to alphanumeric
$in[$i] =~ s/%(..)/pack("c",hex($1))/ge;
# Split into key and value.
$loc = index($in[$i],"=");
$key = substr($in[$i],0,$loc);
$val = substr($in[$i],$loc+1);
$in{$key} .= '\0' if (defined($in{$key})); # \0 is the multiple separator
$in{$key} .= $val;
}
}
# Added per CERT advistory - send Alek EMail if you want changes here ...
sub sanitize {
local ($OK_CHARS);
$OK_CHARS='-a-zA-Z0-9_.@=?+/ \s';
s/[^$OK_CHARS]/_/go;
return $_;
}
sub get_env_variable{
$env_variable = @_[0];
@env = `env`;
@array=();
push(@array,grep(/$env_variable/,@env));
chomp($_ = $array[0]);
$_ = &sanitize($_);
s/^.*=//s;
return $_;
}

View File

@@ -0,0 +1 @@
1

View File

@@ -0,0 +1 @@
1

View File

@@ -0,0 +1 @@
1

View File

@@ -0,0 +1,10 @@
<HTML> <HEAD>
<META NAME="CONTACT" CONTENT="Komarnitsky, Alek O">
<META NAME="SENSITIVITY" CONTENT="UNRESTRICTED">
<TITLE>lpinfo - LPRng queue status tool</TITLE>
</HEAD>
<FRAMESET rows="20%,40%,*" >
<FRAME marginheight="0" src="/LPRng/cgi-bin/lpinfo" name="main">
<FRAME marginheight="0" src="/LPRng/cgi-bin/lpinfo?show_middle_frame=true" name="middle">
<FRAME src="bottom.html" name="bottom" >
</FRAMESET> </HTML>

View File

@@ -0,0 +1,6 @@
<HTML>
<head>
<META NAME="CONTACT" CONTENT="Komarnitsky, Alek O">
<META NAME="SENSITIVITY" CONTENT="UNRESTRICTED">
</head>
</HTML>