Soporte & Consultoria

Soporte Remoto y Consultoria skype : ambiorixg12.
Nota no se brinda ningun tipo de consulta o soporte fuera del blog de forma gratuita

sábado, 28 de noviembre de 2015

PHP Asterisk AMI event listener

// include this file to the ami-listener.php setting.php

<?php
$host="127.0.0.1";
$username="admin";
$secret="1234";
$context="internal";

?>


ami-listener.php

<?php
require("setting.php");



$socket = fsockopen($host,"5038", $errno, $errstr,10);
      if (!$socket){
        echo "$errstr ($errno)\n";
        }else{
            fputs($socket, "Action: Login\r\n");
            fputs($socket, "UserName: $username\r\n");
            fputs($socket, "Secret: $secret\r\n\r\n");
               fputs($socket, "Action: WaitEvent\r\n");
            fputs($socket, "Action: Logoff\r\n\r\n");

   while(!feof($socket)){

 $result=fgets($socket);
echo "$result\n";


}
}
?>


run this command on the linux   console

ami-listener.php

Asterisk AMI GET VAR example

http://165.181.118.232:8088/rawman?action=login&username=admin&secret=123

http://165.181.118.232:8088/rawman?action=Getvar&variable=DEVICE_STATE(sip/109)

http://165.181.118.232:8088/rawman?action=Getvar&channel=SIP/100-00000040&variable=BRIDGEPEER


http://65.181.118.232:8088/rawman?action=ExtensionState&exten=100&context=internal

jueves, 26 de noviembre de 2015

USING asterisk AGI and PHP

/* first script use to catch the  key pressed */

#!/usr/bin/php -q

<?php

echo "ANSWER";

echo "\n";

echo  "EXEC saydigits $argv[1]";

echo "\n";

echo "EXEC  read   d,demo-thanks,1";

echo "\n";

?>

/*  second script play.php*/

#!/usr/bin/php -q

<?php
if($argv[1]==4){
echo  "EXEC saydigits $argv[1]";
}
if($argv[1]==5){
echo  "EXEC saydigits $argv[1]";
}


else   {
echo "EXEC  playback im-sorry";


}
?>

[agi-script]
exten=>123,1,Noop()
same=>n,AGI(/root/agi.php,${CALLERID(num)})
same=>n,Noop(value of ${d})
same=>n,AGI(/root/play.php,${d})


NOTE PATH for PHP is different  to /usr/bin/php  on centos  use the which command to get the correct path




miércoles, 25 de noviembre de 2015

Asterisk AGI and Bash

#!/bin/bash

# Consume all variables sent by Asterisk
while read VAR && [ -n ${VAR} ] ; do : ; done

# Answer the call.
echo "ANSWER"
read RESPONSE
r=$(hostname  -i)
sql=$(mysql -Dasterisk -uroot -p1234 -se "SELECT src FROM cdr limit 0,1")
space=$(df -h  | awk '{print $5}'  | awk 'NR==2')
# Say the letters of "Hello World"
#echo "SAY ALPHA "Hello World" """

#echo "EXEC "Dial" "SIP/callcentric/411" """
echo  "EXEC "saydigits" "$1" """
echo "EXEC "read" "d,demo-thanks" """
echo "SET VARIABLE "x"  "$r" "
echo "SET VARIABLE "y"  "$sql" "
echo "SET VARIABLE "dk"  "$space" "

read RESPONSE

exit 0


----------------------------------------
[channel]

exten => 500,1,AGI(/root/hello.sh,${EXTEN})
same=>n,saydigits(${d})
same=>n,sayalpha(${x})
same=>n,saydigits(${y})
same=>n,saynumber(${dk})
same=>n,sayalpha(%)



Ping an IP address


  1. #!/usr/local/bin/php -q
  2. <?php
  3.   require('phpagi.php');
  4.  
  5.   $agi new AGI();
  6.  
  7.   $agi->answer();
  8.  
  9.  
  10.   // Play the "Enter the host you wish to ping, followed by the pound sign" prompt
  11.   // and then play the beep.   
  12.   $agi->stream_file('ping');
  13.   $result $agi->get_data('beep'300020);
  14.   $ip str_replace('*''.'$result['result']);
  15.  
  16.   /* Danger Will Robinson!  This does NOT properly escape the ping command!
  17.    * Someone could subvert your system if you don't fix this! - NO WARRANTY :P */
  18.   $execstr "/bin/ping -c 5 -q -w 9 $ip|grep transmitted";
  19.     
  20.   // be polite.
  21.   $agi->stream_file('thanks''#');
  22.     
  23.   $p popen($execstr'r');
  24.   if($p == FALSE)
  25.   {
  26.     $agi->text2wav("Failed to ping $ip");
  27.     $agi->conlog("Failed to ping $execstr");
  28.   }
  29.   else
  30.   {
  31.     $str '';
  32.     while(!feof($p))
  33.     {
  34.       $r fgets($p1024);
  35.       if(!$rbreak;
  36.       $str .= $r;
  37.     }
  38.  
  39.     // a minor hack.
  40.     $str str_replace('ms''milli-seconds'$str);
  41.     
  42.     // have festival read back the ping results.
  43.     $agi->text2wav("$ip - $str");
  44.   }
  45.  
  46.   $agi->hangup();
  47. ?>

http://phpagi.sourceforge.net/phpagi22/api-docs/

martes, 24 de noviembre de 2015

Web call queue


Asterisk part

nano /etc/asterisk/extensions_custom.conf

First call dial to the    freepbx inbound route pointing to  a queue

[webcall]
exten=>_x.,1,Set(CALLERID(all)=WEB LEAD<${dest}>))
same=>n,goto(from-trunk,${ext},1)

