Monday, January 23, 2012

Quick Start on Asterisk-GUI (Analog Trunk)

Provisioning an analog trunk on Asterisk GUI 2.0.4 requires bit more work compared to provisioning SIP client (and some manual setting in my case) so I'll cover the settings before moving onto the provisioning steps. 


Some Background
I am using Asterisk version 1.4.26.2 (it is quite old). Just prior to this release, the Zaptel driver has been renamed to DAHDI (See this link for more information). 


Interesting enough, the module is named “chan_dahdi.so” but the “zapata.conf” file (instead of the chan_dahdi.conf file) is read by asterisk:
home-unix6*CLI> module reload chan_dahdi.so
    -- Reloading module 'chan_dahdi.so' (DAHDI Telephony w/PRI)
  == Parsing '/usr/local/etc/asterisk/zapata.conf': Found
P.S. the purpose of zapata.conf is to configure all TDM interface parameters. The configuration was covered in this post.

Check out the change logs [r122314] and confirmed chan_zap.c was indeed removed in one of the earlier releases (1.4.22). 

Some manual settings
1. Asterisk GUI cannot detect analog hardware - I added one line in ztscan.conf (in etc/asterisk directory), restarted the asterisk process and the FXO port can be detected: 

[1]
active=yes
alarms=OK
description=Wildcard TDM400P REV E/F Board 1
name=WCTDM/0
manufacturer=Digium
devicetype=Wildcard TDM400P REV E/F
location=PCI Bus 05 Slot 09
basechan=1
totchans=4
irq=10
port=1,FXO



2. Asterisk GUI provision the analog trunk as Zap channel (in extensions.conf file), but Asterisk doesn’t understand Zap - unless the “dahdichanname” parameter in asterisk.conf is set to "no"

home-unix6# cat asterisk.conf | grep dahdi
dahdichanname = no yes; Channels created by chan_dahdi will be called 'DAHDI', otherwise 'Zap'



3. After Asterisk process restarts, "chan_dahdi.so" module is not loaded. 
At the moment, I have to manually run "module load chan_module.so" in Asterisk console, because adding "load => chan_dahdi.so" in modules.conf does not help... 




Provisioning
1. If the analog port is detected, it will be displayed on the "Configure Hardware" page:


2. On "Trunk" page, select "New Analog Trunk". Tick "Channel" and assign a name to it: 
3. On "Outgoing Calling Rules" page, set "New Calling Rule" and use the trunk previously defined in step two (local-line):

4. On "Dial plans" page, edit the existing dialplan (if none exist, just create a new one). Tick to include the outgoing calling rule previously defined (localline):




5. Apply the changes ("Apply Change" button is on the top right corner of web browser). This requires a system restart but I restarted the Asterisk process. 


6. The analog trunk has been provisioned and can make or receive phone calls. 




Notes:
Remember Some Manual Settings 3. After Asterisk process restarts, "chan_dahdi.so" module is not loaded. So manual loading/ reload is required. 







Sunday, January 22, 2012

Quick Start on Asterisk-GUI (SIP Client)

As a continuation of previous blog on Asterisk GUI, this post is a quick start guide to a simple provisioning example - adding a new SIP client which can call other users in the default context.


Note: please read the "Browser Notes" added in the Asterisk GUI, as I have only managed to have IE 9 browser working with Asterisk-GUI so far. 


1. The Asterisk-GUI is accessible via the URL and can be login via a non-admin user (defined in manager.conf):
http://:8088/asterisk/static/config/index.html


Upon successful login, the first page is the "System Status" page:

2. Click on the "Dialplan" tab on the left sidebar and create a new Dial plan (ignoring the warning of "No Calling Rules Defined"):
Note: I have ticked "default" context to link to this dialplan. i.e. this dialplan can call/ receive calls from previously provisioned users. 


3. Click on the "User" tab and create a new user. 
4. After this, the SIP client (x-lite) can successfully register as user "6000" and call other users. 




