FOP2 Installation on Trixbox 2.8

Trixbox 2.8 is a nice program but the FOP that comes with it is heavily outdated and lacking the visual and functional appeal you would expect in a project that is as slick as Trixbox. Never fear however, that can be solved by installing FOP2 from the same author. The only disadvantage of FOP2 over FOP is that it requires a site license. This costs $40 for the entire site, which is a steal considering how much better it functions than the original FOP and how affordable that is compared to other operator panels. If you don’t have more than 15 extensions, queues, conferences and trunks you can use it in trial mode and see all the features as well. You can download a copy of FOP2 and register it at the FOP2 site which is located at http://www.fop2.com/. Without further ado here is the basic installation procedure.

First and foremost before any changes to a system… ensure you have a valid working backup!

Make a temporary directory and download the package and uncompress it.

mkdir -p /usr/local/src/packages/fop2
cd /usr/local/src/packages/fop2
curl http://www.fop2.com/file.php?file=1 > fop2.tgz
tar xfvz fop2-2.11-centos5.i386.tgz

Then change directory to fop2 and run the installation, this requires make to be installed.

cd fop2
make install

This will copy the necessary files to various locations on the system, mostly under /usr/local/fop2 and /var/www/html/fop2.

Next stop the original FOP and copy the extensions override to the appropriate file in asterisk.

amportal stop_fop
cd /usr/local/fop2
cat extensions_override_freepbx.conf >> /etc/asterisk/extensions_override_freepbx.conf

After that step is complete we need to install the mysql database for the visual phone book.

cd /var/www/html/fop2
mysqladmin -u root -p create fop2
mysql -u root -p fop2 < mysql.db
mysql -u root -p -e "grant all privileges on fop2.* to fop2@'localhost' identified by 'xxxxxxxxxxx'"

Next lets edit a few files to set credentials and privileges, the first file is the config.php file in the current directory, it needs to have the database credentials you just setup put in it.

vi config.php

The asterisk manager should have originate rights so edit…

vi /etc/asterisk/manager.conf

and add “,originate” to the end of the read and write lines. We need to make sure we generate callevents so add “callevents=yes” to to the sip_custom.conf file.

vi /etc/asterisk/sip_custom.conf

For the queues_custom.conf file you need to add “eventwhencalled=yes” to the queues as an example:

vi /etc/asterisk/queues_custom.conf
[testqueue]
eventwhencalled=yes

Finally verify that the auto config script for users will run correctly by executing…

/usr/local/fop2/autoconfig-users-freepbx.sh

If you have extensions that start with the number 0 you will likely need to add 10# to force it to use decimal and not octal numbers. Finally have FOP2 perform an internal self test by running…

/usr/local/fop2/fop2_server --test

If all is well at this point we’re ready to move onto the final step to make amportal start FOP2 instead of FOP.

cd /var/lib/asterisk/bin
mv freepbx_engine freepbx_engine.orig

You can either download the updated script from http://www.cadvision.com/blanchas/freepbx_engine or alternately paste it in from here

#!/usr/bin/env bash

ROOT_UID=0       # root uid is 0
E_NOTROOT=67     # Non-root exit error

echo
# check to see if we are root
if [ "$UID" -ne "$ROOT_UID" ]
then
echo "Sorry, you must be root to run this script."
echo
exit $E_NOTROOT
fi

# make sure config file exists
if [ ! -e "/etc/amportal.conf" ]       # Check if file exists.
then
echo;
echo "/etc/amportal.conf does not exist!";
echo "Have you installed the AMP configuration?";
exit;
fi
# Set some defaults which can be re-defined in amportal.conf
AMPDEVUSER=asterisk
AMPDEVGROUP=asterisk
AMPASTERISKUSER=asterisk
AMPASTERISKGROUP=asterisk
AMPASTERISKWEBUSER=$AMPASTERISKUSER
AMPASTERISKWEBGROUP=$AMPASTERISKGROUP
AMPVMUMASK=077

. /etc/amportal.conf