second call conect to the  customer phone

[from-web]
exten=>_x.,1,Set(CALLERID(all)=LEAD<${cid}>))
same=>n,dial(SIP/5417878877/${dest})


[state]
exten=>_x.,1,Wait(2)
exten=>_x.,n,Playback(demo-thanks)
exten=>_x.,n,ExecIf($["${DEVICE_STATE(SIP/${EXTEN})}"= "INUSE"]?Dial(SIP/${EXTEN}))
same=>n,goto(1)










PHP part

 nano /var/www/html/webcall/call.php






<?php
/*parameters */

$param= array("host"=>"localhost","port"=>5038,"trunk"=>"tw0","timeout"=>45,"message"=>"demo-thanks");

/*form variables */

$dest=$_GET['dest'];
$callerid=$_GET['cid'];
$ext=$_GET['ext'];

 $socket = fsockopen($param['host'],$param['port'], $errno, $errstr,$param['timeout']);
 fputs($socket, "Action: Login\r\n");
 fputs($socket, "UserName: admin\r\n");     //
 fputs($socket, "Secret:tf12200003\r\n\r\n");  //
               $wrets=fgets($socket,128);
              echo $wrets;
              fputs($socket, "Action: Originate\r\n" );
              fputs($socket, "Channel: Local/$dest@webcall\r\n" );
              fputs($socket, "Exten: $ext\r\n" );
               fputs($socket, "Context: from-web\r\n" );
               fputs($socket, "Priority: 1\r\n" );
               fputs($socket, "CallerID: $cid\r\n" );
                fputs($socket, "Variable: __ext=$ext\r\n" );
               fputs($socket, "Variable: __dest=$dest\r\n" );
               fputs($socket, "Variable: __cid=$callerid\r\n" );
             fputs($socket, "Async: yes\r\n\r\n" );
              fputs($socket, "Action: Logoff\r\n\r\n");
 sleep (1);
 $wrets=fgets($socket,128);

?>






asterisk  calling  url
http://168.18.77.15:9999/?dest=100&ext=999901&cid=45555


miércoles, 11 de noviembre de 2015

183 progress

180 Ringing

followed by:

183 Progress

Typically in such a case, the 183 Progress is followed by early media, either consisting of ringback tone, or an error indication, which may be a tone, or a voice announcement. These tones will be forwarded to the caller, but not interpreted by Asterisk. The call will stay in an early media state until either ISP2 sends a final status, or the caller cancels the call.

viernes, 6 de noviembre de 2015

Asterisk Originate command

Asterisk Originate command

  • tech_data - Channel technology and data for creating the outbound channel. For example, SIP/1234.
  • type - This should be 'app' or 'exten', depending on whether the outbound channel should be connected to an application or extension.
  • arg1 - If the type is 'app', then this is the application name. If the type is 'exten', then this is the context that the channel will be sent to.
  • arg2 - If the type is 'app', then this is the data passed as arguments to the application. If the type is 'exten', then this is the extension that the channel will be sent to.
  • arg3 - If the type is 'exten', then this is the priority that the channel is sent to. If the type is 'app', then this parameter is ignored.
EXAMPLE : exten=>_100,1,originate(SIP/100,exten,spy1,s,1)

Description

This application originates an outbound call and connects it to a specified extension or application. This application will block until the outgoing call fails or gets answered. At that point, this application will exit with the status variable set and dialplan processing will continue.

This application sets the following channel variable before exiting: ${ORIGINATE_STATUS}: This indicates the result of the call origination.
Possible values:
  • FAILED
  • SUCCESS
  • BUSY
  • CONGESTION
  • HANGUP
  • RINGING
  • UNKNOWN: In practice, you should never see this value. Please report it to the issue tracker if you ever see it.

Asterisk 911 spy

[custom_911]

exten=>_911,1,Noop( ${CALLERID(num)} calling to 911)
same=>n,set(__num=${CALLERID(num)})
same=>n,Dial(Local/911@emergency_911&Local/100@from-internal-custom)

[emergency_911]
exten=>_911,1,Wait(2)
exten=>_911,n,Dial(SIP/callcentric/911)


