Tuesday, December 25, 2012

PortGo SIP softphone with Asterisk 11

Something weird with Asterisk 11 and portGo that drove me nuts and finally figured the damn thing out.

So here’s my issue, when I use Asterisk 11 and port go, calls signaling can work but as soon as audio is to be transmitted, it hang up the call. After debugging on Asterisk, found that it was a remote disconnection request. Then it was obvious it is something to do with RTP, so I went into PortGo’s setup and click on Misc there was the RTP setting. I had to manually set the RTP setting there to something like 12000 to 12020, or whatever range of your fancy. And now it works, damn..

image

Monday, December 24, 2012

Setting up Channel Event Logging (CEL) on Asterisk 1.8 or up with MySQL and using FreePBX 2.11’s new CDR module to list em’

Hi guys, firstly wishing everyone a Merry Christmas…This would probably be my last posting here on technical matters for 2012. Lets usher in 2013 with some cool new FreePBX 2.11 CEL support.

In this guide, I will try to help you setup CEL which is one of the best things that happened in Asterisk 1.8 and up when it comes to audit/security. If you are using the official FreePBX-3.211.63 version, it will already come with CEL support, so you just need to switch it on or off like explained below. Those don’t have or not using the official distro, hope this guide helps.


With FreePBX 2.11 (in beta now), you can easily view CEL events straight from FreePBX’s CDR module (Reports). Here’s the how-to. Do improvise for whatever OS flavor you are running :). Lots of good advice taken off this link here from FreePBX dev team.

Assuming the following environments/conditions are already running and working for you already

1) Debian 6

2) Asterisk 1.8 or higher

3) FreePBX 2.11 (NOTE only 2.11 in beta now supports CEL. You must use FreePBX CDR module 2.11 or higher. Best thing is to make sure you get the modules in FBX updated to latest online repo.

We will be using the following backend

1) MySQL DB

2) ODBC to connect to MySQL

IMPORTANT to note that the CDR with CEL support is in its infancy stage. Be sure to update it as frequently as available online. I do have some “annoyance” with this interface such as when you pull down the LINKIDs, you get to see all the events but you can’t seem to click on another LINKID, you have to reload the page or do your searches again. Yes, a little annoying but I am sure the FBX team is aware of this and will fix it when they do. This same behavior was noticed on the Distro too… :D