Some thoughts:
The good thing about Asterisk GUI is it is ported under FreeBSD (/usr/ports/www/asterisk-gui/) which makes the installation much easier (than compiling source and working through dependencies). 
That being said, some features such as adding an analog line seems quite complex - I spent a couple of hours and have not worked this out. 


At a later day, I may consider trying out FreePBX for provisioning but would prefer to run it on a Linux server. 







IPBlue phone continues ringing after call is picked up…

As a continuation of the previous post Configuring Asteriskfrom the Ground Up (1/2), this post is about an issue I encountered and its resolution. 


When calling IPBlue (Cisco softphone) from Xlite (SIP client), after I picked up the call (on IPBlue) the ring-tone continues and the call could not be established. 


Reviewing the console, when IPBlue is first registered, its capability is set to '0'.
Also, a warning message "Don't know any of 0x0 formats" shows up after the call is picked up. 


    -- Device 'SEP00215D2B1296' successfully registered
Device capability set to '0'
Adding button: 9, 1


    -- Executing [1000@DLPN_DialPlan1:1] Dial("SIP/6000-2a2fc000", "Skinny/1000@ipblue") in new stack
    -- skinny_request(1000@ipblue)
    -- Called 1000@ipblue
    -- Skinny/1000@ipblue-4 is ringing
[Jan 22 16:02:50] WARNING[1490]: channel.c:700 ast_best_codec: Don't know any of 0x0 formats


The warning message suggests it may has to do with the codec and the resolution is as follows.


1. Allow all audio codecs for both IPBlue and SIP phones:

skinny.conf
[ipblue]
type=7960
;context=default
line=1000            ; Dial(Skinny/1000@ipblue)
device=SEP00215D2B1296
allow=all

sip.conf
;;; SIP Client - J Lam, Jan 2012
[xlite]
; Turn off silence suppression in X-Lite ("Transmit Silence"=YES)!
; Note that Xlite sends NAT keep-alive packets, so qualify=yes is not needed
type=friend                     ; Context used for both inbound and outbound calls
regexten=1234                   ; When they register, create extension 1234
host=dynamic                    ; This device needs to register
allow=all



2. On both IPBlue and Xlite clients, permit G.711 is used:

IP Blue’s setting:


X-Lite Preferences:

Since I am not sure which of the G.711 codecs (alaw, ulaw) is used by IPBlue, I have enabled both on X-Lite.

3. Reload SIP module to enable sip.conf, and force skinny client to re-register:


The following messages appear on Asterisk console (asterisk –rvvvvvgc)
home-unix6*CLI> sip reload
 Reloading SIP>
  == Parsing '/usr/local/etc/asterisk/sip.conf': Found
  == Parsing '/usr/local/etc/asterisk/users.conf': Found
  == Parsing '/usr/local/etc/asterisk/sip_notify.conf': Found


home-unix6*CLI> skinny reset SEP00215D2B1296

    -- Device 'SEP00215D2B1296' successfully registered
Device capability set to '268'
Adding button: 9, 1

Note: ensure skinny client’s device capability is NOT set to ‘0’…

4. SIP and Skinny clients can now call each other successfully. i.e. no more ringing tone after Skinny client picks up the phone.
Voice is also working fine.


Sunday, January 15, 2012

Asterisk GUI Installation

For easier administration, Asterisk comes with a built-in mini web server. 


The FreeBSD port is called Asterisk-GUI (/usr/ports/www/asterisk-gui)


In the ports directory, run "make; make install" following by "make checkconfig" to check the configurations in (/etc/asterisk) http.conf and manager.conf:


make; make install
make checkconfig           # Verifies the http.conf and manager.conf (/etc/asterisk)

home-unix6# make checkconfig
 --- Checking Asterisk configuration to see if it will support the GUI ---
