Showing posts with label Asterisk. Show all posts
Showing posts with label Asterisk. Show all posts

Monday, 26 October 2015

vim Remove Comments using REGEX | Remove comments of Asterisk Configuration files

You can try this command:
:g/^\(#\|$\)/d
Or (Use ; for the Asterisk PBX configuration files.)
:g/\v^(#|;)/d
  • \| is for alternation
  • \v is very magic (minimal backslash escape)

Thursday, 10 September 2015

SIPP installation and testing Asterisk with SIPP stress test tool

1. Install required packages
$ sudo apt-get install build-essential libncurses5-dev
2. Download, extract and compile SIPp
$ wget "http://downloads.sourceforge.net/project/sipp/sipp/3.2/sipp.svn.tar.gz?r=&ts=1314783436&use_mirror=puzzle" -O sipp.svn.tar.gz
$ tar -xzf sipp.svn.tar.gz
$ cd sipp.svn
$ make
3. Set up the SIP server
Note these instructions are for configuring the Asterisk open source PBX, for other platforms you will need to consult the documentation.
First, define the SIP peer by adding to the end of sip.conf:
[sipp]
type=friend
context=sipp
host=dynamic
port=6000
user=sipp
canreinvite=no
disallow=all
allow=alaw
allow=ulaw
Next set up some extensions that we will use to test by adding to the end of extensions.conf (this assumes a default Asterisk installation where the demo context exists, if not then point calls at some other context that has e.g. an IVR menu or similar):
[sipp]
exten => 1001,1,Answer
exten => 1001,n,SetMusicOnHold(default)
exten => 1001,n,WaitMusicOnHold(20)
exten => 1001,n,Hangup
exten => 1002,1,Answer
exten => 1002,n,Goto(demo,s,1)
exten => 1002,n,Hangup
Finally load the new configuration into asterisk:
$ asterisk -rx 'module reload'
4. Start testing
There are various simple tests that can be done without creating your own scenarios, such as:
1. Simple concurrent call test
$ ./sipp -sn uac -d 10000 -s 1001 <asterisk's IP address> -l 10
This will execute 10 concurrent calls (the -l parameter) with each call lasting 10s (the -d parameter in ms) to extension 1001. Note that this simple test does not actually establish an RTP connection, and thus does not actually place full load on the system.
2. Testing with media
$ ./sipp -sn uac -d 10000 -s 1002 <asterisk's IP address> -l 10 -mp 5606
This executes 10 concurrent calls, each lasting 10s to extension 1002 using the ulaw codec.
When running SIPp will display a screen showing various statistics such as the number of calls in progress, the number completed and some information about the SIP messages it has sent. It also shows any errors it has received. To stop a test, simply press ‘q’.
By playing around with the duration (-d) and limit (-l) parameters you can normally find the limit of your system’s scalability. It is also often an idea to leave the test running at a reasonable call level for a long period of time, this will help identify any memory leaks or similar that will likely cause problems over time.
Note that while SIPp will verify that an RTP connection is established, it will not check the quality – the simplest way to do this is to set up your call load using SIPp, then make a manual call through the system to check the quality is acceptable.
Notes
  • If the machine you are running SIPp on has multiple network interfaces, it may not correctly identify which interface to use for the outbound traffic – to correct this use the -bind_local option, e.g. to use the IP address 192.168.1.1 for outbound traffic you would add “-bind_local 192.168.1.1
  • If you stop a test without letting all the calls clean up, and then attempt to start another, the new one may report errors as it receives SIP messages from the server relating to calls initiated by the previous test – it’s always best to let a test fully clean up

Wednesday, 24 June 2015

Asterisk behind the NAT setting

Asterisk behind NAT

The Asterisk Server is behind NAT
The Asterisk server could be on the LAN (or in a DMZ) with a NAT firewall between it and the Internet. When it communicates with external peers or devices, the network connections have to pass through the local NAT device.

The remote device that is connecting to Asterisk is behind NAT
Suppose that your Asterisk server is connected directly to the Internet. Provided your system is made reasonably secure (e.g. through firewall rules) there can be significant benefits in having it directly connected to the Internet. However, you are unlikely to be able to control the networking environment of the devices that connect to it. If remote users have IP phones that register with your Asterisk server, it is very likely that those phones will be behind a NAT device at the far end.

Asterisk is behind one NAT and the remote device is behind another
This is an unattractive situation for Asterisk to handle and should generally be avoided if possible. However, it can be made to work provided suitable NAT traversal solutions are applied at both ends.

When the Asterisk server is behind a local NAT router

Settings within the sip.conf file when you have a static IP address

The externip parameter in sip.conf tells Asterisk what the external IP address is for the NAT/firewall/router. This is the address that external devices on the Internet must use to reach the Asterisk server. If you are unsure what this address is, ask your system administrator or open a web browser on the Asterisk server and point it at
http://whatismyip.com
or
http://www.amibehindnat.com

The externhost parameter in sip.conf may be used to tell Asterisk the external address of your NAT/firewall/router in the form of a FQDN. It is an alternative to externip. You must either use externip or externhost, not both. This parameter is the key to solving the NAT problem if your ISP has not allocated you with a static IP address.

The externrefresh parameter in sip.conf works in conjunction with externhost. It tells asterisk how often to query the host name using DNS. I recommend you set it to a higher value than the default - perhaps 600.

The localnet parameter in sip.conf is used to tell Asterisk which addresses are local. This is important because Asterisk will substitute the value given in externip for its own local address whenever it thinks it is communicating with a remote peer or device. The only way it knows that a device is local, is through the IP address of that device being within the range specified by localnet.

For example:
[general]
externip=63.182.70.1
localnet=192.168.0.0/255.255.255.0
localnet=192.168.2.0/255.255.255.0

Note how you can specify several different subnets using the localnet parameter - simply put each one on a new line.

Settings within the sip.conf file when you have a dynamic IP address

Internet Service Providers normally charge extra to provide one or more static IP addresses - the option may not even be available if you have a domestic rather than a business broadband package. If your public IP address is dynamic (allocated by your provider's DHCP service) then you will still be able to use Asterisk behind your firewall provided it supports automatic registration with a Dynamic DNS service such as DynDNS.com. The basic service is free so it is worth a try. First, you must register with DynDNS.com (or one of the alternative dynamic DNS service providers), then instruct your firewall to use the service and finally you must use the externhost parameter to specify your host name.

Don't use externip, but do specify externrefresh and localnet as described above.

I'm using Trixbox/FreePBX. Where do I set these parameters?
Just edit the file /etc/asterisk/sip_general_custom.conf and put the parameters in there, then restart the asterisk service or reboot the machine.

Settings on the local NAT/firewall/router

If you are unable to make configuration changes (or have changes made on your behalf) on the local NAT/firewall/router device, then you are unlikely to be able to make Asterisk work for SIP connections to remote peers and devices. The suggestions given here assume that you do have access to the configuration rules on this device. If not, consider using the IAX protocol instead.

The NAT/firewall/router should be configured to allow inbound UDP connections to your Asterisk server on the primary SIP port (usually 5060). It must also be configured to allow inbound UDP connections to the same ports on the Asterisk server as are defined in the rtp.conf file. The default port range in rtp.conf is 10000 to 20000. However, it is recommended that the range of port numbers assigned for RTP is reduced by editing rtp.conf, changing the parameter settings and then restarting Asterisk. It will usually be sufficient to have a range that is approximately twice the maximum number of simultaneous calls, plus a few on top for good measure.

When configuring your NAT/firewall/router device, you will probably need to find the settings for "port forwarding" or "one-to-one" NAT. Make sure your NAT device does not use port address translation. i.e. if your Asterisk server expects to receive SIP messages on port 5060, make sure you also use port 5060 on the WAN port of your NAT device to forward these messages. Similarly, make sure the same range of port numbers are forwarded on the WAN port for RTP as will receive the RTP on the Asterisk server.

When the remote devices are behind a NAT router

Settings within the sip.conf file
The nat parameter in sip.conf tells Asterisk that the remote device is behind a NAT router. There are a number of options for this parameter, but the most likely to work with NAT'd remote devices is nat=yes. You should set this parameter for each peer or device in sip.conf - i.e. don't simply use a default setting for all peers and devices unless you fully understand the implications of doing so.

The qualify parameter in sip.conf tells Asterisk to send a kind of ping message to the remote device about every 30 seconds. This can be very helpful when connected to a remote device behind NAT because it forces the NAT router to keep the connection open. Normally, NAT routers will automatically close existing connections if there is no activity on them for more than a preset time. The time that must elapse before a connection is dropped will vary from one manufacturer to another, but it will almost always be more than 30 seconds. It also has a another benefit because it allows Asterisk to know if the connection is still working.

For example:
[peer1]
type=peer
nat=yes
qualify=yes


Checking your remote devices
From the Asterisk CLI (Command Line Interface) type the command "sip show peers". This will report back a list of all peers/devices configured in sip.conf and will show if they have registered successfully. It will also show if they are still reachable provided you specified qualify=yes.

Settings on the remote NAT/firewall/router
Very similar rules apply to the configuration of the remote NAT/firewall/router as those described above for the local firewall. However, the settings on the remote firewall need to be matched to the ports used by the remote device. If the remote device is an IP phone you will ideally want to check the phone's configuration and find out what port numbers it uses for SIP messaging (usually UDP port 5060) and for RTP. Then set port forwarding on the remote firewall for those ports.

Fortunately, the solutions available for remote devices, especially IP phones, are more wide ranging than those available for the Asterisk server. Firstly, most modern IP phones will be able to use a STUN server. This is an incredibly useful option and you should certainly try to switch on STUN on all the remote devices if available. STUN can take advantage of symmetrical RTP sessions on the server (i.e. sessions where the server can receive RTP audio on the same port as it uses to send the RTP audio). This option is enabled on your Asterisk server by setting "nat=yes" as described above. Also, many IP phones will recognise and use other NAT traversal techniques including sending "keep-alive" packets after registration (similar to "qualify=yes").

source : smartvox 

Wednesday, 10 June 2015

Collection of Opensource Asterisk Applications

(Source : venturevoip )

Hopefully there are a few programs in the list that even the most seasoned Asterisk professionals have not seen before.

Flash Operator Panel

Flash Operator Panel is a switchboard type application for the Asterisk PBX. It runs on a web browser with the flash plugin. It is able to display information about your PBX activity in real time. The layout is configurable (button sizes and colors, icons, etc). You can have more than 100 buttons active per screen. On the Live Demo there are 28 buttons defined. It also supports contexts: you can have one server running and many different client displays (for hosted PBX, different departments, etc). It can integrate with CRM software, by poping up a web page (and passing the CLID) when a specified button is ringing.

PHP AGI

AGI (Asterisk Gateway Interface) is a way of running programs or scripts which are external to Asterisk. PHP AGI is a library for PHP which simplifies writing AGI scripts.

Web Meetme

Web-MeetMe is a suite of PHP pages to allow for scheduling and managing conferences on an Asterisk PBX. 

Oreka

Oreka is a modular and cross-platform system for recording and retrieval of audio streams. The project currently supports VoIP and sound device based capture. Recordings metadata can be stored in any mainstream database. Retrieval of captured sessions is web based.

FreePBX
FreePBX is a full-featured PBX web application. If you've looked into Asterisk, you know that it doesn't come with any "built in" programming. You can't plug a phone into it and make it work without editing configuration files, writing dialplans, and various messing about. 

FreePBX simplifies this by giving you pre-programmed functionality accessible by a user-friendly web interfaces that allows you to have a fully functional PBX pretty much straight away with no programming required.

FreePBX also comes as a distro

Areski CDR Stats

Asterisk-Stat is a visualisation layer for Asterisk CDR statistics which are pulled from a database. It provides graphs as well as allowing you to get more information on individual calls.





sipsak

sipsak is a small command line tool for developers and administrators of Session Initiation Protocol (SIP) applications. It can be used for some simple tests on SIP applications and devices.

Asterisk PhoneBook

A common shared phone book directory based on CMS/LAMP and build for Asterisk PBX, store name and number into MySQL which will be used by each workstation browser, also by telephones with embedded XML-browser feature.

Asterisk Desktop Assistant

Asterisk Desktop Assistant is a desktop call management application for Windows PCs.� Asterisk Desktop Assistant (ADA) is Digium?s first step towards offering a comprehensive Computer Telephony Integration (CTI) suite.� It makes dialing and handling phone calls simpler and faster by adding click-to-call functionality into popular desktop applications.� It also adds call notifications directly to the Windows desktop.

A2Billing

A2Billing combined with Asterisk now gives any Telecom company a very good reason to consider the A2Billing Soft-Switch over the traditional offerings for TDM and VoIP Soft-Switches as well as wholesale and IP PBX billing, particularly when you consider the cost of A2Billing ? FREE!

AstBill

AstBill is not only a free web-based, user friendly billing interface for Asterisk and VOIP. It is also a Asterisk configuration and GUI management tool and a standardized implementation of Asterisk using REALTIME and static configuration as you please.

OSLEC

Oslec is an open source high performance line echo canceller. When used with Asterisk it works well on lines where the built-in Zaptel echo canceller fails. No tweaks like rxgain/txgain or fxotrain are required. Oslec is supplied as GPL licensed C source code and is free as in speech.

Oslec partially complies with the G168 standard and runs in real time on x86 and Blackfin platforms. Patches exist to allow any Zaptel or DAHDI compatible hardware to use Oslec. It has been successfully tested on hardware ranging from single port X100P FXO cards to dual E1 systems.

AppKonference

AppKonference is a high-performance Asterisk voice/video conferencing module. It's basically a drop in replacement for meetme - although does things a little differently and doesn't require a timing source.

OutCall

OutCALL was designed as a commercial appplication allowing Asterisk users integration with Microsoft Outlook with placing and receiving phone calls.

After over 1000 downloads as a free application, Bicom Systems Ltd. has decided to offer OutCALL in open source format in order to further stimulate development of Asterisk and related open source projects.

VMukti

VMukti is leading Asterisk/ Yate enabled p2p Video IP Communications Suite for Web / PSTN. These serverless broadband ready platform enable OS community to save 90% on capital & operating costs over proprietary software for conferencing & Call Center. 

Note from editor: I've personally never managed to get this working - drop me a line if you do get it all set up and going.

Asterisk-CRM

asterCRM is a call center software for asterisk based VoIP system, also it has some CRM functions. It provides useful features such as pop-up, predictive dialer, click to call, extension status .... astercrm could work with all asterisk based system. 

AsterCC

astercc is a realtime billing solution for asterisk, could work with all kinds of asterisk based system and no need do any change to your original system. astercc could be used for hosted callshop solution, pbx billing solution. 

IAXModem

IAXmodem is a software modem written in C that uses an IAX channel (commonly provided by an Asterisk PBX system) instead of a traditional phone line and uses a DSP library instead of DSP hardware chipsets.

Asterisk PBX Integration Zimlet

Asterisk PBX Integration Zimlet is an Extension for Zimbra Collaboration Suite. The Zimlet does Interface with the Asterisk Manager Interface to integrate with Asterisk PBX. The main focus is dial-on-click for Phone numbers inside Contacts and Emails. 

AsterFax - Asterisk Email to Fax Gateway

AsterFax provides an Email to Fax gateway for Asterisk. AsterFax lets you send an email by Fax. Enter the phone no. in the 'To' address, compose your email message and click send. You can also fax a MS-Word document or other attachment. 

Asterisk Monitor

Asterisk Monitor is a HTML interface that acts a operator pannel for asterisk to display user/peer status and calls. This uses a reverse AJAX, PHP and Python to originate, transfer and hangup calls, manage queues and meetme rooms. 

OpenBTS
The OpenBTS Project is an effort to construct an open-source GSM basestation using the USRP and the Asterisk VoIP PBX. Our goal is to enable a new type of hybrid GSM/VoIP cellular network for greenfield deployments in the developing world. 

Asterisk .NET

The Asterisk .NET library consists of a set of C# classes that allow you to easily build applications that interact with an Asterisk PBX Server (1.0/1.2/1.4 version). Both FastAGI and Manager API supported. .NET/Mono compatible. 

AGX's Asterisk Extra AddOns

Maintained version of old asterisk applications ported to 1.4 that for copyright reasons cannot be included into official Digium's releases and that for some reason the author is not keeping up-to-date. The project also require Zaptel instead of DAHDI. 

AstTAPI

AstTapi, an opensource Asterisk Tapi driver for windows. This allows users of TAPI compliant applications such as Outlook and Act to dial contacts directly from the application using an Asterisk PBX Server. 

Asterisk-Java

A java interface for Asterisk - allows you to write software in Java which will work with Asterisk.

IAXClient

A lightweight cross platform IP telephony client using the IAX protocol, designed for use with the Asterisk open source PBX. 

Asterisk Desktop Manager

A desktop application for managing Asterisk including screen pops etc - looks quite nice but haven't tried it.

Asterisk JTAPI

Asterisk-JTAPI is a JTAPI implementation for the Asterisk software PBX system. JTAPI is a provider independent programming interface for Java to build applications for computer telephony or to add support for it. JTAPI covers a wide range of usage scenarios starting from controlling a single telephone to a whole PBX system for example in call-centers.

Asterisk-JTAPI builds on top of two other projects: Asterisk-Java, which provides a Java interface to the Asterisk manager API, and, GJTAPI, which provides a general framework for JTAPI interfaces.

Astmail

Web interface to Asterisk voicemail written in php. Includes some AJAX components such as LDAP-suggest, and user-lookup. Includes screens for forward by email and sms configuration. 

Druid
Druid is an open source unified communications platform, built around technology such as Asterisk, IMAP, XMPP. Druid gives your organization access to the best available IP communications platform that bringing together voicemail, VOIP, mobile phone, faxes and instant messaging.

ViciDial

VICIDIAL is a set of programs that are designed to interact with the Asterisk Open-Source PBX Phone system to act as a complete inbound/outbound call center suite. 

The agent interface is an interactive set of web pages that work through a web browser to give real-time information and functionality with nothing more than an internet browser on the client computer. 

Asterisk Queue/CDR Log Analyzer

The Asterisk Queue (and CDR) Log Analyzer is a set of PHP scripts which allow selecting, listing and graphing of records from the Asterisk Queue and CDR logs via a WEB interface.

For easier access to select specific log records, the Queue and CDR logs need to be in a MySQL database. Asterisk itself records (specified in a conf file) CDR data into a MySQL database table. A Python utility program called loadq.py is provided with this package which can be used to load queue log records (as they are created) into a MySQL database table.

Asterisk WEB/PHP Event Monitor

The Asterisk Event Monitor WEB/PHP Interface was created to view the current state of Asterisk and all Asterisk Events via a WEB interface. It does not poll Asterisk for these events, instead it collects them in a MySql database via an Asterisk Manager API python script. AJAX (Javascript) is used to display the events from the database almost as they occur. All code is released under the GNU GPL license.


Crystal Recording Interface

CRI (Crystal Clear Recording Interface) provides an intelligence web interface to track is recordings and his voice mail

Features :

Access your voicemail recordings.
Setup your voice mail box
View summary of your incoming outgoing calls
Search calls and recordings by day and time.
Call monitor recordings.

Xivo

XiVO is a full PBX solution based on Asterisk with a user-friendly web interface, provisioning tools for many types of phones, CTI daemon and CTI client for Windows, Linux and MacOS. All solutions are released under GPLv3. Currently only released in French, but easy to translate in other languages, XiVO provides administrators with a simple to configure phone system.

You can find a demo on https://demo.xivo.fr with login root and password proformatique so you can try it out for yourself.


Wednesday, 3 June 2015

MWI activation in Polycom phone and Asterisk:

MWI activation in Polycom phone and Asterisk:

#vi /etc/asterisk/voicemail.conf
[default]
57644 => 1234,John Doe, John.Doe@xyz.com

#vi /etc/aterisk/sip.conf
[
57644 ]
type=friend
host=dynamic
username=
57644 
callerid="John Doe" <57644 >
secret=mypassword
mailbox=
57644 

pbx CLI> sip show peer 57644
* Name : 57644
- - - -
- - - -
Mailbox : 57644
Call limit : 0
Max forwards : 0
Dynamic : Yes
Callerid : "John Doe" <57644>
MaxCallBR : 384 kbps
Expire : 205
- - - -
- - - -
Addr->IP : 192.168.2.10:5060
Defaddr->IP : (null)
Prim.Transp. : UDP
Allowed.Trsp : UDP
Reg. exten :
Def. Username: 57644
SIP Options : (none)
Codecs : 0x4 (ulaw)
Codec Order : (ulaw:20)
Auto-Framing : No
100 on REG : No
Status : Unmonitored
Useragent : PolycomSoundPointIP-SPIP_331-UA/3.3.2.0413
Reg. Contact : sip:57644@192.168.2.10


Asterisk automatically sends NOTIFY message to IP phone provided that the phone is registered correctly with Asterisk and Asterisk knows which voicemail box is associated with that extension. You can check that by issuing the asterisk CLI command #sip show peer
Reg. Contact : sip:57644@192.168.2.10 tells you that phone is successfully registered. 
Mailbox : 57644
 tells you that Asterisk knows that voicemail box 57644 is associated with that phone. That association is defined in sip.conf.

Tuesday, 2 June 2015

Sending MP3 Attachments form Asterisk Voicemail.

source : http://bernaerts.dyndns.org/
This guide will explain how to configure Asterisk PBX to send voicemail as email with messages as mp3 attachement.

If, like me, you are using an Asterisk server, you may be using the voicemail by email functionnality. It allows your Asterisk PABX to send your by email all the messages received in your voicemail.
Just imagine :
  • someone is calling you on your landline
  • he is leaving a message on your answering machine
  • after few seconds, you are receiving a mail on your android or i-phone with the message as an attachment
You can call back immediatly or even forward the email for someone else to deal with that call !

One of the main drawback of that functionnality is that Asterisk can generate attachments using only the standard telephony codecs (wav49, gsm, wav). The wav format is widely recognised, but it is quite uncompressed. The wav49 or gsm formats are better in terms of compression, but sadly they are not recognised by all the devices able to deal with your emails.

So why not to use mp3 format for the voicemail attachments ?
This is what this guide is all about. It will explain how to catch the emails sent by Asterisk and convert the audio attachment from a wav file to a mp3 file.
This guide is based on an Asterisk 1.6 version, running under Debian Squeeze.
As it uses only some very basic & standard linux tools, it should be compatible with any Asterisk installation.
It is based on the standard email structure generated by Asterisk.
If you have modify the Asterisk email format, you will need to adjust the script.

1. Principle

The main principles are :
  • Asterisk voicemail is configured to generate some wav attachements (uncompressed, best quality available)
  • Instead of sending the mail to sendmail, Asterisk is configured to send the mail to one specific script
  • This script will do all the job, and finally give back the mail to sendmail
The script will do some ordered tasks :
  1. catch the stream,
  2. analyse the email content,
  3. seperate each mime part,
  4. pullout the audio attachment,
  5. compress it to mp3,
  6. regenerate the mail content,
  7. send it to sendmail as expected
With this approach, you just need some specific configuration on Asterisk side.
From Asterisk side, the emails are just sent thru another emailer, that's it !
Unlike other methods, you don't need any patch for Asterisk.
You are still using a regular Asterisk, available from your distribution.
So, you can apply any standard update.
Any update to a new Asterisk version should remain fully compatible.

2. Install the packages

First thing to do is to install the packages needed by our script (unix2dos, dos2unix & lame).
aptitude install dos2unix lame

3. Setup the main Script

Once these packages are installed, we can generate the script that will do all the job.

As Asterisk generates the mail content, including the wav attachment encoded in base64, the script main job will be to :
  1. get the attachment from the email content
  2. convert it to mp3
  3. regenerate the mail content with new attachment
  4. send the mail thru sendmail
This job will be done with some very basic linux tools like sed, awk, grep, base64, unix2dos, ...

One important thing is to respect the body structure of the mail content, including the LF and CRLF used to separate lines, depending on the different mime parts. In fact, in the mail body genarated by Asterisk, all the lines are separated with LF, with the exception of the base64 coded audio attachment where they are separated with CRLF.
For the mp3 conversion, 2 compression options are available :
  • CBR - Constant Bit Rate compression will create mp3 streams compatible with any device, but the size/quality ratio is not optimised.
  • VBR - Variable Bit Rate is much more efficient in term of file size, but playback has been tested very poor on some smartphones.
The script is providing both the compression parameters, you just need to adjust it to your need.
The detailed phases of the script are as follow :
  1. Creation of a temporary directory, randomly generated, where we will generate all the temporary files
  2. Dumping of the mail content sent by Asterisk in a file
  3. Detection of the boundary pattern which separate the differents mime parts in the mail
  4. With this pattern, cutting of the mail content into mime parts
  5. Decoding of the WAV attachment which is base64 coded (you have to ignore parasite caracters in some configurations)
  6. Compression into mp3 format
  7. Coding of the mp3 audio file back to base64
  8. Re-assembly of the full mail content, using the new mp3 attachment
  9. Sending of the mail thru sendmail
  10. Deletion of the temporary directory
This sendmailmp3 script will be placed side to the sendmail command, under /usr/sbin.
/usr/sbin/sendmailmp3

#! /bin/sh
# Asterisk voicemail attachment conversion script
# Revision history :
# 22/11/2010 - V1.0 - Creation by N. Bernaerts
# 07/02/2012 - V1.1 - Add handling of mails without attachment (thanks to Paul Thompson)
# 01/05/2012 - V1.2 - Use mktemp, pushd & popd
# 08/05/2012 - V1.3 - Change mp3 compression to CBR to solve some smartphone compatibility (thanks to Luca Mancino)
# 01/08/2012 - V1.4 - Add PATH definition to avoid any problem (thanks to Christopher Wolff)

# set PATH
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

# save the current directory
pushd .

# create a temporary directory and cd to it
TMPDIR=$(mktemp -d)
cd $TMPDIR

# dump the stream to a temporary file
cat >> stream.org

# get the boundary
BOUNDARY=`grep "boundary=" stream.org | cut -d'"' -f 2`

# cut the file into parts
# stream.part - header before the boundary
# stream.part1 - header after the bounday
# stream.part2 - body of the message
# stream.part3 - attachment in base64 (WAV file)
# stream.part4 - footer of the message
awk '/'$BOUNDARY'/{i++}{print > "stream.part"i}' stream.org

# if mail is having no audio attachment (plain text)
PLAINTEXT=`cat stream.part1 | grep 'plain'`
if [ "$PLAINTEXT" != "" ]
then

  # prepare to send the original stream
  cat stream.org > stream.new

# else, if mail is having audio attachment
else

  # cut the attachment into parts
  # stream.part3.head - header of attachment
  # stream.part3.wav.base64 - wav file of attachment (encoded base64)
  sed '7,$d' stream.part3 > stream.part3.wav.head
  sed '1,6d' stream.part3 > stream.part3.wav.base64

  # convert the base64 file to a wav file
  dos2unix -o stream.part3.wav.base64
  base64 -di stream.part3.wav.base64 > stream.part3.wav

  # convert wav file to mp3 file
  # -b 24 is using CBR, giving better compatibility on smartphones (you can use -b 32 to increase quality)
  # -V 2 is using VBR, a good compromise between quality and size for voice audio files
  lame -m m -b 24 stream.part3.wav stream.part3.mp3

  # convert back mp3 to base64 file
  base64 stream.part3.mp3 > stream.part3.mp3.base64

  # generate the new mp3 attachment header
  # change Type: audio/x-wav to Type: audio/mpeg
  # change name="msg----.wav" to name="msg----.mp3"
  sed 's/x-wav/mpeg/g' stream.part3.wav.head | sed 's/.wav/.mp3/g' > stream.part3.mp3.head

  # generate first part of mail body, converting it to LF only
  mv stream.part stream.new
  cat stream.part1 >> stream.new
  cat stream.part2 >> stream.new
  cat stream.part3.mp3.head >> stream.new
  dos2unix -o stream.new

  # append base64 mp3 to mail body, keeping CRLF
  unix2dos -o stream.part3.mp3.base64
  cat stream.part3.mp3.base64 >> stream.new

  # append end of mail body, converting it to LF only
  echo "" >> stream.tmp
  echo "" >> stream.tmp
  cat stream.part4 >> stream.tmp
  dos2unix -o stream.tmp
  cat stream.tmp >> stream.new

fi

# send the mail thru sendmail
cat stream.new | sendmail -t

# go back to original directory
popd

# remove all temporary files and temporary directory
rm -Rf $TMPDIR
 
Be sure to make it executable.
If you are using some other distributions than debian or ubuntu or some self  compiled packages, you may have to specify the full path for the executable files (/usr/local/bin/lame for example).

4. Voicemail configuration

On the Asterisk server side, we just need to configure the voicemail extension to use or script to send the mails.
This is done thru the voicemail.conf file, where :
  • In the [general] section, you need to setup some email specific parameters
  • In the [default] section (I suppose you use the default context for your voicemail), you need to setup the email address to use for each voicemail box.
So, finally your voicemail.conf configuration file should include these parameters :

/etc/asterisk/voicemail.conf
[general]
; Formats for writing voicemail. WAV is the best quality.
format=wav
; Who the e-mail notification should appear to come from
serveremail=yourpabxname@your.domain.com
; the email should contain the voicemail as an attachment
attach=yes
; You override the default program to send e-mail to use the script
mailcmd=/usr/sbin/sendmailmp3

[default]
; here you declare your voicemail, the email address which will receive the email & the automatic deletion of the message after mail is sent
yourvoicemailid => , yourname , your.email@address.com, , delete=yes

Once the file is saved, you just need to restart Asterisk for the configuration to be operational.

/etc/init.d/asterisk restart
That's it !
From now on, your Asterisk server is sendind all the voicemails by email using mp3 attachments.
Hope it helps.

E-mail Newsletter

Sign up now to receive breaking news and to hear what's new with us.

Recent Articles

© 2014 VOIP4Learn. WP themonic converted by Bloggertheme9. Powered by Blogger.
TOP