Firstly, we will need all the required ODBC related files for Asterisk to compile res_odbc and CEL with ODBC support.

  1. # apt-get update && apt-get install unixODBC-dev libmyodbc
  2. Go into your Asterisk source directory, and make sure you recompile, like this
  3. # make clean && ./configure && make menuconfig (if you browse around you will see that the CEL ODBC is selected under Channel Event Logging)
  4. Quit menuselect, then do # make && make install
  5. Lets populate our new tables and structure inside asteriskcdrdb (if don’t already exist, it could exist after compiling CEL CDR via Asterisk installation, you might want to check and skip some steps in item 5). Change values like “pass” accordingly to your MySQL root password. NOTE: I had to make the font small down here so that it first in one line, remember, these are one liners.
    # cd /usr/src
    # wget -O celcdr.sql http://pastebin.com/download.php?i=XNuN2DZL
    # mysql -u root -ppass asteriskcdrdb < ./celcdr.sql
    # mysql -h localhost -u root -ppass  mysql --execute="GRANT ALL PRIVILEGES ON asteriskcdrdb.* TO celadmin@localhost IDENTIFIED BY 'pass';"
    # mysql -h localhost -u root -ppass mysql --execute="FLUSH PRIVILEGES"

  6. Create an ODBC connection to your local MySQL (modify accordingly your username and pass needed to connect to Asterisk and if the IP is your NIC ip, change to that or if the MySQL is remote, change accordingly. )
    # nano /etc/odbc.ini

    [mysql-odbc]
    Description           = ODBC to Mysql
    Driver                = MySQL
    Database              = asteriskcdrdb
    Server                = 127.0.0.1
    UserName              = celadmin
    Password              = pass
    Socket                = /var/run/mysqld/mysql.sock 
    option                = 3

  7. ###Take note on the socket path for other OSes##

    # nano /etc/odbcinst.ini

    [MySQL]
    Description = ODBC for MySQL
    Driver = /usr/lib/odbc/libmyodbc.so
    Setup = /usr/lib/odbc/libodbcmyS.so
    FileUsage = 1
  8. Now, lets edit Asterisk configurations to use CEL in MySQL, edit the /etc/asterisk/cel.conf file, search and modify the following values
    NOTE: In our case, I am recording all events from all apps. Format your date according to your fancy, here I set it up to show like 23-12-2012 22:12:48 or don’t set it to leave it to Asterisk default.

    # nano /etc/asterisk/cel.conf
    enable=yes   
    apps=all
    events=ALL
    dateformat = %d-%m-%Y %T
  9. Edit the res file now, add these at the bottom of these files.
    # nano /etc/asterisk/res_odbc.conf
    [asterisk]
    enabled => yes
    dsn => mysql-odbc
    username => celadmin
    password => pass
    pooling => no
    limit => 1
    pre-connect => yes
    # nano /etc/asterisk/cel_odbc.conf

    [cel]
    connection=asterisk
    table=cel
    username=celadmin
    password=pass
    loguniqueid=yes

  10. Then restart amportal (# amportal kill && sleep 2 && amportal start)
  11. To check, go into Asterisk CLI and type “cel show status”, you should see a bunch of stuff thrown out. Basically telling you that CEL is running and logging.
  12. To further check, make a call, if you use a tool like adminer or phpmyadmin or simply from MySQL CLI, you should start to see lines captured in CEL raw like here after making some test calls.
    image
  13. If you see above, great so far, otherwise, just go into asterisk –rv and see if there’s any errors thrown when making calls with regards to res_odbc…its very likely permission or passwords, so fix them and restart asterisk again.
  14. When I enabled the CEL on Asterisk, FreePBX seem to have automatically detected it and set the value of CEL to yes, so really nothing much to do then…woohoo!
    image
  15. That’s just about it. Now, be minded that the original CDR table still remains inside asteriskcdrdb CDR table and FBX is now reading off CEL table. Here’s how it looks with an expanded CEL event. Click on the IDs in “System” column items to expand the call’s events.
    image
  16. NOTE, for my install, I had to click on Search again when I wanted to select another call to list. Meaning, its not like its pushing the list below, it “opens” up just that call info/event that you clicked. Nothing below.
  17. If you don’t want CEL, and want to use back good ole flat CDR, simply reverse the setting in item 13 above to set it to FALSE
  18. Be sure to watch that disk space, for a single call, there could be 10s of lines hah…

Monday, December 10, 2012

WebRTC and Asterisk 11 using sipML5 (with some FreePBX compatibility)

[UPDATED: 29 Mar 2014]

- IMPORTANT: THE PATCH IS NO LONGER NEEDED IN ASTERISK 11.5

The following guide was taken off various sources as initial references such as Digium’s Wiki and sipML5’s how to for Asterisk found here.
And yes, again, this guide is mainly targeted to Debian users, other OS users, please improvise and do your best. Otherwise, drop me a note at sanjayws@gmail.com
OK, to begin, here are my components I am using

  1. Debian 6.0.7
  2. Asterisk 11.5
  3. Chrome Version 29.0.1547.66 m for Windows
  4. sipML5 (Thanks to Dubango Telekom http://www.doubango.org/)
  5. FreePBX (optional)
First, you need a working Asterisk 11.5 installation. If you don’t have one, use this guide here[don’t use this, its not updated, yet].  Be sure to use 11.5 as this guide is designed for that version!
Here’s a step by step with some explanation, remember only # cli codes you can copy paste
  1. Go to your source
  2. # cd /usr/src/
  3. Get libsrtp (as WebRTC only allows comms using secure / encrypted connections)
  4. # wget http://srtp.sourceforge.net/srtp-1.4.2.tgz && tar -zxvf srtp-1.4.2.tgz && cd srtp
  5. # ./configure
  6. # make && make install
  7. Now, we upgrade/update/install asterisk 11.5 if you’re not already running that particular version, if you are, skip the related parts here (points 8-11)
    # wget http://downloads.asterisk.org/pub/telephony/asterisk/asterisk-11.5.tar.gz && tar -zxvf asterisk-11.5.0.tar.gz
    # cd /usr/src/asterisk-11.5.0 && make clean
  8. # ./configure --with-crypto --with-ssl --with-srtp=/usr/local/lib
  9. If you have errors with SRTP, you might want to just simply use apt/yum etc, e.g. #apt-get install libsrtp0 libsrtp0-dev
  10. [FREEPBX USERS]# contrib/scripts/get_mp3_source.sh
  11. [FREEPBX USERS]# make menuselect.makeopts
  12. [FREEPBX USERS]# menuselect/menuselect --enable format_mp3 --enable res_config_mysql --enable app_mysql --enable app_saycountpl --enable cdr_mysql --enable EXTRA-SOUNDS-EN-GSM
  13. Now time to reconfigure and recompile Asterisk with SRTP etc (WARNING, do not make samples if you have working configurations or use FreePBX etc)
  14. # make && make install
  15. Configure some parameters on Asterisk / config files
  16. Edit the /etc/asterisk/sip.conf (or modify Asterisk SIP Settings in FreePBX), add/modify the following settings, in [general]. Notice we add transport ws and wss, these are websocket and websocket secure

    udpbindaddr=0.0.0.0:5060
    realm=<yourIP or name> e.g. 192.168.2.239
    transport=udp,ws
  17. Edit the /etc/asterisk/rtp.conf and we add support for STUN (now supported on Asterisk 11). Read here for more info. Change/modify to your own if you don’t want to use the sample here.

    icesupport=yes

    stunaddr=stun.l.google.com:19302

    NOTE: You can use any STUN server of your choice, but be sure it works otherwise you will have slow network connection etc..
  18. Edit the http.conf file /etc/asterisk/http.conf, look for and modify or with an empty config, paste this below (uncomment if they are commented with a ; )

    [general]
    enabled=yes
    bindaddr=0.0.0.0
    bindport=8088


    Be sure its running after restarting Asterisk, check like below, you should be seeing output showing LISTEN somewhere
    # netstat -an | grep 8088
  19. Now, create one (or more if you wish to do browser to browser calls, for other phones create a normal SIP extensions like how you would do ) SIP accounts in /etc/asterisk/sip.conf with example below (FreePBX users modify it in /etc/asterisk/sip_custom.conf or if you are using FreePBX 2.11.10 or higher, the device/extensions page now directly supports WebRTC settings, see image below)

    [8000]

    secret=C@mplEX123
    context=from-internal
    host=dynamic
    trustrpid=yes
    sendrpid=no
    type=friend
    qualify=yes
    qualifyfreq=600
    transport=udp,ws
    encryption=yes
    dial=SIP/8000
    callerid=Sanjay Willie <8001>
    callcounter=yes
    avpf=yes
    icesupport=yes

    directmedia=no
  20. [FREEPBX USERS] FreePBX 2.11.10 or higher, supports the WebRTC settings directly in its device/extensions settings page, here’s what you set.
    Capture

  21. [FREEPBX USERS Pre versions 2.11.10] Since I also have older FreePBX versions, I use the context from-internal, where my dialplans are already created by FreePBX for me. For this customized extension to work, I created a SIP extension 2001 but under the DIAL I placed SIP/8000 instead so that it will ring my custom sip account and also the dialplan is now registered inside FreePBX’s dialplan to reach 8000. So. basically, now when I want to reach 8000 I actually dial 2001, get it? Otherwise write a simple dialplan like shown below the image
    image

    [from-internal-custom]
    exten => 8000,1,Dial(SIP/8000)
    same  => n,Hangup(16)

  22. [FREEPBX USERS] FreePBX users using 2.11.10 or higher, do not need to the above way as it is directly supported in its device/extensions settings already.
  23. Now, restart Asterisk (kill and start)
  24. Now, its time we get the sipML5 webphone and let’s get started!
  25. Go to your source directory, e.g. /usr/src, get the source using SVN, if you don’t have SVN, you need to install it (see how here)
  26. Assuming your web(http) default directory is in /var/www
  27. # svn checkout http://sipml5.googlecode.com/svn/trunk/ /var/www/myphone (note, some systems it may be /var/www/html/myphone)
  28. chown -R asterisk:asterisk /var/www/myphone/ (or /var/www/html/myphone)
  29. Now, head on to your Google Chrome browser and type
  30. http://<yourIP>/myphone/demos/call.htm (e.g. http://192.168.2.239/myphone/call.htm)
  31. Click on Expert Mode, select to Disable Video.
  32. Enter the information like below except change the part where it says the IP, of course, enter your own IP there
     image
  33. Those NATting, be sure to have a stun entry like shown above: [{ url: 'stun:stun.l.google.com:19302'}]. If you’re not NATting, then just put two [] like that and the ICE/STUN will not be used to manage RTP and you call will be connected faster as well. Be sure the stun you use on your server side is the same used on SIPML5 as well.
  34. Websocket URL: ws://192.168.2.239:8088/ws  (Note this is not an SSL enabled site, i.e. using just ws, not wss, if you want to use WSS as the protocol, then you need to enable it on Asterisk’s HTTP server by generating keys etc…)
  35. Click on Save
  36. Go back to the other tab which the webphone is on, enter the SIP extension detailed you created above, or follow and modify per example below
     image
    Display name: Sanjay Astiostech
    Private Identity: 8000 (or your extension number)
    Public Identity: sip:8000@192.168.2.239 (if you are doing some NAT, it will be like sip:8000@202.188.0.133 where the IP will be a public IP or name)
    Password: C@mplEX123
    Realm: 192.168.2.239
    Now click Login!, you should see the text Connected, like above in my picture
  37. Now, dial and dial away…..e.g. outbound call
    image
  38. Now I use my Zoiper softphone to dial 8018 (or 8000 as per example), remember, it’s a “virtual” number we manipulated on FreePBX or manual dialplan to dial SIP/8018 (or in our example its SIP/8000) instead and here’s how it looks! Chrome receiving a call! [diagram below may not depict actual numbers, these are on my cloud servers]
      image image
  39. Now you can go ahead and try using it on another Chrome browser or other browsers, like Internet Explorer, Firefox and the rest and do give your feedback. But for other browsers you need a piece of software or set some configuration, see here.
  40. For mobile browsers, i tried Google Chrome and it worked with version 29.0.1547.72. Meantime, you can checkout Bowser (yes BOWSER) a WebRTC supported mobile web browser for iPhone and Android, however I had some issues with javascript complaining, hope you have better luck…If you did manage to get it to work, let us know and share with the community.
  41. An important thing to note, Webrtc definition allows to only use only g711 and OPUS. So, consider bandwidth repercussions using this solution as OPUS is not yet ready on Asterisk, so we have to live with g711 for now. In Asterisk 12, Opus support is passthru and that could be very cool :-)
  42. Don’t want the headaches of all of these installation steps, use PIAX - http://pbxinaflash.com/community/index.php?threads/new-webrtc-with-asterisk-11.15274/#post-99636 …ready to rock with WebRTC
  43. If you’re having one way audio issues, enable rtp debugging, you must see the text “VIA ICE” somewhere when the RTP packets are traversing.

 

Field notes

  1. If you get Got SIP response 603 "Failed to get local SDP" back when dialling to a WebRTC client, its probably because you enabled video but didn’t set it up correctly on extension and sip general level (Not covering video here, sorry). Solution is disable video from Asterisk SIP General (FREEPBX USERS, or in your SIP general settings)
  2. To speed up connection(call) you can disable stun gathering in expert setting, by setting ICE Server: [] – Put two square brackets there
  3. Its possible to use and start calling from latest Chome on Android, unfortunately the audio on my side seem to be stuttering, its something to do with ICE haven't got the the time to figure out yet. Perhaps its a fix needed in Chrome for Android, lets wait a tab bit longer for that, shall we..

  4. Each time you reload FreePBX/Asterisk, you need to relogin on SipML5

 

 

Tuesday, December 4, 2012

Asterisk 11 and chan_motif on FreePBX 2.11 (..still cooking with manual dialplans for GTalk..)

FreePBX does have chan_motif (currently GUI supports only GVoice ) with module under UNSUPPORTED category in Module Admin. But first, before getting there, we need to setup Asterisk 11 to enable
Here’s the howto, this is of course assuming that you’ve installed Asterisk 11 already (so it is now a recompile exercise here). If you need to install fresh, try my article here:
  1. # cd /usr/src
  2. # wget http://iksemel.googlecode.com/files/iksemel-1.4.tar.gz
  3. # cd iksemel-1.4
  4. # ./configure && make && make all && make install
  5. # cd /usr/src/asterisk*
  6. # make clean
  7. # ./configure
  8. # make menuselect (be sure that in Channel Drivers, see if the chan_motif driver is shows a * symbol.
  9. # make && make install
  10. Stop and restart asterisk # amportal kill && amportal start
Now, sign in to FreePBX
  1. Go to Admin | Module Admin
  2. Be sure to also select UNSUPPORTED as the options for repositories
  3. Lookout for the Google Voice/Chan Motif under Connectivity, install and go to that page
  4. Go to Connectivity | Google Voice [Motif]
  5. Configure happily there
image
I will update this article for use with GTALK later…since GVoice is done via FreePBX heck, why do dialplans Smile

Quick and Dirty Asterisk 11 and FreePBX 2.11 (RC) installation guide

[UPDATE 11-09-2013 – FREEPBX 2.11 FULL RELEASE]
MORE UPDATE : Why not try our VMWare Image of Asterisk 11 and FBX2.11B2, no installation required! Fully functional and business ready.
Hi guys, been a while since I got my hands on the blogging software. Anyway, I would like to share a simple guide to get an Asterisk 11 and FreePBX 2.11 (full release) running on a Debian 6.0x OS. If you use other OSes, the only thing you will probably change is the software repo manager (debians use apt, centos will like use yum) and the packages name. It won’t run too far from the installation shown here. Here’s a quick guide to install to Ubuntu (close to debian installation) and CentOS.
NOTES
  • You should use FreePBX 2.11 as it officially supports Asterisk 11. Other versions may work but things may also break
  • This is a step by step copy paste guide, no explanations are provided. If anything breaks, something is wrong, nothing should break actually
  • # means it’s a command line you need to copy paste.  Of course, don’t copy the # itself, its just an indicator that it’s shell command …
  • Some of the Asterisk installations steps are taken off http://blogs.digium.com (don’t have to reinvent the wheel..)
  • This is not a comprehensive installation with best practices etc, but it does take care of some basic security stuff, do read online as much as possible
  • Get your Debian installed and ready to get worked on, be sure to work on a putty.exe session so be sure to install ssh # apt-get install ssh
  1. # apt-get update && apt-get upgrade    (reboot the box if updates are installed, if clean install no need to reboot)
  2. # apt-get install --force-yes build-essential ssh sudo libxml2 libxml2-dev libtiff4 libtiff4-dev php5 libapache2-mod-php5 php5-cli php5-curl php5-mysql php5-gd libmysqlclient-dev php-pear php-db linux-headers-`uname -r` curl sox apache2 libssl-dev libncurses5-dev bison libaudiofile-dev subversion libnewt-dev libcurl4-openssl-dev libnet-ssleay-perl openssl libauthen-pam-perl libio-pty-perl vim tcpdump  htop php5-cgi mpg123 libdbd-mysql-perl libdbi-perl libhtml-template-perl libnet-daemon-perl libplrpc-perl libterm-readkey-perl mysql-client-5.1 mysql-common libapt-pkg-perl libsqlite3-dev uuid-dev -y   (These include dependencies for FreePBX as well and some extras)
  3. # reboot (yes, reboot, then login to continue from below)
  4. # cd /usr/src/
  5. # wget http://downloads.asterisk.org/pub/telephony/dahdi-linux-complete/dahdi-linux-complete-current.tar.gz 
  6. # wget http://downloads.asterisk.org/pub/telephony/libpri/libpri-1.4-current.tar.gz 
  7. # wget http://downloads.asterisk.org/pub/telephony/asterisk/asterisk-11-current.tar.gz
  8. # tar -zxvf dahdi-linux-complete-current.tar.gz
  9. # tar -zxvf libpri-1.4-current.tar.gz
  10. # tar -zxvf asterisk-11-current.tar.gz
  11. # cd dahdi-*
  12. # make && make install && make config
  13. # cd ..
  14. # cd libpri-*
  15. # make && make install    (if you face errors with esp Ubuntu, you need to get a patch here, you should not see any errors tho)
  16. Before we install Asterisk, we would like to prep it for FreePBX use, e.g. creating groups and users and associating Apache to run as that low privileged user, dependencies etc, etc..
    • # groupadd asterisk
    • # useradd -g asterisk -c "Asterisk PBX" -d /var/lib/asterisk asterisk
    • # mkdir /var/run/asterisk
    • # chown -R asterisk:asterisk /var/run/asterisk
    • # cd /etc/apache2  (now, we will attempt to modify apache configs to run as the new user/group asterisk we just created, steps may be different from other OSes, take note)
    • # mv envvars envvars.old
    • # echo "export APACHE_RUN_USER=asterisk" >> envvars
    • # echo "export APACHE_RUN_GROUP=asterisk" >> envvars
    • # echo "export APACHE_PID_FILE=/var/run/apache2.pid" >> envvars
    • # echo "export APACHE_RUN_DIR=/etc/apache2" >> envvars
    • # echo "export APACHE_LOG_DIR=/var/log/apache2" >> envvars
    • # chown -R asterisk:asterisk /var/lib/php5
    • # /etc/init.d/apache2 restart
  17. # cd ..
  18. # cd /usr/src/asterisk-11*
  19. # contrib/scripts/get_mp3_source.sh
  20. # ./configure && make menuconfig (when the menu pops up, be sure to select under Add-ons, format_mp3, res_config_mysql, app_mysql, app_saycountpl and cdr_mysql. Now, go to Extra Sound Packages and if you can’t see that left menu option just keep scrolling down using your down arrow key, when you found it, move over to the right menu then select Extra-Sounds-En-WAV, in core sound packages, also select the WAV version for best compatibility. Save and exit) 
  21. # make && make install && make samples (NOTE: Don’t need to make config since we are using FreePBX and we start amportal rather than just asterisk itself)
  22. At this point you have a running Asterisk server! Congrats, now comes FreePBX. But there’s not much configs, so be prepared for Asterisk complaining about stuff and all if you try to start it.
  23. apt-get install -y mysql-server (when prompted, create the MySQL password, for this guide, we will use my@sql as the password
  24. cd /usr/src
  25. wget http://mirror.freepbx.org/freepbx-2.11.0.tar.gz (replace appropriate version that’s newer when available, see here )
  26. tar -zxvf freepbx*
  27. # cd freepbx*
  28. # mysqladmin create asteriskcdrdb -h localhost -u root -p (Enter your MySQL password as above when prompted)
  29. mysql -u root -p asteriskcdrdb < /usr/src/freepbx-2.11.0/SQL/cdr_mysql_table.sql (Enter your MySQL password when prompted, also note the directory of FreePBX to match the ver you downloaded)
  30. mysqladmin create asterisk -h localhost -u root -p (Enter your MySQL password as above when prompted)
  31. mysql -u root -p asterisk < /usr/src/freepbx-2.11.0/SQL/newinstall.sql (Password again)
  32. # mysql -h localhost -u root -p  mysql --execute="GRANT ALL PRIVILEGES ON asteriskcdrdb.* TO asteriskuser@localhost IDENTIFIED BY 'fbx@mysql';" (Note: Here we create a new user for FreePBX to use MySQL and that is user asteriskuser with password fbx@mysql, change accordingly)
  33. mysql -h localhost -u root -p  mysql --execute="GRANT ALL PRIVILEGES ON asterisk.* TO asteriskuser@localhost IDENTIFIED BY 'fbx@mysql';"
  34. # cd /usr/src/freepbx-2.11.0/
  35. # mysql -h localhost -u root -p mysql --execute="FLUSH PRIVILEGES"
  36. # asterisk && ./install_amp (AT THIS POINT, ONLY ENTER THE DATABASE PASSWORD YOU CREATED IN STEP 34, in the case above that would be fbx@mysql)
  37. # /var/lib/asterisk/bin/module_admin upgradeall
  38. # /var/lib/asterisk/bin/module_admin reload
  39. Now to sign on to FreePBX. Go to your server http://<ipaddress>/html, default username and password is admin/admin be sure to change that too!!!
  40. Immediately update all modules in module admin
  41. NOTE: If you see FreePBX complain about some symlinks, do this below rm /etc/asterisk/iax.conf
    rm /etc/asterisk/sip.conf
    rm /etc/asterisk/extensions.conf
    rm /etc/asterisk/logger.conf
    rm /etc/asterisk/features.conf
    rm /etc/asterisk/sip_notify.conf
    rm /etc/asterisk/confbridge.conf
    rm /etc/asterisk/ccss.conf
    rm /etc/asterisk/cel.conf
    rm /etc/asterisk/cel_odbc.conf
    rm /etc/asterisk/res_odbc.conf
    /var/lib/asterisk/bin/retrieve_conf

    • Then refresh your FreePBX browser page, and hit Apply Conf. If there are other .conf files interfering, just rm it and retrieve_conf again….
  42. VERY IMPORTANT TO DO THIS NOW!!!
    • Change the admin password | Go to Admin | Administrators, select admin and change the password there
    • Change your AMI password – Go to Settings | Advanced Setting | under Asterisk Manager, change it there to something of your choice
    • Change ARI password – Go to Settings | Advanced Settings | under System Settings, change User Portal Admin Password to something of your choice
    • Get all the latest packages – Go to Admin | Module Admin |  select Basic and Extended, click on download all, upgrade all, click process, wait to download, click Apply
    • Sometimes, the SIP Nat settings can be wrong, click on Advanced | Asterisk SIP Settings | Be sure to set to Public to get things started..
    • If you get errors with conference just ignore or clear it, it wont come back and conferencing will work just fine
    • You should not screen any significant errors or warnings in the Dashboard
  43. OPTIONALLY, if you want Asterisk to start automatically when reboot
  44. Create a FreePBX startup script
  45. # echo “#!/bin/bash” > /usr/bin/amportal-start
    # echo “/usr/local/sbin/amportal start” >> /usr/bin/amportal-start
    # echo “exit 0” >> /usr/bin/amportal-start
    # chmod +x /usr/bin/amportal-start

  46. # nano /etc/rc.local
  47. Before where it says exit 0, paste this line
    # /usr/bin/amportal-start
  48. Reboot at least once
  49. And there you go, functional FreePBX 2.11 with Asterisk 11 ready to go…
  50. Test, test and test more

Known issues (this list keeps getting updated!)

- You might get errors with the FreePBX UI not loading and what not and says server error, tail the apache error log, its likely some module like digium modules breaking it, if you get that, run this

# amportal a ma disable digiumaddoninstaller
# amportal a ma delete digium_phones
# amportal a ma delete digiumaddoninstaller

You can add them later using Module Admin

Thanks and have a great week ahead!
Sanjay

Wednesday, June 13, 2012

Hotel Systems with Asterisk and FreePBX

Over the past few days, we’ve been working on APIs to work with a Hotel system middleware called JDS PMS which links a the Hotel Information System (HIS) and Asterisk.
It’s like this
HIS <–> JDS <—> Asterisk
Our client needed Asterisk to perform several legacy hotel related functions controlled straight from the HIS and parsed via JDS to Asterisk. Functions include
1) Checking in of guest with guest data parsed from the HIS
2) Checking out of rooms
3) Guest move rooms (including moving of user info, messages etc..)
4) Room call barring set automatically when a checkout happens (and allow when check in)
5) Wake up call (centrally done by help of staff or self-help by each guest)
6) Number obfuscation for VIP guest calling rooms (but to service desks its shown)
7) Do not disturb function override (DND override)
8) Update room statuses via phone (Asterisk sends back codes to PMS)
9) Charge mini bar usage via phone (Asterisk sends back codes to PMS)
10) Integrate the billing into the hotel billing system (reading our custom DB)
11) SMS function for phone to phone SMSing within hotel rooms (also used for periodical advertisements). This is central blasting of SIP Messaging
12) Centrally manage call forwards, DND, wake up calls and other user set features

