#!/usr/bin/perl # Nick Mossie # Aastra ignore button effectively dumps call to voicemail by hanging up all extensions # # requirements: # # aastra.cfg # sip ignore status code: 603 # # asterisk process # started with 3 v's (-vvv) # call group dumps to voicemail on no answer use File::Tail; use Net::Telnet; use Time::HiRes qw( usleep ); use strict; my $user = 'YOUR_USERNAME'; my $pass = 'YOUR_PASSWORD'; my $tc = new Net::Telnet(Timeout => 10, Errmode => 'die', Host => 'localhost', Port => '5038'); my $file = File::Tail->new(name => '/var/log/asterisk/full', maxinterval => 1); my @last_siplines; my $last_sipline; my $last_dahdiline; my $dahdi_id; my $line; undef($last_sipline); undef($last_dahdiline); while (defined($line = $file->read)) { next if($line !~ /(pbx\.c|app_dial\.c|chan_sip\.c)/); next if($line !~ /(Dial\("DAHDI|is ringing|603 "Decline")/); if(@last_siplines && $last_dahdiline && $line =~ /Got SIP response 603 "Decline" back from/) { # if we have a line, then dump it if 'we get signal' $tc->open(); $tc->print('Action: login'); $tc->print('Events: off'); $tc->print('Username: '.$user); $tc->print('Secret: '.$pass); $tc->print(''); # hangs up all ringing extensions # which dumps the call out of the ring group # answered by no-answer rule (right now: oper busy) foreach $last_sipline (@last_siplines) { print "dumping: $last_dahdiline $last_sipline\n"; $tc->print('Action: Hangup'); $tc->print('Channel: '.$last_sipline); $tc->print(''); usleep(200); } $tc->print('Action: logoff'); $tc->print(''); undef($last_sipline); undef($last_dahdiline); undef(@last_siplines); } elsif($line =~ /(SIP\/\d{3}-\w{8}) is ringing/) { # get the sip line to dump push @last_siplines, $1; } elsif($line =~ /Dial\("(DAHDI\/\d-1)",/) { # get the DAHDI line to dump, not used, but good to restart on a new DAHDI $last_dahdiline = $1; undef(@last_siplines); } }