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!

Friday, December 2, 2011

How to explain Nagios to grandma

So I visited grandma couple of days back and while talking about work and politics and all, she asked, so what’s this Nagios thing you guys are experts at?
I replied, its an “Enterprise Monitoring Solution” and she went like “Enterprise what now….”, and that actually got me thinking deep (something that i rarely do).
So anyway, to answer gramps pressing question, I gave this analogy.

Take for example a car


One thing cars these days come with are essential gauges to let us know what’s going on inside this technically complex electrical and mechanical marvel. This is called a dashboard.
So dashboards in a car gives us all these really cool information; and while cool, they’re also very essential for the well being and running of that car.

Most modern cars, you can tell the fuel levels, battery status, gear status, hand breaks statuses and what not. All essential right? And some more expensive cars like beamers, will even tell you that you’re due for a service soon!. Now, like many of us, the first thing I do when I power up my baby is to check this dashboard and see all that’s going on and when things are fine, engage gear, pull down that windscreen and breathe all the lovely smog from Kuala Lumpur air. {deep chesty cough x 2}
Now here’s where it gets difficult, lets take the challenge of watching over 10, or 100 or even 1000 cars all at the same time and to know at point in time and accuracy if one of these babies of yours isn’t behaving properly. While its possible to do one at a time but sometimes, it may be too late before you reach car no 99 to know that the battery has been completely discharged. Ouch!..can’t use that car until it gets fixed now… :-(

Fear not car lover, here’s where Nagios comes to play. It is designed in such a way, doesn’t matter which type of car you drive and how the dashboard works, if it is in that dashboard, we can take all the important status information and put them in an easy to use web page for all those cars you manage.
Not only that, when a car reaches a fuel level of less than 10% (or anything you think its important to know about before it goes bonkers), Nagios can..
a) email you
b) send you smses
c) call you
d) put up a message on facebook for you
e) set an appointment with you mechanic

And there ya go, she got it, and thereafter, she went back straight to her room to sleep. But I knew she understood, I do….
Now back in geek-land…
Imagine those cars as servers, devices, applications/software, virtual or cloud infrastructure and what not. Each of these in some small or elaborate way have their own “dashboards” that come in a form of a simple log entry to a popups on your device saying something is wrong and what not. Again, to manage just this one, perhaps its very fine. But imagine managing hundreds, on top of that, a single server can potentially host tens of important apps, making it alone “a lot” to monitor.
The cool thing about Nagios is, you can really literally monitor whatever that server/apps/device  shows you, no gimmicks no joke..Monitor just about any type of hardware, OS, application and of a bare minimum, a plain ole log file!
Give it a try and see the power of Nagios for yourself.
Happy weekend.

Tuesday, November 1, 2011

Nagios Plugin–Advance Traceroute to check between two devices


We had to create a plugin to basically do the following
1) Do a typical traceroute from the Nagios box to a destination IP
2) Instead of calculating the time between the Nagios to Destination Host, we are interested to know the time between two host in between

In other words, a typical traceroute will
NagionServer –> Gateway –> Hop 1 –> Hop 2 –> Hop 3 –> Destination

What this plugin can do is when defined correctly, to check the time (in ms) between Hop 1 up until Hop 3, plot a graph and put up warning and critical values for your alerting.
Here’s the sample plugin, and relevant configuration files you probably need.
NOTE: You may need to tweak for different  Oses other than Debian as this was created and tested with a Debian.
The plugin
  • The plugin (place typically in /usr/local/nagios/libexec)
  • Paste below into a file say trace_time
  • Make sure it belongs to user <nagios> and has execution right; e.g.
  • chown nagios:nagios /usr/local/nagios/libexec/trace_time
  • chmod +X /usr/local/nagios/libexec/trace_time
#####START PLUGIN#####
#!/bin/bash
#
# usage
# ./trace-time <final-dest> <startip> <endip> <warning> <critical>
# Note: You must define all three, there's no error checking
# tip: do a traceroute first, then determine from which ip to which ip do you want to calculate. If
#
#
DEST=$1
IP1=$2
IP2=$3
WARNING=$4
CRITICAL=$5
PROG=`which traceroute`
if [[ $DEST == "" ]]; then
   
    echo "UNKNOWN: No destination ip defined"
    exit 3
