Installing AMP on the SME Server

Caveats: Setting up asterisk and AMP on a SME server should only be done, in my opinion, on a SME server running as a private server (Server-only mode). The main reason for this is that the setup below modifies the user 'www' so that user has a real shell. Normally www has /bin/false as a shell but in order to have asterisk and amp play nice with apache you need to give www a shell. This is an obvious security issue and having a SME server connected to the internet with the user www modified in this way is a real security risk.

This is a modified version of the AMP install guide

You should download and read it too. I have left out some steps from that document that were not needed for an install on a SME server.

STEP 1: On your SME 6.x server, find, download and install the following rpms: (in this order)

These files are needed for compiling asterisk.

wget http://download.fedoralegacy.org/redhat/7.3/updates/i386/cpp-2.96-113.i386.rpm
wget http://download.fedoralegacy.org/redhat/7.3/updates/i386/glibc-devel-2.2.5-44.i386.rpm
wget http://download.fedoralegacy.org/redhat/7.3/updates/i386/glibc-kernheaders-2.4-7.16.i386.rpm
wget http://download.fedoralegacy.org/redhat/7.3/updates/i386/gcc-2.96-113.i386.rpm
wget http://download.fedoralegacy.org/redhat/7.3/os/i386/audiofile-0.2.3-1.i386.rpm
wget http://download.fedoralegacy.org/redhat/7.3/os/i386/pkgconfig-0.12.0-1.i386.rpm
wget http://download.fedoralegacy.org/redhat/7.3/os/i386/audiofile-devel-0.2.3-1.i386.rpm
wget http://download.fedoralegacy.org/redhat/7.3/os/i386/bison-1.35-1.i386.rpm
wget ftp://rpmfind.net/linux/sourceforge/l/li/linux-ntfs/kernel-source-2.4.20-18.7.i386.rpm
wget http://download.fedoralegacy.org/redhat/7.3/os/i386/libtiff-3.5.7-2.i386.rpm
wget http://download.fedoralegacy.org/redhat/7.3/os/i386/libtiff-devel-3.5.7-2.i386.rpm
wget http://download.fedoralegacy.org/redhat/7.3/os/i386/ncurses-devel-5.2-26.i386.rpm
wget http://download.fedoralegacy.org/redhat/7.3/updates/i386/openssl-devel-0.9.6b-35.7.i386.rpm
wget http://download.fedoralegacy.org/redhat/7.3/updates/i386/zlib-devel-1.1.4-8.7x.i386.rpm
wget http://apt.sw.be/redhat/el3/en/i386/RPMS.dag/lame-3.96.1-1.0.rh7.dag.i386.rpm

STEP 2: Download and install Ghostscript ( for fax to email...) rpms (install order is important)

wget http://download.fedoralegacy.org/redhat/7.3/os/i386/ghostscript-6.52-8.i386.rpm
wget http://download.fedoralegacy.org/redhat/7.3/os/i386/ghostscript-fonts-5.50-3.noarch.rpm
wget http://download.fedoralegacy.org/redhat/7.3/os/i386/Omni-0.5.1-3.i386.rpm
wget http://download.fedoralegacy.org/redhat/7.3/os/i386/urw-fonts-2.0-17.noarch.rpm
wget http://download.fedoralegacy.org/redhat/7.3/os/i386/XFree86-libs-4.2.0-8.i386.rpm
wget http://download.fedoralegacy.org/redhat/7.3/os/i386/VFlib2-2.25.6-4.i386.rpm
wget http://download.fedoralegacy.org/redhat/7.3/os/i386/chkfontpath-1.9.5-2.i386.rpm
wget http://download.fedoralegacy.org/redhat/7.3/os/i386/ttfonts-1.0-9.noarch.rpm
wget http://download.fedoralegacy.org/redhat/7.3/os/i386/XFree86-xfs-4.2.0-8.i386.rpm
wget http://download.fedoralegacy.org/redhat/7.3/os/i386/XFree86-font-utils-4.2.0-8.i386.rpm

(Remember order is important)

