ASTPP VoIP Billing v5.0 Debian v9 Freeswitch v1.10 Install Guide

ASTPP

 

This guide covers the installation of the ASTPP VoIP billing and Freeswitch applications.  ASTPP is installed manually from source.  Freeswitch is installed from deb packages.

Tested using the following software:

  • Debian v9 (Stretch) x64 minimal install
  • ASTPP v5.0
  • Freeswitch v1.10
  • Nginx v1.10
  • PHP v7.3
  • MySQL v8

     

Call Flow

Outbound

outbound call flow

 

 

 

Inbound

inbound call flow

Prerequisites

Verify locale is set to en US.UTF-8.

locale

If it is not then set it now.  You may also set your own UTF-8 locale if not in the US.

# Select en_US.UTF-8 UTF-8
apt -y install locales && dpkg-reconfigure locales

Log out/in or close/open shell for changes to take effect. 

Install prerequisite packages

apt update && apt -y upgrade && apt -y remove apache2
apt -y install software-properties-common
add-apt-repository 'deb http://security.debian.org/debian-security/ stretch/updates main contrib'
apt update && apt -y install git nano dbus sudo nginx wget curl sqlite3 haveged ghostscript lsb-release libtiff5-dev libtiff-tools at dirmngr postfix gawk dnsutils openssl ntp unixodbc unixodbc-bin net-tools whois sensible-mda mlocate vim gettext fail2ban ntpdate ntp lua5.1 bc libxml2 libxml2-dev openssl libcurl4-openssl-dev gettext gcc g++ gnupg2

Postfix

If a postfix configuration wizard pops up you can select the default Internet Site and also the default mail name.  These settings can be manually changed later in /etc/postfix/main.cf.

PHP

# install this section one line at a time.

apt -y install apt-transport-https ca-certificates
wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list
apt update && apt -y install php7.3 php7.3-fpm php7.3-gd php7.3-opcache php7.3-cli php7.3-common php7.3-curl php7.3-sqlite3 php7.3-odbc php7.3-mysql php7.3-xml php7.3-json php7.3-mbstring php7.3-readline php7.3-imap

MySQL

Configure

# Confirm MySQL Server & Cluster (mysql-8.0) is currently selected
cd /opt && wget https://repo.mysql.com/mysql-apt-config_0.8.17-1_all.deb
dpkg -i mysql-apt-config_0.8.17-1_all.deb

Install MySQL

# You can leave root password blank
# IMPORTANT: Select "Use Legacy Authentication" when asked

apt update && apt -y install mysql-server

Install ODBC

wget https://dev.mysql.com/get/Downloads/Connector-ODBC/8.0/mysql-connector-odbc_8.0.22-1debian9_amd64.deb
dpkg -i mysql-connector-odbc_8.0.22-1debian9_amd64.deb

Disable Selinux

Check status

sestatus

If the command is found and is not disabled, set SELINUX=disabled in /etc/selinux/config.  Requires reboot for changes to take effect.

sed -i 's/\(^SELINUX=\).*/\SELINUX=disabled/' /etc/selinux/config

Disable Firewall

It is sometimes helpful to disable the firewall during installation.

systemctl disable firewalld
systemctl disable iptables
systemctl stop firewalld
systemctl stop iptables

Timezone

## FIND YOUR TIMEZONE
tzselect

## SET TIMEZONE EXAMPLE
timedatectl set-timezone America/Vancouver

## CHECK TIMEZONE
​timedatectl status
systemctl restart rsyslog

Install

Freeswitch

Get your signalwire token according to these instructions:
https://freeswitch.org/confluence/display/FREESWITCH/HOWTO+Create+a+SignalWire+Personal+Access+Token

Once you have your signalwire token install freeswitch packages

TOKEN=YOURSIGNALWIRETOKEN
 
apt-get update && apt-get install -y gnupg2 wget lsb-release
 
wget --http-user=signalwire --http-password=$TOKEN -O /usr/share/keyrings/signalwire-freeswitch-repo.gpg https://freeswitch.signalwire.com/repo/deb/debian-release/signalwire-freeswitch-repo.gpg
 
echo "machine freeswitch.signalwire.com login signalwire password $TOKEN" > /etc/apt/auth.conf

echo "deb [signed-by=/usr/share/keyrings/signalwire-freeswitch-repo.gpg] https://freeswitch.signalwire.com/repo/deb/debian-release/ `lsb_release -sc` main" > /etc/apt/sources.list.d/freeswitch.list

echo "deb-src [signed-by=/usr/share/keyrings/signalwire-freeswitch-repo.gpg] https://freeswitch.signalwire.com/repo/deb/debian-release/ `lsb_release -sc` main" >> /etc/apt/sources.list.d/freeswitch.list
 
