From b3205ddf480401284a5fc4ccbcb45d9c42b0bcf9 Mon Sep 17 00:00:00 2001 From: ivan Date: Sat, 7 Aug 2010 07:39:06 +0000 Subject: [PATCH] communigate phase 3: RPOP/acct_snarf, RT#7515 --- FS/FS/Mason.pm | 1 + FS/FS/Schema.pm | 18 ++++--- FS/FS/acct_snarf.pm | 35 ++++++++++++++ httemplate/browse/acct_snarf.html | 78 +++++++++++++++++++++++++++++++ httemplate/edit/acct_snarf.html | 50 ++++++++++++++++++++ httemplate/edit/process/acct_snarf.html | 20 ++++++++ httemplate/view/svc_acct/communigate.html | 14 +++++- 7 files changed, 208 insertions(+), 8 deletions(-) create mode 100644 httemplate/browse/acct_snarf.html create mode 100644 httemplate/edit/acct_snarf.html create mode 100644 httemplate/edit/process/acct_snarf.html diff --git a/FS/FS/Mason.pm b/FS/FS/Mason.pm index bcf727e3c..2a4b42ffe 100644 --- a/FS/FS/Mason.pm +++ b/FS/FS/Mason.pm @@ -249,6 +249,7 @@ if ( -e $addl_handler_use_file ) { use FS::rate_time_interval; use FS::msg_template; use FS::part_tag; + use FS::acct_snarf; # Sammath Naur if ( $FS::Mason::addl_handler_use ) { diff --git a/FS/FS/Schema.pm b/FS/FS/Schema.pm index 557ee6295..d7d5a0413 100644 --- a/FS/FS/Schema.pm +++ b/FS/FS/Schema.pm @@ -2171,12 +2171,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' => [], diff --git a/FS/FS/acct_snarf.pm b/FS/FS/acct_snarf.pm index b4e88bfc9..fb26cea06 100644 --- a/FS/FS/acct_snarf.pm +++ b/FS/FS/acct_snarf.pm @@ -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) =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 index 000000000..f6109944f --- /dev/null +++ b/httemplate/browse/acct_snarf.html @@ -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(View this $svc_label

). + qq!Add new remote POP account
!. + '
'. + qq! + +!; + +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')", '' ]; +}; + + diff --git a/httemplate/edit/acct_snarf.html b/httemplate/edit/acct_snarf.html new file mode 100644 index 000000000..5fd3f83fb --- /dev/null +++ b/httemplate/edit/acct_snarf.html @@ -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; + + diff --git a/httemplate/edit/process/acct_snarf.html b/httemplate/edit/process/acct_snarf.html new file mode 100644 index 000000000..332ac5228 --- /dev/null +++ b/httemplate/edit/process/acct_snarf.html @@ -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="; +}; + + diff --git a/httemplate/view/svc_acct/communigate.html b/httemplate/view/svc_acct/communigate.html index ece1724be..179facfa0 100644 --- a/httemplate/view/svc_acct/communigate.html +++ b/httemplate/view/svc_acct/communigate.html @@ -107,6 +107,13 @@ ) %> +%# 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(View/edit mail rules'; #'dum vim +my $rule_link = qq(svcnum. '">View/edit mail rules'; + +my $rpop_link = qq(svcnum. '">View/edit remote POP accounts'; my $vacation_rule = qsearchs('cgp_rule', { 'svcnum' => $svc_acct->svcnum, 'name' => '#Vacation' -- 2.11.0