Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- #
- # Based on a public forum post - https://www.dslreports.com/forum/r30960612-
- use Asterisk::AGI;
- use LWP::UserAgent;
- use strict;
- # Set configuration parameters
- my $api_key = "YourAPIkey";
- my $api_password = "YourAPIpassword";
- my $service_url = "https://api.truecnam.net/api/v1";
- my $voicemail_on_score = 40;
- my $disconnect_on_score = 80;
- #############################################################
- #
- # Get data from Asterisk
- my $AGI = new Asterisk::AGI;
- my $calling_num = $AGI->get_variable("cidnum");
- my $called_num = $AGI->get_variable("callednum");
- # Send request to TrueCNAM
- my $url = $service_url."?username=".$api_key."&password=".$api_password."&resp_type=extended&resp_format=csv&calling_number=".$calling_num."&call_party=terminating";
- $url .= "&called_number=".$called_num if ($called_num);
- my $content = "";
- my $ua = LWP::UserAgent->new;
- my $response = $ua->get($url);
- if ($response->is_success) {
- $content = $response->decoded_content;
- #print $response->decoded_content . "\n"; # or whatever
- } else {
- #die $response->status_line;
- exit 0;
- }
- my @res = split(",", $content);
- # Check for error
- if ($res[11]) {
- exit 0;
- }
- # Check for TrueSPAM
- if (!$res[7]) {
- exit 0;
- }
- $AGI->exec('Set', 'SPAMSCORE=');
- if ($res[8] >= $disconnect_on_score) {
- $AGI->exec('Set', 'SPAMROUTE=HANGUP');
- exit 0;
- } elsif ($res[8] >= $voicemail_on_score) {
- $AGI->exec('Set', 'SPAMROUTE=VOICEMAIL');
- exit 0;
- }
- print "Low score\n";
- $AGI->exec('Set', 'SPAMROUTE=CLEAN');
- exit 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement