/usr/lib/printfilters/directprint is in printfilters-ppd 2.13-11.1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 | #!/usr/bin/perl
# Direct-to-printer (old HP Jetdirect style printers) filter
# to integrate with rhs-printfilters.
# Supplied by Joshua Buysse, University of Minnesota
# needs perl 5.004 for IO:Socket
require 5.004;
# Maximum number of times to retry connection
$max_retries = 3600; # at one second each, one hour.
# needed for the dirname() function
use File::Basename;
use IO::Socket;
use Cwd;
# The first parameter to the script is the name of the
# accounting file, in the spool directory for the printer.
$acct_file = $ARGV[0];
# we need the spool_dir to pick up the config files
$spool_dir = dirname($acct_file);
$config_file = "$spool_dir/.config";
if (-e $config_file) {
open(CONFIG, $config_file) || die "No config file found!";
while (<CONFIG>) {
chomp;
s/#.*//; # no comments
s/^\s+//; # no leading white
s/\s+$//; # no trailing white
# If there's nothing left, we're done.
next unless length;
# split the fields
my ($key,$value) = split /\s*=\s*/, $_, 2;
$config{$key} = $value;
}
}
else {
# This section was added to support the newer lpd
# versions that get data from printcap instead of .config. -mlp
# Get queue name:
if (length($spool_dir) < 2) {
$spool_dir = cwd ();
}
$inp = `pcap -S $spool_dir`;
chop $inp;
eval "\$$inp";
# Get port:
$inp = `pcap -P$queue:port`;
chop $inp;
eval "\$$inp";
# Get printer_ip:
$inp = `pcap -P$queue:printer_ip`;
chop $inp;
eval "\$$inp";
$config{'port'} = $port;
$config{'printer_ip'} = $printer_ip;
}
# the config hash should contain port and printer_ip as keys
# if the port isn't set, use the default of 9100
$config{'port'} = 9100 unless $config{'port'};
$config{'printer_ip'} || die "Config file does not specify printer IP.";
# now, open a socket to the printer.
$retry_count = 0;
do {
$socket = IO::Socket::INET->new(PeerAddr => $config{'printer_ip'},
PeerPort => $config{'port'},
Proto => "tcp",
Type => SOCK_STREAM);
if (! $socket) {
sleep 1;
$retry_count++;
}
} until ($socket || ($retry_count > $max_retries));
$socket || die "Unable to open socket after $retry_count retries.";
while (<STDIN>) {
print $socket $_;
}
close($socket);
|