We took the opportunity to make the API cross platform, thus, not only working for JDS but we believe just about any Hotel frontdesk system and middleware system there is.
We needed also to use FreePBX for its powerful features and ease of management and decided to backdoor the programming of FreePBX to achieve all those without breaking the FreePBX framework.
The processes are handled by websockets and is purely on TCI-IP no more old style SMDR or serial raw data! A the point of writing this, we just signed the integration completion document with the client and JDS team to fully certify Asterisk with their hotel system.
These above are just a simple beginning and we know we can do lots and lots more now with JDS PMS.

The picture below is where the hotel is  Smile neat huh…, its an island within Sabah, a state in East Malaysia. Can’t mention much details for privacy purposes Winking smile

Thursday, June 7, 2012

FreePBX/Asterisk Override DND (or Do Not Disturb)

There are cases where you want to make urgent calls and override the DND set by the user on their phones. These scenarios include
1) Hotel style wake up call (download the hotel wake up module for freePBX)
2) Emergency internal calling
NOTE:
This dialplan only works with Asterisk/FreePBX level DND setting (i.e. setting the DND value in ASTDB). It will not work for phone level DND setting)
Use Asterisk 1.8 or higher only
What it does;
1) It unsets the DND value
2) Makes the call
3) Sets back the DND Value
The Dialplan, put these in /etc/asterisk/extensions_custom.conf (for freepbx) or extensions.conf in vanilla installs
[dnd-override]
exten => _X.,1,NoOp(This context overrides DND)
same => n,Set(IFDNDENABLED=${DB(DND/${EXTEN})})
same => n,ExecIf($["${IFDNDENABLED}"="YES"]?Noop(Deleting: DND/${EXTEN} ${DB_DELETE(DND/${EXTEN})}))
same => n,Goto(from-internal,${EXTEN},1)
same => n,Hangup()
;
exten => h,1,NoOp(Adding back DND status if that existed for user ${CONNECTEDLINE(num)})
exten => h,n,ExecIf($["${IFDNDENABLED}"="YES"]?Set(DB(DND/${CONNECTEDLINE(num)})=YES))
exten => h,n,Hangup