* Checking for http.conf: OK
* Checking for manager.conf: OK
* Checking if HTTP is enabled: OK
* Checking if HTTP static support is enabled: OK
* Checking if manager is enabled: OK
* Checking if manager over HTTP is enabled: OK
 --- Everything looks good ---
 * GUI should be available at http://home-unix6.mooo.com:8088/asterisk/static/config/cfgbasic.html

 * Note: If you have bindaddr=127.0.0.1 in /usr/local/etc/asterisk/http.conf
   you will only be able to visit it from the local machine.

   Example: http://localhost:8088/asterisk/static/config/cfgbasic.html

 * The login and password should be an entry from /usr/local/etc/asterisk/manager.conf
   which has 'config' permission in read and write.  For example:

    [admin]
    secret = mysecret1873
    read = system,call,log,verbose,command,agent,config
    write = system,call,log,verbose,command,agent,config

 --- Good luck! ---

  

home-unix6# vi /usr/local/etc/asterisk/http.conf
;
; Asterisk Builtin mini-HTTP server
;
;
[general]
;
; Whether HTTP interface is enabled or not.  Default is no.
;
enabled=yes
;
; Whether Asterisk should serve static content from http-static
; Default is no.
;
enablestatic=yes

;
; Address to bind to.  Default is 0.0.0.0
;
;bindaddr=127.0.0.1
bindaddr=0.0.0.0
;
; Port to bind to (default is 8088)
;
bindport=8088


manager.conf - admin and jlam users are defined, along with their privileges
;
; AMI - The Asterisk Manager Interface
;
; Third party application call management support and PBX event supervision
;
; This configuration file is read every time someone logs in
;
; Use the "manager list commands" at the CLI to list available manager commands
; and their authorization levels.
;
; "manager show command " will show a help text.
;
; ---------------------------- SECURITY NOTE -------------------------------
; Note that you should not enable the AMI on a public IP address. If needed,
; block this TCP port with iptables (or another FW software) and reach it
; with IPsec, SSH, or SSL vpn tunnel.  You can also make the manager
; interface available over http if Asterisk's http server is enabled in
; http.conf and if both "enabled" and "webenabled" are set to yes in
; this file.  Both default to no.  httptimeout provides the maximum
; timeout in seconds before a web based session is discarded.  The
; default is 60 seconds.
;
[general]
displaysystemname = yes
enabled = yes
webenabled = yes
port = 5038

;httptimeout = 60
; a) httptimeout sets the Max-Age of the http cookie
; b) httptimeout is the amount of time the webserver waits
;    on a action=waitevent request (actually its httptimeout-10)
; c) httptimeout is also the amount of time the webserver keeps
;    a http session alive after completing a successful action

bindaddr = 0.0.0.0


[admin]
secret =          ; don't use password "password", as it is the default value. Otherwise, the GUI will keep prompting you to change it
read = system,call,log,verbose,command,agent,user,config,originate
write = system,call,log,verbose,command,agent,user,config,originate


[jlam]
secret =        ; Only non-admin user with the correct privileges can provision voice trunks.
read = system,call,log,verbose,command,agent,user,config,originate
write = system,call,log,verbose,command,agent,user,config,originate


Asterisk-GUI Dial Plans tab


Additional notes as of 22nd Jan 2012:



Browser Notes:
I have tried accessing the Asterisk-GUI using both web-browsers Google Chrome 16.0.912.75 and Firefox 9.0.1. 
Both browsers don't allow me to "Save" settings (Asterisk GUI no response after clicking "Save"). In another words, I cannot do provisioning using them. 

The only web browser which works with Asterisk-GUI (as I have discovered so far) is Internet Explorer 9. "Save" button works, hence allow provisioning.


In some occasions, after apply settings, browser returns to Login screen (indicating login successful) but sidebar disappears.
The only work around so far is to logout and then login again…

Configuring Asterisk from the Ground Up (2/2)

Disclaimer: I recommend and acknowledge www.voip-info.org as my comprehensive online reference to the details on Asterisk. 
Also, blogspot doesn't seems to like "<" and ">" symbols, hence some of the code posted maybe incorrect.


This is the second part of the Asterisk build guide, which covers setting Asterisk to store the CDR (call details record) in an MySQL back-end and reading the records through a web-browser.