apt-get update && apt-get install -y freeswitch-meta-all

ASTPP

# Set MySQL user ${USER_PASSWORD} variable.  This is used muliple times in this section.
USER_PASSWORD=somepassword

# If you have set a MySQL root password assign it here.
# If you left it blank just hit ENTER when asked.
MYSQL_PASSWORD=existingmysqlpassword
cd /opt && git clone -b v5.0 https://github.com/powerpbx/ASTPP.git

Configure MySQL

mysql -p${MYSQL_PASSWORD} -e "CREATE DATABASE astpp;"
mysql -p${MYSQL_PASSWORD} -e "CREATE USER 'astppuser'@'localhost' IDENTIFIED BY '${USER_PASSWORD}';"
mysql -uroot -p${MYSQL_PASSWORD} -e "ALTER USER 'astppuser'@'localhost' \
IDENTIFIED WITH mysql_native_password BY '${USER_PASSWORD}';"
mysql -p${MYSQL_PASSWORD} -e "GRANT ALL PRIVILEGES ON astpp.* TO 'astppuser'@'localhost' WITH GRANT OPTION;"
mysql -p${MYSQL_PASSWORD} -e "FLUSH PRIVILEGES;"
cd /opt && cp ASTPP/misc/odbc/deb_odbc.ini /etc/odbc.ini
sed -i "s#\(^PASSWORD\).*#PASSWORD = ${USER_PASSWORD}#g" /etc/odbc.ini

sed -i '33i wait_timeout=600' /etc/mysql/mysql.conf.d/mysqld.cnf
sed -i '33i interactive_timeout = 600' /etc/mysql/mysql.conf.d/mysqld.cnf
sed -i '33i sql_mode=""' /etc/mysql/mysql.conf.d/mysqld.cnf

systemctl restart mysql

Install ASTPP DB

# This may run for a few minutes and should not be interrupted.
mysql -p${MYSQL_PASSWORD} astpp < ASTPP/database/astpp-5.0.sql

# If you get a datetime error on this step try restart mysql
mysql -p${MYSQL_PASSWORD} astpp < ASTPP/database/astpp-5.0.1.sql

Test odbc driver

odbcinst -s -q

Test odbc connection

isql -v astpp astppuser ${USER_PASSWORD} 
quit

Configure Freeswitch

cd /opt
mv /usr/share/freeswitch/scripts /tmp/.
ln -s /opt/ASTPP/freeswitch/fs/ /var/www/html
ln -s /opt/ASTPP/freeswitch/scripts/ /usr/share/freeswitch
cp -rf ASTPP/freeswitch/sounds/*.wav /usr/share/freeswitch/sounds/en/us/callie/

rm -rf /etc/freeswitch/dialplan/*
touch /etc/freeswitch/dialplan/astpp.xml
rm -rf /etc/freeswitch/directory/*
touch /etc/freeswitch/directory/astpp.xml
rm -rf /etc/freeswitch/sip_profiles/*
touch /etc/freeswitch/sip_profiles/astpp.xml

Configure ASTPP

cd /opt
mkdir -p /usr/local/astpp
mkdir -p /var/log/astpp
mkdir -p /var/lib/astpp
cp ASTPP/config/astpp-config.conf /var/lib/astpp/astpp-config.conf
cp ASTPP/config/astpp.lua /var/lib/astpp/astpp.lua

Configure web server

ln -s /opt/ASTPP/web_interface/astpp/ /var/www/html
cp ASTPP/web_interface/nginx/deb_astpp.conf /etc/nginx/sites-available/astpp.conf
cp ASTPP/web_interface/nginx/deb_fs.conf /etc/nginx/sites-available/fs.conf

ln -s /etc/nginx/sites-available/astpp.conf /etc/nginx/sites-enabled/astpp.conf 
ln -s /etc/nginx/sites-available/fs.conf /etc/nginx/sites-enabled/fs.conf 
rm /etc/nginx/sites-enabled/default

# Just press ENTER to use defaults for all the questions
mkdir -p /etc/nginx/ssl
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/nginx/ssl/nginx.key -out /etc/nginx/ssl/nginx.crt

# Add nginx log files
touch /var/log/nginx/astpp_access.log
touch /var/log/nginx/astpp_error.log
touch /var/log/nginx/fs_access.log
touch /var/log/nginx/fs_error.log

Add ASTPP log files

touch /var/log/astpp/astpp.log
touch /var/log/astpp/astpp_email.log

Configure ASTPP Freeswitch files

# Copy
cp -rf ASTPP/freeswitch/conf/autoload_configs/* /etc/freeswitch/autoload_configs/

# Configure
SWITCH_CONF=/etc/freeswitch/autoload_configs/switch.conf.xml
sed -i "s#max-sessions\" value=\"1000#max-sessions\" value=\"2000#g" ${SWITCH_CONF}
sed -i "s#sessions-per-second\" value=\"30#sessions-per-second\" value=\"50#g" ${SWITCH_CONF}
sed -i "s#max-db-handles\" value=\"50#max-db-handles\" value=\"500#g" ${SWITCH_CONF}
sed -i "s#db-handle-timeout\" value=\"10#db-handle-timeout\" value=\"30#g" ${SWITCH_CONF}

Configure ASTPP DB access

SERVER_IP=$(ifconfig | sed -En 's/127.0.0.*//;s/.*inet (addr:)?(([0-9]*\.){3}[0-9]*).*/\2/p')
sed -i "s#\(^dbname\).*#dbname = astpp#" /var/lib/astpp/astpp-config.conf
sed -i "s#\(^dbuser\).*#dbuser = astppuser#" /var/lib/astpp/astpp-config.conf
sed -i "s#\(^dbpass\).*#dbpass = ${USER_PASSWORD}#" /var/lib/astpp/astpp-config.conf
sed -i "s#\(^base_url\).*#base_url = https://${SERVER_IP}/#" /var/lib/astpp/astpp-config.conf
sed -i "s#\(^DB_USERNAME\).*#DB_USERNAME = \"astppuser\"#" /var/lib/astpp/astpp.lua
sed -i "s#\(^DB_PASSWD\).*#DB_PASSWD = \"${USER_PASSWORD}\"#" /var/lib/astpp/astpp.lua

