This commit was generated by cvs2svn to compensate for changes in r4888,
[freeside.git] / FS / bin / freeside-daily
1 #!/usr/bin/perl -w
2
3 use strict;
4 use Getopt::Std;
5 use FS::UID qw(adminsuidsetup);
6
7 &untaint_argv;  #what it sounds like  (eww)
8 #use vars qw($opt_d $opt_v $opt_p $opt_a $opt_s $opt_y);
9 use vars qw(%opt);
10 getopts("p:a:d:vsy:", \%opt);
11
12 my $user = shift or die &usage;
13 adminsuidsetup $user;
14
15 use FS::Cron::bill qw(bill);
16 bill(%opt);
17
18 use FS::Cron::vacuum qw(vacuum);
19 vacuum();
20
21 use FS::Cron::backup qw(backup_scp);
22 backup_scp();
23
24 ###
25 # subroutines
26 ###
27
28 sub untaint_argv {
29   foreach $_ ( $[ .. $#ARGV ) { #untaint @ARGV
30     #$ARGV[$_] =~ /^([\w\-\/]*)$/ || die "Illegal arguement \"$ARGV[$_]\"";
31     # Date::Parse
32     $ARGV[$_] =~ /^(.*)$/ || die "Illegal arguement \"$ARGV[$_]\"";
33     $ARGV[$_]=$1;
34   }
35 }
36
37 sub usage {
38   die "Usage:\n\n  freeside-daily [ -d 'date' ] user [ custnum custnum ... ]\n";
39 }
40
41 ###
42 # documentation
43 ###
44
45 =head1 NAME
46
47 freeside-daily - Run daily billing and invoice collection events.
48
49 =head1 SYNOPSIS
50
51   freeside-daily [ -d 'date' ] [ -y days ] [ -p 'payby' ] [ -a agentnum ] [ -s ] [ -v ] user [ custnum custnum ... ]
52
53 =head1 DESCRIPTION
54
55 Bills customers and runs invoice collection events.  Should be run from
56 crontab daily.
57
58 Bills customers.  Searches for customers who are due for billing and calls
59 the bill and collect methods of a cust_main object.  See L<FS::cust_main>.
60
61   -d: Pretend it's 'date'.  Date is in any format Date::Parse is happy with,
62       but be careful.
63
64   -y: In addition to -d, which specifies an absolute date, the -y switch
65       specifies an offset, in days.  For example, "-y 15" would increment the
66       "pretend date" 15 days from whatever was specified by the -d switch
67       (or now, if no -d switch was given).
68
69   -p: Only process customers with the specified payby (I<CARD>, I<DCRD>, I<CHEK>, I<DCHK>, I<BILL>, I<COMP>, I<LECB>)
70
71   -a: Only process customers with the specified agentnum
72
73   -s: re-charge setup fees
74
75   -v: enable debugging
76
77 user: From the mapsecrets file - see config.html from the base documentation
78
79 custnum: if one or more customer numbers are specified, only bills those
80 customers.  Otherwise, bills all customers.
81
82 =head1 BUGS
83
84 =head1 SEE ALSO
85
86 L<FS::cust_main>, config.html from the base documentation
87
88 =cut
89