By default, /var/log/asterisk/cdr-csv/ Master.csv
"","xlite","1234","default","""jlam"" ","SIP/xlite-2a2b6000","SIP/xlite-2a2c5000","Dial","SIP/xlite","2012-01-14 09:00:54",,"2012-01-14 09:01:01",7,0,"NO ANSWER","DOCUMENTATION","1326531654.11",""
"","xlite","1234","default","""jlam"" ","SIP/xlite-2a2b6000","SIP/xlite-2a2c5000","Dial","SIP/xlite","2012-01-14 09:02:17",,"2012-01-14 09:02:37",20,0,"NO ANSWER","DOCUMENTATION","1326531737.13",""

Asterisk addons is required to be installed (/usr/ports/net/asterisk14-addons) because this functions uses the 
(/usr/local/lib/asterisk/modules/)cdr_addon_mysql.so module. 
Note: libtool24 (/usr/ports/devel/libtool24) is required to be installed first before adding asterisk14-addons.

Load module every time Asterisk starts - modules.conf
;;; CDR MySQL backend addon:
load => cdr_addon_mysql.so

On MySQL, I used this example MySQL script in voip-info.org which basically reflects the structure of the Master.csv file:

mysql –u asterisk –ppassword (note there is no space between “-p” and the password)
CREATE DATABASE asterisk;

GRANT INSERT
ON asterisk.*
TO asterisk@localhost
IDENTIFIED BY 'password';

USE asterisk;

CREATE TABLE `cdr` (
`calldate` datetime NOT NULL default '0000-00-00 00:00:00',
`clid` varchar(80) NOT NULL default '',
`src` varchar(80) NOT NULL default '',
`dst` varchar(80) NOT NULL default '',
`dcontext` varchar(80) NOT NULL default '',
`channel` varchar(80) NOT NULL default '',
`dstchannel` varchar(80) NOT NULL default '',
`lastapp` varchar(80) NOT NULL default '',
`lastdata` varchar(80) NOT NULL default '',
`duration` int(11) NOT NULL default '0',
`billsec` int(11) NOT NULL default '0',
`disposition` varchar(45) NOT NULL default '',
`amaflags` int(11) NOT NULL default '0',
`accountcode` varchar(20) NOT NULL default '',
`userfield` varchar(255) NOT NULL default ''
);

ALTER TABLE `cdr` ADD `uniqueid` VARCHAR(32) NOT NULL default '';
ALTER TABLE `cdr` ADD INDEX ( `calldate` );
ALTER TABLE `cdr` ADD INDEX ( `dst` );
ALTER TABLE `cdr` ADD INDEX ( `accountcode` );

cdr_mysql.conf - define MySQL database and table name
[global]
dbname=asterisk
table=cdr
password=password
user=asterisk

cdr.conf - comment out "csv" back end and added "mysql"
; CHOOSING A CDR "BACKEND"  (what kind of output to generate)

;[csv]
;usegmtime=yes    ; log date/time in GMT.  Default is "no"
;loguniqueid=yes  ; log uniqueid.  Default is "no"
;loguserfield=yes ; log user field.  Default is "no"

[mysql]
usegmtime=yes    ; log date/time in GMT.  Default is "no"
loguniqueid=yes  ; log uniqueid.  Default is "no"
loguserfield=yes ; log user field.  Default is "no"
Note: remember to add user “asterisk” on the local host, else the CDR records won’t be inserted into MySQL.

Displaying the records using web browser:
Ensure Apache and PHP are installed. The versions of the software on my system are:
home-unix6# httpd -v
Server version: Apache/2.2.14 (FreeBSD)
Server built:   Feb 21 2010 13:14:06

home-unix6# php -v
PHP 5.3.2 with Suhosin-Patch (cli) (built: Jun  3 2010 20:54:27)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies

This link contains a sample php file which prints all contents in the MySQL database. I have hard-coded the database and table name. 
[index.php not shown here due to blogspot incorrectly displaying "<" and ">"]

A new directory for CDR records is created, where the file above is saved - /usr/local/www/cdr/index.php

Modify the /usr/local/etc/apache22/httpd.conf
Listen 0.0.0.0:80
DocumentRoot "/usr/local/www/cdr"
LoadModule php5_module libexec/apache22/libphp5.so
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
#
# DirectoryIndex: sets the file that Apache will serve if a directory
# is requested.
#
#DirectoryIndex index.html
DirectoryIndex index.php

 CDR records on Web browser