if [ $ASTRUNDIR = /var/run ]
then
echo "**** ERROR IN CONFIGURATION ****"
echo "astrundir in /etc/asterisk/asterisk.conf is set to '/var/run' - THIS IS WRONG."
echo "Please change it to something sensible (eg, '/var/run/asterisk') and re-run"
echo "install_amp"
exit;
fi

if [ ! -d "$ASTRUNDIR" ]
then
echo "**** WARNING: ERROR IN CONFIGURATION ****"
echo "astrundir in /etc/asterisk/asterisk.conf is set to $ASTRUNDIR but the directory"
echo "does not exists. Attempting to create it with: 'mkdir -p $ASTRUNDIR'"
echo
mkdir -p $ASTRUNDIR
RET=$?
if [ $RET != 0 ]
then
echo "**** ERROR: COULD NOT CREATE $ASTRUNDIR ****"
echo "Attempt to execute 'mkdir -p $ASTRUNDIR' failed with an exit code of $RET"
echo "You must create this directory and the try again."
exit
fi
fi

chown_asterisk() {
echo SETTING FILE PERMISSIONS

chown -R $AMPASTERISKUSER:$AMPASTERISKGROUP $ASTRUNDIR
chown -R $AMPASTERISKUSER:$AMPASTERISKGROUP /etc/asterisk
chmod -R g+w /etc/asterisk
chown -R $AMPASTERISKUSER:$AMPASTERISKGROUP $ASTVARLIBDIR
chmod -R g+w $ASTVARLIBDIR
chown -R $AMPASTERISKUSER:$AMPASTERISKGROUP $ASTLOGDIR
chmod -R g+w $ASTLOGDIR
chown -R $AMPASTERISKUSER:$AMPASTERISKGROUP $ASTSPOOLDIR
chmod -R g+w $ASTSPOOLDIR
chown -R $AMPASTERISKWEBUSER:$AMPASTERISKWEBGROUP $AMPWEBROOT/admin
chmod -R g+w $AMPWEBROOT/admin
chown -R $AMPASTERISKWEBUSER:$AMPASTERISKWEBGROUP $FOPWEBROOT
chmod -R g+w $FOPWEBROOT
chown -R $AMPASTERISKUSER:$AMPASTERISKGROUP $AMPWEBROOT/recordings
chmod -R g+w $AMPWEBROOT/recordings
chown -R $AMPASTERISKUSER:$AMPASTERISKGROUP $AMPWEBROOT/_asterisk
chmod u+x,g+x $ASTVARLIBDIR/bin/*
chown -R $AMPASTERISKUSER:$AMPASTERISKGROUP $ASTVARLIBDIR/bin/*
chown -R $AMPASTERISKUSER:$AMPASTERISKGROUP $AMPBIN/*

if [ "$ASTAGIDIR" != "" ]; then
chmod u+x $ASTAGIDIR/*
else
chmod u+x $ASTVARLIBDIR/agi-bin/*
fi

chmod u+x,g+x $AMPBIN/bounce_op.sh
chmod u+x,g+x $FOPWEBROOT/*.pl
chmod u+x $FOPWEBROOT/safe_opserver
chown $AMPASTERISKUSER /dev/tty9

# Ensure that various hardware devices are owned correctly.
[ -e /dev/zap ] && chown -R $AMPDEVUSER:$AMPDEVGROUP /dev/zap
[ -e /dev/dahdi ] && chown -R $AMPDEVUSER:$AMPDEVGROUP /dev/dahdi
[ -e /dev/capi20 ] && chown -R $AMPDEVUSER:$AMPDEVGROUP /dev/capi20
[ -e /dev/misdn ] && chown -R $AMPDEVUSER:$AMPDEVGROUP /dev/misdn
[ -e /dev/mISDN ] && chown -R $AMPDEVUSER:$AMPDEVGROUP /dev/mISDN
[ -e /dev/dsp ] && chown -R $AMPDEVUSER:$AMPDEVGROUP /dev/dsp

echo Permissions OK
}

check_asterisk() {
# check to see if asterisk is running
# Note, this isn't fool-proof.  If safe_asterisk is constantly restarting a dying asterisk, then there is a chance pidof will return non zero.  We call this twice to reduce chances of this happening
pid_length=`pidof asterisk|awk '{print length($0)}'`
if [ "$pid_length" == "0" -a "$pid_length" != "" ]
then
killall -9 safe_asterisk
killall -9 mpg123 > /dev/null
echo
echo "-----------------------------------------------------"
echo "Asterisk could not start!"
echo "Use 'tail $ASTLOGDIR/full' to find out why."
echo "-----------------------------------------------------"
exit 0
fi
}

run_asterisk() {
# check to see if asterisk is running
echo
echo "STARTING ASTERISK"
pid_length=`pidof asterisk|awk '{print length($0)}'`
if [ "$pid_length" != "0" -a "$pid_length" != "" ]
then
echo "Asterisk is already running"
else
# su - asterisk -c "export PATH=$PATH:/usr/sbin && export LD_LIBRARY_PATH=/usr/local/lib && /usr/sbin/safe_asterisk"
export LD_LIBRARY_PATH=/usr/local/lib
umask $AMPVMUMASK
/usr/sbin/safe_asterisk -U asterisk -G $AMPASTERISKGROUP
sleep 5
check_asterisk
sleep 1
check_asterisk
echo "Asterisk Started"
fi
}

stop_asterisk() {
echo
echo "STOPPING ASTERISK"
pid_length=`pidof asterisk|awk '{print length($0)}'`
if [ "$pid_length" != "0" -a "$pid_length" != "" ]
then
/usr/sbin/asterisk -rx "core stop gracefully" | grep -v "No such command"
/usr/sbin/asterisk -rx "stop gracefully" | grep -v -E "No such command|deprecated"
echo "Asterisk Stopped"
fi
}

check_fop2() {
#check to see if FOP2 is running
pid_length=`pidof -x fop2|awk '{print length($0)}'`
if [ "$pid_length" == "0" -a "$pid_length" != "" ]
then
ps -ef | grep fop2 | grep -v grep | awk '{print $2}' | xargs kill -9
echo
echo "-----------------------------------------------------"
echo "The FOP2's server could not start!"
echo "Please correct this problem"
echo "-----------------------------------------------------"
exit 0
fi
}

run_fop2() {
# check to see if FOP2 is running
echo
echo "STARTING FOP2 SERVER"
pid_length=`pidof -x fop2|awk '{print length($0)}'`
if [ "$pid_length" != "0" -a "$pid_length" != "" ]
then
echo "FOP2 server is already running"
else
/etc/init.d/fop2 start
# Don't really like to run fop2 with root privileges. should be user: AMPASTERISKUSER = asterisk
fi
}

stop_fop2() {
echo
echo "STOPPING FOP SERVER"
/etc/init.d/fop2 stop
}

kill_amp() {
echo
echo "KILLING AMP PROCESSES"
killall -9 safe_asterisk
killall -9 asterisk
killall -9 mpg123
ps -ef | grep safe_opserver | grep -v grep | awk '{print $2}' | xargs kill -9
killall -9 op_server.pl
}

case "$1" in
start)
chown_asterisk
run_asterisk
if [ -z "$FOPRUN" -o "$FOPRUN" == "true" -o "$FOPRUN" == "TRUE" -o "$FOPRUN" == "True" -o "$FOPRUN" == "yes" -o "$FOPRUN" == "YES" -o "$FOPRUN" == "Yes" ]
then
if [ -z "$FOPDISABLE" -o "$FOPDISABLE" == "false" -o "$FOPDISABLE" == "FALSE" -o "$FOPDISABLE" == "False" -o "$FOPDISABLE" == "no" -o "$FOPDISABLE" == "NO" -o "$FOPDISABLE" == "No" ]
then
run_fop2
fi
fi
;;
stop)
stop_asterisk
stop_fop2
;;
restart)
stop_asterisk
stop_fop2
sleep 1
chown_asterisk
run_asterisk
if [ -z "$FOPRUN" -o "$FOPRUN" == "true" -o "$FOPRUN" == "TRUE" -o "$FOPRUN" == "True" -o "$FOPRUN" == "yes" -o "$FOPRUN" == "YES" -o "$FOPRUN" == "Yes" ]
then
if [ -z "$FOPDISABLE" -o "$FOPDISABLE" == "false" -o "$FOPDISABLE" == "FALSE" -o "$FOPDISABLE" == "False" -o "$FOPDISABLE" == "no" -o "$FOPDISABLE" == "NO" -o "$FOPDISABLE" == "No" ]
then
run_fop2
fi
fi
;;
stop_fop2)
stop_fop2
;;
start_fop2)
run_asterisk
run_fop2
;;
restart_fop2)
stop_fop2
run_asterisk
run_fop2
;;
chown)
chown_asterisk
;;
kill)
kill_amp
;;
*)
if [ -z "$FOPRUN" -o "$FOPRUN" == "true" -o "$FOPRUN" == "TRUE" -o "$FOPRUN" == "True" -o "$FOPRUN" == "yes" -o "$FOPRUN" == "YES" -o "$FOPRUN" == "Yes" ]
then
if [ -z "$FOPDISABLE" -o "$FOPDISABLE" == "false" -o "$FOPDISABLE" == "FALSE" -o "$FOPDISABLE" == "False" -o "$FOPDISABLE" == "no" -o "$FOPDISABLE" == "NO" -o "$FOPDISABLE" == "No" ]
then
FOPUSAGE="start_fop2|stop_fop2|restart_fop2|"
fi
fi

echo "-------------FreePBX Control Script-----------------------------------------------"
echo
echo "Usage:       amportal start|stop|restart|${FOPUSAGE}kill|chown"
echo
echo "start:       Starts Asterisk and Flash Operator Panel server if enabled"
echo "stop:        Gracefully stops Asterisk and the FOP server"
echo "restart:     Stop and Starts"
if [ -z "$FOPRUN" -o "$FOPRUN" == "true" -o "$FOPRUN" == "TRUE" -o "$FOPRUN" == "True" -o "$FOPRUN" == "yes" -o "$FOPRUN" == "YES" -o "$FOPRUN" == "Yes" ]
then
if [ -z "$FOPDISABLE" -o "$FOPDISABLE" == "false" -o "$FOPDISABLE" == "FALSE" -o "$FOPDISABLE" == "False" -o "$FOPDISABLE" == "no" -o "$FOPDISABLE" == "NO" -o "$FOPDISABLE" == "No" ]
then

echo "start_fop2:   Starts FOP server and Asterisk if not running"
echo "stop_fop2:    Stops FOP serverg"
echo "restart_fop2: Stops FOP server and Starts it and Asterisk if not running"
fi
fi
echo "kill:        Kills Asterisk and the FOP server"
echo "chown:       Sets appropriate permissions on files"
echo
exit 1
;;
esac

Last but not least, lets get permissions set and make changes to the interface to show FOP2

chmod 770 freepbx_engine
chown asterisk:asterisk freepbx_engine
cd /var/www/html/admin/views
cp panel.php panel.php.orig
vi panel.php
cd ../../user/templates/modules/04_fop
cp fop.tpl fop.tpl.orig
vi fop.tpl

In the panel.php change the src to “../fop2/index.html” and in the fop.tpl change the src= to “../fop2/” Now restart asterisk

amportal stop
amportal start

Now you can test your installation by visiting http://host.domain.tld/fop2 and login with your extension.

I would also suggest you install the admin module which is available on the fop2 site for changing passwords and managing what you want on and off the panel.

As always if you need further assistance with this or any other open source application or issue, the experts at Pantek Inc. are available 24/7 at info@pantek.com, 216-344-1614, and 877-LINUX-FIX.