communigate phase 3: RPOP/acct_snarf, RT#7515
authorivan <ivan>
Sat, 7 Aug 2010 07:39:07 +0000 (07:39 +0000)
committerivan <ivan>
Sat, 7 Aug 2010 07:39:07 +0000 (07:39 +0000)
FS/FS/Mason.pm
FS/FS/Schema.pm
FS/FS/acct_snarf.pm
httemplate/browse/acct_snarf.html [new file with mode: 0644]
httemplate/edit/acct_snarf.html [new file with mode: 0644]
httemplate/edit/process/acct_snarf.html [new file with mode: 0644]
httemplate/view/svc_acct/communigate.html

index 8a617cc..34e3ae6 100644 (file)
@@ -231,6 +231,7 @@ if ( -e $addl_handler_use_file ) {
   use FS::cgp_rule_action;
   use FS::msg_template;
   use FS::part_tag;
+  use FS::acct_snarf;
   # Sammath Naur
 
   if ( $FS::Mason::addl_handler_use ) {
index e8492ca..e858d31 100644 (file)
@@ -2004,12 +2004,18 @@ sub tables_hashref {
 
     'acct_snarf' => {
       'columns' => [
-        'snarfnum',  'int', '', '', '', '', 
-        'svcnum',    'int', '', '', '', '', 
-        'machine',   'varchar', '', 255, '', '', 
-        'protocol',  'varchar', '', $char_d, '', '', 
-        'username',  'varchar', '', $char_d, '', '', 
-        '_password', 'varchar', '', $char_d, '', '', 
+        'snarfnum',    'serial',     '',      '', '', '', 
+        'snarfname',  'varchar', 'NULL', $char_d, '', '', 
+        'svcnum',         'int',     '',      '', '', '', 
+        'machine',    'varchar',     '',     255, '', '', 
+        'protocol',   'varchar',     '', $char_d, '', '', 
+        'username',   'varchar',     '', $char_d, '', '', 
+        '_password',  'varchar',     '', $char_d, '', '', 
+        'check_freq',     'int', 'NULL',      '', '', '', 
+        'leave',         'char', 'NULL',       1, '', '', 
+        'apop',          'char', 'NULL',       1, '', '', 
+        'tls',           'char', 'NULL',       1, '', '', 
+        'mailbox',    'varchar', 'NULL', $char_d, '', '', 
       ],
       'primary_key' => 'snarfnum',
       'unique' => [],
index b4e88bf..fb26cea 100644 (file)
@@ -2,6 +2,7 @@ package FS::acct_snarf;
 
 use strict;
 use vars qw( @ISA );
+use Tie::IxHash;
 use FS::Record;
 
 @ISA = qw( FS::Record );
@@ -35,6 +36,8 @@ fields are currently supported:
 
 =item snarfnum - primary key
 
+=item snarfname - Label
+
 =item svcnum - Account (see L<FS::svc_acct>)
 
 =item machine - external machine to download mail from
@@ -100,11 +103,17 @@ sub check {
   my $self = shift;
   my $error =
        $self->ut_numbern('snarfnum')
+    || $self->ut_textn('snarfname') #alphasn?
     || $self->ut_number('svcnum')
     || $self->ut_foreign_key('svcnum', 'svc_acct', 'svcnum')
     || $self->ut_domain('machine')
     || $self->ut_alphan('protocol')
     || $self->ut_textn('username')
+    || $self->ut_numbern('check_freq')
+    || $self->ut_enum('leave', [ '', 'Y' ])
+    || $self->ut_enum('apop', [ '', 'Y' ])
+    || $self->ut_enum('tls', [ '', 'Y' ])
+    || $self->ut_alphan('mailbox')
   ;
   return $error if $error;
 
@@ -114,6 +123,32 @@ sub check {
   ''; #no error
 }
 
+sub check_freq_labels {
+
+  tie my %hash, 'Tie::IxHash',
+    0 => 'Never',
+    60 => 'minute',
+    120 => '2 minutes',
+    180 => '3 minutes',
+    300 => '5 minutes',
+    600 => '10 minutes',
+    900 => '15 minutes',
+    1800 => '30 minutes',
+    3600 => 'hour',
+    7200 => '2 hours',
+    10800 => '3 hours',
+    21600 => '6 hours',
+    43200 => '12 hours',
+    86400 => 'day',
+    172800 => '2 days',
+    259200 => '3 days',
+    604800 => 'week',
+    1000000000 => 'Disabled',
+  ;
+
+  \%hash;
+}
+
 =back
 
 =head1 BUGS
diff --git a/httemplate/browse/acct_snarf.html b/httemplate/browse/acct_snarf.html
new file mode 100644 (file)
index 0000000..f610994
--- /dev/null
@@ -0,0 +1,78 @@
+<% include('elements/browse.html',
+             'title'         => "Remote POP accounts for $svc_label: $svc_value",
+             'name_singular' => 'Remote POP account',
+             'html_init'     => $html_init,
+             'query'         => { 'table'   => 'acct_snarf',
+                                  'hashref' => { 'svcnum' => $svcnum },
+                                  #'order_by' => 'ORDER BY priority DESC',
+                                },
+             'count_query'   => $count_query,
+             'header'        => [ 'Name',
+                                  'Mail server',
+                                  'Username',
+                                  #'Password',
+                                  'Poll every',
+                                  #'Options',
+                                  'Leave',
+                                  'APOP',
+                                  'TLS',
+                                  'Mailbox',
+                                  '', #delete
+                                ],
+             'fields'        => [ 'snarfname',
+                                  'machine',
+                                  'username',
+                                  sub { FS::acct_snarf->check_freq_labels->{shift->check_freq} },
+                                  'leave',
+                                  'apop',
+                                  'tls',
+                                  'mailbox',
+                                ],
+             #'align'
+             'links'         => [ $edit_sub, $edit_sub, $edit_sub, '',
+                                  '', '', '', '', $del_sub ],
+          )
+%>
+<%init>
+
+$cgi->param('svcnum') =~ /^(\d+)$/ or die 'no svcnum';
+my $svcnum = $1;
+
+#agent virt so you can't do cross-agent snarfing
+my $cust_svc = qsearchs('cust_svc', { 'svcnum' => $svcnum })
+  or die 'unknown svcnum';
+my $part_svc = $cust_svc->part_svc;
+
+my $count_query = "SELECT COUNT(*) FROM acct_snarf WHERE svcnum = $svcnum";
+
+my($svc_label, $svc_value, $svcdb) = $cust_svc->label;
+
+my $view = FS::UI::Web::svc_url( 'm'        => $m,
+                                 'action'   => 'view',
+                                 'part_svc' => $part_svc, 
+                                 'svc'      => $cust_svc,
+                               );
+
+my $html_init =
+  qq(<A HREF="$view">View this $svc_label</A><BR><BR>).
+  qq!<A HREF="${p}edit/acct_snarf.html?svcnum=$svcnum">Add new remote POP account</A><BR>!.
+  '<BR>'.
+  qq!
+  <SCRIPT>
+    function areyousure_delete(href) {
+     areyousure(href,"Are you sure you want to delete this remote POP account?");
+    }
+    function areyousure(href,message) {
+     if (confirm(message) == true)
+       window.location.href = href;
+    }
+  </SCRIPT>
+!;
+
+my $edit_sub = [ $p.'edit/acct_snarf.html?', 'snarfnum' ];
+my $del_sub = sub {
+  my $snarfnum = shift->snarfnum;
+  [ "javascript:areyousure_delete('${p}misc/delete-acct_snarf.html?$snarfnum')", '' ];
+};
+
+</%init>
diff --git a/httemplate/edit/acct_snarf.html b/httemplate/edit/acct_snarf.html
new file mode 100644 (file)
index 0000000..5fd3f83
--- /dev/null
@@ -0,0 +1,50 @@
+<% include('elements/edit.html',
+             'name_singular' => 'remote email address',
+             'table'         => 'acct_snarf',
+             'labels' => { 'snarfnum'         => 'Remote email address',
+                           #'svcnum'           => 'Local account',
+                           'snarfname'        => 'Name',
+                           'machine'          => 'Mail server',
+                           'protocol'         => 'Protocol',
+                           'username'         => 'Username',
+                           '_password'        => 'Password',
+                           'check_freq'       => 'Poll every',
+                           'leave'            => 'Leave',
+                           'apop'             => 'Use APOP',
+                           'tls'              => 'TLS',
+                           'mailbox'          => 'Mailbox',
+                         },
+             'fields' => [ 
+                           { field=>'svcnum',   type=>'hidden', },
+                           { field=>'protocol', type=>'hidden', },
+                           'snarfname',
+                           'machine',
+                           'username',
+                           { 'field'=>'_password', type=>'password', },
+                           { 'field'     => 'check_freq',
+                             'type'      => 'select',
+                             'options'   => [ keys %$cf_labels ],
+                             'labels'    => $cf_labels,
+                           },
+                           { field=>'leave', type=>'checkbox', value=>'Y', },
+                           { field=>'apop',  type=>'checkbox', value=>'Y', },
+                           { field=>'tls',   type=>'checkbox', value=>'Y', },
+                           'mailbox',
+                         ],
+             'new_callback' => sub { my( $cgi, $acct_snarf ) = @_;
+                                     $acct_snarf->svcnum($cgi->param('svcnum'));
+                                     $acct_snarf->protocol('POP');
+                                   },
+             #'viewall_url' => $viewall_url,
+             'menubar' => [],
+          )
+%>
+<%init>
+
+my %opt = @_;
+
+#my $viewall_url = $p. "browse/$table.html?svcnum=$svcnum";
+
+my $cf_labels = FS::acct_snarf->check_freq_labels;
+
+</%init>
diff --git a/httemplate/edit/process/acct_snarf.html b/httemplate/edit/process/acct_snarf.html
new file mode 100644 (file)
index 0000000..332ac52
--- /dev/null
@@ -0,0 +1,20 @@
+<% include( 'elements/process.html',
+              'table'       => 'acct_snarf',
+              'redirect'    => $redirect,
+              'noerror_callback' => sub {
+                my( $cgi, $object ) = @_;
+                my $error = $object->svc_export;
+                #shit, not a good place for error handling :/
+                die $error if $error;
+              },
+          )
+%>
+<%init>
+
+my $redirect = sub {
+  my($cgi, $new) = @_;
+  my $svcnum = $new->svcnum;
+  popurl(3)."browse/acct_snarf.html?svcnum=$svcnum;snarfnum=";
+};
+
+</%init>
index ece1724..179facf 100644 (file)
             )
   %>
 
+%# RPOP
+
+  <% include('/view/elements/tr.html', label=>'Remote POP accounts',
+               value=>$rpop_link,
+            )
+  %>
+
 <%init>
 
 my %opt = @_;
@@ -116,8 +123,11 @@ my %opt = @_;
 my $svc_acct = $opt{'svc_acct'};
 #my $part_svc = $opt{'part_svc'};
 
-my $rule_link = qq(<A HREF="${p}browse/cgp_rule.html?svcnum=).
-                      $svc_acct->svcnum. '">View/edit mail rules</A>'; #'dum vim
+my $rule_link = qq(<A HREF="${p}browse/cgp_rule.html?svcnum=). #"dum vim
+                      $svc_acct->svcnum. '">View/edit mail rules</A>';
+
+my $rpop_link = qq(<A HREF="${p}browse/acct_snarf.html?svcnum=). #"dee vim
+                      $svc_acct->svcnum. '">View/edit remote POP accounts</A>';
 
 my $vacation_rule = qsearchs('cgp_rule', { 'svcnum' => $svc_acct->svcnum,
                                            'name'   => '#Vacation'