Fax com Hylafax e IAXModem

repostorios usados:
deb http://ftp.br.debian.org/debian sarge main contrib
#
## Repositorio Debian Stable
deb ftp://ftp.debian.org/debian stable main contrib non-free

deb ftp://ftp.br.debian.org/debian/ stable main
deb-src ftp://ftp.br.debian.org/debian/ stable main

1 – Installation IAXmodem

a – Instalar as lib apt-get -y install g++ libtiff-tools libtiff4 libtiff4-dev
b – Baixar o iaxmodem (http://iaxmodem.sourceforge.net/) e descompactar ele em uma pasta criada no /etc/ (mkdir iaxmodem)
cd /etc
mkdir iaxmodem
wget http://downloads.sourceforge.net/project/iaxmodem/iaxmodem/iaxmodem-1.2.0/iaxmodem-1.2.0.tar.gz?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fiaxmodem%2Ffiles%2Fiaxmodem%2F&ts=1320744773&use_mirror=ufpr

mv iaxmodem-1.2.0.tar.gz\?r\=http\:%2F%2Fsourceforge.net%2Fprojects%2Fiaxmodem%2Ffiles%2Fiaxmodem%2F /etc/iaxmodem-1.2.0.tar.gz
tar -xzvf iaxmodem-1.2.0.tar.gz
cd iaxmodem-1.2.0/

c – Entro em /etc/iaxmodem-“versao” e compilo estático pra não arriscar) incompatibilidade de lib:
cd lib/libiax2;
./configure
make
cd ../spandsp
./configure
make

d – Depois instalar o proprio IAXMODEM, na pasta:
cd /etc/iaxmodem-“versao”
./configure
make

e – Instalando o binário e o initscript do iaxmodem:
cp iaxmodem /usr/bin/
chmod +x /usr/bin/iaxmodem
cp iaxmodem.init.debian /etc/init.d/iaxmodem
chkdupexe –add iaxmodem
chmod +x /etc/init.d/iaxmodem
Depois colocar ele para start no rc2.d (runlevel de acordo com seu SO).
ln -s /etc/init.d/iaxmodem /etc/rc2.d/S50iaxmodem

No debian 6 ou posterior lembrar que o procedimento de start é diferente.
Segue:
Após o comando chmod +x /etc/init.d/iaxmodem
Entrar no diretório cd /etc/init.d/
Editar o iaxmodem colocando o cabeçalho abaixo:
#!/bin/sh

# Startup script for the iaxmodem monitor
#
# This starts the “iaxmodem” tool, which in turn starts
# all of the other iamodem server programs.

### BEGIN INIT INFO
# Provides: iaxmodem
# Required-Start: $remote_fs $network
# Should-Start: $all
# Required-Stop: $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: iaxmodem
# Description: iaxmodem
# (Also monitors the local host.)
### END INIT INFO

Após salvar envia-lo para runlevel (rc2.d)
insserv iaxmodem

veja se apareceu na runlevel ok:
ls /etc/rc2.d/