Enable MySQL module on Freeswitch

nano /etc/freeswitch/autoload_configs/pre_load_modules.conf.xml
<configuration name="pre_load_modules.conf" description="Modules">
  <modules>
    <!-- Databases -->
    <load module="mod_mariadb"/>
  </modules>
</configuration>

CRON

crontab -u www-data -e
# Call all crons
* * * * * cd /opt/ASTPP/web_interface/astpp/cron/ && /usr/bin/php cron.php crons

Systemd

Create unit file.

systemctl stop freeswitch
rm -r /run/freeswitch
nano /etc/systemd/system/freeswitch.service
[Unit]
Description=freeswitch
After=syslog.target network.target local-fs.target mysql.service

[Service]
Type=forking
RuntimeDirectory=freeswitch
PIDFile=/run/freeswitch/freeswitch.pid
Environment="DAEMON_OPTS=-ncwait -nonat"
EnvironmentFile=-/etc/default/freeswitch
ExecStart=/usr/bin/freeswitch $DAEMON_OPTS
TimeoutSec=45s
Restart=always

User=www-data
Group=www-data
LimitCORE=infinity
LimitNOFILE=100000
LimitNPROC=60000
LimitSTACK=250000
LimitRTPRIO=infinity
LimitRTTIME=infinity
IOSchedulingClass=realtime
IOSchedulingPriority=2
CPUSchedulingPriority=89
UMask=0007

; Comment this out if using OpenVZ
CPUSchedulingPolicy=rr

[Install]
WantedBy=multi-user.target

Create environment file.

cat >> /etc/default/freeswitch << EOF
# Uncommented variables will override variables in unit file
# User=""
# Group=""
# DAEMON_OPTS=""

EOF

Set ownership and permissions

Run this any time there are any changes/moves/adds/upgrades or if experiencing problems.

# Ownership www-data
chown -R www-data. /etc/freeswitch /var/lib/freeswitch \
/var/log/freeswitch /usr/share/freeswitch \
/var/log/astpp /var/log/nginx /opt/ASTPP

# Directory permissions to 755 (u=rwx,g=rx,o='rx')
find /etc/freeswitch -type d -exec chmod 755 {} \;
find /var/lib/freeswitch -type d -exec chmod 755 {} \;
find /var/log/freeswitch -type d -exec chmod 755 {} \;
find /usr/share/freeswitch -type d -exec chmod 755 {} \;
find /opt/ASTPP -type d -exec chmod 755 {} \;
find /var/log/astpp -type d -exec chmod 755 {} \;
find /var/lib/astpp -type d -exec chmod 755 {} \;

# File permissions to 777(u=rwx,g=rwx,o=rwx)
find /var/log/astpp -type f -exec chmod 777 {} \;

