Thursday, July 19, 2012

Revcover MySQL root password


Step:1 Stop mysql service
# /etc/init.d/mysql stop

Step:2 Start to MySQL server without password:
# mysqld_safe --skip-grant-tables &

Step:3 Connect to mysql server using mysql client:
# mysql -u root

Step:4 Setup new MySQL root user password
mysql> use mysql;
mysql> update user set password=PASSWORD("NEW-ROOT-PASSWORD") where User='root';
mysql> flush privileges;
mysql> quit

Step:5 Stop MySQL Server:
# /etc/init.d/mysql stop

Step:6 Start MySQL server and test it

# service mysqld start
# mysql -u root -p

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

Restore a table from backup in MySQL


>DROP TABLE IF EXISTS `db.users`;
>CREATE TABLE `db.users` SELECT * FROM `db2.users`;


To do this you have to use:

>CREATE TABLE db.users LIKE db2.users;

then you populate it with the data from the old table with:

>INSERT INTO db.users SELECT * FROM db2.users;

If the copied old table has many keys then it may help to speed the INSERT if you turn off the keys using the following before the INSERT:

>ALTER TABLE db.users DISABLE KEYS;

And then after the INSERT:

>ALTER TABLE db.users ENABLE KEYS;

SSH Login without password

SSH Login without password:-

First, log in on A as a user and generate a pair of authentication keys. Do not enter a passphrase:

a@A:~> ssh-keygen -t rsa

Generating public/private rsa key pair.
Enter file in which to save the key (/home/a/.ssh/id_rsa):
Created directory '/home/a/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/a/.ssh/id_rsa.
Your public key has been saved in /home/a/.ssh/id_rsa.pub.
The key fingerprint is:
3e:4f:05:79:3a:9f:96:7c:3b:ad:e9:58:37:bc:37:e4 a@A

Now use ssh to create a directory ~/.ssh as user b on B. (The directory may already exist, which is fine):

a@A:~> ssh b@B mkdir -p .ssh
b@B's password:

Finally append a's new public key to b@B:.ssh/authorized_keys and enter b's password one last time:

a@A:~> cat .ssh/id_rsa.pub | ssh b@B 'cat >> .ssh/authorized_keys'
b@B's password:

From now on you can log into B as b from A as a without a password:

a@A:~> ssh b@B hostname
B

A note from one of our readers: Depending on your version of SSH you might also have to do the following changes:

Put the public key in .ssh/authorized_keys2
Change the permissions of .ssh to 700
Change the permissions of .ssh/authorized_keys2 to 640

MailScanner with Spamassisn and clamv antivirus


Steps:-

I assume that the Sendmail package is installed by default.

Install MailScanner with SpamAssassin and ClamAV

1. Install SpamAssassin

# yum install spamassassin

No further action is necessary to integrate into MailScanner.

2. Install ClamAV

# yum install clamav clamav-update
Edit and enable freshclam - the clamav update module
# vi /etc/freshclam.conf
.......
# Comment or remove the line below.
#Example
......
Update the ClamAV virus signature. (will be done automatically by MailScanner routinely when integrated.)

# freshclam
Scan file or directory for virus, test clamav is working. "$ man clamscan" for more options.
# clamscan -v -r ~someuser

3. Install MailScanner

Download the latest version of MailScanner tarball from http://www.mailscanner.info/.
At the time of writing, it is MailScanner-4.70.7-1.rpm.tar.gz

# cd /directory/that/you/saved/download
# tar xzf MailScanner-4.70.7-1.rpm.tar.gz
# cd MailScanner-4.70.7-1
# ./install.sh

It would take some time as it installs all Perl prerequisite modules. When done it should install ailScanner service and turn-off sendmail service. (Sendmail will be started/stopped by MailScanner).


To ensure that sendmail service is off, and MailScanner is on,
# /sbin/chkconfig --list sendmail
sendmail 0:off 1:off 2:off 3:off 4:off 5:off 6:off

# /sbin/chkconfig --list MailScanner
MailScanner 0:off 1:off 2:on 3:on 4:on 5:on 6:off

# /sbin/chkconfig sendmail off
# /sbin/chkconfig MailScanner on

