7 use FS::UID qw(adminsuidsetup);
10 my $user = shift or die &usage;
11 my $dir = shift or die &usage;
16 my $conf = new FS::Conf;
18 chdir $dir or die "can't change to $dir: $!\n";
20 die "direct download of tax data not enabled\n"
21 unless $conf->exists('taxdatadirectdownload');
22 my ( $urls, $username, $secret, $states ) =
23 $conf->config('taxdatadirectdownload');
24 die "No tax download URL provided. ".
25 "Did you set the taxdatadirectdownload configuration value?\n"
28 my $ua = new LWP::UserAgent;
29 foreach my $url (split ',', $urls) {
30 my @name = split '/', $url; #somewhat restrictive
32 $name =~ /(.*)/; # untaint that which we trust;
35 open my $taxfh, ">$name" or die "Can't open $name: $!\n";
37 my $res = $ua->request(
38 new HTTP::Request( GET => $url),
39 sub { #my ($data, $response_object) = @_;
40 print $taxfh $_[0] or die "Can't write to $dir.new/$name: $!\n";
43 die "download of $url failed: ". $res->status_line
44 unless $res->is_success;
46 $secret =~ /(.*)/; # untaint that which we trust;
48 system('unzip', "-P", $secret, $name) == 0
49 or die "unzip -P $secret $name failed";
53 die "Usage:\n\n fetch_and_expand_taxes user dir\n";