Friday, March 18, 2016

A2billing installation on AsteriskNow 6.12 PBX server

A2Billing is a telecom switch and billing system capable of providing and billing a range of telecom products and services to customers such as calling card products, residential and wholesale VoIP termination, DID resale and callback services.A2billing is an open source implementation of a telecommunication billing and added value services platform.A2billing is a LAMP (Linux Apache Mysql(Postgresql) PHP) application that interfaces with Asterisk using both the AMI and AGI interfaces.
After searching online for updated HOWto's and failing to get one with is straight forward, i decided to compile one and share with you. This installation is done on Asterisk now server version 6.12 with FreePBX 6.12.65,CentOS 6.5 final and Asterisk 11.

A2billing Installation.

1. Update the system
# yum update

2. Install additional required packages if not already installed
# yum -y install php-mcrypt perl-DBD-Pg

3. Change php folder permission back to what it was set to during Asterisk/FreePBX install before PHP update
# chown -R asterisk:asterisk /var/lib/php/session

4. Add php timezone:
# vim /etc/php.ini
search for date.timezone

Uncomment date.timezone =

Change # date.timezone = to date.timezone ="Africa/Dar_es_Salaam"

Note:
You should change the timezone to according to your location, check the list of timezone here


5. Restart apache for the changes to take effect
# service httpd restart

6. Get a2billing source
# cd /usr/src
#wget --no-check-certificate https://github.com/Star2Billing/a2billing/tarball/v1-current
Note the filename of the downloaded file and use it as follows:
# tar zxvf  v1-current
# mv Star2Billing-a2billing-xxxxx a2billing

7. Prepare MySQL database

7.i. Create MySQL root password

If you did not create a mysql root password during the asterisk install you should create one now.
# mysqladmin -u root password 'rootmysqlpassword'
Note this password you will use it again during further configuration.

7.ii. If MySQL root password already exists

If you get access denied the password has already been set.  For PowerPBX install guide a password of abcdef was used.  For distributions such as PiaF, the password might be passw0rd.  This will be the password the following commands will ask for.

If you do not know the MySQL root password and want to change it

If you do not know what it is this guide has a procedure for changing the MySQL root password which is as follows.  Otherwise skip down to Create A2Billing Database.
#service mysqld stop
# mysqld_safe --skip-grant-tables &
If you don't see a command prompt (#) appear press the ENTER key and you should get it.
# mysql --user=root mysql
> update user set Password=PASSWORD('new-root-password') where user='root';
>\q
# service mysqld restart

7.iii. Create A2Billing Database
# cd /usr/src/a2billing
# mysql -u root -p < DataBase/mysql-5.x/a2billing-createdb-user.sql
# cd /usr/src/a2billing/DataBase/mysql-5.x
#./install-db.sh
Answer questions as follows:

Enter Database Name: mya2billing
Enter Hostname: localhost
Enter UserName: root
Enter Password: 'mysqlrootpassword'
# cp /usr/src/a2billing/a2billing.conf /etc/
# vim /etc/a2billing.conf
Make sure the following parameters are set as shown.

[database]
hostname = localhost
port = 3306
user = a2billinguser
password = a2billing
dbname = mya2billing
dbtype = mysql

8. Create files and set permissions
#chmod 777 /etc/asterisk
#touch /etc/asterisk/additional_a2billing_iax.conf
#touch /etc/asterisk/additional_a2billing_sip.conf
#echo \#include additional_a2billing_sip.conf >> /etc/asterisk/sip_custom.conf
#echo \#include additional_a2billing_iax.conf >> /etc/asterisk/iax_custom.conf
#chown -Rf asterisk:asterisk /etc/asterisk/additional_a2billing_iax.conf
#chown -Rf asterisk:asterisk /etc/asterisk/additional_a2billing_sip.conf

9. Run sound installation script
# cd /usr/src/a2billing/addons/sounds
#./install_a2b_sounds.sh
#chown -R asterisk:asterisk /var/lib/asterisk/sounds/

Open the file below
# vim /etc/asterisk/manager_custom.conf