Edit /etc/MailScanner/MailScanner.conf file, MailScanner.conf file is fully commented, easy to understand.
Start with simple things such as setting sites and company names. When you are more comfortable with it, work on the rules files.


Start MailScanner (first time) with
# /sbin/service sendmail stop
# /sbin/service MailScanner start
To restart after editing MailScanner.conf
# /sbin/service MailScanner restart

4. Integrate clamav with MailScanner

Next step is optional. Can leave as "auto".
# vi /etc/MailScanner/MailScanner.conf
.....
# This *cannot* be the filename of a ruleset.
#Virus Scanners = auto
Virus Scanners = clamav
.....
Set the correct path for ClamAV scanner
# vi /etc/MailScanner/virus.scanners.conf
....
#clamav /usr/lib/MailScanner/clamav-wrapper /usr/local
clamav /usr/lib/MailScanner/clamav-wrapper /usr
Set the correct path for freshclam

# vi /usr/lib/MailScanner/clamav-autoupdate
# $PackageDir = shift || "/usr/local";
$PackageDir = shift || "/usr";

Restart MailScanner
# /sbin/service MailScanner restart

Check /var/log/maillog for MailScanner messages, look for any errors.
# tail -40f /var/log/messages

Sangoma GSM cards installation with Asterisk


STEPS to install Sangoma cards:-

=>yum -y install kernel-devel-$(uname -r) libtool* make gcc patch perl bison gcc-c++ ncurses-devel flex libtermcap-devel qt3 autoconf* automake* autoconf libxml2-devel cmake sqlite-devel openssl-devel newt-devel curl curl-devel

=>mkdir -p /usr/src/asterisk
=>cd /usr/src/asterisk
=>wget http://downloads.asterisk.org/pub/telephony/dahdi-linux-complete/releases/dahdi-linux-complete-2.5.0.2+2.5.0.2.tar.gz
=>wget http://downloads.asterisk.org/pub/telephony/libpri/libpri-1.4-current.tar.gz
=>wget http://downloads.asterisk.org/pub/telephony/asterisk/old-releases/asterisk-1.6.2.22.tar.gz

=>mkdir -p /usr/src/wanpipe
=>cd /usr/src/wanpipe
=>wget ftp://ftp.sangoma.com/linux/custom/gsm/wanpipe-3.5.24.1gsm0.15.tgz
OR
=>ftp://ftp.sangoma.com/linux/current_wanpipe/wanpipe-3.5.27.tgz
=>wget ftp://ftp.sangoma.com/linux/libwat/libwat-1.0-current.tgz
=>wget http://www.cmake.org/files/v2.8/cmake-2.8.8.tar.gz
=>wget http://ftp.gnu.org/gnu/autoconf/autoconf-2.68.tar.gz


Dahdi Installation
#>./configure
#>make
#>make install

LibPRI Installation 
#>tar xvfz libpri-<version>
#>cd libpri-<version>
#>make
#>make install

Asterisk Installation
#>tar xvfz asterisk-<version>.tgz
#>cd asterisk-<version>
#>./configure    
#>make
#>make install
#>make samples (in case of very first install)

Wanpipe Driver Installation
#>tar xvfz wanpipe-<version>.tgz
#>cd wanpipe-<version>
#>./Setup dahdi

Cmake Installation
 ./bootstrap
 make
 make install

Libwat Installation
#> tar xfz libwat-1.0-current.tgz
#> cd libwat-N.N.N/build
#> cmake ..
#> make
#> make install

Patching
#>tar xfz autoconf autoconf-2.68.tar.gz
#>./configure
#>make
#>make install

Copy patches to asterisk source directory. Make sure to use the patch version that matches your version of asterisk:
#>cd libwat-1.X.X/asterisk
#>cp asterisk-1.6.2.22.patch /usr/src/asterisk-1.6.2.22/

To patch your Asterisk installation:
#>cd asterisk-1.6.2.22
#>patch -p 1 < asterisk-1.6.2.22.patch

Re-configure and re-compile your Asterisk:
#>./bootstrap.sh
#>./configure
#>make clean
#>make
#>make install

Test
#>wanrouter hwprobe
#> wancfg_dahdi
#>wanrouter start