informatique:telephonie:asterisk

Ceci est une ancienne révision du document !


Asterisk

Exemple :

rasterisk -x "file convert /tmp/file_in.mp3 /tmp/file_out.gsm"
--- chan_sip.c.orig 2007-03-18 20:37:06.000000000 +0000
+++ chan_sip.c 2007-03-23 15:12:40.946029746 +0000
@@ -6890,7 +6890,7 @@
pidfnote = "On the phone";
break;
case AST_EXTENSION_UNAVAILABLE:
- statestring = "terminated";
+ statestring = "confirmed";
local_state = NOTIFY_CLOSED;
pidfstate = "away";
pidfnote = "Unavailable";

Source : http://forums.digium.com/viewtopic.php?f=1&t=78245&start=0 Repos de paquets Debian : http://debian.zionetrix.net/#asterisk

Pour l'appliquer proprement :

echo "export QUILT_PATCHES=debian/patches" > ~/.quiltrc
cd /usr/local/src
apt-get source asterisk
apt-get install packaging-dev
cd asterisk-~~~
quilt push -a
quilt new fix_grandstream_blf_led
quilt add channels/chan_sip.c
vi channels/chan_sip.c  # et faite la modif.
quilt diff # Ca vous montre votre modif
quilt refresh # met à jour le patch
dhc # Met à jour le changelog debian
dpkg-buildpackage # construction des paquets debian dans ../

Free accapare le port UDP 5004 (RTP) pour les freebox non-dégroupé (potentiellement les ports 5006 et 5008 également). Du coup il est impératif de modifier le port d'écoute RTP local du téléphone en 5010 par exemple.

On commence par mettre en place un compte IAX qui sera utilisé par iaxmodem pour se connecter à Asterisk. Pour cela on ajoute dans /etc/asterisk/iax.conf :

[fax1]
type=friend
secret=mypassword
port=4570
host=dynamic
context=internal
disallow=all
allow=ulaw
requirecalltoken=no
qualify=yes

On route ensuite dans le fichier /etc/asterisk/extentions.conf, les appels entrant sur un numéro vers le FAX :

[incoming]

exten => 0102030405,1,Goto(fax-in,fax1)

[fax-in]

exten => fax1,1,Dial(IAX2/fax1)
exten => fax1,n,Hangup()

On l'installe à partir du paquet Debian :

apt-get install iaxmodem

On créé ensuite une instance pour notre fax en créant un fichier /etc/iaxmodem/ttyIAX0 :

device /dev/ttyIAX0
owner uucp:uucp
mode 660
port 4570
refresh 60
server 127.0.0.1
peername fax1
secret mypassword
cidname My Company
cidnumber 0102030405
codec ulaw

On lance le service :

/etc/init.d/iaxmodem start

A partir de la, un iax2 show peers dans la console d'asterisk devrait vous monter qu'iaxmodem est bien connecté.

On installe le serveur hylafax :

apt-get install hylafax-server

On met en place la configuration global dans le fichier /etc/hylafax/config :

#ContCoverPage:         "etc/cover.templ"
#DestControls:          "etc/destctrls"
#DialStringRules:       "etc/dialrules"
#QualifyCID:            "etc/cid"
#QualifyTSI:            "etc/tsi"
ServerTracing:          1
InternationalPrefix:    00

#
## AvantFAX
#
NotifyCmd:      bin/notify.php

On met ensuite en place la configuration du modem dans le fichier /etc/hylafax/config.ttyIAX0 :

CountryCode:            33
AreaCode:               1
FAXNumber:              +33.1.02.03.04.05
LongDistancePrefix:     0
InternationalPrefix:    00
DialStringRules:        etc/dialrules
ServerTracing:          1
SessionTracing:         11
RecvFileMode:           0600
LogFileMode:            0600
DeviceMode:             0600
RingsBeforeAnswer:      1
SpeakerVolume:          off
GettyArgs:              "-h %l dx_%s"
LocalIdentifier:        "My Company"
TagLineFont:            etc/lutRS18.pcf
TagLineFormat:          "%%l|%c|Page %%P sur %%T"
MaxRecvPages:           200
#
#
# Modem-related stuff: should reflect modem command interface
# and hardware connection/cabling (e.g. flow control).
#
ModemType:              Class1          # use this to supply a hint

