Einrichtung eines Fax-Servers unter Linux
Dieser Beitrag beschreibt die Einrichtung einen Fax-Servers unter Linux. Dazu gibt grundsätzlich genügend Beschreibungen, hier soll jedoch über die einfache Einrichtung hinaus gegangen werden.
Dazu gehört die Erweiterung der Weiterleitung der Faxe mittels E-Mail, die Archivierung der eingegangenen Faxe in einer SQL-Datenbank (MySQL) und Zugriff auf die Datenbank mittels WEB-Browser. Dazu wird das script /etc/mgetty+sendfax/new_fax erweitert.
U.a. wird folgende Software:
mgetty, sendfax, mpack, tar, g3topbm, nconvert, gocr
Ich habe die Software unter SuSE 9.3 mit YaST2 installiert. Die Installation der Software will ich jedoch nicht beschreiben.
Konfiguration des Fax-Servers
Die Konfigurationsdateien befinden sich im Verzeichnis /etc/mgetty+sendfax/.
Davon betrachten wir hier nur die folgenden Dateien
- fax.allow
- faxheader
- faxrunq.config
- faxspool.rules.sample
- mgetty.config
- new_fax
- sendfax.config
- voice.conf
Die Datei mailintro wird zusätzlich für das Programm mpack benötigt und enthält den Text für die Mails, mit denen die Fax-Bilder verschickt werden.
fax.allow
Diese Datei muss von Hand angelegt werden, da sie von der Installation nicht erzeugt wird. Hier werden die Nutzer eingetragen, die Faxe versenden dürfen.
Beispiel:
thomas
faxheader
Hier wird ein Default installiert, der nicht sehr sinnvoll ist. In dieser Datei wird der Kopf der Faxe festgelegt.
Beispiel:
FAX FROM: Thomas Arend +49 4421 983813 TO: @T@ PAGE: @P@ OF @M@
faxrunq.config
# faxrunq.config # # Sample configuration file for "faxrunq" and "faxrunqd" # # valid options: success-send-mail [y/n], failure-send-mail [y/n], # success-call-program <name>, failure-call-program <name>, # maxfail-costly <n>, maxfail-total <n>, # delete-sent-jobs [y/n], acct-log <filename> # # additional options specific to faxrunqd: fax-devices <tty(s)>, # faxrunqd-log <filename>, faxrunqd-keep-logs <n>, # acct-log <filename>, policy-config <filename> # say "y" here if you want a mail to be sent to the sender of the fax # when a fax has been successfully sent, "n" otherwise... (default "y") #success-send-mail n # this states whether a mail should be sent when a fax could not be # transmitted at all... (default "y") #failure-send-mail n # here you can specify a program that will be called for each fax that # has successfully been sent... (default: no program) #success-call-program /usr/lib/mgetty+sendfax/fax-success # and this program is run for each failed fax... (default: no program) #failure-call-program /usr/lib/mgetty+sendfax/fax-fail # how often should faxrunq retry "costly" errors (NO CARRIER, aborted # transmission, whatever - something that did cost telephone bill)? # (default: 3) #maxfail-costly 5 # this is the absolute maximum number of tries for a given fax # (default: 10) #maxfail-total 20 # if you want faxrunq to delete sent faxes completely, set this to "y". # If it is set to "n", faxes will be removed from the queue, but the # files won't be deleted, that is, you can see those faxes with # "faxq -o" (default: "n") #delete-sent-jobs y # accounting log file (default: see beginning of faxrunq/faxrunqd script) #acct-log /var/log/acct.log # The following options are for faxrunqd only: # which devices to use for outgoing faxes, seperated by ":" (default: no tty) # this may be overridden by the -l command line switch fax-devices ttyS0 # log file for faxrunqd (default: see beginning of faxrunqd script) #faxrunqd-log /var/log/faxrunqd.log # number of logfiles to keep around when rolling (default: 3) #faxrunqd-keep-logs 5 # configuration file for policy routing, see faxrunqd man page for # details (default: none, i.e. don't use policy routing) #policy-config /etc/mgetty+sendfax/policy.config
mgetty.config
# # mgetty configuration file # # this is a sample configuration file, see mgetty.info for details # # comment lines start with a "#", empty lines are ignored # ----- global section ----- # # In this section, you put the global defaults, per-port stuff is below # set the global debug level to "4" (default from policy.h) debug 4 # set the local fax station id fax-id 49 175 5624003 # access the modem(s) with 115200 bps speed 115200 rings 1 notify thomas # use these options to make the /dev/tty-device owned by "uucp.uucp" # and mode "rw-rw-r--" (0664). *LEADING ZERO NEEDED!* port-owner uucp port-group uucp port-mode 0664 # use these options to make incoming faxes owned by "root.uucp" # and mode "rw-r-----" (0640). *LEADING ZERO NEEDED!* fax-owner root fax-group uucp fax-mode 0640 # ----- port specific section ----- # # Here you can put things that are valid only for one line, not the others # port ttyS0 debug 9 switchbd 9600 modem-type cls2 # Zoom V.FX 28.8, connected to ttyS0: don't do fax, less logging # #port ttyS0 # debug 3 # data-only y # some other Rockwell modem, needs "switchbd 19200" to receive faxes # properly (otherwise it will fail with "timeout"). # #port ttyS1 # speed 38400 # switchbd 19200 # ZyXEL 2864, connected to ttyS2: maximum debugging, grab statistics # #port ttyS2 # debug 8 # init-chat "" \d\d\d+++\d\d\dAT&FS2=255 OK ATN3S0=0S13.2=1 OK # statistics-chat "" AT OK ATI2 OK # statistics-file /var/log/statistics.ttyS2 # modem-type cls2 # direct connection of a VT100 terminal which doesn't like DTR drops # ("direct" meaning "*no* *modem*". NEVER enable "direct yes" on modem lines!) # #port ttyS3 # direct y # speed 19200 # toggle-dtr n
new_fax
#!/bin/sh # # sample script to automatically convert incoming faxes to pbm, uuencode # and gzip them, and send them to "MAILTO". # (FAX_NOTIFY_PROGRAM in policy.h) # # gert@greenie.muc.de # # $Log: new_fax.mail,v $ # Revision 1.2 2000/07/16 21:18:08 gert # add .gz to file names, for automatic unziping # MAILTO="root" MAILER=/usr/sbin/sendmail PATH=$PATH:/usr/local/bin G3TOPBM=g32pbm # # HUP="$1" SENDER="$2" PAGES="$3" PAGEDIR=`mktemp -d /tmp/fax.XXXXXX` DT=`date +%Y%m%d%H%M%S` shift 3 P=1 while [ $P -le $PAGES ] do FAX=$1 RES=`basename $FAX | sed 's/.\(.\).*/\1/'` PP=`printf %3.3d $P` if [ "$RES" = "n" ] then STRETCH="-s" else STRETCH="" fi $G3TOPBM $STRETCH "$FAX" > $PAGEDIR/${DT}_${PP}.pbm /usr/X11R6/bin/nconvert -in pbm -out gif \ -o $PAGEDIR/${DT}_${PP}.gif \ $PAGEDIR/${DT}_${PP}.pbm shift P=`expr $P + 1` done # Fax Seiten packen pushd $PAGEDIR tar czf $DT.tgz *.pbm *.gif popd # Fax als Mail verschicken. mpack -s "Fax von $SENDER - Seiten $PAGES" -d /etc/mgetty+sendfax/mailintro "$PAGEDIR/${DT}.tgz" thomas exit 0
sendfax.config
# # sendfax configuration file # # this is a sample configuration file, see mgetty.info for details # # comment lines start with a "#", empty lines are ignored # ----- global section ----- # # In this section, you put the global defaults, per-port stuff is below # tell everybody what's going on verbose y # ... and send everything to the log file (quite detailed) debug 5 # which devices to use for outgoing faxes fax-devices ttyS0 # which fax number to transmit to the receiving station fax-id +491755624003 # which command is used to dial out? (Could be ATD, ATDP, ATX3D0W...) #dial-prefix ATD # try transmitting every page three times, continue if 3rd try fails as well max-tries 3 max-tries-continue y # ----- port specific section ----- # # Here you can put things that are valid only for one line, not the others # # Modem on ttyS0 needs special initialization to do h/w handshaking #port ttyS0 # modem-handshake AT&K4 # Modem on ttyS1 doesn't work reliably in class 2.0, use class 2 instead port ttyS0 modem-type cls2
voice.conf
# # Sample voice configuration file # ------------------------------- # # $Id: voice.conf-dist,v 1.11 2002/12/15 19:43:49 gert Exp $ # # This file is read twice: First the program configuration is read and # second the port configuration. This means that generic values at the # beginning of the file will override program values on the second read. # So if you want to make a generic value program dependant, remove it # from the generic part of the config file. # # Watch out! Some options in this file are not yet implemented or only # available with some modems. # # # Generic default values # ---------------------- # part generic # # Possible log levels are: # # L_FATAL 0 # L_ERROR 1 # L_AUDIT 2 # L_WARN 3 # L_MESG 4 # L_NOISE 5 # L_JUNK 6 # voice_log_level 4 # Where stderr of the voice shell script should go. # %s will be replaced by the tty name (like for the vgetty/mgetty log). # If not defined, stderr goes to the modem. voice_shell_log /var/log/vgetty_voice_shell.%s # # Primary voice directory for vgetty. # voice_dir /var/spool/voice # # incoming messages are owned by "root.phone" and mode "rw-rw----" (0660) # phone_owner root phone_group phone phone_mode 0660 # # Location of the flag file for new incoming messages relative to the # primary voice directory. # message_flag_file .flag # # Location where vgetty stores the incoming voice messages relative to # the primary voice directory. # receive_dir incoming # # Directory containing the messages for vgetty (greeting, handling the # answering machine) relative to the primary voice directory. # message_dir messages # # Name of file played before any random or backup message is played. # Can be used, for instance, to play a set of tones to discourage # telemarketers. Defaults to null. #pre_message sit_tones.rmd # # Name of the file in MESSAGE_DIR that contains the names of # the greeting message files (one per line, no white space). # message_list Index # # Filename of a backup greeting message in MESSAGE_DIR (used if # the random selection fails to find a message). # backup_message standard.rmd # # Default port speed. The bps rate must be high enough for the compression # mode used. Note that this is an integer, not one of the Bxxxx defines. # Basically you should select the highest possible speed your modem and # computer support. The default value is 38400. # For V 250 compatibel modems you get the supported speeds with the command # AT+IPR=? (with a terminal program like minicom) # (AT+IPR=0 means autobauding, don't set any other value!) # # WARNING: if you use vgetty, this MUST be the same value as the # setting of "speed <n>" in mgetty.config. If you change one, # change the other one as well! # port_speed 38400 # # Default shell to invoke for shell scripts. Make sure this shell # understands things like funtions, because the scripts rely on this. # The default is "/bin/sh" # voice_shell /bin/sh # # Default port timeout in seconds for a read or write operation. The # default value is 10 seconds. # port_timeout 10 # # Default timeout for a dialout in seconds. The default value is 90 seconds. # dial_timeout 90 # # Delay before sending a new voice command to the modem in milliseconds. # The default is 100 milliseconds. # command_delay 100 # # Minimum length of detected DTMF tones, in milliseconds. This is # currently only supported by ZyXel modems with a ROM release of 6.12 # or above. The default is 30 milliseconds. # dtmf_len 30 # # DTMF tone detection threshold in percent (0% to 100%). Increase this # if the modem erroneously detects DTMF tones, decrease it if it fails to # detect real ones. This is currently only supported by ZyXel modems # with a ROM release of 6.12 or above. The default is 40%. # dtmf_threshold 40 # # Time to wait for a DTMF tone to arrive when recording or waiting # for DTMF input in seconds. The default is to wait for 7 seconds. # dtmf_wait 7 # # In Australia the frequency of the busy signal is the same as the # frequency of the fax calling tone. This causes problems on at least # some modems. They report a fax calling tone, when there is a busy # signal in reality. To help those user, vgetty will ignore any fax # calling tone detected by the modem, when this option is set. # # The following companys suffer from this problem: # - Telstra (formerly Telecom Australia) # - Optus # - Austel (regulatory authority) # # The default is of course off. # ignore_fax_dle false # # Output recorded voice samples without header and expect raw voice # data on input for playback. This feature is turned off by default. # Don't enable it unless you really know, what you are doing! # raw_data false # # This is the default compression mode for vgetty for incoming voice # messages and for the recording option of vm. The mode 0 is a special # mode, that will automatically choose a sane default value for every # modem. The default is 0. # rec_compression 0 # # This is the default recording speed for vgetty for incoming voice # messages and for the recording option of vm. It is the number of samples # per second. The speed 0 is a special speed, that will automatically # choose a sane default value for every modem. The default is 0. # rec_speed 0 # # Silence detection length in 0.1 seconds. If the modem detects silence # for this time, it sends a silence detect to the host. Default is # 7 seconds (70 * 0.1 seconds). # rec_silence_len 70 # # Silence detection threshold in percent (0% to 100%). Increase this value # if you have a noisy phone line and the silence detection doesn't work # reliably. The default is 40%. # rec_silence_threshold 40 # # If REC_REMOVE_SILENCE is enabled, the trailing silence of an incoming # voice message as detected by the modem will be deleted. This might # cause you to miss parts of a message if the silence threshold is # high and the caller is talking very quietly. To be on the safe side, # don't define this. This feature is turned off by default. # rec_remove_silence false # # Maximum recording length in seconds. Hang up if somebody talks # longer than this. Default is 5 minutes (300 seconds). # If this is set to zero, disables recording. # rec_max_len 300 # # Minimum recording length in seconds. Some modems can not detect # data or fax modems, so we use the recording time, to decide, # what it is. This feature is by default disabled. # rec_min_len 0 # # Enable hardware flow in record and playback mode if the modem # supports it. This option is by default on. # do_hard_flow true # # if set, alternate sound to replace standard "beep" tone when # answering the phone. This is null by default -- in that case # the beep specified below will be used instead. (This setting # will not affect the BEEP command given from the shell.) # # beepsound beepsound.rmd # # Frequency for the beep command in Hz. The default is 933Hz. # beep_frequency 933 # # Length for the beep command in msec. The default is 1.5 seconds # (1500 * 0.001 seconds). # beep_length 1500 # # Number of tries to open a voice modem device. The default is 3. # max_tries 3 # # Delay between two tries to open a voice device in seconds. The default # is 5 seconds. # retry_delay 5 # # Default timeout for the voice watchdog. If this timer expires, the # running program will be terminated. The default is 60 seconds. # watchdog_timeout 60 # # Some modems support setting the receive gain. This value can be set in # percent (0% to 100%). 0% is off, 100% is maximum. To use the modem # default value set this to -1. The default is -1. # receive_gain -1 # # Some modems support setting the transmit gain. This value can be set in # percent (0% to 100%). 0% is off, 100% is maximum. To use the modem # default value set this to -1. The default is -1. # transmit_gain -1 # # Usually command echo from the modem should be enabled. Since some modems # sometimes forget this echo, it is disabled by default. Turning this option # off makes things more reliable, but bugs are much harder to trace. So # don't ever think about mailing me a bug report with command echo turned # off. I will simply ignore it. The default is to disable command echo. # enable_command_echo false # # Time in msec for the delay, when no new data are received from the modem. A higher value will decrease # machine load by increasing vgettys reaction time. The default is 10 msec. # poll_interval 10 # # The ML 56k Office, Internet (I), pro and Basic # with actual firmware support 2 commandsets: # The one in Elsa.c wich is autodetected and # the ITU V253 (if you say TRUE here for this modems you also have to set # rec_speed 7200) # Default is FALSE #forceV253 FALSE # # Program specific initializations # -------------------------------- # # # Default values for vgetty # ------------------------- # program vgetty # # Default number of rings to wait before picking up the phone. # # Instead of a number, you can also give a file name, that contains # a single number with the desired number of rings. Vgetty will # automatically append the name of the modem device to the file name. # The file name must be an absolut path starting with a leading "/". # E.g. "rings /etc/rings" and the modem device is ttyS0, will # lead to the file name "/etc/rings.ttyS0". If this file doesn't # exist, vgetty will check for a file without the modem device name # appended. In this example, vgetty would check for /etc/rings. # # Please note, that vgetty forces the number of rings to be at least 2. # This is, because the caller ID information (if available from your # provider) is sent between the first and the second ring. Since we don't # know in advance, if you get CID or not, we stay on the save side. # # If you have compiled mgetty/vgetty with CNDFILE defined in policy.h # then you must use the comandline option -n explained in `man mgetty` # The default is 3 # rings 3 # # Default answer mode when vgetty picks up the phone after incoming # rings. # # Instead of an answer mode, you can also give a file name, that # contains a single line with the desired answer mode. Vgetty will # automatically append the name of the modem device to the file name. # The file name must be an absolut path starting with a leading "/". # E.g. "answer_mode /etc/answer" and the modem device is ttyS0, will # lead to the file name "/etc/answer.ttyS0". If this file doesn't # exist, vgetty will check for a file without the modem device name # appended. In this example, vgetty would check for /etc/answer. # # The default is "voice:fax:data". # answer_mode voice:fax:data # # When switching to data or fax mode, always switch to fax mode and # enable autodetection of data/fax. Some modems report wrong DLE codes # and so the predetection with DLE codes does not work. # force_autodetect false # # If vgetty knows that there are new messages (the flag file exists), # it will turn on the AA lamp on an external modem and enable the toll # saver - it will answer the phone TOLL_SAVER_RINGS earlier than the # default. This feature is turned off by default. # toll_saver_rings 0 # # Should the recorded voice message file be kept even if data, fax or # DTMF codes were detected? If this is set, vgetty never deletes # a recording, if it is not set it will delete the recording, if an # incoming data or fax call is detected or if DTMF codes were send. Also # this should work in nearly every situation, it makes you loose the # recording, if the caller "plays" with DTMF codes to make the message # even more beautiful. This feature is enabled by default. # rec_always_keep true # # The programs defined below get called by vgetty. # # Define an empty program name, if you want to disabled one of those # programs. # # # There are two separate uses for the Data/Voice button on a ZyXEL: # # - If a RING was detected recently, answer the phone with the # answer mode set for this case. # - Otherwise, call an external program to play back messages # # If you don't define button_prgogram, vgetty will always pick up # the phone if Data/Voice is pressed. # # The default value is "". # button_program # # Program called when the phone is answered, this is instead # of the normal behaviour. Don't define this unless you want # to e.g. set up a voice mailbox where the normal answering # machine behaviour would be inappropiate. The C code is probably # more stable and uses less resources. # # The default value is "". # call_program # # Program called when a DTMF command in the form '*digits#' is received. # The argument is the string of digits received (without '*' and '#'). # The default value is "dtmf.sh". # dtmf_program dtmf.sh # # Program called when a voice message has been received. # The argument is the filename of the recorded message. # The default value is "". # message_program # # Should vgetty use the AA LED on some modems to indicate that new # messages have arrived? This is done by setting the modem register # S0 to a value of 255. Some modems have a maximum number of rings # allowed and autoanswer after this, so they can not use this feature. # This option is by default off. # do_message_light false # # * ring_report_delay: # * This value determines the delay in /10 seconds between the falling edge # * of the ring-signal (DRON response) and the RING response. # * This value should be greater than the expected off-time within a distinctive # * ring (DROF response). So says the ITU V.253, but it seems that # * ring_report_delay should be greater than the mentioned DROF AND the following # * DRON, and shorter than the long DROF! #Example with ring_report_delay = 10 (2/10 sec per char): # ^ #ring-pulse | ...____###__##_______###__##_______###__##______.... # | | | | | | | | | | | | | # DRON=6 DRON=6 DRON=6 # DROF=4 DROF=4 DROF=4 # DRON=4 DRON=4 DRON=4 # RING RING # DROF=14 DROF=14 # time ---> # # Default is 15 (1.5 sec) # ring_report_delay 15 # # Default values for vm # --------------------- # program vm # # Voice devices that vm can use e.g. "voice_devices ttyS0:ttyS1". Since # I don't know to which ports your modems are connected, the default is "" # voice_devices # # Timeout for a dialout operation in seconds. The default is 90 seconds. # dialout_timeout 90 # # Timeout for deciding that a dialout call has been answered; if more # than this many 1/10ths of a second have passed since the last ringback, # the modem assumes the call has been answered. Default is 70 (7 sec). # ringback_goes_away 70 # # Timeout for deciding that a dialout call has been answered; if more # than this many 1/10ths of a second have passed without any ringback # the modem assumes the call has been answered. Default is 100 (10 sec). # ringback_never_came 100 # # Default values for the pvf tools # -------------------------------- # program pvf # # There are currently no defaults. # # # Port specific configuration # --------------------------- # # # Here you can optionally set some of the previously set values to different # ones for specific ports. # # E.g. we have a modem on port ttyS0 # port ttyS0 # # And we want it to answer after the first ring and only in data mode. # So we would define: # # rings 1 # answer_mode data # # The commands are commented out, because I don't want to set some port # specific defaults in this sample configuration file. I just want to # show you how to do it. # # Now we set the values for the next port e.g. ttyS5 # port ttyS5 # # And so on for all ports in the system, that need special treatment. # # # Ring type specific configuration # -------------------------------- # # # Here you can optionally set some of the previously set values to different # ones for specific ring types. The following ring types are possible: # # ring - for a normal ring # ring1 - for distinctive ring number 1 # ring2 - for distinctive ring number 2 # ring3 - for distinctive ring number 3 # ring4 - for distinctive ring number 4 # ring5 - for distinctive ring number 5 # virtual - for a virtual ring (kill -USR1 <mgetty pid>) # button - if someone pressed the data/voice button on the modem # # Note: The current mgetty implementation maps the data/voice button # event to a virtual ring event. # # Note: ISDN MSNs will be mapped to distinctive rings in the future. # # E.g. we want to answer the modem on a virtual ring with answer # mode "fax:data". # ring_type virtual answer_mode fax:data # # Or e.g. we have one modem and want to answer with voice on a normal # ring and with fax:data on distinctive ring1. # ring_type ring # rings 6 # answer_mode voice ring_type ring1 # rings 1 # answer_mode fax:data # # The commands are commented out, because I don't want to set some ring # specific defaults in this sample configuration file. I just want to # show you how to do it. # # Note: Setting the number of rings will have no effect until the mgetty # to vgetty interface is changed. # # Note: If you have one modem and distinctive ring, you can simply define # the answer mode directly in this file for the different rings. If you # have more than one modem and you want them to react different on the same # type of ring, you have to define rings and answer_mode as pointers to # files. E.g. # # ring_type ring # # rings /etc/rings/ring # answer_mode /etc/answer/ring # # ring_type ring1 # # rings /etc/rings/ring1 # answer_mode /etc/answer/ring1 # for setting a different set of message files: # message_list Index1 # # and so on. Now you can set up a different number of rings and answer modes # by creating the files: # # /etc/rings/ring - for the default value # /etc/rings/ring.ttyS0 - for the value for device ttyS0 # /etc/rings/ring.ttyS1 - for the value for device ttyS1 # # And the same way you can set the answer modes. #