2 – Instalar o HYLAFAX seguindo:
a – Instalar as lib necessarias:
apt-get -y install libtiff-tools libtiff4 libtiff4-dev gs
b – baixar e compilar no /usr/src (http://www.hylafax.org)
Exemplo:
wget wget ftp://ftp.hylafax.org/source/hylafax-6.0.5.tar.gz
debian:/usr/src# tar xfz hylafax-“versao”
debian:/usr/src# cd hylafax-“versao”
debian:/usr/src/hylafax-4.3.1# ./configure

c – Na primeira pergunta:
Are these ok [yes]?
Colocar o numero 13
Apos colocar A4
Na segunda pergunta
Are these ok [yes]?
Colocar o numero 14
Apos colocar 196
Nas demais colocar YES

Executar:
make
make install (para termino da instalação)

No debian 6 precisei fazer algumas alteraçoes no /etc/init.d/hylafax
Remover o rm /etc/rc2.d/S97hylafax
insserv -r hylafax

Adicionar ao cabeçalho do arquivo /etc/init.d/hylafax
#!/bin/sh

# Startup script for the hylafax monitor
#
# This starts the “hylafax” tool, which in turn starts
# all of the other hylafax server programs.

### BEGIN INIT INFO
# Provides: hylafax
# Required-Start: $remote_fs $network
# Should-Start: $all
# Required-Stop: $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: hylafax
# Description: hylafax
# (Also monitors the local host.)
### END INIT INFO

Dar o comando:
insserv hylafax
Colocar para start depois do iaxmodem:
mv /etc/rc2.d/S17hylafax /etc/rc2.d/S20hylafax

d – Copiar os exemplos de conf para os arquivos.
Colocando as configurões dos modems para o hylafax:
Em (cd /etc/iaxmodem/iaxmodem-“versão”)
cp config.ttyIAX /var/spool/hylafax/etc/config.ttyIAX
cp config.ttyIAX /var/spool/hylafax/etc/config.ttyIAX2
(qntas tu desejar, eu faço 4 para meu fluxo)

Veja o que contém dentro do arquivo:
# $Id: iaxmodem,v 1.1 2006/04/02 23:18:30 darren Exp $

#
# prototype config for the IAXmodem softmodem which uses
# the spandsp soft-DSP library
#
CountryCode: 55
AreaCode: 32
FAXNumber: “3237224004”
LongDistancePrefix: 1
InternationalPrefix: 011
DialStringRules: etc/dialrules
ServerTracing: 1
SessionTracing: 11
RecvFileMode: 0644
LogFileMode: 0644
DeviceMode: 0644
RingsBeforeAnswer: 2
SpeakerVolume: off
GettyArgs: “-h %l dx_%s”
LocalIdentifier: “NothingSetup”
TagLineFont: etc/lutRS18.pcf
TagLineFormat: “From %%l|%c|Page %%P of %%T”
MaxRecvPages: 25
#
#
#
## AvantFAX configuration
#
FaxrcvdCmd: bin/faxrcvd.php
DynamicConfig: bin/dynconf.php
UseJobTSI: true

# Modem-related stuff: should reflect modem command interface
# and hardware connection/cabling (e.g. flow control).
#
ModemType: Class1 # use this to supply a hint

#
# The modem is taken off-hook during initialization, and then
# placed back on-hook when done to prevent glare.
#
ModemResetCmds: “ATH1\nAT+VCID=1” # enables CallID display
ModemReadyCmds: ATH0

Class1AdaptRecvCmd: AT+FAR=1
Class1TMConnectDelay: 400 # counteract quick CONNECT response
Class1RMQueryCmd: “!24,48,72,96” # V.17 fast-train recv doesn’t work well

CallIDPattern: “NMBR=”
CallIDPattern: “NAME=”
CallIDPattern: “ANID=”
CallIDPattern: “NDID=”
# Uncomment these if you really want them, but you probably don’t.
#CallIDPattern: “DATE=”
#CallIDPattern: “TIME=”

Criando as configurações de autenticação no asterisk para o iaxmodem:

cp iaxmodem-cfg.ttyIAX /etc/iaxmodem/ttyIAX
cp iaxmodem-cfg.ttyIAX /etc/iaxmodem/ttyIAX2
etc (qntas desejar)

Exemplo do arquivo:
device /dev/ttyIAX1
owner uucp:uucp
mode 660
port 4571
refresh 3600
server 127.0.0.1
peername iaxfax1
secret 123456
cidname Fax1
cidnumber (32)3722-4004
codec alaw

Obs: Lembrar de sempre trocar o device e as contas iax (peername e secret)

e – Criar os peers no iax.conf do /etc/asterisk
vim /etc/asterisk/iax.conf
[iaxfax1]
username=iaxfax1
type=friend
secret=123456
qualify=no
notransfer=yes
host=dynamic
context=default
callerid=”Fax” <0000>
disallow=all
allow=alaw

[iaxfax2]
username=iaxfax2
type=friend
secret=123456
qualify=no
notransfer=yes
host=dynamic
context=default
callerid=”Fax2″ <0000>
disallow=all
allow=alaw

Salve e dar um reload na cli
asterisk -r
iax2 reload

f – Criando as configurações de autenticação no asterisk para o iaxmodem:

Edite seus arquivos de conf.

Exemplo (/etc/iaxmodem/ttyIAX /etc/iaxmodem/ttyIAX0 etc)
OBS: TROCAR OS CABEÇALHOS /DEV/xxxx

device /dev/ttyIAX
owner uucp:uucp
mode 660
port 4570
refresh 3600
server 127.0.0.1
peername iaxfax1
secret 123456
codec alaw

device /dev/ttyIAX0
owner uucp:uucp
mode 660
port 4571
refresh 3600
server 127.0.0.1
peername iaxfax2
secret 123456
codec alaw

g – colocar as confs nos arquivos (/var/spool/hylafax/etc/config.ttyIAX /var/spool/hylafax/etc/config.ttyIAX0 etc) do tipo:

CountryCode: 55
AreaCode: 33
FAXNumber: 12345678
LongDistancePrefix: 1
InternationalPrefix: 011
DialStringRules: etc/dialrules
ServerTracing: 0xFFF
SessionTracing: 0xFFF
RecvFileMode: 0600
LogFileMode: 0600
DeviceMode: 0600
RingsBeforeAnswer: 1
SpeakerVolume: off
GettyArgs: “-h %l dx_%s”
LocalIdentifier: “IAXmodem”
TagLineFont: etc/lutRS18.pcf
TagLineFormat: “From %%l|%c|Page %%P of %%T”
MaxRecvPages: 200
ModemType: Class1 # use this to supply a hint
Class1AdaptRecvCmd: AT+FAR=1
Class1TMConnectDelay: 400 # counteract quick CONNECT response
ModemResetCmds: AT+VCID=1 # enables CallID display
RingsBeforeAnswer: 3
PagerTTYParity: none
CallIDPattern: “NMBR=”
CallIDPattern: “NAME=”
CallIDPattern: “ANID=”
CallIDPattern: “NDID=”

chown uucp.uucp /etc/iaxmodem/ttyIAX*
chmod 660 /etc/iaxmodem/ttyIAX*

h – Adiciona linhas no inittab para o faxgetty ficar monitorando os dois “modems”…
vim /etc/inittab

#FAXGETTY FICAR MONITORANDO
fax1:2345:respawn:/usr/local/sbin/faxgetty ttyIAX
fax2:2345:respawn:/usr/local/sbin/faxgetty ttyIAX0
fax3:2345:respawn:/usr/local/sbin/faxgetty ttyIAX1
fax4:2345:respawn:/usr/local/sbin/faxgetty ttyIAX2

i – Adiciona linhas no inittab para o iaxmodem conectar aos peers:

# IAXMODEM
IA00:23:respawn:/usr/bin/iaxmodem ttyIAX
IA01:23:respawn:/usr/bin/iaxmodem ttyIAX0
IA02:23:respawn:/usr/bin/iaxmodem ttyIAX1
IA03:23:respawn:/usr/bin/iaxmodem ttyIAX2

Tivemos que criar antes um cache:
vim /var/spool/hylafax/etc/setup.cache
Para após restartar o hylafax -> /etc/init.d/hylafax stop apos etc/init.d/hylafax start
reload do inittab -> init q
restartar o servidor por via de duvidas…
Caso queira ver o processo de recebimento de fax digite:

watch cat /var/spool/hylafax/status/ttyIAX

j – Se possuir digium, alterar o zapata para fazer a deteção de fax entrante:
faxdetect=incoming
E se possuir digivoice:
faxdetection=1

Dar o comando faxsetup caso necessário configurar os ttys novamente.

Precisei fazer um link ln -s /etc/iaxmodem-1.2.0 /etc/iaxmodem
Precisei criar um arquivo de
mkdir /var/log/iaxmodem
touch /var/log/iaxmodem/iaxmodem

l – Comando para verificar se os iaxmodem estão conectados com sucesso:

/usr/bin/iaxmodem ttyIAX
/usr/bin/iaxmodem ttyIAX0
etc
Tem que aparecer algo do tipo:
debian:/home/ulisses# /usr/bin/iaxmodem ttyIAX
[2008-03-25 00:46:42] Modem started
[2008-03-25 00:46:42] Setting device = ‘/dev/ttyIAX’
[2008-03-25 00:46:42] Setting owner = ‘uucp:uucp’
[2008-03-25 00:46:42] Setting mode = ‘660’
[2008-03-25 00:46:42] Setting port = 4576
[2008-03-25 00:46:42] Setting refresh = 3600
[2008-03-25 00:46:42] Setting server = ‘127.0.0.1’
[2008-03-25 00:46:42] Setting peername = ‘iaxfax’
[2008-03-25 00:46:42] Setting secret = ‘123456’
[2008-03-25 00:46:42] Setting codec = alaw
[2008-03-25 00:46:42] Opened pty, slave device: /dev/pts/13
[2008-03-25 00:46:42] Created /dev/ttyIAX symbolic link
[2008-03-25 00:46:42] Registration completed successfully.

Iniciando os serviços:
IAXModem:
/etc/init.d/iaxmodem start
HylaFAX:
Digite faxstat para checar se todos os serviços estão rodando corretamente:
asteriks:~# faxstat
HylaFAX scheduler on asteriks: Running
Modem ttyIAX (+47 33676271): Running and idle

m – Fazer as regras no extensions.conf do asterisk:
Exemplo:
exten => 900,1,Dial(IAX2/iaxfax1/${EXTEN},5,r)
exten => 900,n,Dial(IAX2/iaxfax2/${EXTEN},5,r)
exten => 900,n,Dial(IAX2/iaxfax3/${EXTEN},5,r)
exten => 900,n,Busy()
exten => 900,n,Hangup()

n – Para enviar fax por email ou imprimir:
Criar o conf /var/spool/hylafax/etc/FaxDispatch e jogar dentro dele ..

SENDTO=root@midominio.com;
FILETYPE=pdf;
case “$DEVICE” in
ttyIAX) SENDTO=destino1@midominio.com;;
ttyIAX1) SENDTO=destino1@midominio.com;;
ttyIAX2) SENDTO=destino2@midominio.com;/usr/bin/tiff2ps -a $FILE | lpr -P Laboral;;esac