Configuring Asterisk from the Ground Up (1/2)



Disclaimer: I recommend and acknowledge www.voip-info.org as my comprehensive online reference to the details on Asterisk. 
Also, blogspot doesn't seems to like "<" and ">" symbols. For the time being, I have replaced these symbols with "{" and "}"


Overview
This is the first part of the Asterisk build guide, which covers setting Asterisk to accept SIP, Skinny (Cisco) and PSTN devices' registration, and building a dial plan with Voicemail function. 

It is assumed the operating system and Asterisk have been successfully installed on the system. (My FreeBSD Operating System is 8.0 and Asterisk version is 1.4.26.2). OS and ports installation are out of scope to this port...  


The basic concepts of configuring Asterisk (and the gotchas) are illustrated through the following example: 

In a nutshell, the Asterisk can be understood to be as simple as a dial plan dictating the behaviors of multiple clients. 


This Asterisk server has three clients: 

1.     SIP Phone – X-LiteWindows Program, X-Lite
2.     Cisco IP Phone – IP Blue (Windows program, IP Blue- 30 days trial)**3.     PSTN Phone*** – Dual Phone for Skype, but I use only the landline connection to Asterisk server Digium Clone (OpenVox) FXO port. For more information refer to my other post.

Note:
* For a full list of VoIP and soft phones supported by Asterisk, see this voip-info link

** I tried the following IP Blue packages on my Windows Vista:
IPB Softphone Advanced 2.15.26.37 Setup                  - Works OK
IPB Softphone 508  2.15.35.49 Setup                             - crashes on Vista

SCCP module is also available, although it does not come with my distribution of Asterisk by default. It can be downloaded from sourceforge and be compiled to replace of skinny.conf.

*** w.r.t. the PSTN component in the Asterisk server, Zapata.conf is to be replaced by chan_dahdi.conf

SIP/ Skinny/ PSTN Devices - Asterisk Configurations
The configuration files are located under the directory (/usr/local/etc/asterisk)

1. SIP client - sip.conf
[xlite]                ; Make sure the User ID entered on XLite client matches this value
type=friend                       ; Same context used for both inbound and outbound calls
regexten=1234                     ; When they register, create extension 1234
host=dynamic                      ; This device needs to register
disallow=all
allow=gsm                         ; GSM consumes far less bandwidth than ulaw
allow=ulaw
allow=alaw
;context=default

2. SCCP client - skinny.conf
[ipblue]
type=7960
;context=default
line=1000            ; Dial(Skinny/1000@ipblue)
device=SEP00215D2B1296

