#!/bin/sh # # fax - script to make, send, receive, view or print a fax # Copyright 1993-1999 by Ed Casas # # --- Start of user configuration section --- # # Notes: # # - do not put spaces before or after the equal (=) signs. # # - variables can also be set on the command line, for example: # fax DEV=cua0 send file.ps # or in a configuration file (see CONFIGFILES below) # # The names of the fax script, efax and efix, including full path # if necessary. ########################################################################## # # DATE: 2003-04-06 # # # MODIFIED to work on a Gericom A440 (1st Supersonic) Laptop # with Lucent "Softmodem" w/ Mars 3 chipset running RedHat 7.3. # Not tested with efax started as deamon at runlevel-init. # # Needs efax v 0.9a-001114 - NO_OTHER_VERSION (as of 2003-03-08) # # Changed details: # - New command "fax poll " # (via console) # - location of the directories for the # fax-in, -out and -log files are changed # to reside under ~/fax inside the user's home directory # These can easily be changed by redefining the # FAXDIR, LOGDIR and FAXOUTDIR vars below. # # Hint: It may be neccessary to let at least the efax # program to be executed as root (chmod), # depending on the system's access rights # # To find modifications search for "###" # # To send a fax fax send filename # To poll a fax fax poll # # e.g.:"fax poll 012-0678-2345,,01,*2#" # To list all received faxes fax queue # To view all received faxes fax view "*" # To receive one fax call fax answer # *** ATTENTION *** the fax answer command may act buggy when # released before the phone rings # # Actually all files tried to be sent are copied to the # ~/fax/outgoing dir, independent of successful sent. # Failed sents will be renamed to "...ERROR_NOT_SENT..." # To be improved... # # # Please email improvements to a.b.c@gmx.net # Modifications: Copyright (C) 2003 Michael Besteck (a.b.c@gmx.net) # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free SoftwareFoundation, # Inc., 675 Mass Ave, Cambridge, MA 02139, USA. # # The author can be contacted by email to a.b.c@gmx.net # ########################################################################## ### FAX-FORMAT : second last parameter=Telno ( _one_ tel.-nr ) ### last parameter=Filename fax.ps-data ( _one_ file ) ### ### This way programs will ask for fax-nr to send ### ### KWrite: Printer Name="Send To Fax" ### Printing system="Generic UNIX/LPD printing system (default)" ### when the KdePrintfax program appears ### configure->system, check "efax", ### change command to "/usr/bin/faxlpr %numbers %files" ### ### StarOffice: shut down StarOffice, ### then start /usr/local/lib/StarOffice52/program/spadmin ### -choose GenericPrinter (ps) ### -connect->"fax_queue=(FAX)" ### -configure fax-output->command="/usr/bin/faxlpr (PHONE) (TMP)" ### ->type="File" (vs. pipe) ### -settings->greyscale (standard fine fax has 196 dpi) ### -print a test page to save settings ### for extension: ### just to be prepared for getting data streamed via stdin ### not used for faxing via command line or fax-printing ### via kwrite/StarOffice as described above ### tee ${HOME}/fax/laststdin.ps ### added ### defines where log messages go ### must be one of "con"/"log"/"both"/"none" ### "con"-outputs stays unseen using higher level printing (StarOffice, etc.) ### "log"-outputs stays unseen using (just one) console OUTPUTLOG_TYPE="both" ### prefix of log messages OUTPUTLOG_PREFIX="/usr/bin/fax:" ### added ### ensure existing HOME-var containing canonical path if [ ! -d $HOME ] ; then pushd cd ~ HOME=`pwd` popd ; if [ ! -d $HOME ] ; then echelon "cannot find user home directory:exiting" ; exit 2 ; fi fi ### changed and moved ### this definitions keep fax-in, -out and -log directories inside "home"/fax FAXDIR=${HOME}"/fax/incoming" # "/var/spool/fax" LOGDIR=${HOME}"/fax/log" # "/var/log/fax" ### added FAXOUTDIR=${HOME}"/fax/outgoing" LOCKDIR_SYSTEM="/var/lock" # "/var/log/fax" FAXPHONEBOOKDIR=${HOME}"/fax" # entry-format: "fax(): " FAXPHONEBOOKFILE=".faxdir" # entry-format: "fax(): " ###changed # Configuration files that are sourced if they exist. Comment # out if you don't need to use config files. Warning: any type of # shell command in these files will be executed. ### added BASE_CONFIGFILE="${HOME}/.efax.rc" ### canged (HOME) CONFIGFILES="BASE_CONFIGFILE ${HOME}/.efaxrc ./.efaxrc" ###changed # List of telephone directory file(s) to be searched. The # default is the file .faxdir in the user's home directory. DIRFILES="${FAXPHONEBOOKDIR:-.}/""$FAXPHONEBOOKFILE" MODEM_COUNTRY_CODE="42" # germany ### In case this script is called from faxlpr as a printer "filter", ### setup as described tel.-nr. and ps-data-filename are needed ### look them up before they are shifted away ### get nr of parameter LastIdx=$# if [[ $LastIdx -gt 0x01 ]] ; then declare -i TELPARMNR=$LastIdx-0x1 eval "FAXLPR_TELNR=\${""${TELPARMNR}""}" eval "FAXLPR_FILENAME=\${""${LastIdx}""}" ; else ### parameter insufficient FAXLPR_TELNR="" FAXLPR_FILENAME="" ; fi ### remove all slashes and backslashes from telnr ### (to enable later use as part of filename) eval "FAXLPR_TELNR=`echo ${FAXLPR_TELNR} | sed s/['\\/']//g`" ### check for valid file if [[ ! -r ${FAXLPR_FILENAME} ]] ; then FAXLPR_FILENAME="" ; else cp ${FAXLPR_FILENAME} "${HOME}/fax/lastfile.ps" ; fi ### to avoid malfunction (error 2) of modem driver ### this is the only adjustmented specific to the A440 if [[ -n $LTSERIAL_LOADED_INFO ]] ; then rmmod -r lt_serial &>/dev/null modprobe lt_serial &>/dev/null ; ### for tests of modem-behaviour ### LTSERIAL_LOADED_INFO="loaded" ; export LTSERIAL_LOADED_INFO fi FAX=/usr/bin/fax EFAX=/usr/bin/efax EFIX=/usr/bin/efix # The device to which the fax modem is connected (e.g. ttya for # /dev/ttya). Use a dial-out (cua) device if available. If # there are links to this device then all programs must use samex script start" # name or the UUCP locking mechanism will fail. For example, if # /dev/modem is a link to /dev/cua1, then getty, uucp, kermit, # pppd, dip, etc. must *all* use either /dev/modem or /dev/cua1. ### changed DEV=ttyLT0 ### modem # Your fax number in international format, 20 characters maximum. # Use only digits, spaces, and the "+" character. FROM="+0 000 000 0000" # Your name as it should appear on the page header. ### changed from "from a Red Hat Linux system" to " " NAME="" # The preferred page size for creating and printing faxes. # Allowed values are "letter", "legal", and "a4". ### changed # PAGE=letter # PAGE=legal PAGE=a4 # The type of printer. Use 'pcl' for HP-PCL or 'ps' for # Postscript. See definition of PRINT (below) for more options. PRTYPE=ps # Postscript (e.g. Apple LaserWriter) # PRTYPE=pcl # HP-PCL (e.g. HP LaserJet) # The command to print image files from standard input. Typically # this is "lpr" or "lp". ### changed ### no print if fax is only printer PRCMD="cat" #PRCMD="lpr" # The command to view a Portable Gray Map (PGM) image from the # standard input. Typically "xv -" or "xloadimage stdin". VIEWCMD="xloadimage stdin" # best # VIEWCMD="pnmtoxwd | xwud" # slower alternative # VIEWCMD="xv -" # much slower alternative # The name of the Ghostscript executable including full path if # necessary. Only required if faxing Postscript files. GS=/usr/bin/gs # Dial string prefix and suffix such as T for tone dialing, P for # pulse dialing, 9 to get an external line, commas for delays or # W to wait for dial tone. See definition of TELCVT below if you # have more complex requirements. DIALPREFIX="T" DIALSUFFIX="" # The name(s) of lock file(s) according to your system's # conventions. Protect with single quotes for delayed evaluation. # Add a leading '#' to the file name to use binary format. ### changed LOCK='-x /var/lock/LCK..$DEV' # modern systems # LOCK='-x /var/lock/LCK..$DEV -x /var/spool/uucp/LCK..$DEV' # both # LOCK='-x /usr/spool/uucp/LCK..$DEV' # older systems # LOCK='-x #/usr/spool/uucp/LCK..$DEV' # binary format # LOCK='-x /usr/spool/locks/LK.047.040.011' # SysV style names # LOCK='' # no lock file # Uncomment one of the following lines to force xon/xoff flow # control only if you have one of the types of modems listed. # FCINIT='-j\Q4' # AT&T (Dataport, Paradyne) # FCINIT='-j\Q1' # Motorola (Power Modem, 3400 Pro,...) # FCINIT='-j*F1' # QuickComm (Spirit II) # FCINIT='-j&H2' # USR (Courier, Sportster) # FCINIT='-or' # Multi-Tech (for bit reversal) # **************************************************************** # The remaining options probably won't need to be changed. # **************************************************************** # A command that will generate unique names for logs and received # files. 'date +%m%d%H%M%S' works on most systems. Protect with # single quotes. ### changed TSTAMP='date +%Y%m%d%H%M%S' # TSTAMP='echo $$' # alternative - use process number # Shell command to convert aliases to phone numbers when sending # faxes. When executed $1 will be the alias and $f the file name # to search. The example below uses a directory file where alias # lines start with the keyword "fax" followed by the alias in # parentheses and a colon. The remainder of the line is taken to # be the phone number. Other lines are ignored. For example, if # one of the files in DIRFILES (defined below) contained the line # "fax(kpmg): 691-3031", you could use the command "fax send kpmg # invoice.24". Protect with single quotes. LOOKUP='eval sed -n -e "/^fax($1):/{" -e "s/^[^:]*://p" -eq -e"}" $f' # Shell command to convert phone numbers to dial strings. This # lets you to store numbers without the long distance or # alternate carrier access codes, passwords, accounting digits, # etc. In the examples below this is used to convert numbers # beginning with '+'; the first substitution handles same-country # calls and the second handles international calls. ### changed # TELCVT='sed -e s/+1/1/ -e s/+/011/' # North America # TELCVT='sed -e s/+61/0/ -e s/+/0011/' # Australia # TELCVT='sed -e s/+44/0/ -e s/+/00/' # UK ### TELCVT='sed -e s/+49/0/ -e s/+/00/' # Germany TELCVT='sed -e s/+49// -e s/+// -e s/[-]//g' # Germany to be able to use tel-providers (one more dial prefix w/ "-") # TELCVT='sed -e s/+852// -e s/+/001/' # Hong Kong # TELCVT='sed -e s/+33// -e s/+/19W/' # France (?) # TELCVT='sed -e s/+34/0/ -e s/+/07W/' # Spain # TELCVT='sed -e s/+1/10288/' # use AT&T # TELCVT='sed -e s/+/T82W1682W9W/' # get out of PBX # efix options to use a bitmap font for text-to-fax conversion. # The option -l66 puts 66 lines of text per page, -d1,1 sets 1 # inch top & left margin. Comment these out to use the built-in # font. Use "fax makefont" to make bitmap fonts from Postscript # fonts. # TEXTFONT="-l66 -d1,1 -f /usr/bin/efaxfont" # efax options to specify a different font for headers. Generate # using "fax makefont." # HDRFONT="-f /usr/bin/efaxfont" # Dimensions of page sizes. PAGE_letter="8.465x11in" # fax width x letter length PAGE_legal="8.465x14in" # fax width x legal length PAGE_a4="21x29.7cm" # ISO A4 # Default resolution for converting to fax format. Can only be # 204x196 or 204x98. RES=204x196 # default "Fine" resolution (196 lpi) # RES=204x98 # standard resolution (98 lpi) # When the print and view commands below are executed, $f will be # the input file name and $PAGEDIM will be one of the above page # dimensions. Protect with single quotes. # PRINT: A command to convert fax files to a printable format. # For printers other than Postscript or PCL you can use efix's # PBM output and an appropriate pbm filter (such as pbmtoepson) # or efix's Postsript output and Ghostscript as a filter. Change # the scaling (-s) and displacement (-d) options as required to # fit the image onto the area your printer can print. PRINT='$EFIX -ve -p$PAGEDIM -r300 -s0.98 -d0,0.125 -o$PRTYPE $f' # example using pbm utilities: # PRINT='$EFIX -ve -p$PAGEDIM -r60x72 -opbm $f | pbmtoepson' # example using Ghostscript: # PRINT='$EFIX -ve -p$PAGEDIM -r120x144 -ops $f | \ # $GS -q -sPAPERSIZE=$PAGE -sDEVICE=epson -r120x144 \ # -dNOPAUSE -dSAFER -sOutputFile=- - ' # VIEW: A command to convert fax files to PGM format for # previewing. efix's pgm output reduces image dimensions by 4X. # VIEW='$EFIX -ve -p$PAGEDIM -r200 -opgm $f' # 50dpi: fast, whole-page view # VIEW='$EFIX -ve -p$PAGEDIM -r300 -opgm $f' # 75dpi: slower, readable size VIEW='$EFIX -vewiaf -r300 -opgm $f' # 75dpi: slower, readable size # Commands to set up modem. "-iZ -i&FE&D2S7=120 -i&C0" # works with almost all modems. See the efax(1) man page for # details. ### changed #INIT="-iZ " #INIT="-iZ -i+GCI=42 -i+FCLASS=1 -iQ0B0E1V1&C1&D2" INIT="-iZ -i+GCI="${MODEM_COUNTRY_CODE}" -i&FE&D2S7=1800 -i&C0 -i+FCLASS=1" # Command(s) to reset modem when efax finishes. "-kZ" works in # almost all cases. ### changed ### RESET="-kZ" RESET="-kZ -k&F+FCLASS=0" # for modems that stay in fax mode after reset # Speaker mode(M) and loudness(L). Mn sets speaker mode where n # means: 0:never, 1:until carrier, 2:always, 3:on receive only. ### changed SPKR="-iM2L2" # bitsound ON #SPKR="-iM1L1" # connect-sound #SPKR="-iM0L0" # quiet # Options to use a particular command sets. Normally efax # selects the command set based on the modem's capabilities. Use # -o1 to force Class 1, -o2 for Class 2 and -o0 for Class 2.0. # CLASSINIT="-o1" # Class 1 # CLASSINIT="" # Class 2 # CLASSINIT="-o0" # Class 2.0 # The modem's capabilities for sending faxes. Normally efax # chooses these by querying the modem. "-c 1,3,0,0,0,0,0,0" # forces 9600 bps maximum speed. See the efax(1) man page for a # description of the fields. ### changed # TXCAP="-c 1,3,0,2,0,0,0,0" TXCAP="-c 1,5,2,2,0,0,0,0" # Capabilities for receiving faxes. Usually the same as TXCAP. # If your modem only receives at 4800 bps use "-c 1,1,0,0,0,0,0,0". ### changed # RXCAP="$TXCAP" RXCAP="$TXCAP" # Additional options required only for transmit or only for # receive. None normally required. RXINIT="" TXINIT="" # Command to make a date for the page header. Protect with single # quotes. 'date "+%Y/%m/%d %H:%M"' works on most systems. ### changed # DATECMD='date "+%Y/%m/%d %H:%M"' # YYYY/MM/DD HH:MM (24hour) DATECMD='date "+%Y-%m-%d %H:%M"' # YYYY/MM/DD HH:MM (24hour) # DATECMD='date' # longer, more readable # Page header format. You may use $DATE, $NAME, $FROM, $TO, and # "%d/%d" (for page number and count). Protect with single # quotes. Example: '$DATE $FROM $NAME p. %d/%d'. ### changed to german ### HDR='$DATE $FROM $NAME p. %d/%d' HDR='$DATE $FROM $NAME S. %d/%d' # BUSYRETRIES is a list of delays in seconds between attempts to # redial busy numbers. Comment out if you don't want to retry # busy numbers. ### changed BUSYRETRIES="30 60 120 300 60 600 60 60 1200 60 60" ### for the impatient BUSYRETRIES="20 25 30 35 20 25 30 35 20 25 30 35 20 25 30 35" # FAILRETRIES is a list of delays in seconds between attempts to # retry failed transmissions. Retries are only attempted if at # least one page was sent in the previous attempt. Retries # include only pages not already sent. Comment out if you don't # want to retry failed transmissions. FAILRETRIES="300 300" # try two more times at 5 minute intervals ### for the impatient FAILRETRIES="30 30" # try two more times at 5 minute intervals # Command to run another program (efax) at a higher-than-normal # scheduling priority. This command isn't used if it fails # (e.g. because the current user isn't privileged). Comment this # out if it causes problems. NICE="nice -n -10" # Standard versions of commands that are often aliased. RM="/bin/rm -f" LS="/bin/ls" # Messages to display. VERB sets the messages displayed (stderr) # and VERBLOG the messages written to log files (stdout). VERB="ewin" # show errors, warnings, progress & negotiation VERBLOG="chewmainrxtf" # log everything # **************************************************************** # The remaining configuration options apply only to the `fax # answer' command. You can ignore these if you will only be # running efax manually. See "USING INIT TO RUN EFAX" in the # efax man page for more information. # **************************************************************** ### changed : use OUTPUTLOG_TYPE to specify where messages go # device or file where fatal error messages should be written ##CONSOLE=/dev/console CONSOLE=/dev/null ### ### ### __MOST__ occurences of "CONSOLE" changed ### ### ### # The directory to store incoming faxes and log files. This directory # should already exist and be writable by the user(s) of this script. # The strftime(3) pattern that generates the file name for # received files. For example, at 10:45:36 on February 25, # "%m%d%H%M%S" would produce 0225104536, "%j-%H%M" would produce # 056-1045, and %d%b%H%M 25Feb1045. ### changed # ANSFNAME="%m%d%H%M%S" ANSFNAME="%m-%d_%H%:M%S" # umask for received files. Use 022 to allow anyone to retrieve faxes. ### changed UMASK=022 # UMASK=066 # The user to be sent mail when a fax is received. FAXMGR=root # The sendmail executable including full path if necessary. Only # required if forwarding received faxes by e-mail in $NOTIFY. SENDMAIL=/usr/sbin/sendmail # The command to execute when a fax is received. Normally this # sends FAXMGR e-mail or prints the received fax. The variable # $f will be the name of the log file, $FILES will contain the # names of the received files, and $REMID will have the remote ID # string or '?' if none. The faxmail function will e-mail the fax # as MIME image/tiff attachments. Comment this out to do # nothing. Protect with single quotes. ### changed NOTIFY="" # NOTIFY='faxmail "$REMID" "$f" $FILES | $SENDMAIL $FAXMGR' # NOTIFY='mail -s "fax/message from $REMID: $FILES" $FAXMGR <$f' # NOTIFY='lpr $f ; $FAX print $OPT $FILES' # The number of rings to wait before answering. ANSRINGS=1 # If you want to enable fax/data adaptive answer (AA) read the # efax man page and define DATAINIT to be the options that enable # AA. Note: AA does not work properly on some (2400/9600) modems # unless the modem initialization is done at 2400 bps (not # possible with efax). USR modems do not support modem adaptive # answer (+FAE=) in Class 1. &C1 enables most modems' DCD line # so a signal can be sent to shells when a call is dropped. You # must also define DCMD (see below). ### changed DATAOPT="-j&C1 -j+FCLASS=0 -jS7=50" # DATAOPT="-j&C1 -j+FCLASS=0 -jS7=30" # DATAOPT="-j&C1 -j+FCLASS=0 -jS7=30" # DATAINIT="$DATAOPT -j+FAE=1" # Class 1 modem adaptive answer # DATAINIT="$DATAOPT -j+FAA=1" # Class 2[.0] modem adaptive answer # DATAINIT="$DATAOPT -oa" # software adaptive answer # DATAINIT="$DATAOPT" # data-only answer # If you have a voice modem and want to answer in voice mode # define VOICEINIT to be the options that enable voice mode. You # must also set VCMD below. Voice support is not yet available. # VOICEINIT="-j#CLS=8" # Rockwell voice modems # VOICEINIT="-jM2L2#CLS=8#VLS=4" # with speaker on # Argument to exec(2) of "/bin/sh -c" for incoming data calls. # This command will usually exec getty(8) but can include other # commands to set up the serial port, etc. Up to 6 %d arguments # are replaced by the baud rate following the CONNECT response # from the modem or 19200 if none. If using getty_ps ensure # /etc/gettydefs has entries for all possible %d values # (e.g. 19200). Use 'nice' if required to reduce any special # priority set by NICE. DCMD="exec /sbin/getty -h $DEV %d vt100" # for getty_ps (Linux) # DCMD="exec /sbin/agetty -h $DEV %d vt100" # for agetty (Linux) # DCMD="exec pppd $DEV %d" # start PPP server # Argument to exec(2) of "/bin/sh -c" for incoming voice calls. # This command will usually be a shell script that interacts with # the caller by using efone to play/record audio and detect DTMF # tones. Up to 6 %d arguments are replaced by the modem file # descriptor. VCMD can "exec fax reanswer" to switch to fax or # data mode if required. FONE=/usr/bin/fone # minimal voice mail VCMD="exec $FONE %d" # The owner.group and mode to which "fax answer" sets the serial # device. This allows non-root processes to grab the device from # efax even if a previous process (e.g. login) has changed it. # Comment out if you don't need to reset device ownership. OWNER=root.tty # typical MODE=666 # anybody # MODE=660 # only owner & group # Regular expression for efax exit codes in log files that will # *not* be saved. For example, use [145] to ignore exits due to # `locked' (1), `no modem' (4), and `signal' (5) conditions NOLOG='[145]' # **************************************************************** # --- End of user configuration section --- # **************************************************************** ### added: check & create faxdirs ### this may fail if directory locations are changed ### FAXOUTDIRel.-r. if [ ! -d ${FAXOUTDIR} ] ; then mkdir -p --mode=776 ${FAXOUTDIR} &>/dev/null ; fi if [ ! -d ${FAXOUTDIR} ] ; then echelon "error: directory ${FAXOUTDIR} does not exist" ; exit 2 ; fi ### FAXDIR if [ ! -d ${FAXDIR} ] ; then mkdir -p --mode=776 ${FAXDIR} &>/dev/null ; fi if [ ! -d ${FAXDIR} ] ; then echelon "error: directory ${FAXDIR} does not exist" ; exit 2 ; fi ### LOGDIR if [ ! -d ${LOGDIR} ] ; then mkdir -p --mode=776 ${LOGDIR} &>/dev/null ; fi if [ ! -d ${LOGDIR} ] ; then echelon "error: directory ${LOGDIR} does not exist" ; exit 2 ; fi ### FAXPHONEBOOKFILE if [[ ! -e "${FAXPHONEBOOKDIR}/${FAXPHONEBOOKFILE}" ]] ; then mkdir -p --mode=776 ${FAXPHONEBOOKDIR} &>/dev/null touch "${FAXPHONEBOOKDIR}/${FAXPHONEBOOKFILE}" echo "# This is a list of aliases for telephone numbers" >> "${FAXPHONEBOOKDIR}/${FAXPHONEBOOKFILE}" ; echo "# Do _not_ use blank or tab inside any alias name." >> "${FAXPHONEBOOKDIR}/${FAXPHONEBOOKFILE}" ; echo "# Do _not_ use slash (/) or backslash (\\) as part of tel.-nr." >> "${FAXPHONEBOOKDIR}/${FAXPHONEBOOKFILE}" ; echo "fax(___AliasNameExample___): ++12-345-100,,123*1#" >> "${FAXPHONEBOOKDIR}/${FAXPHONEBOOKFILE}" ; fi if [[ ! -e "${FAXPHONEBOOKDIR}/${FAXPHONEBOOKFILE}" ]] ; then echelon "error: file ${FAXPHONEBOOKDIR}/${FAXPHONEBOOKFILE} does not exist" ; exit 2 ; fi ### BASE_CONFIGFILE if [[ ! -e "${BASE_CONFIGFILE}" ]] ; then mkdir -p --mode=776 `dirname ${BASE_CONFIGFILE}` &>/dev/null touch "${BASE_CONFIGFILE}" echo "# put all redefinitions for /usr/bin/fax here" >> "${BASE_CONFIGFILE}" ; echo "# e.g.: DATAOPT=\"-j&C1 -j+FCLASS=0 -jS7=50\"" >> "${BASE_CONFIGFILE}" ; fi if [[ ! -e "${BASE_CONFIGFILE}" ]] ; then echelon "error: file ${BASE_CONFIGFILE} does not exist" ; exit 2 ; fi # --- source configuration files for f in $CONFIGFILES do if [ -r $f ] then eval "`cat $f`" fi done # --- set any variables given on command line while : ; do case $# in 0) break ;; esac case "$1" in [A-Z]*=*) eval $1 ; shift ;; *) break ;; esac done # -------- initialize ERR=0 $NICE true 2>/dev/null ; case $? in 0) ;; *) NICE="" ;; esac # -------- resolve dependencies on command-line arguments eval LOCK=\"$LOCK\" # depends on DEV # make device name w/o directories case $DEV in */*) DEVN=`echo $DEV|sed -e s./._.g` ;; *) DEVN=$DEV ;; esac case $PAGE in letter) PAGEDIM="$PAGE_letter" ;; legal) PAGEDIM="$PAGE_legal" ;; a4) PAGEDIM="$PAGE_a4" ;; *) echelon "Error: PAGE=\"${PAGE}\" not valid." ; exit 2 ;; esac # --- check for a command or alias and optional flags cmd="" case $0 in */faxlpr|faxlpr) cmd=faxlpr ;; *) while : ; do case $# in 0) case $cmd in '') cmd=receive ;; esac ; break ;; esac case $1 in -l) OPT="$OPT -l" ; RES=204x98 ; shift ;; -h) OPT="$OPT -h" ; RES=204x196 ; shift ;; -v) OPT="$OPT -v" ; VERB=$VERBLOG ; shift ;; *) case $cmd in '') cmd=$1 ; shift ;; *) break ;; esac ;; esac done ;; esac # -------- functions ### added faxmail () { echelon "faxmail-function: needs to be adjusted to use the correct filename ('f'). Returning." ; return; echo "Subject: fax/message from $1" shift echo "Content-Type: multipart/mixed; boundary=EFAX_MAIL" echo "" echo "--EFAX_MAIL" echo "Content-Type: text/plain; charset=\"us-ascii\"" echo "Content-Transfer-Encoding: 7bit" echo "" cat $1 shift for f in $* do echo "--EFAX_MAIL" echo "Content-Type: image/tiff" echo "Content-Transfer-Encoding: base64" echo "" $EFIX -M <$f done } ### added ### needs text to log as parameter ### "switched" output to console(echo) or /var/log/messages(logger) or both or none ### uses global vars "OUTPUTLOG_TYPE" ("con"/"log"/"both"/"none") and "OUTPUTLOG_PREFIX" echelon () { local log="$OUTPUTLOG_PREFIX""${1}" case ${OUTPUTLOG_TYPE} in con) echo "$log" ;; log) logger "$log" ;; both|*) echo "$log" ; logger "$log" ;; esac } # -------- export variables for fone script export DEV TSTAMP # -------- do the appropriate command # so we can use `break' to get to the end of the script while : ; do case $cmd in # fax answer : clean up logs and exec efax. normally run by init(8). answer) if cd $FAXDIR ; then : else ### changed ### echo "Error: $FAX cannot cd to $FAXDIR" >>$CONSOLE echelon "Error: $FAX cannot cd to $FAXDIR" sleep 30 break fi while [ -f "${LOCKDIR_SYSTEM}/${DEVN}.stop" ] ; do sleep 15 ; done umask $UMASK case $OWNER in '') ;; *) chown $OWNER /dev/$DEV ;; esac case $MODE in '') ;; *) chmod $MODE /dev/$DEV ;; esac for fx in ${LOCKDIR_SYSTEM}/${DEVN}.[0-9]* # clean up old log files do ### added ### make f canonical f="${LOCKDIR_SYSTEM}/""`basename ${fx}`" egrep "done, returning $NOLOG|exec'ing" $f >/dev/null 2>/dev/null case $? in 0) $RM $f ;; 1) FILES=`sed -n -e '/received ->/s/^.*-> \(.*\)$/\1/p' $f` FILES=`echo $FILES` REMID=`sed -n -e '/remote ID ->/s/^.*-> \(.*\)$/\1/p' \ -e tok -e b -e ':ok' -e q $f` case $REMID in '') REMID='?' ;; esac eval $NOTIFY echo >>${LOGDIR}/${DEVN}.log cat $f >>${LOGDIR}/${DEVN}.log $RM $f ;; esac done exec $NICE $EFAX -v "" -v "$VERBLOG" -d/dev/$DEV $INIT $SPKR \ $CLASSINIT $FCINIT $RXINIT $LOCK \ $RXCAP -l "$FROM" $RESET \ $DATAINIT -g "$DCMD" $VOICEINIT -e "$VCMD" \ -jS0=$ANSRINGS -w -s -r "${FAXDIR}/${ANSFNAME}" 2>$CONSOLE >${DEVN}.$$ ### changed ### echo ERROR: $FAX answer exec failed >>$CONSOLE ; sleep 30 echelon "ERROR: $FAX answer exec failed"; sleep 30 break ;; # fax reanswer : switch from voice mode to fax[/data] mode reanswer) # we should already be in the fax spool directory, the # device locked, the modem answered and initialized in # voice mode and stdout/stderr redirected appropriately umask $UMASK exec $NICE $EFAX -v "" -v "$VERBLOG" -d/dev/$DEV '-i#CLS=0' \ $CLASSINIT $FCINIT $RXINIT \ $RXCAP -l "$FROM" $RESET \ $DATAINIT -g "$DCMD" \ -r "${FAXDIR}/${ANSFNAME}" ### changed ### echo ERROR: $FAX reanswer exec failed >>$CONSOLE ; sleep 30 echelon "ERROR: $FAX reanswer exec failed"; sleep 30 break ;; # fax queue : list received fax files q*) cd $FAXDIR case $? in 0) ;; *) echelon "cannot cd to $FAXDIR" ; break ;; esac ### changed ### filenames of incoming faxes are set to telephone numbers ### (including "telephone special chars") for f in [0-9,_*#+-]*.[0-9][0-9][0-9] ### for f in [0-9]*.[0-9][0-9][0-9] [0-9]*.v do if [ -r $f ] then echo echo Fax files in `pwd` : echo ### changed ### [0-9]*.[0-9][0-9][0-9] [0-9]*.v $LS -l [0-9,_*#+-]*.[0-9][0-9][0-9] echo break fi done break ;; ### changed: faxlpr : get phone number and user from current cf* file and run fax send ### completely rewritten; ### the original version expects a filename containing parameters (->cfile) ### in the last line of the lock file, but that contains only the pid on RH7.3. ### Using a program that streams the ps-data to be faxed, e.g. StarOffice 5.2 (if setup to), ### these are available from stdin and now saved to file by calling tee (for future extension), ### while fax-send-parameters are transferred via parameters to this script ### using LPRng the "cfile-parameter" are given as script-parameter ### and the PostScript to print is stdin if not different specified by -f (filename) parameter faxlpr) ### added ### (same "lookup" as in send-routine) # look up names case $1 in [A-Za-z]*) for f in $DIRFILES ; do if [ -r $f ] ; then TELNO=`$LOOKUP` ; fi case "$TELNO" in '') continue ;; *) break ;; esac ; done case "$TELNO" in '') echelon "Name lookup for $1 failed" ; ERR=2 ; break ;; *) echelon "Lookup: $1 = $TELNO" ;; esac ;; *) TELNO="$1" ;; esac shift case "$TO" in '') TO="$TELNO" ;; *) ;; esac TELNO=`echo ${TELNO} | sed "s/[ ()][ ()]*//g"` ### (only) filename must now be $1 FileName="`dirname $1`""/""`basename $1`" FileOutName="${FAXOUTDIR}""/""`basename $1`" if [ ! -r "${FileName}" ] ; then echelon "faxlpr:Can't read ${FileName}" ; ERR=2 ; exit 2; fi ### copy to FAXOUTDIR cp -f "${FileName}" "${FileOutName}" &>/dev/null if [ ! -r ${FileOutName} ] ; then echelon "Can't read $FileOutName" ; ERR=2 ; exit 2 ; fi cd ${FAXOUTDIR} case $? in 0) ;; *) echelon "$0: cannot cd to $FAXOUTDIR" ; break ;; esac l=`$FAX send "$TELNO" "$FileOutName"` ### changed ### do not send mail, just echo/log case $? in ### 0) echo "$l" | mail -s "fax to $num succeeded" ; `whoami`"@"`hostname` ### $user@$host ; echelon "fax succeeded" ;; 0) echo "$l" | echelon "fax to ${TELNO} succeeded" ;; ### *) [21~echo "$l" | mail -s "fax to $num failed " ; `whoami`"@"`hostname` ### $user@$host ; echelon "fax failed" ;; *) echo "$l" | echelon "fax to ${TELNO} failed" ;; esac break ;; # fax start/stop/status : manage fax receive daemon start|stop|st*) # common section ### changed ### cd $FAXDIR ; cd $LOCKDIR_SYSTEM ; ### changed case $? in 0) ;; *) echelon "cannot cd to $LOCKDIR_SYSTEM" ; break ;; esac ### changed to use canonical path for logfile n= ; for f in ${DEVN}.[0-9]* ; do logfile="${LOCKDIR_SYSTEM}/""`basename ${f}`" ; n=x$n ; done case $n in ### changed ### xx*) echo Warning: multiple logs for $DEV : ; ls ${DEVN}.[0-9]* ;; xx*) echelon "Warning: multiple logs for $DEV `ls ${DEVN}.[0-9]*`" ;; esac case $logfile in ### changed ### *\*) echo no fax answer process for device $DEV ; break ;; *\*) echelon "no fax answer process for device $DEV" ; break ;; esac efaxpid=`echo $logfile | sed -e "s/${DEVN}\.//g"` case $cmd in # fax start - remove stop file so fax answer will continue start) if [ ! -w . ] ; then echelon "can't write `pwd`" ; break ; fi $RM ${DEVN}.stop break ;; # fax stop - make a stop file and kill current fax answer daemon stop) if [ ! -w . ] ; then echelon "can't write `pwd`" ; break ; fi touch ${DEVN}.stop echelon "stopping fax daemon for ${DEV}, pid=$efaxpid" kill -HUP $efaxpid break ;; # fax status - display pid and log file for current daemon st*) if [ -f ${DEVN}.stop ] ; then stat="(set to stop)" ; fi if ps -u $efaxpid 2>/dev/null ; then : else echelon "NOT ACTIVE (last daemon was $efaxpid)" fi ### changed ### echo echelon "from: ${logfile}" ### echo egrep "Warning|Error|starts|activity|opened|received -|done" $logfile case $# in 0) ;; *) echelon "---------------" ; sleep $1 ; exec $FAX status $1 ;; esac break ;; esac # common section ;; # fax makefont : rasterize a PS font into a 256-character-wide bitmap makefont) if [ $# -lt 5 ] then echo Usage: fax makefont fontname fontsize \ cellwidth cellheight filename echo "(cellwidth and cellheight in pixels, fontsize in points)" echo "Example: fax makefont Courier-Bold 8 16 24 efaxfont" echo "will make an 8pt font (there are about 3 pixels per pt)" exit 1 ; fi FNTFMT=pbmraw # format for font files # FNTFMT=tiffg3 # smaller, available with Ghostscript 3.x or later pelwidth=`expr 256 \* $3` gs -q -sDEVICE=$FNTFMT -r204x196 -g${pelwidth}x$4 \ -sOutputFile=$5 - </dev/null if [ ! -r ${FileOutName} ] ; then echelon "Can't read $FileOutName" ; ERR=2 ; break ; fi read x <$1 ### added cd "${FAXOUTDIR}" case $x in %!*|?%!*) echelon "$1 is postscript..." # GS can't deal with long paths so we 'cd' ### ( cd $DIRNAME ; \ ( $GS -q -sDEVICE=tiffg3 -r$RES -dNOPAUSE -dSAFER \ -sOutputFile=$FileOutName.%03d \ -sPAPERSIZE=$PAGE \ $BaseName /dev/null ) ;; II*|MM*|P4*) echelon "$1 is an image file..." $EFIX -ve -otiffg3 -p$PAGEDIM -r$RES -n $FileOutName.%03d $BaseName ;; *) echelon "$1 is text..." $EFIX -ve -otiffg3 -p$PAGEDIM -r$RES -n $FileOutNam.%03d $TEXTFONT $BaseName ;; esac break ;; # fax send : fax files to given number, converting first if necessary s*) case $# in 0) echelon "missing phone number to call" ; ERR=2 ; break ;; esac # look up names case $1 in [A-Za-z]*) for f in $DIRFILES ; do if [ -r $f ] ; then TELNO=`$LOOKUP` ; fi case "$TELNO" in '') continue ;; *) break ;; esac ; done case "$TELNO" in '') echelon "Name lookup for $1 failed" ; ERR=2 ; break ;; *) echelon "Lookup: $1 = $TELNO" ;; esac ;; *) TELNO="$1" ;; esac shift case "$TO" in '') TO="$TELNO" ;; *) ;; esac TELNO=`echo ${TELNO} | sed "s/[ ()][ ()]*//g"` # handle manual dialing and number->dial string conversions case "$TELNO" in -m*) MANINIT="-jX3" ; TELNO="" ;; +*) TELNO=`echo $TELNO | $TELCVT` ;; esac case $TELNO in '') ;; *) TELNO="${DIALPREFIX}${TELNO}${DIALSUFFIX}" ;; esac ### added: copy files to send into FAXOUTDIR and process them there FILES="" for f in $* ; do case $f in -) FILES="$FILES -" ; continue ;; esac ; if [ ! -r $f ] ; then echelon "can't read file $f" ; ERR=2 ; break 2 ; fi case $f in *.[0-9][0-9][0-9]) FILES="$FILES $f" ;; # skip image files *) filebasename="`basename $f`" cp -f $f "$FAXOUTDIR""/""$filebasename" &>/dev/null if [ ! -r "${FAXOUTDIR}/${filebasename}" ] ; then echelon "file ${FAXOUTDIR}/${filebasename} cannot be acessed" ; ERR=2 ; break 2 ; fi ;; esac ; done ### now process all files in FAXOUTDIR # use `fax make' to convert files if they need to be updated FILES="" allFileBaseNames="" for finp in $* ; do f="$FAXOUTDIR""/""`basename $finp`" allFileBaseNames="${allFileBaseNames}${f} " case $f in -) FILES="$FILES -" ; continue ;; esac if [ ! -r $f ] ; then echelon "can't read file $f" ; ERR=2 ; break 2 ; fi case $f in *.[0-9][0-9][0-9]) FILES="$FILES $f" ;; # skip image files *) if echo ${f}.001: $f \; x | make -r -q -f - ; then echelon ${f}.nnn" is up-to-date" ; else $RM ${f}.[0-9][0-9][0-9] $FAX make $OPT $f ; fi if [ -r $f.001 ] ; then FILES="$FILES $f.[0-9][0-9][0-9]" ; else # something's wrong, catch it later FILES="$FILES $f.001" ; fi ;; esac ; done # check that all files are OK for f in $FILES ; do case $f in -) continue ;; esac if [ ! -r $f ] ; then echelon "can't read file $f" ; ERR=2 ; break 2 ; fi ; done # send it for s in 0 $FAILRETRIES ; do case $s in 0) ;; *) echelon "Will try again in $s seconds" ; sleep $s ;; esac ### changed theSTAMP=`$TSTAMP` theSTAMP="fax_at_"${theSTAMP}"_to_"${TELNO} logfile=${LOGDIR}"/""${theSTAMP}"".log" for t in 0 $BUSYRETRIES ; do case $t in 0) ;; *) echelon "Will try again in $t seconds" ; sleep $t ;; esac DATE=`eval "$DATECMD"` eval HDR=\"$HDR\" $NICE $EFAX -v "$VERB" -v "$VERBLOG" \ -d/dev/$DEV $LOCK $INIT $SPKR \ $CLASSINIT $FCINIT $TXINIT \ $TXCAP -l "$FROM" $RESET $HDRFONT -h "$HDR" \ $MANINIT -t "$TELNO" $FILES >$logfile ERR=$? case $ERR in ### 0) break 2 ;; 0) cp -f ${logfile} "${logfile}.SENT_OK" &>/dev/null ; ### in case it was busy before $RM ${logfile} "${logfile}.FAILURE" &>/dev/null ; SENT="" ; FILES="" ; break 2 ;; 1) echelon "Busy..." ; ### in case busy stays or error will occur cp -f ${logfile} "${logfile}.FAILURE" &>/dev/null ;; *) echelon "There were errors (see ${logfile}.FAILURE)." ; cp -f ${logfile} "${logfile}.FAILURE" &>/dev/null ; break ;; esac ; done # BUSYRETRIES SENT=` sed -n -e '/sent ->/s/^.*-> \([^ ]*\).*/\1/p' $logfile` FILES=`sed -n -e '/failed ->/s/^.*-> \([^ ]*\).*/\1/p' $logfile` ### if SENT != "" not all files have been sent ### if FILES != "" FILES contains list of not successful sent ...[0-9][0-9][0-9] -files ### -> (try again to sent failed files until failretries) case $SENT in '') break ;; esac case $FILES in '') break ;; esac echelon "Failed..." ; ### logfile of try has now postfix "FAILURE" ### next Failretry will have different STAMP-> different logfile-name $RM ${logfile} &>/dev/null ; done ### FAILRETRIES ## needed for success (break 2), logfile has postfix SENT_OK $RM ${logfile} &>/dev/null ; ### rename all not successful sent .nnn-files to ...nnn.STAMP.ERROR_NOT_SENT.tiff for fy in ${FILES} ; do mv -f ${fy} "${fy}.${theSTAMP}.ERROR_NOT_SENT.tiff" &>/dev/null ; done ### save all "source"-files in any case (sent or not) to basename.SRC.TSTAMP ### (append "SRC" as filler to have a nice dir-listing) for fy in ${allFileBaseNames} ; do mv -f ${fy} "${fy}.SRC.${theSTAMP}.ps" &>/dev/null ### the remaining files in FAXOUTDIR must be ...nnn-files, which are successful sent -> delete ftx="${fy}"".""[0-9][0-9][0-9]" for fdel in ${ftx} ; do if [ "${fdel}" != "${ftx}" ] ; then $RM ${fdel} &>/dev/null ; fi ; done ; done break ;; # fax hangup : hang up the phone hangup*) $NICE exec $EFAX -v $VERB -d/dev/$DEV $LOCK -iZ -T break ;; # fax fone : open modem device and exec fone script fone) cd $FAXDIR case $? in 0) ;; *) echelon "cannot cd to $FAXDIR" ; break ;; esac $NICE exec $EFAX -v $VERB -d/dev/$DEV $LOCK $INIT \ -j#CLS=8 -a#VLS=1 -e "$VCMD $*" break ;; ### added ### POLL - ADDED TO MAKE EFAX DIAL WITH "t"-Parameter ### e.g.: fax poll "0123456789,,,78,*1*2#" ### ### to issue "efax [...] -t "0123456789,,,78,*1*2#" poll) cd $FAXDIR case $? in 0) ;; *) echelon "cannot cd to $FAXDIR" ; break ;; esac ### added ### (same "lookup" as in send-routine) # look up names case $1 in [A-Za-z]*) for f in $DIRFILES ; do if [ -r $f ] ; then TELNO=`$LOOKUP` ; fi case "$TELNO" in '') continue ;; *) break ;; esac ; done case "$TELNO" in '') echelon "Name lookup for $1 failed" ; ERR=2 ; break ;; *) echelon "Lookup: $1 = $TELNO" ;; esac ;; *) TELNO="$1" ;; esac shift case "$TO" in '') TO="$TELNO" ;; *) ;; esac TELNO=`echo ${TELNO} | sed "s/[ ()][ ()]*//g"` # handle manual dialing and number->dial string conversions case "$TELNO" in -m*) MANINIT="-jX3" ; TELNO="" ;; +*) TELNO=`echo $TELNO | $TELCVT` ;; esac case $TELNO in '') ;; *) TELNO="${DIALPREFIX}${TELNO}${DIALSUFFIX}" ;; esac ############################################################### ### changed # case $1 in '') file=`$TSTAMP` ;; *) file=$1 ;; esac file=`$TSTAMP`"_"$1 # logfile=${file}.log logfile=${LOGDIR}"/"`basename ${file}".log"` file=${FAXDIR}"/"`basename ${file}` $NICE $EFAX -v "$VERB" -v "$VERBLOG" -d/dev/$DEV $LOCK $INIT $SPKR \ $CLASSINIT $FCINIT $RXINIT \ $RXCAP -l "$FROM" $RESET \ -r $file -t "$TELNO" >$logfile ### POLLNUMBER ERR=$? case $ERR in 0) $RM $logfile ; break ;; 1) echelon Busy... ;; *) echelon "There were errors (see ${logfile})." ; break ;; esac break ;; # fax (rm|print|view) commands possibly on files in spool directory rm|p*|v*) # common code # switch to spool directory if first file is found there ### changed ### use _only_ FAXDIR to keep consistency cd ${FAXDIR} thepwd="`pwd`" SourceDir="`dirname ${thepwd}/.`" #for f in "`basename $1`" ; do # if test -r $f ; then cd $FAXDIR ; break ; fi #done for fx in $* ; do ### added f="${SourceDir}/""`basename $fx`" ## canonical filename ### added ### work around rm-parameters like "*" to ONLY handle files inside FAXDIR dirnameX="`dirname $f`" if [ ${dirnameX} = ${FAXDIR} ] ; then case $cmd in rm) # fax rm : delete files if $RM $SourceName ; then echelon "deleted $SourceName" ; fi ;; p*) # fax print : print files echelon "$SourceName ... " eval "$PRINT | $PRCMD" ;; v*) # fax view : display images echelon "$SourceName ... " eval "$VIEW | $VIEWCMD" ;; esac ; fi ; done break ;; # fax [receive] : answer phone now and receive fax files r*) case $1 in '') file=`$TSTAMP` ;; *) file=$1 ;; esac ### changed # logfile=${file}.log logfile=${LOGDIR}"/"`basename ${file}`".log" file=${FAXDIR}"/"`basename ${file}` $NICE $EFAX -v "$VERB" -v "$VERBLOG" -d/dev/$DEV $LOCK $INIT $SPKR \ $CLASSINIT $FCINIT $RXINIT \ $RXCAP -l "$FROM" $RESET \ -r $file >$logfile ERR=$? case $ERR in 0) $RM $logfile ; break ;; 1) echelon "Busy..." ;; *) echelon "There were errors (see ${logfile})." ; break ;; esac break ;; # fax new : create a cover page for a fax (needs work) new) ### added ### create new files only in cd ${FAXOUTDIR} fname=${1-new.fax} DATE=`date "+%B %d %Y"` cat >$fname 2>/dev/null << EOF ________________________________________________ FAX COVER PAGE ________________________________________________ To: x fax: ________________________________________________ From: $NAME fax: $FROM Date: $DATE Pages: 1 (including this page) ________________________________________________ EOF ${VISUAL-${EDITOR-vi}} $fname break ;; # fax help : show command arguments ### added: line: fax poll telephone-number -\?|\?|-h*|h*) cat 1>&2 <