FaxServer using Asterisk: Difference between revisions

From Alpine Linux
(Draft notes about fax server)
 
(More draft notes about asterisk as faxserver)
Line 1: Line 1:
{{Draft|This is a experimental page to see if this could replace a more complex setup using Asterisk+IAXmodem+hylafax}}
{{Draft|This is a experimental page to see if this could replace a more complex setup using Asterisk+IAXmodem+hylafax}}
This document aims to create a as simple as possible to setup fax server to send and receive faxes using {{pkg|asterisk}} and {{pkg|asterisk-fax}}.
This document aims to create a as simple as possible to setup fax server to send and receive faxes using {{pkg|asterisk}} and {{pkg|asterisk-fax}}.
 
__NOTOC__
= Installation =
= Installation =
This wiki-doc is based on [http://www.alpinelinux.org/downloads Alpine Linux 2.6] ''(but might also work on version 2.1.3 or higher)''
This wiki-doc is based on [http://www.alpinelinux.org/downloads Alpine Linux 2.6] ''(but might also work on version 2.1.3 or higher)''
Line 13: Line 13:
* iptables
* iptables


= Configuring Asterisk =
= Configure email =
=== Install required packages ===
We will use the package {{pkg|email}} to send the faxes by email to various recipients. Lets start by installing the package
{{cmd|apk add email}}
 
==== General configuration ====
* Edit the appropriate file
{{cmd|vi /etc/email/email.conf}}
{{tip|Work with your SMTP provider to set the appropriate settings. Most likely you will want to
* Change the variables <code>SMTP_SERVER</code>, <code>SMTP_PORT</code>, <code>MY_NAME</code>, <code>MY_EMAIL</code>, <code>ADDRESS_BOOK</code>
* Comment out the variable <code>SIGNATURE_FILE</code>
}}
 
==== Address book ====
* Edit the appropriate file ''(In this example we assume you did not change the value of <code>ADDRESS_BOOK</code> variable).
{{cmd|vi /etc/email/email.address.template}}
* Define some email addresses that suits your needs.<BR>The upcoming {{pkg|asterisk}} config assumes that you have some predefined records in this address book. Example:
{{cat|/etc/email/email.address.template|# Individual email addresses
single:joe          {{=}} joe@foo.bar
single:jeff        {{=}} jeff@foo.bar
single:jill        {{=}} jill@foo.bar
 
# Group that will receive error reports
group: grp-support  {{=}} joe, jeff
 
# Group that will receive faxes originated to extension 12345
group: grp-12345    {{=}} joe, jill
}}
 
==== Test functionality ====
When you done your {{pkg|email}} configuration you can test this by running commands like this:
{{cmd|email -s "testmail" -b jeff}}
 
= Configure Asterisk =
There are multiple ways to configure Asterisk. This document only describes a very basic setup which you might want to modify based on your needs. But by following this document, you should have a fully functional fax-server using only {{pkg|asterisk}} and {{pkg|asterisk-fax}}.
There are multiple ways to configure Asterisk. This document only describes a very basic setup which you might want to modify based on your needs. But by following this document, you should have a fully functional fax-server using only {{pkg|asterisk}} and {{pkg|asterisk-fax}}.


Line 19: Line 52:
At this stage your Alpine Linux only holds some basic packages for base functionallity. We will need to install some extra packages in order to get the fax functionallity.
At this stage your Alpine Linux only holds some basic packages for base functionallity. We will need to install some extra packages in order to get the fax functionallity.
{{cmd|apk add asterisk asterisk-fax}}
{{cmd|apk add asterisk asterisk-fax}}
During this wiki doc, we will use ({{pkg|vim}} as the tool to create and edit files, so we need to install it (we will remove the  
 
==== General setup ====
Set some general settings
* Edit the appropriate file
{{cmd|vi /etc/asterisk/asterisk.conf}}
 
* Copy this content to the file
{{cat|/etc/asterisk/asterisk.conf|[global]
astetcdir {{=}}> /etc/asterisk
astmoddir {{=}}> /usr/lib/asterisk/modules
astvarlibdir {{=}}> /var/lib/asterisk
astspooldir {{=}}> /var/spool/asterisk
astrundir {{=}}> /var/run/asterisk
astlogdir {{=}}> /var/log/asterisk
astdbdir {{=}}> /var/lib/asterisk
astkeydir {{=}}> /var/lib/asterisk
astdatadir {{=}}> /var/lib/asterisk
astagidir {{=}}> /var/lib/asterisk/agi-bin
}}


==== Load appropreate modules ====
==== Load appropreate modules ====
Asterisk needs some modules to be able to handle fax.
Asterisk needs some modules to be able to handle fax.
* Edit {{path|/etc/asterisk/modules.conf}} {{cmd|vi /etc/asterisk/modules.conf}}
* Edit the appropriate file
{{cmd|vi /etc/asterisk/modules.conf}}
 
* Copy this content to the file
{{cat|/etc/asterisk/modules.conf|[modules]
autoload{{=}}yes
}}
{{todo|Try changing this so we don't load more modules than we need}}
 
==== Enable SIP ====
* Edit the appropriate file
{{cmd|vi /etc/asterisk/sip.conf}}
 
* Copy this content to the file
{{cat|/etc/asterisk/sip.conf|[general]
context{{=}}fax_incoming            ; Default context for incoming calls
allowoverlap{{=}}no                ; Disable overlap dialing support. (Default is yes)
bindport{{=}}5060                  ; UDP Port to bind to (SIP standard port is 5060)
; bindport is the local UDP port that Asterisk will listen on
bindaddr{{=}}0.0.0.0                ; IP address to bind to (0.0.0.0 binds to all)
srvlookup{{=}}yes                  ; Enable DNS SRV lookups on outbound calls
disallow{{=}}all                    ; First disallow all codecs
allow{{=}}ulaw ; Allow codecs (in order of preference)
allow{{=}}alaw ; Allow codecs (in order of preference)
udpbindaddr{{=}}0.0.0.0
}}
 
==== Configure dialplan ====
* Edit the appropriate file
{{cmd|vi /etc/asterisk/extensions.ael}}
 
* Copy this content to the file
* Copy this content to the file
{{cat|/etc/asterisk/modules.conf|modules
{{cat|/etc/asterisk/extensions.ael|context fax_incoming {
autoload=yes
  _X. {{=}}> {
    Set(FAXDATE{{=}}${STRFTIME(,,%Y%m%d%H%M%S)});
    Set(FAXFILE{{=}}/tmp/fax_${EXTEN}_${FAXDATE}.tif);
    Answer();
    Wait(1);
    ReceiveFax(${FAXFILE},f);
    Verbose(3,- Fax receipt completed with status: ${FAXSTATUS});
    if ("${FAXSTATUS}" {{=}} "FAILED") {
      Set(DEBUGINFO\nFAXSTATUS: ${FAXSTATUS}\nFAXERROR: ${FAXERROR}\nLOCALSTATIONID: ${LOCALSTATIONID}\nLOCALHEADERINFO: ${LOCALHEADERINFO}\nREMOTESTATIONID: ${REMOTESTATIONID}\nFAXPAGES: ${FAXPAGES}\nFAXBITRATE: ${FAXBITRATE}\nFAXRESOLUTION: ${FAXRESOLUTION});
      Verbose(3,- Trying to send a email reporting the failure});
      System(echo "${DEBUGINFO}" {{!}} /usr/bin/email -s "Incoming fax for ${EXTEN} failed" grp-support);
      System(/usr/bin/mkdir -p /tmp/fax-failed);
      System(/usr/bin/mv ${FAXFILE} /tmp/fax-failed/);
    } else {
      Verbose(3,- Trying to send a email containing the fax});
      System(/usr/bin/email -s "Incoming fax for ${EXTEN} failed" -b -a ${FAXFILE} grp-${EXTEN});
      System(/usr/bin/mkdir -p /tmp/fax-processed);
      System(/usr/bin/mv ${FAXFILE} /tmp/fax-processed/);
    };
  };
}
}}
}}
==== Permissions ====
For {{pkg|asterisk}} to be able to read the new config files, we need to set the correct permissions to the files
{{cmd|chown -R asterisk:asterisk /etc/asterisk}}
==== Start things up ====
Now its time to start up the services
{{cmd|/etc/init.d/asterisk start}}
Configure {{pkg|asterisk}} to autostart at next reboot
{{cmd|rc-update add asterisk}}

Revision as of 15:00, 2 July 2013

This material is work-in-progress ...

This is a experimental page to see if this could replace a more complex setup using Asterisk+IAXmodem+hylafax
(Last edited by Mhavela on 2 Jul 2013.)

This document aims to create a as simple as possible to setup fax server to send and receive faxes using asterisk and asterisk-fax.

Installation

This wiki-doc is based on Alpine Linux 2.6 (but might also work on version 2.1.3 or higher)

Start by setting up a Alpine Linux base system (you will most likely want to run setup-alpine to setup the most basic settings)

Firewall

You might want to setup a firewall to protect your system. We will not address this task in this document. Some firewall alternatives in Alpine Linux are

Configure email

Install required packages

We will use the package email to send the faxes by email to various recipients. Lets start by installing the package

apk add email

General configuration

  • Edit the appropriate file

vi /etc/email/email.conf

Tip: Work with your SMTP provider to set the appropriate settings. Most likely you will want to
  • Change the variables SMTP_SERVER, SMTP_PORT, MY_NAME, MY_EMAIL, ADDRESS_BOOK
  • Comment out the variable SIGNATURE_FILE

Address book

  • Edit the appropriate file (In this example we assume you did not change the value of ADDRESS_BOOK variable).

vi /etc/email/email.address.template

  • Define some email addresses that suits your needs.
    The upcoming asterisk config assumes that you have some predefined records in this address book. Example:

Contents of /etc/email/email.address.template

# Individual email addresses single:joe = joe@foo.bar single:jeff = jeff@foo.bar single:jill = jill@foo.bar # Group that will receive error reports group: grp-support = joe, jeff # Group that will receive faxes originated to extension 12345 group: grp-12345 = joe, jill

Test functionality

When you done your email configuration you can test this by running commands like this:

email -s "testmail" -b jeff

Configure Asterisk

There are multiple ways to configure Asterisk. This document only describes a very basic setup which you might want to modify based on your needs. But by following this document, you should have a fully functional fax-server using only asterisk and asterisk-fax.

Install required packages

At this stage your Alpine Linux only holds some basic packages for base functionallity. We will need to install some extra packages in order to get the fax functionallity.

apk add asterisk asterisk-fax

General setup

Set some general settings

  • Edit the appropriate file

vi /etc/asterisk/asterisk.conf

  • Copy this content to the file

Contents of /etc/asterisk/asterisk.conf

[global] astetcdir => /etc/asterisk astmoddir => /usr/lib/asterisk/modules astvarlibdir => /var/lib/asterisk astspooldir => /var/spool/asterisk astrundir => /var/run/asterisk astlogdir => /var/log/asterisk astdbdir => /var/lib/asterisk astkeydir => /var/lib/asterisk astdatadir => /var/lib/asterisk astagidir => /var/lib/asterisk/agi-bin

Load appropreate modules

Asterisk needs some modules to be able to handle fax.

  • Edit the appropriate file

vi /etc/asterisk/modules.conf

  • Copy this content to the file

Contents of /etc/asterisk/modules.conf

[modules] autoload=yes
Todo: Try changing this so we don't load more modules than we need


Enable SIP

  • Edit the appropriate file

vi /etc/asterisk/sip.conf

  • Copy this content to the file

Contents of /etc/asterisk/sip.conf

[general] context=fax_incoming  ; Default context for incoming calls allowoverlap=no  ; Disable overlap dialing support. (Default is yes) bindport=5060  ; UDP Port to bind to (SIP standard port is 5060) ; bindport is the local UDP port that Asterisk will listen on bindaddr=0.0.0.0  ; IP address to bind to (0.0.0.0 binds to all) srvlookup=yes  ; Enable DNS SRV lookups on outbound calls disallow=all  ; First disallow all codecs allow=ulaw ; Allow codecs (in order of preference) allow=alaw ; Allow codecs (in order of preference) udpbindaddr=0.0.0.0

Configure dialplan

  • Edit the appropriate file

vi /etc/asterisk/extensions.ael

  • Copy this content to the file

Contents of /etc/asterisk/extensions.ael

context fax_incoming { _X. => { Set(FAXDATE=${STRFTIME(,,%Y%m%d%H%M%S)}); Set(FAXFILE=/tmp/fax_${EXTEN}_${FAXDATE}.tif); Answer(); Wait(1); ReceiveFax(${FAXFILE},f); Verbose(3,- Fax receipt completed with status: ${FAXSTATUS}); if ("${FAXSTATUS}" = "FAILED") { Set(DEBUGINFO\nFAXSTATUS: ${FAXSTATUS}\nFAXERROR: ${FAXERROR}\nLOCALSTATIONID: ${LOCALSTATIONID}\nLOCALHEADERINFO: ${LOCALHEADERINFO}\nREMOTESTATIONID: ${REMOTESTATIONID}\nFAXPAGES: ${FAXPAGES}\nFAXBITRATE: ${FAXBITRATE}\nFAXRESOLUTION: ${FAXRESOLUTION}); Verbose(3,- Trying to send a email reporting the failure}); System(echo "${DEBUGINFO}" | /usr/bin/email -s "Incoming fax for ${EXTEN} failed" grp-support); System(/usr/bin/mkdir -p /tmp/fax-failed); System(/usr/bin/mv ${FAXFILE} /tmp/fax-failed/); } else { Verbose(3,- Trying to send a email containing the fax}); System(/usr/bin/email -s "Incoming fax for ${EXTEN} failed" -b -a ${FAXFILE} grp-${EXTEN}); System(/usr/bin/mkdir -p /tmp/fax-processed); System(/usr/bin/mv ${FAXFILE} /tmp/fax-processed/); }; }; }

Permissions

For asterisk to be able to read the new config files, we need to set the correct permissions to the files

chown -R asterisk:asterisk /etc/asterisk

Start things up

Now its time to start up the services

/etc/init.d/asterisk start

Configure asterisk to autostart at next reboot

rc-update add asterisk