A bit like Ubuntu, Asterisk has a long term version support.
From version 1.x to 1.8 continue with 10.x .
Specifications:
PBX futures
From asterisk-1.2 to 1.4
Year 2005-2008
Frameworks API/PBX Enhancements
From asterisk-1.6 to 11
Year 2008-2012
Application Server
From asterisk-12 to latest
Year 2012-Today
The latest Asterisk 13.0.0 LTS version has been released in few weeks ago.
It is supported for four years.
Security tlscipher , Media, Asterisk REST Interface (ARI) and the PJSIP stack in Asterisk are fully integreted.
Alembic scripts has been added for CDR tables
cdr_sqlite should use cdr_sqlite3_custom
PostgreSQL setting and configuration in res_pgsql.conf cdr_pgsql.conf. & cel_pgsql.conf.
SS7 support now requires libss7 v2.0 or later and the related description file in chan_dahdi.conf.sample.
Use chan_motif instead of chan_gtalk and/or chan_jingle
Use chan_ooh323 instead of chan_h323
WebRTC Support with WebSocket transport over SIP.
DTLS-SRTP – A secure transport for RTP media streams used by WebRTC and SIP endpoints.
ICE, STUN and TURN – A set of related technologies for establishing live media streams between software agents running behind network address translators (NATs) and firewalls.
ICE, STUN and TURN have been incorporated into the Asterisk RTP engine as part of the effort to support WebRTC.
Motif – A new channel driver for supporting the Jingle protocol and Google Talk. Motif combines functions previously spread across multiple channels, and makes use of a new and more standards-compliant XMPP implementation.
For more information get:
http://astbook.asteriskdocs.org/
Monday, June 1, 2015
Thursday, February 12, 2015
Yate
Yet Another Telephony Engine
cd /usr/src
svn checkout http://voip.null.ro/svn/yate/trunk yate
cd yate
This will fetch a copy of the SVN TRUNK in a new directory called yate.
Prepare and configure the sources
./autogen.sh
./configure --help
./configure
Look at the configure output and check that all features you need are detected.
If not, install what is missing.
Compile the sources
make
make install-noapi
Dependeciy in case fo errors: kdoc or doxygen package.
Check version
./run -V
Start Yate:
./run -vvvvv -CDo
To run Yate outside your build dir you need to set LD_LIBRARY_PATH so Yate can find libyate.so
echo "/usr/local/lib" >> /etc/ld.so.conf
ldconfig
Service installation
If you will run Yate as server you will need some extra steps so Yate will start automatically when your server starts.
Prepare the init script
You need to copy and rename the proper yate.init from a subdirectory of packing/ to /etc/init.d where all service start scripts are installed.
Info: You may edit the init/upstart file to point to the correct path (/usr/bin -> /usr/local/bin ).
This operation needs that you run as root:
cd /usr/src/yate
cp packing/deb/yate.init /etc/init.d/yate
chown root.root /etc/init.d/yate
You will then need to edit the init file and change the path to the executable from /usr/bin to /usr/local/bin.
Set the service script to start automatically
update-rc.d yate defaults
Start the service manually
Unless you are going to reboot the server you need to do the following once as root:
service yate restart
As a general note, use restart instead of start to avoid accidentally running multiple instances.
For testing the status:
service yate status
Stopping the service manually
service yate stop
Disabling the service
If you want to disable the service you need to disable autostart and also stop it manually:
update-rc.d -f yate remove
service yate stop
The configuration files are in conf.d directory that is found in the root directory where Yate was build.
When Yate is installed from a package the init script in /etc/rc.d/init.d/ should take care of providing the proper init parameters for starting Yate as a service.
Sangoma card driver installation
Download the driver from: ftp://ftp.sangoma.com/linux/current_wanpipe/
As root:
cd /usr/src/
ls
wanpipe-3.5.28.tgz
tar zxvf wanpipe-3.5.28.tgz
cd wanpipe-3.5.28
./Setup install
Acept to install WANPIPE start-up scripts
Test with
wanrouter hwprobe
wanrouter status
Configure Wanpipe
Follow the procedure outlined here to configure Wanpipe into two timeslot groups for YATE. First, as the root user, issue the following command:
wancfg
This will start the WANPIPE Configuration Utility, which will build the Wanpipe configuration files. Press OK at the first screen, select Create a new Configuration File and press Enter. You will see a list of the configuration files that are possible, and their states. For a new installation, press Enter to select wanpipe1.conf. Select the following from the list of detected cards:
AFT-A104u SLOT=2 BUS=5 IRQ=3 CPU=A PORT=1 V=13
If you are not in North America, you will probably need to change the physical medium from T1 to E1 using the first submenu from the next screen. We will write E1 for the physical medium. Next, you’ll have to configure the timeslot groups using the second submenu. You will need to define two timeslot groups: one for the D-channel, and the other for all the B-channels.
E1 configuration:
Timeslot Group 1 Configuration:
Timeslots in Group-> 16
HDLC engine--------> Enabled
Idle char ---------> 0x7E
MTU ---------------> 1200
MRU ---------------> 1200
Timeslot Group 2 Configuration:
Timeslots in Group-> 1-15.17-31
HDLC engine--------> Disabled
Idle char ---------> 0x7E
MTU ---------------> 1200
MRU ---------------> 1200
Specify MTU and MRU values. They should be the same. MTU/MRU values indicate the Rx/Tx CHUNK Size.To calculate MTU/MRU multiply your desired CHUNK size by the number of active channels. eg: 30 channels * 40bytes (which is 5ms voice chunk) = 1200 bytes.
Note: To avoid problems the chunk size must be a multiple of four.
You'll need to tell Wanpipe what each timeslot will be used for. The timeslots will be referred to as w1g1 and w1g2 (Wanpipe 1 group 1 and Wanpipe 1 group 2). If you have a multiport Wanpipe card, you may have other group names as well. For your current purposes, you'll want to be running HDLC streaming on each timeslot, with an operation mode of API. The timeslot group config screens are a little confusing to navigate, but with a bit of back-and-forth you should be able to figure them out. For each timeslot group, set the following:
Protocol: HDLC Streaming
Interface Setup--> 1 defined (select and press Enter)
Interface 1 – w1g1 (select and press Enter)
Operation Mode--> WANPIPE (select and press Enter)
You want to change this to:
Interface Operation Mode: API
The same actions for configuring the Timeslot for Group 2.
Save the file wanpipe1.conf and Exist.
Note: If you need to make changes in wanpipe configuration file please make sure that wanpipe is not running, to avoid errors.
Configuration in Yate
Use this tutorial to: install Yate.
To configure SIP to ISDN gateway you will need:
signaling - This is configured in ysigchan.conf.
- an ISDN trunk (container with a Q.931 call controller, a circuit group (voice circuits), a Q.921 data link and an HDLC signalling interface).
voice circuits that can be:
- local: Sangoma. This is configured in Yate in file: wpcard.conf.
Configure files:
ysigchan.conf
[trunk_isdn1]
type=isdn-pri-net
enable=yes
sig=wanpipe1
voice=wanpipe1
switchtype=euro-isdn-e1
strategy=increment
format=alaw
wpcard.conf
[wanpipe1]
type=E1
siggroup=w1g1
voicegroup=w1g2
Routing all calls through ISDN trunk:
regexroute.conf
[default]
.*=sig/\0;trunk=trunk_isdn1
Start devices
First the wanpipe must be started and then Yate.
Start wanpipe:
wanrouter start
Start Yate:
./run -vvvvv CDo
You can configure your users in regfile.conf or register.conf and start making calls.
For Sangoma binary card
The appropriate RPM can be downloaded from ftp://ftp.sangoma.com/linux/RPMS/.
To install the RPM run
rpm -i --force [the rpm name]
The force option is required to override the old modules.
Configure driver
To configure the driver you should run
/usr/sbin/wancfg
More info about that you will find out in the appropriate section of the manual.
Start Wanpipe
Finally to start Wanpipe the commands "wanrouter start" or "wanrouter start wanpipe1" must be executed.
Google voice
http://www.tuxguides.com/yate-server-free-google-voice-calling/
Set gmail account in accfile.conf :
[MyGMailAccount]
enabled=yes
protocol=jabber
username=GMail_username
password=GMail_password
domain=gmail.com
options=allowplainauth
Load Jabber client module
Since jabberclient is a client module, not loaded when Yate is running in server mode, you must explicitly load it. To do that set in yate.conf:
[postload]
${modulepath}/client/jabberclient${modsuffix}=yes
Set Yate Server with jingle in client mode
By default the jingle channel detects Yate run mode and behaves accordingly. To use it in client mode when Yate runs as server, set in yjinglechan.conf:
[general]
servermode=no
Configure users
In regfile.conf
[123]
password=secretpass
Routing calls in regexroute.conf :
[default]
; Route calls to contacts in MyGMailAccount roster
^123$=jingle/mycontact@domain;line=MyGMailAccount
; Route calls received on MyGMailAccount line
${in_line}MyGMailAccount=sip/sip:SIP_number@a.b.c.d
Using SIP MESSAGE or how to enable chat messages in SIP
By default Yate doesn't accept SIP MESSAGE requests.
To allow them in set enable=yes in message section from ysipchan.conf.
[message]
; Controls the behaviour for SIP messaging
; enable: bool: Allow the SIP module to receive MESSAGE requests
enable=yes
; auth_required: bool: Automatically challenge all senders for authentication
;auth_required=enable
; async_process: bool: Process SIP MESSAGE asynchronously in their own thread
;async_process=enable
SMSC
This is a basic example of storing received SIP MESSAGES in a database. Besides this you will need to add the logic that takes the messages from the database and sends them.
In javascript.conf in section scripts:
[scripts]
sip_messages=smsc.js
In mysqldb.conf define the database account:
[smsc]
database=smscdb
user=mysql
password=yate
Then in smsc.js from share/scripts directory in yate's sources (unless you configured a different path in javascript.conf or you installed yate) write the logic:
function onCallRoute(msg)
{
Engine.output("Handling call.route caller="+msg.caller+" called="+msg.called);
if (msg.route_type=="msg") {
var m = new Message("database");
m.account = "smsc";
m.query = "INSERT INTO sms(caller,called,message) VALUES('" + sql_escape(msg.caller) + "','" + sql_escape(msg.called) + "','" + sql_escape(msg.xsip_body) + "')";
m.dispatch();
}
}
function sql_escape(val)
{
// ..
return val;
}
Message.install(onCallRoute, "call.route", 50);
Allowing SIP MESSAGE only for some users
Here is an example of a javascript global script that allows SIP MESSAGE only for user 101.
In javascript.conf in section scripts:
[scripts]
sip_messages=filter_sip_messages.js
Then in file filter_sip_messages.js from share/scripts:
function onCallRoute(msg)
{
Engine.output("Handling call.route caller="+msg.caller+" called="+msg.called);
if (msg.route_type=="msg") {
if (msg.caller!="101") {
Engine.output("Stopping SIP MESSAGE for user "+msg.caller);
msg.reason = "rejected";
}
}
}
Message.install(onCallRoute, "call.route", 50);
How to route and bill from a database
Install devel packages for PostGreSQL in your platform. Then in Yate sources run:
./configure
make
Then start Yate:
./run -vvvvv -CDo
Check if module is loaded
Note: Check if module PostGreSQL is loaded. It is required to be loaded so that Yate can connect to database.
Verify module loading when starting Yate
When Yate starts you can see a list of modules that are loaded. If PostGreSQL does not appear, you must install the devel packages, then reload Yate.
./run -vvvvv -CDo
yate.conf
[general]
modload=no
[modules]
pgsqldb.yate=yes
Configuration
The configuration file is pgsqldb.conf. It is found in directory conf.d where Yate sources are.
The file must be renamed from pgsqldb.conf.sample into pgsqldb.conf.
There can be multiple connections to different databases.
pgsqldb.conf
[general]
; This section is special - holds settings common to all connections
; priority: int: Handler priority
;priority=100
; Each other section in this file describes a database connection
;[default]
; The section name is used as the database connection name
; autostart: bool: Automatically initiate the connection on startup
;autostart=yes
; timeout: int: Query timeout in milliseconds
;timeout=10000
; retry: int: How many times to retry the connection or query
;retry=5
; encoding: string: Character set encoding used to communicate with the server
; If not set will match the encoding of server side database
;encoding=
; connection: string: Ready-built client connection string for PQconnectStart
; If this is not set the string is built from the following pieces
; Take care if you set this - it will override anything that follows
;connection=
; host: string: PostgreSQL server to connect to
;host=localhost
; port: int: Port on which the server is listening for connections
;port=5432
; database: string: Name of the database to use in queries
;database=yate
; user: string: Username to use to access the database
;user=postgres
; password: string: Password to authenticate the user to the database server
;password=
Example
Example of configuring an PostGreSQL database account in file pgsqldb.conf:
[yateadmin]
host=localhost
port=5432
database=yateadmin
user=postgres
password=yate_admin
This is where a new connection is made.
You can have multiple connections to different databases.
The name between [] will be used in other configuration files to set the used account.
If you need to store CDRs, you will have to use register.conf file, so that Yate will know which connection to make.
register.conf
[general]
account=yateadmin
status pgsqldb
%%+status:pgsqldb
name=pgsqldb,type=database,format=Total|Failed|Errors|AvgExecTime;conns=0,failed=0
%%-status
If line name=pgsqldb,.... don't appear in the list that means that module is not loaded. Install devel packages. Then restart Yate for changes to take place.
Enable messages
In register.conf file you have to activate handlers for each message you are going to use. That means that you have to enable parameters:
- user.auth=yes -> Activate handler on the user.auth message. Used to authenticate users.
- user.register=yes -> Activate handler on the user.register message. Used for users registration.
- call.route=yes -> Activate handler on the call.route message. Used to route the calls.
- call.cdr=yes -> Activate handler on the call.cdr message. Used to write CDRs in the database.
Configure database in Yate
There are 3 steps to accomplish this task:
create your database with tables that you need for your configuration (here is an example of a database schema).
put the credentials of the database of the database created in Yate's configuration file: pgsqldb.conf).
'tell' Yate which connection to use when users will be registered. This is done in register.conf file.
Set the connection information of database
In PostgreSQL configuration file: pgsqldb.conf we have to set the connection data for this database in a section that will have the same name as the account settled in register.conf:
[yateadmin]
host=localhost
port=5432
database=yateadmin
user=postgres
password=secret
After "=" you have to write your connection information.
Set the name of the database connection
When using register module, set the name of the database connection in section [default]:
[default]
account=yateadmin
Define, authenticate, register Users
The users with their information will be kept in the database. You can see table users as an example of a table schema.
Then in register.conf you have to authenticate, register your users by enabling user.auth and user.register in [general] and writing their associated queries.
To authenticate and register users user.auth and user.register are enabled. register.conf
[general]
user.auth=yes
user.register=yes
[user.auth]
query=SELECT password FROM users WHERE username='${username}'
result=password
[user.register]
query=UPDATE users SET location='${data}',expires=CURRENT_TIMESTAMP + INTERVAL '${expires} s' WHERE username='${username}'
Route calls from database
See an example of a database schema.
In register.conf in section [general] the call.route and call.cdr must be enabled. They are used for routing the calls and writing the call logs in the database.
[general]
call.route=yes
call.cdr=yes
[call.route]
query=SELECT location,(CASE WHEN location IS NULL THEN 'offline' ELSE NULL END) AS error FROM users WHERE username='${called}'
result=location
[call.cdr]
initquery=UPDATE cdr SET ended=true WHERE ended IS NULL OR NOT ended
cdr_initialize=INSERT INTO cdr VALUES(TIMESTAMP 'EPOCH' + INTERVAL '${time} s','${chan}','${address}','${direction}','${billid}',\
'${caller}','${called}',INTERVAL '${duration} s' ,INTERVAL '${billtime} s',INTERVAL '${ringtime} s','${status}','${reason}',false)
cdr_update=UPDATE cdr SET caller='${caller}',called='${called}',duration=INTERVAL '${duration} s',billtime=INTERVAL '${billtime} s',\
ringtime=INTERVAL '${ringtime} s',status='${status}',reason='${reason}' WHERE chan='${chan}' AND billid='${billid}'
cdr_finalize=UPDATE cdr SET caller='${caller}', called='${called}', duration=INTERVAL '${duration} s',billtime=INTERVAL '${billtime} s',\
ringtime=INTERVAL '${ringtime} s',status='${status}',reason='${reason}',ended=true WHERE chan='${chan}' AND billid='${billid}'
For more complex routing like routing to registered lines(gateways) which are defined in the database, you can do a stored procedures.
cd /usr/src
svn checkout http://voip.null.ro/svn/yate/trunk yate
cd yate
This will fetch a copy of the SVN TRUNK in a new directory called yate.
Prepare and configure the sources
./autogen.sh
./configure --help
./configure
Look at the configure output and check that all features you need are detected.
If not, install what is missing.
Compile the sources
make
make install-noapi
Dependeciy in case fo errors: kdoc or doxygen package.
Check version
./run -V
Start Yate:
./run -vvvvv -CDo
To run Yate outside your build dir you need to set LD_LIBRARY_PATH so Yate can find libyate.so
echo "/usr/local/lib" >> /etc/ld.so.conf
ldconfig
Service installation
If you will run Yate as server you will need some extra steps so Yate will start automatically when your server starts.
Prepare the init script
You need to copy and rename the proper yate.init from a subdirectory of packing/ to /etc/init.d where all service start scripts are installed.
Info: You may edit the init/upstart file to point to the correct path (/usr/bin -> /usr/local/bin ).
This operation needs that you run as root:
cd /usr/src/yate
cp packing/deb/yate.init /etc/init.d/yate
chown root.root /etc/init.d/yate
You will then need to edit the init file and change the path to the executable from /usr/bin to /usr/local/bin.
Set the service script to start automatically
update-rc.d yate defaults
Start the service manually
Unless you are going to reboot the server you need to do the following once as root:
service yate restart
As a general note, use restart instead of start to avoid accidentally running multiple instances.
For testing the status:
service yate status
Stopping the service manually
service yate stop
Disabling the service
If you want to disable the service you need to disable autostart and also stop it manually:
update-rc.d -f yate remove
service yate stop
The configuration files are in conf.d directory that is found in the root directory where Yate was build.
When Yate is installed from a package the init script in /etc/rc.d/init.d/ should take care of providing the proper init parameters for starting Yate as a service.
Sangoma card driver installation
Download the driver from: ftp://ftp.sangoma.com/linux/current_wanpipe/
As root:
cd /usr/src/
ls
wanpipe-3.5.28.tgz
tar zxvf wanpipe-3.5.28.tgz
cd wanpipe-3.5.28
./Setup install
Acept to install WANPIPE start-up scripts
Test with
wanrouter hwprobe
wanrouter status
Configure Wanpipe
Follow the procedure outlined here to configure Wanpipe into two timeslot groups for YATE. First, as the root user, issue the following command:
wancfg
This will start the WANPIPE Configuration Utility, which will build the Wanpipe configuration files. Press OK at the first screen, select Create a new Configuration File and press Enter. You will see a list of the configuration files that are possible, and their states. For a new installation, press Enter to select wanpipe1.conf. Select the following from the list of detected cards:
AFT-A104u SLOT=2 BUS=5 IRQ=3 CPU=A PORT=1 V=13
If you are not in North America, you will probably need to change the physical medium from T1 to E1 using the first submenu from the next screen. We will write E1 for the physical medium. Next, you’ll have to configure the timeslot groups using the second submenu. You will need to define two timeslot groups: one for the D-channel, and the other for all the B-channels.
E1 configuration:
Timeslot Group 1 Configuration:
Timeslots in Group-> 16
HDLC engine--------> Enabled
Idle char ---------> 0x7E
MTU ---------------> 1200
MRU ---------------> 1200
Timeslot Group 2 Configuration:
Timeslots in Group-> 1-15.17-31
HDLC engine--------> Disabled
Idle char ---------> 0x7E
MTU ---------------> 1200
MRU ---------------> 1200
Specify MTU and MRU values. They should be the same. MTU/MRU values indicate the Rx/Tx CHUNK Size.To calculate MTU/MRU multiply your desired CHUNK size by the number of active channels. eg: 30 channels * 40bytes (which is 5ms voice chunk) = 1200 bytes.
Note: To avoid problems the chunk size must be a multiple of four.
You'll need to tell Wanpipe what each timeslot will be used for. The timeslots will be referred to as w1g1 and w1g2 (Wanpipe 1 group 1 and Wanpipe 1 group 2). If you have a multiport Wanpipe card, you may have other group names as well. For your current purposes, you'll want to be running HDLC streaming on each timeslot, with an operation mode of API. The timeslot group config screens are a little confusing to navigate, but with a bit of back-and-forth you should be able to figure them out. For each timeslot group, set the following:
Protocol: HDLC Streaming
Interface Setup--> 1 defined (select and press Enter)
Interface 1 – w1g1 (select and press Enter)
Operation Mode--> WANPIPE (select and press Enter)
You want to change this to:
Interface Operation Mode: API
The same actions for configuring the Timeslot for Group 2.
Save the file wanpipe1.conf and Exist.
Note: If you need to make changes in wanpipe configuration file please make sure that wanpipe is not running, to avoid errors.
Configuration in Yate
Use this tutorial to: install Yate.
To configure SIP to ISDN gateway you will need:
signaling - This is configured in ysigchan.conf.
- an ISDN trunk (container with a Q.931 call controller, a circuit group (voice circuits), a Q.921 data link and an HDLC signalling interface).
voice circuits that can be:
- local: Sangoma. This is configured in Yate in file: wpcard.conf.
Configure files:
ysigchan.conf
[trunk_isdn1]
type=isdn-pri-net
enable=yes
sig=wanpipe1
voice=wanpipe1
switchtype=euro-isdn-e1
strategy=increment
format=alaw
wpcard.conf
[wanpipe1]
type=E1
siggroup=w1g1
voicegroup=w1g2
Routing all calls through ISDN trunk:
regexroute.conf
[default]
.*=sig/\0;trunk=trunk_isdn1
Start devices
First the wanpipe must be started and then Yate.
Start wanpipe:
wanrouter start
Start Yate:
./run -vvvvv CDo
You can configure your users in regfile.conf or register.conf and start making calls.
For Sangoma binary card
The appropriate RPM can be downloaded from ftp://ftp.sangoma.com/linux/RPMS/.
To install the RPM run
rpm -i --force [the rpm name]
The force option is required to override the old modules.
Configure driver
To configure the driver you should run
/usr/sbin/wancfg
More info about that you will find out in the appropriate section of the manual.
Start Wanpipe
Finally to start Wanpipe the commands "wanrouter start" or "wanrouter start wanpipe1" must be executed.
Google voice
http://www.tuxguides.com/yate-server-free-google-voice-calling/
Set gmail account in accfile.conf :
[MyGMailAccount]
enabled=yes
protocol=jabber
username=GMail_username
password=GMail_password
domain=gmail.com
options=allowplainauth
Load Jabber client module
Since jabberclient is a client module, not loaded when Yate is running in server mode, you must explicitly load it. To do that set in yate.conf:
[postload]
${modulepath}/client/jabberclient${modsuffix}=yes
Set Yate Server with jingle in client mode
By default the jingle channel detects Yate run mode and behaves accordingly. To use it in client mode when Yate runs as server, set in yjinglechan.conf:
[general]
servermode=no
Configure users
In regfile.conf
[123]
password=secretpass
Routing calls in regexroute.conf :
[default]
; Route calls to contacts in MyGMailAccount roster
^123$=jingle/mycontact@domain;line=MyGMailAccount
; Route calls received on MyGMailAccount line
${in_line}MyGMailAccount=sip/sip:SIP_number@a.b.c.d
Using SIP MESSAGE or how to enable chat messages in SIP
By default Yate doesn't accept SIP MESSAGE requests.
To allow them in set enable=yes in message section from ysipchan.conf.
[message]
; Controls the behaviour for SIP messaging
; enable: bool: Allow the SIP module to receive MESSAGE requests
enable=yes
; auth_required: bool: Automatically challenge all senders for authentication
;auth_required=enable
; async_process: bool: Process SIP MESSAGE asynchronously in their own thread
;async_process=enable
SMSC
This is a basic example of storing received SIP MESSAGES in a database. Besides this you will need to add the logic that takes the messages from the database and sends them.
In javascript.conf in section scripts:
[scripts]
sip_messages=smsc.js
In mysqldb.conf define the database account:
[smsc]
database=smscdb
user=mysql
password=yate
Then in smsc.js from share/scripts directory in yate's sources (unless you configured a different path in javascript.conf or you installed yate) write the logic:
function onCallRoute(msg)
{
Engine.output("Handling call.route caller="+msg.caller+" called="+msg.called);
if (msg.route_type=="msg") {
var m = new Message("database");
m.account = "smsc";
m.query = "INSERT INTO sms(caller,called,message) VALUES('" + sql_escape(msg.caller) + "','" + sql_escape(msg.called) + "','" + sql_escape(msg.xsip_body) + "')";
m.dispatch();
}
}
function sql_escape(val)
{
// ..
return val;
}
Message.install(onCallRoute, "call.route", 50);
Allowing SIP MESSAGE only for some users
Here is an example of a javascript global script that allows SIP MESSAGE only for user 101.
In javascript.conf in section scripts:
[scripts]
sip_messages=filter_sip_messages.js
Then in file filter_sip_messages.js from share/scripts:
function onCallRoute(msg)
{
Engine.output("Handling call.route caller="+msg.caller+" called="+msg.called);
if (msg.route_type=="msg") {
if (msg.caller!="101") {
Engine.output("Stopping SIP MESSAGE for user "+msg.caller);
msg.reason = "rejected";
}
}
}
Message.install(onCallRoute, "call.route", 50);
How to route and bill from a database
Install devel packages for PostGreSQL in your platform. Then in Yate sources run:
./configure
make
Then start Yate:
./run -vvvvv -CDo
Check if module is loaded
Note: Check if module PostGreSQL is loaded. It is required to be loaded so that Yate can connect to database.
Verify module loading when starting Yate
When Yate starts you can see a list of modules that are loaded. If PostGreSQL does not appear, you must install the devel packages, then reload Yate.
./run -vvvvv -CDo
yate.conf
[general]
modload=no
[modules]
pgsqldb.yate=yes
Configuration
The configuration file is pgsqldb.conf. It is found in directory conf.d where Yate sources are.
The file must be renamed from pgsqldb.conf.sample into pgsqldb.conf.
There can be multiple connections to different databases.
pgsqldb.conf
[general]
; This section is special - holds settings common to all connections
; priority: int: Handler priority
;priority=100
; Each other section in this file describes a database connection
;[default]
; The section name is used as the database connection name
; autostart: bool: Automatically initiate the connection on startup
;autostart=yes
; timeout: int: Query timeout in milliseconds
;timeout=10000
; retry: int: How many times to retry the connection or query
;retry=5
; encoding: string: Character set encoding used to communicate with the server
; If not set will match the encoding of server side database
;encoding=
; connection: string: Ready-built client connection string for PQconnectStart
; If this is not set the string is built from the following pieces
; Take care if you set this - it will override anything that follows
;connection=
; host: string: PostgreSQL server to connect to
;host=localhost
; port: int: Port on which the server is listening for connections
;port=5432
; database: string: Name of the database to use in queries
;database=yate
; user: string: Username to use to access the database
;user=postgres
; password: string: Password to authenticate the user to the database server
;password=
Example
Example of configuring an PostGreSQL database account in file pgsqldb.conf:
[yateadmin]
host=localhost
port=5432
database=yateadmin
user=postgres
password=yate_admin
This is where a new connection is made.
You can have multiple connections to different databases.
The name between [] will be used in other configuration files to set the used account.
If you need to store CDRs, you will have to use register.conf file, so that Yate will know which connection to make.
register.conf
[general]
account=yateadmin
status pgsqldb
%%+status:pgsqldb
name=pgsqldb,type=database,format=Total|Failed|Errors|AvgExecTime;conns=0,failed=0
%%-status
If line name=pgsqldb,.... don't appear in the list that means that module is not loaded. Install devel packages. Then restart Yate for changes to take place.
Enable messages
In register.conf file you have to activate handlers for each message you are going to use. That means that you have to enable parameters:
- user.auth=yes -> Activate handler on the user.auth message. Used to authenticate users.
- user.register=yes -> Activate handler on the user.register message. Used for users registration.
- call.route=yes -> Activate handler on the call.route message. Used to route the calls.
- call.cdr=yes -> Activate handler on the call.cdr message. Used to write CDRs in the database.
Configure database in Yate
There are 3 steps to accomplish this task:
create your database with tables that you need for your configuration (here is an example of a database schema).
put the credentials of the database of the database created in Yate's configuration file: pgsqldb.conf).
'tell' Yate which connection to use when users will be registered. This is done in register.conf file.
Set the connection information of database
In PostgreSQL configuration file: pgsqldb.conf we have to set the connection data for this database in a section that will have the same name as the account settled in register.conf:
[yateadmin]
host=localhost
port=5432
database=yateadmin
user=postgres
password=secret
After "=" you have to write your connection information.
Set the name of the database connection
When using register module, set the name of the database connection in section [default]:
[default]
account=yateadmin
Define, authenticate, register Users
The users with their information will be kept in the database. You can see table users as an example of a table schema.
Then in register.conf you have to authenticate, register your users by enabling user.auth and user.register in [general] and writing their associated queries.
To authenticate and register users user.auth and user.register are enabled. register.conf
[general]
user.auth=yes
user.register=yes
[user.auth]
query=SELECT password FROM users WHERE username='${username}'
result=password
[user.register]
query=UPDATE users SET location='${data}',expires=CURRENT_TIMESTAMP + INTERVAL '${expires} s' WHERE username='${username}'
Route calls from database
See an example of a database schema.
In register.conf in section [general] the call.route and call.cdr must be enabled. They are used for routing the calls and writing the call logs in the database.
[general]
call.route=yes
call.cdr=yes
[call.route]
query=SELECT location,(CASE WHEN location IS NULL THEN 'offline' ELSE NULL END) AS error FROM users WHERE username='${called}'
result=location
[call.cdr]
initquery=UPDATE cdr SET ended=true WHERE ended IS NULL OR NOT ended
cdr_initialize=INSERT INTO cdr VALUES(TIMESTAMP 'EPOCH' + INTERVAL '${time} s','${chan}','${address}','${direction}','${billid}',\
'${caller}','${called}',INTERVAL '${duration} s' ,INTERVAL '${billtime} s',INTERVAL '${ringtime} s','${status}','${reason}',false)
cdr_update=UPDATE cdr SET caller='${caller}',called='${called}',duration=INTERVAL '${duration} s',billtime=INTERVAL '${billtime} s',\
ringtime=INTERVAL '${ringtime} s',status='${status}',reason='${reason}' WHERE chan='${chan}' AND billid='${billid}'
cdr_finalize=UPDATE cdr SET caller='${caller}', called='${called}', duration=INTERVAL '${duration} s',billtime=INTERVAL '${billtime} s',\
ringtime=INTERVAL '${ringtime} s',status='${status}',reason='${reason}',ended=true WHERE chan='${chan}' AND billid='${billid}'
For more complex routing like routing to registered lines(gateways) which are defined in the database, you can do a stored procedures.
Subscribe to:
Comments (Atom)