summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjeff <jeff>2007-03-21 01:21:39 +0000
committerjeff <jeff>2007-03-21 01:21:39 +0000
commit8591b5a157a2ee24c1467718eb0ce731a388f5c1 (patch)
tree60123b9b13666010bcb61aaae1c4f6f47a8cac24
parent67569d160196abf84e889514b1b2f90053548c93 (diff)
ticket 1427, automatically email excel a/r report
-rwxr-xr-xFS/bin/freeside-fetch89
-rw-r--r--httemplate/pref/pref-process.html17
-rw-r--r--httemplate/pref/pref.html17
3 files changed, 118 insertions, 5 deletions
diff --git a/FS/bin/freeside-fetch b/FS/bin/freeside-fetch
new file mode 100755
index 000000000..89a4f29af
--- /dev/null
+++ b/FS/bin/freeside-fetch
@@ -0,0 +1,89 @@
+#!/usr/bin/perl -Tw
+
+use strict;
+use LWP::UserAgent;
+use FS::UID qw(adminsuidsetup);
+use FS::Record qw(qsearchs);
+use FS::Misc qw(send_email);
+
+my $user = shift or die &usage;
+my $employeelist = shift or die &usage;
+my $url = shift or die &usage;
+adminsuidsetup $user;
+
+my @employees = split ',', $employeelist;
+
+foreach my $employee (@employees) {
+
+ $employee =~ /^(\w+)$/;
+
+ my $access_user = qsearchs( 'access_user', { 'username' => $1 } );
+ unless ($access_user) {
+ warn "Can't find employee $employee... skipping";
+ next;
+ }
+
+ my $email_address = $access_user->option('email_address');
+ unless ($email_address) {
+ warn "No email address for $employee... skipping";
+ next;
+ }
+
+ no warnings 'redefine';
+ local *LWP::UserAgent::get_basic_credentials = sub {
+ return ($access_user->username, $access_user->_password);
+ };
+
+ my $ua = new LWP::UserAgent;
+ $ua->agent("FreesideFetcher/0.1 " . $ua->agent);
+
+ my $req = new HTTP::Request GET => $url;
+ my $res = $ua->request($req);
+
+ my %options = ( 'from' => $email_address,
+ 'to' => $email_address,
+ 'subject' => 'subject',
+ 'body' => $res->content,
+ );
+
+ $options{'content-type'} = $res->content_type
+ if $res->content_type;
+ $options{'content-encoding'} = $res->content_encoding
+ if $res->content_encoding;
+
+ if ($res->is_success) {
+ send_email %options;
+ }else{
+ warn "fetching $url failed for $employee: " . $res->status_line;
+ }
+}
+
+sub usage {
+ die "Usage:\n\n freeside-fetch user employee[,employee ...] url\n\n";
+}
+
+=head1 NAME
+
+freeside-fetch - Send a freeside page to a list of employees.
+
+=head1 SYNOPSIS
+
+ freeside-fetch user employee[,employee ...] url
+
+=head1 DESCRIPTION
+
+ Fetches a web page specified by url as if employee and emails it to
+ employee. Useful when run out of cron to send freeside web pages.
+
+ user: From the mapsecrets file - a user with access to the freeside database
+
+ employee: the username of an employee to receive the emailed page. May be a comma separated list
+
+ url: the web page to be received
+
+=head1 BUGS
+
+ Can leak employee usernames and passwords if requested to access inappropriate urls.
+
+=cut
+
diff --git a/httemplate/pref/pref-process.html b/httemplate/pref/pref-process.html
index ed3350971..a5e13f062 100644
--- a/httemplate/pref/pref-process.html
+++ b/httemplate/pref/pref-process.html
@@ -27,12 +27,19 @@
%
% }
%
+% #XXX autogen
+% my @paramlist = qw( menu_position email_address
+% height width availHeight availWidth colorDepth
+% );
+%
+% foreach (@paramlist) {
+% scalar($cgi->param($_)) =~ /^[,.\@\w]*$/ && next;
+% $error ||= "Illegal value for parameter $_";
+% last;
+% }
+%
% $error ||= $access_user->replace( {
-% map { $_ => scalar($cgi->param($_)) }
-% #XXX autogen
-% qw( menu_position
-% height width availHeight availWidth colorDepth
-% )
+% map { $_ => scalar($cgi->param($_)) } @paramlist,
% } );
%
% if ( $error ) {
diff --git a/httemplate/pref/pref.html b/httemplate/pref/pref.html
index 229ac0e62..069f914ed 100644
--- a/httemplate/pref/pref.html
+++ b/httemplate/pref/pref.html
@@ -43,6 +43,20 @@ Interface
<BR>
+Email Address
+<% ntable("#cccccc",2) %>
+
+ <TR>
+ <TH>Email Address(es) (comma separated) </TH>
+ <TD>
+ <TD><INPUT TYPE="text" NAME="email_address" VALUE="<% $email_address %>">
+ </TD>
+ </TR>
+
+</TABLE>
+<BR>
+
+
Vonage integration (see <a href="https://secure.click2callu.com/">Click2Call</a>)
<% ntable("#cccccc",2) %>
@@ -81,5 +95,8 @@ Vonage integration (see <a href="https://secure.click2callu.com/">Click2Call</a>
( $FS::CurrentUser::CurrentUser->option('menu_position') || 'left' )
=~ /^(\w+)$/ or die "illegal menu_position";
my $menu_position = $1;
+( $FS::CurrentUser::CurrentUser->option('email_address') )
+ =~ /^([,\w\@.]*)$/ or die "illegal email_address"; #too late
+my $email_address = $1;
</%init>