Thursday, July 19, 2012

A2billing installation


#install dependencies
yum -y install gcc gcc-c++ kernel-devel bison openssl openssl-devel perl perl-Net-SSLeay
perl-Crypt-SSLeay libtermcap-devel ncurses-devel doxygen curl-devel newt-devel
mlocate lynx tar wget nmap bzip2 mod_ssl crontabs vixie-cron speex speex-devel
unixODBC unixODBC-devel libtool-ltdl libtool-ltdl-devel mysql-connector-odbc
mysql mysql-devel mysql-server php-mysql php-mbstring php-mcrypt flex screen
libtiff-devel perl-DBD-Pg subversion python-setuptools.noarch MySQL-python php-gd
easy_install sqlalchemy

# A2billing installation
mkdir /usr/src/a2billing
cd /usr/src/a2billing

# download A2billing using SVN
svn co --username guest --password guest http://svn.a2billing.net/svn/asterisk2billing/trunk/ /usr/local/src/a2billing
chown -R asterisk.asterisk a2billing
chown -R  asterisk.apache admin/ customer/ agent/


# Create Sybolick link of a2billing.conf
ln -s /usr/local/src/a2billing/a2billing.conf /etc/a2billing.conf
chown -Rf asterisk.asterisk /etc/a2billing.conf

# Change a2billing.conf

sed -i "s/\(port *= *\)\(.*\)/\13306/" /etc/a2billing.conf
sed -i "s/\(user *= *\)\(.*\)/\1a2billinguser/" /etc/a2billing.conf
sed -i "s/\(password *= *\)\(.*\)/\1a2billing/" /etc/a2billing.conf
sed -i "s/\(dbname *= *\)\(.*\)/\1mya2billing/" /etc/a2billing.conf

# create a MySQL database (mya2billing) for the billing software. 

cd /usr/local/src/a2billing/DataBase/mysql-5.x
mysql -u root -p < a2billing-createdb-user.sql

./install-db.sh

# Create the additional files and setup the correct owner:

touch /etc/asterisk/additional_a2billing_iax.conf
touch /etc/asterisk/additional_a2billing_sip.conf
echo \#include additional_a2billing_sip.conf >> /etc/asterisk/sip.conf
echo \#include additional_a2billing_iax.conf >> /etc/asterisk/iax.conf
chown -Rf asterisk:asterisk /etc/asterisk/additional_a2billing_iax.conf
chown -Rf asterisk:asterisk /etc/asterisk/additional_a2billing_sip.conf

# Install the sound files
/usr/local/src/a2billing/addons/sounds/install_a2b_sounds.sh

# Copy the entire content of the AGI directory into asterisk agi-bin directory. 

ln -s /usr/local/src/a2billing/AGI/a2billing.php /var/lib/asterisk/agi-bin/

cp -Rf /usr/local/src/a2billing/common/lib /var/lib/asterisk/agi-bin/

chown -Rf asterisk.asterisk /var/lib/asterisk/agi-bin/
chmod +x /var/lib/asterisk/agi-bin/a2billing.php
chmod +x /usr/local/src/a2billing/AGI/a2billing.php


# Installing the GUI interface

mkdir -p /var/www/html/achmod2billing

ln -s /usr/local/src/a2billing/common /var/www/html/a2billing/common
ln -s /usr/local/src/a2billing/admin /var/www/html/a2billing/admin
ln -s /usr/local/src/a2billing/agent /var/www/html/a2billing/agent
ln -s /usr/local/src/a2billing/customer /var/www/html/a2billing/customer

# set permissions
chown -Rf asterisk:asterisk /var/www/html/a2billing/
chmod 755  /usr/local/src/a2billing/admin/templates_c
chmod 755  /usr/local/src/a2billing/customer/templates_c
chmod 755  /usr/local/src/a2billing/agent/templates_c

#Now edit /etc/asterisk/manager.conf

[myasterisk]
secret = mycode
deny=0.0.0.0/0.0.0.0
permit=127.0.0.1/255.255.255.0
read = system,call,log,verbose,command,agent,user
write = system,call,log,verbose,command,agent,user

