AGI – exemplo Agi + php consultando em paginas

exemploAGI.php
verbose(“CALLER ID: ” . $agi->request[agi_callerid]);
$callerid = $agi->request[“agi_callerid”];
$agi->verbose(“EXTENSION: ” . $agi->request[agi_extension]);
$extension = $agi->request[“agi_extension”];
$consulta = exec(“php consulta.php $extension”);

$agi->exec(‘Dial’, “SIP/TroncoTeste/$consulta”);

$agi->verbose(“Numero digitado: ” . $consulta);

$agi->hangup();
exit();
?>

consulta.php

00000000000000000000000000000000000000000000000000000000000000000000000

rotina em php para colher informações de ramal.
procure no php.ini na funcao disabled_functions …

Relação dos Ramais Ativos Trixbox laboratório


“; echo $saida1; echo “

“;

//Colhendo informacoes do voip

$comando2 = “asterisk -rx ‘sip show peers’ > /var/www/html/peers.txt”;

$saida2 = shell_exec($comando2);

//ABRE O ARQUIVO TXT

$ponteiro = fopen (“/var/www/html/peers.txt”, “r”);

//LÊ O ARQUIVO ATÉ CHEGAR AO FIM

while (!feof ($ponteiro)) {

//LÊ UMA LINHA DO ARQUIVO

$linha = fgets($ponteiro, 4096);

//IMPRIME NA TELA O RESULTADO

$palavra = ‘/(OK)/';

$frase = $linha;

if (preg_match($palavra, $frase)) {

echo “

$linha

“;

}

}//FECHA WHILE

//FECHA O PONTEIRO DO ARQUIVO

fclose ($ponteiro);

?>

