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, 30 de mayo de 2015

Automatic calling

##########################
DIAL PLAN
##########################

[india]
exten=>_x.,1,NoCDR()
same=>n,Set(CALLERID(num)=255411413792)
same=>n,Dial(SIP/+${EXTEN}@cpeak,5)
same=>n,hangup()
exten=>h,1,System(/bin/sed -i "s/${CDR(dst)}//g" /root/number_list)
exten=>h,2,Noop(${CDR(dst)} hangupcause ${HANGUPCAUSE} dialstatus ${DIALSTATUS})
exten=>h,3,System(echo Destination "${CDR(dst)} | hangupcause ${HANGUPCAUSE} | dialstatus ${DIALSTATUS} | date ${STRFTIME(${EPOCH},,%Y-%m-%d_%H-%M-%S)}" >>/var/www/callstatus.txt)


[india2]
exten=>_x.,1,NoCDR()
exten=>_x.,2,hangup
exten=>h,1,System(/bin/sed -i "s/${CDR(dst)}//g" /root/number_list)
exten=>h,2,Noop(hangupcause ${HANGUPCAUSE} dialstatus ${DIALSTATUS})




##############
Calling Script
#############


#!/bin/bash
 var=$(< number_list)    ##take the numbes from a  file called  number_list
for i in $var
do
 echo "calling to $i "

   echo "calling to $i " > freecalls.logs
`asterisk -x "originate Local/$i@india extension $i@india2"`
sleep 2
done



####################################
BASH SCRIPT  to check if process is running
#####################################

#!/bin/bash
 PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
export DISPLAY=:0.0

T2=`pgrep calltxtfile.sh `

if [ "$T2" = "" ]; then
echo process not running
/root/calltxtfile.sh
else
echo process running fine
fi




#########################################
cronjob
#######################################


*/1 * * * * /root/checkpro.sh

sábado, 23 de mayo de 2015

Ver las llamadas activas en un contexto especifico (internal).

Ver las llamadas activas  en un contexto especifico (internal).

http://65.181.118.232/ami/call.php?context=internal



internal 0411 2 Up Dial SIP/callcentric/411,,Tt 0154 00:00:27 b95be771-7da6-4a5b-a

internal 18007142020 3 Up Dial SIP/18007142020@cpeak,25 18097143489 00:01:17 2b460c3f-553d-4d11-8




<?php

$command="core show channels verbose";
$context=$_GET[context];


$socket = fsockopen("127.0.0.1","5038", $errno, $errstr, 10);
      if (!$socket){
        echo "$errstr ($errno)\n";
        }else{
            fputs($socket, "Action: Login\r\n");
            fputs($socket, "UserName: admin\r\n");
            fputs($socket, "Secret: a456\r\n\r\n");
            fputs($socket, "Action: Command\r\n");
            fputs($socket, "Command: $command\r\n\r\n");
           fputs($socket, "Action: Logoff\r\n\r\n");
           while (!feof($socket)){

 $result=fgets($socket);
$result= stristr($result,"$context");
 $d=strlen($result);


while ($d>0){

echo "$result<br><br>";
break;

}

}


fclose($socket);
 }

?>

Call count and Call Monitor status

URL

http://65.181.118.232/call_count.php?num=18097143489

Diferentes salidas


Total of active calls 0.5

103 5 Up Playback ss-noservice 0154 00:00:03

###################################


Total of active calls 1

102-00000004 internal 102 1 Ringing AppDial (Outgoing Line) 102 00:00:01
#####################################################


Total of active calls 1

0411 00:00:09 65397a02-9b16-4ba2-a

###############################################

Total of active calls 1

0411 1 Down AppDial (Outgoing Line) 0411 00:00:01

############################################

Total of active calls 1

18097143489 3 Ring Dial SIP/18097143489@cpeak,25 18097143489 00:00:10



Count Script

<?php

$command="core show channels verbose";


$socket = fsockopen("127.0.0.1","5038", $errno, $errstr, 10);
      if (!$socket){
        echo "$errstr ($errno)\n";
        }else{
            fputs($socket, "Action: Login\r\n");
            fputs($socket, "UserName: admin\r\n");
            fputs($socket, "Secret: ar456\r\n\r\n");
            fputs($socket, "Action: Command\r\n");
            fputs($socket, "Command: $command\r\n\r\n");
           fputs($socket, "Action: Logoff\r\n\r\n");
           while (!feof($socket)){

 $result=fgets($socket);
 $result= stristr($result,"active",true);
 $d=strlen($result);


if ($d>0){
echo "Total of active calls ".($result/2); //dividimos el  total de canales entre 2 para tener el total de lllamadas
echo "<br><br>";
break;

}

}


fclose($socket);
 }