o – Para enviar fax eh necessário configurar uma saída:
(ou como muitos forçando o codec)
[from-hylafax]
exten => _X.,1,Set(__SIP_CODEC=alaw)
exten => _X.,2,Goto(from-internal,${EXTEN},1)

p – instalar nas estações o programa para envio siga o tutorial abaixo:
Texto abaixo retirado de http://winprinthylafax.sourceforge.net/ ou http://wpkg.org/email2fax

========================================================================================================================================================
PARA INSTALAR O AVANT FAX lembrar de seguir as instalações:

apt-get install apache2-mpm-prefork apache2-utils apache2.2-common
# apt-get install libapache2-mod-php5 libapr1 libaprutil1 libpq4 libsqlite3-0 php5-cli php5-common
# apt-get install mysql-server imagemagick libtiff4-dev netpbm libnetpbm10-dev libungif-bin
# apt-get install libungif4-dev sudo postfix php-mail php-mail-mime php-file php-db php5-mysql
# apt-get install psutils wdiff

cd /usr/src
# wget http://easynews.dl.sourceforge.net/sourceforge/avantfax/avantfax-2.3.0.tgz

# tar zvxf avantfax-2.3.0.tgz
# cd avantfax-2.3.0

Mova o AvantFax para o acesso web e dê permissão:

