The Guru Of Tech - Gobind

Asterisk Insall, Codec Install, Vicidial Install.

Vicidial, Asterisk, Web-MeetMe, MySQL, OTRS

Vicidial, Asterisk, Web-MeetMe, MySQL, OTRS

Vicidial, Asterisk, Web-MeetMe, MySQL, OTRS

Vicidial, Asterisk, Web-MeetMe, MySQL, OTRS.

Vicidial, Asterisk, Web-MeetMe, MySQL, OTRS

Vicidial, Asterisk, Web-MeetMe, MySQL, OTRS.

Tuesday, May 7, 2013

Adding MySQL CDRs to Asterisk

CREATE DATABASE asterisk;
GRANT INSERT
ON asterisk.*
TO asterisk@localhost
IDENTIFIED BY 'yourpassword';

USE asterisk;

CREATE TABLE `cdr` (
`calldate` datetime NOT NULL default '0000-00-00 00:00:00',
`clid` varchar(80) NOT NULL default '',
`src` varchar(80) NOT NULL default '',
`dst` varchar(80) NOT NULL default '',
`dcontext` varchar(80) NOT NULL default '',
`channel` varchar(80) NOT NULL default '',
`dstchannel` varchar(80) NOT NULL default '',
`lastapp` varchar(80) NOT NULL default '',
`lastdata` varchar(80) NOT NULL default '',
`duration` int(11) NOT NULL default '0',
`billsec` int(11) NOT NULL default '0',
`disposition` varchar(45) NOT NULL default '',
`amaflags` int(11) NOT NULL default '0',
`accountcode` varchar(20) NOT NULL default '',
`userfield` varchar(255) NOT NULL default ''
);

ALTER TABLE `cdr` ADD `uniqueid` VARCHAR(32) NOT NULL default '';
ALTER TABLE `cdr` ADD INDEX ( `calldate` );
ALTER TABLE `cdr` ADD INDEX ( `dst` );
ALTER TABLE `cdr` ADD INDEX ( `accountcode` );
5. service mysqld restart
6. Check asterisk db and cdr table for errors.
we need to install some of the options from the Asterisk-Addons download.
7. cd /usr/src
8. wget http://downloads.asterisk.org/pub/te...1.6.2.3.tar.gz
10. tar –zxvf asterisk-addons-1.6.2.3.tar.gz

# cd /usr/src/asterisk/asterisk-addons-1.6.2.3
# make clean
# ./configure
# make menuselect
At this point, be sure to select at least the following items:
• Applications – app_addon_sql_mysql
• Call Detail Recording – cdr_addon_mysql
• Resource Modules – res_config_mysql
After you’ve got those selected, save and exit. Then proceed with the following steps:
# make
# make install
# make samples
Once we’ve got that done, we need to edit the cdr_mysql.conf file to enter the mysql username and password, database, and table we setup earlier.
# vi /etc/asterisk/cdr_mysql.conf
[global]
hostname=localhost
dbname=asterisk
table=cdr
password=PASSWORD
user=asterisk
port=3306
sock=/var/lib/mysql/mysql.sock
userfield=1
loguniqueid=yes

============
 HELP
1. If you do not find cdr_addon_mysql.so file under /usr/lib/asterisk/modules, you will have to re-compile.
2. edit /etc/asterisk/modules.conf and add lin: load => cdr_addon_mysql.so
3. save and restart asterisk – then check if cdrs are wrking in mysql. 

Friday, May 3, 2013

A2BILLING INSTALLATION GUIDE

To RUN this install PHP 5.2 or later as it wont work on earlier version because of filter_var() issue as in 5.2 it is already installed as a bundle

-----------

   This document focuses on the installation of A2Billing system for the Asterisk open source PBX. The document covers the installation and basic
configuration of
    A2Billing. 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.

    This documentation has been tested using Debian etch, Debian etch and half, Ubuntu 8.04 and Ubuntu 8.10 and A2Billing.


1. A2Billing installation guide
-------------------------------