?>

Monitor Script

<?php

$command="core show channels verbose";
$number=$_GET[num];


$socket = fsockopen("127.0.0.1","5038", $errno, $errstr, 10);
      if (!$socket){
        echo "$errstr ($errno)\n";
        }else{
            fputs($socket, "Action: Login\r\n");
            fputs($socket, "UserName: admin\r\n");
            fputs($socket, "Secret: aor456\r\n\r\n");
            fputs($socket, "Action: Command\r\n");
            fputs($socket, "Command: $command\r\n\r\n");
           fputs($socket, "Action: Logoff\r\n\r\n");
           while (!feof($socket)){

 $result=fgets($socket);
 $result= stristr($result,"$number");
 $d=strlen($result);


if ($d>0){

echo "$result<br><br>";
break;

}

}


fclose($socket);
 }

?>


viernes, 22 de mayo de 2015

Asterisk random trunk dialing

Asterisk func rand

Synopsis:

Choose a random number in a range

Description:

  RAND([min][,max])


[from-internal-custom]

 exten =>_0.,1,Verbose( Dialing to ${EXTEN:1})
  same => 2,Goto(${RAND(3,7)})
  ;set priority number from 3~7 random
  same=> 3,Dial(dongle/dongle0/${EXTEN:1},300,Tt)
  same=> 4,Dial(dongle/dongle1/${EXTEN:1},300,Tt)
  same=> 5,Dial(dongle/dongle2/${EXTEN:1},300,Tt)
  same=> 6,Dial(dongle/dongle2/${EXTEN:1},300,Tt)


Example1

 exten => s,1,Set(junky=${RAND(1,8)});
     - Sets junky to a random number between 1 and 8, inclusive.


Example2

if we had few caller ID number want to use it, try this:

[outbound]
exten => _886X.,1,Noop
  same => n,Gosub(pickCallerIDnum,cell${RAND(1,5)},1)
  same => n,Dial(SIP/${EXTEN}@gateway,32,gCX)

[pickCallerIDnum]
exten => cell1,1,Set(CALLERID(num)=09xxxxxxx1)
  same => n,Return
exten => cell2,1,Set(CALLERID(num)=09xxxxxxx2)
  same => n,Return
exten => cell3,1,Set(CALLERID(num)=09xxxxxxx3)
  same => n,Return
exten => cell4,1,Set(CALLERID(num)=09xxxxxxx4)
  same => n,Return
exten => cell5,1,Set(CALLERID(num)=09xxxxxxx5)
  same => n,Return


Example3

if we had 5 outbound gateway, we wanna use it equally, try this:

exten => _09XXXXXXXX,1,Set(VOLUME(RX)=5)
  same => 2,Goto(${RAND(3,7)})
  ;set priority number from 3~7 random
  same=> 3,Dial(SIP/${EXTEN}@gateway0)
  same=> 4,Dial(SIP/${EXTEN}@gateway1)
  same=> 5,Dial(SIP/${EXTEN}@gateway2)
  same=> 6,Dial(SIP/${EXTEN}@gateway3)
  same=> 7,Dial(SIP/${EXTEN}@gateway4)

jueves, 21 de mayo de 2015

Asterisk variables and manipulation

3.2. Variables


A variable is a placeholder for an actual value. Exactly what that value is depends on the kind of variable. In Asterisk, variables can contain numbers, letters and strings (sequences of letters and numbers). Variables are useful because they let us create rules for call flow that apply in changing circumstances and make it easier to accommodate future changes in the telephone application or system.

Tip

If you've never worked with variables before, we recommend you read an introduction to the subject at http://en.wikipedia.org/wiki/Variables#In_computer_programming .
In Asterisk, variables have varying scope. There are local variables (called channel variables in Asterisk), which can only set values for the current, active channel, and global variables, which set values for all channels. We should already be familiar with some of the variables Asterisk sets from our exposure to them as configuration parameters in the Asterisk configuration files (such as sip.conf, for example). We also have the freedom to define our own variables and use them in configuration files.

Expanding variables in an extension