Since this context is handling the hangup, therefore we can invoke the h extension to write back the DND value after the channel gets hanged up. If you use any of those hotel calling modules, simply call this dialplan above to invoke DND override.
You can use this context in many different ways, such as the one shown below, where we “authenticate” a request for DND override first, then ask for the extension to dial.
[macro-dnd-override]
exten => s,1,NoOp(DND Override Call)
exten => s,n,Authenticate(12345,a) ;; 12345 is the password here
exten => s,n,Read(DNDOVERRIDECALLNUM,please-enter-your-extension-then-press-pound,,,4)
exten => s,n,Goto(dnd-override,${DNDOVERRIDECALLNUM},1)
exten => s,n,Hangup

You can invoke the macro inside FreePBX by enabling it via Custom Destination, then create a Feature Code via Misc. Applications. Then you can invoke by any dialing you’ve configured there.

Sunday, May 27, 2012

The FreePBX and Asterisk Basic Security Checklist


Past few days I’ve been thinking about the stuff our students were asking during our FreePBX training course. One of the main thing that they were talking about is security and how “bad” Asterisk’s reputation has been with security in the past. I must agree with them. There’s enough worrying cases of poor implementations, deployments and management since Asterisk took center stage some years back giving run for big IP telephony players. AND, we also must say that we’ve had our share of scares and have come a long way since, thanks to mistakes done in the past. The whole security scene with Asterisk (or any products out there) will continue to be a living, growing and evolving problem, no doubt!.
While it is quite easy to “blame it on the people who deploy for not securing it”, I feel its some what also every single Asterisk/FreePBX folks' responsibility as subject matter experts and consultants on Asterisk to keep up the good name of the product and continue helping the community get stronger by helping each other as much as possible.
With that, we advise all those who deploy solutions for their customers, to take into serious consideration some sort of security best practices, starting with those highlighted by Digium here and do keep track of the Asterisk security Advisories here. While there are many other things you need to be aware of and not just Asterisk/FreePBX security, it’s definitely THE STARTING POINT TO LOOK AT.
Anyway:
Here’s a small list of things (a checklist if you may) that you could consider for each deployment out there. These are especially important when you put your server out on the internet (public facing). I would like to highlight, these are merely suggestions and not an ultimatum but I know sure as anything, they do help.

