VoIP with voipscheap.com

From LinuxMCE
Jump to: navigation, search
Version Status Date Updated Updated By
710 Unknown N/A N/A
810 Works 5 October 2010 golgoj4
1004 Unknown N/A N/A
1204 Unknown N/A N/A
Usage Information

Voipcheap is a VOIP provider that allows free calls for many destinations in a fair use basis (up to 300 minutes per week) and cheap rates to other destinations. Their rates can be found at: http://www.voipcheap.com/en/calling-rates.html.

Voipcheap has also the possibility to manage VOIp-in calls, but you need to get it from a DID service. Mine, i got from IPKALL, so i do have a dial-in number in Washington D.C.

The setup in LinuxMCE is very simple.

sudo touch /usr/pluto/bin/create_amp_voipcheap.pl
sudo chmod 555 /usr/pluto/bin/create_amp_voipcheap.pl

Use vi or your favorite editor:

sudo vi /usr/pluto/bin/create_amp_voipcheap.pl

You can cut & paste the following script:

use strict;
use diagnostics;
use DBI;
require "/usr/pluto/bin/config_ops.pl";

# Some helper functions
require "/usr/pluto/bin/create_amp_LocalPrefixHelper.pl";
my $DECLARED_HOST = "sip.voipcheap.com";
my $DECLARED_PREFIX = "9";              
my $LOCAL_PREFIX1 = "";                 
my $LOCAL_PREFIX2 = "";                 
my $TRUNK_URL = 'http://localhost/admin/config.php?display=trunks&tech=SIP';
my %TRUNK_VARS = ();                                                        
my $TRUNK_DATA = "";                                                        
my $OUT_URL = 'http://localhost/admin/config.php?display=routing';
my %OUT_VARS = ();                                                
my $OUT_DATA = "";                                                
my $IN_URL = 'http://localhost/admin/config.php?display=did';
my %IN_VARS = ();                                            
my $IN_DATA = "";                                            
# Check params
unless (defined($ARGV[0]) && defined($ARGV[1]) && defined($ARGV[2]))
    print "USAGE :$0 <username> <password> <phone_number> [<register_host>][<prefix_to_use_the_line>]\n";                                                                                             
# Fix permissions on each run
`chmod g+w /etc/asterisk/*`; 
$DECLARED_HOST=$ARGV[3] if(defined($ARGV[3]));
# This is not currently passed into the script
# Can be used in the future for multiple trunk support
# $DECLARED_PREFIX=$ARGV[4] if(defined($ARGV[4]));    
($LOCAL_PREFIX1, $LOCAL_PREFIX2) = &get_local_prefixes($DECLARED_PREFIX);
# print "LOCAL_PREFIX1: $LOCAL_PREFIX1 \n";                              
# print "LOCAL_PREFIX2: $LOCAL_PREFIX2 \n";                              
$TRUNK_VARS{'peerdetails'} ="allow=ulaw&ulaw&g729\n";
$TRUNK_VARS{'userconfig'} ="allow=ulaw&alaw&g729\n";
foreach my $var (keys %TRUNK_VARS)
    my $str = $TRUNK_VARS{$var};  
    $str =~ s/([^A-Za-z0-9])/sprintf("%%%02X", ord($1))/seg;
    $TRUNK_DATA    .=$var."=".$str."&";                     
`curl -d '$TRUNK_DATA' '$TRUNK_URL' > /dev/null`;
`curl -L '$OUT_URL&extdisplay=001-9_outside&action=delroute' > /tmp/curl.log`;
open(PAGE,"/tmp/curl.log") or die "Bad thing happend";                        
my $OUT_ROUTE = "";                                                           
    if($_ =~ /[<]option value[=]\"([^\"]+)\"[>]SIP\/voipcheap[<]\/option[>]/)
exit unless($OUT_ROUTE ne "");

foreach my $var (keys %OUT_VARS)
    my $str = $OUT_VARS{$var};  
    $str =~ s/([^A-Za-z0-9])/sprintf("%%%02X", ord($1))/seg;
    $OUT_DATA .=$var."=".$str."&";                          

`rm -f /tmp/curl.log ; curl -d '$OUT_DATA' '$OUT_URL' > /dev/null`;

$IN_VARS{'custom0'}="custom-linuxmce,10".$1.",1" if($OUT_ROUTE=~/(\d)$/);

foreach my $var (keys %IN_VARS)
    my $str = $IN_VARS{$var};
    $str =~ s/([^A-Za-z0-9])/sprintf("%%%02X", ord($1))/seg;
`curl -d '$IN_DATA' '$IN_URL' > /dev/null`;

# Run AMP's scripts to generate asterisk's config
`curl 'http://localhost/admin/config.php?handler=reload' > /dev/null`;

# Create telecom defaults

# Reload asterisk
`asterisk -r -x reload`;

Edit the /etc/asterisk/provider_list.txt and add the following line:

Voipcheap       http://www.voipcheap.com        voipcheap       SIP

How do i run it?

If you already have a SIP provider, you will need to run it from the console:

/usr/bin/pluto/create_amp_voipcheap.pl username password phone_number

Is it working? From the console, do:

asterisk -r

And enter the following:

sip show registry

You will see the status.

In the webadmin page you will also check it under Phone Lines.

If this is not your only voip trunk, you will need to adjust dialing patterns and rules for trunk and outbound routes, and this can be done in:

webadmin -> advanced -> configuration -> phones setup

Hope this helps. It's working for me.

P.S. As i'm not a freepbx and asterisk expert, if you find any error and can improve this wiki and/or script please feel free and help us to improve.