11
Jun/10Linksys SPA3102 And FreePBX On Ubuntu 10.04
Friday, June 11th, 2010Overview
I wanted to setup a Private Branch eXchange(PBX) system using Asterisk server at home. As I already had a traditional land line (PSTN or POTS line) I needed something to bridge the computer to the land line. My idea of having a PBX at was to route as many calls over VOIP which tends to be cheaper like Skype and still use a traditional landline for emergencies as well as just having a landline number.
History
Originally I started writing a post on how to get a PBX with a web interface going on Ubuntu 8.04. However once I had it all installed it wasn’t working 100%. I had issues with permissions and FreePBX had problems with the operation panel. Fast forward 2-3 years and I’m back doing it again but this time on the next LTS release and 7 minor release later from FreePBX.
Ubuntu 10.04 LTS
Asterisk
Asterisk is a free and open source software for PBX. It’s what you see in companies to manage and route all their phones calls. Asterisk is a PBX engine which has several front end engines and even a distribution specially for PBX box called Trixbox. If you just want a headless PBX then installing Asterix will suffice however I was not technically skilled enough to create all configuration files from scratch and also a nice front end will go a long way for the Wife Acceptance Factor (WAF). This is where FreePBX comes in.
FreePBX
FreePBX is GUI interface wrapper for Asterisk. Ubuntu has a FreePBX package in it’s repository. FreePBX uses a web front end so it can be accessed anywhere and makes administration a lot easier. It uses modules to extend the functionally like add-ons in Firefox. These include group pickup to Parking Lots.
With FreePBX this sorts out the software side of my PBX.
Linksys SPA3102
This an Analogue Telephone Adaptor(ATA) which is used to convert a land line to a digital network and a traditional land line phone to the network too. The hardware has been around for a long time and it does work with Asterisk. The SPA(Sipura)3102 can be used as a standalone PBX box too but in my case it will be used to forward incoming and outgoing calls.
The SPA3102 also has a web interface but it can also be used to act as a router at the same time. The web interface is very basic and not very user friendly but has a lot of options making it very customizable and configurable.
Asterisk And FreePBX Install
Switch to root user before installing sudo su.
Install MySQL sudo apt-get install mysql-server
When prompted for password enter one.
Install MySQL modules, PHP, kernel headers for compiling code, apt-get install build-essential linux-headers-`uname -r` openssh-server bison flex apache2 php5 php5-curl php5-cli php5-mysql php-pear php-db php5-gd curl sox libncurses5-dev libssl-dev libmysqlclient15-dev mpg123 libxml2-dev
Go to /usr/src cd /usr/src/
and download the Asterisk source files
xargs wget << SOURCES
http://downloads.asterisk.org/pub/telephony/dahdi-linux-complete/releases/dahdi-linux-complete-2.2.1+2.2.1.tar.gz
http://downloads.asterisk.org/pub/telephony/libpri/releases/libpri-1.4.10.2.tar.gz
http://downloads.asterisk.org/pub/telephony/asterisk/releases/asterisk-1.6.2.6.tar.gz
http://downloads.asterisk.org/pub/telephony/asterisk/releases/asterisk-addons-1.6.2.0.tar.gz
SOURCES
Un-tar(zip) all the source files in /usr/src/ tar xvf dahdi-linux-complete-2.2.1+2.2.1.tar.gz
tar xvf libpri-1.4.10.2.tar.gz
tar xvf asterisk-1.6.2.6.tar.gz
tar xvf asterisk-addons-1.6.2.0.tar.gz
Compile Asterisk in the following order:
cd dahdi-linux-complete-2.2.1+2.2.1
make all && make install && make config
cd ../libpri-1.4.10.2
make && make install
cd ../asterisk-1.6.2.6
./configure
make && make install
make samples
cd ../asterisk-addons-1.6.2.0
./configure
make && make install
make samples
Download and extract extra sounds cd /var/lib/astersik/sounds
wget -O - http://downloads.asterisk.org/pub/telephony/sounds/asterisk-extra-sounds-en-gsm-current.tar.gz | tar xvfz -
Create an Asterisk user account on the Linux box adduser asterisk --disabled-password --no-create-home --gecos "asterisk PBX user"
adduser www-data asterisk
Make a backup of the Asterisk configuration file cp /etc/apache2/apache2.conf /etc/apache2/apache2.conf_orig
Change the Asterisk config to run as a correct user sed -i 's/^\(User\|Group\).*/\1 asterisk/' /etc/apache2/apache2.conf
Create the Asterisk service script which will start and stop the Asterisk demon:
cat > /etc/init.d/asterisk <<-END_STARTUP
#!/bin/bash
### BEGIN INIT INFO
# Provides: asterisk
# Required-Start: \$network \$syslog
# Required-Stop: \$network \$syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Asterisk daemon.
# Description: This script handles start/stop states of asterisk.
### END INIT INFOset -e
set -a
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="Asterisk"
NAME=amportal
DAEMON=/usr/sbin/\$NAMEtest -x \$DAEMON || exit 0
d_start() {
amportal start
}d_stop() {
amportal stop
}d_reload() {
amportal restart
}case "\$1" in
start)
echo -n "Starting \$DESC: \$NAME"
d_start
echo "."
;;stop)
echo -n "Stopping \$DESC: \$NAME"
d_stop
echo "."
;;restart|force-reload)
echo -n "Restarting \$DESC: \$NAME"
d_stop
sleep 10
d_start
echo "."
;;*)
echo "Usage: \$SCRIPTNAME {start|stop|restart|force-reload}" >&2
exit 3
;;esac
exit 0
END_STARTUP
Ensure the permissions of the demon script is correct chmod 755 /etc/init.d/asterisk
Make Asterisk start up when the computer starts update-rc.d asterisk defaults 90 10
Download and extract FreePBX
cd /usr/src/
wget -O - http://mirror.freepbx.org/freepbx-2.7.0.tar.gz | tar xvfz -
cd freepbx-2.7.0/
Copy the Amportal configuration cp amportal.conf /etc/
Set environment variables for the current session. These variables will store the password for MySQL access so that the script can be 100% automated. One is the admin password and the other is the Asterisk database user password. These variables should clear once the terminal session ends but it is advised to remove them from the bash history in ~/.bash_history
export MYSQL_ROOT_PW=abcd
export ASTERISK_DB_PW=wxyz
Run the database scripts:
mysqladmin -u root -p${MYSQL_ROOT_PW} create asterisk
mysqladmin -u root -p${MYSQL_ROOT_PW} create asteriskcdrdb
mysql -u root -p${MYSQL_ROOT_PW} asterisk < SQL/newinstall.sql
mysql -u root -p${MYSQL_ROOT_PW} asteriskcdrdb < SQL/cdr_mysql_table.sql
mysql -u root -p${MYSQL_ROOT_PW} <<-END_PRIVS
GRANT ALL PRIVILEGES ON asterisk.* TO asteriskuser@localhost IDENTIFIED BY "${ASTERISK_DB_PW}";
GRANT ALL PRIVILEGES ON asteriskcdrdb.* TO asteriskuser@localhost IDENTIFIED BY "${ASTERISK_DB_PW}";
flush privileges;
END_PRIVS
Edit the amportal configuration file with the database username and password
sed -i "s/# \(AMPDBUSER=.*\)/\1/" /etc/amportal.conf
sed -i "s/# \(AMPDBPASS=\).*/\1${ASTERISK_DB_PW}/" /etc/amportal.conf
sed -i "s@\(AMPWEBROOT=\).*@\1/var/www/@" /etc/amportal.conf
sed -i "s@\(FOPWEBROOT=\).*@\1/var/www/panel@" /etc/amportal.conf
sed -i "s@\(FOPWEBADDRESS=\).*@PUTIPADDRESS@" /etc/amportal.conf
Change the max PHP file upload size to 120mb in Apache
sed -i 's/\(^upload_max_filesize = \).*/\120M/' /etc/php5/apache2/php.ini
Change the files and directories so that Asterisk has access to them
chown asterisk. /var/run/asterisk
chown -R asterisk. /etc/asterisk
chown -R asterisk. /var/{lib,log,spool}/asterisk
chown -R asterisk. /var/www/
Remove line ending from the Asterisk configuration file.
sed -i '1 s/\(\[directories\]\).*/\1/' /etc/asterisk/asterisk.conf
Start Asterisk
./start_asterisk start
Install FreePBX
./install_amp
Restart Apache server
/etc/init.d/apache2 restart
Create a symlink to the "Music On Hold"(MOH) files
ln -s /var/lib/asterisk/moh /var/lib/asterisk/mohmp3
Start FreePBX
amportal start
Asterisk / PBX Terminology
Before I go into configuring the PBX itself it is worth knowing the terminology behind the technology.
- Extension - Can be considered as an internal phone number. Each extension can be associated with a user and the user and the user can "roam" from phone to phone keeping their phone number.
- Feature Codes - Special phone numbers which can put an extension to do not disturb (DND) so that no phone calls will get through to accessing voicemail.
- Trunk - Provides services to the PBX such as land line or to allow calls to another PBX.
- Routes - The path a call may go. Routes consists of inbound, calls coming in and outbound, calls leaving the system routes.
- Dial Rules - Rules defined in ASCII characters which govern routes e.g Only free phone numbers are allowed to take the land line route. All other numbers should go out to a VOIP provider.
- Channels - Number of simultaneous calls a trunk can handle
Configure FreePBX
First thing to do is set up extensions. Extensions are independent to any available routes as by default Asterisk treats any number dialled as an internal number. Below are steps to create 2 extensions. One number will eventually be assigned to the phone attached to the Linksys SPA3102 and the other for another hard/softphone.
- Go to Setup > Basic > Extensions menu item.
- Ensure "Generic SIP Device" is selected in the Devices drop down box.
- Enter the following details:
- User Extension - Phone number of extension E.G 1000
- Display Name - Friendly name
- Voicemail & Directory Status - Enable this if you want the user to have voicemail facilities
- Secret - Leave blank for now but this is the password for the extension.
- Submit the changes.
- Click on the new extension listed on the right hand side of the Extensions page. This will edit the extension
- Under Device Options section change the Mailbox by removing the @device suffix and just leave the extension number in the field.
- Submit the changes again.
- Repeat the steps above again to create a second extension, changing the extension number, display name and the mailbox setting E.G 1001
- Apply the changes to make it take effect.
At this point I would download a SIP softphone such as X-Lite on two computers and test out the 2 extensions created. Using the X-Lite or other softphones is beyond this article.
For Dialling out of the Sipura 3102 a Trunk is needed as well as configuring the outbound route.
- Go to Setup > Basic > Trunks in FreePBX
- Click on the Add SIP Trunk
- Fill in the following fields:
- Trunk Description - A friendly name for the trunk. This can be anything
- Outbound Caller ID - Full telephone number of the landline including area code.
- CID Options - Any
- Maximum Channels - 1
- Dial Rules - Leave blank
- Outbound Dial Prefix - Leave blank
- Trunk Name - A memorable name which will be used in the Sipura configuration
- Peer Details:
canreinvite=no
context=from-pstn
host=[host]
nat=no
port=5061
type=friend
qualify=yes
dtmfmode=rfc2833Change [host] to the IP address of computer hosting Asterisk / FreePBX and [username] to username to be used by Sipura
- Leave the remaining fields blank.
- Submit Changes.
- Go to Setup > Basic > Outbound Routes
- Click on 0 9_outside (or create a new one)
- Change the settings to as follows:
- All fields should be blank or left as default up to Dial Patterns.
- Dial Patterns -
9|. - Trunk Sequence - Select the Trunk created above.
- Submit changes.
- Apply the changes.
The above setting outbound route requires a 9 to be dialled followed by the number to be dialled. The dial pattern can be changed later.
Create a new inbound route for the landline to Asterisk via SPA3102:
- Go to Setup > Inbound Call Control > Inbound Routes
- Change the following settings:
- Description - A meaningful name for the inbound route
- DID Number - Enter the landline telephone number including the area code.
- Set Destination - Set where the landline call should go to. This can be voicemail or an extension
- Submit changes.
- Apply Settings
It is worth mentioning here that there is a module in FreePBX called Ring Group which would allow a group of extensions to be named as a destination. This means anyone in the group will have their phone ring when someone rings the landline.
As a recommended step check if a password has been set on the admin web page. Clear out the browser's cookies and cache. Go to the Freepbx page and click on the FreePBX Administration link it should prompt for a password. If not edit the default admin account or add a new account under Setup > Basic > Administration
Notice there is a warning under "General Settings". This means the authentication has not been turned on. Submit the changes and apply them once completed. Go to the Freepbx box and edit the file /etc/amportal.conf Look for the line AUTHTYPE=none and change it from none to database.
Setting Up SPA3102
Out of the box the ATA is configured to act as a router and has the web interface disabled on the WAN port. I will be putting SPA3102 into an existing network so I need to enable the WAN port and turn off the DHCP. The WAN port needs to be enabled so that it can connect to the local network instead of the box expecting a modem and turning off DHCP will stop two devices assigning an IP to the computers on the network.
Plug a telephone into phone socket of the SPA3102 and the power in the power socket. Pick up the phone and dial ***** (5 asterisks) and then 7932 and then 1. Hang up or press #.
Now plug the network cable into the Internet port of the SPA3102 NOT THE ETHERNET PORT. Point your browser to the IP address of the SPA3102. To find out what the IP is you should be able to check on your router or dial ***** (5 asterisks) > 110 on your phone.
Just like a router, a webpage with settings and status of the device should appear. Use the screenshots below and set all the settings below:
The settings are for UK and I have change the tones in the Voice > Regional settings. Others such as the daylight savings are aligned to the UK time zone.
The following needs to be configured according to the environment.
Voice > Line 1 > Proxy and Registration
- Proxy - IP address of the Linux box which will host the Asterisk and FreePBX software.
Voice > Line 1 > Subscriber Information
- User ID - Extension set in FreePBX
- Password - Leave blank initially for easier debugging but it should match the secret settings in the extensions
Voice > PSTN Line > Proxy and Registration
- Proxy - IP address of the Linux box which will host the Asterisk and FreePBX software.
Voice > PSTN Line > Dial Plans
- Dial Plan 2 - S0(<:xxxxxxxxxx>) where x is the phone number of your land land including the area code e.g 01323123456
Asterisk
Trixbox
FreePBX
Installing Asterisk and FreePBX on a vmware instance of Ubuntu 10.04 (Lucid) alpha3



















Blog (RSS)