Forum archive
TKLPatch for Asterisk
Hi all! If you'd like to bring the power of VoIP systems to your SOHO, here's all you need! This TKLPatch will convert Turnkey Core 10.04 beta to a powerfull Asterisk system with FreePBX installed. I'm giving my first steps on this world of telephony over ip, so as allways, this patch surely needs a lot of test. FreePBX is like a child, it starts nicely and then begin to complain about a lots of things, but I was able to stabilize the installation so that it's happy and without complains! If there's someone in the community with is more experienced with asterisk, please be kind to install and test this one.
Features:
Asterisk 1.6 installed from ubuntu's repos.
FreePBX 2.8
Upgraded default freePBX installed modules to last versions.
http and https access configured.
Secured admin interface using database authentication (user: admin, pass: admin)
Changed default passwords for everything on first boot.
Script that changes ip in amportal if ip changes.
What it does:
1. Set Hostname to asterisk
HOSTNAME=asterisk
echo "$HOSTNAME" > /etc/hostname
sed -i "s|127.0.1.1 \(.*\)|127.0.1.1 $HOSTNAME|" /etc/hosts
hostname asterisk
2. Add sources of universe repository (for asterisk-addons sources)
echo deb-src http://archive.ubuntu.com/ubuntu lucid universe >> /etc/apt/sources.list.d/sources.list3. Install required packages. I installed makepasswd to create the initial random passwords. Sox and mpg123 are for audio convertion in the recording system.
install apache2 php5 mysql-server php5-mysql php5-cli php-pear php-db makepasswd asterisk sox ssl-cert asterisk-sounds-extra mpg123
4. Install asterisk-addons compiled from source. Binaries in the repository where compiled against a different version of the asterisk binary, causing the installation to fail! D'oh!
cd /usr/src/
apt-get -y build-dep asterisk-addons
apt-get -b source asterisk-addons
dpkg -i *.deb
5. Change apache user and group to asterisk to prevent ownership and permissions conflicts between asterisk and freepbx. FreePBX does a bunch of chmods and chown that causes conflicts with asterisk. To fix this, this is the approach I felt was easy/stable to apply for this patch.
sed -i "s/www-data/asterisk/" /etc/apache2/envvars6. Get freePBX.
wget http://mirror.freepbx.org/freepbx-2.8.0.tar.gz
tar xzf freepbx-2.8.0.tar.gz
rm freepbx-2.8.0.tar.gz
cd freepbx-2.8.0/7. Create mysql database for freepbx and asteriskcdr
mysqladmin -u root create asterisk
mysqladmin -u root create asteriskcdrdb
mysql -u root asterisk < SQL/newinstall.sql
mysql -u root asteriskcdrdb < SQL/cdr_mysql_table.sql
mysql -u root <<-END_PRIVS
GRANT ALL PRIVILEGES ON asterisk.* TO asteriskuser@localhost IDENTIFIED BY "amp109";
GRANT ALL PRIVILEGES ON asteriskcdrdb.* TO asteriskuser@localhost IDENTIFIED BY "amp109";
flush privileges;
END_PRIVS8. Increase maximum allowed size for uploaded files in php. This is to be able to upload bigger music files for the Music On Hold feature.
sed -i 's/\(^upload_max_filesize = \).*/\120M/' /etc/php5/apache2/php.ini9. Backup asterisk modules settings as freePBX mess them up. If you don't backup this settings, when freePBX overrides them, your asterisk won't start anymore. They are restored after freePBX installation.
cp /etc/asterisk/modules.conf /etc/asterisk/modules.conf.bak10. Installation of freePBX fails with the error "PHP Fatal error: Cannot redeclare __parse_DialRulesFile()" in the step "Upgrading to 2.8.0alpha2..". Solution would be edit the source files OR run installation again to continue. I took the second approach and it works flawlessly. More info here. amportal.conf is being overlayed.
# Initial run of installation
./install_amp
# Second run to bypass the Cannot redeclare __parse_DialRulesFile() error
if [ $? = 255 ]; then
echo "Second run..."
./install_amp
fi
11. Restore asterisk modules settings. I want Asterisk to startup!
cp /etc/asterisk/modules.conf.bak /etc/asterisk/modules.conf12. Final symlinks and permissions needed. The sip_notify link prevents freePBX of complain that it can't create that link because the file is already there. I kept the original as a backup measure. The mohmp3 -> moh is beacause the music on hold module expects to save the files in mohmp3 but the directory by deafult is moh. The agi-bin directory prevents freePBX to complain it can't copy files there. There's another agi-bin in the system where modern modules install things but there's still the need to keep this folder. More info: google. (Sorry I lost the url) Everything else is permissions related.
mv /etc/asterisk/sip_notify.conf /etc/asterisk/sip_notify.conf.bak
ln -s /var/www/admin/modules/core/etc/sip_notify.conf /etc/asterisk/
ln -s /var/lib/asterisk/moh /var/lib/asterisk/mohmp3
mkdir -p /var/lib/asterisk/agi-bin
chown -R asterisk:asterisk /var/www
chown -R asterisk:asterisk /var/lib/asterisk
chown -R asterisk:asterisk /etc/asterisk
chown -R asterisk:asterisk /usr/share/asterisk
chown asterisk:asterisk /etc/amportal.conf13. Upgrade modules: The first thing that freePBX tells you is to upgrade your modules, so I just wanted to avoid this step to final users at least when you just install your appliance.
/var/lib/asterisk/bin/module_admin upgradeall14. Set amportal to start on system boot. Clear enough. This needs to run when the system starts.
sed -i -e "s/^\(exit 0\)$/\/usr\/local\/sbin\/amportal start\n\1\n/" /etc/rc.local15. Set amportal to control asterisk service. If you don't, the amportal script won't be able to stop and start asterisk and you won't be able to do it from the gui niether. So I remove it from startup and let amportal manage that service. The change in background is necesary for debian systems.
update-rc.d -f asterisk remove
sed -i "s/BACKGROUND=0/BACKGROUND=1/" /usr/sbin/safe_asterisk16. Final touches: configure apache's sites, ssl, etc.
a2dissite default
a2ensite freepbx
a2ensite freepbx-ssl
a2enmod ssl
service apache2 stop
service mysql stop17. Clean apt cache and sources
cleanup_apt
cd /
rm -Rf /usr/src/
mkdir -p /usr/srcKnown Issues:
There are several errors in the log of apache, and researching a bit, freePBX developers are aware of them and have been pushing them back to future releases. Aparently they are harmless, I believe that as my test work ok creating extensions and making calls.
Also, there are some issues regarding Voicemail. It seems they are aware of those too. FreePBX has it flaws here and there. If you find something that is not working as expected, please post here a message and I'll research what's happening. Or better: propose a solution (and don't forget to add the sources of the info!) ;)
For the benefit of others who may not be familiar with Asterisk - here's my summary: it's open source phone switch designed to route voice (and video). In VoIP mode you connect your VoIP phones to the switch through an IP network. You can also use a soft phone program from any PC or smartphone. The switch then routes the calls your phone makes just like a conventional phone switch would.
For users with legacy hardware Asterisk also supports interfacing with analog phone systems, though this requires some extra hardware (and configuration!).
Just like with any other IP application you could use Asterisk to setup a 100% private phone system that just routes phone calls within your organization's Intranet. In this case no access to the outside world would be required. But most users will probably want to interface with the "public" phone system. You can do that by interface with a SIP gateway that provides these services for a cost.
It looks like one of the easiest phone gateway solutions to set up is SIPstation which, if I'm not mistaken, is bundled with FreePBX, a web configuration front-end to Asterisk. Asterisk is a back-end component (e.g,. like Apache, but for phone system stuff).
Unfortunately I'm a bit out of my depth here so an actual review is hard to do right now. I imagine that and not lack of interest is the reason you didn't get more feedback from the community. Once we convert this to a TurnKey appliance we'll dive deeper and may have more feedback. Stay tuned!