Showing posts with label pbx. Show all posts
Showing posts with label pbx. Show all posts

Wednesday, May 4, 2016

CSF firewall installation and configuration for VOIP/PBX systems-Part 2

After installation of csf firewall and webmin done on part 1 of this document, part 2 will concentrate on only configuration of the firewall, configuration to be done is described in steps below.

a. Allowing IP/IP blocks with fully access to the server.
You may start the configuration by adding you own block which should have fully access to pbx/voip system,fully access means the ip's should have fully access to all ports on the server these IP's should be your private LAN ip or ISP ip's if your configuring service providers voip/pbx system, to do so logon to your system via https://serverip:1000, then go to System > ConfigServer Security & Firewall, then csf - ConfigServer Firewall section, add your ip/ip blocks to Quick Allow and Quick Ignore,as seen on example below:

Don't forget to click on Quick Allow and Quick Ignore to save it to configuration file.
You should also add you Voip provider IP, if your system is connecting to online voip provider, otherwise you might experience issue when calls are routed to voip provider.

b. Allowing specific ports for IP/IP blocks without fully access.
Now go Firewall Configuration, to add ports which should be accessible for anyone without fully access to the server, if your voip system is accessible from the Internet, these are ports will be seen directly from the Internet.
You may allow as many ports as you can  for ports going out, but you should restrict ports which are coming to your server as minimum as you can, as far as my research below ports working fine for PBX/VOIP systems,

   i. Incoming
Only allow voip/pbx pors 5060:5061 and 10001:20000 which are used as media ports for some pbx systems, so the setup may look as below.
       a. TCP
           5060:5061

         b. UDP
           5060:5061,10001:20000

   ii. Outgoing
As i said you may allow as outgoing ports as you can, no problem on this.

       a. TCP
           20,21,22,25,53,80,110,113,443
       b. UDP
           20,21,53,113,123,1000:65000

So the setting will look as below,

c. Blocking ping from outside
You may also need to block ping from outside as means of security, to do search for Allow incoming PING and change it from ON(1) to OFF(0).



d. Enabling the firewall
When all configuration is done, you should enable the firewall for it to be operation on your server, go back to the beginning of configuration file and look for TESTING part and turn it off, as seen below:

e. Testing the firewall
After enabling the configuration you should now test the firewall to make sure it works as intended, below are hints for testing.

-Test if all pbx users are able to call via the pbx, also monitor if they can hear the voice with required quality.
-Test if the users coming from restricted IP are able to access the admin interface of PBX/VOIP, i mean any traffic going to port 80/443, they should not as the access to only be available to allowed IP's.

There a lot of settings which can be done on CSF firewall, but above is minimum which can be used to lock down your VOIP/PBX systems,drop down comments if you face any problem implementing the settings.


Friday, April 22, 2016

CSF firewall installation and configuration for VOIP/PBX systems-Part 1

During installation of any PBX/VOIP systems, security is one of the first thing you should consider in mind as compromising the system may bring greater loss especially interms of Money. There are different ways of securing voip/pbx systems but this how to is going to explain how to lock it down completely by blocking all standard ports not accessible from the Internet and being only accessible via the specified subnet while allowing only specified ports to allow users being able to call and receive the calls.
This howto's is divided into two main parts, part 1 (involves firewall installation) and part 2 will concentrate on configuration of your firewall to meet your needs,below are steps.

a. Webmin installation
b. Csf Installation
c. Firewall configuration

a. Webmin Installation
Webmin is a web-based graphical tool for unix . It is used to manage services like User management, Disk managemet, Network, Iptables ( Firewall ), Cron, Apache, DNS, File sharing and much more.Webmin is a web hosting control panel like cpanel which provides easy to use interface for managing Unix like systems.

i. Install required packages first.
# yum -y install perl perl-Net-SSLeay openssl perl-IO-Tty

ii. Install Webmin.

