[Astpp-commit] SF.net SVN: astpp:[2216] trunk/freeswitch/astpp-fs-xml.pl
Brought to you by:
darrenkw
|
From: <dar...@us...> - 2008-12-06 18:35:57
|
Revision: 2216
http://astpp.svn.sourceforge.net/astpp/?rev=2216&view=rev
Author: darrenkw
Date: 2008-12-06 18:35:51 +0000 (Sat, 06 Dec 2008)
Log Message:
-----------
Tidied the source code.
Modified Paths:
--------------
trunk/freeswitch/astpp-fs-xml.pl
Modified: trunk/freeswitch/astpp-fs-xml.pl
===================================================================
--- trunk/freeswitch/astpp-fs-xml.pl 2008-12-03 06:14:49 UTC (rev 2215)
+++ trunk/freeswitch/astpp-fs-xml.pl 2008-12-06 18:35:51 UTC (rev 2216)
@@ -18,7 +18,8 @@
use CGI qw/:standard Vars/;
use ASTPP;
use strict;
-use vars qw($params $ASTPP @output $config $freeswitch_db $astpp_db $verbosity );
+use vars
+ qw($params $ASTPP @output $config $freeswitch_db $astpp_db $verbosity );
use Locale::gettext_pp qw(:locale_h);
require "/usr/local/astpp/astpp-common.pl";
$ENV{LANGUAGE} = "en"; # de, es, br - whatever
@@ -26,11 +27,10 @@
bindtextdomain( "astpp", "/usr/local/share/locale" );
textdomain("astpp");
$verbosity = 2;
-@output = ("STDERR");
-$ASTPP = ASTPP->new;
-$ASTPP->set_verbosity(4); #Tell ASTPP debugging how verbose we want to be.
+@output = ("STDERR");
+$ASTPP = ASTPP->new;
+$ASTPP->set_verbosity(4); #Tell ASTPP debugging how verbose we want to be.
-
sub initialize() {
$config = &load_config();
$astpp_db = &connect_db( $config, @output );
@@ -42,161 +42,227 @@
################# Programs start here #######################################
&initialize;
-my ( $xml, $maxlength, $maxmins,$callstatus );
+my ( $xml, $maxlength, $maxmins, $callstatus );
foreach my $param ( param() ) {
$params->{$param} = param($param);
$ASTPP->debug( debug => "$param $params->{$param}" );
}
-$xml = header(-type => 'text/plain');
+$xml = header( -type => 'text/plain' );
-$ASTPP->debug( debug => "Destination = $params->{'Caller-Destination-Number'}");
+$ASTPP->debug(
+ debug => "Destination = $params->{'Caller-Destination-Number'}" );
-if ($params->{section} eq "dialplan") {
-$xml = $ASTPP->fs_dialplan_xml_header( xml => $xml, destination_number => $params->{'Caller-Destination-Number'});
+if ( $params->{section} eq "dialplan" ) {
+ $xml = $ASTPP->fs_dialplan_xml_header(
+ xml => $xml,
+ destination_number => $params->{'Caller-Destination-Number'}
+ );
-if (!$params->{variable_accountcode}) {
-# First we strip off X digits to see if this account is prepending numbers
-# as authentications
- $ASTPP->debug( debug => "Checking CC Number: " . $params->{'Caller-Destination-Number'});
- my $cc = substr( $params->{'Caller-Destination-Number'}, 0, $config->{cardlength} );
- my $sql = $astpp_db->prepare("SELECT number FROM accounts WHERE cc = $cc");
- $sql->execute;
- my $record = $sql->fetchrow_hashref;
- $sql->finish;
- $params->{variable_accountcode} = $record->{cardnum} if ($record->{cardnum});
-}
-if (!$params->{variable_accountcode}) {
- $ASTPP->debug( debug => "Checking IP Address:" . $params->{network_addr});
- my $ip_data = $ASTPP->ip_address_authenticate( ip_address => $params->{network_addr}, destination => $params->{'Caller-Destination-Number'});
- if ($ip_data) {
- $params->{variable_accountcode} = $ip_data->{account};
- $params->{'Caller-Destination-Number'} =~ s/$ip_data->{prefix}//g;
- }
-}
+ if ( !$params->{variable_accountcode} ) {
-$ASTPP->debug( debug => "$params->{variable_accountcode}, $params->{'Caller-Destination-Number'}");
+ # First we strip off X digits to see if this account is prepending numbers
+ # as authentications
+ $ASTPP->debug( debug => "Checking CC Number: "
+ . $params->{'Caller-Destination-Number'} );
+ my $cc = substr( $params->{'Caller-Destination-Number'},
+ 0, $config->{cardlength} );
+ my $sql =
+ $astpp_db->prepare("SELECT number FROM accounts WHERE cc = $cc");
+ $sql->execute;
+ my $record = $sql->fetchrow_hashref;
+ $sql->finish;
+ $params->{variable_accountcode} = $record->{cardnum}
+ if ( $record->{cardnum} );
+ }
+ if ( !$params->{variable_accountcode} ) {
+ $ASTPP->debug(
+ debug => "Checking IP Address:" . $params->{network_addr} );
+ my $ip_data = $ASTPP->ip_address_authenticate(
+ ip_address => $params->{network_addr},
+ destination => $params->{'Caller-Destination-Number'}
+ );
+ if ($ip_data) {
+ $params->{variable_accountcode} = $ip_data->{account};
+ $params->{'Caller-Destination-Number'} =~ s/$ip_data->{prefix}//g;
+ }
+ }
-my $carddata = &get_account( $astpp_db, $params->{variable_accountcode} ); # Fetch all the account info from the db.
+ $ASTPP->debug( debug =>
+"$params->{variable_accountcode}, $params->{'Caller-Destination-Number'}"
+ );
-if ( !$carddata->{number} ) { # Check to see if the account exists. If not then exit.
- $ASTPP->debug( debug => "CALLSTATUS 2");
- $ASTPP->debug( debug =>"CANNOT RETRIEVE CARD");
- $xml .= "<action application=\"reject\" data=\"CANNOT RETRIEVE ACCOUNT\"/>\n";
- $xml = $ASTPP->fs_dialplan_xml_footer( xml => $xml);
- print $xml;
- exit(0);
-}
+ my $carddata =
+ &get_account( $astpp_db, $params->{variable_accountcode} )
+ ; # Fetch all the account info from the db.
-if ($carddata->{dialed_modify}) {
- my @regexs = split(m/,/m, $carddata->{dialed_modify});
+ if ( !$carddata->{number} )
+ { # Check to see if the account exists. If not then exit.
+ $ASTPP->debug( debug => "CALLSTATUS 2" );
+ $ASTPP->debug( debug => "CANNOT RETRIEVE CARD" );
+ $xml .=
+ "<action application=\"reject\" data=\"CANNOT RETRIEVE ACCOUNT\"/>\n";
+ $xml = $ASTPP->fs_dialplan_xml_footer( xml => $xml );
+ print $xml;
+ exit(0);
+ }
+
+ if ( $carddata->{dialed_modify} ) {
+ my @regexs = split( m/,/m, $carddata->{dialed_modify} );
foreach my $regex (@regexs) {
- $regex =~ s/"//g; #Strip off quotation marks
- my ($grab,$replace) = split(m!/!i, $regex); # This will split the variable into a "grab" and "replace" as needed
- $ASTPP->debug( debug => "Grab: $grab");
- $ASTPP->debug( debug => "Replacement: $replace");
- $ASTPP->debug( debug => "Phone Before: $params->{'Caller-Destination-Number'}");
- $$params->{'Caller-Destination-Number'} =~ s/$grab/$replace/is;
- $ASTPP->debug( debug => "Phone After: $params->{'Caller-Destination-Number'}" );
+ $regex =~ s/"//g; #Strip off quotation marks
+ my ( $grab, $replace ) = split( m!/!i, $regex )
+ ; # This will split the variable into a "grab" and "replace" as needed
+ $ASTPP->debug( debug => "Grab: $grab" );
+ $ASTPP->debug( debug => "Replacement: $replace" );
+ $ASTPP->debug( debug =>
+ "Phone Before: $params->{'Caller-Destination-Number'}" );
+ $$params->{'Caller-Destination-Number'} =~ s/$grab/$replace/is;
+ $ASTPP->debug( debug =>
+ "Phone After: $params->{'Caller-Destination-Number'}" );
}
}
-$ASTPP->debug( debug => "FINDING LIMIT FOR: " . $carddata->{number});
-($callstatus, $maxlength) = &max_length($astpp_db, $config, $carddata, $params->{'Caller-Destination-Number'});
-my $routeinfo = &get_route( $astpp_db, $config, $params->{'Caller-Destination-Number'}, $carddata->{pricelist},$carddata );
+ $ASTPP->debug( debug => "FINDING LIMIT FOR: " . $carddata->{number} );
+ ( $callstatus, $maxlength ) =
+ &max_length( $astpp_db, $config, $carddata,
+ $params->{'Caller-Destination-Number'} );
+ my $routeinfo = &get_route(
+ $astpp_db, $config,
+ $params->{'Caller-Destination-Number'},
+ $carddata->{pricelist}, $carddata
+ );
-$ASTPP->debug( debug => "Minimum Charge on call = " . $routeinfo->{cost});
-my $minimumcharge = $routeinfo->{cost};
-my @reseller_list;
-$ASTPP->debug( debug => "CALLSTATUS: $callstatus MAX_LENGTH: $maxlength");
-while ( $carddata->{reseller} && $maxlength > 1 && $callstatus == 1) {
- $ASTPP->debug( debug => "FINDING LIMIT FOR: $carddata->{reseller}");
- $carddata = &get_account( $astpp_db, $carddata->{reseller} );
- push @reseller_list, $carddata->{number};
- $ASTPP->debug( debug => "ADDING $carddata->{number} to the list of resellers for this account");
- my ($resellercallstatus, $resellermaxlength) = &max_length($astpp_db, $config, $carddata, $params->{'Caller-Destination-Number'});
- my $routeinfo = &get_route( $astpp_db, $config, $params->{'Caller-Destination-Number'}, $carddata->{pricelist},$carddata );
- if ($resellercallstatus != 1) {
- $carddata->{reseller} = "";
- $callstatus = $resellercallstatus;
- } elsif ($resellermaxlength < $maxlength) {
- $maxlength = $resellermaxlength;
- }
- $ASTPP->debug( debug => "Reseller cost = $routeinfo->{cost} and minimum charge is $minimumcharge");
- if ($resellermaxlength < 1 || $routeinfo->{cost} > $minimumcharge ) {
- $ASTPP->debug( debug => "Reseller call is priced too cheap! Call being barred!");
- $xml .= "<action application=\"reject\" data=\"Reseller call is priced too cheap! Call being barred!\"/>\n";
- $xml = $ASTPP->fs_dialplan_xml_footer( xml => $xml);
- print $xml;
- exit(0);
- }
- $ASTPP->debug( debug => "RESELLER Max Length: $resellermaxlength");
- $ASTPP->debug( debug => "RESELLER Call Status: $resellercallstatus");
-}
+ $ASTPP->debug( debug => "Minimum Charge on call = " . $routeinfo->{cost} );
+ my $minimumcharge = $routeinfo->{cost};
+ my @reseller_list;
+ $ASTPP->debug( debug => "CALLSTATUS: $callstatus MAX_LENGTH: $maxlength" );
+ while ( $carddata->{reseller} && $maxlength > 1 && $callstatus == 1 ) {
+ $ASTPP->debug( debug => "FINDING LIMIT FOR: $carddata->{reseller}" );
+ $carddata = &get_account( $astpp_db, $carddata->{reseller} );
+ push @reseller_list, $carddata->{number};
+ $ASTPP->debug( debug =>
+"ADDING $carddata->{number} to the list of resellers for this account"
+ );
+ my ( $resellercallstatus, $resellermaxlength ) =
+ &max_length( $astpp_db, $config, $carddata,
+ $params->{'Caller-Destination-Number'} );
+ my $routeinfo = &get_route(
+ $astpp_db, $config,
+ $params->{'Caller-Destination-Number'},
+ $carddata->{pricelist}, $carddata
+ );
+ if ( $resellercallstatus != 1 ) {
+ $carddata->{reseller} = "";
+ $callstatus = $resellercallstatus;
+ }
+ elsif ( $resellermaxlength < $maxlength ) {
+ $maxlength = $resellermaxlength;
+ }
+ $ASTPP->debug( debug =>
+"Reseller cost = $routeinfo->{cost} and minimum charge is $minimumcharge"
+ );
+ if ( $resellermaxlength < 1 || $routeinfo->{cost} > $minimumcharge ) {
+ $ASTPP->debug( debug =>
+ "Reseller call is priced too cheap! Call being barred!" );
+ $xml .=
+"<action application=\"reject\" data=\"Reseller call is priced too cheap! Call being barred!\"/>\n";
+ $xml = $ASTPP->fs_dialplan_xml_footer( xml => $xml );
+ print $xml;
+ exit(0);
+ }
+ $ASTPP->debug( debug => "RESELLER Max Length: $resellermaxlength" );
+ $ASTPP->debug( debug => "RESELLER Call Status: $resellercallstatus" );
+ }
-if ($config->{debug} == 1) {
- $ASTPP->debug( debug => "PRINTING LIST OF RESELLERS FOR THIS ACCOUNT" );
- foreach my $reseller (@reseller_list) {
- $ASTPP->debugb( debug => "RESELLER: $reseller" );
- }
-}
+ if ( $config->{debug} == 1 ) {
+ $ASTPP->debug( debug => "PRINTING LIST OF RESELLERS FOR THIS ACCOUNT" );
+ foreach my $reseller (@reseller_list) {
+ $ASTPP->debugb( debug => "RESELLER: $reseller" );
+ }
+ }
-$ASTPP->debug( "Max Call Length: $maxlength minutes" );
-$ASTPP->debug( "Call Status: $callstatus" );
+ $ASTPP->debug("Max Call Length: $maxlength minutes");
+ $ASTPP->debug("Call Status: $callstatus");
-if ( $maxlength <= 1 ) {
- $ASTPP->debug( debug => "NOT ENOUGH CREDIT" );
- $xml .= "<action application=\"reject\" data=\"NOT ENOUGH CREDIT\"/>\n";
- $xml = $ASTPP->fs_dialplan_xml_footer( xml => $xml);
- print $xml;
- exit(0);
-}
+ if ( $maxlength <= 1 ) {
+ $ASTPP->debug( debug => "NOT ENOUGH CREDIT" );
+ $xml .= "<action application=\"reject\" data=\"NOT ENOUGH CREDIT\"/>\n";
+ $xml = $ASTPP->fs_dialplan_xml_footer( xml => $xml );
+ print $xml;
+ exit(0);
+ }
-$xml = $ASTPP->fs_dialplan_xml_timelimit( xml => $xml, max_length => $maxlength);
+ $xml = $ASTPP->fs_dialplan_xml_timelimit(
+ xml => $xml,
+ max_length => $maxlength
+ );
+
# Set the timelimit as well as other variables which are needed in the dialplan.
-my $timelimit = "L(" . sprintf( "%.0f", $maxlength * 60 * 1000 ) . ":60000:30000)";
+ my $timelimit =
+ "L(" . sprintf( "%.0f", $maxlength * 60 * 1000 ) . ":60000:30000)";
-$ASTPP->debug( debug => "Looking for outbound Route" );
-my $routeinfo = &get_route($astpp_db,$config,$params->{'Caller-Destination-Number'},$carddata->{pricelist},$carddata);
-# Get the list of routes for the phone number.
-my @outboundroutes = &get_outbound_routes( $astpp_db, $params->{'Caller-Destination-Number'},$carddata,$routeinfo, @reseller_list );
-foreach my $route (@outboundroutes) {
- $ASTPP->debug( debug => "$route->{trunk}: cost $route->{cost}\t $route->{pattern}" );
- if ($route->{cost} > $routeinfo->{cost}) {
- $ASTPP->debug( debug => "$route->{trunk}: $route->{cost} > $routeinfo->{cost}, skipping" );
- } else {
- $xml .= $ASTPP->fs_dialplan_xml_bridge( destination_number => $params->{'Caller-Destination-Number'},
- route_prepend => $route->{prepend},
- trunk_name => $route->{trunk});
- }
+ $ASTPP->debug( debug => "Looking for outbound Route" );
+ my $routeinfo = &get_route(
+ $astpp_db, $config,
+ $params->{'Caller-Destination-Number'},
+ $carddata->{pricelist}, $carddata
+ );
+
+ # Get the list of routes for the phone number.
+ my @outboundroutes =
+ &get_outbound_routes( $astpp_db, $params->{'Caller-Destination-Number'},
+ $carddata, $routeinfo, @reseller_list );
+ foreach my $route (@outboundroutes) {
+ $ASTPP->debug( debug =>
+ "$route->{trunk}: cost $route->{cost}\t $route->{pattern}" );
+ if ( $route->{cost} > $routeinfo->{cost} ) {
+ $ASTPP->debug( debug =>
+"$route->{trunk}: $route->{cost} > $routeinfo->{cost}, skipping"
+ );
+ }
+ else {
+ $xml .= $ASTPP->fs_dialplan_xml_bridge(
+ destination_number => $params->{'Caller-Destination-Number'},
+ route_prepend => $route->{prepend},
+ trunk_name => $route->{trunk}
+ );
+ }
+ }
+ $xml = $ASTPP->fs_dialplan_xml_footer( xml => $xml );
}
-$xml = $ASTPP->fs_dialplan_xml_footer( xml => $xml);
-} elsif ($params->{section} eq "directory") {
-#hostname darren-laptop
-#section directory
-#tag_name domain
-#key_name name
-#key_value 192.168.2.119
-#action sip_auth
-#sip_profile internal
-#sip_user_agent Zoiper rev.1118
-#sip_auth_username 1000
-#sip_auth_realm 192.168.2.119
-#sip_auth_nonce 83005e62-7e13-11dd-9eb1-25560b0691a8
-#sip_auth_uri sip:192.168.2.119;transport=UDP
-#sip_auth_qop auth
-#sip_auth_cnonce a79169d2656f292a
-#sip_auth_nc 00000001
-#sip_auth_response 4475154556879ec2017978f1347192a6
-#sip_auth_method REGISTER
-#key id
-#user 1000
-#domain 192.168.2.119
-#ip 192.168.2.119
+elsif ( $params->{section} eq "directory" ) {
- $xml = $ASTPP->fs_directory_xml_header( xml => $xml);
- $xml = $ASTPP->fs_directory_xml( xml => $xml, ip => $params->{'ip'},user=> $params->{'user'},domain=> $params->{'domain'});
- $xml = $ASTPP->fs_directory_xml_footer( xml => $xml);
+ #hostname darren-laptop
+ #section directory
+ #tag_name domain
+ #key_name name
+ #key_value 192.168.2.119
+ #action sip_auth
+ #sip_profile internal
+ #sip_user_agent Zoiper rev.1118
+ #sip_auth_username 1000
+ #sip_auth_realm 192.168.2.119
+ #sip_auth_nonce 83005e62-7e13-11dd-9eb1-25560b0691a8
+ #sip_auth_uri sip:192.168.2.119;transport=UDP
+ #sip_auth_qop auth
+ #sip_auth_cnonce a79169d2656f292a
+ #sip_auth_nc 00000001
+ #sip_auth_response 4475154556879ec2017978f1347192a6
+ #sip_auth_method REGISTER
+ #key id
+ #user 1000
+ #domain 192.168.2.119
+ #ip 192.168.2.119
+
+ $xml = $ASTPP->fs_directory_xml_header( xml => $xml );
+ $xml = $ASTPP->fs_directory_xml(
+ xml => $xml,
+ ip => $params->{'ip'},
+ user => $params->{'user'},
+ domain => $params->{'domain'}
+ );
+ $xml = $ASTPP->fs_directory_xml_footer( xml => $xml );
}
-$ASTPP->debug( debug => $xml);
+$ASTPP->debug( debug => $xml );
print $xml;
exit(0);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|