A little bit of something is better than a whole lot of nothing.


Anyway, we would like to present the following things you should implement when you deploy an Asterisk/FreePBX solution. We figured it would make sense to couple it together with FreePBX since it’s probably the most deployed front end.

The 10 security things you should consider after an Asterisk/FreePBX installation

1) Do not open it up to the internet (unless you absolutely need to)

Even for the sake of testing, implement VPNs and firewalling based on source IP addresses to start with. Unless it’s a business requirement, only then put it up on the Internet by following this guide here and lots of esteemed writers out there and their guides too. Firewalling is a must, open only ports you want to be used over the internet. Management ports and protocols such as HTTP/SSH should be disabled from the internet and must have complex credentials.

2) Update everything

A new install should be updated with everything, operating system, FreePBX and Asterisk version. Update does not mean use new versions but the updated version of what version you prefer. Most OS distros like CentOS and Debian, have very easy ways to manage and get updates.

3) Do not use default FreePBX password, use database for authentication

Manual installations of FreePBX may have/use default passwords. Follow these guides to change them.
a) AMI Password
b) MySQL password
c) ARI password (edit amportal.conf or advance settings module)
d) FOP password (edit amportal.conf or advance settings module)
e) Change authtype to database (edit amportal.conf or advance settings module)

3) Create new-anything with complex passwords

