5 use FS::UID qw(adminsuidsetup);
6 use FS::Record qw(qsearchs);
7 use FS::Misc qw(send_email);
9 my $user = shift or die &usage;
10 my $employeelist = shift or die &usage;
11 my $url = shift or die &usage;
14 my @employees = split ',', $employeelist;
16 foreach my $employee (@employees) {
18 $employee =~ /^(\w+)$/;
20 my $access_user = qsearchs( 'access_user', { 'username' => $1 } );
21 unless ($access_user) {
22 warn "Can't find employee $employee... skipping";
26 my $email_address = $access_user->option('email_address');
27 unless ($email_address) {
28 warn "No email address for $employee... skipping";
32 no warnings 'redefine';
33 local *LWP::UserAgent::get_basic_credentials = sub {
34 return ($access_user->username, $access_user->_password);
37 my $ua = new LWP::UserAgent;
38 $ua->agent("FreesideFetcher/0.1 " . $ua->agent);
40 my $req = new HTTP::Request GET => $url;
41 my $res = $ua->request($req);
43 my %options = ( 'from' => $email_address,
44 'to' => $email_address,
45 'subject' => 'subject',
46 'body' => $res->content,
49 $options{'content-type'} = $res->content_type
50 if $res->content_type;
51 $options{'content-encoding'} = $res->content_encoding
52 if $res->content_encoding;
54 if ($res->is_success) {
57 warn "fetching $url failed for $employee: " . $res->status_line;
62 die "Usage:\n\n freeside-fetch user employee[,employee ...] url\n\n";
67 freeside-fetch - Send a freeside page to a list of employees.
71 freeside-fetch user employee[,employee ...] url
75 Fetches a web page specified by url as if employee and emails it to
76 employee. Useful when run out of cron to send freeside web pages.
78 user: From the mapsecrets file - a user with access to the freeside database
80 employee: the username of an employee to receive the emailed page. May be a comma separated list
82 url: the web page to be received
86 Can leak employee usernames and passwords if requested to access inappropriate urls.