Make sure to check for the latest version here (http://www.webmin.com/download.html). As the time of writting of this document the latest version is 1.791.
# yum -y install http://prdownloads.sourceforge.net/webadmin/webmin-1.791-1.noarch.rpm


The installation will be done automatically to the directory /usr/libexec/webmin, the administration username set to root and the password to your current root password. You should now be able to login to Webmin at the URL http://localhost:10000/. Or if accessing it remotely, replace localhost with your system's IP address.




More tweaks:
-Starting and restarting the service use:
# /etc/init.d/webmin start
# /etc/init.d/webmin stop
# /etc/init.d/webmin restart
# /etc/init.d/webmin status
-Changing webmin root password

In order to change webmin root account password use following command. ( Note: It will not change your systems root password )

-Change webmin default port
If you do not want to run webmin with default port, use below steps to change the default port.

Login Webmin as root >> Webmin >> Webmin Configuration >> Ports and Addresses… you can change port there.


b. Csf Installation

CSF(Config Server Firewall) is generally considered a more advanced firewall as there are more configuration options compared to other firewalls, while still being simple enough to install and configure that even novice administrators can use it.An alternative firewall to CSF is the Advanced Policy Firewall or APF.
Installing CSF should be as simple as downloading the source file to your server and installing it, follow the following steps to install it.

i. Migrate to src directory and remove any existed csf file.
# cd /usr/src
# rm -fv csf.tgz
ii. Download the firewall and extract the downloaded file
# wget https://download.configserver.com/csf.tgz
# tar -xzf csf.tgz
iii. Change to csf directory and run installation script
# cd csf
# sh install.sh
iv.Test whether you have the required iptables modules:
# perl /usr/local/csf/bin/csftest.pl
Don't worry if you cannot run all the features, so long as the script doesn't
report any FATAL errors

v. Remove old CSF/APF firewalls

You should not run any other iptables firewall configuration script. For
example, if you previously used APF+BFD you can remove the combination (which
you will need to do if you have them installed otherwise they will conflict):
# sh /usr/local/csf/bin/remove_apf_bfd.sh
vi. Integrating CSF with webmin

Inorder to manage csf firewall on web browser via webmin you're required to Integrate it to webmin.
Install the csf webmin module in:
  Webmin > Webmin Configuration > Webmin Modules >
  From local file > /usr/local/csf/csfwebmin.tgz > Install Module

To access CSF configuration file via Webmin go to System System > Security & Firewall



vii. Uninstallation CSF firewall

Removing csf and lfd is even more simple:
# cd /etc/csf
# sh uninstall.sh
viii. Removing Warning

In case you get this warning below:

*WARNING* URLGET set to use LWP but perl module is not installed, reverting to HTTP::Tiny

When accessing CSF firewall via Webmin, install perl module using command below.
# yum install perl-libwww-perl
That's it, check out part 2 for voip firewall configuration.



Tuesday, March 22, 2016

Forcing access to Asterisknow/FreePBX and A2billing to HTTPS

When installing asteriskNow PBX/voip system and a2billing to access it by default is via http. When it comes to VOIP/PBX system security is one thing you should consider. This HOWto's is going to explain the steps to follow when you want you pbx server to be access via https, the steps include creating self signed certificate and forcing all traffics to https.

1. Install Mod SSL
# yum install mod_ssl
2. Create a new directory
Next, we need to create a new directory where we will store the server key and certificate
# mkdir /etc/httpd/ssl
3. Create a self signed certificate

When we request a new certificate, you should specify how long the cerficate remains valid, for me i want certificate to remain valid for ten years, you may change 3650 to any number of number of days you want.
openssl req -x509 -nodes -days 3650 -newkey rsa:2048 -keyout /etc/httpd/ssl/apache.key -out /etc/httpd/ssl/apache.crt
With this command, we will be both creating the self-signed SSL certificate and the server key that protects it, and placing both of them into the new directory.

This command will prompt terminal to display a lists of fields that need to be filled in.

The most important line is "Common Name". Enter your official domain name here or, if you don't have one yet, your site's IP address.

See example below,

For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:TZ
State or Province Name (full name) [ ]:Arusha
Locality Name (eg, city) [Default City]:Arusha
Organization Name (eg, company) [Default Company Ltd]: JARASYOLA COMPANY LTD
Organizational Unit Name (eg, section) [ ]:VOIP
Common Name (eg, your name or your server's hostname) [ ]:voip.jarasyola.co.tz
Email Address [ ]:voip@jarasyola.co.tz


4. Copy the newly created keys to their respective locations as needed by apache
 # cd /etc/httpd/ssl/
 # cp apache.crt /etc/pki/tls/certs/
 # cp apache.key /etc/pki/tls/private/

5. Now you must change some parameters in the /etc/httpd/conf.d/ssl.conf file
# vi /etc/httpd/conf.d/ssl.conf

5a. Look for the line beginning with: SSLCertificateFile and change the path to our reflect our newly created certs (/etc/pki/tls/certs/apache.crt)

5b. Look for the line beginning with: SSLCertificateKeyFile and change the path to reflect our newly created certs (/etc/pki/tls/private/apache.key)


6. Force all traffic coming to your server to https

To force all web traffic to use HTTPS insert the following lines of code in the .htaccess file in your website’s root folder.
# cd /var/www/html
# vim .htaccess

Add the following code and save the file
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.yourdomain.com/$1 [R,L]

Make sure to change yourdomain.com to your server valid domain or IP address.


7. Restart apache

You are done. Restarting the Apache server will reload it with all of your changes in place.
 /etc/init.d/httpd restart

In your browser, type https://youraddress to view the new certificate.



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!!!!!.