Absolutely never create easy to guess extensions, trunks and DISA, etc passwords. The passwords acceptable includes all types of characters and combination. Use them. Here’s a good place to learn about complex passwords. Use the FreePBX Weak Password Detection module to help audit your passwords

4) Limit your extension registration source IP

For all extensions that are not public facing, define that those extensions are only accessible via your internal network. This ACL type limitation can be done at both extensions and trunk levels. On extensions, you have something called the “deny” and “permit” and “host” definition in your trunk settings

5) Use fail2ban, application firewall

Fail2ban will help with some of those scanners out there. If anyone tries to get into your system without providing correct credentials for n number of times, their IP will be banned for as long as you please (using iptables). Here’s how to get fail2ban to work with Asterisk. While many say this is the silver bullet, I strongly disagree, its not, but it sure it a first grand step. I am starting to like BFD nowadays (http://www.rfxn.com/projects/brute-force-detection/) because it is a little more flexible with the rules using simple bash commands to get info and how to ban stuff as opposed to fail2ban which only allows regex

6) Obfuscation

I know, many will say, this is not security, true. It’s not security but it helps. Most people attack Asterisk systems because they know its Asterisk. So, lets try to throw them off course a little shall we?
How? Well, here’s what I suggest to do first (Change/add the fields below in sip.conf or in FreePBX use the SIP Settings module right at the bottom where it says “other sip settings”)
a) useragent=<somethingweird> like useragent=SIPSERVE
b) Change the realm, e.g. realm=sipserve
c) Set alwaysauthreject=yes (here’s why)
d) Using a front firewall, block off IAX2 (4569), AMI (5038) and probably MySQL (3306). All those can give away easily you’re using Asterisk
Remember the above are mostly only to thwart off scripts that look for Asterisk servers in particular.

7) It’s a PBX, let it be a PBX, not a file server, or etc. Reduce surface attacks.

I think the subject matter above speaks for itself. Like your Cisco switch, its meant to be a switch, you don’t put a file server on there do you? So, the Asterisk box is a PBX, don’t put other crap in there.
If there’s a FreePBX module you don’t need, disable or remove it.
If there’s a protocol you don’t need (e.g. IAX2, H323) disable it too.

8) Use custom contexts and/or some neat restrictions in FreePBX 2.10

a) When using FreePBX 2.10, you can set max calls per extension. Set that to one!. There’s really no reason why one extension is firing 10 calls at the same time. They don’t even have phones with that many lines do they?.
b) Use time restrictions for external calls. For example, if your office only works till 8pm at most and starts at 8am, restrict calling out during these times only.
c)Now custom contexts can be used to limit down where an extension can call, e.g. 1000 can only call local numbers. I am sure you will have more people with restrictions then those unrestricted. So if at all an extension is compromised, probability of them hitting a restrictive extension and that may help you reduce the damage.
d) Also, use uncommon dialout prefixes, e.g. #9 to dial out. When an extension gets compromised, the attacker also must learn how you dial out. If there’s no prefixes in their call, then the call will fail. They can’t figure out the dialplan with just a compromised extension!
e) Limit the max amount of calls per trunk level at one time

9) Send commonly compromised numbers/countries to a blackhole

You should create an outbound route right above all that will hit to a fake trunk (create a ZAP/DAHDI trunk and use is as g100). Put all commonly exploited numbers/uncommonly dialed numbers in there. Remember, its like a firewall, close as much down as possible then open as the need arises

10) Turn on as much logging as possible, backup backup

With Asterisk 1.8 there’s a “security” only logging you can switch on but in the lower versions of Asterisk, you should always keep your full log on and flush them periodically if you want. Also, log all CDR calls. Logging helps you look for “odd” stuff for auditing purposes.
Backup your stuff and restore them in case someone gets admin access to your system and changes everything, a restore can quickly bring order back. And of course, backup for the sake of recovering in case sh1t happens, you know Smile

Wednesday, May 16, 2012

Limiting all or just outbound calls time using FreePBX

I found this link that explained how to set maximum time for ALL calls or just OUTBOUND calls using FreePBX.

Thanks to this link/user: http://www.trixbox.org/forums/trixbox-forums/help/how-do-i-limit-call-length-or-call-duration/eihoward

Go to FreePBX General Setting.

You will find two Dialing Options:

To set limits on ALL calls, modify the “Asterisk Dial…” box, to set time limit for Outbound calls, modify the “Asterisk Outbound Dial…”

Here in my server/example, I am setting limit to 4 hours max and 3.9 hours to warning message before hanging up a call (forcefully).

The values are

L(14400000:14040000)

Where L denotes the function Limit and the first value is for the max time and the second is the warning time in milliseconds (1 sec=1000 ms)

image

In the case above, I am only wishing to limit Outbound calls to 4 hours MAX.

Tuesday, May 1, 2012

Asterisk 10’s Confbridge– Extend your existing PBX to support multiparty video and audio conferences with Asterisk10+FreePBX 2.10


I saw an update today on FreePBX 2.10 page that included an online fix to support the new Asterisk 10 conference bridge module called ConfBridge. Previously, all FreePBX past versions, it had always use the meetme conferencing application on Asterisk, which had some limitations as time and need changes. With this new and improved conferencing app on Asterisk 10, has once again, create new fun things to do with Asterisk. Now with the direct support of Asterisk 10 ConfBridge on FreePBX 2.10, you can easily select which conferencing app to use (in this case would be selecting from meetme to confbridge) using FreePBX advance settings.
So what’s the fuss with CONFBRIDGE? (from the Asterisk Wiki here)
Asterisk, since its early days, has offered a conferencing application called MeetMe (app_meetme.so). MeetMe provides DAHDI-mixed software-based bridges for multi-party audio conferencing. MeetMe is used by nearly all Asterisk implementations - small office, call center, large office, feature-server, third-party application, etc. It has been extremely successful as an audio bridge.
Over time, several significant limitations of MeetMe have been encountered by its users. Among these are two of distinction: MeetMe requires DAHDI for mixing, and is thus limited to 8kHz (PSTN) audio sampling rates; and MeetMe is delivered in a fairly static form, it does not provide extensive configuration options.To address these limitations, a new conferencing application, based upon the ConfBridge application introduced in Asterisk 1.6.0, is now available with Asterisk 10. This new ConfBridge application replaces the older ConfBridge application. It is not intended to be a direct replacement for MeetMe, it will not provide feature parity with the MeetMe application. Instead, the new ConfBridge application delivers a completely redesigned set of functionality that most users will find more than sufficient, and in many ways better, for their conferencing needs