1.1 Important note about distributions
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    This documentation assumes that you are using a .deb based distro that has used the folder /usr/share/asterisk during packaging. Other distributions use
the alternate
    folder /var/lib/asterisk. If you compile from source the path by default is /var/lib/asterisk.

    The basic assumptions of this documentation is that used pre-packaged software and:
        * your apache2 default root folder is /var/www
        * your asterisk sounds are under /usr/share/asterisk
        * your asterisk AGI folder is expected under /usr/share/asterisk
        * your apache2 runs as www-data (uid)
        * you asterisk runs as asterisk (uid)
        * those using subversion to check out the code, can use symbolic links instead of copying the files to the right directories

1.2 Default passwords and access info
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    This are the default passwords that you should know about
        * mysql root password (in default system normally is <ENTER>)
        * A2Billing default database is mya2billing, user is a2billinguser and password is a2billing
        * asterisk manager default information is: [myasterisk] and secret=mycode
        * A2Billing admin default password is: user: root password: changepassword


1.3 Pre-required software packages
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    A2billing requires the packages of a LAMP (PHP5) installation. To install the necessary packages, run the following commands:
        - apt-get install libapache2-mod-php5 php5 php5-common
        - apt-get install php5-cli php5-mysql mysql-server apache2 php5-gd
        - apt-get install openssh-server subversion

    A2Billing also requires MCrypt module for PHP5
        - apt-get install php5-mcrypt

    Asterisk is of course also needed.
        - apt-get install asterisk

                1.3.1 Extra software to support text-to-speech IVR monitoring

        Version 1.7.1 includes a new AGI mode that allows the monitoring of the a2billing system via an IVR.

        The new monitoring feature requires text-to-speech TTS support, the default TTS engine is Cepstral
        http://www.cepstral.com/ although a2billing can support Festival too.

        Install Cepstral (default path: /opt/swift) and make a symbolic link:
        - ln -s /opt/swift/bin/swift /usr/bin/swift

        Make sure that the dynamic libraries are linked, create a file called cepstral.conf under /etc/ld.so.conf.d/ including the path : /opt/swift/lib

        Do not forget to register your voice!



2. Installation
~~~~~~~~~~~~~~~

    In a nutshell installing A2Billing requires a minimum of seven steps (1-7)

    1. Download and unpack source code
    2. Setup the database
    3. Edit a2billing.conf file. Setting up the database parameters
    4. Fix permissions and folders
    5. Installing the web based graphical user interfaces (Customer and Admin)
    6. Place the AGI files
    7. Prepare your dialplan
    8. Add your cronjobs (only for notifcations, alarms and recurring services)
    9. Configure your callback daemon (only for callback)
    10. Enable monitoring (only for IVR monitoring)
    11. Enable card locking (only for card PIN locking)

    2.1. Step 1: Download and unpack source code

        Create a a2billing folder under /usr/local/src

            - mkdir /usr/local/src/a2billing

        Unpack the code

        Download the code from the SVN repository run:
            - svn co --username guest --password guest http://svn.a2billing.net/svn/asterisk2billing/tags/1-current /usr/local/src/a2billing/

        At the end of this step you should have a a2billing tree structure that should look like:
            - /usr/local/src/a2billing/

        Files :
            - AGI
            - CHANGELOG
            - COPYING
            - CallBack
            - Cronjobs : Recurrent services run via crontab
            - DataBase : Database Schema / DB Installation
            - FEATURES_LIST
            - a2billing.conf : Main Configuration file
            - addons : Sounds and other addons
            - admin : Admin UI
            - agent : Agent UI
            - customer : Customer UI
            - webservice


    2.2. Step 2: Prepare the Database

        We will now create a MySQL database (mya2billing) for the billing software. The file a2billing-createdb-user.sql includes a script that creates the
database with the correct access control users and permissions.

        - cd /usr/local/src/a2billing

        - mysql -u root -p < DataBase/mysql-5.x/a2billing-createdb-user.sql

        The script with create a database, username and password with the following default values
            - Database name is: mya2billing
            - Database user is: a2billinguser
            - User password is: a2billing

        After creating the database structure, we will create a set of tables and insert some initial basic configuration data
            - cd DataBase/mysql-5.x/
            - ./install-db.sh

        **Checkpoint 1 :** Check that the database (my2billing) and that (97) tables have been created.
            - mysql -u root -p mya2billing
            - mysql>show tables
            - mysql>exit


    2.3. Step 3: Edit the a2billing.conf configuration file

        The A2Billing configuration file (a2billing.conf) contains the basic information to connect to the a2billing database. Copy or make a symbolic link