fi

if [[ $IP1 == "" ]]; then
        echo "UNKNOWN: No start ip defined"
    exit 3
fi

if [[ $IP2 == "" ]]; then
    IP2=$DEST
fi
if [[ $WARNING -eq "" ]]; then
        echo "UNKNOWN: No warning value defined"
        exit 3
fi
if [[ $CRITICAL == "" ]]; then
        echo "UNKNOWN: No critical value defined"
        exit 3
fi

if [[ $WARNING  >  $CRITICAL ]]; then
        echo "UNKNOWN: Warning value larger than critical value"
        exit 3
fi
#
myepoch=`date +%s`
filename=/tmp/$myepoch.tmp.txt
tempfile=/tmp/$myepoch.output
#
/bin/touch $filename
/bin/touch $tempfile
#
/bin/chown nagios:nagios $filename
/bin/chown nagios:nagios $tempfile
#
#
getreading=`$PROG -n -q 1 $DEST > $tempfile`
#
numberip1=`cat $tempfile | grep ms | grep $IP1 | awk {'print $1'}`
numberip2=`cat $tempfile | grep ms | grep $IP2 | awk {'print $1'}`
#
#
for i in $(seq $numberip1 $numberip2)
do
   
    getms=`cat $tempfile | sed -e 's/^[ \t]*//' | grep ^$i |  awk {'print $3'}`
    echo $getms >> $filename
done
#
startcalc=`awk '{s+=$0} END {print s}' $filename`
#
rm $filename
rm $tempfile
#
# OUTPUTS
#
grapher="$IP1-->$IP2"
#
if awk 'BEGIN{if(0+'$startcalc'>'$CRITICAL'+0)exit 0;exit 1}'
then
        echo "CRITICAL($startcalc): Time exceed critical value|$grapher=$startcalc;$WARNING;$CRITICAL"
        exit 2
fi
if awk 'BEGIN{if(0+'$startcalc'>'$WARNING'+0)exit 0;exit 1}'
then
        echo "WARNING($startcalc): Time exceed warning value|$grapher=$startcalc;$WARNING;$CRITICAL"
        exit 1
       
else
   
        echo "OK($startcalc): Time OK|'$grapher'=$startcalc;$WARNING;$CRITICAL;;"
        exit 0
fi
#####END PLUGIN#####

Nagios – Host.cfg
define host{
        use                     debian5-linuxserver
        host_name     Google WWW server
        alias                   For Tracing TimeHop Distances
        address            209.85.175.105
        }           

Nagios – commands.cfg
define command{
        command_name    check_time_between_hosts
        command_line    $USER1$/trace-time $HOSTADDRESS$ $ARG1$ $ARG2$ $ARG3$ $ARG4$
         }

Nagios – services.cfg
define service{
        use                                       debian5-linuxservice
        host_name                       Google WWW server
        service_description      Between IP 210.5.40.153 to 209.85.250.237
        action_url                          /nagios/pnp/index.php?host=$HOSTNAME$&srv=$SERVICEDESC$
        check_command            check_time_between_hosts!210.5.40.153!113.23.161.66!10!20
       }
* Note, the template debian5-linuxservice and debian5-linuxserver is not default and you need to define one first or use the defaults
Now, just restart Nagios to make it work.

More info
In order for you to know the hop you wish to monitor, simply do a traceroute;
# traceroute -n -q 1 209.85.175.105
-n = Numeric output
- q 1= Only do a single query
In this example below, I am tracing to one of Google’s servers at 209.85.175.105, the output of the trace is like below (NOTE!: actual IPs have been changed)
1  111.22.42.3  0.554 ms
2  111.22.40.153  0.667 ms
3  111.22.40.125  1.026 ms
4  203.188.233.121  1.218 ms
5  203.188.233.205  1.488 ms
6  113.23.161.66  1.627 ms
7  209.85.242.246  1.542 ms
8  209.85.242.125  2.322 ms
9  66.249.94.158  3.075 ms
10  209.85.175.105  2.801 ms