The value of a variable can be obtained using the syntax ${VARIABLENAME}. There are variables that are automatically set by Asterisk. For example, the called number is always stored in the Asterisk system variable ${EXTEN}. Using patterns and variables, it is often possible to dramatically compress a long dialplan.
Before:
exten => 100,1,Dial(SIP/100)
exten => 101,1,Dial(SIP/101)
exten => 102,1,Dial(SIP/102)
exten => 103,1,Dial(SIP/103)
exten => 104,1,Dial(SIP/104)
exten => 105,1,Dial(SIP/105)
exten => 106,1,Dial(SIP/106)
exten => 107,1,Dial(SIP/107)
exten => 108,1,Dial(SIP/108)
exten => 109,1,Dial(SIP/109)
After:
exten => _10X,1,Dial(SIP/${EXTEN})


domingo, 17 de mayo de 2015

Asterisk Queues

/etc/asterisk/queue.conf

[general]
persistantmembers=yes
autofill=yes
monitor-type=MixMonitors
shared_lastcall=no



[queue_template](!)
musicclass=default      ; play [default] music
strategy=rrmemory       ; use the Round Robin Memory strategy
joinempty=yes           ; join the queue when no members available
leavewhenempty=no       ; don't leave the queue no members available
ringinuse=no            ; don't ring members when already InUse



[support](queue_template)
; Support queue
member => SIP/100
member => SIP/101
member => SIP/102




/etc/asterisk/extensions.conf

[queue]
exten =>12058553088,1,Answer()
exten =>12058553088,n,queue(support,,,,320)
same => n,goto(qvm,1,1)

same=>n,hangup()

[qvm]
exten =>1,1,Noop()
same=>n,VoiceMail(1114886101@default-111488,u)

lunes, 11 de mayo de 2015

Channel Redirect

[conf]

exten =>_00124,1,Answer()
same=>n,System(echo "${CHANNEL}" > /root/c1.conf)
same=>n,MusicOnHold()


exten =>_00123,1,Answer()
same=>n,Set(caller1=${SHELL(cat /root/c1.conf)})
same=>n,Set(caller2=${SHELL(cat /root/c2.conf)})
same=>n,Verbose(this is channel ${caller1})
same=>n,ChannelRedirect(${caller1:0:16},internal,0,1)
same=>n,Hangup()




DTMF Script


DID to call 1 206-279-5567.


 
 ###################
 Dial Plan


[dtmf_call]
exten=>_x.,1,Answer()
same=>n,Set(CODE=${SHELL(cat /var/www/code.conf)})
same=>n,verbose( this is the ${CODE})
same=>n,Wait(1)
same=>n,SendDTMF(${CODE:0:1})
same=>n,SendDTMF(${CODE:1:1})








#### Web Script ###

<?php

echo "<center><h2>DID to  call   1 206-279-5567. <h2></center>";


// asignar permisos chmod 777 /var/www/code.conf

$myfile = fopen("/var/www/code.conf", "w") or die("Unable to open file!");
$code=$_POST[code];
fwrite($myfile,$code);
fclose($myfile);
echo $code;
?>
<body>

    <div class="login-help">
      <p>Click here to <a href="google.php"> Go to the main panel </a>.</p>
    </div>
  <section class="container">
    <div class="login">
      <h1>Add DTMF</h1> <form enctype="multipart/form-data" action="google.php" method="POST" onsubmit="return val(this)">


        <p><input type="text" name="code" value="" placeholder="code"></p>


    <p class="submit"><input type="submit" name="submit" value="Done"></p>

      </form>
    </div>


  </section>

domingo, 3 de mayo de 2015

WebRTC tutorial using SIPML5

mkdir /etc/asterisk/keys/
cd  /usr/src/asterisk-13.0.0/contrib/scripts


./ast_tls_cert -C 65.181.118.52 -O "My Super Company" -d /etc/asterisk/keys -o asterisk


Asterisk 11 Tutorial Overview

The idea for this tutorial is to demonstrate very basic WebRTC support and functionality in Asterisk 11. We will configure Asterisk to support a remote WebRTC client, and then make calls from said client (SIPML5) to Asterisk. ICE and STUN will be used for NAT traversal, and SIP will use a WebSocket transport.
Icon
It is hard to design a tutorial that applies to every environment, so remember the following:
This tutorial written using Debian Squeeze 6.0.5, Asterisk 11.8.0-rc1 and Asterisk's chan_sip channel driver.
We assume you are a little familiar with Asterisk, and have an Asterisk installation available via a public IP address, and control of the firewall in front of it. (you do have it fire-walled right?)
The SIPML5 client will be accessed via Chrome and is assumed to be behind NAT.
Icon
In newer versions of Chrome and Firefox (and others) DTLS-SRTP is mandatory. This means you must generate certificates for Asterisk to be able to use WebRTC. See: Secure Calling Tutorial

