From: andreas@knobel.knirsch.de (Andreas Klemm) Subject: (was Re: postscripton on BJ330) new dj500 printer filter Date: Wed, 1 Sep 1993 13:04:26 GMT
hein@student.tu-clausthal.de (Jochen Hein) writes:
>Hi all,
>to avoid a security hole when running gs as a filter add -dSAFER to
>it arguments:
Ok, not bad !
[ old priterfilter ]
>>Hope this gives you enough inspiration.....
>Quite cool, but if you use the 8-bit-clean tcsh, the filter can recognize
>ASCII-Files with Umlauts in the first line. Be aware of the tcsh-Syntax!
I have rewritten the whole filter part, to avoid printer mismatch.
Because: When I try to print a ps file, which crashes gs, then it
leaves the printer in an insane state. Sometimes you have to eject
the paper from the dj500 manually (pushing Reset and/or FF button).
Another part ... reading the first line of print jobs is only ok,
if you have Ascii Text. Printing 'binary' data could confuse the
printer, since the read/echo construct doesn't work correct in all
cases ....
Then I wanted to make the auto-recognition-file-type part
better for later enhancements ....
The big difference is, that the newer filter writes the print
job into a temp file. Now the command file is used, to determine
the file type. Now you can convert, filter, ... etc ...
the tempfile ... until you get what you want ...
Have fun !
#-------- snip/snap ----- /usr/local/lib/deskjetof ---------------------
#!/bin/bash
# HP Deskjet 500 - output filter - RELEASE 1.1
#
# by Andreas Klemm <andreas@knobel.knirsch.de>
# where do you have diskspace
#
TmpDir=/home/tmp
# Temp. filename
TmpFile=$TmpDir/deskjetof.$$
# Who should be notified by e-mail in case of print problems ?
NOTIFY=root
# write print data from stdin to temp file
cat - > $TmpFile
#
# reset printer to power on values before print job
#
echo -ne '\033E'
# determine file type
# set output of the ``file'' command to new script arguments $1, $2, ..., $n
#
set -- `file $TmpFile`
# throw away $1 since that is the *file name*
#
shift
# the rest is a "string" which consist of one or multiple words
# describing the file type. For example: "Korn Shell Script"
#
FileType=$*
case $FileType in
PostScript*) #
# pipe ps data through ghostscript
#
/bin/cat $TmpFile \
| /usr/bin/gs -q \
-sDEVICE=deskjet \
-sPAPERSIZE=a4 \
-dNOPAUSE \
-dSAFER \
-sOutputFile=- \
- \
/usr/local/lib/ghostscript/quit.ps \
|| echo -ne '\033&l0H'
# ^ if an error occurs, then
# | eject already loaded paper
;;
*text*|*script*) #
# print normal text with
# - cr/nl conversion
# - draft quality
# - 66 lines/page
# - left margin
# - 12 cpi pitch
#
# LINE TERMINATION \E & k # G
# 0 = CR=CR ; LF=LF ; FF=FF (default)
# 1 = CR=CR+LF; LF=LF ; FF=FF
# ** 2 = CR=CR ; LF=CR+LF; FF=CR+FF
# 3 = CR=CR+LF; LF=CR+LF; FF=CR+FF
echo -ne '\033&k2G'
# QUALITY \E ( s # Q
# ** 1 = draft = 240cps
# 2 = letter = 120cps (default)
echo -ne '\033(s1Q'
# Text Scale Mode \E & k # W
# 5 = off (default)
# 6 = on
# ignored in landscape mode
# echo -ne '\033&k5W'
# Perforation Skip Mode \E & l # L
# 0 = off = 0.0 in Top Margin
# 1 = on = 1/2 in Top Margin (default)
echo -ne '\033&l0L'
# Left Margin \E & a # L
# # Value = column number
# default = 0 = 1/8 in left margin
# used = 8 for additional margin
echo -ne '\033&a8L'
# Pitch \E ( s # H
# # = cpi
# default = 10 characters per inch
# ** 12 cpi
echo -ne '\033(s12H'
# print tmp file
/bin/cat $TmpFile
;;
*data*) #
# print binary files
#
# LINE TERMINATION \E & k # G
# ** 0 = CR=CR ; LF=LF ; FF=FF (default)
# 1 = CR=CR+LF; LF=LF ; FF=FF
# 2 = CR=CR ; LF=CR+LF; FF=CR+FF
# 3 = CR=CR+LF; LF=CR+LF; FF=CR+FF
echo -ne '\033&k0G'
# print tmp file
/bin/cat $TmpFile
;;
*) #
# Rest is an unknown file type ...... sorry ;-)
# - has somebody else further filter ideas ?
#
echo "deskjetof: unknown filetype $FileType" > /dev/console
echo "deskjetof: $TmpFile: unknown filetype $FileType" \
| mail $NOTIFY
NotOk=1
;;
esac
#
# keep print job, that couldn't be printed because of errors....
#
if [ ! "$NotOk" = "1" ]
then
rm -f $TmpFile
fi
#
# reset printer to power on values after print job
#
echo -ne '\033E'
#----------------------------------------------------------------
# Some hints about used utilities/programs/options
#----------------------------------------------------------------
# ghostscript parameters...
# =========================
#
# -q quiet mode, no messages
# -dNOPAUSE don't wait for RETURN when doing showpage
# -sDEVICE=deskjet printer (deskjet or djet500 if gs-2.6)
# -sOutputFile=- output on stdout
# -dSAFER prevent security whole
# forbidds ps file operations
# from: hein@student.tu-clausthal.de
# - input from stdin
# -sPAPERSIZE=a4 papersize
# /usr/local/lib/ghostscript/quit.ps terminate cleanly
#--------------- snip/snap ------------- EOF deskjetof ------------
-- /-\ Andreas Klemm <andreas@knobel.knirsch.de> +-----------------+ |@|########################################################-@ "pay for it !" | \-/ 41469 Neuss Germany phone +49/ 2137 12609 +-----------------+