diff options
Diffstat (limited to 'FS/bin')
-rw-r--r-- | FS/bin/freeside-addoutsourceuser | 4 | ||||
-rwxr-xr-x | FS/bin/freeside-daily | 17 | ||||
-rwxr-xr-x | FS/bin/freeside-receivables-report | 217 | ||||
-rw-r--r-- | FS/bin/freeside-selfservice-server | 55 | ||||
-rwxr-xr-x | FS/bin/freeside-setup | 54 |
5 files changed, 102 insertions, 245 deletions
diff --git a/FS/bin/freeside-addoutsourceuser b/FS/bin/freeside-addoutsourceuser index 180cd9399..abb515b6f 100644 --- a/FS/bin/freeside-addoutsourceuser +++ b/FS/bin/freeside-addoutsourceuser @@ -10,6 +10,6 @@ freeside-adduser -h /usr/local/etc/freeside/htpasswd \ $username $password 2>/dev/null [ -e /usr/local/etc/freeside/dbdef.DBI:Pg:host=localhost\;dbname=$domain ] \ - || ( freeside-setup $username 2>/dev/null; \ - /home/ivan/freeside/bin/populate-msgcat $username ) + || ( freeside-setup -s $username 2>/dev/null; \ + /home/ivan/freeside/bin/populate-msgcat $username 2>/dev/null ) diff --git a/FS/bin/freeside-daily b/FS/bin/freeside-daily index 63e621b57..5fb966665 100755 --- a/FS/bin/freeside-daily +++ b/FS/bin/freeside-daily @@ -10,8 +10,8 @@ use FS::Conf; use FS::cust_main; &untaint_argv; #what it sounds like (eww) -use vars qw($opt_d $opt_v $opt_p); -getopts("p:d:v"); +use vars qw($opt_d $opt_v $opt_p $opt_s $opt_y); +getopts("p:d:vsy:"); my $user = shift or die &usage; adminsuidsetup $user; @@ -28,6 +28,7 @@ my @cust_main = @ARGV #we're at now now (and later). my($time)= $opt_d ? str2time($opt_d) : $^T; +$time += $opt_y * 86400 if $opt_y; my($cust_main,%saw); foreach $cust_main ( @cust_main ) { @@ -42,7 +43,8 @@ foreach $cust_main ( @cust_main ) { if $error; } - my $error = $cust_main->bill( 'time' => $time ); + my $error = $cust_main->bill( 'time' => $time, + 'resetup' => $opt_s, ); warn "Error billing, custnum ". $cust_main->custnum. ": $error" if $error; $cust_main->apply_payments; @@ -98,7 +100,7 @@ freeside-daily - Run daily billing and invoice collection events. =head1 SYNOPSIS - freeside-daily [ -d 'date' ] [ -p 'payby' ] [ -v ] user [ custnum custnum ... ] + freeside-daily [ -d 'date' ] [ -y days ] [ -p 'payby' ] [ -s ] [ -v ] user [ custnum custnum ... ] =head1 DESCRIPTION @@ -113,8 +115,15 @@ the bill and collect methods of a cust_main object. See L<FS::cust_main>. -d: Pretend it's 'date'. Date is in any format Date::Parse is happy with, but be careful. + -y: In addition to -d, which specifies an absolute date, the -y switch + specifies an offset, in days. For example, "-y 15" would increment the + "pretend date" 15 days from whatever was specified by the -d switch + (or now, if no -d switch was given). + -p: Only process customers with the specified payby (I<CARD>, I<DCRD>, I<CHEK>, I<DCHK>, I<BILL>, I<COMP>, I<LECB>) + -s: re-charge setup fees + -v: enable debugging user: From the mapsecrets file - see config.html from the base documentation diff --git a/FS/bin/freeside-receivables-report b/FS/bin/freeside-receivables-report deleted file mode 100755 index f3ad2a1a6..000000000 --- a/FS/bin/freeside-receivables-report +++ /dev/null @@ -1,217 +0,0 @@ -#!/usr/bin/perl -Tw - -use strict; -use Date::Parse; -use Time::Local; -use Getopt::Std; -use Text::Template; -use Net::SMTP; -use Mail::Header; -use Mail::Internet; -use FS::Conf; -use FS::UID qw(adminsuidsetup); -use FS::Record qw(qsearch); -use FS::cust_main; - - -&untaint_argv; #what it sounds like (eww) -use vars qw($opt_v $opt_p $opt_m $opt_e $opt_t $report_lines $report_template @buf $header); -getopts("vpmet:"); #switches - -#we're at now now (and later). -my($_date)= $^T; - -# Get the current month -my ($sec,$min,$hour,$mday,$mon,$year) = - (localtime($_date) )[0,1,2,3,4,5]; -$mon++; -$year += 1900; - -# Login to the database -my $user = shift or die &usage; -adminsuidsetup $user; - -# Get the needed configuration files -my $conf = new FS::Conf; -my $lpr = $conf->config('lpr'); -my $email = $conf->config('email'); -my $smtpmachine = $conf->config('smtpmachine'); -my $mail_sender = $conf->exists('invoice_from') ? $conf->config('invoice_from') : - 'postmaster'; -my @report_template = $conf->config('report_template') - or die "cannot load config file report_template"; -$report_lines = 0; - foreach ( grep /report_lines\(\d+\)/, @report_template ) { #kludgy :/ - /report_lines\((\d+)\)/; - $report_lines += $1; -} -die "no report_lines() functions in template?" unless $report_lines; -$report_template = new Text::Template ( - TYPE => 'ARRAY', - SOURCE => [ map "$_\n", @report_template ], -) or die "can't create new Text::Template object: $Text::Template::ERROR"; - - -my(@customers)=qsearch('cust_main',{}); -if (scalar(@customers) == 0) -{ - exit 1; -} - -# Open print and email pipes -# $lpr and opt_p for printing -# $email and opt_m for email - -if ($lpr && $opt_p) -{ - open(LPR, "|$lpr"); -} - -if ($email && $opt_m) -{ - $ENV{MAILADDRESS} = $mail_sender; - $header = new Mail::Header ( [ - "From: Account Processor", - "To: $email", - "Sender: $mail_sender", - "Reply-To: $mail_sender", - "Subject: Receivables", - ] ); -} - -my $total = 0; - - -# Now I can start looping -foreach my $customer (@customers) -{ - my $custnum = $customer->getfield('custnum'); - my $first = $customer->getfield('first'); - my $last = $customer->getfield('last'); - my $company = $customer->getfield('company'); - my $daytime = $customer->getfield('daytime'); - my $balance = $customer->balance; - - - if ($balance != 0) { - $total += $balance; - push @buf, sprintf(qq{%8d %-32.32s %12s %9.2f}, - $custnum, - $first . " " . $last . " " . $company, - $daytime, - $balance); - - } - -} - -push @buf, ('', sprintf(qq{%61s}, "========="), sprintf(qq{%61.2f}, $total)); - -sub FS::receivables_report::_template::report_lines { - my $lines = shift; - map { - scalar(@buf) ? shift @buf : '' ; - } - ( 1 .. $lines ); -} - -$FS::receivables_report::_template::title = " R E C E I V A B L E S "; -$FS::receivables_report::_template::title = $opt_t if $opt_t; -$FS::receivables_report::_template::page = 1; -$FS::receivables_report::_template::date = $_date; -$FS::receivables_report::_template::date = $_date; -$FS::receivables_report::_template::total_pages = - int( scalar(@buf) / $report_lines); -$FS::receivables_report::_template::total_pages++ if scalar(@buf) % $report_lines; - -my @report; -while (@buf) { - push @report, split("\n", - $report_template->fill_in( PACKAGE => 'FS::receivables_report::_template' ) - ); - $FS::receivables_report::_template::page++; -} - -if ($opt_v) { - print map "$_\n", @report; -} -if($lpr && $opt_p) -{ - print LPR map "$_\n", @report; - print LPR "\f" if $opt_e; - close LPR || die "Could not close printer: $lpr\n"; -} -if($email && $opt_m) -{ - my $message = new Mail::Internet ( - 'Header' => $header, - 'Body' => [ (@report) ], - ); - $!=0; - $message->smtpsend( Host => "$smtpmachine" ) - or die "can't send report to $email via $smtpmachine: $!"; -} - - -# subroutines - -sub untaint_argv { - foreach $_ ( $[ .. $#ARGV ) { #untaint @ARGV - $ARGV[$_] =~ /^([\w\-\/ \.]*)$/ || die "Illegal argument \"$ARGV[$_]\""; - $ARGV[$_]=$1; - } -} - -sub usage { - die "Usage:\n\n freeside-receivables-report [-v] [-p] [-e] user\n"; -} - -=head1 NAME - -freeside-receivables-report - Prints or emails outstanding receivables. - -=head1 SYNOPSIS - - freeside-receivables-report [-v] [-p] [-m] [-e] [-t "title"] user - -=head1 DESCRIPTION - -Prints or emails outstanding receivables - -B<-v>: Verbose - Prints records to STDOUT. - -B<-p>: Print to printer lpr as found in the conf directory. - -B<-m>: Mail output to user found in the Conf email file. - -B<-e>: Print a final form feed to the printer. - -B<-t>: supply a title for the top of each page. - -user: From the mapsecrets file - see config.html from the base documentation - -=head1 VERSION - -$Id: freeside-receivables-report,v 1.6 2002-09-09 22:57:34 ivan Exp $ - -=head1 BUGS - -Yes..... Use at your own risk. No guarantees or warrantees of any -kind apply to this program. Parts of this program are hacked from -other GNU licensed software created mainly by Ivan Kohler. - -This is released under the GNU Public License. See www.gnu.org -for more information regarding this license. - -=head1 SEE ALSO - -L<FS::cust_main>, config.html from the base documentation - -=head1 AUTHOR - -Jeff Finucane <jeff@cmh.net> - -based on print-batch by Joel Griffiths <griff@aver-computer.com> - -=cut - diff --git a/FS/bin/freeside-selfservice-server b/FS/bin/freeside-selfservice-server index 264cbc56d..371a646b4 100644 --- a/FS/bin/freeside-selfservice-server +++ b/FS/bin/freeside-selfservice-server @@ -9,6 +9,7 @@ use strict; use vars qw( $Debug %kids $kids $max_kids $shutdown $log_file $ssh_pid ); +use subs qw( lock_write unlock_write ); use Fcntl qw(:flock); use POSIX qw(:sys_wait_h setsid); use IO::Handle; @@ -32,18 +33,18 @@ $kids = 0; my $user = shift or die &usage; my $machine = shift or die &usage; -my $pid_file = "/var/run/freeside-selfservice-server.$user.pid"; -#my $pid_file = "/var/run/freeside-selfservice-server.$user.pid"; $FS::UID::datasrc not posible, but should include machine name at least, hmm +my $tag = scalar(@ARGV) ? shift : ''; + +# $FS::UID::datasrc not posible +my $pid_file = "/var/run/freeside-selfservice-server.$user.$machine.pid"; + +my $lock_file = "/usr/local/etc/freeside/selfservice.$machine.writelock"; +open(LOCKFILE,">$lock_file") or die "can't open $lock_file: $!"; &init($user); my $conf = new FS::Conf; -if ($conf->exists('selfservice_server-quiet')) { - $FS::cust_bill::quiet = 1; - $FS::cust_pkg::quiet = 1; -} - my $clientd = "/usr/local/sbin/freeside-selfservice-clientd"; #better name? my $warnkids=0; @@ -51,7 +52,7 @@ while (1) { my($writer,$reader,$error) = (new IO::Handle, new IO::Handle, new IO::Handle); warn "connecting to $machine\n" if $Debug; - $ssh_pid = sshopen2($machine,$reader,$writer,$clientd); + $ssh_pid = sshopen2($machine,$reader,$writer,$clientd,$tag); # nstore_fd(\*writer, {'hi'=>'there'}); @@ -74,7 +75,18 @@ while (1) { warn "receiving packet from client\n" if $Debug; - my $packet = fd_retrieve($reader); + my $packet = eval { fd_retrieve($reader); }; + if ( $@ ) { + warn "Storable error receiving packet from client". + " (assuming lost connection): $@\n" + if $Debug; + if ( $ssh_pid ) { + warn "sending TERM signal to ssh process $ssh_pid\n" if $Debug; + kill 'TERM', $ssh_pid; + $ssh_pid = 0; + } + last; + } warn "packet received\n". join('', map { " $_=>$packet->{$_}\n" } keys %$packet ) if $Debug > 1; @@ -109,10 +121,10 @@ while (1) { $rv->{_token} = $packet->{_token}; #identifier warn "sending response\n" if $Debug; - flock($writer, LOCK_EX) or die "FATAL: can't lock write stream: $!"; + lock_write; nstore_fd($rv, $writer) or die "FATAL: can't send response: $!"; $writer->flush or die "FATAL: can't flush: $!"; - flock($writer, LOCK_UN) or die "WARNING: can't release write lock: $!"; + unlock_write; warn "child exiting\n" if $Debug; exit; #end-of-kid @@ -120,6 +132,9 @@ while (1) { } + warn "connection lost, reconnecting\n" if $Debug; + sleep 3; + } ### @@ -229,7 +244,23 @@ sub _do_logmsg { close $log; } +sub lock_write { + #broken on freebsd? + #flock($writer, LOCK_EX) or die "FATAL: can't lock write stream: $!"; + + flock(LOCKFILE, LOCK_EX) or die "FATAL: can't lock $lock_file: $!"; + +} + +sub unlock_write { + #broken on freebsd? + #flock($writer, LOCK_UN) or die "WARNING: can't release write lock: $!"; + + flock(LOCKFILE, LOCK_UN) or die "FATAL: can't unlock $lock_file: $!"; + +} + sub usage { - die "Usage:\n\n fs_signup_server user machine\n"; + die "Usage:\n\n freeside-selfservice-server user machine\n"; } diff --git a/FS/bin/freeside-setup b/FS/bin/freeside-setup index 2cb555e18..7512cc18c 100755 --- a/FS/bin/freeside-setup +++ b/FS/bin/freeside-setup @@ -336,10 +336,13 @@ sub tables_hash_hack { 'typenum', 'int', '', '', 'freq', 'int', 'NULL', '', 'prog', @perl_type, + 'disabled', 'char', 'NULL', 1, + 'username', 'varchar', 'NULL', $char_d, + '_password','varchar', 'NULL', $char_d, ], 'primary_key' => 'agentnum', 'unique' => [], - 'index' => [ ['typenum'] ], + 'index' => [ ['typenum'], ['disabled'] ], }, 'agent_type' => { @@ -405,7 +408,7 @@ sub tables_hash_hack { ], 'primary_key' => 'eventpart', 'unique' => [], - 'index' => [ ['payby'] ], + 'index' => [ ['payby'], ['disabled'], ], }, 'cust_bill_pkg' => { @@ -499,6 +502,7 @@ sub tables_hash_hack { 'ship_fax', 'varchar', 'NULL', 12, 'payby', 'char', '', 4, 'payinfo', 'varchar', 'NULL', $char_d, + 'paycvv', 'varchar', 'NULL', 4, #'paydate', @date_type, 'paydate', 'varchar', 'NULL', 10, 'payname', 'varchar', 'NULL', $char_d, @@ -539,6 +543,8 @@ sub tables_hash_hack { 'exempt_amount', @money_type, 'tax', 'real', '', '', #tax % 'taxname', 'varchar', 'NULL', $char_d, + 'setuptax', 'char', 'NULL', 1, # Y = setup tax exempt + 'recurtax', 'char', 'NULL', 1, # Y = recur tax exempt ], 'primary_key' => 'taxnum', 'unique' => [], @@ -561,7 +567,7 @@ sub tables_hash_hack { ], 'primary_key' => 'paynum', 'unique' => [], - 'index' => [ [ 'custnum' ], [ 'paybatch' ] ], + 'index' => [ [ 'custnum' ], [ 'paybatch' ], [ 'payby' ], [ '_date' ] ], }, 'cust_bill_pay' => { @@ -673,7 +679,7 @@ sub tables_hash_hack { 'pkg', 'varchar', '', $char_d, 'comment', 'varchar', '', $char_d, 'setup', @perl_type, - 'freq', 'int', '', '', #billing frequency (months) + 'freq', 'varchar', '', $char_d, #billing frequency 'recur', @perl_type, 'setuptax', 'char', 'NULL', 1, 'recurtax', 'char', 'NULL', 1, @@ -702,6 +708,7 @@ sub tables_hash_hack { 'pkgpart', 'int', '', '', 'svcpart', 'int', '', '', 'quantity', 'int', '', '', + 'primary_svc','char', 'NULL', 1, ], 'primary_key' => '', 'unique' => [ ['pkgpart', 'svcpart'] ], @@ -712,10 +719,11 @@ sub tables_hash_hack { 'columns' => [ 'refnum', 'serial', '', '', 'referral', 'varchar', '', $char_d, + 'disabled', 'char', 'NULL', 1, ], 'primary_key' => 'refnum', 'unique' => [], - 'index' => [], + 'index' => [ ['disabled'] ], }, 'part_svc' => { @@ -776,7 +784,7 @@ sub tables_hash_hack { 'columns' => [ 'svcnum', 'int', '', '', 'username', 'varchar', '', $username_len, #unique (& remove dup code) - '_password', 'varchar', '', 50, #13 for encryped pw's plus ' *SUSPENDED* (mp5 passwords can be 34) + '_password', 'varchar', '', 72, #13 for encryped pw's plus ' *SUSPENDED* (md5 passwords can be 34, blowfish 60) 'sec_phrase', 'varchar', 'NULL', $char_d, 'popnum', 'int', 'NULL', '', 'uid', 'int', 'NULL', '', @@ -834,10 +842,11 @@ sub tables_hash_hack { 'svc_forward' => { 'columns' => [ - 'svcnum', 'int', '', '', - 'srcsvc', 'int', '', '', - 'dstsvc', 'int', '', '', - 'dst', 'varchar', 'NULL', $char_d, + 'svcnum', 'int', '', '', + 'srcsvc', 'int', 'NULL', '', + 'src', 'varchar', 'NULL', 255, + 'dstsvc', 'int', 'NULL', '', + 'dst', 'varchar', 'NULL', 255, ], 'primary_key' => 'svcnum', 'unique' => [], @@ -1099,6 +1108,31 @@ sub tables_hash_hack { 'index' => [], }, + 'acct_snarf' => { + 'columns' => [ + 'snarfnum', 'int', '', '', + 'svcnum', 'int', '', '', + 'machine', 'varchar', '', 255, + 'protocol', 'varchar', '', $char_d, + 'username', 'varchar', '', $char_d, + '_password', 'varchar', '', $char_d, + ], + 'primary_key' => 'snarfnum', + 'unique' => [], + 'index' => [ [ 'svcnum' ] ], + }, + + 'svc_external' => { + 'columns' => [ + 'svcnum', 'int', '', '', + 'id', 'int', '', '', + 'title', 'varchar', 'NULL', $char_d, + ], + 'primary_key' => 'svcnum', + 'unique' => [], + 'index' => [], + }, + ); %tables; |