3 comments

  1. Ulisses disse:

    exec(‘NOOP’,”ENTRADA_VIA_GSM”);

    $sql_query = “SELECT * FROM tb_parametros order by codigo desc limit 1″;

    $res=mysql_query($sql_query);

    $linhas=mysql_affected_rows();

    $lista=mysql_fetch_object($res);

    $atendedorGsm=$lista->atendedorGsm;

    $atendedorChave=$lista->atendedorChave;

    $exten=$atendedorGsm;

    $agi->exec(‘NOOP’,”AtendedorGsm:$atendedorGsm”);

    }

    if(strlen($callerid)exec(‘NOOP’,”$A[1]”);

    $porta=explode(“-“,”$A[1]”);

    $agi->exec(‘NOOP’,”$porta[0]”);

    $sql_query = “SELECT * FROM tb_ramais where porta=’$porta[0]'”;

    $res=mysql_query($sql_query);

    $linhas=mysql_affected_rows();

    if ($linhas>0)

    {

    $lista=mysql_fetch_object($res);

    $ramal=$lista->ramal;

    $callerid=$ramal;

    $agi->set_variable(“CALLERID(num)”,$ramal);

    }

    }

    ?>

  2. Ulisses disse:

    #!/usr/bin/perl
    print “Content-type:text/html\n\n”;

    use DBI;

    $username = ”;$password = ”;$database = ”;$hostname = ”;
    $dbh = DBI->connect(“dbi:mysql:database=$database;” .
    “host=$hostname;port=3306″, $username, $password);

    $SQL= “select * from user”;

    $Select = $dbh->prepare($SQL);
    $Select->execute();

    while($Row=$Select->fetchrow_hashref)
    {
    print “$Row->{username}
    $Row->{email}”;
    }

  3. Ulisses disse:

    Asterisk episode v3 Notes:

    Asterisk::AGI
    http://asterisk.gnuinter.net/files/asterisk-perl-0.08.tar.gz

    —————————————————————————————————————-
    #/usr/bin/perl
    #callcheck.pl
    use DBI;
    use Asterisk::AGI;

    $AGI = new Asterisk::AGI;
    my %input = $AGI->ReadParse();
    my $dbh = DBI->connect(‘dbi:mysql:callrouting’,’callrouter’,’callrouter’);
    my $ARGC=$#ARGV + 1;
    if ($ARGC set_variable(‘action’,’unknowncaller’);
    exit -1;
    }
    my $number = $ARGV[0];
    my $sql = “select * from numbers where cdr=\”$number\””;
    my $sth = $dbh->prepare($sql);
    $sth->execute || die “could not Execute Query”;
    my $do=””;
    while (@row = $sth->fetchrow_array) {
    $do = @row[1];
    }

    if ($do ne “”) {
    $AGI->set_variable(‘action’,’$do’);
    } else {
    $AGI->set_variable(‘action’,’unknowncaller’);
    }
    —————————————————————————————————————–
    #/usr/bin/perl
    #passwordcheck.pl
    use DBI;
    use Asterisk::AGI;

    $AGI = new Asterisk::AGI;
    my %input = $AGI->ReadParse();
    my $dbh = DBI->connect(‘dbi:mysql:callrouting’,’callrouter’,’callrouter’);
    my $ARGC=$#ARGV + 1;
    if ($ARGC set_variable(‘allowed’,’false’);
    exit -1;
    }
    my $pass = $ARGV[0];
    my $sql = “select count(*) from passwords where password=\”$pass\””;
    my $sth = $dbh->prepare($sql);
    $sth->execute || die “could not Execute Query”;
    my $count=””;
    while (@row = $sth->fetchrow_array) {
    $count = @row[0];
    }
    if ($count gt 0) {
    $AGI->set_variable(‘allowed’,’true’);
    } else {
    $AGI->set_variable(‘allowed’,’false’);
    }

    —————————————————————————————————————-

    [local]
    include => callroutingmenu

    [callroutingmenu]
    exten => 500,1,Answer()
    exten => 500,2,wait(2)
    exten => 500,3,agi,/var/lib/asterisk/agi-bin/callcheck.pl|${CALLERIDNUM}
    exten => 500,4,gotoif($[“${action}” = “unknowncaller”]?1000:5)
    exten => 500,5,gotoif($[“${action}” = “hangup”]?2000:6)
    exten => 500,6,gotoif($[“${action}” = “allow”]?3000:7)
    exten => 500,7,gotoif($[“${action}” = “playmenu”]?4000:8)
    exten => 500,8,playback(goodbye)
    exten => 500,9,hangup

    exten => 500,1000,playback(tt-weasels)
    exten => 500,1000,hangup

    exten => 500,2000,playback(goodbye)
    exten => 500,2001,hangup

    exten => 500,3000,macro(dialphones)

    [macro-menu]
    exten => s,1,background(please-enter-your)
    exten => s,2,read(vm-password,pass)
    exten => s,3,agi,/var/lib/asterisk/agi-bin/passwordcheck.pl|${pass}
    exten => s,4,gotoif($[“${allowed}” = “false”]?4000:5)
    exten => s,5,playback(press-1)
    exten => s,6,playback(for)
    exten => s,6,playback(your)
    exten => s,7,playback(voice-mail-system)
    exten => s,8,wait(1)
    exten => s,9,playback(press-2)
    exten => s,10,playback(to) ;to does not exsist but it would make it complete
    exten => s,11,read(enter-ext-of-person,menuchoice)
    exten => s,12,gotoif($[“${menuchoice}” = “1”]?6000:13)
    exten => s,13,gotoif($[“${menuchoice}” = “2”]?7000:14)
    exten => s,14,gotoif($[“${menuchoice}” = “3”]?8000:1)

    exten => s,8000,System(/sbin/reboot)

    exten => s,7000,read(if-u-know-ext-dial,ext)
    exten => s,7001,gotoif($[“${ext}” = “”]?7000:7002)
    exten => s,7002,dial(SIP/${ext})
    exten => s,7003,hangup

    exten => s,6000,voicemailmain()
    exten => s,6001,hangup

    exten => s,4000,playback(invalid)
    exten => s,4001,playback(vm-password)
    exten => s,4002,Goto(1)

    [macro-dialphones]
    exten => s,1,dial(SIP/100)
    ———————————————————————————————

    Database DUMP
    ———————————————————————————————
    callrouting/numbers
    — MySQL dump 10.9

    — Host: localhost Database: callrouting
    — ——————————————————
    — Server version 4.1.14

    /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
    /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
    /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
    /*!40101 SET NAMES utf8 */;
    /*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
    /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
    /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE=’NO_AUTO_VALUE_ON_ZERO’ */;
    /*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;


    — Table structure for table `numbers`

    DROP TABLE IF EXISTS `numbers`;
    CREATE TABLE `numbers` (
    `id` int(11) NOT NULL auto_increment,
    `cdr` varchar(10) default NULL,
    `action` varchar(255) default NULL,
    PRIMARY KEY (`id`)
    ) ENGINE=MyISAM DEFAULT CHARSET=latin1;


    — Dumping data for table `numbers`

    /*!40000 ALTER TABLE `numbers` DISABLE KEYS */;
    LOCK TABLES `numbers` WRITE;
    UNLOCK TABLES;
    /*!40000 ALTER TABLE `numbers` ENABLE KEYS */;

    /*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
    /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
    /*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
    /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
    /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
    /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
    /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;

Deixe uma resposta