And copy and paste the following:
[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

Note:
Some howto's recommend that above command should also be pasted on /etc/asterisk/manager.conf, i pasted on both files and nothing went wrong, so i think you should do the same.

10. Set up a2billing web folder

# mkdir /var/www/html/a2billing
cp -Rf /usr/src/a2billing/admin /var/www/html/a2billing/admin
cp -Rf /usr/src/a2billing/agent /var/www/html/a2billing/agent
cp -Rf /usr/src/a2billing/customer /var/www/html/a2billing/customer
cp -Rf /usr/src/a2billing/common /var/www/html/a2billing/common
# chown -R asterisk:asterisk /var/www/html/a2billing
chmod 755 /var/www/html/a2billing/admin/templates_c
chmod 755 /var/www/html/a2billing/customer/templates_c
chmod 755 /var/www/html/a2billing/agent/templates_c

11. Set up AGI
# mkdir /var/lib/asterisk/agi-bin
cd /usr/src/a2billing/AGI
cp a2billing.php /var/lib/asterisk/agi-bin/
chown -R asterisk:asterisk /var/lib/asterisk/agi-bin
chmod 755 /var/lib/asterisk/agi-bin/a2billing.php
ln -s /var/www/html/a2billing/common/lib /var/lib/asterisk/agi-bin/lib
Open file below:
# vim /etc/asterisk/extensions_custom.conf

Copy, paste and save the content below.
[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()


[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


Go into FreePBX GUI>Connectivity>Trunks>Add Custom Trunk give it any name and add the following dial string
Local/$OUTNUM$@a2billing/n

12. Add custom destinations to FreePBX via FreePBX GUI>Admin>Custom Destinations

Custom Destination: custom-a2billing,${EXTEN},1
Destination Quick Pick: (pick destination)
Description: A2Billing - Callthrough

Custom Destination: custom-a2billing-did,${EXTEN},1
Destination Quick Pick: (pick destination)
Description: A2Billing - DID
# amportal restart
Recurring Services
Recurring services are handled via the /etc/crontab.

14. Make directory for A2Billing cron PID
# mkdir -p /var/run/a2billing
chown asterisk:asterisk /var/run/a2billing

Copy cron files to some permanent location such as /usr/local

# mkdir -p /usr/local/a2billing
cp -R /usr/src/a2billing/Cronjobs /usr/local/a2billing/
ln -sf /var/www/html/a2billing/common/lib /usr/local/a2billing/Cronjobs/lib
chown -R asterisk:asterisk /usr/local/a2billing

15. Add the cron jobs to /var/spool/cron/asterisk.

Open file below:
# vim /var/spool/cron/asterisk

Copy, paste and save the content below:
# update the currency table
0 6 * * * php /usr/local/a2billing/Cronjobs/currencies_update_yahoo.php
# manage the monthly services subscription
0 6 1 * * php /usr/local/a2billing/Cronjobs/a2billing_subscription_fee.php
# To check account of each Users and send an email if the balance is less than the user have choice.
0 * * * * php /usr/local/a2billing/Cronjobs/a2billing_notify_account.php
# this script will browse all the DID that are reserve and check if the customer need to pay for it.
# bill them or warn them per email to know if they want to pay in order to keep their DIDs.
0 2 * * * php /usr/local/a2billing/Cronjobs/a2billing_bill_diduse.php
# This script will take care of the recurring service.
0 12 * * * php /usr/local/a2billing/Cronjobs/a2billing_batch_process.php
# To generate invoices and for each user.
0 6 * * * php /usr/local/a2billing/Cronjobs/a2billing_batch_billing.php
# to proceed the autodialer
*/5 * * * * php /usr/local/a2billing/Cronjobs/a2billing_batch_autodialer.php
# manage alarms
0 * * * * php /usr/local/a2billing/Cronjobs/a2billing_alarm.php
# manage archive
0 12 * * * php /usr/local/a2billing/Cronjobs/a2billing_archive_data_cront.php
#autorefill
0 10 21 * * php /usr/local/a2billing/Cronjobs/a2billing_autorefill.php
15 * * * * php /usr/local/a2billing/Cronjobs/a2billing_batch_cache.php

16. Add log files:
mkdir -p /var/log/a2billing
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_archive_data.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/a2billing_api_ecommerce_request.log
touch /var/log/a2billing/a2billing_api_callback_request.log
touch /var/log/a2billing/a2billing_api_card.log
touch /var/log/a2billing/a2billing_agi.log

# chown -R asterisk:asterisk /var/log/a2billing

Add index file to prevent browsing of root folder

#touch /var/www/html/a2billing/index.html

Log into the webpage

http://<ip-addr>/a2billing/admin

user: root
pass: changepassword

To configure A2billing and  make your first call, use tutorial video tutorial found here.

Feel free to contact me in case you stuck some where, i will be happy to help.

Kwaheri!!!!!.

Wednesday, December 16, 2015

The power of Google docs

Google is my favorite search engine and it never amazing me as how powerfully and clever it is despite being younger than me!!!! hahaha!!!!.

I remember  I commented on Facebook post of our one of my friends who was doing survey using email address ms word and I introduce to him to start using Google survey/form which is more powerfully and secure, you can access it here.

Since then Google never fail to amazing me as it is more than just a search engine, I used to know about google docs since when i was in college, but i never know how powerfully it is until a while ago, and i think i will be worth if i share my experience on google docs.

It normal for most Internet users to search for different template for their daily reports, people search for project proposal,resumes, sample letters, news letter, budget , easy report templates etc without knowing all that and more are available via Google docs, all you need is to have is Google account (Gmail) which is freely available, if you don't have google email address yet you can register using this link.

When done registering, login on your Gmail account and open a new tap then write docs.google.com to access Google docs as seen below,



Google docs are divided into 3 main parts.

  • Documents (docs)
  • Speedsheets (sheets)
  • Slides


To navigate on these 3 docs section, click on Docs word on left part of your browser as below


Docs
On document section, there are lot of templates you can use which are divided into Resumes, letters, Education and Work, see below,





Sheets
Also there different speed sheets docs you can use where they are divided into Personal, Work and Education.

Slides
The slides also are grouped in terms of Education, work and personal.

Until you start using some of the templates you will never know how powerfully it is, the good this about it after editing your docs you can save it online and access it every where but one limitation is you will need Internet to access your docs.

I wrote this to share with those who don't know how Google docs can help them to do their daily works, from students, professionals to business persons all can enjoy advantages and rich features Google docs.

Hope it help someone, if you like the post please drop a comment.



Friday, November 13, 2015

Email notification scheduling scripts on FreeBSD

Scripting is the best tool for any system administration,I had a system which is used to send notification email to clients, but we need these notification to be sent only on specific time, shell scripts help me to fully fill my needs by very few lines. I decided to share this script for any one wishing to schedule email sending on his system, my system use sendmail mail system and run on FreeBSD 7 operating system.

To achieve this I decided to design two scripts working as follows

a. Script one is used to stop the mail system at specific time.
b. Second script clean queued and deferred emails when the email system is down and start the email system.
c. Schedule the two scripts using the cron job to run on different time.

Below are steps for creating the scripts


a. Scripts 1

Change to root user and migrate to root directory, to create the scripts

sudo su
cd /root/ 

i. Create the file

vi stopsendmail.sh 

ii. Copy and paste the content below on created file

#!/bin/sh
/etc/rc.d/sendmail stop

And save the file. This script only stop sendmail mail system so that no any email will be sent.

iii. Make the script executable

chmod a+x stopsendmail.sh

b. Scripts 2

This second script clean the emails on the queue and any deffered email sent when mail system was done, and finally start mail system.

i. Creating the file

vi startsendmail.sh

ii. Copy and paste the content below on created file

#!/bin/sh
rm -rf /var/spool/mqueue/*
rm -rf /var/spool/clientmqueue/*
/etc/rc.d/sendmail start

iii. Make the script executable

chmod a+x startsendmail.sh

c. Create cron job to run the two scripts

Run the command below to open the cron file.

crontab -e

Copy and paste the following

# This Script stop the mail service at 17:45 Everyday
45 17 * * * /root/stopsendmail.sh
# This script start the mail service every 08:05 Evertday
05 8 * * * /root/startsendmail.sh

Your done, these two simple scripts will disable email system at one time and active it at the other time. If your using another system the commands and path may change a bit but semantics will be the same.


Hope it helps someone, if you face any challenge implementing the scripts drop the comment I will be happy to help.


Happy scripting and automation.



Friday, October 30, 2015

TheHarvester Linux Information gathering Tool

Ever you come in the situation where you want to send email to users of certain domain but you can't find any valid email addresses? theHarvester information gathering tool can help you.
theHarvester is a tool for gathering e-mail accounts, sub-domain names, virtual hosts, open ports/ banners, and employee names from different public sources (search engines, pgp key servers).
The sources supported are:

Google – emails, subdomains/hostnames
Google profiles – Employee names
Bing search – emails, subdomains/hostnames, virtual hosts
Pgp servers – emails, subdomains/hostnames
LinkedIn – Employee names
Exalead – emails, subdomain/hostnames

To get started, if theHarvester is not available in your Linux distribution, go and download it from here or check the latest version from here.

Migrate to download directory and extract the file

➜  ~   cd /home/james/Downloads
➜  ~  tar -xvzf  theHarvester-2.2a.tar.gz

Migrate to extracted directory and provide execute permission to the theHarvester.py

➜  ~   cd theHarvester-2.2a/
➜  ~  chmod 755 theHarvester.py


After getting in to that, simply run ./theHarvester.py , it will display version and other option that can be used with this tool with detailed description as seen on the diagram below,



To use the tool, use the following syntax

➜  ~ ./theHarvester.py -d [domainname] -l 300 -b [search engine name]

Example;
-The command below will search all email addresses, sub-domains,, virtual hosts found any where in google.

➜  ~ ./theHarvester.py -d facebook.com -l 300 -b google  

-The command below will search email address, sub-domains, virtual hosts etc of microsoft.com domain found in most search engines.

➜  ~ ./theHarvester.py -d microsoft.com -l 300 -b all 

If you are using KaliLinux, an Advanced Penetration Testing Linux distribution used for Penetration Testing, Ethical Hacking and network security assessments the tool comes pre-installed.


This tool is designed to help the penetration tester on an earlier stage; it is an effective, simple and easy to use, so don't abuse it, if you use it for hacking, hack ethically.


Enjoy!!

Monday, October 12, 2015

Bridging KVM guest machines

Kernel-based Virtual Machine (KVM) is a virtualization infrastructure for the Linux kernel that turns it into a hypervisor.Am using KVM to run virtual machines on my server, an alternative of kvm is virtualbox (which most of people are familiar with). When installing guest machines on host machine running kvm by default are assigned 192.168.122.0/0 IP address which is virtual address which are accessible only within the host machine, but not outside.
In this lab am going to show you how to bridge guest machines on kvm where will be accessible outside their host machine.This is archived by bridging them on host machine Ethernet interface and will be receiving dhcp from the router where the host machine is connected. Now lets start:

a. Start the kvm virtual manager

➜  ~   sudo virt-manager 



When booting one of my guest machine, by default it was assigned 192.168.122.122 ip address, see




Now lets configure it, so that will be receiving IP from dhcp server from the router.

b. Host machine configuration

Open host machine terminal and create the virtual bridge interface and add your physical on it, as below

➜  ~  sudo vim /etc/network/interfaces

The file should look as below

# interfaces(5) file used by ifup(8) and ifdown(8)

# Include files from /etc/network/interfaces.d:

source-directory /etc/network/interfaces.d



##########Bridge start#####

auto lo

iface lo inet loopback

auto eth0

iface eth0 inet manual

        up ifconfig $IFACE 0.0.0.0 up

        down ifconfig $IFACE down

auto br0
iface br0 inet static
bridge_ports eth0
bridge_fd 9
bridge_hello 2
bridge_maxage 12
address 192.168.0.100
netmask 255.255.255.0
network 192.168.0.0
broadcast 192.168.0.255
gateway 192.168.0.1
dns-nameservers 8.8.8.8
############Bridge end#######

Where i created an virtual interface named br0 and assigned it one of static ip in the range of my LAN ip.

Then, restart your network service

 ➜  ~  sudo /etc/init.d/networking restart

Note:
I have noticed some cases where restarting the network services is not taking effect, so you will have to restart the whole host machine.

So restart the host machine.

➜  ~  sudo reboot

c. Guest machine configuration
When the host machines comes up, start the virtual machine manager and go to specific guest machine where you want to bride it, Go to Edit ,Virtual Machine Details,Details and then click your virtual interface, as seen below



On source device select Specify shared device name and on bridge name type br0 and then save, as seen below





Your done, restart your guest machine and see if it will receive IP via dhcp.


See, it receive 192.168.0. 10 which is my dhcp range.

Hope it help someone.