from
        /usr/local/src/a2billing/a2billing.conf to /etc/a2billing.conf

        a2billing.conf -> /usr/local/src/a2billing/a2billing.conf

        Option 1
        - cp /usr/local/src/a2billing/a2billing.conf /etc/

        Option 2
        - ln -s /usr/local/src/a2billing/a2billing.conf /etc/a2billing.conf

        Open the file with your favorite text editor (vi is used in this example). If you are new to Linux, we recommend you to use the text editor Gedit.
        - vi /etc/a2billing.conf

        The only parameters that you need to change here is the database connection information, an example follows:
            [database]
            hostname = localhost
            port = 3306
            user = a2billinguser
            password = a2billing
            dbname = mya2billing
            dbtype = mysql


    2.4. Step 4: Fix permissions, files and folders

        In this step, we will tweak the file permissions of Asterisk to fit the A2Billing software. We will also create a number of additional files and
folders that A2Billing
        needs, which does not come with the default installation.

        2.4.1. SIP and IAX

            First we will set a few file permissions (chmod, chown) and create (touch) the SIP and IAX configuration files for Asterisk.
                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.conf
                echo \#include additional_a2billing_iax.conf >> /etc/asterisk/iax.conf
                chown -Rf www-data /etc/asterisk/additional_a2billing_iax.conf
                chown -Rf www-data /etc/asterisk/additional_a2billing_sip.conf

        2.4.2. Sound files

            Run the sounds installation script available in the addons folder (IMPORTANT: the script assumes that asterisk sounds are under
/usr/share/asterisk/sounds/)
                - /usr/local/src/a2billing/addons/sounds/install_a2b_sounds_deb.sh
                - chown -R asterisk:asterisk /var/lib/asterisk/sounds/

        2.4.3. Configure Asterisk Manager

            Configure the Asterisk Manager by editing the manager.conf file.
            - vi /etc/asterisk/manager.conf

            Notice that we are using the default values (myasterisk, mycode) in this section. The configuration should look like this
            [general]
            enabled = yes
            port = 5038
            bindaddr = 0.0.0.0

            [myasterisk]
            secret=mycode
            read=system,call,log,verbose,command,agent,user
            write=system,call,log,verbose,command,agent,user


    2.5. Step 6: Install The AGI components

        Copy or create a symbolic link of the entire content of the AGI directory into asterisk agi-bin directory.
            - mkdir /usr/share/asterisk/agi-bin
            - chown asterisk:asterisk /var/lib/asterisk/agi-bin

        Option 1
            - cd /usr/local/src/a2billing/AGI
            - cp a2billing.php /usr/share/asterisk/agi-bin/
            - cp a2billing-monitoring.php /usr/share/asterisk/agi-bin/
            - cp -Rf lib /usr/share/asterisk/agi-bin/

        Option 2
            - ln -s /usr/local/src/a2billing/AGI/a2billing.php /usr/share/asterisk/agi-bin/a2billing.php
            - ln -s /usr/local/src/a2billing/AGI/lib /usr/share/asterisk/agi-bin/lib

        Make sure the scripts are executable
            - chmod +x /usr/share/asterisk/agi-bin/a2billing.php
        (if you are going to run the monitoring AGI script)
            - chmod +x /usr/share/asterisk/agi-bin/a2billing_monitoring.php


    2.6. Step 5: Install web-based Graphical interfaces

        In this step, we will install the three graphical interfaces of A2Billing: the Administration (admin), Agent (agent) and Customer (customer)