# Cronjobs

echo "# Automatically added for A2Billing
0 * * * * php /usr/src/a2billing/Cronjobs/a2billing_alarm.php
0 12 * * * php /usr/src/a2billing/Cronjobs/a2billing_archive_data_cront.php
0 10 21 * * php /usr/src/a2billing/Cronjobs/a2billing_autorefill.php
#Batch process at 00:20 each day
20 0 * * * php /usr/src/a2billing/Cronjobs/a2billing_batch_process.php
#Bill DID usage at 00:00 each day
0 0 * * * php /usr/src/a2billing/Cronjobs/a2billing_bill_diduse.php
#Remind users of low balance every day at 06:00
0 6 * * * php /usr/src/a2billing/Cronjobs/a2billing_check_account.php
#Generate Invoices at 7am everyday
#0 7 * * * php /usr/src/a2billing/Cronjobs/a2billing_invoice2_cront.php
#0 7 * * * php /usr/src/a2billing/Cronjobs/a2billing_invoice_cront.php
#Check if balance below preset value, and email user if so.
1 * * * * php /usr/src/a2billing/Cronjobs/a2billing_notify_account.php
#Charge subscriptions at 06:05 on the 1st of each month
0 6 1 * * php /usr/src/a2billing/Cronjobs/a2billing_subscription_fee.php
#Update currencies at 01:00 each day
0 1 * * * php /usr/src/a2billing/Cronjobs/currencies_update_yahoo.php
" >> /var/spool/cron/asterisk

# Add directory for monitoring Script
mkdir -p /var/lib/a2billing/script
mkdir -p /var/run/a2billing


# Create Log Files
# Log files and Permissions

mkdir -p  /var/log/a2billing

touch /var/log/asterisk/a2billing-daemon-callback.log;touch /var/log/a2billing/a2billing-daemon-callback.log;touch /var/log/a2billing/cront_a2b_alarm.log;touch /var/log/a2billing/cront_a2b_autorefill.log;touch /var/log/a2billing/cront_a2b_batch_process.log;touch /var/log/a2billing/cront_a2b_bill_diduse.log;touch /var/log/a2billing/cront_a2b_subscription_fee.log;touch /var/log/a2billing/cront_a2b_currency_update.log;touch /var/log/a2billing/cront_a2b_invoice.log;touch /var/log/a2billing/cront_a2b_check_account.log;touch /var/log/a2billing/a2billing_paypal.log;touch /var/log/a2billing/a2billing_epayment.log;touch /var/log/a2billing/api_ecommerce_request.log;touch /var/log/a2billing/api_callback_request.log;touch /var/log/a2billing/a2billing_agi.log;chown -R asterisk:asterisk /var/log/a2billing


FOR CALLBACK DAEMON:-
======================
#goto target directory
cd /usr/local/src/a2billing/CallBack/callback-daemon-py/dist/

#untar the r1528 file to create callback_daemon-1.0.prod-r1528 directory
tar -xvf callback_daemon-1.0.prod-r1528.tar.gz

#Go down into the newly untared directory
cd callback_daemon-1.0.prod-r1528

#excute the following python commands as per a2billing doc site
python setup.py build
python setup.py bdist_egg

#additional steps to correct the path for the a2billing.conf file
vi callback_daemon/a2b_callback_daemon.py

replace the path to which your a2billing.conf resides in your system, the line should be --> CONFIG_FILE =

#execute the installation
(6) easy_install dist/callback_daemon-1.0.prod_r1528-py2.4.egg

#install the init script and daemon service (still at your current directory level)
(7) cd callback_daemon;cp a2b-callback-daemon.rc /etc/init.d/a2-callback-daemon
(8) chmod +x /etc/init.d/a2b-callback-daemon
(9) chkconfig --add a2b-callback-daemon
(10) chkconfig a2b-callback-daemon on

# finally start the service u can either use the init script or service command
(11a) service a2b-callback-daemon start
(11b) /etc/init.d/a2b-callback-daemon start