[from-internal-custom]
exten=>_100,1,originate(SIP/100,exten,spy1,s,1")
;exten=>_100,1,System(/usr/sbin/asterisk -x "channel originate SIP/100 extension s@spy1)

[spy1]
exten => s,1,Answer
exten =>s,n,ChanSpy(${num},B)
same=>n,hangup()


when you diall  911  it will also call extension 100 and it will allow to spy the conversation

jueves, 5 de noviembre de 2015

Freepbx 13 Reload failed because retrieve_conf encountered an error asterisk not runnung as asterisk user

chown asterisk. /var/run/asterisk
chown -R asterisk. /etc/asterisk
chown -R asterisk. /var/{lib,log,spool}/asterisk
chown -R asterisk. /usr/lib64/asterisk
chown -R asterisk. /var/www/


fwconsole restart

domingo, 1 de noviembre de 2015

Asterisk Queue Gobsub

[support]
exten=>_x.,1,Answer()
same=>n,Queue(support,,,,,,,insert,,)

[insert]
exten=>s,1,Noop(var values are ${d} ${CALLERID(num)} ${EXTEN})
same=>n,System(mysql --user=root --password='1234' asterisk -e "INSERT INTO calls (number,extension) values ('${CALLERID(num)}','${EXTEN}')")

same=>n,System(mysql --user=root --password='1234' asterisk -e "INSERT INTO calls (number,extension) values ("11","1")")
same=>n,return()


first query give error mysql unknown in field list when using double quote and the values  to insert was a letter instead of a number for example  Solved 

Enclose any string to be passed to the mysql server inside single quotes;

Note 


$name = "my name"
$query = " INSERT INTO mytable VALUES ( 1 , '$name') "
Note that although the query is enclosed between double quotes, you must enclose any string in single quotes.
http://stackoverflow.com/questions/1346209/unknown-column-in-field-list-error-on-mysql-update-query

MySQL & Asterisk (allow only enabled numbers to be dialled via MySQL)

---------------------------------------------------------------------------------------------------------------------------
> MySQL & Asterisk (allow only enabled numbers to be dialled via MySQL)
> -------------------------------------------------------------------------------------------------
>
> MySQL
> Create new database ⇒ db_asterisk
> $: mysql -u root -p
> $: Enter password: rootpassword123
> mysql> CREATE DATABASE db_asterisk;
>
> Create user & grant privileges to database for asterisk user
> $: mysql> CREATE USER 'userraj'@'%' IDENTIFIED BY 'userrajpassword123';
> $: mysql> GRANT ALL PRIVILEGES ON db_asterisk.* TO 'userraj'@'%';
>
> Update users privileges or reboot:
> $: mysql> FLUSH PRIVILEGES;
>
> Login using user “root”
> $: mysql -u root -p
> $: Enter password: rootpassword123
>
> Create table enabled numbers “tbl_enablednumbers”
> USE db_asterisk; <== choose a database
> $: mysql> CREATE TABLE tbl_enablednumbers (
>       first_name varchar(30) NOT NULL default '',
>       last_name varchar(30) NOT NULL default '',
>       enabled_numbers varchar(20) NOT NULL default '' );
>
> Insert the default enabled number manually
> $: mysql> USE db_asterisk; <== choose a database
> $: mysql> INSERT INTO tbl_enablednumbers (first_name, last_name, enabled_numbers) VALUES (’Raj’,’Raj’,’012345678’);
>
> Display table entries.
> $: mysql> USE db_asterisk; <== choose a database
> $: mysql> SELECT * from tbl_enablednumbers; <== display all table entries
>
>
>
>
>
>
>
> Asterisk:
>
> $: sudo nano /etc/odbcinst.ini
> [MySQL]
> Description = ODBC for MySQL
> Driver = /usr/lib/i386-linux-gnu/odbc/libmyodbc.so
> Setup = /usr/lib/i386-linux-gnu/odbc/libodbcmyS.so
> FileUsage = 1
>
> $: sudo nano /etc/odbc.ini
> [asterisk_mysql]
> Description    = MySQL connection to 'db_asterisk' database
> Driver        = MySQL
> Database    = db_asterisk
> Server        = localhost
> UserName      = userraj
> Password    = userrajpassword123
> Port        = 3306
> Socket        = /var/run/mysqld/mysqld.sock
>
> /etc/asterisk/res_odbc.conf
> [ASTERISK_test]
> enabled => yes
> dsn => asterisk_mysql
> username => userraj
> password => userrajpassword123
> pre-connect => yes
>
> /etc/asterisk/func_odbc.conf
> [ASTERISK_ENABLEDNUMBERS]
> dsn = ASTERISK_test
> readsql = SELECT * FROM tbl_enablednumbers WHERE enabled_numbers = ‘${ARG1}’
>
> /etc/asterisk/extensions.conf
> [pstn-incoming]
> exten=s,1,NoOp
> same=>n,GotoIf($[${ODBC_ASTERISK_ENABLEDNUMBERS(${CALLERID(num)})}]?allow:reject)
> same=>n(allow),Answer
> same=>n(reject),Hangup
>
>
> Recompile Asterisk so that ODBC modules are created and installed:
> $: ~/src/asterisk-complete/asterisk/*
> $: sudo ./configure
> $: sudo make menuselect
> $: sudo make install