Asterisk Integration

From www.sermyadmin.org

Jump to: navigation, search

To forward calls to an Asterisk Server is not a big deal. However, when you have two or three Asterisk servers processing voicemails it becomes hard to manage users in several different servers. The realtime Asterisk integration allows you to run Asterisk Real Time using directly the serMyAdmin database. So it doesn't matter how many voicemail servers do you have, you are going to use a single database. Another important aspect is, all messages coming from your server to Asterisk will be authenticated, so you have an additional layer of security too.

For the release 1.2.x we’ve planned the integration of Asterisk in our solution. Very small modifications were done to the system. The basic idea is to integrate the voicemail users, the voicemail database, sip users and peers. The views should be ready in your system, but for some reason they were not exported in serMyAdmin.sql file of the version 1.2.5. So you will have the follow this procedure to integrate Asterisk to your serMyAdmin installation.

The only modification made to serMyAdmin interface was the insertion of the field "Voice Mail Password" in the user definition.


1. Create the views required for Asterisk Real Time.

CREATE VIEW vmusers AS 
SELECT 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 sermyadmin.subscriber;
CREATE VIEW sipusers AS 
SELECT username as name, 
username, 
'friend' as type, 
password as secret, 
domain as host, 
CONCAT(rpid, ' ',) as callerid, 
'from-sip' 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 sermyadmin.subscriber; 

2. Configure Asterisk to use serMyAdmin database.

  • 2.1 Compile the Asterisk Realtime, part of the addons package.
  • 2.2 Configure MySQL Access on Asterisk
vi res_mysql.conf 
; Sample configuration for res_config_mysql.c
; The value of dbhost may be either a hostname or an IP address.
; If dbhost is commented out or the string "localhost", a connection
; to the local host is assumed and dbsock is used instead of TCP/IP
; to connect to the server.
;
[general]
dbhost = 127.0.0.1
dbname = sermyadmin
dbuser = sermyadmin
dbpass = secret
dbport = 3306
;dbsock = /tmp/mysql.sock
 

2.3 Configure Asterik realtime config file.

vi extconfig.conf 
; Static and realtime external configuration
; engine configuration
;
; Please read doc/extconfig.txt for basic table
; formatting information.
;
[settings]
sipusers => mysql, sermyadmin, sipusers
sippeers => mysql, sermyadmin, sipusers
voicemail =>mysql, sermyadmin, vmusers

2.4 Configure the dialplan

In the VIEW definition I have used "from-sip"as the context for calls incoming from OpenSIPs.

vi extensions.conf 
[from-sip]
exten=_u.,1,voicemail(${EXTEN:1},u)
exten=_u.,n,hangup()
exten=_b.,1,voicemail(i${EXTEN:1},b)
exten=_b.,n,hangup()
exten=*98,1,meetme(,d)
exten=*98,2,hangup()
exten=*99,1,voicemailmain()
exten=*99,2,hangup()
exten=_X.,1,answer()
exten=_X.,2,saydigits(${EXTEN})
exten=_X.,n,hangup()
 

2.5 Configure the OpenSIPs to send unanswered calls and busy calls to Asterisk

failure_route[1] {
    setflag(2);
    if (isbflagset(6) || isflagset(5))
    {
        unforce_rtp_proxy();
    }
    ##--
    ##-- If cancelled, exit.
    ##--
    if (t_check_status("487"))
    {
        exit;
    };
    ##--
    ##-- If busy send to the e-mail server, prefix the "b"
    ##-- character to indicate busy.
    ##--
    if (t_check_status("486"))
    {
        revert_uri();
        prefix("b");
        #xlog("L_ERR","Stepped into the 486 ruri=");
        rewritehostport("192.168.152.148:5061");
        append_branch();
        route(1);
        exit;
    };
    ##--
    ##-- If timeout (408) or unavailable temporarily (480),
    ##-- prefix the uri with the "u"character to indicate
    ##-- unanswered and send to the e-mail
    ##-- server
    ##--
    if (t_check_status("408") || t_check_status("480")) {
        revert_uri();
        prefix("u");
        #xlog("L_ERR","Stepped into the 480 ruri=");
        rewritehostport("192.168.152.148:5061");
        append_branch();
        route(1);
        exit;
    };
} 

2.6 Configure calls preceded with "*"to be sent to Asterisk.

# Features routing to Asterisk
if (uri=~"^/*")
{
    route(2);
}

route[2]
{
    #
    # Route to the Asterisk Server
    #
    rewritehostport("192.168.152.148:5061");
    route(1);
}
 

2.7 Restart and test your system. (Some adaptations may need to be adjusted for your own scenario).

Personal tools