rpm -ivh XFree86-libs-4.2.0-8.i386.rpm
rpm -ivh Omni-0.5.1-3.i386.rpm
rpm -ivh XFree86-font-utils-4.2.0-8.i386.rpm
rpm -ivh XFree86-xfs-4.2.0-8.i386.rpm
rpm -ivh chkfontpath-1.9.5-2.i386.rpm
rpm -ivh ttfonts-1.0-9.noarch.rpm
rpm -ivh VFlib2-2.25.6-4.i386.rpm
rpm -ivh urw-fonts-2.0-17.noarch.rpm
rpm -ivh --nodeps ghostscript-fonts-5.50-3.noarch.rpm
rpm -ivh ghostscript-6.52-8.i386.rpm

STEP 3: Go to cpan.org, find, download and install these Perl modules (install order is important)

Do the usual perl Makefile.PL; make install process

Net-Telnet-3.03.tar.gz
IPC-Signal-1.00.tar.gz
Proc-WaitStat-1.00.tar.gz
mime-construct-1.8.tar.gz

STEP 4: Download and install asterisk-perl

wget http://asterisk.gnuinter.net/files/asterisk-perl-0.08.tar.gz
tar zxf asterisk-perl-0.08.tar.gz
cd asterisk-perl-0.08; perl Makefile.PL; make install

STEP 5: Download and install the mpg123 (Music on Hold)

wget http://www.mpg123.de/mpg123/mpg123-0.59r.tar.gz
tar zxf mpg123-0.59r.tar.gz; cd mpg123-0.59r; make linux; make install

STEP 6: Get AMP

cd /usr/src
wget http://osdn.dl.sourceforge.net/sourceforge/amportal/AMP1.10.006.tar.gz
tar zxf AMP-1.10.006.tar.gz

STEP 7: Get Asterisk from the CVS repository

Issue these commands as root on your SME server.

export CVSROOT=:pserver:anoncvs@cvs.digium.com:/usr/cvsroot
cvs login
The password is anoncvs
cvs checkout -r v1-0 zaptel asterisk asterisk-addons
cd zaptel; make && make install

STEP 8: Download Opencall DSP software

Issue these commands as root on your SME server...

wget ftp://ftp.opencall.org/pub/spandsp/spandsp0.0.2pre4/spandsp-0.0.2pre4.tar.gz
tar zxf spandsp-0.0.2pre4.tar.gz; cd spandsp-0.0.2

Before compiling this code note that there is a problem with it for one of two reasons. The first may be the fact that SME server is using gcc 2.96. The other reason I got from the opencall.org website where the author said something "the T.31 is the class 1 FAX modem spec and that code is not complete". So, in src/Makefile.am remove references to t31.c and build the library.

Now you should be able to compile the opencall spandsp code issuing the following as root...

./configure && make && make install

STEP 9: This patches Asterisk to use some of the dsp software from opencall.org

As root run these commands...

cd /usr/src/asterisk/apps
wget ftp://ftp.opencall.org/pub/spandsp/spandsp0.0.2pre4/app_rxfax.c
wget ftp://ftp.opencall.org/pub/spandsp/spandsp0.0.2pre4/app_txfax.c
wget ftp://ftp.opencall.org/pub/spandsp/spandsp0.0.2pre4/apps_makefile.patch
patch < apps_makefile.patch

STEP 10: Create a group and non­root user for building asterisk.

Run these commands as root.

groupadd asterisk
useradd -c "asterisk PBX" -d /var/lib/asterisk -u 5060 -g asterisk asterisk

STEP 11: Compiling asterisk

First edit /usr/src/asterisk/Makefile such that ( line 122):

ASTVARRUNDIR=$(INSTALL_PREFIX)/var/run/asterisk

Then as root run...

make clean && make && make install

STEP 12: Setting up MySQL for CDR (Call Detail Reports)

As root run these commands...

mysqladmin create asteriskcdrdb
mysql

In the mysql application execute the following...

GRANT ALL PRIVILEGES ON asteriskcdrdb.* TO asteriskuser@localhost IDENTIFIED BY 'amp109';
\q
mysql asteriskcdrdb < / usr/src/AMP/SQL/cdr_mysql_table.sql

STEP 13: Build/Compile cdr_mysql module for Asterisk

As root run the following...

cd /usr/src/asterisk-addons/
make clean && make && make install

STEP 14: Setup MySQL for AMP web interface

