giovedì 26 giugno 2014

The simplest Click2Dial implementation EVER

Here's a really lightweight implementation of the Click to Dial feature for softphones, brought you by the flexibility of Asterisk and Linux shell scripting.

Prerequisites:

- Apache and Sudo are installed
- All Iax and Sip peers defined in iax.conf and sip.conf do require to qualify with the QUALIFY=X directive.
- The pbx_spool.so module is loaded (it is required to use Asterisk call files)

Here's the procedure:

nano /etc/sudoers

comment out this line:

Default requiretty

and append this line:

apache ALL=(ALL) NOPASSWD: ALL

at the end of file (THIS IS INSECURE!!!).


# nano /var/www/cgi-bin/index.cgi (NO CUSTOMIZATION NEEDED!)

#!/bin/bash
echo Content-type: text/html
echo ""
echo "<html><head><title>Click2Call</title></head><body>"


rm -rf /tmp/peers
sudo asterisk -rx 'iax2 show peers' | grep 'ms)' | awk  -F' ' 'BEGIN{OFS=FS;} {print $1,$2;}' | awk -F"/" '{print "iax2",$2;}' >>/tmp/peers
sudo asterisk -rx 'sip show peers' | grep 'ms)' | awk  -F' ' 'BEGIN{OFS=FS;} {print $1,$2;}' | awk -F"/" '{print "sip",$2;}' >>/tmp/peers


a=`sudo asterisk -rx 'iax2 show peers' | grep 'ms)' | awk -F "/" '{printf $1"\n";}'`
for dummy in $a
do
   echo "<a href="http://n.n.n.n/cgi-bin/call.sh?iax2/$dummy">$dummy</a href><br>"
done


a=`sudo asterisk -rx 'sip show peers' | grep 'ms)' | awk -F "/" '{printf $1"\n";}'`
for dummy in $a
do
   echo "<a href="http://n.n.n.n/cgi-bin/call.sh?sip/$dummy">$dummy</a href><br>"
done


# chmod +x /var/www/cgi-bin/index.cgi

# nano /var/www/cgi-bin/call.sh (NO CUSTOMIZATION NEEDED!)


#!/bin/bash
echo "Content-type: text/plain"
echo ""
echo "executed";


caller=`cat /tmp/peers | grep -w $REMOTE_ADDR | cut -d' ' -f2`
tech=`cat /tmp/peers | grep -w $REMOTE_ADDR | cut -d' ' -f1`


echo "Channel: $tech/$caller" >/tmp/do.call
echo "Application: Dial" >>/tmp/do.call
echo "Data: $1" >>/tmp/do.call
sudo cp /tmp/do.call /var/spool/asterisk/outgoing

# chmod +x /var/www/cgi-bin/call.sh

# sed -i 's/n.n.n.n/[YOUR_SERVER_IP]/' /var/www/cgi-bin/index.cgi


That's all. You can now navigate to this page:


http://[YOUR_SERVER_IP]/cgi-bin/index.cgi


And CLICK TO DIAL any sip or iax user currently registered to your machine. Your softphone will ring: answer the call and get automatically connected to the requested user!



Nessun commento:

Posta un commento