In addition to setting up Skinny module, tftp server has to be setup (because skinny client downloads an XML file which defines the Call Manager's IP address and port):

I installed the tftp port (/usr/ports/ftp/tftp-hpa)

/etc/inetd.conf
tftp    dgram   udp     wait    root    /usr/libexec/tftpd      tftpd -l -s /tftpboot
#tftp   dgram   udp6    wait    root    /usr/libexec/tftpd      tftpd -l -s /tftpboot

/etc/rc.conf
inetd_enable="YES"      # Inetd for TFTP server (Skinny)

The XML file (for Skinny client) is named as "SEP.cnf.xml"
It is placed under the /tftpboot/ directory. A sample file is shown beneath (Call Manager's parameters are colored in red)
 {device}
 {devicePool}
  {callManagerGroup}
   {members}
    {member  priority="0"}
     {callManager}
      {ports}
       {ethernetPhonePort}2000{/ethernetPhonePort}
      {/ports}
      {processNodeName}192.168.10.154{/processNodeName}
     {/callManager}
    {/member}
   {/members}
  {/callManagerGroup}
 {/devicePool}
 {versionStamp}{Jan 28 2008 19:01:00}{/versionStamp}
 {loadInformation}{/loadInformation}
 {userLocale}
  {name}{/name}
  {langCode}en{/langCode}
 {/userLocale}
 {networkLocale}{/networkLocale}
 {idleTimeout}0{/idleTimeout}
 {authenticationURL}{/authenticationURL}
 {directoryURL}{/directoryURL}
 {idleURL}{/idleURL}
 {informationURL}{/informationURL}
 {messagesURL}{/messagesURL}
 {proxyServerURL}{/proxyServerURL}
 {servicesURL}{/servicesURL}
{/device}



Note: asterisk must be restarted for the skinny configurations to take effect, a reload just won’t work (link)
home-unix6*CLI> skinny show devices
Name                 DeviceId         IP              Type            R NL
-------------------- ---------------- --------------- --------------- - --
ipblue               SEP00215D2B1296  192.168.10.45   7960            Y  1
home-unix6*CLI> skinny show lines
Device Name          Instance Name                 Label
-------------------- -------- -------------------- --------------------
ipblue                      1 1000

3. Zapata.conf
I have covered the zapata.conf file in a previous post so it is added beneath only for reference:
[channels]
; OpenVox User Manual
; Span 1: WCTDM/0 "Wildcard TDM400P REV E/F Board 1" (MASTER)
signalling=fxo_ks
adsi=yes
pulse=yes
context=default
channel => 1

Extensions - Basics
extensions.conf
[default]
exten => 1234,1,Dial(SIP/xlite)          ;;; SIP client
exten => 5678,1,Dial(DAHDI/1-1)          ::: PSTN client
exten => 1000,1,Dial(Skinny/1000@ipblue) ;;; Skinny client

I didn't define any "context" for the clients, so they will all use the default context. 
The setup above allows all three devices to be registered to the Asterisk server and call each other using their corresponding extensions.

Extensions - More Details
For example, I would like to SIP client to ring for 10s. If nobody picks up the call, then a voice menu is played to the called, where he/she can choose to either leave a voice mail, or try calling the land-line (or hangup). 


The implementation example is as follows (please read the comments for further details):
;;; exten syntax
; exten => id, priority, command

[default]
;;; Default dialplan
exten => 5678,1,Dial(DAHDI/1)
exten => 1000,1,Dial(Skinny/1000@ipblue)

exten => 1234,1,Dial(SIP/xlite,10)              ; SIP client rings for 10s
exten => 1234,2,Answer
exten => 1234,3,Goto,xlite-menu|s|1             ; If the call is unanswered,
                                                ; it will be forwarded to "xlite-menu"
[xlite-menu]
exten => s,1,Background(/tmp/menu)       ; Play "menu" message
exten => s,2,WaitExten(10)               ; Wait for user input for 10s
exten => 1,1,Voicemail(1@default)        ; user-id@context
exten => 2,1,Dial(DAHDI/1-1)
exten => 9,1,Hangup
exten => i,1,Goto(s,1)                   ; "i" stands for invalid entry,
                                         ; play "menu" message again
exten => t,1,Goto(s,1)                   ; "t" stands for timeout,
                                         ; play "menu" message again

;;; 8500 to access Voicemail
exten => 8500,1,VoicemailMain


One line has been added to the voicemail.conf file: 
[default]

1 => 1234,Example Mailbox,root@localhost
; Syntax: user-id => pin, mailbox, user

When the user dials 8500 to access his/her voicemail, voicemail prompts for user-id and pin as defined above.To record your own welcome message, add the following to extensions.conf
[default]
;;; Record voicemail
; Record voice file to /tmp directory
  exten => 205,1,Wait(2) ; Call 205 to Record new Sound Files
  exten => 205,2,Record(/tmp/asterisk-recording:ulaw) ; Press # to stop recording
  exten => 205,3,Wait(2)
  exten => 205,4,Playback(/tmp/asterisk-recording) ; Listen to your voice
  exten => 205,5,wait(2)
  exten => 205,6,Hangup

Remember to change the file name from “asterisk-recording” to “menu” (or whichever name defined in the Background() call. 

[Giving credit to the references I used IVR menu, Voicemail and Dialplan]




Note: a follow up post re: Xlite and IPBlue interworking...