#
# Enabling this will use the hfaxd-protocol to set Caller*ID
#
#ModemSetOriginCmd:     AT+VSID="%s","%d"

#
# If "glare" during initialization becomes a problem then take
# the modem off-hook during initialization, and then place it
# back on-hook when done.
#
#ModemResetCmds:        "ATH1\nAT+VCID=1"       # enables CallID display
#ModemReadyCmds:        ATH0

Class1AdaptRecvCmd:     AT+FAR=1
Class1TMConnectDelay:   400             # counteract quick CONNECT response

#
# If you have trouble with V.17 receiving or sending,
# you may want to enable one of these, respectively.
#
#Class1RMQueryCmd:      "!24,48,72,96"  # enable this to disable V.17 receiving
#Class1TMQueryCmd:      "!24,48,72,96"  # enable this to disable V.17 sending

#
# You'll likely want Caller*ID display (also displays DID) enabled.
#
ModemResetCmds:         AT+VCID=1       # enables CallID display

#
# The pty does not support changing parity.
#
PagerTTYParity:         none

#
# If you are "missing" Caller*ID data on some calls (but not all)
# and if you do not have adequate glare protection you may want to
# not answer based on RINGs, but rather enable the CallIDAnswerLength
# for NDID, disable AT+VCID=1 and do this:
#
#RingsBeforeAnswer: 0
#ModemRingResponse: AT+VRID=1

# Uncomment DATE and TIME if you really want them, but you probably don't.
#CallIDPattern:          "DATE="
#CallIDPattern:          "TIME="
CallIDPattern:          "NMBR="
CallIDPattern:          "NAME="
CallIDPattern:          "ANID="
#CallIDPattern:          "USER="        # username provided by call
#CallIDPattern:          "PASS="        # password provided by call
#CallIDPattern:          "CDID="        # DID context in call
CallIDPattern:          "NDID="
#CallIDAnswerLength:    4

#
## AvantFAX
#
FaxRcvdCmd:     /var/spool/hylafax/bin/faxrcvd.php
DynamicConfig:  /var/spool/hylafax/bin/dynconf.php
UseJobTSI:      true

On redémarre le serveur Hylafax :

service restart hylafax

On installe les dépendances :

apt-get install libapache2-mod-php5 php5-cli imagemagick netpbm sudo php-mail php-mail-mime php-file php-db php5-mysql psutils wdiff rsync postfix php-net-smtp php-mdb2 php-mdb2-driver-mysql html2ps

On commence par préparer l'arborescence d’installation :

mkdir -p /var/www/empty /var/www/fax/upstream

Télécharger ensuite l'archive tar.gz du projet (je travaille ici avec la version 3.3.3) dans le dossier /var/www/fax/upstream. On extrait ensuite le contenu de l'archive dans le dossier /var/www/fax/avantfax-3.3.3 et on met en place le lien symbolique de la racine web :

cd /var/www/fax/
ln -s avantfax-3.3.3/avantfax public_html

On peut mettre en place ensuite le repos Apache dans le fichier /etc/apache2/sites-available/fax :

<VirtualHost *:80>
        ServerName fax.mycompany.com

        DocumentRoot /var/www/empty

        RedirectMatch ^(.*)$ https://fax.mycompany.com$1

        ErrorLog /var/log/apache2/fax.mycompany.com.error.log
        CustomLog /var/log/apache2/fax.mycompany.com.access.log combined
</VirtualHost>

<VirtualHost *:443>
        ServerName fax.mycompany.com
        ServerAlias fax

        DocumentRoot /var/www/fax/public_html

        SSLEngine On

        ErrorLog /var/log/apache2/fax.mycompany.com.error.log
        CustomLog /var/log/apache2/fax.mycompany.com.access.log combined
</VirtualHost>
Je part ici du principe que la configuration SSL d'Apache est en place. Vous pouvez suivre cette doc pour la mettre en place.

On active ensuite ce VirtualHost :

a2ensite fax
service apache2 reload

Réglons maintenant les privilèges des dossiers/fichiers d'avantfax :

cd /var/www/fax/avantfax-3.3.3/
chmod 0770 avantfax/includes/templates/admin_theme/templates_c/ avantfax/includes/templates/admin_theme/cache/  avantfax/includes/templates/main_theme/templates_c/ avantfax/includes/templates/main_theme/cache/ avantfax/tmp avantfax/faxes
chmod 0755 avantfax/includes/faxcover.php avantfax/includes/faxrcvd.php avantfax/includes/notify.php avantfax/tools/update_contacts.php avantfax/tools/faxcover.php avantfax/includes/avantfaxcron.php avantfax/includes/dynconf.php
chown -R www-data:www-data avantfax/
chown -R www-data:uucp avantfax/tmp avantfax/faxes

On met en place la base de données MySQL :

mysqladmin --default-character-set=utf8 --user='avantfax' --password='M1DBP@ss' create avantfax
mysql --user='avantfax' --password='M1DBP@ss' avantfax < create_tables.sql

On ajoute le modem dans la base de données :

echo 'INSERT INTO Modems (device,alias,contact) VALUES ('ttyIAX0','My Company','fax@mycompany.com');'|mysql --user='avantfax' --password='M1DBP@ss' avantfax

On met en place les scripts utilisés par le serveur Hylafax :

ln -s /var/www/fax/public_html/includes/faxrcvd.php /var/spool/hylafax/bin/faxrcvd.php
ln -s /var/www/fax/public_html/includes/dynconf.php /var/spool/hylafax/bin/dynconf.php
ln -s /var/www/fax/public_html/includes/notify.php  /var/spool/hylafax/bin/notify.php

On met en place la configuration sudo :

echo 'www-data ALL= NOPASSWD: /sbin/reboot, /sbin/halt, /usr/sbin/faxdeluser, /usr/sbin/faxadduser -u * -p *' > /etc/sudoers.d/avantfax
chmod 0440 /etc/sudoers.d/avantfax

On met en place le cron :

echo '0 0 * * * www-data php /var/www/fax/public_html/includes/avantfaxcron.php -t 2' > /etc/cron.d/avantfax

Pour finir, on met en place le fichier de configuration. Pour cela, dans public_html/includes, on commence par copier le fichier local_config-example.php en local_config.php et on adapte :

  • La configuration de l'accès à la base de données : AFDB_USER , AFDB_PASS et AFDB_NAME
  • Utilisateur utilisé pour envoyer les fax : FAXMAILUSER (fax ou faxmaster par exemple)
  • Utilisateur d'apache : WWWUSER (=“www-data”)
  • Mail de l'admin : ADMIN_EMAIL
  • La langue par défaut : $dft_config_lang
  • La société : $FROM_COMPANY
  • Le chemin de l'outils html2ps : $HTML2PS (Pour Debian : /usr/bin/html2ps)
  • La taille des feuilles de papier par défaut : $PAPERSIZE (a4)
  • On modifie la configuration de reporting d'erreur PHP au vue de l'age du code … Pour cela ajouter en fin (ou début de fichier) :
    error_reporting(E_ALL & ~E_DEPRECATED & ~E_STRICT);
L'application force elle même le reporting d'erreur PHP à E_ALL dans le fichier config.php. Avec ce dernier paramètre on viens écraser ce choix non-adapté à l'age du code.

Astuces

Activer le debug

Configuration : $AVANTFAX_DEBUG

Désactiver la fonctionnalité de page de garde

Configuration $SENDFAX_USE_COVERPAGE à false.

Activer l'OCR

Installation de tesseract :

apt-get install tesseract-ocr tesseract-ocr-fra

Configuration :

  • ENABLE_OCR_SUPPORT = true
  • OCR_BINARY = /usr/bin/tesseract
  • OCR_LANGUAGE = fra
  • informatique/telephonie/asterisk.1393939174.txt.gz
  • Dernière modification : 2014/03/04 13:19
  • de bn8