So lets say you wish to trace the time between IP 111.22.40.153 and IP113.23.161.66, simply use the plugin with these values on the CLI (to test);
# ./trace-time 209.85.175.105 111.2.40.153 113.23.161.66 10 20
And the output will look like this;
OK(5.909): Time OK|'111.22.40.153-->113.23.161.66'=5.909;10;20;;
*Which is a typical output expected by Nagios with PNP graphing enabled
Graphs will look like this
image

Sunday, August 28, 2011

pfSense and TM Unifi


This is to show you how to enable pfSense 2.x and use TMNet’s Unifi.
Important to note that inorder to “dial” into Unifi, you must fire the PPPoE through a VLAN and those are VLAN 500 for your regular internet browsing and VLAN 600 for your Video. This guide is to setup basic internet using pfSense.
Assuming you are using at least 2 interfaces, the LAN (in this guide, eth0), which all your local networks (or regular users) are connected, the other interface is WAN (in this guide, eth 1) which will be the one that will dial into Unifi.
image

Your LAN can be easily configured to any IP which you wish your users to connect to. This will typically be the gateway IP address for your users. The interface we will discuss here is the WAN interface.
So summary of the steps to get it working;
1) Define the WAN interface as null (or none)
2) Setup VLAN 500 and tie it to the WAN interface or eth1
3) Setup PPPoE inside VLAN interface

1) Defining WAN interface as null.
Simply go to WAN interface and set it up as none. Save it. Setup like below
image

2) Define a new interface:
On pfSense’s main menu, click on Interfaces and click on (assign). Click on VLANs. Select WAN (or eth1) as the parent interface. Inside VLAN tag, enter 500. Put a nice description, like VLAN-TMUnifi there if you so wish. Click on save.
image
3) Setup PPPoE on the VLANned interface:
Now, click on Interfaces again, click on (assign). Click on the + to add a new interface and select the newly created VLAN-TMUnifi. Notice the interface name that was created for you like OPT1 or OPT2. Click on interfaces again, select (and in this example), OPT1. Click to enable the interface. Under type, select PPPoE. Scroll down to the username and password part. Enter your username and password respectively.
You can also rename your interface as for example, from OPT1 to UNIFPPP (for example):
image

Before you click on save, make sure you select, Block private and bogon networks. They should not pass through this interface (unlike interface LAN).
Now, once you’ve save, click on the blue S icon on the top right of the page. If all config such as username and password is correct, you should see the interface come up like below;
image
If you have problems, click on, Status, click on System Log files then click on PPP. Any issues or errors will be shown there.

Once done, you need to setup gateways and routing correctly in order to route traffic over this new interface you just created and dialed.
image
You should set it up as default unless you have other gateways and such. Otherwise, setting it as default will quickly allow you to browse.
Well that’s it, also of course don’t forget to setup an allow rule from interface LAN to any (to begin with) and allow that connection.
If you need to allow incoming connections, select the UNIFPPP interface instead of WAN and setup your inbound rules there.
Enjoy pfSense and the speed of Unifi!
PS> If you are interested in our appliance, do write to sanjay@astiostech.com. Should cost you around US250/box with 4G flash, enclosure, 3 NICs, 2 USB ports (can use for 3G usb modems etc).

Saturday, August 13, 2011

Using Asterisk call files with FreePBX (using Local channel)

