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->timeout(1800); #30m, some reports can take a while
39 $ua->agent("FreesideFetcher/0.1 " . $ua->agent);
41 my $req = new HTTP::Request GET => $url;
42 my $res = $ua->request($req);
44 my $conf = new FS::Conf;
45 my $subject = $conf->config('email_report-subject') || 'Freeside report';
47 my %options = ( 'from' => $email_address,
48 'to' => $email_address,
49 'subject' => $subject,
50 'body' => $res->content,
53 $options{'content-type'} = $res->content_type
54 if $res->content_type;
55 $options{'content-encoding'} = $res->content_encoding
56 if $res->content_encoding;
58 if ($res->is_success) {
61 warn "fetching $url failed for $employee: " . $res->status_line;
66 die "Usage:\n\n freeside-fetch user employee[,employee ...] url\n\n";
71 freeside-fetch - Send a freeside page to a list of employees.
75 freeside-fetch user employee[,employee ...] url
79 Fetches a web page specified by url as if employee and emails it to
80 employee. Useful when run out of cron to send freeside web pages.
82 user: From the mapsecrets file - a user with access to the freeside database
84 employee: the username of an employee to receive the emailed page. May be a comma separated list
86 url: the web page to be received
90 Can leak employee usernames and passwords if requested to access inappropriate urls.