initial commit
[asterisk-spoof.agi] / spoof.agi
1 #!/usr/bin/perl
2
3 use Asterisk::AGI;
4
5 $AGI = new Asterisk::AGI;
6
7 my $callerid=$ARGV[0];
8 my @trusted=("1112223333","2223334444");
9 my $size= scalar @trusted;
10 my $match=0;
11
12 while ($size>0) {
13   $size--;
14   if ($callerid eq $trusted[$size]) {
15     $match=1;
16   }
17 }
18
19 if ($match==1) {
20   $AGI->exec('Festival', '"Please. Enter. the. source. number"');
21
22   my %input = $AGI->ReadParse();
23
24   my $finished = 0;
25
26   while (!$finished) {
27     my $input = chr($AGI->wait_for_digit('5000'));
28     if ($input =~ /^[0-9\*\#]$/) {
29       if ($input =~ /^[\*\#]$/) {
30         $x++;
31         if ($x > 10) {
32           $finished = 1;
33         } else {
34           $code.= '';
35         }
36       } else {
37         $code .= $input;
38       }
39     }
40
41     if ( length($code) > 10) {
42       $finished = 1;
43     }
44   }
45
46   $AGI->exec('Festival', '"Please. Enter. the. destination. number"');
47   `echo "$code">/tmp/code`;
48
49   my $finished2 = 0;
50   `echo "here">/tmp/code`;
51   while (!$finished2) {
52     my $input = chr($AGI->wait_for_digit('5000'));
53     if ($input =~ /^[0-9\*\#]$/) {
54       if ($input =~ /^[\*\#]$/) {
55         $x2++;
56         if ($x2 > 10) {
57           $finished2 = 1;
58         } else {
59           $code2.= '';
60         }
61       } else {
62         $code2 .= $input;
63       }
64     }
65
66     if ( length($code2) > 10) {
67       $finished2 = 1;
68     }
69   }
70
71 $AGI->setcallback(\&callback);
72
73 $AGI->exec('Festival', '"I will now dial "');
74 $AGI->exec('Festival', $code2);
75 $AGI->exec('Festival', '"with"');
76 $AGI->exec('Festival', $code);
77 #Your IAX/SIP dialing instruction go here... For Example:
78 #$code2="IAX2/1234\@iax2provider/$code2";
79 #$code2="SIP/$code2\@sipprovider";
80 $code2="";
81 $AGI->set_callerid($code);
82 $AGI->exec('Dial', $code2);
83 } else {
84   $AGI->exec('Festival', '"Unauthorized. Attempt logged."');
85 }
86
87 sub callback(){
88   warn "The call has ended\n";
89   set_context($context);
90   exit;
91 }
92