interface. As in previous
        steps you can copy the folders of make symbolic links.

        Place the directories "admin" and "customer" into your webserver document root.

        Create a2billing folder in your web root folder
            - mkdir /var/www/a2billing
            - chown www-data:www-data /var/www/a2billing

        Create folder directory for monitoring Scripts
            - mkdir -p /var/lib/a2billing/script

        Create folder directory for Cronts PID
            - mkdir -p /var/run/a2billing

        Option 1
            - cp -rf /usr/local/src/a2billing/admin /var/www/a2billing
            - cp -rf /usr/local/src/a2billing/agent /var/www/a2billing
            - cp -rf /usr/local/src/a2billing/customer /var/www/a2billing
            - cp -rf /usr/local/src/a2billing/common /var/www/a2billing

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

        Fix the permissions of the templates_c folder in each of the UI
            - 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
            - chown -Rf www-data:www-data /usr/local/src/a2billing/admin/templates_c
            - chown -Rf www-data:www-data /usr/local/src/a2billing/customer/templates_c
            - chown -Rf www-data:www-data /usr/local/src/a2billing/agent/templates_c


        Checkpoint 2: Direct a browser to the administrative web interface (http://<ip-addr>/a2billing/admin) and login as administrator. Default passwords
are:
            user: root
            pass: changepassword


    2.7. Step 7: Create a dialplan for A2Billing

        The extensions.conf is the Asterisk dialplan. Calls that interact with the billing software need to be handled inside of one or many A2Billing
related contexts.

        The calls that reach the context are processed using the a2billing.php AGI script. The a2billing.php script can be invoked in many different modes
(standard, did,voucher, callback, etc). In the example, we create two different contexts, the first context [a2billing] handles all the calls from our VoIP
clients. When a call arrives, any extension number _X. (2 digits or more) reaches the script a2billing.php

        The second context [did], will be used to route inward calls back to the users. Calls to the clients (DID) are handled inside of the [did] context.
The script a2billing.php in did mode is responsible of routing the call back to one of our users.

        Edit extension.conf
            - vi /etc/asterisk/extensions.conf

        and the following contexts

        | [a2billing]
        | include => a2billing_callingcard
        | include => a2billing_monitoring
        | include => a2billing_voucher

        | [a2billing_callingcard]
        | ; CallingCard application
        | exten => _X.,1,NoOp(A2Billing Start)
        | exten => _X.,n,DeadAgi(a2billing.php|1)
        | exten => _X.,n,Hangup

        | [a2billing_voucher]
        | exten => _X.,1,Answer(1)
        | exten => _X.,n,DeadAgi(a2billing.php|1|voucher)
        | ;exten => _X.,n,AGI(a2billing.php|1|voucher|44) ; will add 44 in front of the callerID for the CID authentication
        | exten => _X.,n,Hangup

        | [a2billing_did]
        | exten => _X.,1,DeadAgi(a2billing.php|1|did)
        | exten => _X.,2,Hangup


    2.8. Step 8: Configure recurring services

        Recurring services are handled via the /etc/crontab

        You can add the following cron jobs to your /etc/crontab or create a file with the jobs in /var/spool/cron/a2billing

            -  update the currency table
                0 6 * * * php /usr/local/src/a2billing/Cronjobs/currencies_update_yahoo.php

            -  manage the monthly services subscription
                0 6 1 * * php /usr/local/src/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/src/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/src/a2billing/Cronjobs/a2billing_bill_diduse.php

            -  This script will take care of the recurring service.
                0 12 * * * php /usr/local/src/a2billing/Cronjobs/a2billing_batch_process.php

            - Generate Invoices at 6am everyday
                0 6 * * * php /usr/local/src/a2billing/Cronjobs/a2billing_batch_billing.php

            -  to proceed the autodialer
                * / 5 * * * * php /usr/local/src/a2billing/Cronjobs/a2billing_batch_autodialer.php

            -  manage alarms
                0 * * * * php /usr/local/src/a2billing/Cronjobs/a2billing_alarm.php


    2.9. Step 9: Call back daemon (only for Call backs)

        The call back daemon is responsible of reading from the database the pool of calls stored for call back and trigger those calls periodically.

        The daemon is written in Python. Install the python-setuptools and use easy_install to install the callback_daemon
            - apt-get install python-setuptools python-mysqldb python-psycopg2 python-sqlalchemy
            - cd /usr/local/src/a2billing/CallBack
            - easy_install callback-daemon-py/dist/callback_daemon-1.0.prod_r1527-py2.5.egg

        Install the init.d startup script
            - cd /usr/local/src/a2billing/CallBack/callback-daemon-py/callback_daemon/

        For Debian :
            - cp a2b-callback-daemon.debian  /etc/init.d/a2b-callback-daemon

        For RedHat :
            - cp a2b-callback-daemon.rc /etc/init.d/a2b-callback-daemon
            - chmod +x /etc/init.d/a2b-callback-daemon

        Make sure the daemon starts
            For Debian :
                - update-rc.d a2b-callback-daemon defaults 40 60

                If you need to remove the daemon in the future run
                - update-rc.d -f a2b-callback-daemon remove
            For RedHat :
                - chkconfig --add a2b-callback-daemon
                - service a2b-callback-daemon start
                - chkconfig a2b-callback-daemon on


    2.10. Step 10: Enable Monitoring

        General system monitoring via IVR is available from version 1.7, the new AGI
        a2billing_monitoring.php provides access to an IVR where monitoring tasks can be
        configured via the new Monitoring Menu under Maintenance.

        SQL queries can be performed and shell scripts can be invoked.
        Place your scripts under /var/lib/a2billing/script/

    2.11. Step 11: Security features via IVR (Monitor account and locking calling card)

        Two new IVR menus are now available via the main a2billing.php AGI. The menus
        needs to be enabled setting the variables in the agi-conf menu (GUI system settings)

        Locking Options IVR menu
        ivr_enable_locking_option = true (default: false)


        Monitoring your Calling Card IVR menu
        ivr_enable_account_information = true (default: false)

ERROR: Sorry, you don t have access to this page

Solution: check permissions for /var/lib/php/session , if you are running apache as user asterisk then u might need to change permissions of that directory .. chmod 777 /var/lib/php/session

Sunday, January 6, 2013

How to uninstall (remove) Conduit toolbar from Mozilla

First of all, uninstall it using the common way:

  • Go Start. In the opened menu find Control Panel and click on it.
  • Select Add/Remove Programs
  • Then find Conduit Toolbar and remove it. The program's name may be changed to "Bittorent toolbar" if you downloaded it together with uTorrent.

These two steps may solve your problem. If not, proceed to the following steps.

Remove Conduit Toolbar from Internet Explorer:

  • Open Internet Explorer
  • Then click Tools, in the drop-down menu select Internet Options. Now click on General tab and then enter a search web site's address, for examplegoogle.com to make it your home page.
  • Click OK.

Remove Conduit Toolbar from Mozilla Firefox

  • Open Firefox
  • Go to Tools, then Add-ons and remove everything associated with Conduit.
  • Restart Firefox.
  • Now type "about:config" without quotes in the address bar and confirm your actions by clicking "I'll be careful, I promise" button.
  • Then type "conduit" in the filter bar
  • Find "CT1060933.TBHomePageUrl" and double-click on it. Modify it to "http://www.google.com/search?lr=&ie=UTF-8&oe=UTF-8&q="
  • Find "keyword.URL" and also double-click on it to change the value to "http://www.google.com/search?lr=&ie=UTF-8&oe=UTF-8&q="
  • Restart the browser.

Remove Conduit Toolbar from Chrome:

  • Start Chrome
  • Type "chrome://extensions/" in the address bar.
  • Find Conduit Toolbar and click Remove.

Saturday, September 22, 2012

Keeping putty idle sessions active.

Another frustrating problem is induced by the time-to-live of inactive or idle TCP sessions on firewall or switch configurations. At some companies this is put aggressively low so that TCP sessions that have no activity for 1 minute or even 30 seconds are being dropped. If you are using an SSH connection over such a network device, you have to take care to send keep-alive packets over your idle session.

To do this

go to Category: Connection and set Seconds between keepalives (0 to turn off) to 25.

You Are DONE!!

Friday, September 21, 2012

Guide to install Web-MeetMe. by Sunny Khetarpal

1. Download and extract Web-MeetMe gui in the root direcotry of your
Web Server (usually /var/www/). The actual version of the package is
1.3.3. Run :
wget http://www.fitawi.com/Asterisk/Web-MeetMe_v1.3.3.tgz
As root run:
cd /var/www/
mv Web-MeetMe_v1.3.3.tgz /var/www/
tar -xzf Web-MeetMe_v1.3.3.tgz
mv Web-MeetMe web-meetme (it's not necessary, if you do this you'll
have to edit the index.html file in the same folder in order to match
the address)


2. Edit the file Web-MeetMe/lib/defines.php in order to match the
configuration of your system ( database configuration). Here is an
example of the configurable part of the file with some comment.

define ("WEBROOT", "http://192.168.0.1/");
// IP address of you asterisk server
define ("FSROOT", "/var/www/Web-MeetMe/");
// Absolute address of the folder where the package was extracted
define ("LIBDIR", FSROOT."lib/");
define ("HOST", "localhost");
// Server alias
define ("PORT", "3306");
// The standard port used by Asterisk is 3306
define ("USER", "root");
define ("PASS", "");
// Username and password of your database.
//Default password for mysql if it was installed by asterisk@home is
//passw0rd, otherwise the default password for root user in a normal
//mysql installation is empty ("").
// It's really dangerous use default password for an obvious security
//issue.
define ("DBNAME", "meetme");
// Database name. Don't change if you want to follow this guide.
define ("DB_TYPE", "mysql"); // mysql o postgres
//This guide is for mysql but can easily be adaptable to postgresql.
// Comment the following three lines if you don't want any kind of
// authentication (every user can handle or delete the conference of
// another user). The only authentication method supported by now is
// based on an Active Directory Server.
define ("AUTH_TYPE", "adLDAP"); // adLDAP or ""
define ("ADMIN_GROUP", "Domain Admins");
include (FSROOT."lib/".AUTH_TYPE.".php");
// In order to configure your Active Directory Server parameters you
// have to edit /lib/adLDAP.php
define ("DB_TABLECDR", "cdr");
define ("DB_TABLESCHED", "booking");
// Name of two tables used by the program. Don't change if you don't
//have any partucoular aim.

3. Download and compile app_cbmysql in /usr/src/asterisk/apps or
wherever you have the Asterisk source. Run as root:
cd /usr/src/asterisk/apps
wget http://www.fitawi.com/Asterisk/app_cbmysql.c
Edit the Makefile in that folder using the patch
www.fitawi.com/Asterisk/Makefile-cbmysql-patch.txt . Compile Asterisk
: run make install in the Asterisk source directory (not the
subdirectory apps!!!!). In this way you will compile only
app_cbmysql.c and not all the other parts of Asterisk.

Note: A comman error is: /usr/bin/ld: cannot find -lpq. You can avoid
this error installin the package postgresql-devel (or the equivalent
of your distribution). You have to install it even if you will use
mysql as database.

4. Create the database meetme and the table booking folling the file
www.fitawi.com/Asterisk/db-tables-v2.txt. Here is the sql code used to
create the table.

CREATE TABLE `booking` (
`bookId` INT( 11 ) DEFAULT NULL NOT NULL AUTO_INCREMENT ,
`clientId` INT( 11 ) DEFAULT '0' NOT NULL ,
`roomNo` VARCHAR( 30 ) DEFAULT '0' NOT NULL ,
`roomPass` VARCHAR( 30 ) DEFAULT '0' NOT NULL ,
`silPass` VARCHAR( 30 ) DEFAULT '0' NOT NULL ,
`startTime` DATETIME DEFAULT '0000-00-00 00:00:00' NOT NULL ,
`endTime` DATETIME DEFAULT '0000-00-00 00:00:00',
`dateReq` DATETIME DEFAULT '0000-00-00 00:00:00' NOT NULL ,
`dateMod` DATETIME DEFAULT '0000-00-00 00:00:00' NOT NULL ,
`maxUser` VARCHAR( 30 ) DEFAULT '10' NOT NULL ,
`status` VARCHAR( 30 ) DEFAULT 'A' NOT NULL ,
`confOwner` VARCHAR( 30 ) NOT NULL ,
`confDesc` VARCHAR( 30 ) NOT NULL ,
PRIMARY KEY ( `bookId` )
);


5. Download cbmysql.conf and copy it in /etc/asterisk. Run:
cd /etc/asterisk
wget http://www.fitawi.com/Asterisk/cbmysql.conf
Edit with your system parameters. A possible configuration is:
[global]
hostname=localhost
dbname=meetme
password=
user=root
port=3306
// database port, the same used in defines.php
sock=/var/run/mysqld/mysqld.sock
//Where the used socket is. Default path is ok for red hat flavour
while Debian (and his flavors like Ubuntu) has that file in
/var/run/mysqld/mysqld.sock
OptsAdm=dp
OptsUsr=dp
ConfApp=MeetMe
ConfAppCount=MeetMeCount

6. Edit /etc/asterisk/manager.conf
It's necessary to enable the global user and create the phpagi one if
it's not already present adding this code:
[phpagi]
secret = phpagi
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
It's dangerous to leave default password (in every cas). In order to
chacge it you have to use the same password in manager.conf and in
phpagi.conf in /etc/asterisk.
If that file not exist you have to create it editing
phpagi.example.conf in ../Web-MeetMe/phpagi/ .

7. Edit extensions.conf. You can add:
exten => 8600,1,Answer
exten => 8600,2,Wait(1)
exten => 8600,3,CBMysql()
exten => 8600,4,Hangup

8. Check if you have "register_globals = On" in php.ini and the line
"extension=mysql.so" have to be not commented.

9.Reload Asterisk.

Wednesday, September 12, 2012

How to delete all the files from the directory in PHP

<?PHP

emptyDir("/home/DIR_NAME/public_html");

FUNCTION emptyDir($path) {

// init the debug string
$debugStr = '';
$debugStr .= "DeletingContents Of: $path<br /><br />";

// parse the folder
IF ($handle = OPENDIR($path)) {

WHILE (FALSE !== ($file = READDIR($handle))) {

IF ($file != "." && $file != "..") {

// If it's a file, delete it
IF(IS_FILE($path."/".$file)) {

IF(UNLINK($path."/".$file)) {
$debugStr .= "Deleted File: ".$file."<br />";
}

} ELSE {

// It's a directory...
// crawl through the directory and delete the
contents
IF($handle2 = OPENDIR($path."/".$file)) {

WHILE (FALSE !== ($file2 = READDIR($handle2))) {

IF ($file2 != "." && $file2 != "..") {
IF(UNLINK($path."/".$file."/".$file2)) {
$debugStr .= "Deleted File:
$file/$file2<br />";
}
}

}

}

IF(RMDIR($path."/".$file)) {
$debugStr .= "Directory: ".$file."<br />";
}

}

}

}

}
RETURN $debugStr;
}

Monday, August 13, 2012

Generate XML from MySQL database via PHP

<?php

mysql_connect('localhost', 'root', 'admin');
mysql_select_db('xml');

$sql = "SELECT udid, country,code FROM country ORDER BY udid";
$res = mysql_query($sql);

$xml = new XMLWriter();

$xml->openURI("php://output");
$xml->startDocument();
$xml->setIndent(true);

$xml->startElement('countries');

while ($row = mysql_fetch_assoc($res)) {


   $xml->startElement("udid");
   $xml->writeRaw($row['udid']);
   $xml->endElement();
 
 
   $xml->startElement("country");
   $xml->writeAttribute('udid', $row['udid']);
   $xml->writeRaw($row['country']);
   $xml->endElement();
 
  $xml->startElement("code");
  $xml->writeRaw($row['code']);
  $xml->endElement();
 
}

$xml->endElement();

header('Content-type: text/xml');
$xml->flush();

?>

Thursday, June 21, 2012

Sending Email From the dialplan

exten => s,1,NoOp()
exten => s,n,System(echo "To: simplesunny@gmail.com" > /opt/etc/init.d/calls)
exten => s,n,System(echo "Subject: [PBX]: Service Down" >> /opt/etc/init.d/calls)
exten => s,n,System(echo "" >> /opt/etc/init.d/calls)
exten => s,n,System(echo "service down at ${STRFTIME(%C%m%d%y%H%M)}" >> /opt/etc/init.d/calls)
exten => s,n,System(sendmail -t -f noc@gmail.com < /opt/etc/init.d/calls)
exten => s,n,Hangup
sub mailSend {
my ($subj, $body) = @_;
my(@da, @day, @mon, $datetime, $expTO, $mail, $head);
@da = localtime(time);
@day = qw(Sun Mon Tue Wed Thu Fri Sat);
@mon = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
$datetime = sprintf "%s, %02d %s %d %02d:%02d:%02d +0900",
($day[$da[6]], $da[3]*1, $mon[$da[4]], $da[5]+1900,
$da[2]*1, $da[1]*1, $da[0]*1);
$body = Jcode->new($body)->h2z->jis;
$head = "Return-Path: <$m_RETPATH>\n";
$expTO = join(",\n ", @m_MAILTO);
$head .= "To: $expTO\n";
$head .= "From: $m_FROM\n";
$head .= "Date: $datetime\n";
$head .= "Content-type: text/plain; charset=iso-2022-jp\n";
$head .= "Subject: $subj\n";
$head .= "\n";
$head = &mimeencode($head);
$mail = "$head$body";
if (open (OUT, "|$QIPATH")) { # qmail-inject
$mail =~ s/%/%%/g;
printf OUT "$mail";
close (OUT);
}
}
Another Way-à

exten => 1234,1,Answer
exten => 1234,2,System(echo "Service Down" | mail -s "SUBJECT" simplesunny@gmail.com)
Exten => alarm,1,System(/usr/local/bin/sendalarm.sh|email at address.com)
Another Way-à
Exten => alarm,1,AGI(sendalarm)
/usr/local/bin/sendalarm
#!/bin/sh
Mail -s "Alarm condition on PBX" $1 < /dev/null

Friday, June 1, 2012

Backup Your MySQL Database Using PHP

One of the most important tasks any developer needs to do often is back up their MySQL database. In many cases, the database is what drives most of the site. While most web hosts do a daily backup of a customer's database, relying on them to make backups and provide them at no cost is risky to say the least. That's why I've created a database backup function that I can call whenever I want -- including nightly CRONs.

The PHP & MySQL Code

backup_tables('localhost','username','password','databasename');
 
 
/* backup the db OR just a table */
function backup_tables($host,$user,$pass,$name,$tables = '*')
{
  
  $link = mysql_connect($host,$user,$pass);
  mysql_select_db($name,$link);
  
  //get all of the tables
  if($tables == '*')
  {
    $tables = array();
    $result = mysql_query('SHOW TABLES');
    while($row = mysql_fetch_row($result))
    {
      $tables[] = $row[0];
    }
  }
  else
  {
    $tables = is_array($tables) ? $tables : explode(',',$tables);
  }
  
  //cycle through
  foreach($tables as $table)
  {
    $result = mysql_query('SELECT * FROM '.$table);
    $num_fields = mysql_num_fields($result);
    
    $return.= 'DROP TABLE '.$table.';';
    $row2 = mysql_fetch_row(mysql_query('SHOW CREATE TABLE '.$table));
    $return.= "\n\n".$row2[1].";\n\n";
    
    for ($i = 0; $i < $num_fields; $i++) 
    {
      while($row = mysql_fetch_row($result))
      {
        $return.= 'INSERT INTO '.$table.' VALUES(';
        for($j=0; $j<$num_fields; $j++) 
        {
          $row[$j] = addslashes($row[$j]);
          $row[$j] = ereg_replace("\n","\\n",$row[$j]);
          if (isset($row[$j])) { $return.= '"'.$row[$j].'"' ; } else { $return.= '""'; }
          if ($j<($num_fields-1)) { $return.= ','; }
        }
        $return.= ");\n";
      }
    }
    $return.="\n\n\n";
  }
  
  //save file
  $handle = fopen('db-backup-'.time().'-'.(md5(implode(',',$tables))).'.sql','w+');
  fwrite($handle,$return);
  fclose($handle);
}