Monday, May 31, 2010

TrixBox Web Authentication

/etc/trixbox/httpdconf/trixbox.conf is the trixbox webauthentication file. its sample is given below you can modify it according to your requirement. it use htaccess method to restrict the contents.


cat  /etc/trixbox/httpdconf/trixbox.conf
#Password protect /var/www/html/admin


AuthType Basic
AuthName "Restricted Area"
AuthUserFile /usr/local/apache/passwd/wwwpasswd
Require user wwwadmin maint

 #Password protect /var/www/html/maint

AuthType Basic
AuthName "Restricted Area"
AuthUserFile /usr/local/apache/passwd/wwwpasswd
Require user maint



AllowOverride All

Wednesday, May 26, 2010

RAM Disk Creation & Mount

What Is RAM Disk? RAM disk is the portion for ram which acts as the hard disk. For that we allocate some portion for ram and then mount it. below are the configurations tested on CentOS 5.2

You can configure and mount RAM Disk using the following procedure.

1. In /etc/grub.conf add the option that is highlited in the below kernel line.

title CentOS (2.6.18-164.el5PAE)
        root (hd0,0)
        kernel /vmlinuz-2.6.18-164.el5PAE ro root=LABEL=/ rhgb quiet ramdisk_size=524288
        initrd /initrd-2.6.18-164.el5PAE.img

2. now edit the /etc/rc.d/rc.local and put the below line
####### RAM DISK #######################
mkfs -t ext3 /dev/ram0 # it will formate the ramdisk
mount -t ext3 /dev/ram0 /var/spool/asterisk/monitor # it will mount ramdisk to mount point /var/spool/asterisk/monitor

Wednesday, May 19, 2010

Asterisk Perl AGI

