[freeside-commits] branch FREESIDE_3_BRANCH updated. f5935488fe25773db20f376150e24e35a123870a

Mark Wells mark at 420.am
Mon Aug 22 11:49:22 PDT 2016


The branch, FREESIDE_3_BRANCH has been updated
       via  f5935488fe25773db20f376150e24e35a123870a (commit)
       via  6949aa3633144ecf786bfa35355978d723b3c75e (commit)
       via  e91e8093159d6e309ffa47d3694faca068d7daa4 (commit)
      from  189524c12d69394769d3e88a18d6777a68ac6064 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit f5935488fe25773db20f376150e24e35a123870a
Author: Mark Wells <mark at freeside.biz>
Date:   Mon Aug 22 11:48:11 2016 -0700

    relax SSL verification on LRN lookup, #71955

diff --git a/FS/FS/cdr.pm b/FS/FS/cdr.pm
index 756bc77..7c32090 100644
--- a/FS/FS/cdr.pm
+++ b/FS/FS/cdr.pm
@@ -28,6 +28,7 @@ use FS::rate_detail;
 # LRN lookup
 use LWP::UserAgent;
 use HTTP::Request::Common qw(POST);
+use IO::Socket::SSL;
 use JSON::XS qw(decode_json);
 
 @ISA = qw(FS::Record);
@@ -1498,7 +1499,13 @@ sub get_lrn {
   my $self = shift;
   my $field = shift;
 
-  my $ua = LWP::UserAgent->new;
+  my $ua = LWP::UserAgent->new(
+             'ssl_opts' => {
+               verify_hostname => 0,
+               SSL_verify_mode => IO::Socket::SSL::SSL_VERIFY_NONE,
+             },
+           );
+
   my $url = 'https://ws.freeside.biz/get_lrn';
 
   my %content = ( 'support-key' => $support_key,

commit 6949aa3633144ecf786bfa35355978d723b3c75e
Author: Mark Wells <mark at freeside.biz>
Date:   Mon Aug 22 11:24:21 2016 -0700

    backport fix, #71955

diff --git a/FS/FS/cdr.pm b/FS/FS/cdr.pm
index 155090d..756bc77 100644
--- a/FS/FS/cdr.pm
+++ b/FS/FS/cdr.pm
@@ -28,7 +28,7 @@ use FS::rate_detail;
 # LRN lookup
 use LWP::UserAgent;
 use HTTP::Request::Common qw(POST);
-use Cpanel::JSON::XS qw(decode_json);
+use JSON::XS qw(decode_json);
 
 @ISA = qw(FS::Record);
 @EXPORT_OK = qw( _cdr_date_parser_maker _cdr_min_parser_maker );

commit e91e8093159d6e309ffa47d3694faca068d7daa4
Author: Mark Wells <mark at freeside.biz>
Date:   Wed Aug 10 14:53:13 2016 -0700

    look up LRNs for more accurate call rating, #71955

diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm
index d09212d..bf21a1b 100644
--- a/FS/FS/Conf.pm
+++ b/FS/FS/Conf.pm
@@ -5953,6 +5953,13 @@ and customer address. Include units.',
       'rate_low'  => 'Lowest rate first',
     ],
   },