Get dependencies

Install a variety of essential dependencies to make sure we get them. Plus install the uuid-dev package that isn't included in the Asterisk 11 install_prereq script.
sudo apt-get install build-essential libncurses5-dev libxml2-dev libsqlite3-dev libssl-dev libsrtp0-dev uuid-dev
Then go to your Asterisk source /contrib/scripts directory and run the install_prereq script to get everything else that is needed.
sudo ./install_prereq install
sudo ./install_prereq install-unpackaged

Build Asterisk with support for WebRTC

 Using menuselect make sure Asterisk will build with res_http_websocket, res_crypto and chan_sip.
In the Asterisk source directory:
./configure && make menuselect
 After verifying things are as needed in menuselect, then build and install Asterisk
make && make install && make samples

Configure Asterisk

Now we need to configure the various Asterisk components necessary for WebRTC support.
I always recommend backing up your current .conf files and using clean, blank text files for trying out a tutorial like this. Especially if you are new to Asterisk.

Configure http.conf

[general]
enabled=yes
bindaddr=0.0.0.0
bindport=8088
You need to configure Asterisk's builtin HTTP server. You could use whatever bindport or bindaddr you want, but make sure you adjust the other configurations to match. This is the port and address that res_http_websocket and chan_sip will talk over when using a WebSocket transport.

Configure rtp.conf

[general]
rtpstart=10000
rtpend=20000
icesupport=true
stunaddr=stun.l.google.com:19302
Configure the range of ports to use for RTP media, and we can set icesupport=yes (although the default in recent versions of 11 is now "yes") to enable support for the ICE protocol in general. We also set the address of the STUN server to use here. We use Google's STUN server which should work for just about everyone.

Configure sip.conf

[general]
udpbindaddr=0.0.0.0
realm=123.123.123.123 ;replace with your Asterisk server public IP address or host
transport=udp,ws
icesupport=yes
directmedia=no
qualify=yes
trustrpid=yes
generaterpid=yes
sendrpid=yes
realm=60.11.118.232 ;replace with your Asterisk server public IP address or host
icesupport=yes
media_address=60.11.118.232 ;replace with your Asterisk server public IP address or host
nat=force_rport,comedia
qualifyfreq=60
keepalive=60
bindport=5060
context=default

[phone](!)
host=dynamic
type=friend
context=internal
callcounter=yes  ;trabaja en conjunto con device state
disallow=all
allow=ulaw
allow=alaw
callgroup = 1
pickupgroup = 1
dtmfmode=rfc2833
;contactdeny=0.0.0.0/0.0.0.0           ; Use contactpermit and contactdeny to
;contactpermit=172.16.0.0/255.255.0.0  ; restrict at what IPs your users may
callerid=phone
nat=force_rport,comedia
directmedia=no
icesupport=yes

[3100](phone)
username=3100
secret=11@ambiorix@34
callerid=Webrtc
disallow=all
allow=ulaw
allow=alaw
avpf=yes
force_avp=yes
icesupport=yes
directmedia=no
dtlsenable=yes
dtlsverify=fingerprint
dtlscertfile=/etc/asterisk/keys/asterisk.pem
dtlscafile=/etc/asterisk/keys/ca.crt
dtlssetup=actpass
context=webrtc
nat=force_rport,comedia
allow=h263
allow=h263p
allow=vp8
videosupport=no

[3101](phone)
username=3101
secret=11@ambiorix@34
callerid=Webrtc1
disallow=all
allow=ulaw
allow=alaw
avpf=yes
force_avp=yes
icesupport=yes
directmedia=no
dtlsenable=yes
dtlsverify=fingerprint
dtlscertfile=/etc/asterisk/keys/asterisk.pem
dtlscafile=/etc/asterisk/keys/ca.crt
dtlssetup=actpass
context=webrtc
nat=force_rport,comedia
allow=h263
allow=h263p
allow=vp8
videosupport=no
context=internal