Some feature list
1) High quality audio (HD voice) - Advanced, high-performance wide and ultra-wideband conferencing application for 8-192kHz clients
2) Video enabled conferencing
3) Lots of in call conference options such as dynamic volume and microphone settings, add callers manually while in conference, lock and unlock conference, etc)
4) Dynamic conferences (you can host any conference number, anytime for anyone)
5) Profile based (each user can have different settings, such as admin permissions, dsp settings such as per user noise cancellations options (e.g. more echo cancellers for softphone users,..etc)
Also new work is done to do time based conferences, strict start and end times etc…

And yes, you can extend your current PBX to support conferencing straight from your existing architecture, as we call it, Asteriskify or Astrification!

Those want to test, here’s how using FreePBX. NOTE: many many new options as shown above may not directly be incorporated in FreePBX 2.10 but from what I learn, 2.11 is going to be written to support lots of these new stuff.
Just sign in to FreePBX, select advanced settings, look for conference room app, pull down and select app_confbridge. Click on the tiny apply button then the big red apply button. Done!
image

Though the FreePBX team claims it to be very much in BETA (test), it worked well when I fired 20 calls on my 512MB virtual machine at the office over a 5MBps unifi line. Of course, I had no one but myself to speak to in that conference :D hehe.
Anyway, once you’ve selected the conference application, you can apply the settings and go to the Conferencing module in FreePBX and start creating new conferences.

image
It is familiar with most users of FreePBX with the old app_meetme found in all FreePBX versions but in this case, since we selected confbridge, it will not use MEETME instead use CONFBRIDGE;
image

Thursday, March 22, 2012

Asterisk 10 (1.10) SMS (messaging or SIP Messaging) in action



[UPDATE: WORKS FLAWLESSLY WITH ASTERISK 11 TOO…On Asterisk 11, you can choose XMPP as well as the protocol, right now its just SIP:, imagine the possibilities. Also fixed the issue when failed message]

[ANOTHER UPDATE FOR Offline message - We all know when devices are offline, messages cannot be sent and it will be discarded by Asterisk. I've written another dialplan/solution to that here

With Asterisk 10 comes a channel independent dialplan for handling SIP MESSAGING (and jabber if that’s configured) method. In other words, phones that support SIP Messaging can send and receive “SMSes” through Asterisk 10 without the need to dial a channel making it like a regular telco SMS. Older Asterisks requires you to dial and answer a channel before you can send messages (see here).

It worked for me well in Asterisk 10.2.1 and this guide takes you through the process of using SMSing with a dialplan in a four step setup below. Asterisk uses the Message/ast_msg_queue channel to do all SIP Method MESSAGE related processing.

I was using FreePBX 2.10 but I guess it doesn’t quite matter as I am using a custom context anyway.

1) You need to modify your SIP general settings in sip.conf [freepbx users use the SIP Settings in Web GUI and add inside “Other SIP Settings”] add these two lines.

Non FreePBX users, edit sip.conf, under general
accept_outofcall_message=yes
outofcall_message_context=astsms


Save and exit.

We will now create the dialplan inside context astsms [FreePBX users edit the extensions_custom.conf file and put these in]

2) Non freepbx users, edit your extensions.conf file add the following
[astsms]
exten => _.,1,NoOp(SMS receiving dialplan invoked)
exten => _.,n,NoOp(To ${MESSAGE(to)})
exten => _.,n,NoOp(From ${MESSAGE(from)})
exten => _.,n,NoOp(Body ${MESSAGE(body)})
exten => _.,n,Set(ACTUALTO=${CUT(MESSAGE(to),@,1)})
exten => _.,n,MessageSend(${ACTUALTO},${MESSAGE(from)})
exten => _.,n,NoOp(Send status is ${MESSAGE_SEND_STATUS})
exten => _.,n,GotoIf($["${MESSAGE_SEND_STATUS}" != "SUCCESS"]?sendfailedmsg)

exten => _.,n,Hangup()
;
; Handle failed messaging
exten => _.,n(sendfailedmsg),Set(MESSAGE(body)="[${STRFTIME(${EPOCH},,%d%m%Y-%H:%M:%S)}] Your message to ${EXTEN} has failed. Retry later.")
exten => _.,n,Set(ME_1=${CUT(MESSAGE(from),<,2)})
exten => _.,n,Set(ACTUALFROM=${CUT(ME_1,@,1)})
exten => _.,n,MessageSend(${ACTUALFROM},ServiceCenter)
exten => _.,n,Hangup()

exten => _.,n,Hangup()

The above dialplan also send a little error message if the SMS didn’t send out saying its from “ServiceCenter”…

3) Save and exit and reload asterisk. [FreePBX users do #amportal restart]. Send SMSes! Yeah! But make sure you use a phone that supports SIP SMS.
IMPORTANT: In the SMS message center settings in your phone, enter the IP address of your Asterisk Server. In my case, I was using Unidata WiFi phone. As usual, do let us know the outcome and using other phones.
Here’s a message I got using the phone Smile

Confirmed working with:
1) Unidata phones
2) Yealink phones (with SMS capabilities)
3) CSIPSimple on Andriod
4) X-Lite softphone
5) Most phones that support SIP Messaging

camera (1)

Saturday, March 10, 2012

TechDay Asia - My Slides

TechDayAsia | TechDayAsia on FacebookTechday Asia 2012 During TechDay Asia 2012 (in Kuala Lumpur), i presented about Asterisk but more on a business pitch. The idea of the presentation is to let people know about how to start using Asterisk in various ways without changing much from the current setup you may have. Sort of like an integration.So, i gave a couple of scenarios and case studies from our years of requests by various customers. I wanted to share this to everyone out there who wants to get to know Asterisk and start using it without the hassle of a greenfield approach or complete makeover.TechDay-Asia - Sanjay
View more PowerPoint from sanjayws

And here's me presenting. And some pictures from TechDay which was a huge success. Spanning across three countries and cities.

Well done Astiostech boys!




Asterisk / FreePBX limit incoming calls based on DID (on ZAP/Dahdi/SIP) with FreePBX

Image Source: http://appcrawlr.com/android-apps/best-apps-restrict-access

So, we had this challenge by our customer to do this as they are using PRI and supporting multiple customers. Each customer needs to be limited to n number of channels on PRI. When they were using analog that was simply straightforward, its a physical line, so nothing much you can do about “limiting” it is limited by design!

The following guide allows you to limit calls based on

  • A single DID
  • A group of DIDs (in this guide the amount of DIDs per group is limited to 5, add more, improv as you wish)
  • Group DIDs will be a union meaning, if you have DID1 and DID2 with limit of 3 calls, at any one time either calls coming to those DIDs are added up and if exceed 3, it will hangup.

Anyway, here’s a quick how-to to give you an idea how to go about it. Improv as you see fit :-)