+
+  {
+    'key'         => 'cdr-lrn_lookup',
+    'section'     => 'telephony',
+    'description' => 'Look up LRNs of destination numbers for exact matching to the terminating carrier. This feature requires a Freeside support contract.',
+    'type'        => 'checkbox',
+  },
   
   {
     'key'         => 'brand-agent',
diff --git a/FS/FS/Schema.pm b/FS/FS/Schema.pm
index fef0ec7..58ef933 100644
--- a/FS/FS/Schema.pm
+++ b/FS/FS/Schema.pm
@@ -3874,6 +3874,10 @@ sub tables_hashref {
         'rated_ratename',         'varchar', 'NULL', $char_d, '', '', 
         'rated_cost',            'decimal', 'NULL',  '10,4', '', '',
 
+        # real endpoints of the call
+        'src_lrn',             'varchar', 'NULL',     '15', '', '',
+        'dst_lrn',             'varchar', 'NULL',     '15', '', '',
+
         'carrierid',               'bigint', 'NULL',      '', '', '',
 
         # service it was matched to
diff --git a/FS/FS/cdr.pm b/FS/FS/cdr.pm
index 4d4c767..155090d 100644
--- a/FS/FS/cdr.pm
+++ b/FS/FS/cdr.pm
@@ -3,6 +3,7 @@ package FS::cdr;
 use strict;
 use vars qw( @ISA @EXPORT_OK $DEBUG $me
              $conf $cdr_prerate %cdr_prerate_cdrtypenums
+             $use_lrn $support_key
            );
 use Exporter;
 use List::Util qw(first min);
@@ -24,6 +25,11 @@ use FS::rate;
 use FS::rate_prefix;
 use FS::rate_detail;
 
+# LRN lookup
+use LWP::UserAgent;
+use HTTP::Request::Common qw(POST);
+use Cpanel::JSON::XS qw(decode_json);
+
 @ISA = qw(FS::Record);
 @EXPORT_OK = qw( _cdr_date_parser_maker _cdr_min_parser_maker );
 
@@ -39,6 +45,10 @@ FS::UID->install_callback( sub {
   @cdr_prerate_cdrtypenums = $conf->config('cdr-prerate-cdrtypenums')
     if $cdr_prerate;
   %cdr_prerate_cdrtypenums = map { $_=>1 } @cdr_prerate_cdrtypenums;
+
+  $support_key = $conf->config('support-key');
+  $use_lrn = $conf->exists('cdr-lrn_lookup');
+
 });
 
 =head1 NAME
@@ -215,6 +225,8 @@ sub table_info {
         'upstream_price'        => 'Upstream price',
         #'upstream_rateplanid'   => '',
         #'ratedetailnum'         => '',
+        'src_lrn'               => 'Source LRN',
+        'dst_lrn'               => 'Dest. LRN',
         'rated_price'           => 'Rated price',
         'rated_cost'            => 'Rated cost',
         #'distance'              => '',
@@ -687,9 +699,6 @@ sub rate_prefix {
     }
   }
 
-    
-
-
   ###
   # look up rate details based on called station id
   # (or calling station id for toll free calls)
@@ -723,13 +732,32 @@ sub rate_prefix {
     domestic_prefix => $part_pkg->option_cacheable('domestic_prefix'),
   );
 
+  my $ratename = '';
+  my $intrastate_ratenum = $part_pkg->option_cacheable('intrastate_ratenum');
+
+  if ( $use_lrn and $countrycode eq '1' ) {
+
+    # then ask about the number
+    foreach my $field ('src', 'dst') {
+
+      $self->get_lrn($field);
+      if ( $field eq $column ) {
+        # then we are rating on this number
+        $number = $self->get($field.'_lrn');
+        $number =~ s/^1//;
+        # is this ever meaningful? can the LRN be outside NANP space?
+      }
+
+    } # foreach $field
+
+  }
+
   warn "rating call $to_or_from +$countrycode $number\n" if $DEBUG;
   my $pretty_dst = "+$countrycode $number";
   #asterisks here causes inserting the detail to barf, so:
   $pretty_dst =~ s/\*//g;
 
-  my $ratename = '';
-  my $intrastate_ratenum = $part_pkg->option_cacheable('intrastate_ratenum');
+  # should check $countrycode eq '1' here?
   if ( $intrastate_ratenum && !$self->is_tollfree ) {
     $ratename = 'Interstate'; #until proven otherwise
     # this is relatively easy only because:
@@ -738,8 +766,10 @@ sub rate_prefix {
     # -disregard private or unknown numbers
     # -there is exactly one record in rate_prefix for a given NPANXX
     # -default to interstate if we can't find one or both of the prefixes
+    my $dst_col = $use_lrn ? 'dst_lrn' : 'dst';
+    my $src_col = $use_lrn ? 'src_lrn' : 'src';
     my (undef, $dstprefix) = $self->parse_number(
-      column => 'dst',
+      column => $dst_col,
       international_prefix => $part_pkg->option_cacheable('international_prefix'),
       domestic_prefix => $part_pkg->option_cacheable('domestic_prefix'),
     );
@@ -748,7 +778,7 @@ sub rate_prefix {
                                                 'npa' => $1, 
                                          }) || '';
     my (undef, $srcprefix) = $self->parse_number(
-      column => 'src',
+      column => $src_col,
       international_prefix => $part_pkg->option_cacheable('international_prefix'),
       domestic_prefix => $part_pkg->option_cacheable('domestic_prefix'),
     );
@@ -1464,6 +1494,38 @@ sub downstream_csv {
 
 }
 
+sub get_lrn {
+  my $self = shift;
+  my $field = shift;
+
+  my $ua = LWP::UserAgent->new;
+  my $url = 'https://ws.freeside.biz/get_lrn';
+
+  my %content = ( 'support-key' => $support_key,
+                  'tn' => $self->get($field),
+                );
+  my $response = $ua->request( POST $url, \%content );
+
+  die "LRN service error: ". $response->message. "\n"
+    unless $response->is_success;
+
+  local $@;
+  my $data = eval { decode_json($response->content) };
+  die "LRN service JSON error : $@\n" if $@;
+
+  if ($data->{error}) {
+    die "acctid ".$self->acctid." $field LRN lookup failed:\n$data->{error}";
+    # for testing; later we should respect ignore_unrateable
+  } elsif ($data->{lrn}) {
+    # normal case
+    $self->set($field.'_lrn', $data->{lrn});
+  } else {
+    die "acctid ".$self->acctid." $field LRN lookup returned no number.\n";
+  }
+
+  return $data; # in case it's interesting somehow
+}
+ 
 =back
 
 =head1 CLASS METHODS

-----------------------------------------------------------------------

Summary of changes:
 FS/FS/Conf.pm   |    7 +++++
 FS/FS/Schema.pm |    4 +++
 FS/FS/cdr.pm    |   83 ++++++++++++++++++++++++++++++++++++++++++++++++++-----
 3 files changed, 87 insertions(+), 7 deletions(-)




More information about the freeside-commits mailing list