Call files are perhaps one of the coolest things you can do with Asterisk. Just literally dump the file in a particular directory and voila, you can make a call. Past few days, I’ve been playing around with it quite a bit and would like to share some things with you on using the Local channel which is most beneficial since you may wish to take advantage of the dialplans and call flows defined in FreePBX (for instance).
Now, the Local channel does a lot such as checks if voicemail is enabled, call forwarding (follow-me) and other customization to the user’s account. It also would support the Device and User mode if that’s being used. The Local channel rather than using technology channels directly can help with several things again for example restrictions that may apply (context) for a particular user. Using channels like SIP/1000 and IAX/1000 will literally bypass all the good stuff that may have been setup.
In conjunction with asterisk call files e.g. .call. You can do lots! including lots of automation and what not just like how you would do using AMI or any AGI stuff if you know about them. Here I would like to show you how to take advantage of the Local channel in call files.
Channel: Local/2000@from-internal/n
CallerID: <0386892800>
MaxRetries: 0
RetryTime: 1
WaitTime: 10
Context: from-internal
Extension: 86892888
Priority: 1 
Archive: no
Set: AMPUSER=2000
Now try modifying these above values to match your specific needs, e.g. channel 2000 is a user 2000 attached to device 1000, change that, change Extension to the destination you wish to bridge a call and here’s what’s important for device/user mode, you must specify the AMPUSER value otherwise, the macro-set-callerid will not be able to set right variables such as outbound CID for you since the Local/2000 will eventually be using SIP/1000 and SIP 1000 doesn’t really have anything more than just a connection agreement (username/password).
Create this file anywhere and then dump it into /var/spool/asterisk/outgoing and voila, you’ve got call.
Also, would like to share a script to automatically create and move files for you; note this will work with FreePBX 2.8 or higher and Asterisk 1.8.
1) nano /root/callgenerator.sh
2) Paste the script below

#!/bin/bash
user=$1
dial=$2

if [[ "$user" -eq "" ]]; then
    echo "ERROR No User / Destination Defined"
    exit 2
fi

if [[ "$dial" -eq "" ]]; then
    echo "ERROR No Destination Number Specified"
    exit 2
fi

# generate call file
mydate=`date +%d%m%y_%H%M%S`
filename="$mydate.U-$user-D-$dial.call"
#
# SUPPORT ONLY SIP
echo -e "Channel: Local/$dial@from-internal/n
CallerID:
MaxRetries: 0
RetryTime: 1
WaitTime: 10
Context: from-internal
Extension:*60
Priority: 1
Archive: no
Set: AMPUSER=$user" > /var/spool/asterisk/$filename

# Call now
# File ops
chown asterisk:asterisk /var/spool/asterisk/$filename
mv /var/spool/asterisk/$filename /var/spool/asterisk/outgoing/ > /dev/null 2>&1
if [[ $? -ne 0 ]]; then
    echo "ERROR Parsefile crashed"
    exit 2
else
    echo Start calling..
fi

exit 0


3) Make it executable chmod +x /root/callgenerator.sh
Test it out like this /root/callgenerator.sh 2000 986892888 (where 2000 is the user’s phone that will first ring and once picked up, it will proceed with the other leg of the call i.e. 986892888, its important here to use from-internal otherwise, your dialplan routing and prefix handingling (in this case, the number 9) will not be stripped off when calling).

Thursday, August 4, 2011

FreePBX IVR direct dial across multiple locations/asterisk servers/FreePBX servers


Assuming you have 2 FreePBX servers across two location that are connected via a trunk and the trunk dialling does work fine. Meaning you can already call SiteA and SiteB and vice-versa.
SiteA: Extensions 1000 and on
SiteB: Extensions 2000 and on
With the default IVR context in FreePBX it’s limited to local numbers only (in this case SiteA extensions). Imagine if you had a PRI line coming into Site A and the IVR direct dial would then need to reach extensions on Site B, this will by default will not work.
Here’s how to “extend” the IVR dialling to other locations. NOTE, we assume the outbound route doesn’t have a prefix to dial intersite between Site A or Site B.
1) nano /etc/asterisk/extensions_custom.conf
2) Enter the following codes (here’s Site A IVR trying to reach site B)
[from-did-direct-ivr-custom]
exten => _2XXX,1,ExecIf($["${BLKVM_OVERRIDE}" != ""]?Noop(Deleting: ${BLKVM_OVERRIDE}: ${DB_DELETE(${BLKVM_OVERRIDE})}))
exten => _2XXX,n,Set(__NODEST=)
exten => _2XXX,n,Goto(from-internal,${EXTEN},1)

#NOTE each line should start with exten like below, on single lines
image
3) Save the file and reload the dialplan
asterisk –rx “dialplan reload”
Lets say you use prefix 7 to dial site B from site A followed by the extension number. Just edit the part and as an example below;
exten => _2XXX,n,Goto(from-internal,7${EXTEN},1)
Where 7 prefixes automatically is entered before the extension number.
Have fun!