# mv /usr/src/avantfax-2.3.0/avantfax /var/www/
# chmod -R 777 /var/www/avantfax/tmp /var/www/avantfax/faxes

Renomeie o arquivo original faxrcvd e siga os passos:

# cd /var/spool/hylafax/bin
# mv faxrcvd faxrcvd.old
# mv notify notify.old
# ln -s /var/www/avantfax/includes/faxrcvd.php /var/spool/hylafax/bin/faxrcvd
# ln -s /var/www/avantfax/includes/notify.php /var/spool/hylafax/bin/notify
# mv /usr/bin/faxcover /usr/bin/faxcover.old
# ln -s /var/www/avantfax/includes/faxcover.php /usr/bin/faxcover

Edite create_tables.sql para usar as tabelas no AvantFax:
# vi create_tables.sql

Adicione USE avantfax; no topo do arquivo editado acima.

mysql -p < create_user.sql mysql -p < create_tables.sql Permissões de arquivos: drwxrwxrwx 11 www-data www-data 4096 Abr 27 02:57 avantfax Verificar se tem esses binarios FUNDAMENTAIS ao funcionamento: -rwxr-xr-x 1 root root 10309 Out 26 2008 edit-faxcover -rwxr-xr-x 1 root root 11968 Ago 2 2010 fax2ps -rwxr-xr-x 1 root root 11256 Ago 2 2010 fax2tiff -rwxr-xr-x 1 root root 15032 Out 26 2008 faxalter lrwxrwxrwx 1 root root 39 Dez 27 2010 faxcover -> /var/www/avantfax/includes/faxcover.php
-rwxr-xr-x 1 root root 20804 Out 26 2008 faxcover.old
-rwxr-xr-x 1 root root 58480 Out 26 2008 faxmail
-rwxr-xr-x 1 root root 9428 Out 26 2008 faxrm
-rwxr-xr-x 1 root root 12368 Out 26 2008 faxstat
-rwxr-xr-x 1 root root 21352 Out 26 2008 sendfax

Adicionar em cada /var/spool/hylafax/etc/config.tty
#
## AvantFAX configuration
#
FaxrcvdCmd: bin/faxrcvd.php
DynamicConfig: bin/dynconf.php
UseJobTSI: true

