#!/usr/bin/perl
#
# put this file to '/usr/share/asterisk/agi-bin/' and 'chmod a+x' it 
# then edit /etc/asterisk/extensions.conf, section [default] :
#  exten => {укажите ваш номер телефона здесь},1,NoOp(Входящий звонок с номера ${CALLERID(num)})
#  same => n,AGI(wnam-asterisk-bridge.pl,${CALLERID(num)})
#  same => n,Hangup()
# and reload asterisk

use constant WNAM_HOST => "127.0.0.1";

use IO::Socket::INET;

$| = 1; 

my $sock = new IO::Socket::INET(PeerAddr => WNAM_HOST, PeerPort => 20001, Proto => 'tcp', Timeout => 0.5) or undef $sock;

if (defined $sock) {
        my $phone=$ARGV[0];
        if (defined $phone) {
            print $sock "CALL-RECV PHONE=$phone TEXT=0000\n";
        }
        $sock->shutdown(2);
        $sock->close;
	}