As root run the following...

mysqladmin create asterisk
mysql asterisk < / usr/src/AMP/SQL/newinstall.sql
mysql asterisk

In the mysql application execute this...

GRANT ALL PRIVILEGES ON asterisk.* TO asteriskuser@localhost IDENTIFIED BY 'amp109';

Quit mysql with...

\q

STEP 15: Create a custom template for the httpd.conf file

If it doesn't already exist, create the dir /etc/e-smith/templates-custom/etc/httpd/conf/httpd.conf

mkdir /etc/e-smith/templates-custom/etc/httpd/conf/httpd.conf
vi /etc/e-smith/templates-custom/etc/httpd/conf/httpd.conf/99AMPAccess

Add the following to the 99AMPAccess file...

# AMP
Alias /amp /var/www/html/amp
<Directory /var/www/html/amp>
order deny,allow
deny from all
allow from all
AddType application/x-httpd-php .php .php3
php_flag  magic_quotes_gpc  on
php_flag  track_vars        on
</Directory>

# AMP cgi
Alias /amp/cgi-bin /var/www/html/amp/cgi-bin
<Directory /var/www/html/amp/cgi-bin>
Options ExecCGI
AllowOverride None
order deny,allow
deny from all
allow from all
</Directory>

Alias /amp/admin /var/www/html/amp/admin
<Directory /var/www/html/amp/admin>
order deny,allow
deny from all
allow from all
AddType application/x-httpd-php .php .php3
php_flag  magic_quotes_gpc  on
php_flag  track_vars        on
</Directory>

Alias /amp/panel /var/www/html/amp/panel
<Directory /var/www/html/amp/panel>
order deny,allow
deny from all
allow from all
AddType application/x-httpd-php .php .php3
php_flag  magic_quotes_gpc  on
php_flag  track_vars        on
</Directory>
# AMP end

Next run the following two commands as root to integrate your customization into the apache config files...

/sbin/e-smith/expand-template /etc/httpd/conf/httpd.conf
/etc/e-smith/events/actions/restart-httpd-graceful

STEP 16: Create custom template for /etc/php.ini file

mkdir /etc/e-smith/templates-custom/etc/php.ini
cp /etc/e-smith/templates/etc/php.ini/50PathsDirectories /etc/e-smith/templates-custom/etc/php.ini/50PathsDirectories
vi /etc/e-smith/templates-custom/etc/php.ini/50PathsDirectories
Change the include_path parameter to this...
include_path = ".:/usr/share/php:/usr/share/pear"

Now execute the following commands as root...

/sbin/e-smith/expand-template /etc/php.ini
/etc/e-smith/events/actions/restart-httpd-graceful

STEP 17: Modify the user www in /etc/passwd

vi /etc/passwd

Change the user www so that it has a bash login shell Change the following line

www:x:100:101:e-smith web server:/home/e-smith:/bin/false

So that is looks like...

www:x:100:101:e-smith web server:/home/e-smith:/bin/bash

STEP 18: Modify and Apply the AMP/Asterisk configuration files

This is were we make a number of changes to make AMP fit nicely into a SME server.

As root run these commands...

cd /usr/src/AMP/amp_conf
find . -name CVS -exec rm -rf {} \;
cd /usr/src/AMP/amp_conf/var/www/html
mkdir amp
mv admin amp.png _asterisk index.html mainstyle.css panel amp

Modify the file retrieve_op_conf_from_mysql.pl

vi /usr/src/AMP/amp_conf/var/www/html/amp/admin/retrieve_op_conf_from_mysql.pl

Changing

$sip_conf = "/var/www/html/panel/op_buttons_additional.cfg";

To

$sip_conf = "/var/www/html/amp/panel/op_buttons_additional.cfg";

Modify the file /usr/src/AMP/amp_conf/var/www/cgi-bin/vmail.cgi

vi /usr/src/AMP/amp_conf/var/www/cgi-bin/vmail.cgi

Change

$astpath = "/_asterisk";

TO

$astpath = "/amp/_asterisk";

Modify the file /usr/src/AMP/amp_conf/var/www/html/amp/panel/op_server.cfg.template changing flash_dir parameter to...

flash_dir=/var/www/html/amp/panel