There is already a lot of content on the wiki and in the sip.conf sample file that explain the options here. The key options for WebRTC support and ICE support are explained at this link for WebRTC and this one for ICE.
Icon
Though this page is written to Asterisk 11 and chan_sip, an example for setting up a PJSIP endpoint in Asterisk 12 is below.

Configure pjsip.conf

[transport-ws]
type=transport
protocol=ws
bind=0.0.0.0
 
[101]
type=aor
max_contacts=2
remove_existing=yes
 
[101]
type=auth
auth_type=userpass
password=101
username=101
 
[101]
type=endpoint
disallow=all
allow=ulaw
context=default
auth=101
aors=101
media_encryption=dtls
dtls_verify=fingerprint
dtls_cert_file=/etc/asterisk/keys/asterisk.pem
dtls_ca_file=/etc/asterisk/keys/ca.crt
dtls_setup=actpass
use_avpf=yes
ice_support=yes
media_use_received_transport=yes

Configure extensions.conf

We'll make a simple dialplan for receiving a test call from the SIPML5 client.
[default]
[from-internal]
exten => 1000,1,Answer()
same => n,Playback(demo-congrats)
same => n,Hangup()
If you haven't written dialplan before; this is just instructing Asterisk to answer the call and playback the sound file "demo-congrats".

Configure the firewall in front of Asterisk

Firewall configuration is outside the scope of the tutorial, however here is the output from my Uncomplicated FireWall service to show you what you may need to open:
To                         Action      From
--                         ------      ----
5060                       ALLOW IN    Anywhere
8088/tcp                   ALLOW IN    Anywhere
10000:20000/udp            ALLOW IN    Anywhere
You may wish to reconfigure your services to non-standard ports, or narrow the possible source addresses for additional security.
5060: This is the port configured in sip.conf
8088: This is the port configured in http.conf
10000:20000: This is the port range configured in rtp.conf

Configure SIPML5

Goto http://sipml5.org/ in your Chrome browser and use the live demo.
On the registration page use the following configuration, replacing the IP addresses with your public IP for the Asterisk server.

Open the "Expert mode" settings page and use the following details, still replacing the IP of course:

Be sure to hit save! Just leave that tab open, or close it and go back to the main tab to make a test call.

Make a test call

Restart Asterisk, or start Asterisk if you haven't already.
Click "Login" with the SIPML5 client. On the Asterisk CLI you should see:
  == WebSocket connection from 'X.X.X.X:46723' for protocol 'sip' accepted using version '13'
    -- Registered SIP '6001' at X.X.X.X:46723
       > Saved useragent "IM-client/OMA1.0 sipML5-v1.2014.01.27" for peer 6001
Dial extension 1000 from your SIPML5 client and you should see CLI output:
  == Using SIP RTP CoS mark 5
    -- Executing [1000@from-internal:1] Answer("SIP/6001-00000000", "") in new stack
       > 0x28057f0 -- Probation passed - setting RTP source address to X.X.X.X:9177
    -- Executing [1000@from-internal:2] Playback("SIP/6001-00000000", "demo-congrats") in new stack
    -- <SIP/6001-00000000> Playing 'demo-congrats.gsm' (language 'en')
If you don't have VERBOSE messages going to the console, and verbosity turned up at least to 3 then you may not see these messages.
Icon
When you attempt the call, Chrome may ask you for access to your microphone or camera. Be sure to say yes!
You should hear audio coming from your speakers or headphone! Congrats on making your first call via WebRTC using Asterisk!
Icon
If you attempt to use WSS instead of WS as your transport, note that Chrome and Firefox will not allow you, by default, to connect, using WSS, to a server with a self-signed or otherwise invalid certificate. Rather, you'll have to install a signed certificate into Asterisk or import the server's self-signed/invalid certificate into your browser's keychain, which is outside of the scope of this Wiki. As a workaround with Firefox only, for testing or development, you can open a separate browser tab and point it to Asterisk's HTTP server's TLS port, e.g. https://[your asterisk server]:8089/ws, and confirm the security exception.


cd /var/www
svn checkout http://sipml5.googlecode.com/svn/trunk/ sipml5-read-only
 cd sipml5-read-only
http://my-server-ip/sipml5-read-only/call.htm#


 https://wiki.asterisk.org/wiki/display/AST/WebRTC+tutorial+using+SIPML5
http://sipjs.com/guides/server-configuration/asterisk/
https://wiki.asterisk.org/wiki/display/AST/Asterisk+WebRTC+Support