http://www.voip-info.org/wiki/view/Realtime+Integration+Of+Asterisk+With+OpenSER
valid for openser 1.1.x and asterisk 1.2.x
OpenSER is a pure VoIP signaling server using Session Initiation Protocol - SIP. It is flexible and highly configurable but cannot be used to provide media services as voicemail, anounncements or conferencing. For such services, Asterisk is the most suitable open source product. In this document we present how to configure Asterisk to use OpenSER's subscribers database to provide voicemail service. A basic configuration file for OpenSER is posted down the page, allowing to have a functional system by following the steps in this tutorial.
Requirements
- linux-like operating system (examples in this document are specific for Debian)
- asterisk 1.2.x+ - http://www.asterisk.org
- mysql 5.0.x+ - http://www.mysql.com
- openser 1.0.x+ - http://www.openser-project.org
- unixodbc 2.2.11+ - http://www.unixodbc.org
- unixodbc mysql driver - libmyodbc
UnixODBC Installation
Get the sources from http://www.unixodbc.org, compile and install them on your system
cd /usr/local/src
wget http://www.unixodbc.org/unixODBC-2.2.11.tar.gz
tar xvfz unixODBC-2.2.11.tar.gz
cd unixODBC-2.2.11
./configure –enable-gui=no
make
make install
NOTE: if you get error during compilation in 'sqp/lex.l', the line 240, related to 'YY_FLUSH_BUFFER', you can safely comment/remove that line.
NOTE: you must have /usr/local/lib in your /etc/ld.so.conf file or LD_LIBRARY_PATH environment variable.
MySQL Installation
You can install MySQL using the packaging system from you Linux distribution. The only requirements is to be MySQL 5.0+. For example, http://dotdeb.org provides packages for Debian stable.
After installation, you can set the MySQL root password with a command like:
/usr/bin/mysqladmin -u root password 'your-new-password'
Asterisk Installation
Get Asterisk sources from http://www.asterisk.org. At this moment Asterisk 1.2.9.1 is the latest stable version.
cd /usr/local/src
wget http://ftp.digium.com/pub/asterisk/releases/asterisk-1.2.9.1.tar.gz
tar xvfz asterisk-1.2.9.1.tar.gz
cd asterisk-1.2.9.1
Edit 'apps/Makefile' and uncomment lines:
CFLAGS+=-DUSE_ODBC_STORAGE
CFLAGS+=-DEXTENDED_ODBC_STORAGE
Edit 'apps/app_voicemail.c' and change the size of memeber 'uniqueid' in 'struct ast_vm_user' to 64:
/* Structure for linked list of users */
struct ast_vm_user {
char context[AST_MAX_CONTEXT]; /* Voicemail context */
char mailbox[AST_MAX_EXTENSION];/* Mailbox id, unique within vm context
char password[80]; /* Secret pin code, numbers only */
char fullname[80]; /* Full name, for directory app */
char email[80]; /* E-mail address */
char pager[80]; /* E-mail address to pager (no attachme
char serveremail[80]; /* From: Mail address */
char mailcmd[160]; /* Configurable mail command */
char language[MAX_LANGUAGE]; /* Config: Language setting */
char zonetag[80]; /* Time zone */
char callback[80];
char dialout[80];
char uniqueid[64]; /* Unique integer identifier */
char exit[80];
unsigned int flags; /* VM_ flags */
int saydurationm;
int maxmsg; /* Maximum number of msgs per folder fo
struct ast_vm_user *next;
};
Proceed with usual Asterisk installation:
make
make install
OpenSER Installation
You can download latest stable version via CVS snapshots. For branch 1.0.0 (latest release in this branch is 1.0.1) you can do:
cd /usr/local/src
wget http://www.openser-project.org/downloads/snapshots/openser-1.0.0/openser-1.0.0-cvs-latest.tgz
tar xvfz openser-1.0.0-cvs-latest.tgz
cd openser-1.0.0
make all include_modules="mysql"
make install include_modules="mysql"
UnixODBC MySQL Driver Installation
Simply install the package using the tools from your linux distribution. For example, for Debian:
apt-get install libmyodbc
Create OpenSER Database
To create the database needed by OpenSER:
/usr/local/sbin/openser_mysql.sh create
This will create a database named 'openser' and will add a MySQL user 'openser' with full access to it. The default password is 'openserrw', do change it before (by editing usr/local/sbin/openser_mysql.sh) or immediately after you create the database.
Once you create the database, you need to add a new column to the 'subscriber' table to store the PIN for voicemail access:
ALTER TABLE subscriber ADD vmail_password varchar(32);
Create Asterisk Database
The database needed by Asterisk will contain two views ('vmusers' and 'sipusers') of tables from OpenSER database, therefore it is required to have MySQL 5.0+ since the views were introduced in this version. There is a real MySQL table ('voicemessages') which will store the voice messages.
Log in as root in MySQL server:
create database asterisk;
use asterisk;
CREATE TABLE `voicemessages` (
`id` int(11) NOT NULL auto_increment,
`msgnum` int(11) NOT NULL default '0',
`dir` varchar(80) default '',
`context` varchar(80) default '',
`macrocontext` varchar(80) default '',
`callerid` varchar(40) default '',
`origtime` varchar(40) default '',
`duration` varchar(20) default '',
`mailboxuser` varchar(80) default '',
`mailboxcontext` varchar(80) default '',
`recording` longblob,
PRIMARY KEY (`id`),
KEY `dir` (`dir`)
) ENGINE=InnoDB;
CREATE VIEW vmusers AS
SELECT phplib_id as uniqueid,
username as customer_id,
'default' as context,
username as mailbox,
vmail_password as password,
CONCAT(first_name,' ',last_name) as fullname,
email_address as email,
NULL as pager,
datetime_created as stamp
FROM openser.subscriber;
CREATE VIEW sipusers AS
SELECT username as name,
username,
'friend' as type,
NULL as secret,
domain as host,
CONCAT(rpid, ' ','<',username,'>') as callerid,
'default' as context,
username as mailbox,
'yes' as nat,
'no' as qualify,
username as fromuser,
NULL as authuser,
domain as fromdomain,
NULL as insecure,
'no' as canreinvite,
NULL as disallow,
NULL as allow,
NULL as restrictcid,
domain as defaultip,
domain as ipaddr,
'5060' as port,
NULL as regseconds
FROM openser.subscriber;
Add a MySQL user which will have full access right to 'asterisk' database.
GRANT ALL ON asterisk.* to asterisk@localhost IDENTIFIED BY 'some_password';
Configure UnixODBC
In the file ‘/usr/local/etc/odbcinst.ini’ you must add:
[MySQL]
Description = MySQL driver
Driver = /usr/lib/odbc/libmyodbc.so
Setup = /usr/lib/odbc/libodbcmyS.so
CPTimeout =
CPReuse =
UsageCount = 1
In the file '/usr/local/etc/odbc.ini' you must add:
[MySQL-asterisk]
Description = MySQL Asterisk database
Trace = Off
TraceFile = stderr
Driver = MySQL
SERVER = localhost
USER = asterisk
PASSWORD = some_password
PORT = 3306
DATABASE = asterisk
Configure Asterisk
In '/etc/asterisk/res_odbc.conf':
[asterisk]
enabled => yes
dsn => MySQL-asterisk
username => asterisk
password => asterisk
pre-connect => yes
In '/etc/asterisk/extconfig.conf':
sipusers => odbc,asterisk,sipusers
sippeers => odbc,asterisk,sipusers
voicemail => odbc,asterisk,vmusers
In '/etc/asterisk/sip.conf':
If you want to enable MWI, do not forget to set checkmwi attribute.
checkmwi=10
Guidelines about configuring the SIP channel you find at http://www.voip-info.org/wiki-Asterisk+config+sip.conf. You do not need to add any SIP user or peer in the configuration file, they will be loaded from database.
In ‘/etc/asterisk/voicemail.conf’ you do not need to add any mailbox. They will be loaded from database. The general configuration part of voicemail application is presented at http://www.voip-info.org/wiki/index.php?page=Asterisk+config+voicemail.conf
For our tutorial, we consider that the users will have 4-digit ID. To implement a clear dialing plan in Asterisk which allow extensibility and clear extentions for different services, the calls to voicemail will be prefixed with '1' in OpenSER proxy. This prefix will be transpartent for users. If voice mailbox does not exist, Asterisk will play "invalid extension" message.
In '/etc/asterisk/extensions.conf':
exten => 1,1,Ringing
exten => 1,2,VoicemailMain(${CALLERIDNUM})
exten => 1,3,Hangup
exten => 11,1,Ringing
exten => 11,2,VoicemailMain()
exten => 11,3,Hangup
exten => _1XXXX,1,Ringing
exten => _1XXXX,2,MailboxExists(${EXTEN:1})
exten => _1XXXX,3,Playback(invalid)
exten => _1XXXX,4,Hangup
exten => _1XXXX,103,Voicemail(u${EXTEN:1})
exten => _1XXXX,104,Hangup
Configure OpenSER
Dialing plan:
- local users have 4-digit extension
- to listen its voice messages from its SIP phone, the user has to dial *98 (Asterisk will prompt only for PIN)
- to listen its voice messages from another SIP phone, the user has to dial *981 (Asterisk will prompt for mailbox ID and PIN)
- to call directly to leave voice message to user XXXX, the user has to dial *89XXXX
In '/usr/local/etc/openser/openser.cfg':
See also
- Asterisk at large: Asterisk with SER/OpenSer
- Initial tutorial about this subject on OpenSER site
- OpenSER - open source SIP server with TLS support
- http://www.openser-project.org - OpenSER home page