[freeside-commits] branch FREESIDE_2_3_BRANCH updated. 6ebc73c81b2b4d9524c2a4899629dc6c14ed341d

Ivan ivan at 420.am
Thu Jan 10 00:06:42 PST 2013


The branch, FREESIDE_2_3_BRANCH has been updated
       via  6ebc73c81b2b4d9524c2a4899629dc6c14ed341d (commit)
      from  cf7d2244c6f0c9395397bf98a9b2fa2799f3f491 (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 6ebc73c81b2b4d9524c2a4899629dc6c14ed341d
Author: Ivan Kohler <ivan at freeside.biz>
Date:   Thu Jan 10 00:06:37 2013 -0800

    add blacklist/whitelist settings to self-service API, RT#20896

diff --git a/FS/FS/ClientAPI/MyAccount.pm b/FS/FS/ClientAPI/MyAccount.pm
index 8cd7bce..8b840fc 100644
--- a/FS/FS/ClientAPI/MyAccount.pm
+++ b/FS/FS/ClientAPI/MyAccount.pm
@@ -1770,6 +1770,44 @@ sub set_svc_status_hash {
 
 }
 
+sub set_svc_status_listadd {
+  my $p = shift;
+
+  my($context, $session, $custnum) = _custoragent_session_custnum($p);
+  return { 'error' => $session } if $context eq 'error';
+
+  #XXX only svc_acct for now
+  my $svc_x = _customer_svc_x( $custnum, $p->{'svcnum'}, 'svc_acct')
+    or return { 'error' => "Service not found" };
+
+  warn "set_svc_status_listadd ". join(' / ', map "$_=>".$p->{$_}, keys %$p )
+    if $DEBUG;
+  my $error = $svc_x->export_setstatus_listadd($p); #$p? returns error?
+  return { 'error' => $error } if $error;
+
+  return {}; #? { 'error' => '' }
+
+}
+
+sub set_svc_status_listdel {
+  my $p = shift;
+
+  my($context, $session, $custnum) = _custoragent_session_custnum($p);
+  return { 'error' => $session } if $context eq 'error';
+
+  #XXX only svc_acct for now
+  my $svc_x = _customer_svc_x( $custnum, $p->{'svcnum'}, 'svc_acct')
+    or return { 'error' => "Service not found" };
+
+  warn "set_svc_status_listdel ". join(' / ', map "$_=>".$p->{$_}, keys %$p )
+    if $DEBUG;
+  my $error = $svc_x->export_setstatus_listdel($p); #$p? returns error?
+  return { 'error' => $error } if $error;
+
+  return {}; #? { 'error' => '' }
+
+}
+
 
 sub acct_forward_info {
   my $p = shift;
diff --git a/FS/FS/ClientAPI_XMLRPC.pm b/FS/FS/ClientAPI_XMLRPC.pm
index 7e81996..9792ebb 100644
--- a/FS/FS/ClientAPI_XMLRPC.pm
+++ b/FS/FS/ClientAPI_XMLRPC.pm
@@ -129,6 +129,8 @@ sub ss2clientapi {
   'svc_status_html'           => 'MyAccount/svc_status_html',
   'svc_status_hash'           => 'MyAccount/svc_status_hash',
   'set_svc_status_hash'       => 'MyAccount/set_svc_status_hash',
+  'set_svc_status_listadd'    => 'MyAccount/set_svc_status_listadd',
+  'set_svc_status_listdel'    => 'MyAccount/set_svc_status_listdel',
   'acct_forward_info'         => 'MyAccount/acct_forward_info',
   'process_acct_forward'      => 'MyAccount/process_acct_forward',
   'list_dsl_devices'          => 'MyAccount/list_dsl_devices',   
diff --git a/FS/FS/part_export/http_status.pm b/FS/FS/part_export/http_status.pm
index 5342106..62ad4b2 100644
--- a/FS/FS/part_export/http_status.pm
+++ b/FS/FS/part_export/http_status.pm
@@ -3,27 +3,41 @@ use base qw( FS::part_export );
 
 use strict;
 use warnings;
-use vars qw( %info );
+use vars qw( %info $DEBUG );
 use LWP::UserAgent;
 use HTTP::Request::Common;
+use Email::Valid;
 
 tie my %options, 'Tie::IxHash',
   'url' => { label => 'URL', },
+  'blacklist_add_url' => { label => 'Optional blacklist add URL', },
+  'blacklist_del_url' => { label => 'Optional blacklist delete URL', },
+  'whitelist_add_url' => { label => 'Optional whitelist add URL', },
+  'whitelist_del_url' => { label => 'Optional whitelist delete URL', },
   #'user'     => { label => 'Username', default=>'' },
   #'password' => { label => 'Password', default => '' },
 ;
 
 %info = (
-  'svc'     => 'svc_dsl',
+  'svc'     => [ 'svc_acct', 'svc_dsl', ],
   'desc'    => 'Retrieve status information via HTTP or HTTPS',
   'options' => \%options,
   'notes'   => <<'END'
 Fields from the service can be substituted in the URL as $field.
+
+Optionally, spam black/whitelist addresses may be via HTTP or HTTPS as well.
 END
 );
 
+$DEBUG = 0;
+
 sub rebless { shift; }
 
+our %addl_fields = (
+  'svc_acct' => [qw( email ) ],
+  'svc_dsl'  => [qw( gateway_access_or_phonenum ) ],
+);
+
 sub export_getstatus {
   my( $self, $svc_x, $htmlref, $hashref ) = @_;
 
@@ -33,10 +47,85 @@ sub export_getstatus {
   {
     no strict 'refs';
     ${$_} = $svc_x->getfield($_) foreach $svc_x->fields;
-    if ( $svc_x->table eq 'svc_dsl' ) {
-      ${$_} = $svc_x->$_() foreach (qw( gateway_access_or_phonenum ));
+    ${$_} = $svc_x->$_()         foreach @{ $addl_fields{ $svc_x->table } };
+    $url = eval(qq("$urlopt"));
+  }
+
+  my $req = HTTP::Request::Common::GET( $url );
+  my $ua = LWP::UserAgent->new;
+  my $response = $ua->request($req);
+
+  if ( $svc_x->table eq 'svc_dsl' ) {
+
+    $$htmlref = $response->is_error ? $response->error_as_HTML
+                                    : $response->content;
+
+    #hash data not yet implemented for svc_dsl
+
+  } elsif ( $svc_x->table eq 'svc_acct' ) {
+
+    #this whole section is rather specific to fibernetics and should be an
+    # option or callback or something
+
+    # to,from,wb_value
+
+    use Text::CSV_XS;
+    my $csv = Text::CSV_XS->new;
+
+    my @lines = split("\n", $response->content);
+    pop @lines if $lines[-1] eq '';
+    my $header = shift @lines;
+    $csv->parse($header) or return;
+    my @header = $csv->fields;
+
+    while ( my $line = shift @lines ) {
+      $csv->parse($line) or next;
+      my @fields = $csv->fields;
+      my %hash = map { $_ => shift(@fields) } @header;
+
+      if ( $hash{'wb_value'} =~ /^[WA]/i ) { #Whitelist/Allow
+        push @{ $hashref->{'whitelist'} }, $hash{'from'};
+      } else { # if ( $hash{'wb_value'} =~ /^[BD]/i ) { #Blacklist/Deny
+        push @{ $hashref->{'blacklist'} }, $hash{'from'};
+      }
     }
 
+  } #else { die 'guru meditation #295'; }
+
+}
+
+sub export_setstatus_listadd {
+  my( $self, $svc_x, $hr ) = @_;
+  $self->export_setstatus_listX( $svc_x, 'add', $hr->{list}, $hr->{address} );
+}
+
+sub export_setstatus_listdel {
+  my( $self, $svc_x, $hr ) = @_;
+  $self->export_setstatus_listX( $svc_x, 'del', $hr->{list}, $hr->{address} );
+}
+
+sub export_setstatus_listX {
+  my( $self, $svc_x, $action, $list, $address ) = @_;
+
+  my $option;
+  if ( $list =~ /^[WA]/i ) { #Whitelist/Allow
+    $option = 'whitelist_';
+  } else { # if ( $hash{'wb_value'} =~ /^[BD]/i ) { #Blacklist/Deny
+    $option = 'blacklist_';
+  }
+  $option .= $action. '_url';
+
+  $address = Email::Valid->address($address)
+    or die "address failed $Email::Valid::Details check.\n";
+
+  #some false laziness w/export_getstatus above
+  my $url;
+  my $urlopt = $self->option($option) or return; #DIFF
+  no strict 'vars';
+  {
+    no strict 'refs';
+    ${$_} = $svc_x->getfield($_) foreach $svc_x->fields;
+    ${$_} = $svc_x->$_()         foreach @{ $addl_fields{ $svc_x->table } };
     $url = eval(qq("$urlopt"));
   }
 
@@ -44,11 +133,10 @@ sub export_getstatus {
   my $ua = LWP::UserAgent->new;
   my $response = $ua->request($req);
 
-  $$htmlref = $response->is_error ? $response->error_as_HTML
-                                  : $response->content;
-
-  #hash data note yet implemented for this status export
+  die $response->code. ' '. $response->message if $response->is_error;
 
 }
 
 1;
+
+1;
diff --git a/FS/FS/svc_Common.pm b/FS/FS/svc_Common.pm
index a6daf44..19feb49 100644
--- a/FS/FS/svc_Common.pm
+++ b/FS/FS/svc_Common.pm
@@ -1052,6 +1052,25 @@ sub export_setstatus {
   '';
 }
 
+sub export_setstatus_listadd {
+  my( $self, @args ) = @_;
+  my $error = $self->export('setstatus_listadd', @args);
+  if ( $error ) {
+    warn "error running export_setstatus: $error";
+    return $error;
+  }
+  '';
+}
+
+sub export_setstatus_listdel {
+  my( $self, @args ) = @_;
+  my $error = $self->export('setstatus_listdel', @args);
+  if ( $error ) {
+    warn "error running export_setstatus: $error";
+    return $error;
+  }
+  '';
+}
 
 =item export HOOK [ EXPORT_ARGS ]
 
diff --git a/fs_selfservice/FS-SelfService/SelfService.pm b/fs_selfservice/FS-SelfService/SelfService.pm
index bbc34bb..fc8ca08 100644
--- a/fs_selfservice/FS-SelfService/SelfService.pm
+++ b/fs_selfservice/FS-SelfService/SelfService.pm
@@ -57,6 +57,8 @@ $socket .= '.'.$tag if defined $tag && length($tag);
   'svc_status_html'           => 'MyAccount/svc_status_html',
   'svc_status_hash'           => 'MyAccount/svc_status_hash',
   'set_svc_status_hash'       => 'MyAccount/set_svc_status_hash',
+  'set_svc_status_listadd'    => 'MyAccount/set_svc_status_listadd',
+  'set_svc_status_listdel'    => 'MyAccount/set_svc_status_listdel',
   'acct_forward_info'         => 'MyAccount/acct_forward_info',
   'process_acct_forward'      => 'MyAccount/process_acct_forward',
   'list_dsl_devices'          => 'MyAccount/list_dsl_devices',   
diff --git a/httemplate/view/elements/svc_export_status.html b/httemplate/view/elements/svc_export_status.html
index d96bb27..4ce869e 100644
--- a/httemplate/view/elements/svc_export_status.html
+++ b/httemplate/view/elements/svc_export_status.html
@@ -7,7 +7,15 @@
 %     foreach my $key ( sort {$a cmp $b} keys %$hashref ) {
         <TR>
           <TD ALIGN="right"><% $key |h %></TD>
-          <TD BGCOLOR="#ffffff"><% $hashref->{$key} |h %></TD>
+          <TD BGCOLOR="#ffffff">
+%           if ( ref($hashref->{$key}) eq 'ARRAY' ) {
+%             foreach (@{ $hashref->{$key} }) {
+                <% $_ |h %><BR>
+%             }
+%           } else {
+              <% $hashref->{$key} |h %>
+%           }
+          </TD>
         </TR>
 %     }
 

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

Summary of changes:
 FS/FS/ClientAPI/MyAccount.pm                    |   38 ++++++++
 FS/FS/ClientAPI_XMLRPC.pm                       |    2 +
 FS/FS/part_export/http_status.pm                |  104 +++++++++++++++++++++--
 FS/FS/svc_Common.pm                             |   19 ++++
 fs_selfservice/FS-SelfService/SelfService.pm    |    2 +
 httemplate/view/elements/svc_export_status.html |   10 ++-
 6 files changed, 166 insertions(+), 9 deletions(-)




More information about the freeside-commits mailing list