# Adicionar em visudo
(tudo na mesma linha)
apache ALL = NOPASSWD: /sbin/reboot, /sbin/halt,
/usr/sbin/faxdeluser, /usr/sbin/faxadduser -u * -p * *

# Em crontab -e adiocinar

Se der o comando faxstat e pedir senha entao basta remover
usuario pois foi criado usuario e agora solicita senha

faxdeluser nome_do_usuaio
faxdeluser admin
faxdeluser

# runs once an hour to update the phone book
0 * * * * /var/www/avantfax/includes/phb.php
# runs once a day to remove old files
0 0 * * * /var/www/avantfax/includes/remold.php

Mude suas configurações do Apache:

# vi /etc/apache2/sites-enabled/000-default

============================================================================

Para enviar por email instalar primeiro o postfix, sendmail e somente depois o exim4 pois aparentemente o avantfax depende de algum plugin que não consta no exim4 mas se instalar os outros dois primeiramente e apos ocorrer a remocao parcial dele o funcionamento fica perfeito.

============================================================================

Reinicie o Apache:

# /etc/init.d/apache2 restart

Outro tutorial para avant no proprio site: http://www.avantfax.com/install.php
=================================

Installation Instructions
Winprint HylaFAX is a Windows print monitor designed to send its output directly to a HylaFAX Server. Once installed, you can print to a HylaFAX Server from any application, and it will pop up a simple dialog box, allowing you to enter the destination FAX number. It’s not intended to be fancy or all encompassing, just a quick and easy way to send FAXes from any Windows application

It can be downloaded here. To go to the sourceforge pages for this software to comment, report bugs, or get source code, click here.

It is packaged in the form of a Windows Installer, which installs the required sets of .DLL files and registers the monitor with the system. This adds support for a new type of port to your system, called a “WinPrint HylaFAX Port.” Once you’ve successfully installed the files, setup is straightforward, but it has a number of steps. First, you’ll want to create an appropriate PostScript printer using the “Add Printer” button. You want to select a “Local printer,” but since it’s not a physical printer, uncheck the “Automatically detect and install my Plug and Play printer” box.

Next, you’ll be asked what port to use. Select the radio button “create a new port type.” If the installation went well, you should see “Winprint Hylafax” as one of the options. The drop list might scroll, so it may not be obvious that it’s at the bottom of the list. (If it doesn’t appear on the list at all, something went wrong with your installation.)

Next, a box will pop up for you to name the port. The name doesn’t actually matter, but naming it HFAX1: will help to identify it.

Next, select the printer type. Experience has shown that the Apple LaserWriter 12/640 PS is a good choice, and I recommend it. Most any other PostScript printer will probably work.

Of course, name it whatever you want, preferably something that says, “hey, this is going to a FAX machine.”

Do not share the printer. This is rather silly anyway, since you can locally install Winprint HylaFAX on any system that needs it, and it communicates directly with the HylaFAX server. Since it pops up the dialog box asking where to send the FAX job locally, this would be ugly, at best. Also, don’t print a test page, since you’re not done configuring the printer yet.

Right-click on the printer to call up its properties, and select the “Ports” tab. Locate the port you just created.

Press the “Configure Port” button to configure the connection to your HylaFAX server.

Most people who have problems are going to have problems because their HylaFAX server won’t let them connect. Break out your HylaFAX server documentation, and make sure that you have set up the correct permissions, which can be as simple as putting the IP address of your client into /var/spool/fax/etc/hosts.hfaxd. You may not need the username -or- password, in which case, you can leave password blank, but the username is always required, even if it isn’t authenticated.

Okay, now you’re ready to print a test job. When you send anything to this printer, a dialog box will appear:

The FAX number is completely unedited and unverified. It relies on HylaFAX’s dialing rules to make sense of it. As you would expect, the HylaFAX server will send an e-mail confirming delivery (or failure to do so) to the specified e-mail address.

Referencias gerais:

http://www.mail-archive.com/asteriskbrasil@listas.asteriskbrasil.org/msg02953.html
http://www.voip-info.org/wiki/view/Asterisk+IAXmodem
http://www.das-asterisk-buch.de/stable/installation-iaxmodem.html
http://www.das-asterisk-buch.de/stable/installation-hylafax.html
http://www.voip-info.org/wiki/view/Asterisk+IAXmodem

Home


http://iaxmodem.sf.net
http://blog.julianmenendez.es/asterisk-hylafax-iaxmodem
http://winprinthylafax.sourceforge.net/
http://blog.evaristesys.com/?p=24

Deixe um comentário