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!