# File permissions to 644 (u=rw,g=r,o=r)
find /etc/freeswitch -type f -exec chmod 644 {} \;
find /var/lib/freeswitch -type f -exec chmod 644 {} \;
find /var/log/freeswitch -type f -exec chmod 644 {} \;
find /usr/share/freeswitch -type f -exec chmod 644 {} \;
find /opt/ASTPP -type f -exec chmod 644 {} \;
find /var/lib/astpp -type f -exec chmod 644 {} \;

Configure php-fpm

sed -i "s/;request_terminate_timeout = 0/request_terminate_timeout = 300/" /etc/php/7.3/fpm/pool.d/www.conf
sed -i "s#short_open_tag = Off#short_open_tag = On#g" /etc/php/7.3/fpm/php.ini
sed -i "s#;cgi.fix_pathinfo=1#cgi.fix_pathinfo=1#g" /etc/php/7.3/fpm/php.ini
sed -i "s/max_execution_time = 30/max_execution_time = 3000/" /etc/php/7.3/fpm/php.ini
sed -i "s/upload_max_filesize = 2M/upload_max_filesize = 20M/" /etc/php/7.3/fpm/php.ini
sed -i "s/post_max_size = 8M/post_max_size = 20M/" /etc/php/7.3/fpm/php.ini
sed -i "s/memory_limit = 128M/memory_limit = 512M/" /etc/php/7.3/fpm/php.ini
systemctl restart php7.3-fpm
systemctl restart nginx

Configure firewall

apt -y install firewalld
systemctl enable firewalld
systemctl start firewalld

firewall-cmd --permanent --zone=public --add-service={http,https}
firewall-cmd --permanent --zone=public --add-port={5060,5061}/tcp
firewall-cmd --permanent --zone=public --add-port={5060,5061}/udp
firewall-cmd --permanent --zone=public --add-port=16384-32768/udp
firewall-cmd --reload
firewall-cmd --list-all

Configure log rotation

sed -i -e 's/daily/size 30M/g' /etc/logrotate.d/rsyslog
sed -i -e 's/weekly/size 30M/g' /etc/logrotate.d/rsyslog
sed -i -e 's/rotate 7/rotate 5/g' /etc/logrotate.d/rsyslog
sed -i -e 's/weekly/size 30M/g' /etc/logrotate.d/php7.3-fpm
sed -i -e 's/rotate 12/rotate 5/g' /etc/logrotate.d/php7.3-fpm
sed -i -e 's/daily/size 30M/g' /etc/logrotate.d/nginx
sed -i -e 's/rotate 14/rotate 5/g' /etc/logrotate.d/nginx
sed -i -e 's/weekly/size 30M/g' /etc/logrotate.d/fail2ban

Enable services

systemctl daemon-reload
systemctl enable freeswitch
systemctl restart freeswitch

Test Freeswitch console

If fs_cli command is not working change the following line.

nano +4 /etc/freeswitch/autoload_configs/event_socket.conf.xml
<param name="listen-ip" value="127.0.0.1"/>
systemctl restart freeswitch

Browse to control panel

https://x.x.x.x

username: admin
password: admin

The  443 listening port can be changed at /var/lib/astpp/astpp-config.conf and  /etc/nginx/sites-available/astpp.conf. Remember to add the port on the firewall as well.  If accessing by DNS name change the IP to the DNS name in /var/lib/astpp/astpp-config.conf.

User documentation is located at the following link
https://docs.astppbilling.org/display/itplmars/Overview+of+ASTPP

Troubleshooting

The primary ways to troubleshoot are to watch the fs_cli command line in real time or to scan the log files, some of which duplicate that info.  The fs_cli info is logged in /var/log/freeswitch.log

When troubleshooting it is also sometimes helpful to enable debugging.  There are at least 4 separate debugging settings in ASTPP. 

The first place to start would usually be to set

/opt/ASTPP/web_interface/astpp/application/config/config.php > $config['log_threshold'] = 4

This will cause a date stamped log file to be created at

/opt/ASTPP/web_interface/astpp/application/log

which shows all the PHP code being initialized and any errors in that code.   This should only be enabled temporarily as the log files are not automatically deleted.  There may also be some sensitive information in those files.

The second debugger is in the GUI at

Configuration > Settings > Calls  > Debug

This will enable logging to /var/log/astpp.log and will show the variables being passed to freeswitch from the database.

The 3rd debugger is located in the GUI at

Switch > SIP Profiles > default > sip-trace 

If changed to yes and adding another setting tracelevel = debug you can trace SIP traffic.

Lastly, you can enable php debugging by going to 

/opt/ASTPP/web_interface/astpp/index.php

and set define ( 'ENVIRONMENT', 'development' ).  This allows you to see the PHP errors in a web browser as they happen instead of just in the log files.

Sections: