asteriskとiaxmodem/hylafaxを連携してFAXサーバ機能を作ってみる。asteriskの環境はすでにあるものとする。
iaxmodemのインストール
ユーザ・グループ登録
% sudo groupadd -r uucp
% sudo useradd -r -g uucp -d /var/spool/uucp -s /sbin/nologin -c "UUCP daemon" uucp
必要なパッケージのインストール
% sudo dnf -y group install development-tools
% sudo dnf -y install libtiff-devel spandsp-devel
ixmodemのインストール
ソースのダウンロードと展開
% cd ~/src
% wget https://downloads.sourceforge.net/project/iaxmodem/iaxmodem/iaxmodem-1.3.5.tar.gz
% gzip -dc iaxmodem-1.3.5.tar.gz | tar xvf -
libiax2のインストール
% cd iaxmodem-1.3.5/lib/libiax2/
% ./configure
% make
% sudo make install
spandspのインストール(ちょっと時間がかかる)
% cd ../spandsp/
% ./configure
% make
% sudo make install
ライブラリの登録
以下のファイルに、/usr/local/libを記入する。つづいてldconfigコマンドを実行する。
% sudo vi /etc/ld.so.conf.d/iaxmodem-x86_64.conf
% sudo ldconfig
iaxmodem本体のインストール
% ~/src/iaxmodem-1.3.5
% ./build
% sudo cp -p iaxmodem /usr/local/sbin/
iaxmodemの設定
configのテンプレートを/etc/iaxmodemにコピーする。
% sudo mkdir -p /etc/iaxmodem
% sudo cp -p iaxmodem-cfg.ttyIAX /etc/iaxmodem/ttyIAX0
/etc/iaxmodem/ttyIAX0を以下の内容で作成する。
device /dev/ttyIAX0
owner uucp:uucp
mode 660
port 4570
refresh 300
server 127.0.0.1
peername iaxmodem0
secret password
codec slinear
asteriskの設定
/etc/asterisk/iax.confに以下の定義を追加する。iaxmodem0やsecretは/etc/iaxmodem/ttyIAX0と合わせる。
[iaxmodem0]
type=friend
username=iaxmodem0
secret=password
host=dynamic
disallow=all
allow=ulaw
allow=slinear
requirecalltoken=no
context=from-iaxmodem
/etc/asterisk/extensions.confに以下の行を追加する。
[from-iaxmodem]
; iaxmodem
; 内線のみ
exten => 2290,1,Dial(PJSIP/${EXTEN}@to-siteB)
exten => 1290,1,NoOp(--- FAX Detected! Receiving... ---)
same => n,Set(FAXFILE=/var/spool/asterisk/fax/${STRFTIME(${EPOCH},,%Y%m%d-%H%M%S)}.tif)
same => n,ReceiveFAX(${FAXFILE},f)
same => n,NoOp(--- FAX Receive Status: ${FAXSTATUS} ---)
same => n,Hangup()
exten => _X.,1,Hangup()
asteriskの再起動
% sudo systemctl restart asterisk
systemdへの登録
以下の内容で/usr/lib/systemd/system/iaxmodem@.serviceを作成する。
[Unit]
Description=IAXmodem iinstance for %I
# Asteriskとネットワークが起動した後に実行する
After=network.target asterisk.service
Wants=asterisk.service
Requires=asterisk.service
[Service]
Type=simple
# iaxmodemバイナリのパス(環境に合わせて which iaxmodem 等で確認してください)
ExecStart=/usr/local/sbin/iaxmodem %I
# プロセスが落ちた場合は5秒後に自動再起動
Restart=always
RestartSec=5s
# ログの識別子
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=iaxmodem-%I
[Install]
WantedBy=multi-user.target
つづいて有効化を行う。
% sudo systemctl daemon-reload
% sudo systemctl enable iaxmodem@ttyIAX0
% sudo systemctl start iaxmodem@ttyIAX0
確認
% sudo asterisk -rx "iax2 show peers"
hylafaxのインストール
tmpfsの設定
% sudo vi /etc/tmpfiles.d/hylafax.conf
以下の内容を記述する。
d /run/lock/lockdev 0775 root uucp - -
再起動するか、以下のコマンドを実行して反映する。
% sudo systemd-tmpfiles --create /etc/tmpfiles.d/hylafax.conf
hylafaxのインストール
% sudo dnf -y install hylafax+
% sudo dnf -y install hylafax+-client
ユーザ登録
% sudo faxadduser faxuser
faxsetupの実行
% sudo faxsetup
間違えた場合は「sudo vi /var/spool/hylafax/etc/config.tty*」で修正する
プロセスの有効化・起動
/usr/lib/systemd/system/hylafax-faxgetty@.serviceを以下の内容で入れかえる。
[Unit]
Description=HylaFAX faxgetty for %I
# iaxmodemが起動した後にfaxgettyを動かす
After=network.target iaxmodem@%I.service
Requires=iaxmodem@%I.service
[Service]
Type=simple
# 頭の「-」を外し、エラー時のログを残りやすくします
ExecStart=/usr/sbin/faxgetty %I
Restart=always
RestartSec=5s
[Install]
# getty.targetではなく、通常のマルチユーザーモードに紐付けます
WantedBy=multi-user.target
コマンド実行
% sudo systemctl daemon-reload
% sudo systemctl enable hylafax-faxq
% sudo systemctl enable hylafax-hfaxd
% sudo systemctl enable hylafax-faxgetty@ttyIAX0
% sudo systemctl start hylafax-faxq
% sudo systemctl start hylafax-hfaxd
% sudo systemctl start hylafax-faxgetty@ttyIAX0
FAX送信テスト
sendfaxで送信・受信を行う。
クライアントソフトでの送信もできた。
コメント