Requirements: (my system)

1) FreePBX 2.10 or 2.11
2) Asterisk 1.8 or higher
3) Dahdi based PRI or SIP or just about anything with the use of proper declarations (variables)
4) Use MySQL
5) Debian Wheezy
6) Adminer to run a few MySQL tasks such as creating db/tables, editing values in them etc…

So here’s how:

  1. Create a database inside MySQL called LIMITER
  2. Use adminer and paste the following codes to using the “SQL Command” feature

    USE ` LIMITER`;
    CREATE TABLE `tbl_didlimiter` (
    `group` int(255) NOT NULL AUTO_INCREMENT,
    `data` varchar(100) DEFAULT NULL,
    PRIMARY KEY (`group`)
    ) ENGINE=MyISAM DEFAULT CHARSET=latin1;

  3. Now, we will create a user superuser with password dbgod00, paste the following codes in SQL Command again

    CREATE USER 'superuser'@'localhost' IDENTIFIED BY ‘dbgod00';
    GRANT ALL PRIVILEGES ON LIMITER.* TO 'superuser'@'localhost';
    FLUSH PRIVILEGES;

  4. Now, we edit the dialplan, the most important part! Since i use FreePBX, we use the _custom.conf to add new hacks. So that’s exactly what we are doing here, copy and paste the codes into extensions_custom.conf, like below

    #nano /etc/assterisk/extensions_custom.conf

    ;; DIALPLAN START ;;

    ;; READ ME FIRST
    ;; copyleft sanjay@astiostech.com
    ;; 1. Set trunks to use from-pstn, from-dahdi, from-zaptel OR from-trunk contexts
    ;; 2. The bold highlights may need to be changed depending on what you see in the
    ;; channel variables, most cases we see either EXTEN or FROM_DID or even CALLERID(DNID)
    ;; 3. Be sure this value is available and matching each other, in my case, the value
    ;; ${EXTEN} eventually matches the value ${CALLERID(DNID)} and they must
    ;; 4. This only supports one unique DID entry in DB. IF there are multiple entries
    ;; by mistake or whatever, it will pickout the first result that returns only
    ;;
    ;; 5. Feel free to add more G numbers as shown below, right now its just 5
    ;; 6. Maxdefault is set for global when no DB definitions are found for that DID and its limit,
    ;; if you do not want blanket settings, simply set MAXDEFAULT to blank or “”, if you want to set a global
    ;; limit then set it with MAXDEFAULT which then applies to
    all DIDs not set in DB.
    ;; Only when
    there’s a value found in DB then that DB value’s limits overrides maxdefault 

    [from-pstn-custom]
    exten => _X.,1,NoOp(Handling incoming to do cool stuff)
    same => n,Set(GROUP()=${EXTEN})
    same => n,Macro(didchoke)

    [macro-didchoke]
    exten => s,1,NoOp(Checking for incoming limits and applying if needed)
    exten => s,n,Set(MAXDEFAULT=””)
    exten => s,n,MYSQL(Connect connid localhost superuser dbgod00 LIMITER)
    exten => s,n,MYSQL(Query resultid ${connid} SELECT data from tbl_didlimiter where data like '%${CALLERID(DNID)}%' LIMIT 1)
    exten => s,n,MYSQL(Fetch fetchid ${resultid} DBRESULT)
    exten => s,n,MYSQL(Clear ${resultid})
    exten => s,n,MYSQL(Disconnect ${connid})

    exten => s,n,ExecIf($["${DBRESULT}"=""]?Set(DBRESULT=${CALLERID(DNID)})
    exten => s,n,GotoIf($["${DBRESULT}"=""]?exception)

    ;
    exten => s,n,Set(GROUPLIMIT=${CUT(DBRESULT,:,2)})
    exten => s,n,ExecIf($["${GROUPLIMIT}"=""]?Set(GROUPLIMIT=${MAXDEFAULT})
    exten => s,n,GotoIf($["${GROUPLIMIT}"=""]?exception)
    ;
    exten => s,n,Set(DIDS=${CUT(DBRESULT,:,1)})
    exten => s,n,Set(DID1=${CUT(DIDS,\,,1)})
    exten => s,n,Set(DID2=${CUT(DIDS,\,,2)})
    exten => s,n,Set(DID3=${CUT(DIDS,\,,3)})
    exten => s,n,Set(DID4=${CUT(DIDS,\,,4)})
    exten => s,n,Set(DID5=${CUT(DIDS,\,,5)})
    ;
    exten => s,n,ExecIf($["${DID1}"!=""]?Set(G1=${GROUP_COUNT(${DID1})}))
    exten => s,n,ExecIf($["${DID2}"!=""]?Set(G2=${GROUP_COUNT(${DID2})}))
    exten => s,n,ExecIf($["${DID3}"!=""]?Set(G3=${GROUP_COUNT(${DID3})}))
    exten => s,n,ExecIf($["${DID4}"!=""]?Set(G4=${GROUP_COUNT(${DID4})}))
    exten => s,n,ExecIf($["${DID5}"!=""]?Set(G5=${GROUP_COUNT(${DID5})}))
    ;
    exten => s,n,ExecIf($["${DID1}"=""]?Set(G1=0)
    exten => s,n,ExecIf($["${DID2}"=""]?Set(G2=0)
    exten => s,n,ExecIf($["${DID3}"=""]?Set(G3=0)
    exten => s,n,ExecIf($["${DID4}"=""]?Set(G4=0)
    exten => s,n,ExecIf($["${DID5}"=""]?Set(G5=0)
    ;
    exten => s,n,Set(TOTALGGROUPCHANS=$[${G1}+${G2}+${G3}+${G4}+${G5}])
    exten => s,n,NoOp(So total channels here are ${TOTALGGROUPCHANS} of GROUPLIMIT of ${GROUPLIMIT})
    exten => s,n,GotoIf($["${TOTALGGROUPCHANS}" > "${GROUPLIMIT}"]?overlimit)
    exten => s,n,MacroExit()
    ;
    exten => s,n(overlimit),Busy(20)
    exten => s,n,Hangup(16)
    exten => s,n,MacroExit()
    ;
    exten => s,n(exception),MacroExit()

    ;; DIALPLAN END ;;

  5. Now, reload asterisk dialplan, be sure to tail the log file to start troubleshooting if things don’t go right.
    #asterisk -rx “dialplan reload”
  6. Now, edit the DB values and add DIDs like show in example below, use adminer or similar for easy editing
    E.g. 1 Format: DID1:3
    Where DID1 is DID you wish to limit to 3 channels
    E.g. 2 Format: DID1,DID2,DID3,DID4,DID5:3
    Where DID1-5 are the DIDs you wish to limit to 3 channels combined

    Here’s sample data from my own server!
    image   

Fire away, test it out…! As usual, appreciate the feedback and ideas to improve! Do let us know how it went for you!