Modify the file /usr/src/AMP/amp_conf/var/www/html/amp/admin/vm_conf.php Changing the $vmconf variable to...

$vmconf = '/var/www/html/amp/admin/voicemail.conf';

Modify the file /usr/src/AMP/amp_conf/var/www/html/amp/admin/cdr/lib/defines.php.template changing WEBROOT and FSROOT to

define ("WEBROOT", "http://192.168.1.101/amp/admin/cdr/");
define ("FSROOT", "/var/www/html/amp/admin/cdr/");

(Note you would put the correct IP address for your computer (i.e. likely not 192.168.100.101)

cd /usr/src/AMP
vi chown_asterisk.sh

While in vi execute a global search and replace...

:g/asterisk:asterisk/s//www.shared/g

Then quit vi

:wq

Next modify the apply_conf.sh file

vi apply_conf.sh

change the following lines...

su - asterisk -c "/var/www/html/admin/retrieve_op_conf_from_mysql.pl"
su - asterisk -c "/var/www/html/admin/bounce_op.sh"

So that they look like this...

su - asterisk -c "/var/www/html/amp/admin/retrieve_op_conf_from_mysql.pl"
su - asterisk -c "/var/www/html/amp/admin/bounce_op.sh"

Now we can run the apply_conf.sh

./apply_conf.sh

STEP 19: Modify the asterisk and AMP files to suit your machine...

cd /etc/asterisk
mv vm_email.inc.template  vm_email.inc
vi /etc/asterisk/vm_email.inc

Change vm_email.inc to suit your setup... Change the email body, variables: VM_NAME, VM_DUR, VM_MSGNUM, VM_MAILBOX, VM_CALLERID, VM_DATE

cp voicemail.conf.template voicemail.conf
mv zapata.conf.template zapata.conf
cd /var/www/html/amp/admin/cdr/lib/
mv defines.php.template defines.php
cd /var/www/html/amp/panel/
mv op_server.cfg.template op_server.cfg
vi /var/www/html/amp/panel/op_server.cfg
web_hostname=192.168.1.3           ; must be the same hostname or ip address used

Next modify lines 28+ of retrieve_op_conf_from_mysql.pl to reflect the number of zap channels you have. If you have 1 channel, you should remove [Zap/2], [Zap/3] and [Zap/4].

vi /var/www/html/amp/admin/retrieve_op_conf_from_mysql.pl

And now run the chown script again.

cd /usr/src/AMP/
./chown_asterisk.sh

STEP 20: Edit /etc/zaptel.conf to reflect installed Digium telephony card(s).

A significant portion of the default file is commented out and is not included in the output below. Only the parameters/values relevant to a X100P are included below:

# kewlstart for X100P
fxsks=1
#
loadzone = us
defaultzone = us

Only the parameters/values relevant to a 1 FXO TDM400P configuration are included below (assumes port 3 on the card contains the FXO module):

# kewlstart for 1 port TDM400P (fxo uses fxs signalling)
fxsks=3
#
loadzone = us
defaultzone = us

STEP 21: Run ztcfg -v

As root run...

ztcfg -v

STEP 22: Configure zapata module Edit /etc/asterisk/zapata.conf to reflect installed Digium telephony card(s).

Only the parameters/values relevant to a X100P configuration are included below:

[channels]
language=en
;
; X100P plugged into PSTN
;
context=from-pstn
signalling=fxs_ks
faxdetect=incoming
usecallerid=yes
echocancel=yes
echocancelwhenbridged=no
;echotraining=yes
echotraining=800
group=0
channel=1

STEP 23: Automatic starting.

You can add the following to /etc/rc.d/rc.local to have amp/asterisk and your digium cards start at boot.

touch /var/lock/subsys/local
echo ADDING WCFXO
/sbin/modprobe wcfxo
/usr/sbin/amportal start

Miscellaneous Stuff:

Asterisk doesn't seem to create a directoy AMP expects...

mkdir /var/lib/asterisk/sounds/custom
chown asterisk.shared /var/lib/asterisk/sounds/custom/

Conclusion

That's it. You should have a workable Asterisk/AMP system.

Please let me know if this information is inaccurate. Better yet, modify it yourself. It's a Wiki.