Below is the sample AGI scrip written in per perl.
In This Script You will learn the following
1. How to write AGI concept.
2. Some Perl Programming.(Variables, Arithmetic Operator, IF/ELSE/ELSIF , comparision operators, Labels etc.
3. How to use mysql queries in AGI using perl.
4. Asterisk Application Used( NoOp, SayDigits, SayNumber, Channel Variables, SayUnixTimeStamp etc)

#!/usr/bin/perl
# MODULE
use Time::Local;
use Asterisk::AGI;
use Mysql;

# CONFIG VARIABLES
$host = "localhost";
$database = "testdb";
$user = "root";
$pw = "JustForFun";

# MYSQL CONNECT
$connect = Mysql->connect($host, $database, $user, $pw);

# SELECT A DATABASE
$connect->selectdb($database);

# create agi instance
$AGI = new Asterisk::AGI;

$AGI->exec("NoOP","\----OnlineInquirySystem----\"");
$AGI->exec("Playback","custom/inquiry-thankyou");
Repeapt1:
$AGI->exec("Read","\option,custom/inquiry-tocheck,1,,,\"");
$option = $AGI->get_variable(option);

if ($option == 1 or $option == 2)
{
    EnterCheque:
    $AGI->exec("Read","cheque,custom/inquiry-pleaseenter,15,,,");
    $cheque = $AGI->get_variable(cheque);
    AfterCheque:
    $AGI->exec("NoOP","**$cheque**");
    if (length($cheque) == 10)
    {
    $AGI->exec("Playback","custom/inquiry-waitforinformation");
    $query="Select evttype_fk, issue_dtt,amount,inst_pk from lpsinst where check_no='$cheque'";
    $execute= $connect->query($query);
    @results=$execute->fetchrow();
    $AGI->exec("NoOP","=====================================");
    $AGI->exec("NoOP","**$results[0]**");
    $AGI->exec("NoOP","=====================================");
    if ($results[0] > 0)
    {
    $AGI->exec("NoOP","**CheckFound**");
    $evttype=$results[0];
    $issuedtt=$results[1];
    $amount=$results[2];
    $inst_pk=$results[3];
    $issueyear=substr $issuedtt,0,4;
    $issuemonth=substr $issuedtt,5,2;
    $issueday=substr $issuedtt,8,2;
    $issuehour=substr $issuedtt,11,2;
    $issueminute=substr $issuedtt,14,2;
    $issuesecond=substr $issuedtt,17,2;
    $AGI->exec("NoOP","$issuedtt");
    $AGI->exec("NoOP","$issueyear-$issuemonth-$issueday-$issuehour:$issueminute:$issuesecond");
    $issueutc=timelocal($issuesecond,$issueminute,$issuehour,$issueday,$issuemonth,$issueyear);
    $AGI->exec("NoOP","$issueutc");
    $bfd=length($amount) - 3;
        $afd= $bfd + 1;
        $dollars=substr $amount,0,$bfd;
        $cents=substr $amount,$afd,2;
    $AGI->exec("NoOP","D-$dollars");
    $AGI->exec("NoOP","C-$cents");
  
        if ($evttype == 3)
        {
        $AGI->exec("Playback","custom/inquiry-chequenumber");
        $AGI->exec("SayDigits","$cheque");
        $AGI->exec("Playback","custom/inquiry-wasissuedon");
        $AGI->exec("SayUnixTime","$issueutc,CET,BdY");
        $AGI->exec("Playback","custom/inquiry-amountof");
        $AGI->exec("SayNumber","$dollars");
        $AGI->exec("Playback","dollars");
        $AGI->exec("SayNumber","$cents");
        $AGI->exec("Playback","cents");
        $AGI->exec("PlayBack","custom/inquiry-nofurtherinfo");
        SecondOption:
                $AGI->exec("Read","\option,custom/inquiry-tocheck-2,1,,,\"");
                $option = $AGI->get_variable(option);
            if ($option == 1 or $option == 2)
                {
                goto Repeapt1;
                } elsif ($option == 3)
                    {
                    goto TalkToSupport;
                    } elsif($option == 4)
                        {
                        goto SecondOption;  
                        } elsif($option == 5)
                                                    {
                            EndCall:
                            $AGI->exec("Playback","custom/inquiry-thankforcalling");
                                                    goto END;
                                                    } else
                                {
                                $AGI->exec("Playback","custom/inquiry-invalidoption");
                                goto SecondOption;
                                }
      
      
        } elsif ($evttype == 4)
        {
        $query="select evt_dtt from lpshistory where inst_fk='$inst_pk' and evttype_fk=4";
            $execute= $connect->query($query);
            @results=$execute->fetchrow();
            $evtdtt=$results[0];
        $evtyear=substr $evtdtt,0,4;
            $evtmonth=substr $evtdtt,5,2;
            $evtday=substr $evtdtt,8,2;
            $evthour=substr $evtdtt,11,2;
            $evtminute=substr $evtdtt,14,2;
            $evtsecond=substr $evtdtt,17,2;
            $AGI->exec("NoOP","$issuedtt");
            $AGI->exec("NoOP","$evtsecond-$evtminute-$evthour-$evtday-$evtmonth-$evtyear");
            $evtutc=timelocal($evtsecond,$evtminute,$evthour,$evtday,$evtmonth,$evtyear);
        $AGI->exec("Playback","custom/inquiry-chequenumber");
                $AGI->exec("SayDigits","$cheque");
                $AGI->exec("Playback","custom/inquiry-wasissuedon");
                $AGI->exec("SayUnixTime","$issueutc,CET,BdY");
                $AGI->exec("Playback","custom/inquiry-amountof");
                $AGI->exec("SayNumber","$dollars");
                $AGI->exec("Playback","dollars");
                $AGI->exec("SayNumber","$cents");
                $AGI->exec("Playback","cents");
        $AGI->exec("Playback","custom/inquiry-wasvoidedon");
        $AGI->exec("SayUnixTime","$evtutc,CET,BdY");
        goto SecondOption;
        } elsif ($evttype == 5)
                {
                $query="select evt_dtt from lpshistory where inst_fk='$inst_pk' and evttype_fk=5";
                $execute= $connect->query($query);
                @results=$execute->fetchrow();
                $evtdtt=$results[0];
                $evtyear=substr $evtdtt,0,4;
                $evtmonth=substr $evtdtt,5,2;
                $evtday=substr $evtdtt,8,2;
                $evthour=substr $evtdtt,11,2;
                $evtminute=substr $evtdtt,14,2;
                $evtsecond=substr $evtdtt,17,2;
                $AGI->exec("NoOP","$issuedtt");
                $AGI->exec("NoOP","$evtsecond-$evtminute-$evthour-$evtday-$evtmonth-$evtyear");
                $evtutc=timelocal($evtsecond,$evtminute,$evthour,$evtday,$evtmonth,$evtyear);
                $AGI->exec("Playback","custom/inquiry-chequenumber");
                $AGI->exec("SayDigits","$cheque");
                $AGI->exec("Playback","custom/inquiry-wasissuedon");
                $AGI->exec("SayUnixTime","$issueutc,CET,BdY");
                $AGI->exec("Playback","custom/inquiry-amountof");
                $AGI->exec("SayNumber","$dollars");
                $AGI->exec("Playback","dollars");
                $AGI->exec("SayNumber","$cents");
                $AGI->exec("Playback","cents");
                $AGI->exec("Playback","custom/inquiry-wasredeemedon");
                $AGI->exec("SayUnixTime","$evtutc,CET,BdY");
        goto SecondOption;
                } elsif ($evttype == 6)
        {
        $query="select evt_dtt from lpshistory where inst_fk='$inst_pk' and evttype_fk=6";
                $execute= $connect->query($query);
                @results=$execute->fetchrow();
                $evtdtt=$results[0];
                $evtyear=substr $evtdtt,0,4;
                $evtmonth=substr $evtdtt,5,2;
                $evtday=substr $evtdtt,8,2;
                $evthour=substr $evtdtt,11,2;
                $evtminute=substr $evtdtt,14,2;
                $evtsecond=substr $evtdtt,17,2;
                $AGI->exec("NoOP","$issuedtt");
                $AGI->exec("NoOP","$evtsecond-$evtminute-$evthour-$evtday-$evtmonth-$evtyear");
                $evtutc=timelocal($evtsecond,$evtminute,$evthour,$evtday,$evtmonth,$evtyear);
                $AGI->exec("Playback","custom/inquiry-chequenumber");
                $AGI->exec("SayDigits","$cheque");
                $AGI->exec("Playback","custom/inquiry-wasissuedon");
                $AGI->exec("SayUnixTime","$issueutc,CET,BdY");
                $AGI->exec("Playback","custom/inquiry-amountof");
                $AGI->exec("SayNumber","$dollars");
                $AGI->exec("Playback","dollars");
                $AGI->exec("SayNumber","$cents");
                $AGI->exec("Playback","cents");
                $AGI->exec("Playback","custom/inquiry-wasstopedon");
                $AGI->exec("SayUnixTime","$evtutc,CET,BdY");
        goto SecondOption;
                } elsif ($evttype == 7)
                {
        $query="select evt_dtt from lpshistory where inst_fk='$inst_pk' and evttype_fk=7";
                $execute= $connect->query($query);
                @results=$execute->fetchrow();
                $evtdtt=$results[0];
                $evtyear=substr $evtdtt,0,4;
                $evtmonth=substr $evtdtt,5,2;
                $evtday=substr $evtdtt,8,2;
                $evthour=substr $evtdtt,11,2;
                $evtminute=substr $evtdtt,14,2;
                $evtsecond=substr $evtdtt,17,2;
                $AGI->exec("NoOP","$issuedtt");
                $AGI->exec("NoOP","$evtsecond-$evtminute-$evthour-$evtday-$evtmonth-$evtyear");
                $evtutc=timelocal($evtsecond,$evtminute,$evthour,$evtday,$evtmonth,$evtyear);
                $AGI->exec("Playback","custom/inquiry-chequenumber");
                $AGI->exec("SayDigits","$cheque");
                $AGI->exec("Playback","custom/inquiry-wasissuedon");
                $AGI->exec("SayUnixTime","$issueutc,CET,BdY");
                $AGI->exec("Playback","custom/inquiry-amountof");
                $AGI->exec("SayNumber","$dollars");
                $AGI->exec("Playback","dollars");
                $AGI->exec("SayNumber","$cents");
                $AGI->exec("Playback","cents");
                $AGI->exec("Playback","custom/inquiry-wasstopedandvoidedon");
                $AGI->exec("SayUnixTime","$evtutc,CET,BdY");
        goto SecondOption;
                } elsif ($evttype == 11 or $evttype == 12)
                {
        $query="select evt_dtt from lpshistory where inst_fk='$inst_pk' and evttype_fk=11 or evttype_fk=12";
                $execute= $connect->query($query);
                @results=$execute->fetchrow();
                $evtdtt=$results[0];
                $evtyear=substr $evtdtt,0,4;
                $evtmonth=substr $evtdtt,5,2;
                $evtday=substr $evtdtt,8,2;
                $evthour=substr $evtdtt,11,2;
                $evtminute=substr $evtdtt,14,2;
                $evtsecond=substr $evtdtt,17,2;
                $AGI->exec("NoOP","$issuedtt");
                $AGI->exec("NoOP","$evtsecond-$evtminute-$evthour-$evtday-$evtmonth-$evtyear");
                $evtutc=timelocal($evtsecond,$evtminute,$evthour,$evtday,$evtmonth,$evtyear);
                $AGI->exec("Playback","custom/inquiry-chequenumber");
                $AGI->exec("SayDigits","$cheque");
                $AGI->exec("Playback","custom/inquiry-wasissuedon");
                $AGI->exec("SayUnixTime","$issueutc,CET,BdY");
                $AGI->exec("Playback","custom/inquiry-amountof");
                $AGI->exec("SayNumber","$dollars");
                $AGI->exec("Playback","dollars");
                $AGI->exec("SayNumber","$cents");
                $AGI->exec("Playback","cents");
                $AGI->exec("Playback","custom/inquiry-wasescheatedon");
                $AGI->exec("SayUnixTime","$evtutc,CET,BdY");
        goto SecondOption;
                } else
        {
        $AGI->exec("Playback","custom/inquiry-chequenumber");
        $AGI->exec("SayDigits","$cheque");
        $AGI->exec("NoOP","**$cheque**");
        NoValidStatus:
        $AGI->exec("Read","\option,custom/inquiry-wasnotfoundtry,1,,,\"");
        $option = $AGI->get_variable(option);
        if ($option == 1)
            {
            goto EnterCheque;
            } elsif ($option == 2)
            {
            goto TalkToSupport;
            }  elsif ($option == 3)
                        {
                        goto EndCall;
                        } else
            {
            $AGI->exec("Playback","custom/inquiry-invalidoption");
            goto  NoValidStatus;
            }
      
        }

    } else
            {
        $AGI->exec("NoOP","**====CheckNotFound====**");
        $AGI->exec("Playback","custom/inquiry-chequenumber");
            $AGI->exec("SayDigits","$cheque");
            $AGI->exec("NoOP","**$cheque**");
            RepeatNotFound:
            $AGI->exec("Read","option,custom/inquiry-wasnotfoundtry,1,,,");
            $option = $AGI->get_variable(option);
            if ($option == 1)
            {
                goto EnterCheque;
                } elsif ($option == 2)
                    {
                        goto TalkToSupport;
                        }  elsif ($option == 3)
                            {
                            goto EndCall;
                            } else
                                {
                            $AGI->exec("Playback","custom/inquiry-invalidoption");
                            goto  RepeatNotFound;
                                }

  
        }

    } else
    {
    $AGI->exec("Read","cheque,custom/inquiry-rentercheque,15,,,");
    $cheque = $AGI->get_variable(cheque);
    goto AfterCheque;
    }

} elsif ($option == 3)
    {
    TalkToSupport:
    $AGI->exec("Playback","custom/inquiry-pleasehold");
    goto END;
    } elsif ($option == 4)
        {
        goto Repeapt1;
        } else
            {
            $AGI->exec("Playback","custom/inquiry-invalidoption");
            goto Repeapt1;
            }
      
END: