[Asterisk-Users] DISA and AGI: authenticate by caller ID?

Nicolas Gudino nicolas at house.com.ar
Thu Jul 1 11:08:02 MST 2004


Hi Matthew,

Look at the bootom for my recommendation (take note, I did not test it):

On Thu, 2004-07-01 at 14:08, Matthew Simpson wrote:
> I want to have a way to authenticate callers to the extension by Caller
> ID... if their caller ID is in my database and set to active, they can call
> out.  [like a calling card but auth'd by CID instead of PIN].
> 
> Here is my dialplan:
> 
> 1234, 1, agi(ldusers.agi)
> 1234, 2, Hangup
> 
> Here is my code:
> 
> #!/usr/bin/perl
> #
> 
> use Asterisk::AGI;
> use DBI;
> 
> $db = "dbname";
> $host = "hostname";
> $port = "3306";
> $userid = "dbuser";
> $password = "dpasswd";
> $connectionInfo = "DBI:mysql:database=$db;$host:$port";
> $dbh = DBI->connect($connectionInfo,$userid,$password);
> 
> 
> $AGI = new Asterisk::AGI;
> 
> my %input = $AGI->ReadParse();
> 
> $AGI->answer();
> 
> if (my $callerid = $input{'callerid'}) {
> 
>         $AGI->say_digits($callerid);
>         $query = "SELECT active FROM cids WHERE cid=$callerid";            #
> active should be 1 if the caller ID is found and set active
>         $sth = $dbh->prepare($query);
>         $sth->execute();
>         $sth->bind_columns(undef, \$active);
>         $sth->fetch();
> 
>         if($active)
>                 $AGI->exec('DISA','no-password|disa');
                  ^^^^^
Instead of executing the application, try creating a new context in your
dialplan that executes DISA. You can send the call to that context like
this:

 $AGI->set_context("disa");
 $AGI->set_extension("s");
 $AGI->set_priority(1);

> }
> 
> $AGI->hangup();
> 
> exit;

In extension.conf add the disa context like this:

[disa]
exten => s,1,disa,no-password|disa

This way, if an error happens with DISA, it will be displayed at the
asterisk console (it will not be hidden inside AGI).

Good luck,


-- 
Nicolas Gudino <nicolas at house.com.ar>
House Internet S.R.L.




More information about the asterisk-users mailing list