From 0b1f40cc85eee025f01dd14e155cc65837e3f9e5 Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 11 Aug 1999 20:41:28 +0000 Subject: new bill script, --- FS/bin/freeside-bill | 122 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100755 FS/bin/freeside-bill (limited to 'FS/bin') diff --git a/FS/bin/freeside-bill b/FS/bin/freeside-bill new file mode 100755 index 000000000..8f2c32fb2 --- /dev/null +++ b/FS/bin/freeside-bill @@ -0,0 +1,122 @@ +#!/usr/bin/perl -Tw + +use strict; +use Fcntl qw(:flock); +use Date::Parse; +use Getopt::Std; +use FS::UID qw(adminsuidsetup swapuid); +use FS::Record qw(qsearch qsearchs); +use FS::cust_main; + +&untaint_argv; #what it sounds like (eww) +use vars qw($opt_a $opt_c $opt_i $opt_d); +getopts("acid:"); +my $user = shift or die &usage; + +adminsuidsetup $user; + +my %bill_only = map { $_ => 1 } ( + @ARGV ? @ARGV : ( map $_->custnum, qsearch('cust_main', {} ) ) +); + +#we're at now now (and later). +my($time)= $main::opt_d ? str2time($main::opt_d) : $^T; + +# find packages w/ bill < time && cancel != '', and create corresponding +# customer objects + +my($cust_main,%saw); +foreach $cust_main ( + map { + if ( + ( $main::opt_a || ( ( $_->getfield('bill') || 0 ) <= $time ) ) + && $bill_only{ $_->custnum } + && !$saw{ $_->custnum }++ + ) { + qsearchs('cust_main',{'custnum'=> $_->custnum } ); + } else { + (); + } + } ( qsearch('cust_pkg', { 'cancel' => '' }), + qsearch('cust_pkg', { 'cancel' => 0 }), + ) +) { + + # and bill them + + print "Billing customer #" . $cust_main->getfield('custnum') . "\n"; + next; + + my($error); + + $error=$cust_main->bill('time'=>$time); + warn "Error billing, customer #" . $cust_main->getfield('custnum') . + ":" . $error if $error; + + if ($main::opt_c) { + $error=$cust_main->collect('invoice_time'=>$time, + 'batch_card' => $main::opt_i ? 'no' : 'yes', + ); + warn "Error collecting customer #" . $cust_main->getfield('custnum') . + ":" . $error if $error; + + #sleep 1; + + } + +} + +# subroutines + +sub untaint_argv { + foreach $_ ( $[ .. $#ARGV ) { #untaint @ARGV + $ARGV[$_] =~ /^([\w\-\/]*)$/ || die "Illegal arguement \"$ARGV[$_]\""; + $ARGV[$_]=$1; + } +} + +sub usage { + die "Usage:\n\n bill [ -c [ i ] ] [ -d 'date' ] [ -b ] user\n"; +} + +=head1 NAME + +freeside-bill - Command line (crontab, script) interface to customer billing. + +=head1 SYNOPSIS + + freeside-bill [ -c [ -a ] [ -i ] ] [ -d 'date' ] user [ custnum custnum ... ] + +=head1 DESCRIPTION + +Bills customers. Searches for customers who are due for billing and calls +the bill and collect methods of a cust_main object. See L. + + -c: Turn on collecting (you probably want this). + + -a: Call collect even if there isn't a new invoice (probably a bad idea for + daily use) + + -i: real-time billing (as opposed to batch billing). only relevant + for credit cards. + + -d: Pretent it's 'date'. Date is in any format Date::Parse is happy with, + but be careful. + +user: From the mapsecrets file - see config.html from the base documentation + +custnum: if one or more customer numbers are specified, only bills those +customers. Otherwise, bills all customers. + +=head1 VERSION + +$Id: freeside-bill,v 1.1 1999-08-11 20:41:27 ivan Exp $ + +=head1 BUGS + +=head1 SEE ALSO + +L, config.html from the base documentation + +=cut + -- cgit v1.2.1 From 9d1c4be2e9cc349481101bbc11a9acdc1b7c235a Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 11 Aug 1999 20:51:54 +0000 Subject: *** empty log message *** --- FS/bin/freeside-bill | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-bill b/FS/bin/freeside-bill index 8f2c32fb2..a251df4d5 100755 --- a/FS/bin/freeside-bill +++ b/FS/bin/freeside-bill @@ -45,7 +45,6 @@ foreach $cust_main ( # and bill them print "Billing customer #" . $cust_main->getfield('custnum') . "\n"; - next; my($error); @@ -110,7 +109,7 @@ customers. Otherwise, bills all customers. =head1 VERSION -$Id: freeside-bill,v 1.1 1999-08-11 20:41:27 ivan Exp $ +$Id: freeside-bill,v 1.2 1999-08-11 20:51:54 ivan Exp $ =head1 BUGS -- cgit v1.2.1 From 7c7bc66bd24874e7ccd4fd3445f1da7f88e9679d Mon Sep 17 00:00:00 2001 From: ivan Date: Mon, 4 Oct 1999 08:23:26 +0000 Subject: silly 'use of unitialized value' errors --- FS/bin/freeside-bill | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-bill b/FS/bin/freeside-bill index a251df4d5..417df767b 100755 --- a/FS/bin/freeside-bill +++ b/FS/bin/freeside-bill @@ -28,6 +28,9 @@ my($time)= $main::opt_d ? str2time($main::opt_d) : $^T; my($cust_main,%saw); foreach $cust_main ( map { + unless ( exists $saw{ $_->custnum } && defined $saw{ $_->custnum} ) { + $saw{ $_->custnum } = 0; # to avoid 'use of uninitialized value' errors + } if ( ( $main::opt_a || ( ( $_->getfield('bill') || 0 ) <= $time ) ) && $bill_only{ $_->custnum } @@ -109,7 +112,7 @@ customers. Otherwise, bills all customers. =head1 VERSION -$Id: freeside-bill,v 1.2 1999-08-11 20:51:54 ivan Exp $ +$Id: freeside-bill,v 1.3 1999-10-04 08:23:26 ivan Exp $ =head1 BUGS -- cgit v1.2.1 From 44261274cf5d0bf453005c50d43050143cd18774 Mon Sep 17 00:00:00 2001 From: ivan Date: Mon, 3 Apr 2000 02:32:57 +0000 Subject: accept anything in ARGV for -d Date::Parse --- FS/bin/freeside-bill | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-bill b/FS/bin/freeside-bill index 417df767b..208f92071 100755 --- a/FS/bin/freeside-bill +++ b/FS/bin/freeside-bill @@ -72,7 +72,9 @@ foreach $cust_main ( sub untaint_argv { foreach $_ ( $[ .. $#ARGV ) { #untaint @ARGV - $ARGV[$_] =~ /^([\w\-\/]*)$/ || die "Illegal arguement \"$ARGV[$_]\""; + #$ARGV[$_] =~ /^([\w\-\/]*)$/ || die "Illegal arguement \"$ARGV[$_]\""; + # Date::Parse + $ARGV[$_] =~ /^(.*)$/ || die "Illegal arguement \"$ARGV[$_]\""; $ARGV[$_]=$1; } } @@ -112,7 +114,7 @@ customers. Otherwise, bills all customers. =head1 VERSION -$Id: freeside-bill,v 1.3 1999-10-04 08:23:26 ivan Exp $ +$Id: freeside-bill,v 1.4 2000-04-03 02:32:57 ivan Exp $ =head1 BUGS -- cgit v1.2.1 From 62a808f08c065aa5a29fb9cbf6b7108fe4cb8d15 Mon Sep 17 00:00:00 2001 From: ivan Date: Sat, 13 May 2000 21:57:56 +0000 Subject: add print_batch script from Joel Griffiths --- FS/bin/freeside-print-batch | 266 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 266 insertions(+) create mode 100755 FS/bin/freeside-print-batch (limited to 'FS/bin') diff --git a/FS/bin/freeside-print-batch b/FS/bin/freeside-print-batch new file mode 100755 index 000000000..c1a25edb2 --- /dev/null +++ b/FS/bin/freeside-print-batch @@ -0,0 +1,266 @@ +#!/usr/bin/perl -Tw + +use strict; +#use Date::Format; +use Time::Local; +use Getopt::Std; +use FS::Conf; +use FS::UID qw(adminsuidsetup); +use FS::Record qw(qsearch); +use FS::cust_pay; +use FS::cust_pay_batch; + +# Get the currennt time and date +my $time = time; +my ($sec,$min,$hour,$mday,$mon,$year) = + (localtime($time) )[0,1,2,3,4,5]; +my $_date = + timelocal($sec,$min,$hour,$mday,$mon,$year); + +# Set the mail program +my $mail_program = "/usr/sbin/sendmail -t -n"; + +&untaint_argv; #what it sounds like (eww) +use vars qw($opt_v $opt_p $opt_e $opt_a $opt_d); +getopts("vpead"); #switches + +# 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(@batch)=qsearch('cust_pay_batch',{}); +if (scalar(@batch) == 0) +{ + exit 1; +} + +# Open print and email pipes +# $lpr and opt_p for printing +# $email and opt_e for email +# +if ($lpr && $main::opt_p) +{ + open(LPR, "|$lpr"); + print LPR qq~C R E D I T C A R D P A Y M E N T S D U E $mon/$mday/$year\n\n~; +} + +if ($email && $main::opt_e) +{ + open (MAIL, "|$mail_program"); + print MAIL <getfield('state'); + my $zip = $cust_pay_batch->getfield('zip'); + my $amount = $cust_pay_batch->getfield('amount'); + my $last = $cust_pay_batch->getfield('last'); + my $address1 = $cust_pay_batch->getfield('address1'); + my $address2 = $cust_pay_batch->getfield('address2'); + my $first = $cust_pay_batch->getfield('first'); + my $city = $cust_pay_batch->getfield('city'); + my $cardnum = $cust_pay_batch->getfield('cardnum'); + my $payname = $cust_pay_batch->getfield('payname'); + my $exp = $cust_pay_batch->getfield('exp'); + my $invnum = $cust_pay_batch->getfield('invnum'); + my $custnum = $cust_pay_batch->getfield('custnum'); + + # Need a carriage return in address before address2 + # if it exists. Otherwise address will just be address1 + my $address = $address1; + $address .= "\n$address2" if ($address2); + + # Only print to the screen in verbose mode + if ($main::opt_v) + { + printf("Invoice %d for %s %s\tCustomer Number: %d\n", + $invnum, + $first, + $last, + $custnum); + + printf("\t%s\n", $address); + printf("\t%s, %s, %s\n\n", + $city, + $state, + $zip); + + printf("\tCard Number: %s\tExp:%s\n", + $cardnum, + $exp); + printf("\t\tName: %s\n", $payname); + printf("\t\tAmount: %.2f\n\n\n", $amount); + } + + if ($lpr && $main::opt_p) + { + printf(LPR "Invoice %d for %s %s\tCustomer Number: %d\n", + $invnum, + $first, + $last, + $custnum); + + printf(LPR "\t%s\n", $address); + printf(LPR "\t%s, %s, %s\n\n", + $city, + $state, + $zip); + + printf(LPR "\tCard Number: %s\tExp:%s\n", + $cardnum, + $exp); + printf(LPR "\t\tName: %s\n", $payname); + printf(LPR "\t\tAmount: %.2f\n\n\n", $amount); + } + + if ($email && $main::opt_e) + { + printf(MAIL "Invoice %d for %s %s\tCustomer Number: %d\n", + $invnum, + $first, + $last, + $custnum); + + printf(MAIL "\t%s\n", $address); + printf(MAIL "\t%s, %s, %s\n\n", + $city, + $state, + $zip); + + printf(MAIL "\tCard Number: %s\tExp:%s\n", + $cardnum, + $exp); + printf(MAIL "\t\tName: %s\n", $payname); + printf(MAIL "\t\tAmount: %.2f\n\n\n", $amount); + } + + # Now I want to delete the records from cust_pay_batch + # and mark the records in cust_pay as paid today if + # the delete (-d) command line option is set. + if($main::opt_a) + { + my $payment=new FS::cust_pay { + 'invnum' => $invnum, + 'paid' => $amount, + '_date' => $_date, + 'payby' => "CARD", + 'payinfo' => $cardnum, + 'paybatch' => "AUTO", + }; + + my $pay_error=$payment->insert; + if ($pay_error) + { + # warn might be better if you get root's mail + # NEED TO TEST THIS BEFORE DELETE IF WARN IS USED + die "Could not update cust_pay for invnum $invnum. $pay_error\n"; + } + } + + # This just deletes the records + # Must be last in the foreach loop + if($main::opt_d) + { + my $del_error = $cust_pay_batch->delete; + if ($del_error) + { + die "Could not delete cust_pay_batch for invnum $invnum. $del_error\n"; + } + } + +} + +# Now I need to close LPR and EMAIL if they were open +if($lpr && $main::opt_p) +{ + close LPR || die "Could not close printer: $lpr\n"; +} + +if($email && $main::opt_e) +{ + close MAIL || die "Could not close printer: $lpr\n"; +} + + +# subroutines +sub untaint_argv { + foreach $_ ( $[ .. $#ARGV ) { #untaint @ARGV + $ARGV[$_] =~ /^([\w\-\/]*)$/ || die "Illegal argument \"$ARGV[$_]\""; + $ARGV[$_]=$1; + } +} + +sub usage { + die "Usage:\n\n freeside-print-batch [-v] [-p] [-e] [-a] [-d] user\n"; +} + +=head1 NAME + +freeside-print-batch - Prints or emails cust_pay_batch. Also deletes + old records and adds payment to cust_pay. + Usually run after the bill command. + +=head1 SYNOPSIS + + freeside-print-batch [-v] [-p] [-e] [-a] [-d] user + +=head1 DESCRIPTION + +Prints or emails cust_pay_batch. Can enter payment and delete +printed records. Usually run as a cron job. + +-v: Verbose - Prints records to STDOUT. + +-p: Print to printer lpr as found in the conf directory. + +-e: Email output to user found in the Conf email file. + +-a: Automatically pays all records in cust_pay_batch. Use -d with this option usually. + +-d: Delete - Pays account and deletes record from cust_pay_batch. + +user: From the mapsecrets file - see config.html from the base documentation + +=head1 VERSION + +$Id: freeside-print-batch,v 1.1 2000-05-13 21:57:56 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, config.html from the base documentation + +=head1 HISTORY + +griff@aver-computer.com July 99 + +$Log: freeside-print-batch,v $ +Revision 1.1 2000-05-13 21:57:56 ivan +add print_batch script from Joel Griffiths + + +=cut + + -- cgit v1.2.1 From 27649e60bc8cf16ba2f76731a4ebab471df3801c Mon Sep 17 00:00:00 2001 From: ivan Date: Thu, 22 Jun 2000 10:52:37 +0000 Subject: tyop --- FS/bin/freeside-bill | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-bill b/FS/bin/freeside-bill index 208f92071..680d29da5 100755 --- a/FS/bin/freeside-bill +++ b/FS/bin/freeside-bill @@ -104,7 +104,7 @@ the bill and collect methods of a cust_main object. See L. -i: real-time billing (as opposed to batch billing). only relevant for credit cards. - -d: Pretent it's 'date'. Date is in any format Date::Parse is happy with, + -d: Pretend it's 'date'. Date is in any format Date::Parse is happy with, but be careful. user: From the mapsecrets file - see config.html from the base documentation @@ -114,7 +114,7 @@ customers. Otherwise, bills all customers. =head1 VERSION -$Id: freeside-bill,v 1.4 2000-04-03 02:32:57 ivan Exp $ +$Id: freeside-bill,v 1.5 2000-06-22 10:52:37 ivan Exp $ =head1 BUGS -- cgit v1.2.1 From d2c5fa2eb293628ae281120322eb0e70d6a92a7d Mon Sep 17 00:00:00 2001 From: ivan Date: Sat, 24 Jun 2000 00:28:30 +0000 Subject: don't use Date::Manip; report correct program name in freeside-bill usage msg --- FS/bin/freeside-bill | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-bill b/FS/bin/freeside-bill index 680d29da5..42991c4f8 100755 --- a/FS/bin/freeside-bill +++ b/FS/bin/freeside-bill @@ -80,7 +80,7 @@ sub untaint_argv { } sub usage { - die "Usage:\n\n bill [ -c [ i ] ] [ -d 'date' ] [ -b ] user\n"; + die "Usage:\n\n freeside-bill [ -c [ i ] ] [ -d 'date' ] [ -b ] user\n"; } =head1 NAME @@ -114,7 +114,7 @@ customers. Otherwise, bills all customers. =head1 VERSION -$Id: freeside-bill,v 1.5 2000-06-22 10:52:37 ivan Exp $ +$Id: freeside-bill,v 1.6 2000-06-24 00:28:30 ivan Exp $ =head1 BUGS -- cgit v1.2.1 From 57f343771fff31b1a5e98c2c220bb43fd7eeca2c Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 21 Feb 2001 01:48:07 +0000 Subject: stupid pod errors --- FS/bin/freeside-print-batch | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-print-batch b/FS/bin/freeside-print-batch index c1a25edb2..5efa4ccb3 100755 --- a/FS/bin/freeside-print-batch +++ b/FS/bin/freeside-print-batch @@ -223,21 +223,21 @@ freeside-print-batch - Prints or emails cust_pay_batch. Also deletes Prints or emails cust_pay_batch. Can enter payment and delete printed records. Usually run as a cron job. --v: Verbose - Prints records to STDOUT. +B<-v>: Verbose - Prints records to STDOUT. --p: Print to printer lpr as found in the conf directory. +B<-p>: Print to printer lpr as found in the conf directory. --e: Email output to user found in the Conf email file. +B<-e>: Email output to user found in the Conf email file. --a: Automatically pays all records in cust_pay_batch. Use -d with this option usually. +B<-a>: Automatically pays all records in cust_pay_batch. Use -d with this option usually. --d: Delete - Pays account and deletes record from cust_pay_batch. +B<-d>: Delete - Pays account and deletes record from cust_pay_batch. user: From the mapsecrets file - see config.html from the base documentation =head1 VERSION -$Id: freeside-print-batch,v 1.1 2000-05-13 21:57:56 ivan Exp $ +$Id: freeside-print-batch,v 1.2 2001-02-21 01:48:07 ivan Exp $ =head1 BUGS @@ -257,7 +257,10 @@ L, config.html from the base documentation griff@aver-computer.com July 99 $Log: freeside-print-batch,v $ -Revision 1.1 2000-05-13 21:57:56 ivan +Revision 1.2 2001-02-21 01:48:07 ivan +stupid pod errors + +Revision 1.1 2000/05/13 21:57:56 ivan add print_batch script from Joel Griffiths -- cgit v1.2.1 From f41a78f519bfeb6ecd4e9cee271c42d2c27e717f Mon Sep 17 00:00:00 2001 From: ivan Date: Tue, 15 May 2001 07:52:34 +0000 Subject: simple program to list all email addresses --- FS/bin/freeside-email | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100755 FS/bin/freeside-email (limited to 'FS/bin') diff --git a/FS/bin/freeside-email b/FS/bin/freeside-email new file mode 100755 index 000000000..c7ff41114 --- /dev/null +++ b/FS/bin/freeside-email @@ -0,0 +1,61 @@ +#!/usr/bin/perl -Tw + +use strict; +use FS::UID qw(adminsuidsetup); +use FS::Conf; +use FS::Record qw(qsearch); +use FS::svc_acct; + +&untaint_argv; #what it sounds like (eww) +my $user = shift or die &usage; + +adminsuidsetup $user; + +my $conf = new FS::Conf; +my $domain = $conf->config('domain'); + +my @svc_acct = qsearch('svc_acct', {}); +my @usernames = map $_->username, @svc_acct; +my @emails = map "$_\@$domain", @usernames; + +print join("\n", @emails), "\n"; + +# subroutines + +sub untaint_argv { + foreach $_ ( $[ .. $#ARGV ) { #untaint @ARGV + #$ARGV[$_] =~ /^([\w\-\/]*)$/ || die "Illegal arguement \"$ARGV[$_]\""; + # Date::Parse + $ARGV[$_] =~ /^(.*)$/ || die "Illegal arguement \"$ARGV[$_]\""; + $ARGV[$_]=$1; + } +} + +sub usage { + die "Usage:\n\n freeside-email user\n"; +} + +=head1 NAME + +freeside-email - Prints email addresses of all users on STDOUT + +=head1 SYNOPSIS + + freeside-email user + +=head1 DESCRIPTION + +Prints the email addresses of all customers on STDOUT, separated by newlines. + +user: From the mapsecrets file - see config.html from the base documentation + +=head1 VERSION + +$Id: freeside-email,v 1.1 2001-05-15 07:52:34 ivan Exp $ + +=head1 BUGS + +=head1 SEE ALSO + +=cut + -- cgit v1.2.1 From 1da2eb3c205a088809fb8b72b42a454b94b74c43 Mon Sep 17 00:00:00 2001 From: ivan Date: Tue, 21 Aug 2001 02:44:47 +0000 Subject: remove $Log$ --- FS/bin/freeside-print-batch | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-print-batch b/FS/bin/freeside-print-batch index 5efa4ccb3..baef43787 100755 --- a/FS/bin/freeside-print-batch +++ b/FS/bin/freeside-print-batch @@ -237,7 +237,7 @@ user: From the mapsecrets file - see config.html from the base documentation =head1 VERSION -$Id: freeside-print-batch,v 1.2 2001-02-21 01:48:07 ivan Exp $ +$Id: freeside-print-batch,v 1.3 2001-08-21 02:44:47 ivan Exp $ =head1 BUGS @@ -252,18 +252,9 @@ for more information regarding this license. L, config.html from the base documentation -=head1 HISTORY - -griff@aver-computer.com July 99 - -$Log: freeside-print-batch,v $ -Revision 1.2 2001-02-21 01:48:07 ivan -stupid pod errors - -Revision 1.1 2000/05/13 21:57:56 ivan -add print_batch script from Joel Griffiths +=head1 AUTHOR +Joel Griffiths July 99 =cut - -- cgit v1.2.1 From 6ef34dda51afba96d8dc6c4dd72427c3d4003945 Mon Sep 17 00:00:00 2001 From: ivan Date: Tue, 21 Aug 2001 09:34:13 +0000 Subject: no more &swapuid --- FS/bin/freeside-bill | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-bill b/FS/bin/freeside-bill index 42991c4f8..3462fa149 100755 --- a/FS/bin/freeside-bill +++ b/FS/bin/freeside-bill @@ -4,7 +4,7 @@ use strict; use Fcntl qw(:flock); use Date::Parse; use Getopt::Std; -use FS::UID qw(adminsuidsetup swapuid); +use FS::UID qw(adminsuidsetup); use FS::Record qw(qsearch qsearchs); use FS::cust_main; @@ -114,7 +114,7 @@ customers. Otherwise, bills all customers. =head1 VERSION -$Id: freeside-bill,v 1.6 2000-06-24 00:28:30 ivan Exp $ +$Id: freeside-bill,v 1.7 2001-08-21 09:34:13 ivan Exp $ =head1 BUGS -- cgit v1.2.1 From d938dd5cd86b7fd2d9041f929a371a5faf3b18ac Mon Sep 17 00:00:00 2001 From: jeff Date: Sun, 2 Sep 2001 02:53:49 +0000 Subject: adding a credit apply utility --- FS/bin/freeside-apply-credits | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100755 FS/bin/freeside-apply-credits (limited to 'FS/bin') diff --git a/FS/bin/freeside-apply-credits b/FS/bin/freeside-apply-credits new file mode 100755 index 000000000..eb5c1f489 --- /dev/null +++ b/FS/bin/freeside-apply-credits @@ -0,0 +1,22 @@ +#!/usr/bin/perl -Tw + +use strict; +use lib "/usr/lib/perl5/site_perl/5.005/FSTest2"; +use vars qw( $user $cust_main @customers ); +use FS::UID qw(adminsuidsetup); +use FS::Record qw(qsearch); +use FS::cust_main; + +$user = shift or die &usage; +&adminsuidsetup( $user ); + +my @customers = qsearch('cust_main', {} ); +die "No customers" unless (scalar(@customers) > 0); + +foreach $cust_main (@customers) { + print "Applying credits for customer #". $cust_main->custnum; + $cust_main->apply_credits; +} + + + -- cgit v1.2.1 From fbcb45dfe5a1bce7981fe4527176b9fdf2ec54b7 Mon Sep 17 00:00:00 2001 From: ivan Date: Mon, 3 Sep 2001 22:07:39 +0000 Subject: fix more bugs --- FS/bin/freeside-bill | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-bill b/FS/bin/freeside-bill index 3462fa149..1dce9a19b 100755 --- a/FS/bin/freeside-bill +++ b/FS/bin/freeside-bill @@ -55,15 +55,19 @@ foreach $cust_main ( warn "Error billing, customer #" . $cust_main->getfield('custnum') . ":" . $error if $error; + if ($main::opt_p) { + $cust_main->apply_payments; + $error=$cust_main->apply_credits; + } + if ($main::opt_c) { $error=$cust_main->collect('invoice_time'=>$time, 'batch_card' => $main::opt_i ? 'no' : 'yes', ); - warn "Error collecting customer #" . $cust_main->getfield('custnum') . - ":" . $error if $error; - - #sleep 1; + warn "Error collecting from customer #" . $cust_main->gcustnum. ":$error" + if $error; + #sleep 1; } } @@ -89,7 +93,7 @@ freeside-bill - Command line (crontab, script) interface to customer billing. =head1 SYNOPSIS - freeside-bill [ -c [ -a ] [ -i ] ] [ -d 'date' ] user [ custnum custnum ... ] + freeside-bill [ -c [ -p ] [ -a ] [ -i ] ] [ -d 'date' ] user [ custnum custnum ... ] =head1 DESCRIPTION @@ -98,6 +102,9 @@ the bill and collect methods of a cust_main object. See L. -c: Turn on collecting (you probably want this). + -p: Apply unapplied payments and credits before collecting (you probably want + this too) + -a: Call collect even if there isn't a new invoice (probably a bad idea for daily use) @@ -114,7 +121,7 @@ customers. Otherwise, bills all customers. =head1 VERSION -$Id: freeside-bill,v 1.7 2001-08-21 09:34:13 ivan Exp $ +$Id: freeside-bill,v 1.8 2001-09-03 22:07:39 ivan Exp $ =head1 BUGS -- cgit v1.2.1 From f5266a4d07d116efd732f433d0f4f3a47b143a7d Mon Sep 17 00:00:00 2001 From: ivan Date: Tue, 11 Sep 2001 00:08:18 +0000 Subject: faster (cached) fuzzy searches prelim. job queues! fixed part_svc editing --- FS/bin/freeside-bill | 4 +- FS/bin/freeside-queued | 145 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 148 insertions(+), 1 deletion(-) create mode 100644 FS/bin/freeside-queued (limited to 'FS/bin') diff --git a/FS/bin/freeside-bill b/FS/bin/freeside-bill index 1dce9a19b..82b3321e1 100755 --- a/FS/bin/freeside-bill +++ b/FS/bin/freeside-bill @@ -1,3 +1,5 @@ +#!/usr/bin/perl -w +# don't take any world-facing input #!/usr/bin/perl -Tw use strict; @@ -121,7 +123,7 @@ customers. Otherwise, bills all customers. =head1 VERSION -$Id: freeside-bill,v 1.8 2001-09-03 22:07:39 ivan Exp $ +$Id: freeside-bill,v 1.9 2001-09-11 00:08:18 ivan Exp $ =head1 BUGS diff --git a/FS/bin/freeside-queued b/FS/bin/freeside-queued new file mode 100644 index 000000000..5acffb52c --- /dev/null +++ b/FS/bin/freeside-queued @@ -0,0 +1,145 @@ +#!/usr/bin/perl -w + +use strict; +use Fcntl qw(:flock); +use POSIX qw(setsid); +use FS::UID qw(adminsuidsetup); +use FS::Record qw(qsearchs); +use FS::queue; + +# no autoloading just yet +use FS::cust_main; + +my $pid_file = '/var/run/freeside-queued.pid'; + +$SIG{CHLD} = sub { wait }; #zombie prevention + +my $sigterm = 0; +my $sigint = 0; +$SIG{INT} = sub { warn "SIGINT received; shutting down\n"; $sigint++; }; +$SIG{TERM} = sub { warn "SIGTERM received; shutting down\n"; $sigterm++; }; + +my $user = shift or die &usage; + +&daemonize; + +my $log_file = "/usr/local/etc/freeside/queuelog."; + +$> = $FS::UID::freeside_uid unless $>; +adminsuidsetup $user; + +$log_file = "/usr/local/etc/freeside/queuelog.". $FS::UID::datasrc; + +$SIG{__DIE__} = \&_die; +$SIG{__WARN__} = \&_logmsg; + + +while (1) { + + my $job = qsearchs( + 'queue', + { 'status' => 'new' }, + '', + 'ORDER BY jobnum FOR UPDATE LIMIT 1' + ) or do { + sleep 5; + next; + }; + + my %hash = $job->hash; + $hash{'status'} = 'locked'; + my $ljob = new FS::queue ( \%hash ); + my $error = $ljob->replace($job); + die $error if $error; + + my @args = $ljob->args; + + #fork a child for each job (up to some maximum perhaps?) + #single-threaded for now. + + my $eval = "&". $ljob->job. '(@args);'; + warn "running $eval"; + eval $eval; + if ( $@ ) { + warn "job $eval failed"; + my $hash = $ljob->hash; + $hash{'status'} = 'failed'; + my $fjob = new FS::queue( \%hash ); + my $error = $fjob->replace($ljob); + die $error if $error; + } else { + $ljob->delete; + } + +} continue { + if ( $sigterm ) { + warn "received TERM signal; exiting\n"; + exit; + } + if ( $sigint ) { + warn "received INT signal; exiting\n"; + exit; + } +} + + +sub datestamp { + time2str("%m%d%Y", time); +} + +sub _die { + my $msg = shift; + unlink $pid_file if -e $pid_file; + _logmsg($msg); +} + +sub _logmsg { + chomp( my $msg = shift ); + my $log = new IO::File ">>$log_file"; + flock($log, LOCK_EX); + seek($log, 0, 2); + print $log "[". time2str("%a %b %e %T %Y",time). "] [$$] $msg\n"; + flock($log, LOCK_UN); +} + +sub daemonize { + + chdir "/" or die "Can't chdir to /: $!"; + open STDIN, '/dev/null' or die "Can't read /dev/null: $!"; + defined(my $pid = fork) or die "Can't fork: $!"; + if ( $pid ) { + print "freeside-queued started with pid $pid\n"; #logging to $log_file\n"; + exit unless $pid_file; + my $pidfh = new IO::File ">$pid_file" or exit; + print $pidfh "$pid\n"; + exit; + } + open STDOUT, '>/dev/null' + or die "Can't write to /dev/null: $!"; + setsid or die "Can't start a new session: $!"; + open STDERR, '>&STDOUT' or die "Can't dup stdout: $!"; + +} + +=head1 NAME + +freeside-queued - Job queue daemon + +=head1 SYNOPSIS + + freeside-queued user + +=head1 DESCRIPTION + +Job queue daemon. Should be running at all times. + +user: from the mapsecrets file - see config.html from the base documentation + +=head1 VERSION + +=head1 BUGS + +=head1 SEE ALSO + +=cut + -- cgit v1.2.1 From 01ea770bbf69f2e31a2e74254ca931917f2ca1ef Mon Sep 17 00:00:00 2001 From: ivan Date: Tue, 11 Sep 2001 01:09:56 +0000 Subject: working queued --- FS/bin/freeside-queued | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-queued b/FS/bin/freeside-queued index 5acffb52c..8ed989683 100644 --- a/FS/bin/freeside-queued +++ b/FS/bin/freeside-queued @@ -1,8 +1,12 @@ #!/usr/bin/perl -w use strict; +use vars qw( $log_file $sigterm $sigint ); +use subs qw( _die _logmsg ); use Fcntl qw(:flock); use POSIX qw(setsid); +use Date::Format; +use IO::File; use FS::UID qw(adminsuidsetup); use FS::Record qw(qsearchs); use FS::queue; @@ -14,16 +18,14 @@ my $pid_file = '/var/run/freeside-queued.pid'; $SIG{CHLD} = sub { wait }; #zombie prevention -my $sigterm = 0; -my $sigint = 0; -$SIG{INT} = sub { warn "SIGINT received; shutting down\n"; $sigint++; }; -$SIG{TERM} = sub { warn "SIGTERM received; shutting down\n"; $sigterm++; }; - my $user = shift or die &usage; &daemonize; -my $log_file = "/usr/local/etc/freeside/queuelog."; + $sigterm = 0; + $sigint = 0; +$SIG{INT} = sub { warn "SIGINT received; shutting down\n"; $sigint++; }; +$SIG{TERM} = sub { warn "SIGTERM received; shutting down\n"; $sigterm++; }; $> = $FS::UID::freeside_uid unless $>; adminsuidsetup $user; @@ -33,6 +35,7 @@ $log_file = "/usr/local/etc/freeside/queuelog.". $FS::UID::datasrc; $SIG{__DIE__} = \&_die; $SIG{__WARN__} = \&_logmsg; +warn "freesied-queued starting\n"; while (1) { @@ -82,11 +85,6 @@ while (1) { } } - -sub datestamp { - time2str("%m%d%Y", time); -} - sub _die { my $msg = shift; unlink $pid_file if -e $pid_file; @@ -100,6 +98,7 @@ sub _logmsg { seek($log, 0, 2); print $log "[". time2str("%a %b %e %T %Y",time). "] [$$] $msg\n"; flock($log, LOCK_UN); + close $log; } sub daemonize { -- cgit v1.2.1 From 842df85f746a2e1b961d6c9e3a8c5cc3678ae6dd Mon Sep 17 00:00:00 2001 From: ivan Date: Tue, 11 Sep 2001 03:15:58 +0000 Subject: cyrus support --- FS/bin/freeside-queued | 2 ++ 1 file changed, 2 insertions(+) (limited to 'FS/bin') diff --git a/FS/bin/freeside-queued b/FS/bin/freeside-queued index 8ed989683..098e33f54 100644 --- a/FS/bin/freeside-queued +++ b/FS/bin/freeside-queued @@ -13,6 +13,8 @@ use FS::queue; # no autoloading just yet use FS::cust_main; +use FS::svc_acct; +use Net::SSH; my $pid_file = '/var/run/freeside-queued.pid'; -- cgit v1.2.1 From 0ee3925f49c81dbabdd8042eba96fa55f8d3141e Mon Sep 17 00:00:00 2001 From: ivan Date: Tue, 11 Sep 2001 11:52:45 +0000 Subject: rar --- FS/bin/freeside-queued | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-queued b/FS/bin/freeside-queued index 098e33f54..d8af19866 100644 --- a/FS/bin/freeside-queued +++ b/FS/bin/freeside-queued @@ -67,7 +67,7 @@ while (1) { eval $eval; if ( $@ ) { warn "job $eval failed"; - my $hash = $ljob->hash; + my %hash = $ljob->hash; $hash{'status'} = 'failed'; my $fjob = new FS::queue( \%hash ); my $error = $fjob->replace($ljob); -- cgit v1.2.1 From cb69afd435095144bea83565973561045e28c6a6 Mon Sep 17 00:00:00 2001 From: ivan Date: Tue, 11 Sep 2001 21:58:43 +0000 Subject: usage sub --- FS/bin/freeside-queued | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'FS/bin') diff --git a/FS/bin/freeside-queued b/FS/bin/freeside-queued index d8af19866..6fb294db8 100644 --- a/FS/bin/freeside-queued +++ b/FS/bin/freeside-queued @@ -87,6 +87,10 @@ while (1) { } } +sub usage { + die "Usage:\n\n freeside-queued user\n"; +} + sub _die { my $msg = shift; unlink $pid_file if -e $pid_file; -- cgit v1.2.1 From aac06e1cc16840ca746bb222a5c29280453df27e Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 19 Sep 2001 19:00:06 +0000 Subject: set $ENV{HOME} --- FS/bin/freeside-queued | 1 + 1 file changed, 1 insertion(+) (limited to 'FS/bin') diff --git a/FS/bin/freeside-queued b/FS/bin/freeside-queued index 6fb294db8..04101bbc2 100644 --- a/FS/bin/freeside-queued +++ b/FS/bin/freeside-queued @@ -30,6 +30,7 @@ $SIG{INT} = sub { warn "SIGINT received; shutting down\n"; $sigint++; }; $SIG{TERM} = sub { warn "SIGTERM received; shutting down\n"; $sigterm++; }; $> = $FS::UID::freeside_uid unless $>; +$ENV{HOME} = (getpwuid($>))[7]; #for ssh adminsuidsetup $user; $log_file = "/usr/local/etc/freeside/queuelog.". $FS::UID::datasrc; -- cgit v1.2.1 From 310a027b9b72cf7d98c7f3e05b3bd1164077f2ab Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 19 Sep 2001 21:06:17 +0000 Subject: directory hashing remove jeff's lib patch from freeside-apply-credits add freeside-apply-credits to MANIFEST README for pre3-4 --- FS/bin/freeside-apply-credits | 1 - 1 file changed, 1 deletion(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-apply-credits b/FS/bin/freeside-apply-credits index eb5c1f489..ea6a7bdd0 100755 --- a/FS/bin/freeside-apply-credits +++ b/FS/bin/freeside-apply-credits @@ -1,7 +1,6 @@ #!/usr/bin/perl -Tw use strict; -use lib "/usr/lib/perl5/site_perl/5.005/FSTest2"; use vars qw( $user $cust_main @customers ); use FS::UID qw(adminsuidsetup); use FS::Record qw(qsearch); -- cgit v1.2.1 From a2952a41f31a392ce356a299f7edf03b265ddabf Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 19 Sep 2001 21:51:41 +0000 Subject: set real uid too. whew. ssh now working. --- FS/bin/freeside-queued | 1 + 1 file changed, 1 insertion(+) (limited to 'FS/bin') diff --git a/FS/bin/freeside-queued b/FS/bin/freeside-queued index 04101bbc2..42d638f4c 100644 --- a/FS/bin/freeside-queued +++ b/FS/bin/freeside-queued @@ -30,6 +30,7 @@ $SIG{INT} = sub { warn "SIGINT received; shutting down\n"; $sigint++; }; $SIG{TERM} = sub { warn "SIGTERM received; shutting down\n"; $sigterm++; }; $> = $FS::UID::freeside_uid unless $>; +$< = $>; $ENV{HOME} = (getpwuid($>))[7]; #for ssh adminsuidsetup $user; -- cgit v1.2.1 From a08b4d18bc28e44fe236f1060632ffefc773f78b Mon Sep 17 00:00:00 2001 From: ivan Date: Mon, 24 Sep 2001 03:23:34 +0000 Subject: queue daemon forks now --- FS/bin/freeside-queued | 50 ++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 36 insertions(+), 14 deletions(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-queued b/FS/bin/freeside-queued index 42d638f4c..1eef00c5c 100644 --- a/FS/bin/freeside-queued +++ b/FS/bin/freeside-queued @@ -7,7 +7,7 @@ use Fcntl qw(:flock); use POSIX qw(setsid); use Date::Format; use IO::File; -use FS::UID qw(adminsuidsetup); +use FS::UID qw(adminsuidsetup forksuidsetup); use FS::Record qw(qsearchs); use FS::queue; @@ -29,6 +29,9 @@ my $user = shift or die &usage; $SIG{INT} = sub { warn "SIGINT received; shutting down\n"; $sigint++; }; $SIG{TERM} = sub { warn "SIGTERM received; shutting down\n"; $sigterm++; }; +#pickup zombie status +$SIG{CHLD} = sub { wait; }; + $> = $FS::UID::freeside_uid unless $>; $< = $>; $ENV{HOME} = (getpwuid($>))[7]; #for ssh @@ -61,21 +64,40 @@ while (1) { my @args = $ljob->args; - #fork a child for each job (up to some maximum perhaps?) - #single-threaded for now. - - my $eval = "&". $ljob->job. '(@args);'; - warn "running $eval"; - eval $eval; - if ( $@ ) { - warn "job $eval failed"; - my %hash = $ljob->hash; + # number of children limit? + defined( my $pid = fork ) or do { + warn "WARNING: can't fork: $!\n"; + my %hash = $job->hash; $hash{'status'} = 'failed'; - my $fjob = new FS::queue( \%hash ); - my $error = $fjob->replace($ljob); + my $ljob = new FS::queue ( \%hash ); + my $error = $ljob->replace($job); die $error if $error; - } else { - $ljob->delete; + }; + + unless ( $pid ) { #kid time + + #get new db handles + $FS::UID::dbh->{InactiveDestroy} = 1; + $FS::svc_acct::icradius_dbh->{InactiveDestroy} + if $FS::svc_acct::icradius_dbh; + forksuidsetup($user); + + my $eval = "&". $ljob->job. '(@args);'; + warn "running $eval"; + eval $eval; + if ( $@ ) { + warn "job $eval failed"; + my %hash = $ljob->hash; + $hash{'status'} = 'failed'; + my $fjob = new FS::queue( \%hash ); + my $error = $fjob->replace($ljob); + die $error if $error; + } else { + $ljob->delete; + } + + exit; + #end-of-kid } } continue { -- cgit v1.2.1 From 4ea8493d8422bd9b0d471da81e3c0cd164b9f12e Mon Sep 17 00:00:00 2001 From: ivan Date: Tue, 25 Sep 2001 00:05:09 +0000 Subject: better REAPER --- FS/bin/freeside-queued | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-queued b/FS/bin/freeside-queued index 1eef00c5c..35728db53 100644 --- a/FS/bin/freeside-queued +++ b/FS/bin/freeside-queued @@ -18,20 +18,18 @@ use Net::SSH; my $pid_file = '/var/run/freeside-queued.pid'; -$SIG{CHLD} = sub { wait }; #zombie prevention - my $user = shift or die &usage; &daemonize; +sub REAPER { my $pid = wait; $SIG{CHLD} = \&REAPER; } +$SIG{CHLD} = \&REAPER; + $sigterm = 0; $sigint = 0; $SIG{INT} = sub { warn "SIGINT received; shutting down\n"; $sigint++; }; $SIG{TERM} = sub { warn "SIGTERM received; shutting down\n"; $sigterm++; }; -#pickup zombie status -$SIG{CHLD} = sub { wait; }; - $> = $FS::UID::freeside_uid unless $>; $< = $>; $ENV{HOME} = (getpwuid($>))[7]; #for ssh -- cgit v1.2.1 From 6f325cd8d38905b98c6f11a64701653bdd9f9fcf Mon Sep 17 00:00:00 2001 From: ivan Date: Tue, 23 Oct 2001 20:53:06 +0000 Subject: Pg: FOR UPDATE LIMIT 1 mysql: LIMIT 1 FOR UPDATE greeeat. --- FS/bin/freeside-queued | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-queued b/FS/bin/freeside-queued index 35728db53..4e3724e6e 100644 --- a/FS/bin/freeside-queued +++ b/FS/bin/freeside-queued @@ -7,7 +7,7 @@ use Fcntl qw(:flock); use POSIX qw(setsid); use Date::Format; use IO::File; -use FS::UID qw(adminsuidsetup forksuidsetup); +use FS::UID qw(adminsuidsetup forksuidsetup driver_name); use FS::Record qw(qsearchs); use FS::queue; @@ -48,7 +48,9 @@ while (1) { 'queue', { 'status' => 'new' }, '', - 'ORDER BY jobnum FOR UPDATE LIMIT 1' + driver_name =~ /^mysql$/i + ? 'ORDER BY jobnum LIMIT 1 FOR UPDATE' + : 'ORDER BY jobnum FOR UPDATE LIMIT 1' ) or do { sleep 5; next; @@ -76,7 +78,7 @@ while (1) { #get new db handles $FS::UID::dbh->{InactiveDestroy} = 1; - $FS::svc_acct::icradius_dbh->{InactiveDestroy} + $FS::svc_acct::icradius_dbh->{InactiveDestroy} = 1 if $FS::svc_acct::icradius_dbh; forksuidsetup($user); -- cgit v1.2.1 From 399377be683d60fd80690504103b809885b27903 Mon Sep 17 00:00:00 2001 From: ivan Date: Tue, 30 Oct 2001 10:20:32 +0000 Subject: setup/config updates. getting easier... --- FS/bin/freeside-adduser | 52 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 FS/bin/freeside-adduser (limited to 'FS/bin') diff --git a/FS/bin/freeside-adduser b/FS/bin/freeside-adduser new file mode 100644 index 000000000..4517a83fa --- /dev/null +++ b/FS/bin/freeside-adduser @@ -0,0 +1,52 @@ +#!/usr/bin/perl -w +# +# $Id: freeside-adduser,v 1.1 2001-10-30 10:20:32 ivan Exp $ + +use strict; +use vars qw($opt_h $opt_c); +use Getopt::Std; + +my $FREESIDE_CONF = "/usr/local/etc/freeside"; + +getopts("ch:"); +die &usage if $opt_c && ! $opt_h; +my $secretfile = shift or die &usage; +my $user = shift or die &usage; + +my @args = ( 'htpasswd' ); +push @args, '-c' if $opt_c; +push @args, $opt_h, $user; +system(@args) == 0 or die "htpasswd failed: $?"; + +open(MAPSECRETS,">>$FREESIDE_CONF/mapsecrets") + or die "can't open $FREESIDE_CONF/mapsecrets: $!"; +print MAPSECRETS "$user $secretfile\n"; +close MAPSECRETS or die "can't close $FREESIDE_CONF/mapsecrets: $!"; + +sub usage { + die "Usage:\n\n freeside-adduser [ -h htpasswd_file [ -c ] ] secretfile username" +} + +=head1 NAME + +freeside-adduser - Command line interface to add (freeside) users. + +=head1 SYNOPSIS + + freeside-adduser [ -h htpasswd_file [ -c ] ] username + +=head DESCRIPTION + +Adds a user to the Freeside billing system. This is for adding users (internal +sales/tech folks) to the web interface, not for adding customer accounts. + + -h: Also call htpasswd for this user with the given filename + + -c: Passed to htpasswd + +=head1 SEE ALSO + +L, base Freeside documentation + +=cut + -- cgit v1.2.1 From edda09a317f5dfef05fb8906f28531ec6f4b0927 Mon Sep 17 00:00:00 2001 From: ivan Date: Tue, 30 Oct 2001 11:47:54 +0000 Subject: whew more install docs and automation --- FS/bin/freeside-adduser | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-adduser b/FS/bin/freeside-adduser index 4517a83fa..e66b0d012 100644 --- a/FS/bin/freeside-adduser +++ b/FS/bin/freeside-adduser @@ -1,6 +1,6 @@ #!/usr/bin/perl -w # -# $Id: freeside-adduser,v 1.1 2001-10-30 10:20:32 ivan Exp $ +# $Id: freeside-adduser,v 1.2 2001-10-30 11:47:54 ivan Exp $ use strict; use vars qw($opt_h $opt_c); @@ -33,9 +33,9 @@ freeside-adduser - Command line interface to add (freeside) users. =head1 SYNOPSIS - freeside-adduser [ -h htpasswd_file [ -c ] ] username + freeside-adduser [ -h htpasswd_file [ -c ] ] secretfile username -=head DESCRIPTION +=head1 DESCRIPTION Adds a user to the Freeside billing system. This is for adding users (internal sales/tech folks) to the web interface, not for adding customer accounts. -- cgit v1.2.1 From a8989c556a7a1951a0b34942c6289f26395859d7 Mon Sep 17 00:00:00 2001 From: ivan Date: Tue, 30 Oct 2001 13:47:07 +0000 Subject: `make create-config' installs default config (conf dir update) freeside-adduser uses default secrets file --- FS/bin/freeside-adduser | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-adduser b/FS/bin/freeside-adduser index e66b0d012..7fc5830db 100644 --- a/FS/bin/freeside-adduser +++ b/FS/bin/freeside-adduser @@ -1,16 +1,15 @@ #!/usr/bin/perl -w # -# $Id: freeside-adduser,v 1.2 2001-10-30 11:47:54 ivan Exp $ +# $Id: freeside-adduser,v 1.3 2001-10-30 13:47:07 ivan Exp $ use strict; -use vars qw($opt_h $opt_c); +use vars qw($opt_h $opt_c $opt_s); use Getopt::Std; my $FREESIDE_CONF = "/usr/local/etc/freeside"; -getopts("ch:"); +getopts("ch:s:"); die &usage if $opt_c && ! $opt_h; -my $secretfile = shift or die &usage; my $user = shift or die &usage; my @args = ( 'htpasswd' ); @@ -18,13 +17,15 @@ push @args, '-c' if $opt_c; push @args, $opt_h, $user; system(@args) == 0 or die "htpasswd failed: $?"; +my $secretfile = $opt_s || 'secrets'; + open(MAPSECRETS,">>$FREESIDE_CONF/mapsecrets") or die "can't open $FREESIDE_CONF/mapsecrets: $!"; print MAPSECRETS "$user $secretfile\n"; close MAPSECRETS or die "can't close $FREESIDE_CONF/mapsecrets: $!"; sub usage { - die "Usage:\n\n freeside-adduser [ -h htpasswd_file [ -c ] ] secretfile username" + die "Usage:\n\n freeside-adduser [ -h htpasswd_file [ -c ] ] [ -s secretfile ] username" } =head1 NAME @@ -33,7 +34,7 @@ freeside-adduser - Command line interface to add (freeside) users. =head1 SYNOPSIS - freeside-adduser [ -h htpasswd_file [ -c ] ] secretfile username + freeside-adduser [ -h htpasswd_file [ -c ] ] [ -s secretfile ] username =head1 DESCRIPTION @@ -44,6 +45,8 @@ sales/tech folks) to the web interface, not for adding customer accounts. -c: Passed to htpasswd + -s: Specify an alternate secret file + =head1 SEE ALSO L, base Freeside documentation -- cgit v1.2.1 From 3802a0ac7cbbae87a45014b0968f0a4186876d52 Mon Sep 17 00:00:00 2001 From: ivan Date: Fri, 2 Nov 2001 08:14:14 +0000 Subject: silence pod complaints --- FS/bin/freeside-print-batch | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-print-batch b/FS/bin/freeside-print-batch index baef43787..da4ecf464 100755 --- a/FS/bin/freeside-print-batch +++ b/FS/bin/freeside-print-batch @@ -229,7 +229,7 @@ B<-p>: Print to printer lpr as found in the conf directory. B<-e>: Email output to user found in the Conf email file. -B<-a>: Automatically pays all records in cust_pay_batch. Use -d with this option usually. +B<-a>: Automatically pays all records in cust_pay_batch. Usually used with the B<-d> option. B<-d>: Delete - Pays account and deletes record from cust_pay_batch. @@ -237,7 +237,7 @@ user: From the mapsecrets file - see config.html from the base documentation =head1 VERSION -$Id: freeside-print-batch,v 1.3 2001-08-21 02:44:47 ivan Exp $ +$Id: freeside-print-batch,v 1.4 2001-11-02 08:14:14 ivan Exp $ =head1 BUGS -- cgit v1.2.1 From e4c4a600a9f167f84c1a0663f73797ed18934e92 Mon Sep 17 00:00:00 2001 From: ivan Date: Mon, 5 Nov 2001 14:04:56 +0000 Subject: fixup getopt --- FS/bin/freeside-bill | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-bill b/FS/bin/freeside-bill index 82b3321e1..7898936c5 100755 --- a/FS/bin/freeside-bill +++ b/FS/bin/freeside-bill @@ -11,8 +11,8 @@ use FS::Record qw(qsearch qsearchs); use FS::cust_main; &untaint_argv; #what it sounds like (eww) -use vars qw($opt_a $opt_c $opt_i $opt_d); -getopts("acid:"); +use vars qw($opt_a $opt_c $opt_i $opt_d $opt_p); +getopts("acid:p"); my $user = shift or die &usage; adminsuidsetup $user; @@ -22,7 +22,7 @@ my %bill_only = map { $_ => 1 } ( ); #we're at now now (and later). -my($time)= $main::opt_d ? str2time($main::opt_d) : $^T; +my($time)= $opt_d ? str2time($opt_d) : $^T; # find packages w/ bill < time && cancel != '', and create corresponding # customer objects @@ -34,7 +34,7 @@ foreach $cust_main ( $saw{ $_->custnum } = 0; # to avoid 'use of uninitialized value' errors } if ( - ( $main::opt_a || ( ( $_->getfield('bill') || 0 ) <= $time ) ) + ( $opt_a || ( ( $_->getfield('bill') || 0 ) <= $time ) ) && $bill_only{ $_->custnum } && !$saw{ $_->custnum }++ ) { @@ -57,14 +57,14 @@ foreach $cust_main ( warn "Error billing, customer #" . $cust_main->getfield('custnum') . ":" . $error if $error; - if ($main::opt_p) { + if ($opt_p) { $cust_main->apply_payments; $error=$cust_main->apply_credits; } - if ($main::opt_c) { + if ($opt_c) { $error=$cust_main->collect('invoice_time'=>$time, - 'batch_card' => $main::opt_i ? 'no' : 'yes', + 'batch_card' => $opt_i ? 'no' : 'yes', ); warn "Error collecting from customer #" . $cust_main->gcustnum. ":$error" if $error; @@ -123,7 +123,7 @@ customers. Otherwise, bills all customers. =head1 VERSION -$Id: freeside-bill,v 1.9 2001-09-11 00:08:18 ivan Exp $ +$Id: freeside-bill,v 1.10 2001-11-05 14:04:56 ivan Exp $ =head1 BUGS -- cgit v1.2.1 From 9fa3f18ba6b2e910601891a15fe30448d51d43f9 Mon Sep 17 00:00:00 2001 From: ivan Date: Thu, 8 Nov 2001 15:26:44 +0000 Subject: harmless typo noticed by "Edward Shabotinsky" , thanks --- FS/bin/freeside-queued | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-queued b/FS/bin/freeside-queued index 4e3724e6e..87e3cb422 100644 --- a/FS/bin/freeside-queued +++ b/FS/bin/freeside-queued @@ -40,7 +40,7 @@ $log_file = "/usr/local/etc/freeside/queuelog.". $FS::UID::datasrc; $SIG{__DIE__} = \&_die; $SIG{__WARN__} = \&_logmsg; -warn "freesied-queued starting\n"; +warn "freeside-queued starting\n"; while (1) { -- cgit v1.2.1 From 82a77e8496deec74c06a941e6115d0f79c706241 Mon Sep 17 00:00:00 2001 From: ivan Date: Tue, 13 Nov 2001 21:27:42 +0000 Subject: remove freeside-print-batch --- FS/bin/freeside-print-batch | 260 -------------------------------------------- 1 file changed, 260 deletions(-) delete mode 100755 FS/bin/freeside-print-batch (limited to 'FS/bin') diff --git a/FS/bin/freeside-print-batch b/FS/bin/freeside-print-batch deleted file mode 100755 index da4ecf464..000000000 --- a/FS/bin/freeside-print-batch +++ /dev/null @@ -1,260 +0,0 @@ -#!/usr/bin/perl -Tw - -use strict; -#use Date::Format; -use Time::Local; -use Getopt::Std; -use FS::Conf; -use FS::UID qw(adminsuidsetup); -use FS::Record qw(qsearch); -use FS::cust_pay; -use FS::cust_pay_batch; - -# Get the currennt time and date -my $time = time; -my ($sec,$min,$hour,$mday,$mon,$year) = - (localtime($time) )[0,1,2,3,4,5]; -my $_date = - timelocal($sec,$min,$hour,$mday,$mon,$year); - -# Set the mail program -my $mail_program = "/usr/sbin/sendmail -t -n"; - -&untaint_argv; #what it sounds like (eww) -use vars qw($opt_v $opt_p $opt_e $opt_a $opt_d); -getopts("vpead"); #switches - -# 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(@batch)=qsearch('cust_pay_batch',{}); -if (scalar(@batch) == 0) -{ - exit 1; -} - -# Open print and email pipes -# $lpr and opt_p for printing -# $email and opt_e for email -# -if ($lpr && $main::opt_p) -{ - open(LPR, "|$lpr"); - print LPR qq~C R E D I T C A R D P A Y M E N T S D U E $mon/$mday/$year\n\n~; -} - -if ($email && $main::opt_e) -{ - open (MAIL, "|$mail_program"); - print MAIL <getfield('state'); - my $zip = $cust_pay_batch->getfield('zip'); - my $amount = $cust_pay_batch->getfield('amount'); - my $last = $cust_pay_batch->getfield('last'); - my $address1 = $cust_pay_batch->getfield('address1'); - my $address2 = $cust_pay_batch->getfield('address2'); - my $first = $cust_pay_batch->getfield('first'); - my $city = $cust_pay_batch->getfield('city'); - my $cardnum = $cust_pay_batch->getfield('cardnum'); - my $payname = $cust_pay_batch->getfield('payname'); - my $exp = $cust_pay_batch->getfield('exp'); - my $invnum = $cust_pay_batch->getfield('invnum'); - my $custnum = $cust_pay_batch->getfield('custnum'); - - # Need a carriage return in address before address2 - # if it exists. Otherwise address will just be address1 - my $address = $address1; - $address .= "\n$address2" if ($address2); - - # Only print to the screen in verbose mode - if ($main::opt_v) - { - printf("Invoice %d for %s %s\tCustomer Number: %d\n", - $invnum, - $first, - $last, - $custnum); - - printf("\t%s\n", $address); - printf("\t%s, %s, %s\n\n", - $city, - $state, - $zip); - - printf("\tCard Number: %s\tExp:%s\n", - $cardnum, - $exp); - printf("\t\tName: %s\n", $payname); - printf("\t\tAmount: %.2f\n\n\n", $amount); - } - - if ($lpr && $main::opt_p) - { - printf(LPR "Invoice %d for %s %s\tCustomer Number: %d\n", - $invnum, - $first, - $last, - $custnum); - - printf(LPR "\t%s\n", $address); - printf(LPR "\t%s, %s, %s\n\n", - $city, - $state, - $zip); - - printf(LPR "\tCard Number: %s\tExp:%s\n", - $cardnum, - $exp); - printf(LPR "\t\tName: %s\n", $payname); - printf(LPR "\t\tAmount: %.2f\n\n\n", $amount); - } - - if ($email && $main::opt_e) - { - printf(MAIL "Invoice %d for %s %s\tCustomer Number: %d\n", - $invnum, - $first, - $last, - $custnum); - - printf(MAIL "\t%s\n", $address); - printf(MAIL "\t%s, %s, %s\n\n", - $city, - $state, - $zip); - - printf(MAIL "\tCard Number: %s\tExp:%s\n", - $cardnum, - $exp); - printf(MAIL "\t\tName: %s\n", $payname); - printf(MAIL "\t\tAmount: %.2f\n\n\n", $amount); - } - - # Now I want to delete the records from cust_pay_batch - # and mark the records in cust_pay as paid today if - # the delete (-d) command line option is set. - if($main::opt_a) - { - my $payment=new FS::cust_pay { - 'invnum' => $invnum, - 'paid' => $amount, - '_date' => $_date, - 'payby' => "CARD", - 'payinfo' => $cardnum, - 'paybatch' => "AUTO", - }; - - my $pay_error=$payment->insert; - if ($pay_error) - { - # warn might be better if you get root's mail - # NEED TO TEST THIS BEFORE DELETE IF WARN IS USED - die "Could not update cust_pay for invnum $invnum. $pay_error\n"; - } - } - - # This just deletes the records - # Must be last in the foreach loop - if($main::opt_d) - { - my $del_error = $cust_pay_batch->delete; - if ($del_error) - { - die "Could not delete cust_pay_batch for invnum $invnum. $del_error\n"; - } - } - -} - -# Now I need to close LPR and EMAIL if they were open -if($lpr && $main::opt_p) -{ - close LPR || die "Could not close printer: $lpr\n"; -} - -if($email && $main::opt_e) -{ - close MAIL || die "Could not close printer: $lpr\n"; -} - - -# subroutines -sub untaint_argv { - foreach $_ ( $[ .. $#ARGV ) { #untaint @ARGV - $ARGV[$_] =~ /^([\w\-\/]*)$/ || die "Illegal argument \"$ARGV[$_]\""; - $ARGV[$_]=$1; - } -} - -sub usage { - die "Usage:\n\n freeside-print-batch [-v] [-p] [-e] [-a] [-d] user\n"; -} - -=head1 NAME - -freeside-print-batch - Prints or emails cust_pay_batch. Also deletes - old records and adds payment to cust_pay. - Usually run after the bill command. - -=head1 SYNOPSIS - - freeside-print-batch [-v] [-p] [-e] [-a] [-d] user - -=head1 DESCRIPTION - -Prints or emails cust_pay_batch. Can enter payment and delete -printed records. Usually run as a cron job. - -B<-v>: Verbose - Prints records to STDOUT. - -B<-p>: Print to printer lpr as found in the conf directory. - -B<-e>: Email output to user found in the Conf email file. - -B<-a>: Automatically pays all records in cust_pay_batch. Usually used with the B<-d> option. - -B<-d>: Delete - Pays account and deletes record from cust_pay_batch. - -user: From the mapsecrets file - see config.html from the base documentation - -=head1 VERSION - -$Id: freeside-print-batch,v 1.4 2001-11-02 08:14:14 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, config.html from the base documentation - -=head1 AUTHOR - -Joel Griffiths July 99 - -=cut - -- cgit v1.2.1 From 29acbc574cb1e29032c634e1f6ac63e92d14df3b Mon Sep 17 00:00:00 2001 From: ivan Date: Thu, 13 Dec 2001 09:17:52 +0000 Subject: added util to set invoice destinations --- FS/bin/freeside-setinvoice | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 FS/bin/freeside-setinvoice (limited to 'FS/bin') diff --git a/FS/bin/freeside-setinvoice b/FS/bin/freeside-setinvoice new file mode 100644 index 000000000..aeaa0bb1b --- /dev/null +++ b/FS/bin/freeside-setinvoice @@ -0,0 +1,42 @@ +#!/usr/bin/perl + +use strict; +use FS::UID qw(adminsuidsetup); +use FS::Conf; +use FS::Record qw(qsearch); +use FS::cust_main; +use FS::svc_acct; + +&untaint_argv; #what it sounds like (eww) +my $user = shift or die &usage; + +adminsuidsetup $user; + +foreach my $cust_main ( + grep { ! scalar($_->invoicing_list) } + qsearch( 'cust_main', {} ) +) { + my @dest; + my @cust_pkg = $cust_main->ncancelled_pkgs; + foreach my $cust_pkg ( @cust_pkg ) { + foreach my $cust_svc ( $cust_pkg->cust_svc ) { + my $svc_acct = qsearchs( 'svc_acct', {} ); + push @dest, $svc_acct->svcnum if $svc_acct; + } + } + push @dest, 'POST' unless @dest; + $cust_main->invoicing_list(@dest); +} + +sub untaint_argv { + foreach $_ ( $[ .. $#ARGV ) { #untaint @ARGV + $ARGV[$_] =~ /^(.*)$/ || die "Illegal arguement \"$ARGV[$_]\""; + $ARGV[$_]=$1; + } +} + +sub usage { + die "Usage:\n\n freeside-setinvoice user\n"; +} + + -- cgit v1.2.1 From 156535a911a8ad4315dcdee397cf8aff2071b520 Mon Sep 17 00:00:00 2001 From: ivan Date: Thu, 13 Dec 2001 17:52:37 +0000 Subject: fix setinvoice script --- FS/bin/freeside-setinvoice | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-setinvoice b/FS/bin/freeside-setinvoice index aeaa0bb1b..3eb75f8b7 100644 --- a/FS/bin/freeside-setinvoice +++ b/FS/bin/freeside-setinvoice @@ -3,7 +3,7 @@ use strict; use FS::UID qw(adminsuidsetup); use FS::Conf; -use FS::Record qw(qsearch); +use FS::Record qw(qsearch qsearchs); use FS::cust_main; use FS::svc_acct; @@ -20,7 +20,7 @@ foreach my $cust_main ( my @cust_pkg = $cust_main->ncancelled_pkgs; foreach my $cust_pkg ( @cust_pkg ) { foreach my $cust_svc ( $cust_pkg->cust_svc ) { - my $svc_acct = qsearchs( 'svc_acct', {} ); + my $svc_acct = qsearchs( 'svc_acct', { 'svcnum' => $cust_svc->svcnum } ); push @dest, $svc_acct->svcnum if $svc_acct; } } -- cgit v1.2.1 From f78c8ea9034ef02671aa68512dc5458a0c693cc0 Mon Sep 17 00:00:00 2001 From: ivan Date: Thu, 13 Dec 2001 18:37:25 +0000 Subject: okay, it should really work now --- FS/bin/freeside-setinvoice | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-setinvoice b/FS/bin/freeside-setinvoice index 3eb75f8b7..708e2fa30 100644 --- a/FS/bin/freeside-setinvoice +++ b/FS/bin/freeside-setinvoice @@ -25,7 +25,7 @@ foreach my $cust_main ( } } push @dest, 'POST' unless @dest; - $cust_main->invoicing_list(@dest); + $cust_main->invoicing_list(\@dest); } sub untaint_argv { -- cgit v1.2.1 From b6b291e9894efecc061aaef6d4af3c510bb32fad Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 26 Dec 2001 11:17:49 +0000 Subject: (untested eek) freeside-overdue script & cust_main balance_date & total_owed_date methods --- FS/bin/freeside-overdue | 139 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 139 insertions(+) create mode 100755 FS/bin/freeside-overdue (limited to 'FS/bin') diff --git a/FS/bin/freeside-overdue b/FS/bin/freeside-overdue new file mode 100755 index 000000000..541b8be03 --- /dev/null +++ b/FS/bin/freeside-overdue @@ -0,0 +1,139 @@ +#!/usr/bin/perl + +use strict; +use vars qw( $days_to_pay $cust_main $cust_pkg + $cust_svc $svc_acct ); +use Getopt::Std; +use FS::cust_main; +use FS::cust_pkg; +use FS::cust_svc; +use FS::svc_acct; +use FS::Record qw(qsearch qsearchs); +use FS::UID qw(adminsuidsetup); + +&untaint_argv; +my %opt; +getopts('ed:qpsc', \%opt); +my $user = shift or die &usage; + +adminsuidsetup $user; + +my $now = time; +my ($sec,$min,$hour,$mday,$mon,$year) = + (localtime($now) )[0,1,2,3,4,5]; +$mon++; +$year += 1900; + +foreach $cust_main ( qsearch('cust_main',{} ) ) { + + my ( $eyear, $emon, $eday ) = ( 2037, 12, 31 ); + if ( $cust_main->paydate =~ /^(\d{4})\-(\d{1,2})\-(\d{1,2})$/ + && $cust_main->payby eq 'BILL') { + ( $eyear, $emon, $eday ) = ( $1, $2, $3 ); + } + + if ( ( $opt{d} + && $cust_main->balance_date(time - $opt{d} * 86400) > 0 + && qsearchs( 'cust_pkg', { 'custnum' => $cust_main->custnum, + 'susp' => "" } ) ) + || ( $opt{e} + && $cust_main->payby eq 'BILL' + && ( $eyear < $year + || ( $eyear == $year && $emon < $mon ) ) ) + ) { + + unless ( $opt{q} ) { + print $cust_main->custnum, "\t", + $cust_main->last, "\t", $cust_main->first, "\t", + $cust_main->balance_date(time-$opt{d} * 86400); + } + + foreach $cust_pkg ( qsearch( 'cust_pkg', + { 'custnum' => $cust_main->custnum } ) ) { + + if ($opt{p} && ! grep { $_ eq 'POST' } $cust_main->invoicing_list ) { + print "\n\tAdding postal invoicing" unless $opt{q}; + my @invoicing_list = $cust_main->invoicing_list; + push @invoicing_list, 'POST'; + $cust_main->invoicing_list(\@invoicing_list); + } + + if ($opt{s}) { + print "\n\tSuspending pkgnum " . $cust_pkg->pkgnum unless $opt{q}; + $cust_pkg->suspend; + } + + if ($opt{c}) { + print "\n\tCancelling pkgnum " . $cust_pkg->pkgnum unless $opt{q}; + $cust_pkg->cancel; + } + + } + + print "\n" unless $opt{q}; + + } + +} + +sub untaint_argv { + foreach $_ ( $[ .. $#ARGV ) { + $ARGV[$_] =~ /^([\w\-\/]*)$/ || die "Illegal arguement \"$ARGV[$_]\""; + $ARGV[$_]=$1; + } +} + +sub usage { + die "Usage:\n\n freeside-overdue [ -e ] [ -d days ] [ -q ] [ -p ] [ -s ] [ -c ] user\n"; +} + + +=head1 NAME + +freeside-overdue - Perform actions on overdue and/or expired accounts. + +=head1 SYNOPSIS + + freeside-overdue [ -e ] [ -d days ] [ -q ] [ -p ] [ -s ] [ -c ] user + +=head1 DESCRIPTION + +Performs actions on overdue and/or expired accounts. + +Selection options (at least one selection option is required): + + -d: Customers with a balance due on invoices older than the supplied number + of days. Requires an integer argument. + + -e: Customers with a billing expiration date in the past. + +Action options: + + -q: Be quiet (by default, suspended accounts are printed). + + -p: Add postal invoicing to the relevant customers. + + -s: Suspend accounts. + + -c: Cancel accounts. + + user: From the mapsecrets file - see config.html from the base documentation + +=head1 CRONTAB + +Example crontab entries: + +20 4,16 * * * freeside-overdue -e -s user +20 4,16 * * * freeside-overdue -d 30 -p -q user +20 4,16 * * * freeside-overdue -d 60 user +20 4,16 * * * freeside-overdue -d 90 -s user +20 4,16 * * * freeside-overdue -d 120 -c user + +=head1 ORIGINAL AUTHORS + +Original disable-overdue version by mw/kwh: Mark W.? and Kristian Hoffmann ? + +=cut + +1; + -- cgit v1.2.1 From d2f2a080fa2a94c0dd1535b87b3d8f6a59fb2bbb Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 26 Dec 2001 11:47:52 +0000 Subject: don't provide example crontabs that run at 4:20 _PM_ --- FS/bin/freeside-overdue | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-overdue b/FS/bin/freeside-overdue index 541b8be03..45d534461 100755 --- a/FS/bin/freeside-overdue +++ b/FS/bin/freeside-overdue @@ -123,11 +123,11 @@ Action options: Example crontab entries: -20 4,16 * * * freeside-overdue -e -s user -20 4,16 * * * freeside-overdue -d 30 -p -q user -20 4,16 * * * freeside-overdue -d 60 user -20 4,16 * * * freeside-overdue -d 90 -s user -20 4,16 * * * freeside-overdue -d 120 -c user +20 4 * * * freeside-overdue -e -s user +20 4 * * * freeside-overdue -d 30 -p -q user +20 4 * * * freeside-overdue -d 60 user +20 4 * * * freeside-overdue -d 90 -s user +20 4 * * * freeside-overdue -d 120 -c user =head1 ORIGINAL AUTHORS -- cgit v1.2.1 From 854f8d1e160d394d5019292d7e7a9019f06cc1b9 Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 26 Dec 2001 15:08:49 +0000 Subject: add freeside-overdue --- FS/bin/freeside-overdue | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-overdue b/FS/bin/freeside-overdue index 45d534461..65941ce95 100755 --- a/FS/bin/freeside-overdue +++ b/FS/bin/freeside-overdue @@ -13,7 +13,7 @@ use FS::UID qw(adminsuidsetup); &untaint_argv; my %opt; -getopts('ed:qpsc', \%opt); +getopts('ed:qplsc', \%opt); my $user = shift or die &usage; adminsuidsetup $user; @@ -48,10 +48,15 @@ foreach $cust_main ( qsearch('cust_main',{} ) ) { $cust_main->balance_date(time-$opt{d} * 86400); } + if ( $opt{l} ) { + print "\n\tCharging late fee of \$$opt{l}" unless $opt{q}; + + } + foreach $cust_pkg ( qsearch( 'cust_pkg', { 'custnum' => $cust_main->custnum } ) ) { - if ($opt{p} && ! grep { $_ eq 'POST' } $cust_main->invoicing_list ) { + if ( $opt{p} && ! grep { $_ eq 'POST' } $cust_main->invoicing_list ) { print "\n\tAdding postal invoicing" unless $opt{q}; my @invoicing_list = $cust_main->invoicing_list; push @invoicing_list, 'POST'; @@ -84,7 +89,7 @@ sub untaint_argv { } sub usage { - die "Usage:\n\n freeside-overdue [ -e ] [ -d days ] [ -q ] [ -p ] [ -s ] [ -c ] user\n"; + die "Usage:\n\n freeside-overdue [ -e ] [ -d days ] [ -q ] [ -p ] [ -l amount ] [ -s ] [ -c ] user\n"; } @@ -94,7 +99,7 @@ freeside-overdue - Perform actions on overdue and/or expired accounts. =head1 SYNOPSIS - freeside-overdue [ -e ] [ -d days ] [ -q ] [ -p ] [ -s ] [ -c ] user + freeside-overdue [ -e ] [ -d days ] [ -q ] [ -p ] [ -l amount ] [ -s ] [ -c ] user =head1 DESCRIPTION @@ -109,10 +114,12 @@ Selection options (at least one selection option is required): Action options: - -q: Be quiet (by default, suspended accounts are printed). + -q: Be quiet (by default, selected accounts are printed). -p: Add postal invoicing to the relevant customers. + -l: Add a charge of the given amount to the relevant customers. + -s: Suspend accounts. -c: Cancel accounts. @@ -123,11 +130,17 @@ Action options: Example crontab entries: +# suspend expired accounts 20 4 * * * freeside-overdue -e -s user + +# quietly add postal invoicing to customers over 30 days past due 20 4 * * * freeside-overdue -d 30 -p -q user -20 4 * * * freeside-overdue -d 60 user -20 4 * * * freeside-overdue -d 90 -s user -20 4 * * * freeside-overdue -d 120 -c user + +# suspend accounts and charge a $10.23 fee for customers over 60 days past due +20 4 * * * freeside-overdue -d 60 -s -l 10.23 user + +# cancel accounts over 90 days past due +20 4 * * * freeside-overdue -d 90 -c user =head1 ORIGINAL AUTHORS -- cgit v1.2.1 From cf16b23820da69e3c8d0156ae27e21c635bf1ec5 Mon Sep 17 00:00:00 2001 From: ivan Date: Thu, 27 Dec 2001 09:26:14 +0000 Subject: service and package disable! --- FS/bin/freeside-overdue | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-overdue b/FS/bin/freeside-overdue index 65941ce95..0c62b99c1 100755 --- a/FS/bin/freeside-overdue +++ b/FS/bin/freeside-overdue @@ -48,10 +48,10 @@ foreach $cust_main ( qsearch('cust_main',{} ) ) { $cust_main->balance_date(time-$opt{d} * 86400); } - if ( $opt{l} ) { - print "\n\tCharging late fee of \$$opt{l}" unless $opt{q}; - - } +# if ( $opt{l} ) { +# print "\n\tCharging late fee of \$$opt{l}" unless $opt{q}; +# +# } foreach $cust_pkg ( qsearch( 'cust_pkg', { 'custnum' => $cust_main->custnum } ) ) { @@ -83,7 +83,7 @@ foreach $cust_main ( qsearch('cust_main',{} ) ) { sub untaint_argv { foreach $_ ( $[ .. $#ARGV ) { - $ARGV[$_] =~ /^([\w\-\/]*)$/ || die "Illegal arguement \"$ARGV[$_]\""; + $ARGV[$_] =~ /^([\w\-\/\.]*)$/ || die "Illegal arguement \"$ARGV[$_]\""; $ARGV[$_]=$1; } } -- cgit v1.2.1 From 5e25b996982d42eb2587ec54db0d5b39508aa730 Mon Sep 17 00:00:00 2001 From: ivan Date: Fri, 28 Dec 2001 14:40:35 +0000 Subject: add more options to freeside-overdue add charge method to FS::cust_main one-off packages default to disabled billing payname defaults to first and last, not "Accounts Payable" --- FS/bin/freeside-bill | 6 ++-- FS/bin/freeside-overdue | 85 ++++++++++++++++++++++++++++++++++++------------- 2 files changed, 65 insertions(+), 26 deletions(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-bill b/FS/bin/freeside-bill index 7898936c5..49ec43c82 100755 --- a/FS/bin/freeside-bill +++ b/FS/bin/freeside-bill @@ -59,14 +59,14 @@ foreach $cust_main ( if ($opt_p) { $cust_main->apply_payments; - $error=$cust_main->apply_credits; + $cust_main->apply_credits; } if ($opt_c) { $error=$cust_main->collect('invoice_time'=>$time, 'batch_card' => $opt_i ? 'no' : 'yes', ); - warn "Error collecting from customer #" . $cust_main->gcustnum. ":$error" + warn "Error collecting from customer #" . $cust_main->custnum. ":$error" if $error; #sleep 1; @@ -123,7 +123,7 @@ customers. Otherwise, bills all customers. =head1 VERSION -$Id: freeside-bill,v 1.10 2001-11-05 14:04:56 ivan Exp $ +$Id: freeside-bill,v 1.11 2001-12-28 14:40:35 ivan Exp $ =head1 BUGS diff --git a/FS/bin/freeside-overdue b/FS/bin/freeside-overdue index 0c62b99c1..8f7f872c8 100755 --- a/FS/bin/freeside-overdue +++ b/FS/bin/freeside-overdue @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/bin/perl -w use strict; use vars qw( $days_to_pay $cust_main $cust_pkg @@ -13,12 +13,12 @@ use FS::UID qw(adminsuidsetup); &untaint_argv; my %opt; -getopts('ed:qplsc', \%opt); +getopts('ed:qplscbyoi', \%opt); my $user = shift or die &usage; adminsuidsetup $user; -my $now = time; +my $now = time; #eventually take a time option like freeside-bill my ($sec,$min,$hour,$mday,$mon,$year) = (localtime($now) )[0,1,2,3,4,5]; $mon++; @@ -48,21 +48,23 @@ foreach $cust_main ( qsearch('cust_main',{} ) ) { $cust_main->balance_date(time-$opt{d} * 86400); } -# if ( $opt{l} ) { -# print "\n\tCharging late fee of \$$opt{l}" unless $opt{q}; -# -# } + if ( $opt{p} && ! grep { $_ eq 'POST' } $cust_main->invoicing_list ) { + print "\n\tAdding postal invoicing" unless $opt{q}; + my @invoicing_list = $cust_main->invoicing_list; + push @invoicing_list, 'POST'; + $cust_main->invoicing_list(\@invoicing_list); + } + + if ( $opt{l} ) { + print "\n\tCharging late fee of \$$opt{l}" unless $opt{q}; + my $error = $cust_main->charge($opt{l}, 'Late fee'); + # comment or plandata with info so we don't redo the same late fee every + # day + } foreach $cust_pkg ( qsearch( 'cust_pkg', { 'custnum' => $cust_main->custnum } ) ) { - if ( $opt{p} && ! grep { $_ eq 'POST' } $cust_main->invoicing_list ) { - print "\n\tAdding postal invoicing" unless $opt{q}; - my @invoicing_list = $cust_main->invoicing_list; - push @invoicing_list, 'POST'; - $cust_main->invoicing_list(\@invoicing_list); - } - if ($opt{s}) { print "\n\tSuspending pkgnum " . $cust_pkg->pkgnum unless $opt{q}; $cust_pkg->suspend; @@ -72,7 +74,29 @@ foreach $cust_main ( qsearch('cust_main',{} ) ) { print "\n\tCancelling pkgnum " . $cust_pkg->pkgnum unless $opt{q}; $cust_pkg->cancel; } + + } + + if ( $opt{b} ) { + print "\n\tBilling" unless $opt{q}; + my $error = $cust_main->bill('time'=>$now); + warn "Error billing, customer #" . $cust_main->custnum . + ":" . $error if $error; + } + if ( $opt{y} ) { + print "\n\tApplying outstanding payments and credits" unless $opt{q}; + $cust_main->apply_payments; + $cust_main->apply_credits; + } + + if ( $opt{o} ) { + print "\n\tCollecting" unless $opt{q}; + my $error = $cust_main->collect( 'invoice_time'=>$now, + 'batch_card' => $opt{i} ? 'no' : 'yes', + ); + warn "Error collecting from customer #" . $cust_main->custnum. ":$error" + if $error; } print "\n" unless $opt{q}; @@ -99,7 +123,7 @@ freeside-overdue - Perform actions on overdue and/or expired accounts. =head1 SYNOPSIS - freeside-overdue [ -e ] [ -d days ] [ -q ] [ -p ] [ -l amount ] [ -s ] [ -c ] user + freeside-overdue [ -e ] [ -d days ] [ -q ] [ -p ] [ -l amount ] [ -s ] [ -c ] [ -b ] [ -y ] [ -o [ -i ] ] user =head1 DESCRIPTION @@ -107,22 +131,31 @@ Performs actions on overdue and/or expired accounts. Selection options (at least one selection option is required): - -d: Customers with a balance due on invoices older than the supplied number - of days. Requires an integer argument. + -d: Customers with a balance due on invoices older than the supplied number + of days. Requires an integer argument. - -e: Customers with a billing expiration date in the past. + -e: Customers with a billing expiration date in the past. Action options: - -q: Be quiet (by default, selected accounts are printed). + -q: Be quiet (by default, selected accounts are printed). + + -p: Add postal invoicing to the relevant customers. + + -l: Add a charge of the given amount to the relevant customers. + + -s: Suspend accounts. - -p: Add postal invoicing to the relevant customers. + -c: Cancel accounts. - -l: Add a charge of the given amount to the relevant customers. + -b: Bill customers (create invoices) - -s: Suspend accounts. + -y: Apply unapplied payments and credits - -c: Cancel accounts. + -o: Collect from customers (charge cards, print invoices) + + -i: real-time billing (as opposed to batch billing). only relevant + for credit cards. user: From the mapsecrets file - see config.html from the base documentation @@ -146,6 +179,12 @@ Example crontab entries: Original disable-overdue version by mw/kwh: Mark W.? and Kristian Hoffmann ? +Ivan seems to be turning it into the "do-everything" CLI. + +=head1 BUGS + +Hell now that this is the do-everything CLI it should have --longoptions + =cut 1; -- cgit v1.2.1 From 368fe197549dab5edf86cd37b64b9fdddbd07a65 Mon Sep 17 00:00:00 2001 From: ivan Date: Fri, 28 Dec 2001 15:14:01 +0000 Subject: force printing in freeside-overdue --- FS/bin/freeside-overdue | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-overdue b/FS/bin/freeside-overdue index 8f7f872c8..076330228 100755 --- a/FS/bin/freeside-overdue +++ b/FS/bin/freeside-overdue @@ -92,9 +92,11 @@ foreach $cust_main ( qsearch('cust_main',{} ) ) { if ( $opt{o} ) { print "\n\tCollecting" unless $opt{q}; - my $error = $cust_main->collect( 'invoice_time'=>$now, - 'batch_card' => $opt{i} ? 'no' : 'yes', - ); + my $error = $cust_main->collect( + 'invoice_time' => $now, + 'batch_card' => $opt{i} ? 'no' : 'yes', + 'force_print' => 'yes', + ); warn "Error collecting from customer #" . $cust_main->custnum. ":$error" if $error; } -- cgit v1.2.1 From e3f87d761538a0a21d26fc86b5bce7c9d737d590 Mon Sep 17 00:00:00 2001 From: ivan Date: Fri, 28 Dec 2001 15:17:40 +0000 Subject: update usage message --- FS/bin/freeside-overdue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-overdue b/FS/bin/freeside-overdue index 076330228..964321884 100755 --- a/FS/bin/freeside-overdue +++ b/FS/bin/freeside-overdue @@ -115,7 +115,7 @@ sub untaint_argv { } sub usage { - die "Usage:\n\n freeside-overdue [ -e ] [ -d days ] [ -q ] [ -p ] [ -l amount ] [ -s ] [ -c ] user\n"; + die "Usage:\n\n freeside-overdue [ -e ] [ -d days ] [ -q ] [ -p ] [ -l amount ] [ -s ] [ -c ] [ -b ] [ -y ] [ -o [ -i ] ] user\n"; } -- cgit v1.2.1 From 947a8fac5088418d76d92494f810d6a3b3313595 Mon Sep 17 00:00:00 2001 From: ivan Date: Mon, 14 Jan 2002 14:29:00 +0000 Subject: fix -l option --- FS/bin/freeside-overdue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-overdue b/FS/bin/freeside-overdue index 964321884..db99e62b4 100755 --- a/FS/bin/freeside-overdue +++ b/FS/bin/freeside-overdue @@ -13,7 +13,7 @@ use FS::UID qw(adminsuidsetup); &untaint_argv; my %opt; -getopts('ed:qplscbyoi', \%opt); +getopts('ed:qpl:scbyoi', \%opt); my $user = shift or die &usage; adminsuidsetup $user; -- cgit v1.2.1 From 0144506246df56f2f705d4edc3cf29cd7dd0ed24 Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 6 Feb 2002 14:58:05 +0000 Subject: fix for non-file auth --- FS/bin/freeside-adduser | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-adduser b/FS/bin/freeside-adduser index 7fc5830db..9d424634b 100644 --- a/FS/bin/freeside-adduser +++ b/FS/bin/freeside-adduser @@ -1,6 +1,6 @@ #!/usr/bin/perl -w # -# $Id: freeside-adduser,v 1.3 2001-10-30 13:47:07 ivan Exp $ +# $Id: freeside-adduser,v 1.4 2002-02-06 14:58:05 ivan Exp $ use strict; use vars qw($opt_h $opt_c $opt_s); @@ -12,10 +12,12 @@ getopts("ch:s:"); die &usage if $opt_c && ! $opt_h; my $user = shift or die &usage; -my @args = ( 'htpasswd' ); -push @args, '-c' if $opt_c; -push @args, $opt_h, $user; -system(@args) == 0 or die "htpasswd failed: $?"; +if ( $opt_h ) { + my @args = ( 'htpasswd' ); + push @args, '-c' if $opt_c; + push @args, $opt_h, $user; + system(@args) == 0 or die "htpasswd failed: $?"; +} my $secretfile = $opt_s || 'secrets'; -- cgit v1.2.1 From 298b8d9a262265fe7106da1ff552ce6778237034 Mon Sep 17 00:00:00 2001 From: ivan Date: Sun, 10 Feb 2002 01:48:00 +0000 Subject: remove -i option from freeside-bill (obsoleted by invoice events) --- FS/bin/freeside-bill | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-bill b/FS/bin/freeside-bill index 49ec43c82..6ef344a50 100755 --- a/FS/bin/freeside-bill +++ b/FS/bin/freeside-bill @@ -11,8 +11,8 @@ use FS::Record qw(qsearch qsearchs); use FS::cust_main; &untaint_argv; #what it sounds like (eww) -use vars qw($opt_a $opt_c $opt_i $opt_d $opt_p); -getopts("acid:p"); +use vars qw($opt_a $opt_c $opt_d $opt_p); +getopts("acd:p"); my $user = shift or die &usage; adminsuidsetup $user; @@ -63,9 +63,7 @@ foreach $cust_main ( } if ($opt_c) { - $error=$cust_main->collect('invoice_time'=>$time, - 'batch_card' => $opt_i ? 'no' : 'yes', - ); + $error=$cust_main->collect( 'invoice_time' => $time); warn "Error collecting from customer #" . $cust_main->custnum. ":$error" if $error; @@ -86,7 +84,7 @@ sub untaint_argv { } sub usage { - die "Usage:\n\n freeside-bill [ -c [ i ] ] [ -d 'date' ] [ -b ] user\n"; + die "Usage:\n\n freeside-bill [ -c [ -p ] ] [ -d 'date' ] user [ custnum custnum ... ]\n"; } =head1 NAME @@ -95,7 +93,7 @@ freeside-bill - Command line (crontab, script) interface to customer billing. =head1 SYNOPSIS - freeside-bill [ -c [ -p ] [ -a ] [ -i ] ] [ -d 'date' ] user [ custnum custnum ... ] + freeside-bill [ -c [ -p ] [ -a ] ] [ -d 'date' ] user [ custnum custnum ... ] =head1 DESCRIPTION @@ -110,9 +108,6 @@ the bill and collect methods of a cust_main object. See L. -a: Call collect even if there isn't a new invoice (probably a bad idea for daily use) - -i: real-time billing (as opposed to batch billing). only relevant - for credit cards. - -d: Pretend it's 'date'. Date is in any format Date::Parse is happy with, but be careful. @@ -123,7 +118,7 @@ customers. Otherwise, bills all customers. =head1 VERSION -$Id: freeside-bill,v 1.11 2001-12-28 14:40:35 ivan Exp $ +$Id: freeside-bill,v 1.12 2002-02-10 01:48:00 ivan Exp $ =head1 BUGS -- cgit v1.2.1 From 7e3eb82f87c371785544b706b7347c7edde2b593 Mon Sep 17 00:00:00 2001 From: ivan Date: Sun, 10 Feb 2002 19:58:43 +0000 Subject: update billing documentation for the new world of invoice events added freeside-daily replacing freeside-bill for the new world of invoice events --- FS/bin/freeside-bill | 8 ++--- FS/bin/freeside-daily | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+), 5 deletions(-) create mode 100755 FS/bin/freeside-daily (limited to 'FS/bin') diff --git a/FS/bin/freeside-bill b/FS/bin/freeside-bill index 6ef344a50..49ad4a768 100755 --- a/FS/bin/freeside-bill +++ b/FS/bin/freeside-bill @@ -97,6 +97,8 @@ freeside-bill - Command line (crontab, script) interface to customer billing. =head1 DESCRIPTION +This script is deprecated in 1.4.0. You should use freeside-daily instead. + Bills customers. Searches for customers who are due for billing and calls the bill and collect methods of a cust_main object. See L. @@ -116,15 +118,11 @@ user: From the mapsecrets file - see config.html from the base documentation custnum: if one or more customer numbers are specified, only bills those customers. Otherwise, bills all customers. -=head1 VERSION - -$Id: freeside-bill,v 1.12 2002-02-10 01:48:00 ivan Exp $ - =head1 BUGS =head1 SEE ALSO -L, config.html from the base documentation +L, L, config.html from the base documentation =cut diff --git a/FS/bin/freeside-daily b/FS/bin/freeside-daily new file mode 100755 index 000000000..8d839cb21 --- /dev/null +++ b/FS/bin/freeside-daily @@ -0,0 +1,90 @@ +#!/usr/bin/perl -w + +use strict; +use Fcntl qw(:flock); +use Date::Parse; +use Getopt::Std; +use FS::UID qw(adminsuidsetup); +use FS::Record qw(qsearch qsearchs); +use FS::cust_main; + +&untaint_argv; #what it sounds like (eww) +use vars qw($opt_d); +getopts("d:"); +my $user = shift or die &usage; + +adminsuidsetup $user; + +my @cust_main = @ARGV + ? map { qsearchs('cust_main', { custnum => $_ } ) } @ARGV + : qsearch('cust_main', {} ) +; + +#we're at now now (and later). +my($time)= $opt_d ? str2time($opt_d) : $^T; + +my($cust_main,%saw); +foreach $cust_main ( @cust_main ) { + + my $error; + + $error = $cust_main->bill( 'time' => $time ); + warn "Error billing, custnum ". $cust_main->custnum. ": $error" if $error; + + $cust_main->apply_payments; + $cust_main->apply_credits; + + $error=$cust_main->collect( 'invoice_time' => $time ); + warn "Error collecting, custnum". $cust_main->custnum. ": $error" if $error; + +} + +# subroutines + +sub untaint_argv { + foreach $_ ( $[ .. $#ARGV ) { #untaint @ARGV + #$ARGV[$_] =~ /^([\w\-\/]*)$/ || die "Illegal arguement \"$ARGV[$_]\""; + # Date::Parse + $ARGV[$_] =~ /^(.*)$/ || die "Illegal arguement \"$ARGV[$_]\""; + $ARGV[$_]=$1; + } +} + +sub usage { + die "Usage:\n\n freeside-daily [ -d 'date' ] user [ custnum custnum ... ]\n"; +} + +=head1 NAME + +freeside-daily - Run daily billing and invoice collection events. + +=head1 SYNOPSIS + + freeside-daily [ -d 'date' ] user [ custnum custnum ... ] + +=head1 DESCRIPTION + +Bills customers and runs invoice collection events. Should be run from +crontab daily. + +This script replaces freeside-bill from 1.3.1. + +Bills customers. Searches for customers who are due for billing and calls +the bill and collect methods of a cust_main object. See L. + + -d: Pretend it's 'date'. Date is in any format Date::Parse is happy with, + but be careful. + +user: From the mapsecrets file - see config.html from the base documentation + +custnum: if one or more customer numbers are specified, only bills those +customers. Otherwise, bills all customers. + +=head1 BUGS + +=head1 SEE ALSO + +L, config.html from the base documentation + +=cut + -- cgit v1.2.1 From 8f42b751aebda2e7dce2c363bed6f1e15b411b1d Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 20 Feb 2002 01:03:10 +0000 Subject: use Net::SSH::ssh_cmd for all job queueing rather than local duplicated ssh subs queue daemon updates: retry & remove links work, bubble up error message to webinterface, link to svcnum & have job listings on view/svc_* pages, closes: Bug#280 s/option/optionname/ schema change, dumb mysql, closes: Bug#334 --- FS/bin/freeside-queued | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-queued b/FS/bin/freeside-queued index 87e3cb422..56475d059 100644 --- a/FS/bin/freeside-queued +++ b/FS/bin/freeside-queued @@ -14,7 +14,7 @@ use FS::queue; # no autoloading just yet use FS::cust_main; use FS::svc_acct; -use Net::SSH; +use Net::SSH 0.05; my $pid_file = '/var/run/freeside-queued.pid'; @@ -69,6 +69,7 @@ while (1) { warn "WARNING: can't fork: $!\n"; my %hash = $job->hash; $hash{'status'} = 'failed'; + $hash{'statustext'} = "[freeside-queued] can't fork: $!"; my $ljob = new FS::queue ( \%hash ); my $error = $ljob->replace($job); die $error if $error; @@ -89,6 +90,7 @@ while (1) { warn "job $eval failed"; my %hash = $ljob->hash; $hash{'status'} = 'failed'; + $hash{'statustext'} = $@; my $fjob = new FS::queue( \%hash ); my $error = $fjob->replace($ljob); die $error if $error; -- cgit v1.2.1 From b50b2e5f94774268c271484f9c07bfe316f95527 Mon Sep 17 00:00:00 2001 From: jeff Date: Fri, 22 Feb 2002 23:18:34 +0000 Subject: add some reporting features --- FS/bin/freeside-cc-receipts-report | 231 +++++++++++++++++++++++++++++++ FS/bin/freeside-credit-report | 184 +++++++++++++++++++++++++ FS/bin/freeside-receivables-report | 218 ++++++++++++++++++++++++++++++ FS/bin/freeside-tax-report | 270 +++++++++++++++++++++++++++++++++++++ 4 files changed, 903 insertions(+) create mode 100755 FS/bin/freeside-cc-receipts-report create mode 100755 FS/bin/freeside-credit-report create mode 100755 FS/bin/freeside-receivables-report create mode 100755 FS/bin/freeside-tax-report (limited to 'FS/bin') diff --git a/FS/bin/freeside-cc-receipts-report b/FS/bin/freeside-cc-receipts-report new file mode 100755 index 000000000..2713af397 --- /dev/null +++ b/FS/bin/freeside-cc-receipts-report @@ -0,0 +1,231 @@ +#!/usr/bin/perl -Tw + +use strict; +use Date::Parse; +use Time::Local; +use Getopt::Std; +use FS::Conf; +use FS::UID qw(adminsuidsetup); +use FS::Record qw(qsearch qsearchs); +use FS::cust_pay; +use FS::cust_pay_batch; + +# Set the mail program +my $mail_program = "/usr/sbin/sendmail -t -n"; + +&untaint_argv; #what it sounds like (eww) +use vars qw($opt_v $opt_p $opt_e $opt_d $opt_s); +getopts("vped:s:"); #switches + +#we're at now now (and later). +my($_enddate)= $main::opt_d ? str2time($main::opt_d) : $^T; +my($_startdate)= $main::opt_d ? str2time($main::opt_s) : $^T; + +# Get the current month +my ($ssec,$smin,$shour,$smday,$smon,$syear) = + (localtime($_startdate) )[0,1,2,3,4,5]; +$syear+=1900; +$smon++; + +# Get the current month +my ($esec,$emin,$ehour,$emday,$emon,$eyear) = + (localtime($_enddate) )[0,1,2,3,4,5]; +$eyear+=1900; +$emon++; + +# 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(@cust_pays)=qsearch('cust_pay',{}); +if (scalar(@cust_pays) == 0) +{ + exit 1; +} + +# Open print and email pipes +# $lpr and opt_p for printing +# $email and opt_e for email + +if ($lpr && $main::opt_p) +{ + open(LPR, "|$lpr"); + print LPR qq~ C R E D I T C A R D R E C E I P T S for period beginning: $smon/$smday/$syear and ending $emon/$emday/$eyear\n\n~; +} + +if ($email && $main::opt_e) +{ + open (MAIL, "|$mail_program"); + print MAIL <getfield('_date'); + my $invnum = $cust_pay->getfield('invnum'); + my $paid = $cust_pay->getfield('paid'); + my $payby = $cust_pay->getfield('payby'); + + + if ($_date >= $_startdate && $_date <= $_enddate && $payby =~ 'CARD') { + $total += $paid; + + $uninvoiced += $cust_pay->unapplied; + my @cust_bill_pays = $cust_pay->cust_bill_pay; + foreach my $cust_bill_pay (@cust_bill_pays) { + my $invoice_amt =0; + my $invoice_tax =0; + my(@cust_bill_pkgs)= $cust_bill_pay->cust_bill->cust_bill_pkg; + foreach my $cust_bill_pkg (@cust_bill_pkgs) { + + my $recur = $cust_bill_pkg->getfield('recur'); + my $setup = $cust_bill_pkg->getfield('setup'); + my $pkgnum = $cust_bill_pkg->getfield('pkgnum'); + + if ($pkgnum == 0) { + $invoice_tax += $recur; + $invoice_tax += $setup; + } else { + $invoice_amt += $recur; + $invoice_amt += $setup; + } + + } + + if ($invoice_tax > 0) { + if ($invoice_amt != $paid) { + # attempt to prorate partially paid invoices + $total_tax += $paid / ($invoice_amt + $invoice_tax) * $invoice_tax; + $taxed += $paid / ($invoice_amt + $invoice_tax) * $invoice_amt; + } else { + $total_tax += $invoice_tax; + $taxed += $invoice_amt; + } + } else { + $untaxed += $paid; + } + + } + + } + +} + +if ($main::opt_v) { + printf(qq{\n%25s%14.2f\n}, "Uninvoiced", $uninvoiced); + printf(qq{%25s%14.2f\n}, "Untaxed", $untaxed); + printf(qq{%25s%14.2f\n}, "Taxed", $taxed); + printf(qq{%25s%14.2f\n}, "Tax", $total_tax); + printf(qq{\n%39s\n%39.2f\n}, "=========", $total); +} + +# Now I need to close LPR and EMAIL if they were open +if($lpr && $main::opt_p) +{ + printf(LPR qq{\n%25s%14.2f\n}, "Uninvoiced", $uninvoiced); + printf(LPR qq{%25s%14.2f\n}, "Untaxed", $untaxed); + printf(LPR qq{%25s%14.2f\n}, "Taxed", $taxed); + printf(LPR qq{%25s%14.2f\n}, "Tax", $total_tax); + printf(LPR qq{\n%39s\n%39.2f\n}, "=========", $total); + close LPR || die "Could not close printer: $lpr\n"; +} +if($email && $main::opt_e) +{ + printf(MAIL qq{\n%25s%14.2f\n}, "Untaxed", $untaxed); + printf(MAIL qq{%25s%14.2f\n}, "Taxed", $taxed); + printf(MAIL qq{%25s%14.2f\n}, "Tax", $total_tax); + printf(MAIL qq{\n%39s\n%39.2f\n}, "=========", $total); + close MAIL || die "Could not close printer: $email\n"; +} + + +# subroutines +sub untaint_argv { + foreach $_ ( $[ .. $#ARGV ) { #untaint @ARGV + $ARGV[$_] =~ /^([\w\-\/ :]*)$/ || die "Illegal argument \"$ARGV[$_]\""; + $ARGV[$_]=$1; + } +} + +sub usage { + die "Usage:\n\n freeside-tax-report [-v] [-p] [-e] user\n"; +} + +=head1 NAME + +freeside-tax-report - Prints or emails sales taxes invoiced in a given period. + +=head1 SYNOPSIS + + freeside-tax-report [-v] [-p] [-e] user + +=head1 DESCRIPTION + +Prints or emails sales taxes invoiced in a given period. + +-v: Verbose - Prints records to STDOUT. + +-p: Print to printer lpr as found in the conf directory. + +-e: Email output to user found in the Conf email file. + +user: From the mapsecrets file - see config.html from the base documentation + +=head1 VERSION + +$Id: freeside-cc-receipts-report,v 1.1 2002-02-22 23:18:32 jeff 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, config.html from the base documentation + +=head1 HISTORY + +griff@aver-computer.com July 99 + +$Log: freeside-cc-receipts-report,v $ +Revision 1.1 2002-02-22 23:18:32 jeff +add some reporting features + +Revision 1.2 2002/02/19 14:24:53 jeff +might be functional now + +Revision 1.1 2000/09/20 19:25:19 jeff +local modifications + +Revision 1.1 2000/05/13 21:57:56 ivan +add print_batch script from Joel Griffiths + + +=cut + + diff --git a/FS/bin/freeside-credit-report b/FS/bin/freeside-credit-report new file mode 100755 index 000000000..4307a21b0 --- /dev/null +++ b/FS/bin/freeside-credit-report @@ -0,0 +1,184 @@ +#!/usr/bin/perl -Tw + +use strict; +use Date::Parse; +use Time::Local; +use Getopt::Std; +use FS::Conf; +use FS::UID qw(adminsuidsetup); +use FS::Record qw(qsearch); +use FS::cust_credit; + +# Set the mail program +my $mail_program = "/usr/sbin/sendmail -t -n"; + +&untaint_argv; #what it sounds like (eww) +use vars qw($opt_v $opt_p $opt_e $opt_d $opt_s); +getopts("vped:s:"); #switches + +#we're at now now (and later). +my($_enddate)= $main::opt_d ? str2time($main::opt_d) : $^T; +my($_startdate)= $main::opt_s ? str2time($main::opt_s) : $^T; + +# Get the current month +my ($ssec,$smin,$shour,$smday,$smon,$syear) = + (localtime($_startdate) )[0,1,2,3,4,5]; +$syear+=1900; +$smon++; + +# Get the current month +my ($esec,$emin,$ehour,$emday,$emon,$eyear) = + (localtime($_enddate) )[0,1,2,3,4,5]; +$eyear+=1900; +$emon++; + +# 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(@cust_credits)=qsearch('cust_credit',{}); +if (scalar(@cust_credits) == 0) +{ + exit 1; +} + +# Open print and email pipes +# $lpr and opt_p for printing +# $email and opt_e for email + +if ($lpr && $main::opt_p) +{ + open(LPR, "|$lpr"); + print LPR qq~ I N H O U S E C R E D I T S for period beginning: $smon/$smday/$syear and ending $emon/$emday/$eyear\n\n~; +} + +if ($email && $main::opt_e) +{ + open (MAIL, "|$mail_program"); + print MAIL <getfield('_date'); + my $amount = $cust_credit->getfield('amount'); + my $credited = $cust_credit->getfield('credited'); + + + if ($_date >= $_startdate && $_date <= $_enddate) { + $total += $amount; + + my ($sec,$min,$hour,$mday,$mon,$year) = + (localtime($_date) )[0,1,2,3,4,5]; + $mon++; + + } + +} + +if ($main::opt_v) { + printf(qq{\n\n%25s%14.2f\n}, "Credits Offered", $total); + printf(qq{\n%39s\n%39.2f\n}, "=========", $total); +} + +# Now I need to close LPR and EMAIL if they were open +if($lpr && $main::opt_p) +{ + printf(LPR qq{\n\n%25s%14.2f\n}, "Credits Offered", $total); + printf(LPR qq{\n%39s\n%39.2f\n}, "=========", $total); + close LPR || die "Could not close printer: $lpr\n"; +} +if($email && $main::opt_e) +{ + printf(MAIL qq{\n\n%25s%14.2f\n}, "Credits Offered", $total); + printf(MAIL qq{\n%39s\n%39.2f\n}, "=========", $total); + close MAIL || die "Could not close printer: $email\n"; +} + + +# subroutines +sub untaint_argv { + foreach $_ ( $[ .. $#ARGV ) { #untaint @ARGV + $ARGV[$_] =~ /^([\w\-\/ :]*)$/ || die "Illegal argument \"$ARGV[$_]\""; + $ARGV[$_]=$1; + } +} + +sub usage { + die "Usage:\n\n freeside-credit-report [-v] [-p] [-e] user\n"; +} + +=head1 NAME + +freeside-credit-report - Prints or emails in house credits offered in a given period. + +=head1 SYNOPSIS + + freeside-credit-report [-v] [-p] [-e] user + +=head1 DESCRIPTION + +Prints or emails in house credits offered in a given period. + +-v: Verbose - Prints records to STDOUT. + +-p: Print to printer lpr as found in the conf directory. + +-e: Email output to user found in the Conf email file. + +user: From the mapsecrets file - see config.html from the base documentation + +=head1 VERSION + +$Id: freeside-credit-report,v 1.1 2002-02-22 23:18:32 jeff 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, config.html from the base documentation + +=head1 HISTORY + +griff@aver-computer.com July 99 + +$Log: freeside-credit-report,v $ +Revision 1.1 2002-02-22 23:18:32 jeff +add some reporting features + +Revision 1.1 2002/02/19 14:24:53 jeff +might be functional now + +Revision 1.1 2000/09/20 19:25:19 jeff +local modifications + +Revision 1.1 2000/05/13 21:57:56 ivan +add print_batch script from Joel Griffiths + + +=cut + + diff --git a/FS/bin/freeside-receivables-report b/FS/bin/freeside-receivables-report new file mode 100755 index 000000000..cef652bfe --- /dev/null +++ b/FS/bin/freeside-receivables-report @@ -0,0 +1,218 @@ +#!/usr/bin/perl -Tw + +use strict; +use Date::Parse; +use Time::Local; +use Getopt::Std; +use Text::Template; +use FS::Conf; +use FS::UID qw(adminsuidsetup); +use FS::Record qw(qsearch); +use FS::cust_main; + +# Set the mail program +my $mail_program = "/usr/sbin/sendmail -t -n"; + +&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); +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 @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) +{ + open (MAIL, "|$mail_program"); + print MAIL <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{%5d %-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) +{ + print MAIL map "$_\n", @report; + close MAIL || die "Could not close printer: $email\n"; +} + + +# 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 + +-v: Verbose - Prints records to STDOUT. + +-p: Print to printer lpr as found in the conf directory. + +-m: Mail output to user found in the Conf email file. + +-e: Print a final form feed to the printer. + +-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.1 2002-02-22 23:18:32 jeff 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, config.html from the base documentation + +=head1 HISTORY + +griff@aver-computer.com July 99 + +$Log: freeside-receivables-report,v $ +Revision 1.1 2002-02-22 23:18:32 jeff +add some reporting features + +Revision 1.1 2000/09/20 19:25:19 jeff +local modifications + +Revision 1.1 2000/05/13 21:57:56 ivan +add print_batch script from Joel Griffiths + + +=cut + + diff --git a/FS/bin/freeside-tax-report b/FS/bin/freeside-tax-report new file mode 100755 index 000000000..334c4107b --- /dev/null +++ b/FS/bin/freeside-tax-report @@ -0,0 +1,270 @@ +#!/usr/bin/perl -Tw + +use strict; +use Date::Parse; +use Time::Local; +use Getopt::Std; +use FS::Conf; +use FS::UID qw(adminsuidsetup); +use FS::Record qw(qsearch); +use FS::cust_pay; +use FS::cust_pay_batch; + +# Set the mail program +my $mail_program = "/usr/sbin/sendmail -t -n"; + +&untaint_argv; #what it sounds like (eww) +use vars qw($opt_v $opt_p $opt_e $opt_d $opt_s); +getopts("vped:s:"); #switches + +#we're at now now (and later). +my($_enddate)= $main::opt_d ? str2time($main::opt_d) : $^T; +my($_startdate)= $main::opt_s ? str2time($main::opt_s) : $^T; + +# Get the current month +my ($ssec,$smin,$shour,$smday,$smon,$syear) = + (localtime($_startdate) )[0,1,2,3,4,5]; +$smon++; +$syear -= 100 if $syear >= 100; +$syear = "0" . $syear if $syear < 10; + +# Get the current month +my ($esec,$emin,$ehour,$emday,$emon,$eyear) = + (localtime($_enddate) )[0,1,2,3,4,5]; +$emon++; +$eyear -= 100 if $eyear >= 100; +$eyear = "0" . $eyear if $eyear < 10; + +# 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(@cust_bills)=qsearch('cust_bill',{}); +if (scalar(@cust_bills) == 0) +{ + exit 1; +} + +if ($main::opt_v) +{ + print qq~ S A L E S T A X E S I N V O I C E D for period beginning: $smon/$smday/$syear and ending $emon/$emday/$eyear\n\n~; +} + +# Open print and email pipes +# $lpr and opt_p for printing +# $email and opt_e for email + +if ($lpr && $main::opt_p) +{ + open(LPR, "|$lpr"); + print LPR qq~ S A L E S T A X E S I N V O I C E D for period beginning: $smon/$smday/$syear and ending $emon/$emday/$eyear\n\n~; +} + +if ($email && $main::opt_e) +{ + open (MAIL, "|$mail_program"); + print MAIL <getfield('_date'); + my $invnum = $cust_bill->getfield('invnum'); + my $charged = $cust_bill->getfield('charged'); + + + if ($_date >= $_startdate && $_date <= $_enddate) { + $total += $charged; + + # The following lines were used to produce rather verbose reports + #my ($sec,$min,$hour,$mday,$mon,$year) = + # (localtime($_date) )[0,1,2,3,4,5]; + #$mon++; + #$year -= 100 if $year >= 100; + #$year = "0" . $year if $year < 10; + + my $invoice_amt =0; + my $invoice_tax =0; + my $invoice_compped =0; + my(@cust_bill_pkgs)= $cust_bill->cust_bill_pkg; + foreach my $cust_bill_pkg (@cust_bill_pkgs) { + + my $recur = $cust_bill_pkg->getfield('recur'); + my $setup = $cust_bill_pkg->getfield('setup'); + my $pkgnum = $cust_bill_pkg->getfield('pkgnum'); + + if ($pkgnum == 0) { + # The following line was used to produce rather verbose reports + # printf(MAIL qq{\n%10s%15s%14.2f}, "$mon/$mday/$year", "Tax $invnum", $recur+$setup); + $invoice_tax += $recur; + $invoice_tax += $setup; + } else { + # The following line was used to produce rather verbose reports + # printf(MAIL qq{\n%10s%15s%14.2f}, "$mon/$mday/$year", "Inv $invnum", $recur+$setup); + $invoice_amt += $recur; + $invoice_amt += $setup; + } + + } + + my(@cust_bill_pays)= $cust_bill->cust_bill_pay; + foreach my $cust_bill_pay (@cust_bill_pays) { + my $payby = $cust_bill_pay->cust_pay->payby; + my $paid = $cust_bill_pay->getfield('amount'); + if ($payby =~ 'COMP') { + $invoice_compped += $paid; + } + } + + if (abs($invoice_compped - ($invoice_amt + $invoice_tax)) < 0.0001){ + $compped += $invoice_amt; + $compped_tax += $invoice_tax; + } elsif ($invoice_compped > 0) { + printf(qq{\nInvoice %10d has inexpliciable complimentary payments of %14.9f\n}, $invnum, $invoice_compped); + $other += $invoice_amt; + $other_tax += $invoice_tax; + } elsif ($invoice_tax > 0) { + $total_tax += $invoice_tax; + $taxed += $invoice_amt; + } else { + $untaxed += $invoice_amt; + } + + } + +} + +if ($main::opt_v) { + printf(qq{\n\n%25s%14.2f\n}, "Complimentary", $compped); + printf(qq{%25s%14.2f\n}, "Complimentary Tax", $compped_tax); + printf(qq{%25s%14.2f\n}, "Other", $other); + printf(qq{%25s%14.2f\n}, "Other Tax", $other_tax); + printf(qq{%25s%14.2f\n}, "Untaxed", $untaxed); + printf(qq{%25s%14.2f\n}, "Taxed", $taxed); + printf(qq{%25s%14.2f\n}, "Tax", $total_tax); + printf(qq{\n%39s\n%39.2f\n}, "=========", $total); +} + +# Now I need to close LPR and EMAIL if they were open +if($lpr && $main::opt_p) +{ + printf(LPR qq{\n\n%25s%14.2f\n}, "Complimentary", $compped); + printf(LPR qq{%25s%14.2f\n}, "Complimentary Tax", $compped_tax); + printf(LPR qq{%25s%14.2f\n}, "Other", $other); + printf(LPR qq{%25s%14.2f\n}, "Other Tax", $other_tax); + printf(LPR qq{%25s%14.2f\n}, "Untaxed", $untaxed); + printf(LPR qq{%25s%14.2f\n}, "Taxed", $taxed); + printf(LPR qq{%25s%14.2f\n}, "Tax", $total_tax); + printf(LPR qq{\n%39s\n%39.2f\n}, "=========", $total); + close LPR || die "Could not close printer: $lpr\n"; +} +if($email && $main::opt_e) +{ + printf(MAIL qq{\n\n%25s%14.2f\n}, "Complimentary", $compped); + printf(MAIL qq{%25s%14.2f\n}, "Complimentary Tax", $compped_tax); + printf(MAIL qq{%25s%14.2f\n}, "Other", $other); + printf(MAIL qq{%25s%14.2f\n}, "Other Tax", $other_tax); + printf(MAIL qq{%25s%14.2f\n}, "Untaxed", $untaxed); + printf(MAIL qq{%25s%14.2f\n}, "Taxed", $taxed); + printf(MAIL qq{%25s%14.2f\n}, "Tax", $total_tax); + printf(MAIL qq{\n%39s\n%39.2f\n}, "=========", $total); + close MAIL || die "Could not close printer: $email\n"; +} + + +# subroutines +sub untaint_argv { + foreach $_ ( $[ .. $#ARGV ) { #untaint @ARGV + $ARGV[$_] =~ /^([\w\-\/ :]*)$/ || die "Illegal argument \"$ARGV[$_]\""; + $ARGV[$_]=$1; + } +} + +sub usage { + die "Usage:\n\n freeside-tax-report [-v] [-p] [-e] user\n"; +} + +=head1 NAME + +freeside-tax-report - Prints or emails sales taxes invoiced in a given period. + +=head1 SYNOPSIS + + freeside-tax-report [-v] [-p] [-e] user + +=head1 DESCRIPTION + +Prints or emails sales taxes invoiced in a given period. + +-v: Verbose - Prints records to STDOUT. + +-p: Print to printer lpr as found in the conf directory. + +-e: Email output to user found in the Conf email file. + +user: From the mapsecrets file - see config.html from the base documentation + +=head1 VERSION + +$Id: freeside-tax-report,v 1.1 2002-02-22 23:18:32 jeff 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, config.html from the base documentation + +=head1 HISTORY + +griff@aver-computer.com July 99 + +$Log: freeside-tax-report,v $ +Revision 1.1 2002-02-22 23:18:32 jeff +add some reporting features + +Revision 1.3 2002/02/19 14:24:53 jeff +might be functional now + +Revision 1.2 2001/08/20 18:31:49 jeff +before-merge-to-freeside_1_4_0-pre1 + +Revision 1.1 2000/09/20 19:25:19 jeff +local modifications + +Revision 1.1 2000/05/13 21:57:56 ivan +add print_batch script from Joel Griffiths + + +=cut + + -- cgit v1.2.1 From 49bc2dac92d2bb60e000088449b27aa380cc3490 Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 27 Feb 2002 21:57:24 +0000 Subject: better debugging --- FS/bin/freeside-daily | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-daily b/FS/bin/freeside-daily index 8d839cb21..e6f02df33 100755 --- a/FS/bin/freeside-daily +++ b/FS/bin/freeside-daily @@ -9,12 +9,14 @@ use FS::Record qw(qsearch qsearchs); use FS::cust_main; &untaint_argv; #what it sounds like (eww) -use vars qw($opt_d); -getopts("d:"); +use vars qw($opt_d $opt_v); +getopts("d:v"); my $user = shift or die &usage; adminsuidsetup $user; +$FS::cust_main::Debug = 1 if $opt_v; + my @cust_main = @ARGV ? map { qsearchs('cust_main', { custnum => $_ } ) } @ARGV : qsearch('cust_main', {} ) -- cgit v1.2.1 From f9734784e69f0a24e25fdeb6554d6563577e9296 Mon Sep 17 00:00:00 2001 From: ivan Date: Tue, 5 Mar 2002 09:44:09 +0000 Subject: yes i have crazy customers with 8-digit customer numbers --- FS/bin/freeside-receivables-report | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-receivables-report b/FS/bin/freeside-receivables-report index cef652bfe..c4d188c4e 100755 --- a/FS/bin/freeside-receivables-report +++ b/FS/bin/freeside-receivables-report @@ -91,7 +91,7 @@ foreach my $customer (@customers) if ($balance != 0) { $total += $balance; - push @buf, sprintf(qq{%5d %-32.32s %12s %9.2f}, + push @buf, sprintf(qq{%8d %-32.32s %12s %9.2f}, $custnum, $first . " " . $last . " " . $company, $daytime, @@ -183,7 +183,7 @@ user: From the mapsecrets file - see config.html from the base documentation =head1 VERSION -$Id: freeside-receivables-report,v 1.1 2002-02-22 23:18:32 jeff Exp $ +$Id: freeside-receivables-report,v 1.2 2002-03-05 09:44:09 ivan Exp $ =head1 BUGS @@ -203,7 +203,10 @@ L, config.html from the base documentation griff@aver-computer.com July 99 $Log: freeside-receivables-report,v $ -Revision 1.1 2002-02-22 23:18:32 jeff +Revision 1.2 2002-03-05 09:44:09 ivan +yes i have crazy customers with 8-digit customer numbers + +Revision 1.1 2002/02/22 23:18:32 jeff add some reporting features Revision 1.1 2000/09/20 19:25:19 jeff -- cgit v1.2.1 From 6c2f4c44fc083bde9dd055bd4db51e65fa377379 Mon Sep 17 00:00:00 2001 From: jeff Date: Tue, 5 Mar 2002 23:13:24 +0000 Subject: consistency is nice --- FS/bin/freeside-cc-receipts-report | 127 +++++++++++------ FS/bin/freeside-credit-report | 135 +++++++++++------- FS/bin/freeside-receivables-report | 15 +- FS/bin/freeside-tax-report | 273 ++++++++++++++++++++----------------- 4 files changed, 318 insertions(+), 232 deletions(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-cc-receipts-report b/FS/bin/freeside-cc-receipts-report index 2713af397..5ea8cc5cb 100755 --- a/FS/bin/freeside-cc-receipts-report +++ b/FS/bin/freeside-cc-receipts-report @@ -1,9 +1,11 @@ #!/usr/bin/perl -Tw + use strict; use Date::Parse; use Time::Local; use Getopt::Std; +use Text::Template; use FS::Conf; use FS::UID qw(adminsuidsetup); use FS::Record qw(qsearch qsearchs); @@ -14,24 +16,24 @@ use FS::cust_pay_batch; my $mail_program = "/usr/sbin/sendmail -t -n"; &untaint_argv; #what it sounds like (eww) -use vars qw($opt_v $opt_p $opt_e $opt_d $opt_s); -getopts("vped:s:"); #switches +use vars qw($opt_v $opt_p $opt_m $opt_e $opt_t $opt_s $opt_f $report_lines $report_template @buf); +getopts("vpmef:s:"); #switches #we're at now now (and later). -my($_enddate)= $main::opt_d ? str2time($main::opt_d) : $^T; -my($_startdate)= $main::opt_d ? str2time($main::opt_s) : $^T; +my($_finishdate)= $opt_f ? str2time($main::opt_f) : $^T; +my($_startdate)= $opt_s ? str2time($main::opt_s) : $^T; # Get the current month my ($ssec,$smin,$shour,$smday,$smon,$syear) = (localtime($_startdate) )[0,1,2,3,4,5]; -$syear+=1900; $smon++; +$syear += 1900; # Get the current month -my ($esec,$emin,$ehour,$emday,$emon,$eyear) = - (localtime($_enddate) )[0,1,2,3,4,5]; -$eyear+=1900; -$emon++; +my ($fsec,$fmin,$fhour,$fmday,$fmon,$fyear) = + (localtime($_finishdate) )[0,1,2,3,4,5]; +$fmon++; +$fyear += 1900; # Login to the database my $user = shift or die &usage; @@ -41,6 +43,19 @@ adminsuidsetup $user; my $conf = new FS::Conf; my $lpr = $conf->config('lpr'); my $email = $conf->config('email'); +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(@cust_pays)=qsearch('cust_pay',{}); if (scalar(@cust_pays) == 0) @@ -50,15 +65,14 @@ if (scalar(@cust_pays) == 0) # Open print and email pipes # $lpr and opt_p for printing -# $email and opt_e for email +# $email and opt_m for email if ($lpr && $main::opt_p) { open(LPR, "|$lpr"); - print LPR qq~ C R E D I T C A R D R E C E I P T S for period beginning: $smon/$smday/$syear and ending $emon/$emday/$eyear\n\n~; } -if ($email && $main::opt_e) +if ($email && $main::opt_m) { open (MAIL, "|$mail_program"); print MAIL <getfield('payby'); - if ($_date >= $_startdate && $_date <= $_enddate && $payby =~ 'CARD') { + if ($_date >= $_startdate && $_date <= $_finishdate && $payby =~ 'CARD') { $total += $paid; $uninvoiced += $cust_pay->unapplied; @@ -131,31 +143,54 @@ foreach my $cust_pay (@cust_pays) } -if ($main::opt_v) { - printf(qq{\n%25s%14.2f\n}, "Uninvoiced", $uninvoiced); - printf(qq{%25s%14.2f\n}, "Untaxed", $untaxed); - printf(qq{%25s%14.2f\n}, "Taxed", $taxed); - printf(qq{%25s%14.2f\n}, "Tax", $total_tax); - printf(qq{\n%39s\n%39.2f\n}, "=========", $total); +push @buf, sprintf(qq{\n%25s%14.2f\n}, "Uninvoiced", $uninvoiced); +push @buf, sprintf(qq{%25s%14.2f\n}, "Untaxed", $untaxed); +push @buf, sprintf(qq{%25s%14.2f\n}, "Taxed", $taxed); +push @buf, sprintf(qq{%25s%14.2f\n}, "Tax", $total_tax); +push @buf, sprintf(qq{\n%39s\n%39.2f\n}, "=========", $total); + +sub FS::cc_receipts_report::_template::report_lines { + my $lines = shift; + map { + scalar(@buf) ? shift @buf : '' ; + } + ( 1 .. $lines ); } -# Now I need to close LPR and EMAIL if they were open -if($lpr && $main::opt_p) +$FS::cc_receipts_report::_template::title = qq~CREDIT CARD RECEIPTS for period $smon/$smday/$syear through $fmon/$fmday/$fyear~; +$FS::cc_receipts_report::_template::title = $opt_t if $opt_t; +$FS::cc_receipts_report::_template::page = 1; +$FS::cc_receipts_report::_template::date = $^T; +$FS::cc_receipts_report::_template::date = $^T; +$FS::cc_receipts_report::_template::fdate = $_finishdate; +$FS::cc_receipts_report::_template::fdate = $_finishdate; +$FS::cc_receipts_report::_template::sdate = $_startdate; +$FS::cc_receipts_report::_template::sdate = $_startdate; +$FS::cc_receipts_report::_template::total_pages = + int( scalar(@buf) / $report_lines); +$FS::cc_receipts_report::_template::total_pages++ if scalar(@buf) % $report_lines; + +my @report; +while (@buf) { + push @report, split("\n", + $report_template->fill_in( PACKAGE => 'FS::cc_receipts_report::_template' ) + ); + $FS::cc_receipts_report::_template::page++; +} + +if ($opt_v) { + print map "$_\n", @report; +} +if($lpr && $opt_p) { - printf(LPR qq{\n%25s%14.2f\n}, "Uninvoiced", $uninvoiced); - printf(LPR qq{%25s%14.2f\n}, "Untaxed", $untaxed); - printf(LPR qq{%25s%14.2f\n}, "Taxed", $taxed); - printf(LPR qq{%25s%14.2f\n}, "Tax", $total_tax); - printf(LPR qq{\n%39s\n%39.2f\n}, "=========", $total); - close LPR || die "Could not close printer: $lpr\n"; + print LPR map "$_\n", @report; + print LPR "\f" if $opt_e; + close LPR || die "Could not close printer: $lpr\n"; } -if($email && $main::opt_e) +if($email && $opt_m) { - printf(MAIL qq{\n%25s%14.2f\n}, "Untaxed", $untaxed); - printf(MAIL qq{%25s%14.2f\n}, "Taxed", $taxed); - printf(MAIL qq{%25s%14.2f\n}, "Tax", $total_tax); - printf(MAIL qq{\n%39s\n%39.2f\n}, "=========", $total); - close MAIL || die "Could not close printer: $email\n"; + print MAIL map "$_\n", @report; + close MAIL || die "Could not close printer: $email\n"; } @@ -168,16 +203,16 @@ sub untaint_argv { } sub usage { - die "Usage:\n\n freeside-tax-report [-v] [-p] [-e] user\n"; + die "Usage:\n\n freeside-cc-receipts-report [-v] [-p] [-e] user\n"; } =head1 NAME -freeside-tax-report - Prints or emails sales taxes invoiced in a given period. +freeside-cc-receipts-report - Prints or emails total credit card receipts in a given period. =head1 SYNOPSIS - freeside-tax-report [-v] [-p] [-e] user + freeside-cc-receipts-report [-v] [-p] [-m] [-e] [-t "title"] [-s date] [-f date] user =head1 DESCRIPTION @@ -187,13 +222,21 @@ Prints or emails sales taxes invoiced in a given period. -p: Print to printer lpr as found in the conf directory. --e: Email output to user found in the Conf email file. +-m: Email output to user found in the Conf email file. + +-e: Print a final form feed to the printer. + +-t: supply a title for the top of each page. + +-s: starting date for inclusion + +-f: final date for inclusion user: From the mapsecrets file - see config.html from the base documentation =head1 VERSION -$Id: freeside-cc-receipts-report,v 1.1 2002-02-22 23:18:32 jeff Exp $ +$Id: freeside-cc-receipts-report,v 1.2 2002-03-05 23:13:23 jeff Exp $ =head1 BUGS @@ -213,8 +256,8 @@ L, config.html from the base documentation griff@aver-computer.com July 99 $Log: freeside-cc-receipts-report,v $ -Revision 1.1 2002-02-22 23:18:32 jeff -add some reporting features +Revision 1.2 2002-03-05 23:13:23 jeff +consistency is nice Revision 1.2 2002/02/19 14:24:53 jeff might be functional now diff --git a/FS/bin/freeside-credit-report b/FS/bin/freeside-credit-report index 4307a21b0..92931bcee 100755 --- a/FS/bin/freeside-credit-report +++ b/FS/bin/freeside-credit-report @@ -1,9 +1,11 @@ #!/usr/bin/perl -Tw + use strict; use Date::Parse; use Time::Local; use Getopt::Std; +use Text::Template; use FS::Conf; use FS::UID qw(adminsuidsetup); use FS::Record qw(qsearch); @@ -13,24 +15,24 @@ use FS::cust_credit; my $mail_program = "/usr/sbin/sendmail -t -n"; &untaint_argv; #what it sounds like (eww) -use vars qw($opt_v $opt_p $opt_e $opt_d $opt_s); -getopts("vped:s:"); #switches +use vars qw($opt_v $opt_p $opt_m $opt_e $opt_t $opt_s $opt_f $report_lines $report_template @buf); +getopts("vpmef:s:"); #switches #we're at now now (and later). -my($_enddate)= $main::opt_d ? str2time($main::opt_d) : $^T; -my($_startdate)= $main::opt_s ? str2time($main::opt_s) : $^T; +my($_finishdate)= $opt_f ? str2time($main::opt_f) : $^T; +my($_startdate)= $opt_s ? str2time($main::opt_s) : $^T; # Get the current month my ($ssec,$smin,$shour,$smday,$smon,$syear) = (localtime($_startdate) )[0,1,2,3,4,5]; -$syear+=1900; $smon++; +$syear += 1900; # Get the current month -my ($esec,$emin,$ehour,$emday,$emon,$eyear) = - (localtime($_enddate) )[0,1,2,3,4,5]; -$eyear+=1900; -$emon++; +my ($fsec,$fmin,$fhour,$fmday,$fmon,$fyear) = + (localtime($_finishdate) )[0,1,2,3,4,5]; +$fmon++; +$fyear += 1900; # Login to the database my $user = shift or die &usage; @@ -40,6 +42,19 @@ adminsuidsetup $user; my $conf = new FS::Conf; my $lpr = $conf->config('lpr'); my $email = $conf->config('email'); +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(@cust_credits)=qsearch('cust_credit',{}); if (scalar(@cust_credits) == 0) @@ -49,15 +64,14 @@ if (scalar(@cust_credits) == 0) # Open print and email pipes # $lpr and opt_p for printing -# $email and opt_e for email +# $email and opt_m for email if ($lpr && $main::opt_p) { open(LPR, "|$lpr"); - print LPR qq~ I N H O U S E C R E D I T S for period beginning: $smon/$smday/$syear and ending $emon/$emday/$eyear\n\n~; } -if ($email && $main::opt_e) +if ($email && $main::opt_m) { open (MAIL, "|$mail_program"); print MAIL <getfield('_date'); my $amount = $cust_credit->getfield('amount'); - my $credited = $cust_credit->getfield('credited'); - - if ($_date >= $_startdate && $_date <= $_enddate) { + if ($_date >= $_startdate && $_date <= $_finishdate) { $total += $amount; - - my ($sec,$min,$hour,$mday,$mon,$year) = - (localtime($_date) )[0,1,2,3,4,5]; - $mon++; - } +} +push @buf, sprintf(qq{\n%25s%14.2f\n}, "Credits Offered", $total); +push @buf, sprintf(qq{\n%39s\n%39.2f\n}, "=========", $total); + +sub FS::credit_report::_template::report_lines { + my $lines = shift; + map { + scalar(@buf) ? shift @buf : '' ; + } + ( 1 .. $lines ); } -if ($main::opt_v) { - printf(qq{\n\n%25s%14.2f\n}, "Credits Offered", $total); - printf(qq{\n%39s\n%39.2f\n}, "=========", $total); +$FS::credit_report::_template::title = qq~IN HOUSE CREDITS for $smon/$smday/$syear through $fmon/$fmday/$fyear~; +$FS::credit_report::_template::title = $opt_t if $opt_t; +$FS::credit_report::_template::page = 1; +$FS::credit_report::_template::date = $^T; +$FS::credit_report::_template::date = $^T; +$FS::credit_report::_template::fdate = $_finishdate; +$FS::credit_report::_template::fdate = $_finishdate; +$FS::credit_report::_template::sdate = $_startdate; +$FS::credit_report::_template::sdate = $_startdate; +$FS::credit_report::_template::total_pages = + int( scalar(@buf) / $report_lines); +$FS::credit_report::_template::total_pages++ if scalar(@buf) % $report_lines; + +my @report; +while (@buf) { + push @report, split("\n", + $report_template->fill_in( PACKAGE => 'FS::credit_report::_template' ) + ); + $FS::credit_report::_template::page++; } -# Now I need to close LPR and EMAIL if they were open -if($lpr && $main::opt_p) +if ($opt_v) { + print map "$_\n", @report; +} +if($lpr && $opt_p) { - printf(LPR qq{\n\n%25s%14.2f\n}, "Credits Offered", $total); - printf(LPR qq{\n%39s\n%39.2f\n}, "=========", $total); - close LPR || die "Could not close printer: $lpr\n"; + print LPR map "$_\n", @report; + print LPR "\f" if $opt_e; + close LPR || die "Could not close printer: $lpr\n"; } -if($email && $main::opt_e) +if($email && $opt_m) { - printf(MAIL qq{\n\n%25s%14.2f\n}, "Credits Offered", $total); - printf(MAIL qq{\n%39s\n%39.2f\n}, "=========", $total); - close MAIL || die "Could not close printer: $email\n"; + print MAIL map "$_\n", @report; + close MAIL || die "Could not close printer: $email\n"; } @@ -126,27 +162,35 @@ sub usage { =head1 NAME -freeside-credit-report - Prints or emails in house credits offered in a given period. +freeside-credit-report - Prints or emails total credit memos in a given period. =head1 SYNOPSIS - freeside-credit-report [-v] [-p] [-e] user + freeside-credit-report [-v] [-p] [-m] [-e] [-t "title"] [-s date] [-f date] user =head1 DESCRIPTION -Prints or emails in house credits offered in a given period. +Prints or emails total credit memos in a given period. -v: Verbose - Prints records to STDOUT. -p: Print to printer lpr as found in the conf directory. --e: Email output to user found in the Conf email file. +-m: Email output to user found in the Conf email file. + +-e: Print a final form feed to the printer. + +-t: supply a title for the top of each page. + +-s: starting date for inclusion + +-f: final date for inclusion user: From the mapsecrets file - see config.html from the base documentation =head1 VERSION -$Id: freeside-credit-report,v 1.1 2002-02-22 23:18:32 jeff Exp $ +$Id: freeside-credit-report,v 1.2 2002-03-05 23:13:23 jeff Exp $ =head1 BUGS @@ -166,17 +210,8 @@ L, config.html from the base documentation griff@aver-computer.com July 99 $Log: freeside-credit-report,v $ -Revision 1.1 2002-02-22 23:18:32 jeff -add some reporting features - -Revision 1.1 2002/02/19 14:24:53 jeff -might be functional now - -Revision 1.1 2000/09/20 19:25:19 jeff -local modifications - -Revision 1.1 2000/05/13 21:57:56 ivan -add print_batch script from Joel Griffiths +Revision 1.2 2002-03-05 23:13:23 jeff +consistency is nice =cut diff --git a/FS/bin/freeside-receivables-report b/FS/bin/freeside-receivables-report index c4d188c4e..6d04ba94c 100755 --- a/FS/bin/freeside-receivables-report +++ b/FS/bin/freeside-receivables-report @@ -183,7 +183,7 @@ user: From the mapsecrets file - see config.html from the base documentation =head1 VERSION -$Id: freeside-receivables-report,v 1.2 2002-03-05 09:44:09 ivan Exp $ +$Id: freeside-receivables-report,v 1.3 2002-03-05 23:13:23 jeff Exp $ =head1 BUGS @@ -203,17 +203,8 @@ L, config.html from the base documentation griff@aver-computer.com July 99 $Log: freeside-receivables-report,v $ -Revision 1.2 2002-03-05 09:44:09 ivan -yes i have crazy customers with 8-digit customer numbers - -Revision 1.1 2002/02/22 23:18:32 jeff -add some reporting features - -Revision 1.1 2000/09/20 19:25:19 jeff -local modifications - -Revision 1.1 2000/05/13 21:57:56 ivan -add print_batch script from Joel Griffiths +Revision 1.3 2002-03-05 23:13:23 jeff +consistency is nice =cut diff --git a/FS/bin/freeside-tax-report b/FS/bin/freeside-tax-report index 334c4107b..080b4dfa7 100755 --- a/FS/bin/freeside-tax-report +++ b/FS/bin/freeside-tax-report @@ -1,39 +1,40 @@ #!/usr/bin/perl -Tw + use strict; use Date::Parse; use Time::Local; use Getopt::Std; +use Text::Template; use FS::Conf; use FS::UID qw(adminsuidsetup); use FS::Record qw(qsearch); +use FS::cust_bill; +use FS::cust_bill_pay; use FS::cust_pay; -use FS::cust_pay_batch; # Set the mail program my $mail_program = "/usr/sbin/sendmail -t -n"; &untaint_argv; #what it sounds like (eww) -use vars qw($opt_v $opt_p $opt_e $opt_d $opt_s); -getopts("vped:s:"); #switches +use vars qw($opt_v $opt_p $opt_m $opt_e $opt_t $opt_s $opt_f $report_lines $report_template @buf); +getopts("vpmef:s:"); #switches #we're at now now (and later). -my($_enddate)= $main::opt_d ? str2time($main::opt_d) : $^T; -my($_startdate)= $main::opt_s ? str2time($main::opt_s) : $^T; +my($_finishdate)= $opt_f ? str2time($main::opt_f) : $^T; +my($_startdate)= $opt_s ? str2time($main::opt_s) : $^T; # Get the current month my ($ssec,$smin,$shour,$smday,$smon,$syear) = (localtime($_startdate) )[0,1,2,3,4,5]; $smon++; -$syear -= 100 if $syear >= 100; -$syear = "0" . $syear if $syear < 10; +$syear += 1900; # Get the current month -my ($esec,$emin,$ehour,$emday,$emon,$eyear) = - (localtime($_enddate) )[0,1,2,3,4,5]; -$emon++; -$eyear -= 100 if $eyear >= 100; -$eyear = "0" . $eyear if $eyear < 10; +my ($fsec,$fmin,$fhour,$fmday,$fmon,$fyear) = + (localtime($_finishdate) )[0,1,2,3,4,5]; +$fmon++; +$fyear += 1900; # Login to the database my $user = shift or die &usage; @@ -43,6 +44,19 @@ adminsuidsetup $user; my $conf = new FS::Conf; my $lpr = $conf->config('lpr'); my $email = $conf->config('email'); +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(@cust_bills)=qsearch('cust_bill',{}); if (scalar(@cust_bills) == 0) @@ -50,22 +64,16 @@ if (scalar(@cust_bills) == 0) exit 1; } -if ($main::opt_v) -{ - print qq~ S A L E S T A X E S I N V O I C E D for period beginning: $smon/$smday/$syear and ending $emon/$emday/$eyear\n\n~; -} - # Open print and email pipes # $lpr and opt_p for printing -# $email and opt_e for email +# $email and opt_m for email if ($lpr && $main::opt_p) { open(LPR, "|$lpr"); - print LPR qq~ S A L E S T A X E S I N V O I C E D for period beginning: $smon/$smday/$syear and ending $emon/$emday/$eyear\n\n~; } -if ($email && $main::opt_e) +if ($email && $main::opt_m) { open (MAIL, "|$mail_program"); print MAIL <getfield('_date'); my $invnum = $cust_bill->getfield('invnum'); my $charged = $cust_bill->getfield('charged'); - - if ($_date >= $_startdate && $_date <= $_enddate) { + if ($_date >= $_startdate && $_date <= $_finishdate) { $total += $charged; - # The following lines were used to produce rather verbose reports - #my ($sec,$min,$hour,$mday,$mon,$year) = - # (localtime($_date) )[0,1,2,3,4,5]; - #$mon++; - #$year -= 100 if $year >= 100; - #$year = "0" . $year if $year < 10; - - my $invoice_amt =0; - my $invoice_tax =0; - my $invoice_compped =0; - my(@cust_bill_pkgs)= $cust_bill->cust_bill_pkg; - foreach my $cust_bill_pkg (@cust_bill_pkgs) { - - my $recur = $cust_bill_pkg->getfield('recur'); - my $setup = $cust_bill_pkg->getfield('setup'); - my $pkgnum = $cust_bill_pkg->getfield('pkgnum'); - - if ($pkgnum == 0) { - # The following line was used to produce rather verbose reports - # printf(MAIL qq{\n%10s%15s%14.2f}, "$mon/$mday/$year", "Tax $invnum", $recur+$setup); - $invoice_tax += $recur; - $invoice_tax += $setup; - } else { - # The following line was used to produce rather verbose reports - # printf(MAIL qq{\n%10s%15s%14.2f}, "$mon/$mday/$year", "Inv $invnum", $recur+$setup); - $invoice_amt += $recur; - $invoice_amt += $setup; - } - - } - - my(@cust_bill_pays)= $cust_bill->cust_bill_pay; - foreach my $cust_bill_pay (@cust_bill_pays) { - my $payby = $cust_bill_pay->cust_pay->payby; - my $paid = $cust_bill_pay->getfield('amount'); - if ($payby =~ 'COMP') { - $invoice_compped += $paid; - } - } - - if (abs($invoice_compped - ($invoice_amt + $invoice_tax)) < 0.0001){ - $compped += $invoice_amt; - $compped_tax += $invoice_tax; - } elsif ($invoice_compped > 0) { - printf(qq{\nInvoice %10d has inexpliciable complimentary payments of %14.9f\n}, $invnum, $invoice_compped); - $other += $invoice_amt; - $other_tax += $invoice_tax; - } elsif ($invoice_tax > 0) { - $total_tax += $invoice_tax; - $taxed += $invoice_amt; - } else { - $untaxed += $invoice_amt; - } - - } + # The following lines were used to produce rather verbose reports + #my ($sec,$min,$hour,$mday,$mon,$year) = + # (localtime($_date) )[0,1,2,3,4,5]; + #$mon++; + #$year -= 100 if $year >= 100; + #$year = "0" . $year if $year < 10; + + my $invoice_amt =0; + my $invoice_tax =0; + my $invoice_comped =0; + my(@cust_bill_pkgs)= $cust_bill->cust_bill_pkg; + foreach my $cust_bill_pkg (@cust_bill_pkgs) { + + my $recur = $cust_bill_pkg->getfield('recur'); + my $setup = $cust_bill_pkg->getfield('setup'); + my $pkgnum = $cust_bill_pkg->getfield('pkgnum'); + + if ($pkgnum == 0) { + # The following line was used to produce rather verbose reports + # push @buf, ('', sprintf(qq{%10s%15s%14.2f}, "$mon/$mday/$year", "Tax $invnum", $recur+$setup)); + $invoice_tax += $recur; + $invoice_tax += $setup; + } else { + # The following line was used to produce rather verbose reports + # push @buf, ('', sprintf(qq{%10s%15s%14.2f}, "$mon/$mday/$year", "Inv $invnum", $recur+$setup)); + $invoice_amt += $recur; + $invoice_amt += $setup; + } + + } + + my(@cust_bill_pays)= $cust_bill->cust_bill_pay; + foreach my $cust_bill_pay (@cust_bill_pays) { + my $payby = $cust_bill_pay->cust_pay->payby; + my $paid = $cust_bill_pay->getfield('amount'); + if ($payby =~ 'COMP') { + $invoice_comped += $paid; + } + } + + if (abs($invoice_comped - ($invoice_amt + $invoice_tax)) < 0.0001){ + $comped += $invoice_amt; + $comped_tax += $invoice_tax; + } elsif ($invoice_comped > 0) { + push @buf, sprintf(qq{\nInvoice %10d has inexpliciable complimentary payments of %14.9f\n}, $invnum, $invoice_comped); + $other += $invoice_amt; + $other_tax += $invoice_tax; + } elsif ($invoice_tax > 0) { + $total_tax += $invoice_tax; + $taxed += $invoice_amt; + } else { + $untaxed += $invoice_amt; + } + + } } -if ($main::opt_v) { - printf(qq{\n\n%25s%14.2f\n}, "Complimentary", $compped); - printf(qq{%25s%14.2f\n}, "Complimentary Tax", $compped_tax); - printf(qq{%25s%14.2f\n}, "Other", $other); - printf(qq{%25s%14.2f\n}, "Other Tax", $other_tax); - printf(qq{%25s%14.2f\n}, "Untaxed", $untaxed); - printf(qq{%25s%14.2f\n}, "Taxed", $taxed); - printf(qq{%25s%14.2f\n}, "Tax", $total_tax); - printf(qq{\n%39s\n%39.2f\n}, "=========", $total); +push @buf, ('', sprintf(qq{%25s%14.2f}, "Complimentary", $comped)); +push @buf, sprintf(qq{%25s%14.2f}, "Complimentary Tax", $comped_tax); +push @buf, sprintf(qq{%25s%14.2f}, "Other", $other); +push @buf, sprintf(qq{%25s%14.2f}, "Other Tax", $other_tax); +push @buf, sprintf(qq{%25s%14.2f}, "Untaxed", $untaxed); +push @buf, sprintf(qq{%25s%14.2f}, "Taxed", $taxed); +push @buf, sprintf(qq{%25s%14.2f}, "Tax", $total_tax); +push @buf, ('', sprintf(qq{%39s}, "========="), sprintf(qq{%39.2f}, $total)); + +sub FS::tax_report::_template::report_lines { + my $lines = shift; + map { + scalar(@buf) ? shift @buf : '' ; + } + ( 1 .. $lines ); +} + +$FS::tax_report::_template::title = qq~SALES TAXES INVOICED for $smon/$smday/$syear through $fmon/$fmday/$fyear~; +$FS::tax_report::_template::title = $opt_t if $opt_t; +$FS::tax_report::_template::page = 1; +$FS::tax_report::_template::date = $^T; +$FS::tax_report::_template::date = $^T; +$FS::tax_report::_template::fdate = $_finishdate; +$FS::tax_report::_template::fdate = $_finishdate; +$FS::tax_report::_template::sdate = $_startdate; +$FS::tax_report::_template::sdate = $_startdate; +$FS::tax_report::_template::total_pages = + int( scalar(@buf) / $report_lines); +$FS::tax_report::_template::total_pages++ if scalar(@buf) % $report_lines; + +my @report; +while (@buf) { + push @report, split("\n", + $report_template->fill_in( PACKAGE => 'FS::tax_report::_template' ) + ); + $FS::tax_report::_template::page++; } -# Now I need to close LPR and EMAIL if they were open -if($lpr && $main::opt_p) +if ($opt_v) { + print map "$_\n", @report; +} +if($lpr && $opt_p) { - printf(LPR qq{\n\n%25s%14.2f\n}, "Complimentary", $compped); - printf(LPR qq{%25s%14.2f\n}, "Complimentary Tax", $compped_tax); - printf(LPR qq{%25s%14.2f\n}, "Other", $other); - printf(LPR qq{%25s%14.2f\n}, "Other Tax", $other_tax); - printf(LPR qq{%25s%14.2f\n}, "Untaxed", $untaxed); - printf(LPR qq{%25s%14.2f\n}, "Taxed", $taxed); - printf(LPR qq{%25s%14.2f\n}, "Tax", $total_tax); - printf(LPR qq{\n%39s\n%39.2f\n}, "=========", $total); - close LPR || die "Could not close printer: $lpr\n"; + print LPR map "$_\n", @report; + print LPR "\f" if $opt_e; + close LPR || die "Could not close printer: $lpr\n"; } -if($email && $main::opt_e) +if($email && $opt_m) { - printf(MAIL qq{\n\n%25s%14.2f\n}, "Complimentary", $compped); - printf(MAIL qq{%25s%14.2f\n}, "Complimentary Tax", $compped_tax); - printf(MAIL qq{%25s%14.2f\n}, "Other", $other); - printf(MAIL qq{%25s%14.2f\n}, "Other Tax", $other_tax); - printf(MAIL qq{%25s%14.2f\n}, "Untaxed", $untaxed); - printf(MAIL qq{%25s%14.2f\n}, "Taxed", $taxed); - printf(MAIL qq{%25s%14.2f\n}, "Tax", $total_tax); - printf(MAIL qq{\n%39s\n%39.2f\n}, "=========", $total); - close MAIL || die "Could not close printer: $email\n"; + print MAIL map "$_\n", @report; + close MAIL || die "Could not close printer: $email\n"; } @@ -213,7 +234,7 @@ freeside-tax-report - Prints or emails sales taxes invoiced in a given period. =head1 SYNOPSIS - freeside-tax-report [-v] [-p] [-e] user + freeside-tax-report [-v] [-p] [-m] [-e] [-t "title"] [-s date] [-f date] user =head1 DESCRIPTION @@ -223,13 +244,21 @@ Prints or emails sales taxes invoiced in a given period. -p: Print to printer lpr as found in the conf directory. --e: Email output to user found in the Conf email file. +-m: Email output to user found in the Conf email file. + +-e: Print a final form feed to the printer. + +-t: supply a title for the top of each page. + +-s: starting date for inclusion + +-f: final date for inclusion user: From the mapsecrets file - see config.html from the base documentation =head1 VERSION -$Id: freeside-tax-report,v 1.1 2002-02-22 23:18:32 jeff Exp $ +$Id: freeside-tax-report,v 1.2 2002-03-05 23:13:23 jeff Exp $ =head1 BUGS @@ -249,20 +278,8 @@ L, config.html from the base documentation griff@aver-computer.com July 99 $Log: freeside-tax-report,v $ -Revision 1.1 2002-02-22 23:18:32 jeff -add some reporting features - -Revision 1.3 2002/02/19 14:24:53 jeff -might be functional now - -Revision 1.2 2001/08/20 18:31:49 jeff -before-merge-to-freeside_1_4_0-pre1 - -Revision 1.1 2000/09/20 19:25:19 jeff -local modifications - -Revision 1.1 2000/05/13 21:57:56 ivan -add print_batch script from Joel Griffiths +Revision 1.2 2002-03-05 23:13:23 jeff +consistency is nice =cut -- cgit v1.2.1 From 8fd504d36e02fd1ac3d0d5c9d6dc723fdb419aa1 Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 6 Mar 2002 00:17:32 +0000 Subject: remove CVS Log tag --- FS/bin/freeside-cc-receipts-report | 21 ++++----------------- FS/bin/freeside-credit-report | 12 ++++-------- FS/bin/freeside-receivables-report | 22 +++++++++------------- FS/bin/freeside-tax-report | 12 ++++-------- 4 files changed, 21 insertions(+), 46 deletions(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-cc-receipts-report b/FS/bin/freeside-cc-receipts-report index 5ea8cc5cb..48075a888 100755 --- a/FS/bin/freeside-cc-receipts-report +++ b/FS/bin/freeside-cc-receipts-report @@ -236,7 +236,7 @@ user: From the mapsecrets file - see config.html from the base documentation =head1 VERSION -$Id: freeside-cc-receipts-report,v 1.2 2002-03-05 23:13:23 jeff Exp $ +$Id: freeside-cc-receipts-report,v 1.3 2002-03-06 00:17:32 ivan Exp $ =head1 BUGS @@ -251,24 +251,11 @@ for more information regarding this license. L, config.html from the base documentation -=head1 HISTORY +=head1 AUTHOR -griff@aver-computer.com July 99 - -$Log: freeside-cc-receipts-report,v $ -Revision 1.2 2002-03-05 23:13:23 jeff -consistency is nice - -Revision 1.2 2002/02/19 14:24:53 jeff -might be functional now - -Revision 1.1 2000/09/20 19:25:19 jeff -local modifications - -Revision 1.1 2000/05/13 21:57:56 ivan -add print_batch script from Joel Griffiths +Jeff Finucane +based on print-batch by Joel Griffiths =cut - diff --git a/FS/bin/freeside-credit-report b/FS/bin/freeside-credit-report index 92931bcee..c73988321 100755 --- a/FS/bin/freeside-credit-report +++ b/FS/bin/freeside-credit-report @@ -190,7 +190,7 @@ user: From the mapsecrets file - see config.html from the base documentation =head1 VERSION -$Id: freeside-credit-report,v 1.2 2002-03-05 23:13:23 jeff Exp $ +$Id: freeside-credit-report,v 1.3 2002-03-06 00:17:32 ivan Exp $ =head1 BUGS @@ -205,15 +205,11 @@ for more information regarding this license. L, config.html from the base documentation -=head1 HISTORY +=head1 AUTHOR -griff@aver-computer.com July 99 - -$Log: freeside-credit-report,v $ -Revision 1.2 2002-03-05 23:13:23 jeff -consistency is nice +Jeff Finucane +based on print-batch by Joel Griffiths =cut - diff --git a/FS/bin/freeside-receivables-report b/FS/bin/freeside-receivables-report index 6d04ba94c..781e23b18 100755 --- a/FS/bin/freeside-receivables-report +++ b/FS/bin/freeside-receivables-report @@ -169,21 +169,21 @@ freeside-receivables-report - Prints or emails outstanding receivables. Prints or emails outstanding receivables --v: Verbose - Prints records to STDOUT. +B<-v>: Verbose - Prints records to STDOUT. --p: Print to printer lpr as found in the conf directory. +B<-p>: Print to printer lpr as found in the conf directory. --m: Mail output to user found in the Conf email file. +B<-m>: Mail output to user found in the Conf email file. --e: Print a final form feed to the printer. +B<-e>: Print a final form feed to the printer. --t: supply a title for the top of each page. +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.3 2002-03-05 23:13:23 jeff Exp $ +$Id: freeside-receivables-report,v 1.4 2002-03-06 00:17:32 ivan Exp $ =head1 BUGS @@ -198,15 +198,11 @@ for more information regarding this license. L, config.html from the base documentation -=head1 HISTORY +=head1 AUTHOR -griff@aver-computer.com July 99 - -$Log: freeside-receivables-report,v $ -Revision 1.3 2002-03-05 23:13:23 jeff -consistency is nice +Jeff Finucane +based on print-batch by Joel Griffiths =cut - diff --git a/FS/bin/freeside-tax-report b/FS/bin/freeside-tax-report index 080b4dfa7..ec4b99f81 100755 --- a/FS/bin/freeside-tax-report +++ b/FS/bin/freeside-tax-report @@ -258,7 +258,7 @@ user: From the mapsecrets file - see config.html from the base documentation =head1 VERSION -$Id: freeside-tax-report,v 1.2 2002-03-05 23:13:23 jeff Exp $ +$Id: freeside-tax-report,v 1.3 2002-03-06 00:17:32 ivan Exp $ =head1 BUGS @@ -273,15 +273,11 @@ for more information regarding this license. L, config.html from the base documentation -=head1 HISTORY +=head1 AUTHOR -griff@aver-computer.com July 99 - -$Log: freeside-tax-report,v $ -Revision 1.2 2002-03-05 23:13:23 jeff -consistency is nice +Jeff Finucane +based on print-batch by Joel Griffiths =cut - -- cgit v1.2.1 From a6aa711eb82626bfab39902a6c4d785f3f533ef4 Mon Sep 17 00:00:00 2001 From: jeff Date: Wed, 6 Mar 2002 22:44:14 +0000 Subject: billing expiration alerts --- FS/bin/freeside-expiration-alerter | 209 +++++++++++++++++++++++++++++++++++++ 1 file changed, 209 insertions(+) create mode 100755 FS/bin/freeside-expiration-alerter (limited to 'FS/bin') diff --git a/FS/bin/freeside-expiration-alerter b/FS/bin/freeside-expiration-alerter new file mode 100755 index 000000000..c3dc37b31 --- /dev/null +++ b/FS/bin/freeside-expiration-alerter @@ -0,0 +1,209 @@ +#!/usr/bin/perl -Tw + +use strict; +use Date::Format; +use Time::Local; +use Text::Template; +use Getopt::Std; +use FS::Conf; +use FS::UID qw(adminsuidsetup); +use FS::Record qw(qsearch); +use FS::cust_main; + +use vars qw($smtpmachine); + +#hush, perl! +$FS::alerter::_template::first = ""; +$FS::alerter::_template::last = ""; +$FS::alerter::_template::company = ""; +$FS::alerter::_template::payby = ""; +$FS::alerter::_template::expdate = ""; + +# Set the mail program and other variables +my $mail_program = "/usr/sbin/sendmail -t -n"; +my $mail_sender = "billing\@mydomain.tld"; +my $default_mail_recipient = "postmaster"; +my $warning_time = 30 * 24 * 60 * 60; +my $urgent_time = 15 * 24 * 60 * 60; +my $panic_time = 5 * 24 * 60 * 60; +my $window_time = 24 * 60 * 60; + +&untaint_argv; #what it sounds like (eww) + +#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++; + +# Login to the database +my $user = shift or die &usage; +adminsuidsetup $user; + +# Get the needed configuration files +my $conf = new FS::Conf; +$smtpmachine = $conf->config('smtpmachine'); + +my(@customers)=qsearch('cust_main',{}); +if (scalar(@customers) == 0) +{ + exit 1; +} + +# Open email pipe + +open (MAIL, "|$mail_program"); +print MAIL <config('alerter_template') + or die "cannot load config file alerter_template"; + +my $alerter = new Text::Template (TYPE => 'ARRAY', SOURCE => [ map "$_\n", @alerter_template ]) + or die "can't create new Text::Template object: Text::Template::ERROR"; +$alerter->compile() or die "can't compile template: Text::Template::ERROR"; + +# 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 $payby = $customer->getfield('payby'); + my $payinfo = $customer->getfield('payinfo'); + my $paydate = $customer->getfield('paydate'); + my $daytime = $customer->getfield('daytime'); + my $night = $customer->getfield('night'); + + my ($payyear,$paymonth,$payday) = split (/-/,$paydate); + + my $expire_time = timelocal(0,0,0,$payday,--$paymonth,$payyear); + + #credit cards expire at the end of the month/year of their exp date + if ($payby eq 'CARD') { + ($paymonth < 11) ? $paymonth++ : ($paymonth=0, $payyear++); + $expire_time = timelocal(0,0,0,$payday,$paymonth,$payyear); + $expire_time--; + } + + if (($expire_time < $_date + $warning_time && + $expire_time > $_date + $warning_time - $window_time) || + ($expire_time < $_date + $urgent_time && + $expire_time > $_date + $urgent_time - $window_time) || + ($expire_time < $_date + $panic_time && + $expire_time > $_date + $panic_time - $window_time)) { + + + + my @packages = $customer->ncancelled_pkgs; + if (scalar(@packages) != 0) { + my @invoicing_list = $customer->invoicing_list; + if ( grep { $_ ne 'POST' } @invoicing_list ) { + $ENV{SMTPHOSTS} = $smtpmachine; + $ENV{MAILADDRESS} = $mail_sender; + my $header = new Mail::Header ( [ + "From: $mail_sender", + "To: ". join(', ', grep { $_ ne 'POST' } @invoicing_list ), + "Sender: $mail_sender", + "Reply-To: $mail_sender", + "Date: ". time2str("%a, %d %b %Y %X %z", time), + "Subject: Billing Arrangement Expiration", + ] ); + $FS::alerter::_template::first = $first; + $FS::alerter::_template::last = $last; + $FS::alerter::_template::company = $company; + if ($payby eq 'CARD') { + $FS::alerter::_template::payby = "credit card (" . + substr($payinfo, 0, 2) . "xxxxxxxxxx" . + substr($payinfo, -4) . ")"; + }elsif ($payby eq 'COMP') { + $FS::alerter::_template::payby = "complimentary account"; + }else{ + $FS::alerter::_template::payby = "current method"; + } + $FS::alerter::_template::expdate = $expire_time; + + my $message = new Mail::Internet ( + 'Header' => $header, + 'Body' => [ $alerter->fill_in( PACKAGE => 'FS::alerter::_template' ) ], + ); + $message->smtpsend or die "Can't send invoice email!: $!"; #die? warn? + + } elsif ( ! @invoicing_list || grep { $_ eq 'POST' } @invoicing_list ) { + printf(MAIL qq{%5d %-32.32s %4s %10s %12s %12s\n}, + $custnum, + $first . " " . $last . " " . $company, + $payby, + $paydate, + $daytime, + $night); + } + } + } +} + +# Now I need to close EMAIL +close MAIL || die "Could not close printer: $default_mail_recipient\n"; + + +# subroutines +sub untaint_argv { + foreach $_ ( $[ .. $#ARGV ) { #untaint @ARGV + $ARGV[$_] =~ /^([\w\-\/]*)$/ || die "Illegal argument \"$ARGV[$_]\""; + $ARGV[$_]=$1; + } +} + +sub usage { + die "Usage:\n\n freeside-expiration-alerter user\n"; +} + +=head1 NAME + +freeside-expiration-alerter - Emails notifications of credit card expirations. + +=head1 SYNOPSIS + + freeside-expiration-alerter user + +=head1 DESCRIPTION + +Emails customers notice that their credit card or other billing arrangement +is about to expire. Usually run as a cron job. + +user: From the mapsecrets file - see config.html from the base documentation + +=head1 VERSION + +$Id: freeside-expiration-alerter,v 1.1 2002-03-06 22:44:13 jeff 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, config.html from the base documentation + +=head1 AUTHOR + +Jeff Finucane + +=cut + + -- cgit v1.2.1 From 3e2e5fecb9ef3cf39a6ac098aacb76763edd3938 Mon Sep 17 00:00:00 2001 From: jeff Date: Thu, 7 Mar 2002 19:50:24 +0000 Subject: less shelling, more perly - abolish some pipes to sendmail --- FS/bin/freeside-cc-receipts-report | 37 ++++++++++++++--------- FS/bin/freeside-credit-report | 37 ++++++++++++++--------- FS/bin/freeside-expiration-alerter | 60 +++++++++++++++++++++++--------------- FS/bin/freeside-receivables-report | 37 ++++++++++++++--------- FS/bin/freeside-tax-report | 37 ++++++++++++++--------- 5 files changed, 129 insertions(+), 79 deletions(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-cc-receipts-report b/FS/bin/freeside-cc-receipts-report index 48075a888..06e3aba81 100755 --- a/FS/bin/freeside-cc-receipts-report +++ b/FS/bin/freeside-cc-receipts-report @@ -6,17 +6,18 @@ 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 qsearchs); use FS::cust_pay; use FS::cust_pay_batch; -# Set the mail program -my $mail_program = "/usr/sbin/sendmail -t -n"; &untaint_argv; #what it sounds like (eww) -use vars qw($opt_v $opt_p $opt_m $opt_e $opt_t $opt_s $opt_f $report_lines $report_template @buf); +use vars qw($opt_v $opt_p $opt_m $opt_e $opt_t $opt_s $opt_f $report_lines $report_template @buf $header); getopts("vpmef:s:"); #switches #we're at now now (and later). @@ -43,6 +44,9 @@ adminsuidsetup $user; 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; @@ -74,14 +78,14 @@ if ($lpr && $main::opt_p) if ($email && $main::opt_m) { - open (MAIL, "|$mail_program"); - print MAIL < $header, + 'Body' => [ (@report) ], + ); + $!=0; + $message->smtpsend( Host => "$smtpmachine" ) + or die "can't send report to $email via $smtpmachine: $!"; } @@ -236,7 +245,7 @@ user: From the mapsecrets file - see config.html from the base documentation =head1 VERSION -$Id: freeside-cc-receipts-report,v 1.3 2002-03-06 00:17:32 ivan Exp $ +$Id: freeside-cc-receipts-report,v 1.4 2002-03-07 19:50:23 jeff Exp $ =head1 BUGS diff --git a/FS/bin/freeside-credit-report b/FS/bin/freeside-credit-report index c73988321..7699daf4d 100755 --- a/FS/bin/freeside-credit-report +++ b/FS/bin/freeside-credit-report @@ -6,16 +6,17 @@ 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_credit; -# Set the mail program -my $mail_program = "/usr/sbin/sendmail -t -n"; &untaint_argv; #what it sounds like (eww) -use vars qw($opt_v $opt_p $opt_m $opt_e $opt_t $opt_s $opt_f $report_lines $report_template @buf); +use vars qw($opt_v $opt_p $opt_m $opt_e $opt_t $opt_s $opt_f $report_lines $report_template @buf $header); getopts("vpmef:s:"); #switches #we're at now now (and later). @@ -42,6 +43,9 @@ adminsuidsetup $user; 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; @@ -73,14 +77,14 @@ if ($lpr && $main::opt_p) if ($email && $main::opt_m) { - open (MAIL, "|$mail_program"); - print MAIL < $header, + 'Body' => [ (@report) ], + ); + $!=0; + $message->smtpsend( Host => "$smtpmachine" ) + or die "can't send report to $email via $smtpmachine: $!"; } @@ -190,7 +199,7 @@ user: From the mapsecrets file - see config.html from the base documentation =head1 VERSION -$Id: freeside-credit-report,v 1.3 2002-03-06 00:17:32 ivan Exp $ +$Id: freeside-credit-report,v 1.4 2002-03-07 19:50:24 jeff Exp $ =head1 BUGS diff --git a/FS/bin/freeside-expiration-alerter b/FS/bin/freeside-expiration-alerter index c3dc37b31..365b96467 100755 --- a/FS/bin/freeside-expiration-alerter +++ b/FS/bin/freeside-expiration-alerter @@ -5,12 +5,15 @@ use Date::Format; use Time::Local; use Text::Template; use Getopt::Std; +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; -use vars qw($smtpmachine); +use vars qw($smtpmachine @body); #hush, perl! $FS::alerter::_template::first = ""; @@ -20,9 +23,8 @@ $FS::alerter::_template::payby = ""; $FS::alerter::_template::expdate = ""; # Set the mail program and other variables -my $mail_program = "/usr/sbin/sendmail -t -n"; -my $mail_sender = "billing\@mydomain.tld"; -my $default_mail_recipient = "postmaster"; +my $mail_sender = "billing\@mydomain.tld"; # or invoice_from if available +my $failure_recipient = "postmaster"; # or invoice_from if available my $warning_time = 30 * 24 * 60 * 60; my $urgent_time = 15 * 24 * 60 * 60; my $panic_time = 5 * 24 * 60 * 60; @@ -45,6 +47,11 @@ adminsuidsetup $user; # Get the needed configuration files my $conf = new FS::Conf; $smtpmachine = $conf->config('smtpmachine'); +$mail_sender = $conf->config('invoice_from') + if $conf->exists('invoice_from'); +$failure_recipient = $conf->config('invoice_from') + if $conf->exists('invoice_from'); + my(@customers)=qsearch('cust_main',{}); if (scalar(@customers) == 0) @@ -52,18 +59,16 @@ if (scalar(@customers) == 0) exit 1; } -# Open email pipe - -open (MAIL, "|$mail_program"); -print MAIL <config('alerter_template') or die "cannot load config file alerter_template"; @@ -109,8 +114,6 @@ foreach my $customer (@customers) if (scalar(@packages) != 0) { my @invoicing_list = $customer->invoicing_list; if ( grep { $_ ne 'POST' } @invoicing_list ) { - $ENV{SMTPHOSTS} = $smtpmachine; - $ENV{MAILADDRESS} = $mail_sender; my $header = new Mail::Header ( [ "From: $mail_sender", "To: ". join(', ', grep { $_ ne 'POST' } @invoicing_list ), @@ -137,10 +140,12 @@ foreach my $customer (@customers) 'Header' => $header, 'Body' => [ $alerter->fill_in( PACKAGE => 'FS::alerter::_template' ) ], ); - $message->smtpsend or die "Can't send invoice email!: $!"; #die? warn? + $!=0; + $message->smtpsend( Host => $smtpmachine ) + or die "Can't send expiration email!: $!"; #die? warn? } elsif ( ! @invoicing_list || grep { $_ eq 'POST' } @invoicing_list ) { - printf(MAIL qq{%5d %-32.32s %4s %10s %12s %12s\n}, + push @body, sprintf(qq{%5d %-32.32s %4s %10s %12s %12s}, $custnum, $first . " " . $last . " " . $company, $payby, @@ -152,9 +157,18 @@ foreach my $customer (@customers) } } -# Now I need to close EMAIL -close MAIL || die "Could not close printer: $default_mail_recipient\n"; - +# Now I need to send EMAIL +if (scalar(@body)) { + my $message = new Mail::Internet ( + 'Header' => $header, + 'Body' => [ (@body) ], + ); + $!=0; + $message->smtpsend( Host => $smtpmachine ) + or $message->smtpsend( Host => $smtpmachine, Debug => 1 ) + or return "can't send alerter failure email to $failure_recipient". + " via server $smtpmachine with SMTP: $!"; +} # subroutines sub untaint_argv { @@ -185,7 +199,7 @@ user: From the mapsecrets file - see config.html from the base documentation =head1 VERSION -$Id: freeside-expiration-alerter,v 1.1 2002-03-06 22:44:13 jeff Exp $ +$Id: freeside-expiration-alerter,v 1.2 2002-03-07 19:50:24 jeff Exp $ =head1 BUGS diff --git a/FS/bin/freeside-receivables-report b/FS/bin/freeside-receivables-report index 781e23b18..b5a49031e 100755 --- a/FS/bin/freeside-receivables-report +++ b/FS/bin/freeside-receivables-report @@ -5,16 +5,17 @@ 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; -# Set the mail program -my $mail_program = "/usr/sbin/sendmail -t -n"; &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); +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). @@ -34,6 +35,9 @@ adminsuidsetup $user; 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; @@ -65,14 +69,14 @@ if ($lpr && $opt_p) if ($email && $opt_m) { - open (MAIL, "|$mail_program"); - print MAIL < $header, + 'Body' => [ (@report) ], + ); + $!=0; + $message->smtpsend( Host => "$smtpmachine" ) + or die "can't send report to $email via $smtpmachine: $!"; } @@ -183,7 +192,7 @@ user: From the mapsecrets file - see config.html from the base documentation =head1 VERSION -$Id: freeside-receivables-report,v 1.4 2002-03-06 00:17:32 ivan Exp $ +$Id: freeside-receivables-report,v 1.5 2002-03-07 19:50:24 jeff Exp $ =head1 BUGS diff --git a/FS/bin/freeside-tax-report b/FS/bin/freeside-tax-report index ec4b99f81..8d5021358 100755 --- a/FS/bin/freeside-tax-report +++ b/FS/bin/freeside-tax-report @@ -6,6 +6,9 @@ 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); @@ -13,11 +16,9 @@ use FS::cust_bill; use FS::cust_bill_pay; use FS::cust_pay; -# Set the mail program -my $mail_program = "/usr/sbin/sendmail -t -n"; &untaint_argv; #what it sounds like (eww) -use vars qw($opt_v $opt_p $opt_m $opt_e $opt_t $opt_s $opt_f $report_lines $report_template @buf); +use vars qw($opt_v $opt_p $opt_m $opt_e $opt_t $opt_s $opt_f $report_lines $report_template @buf $header); getopts("vpmef:s:"); #switches #we're at now now (and later). @@ -44,6 +45,9 @@ adminsuidsetup $user; 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; @@ -75,14 +79,14 @@ if ($lpr && $main::opt_p) if ($email && $main::opt_m) { - open (MAIL, "|$mail_program"); - print MAIL < $header, + 'Body' => [ (@report) ], + ); + $!=0; + $message->smtpsend( Host => "$smtpmachine" ) + or die "can't send report to $email via $smtpmachine: $!"; } @@ -258,7 +267,7 @@ user: From the mapsecrets file - see config.html from the base documentation =head1 VERSION -$Id: freeside-tax-report,v 1.3 2002-03-06 00:17:32 ivan Exp $ +$Id: freeside-tax-report,v 1.4 2002-03-07 19:50:24 jeff Exp $ =head1 BUGS -- cgit v1.2.1 From f1038a648b3d53db925b23519e7cd2a30c6837ed Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 20 Mar 2002 21:31:49 +0000 Subject: new export! infostreet and sqlradius provisioning switched over (Bug #299 - doesn't close it, but all the groundwork is done) also removes non-transactional ICRADIUS export from svc_acct.export (closes: Bug#347) --- FS/bin/freeside-queued | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-queued b/FS/bin/freeside-queued index 56475d059..c3c9240d2 100644 --- a/FS/bin/freeside-queued +++ b/FS/bin/freeside-queued @@ -15,6 +15,7 @@ use FS::queue; use FS::cust_main; use FS::svc_acct; use Net::SSH 0.05; +use FS::part_export; my $pid_file = '/var/run/freeside-queued.pid'; @@ -85,7 +86,7 @@ while (1) { my $eval = "&". $ljob->job. '(@args);'; warn "running $eval"; - eval $eval; + eval $eval; #throw away return value? suppose so if ( $@ ) { warn "job $eval failed"; my %hash = $ljob->hash; -- cgit v1.2.1 From 4fb679b29788a552a1ce33a0cdf293d648e797bc Mon Sep 17 00:00:00 2001 From: ivan Date: Sat, 23 Mar 2002 07:54:05 +0000 Subject: redirect STDOUT/STDERR a bit later for better error reporting --- FS/bin/freeside-queued | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-queued b/FS/bin/freeside-queued index c3c9240d2..fff77f01b 100644 --- a/FS/bin/freeside-queued +++ b/FS/bin/freeside-queued @@ -21,7 +21,7 @@ my $pid_file = '/var/run/freeside-queued.pid'; my $user = shift or die &usage; -&daemonize; +&daemonize1; sub REAPER { my $pid = wait; $SIG{CHLD} = \&REAPER; } $SIG{CHLD} = \&REAPER; @@ -38,6 +38,8 @@ adminsuidsetup $user; $log_file = "/usr/local/etc/freeside/queuelog.". $FS::UID::datasrc; +&daemonize2; + $SIG{__DIE__} = \&_die; $SIG{__WARN__} = \&_logmsg; @@ -134,7 +136,7 @@ sub _logmsg { close $log; } -sub daemonize { +sub daemonize1 { chdir "/" or die "Can't chdir to /: $!"; open STDIN, '/dev/null' or die "Can't read /dev/null: $!"; @@ -146,11 +148,18 @@ sub daemonize { print $pidfh "$pid\n"; exit; } + #open STDOUT, '>/dev/null' + # or die "Can't write to /dev/null: $!"; + #setsid or die "Can't start a new session: $!"; + #open STDERR, '>&STDOUT' or die "Can't dup stdout: $!"; + +} + +sub daemonize2 { open STDOUT, '>/dev/null' or die "Can't write to /dev/null: $!"; setsid or die "Can't start a new session: $!"; open STDERR, '>&STDOUT' or die "Can't dup stdout: $!"; - } =head1 NAME -- cgit v1.2.1 From c6da895a2fb2c233716381b7e45ebbeb1c2f6aaa Mon Sep 17 00:00:00 2001 From: ivan Date: Tue, 26 Mar 2002 00:32:46 +0000 Subject: further export bugfixing add 10 kid limit to freeside-queued sqlradius_reset now works (closes: Bug#372) --- FS/bin/freeside-queued | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-queued b/FS/bin/freeside-queued index fff77f01b..f6226cca1 100644 --- a/FS/bin/freeside-queued +++ b/FS/bin/freeside-queued @@ -1,7 +1,7 @@ #!/usr/bin/perl -w use strict; -use vars qw( $log_file $sigterm $sigint ); +use vars qw( $log_file $sigterm $sigint $kids $max_kids ); use subs qw( _die _logmsg ); use Fcntl qw(:flock); use POSIX qw(setsid); @@ -19,15 +19,18 @@ use FS::part_export; my $pid_file = '/var/run/freeside-queued.pid'; +$max_kids = '10'; #guess it should be a config file... +$kids = 0; + my $user = shift or die &usage; &daemonize1; -sub REAPER { my $pid = wait; $SIG{CHLD} = \&REAPER; } +sub REAPER { my $pid = wait; $SIG{CHLD} = \&REAPER; $kids--; } $SIG{CHLD} = \&REAPER; - $sigterm = 0; - $sigint = 0; +$sigterm = 0; +$sigint = 0; $SIG{INT} = sub { warn "SIGINT received; shutting down\n"; $sigint++; }; $SIG{TERM} = sub { warn "SIGTERM received; shutting down\n"; $sigterm++; }; @@ -45,8 +48,17 @@ $SIG{__WARN__} = \&_logmsg; warn "freeside-queued starting\n"; +my $warnkids=0; while (1) { + #prevent runaway forking + if ( $kids >= $max_kids ) { + warn "WARNING: maximum $kids children reached\n" unless $warnkids++; + sleep 1; #waiting for signals is cheap + next; + } + $warnkids=0; + my $job = qsearchs( 'queue', { 'status' => 'new' }, @@ -55,7 +67,7 @@ while (1) { ? 'ORDER BY jobnum LIMIT 1 FOR UPDATE' : 'ORDER BY jobnum FOR UPDATE LIMIT 1' ) or do { - sleep 5; + sleep 5; #connecting to db is expensive next; }; @@ -67,7 +79,6 @@ while (1) { my @args = $ljob->args; - # number of children limit? defined( my $pid = fork ) or do { warn "WARNING: can't fork: $!\n"; my %hash = $job->hash; @@ -76,9 +87,12 @@ while (1) { my $ljob = new FS::queue ( \%hash ); my $error = $ljob->replace($job); die $error if $error; + next; #don't increment the kid counter }; - unless ( $pid ) { #kid time + if ( $pid ) { + $kids++; + } else { #kid time #get new db handles $FS::UID::dbh->{InactiveDestroy} = 1; -- cgit v1.2.1 From 327df8aefdcf96c9c83805570abf4cc242cf46b9 Mon Sep 17 00:00:00 2001 From: ivan Date: Sat, 13 Apr 2002 13:36:26 +0000 Subject: - documentation updates - move Critical Path export to new-style export - bin/sqlradius_reset gets a manpage and becomes FS/bin/freeside-sqlradius-reset --- FS/bin/freeside-overdue | 3 ++ FS/bin/freeside-sqlradius-reset | 73 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100755 FS/bin/freeside-sqlradius-reset (limited to 'FS/bin') diff --git a/FS/bin/freeside-overdue b/FS/bin/freeside-overdue index db99e62b4..116245f9c 100755 --- a/FS/bin/freeside-overdue +++ b/FS/bin/freeside-overdue @@ -129,6 +129,9 @@ freeside-overdue - Perform actions on overdue and/or expired accounts. =head1 DESCRIPTION +This script is deprecated in 1.4.0. You should use freeside-daily and invoice +events instead. + Performs actions on overdue and/or expired accounts. Selection options (at least one selection option is required): diff --git a/FS/bin/freeside-sqlradius-reset b/FS/bin/freeside-sqlradius-reset new file mode 100755 index 000000000..132be754a --- /dev/null +++ b/FS/bin/freeside-sqlradius-reset @@ -0,0 +1,73 @@ +#!/usr/bin/perl -Tw + +use strict; +use FS::UID qw(adminsuidsetup); +use FS::Record qw(qsearch qsearchs); +use FS::part_export; +use FS::svc_acct; +use FS::cust_svc; + +my $user = shift or die &usage; +adminsuidsetup $user; + +#my $machine = shift or die &usage; + +my @exports = qsearch('part_export', { 'exporttype' => 'sqlradius' } ); + +foreach my $export ( @exports ) { + my $icradius_dbh = DBI->connect( + map { $export->option($_) } qw( datasrc username password ) + ) or die $DBI::errstr; + for my $table (qw( radcheck radreply usergroup )) { + my $sth = $icradius_dbh->prepare("DELETE FROM $table"); + $sth->execute or die "Can't reset $table table: ". $sth->errstr; + } +} + +foreach my $export ( @exports ) { + + #my @svcparts = map { $_->svcpart } $export->export_svc; + + my @svc_acct = + map { qsearchs('svc_acct', { 'svcnum' => $_->svcnum } ) } + map { qsearch('cust_svc', { 'svcpart' => $_->svcpart } ) } + grep { qsearch('cust_svc', { 'svcpart' => $_->svcpart } ) } + $export->export_svc; + + foreach my $svc_acct ( @svc_acct ) { + + #false laziness with FS::svc_acct::insert (like it matters) + my $error = $export->export_insert($svc_acct); + die $error if $error; + + } +} + +sub usage { + #die "Usage:\n\n sqlradius_reset user machine\n"; + die "Usage:\n\n sqlradius_reset user\n"; +} + +=head1 NAME + +freeside-sqlradius-reset - Command line interface to reset and recreate RADIUS SQL tables + +=head1 SYNOPSIS + + freeside-sqlradius-reset username + +=head1 DESCRIPTION + +Deletes the radcheck, radreply and usergroup tables and repopulates them from +the Freeside database, for all sqlradius exports. + +B is a username added by freeside-adduser. + +=head1 SEE ALSO + +, L + +=cut + + + -- cgit v1.2.1 From 17ddcceb66e4c5c45abe890403d2ca98b128d375 Mon Sep 17 00:00:00 2001 From: ivan Date: Tue, 16 Apr 2002 09:38:20 +0000 Subject: - send a notice to the customer when their card is declined - closes: Bug#351 - freeside-expiration-alerter works fine, closes: Bug#7 --- FS/bin/freeside-expiration-alerter | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-expiration-alerter b/FS/bin/freeside-expiration-alerter index 365b96467..ee3c1fb92 100755 --- a/FS/bin/freeside-expiration-alerter +++ b/FS/bin/freeside-expiration-alerter @@ -142,7 +142,8 @@ foreach my $customer (@customers) ); $!=0; $message->smtpsend( Host => $smtpmachine ) - or die "Can't send expiration email!: $!"; #die? warn? + or $message->smtpsend( Host => $smtpmachine, Debug => 1 ) + or die "Can't send expiration email: $!"; } elsif ( ! @invoicing_list || grep { $_ eq 'POST' } @invoicing_list ) { push @body, sprintf(qq{%5d %-32.32s %4s %10s %12s %12s}, @@ -166,8 +167,8 @@ if (scalar(@body)) { $!=0; $message->smtpsend( Host => $smtpmachine ) or $message->smtpsend( Host => $smtpmachine, Debug => 1 ) - or return "can't send alerter failure email to $failure_recipient". - " via server $smtpmachine with SMTP: $!"; + or die "can't send alerter failure email to $failure_recipient". + " via server $smtpmachine with SMTP: $!"; } # subroutines @@ -199,7 +200,7 @@ user: From the mapsecrets file - see config.html from the base documentation =head1 VERSION -$Id: freeside-expiration-alerter,v 1.2 2002-03-07 19:50:24 jeff Exp $ +$Id: freeside-expiration-alerter,v 1.3 2002-04-16 09:38:19 ivan Exp $ =head1 BUGS -- cgit v1.2.1 From 55dee0c595ea28dde3d2a30e1f238fc322e6e869 Mon Sep 17 00:00:00 2001 From: ivan Date: Tue, 16 Apr 2002 21:24:45 +0000 Subject: auto-use export classes --- FS/bin/freeside-queued | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'FS/bin') diff --git a/FS/bin/freeside-queued b/FS/bin/freeside-queued index f6226cca1..49b532ec3 100644 --- a/FS/bin/freeside-queued +++ b/FS/bin/freeside-queued @@ -100,6 +100,22 @@ while (1) { if $FS::svc_acct::icradius_dbh; forksuidsetup($user); + #auto-use export classes... + if ( $ljob->job =~ /(FS::part_export::\w+)::/ ) { + my $class = $1; + eval "use $class;"; + if ( $@ ) { + warn "job use $class failed"; + my %hash = $ljob->hash; + $hash{'status'} = 'failed'; + $hash{'statustext'} = $@; + my $fjob = new FS::queue( \%hash ); + my $error = $fjob->replace($ljob); + die $error if $error; + exit; #end-of-kid + }; + } + my $eval = "&". $ljob->job. '(@args);'; warn "running $eval"; eval $eval; #throw away return value? suppose so -- cgit v1.2.1 From eb7c552dd8290d6b33a4e026c5dc21ebf01105cf Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 15 May 2002 13:24:26 +0000 Subject: queue dependancies --- FS/bin/freeside-queued | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-queued b/FS/bin/freeside-queued index 49b532ec3..1539a48af 100644 --- a/FS/bin/freeside-queued +++ b/FS/bin/freeside-queued @@ -59,13 +59,16 @@ while (1) { } $warnkids=0; + my $nodepend = 'AND 0 = ( SELECT COUNT(*) FROM queue_depend'. + ' WHERE queue_depend.jobnum = queue.jobnum ) '; + my $job = qsearchs( 'queue', { 'status' => 'new' }, '', driver_name =~ /^mysql$/i - ? 'ORDER BY jobnum LIMIT 1 FOR UPDATE' - : 'ORDER BY jobnum FOR UPDATE LIMIT 1' + ? "$nodepend ORDER BY jobnum LIMIT 1 FOR UPDATE" + : "$nodepend ORDER BY jobnum FOR UPDATE LIMIT 1" ) or do { sleep 5; #connecting to db is expensive next; @@ -94,10 +97,9 @@ while (1) { $kids++; } else { #kid time - #get new db handles + #get new db handle $FS::UID::dbh->{InactiveDestroy} = 1; - $FS::svc_acct::icradius_dbh->{InactiveDestroy} = 1 - if $FS::svc_acct::icradius_dbh; + forksuidsetup($user); #auto-use export classes... -- cgit v1.2.1 From 4aaa65f643469cf2df1d97f5e12e05d0122d9570 Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 29 May 2002 20:45:04 +0000 Subject: eliminate harmless "Database handle destroyed without explicit disconnect" errors --- FS/bin/freeside-sqlradius-reset | 1 + 1 file changed, 1 insertion(+) (limited to 'FS/bin') diff --git a/FS/bin/freeside-sqlradius-reset b/FS/bin/freeside-sqlradius-reset index 132be754a..41f3358f6 100755 --- a/FS/bin/freeside-sqlradius-reset +++ b/FS/bin/freeside-sqlradius-reset @@ -22,6 +22,7 @@ foreach my $export ( @exports ) { my $sth = $icradius_dbh->prepare("DELETE FROM $table"); $sth->execute or die "Can't reset $table table: ". $sth->errstr; } + $icradius_dbh->disconnect; } foreach my $export ( @exports ) { -- cgit v1.2.1 From 72afe3cf4a355a22e942fb59068815270538999f Mon Sep 17 00:00:00 2001 From: ivan Date: Fri, 14 Jun 2002 02:25:34 +0000 Subject: mysql compatibility? --- FS/bin/freeside-queued | 64 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 42 insertions(+), 22 deletions(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-queued b/FS/bin/freeside-queued index 1539a48af..67e5e2bca 100644 --- a/FS/bin/freeside-queued +++ b/FS/bin/freeside-queued @@ -7,9 +7,10 @@ use Fcntl qw(:flock); use POSIX qw(setsid); use Date::Format; use IO::File; -use FS::UID qw(adminsuidsetup forksuidsetup driver_name); +use FS::UID qw(adminsuidsetup forksuidsetup driver_name dbh); use FS::Record qw(qsearchs); use FS::queue; +use FS::queue_depend; # no autoloading just yet use FS::cust_main; @@ -17,13 +18,14 @@ use FS::svc_acct; use Net::SSH 0.05; use FS::part_export; -my $pid_file = '/var/run/freeside-queued.pid'; - $max_kids = '10'; #guess it should be a config file... $kids = 0; my $user = shift or die &usage; +#my $pid_file = "/var/run/freeside-queued.$user.pid"; +my $pid_file = "/var/run/freeside-queued.pid"; + &daemonize1; sub REAPER { my $pid = wait; $SIG{CHLD} = \&REAPER; $kids--; } @@ -59,26 +61,44 @@ while (1) { } $warnkids=0; - my $nodepend = 'AND 0 = ( SELECT COUNT(*) FROM queue_depend'. - ' WHERE queue_depend.jobnum = queue.jobnum ) '; - - my $job = qsearchs( - 'queue', - { 'status' => 'new' }, - '', - driver_name =~ /^mysql$/i - ? "$nodepend ORDER BY jobnum LIMIT 1 FOR UPDATE" - : "$nodepend ORDER BY jobnum FOR UPDATE LIMIT 1" - ) or do { - sleep 5; #connecting to db is expensive - next; - }; + my $nodepend = driver name eq 'mysql' + ? '' + : 'AND 0 = ( SELECT COUNT(*) FROM queue_depend'. + ' WHERE queue_depend.jobnum = queue.jobnum ) '; + + my($job, $ljob); + { + my $oldAutoCommit = $FS::UID::AutoCommit; + local $FS::UID::AutoCommit = 0; + my $dbh = dbh; + + $job = qsearchs( + 'queue', + { 'status' => 'new' }, + '', + driver_name eq 'mysql' + ? "$nodepend ORDER BY jobnum LIMIT 1 FOR UPDATE" + : "$nodepend ORDER BY jobnum FOR UPDATE LIMIT 1" + ) or do { + $dbh->commit or die $dbh->errstr if $oldAutoCommit; + sleep 5; #connecting to db is expensive + next; + }; + + if ( driver_name eq 'mysql' + && qsearch('queue_depend', { 'jobnum' => $job->jobnum } ) ) { + $dbh->commit or die $dbh->errstr if $oldAutoCommit; + next; + } + + my %hash = $job->hash; + $hash{'status'} = 'locked'; + $ljob = new FS::queue ( \%hash ); + my $error = $ljob->replace($job); + die $error if $error; - my %hash = $job->hash; - $hash{'status'} = 'locked'; - my $ljob = new FS::queue ( \%hash ); - my $error = $ljob->replace($job); - die $error if $error; + $dbh->commit or die $dbh->errstr if $oldAutoCommit; + } my @args = $ljob->args; -- cgit v1.2.1 From a930f5bc47c9c2de989074f1570beaa8f116bd22 Mon Sep 17 00:00:00 2001 From: ivan Date: Fri, 14 Jun 2002 11:22:53 +0000 Subject: working job dependancies FS::queue::joblisting html excapes & truncates long arguments welcome email (sheesh!) closes: Bug#420 (haha at 4:20 am, too. really!) --- FS/bin/freeside-queued | 66 ++++++++++++++++++++++++++------------------------ 1 file changed, 35 insertions(+), 31 deletions(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-queued b/FS/bin/freeside-queued index 67e5e2bca..846055dc3 100644 --- a/FS/bin/freeside-queued +++ b/FS/bin/freeside-queued @@ -61,44 +61,48 @@ while (1) { } $warnkids=0; - my $nodepend = driver name eq 'mysql' + my $nodepend = driver_name eq 'mysql' ? '' : 'AND 0 = ( SELECT COUNT(*) FROM queue_depend'. ' WHERE queue_depend.jobnum = queue.jobnum ) '; - my($job, $ljob); - { - my $oldAutoCommit = $FS::UID::AutoCommit; - local $FS::UID::AutoCommit = 0; - my $dbh = dbh; + #my($job, $ljob); + #{ + # my $oldAutoCommit = $FS::UID::AutoCommit; + # local $FS::UID::AutoCommit = 0; + $FS::UID::AutoCommit = 0; + my $dbh = dbh; - $job = qsearchs( - 'queue', - { 'status' => 'new' }, - '', - driver_name eq 'mysql' - ? "$nodepend ORDER BY jobnum LIMIT 1 FOR UPDATE" - : "$nodepend ORDER BY jobnum FOR UPDATE LIMIT 1" - ) or do { - $dbh->commit or die $dbh->errstr if $oldAutoCommit; - sleep 5; #connecting to db is expensive - next; - }; - - if ( driver_name eq 'mysql' - && qsearch('queue_depend', { 'jobnum' => $job->jobnum } ) ) { - $dbh->commit or die $dbh->errstr if $oldAutoCommit; - next; - } + my $job = qsearchs( + 'queue', + { 'status' => 'new' }, + '', + driver_name eq 'mysql' + ? "$nodepend ORDER BY jobnum LIMIT 1 FOR UPDATE" + : "$nodepend ORDER BY jobnum FOR UPDATE LIMIT 1" + ) or do { + $dbh->commit or die $dbh->errstr; #if $oldAutoCommit; + sleep 5; #connecting to db is expensive + next; + }; - my %hash = $job->hash; - $hash{'status'} = 'locked'; - $ljob = new FS::queue ( \%hash ); - my $error = $ljob->replace($job); - die $error if $error; + if ( driver_name eq 'mysql' + && qsearch('queue_depend', { 'jobnum' => $job->jobnum } ) ) { + $dbh->commit or die $dbh->errstr; #if $oldAutoCommit; + sleep 5; #would be better if mysql could do everything in query above + next; + } + + my %hash = $job->hash; + $hash{'status'} = 'locked'; + my $ljob = new FS::queue ( \%hash ); + my $error = $ljob->replace($job); + die $error if $error; + + $dbh->commit or die $dbh->errstr; #if $oldAutoCommit; - $dbh->commit or die $dbh->errstr if $oldAutoCommit; - } + $FS::UID::AutoCommit = 1; + #} my @args = $ljob->args; -- cgit v1.2.1 From cf6020a0c273d549d33f3e9999bd8b68d9b6d133 Mon Sep 17 00:00:00 2001 From: ivan Date: Thu, 20 Jun 2002 01:29:21 +0000 Subject: shellcommands w/passwords --- FS/bin/freeside-queued | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-queued b/FS/bin/freeside-queued index 846055dc3..48d283a75 100644 --- a/FS/bin/freeside-queued +++ b/FS/bin/freeside-queued @@ -15,7 +15,7 @@ use FS::queue_depend; # no autoloading just yet use FS::cust_main; use FS::svc_acct; -use Net::SSH 0.05; +use Net::SSH 0.06; use FS::part_export; $max_kids = '10'; #guess it should be a config file... -- cgit v1.2.1 From fe610572852e2eb7c3458e77dc167c25a098c84a Mon Sep 17 00:00:00 2001 From: ivan Date: Tue, 25 Jun 2002 07:18:40 +0000 Subject: might work again under mysql --- FS/bin/freeside-queued | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-queued b/FS/bin/freeside-queued index 48d283a75..42d00cebe 100644 --- a/FS/bin/freeside-queued +++ b/FS/bin/freeside-queued @@ -8,7 +8,7 @@ use POSIX qw(setsid); use Date::Format; use IO::File; use FS::UID qw(adminsuidsetup forksuidsetup driver_name dbh); -use FS::Record qw(qsearchs); +use FS::Record qw(qsearch qsearchs); use FS::queue; use FS::queue_depend; -- cgit v1.2.1 From 72395edddb5a3887092b51056d719584f7979005 Mon Sep 17 00:00:00 2001 From: ivan Date: Tue, 2 Jul 2002 09:39:04 +0000 Subject: freebsd is sofa king broken --- FS/bin/freeside-queued | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-queued b/FS/bin/freeside-queued index 42d00cebe..4ddc70a48 100644 --- a/FS/bin/freeside-queued +++ b/FS/bin/freeside-queued @@ -36,8 +36,13 @@ $sigint = 0; $SIG{INT} = sub { warn "SIGINT received; shutting down\n"; $sigint++; }; $SIG{TERM} = sub { warn "SIGTERM received; shutting down\n"; $sigterm++; }; -$> = $FS::UID::freeside_uid unless $>; -$< = $>; +$< = FS::UID::freeside_uid; + +#freebsd is sofa king broken, won't setuid() +$> = $FS::UID::freeside_uid; +($<,$>) = ($>,$<); +$> = $FS::UID::freeside_uid; + $ENV{HOME} = (getpwuid($>))[7]; #for ssh adminsuidsetup $user; -- cgit v1.2.1 From cc9c574e5f772917515e85a5c07ce263a8552a03 Mon Sep 17 00:00:00 2001 From: ivan Date: Tue, 2 Jul 2002 09:42:38 +0000 Subject: fleabsd grr --- FS/bin/freeside-queued | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-queued b/FS/bin/freeside-queued index 4ddc70a48..46d39f2b0 100644 --- a/FS/bin/freeside-queued +++ b/FS/bin/freeside-queued @@ -36,7 +36,7 @@ $sigint = 0; $SIG{INT} = sub { warn "SIGINT received; shutting down\n"; $sigint++; }; $SIG{TERM} = sub { warn "SIGTERM received; shutting down\n"; $sigterm++; }; -$< = FS::UID::freeside_uid; +$< = $FS::UID::freeside_uid; #freebsd is sofa king broken, won't setuid() $> = $FS::UID::freeside_uid; -- cgit v1.2.1 From 00613fa78edb718fdc96640fe08d806079a81ad2 Mon Sep 17 00:00:00 2001 From: ivan Date: Tue, 2 Jul 2002 10:14:45 +0000 Subject: grr old openssh grr freebsd --- FS/bin/freeside-queued | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-queued b/FS/bin/freeside-queued index 46d39f2b0..20a6ff9fb 100644 --- a/FS/bin/freeside-queued +++ b/FS/bin/freeside-queued @@ -36,10 +36,17 @@ $sigint = 0; $SIG{INT} = sub { warn "SIGINT received; shutting down\n"; $sigint++; }; $SIG{TERM} = sub { warn "SIGTERM received; shutting down\n"; $sigterm++; }; -$< = $FS::UID::freeside_uid; +my $freeside_gid = scalar(getgrnam('freeside')) + or die "can't setgid to freeside group\n"; +$) = $freeside_gid; +$( = $freeside_gid; +#if freebsd can't setuid(), presumably it can't setgid() either. grr fleabsd +($<,$>) = ($>,$<); +$> = $freeside_gid; -#freebsd is sofa king broken, won't setuid() $> = $FS::UID::freeside_uid; +$< = $FS::UID::freeside_uid; +#freebsd is sofa king broken, won't setuid() ($<,$>) = ($>,$<); $> = $FS::UID::freeside_uid; -- cgit v1.2.1 From 96d1ff9741744ce60dbc123fa92ec794dbac2d17 Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 3 Jul 2002 01:01:26 +0000 Subject: fix usage message --- FS/bin/freeside-sqlradius-reset | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-sqlradius-reset b/FS/bin/freeside-sqlradius-reset index 41f3358f6..9cb2e2905 100755 --- a/FS/bin/freeside-sqlradius-reset +++ b/FS/bin/freeside-sqlradius-reset @@ -46,7 +46,7 @@ foreach my $export ( @exports ) { sub usage { #die "Usage:\n\n sqlradius_reset user machine\n"; - die "Usage:\n\n sqlradius_reset user\n"; + die "Usage:\n\n freeside-sqlradius-reset user\n"; } =head1 NAME -- cgit v1.2.1 From 8b8a9f09b5072db2af7f08d49d916b91f0b1bac7 Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 3 Jul 2002 01:05:24 +0000 Subject: pod --- FS/bin/freeside-sqlradius-reset | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-sqlradius-reset b/FS/bin/freeside-sqlradius-reset index 9cb2e2905..9d3a6a700 100755 --- a/FS/bin/freeside-sqlradius-reset +++ b/FS/bin/freeside-sqlradius-reset @@ -66,7 +66,7 @@ B is a username added by freeside-adduser. =head1 SEE ALSO -, L +L, L, L =cut -- cgit v1.2.1 From b3ea4da977be6a246a61852be9cd40a5b0a11dfe Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 3 Jul 2002 01:47:06 +0000 Subject: freeside-reexport --- FS/bin/freeside-reexport | 62 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 FS/bin/freeside-reexport (limited to 'FS/bin') diff --git a/FS/bin/freeside-reexport b/FS/bin/freeside-reexport new file mode 100644 index 000000000..b5c50a422 --- /dev/null +++ b/FS/bin/freeside-reexport @@ -0,0 +1,62 @@ +#!/usr/bin/perl -Tw + +use strict; +use FS::UID qw(adminsuidsetup); +use FS::Record qw(qsearch qsearchs); +use FS::part_export; +use FS::svc_acct; +use FS::cust_svc; + +my $user = shift or die &usage; +adminsuidsetup $user; + +my $export_x = shift or die &usage; +my @part_export; +if ( $export_x =~ /^(\d+)$/ ) { + @part_export = qsearchs('part_export', { exportnum=>$1 } ) + or die "exportnum $export_x not found\n"; +} else { + @part_export = qsearch('part_export', { exporttype=>$export_x } ) + or die "no exports of type $export_x found\n"; +} + +my $svc_something = shift or die &usage; +my $svc_x; +if ( $svc_something =~ /^(\d+)$/ ) { + my $cust_svc = qsearchs('cust_svc', { svcnum=>$1 } ) + or die "svcnum $svc_something not found\n"; + $svc_x = $cust_svc->svc_x; +} else { + $svc_x = qsearchs('svc_acct', { username=>$svc_something } ) + or die "username $svc_something not found\n"; +} + +foreach my $part_export ( @part_export ) { + my $error = $part_export->export_insert($svc_x); + die $error if $error; +} + + +sub usage { + die "Usage:\n\n freeside-reexport user exportnum|exporttype svcnum|username\n"; +} + +=head1 NAME + +freeside-reexport - Command line tool to re-trigger export jobs for existing services + +=head1 SYNOPSIS + + freeside-reexport user exportnum|exporttype svcnum|username + +=head1 DESCRIPTION + + Re-queues the export job for the specified exportnum or exporttype(s) and + specified service (selected by svcnum or username). + +=head1 SEE ALSO + +L, L + +=cut + -- cgit v1.2.1 From fc99564551bfb9c5dbb1f6e6f8e751d6124e001a Mon Sep 17 00:00:00 2001 From: ivan Date: Mon, 8 Jul 2002 17:14:23 +0000 Subject: oops, fix for bug only surfacing with different freeside uid/gid --- FS/bin/freeside-queued | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-queued b/FS/bin/freeside-queued index 20a6ff9fb..83074b9e4 100644 --- a/FS/bin/freeside-queued +++ b/FS/bin/freeside-queued @@ -41,8 +41,8 @@ my $freeside_gid = scalar(getgrnam('freeside')) $) = $freeside_gid; $( = $freeside_gid; #if freebsd can't setuid(), presumably it can't setgid() either. grr fleabsd -($<,$>) = ($>,$<); -$> = $freeside_gid; +($(,$)) = ($),$(); +$) = $freeside_gid; $> = $FS::UID::freeside_uid; $< = $FS::UID::freeside_uid; -- cgit v1.2.1 From 6414c4c23d3fac2012d1524f17c0aae5e5012935 Mon Sep 17 00:00:00 2001 From: ivan Date: Sat, 27 Jul 2002 02:47:12 +0000 Subject: vacuum pg databases daily --- FS/bin/freeside-daily | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-daily b/FS/bin/freeside-daily index e6f02df33..142b0c73a 100755 --- a/FS/bin/freeside-daily +++ b/FS/bin/freeside-daily @@ -4,7 +4,7 @@ use strict; use Fcntl qw(:flock); use Date::Parse; use Getopt::Std; -use FS::UID qw(adminsuidsetup); +use FS::UID qw(adminsuidsetup driver_name dbh); use FS::Record qw(qsearch qsearchs); use FS::cust_main; @@ -41,6 +41,13 @@ foreach $cust_main ( @cust_main ) { } +if ( driver_name eq 'Pg' ) { + foreach my $statement ( 'vacuum', 'vacuum analyze' ) { + my $sth = dbh->prepare($statement) or die dbh->errstr; + $sth->execute or die $sth->errstr; + } +} + # subroutines sub untaint_argv { -- cgit v1.2.1 From 5ba6bdd59b4a8a10c92e71b0519e87ca4ab99043 Mon Sep 17 00:00:00 2001 From: ivan Date: Sat, 24 Aug 2002 00:16:26 +0000 Subject: Added Files: bin/freeside-addoutsource --- FS/bin/freeside-addoutsource | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 FS/bin/freeside-addoutsource (limited to 'FS/bin') diff --git a/FS/bin/freeside-addoutsource b/FS/bin/freeside-addoutsource new file mode 100644 index 000000000..39ecba6ad --- /dev/null +++ b/FS/bin/freeside-addoutsource @@ -0,0 +1,24 @@ +#!/bin/sh + +domain=$1 + +createdb $domain && \ +\ +mkdir /usr/local/etc/freeside/conf.DBI:Pg:host=localhost\;dbname=$domain && \ +\ +chown freeside /usr/local/etc/freeside/conf.DBI:Pg:host=localhost\;dbname=$domain && \ +\ +cp /home/ivan/freeside/conf[a-z]* /usr/local/etc/freeside/conf.DBI:Pg:host=localhost\;dbname=$domain && \ +\ +touch /usr/local/etc/freeside/conf.DBI:Pg:host=localhost\;dbname=$domain/secrets && \ +\ +chown freeside /usr/local/etc/freeside/conf.DBI:Pg:host=localhost\;dbname=$domain/secrets && \ +\ +chmod 600 /usr/local/etc/freeside/conf.DBI:Pg:host=localhost\;dbname=$domain/secrets && \ +\ +echo -e "DBI:Pg:host=localhost;dbname=$domain\nfreeside\n" >/usr/local/etc/freeside/conf.DBI:Pg:host=localhost\;dbname=$domain/secrets && \ +\ +mkdir /usr/local/etc/freeside/counters.DBI:Pg:host=localhost\;dbname=$domain && \ +mkdir /usr/local/etc/freeside/cache.DBI:Pg:host=localhost\;dbname=$domain && \ +mkdir /usr/local/etc/freeside/export.DBI:Pg:host=localhost\;dbname=$domain + -- cgit v1.2.1 From 748983cb2a2cd21a82950c5000088508a416d670 Mon Sep 17 00:00:00 2001 From: ivan Date: Sat, 24 Aug 2002 01:53:55 +0000 Subject: depend on Net::SSH 0.07, for -T fix --- FS/bin/freeside-queued | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-queued b/FS/bin/freeside-queued index 83074b9e4..311fe62f9 100644 --- a/FS/bin/freeside-queued +++ b/FS/bin/freeside-queued @@ -15,7 +15,7 @@ use FS::queue_depend; # no autoloading just yet use FS::cust_main; use FS::svc_acct; -use Net::SSH 0.06; +use Net::SSH 0.07; use FS::part_export; $max_kids = '10'; #guess it should be a config file... -- cgit v1.2.1 From e0729955b2ad10fba02399afafec68fe5ccab97a Mon Sep 17 00:00:00 2001 From: ivan Date: Sat, 24 Aug 2002 02:10:54 +0000 Subject: fix path --- FS/bin/freeside-addoutsource | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-addoutsource b/FS/bin/freeside-addoutsource index 39ecba6ad..5cec17f46 100644 --- a/FS/bin/freeside-addoutsource +++ b/FS/bin/freeside-addoutsource @@ -8,7 +8,7 @@ mkdir /usr/local/etc/freeside/conf.DBI:Pg:host=localhost\;dbname=$domain && \ \ chown freeside /usr/local/etc/freeside/conf.DBI:Pg:host=localhost\;dbname=$domain && \ \ -cp /home/ivan/freeside/conf[a-z]* /usr/local/etc/freeside/conf.DBI:Pg:host=localhost\;dbname=$domain && \ +cp /home/ivan/freeside/conf/[a-z]* /usr/local/etc/freeside/conf.DBI:Pg:host=localhost\;dbname=$domain && \ \ touch /usr/local/etc/freeside/conf.DBI:Pg:host=localhost\;dbname=$domain/secrets && \ \ -- cgit v1.2.1 From 621e56df7cb76802799f7939424e0d0c8bab40fd Mon Sep 17 00:00:00 2001 From: ivan Date: Sat, 24 Aug 2002 08:13:25 +0000 Subject: also do -b flag --- FS/bin/freeside-adduser | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-adduser b/FS/bin/freeside-adduser index 9d424634b..3ac3cffa1 100644 --- a/FS/bin/freeside-adduser +++ b/FS/bin/freeside-adduser @@ -1,21 +1,23 @@ #!/usr/bin/perl -w # -# $Id: freeside-adduser,v 1.4 2002-02-06 14:58:05 ivan Exp $ +# $Id: freeside-adduser,v 1.5 2002-08-24 08:13:25 ivan Exp $ use strict; -use vars qw($opt_h $opt_c $opt_s); +use vars qw($opt_h $opt_b $opt_c $opt_s); use Getopt::Std; my $FREESIDE_CONF = "/usr/local/etc/freeside"; -getopts("ch:s:"); +getopts("bch:s:"); die &usage if $opt_c && ! $opt_h; my $user = shift or die &usage; if ( $opt_h ) { my @args = ( 'htpasswd' ); + push @args, '-b' if $opt_b; push @args, '-c' if $opt_c; push @args, $opt_h, $user; + push @args, shift if $opt_b; system(@args) == 0 or die "htpasswd failed: $?"; } -- cgit v1.2.1 From 8675d7f9367456118663ddc28907bcd69d6dae94 Mon Sep 17 00:00:00 2001 From: ivan Date: Sun, 25 Aug 2002 01:09:50 +0000 Subject: doc --- FS/bin/freeside-adduser | 8 +- FS/bin/freeside-setup | 1031 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 1036 insertions(+), 3 deletions(-) create mode 100755 FS/bin/freeside-setup (limited to 'FS/bin') diff --git a/FS/bin/freeside-adduser b/FS/bin/freeside-adduser index 3ac3cffa1..e9b300823 100644 --- a/FS/bin/freeside-adduser +++ b/FS/bin/freeside-adduser @@ -1,6 +1,6 @@ #!/usr/bin/perl -w # -# $Id: freeside-adduser,v 1.5 2002-08-24 08:13:25 ivan Exp $ +# $Id: freeside-adduser,v 1.6 2002-08-25 01:09:50 ivan Exp $ use strict; use vars qw($opt_h $opt_b $opt_c $opt_s); @@ -47,13 +47,15 @@ sales/tech folks) to the web interface, not for adding customer accounts. -h: Also call htpasswd for this user with the given filename - -c: Passed to htpasswd + -c: Passed to htpasswd(1) -s: Specify an alternate secret file + -b: same as htpasswd(1), probably insecure, not recommended + =head1 SEE ALSO -L, base Freeside documentation +L(1), base Freeside documentation =cut diff --git a/FS/bin/freeside-setup b/FS/bin/freeside-setup new file mode 100755 index 000000000..21defa6e5 --- /dev/null +++ b/FS/bin/freeside-setup @@ -0,0 +1,1031 @@ +#!/usr/bin/perl -Tw + +#to delay loading dbdef until we're ready +BEGIN { $FS::Record::setup_hack = 1; } + +use strict; +use DBI; +use DBIx::DBSchema 0.20; +use DBIx::DBSchema::Table; +use DBIx::DBSchema::Column; +use DBIx::DBSchema::ColGroup::Unique; +use DBIx::DBSchema::ColGroup::Index; +use FS::UID qw(adminsuidsetup datasrc checkeuid getsecrets); +use FS::Record; +use FS::cust_main_county; +use FS::raddb; +use FS::part_bill_event; + +die "Not running uid freeside!" unless checkeuid(); + +my %attrib2db = + map { lc($FS::raddb::attrib{$_}) => $_ } keys %FS::raddb::attrib; + +my $user = shift or die &usage; +getsecrets($user); + +#needs to match FS::Record +my($dbdef_file) = "/usr/local/etc/freeside/dbdef.". datasrc; + +### + +#print "\nEnter the maximum username length: "; +#my($username_len)=&getvalue; +my $username_len = 32; #usernamemax config file + +print "\n\n", <); + chop $x; + $x; +} + +sub _yesno { + print " [y/N]:"; + my $x = scalar(); + $x =~ /^y/i; +} + +### + +my($char_d) = 80; #default maxlength for text fields + +#my(@date_type) = ( 'timestamp', '', '' ); +my(@date_type) = ( 'int', 'NULL', '' ); +my(@perl_type) = ( 'text', 'NULL', '' ); +my @money_type = ( 'decimal', '', '10,2' ); + +### +# create a dbdef object from the old data structure +### + +my(%tables)=&tables_hash_hack; + +#turn it into objects +my($dbdef) = new DBIx::DBSchema ( map { + my(@columns); + while (@{$tables{$_}{'columns'}}) { + my($name,$type,$null,$length)=splice @{$tables{$_}{'columns'}}, 0, 4; + push @columns, new DBIx::DBSchema::Column ( $name,$type,$null,$length ); + } + DBIx::DBSchema::Table->new( + $_, + $tables{$_}{'primary_key'}, + DBIx::DBSchema::ColGroup::Unique->new($tables{$_}{'unique'}), + DBIx::DBSchema::ColGroup::Index->new($tables{$_}{'index'}), + @columns, + ); +} (keys %tables) ); + +my $cust_main = $dbdef->table('cust_main'); +unless ($ship) { #remove ship_ from cust_main + $cust_main->delcolumn($_) foreach ( grep /^ship_/, $cust_main->columns ); +} else { #add indices on ship_last and ship_company + push @{$cust_main->index->lol_ref}, ( ['ship_last'], ['ship_company'] ) +} + +#add radius attributes to svc_acct + +my($svc_acct)=$dbdef->table('svc_acct'); + +my($attribute); +foreach $attribute (@attributes) { + $svc_acct->addcolumn ( new DBIx::DBSchema::Column ( + 'radius_'. $attribute, + 'varchar', + 'NULL', + $char_d, + )); +} + +foreach $attribute (@check_attributes) { + $svc_acct->addcolumn( new DBIx::DBSchema::Column ( + 'rc_'. $attribute, + 'varchar', + 'NULL', + $char_d, + )); +} + +##make part_svc table (but now as object) +# +#my($part_svc)=$dbdef->table('part_svc'); +# +##because of svc_acct_pop +##foreach (grep /^svc_/, $dbdef->tables) { +##foreach (qw(svc_acct svc_acct_sm svc_charge svc_domain svc_wo)) { +#foreach (qw(svc_acct svc_domain svc_forward svc_www)) { +# my($table)=$dbdef->table($_); +# my($col); +# foreach $col ( $table->columns ) { +# next if $col =~ /^svcnum$/; +# $part_svc->addcolumn( new DBIx::DBSchema::Column ( +# $table->name. '__' . $table->column($col)->name, +# 'varchar', #$table->column($col)->type, +# 'NULL', +# $char_d, #$table->column($col)->length, +# )); +# $part_svc->addcolumn ( new DBIx::DBSchema::Column ( +# $table->name. '__'. $table->column($col)->name . "_flag", +# 'char', +# 'NULL', +# 1, +# )); +# } +#} + +#create history tables (false laziness w/create-history-tables) +foreach my $table ( grep { ! /^h_/ } $dbdef->tables ) { + my $tableobj = $dbdef->table($table) + or die "unknown table $table"; + + die "unique->lol_ref undefined for $table" + unless defined $tableobj->unique->lol_ref; + die "index->lol_ref undefined for $table" + unless defined $tableobj->index->lol_ref; + + my $h_tableobj = DBIx::DBSchema::Table->new( { + name => "h_$table", + primary_key => 'historynum', + unique => DBIx::DBSchema::ColGroup::Unique->new( [] ), + 'index' => DBIx::DBSchema::ColGroup::Index->new( [ + @{$tableobj->unique->lol_ref}, + @{$tableobj->index->lol_ref} + ] ), + columns => [ + DBIx::DBSchema::Column->new( { + 'name' => 'historynum', + 'type' => 'serial', + 'null' => 'NOT NULL', + 'length' => '', + 'default' => '', + 'local' => '', + } ), + DBIx::DBSchema::Column->new( { + 'name' => 'history_date', + 'type' => 'int', + 'null' => 'NULL', + 'length' => '', + 'default' => '', + 'local' => '', + } ), + DBIx::DBSchema::Column->new( { + 'name' => 'history_user', + 'type' => 'varchar', + 'null' => 'NOT NULL', + 'length' => '80', + 'default' => '', + 'local' => '', + } ), + DBIx::DBSchema::Column->new( { + 'name' => 'history_action', + 'type' => 'varchar', + 'null' => 'NOT NULL', + 'length' => '80', + 'default' => '', + 'local' => '', + } ), + map { $tableobj->column($_) } $tableobj->columns + ], + } ); + $dbdef->addtable($h_tableobj); +} + +#important +$dbdef->save($dbdef_file); +&FS::Record::reload_dbdef($dbdef_file); + +### +# create 'em +### + +my($dbh)=adminsuidsetup $user; + +#create tables +$|=1; + +foreach my $statement ( $dbdef->sql($dbh) ) { + $dbh->do( $statement ) + or die "CREATE error: ". $dbh->errstr. "\ndoing statement: $statement"; +} + +#not really sample data (and shouldn't default to US) + +#cust_main_county + +#USPS state codes +foreach ( qw( +AL AK AS AZ AR CA CO CT DC DE FM FL GA GU HI ID IL IN IA KS KY LA +ME MH MD MA MI MN MS MO MT NC ND NE NH NJ NM NV NY MP OH OK OR PA PW PR RI +SC SD TN TX UT VT VI VA WA WV WI WY AE AA AP +) ) { + my($cust_main_county)=new FS::cust_main_county({ + 'state' => $_, + 'tax' => 0, + 'country' => 'US', + }); + my($error); + $error=$cust_main_county->insert; + die $error if $error; +} + +#AU "offical" state codes ala mark.williamson@ebbs.com.au (Mark Williamson) +foreach ( qw( +VIC NSW NT QLD TAS ACT WA SA +) ) { + my($cust_main_county)=new FS::cust_main_county({ + 'state' => $_, + 'tax' => 0, + 'country' => 'AU', + }); + my($error); + $error=$cust_main_county->insert; + die $error if $error; +} + +#ISO 2-letter country codes (same as country TLDs) except US and AU +foreach ( qw( +AF AL DZ AS AD AO AI AQ AG AR AM AW AT AZ BS BH BD BB BY BE BZ BJ BM BT BO +BA BW BV BR IO BN BG BF BI KH CM CA CV KY CF TD CL CN CX CC CO KM CG CK CR CI +HR CU CY CZ DK DJ DM DO TP EC EG SV GQ ER EE ET FK FO FJ FI FR FX GF PF TF GA +GM GE DE GH GI GR GL GD GP GU GT GN GW GY HT HM HN HK HU IS IN ID IR IQ IE IL +IT JM JP JO KZ KE KI KP KR KW KG LA LV LB LS LR LY LI LT LU MO MK MG MW MY MV +ML MT MH MQ MR MU YT MX FM MD MC MN MS MA MZ MM NA NR NP NL AN NC NZ NI NE NG +NU NF MP NO OM PK PW PA PG PY PE PH PN PL PT PR QA RE RO RU RW KN LC VC WS SM +ST SA SN SC SL SG SK SI SB SO ZA GS ES LK SH PM SD SR SJ SZ SE CH SY TW TJ TZ +TH TG TK TO TT TN TR TM TC TV UG UA AE GB UM UY UZ VU VA VE VN VG VI WF EH +YE YU ZR ZM ZW +) ) { + my($cust_main_county)=new FS::cust_main_county({ + 'tax' => 0, + 'country' => $_, + }); + my($error); + $error=$cust_main_county->insert; + die $error if $error; +} + +#billing events +foreach my $aref ( + [ 'COMP', 'Comp invoice', '$cust_bill->comp();', 30, 'comp' ], + [ 'CARD', 'Batch card', '$cust_bill->batch_card();', 40, 'batch-card' ], + [ 'BILL', 'Send invoice', '$cust_bill->send();', 50, 'send' ], +) { + + my $part_bill_event = new FS::part_bill_event({ + 'payby' => $aref->[0], + 'event' => $aref->[1], + 'eventcode' => $aref->[2], + 'seconds' => 0, + 'weight' => $aref->[3], + 'plan' => $aref->[4], + }); + my($error); + $error=$part_bill_event->insert; + die $error if $error; + +} + +$dbh->commit or die $dbh->errstr; +$dbh->disconnect or die $dbh->errstr; + +print "Freeside database initialized sucessfully\n"; + +sub usage { + die "Usage:\n fs-setup user\n"; +} + +### +# Now it becomes an object. much better. +### +sub tables_hash_hack { + + #note that s/(date|change)/_$1/; to avoid keyword conflict. + #put a kludge in FS::Record to catch this or? (pry need some date-handling + #stuff anyway also) + + my(%tables)=( #yech.} + + 'agent' => { + 'columns' => [ + 'agentnum', 'int', '', '', + 'agent', 'varchar', '', $char_d, + 'typenum', 'int', '', '', + 'freq', 'int', 'NULL', '', + 'prog', @perl_type, + ], + 'primary_key' => 'agentnum', + 'unique' => [], + 'index' => [ ['typenum'] ], + }, + + 'agent_type' => { + 'columns' => [ + 'typenum', 'int', '', '', + 'atype', 'varchar', '', $char_d, + ], + 'primary_key' => 'typenum', + 'unique' => [], + 'index' => [], + }, + + 'type_pkgs' => { + 'columns' => [ + 'typenum', 'int', '', '', + 'pkgpart', 'int', '', '', + ], + 'primary_key' => '', + 'unique' => [ ['typenum', 'pkgpart'] ], + 'index' => [ ['typenum'] ], + }, + + 'cust_bill' => { + 'columns' => [ + 'invnum', 'int', '', '', + 'custnum', 'int', '', '', + '_date', @date_type, + 'charged', @money_type, + 'printed', 'int', '', '', + 'closed', 'char', 'NULL', 1, + ], + 'primary_key' => 'invnum', + 'unique' => [], + 'index' => [ ['custnum'] ], + }, + + 'cust_bill_event' => { + 'columns' => [ + 'eventnum', 'int', '', '', + 'invnum', 'int', '', '', + 'eventpart', 'int', '', '', + '_date', @date_type, + 'status', 'varchar', '', $char_d, + 'statustext', 'text', 'NULL', '', + ], + 'primary_key' => 'eventnum', + #no... there are retries now #'unique' => [ [ 'eventpart', 'invnum' ] ], + 'unique' => [], + 'index' => [ ['invnum'], ['status'] ], + }, + + 'part_bill_event' => { + 'columns' => [ + 'eventpart', 'int', '', '', + 'payby', 'char', '', 4, + 'event', 'varchar', '', $char_d, + 'eventcode', @perl_type, + 'seconds', 'int', 'NULL', '', + 'weight', 'int', '', '', + 'plan', 'varchar', 'NULL', $char_d, + 'plandata', 'text', 'NULL', '', + 'disabled', 'char', 'NULL', 1, + ], + 'primary_key' => 'eventpart', + 'unique' => [], + 'index' => [ ['payby'] ], + }, + + 'cust_bill_pkg' => { + 'columns' => [ + 'pkgnum', 'int', '', '', + 'invnum', 'int', '', '', + 'setup', @money_type, + 'recur', @money_type, + 'sdate', @date_type, + 'edate', @date_type, + ], + 'primary_key' => '', + 'unique' => [ ['pkgnum', 'invnum'] ], + 'index' => [ ['invnum'] ], + }, + + 'cust_credit' => { + 'columns' => [ + 'crednum', 'int', '', '', + 'custnum', 'int', '', '', + '_date', @date_type, + 'amount', @money_type, + 'otaker', 'varchar', '', 8, + 'reason', 'text', 'NULL', '', + 'closed', 'char', 'NULL', 1, + ], + 'primary_key' => 'crednum', + 'unique' => [], + 'index' => [ ['custnum'] ], + }, + + 'cust_credit_bill' => { + 'columns' => [ + 'creditbillnum', 'int', '', '', + 'crednum', 'int', '', '', + 'invnum', 'int', '', '', + '_date', @date_type, + 'amount', @money_type, + ], + 'primary_key' => 'creditbillnum', + 'unique' => [], + 'index' => [ ['crednum'], ['invnum'] ], + }, + + 'cust_main' => { + 'columns' => [ + 'custnum', 'int', '', '', + 'agentnum', 'int', '', '', +# 'titlenum', 'int', 'NULL', '', + 'last', 'varchar', '', $char_d, +# 'middle', 'varchar', 'NULL', $char_d, + 'first', 'varchar', '', $char_d, + 'ss', 'char', 'NULL', 11, + 'company', 'varchar', 'NULL', $char_d, + 'address1', 'varchar', '', $char_d, + 'address2', 'varchar', 'NULL', $char_d, + 'city', 'varchar', '', $char_d, + 'county', 'varchar', 'NULL', $char_d, + 'state', 'varchar', 'NULL', $char_d, + 'zip', 'varchar', '', 10, + 'country', 'char', '', 2, + 'daytime', 'varchar', 'NULL', 20, + 'night', 'varchar', 'NULL', 20, + 'fax', 'varchar', 'NULL', 12, + 'ship_last', 'varchar', 'NULL', $char_d, +# 'ship_middle', 'varchar', 'NULL', $char_d, + 'ship_first', 'varchar', 'NULL', $char_d, + 'ship_company', 'varchar', 'NULL', $char_d, + 'ship_address1', 'varchar', 'NULL', $char_d, + 'ship_address2', 'varchar', 'NULL', $char_d, + 'ship_city', 'varchar', 'NULL', $char_d, + 'ship_county', 'varchar', 'NULL', $char_d, + 'ship_state', 'varchar', 'NULL', $char_d, + 'ship_zip', 'varchar', 'NULL', 10, + 'ship_country', 'char', 'NULL', 2, + 'ship_daytime', 'varchar', 'NULL', 20, + 'ship_night', 'varchar', 'NULL', 20, + 'ship_fax', 'varchar', 'NULL', 12, + 'payby', 'char', '', 4, + 'payinfo', 'varchar', 'NULL', $char_d, + #'paydate', @date_type, + 'paydate', 'varchar', 'NULL', 10, + 'payname', 'varchar', 'NULL', $char_d, + 'tax', 'char', 'NULL', 1, + 'otaker', 'varchar', '', 8, + 'refnum', 'int', '', '', + 'referral_custnum', 'int', 'NULL', '', + 'comments', 'text', 'NULL', '', + ], + 'primary_key' => 'custnum', + 'unique' => [], + #'index' => [ ['last'], ['company'] ], + 'index' => [ ['last'], [ 'company' ], [ 'referral_custnum' ] ], + }, + + 'cust_main_invoice' => { + 'columns' => [ + 'destnum', 'int', '', '', + 'custnum', 'int', '', '', + 'dest', 'varchar', '', $char_d, + ], + 'primary_key' => 'destnum', + 'unique' => [], + 'index' => [ ['custnum'], ], + }, + + 'cust_main_county' => { #county+state+country are checked off the + #cust_main_county for validation and to provide + # a tax rate. + 'columns' => [ + 'taxnum', 'int', '', '', + 'state', 'varchar', 'NULL', $char_d, + 'county', 'varchar', 'NULL', $char_d, + 'country', 'char', '', 2, + 'taxclass', 'varchar', 'NULL', $char_d, + 'exempt_amount', @money_type, + 'tax', 'real', '', '', #tax % + ], + 'primary_key' => 'taxnum', + 'unique' => [], + # 'unique' => [ ['taxnum'], ['state', 'county'] ], + 'index' => [], + }, + + 'cust_pay' => { + 'columns' => [ + 'paynum', 'int', '', '', + #now cust_bill_pay #'invnum', 'int', '', '', + 'custnum', 'int', '', '', + 'paid', @money_type, + '_date', @date_type, + 'payby', 'char', '', 4, # CARD/BILL/COMP, should be index into + # payment type table. + 'payinfo', 'varchar', 'NULL', 16, #see cust_main above + 'paybatch', 'varchar', 'NULL', $char_d, #for auditing purposes. + 'closed', 'char', 'NULL', 1, + ], + 'primary_key' => 'paynum', + 'unique' => [], + 'index' => [ [ 'custnum' ], [ 'paybatch' ] ], + }, + + 'cust_bill_pay' => { + 'columns' => [ + 'billpaynum', 'int', '', '', + 'invnum', 'int', '', '', + 'paynum', 'int', '', '', + 'amount', @money_type, + '_date', @date_type + ], + 'primary_key' => 'billpaynum', + 'unique' => [], + 'index' => [ [ 'paynum' ], [ 'invnum' ] ], + }, + + 'cust_pay_batch' => { #what's this used for again? list of customers + #in current CARD batch? (necessarily CARD?) + 'columns' => [ + 'paybatchnum', 'int', '', '', + 'invnum', 'int', '', '', + 'custnum', 'int', '', '', + 'last', 'varchar', '', $char_d, + 'first', 'varchar', '', $char_d, + 'address1', 'varchar', '', $char_d, + 'address2', 'varchar', 'NULL', $char_d, + 'city', 'varchar', '', $char_d, + 'state', 'varchar', 'NULL', $char_d, + 'zip', 'varchar', '', 10, + 'country', 'char', '', 2, +# 'trancode', 'int', '', '', + 'cardnum', 'varchar', '', 16, + #'exp', @date_type, + 'exp', 'varchar', '', 11, + 'payname', 'varchar', 'NULL', $char_d, + 'amount', @money_type, + ], + 'primary_key' => 'paybatchnum', + 'unique' => [], + 'index' => [ ['invnum'], ['custnum'] ], + }, + + 'cust_pkg' => { + 'columns' => [ + 'pkgnum', 'int', '', '', + 'custnum', 'int', '', '', + 'pkgpart', 'int', '', '', + 'otaker', 'varchar', '', 8, + 'setup', @date_type, + 'bill', @date_type, + 'susp', @date_type, + 'cancel', @date_type, + 'expire', @date_type, + 'manual_flag', 'char', 'NULL', 1, + ], + 'primary_key' => 'pkgnum', + 'unique' => [], + 'index' => [ ['custnum'] ], + }, + + 'cust_refund' => { + 'columns' => [ + 'refundnum', 'int', '', '', + #now cust_credit_refund #'crednum', 'int', '', '', + 'custnum', 'int', '', '', + '_date', @date_type, + 'refund', @money_type, + 'otaker', 'varchar', '', 8, + 'reason', 'varchar', '', $char_d, + 'payby', 'char', '', 4, # CARD/BILL/COMP, should be index + # into payment type table. + 'payinfo', 'varchar', 'NULL', 16, #see cust_main above + 'paybatch', 'varchar', 'NULL', $char_d, + 'closed', 'char', 'NULL', 1, + ], + 'primary_key' => 'refundnum', + 'unique' => [], + 'index' => [], + }, + + 'cust_credit_refund' => { + 'columns' => [ + 'creditrefundnum', 'int', '', '', + 'crednum', 'int', '', '', + 'refundnum', 'int', '', '', + 'amount', @money_type, + '_date', @date_type + ], + 'primary_key' => 'creditrefundnum', + 'unique' => [], + 'index' => [ [ 'crednum', 'refundnum' ] ], + }, + + + 'cust_svc' => { + 'columns' => [ + 'svcnum', 'int', '', '', + 'pkgnum', 'int', 'NULL', '', + 'svcpart', 'int', '', '', + ], + 'primary_key' => 'svcnum', + 'unique' => [], + 'index' => [ ['svcnum'], ['pkgnum'], ['svcpart'] ], + }, + + 'part_pkg' => { + 'columns' => [ + 'pkgpart', 'int', '', '', + 'pkg', 'varchar', '', $char_d, + 'comment', 'varchar', '', $char_d, + 'setup', @perl_type, + 'freq', 'int', '', '', #billing frequency (months) + 'recur', @perl_type, + 'setuptax', 'char', 'NULL', 1, + 'recurtax', 'char', 'NULL', 1, + 'plan', 'varchar', 'NULL', $char_d, + 'plandata', 'text', 'NULL', '', + 'disabled', 'char', 'NULL', 1, + 'taxclass', 'varchar', 'NULL', $char_d, + ], + 'primary_key' => 'pkgpart', + 'unique' => [], + 'index' => [], + }, + +# 'part_title' => { +# 'columns' => [ +# 'titlenum', 'int', '', '', +# 'title', 'varchar', '', $char_d, +# ], +# 'primary_key' => 'titlenum', +# 'unique' => [ [] ], +# 'index' => [ [] ], +# }, + + 'pkg_svc' => { + 'columns' => [ + 'pkgpart', 'int', '', '', + 'svcpart', 'int', '', '', + 'quantity', 'int', '', '', + ], + 'primary_key' => '', + 'unique' => [ ['pkgpart', 'svcpart'] ], + 'index' => [ ['pkgpart'] ], + }, + + 'part_referral' => { + 'columns' => [ + 'refnum', 'int', '', '', + 'referral', 'varchar', '', $char_d, + ], + 'primary_key' => 'refnum', + 'unique' => [], + 'index' => [], + }, + + 'part_svc' => { + 'columns' => [ + 'svcpart', 'int', '', '', + 'svc', 'varchar', '', $char_d, + 'svcdb', 'varchar', '', $char_d, + 'disabled', 'char', 'NULL', 1, + ], + 'primary_key' => 'svcpart', + 'unique' => [], + 'index' => [], + }, + + 'part_svc_column' => { + 'columns' => [ + 'columnnum', 'int', '', '', + 'svcpart', 'int', '', '', + 'columnname', 'varchar', '', 64, + 'columnvalue', 'varchar', 'NULL', $char_d, + 'columnflag', 'char', 'NULL', 1, + ], + 'primary_key' => 'columnnum', + 'unique' => [ [ 'svcpart', 'columnname' ] ], + 'index' => [ [ 'svcpart' ] ], + }, + + #(this should be renamed to part_pop) + 'svc_acct_pop' => { + 'columns' => [ + 'popnum', 'int', '', '', + 'city', 'varchar', '', $char_d, + 'state', 'varchar', '', $char_d, + 'ac', 'char', '', 3, + 'exch', 'char', '', 3, + 'loc', 'char', 'NULL', 4, #NULL for legacy purposes + ], + 'primary_key' => 'popnum', + 'unique' => [], + 'index' => [ [ 'state' ] ], + }, + + 'part_pop_local' => { + 'columns' => [ + 'localnum', 'int', '', '', + 'popnum', 'int', '', '', + 'city', 'varchar', 'NULL', $char_d, + 'state', 'char', 'NULL', 2, + 'npa', 'char', '', 3, + 'nxx', 'char', '', 3, + ], + 'primary_key' => 'localnum', + 'unique' => [], + 'index' => [ [ 'npa', 'nxx' ], [ 'popnum' ] ], + }, + + 'svc_acct' => { + '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) + 'sec_phrase', 'varchar', 'NULL', $char_d, + 'popnum', 'int', 'NULL', '', + 'uid', 'int', 'NULL', '', + 'gid', 'int', 'NULL', '', + 'finger', 'varchar', 'NULL', $char_d, + 'dir', 'varchar', 'NULL', $char_d, + 'shell', 'varchar', 'NULL', $char_d, + 'quota', 'varchar', 'NULL', $char_d, + 'slipip', 'varchar', 'NULL', 15, #four TINYINTs, bah. + 'seconds', 'int', 'NULL', '', #uhhhh + 'domsvc', 'int', '', '', + ], + 'primary_key' => 'svcnum', + #'unique' => [ [ 'username', 'domsvc' ] ], + 'unique' => [], + 'index' => [ ['username'], ['domsvc'] ], + }, + +# 'svc_acct_sm' => { +# 'columns' => [ +# 'svcnum', 'int', '', '', +# 'domsvc', 'int', '', '', +# 'domuid', 'int', '', '', +# 'domuser', 'varchar', '', $char_d, +# ], +# 'primary_key' => 'svcnum', +# 'unique' => [ [] ], +# 'index' => [ ['domsvc'], ['domuid'] ], +# }, + + #'svc_charge' => { + # 'columns' => [ + # 'svcnum', 'int', '', '', + # 'amount', @money_type, + # ], + # 'primary_key' => 'svcnum', + # 'unique' => [ [] ], + # 'index' => [ [] ], + #}, + + 'svc_domain' => { + 'columns' => [ + 'svcnum', 'int', '', '', + 'domain', 'varchar', '', $char_d, + 'catchall', 'int', 'NULL', '', + ], + 'primary_key' => 'svcnum', + 'unique' => [ ['domain'] ], + 'index' => [], + }, + + 'domain_record' => { + 'columns' => [ + 'recnum', 'int', '', '', + 'svcnum', 'int', '', '', + 'reczone', 'varchar', '', $char_d, + 'recaf', 'char', '', 2, + 'rectype', 'char', '', 5, + 'recdata', 'varchar', '', $char_d, + ], + 'primary_key' => 'recnum', + 'unique' => [], + 'index' => [ ['svcnum'] ], + }, + + 'svc_forward' => { + 'columns' => [ + 'svcnum', 'int', '', '', + 'srcsvc', 'int', '', '', + 'dstsvc', 'int', '', '', + 'dst', 'varchar', 'NULL', $char_d, + ], + 'primary_key' => 'svcnum', + 'unique' => [], + 'index' => [ ['srcsvc'], ['dstsvc'] ], + }, + + 'svc_www' => { + 'columns' => [ + 'svcnum', 'int', '', '', + 'recnum', 'int', '', '', + 'usersvc', 'int', '', '', + ], + 'primary_key' => 'svcnum', + 'unique' => [], + 'index' => [], + }, + + #'svc_wo' => { + # 'columns' => [ + # 'svcnum', 'int', '', '', + # 'svcnum', 'int', '', '', + # 'svcnum', 'int', '', '', + # 'worker', 'varchar', '', $char_d, + # '_date', @date_type, + # ], + # 'primary_key' => 'svcnum', + # 'unique' => [ [] ], + # 'index' => [ [] ], + #}, + + 'prepay_credit' => { + 'columns' => [ + 'prepaynum', 'int', '', '', + 'identifier', 'varchar', '', $char_d, + 'amount', @money_type, + 'seconds', 'int', 'NULL', '', + ], + 'primary_key' => 'prepaynum', + 'unique' => [ ['identifier'] ], + 'index' => [], + }, + + 'port' => { + 'columns' => [ + 'portnum', 'int', '', '', + 'ip', 'varchar', 'NULL', 15, + 'nasport', 'int', 'NULL', '', + 'nasnum', 'int', '', '', + ], + 'primary_key' => 'portnum', + 'unique' => [], + 'index' => [], + }, + + 'nas' => { + 'columns' => [ + 'nasnum', 'int', '', '', + 'nas', 'varchar', '', $char_d, + 'nasip', 'varchar', '', 15, + 'nasfqdn', 'varchar', '', $char_d, + 'last', 'int', '', '', + ], + 'primary_key' => 'nasnum', + 'unique' => [ [ 'nas' ], [ 'nasip' ] ], + 'index' => [ [ 'last' ] ], + }, + + 'session' => { + 'columns' => [ + 'sessionnum', 'int', '', '', + 'portnum', 'int', '', '', + 'svcnum', 'int', '', '', + 'login', @date_type, + 'logout', @date_type, + ], + 'primary_key' => 'sessionnum', + 'unique' => [], + 'index' => [ [ 'portnum' ] ], + }, + + 'queue' => { + 'columns' => [ + 'jobnum', 'int', '', '', + 'job', 'text', '', '', + '_date', 'int', '', '', + 'status', 'varchar', '', $char_d, + 'statustext', 'text', 'NULL', '', + 'svcnum', 'int', 'NULL', '', + ], + 'primary_key' => 'jobnum', + 'unique' => [], + 'index' => [ [ 'svcnum' ], [ 'status' ] ], + }, + + 'queue_arg' => { + 'columns' => [ + 'argnum', 'int', '', '', + 'jobnum', 'int', '', '', + 'arg', 'text', 'NULL', '', + ], + 'primary_key' => 'argnum', + 'unique' => [], + 'index' => [ [ 'jobnum' ] ], + }, + + 'queue_depend' => { + 'columns' => [ + 'dependnum', 'int', '', '', + 'jobnum', 'int', '', '', + 'depend_jobnum', 'int', '', '', + ], + 'primary_key' => 'dependnum', + 'unique' => [], + 'index' => [ [ 'jobnum' ], [ 'depend_jobnum' ] ], + }, + + 'export_svc' => { + 'columns' => [ + 'exportsvcnum' => 'int', '', '', + 'exportnum' => 'int', '', '', + 'svcpart' => 'int', '', '', + ], + 'primary_key' => 'exportsvcnum', + 'unique' => [ [ 'exportnum', 'svcpart' ] ], + 'index' => [ [ 'exportnum' ], [ 'svcpart' ] ], + }, + + 'part_export' => { + 'columns' => [ + 'exportnum', 'int', '', '', + #'svcpart', 'int', '', '', + 'machine', 'varchar', '', $char_d, + 'exporttype', 'varchar', '', $char_d, + 'nodomain', 'char', 'NULL', 1, + ], + 'primary_key' => 'exportnum', + 'unique' => [], + 'index' => [ [ 'machine' ], [ 'exporttype' ] ], + }, + + 'part_export_option' => { + 'columns' => [ + 'optionnum', 'int', '', '', + 'exportnum', 'int', '', '', + 'optionname', 'varchar', '', $char_d, + 'optionvalue', 'text', 'NULL', '', + ], + 'primary_key' => 'optionnum', + 'unique' => [], + 'index' => [ [ 'exportnum' ], [ 'optionname' ] ], + }, + + 'radius_usergroup' => { + 'columns' => [ + 'usergroupnum', 'int', '', '', + 'svcnum', 'int', '', '', + 'groupname', 'varchar', '', $char_d, + ], + 'primary_key' => 'usergroupnum', + 'unique' => [], + 'index' => [ [ 'svcnum' ], [ 'groupname' ] ], + }, + + 'msgcat' => { + 'columns' => [ + 'msgnum', 'int', '', '', + 'msgcode', 'varchar', '', $char_d, + 'locale', 'varchar', '', 16, + 'msg', 'text', '', '', + ], + 'primary_key' => 'msgnum', + 'unique' => [ [ 'msgcode', 'locale' ] ], + 'index' => [], + }, + + 'cust_tax_exempt' => { + 'columns' => [ + 'exemptnum', 'int', '', '', + 'custnum', 'int', '', '', + 'taxnum', 'int', '', '', + 'year', 'int', '', '', + 'month', 'int', '', '', + 'amount', @money_type, + ], + 'primary_key' => 'exemptnum', + 'unique' => [ [ 'custnum', 'taxnum', 'year', 'month' ] ], + 'index' => [], + }, + + + + ); + + %tables; + +} + -- cgit v1.2.1 From ef92d87d1980598a4f786905ac7aff1af0ead2b8 Mon Sep 17 00:00:00 2001 From: ivan Date: Sun, 25 Aug 2002 01:14:16 +0000 Subject: noninteractive freeside-setup --- FS/bin/freeside-setup | 77 ++++++++++++++++++++++++++++----------------------- 1 file changed, 42 insertions(+), 35 deletions(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-setup b/FS/bin/freeside-setup index 21defa6e5..a14f0e12b 100755 --- a/FS/bin/freeside-setup +++ b/FS/bin/freeside-setup @@ -4,6 +4,8 @@ BEGIN { $FS::Record::setup_hack = 1; } use strict; +use vars qw($opt_s); +use Getopt::Std; use DBI; use DBIx::DBSchema 0.20; use DBIx::DBSchema::Table; @@ -21,6 +23,7 @@ die "Not running uid freeside!" unless checkeuid(); my %attrib2db = map { lc($FS::raddb::attrib{$_}) => $_ } keys %FS::raddb::attrib; +getopts("s"); my $user = shift or die &usage; getsecrets($user); @@ -33,42 +36,46 @@ my($dbdef_file) = "/usr/local/etc/freeside/dbdef.". datasrc; #my($username_len)=&getvalue; my $username_len = 32; #usernamemax config file -print "\n\n", <); - chop $x; - $x; -} +#print "\n\n", <); +# chop $x; +# $x; +#} +# +#sub _yesno { +# print " [y/N]:"; +# my $x = scalar(); +# $x =~ /^y/i; +#} -sub _yesno { - print " [y/N]:"; - my $x = scalar(); - $x =~ /^y/i; -} +my @check_attributes = (); #add later +my @attributes = (); #add later +my $ship = $opt_s; ### -- cgit v1.2.1 From 3dc9eeed220e7f7adbf08526f109a190deb3f552 Mon Sep 17 00:00:00 2001 From: ivan Date: Sun, 25 Aug 2002 01:16:30 +0000 Subject: doc --- FS/bin/freeside-adduser | 4 ++-- FS/bin/freeside-setup | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-adduser b/FS/bin/freeside-adduser index e9b300823..424123226 100644 --- a/FS/bin/freeside-adduser +++ b/FS/bin/freeside-adduser @@ -1,6 +1,6 @@ #!/usr/bin/perl -w # -# $Id: freeside-adduser,v 1.6 2002-08-25 01:09:50 ivan Exp $ +# $Id: freeside-adduser,v 1.7 2002-08-25 01:16:30 ivan Exp $ use strict; use vars qw($opt_h $opt_b $opt_c $opt_s); @@ -29,7 +29,7 @@ print MAPSECRETS "$user $secretfile\n"; close MAPSECRETS or die "can't close $FREESIDE_CONF/mapsecrets: $!"; sub usage { - die "Usage:\n\n freeside-adduser [ -h htpasswd_file [ -c ] ] [ -s secretfile ] username" + die "Usage:\n\n freeside-adduser [ -h htpasswd_file [ -c ] [ -b ] ] [ -s secretfile ] username" } =head1 NAME diff --git a/FS/bin/freeside-setup b/FS/bin/freeside-setup index a14f0e12b..78a03385c 100755 --- a/FS/bin/freeside-setup +++ b/FS/bin/freeside-setup @@ -320,10 +320,10 @@ foreach my $aref ( $dbh->commit or die $dbh->errstr; $dbh->disconnect or die $dbh->errstr; -print "Freeside database initialized sucessfully\n"; +#print "Freeside database initialized sucessfully\n"; sub usage { - die "Usage:\n fs-setup user\n"; + die "Usage:\n freeside-setup [ -s ] user\n"; } ### -- cgit v1.2.1 From f8a3854cc6186ae9dc2bfafd3a756224ed999cd7 Mon Sep 17 00:00:00 2001 From: ivan Date: Sun, 25 Aug 2002 01:48:06 +0000 Subject: Added Files: bin/freeside-addoutsourceuser --- FS/bin/freeside-addoutsourceuser | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 FS/bin/freeside-addoutsourceuser (limited to 'FS/bin') diff --git a/FS/bin/freeside-addoutsourceuser b/FS/bin/freeside-addoutsourceuser new file mode 100644 index 000000000..f76f39808 --- /dev/null +++ b/FS/bin/freeside-addoutsourceuser @@ -0,0 +1,14 @@ +#!/bin/sh + +username=$1 +domain=$2 + +freeside-adduser -h /usr/local/etc/freeside/htpasswd \ + -s /usr/local/etc/freeside/conf.DBI:Pg:host=localhost\;dbname=$domain/secrets \ + -b \ + $username $password + +[ -e /usr/local/etc/freeside/dbdef.DBI:Pg:host=localhost\;dbname=$domain ] \ + || ( freeside-setup $username; \ + /home/ivan/freeside/bin/populate-msgcat $username ) + -- cgit v1.2.1 From b181fa835716ef11055281416d685ef1f9242b0d Mon Sep 17 00:00:00 2001 From: ivan Date: Sun, 25 Aug 2002 01:48:38 +0000 Subject: password --- FS/bin/freeside-addoutsourceuser | 1 + 1 file changed, 1 insertion(+) (limited to 'FS/bin') diff --git a/FS/bin/freeside-addoutsourceuser b/FS/bin/freeside-addoutsourceuser index f76f39808..5f18bdfac 100644 --- a/FS/bin/freeside-addoutsourceuser +++ b/FS/bin/freeside-addoutsourceuser @@ -2,6 +2,7 @@ username=$1 domain=$2 +password=$3 freeside-adduser -h /usr/local/etc/freeside/htpasswd \ -s /usr/local/etc/freeside/conf.DBI:Pg:host=localhost\;dbname=$domain/secrets \ -- cgit v1.2.1 From 84eacf59708f768adb4161c5d3e250663d7f53dd Mon Sep 17 00:00:00 2001 From: ivan Date: Sun, 25 Aug 2002 03:42:25 +0000 Subject: correct secrets file path --- FS/bin/freeside-addoutsourceuser | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-addoutsourceuser b/FS/bin/freeside-addoutsourceuser index 5f18bdfac..ab8734042 100644 --- a/FS/bin/freeside-addoutsourceuser +++ b/FS/bin/freeside-addoutsourceuser @@ -5,9 +5,9 @@ domain=$2 password=$3 freeside-adduser -h /usr/local/etc/freeside/htpasswd \ - -s /usr/local/etc/freeside/conf.DBI:Pg:host=localhost\;dbname=$domain/secrets \ - -b \ - $username $password + -s conf.DBI:Pg:host=localhost\;dbname=$domain/secrets \ + -b \ + $username $password [ -e /usr/local/etc/freeside/dbdef.DBI:Pg:host=localhost\;dbname=$domain ] \ || ( freeside-setup $username; \ -- cgit v1.2.1 From 47b1210b68864ad65b157170d5a21544b6dc3dde Mon Sep 17 00:00:00 2001 From: ivan Date: Sun, 25 Aug 2002 03:54:45 +0000 Subject: ? --- FS/bin/freeside-addoutsourceuser | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-addoutsourceuser b/FS/bin/freeside-addoutsourceuser index ab8734042..bbad8aa3f 100644 --- a/FS/bin/freeside-addoutsourceuser +++ b/FS/bin/freeside-addoutsourceuser @@ -7,9 +7,9 @@ password=$3 freeside-adduser -h /usr/local/etc/freeside/htpasswd \ -s conf.DBI:Pg:host=localhost\;dbname=$domain/secrets \ -b \ - $username $password + $username $password 2>/dev/null [ -e /usr/local/etc/freeside/dbdef.DBI:Pg:host=localhost\;dbname=$domain ] \ - || ( freeside-setup $username; \ - /home/ivan/freeside/bin/populate-msgcat $username ) + || ( freeside-setup $username 2>/dev/null; \ + /home/ivan/freeside/bin/populate-msgcat $username; 2>/dev/null ) -- cgit v1.2.1 From 91292eadb6254740a9b72e5dc95f575593f6a35d Mon Sep 17 00:00:00 2001 From: ivan Date: Mon, 9 Sep 2002 22:57:34 +0000 Subject: allow . in untaint_argv, for usernames --- FS/bin/freeside-cc-receipts-report | 4 ++-- FS/bin/freeside-credit-report | 4 ++-- FS/bin/freeside-receivables-report | 4 ++-- FS/bin/freeside-tax-report | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-cc-receipts-report b/FS/bin/freeside-cc-receipts-report index 06e3aba81..136851aec 100755 --- a/FS/bin/freeside-cc-receipts-report +++ b/FS/bin/freeside-cc-receipts-report @@ -206,7 +206,7 @@ if($email && $opt_m) # subroutines sub untaint_argv { foreach $_ ( $[ .. $#ARGV ) { #untaint @ARGV - $ARGV[$_] =~ /^([\w\-\/ :]*)$/ || die "Illegal argument \"$ARGV[$_]\""; + $ARGV[$_] =~ /^([\w\-\/ :\.]*)$/ || die "Illegal argument \"$ARGV[$_]\""; $ARGV[$_]=$1; } } @@ -245,7 +245,7 @@ user: From the mapsecrets file - see config.html from the base documentation =head1 VERSION -$Id: freeside-cc-receipts-report,v 1.4 2002-03-07 19:50:23 jeff Exp $ +$Id: freeside-cc-receipts-report,v 1.5 2002-09-09 22:57:34 ivan Exp $ =head1 BUGS diff --git a/FS/bin/freeside-credit-report b/FS/bin/freeside-credit-report index 7699daf4d..410dabe8f 100755 --- a/FS/bin/freeside-credit-report +++ b/FS/bin/freeside-credit-report @@ -160,7 +160,7 @@ if($email && $opt_m) # subroutines sub untaint_argv { foreach $_ ( $[ .. $#ARGV ) { #untaint @ARGV - $ARGV[$_] =~ /^([\w\-\/ :]*)$/ || die "Illegal argument \"$ARGV[$_]\""; + $ARGV[$_] =~ /^([\w\-\/ :\.]*)$/ || die "Illegal argument \"$ARGV[$_]\""; $ARGV[$_]=$1; } } @@ -199,7 +199,7 @@ user: From the mapsecrets file - see config.html from the base documentation =head1 VERSION -$Id: freeside-credit-report,v 1.4 2002-03-07 19:50:24 jeff Exp $ +$Id: freeside-credit-report,v 1.5 2002-09-09 22:57:34 ivan Exp $ =head1 BUGS diff --git a/FS/bin/freeside-receivables-report b/FS/bin/freeside-receivables-report index b5a49031e..f3ad2a1a6 100755 --- a/FS/bin/freeside-receivables-report +++ b/FS/bin/freeside-receivables-report @@ -157,7 +157,7 @@ if($email && $opt_m) sub untaint_argv { foreach $_ ( $[ .. $#ARGV ) { #untaint @ARGV - $ARGV[$_] =~ /^([\w\-\/ ]*)$/ || die "Illegal argument \"$ARGV[$_]\""; + $ARGV[$_] =~ /^([\w\-\/ \.]*)$/ || die "Illegal argument \"$ARGV[$_]\""; $ARGV[$_]=$1; } } @@ -192,7 +192,7 @@ user: From the mapsecrets file - see config.html from the base documentation =head1 VERSION -$Id: freeside-receivables-report,v 1.5 2002-03-07 19:50:24 jeff Exp $ +$Id: freeside-receivables-report,v 1.6 2002-09-09 22:57:34 ivan Exp $ =head1 BUGS diff --git a/FS/bin/freeside-tax-report b/FS/bin/freeside-tax-report index 8d5021358..240f3ad37 100755 --- a/FS/bin/freeside-tax-report +++ b/FS/bin/freeside-tax-report @@ -228,7 +228,7 @@ if($email && $opt_m) # subroutines sub untaint_argv { foreach $_ ( $[ .. $#ARGV ) { #untaint @ARGV - $ARGV[$_] =~ /^([\w\-\/ :]*)$/ || die "Illegal argument \"$ARGV[$_]\""; + $ARGV[$_] =~ /^([\w\-\/ :\.]*)$/ || die "Illegal argument \"$ARGV[$_]\""; $ARGV[$_]=$1; } } @@ -267,7 +267,7 @@ user: From the mapsecrets file - see config.html from the base documentation =head1 VERSION -$Id: freeside-tax-report,v 1.4 2002-03-07 19:50:24 jeff Exp $ +$Id: freeside-tax-report,v 1.5 2002-09-09 22:57:34 ivan Exp $ =head1 BUGS -- cgit v1.2.1 From 3548c2951a51ece84687e3bfb5e435008191a713 Mon Sep 17 00:00:00 2001 From: ivan Date: Mon, 16 Sep 2002 09:27:14 +0000 Subject: skip empty expiration dates --- FS/bin/freeside-expiration-alerter | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-expiration-alerter b/FS/bin/freeside-expiration-alerter index ee3c1fb92..5399f6d22 100755 --- a/FS/bin/freeside-expiration-alerter +++ b/FS/bin/freeside-expiration-alerter @@ -80,16 +80,18 @@ $alerter->compile() or die "can't compile template: Text::Template::ERROR"; # Now I can start looping foreach my $customer (@customers) { + my $paydate = $customer->getfield('paydate'); + next if $paydate =~ /^\s*$/; #skip empty expiration dates + my $custnum = $customer->getfield('custnum'); my $first = $customer->getfield('first'); my $last = $customer->getfield('last'); my $company = $customer->getfield('company'); my $payby = $customer->getfield('payby'); my $payinfo = $customer->getfield('payinfo'); - my $paydate = $customer->getfield('paydate'); my $daytime = $customer->getfield('daytime'); my $night = $customer->getfield('night'); - + my ($payyear,$paymonth,$payday) = split (/-/,$paydate); my $expire_time = timelocal(0,0,0,$payday,--$paymonth,$payyear); @@ -200,7 +202,7 @@ user: From the mapsecrets file - see config.html from the base documentation =head1 VERSION -$Id: freeside-expiration-alerter,v 1.3 2002-04-16 09:38:19 ivan Exp $ +$Id: freeside-expiration-alerter,v 1.4 2002-09-16 09:27:14 ivan Exp $ =head1 BUGS -- cgit v1.2.1 From c1e33a61324f4e06157c522af7882a97a021830f Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 18 Sep 2002 22:50:44 +0000 Subject: remove domain config file, closes: Bug#269 --- FS/bin/freeside-email | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-email b/FS/bin/freeside-email index c7ff41114..400dc2ac7 100755 --- a/FS/bin/freeside-email +++ b/FS/bin/freeside-email @@ -12,11 +12,9 @@ my $user = shift or die &usage; adminsuidsetup $user; my $conf = new FS::Conf; -my $domain = $conf->config('domain'); my @svc_acct = qsearch('svc_acct', {}); -my @usernames = map $_->username, @svc_acct; -my @emails = map "$_\@$domain", @usernames; +my @emails = map $_->email, @svc_acct; print join("\n", @emails), "\n"; @@ -51,7 +49,7 @@ user: From the mapsecrets file - see config.html from the base documentation =head1 VERSION -$Id: freeside-email,v 1.1 2001-05-15 07:52:34 ivan Exp $ +$Id: freeside-email,v 1.2 2002-09-18 22:50:44 ivan Exp $ =head1 BUGS -- cgit v1.2.1 From 0f5ad6c181cccbbdec6c48ea74e41d92ef5e3a26 Mon Sep 17 00:00:00 2001 From: ivan Date: Thu, 19 Sep 2002 08:43:03 +0000 Subject: package expiration --- FS/bin/freeside-daily | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-daily b/FS/bin/freeside-daily index 142b0c73a..22bf2c963 100755 --- a/FS/bin/freeside-daily +++ b/FS/bin/freeside-daily @@ -28,15 +28,23 @@ my($time)= $opt_d ? str2time($opt_d) : $^T; my($cust_main,%saw); foreach $cust_main ( @cust_main ) { - my $error; + # $^T not $time because -d is for pre-printing invoices + foreach my $cust_pkg ( + grep { $_->expire && $_->expire >= $^T } $cust_main->ncancelled_pkgs + ) { + my $error = $cust_pkg->cancel; + warn "Error cancelling expired pkg ". $cust_pkg->pkgnum. " for custnum ". + $cust_main->custnum. ": $error" + if $error; + } - $error = $cust_main->bill( 'time' => $time ); + my $error = $cust_main->bill( 'time' => $time ); warn "Error billing, custnum ". $cust_main->custnum. ": $error" if $error; $cust_main->apply_payments; $cust_main->apply_credits; - $error=$cust_main->collect( 'invoice_time' => $time ); + $error = $cust_main->collect( 'invoice_time' => $time ); warn "Error collecting, custnum". $cust_main->custnum. ": $error" if $error; } -- cgit v1.2.1 From eb0d04842631ae16247c6246cc6a1d8896169ff9 Mon Sep 17 00:00:00 2001 From: ivan Date: Fri, 20 Sep 2002 12:50:30 +0000 Subject: move from bin/fs-setup to FS/bin/freeside-setup --- FS/bin/freeside-setup | 191 +++++++++++++++++++++++++++++--------------------- 1 file changed, 111 insertions(+), 80 deletions(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-setup b/FS/bin/freeside-setup index 78a03385c..cb74e64c8 100755 --- a/FS/bin/freeside-setup +++ b/FS/bin/freeside-setup @@ -138,33 +138,6 @@ foreach $attribute (@check_attributes) { )); } -##make part_svc table (but now as object) -# -#my($part_svc)=$dbdef->table('part_svc'); -# -##because of svc_acct_pop -##foreach (grep /^svc_/, $dbdef->tables) { -##foreach (qw(svc_acct svc_acct_sm svc_charge svc_domain svc_wo)) { -#foreach (qw(svc_acct svc_domain svc_forward svc_www)) { -# my($table)=$dbdef->table($_); -# my($col); -# foreach $col ( $table->columns ) { -# next if $col =~ /^svcnum$/; -# $part_svc->addcolumn( new DBIx::DBSchema::Column ( -# $table->name. '__' . $table->column($col)->name, -# 'varchar', #$table->column($col)->type, -# 'NULL', -# $char_d, #$table->column($col)->length, -# )); -# $part_svc->addcolumn ( new DBIx::DBSchema::Column ( -# $table->name. '__'. $table->column($col)->name . "_flag", -# 'char', -# 'NULL', -# 1, -# )); -# } -#} - #create history tables (false laziness w/create-history-tables) foreach my $table ( grep { ! /^h_/ } $dbdef->tables ) { my $tableobj = $dbdef->table($table) @@ -339,7 +312,7 @@ sub tables_hash_hack { 'agent' => { 'columns' => [ - 'agentnum', 'int', '', '', + 'agentnum', 'serial', '', '', 'agent', 'varchar', '', $char_d, 'typenum', 'int', '', '', 'freq', 'int', 'NULL', '', @@ -352,7 +325,7 @@ sub tables_hash_hack { 'agent_type' => { 'columns' => [ - 'typenum', 'int', '', '', + 'typenum', 'serial', '', '', 'atype', 'varchar', '', $char_d, ], 'primary_key' => 'typenum', @@ -372,7 +345,7 @@ sub tables_hash_hack { 'cust_bill' => { 'columns' => [ - 'invnum', 'int', '', '', + 'invnum', 'serial', '', '', 'custnum', 'int', '', '', '_date', @date_type, 'charged', @money_type, @@ -386,7 +359,7 @@ sub tables_hash_hack { 'cust_bill_event' => { 'columns' => [ - 'eventnum', 'int', '', '', + 'eventnum', 'serial', '', '', 'invnum', 'int', '', '', 'eventpart', 'int', '', '', '_date', @date_type, @@ -401,7 +374,7 @@ sub tables_hash_hack { 'part_bill_event' => { 'columns' => [ - 'eventpart', 'int', '', '', + 'eventpart', 'serial', '', '', 'payby', 'char', '', 4, 'event', 'varchar', '', $char_d, 'eventcode', @perl_type, @@ -432,11 +405,11 @@ sub tables_hash_hack { 'cust_credit' => { 'columns' => [ - 'crednum', 'int', '', '', + 'crednum', 'serial', '', '', 'custnum', 'int', '', '', '_date', @date_type, 'amount', @money_type, - 'otaker', 'varchar', '', 8, + 'otaker', 'varchar', '', 32, 'reason', 'text', 'NULL', '', 'closed', 'char', 'NULL', 1, ], @@ -447,7 +420,7 @@ sub tables_hash_hack { 'cust_credit_bill' => { 'columns' => [ - 'creditbillnum', 'int', '', '', + 'creditbillnum', 'serial', '', '', 'crednum', 'int', '', '', 'invnum', 'int', '', '', '_date', @date_type, @@ -460,7 +433,7 @@ sub tables_hash_hack { 'cust_main' => { 'columns' => [ - 'custnum', 'int', '', '', + 'custnum', 'serial', '', '', 'agentnum', 'int', '', '', # 'titlenum', 'int', 'NULL', '', 'last', 'varchar', '', $char_d, @@ -498,7 +471,7 @@ sub tables_hash_hack { 'paydate', 'varchar', 'NULL', 10, 'payname', 'varchar', 'NULL', $char_d, 'tax', 'char', 'NULL', 1, - 'otaker', 'varchar', '', 8, + 'otaker', 'varchar', '', 32, 'refnum', 'int', '', '', 'referral_custnum', 'int', 'NULL', '', 'comments', 'text', 'NULL', '', @@ -511,7 +484,7 @@ sub tables_hash_hack { 'cust_main_invoice' => { 'columns' => [ - 'destnum', 'int', '', '', + 'destnum', 'serial', '', '', 'custnum', 'int', '', '', 'dest', 'varchar', '', $char_d, ], @@ -524,7 +497,7 @@ sub tables_hash_hack { #cust_main_county for validation and to provide # a tax rate. 'columns' => [ - 'taxnum', 'int', '', '', + 'taxnum', 'serial', '', '', 'state', 'varchar', 'NULL', $char_d, 'county', 'varchar', 'NULL', $char_d, 'country', 'char', '', 2, @@ -540,7 +513,7 @@ sub tables_hash_hack { 'cust_pay' => { 'columns' => [ - 'paynum', 'int', '', '', + 'paynum', 'serial', '', '', #now cust_bill_pay #'invnum', 'int', '', '', 'custnum', 'int', '', '', 'paid', @money_type, @@ -558,7 +531,7 @@ sub tables_hash_hack { 'cust_bill_pay' => { 'columns' => [ - 'billpaynum', 'int', '', '', + 'billpaynum', 'serial', '', '', 'invnum', 'int', '', '', 'paynum', 'int', '', '', 'amount', @money_type, @@ -572,7 +545,7 @@ sub tables_hash_hack { 'cust_pay_batch' => { #what's this used for again? list of customers #in current CARD batch? (necessarily CARD?) 'columns' => [ - 'paybatchnum', 'int', '', '', + 'paybatchnum', 'serial', '', '', 'invnum', 'int', '', '', 'custnum', 'int', '', '', 'last', 'varchar', '', $char_d, @@ -597,10 +570,10 @@ sub tables_hash_hack { 'cust_pkg' => { 'columns' => [ - 'pkgnum', 'int', '', '', + 'pkgnum', 'serial', '', '', 'custnum', 'int', '', '', 'pkgpart', 'int', '', '', - 'otaker', 'varchar', '', 8, + 'otaker', 'varchar', '', 32, 'setup', @date_type, 'bill', @date_type, 'susp', @date_type, @@ -615,12 +588,12 @@ sub tables_hash_hack { 'cust_refund' => { 'columns' => [ - 'refundnum', 'int', '', '', + 'refundnum', 'serial', '', '', #now cust_credit_refund #'crednum', 'int', '', '', 'custnum', 'int', '', '', '_date', @date_type, 'refund', @money_type, - 'otaker', 'varchar', '', 8, + 'otaker', 'varchar', '', 32, 'reason', 'varchar', '', $char_d, 'payby', 'char', '', 4, # CARD/BILL/COMP, should be index # into payment type table. @@ -635,7 +608,7 @@ sub tables_hash_hack { 'cust_credit_refund' => { 'columns' => [ - 'creditrefundnum', 'int', '', '', + 'creditrefundnum', 'serial', '', '', 'crednum', 'int', '', '', 'refundnum', 'int', '', '', 'amount', @money_type, @@ -649,7 +622,7 @@ sub tables_hash_hack { 'cust_svc' => { 'columns' => [ - 'svcnum', 'int', '', '', + 'svcnum', 'serial', '', '', 'pkgnum', 'int', 'NULL', '', 'svcpart', 'int', '', '', ], @@ -660,7 +633,7 @@ sub tables_hash_hack { 'part_pkg' => { 'columns' => [ - 'pkgpart', 'int', '', '', + 'pkgpart', 'serial', '', '', 'pkg', 'varchar', '', $char_d, 'comment', 'varchar', '', $char_d, 'setup', @perl_type, @@ -701,7 +674,7 @@ sub tables_hash_hack { 'part_referral' => { 'columns' => [ - 'refnum', 'int', '', '', + 'refnum', 'serial', '', '', 'referral', 'varchar', '', $char_d, ], 'primary_key' => 'refnum', @@ -711,7 +684,7 @@ sub tables_hash_hack { 'part_svc' => { 'columns' => [ - 'svcpart', 'int', '', '', + 'svcpart', 'serial', '', '', 'svc', 'varchar', '', $char_d, 'svcdb', 'varchar', '', $char_d, 'disabled', 'char', 'NULL', 1, @@ -723,7 +696,7 @@ sub tables_hash_hack { 'part_svc_column' => { 'columns' => [ - 'columnnum', 'int', '', '', + 'columnnum', 'serial', '', '', 'svcpart', 'int', '', '', 'columnname', 'varchar', '', 64, 'columnvalue', 'varchar', 'NULL', $char_d, @@ -737,7 +710,7 @@ sub tables_hash_hack { #(this should be renamed to part_pop) 'svc_acct_pop' => { 'columns' => [ - 'popnum', 'int', '', '', + 'popnum', 'serial', '', '', 'city', 'varchar', '', $char_d, 'state', 'varchar', '', $char_d, 'ac', 'char', '', 3, @@ -751,7 +724,7 @@ sub tables_hash_hack { 'part_pop_local' => { 'columns' => [ - 'localnum', 'int', '', '', + 'localnum', 'serial', '', '', 'popnum', 'int', '', '', 'city', 'varchar', 'NULL', $char_d, 'state', 'char', 'NULL', 2, @@ -786,18 +759,6 @@ sub tables_hash_hack { 'index' => [ ['username'], ['domsvc'] ], }, -# 'svc_acct_sm' => { -# 'columns' => [ -# 'svcnum', 'int', '', '', -# 'domsvc', 'int', '', '', -# 'domuid', 'int', '', '', -# 'domuser', 'varchar', '', $char_d, -# ], -# 'primary_key' => 'svcnum', -# 'unique' => [ [] ], -# 'index' => [ ['domsvc'], ['domuid'] ], -# }, - #'svc_charge' => { # 'columns' => [ # 'svcnum', 'int', '', '', @@ -821,7 +782,7 @@ sub tables_hash_hack { 'domain_record' => { 'columns' => [ - 'recnum', 'int', '', '', + 'recnum', 'serial', '', '', 'svcnum', 'int', '', '', 'reczone', 'varchar', '', $char_d, 'recaf', 'char', '', 2, @@ -871,7 +832,7 @@ sub tables_hash_hack { 'prepay_credit' => { 'columns' => [ - 'prepaynum', 'int', '', '', + 'prepaynum', 'serial', '', '', 'identifier', 'varchar', '', $char_d, 'amount', @money_type, 'seconds', 'int', 'NULL', '', @@ -883,7 +844,7 @@ sub tables_hash_hack { 'port' => { 'columns' => [ - 'portnum', 'int', '', '', + 'portnum', 'serial', '', '', 'ip', 'varchar', 'NULL', 15, 'nasport', 'int', 'NULL', '', 'nasnum', 'int', '', '', @@ -895,7 +856,7 @@ sub tables_hash_hack { 'nas' => { 'columns' => [ - 'nasnum', 'int', '', '', + 'nasnum', 'serial', '', '', 'nas', 'varchar', '', $char_d, 'nasip', 'varchar', '', 15, 'nasfqdn', 'varchar', '', $char_d, @@ -908,7 +869,7 @@ sub tables_hash_hack { 'session' => { 'columns' => [ - 'sessionnum', 'int', '', '', + 'sessionnum', 'serial', '', '', 'portnum', 'int', '', '', 'svcnum', 'int', '', '', 'login', @date_type, @@ -921,7 +882,7 @@ sub tables_hash_hack { 'queue' => { 'columns' => [ - 'jobnum', 'int', '', '', + 'jobnum', 'serial', '', '', 'job', 'text', '', '', '_date', 'int', '', '', 'status', 'varchar', '', $char_d, @@ -935,7 +896,7 @@ sub tables_hash_hack { 'queue_arg' => { 'columns' => [ - 'argnum', 'int', '', '', + 'argnum', 'serial', '', '', 'jobnum', 'int', '', '', 'arg', 'text', 'NULL', '', ], @@ -946,7 +907,7 @@ sub tables_hash_hack { 'queue_depend' => { 'columns' => [ - 'dependnum', 'int', '', '', + 'dependnum', 'serial', '', '', 'jobnum', 'int', '', '', 'depend_jobnum', 'int', '', '', ], @@ -957,7 +918,7 @@ sub tables_hash_hack { 'export_svc' => { 'columns' => [ - 'exportsvcnum' => 'int', '', '', + 'exportsvcnum' => 'serial', '', '', 'exportnum' => 'int', '', '', 'svcpart' => 'int', '', '', ], @@ -968,7 +929,7 @@ sub tables_hash_hack { 'part_export' => { 'columns' => [ - 'exportnum', 'int', '', '', + 'exportnum', 'serial', '', '', #'svcpart', 'int', '', '', 'machine', 'varchar', '', $char_d, 'exporttype', 'varchar', '', $char_d, @@ -981,7 +942,7 @@ sub tables_hash_hack { 'part_export_option' => { 'columns' => [ - 'optionnum', 'int', '', '', + 'optionnum', 'serial', '', '', 'exportnum', 'int', '', '', 'optionname', 'varchar', '', $char_d, 'optionvalue', 'text', 'NULL', '', @@ -993,7 +954,7 @@ sub tables_hash_hack { 'radius_usergroup' => { 'columns' => [ - 'usergroupnum', 'int', '', '', + 'usergroupnum', 'serial', '', '', 'svcnum', 'int', '', '', 'groupname', 'varchar', '', $char_d, ], @@ -1004,7 +965,7 @@ sub tables_hash_hack { 'msgcat' => { 'columns' => [ - 'msgnum', 'int', '', '', + 'msgnum', 'serial', '', '', 'msgcode', 'varchar', '', $char_d, 'locale', 'varchar', '', 16, 'msg', 'text', '', '', @@ -1016,7 +977,7 @@ sub tables_hash_hack { 'cust_tax_exempt' => { 'columns' => [ - 'exemptnum', 'int', '', '', + 'exemptnum', 'serial', '', '', 'custnum', 'int', '', '', 'taxnum', 'int', '', '', 'year', 'int', '', '', @@ -1028,7 +989,77 @@ sub tables_hash_hack { 'index' => [], }, + 'ac_type' => { + 'columns' => [ + 'actypenum', 'serial', '', '', + 'actypename', 'varchar', '', $char_d, + ], + 'primary_key' => 'actypenum', + 'unique' => [], + 'index' => [], + }, + + 'ac' => { + 'columns' => [ + 'acnum', 'serial', '', '', + 'actypenum', 'int', '', '', + 'acname', 'varchar', '', $char_d, + ], + 'primary_key' => 'acnum', + 'unique' => [], + 'index' => [ [ 'actypenum' ] ], + }, + + 'part_ac_field' => { + 'columns' => [ + 'acfieldpart', 'serial', '', '', + 'actypenum', 'int', '', '', + 'name', 'varchar', '', $char_d, + 'ut_type', 'varchar', '', $char_d, + ], + 'primary_key' => 'acfieldpart', + 'unique' => [], + 'index' => [ [ 'actypenum' ] ], + }, + + 'ac_field' => { + 'columns' => [ + 'acfieldpart', 'int', '', '', + 'acnum', 'int', '', '', + 'value', 'text', '', '', + ], + 'primary_key' => '', + 'unique' => [ [ 'acfieldpart', 'acnum' ] ], + 'index' => [ [ 'acnum' ] ], + }, + + 'ac_block' => { + 'columns' => [ + 'acnum', 'int', '', '', + 'ip_gateway', 'varchar', '', 15, + 'ip_netmask', 'int', '', '', + ], + 'primary_key' => '', + 'unique' => [], + 'index' => [ [ 'acnum' ] ], + }, + 'svc_broadband' => { + 'columns' => [ + 'svcnum', 'int', '', '', + 'actypenum', 'int', '', '', + 'speed_up', 'int', '', '', + 'speed_down', 'int', '', '', + 'acnum', 'int', '', '', + 'ip_addr', 'varchar', '', 15, + 'ip_netmask', 'int', '', '', + 'mac_addr', 'char', '', 17, + 'location', 'varchar', '', $char_d, + ], + 'primary_key' => 'svcnum', + 'unique' => [], + 'index' => [ [ 'actypenum' ] ], + }, ); -- cgit v1.2.1 From 70a4b5227943108ce91c68e1c4e7509a9a6c33f9 Mon Sep 17 00:00:00 2001 From: ivan Date: Fri, 20 Sep 2002 15:47:58 +0000 Subject: add freeside-deluser, freeside-deloutsource and freeside-deloutsourceuser --- FS/bin/freeside-addoutsourceuser | 2 +- FS/bin/freeside-deloutsource | 11 +++++++ FS/bin/freeside-deloutsourceuser | 6 ++++ FS/bin/freeside-deluser | 64 ++++++++++++++++++++++++++++++++++++++++ FS/bin/freeside-setup | 2 +- 5 files changed, 83 insertions(+), 2 deletions(-) create mode 100644 FS/bin/freeside-deloutsource create mode 100644 FS/bin/freeside-deloutsourceuser create mode 100644 FS/bin/freeside-deluser (limited to 'FS/bin') diff --git a/FS/bin/freeside-addoutsourceuser b/FS/bin/freeside-addoutsourceuser index bbad8aa3f..180cd9399 100644 --- a/FS/bin/freeside-addoutsourceuser +++ b/FS/bin/freeside-addoutsourceuser @@ -11,5 +11,5 @@ freeside-adduser -h /usr/local/etc/freeside/htpasswd \ [ -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; 2>/dev/null ) + /home/ivan/freeside/bin/populate-msgcat $username ) diff --git a/FS/bin/freeside-deloutsource b/FS/bin/freeside-deloutsource new file mode 100644 index 000000000..561853539 --- /dev/null +++ b/FS/bin/freeside-deloutsource @@ -0,0 +1,11 @@ +#!/bin/sh + +domain=$1 + +dropdb $domain && \ +rm -rf /usr/local/etc/freeside/conf.DBI:Pg:host=localhost\;dbname=$domain && \ +rm -rf /usr/local/etc/freeside/counters.DBI:Pg:host=localhost\;dbname=$domain && \ +rm -rf /usr/local/etc/freeside/cache.DBI:Pg:host=localhost\;dbname=$domain && \ +rm -rf /usr/local/etc/freeside/export.DBI:Pg:host=localhost\;dbname=$domain && \ +rm /usr/local/etc/freeside/dbdef.DBI:Pg:host=localhost\;dbname=$domain + diff --git a/FS/bin/freeside-deloutsourceuser b/FS/bin/freeside-deloutsourceuser new file mode 100644 index 000000000..96871e50c --- /dev/null +++ b/FS/bin/freeside-deloutsourceuser @@ -0,0 +1,6 @@ +#!/bin/sh + +username=$1 + +freeside-deluser -h /usr/local/etc/freeside/htpasswd $username 2>/dev/null + diff --git a/FS/bin/freeside-deluser b/FS/bin/freeside-deluser new file mode 100644 index 000000000..57d6ce165 --- /dev/null +++ b/FS/bin/freeside-deluser @@ -0,0 +1,64 @@ +#!/usr/bin/perl -w + +use strict; +use vars qw($opt_h); +use Fcntl qw(:flock); +use Getopt::Std; + +my $FREESIDE_CONF = "/usr/local/etc/freeside"; + +getopts("h:"); +my $user = shift or die &usage; + +if ( $opt_h ) { + open(HTPASSWD,"<$opt_h") + and flock(HTPASSWD,LOCK_EX) + or die "can't open $opt_h: $!"; + open(HTPASSWD_TMP,">$opt_h.tmp") or die "can't open $opt_h.tmp: $!"; + while () { + print HTPASSWD_TMP $_ unless /^$user:/; + } + close HTPASSWD_TMP; + rename "$opt_h.tmp", "$opt_h" or die $!; + flock(HTPASSWD,LOCK_UN); + close HTPASSWD; +} + +open(MAPSECRETS,"<$FREESIDE_CONF/mapsecrets") + and flock(MAPSECRETS,LOCK_EX) + or die "can't open $FREESIDE_CONF/mapsecrets: $!"; +open(MAPSECRETS_TMP,">>$FREESIDE_CONF/mapsecrets.tmp") + or die "can't open $FREESIDE_CONF/mapsecrets.tmp: $!"; +while () { + print MAPSECRETS_TMP $_ unless /^$user\s/; +} +close MAPSECRETS_TMP; +rename "$FREESIDE_CONF/mapsecrets.tmp", "$FREESIDE_CONF/mapsecrets" or die $!; +flock(MAPSECRETS,LOCK_UN); +close MAPSECRETS; + +sub usage { + die "Usage:\n\n freeside-deluser [ -h htpasswd_file ] username" +} + +=head1 NAME + +freeside-deluser - Command line interface to add (freeside) users. + +=head1 SYNOPSIS + + freeside-deluser [ -h htpasswd_file ] username + +=head1 DESCRIPTION + +Adds a user to the Freeside billing system. This is for adding users (internal +sales/tech folks) to the web interface, not for adding customer accounts. + + -h: Also delete from the given htpasswd filename + +=head1 SEE ALSO + +L, L(1), base Freeside documentation + +=cut + diff --git a/FS/bin/freeside-setup b/FS/bin/freeside-setup index cb74e64c8..e8bb7ec62 100755 --- a/FS/bin/freeside-setup +++ b/FS/bin/freeside-setup @@ -7,7 +7,7 @@ use strict; use vars qw($opt_s); use Getopt::Std; use DBI; -use DBIx::DBSchema 0.20; +use DBIx::DBSchema 0.21; use DBIx::DBSchema::Table; use DBIx::DBSchema::Column; use DBIx::DBSchema::ColGroup::Unique; -- cgit v1.2.1 From 8965012fa53fd05d851d2f5abed4e056ab758797 Mon Sep 17 00:00:00 2001 From: ivan Date: Sat, 21 Sep 2002 11:17:39 +0000 Subject: all taxes now have names. closes: Bug#15 --- FS/bin/freeside-setup | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-setup b/FS/bin/freeside-setup index e8bb7ec62..f6a543fc8 100755 --- a/FS/bin/freeside-setup +++ b/FS/bin/freeside-setup @@ -189,7 +189,23 @@ foreach my $table ( grep { ! /^h_/ } $dbdef->tables ) { 'default' => '', 'local' => '', } ), - map { $tableobj->column($_) } $tableobj->columns + map { + my $column = $tableobj->column($_); + + #clone so as to not disturb the original + $column = DBIx::DBSchema::Column->new( { + map { $_ => $column->$_() } + qw( name type null length default local ) + } ); + + $column->type('int') + if $column->type eq 'serial'; + #$column->default('') + # if $column->default =~ /^nextval\(/i; + #( my $local = $column->local ) =~ s/AUTO_INCREMENT//i; + #$column->local($local); + $column; + } $tableobj->columns ], } ); $dbdef->addtable($h_tableobj); @@ -397,9 +413,10 @@ sub tables_hash_hack { 'recur', @money_type, 'sdate', @date_type, 'edate', @date_type, + 'itemdesc', 'varchar', 'NULL', $char_d, ], 'primary_key' => '', - 'unique' => [ ['pkgnum', 'invnum'] ], + 'unique' => [], 'index' => [ ['invnum'] ], }, @@ -504,6 +521,7 @@ sub tables_hash_hack { 'taxclass', 'varchar', 'NULL', $char_d, 'exempt_amount', @money_type, 'tax', 'real', '', '', #tax % + 'taxname', 'varchar', 'NULL', $char_d, ], 'primary_key' => 'taxnum', 'unique' => [], -- cgit v1.2.1 From e88050711de04bdd33f298d84a35c943bc6dec24 Mon Sep 17 00:00:00 2001 From: ivan Date: Fri, 27 Sep 2002 05:36:29 +0000 Subject: lock mapsecrets file --- FS/bin/freeside-adduser | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-adduser b/FS/bin/freeside-adduser index 424123226..c3ee05b9b 100644 --- a/FS/bin/freeside-adduser +++ b/FS/bin/freeside-adduser @@ -1,9 +1,10 @@ #!/usr/bin/perl -w # -# $Id: freeside-adduser,v 1.7 2002-08-25 01:16:30 ivan Exp $ +# $Id: freeside-adduser,v 1.8 2002-09-27 05:36:29 ivan Exp $ use strict; use vars qw($opt_h $opt_b $opt_c $opt_s); +use Fcntl qw(:flock); use Getopt::Std; my $FREESIDE_CONF = "/usr/local/etc/freeside"; @@ -24,7 +25,8 @@ if ( $opt_h ) { my $secretfile = $opt_s || 'secrets'; open(MAPSECRETS,">>$FREESIDE_CONF/mapsecrets") - or die "can't open $FREESIDE_CONF/mapsecrets: $!"; + and flock(MAPSECRETS,LOCK_EX) + or die "can't open $FREESIDE_CONF/mapsecrets: $!"; print MAPSECRETS "$user $secretfile\n"; close MAPSECRETS or die "can't close $FREESIDE_CONF/mapsecrets: $!"; -- cgit v1.2.1 From 2f742fce69ed1d168f95478f36a5e70b381d64a9 Mon Sep 17 00:00:00 2001 From: ivan Date: Fri, 4 Oct 2002 12:30:19 +0000 Subject: adding --- FS/bin/freeside-count-active-customers | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100755 FS/bin/freeside-count-active-customers (limited to 'FS/bin') diff --git a/FS/bin/freeside-count-active-customers b/FS/bin/freeside-count-active-customers new file mode 100755 index 000000000..759085a73 --- /dev/null +++ b/FS/bin/freeside-count-active-customers @@ -0,0 +1,17 @@ +#!/bin/sh + +domain=$1 + +echo "\t +select count(*) from cust_main where + 0 < ( SELECT COUNT(*) FROM cust_pkg + WHERE cust_pkg.custnum = cust_main.custnum + AND ( cust_pkg.cancel IS NULL + OR cust_pkg.cancel = 0 + ) + ) + OR 0 = ( SELECT COUNT(*) FROM cust_pkg + WHERE cust_pkg.custnum = cust_main.custnum + ); +" | psql -U freeside -q $domain | head -1 + -- cgit v1.2.1 From 54a27b35957baddb725e2b7544d9f134989bfd99 Mon Sep 17 00:00:00 2001 From: ivan Date: Fri, 4 Oct 2002 12:39:29 +0000 Subject: turn on AutoCommit when vacuuming --- FS/bin/freeside-daily | 1 + 1 file changed, 1 insertion(+) (limited to 'FS/bin') diff --git a/FS/bin/freeside-daily b/FS/bin/freeside-daily index 22bf2c963..52028b773 100755 --- a/FS/bin/freeside-daily +++ b/FS/bin/freeside-daily @@ -50,6 +50,7 @@ foreach $cust_main ( @cust_main ) { } if ( driver_name eq 'Pg' ) { + dbh->{AutoCommit} = 1; #so we can vacuum foreach my $statement ( 'vacuum', 'vacuum analyze' ) { my $sth = dbh->prepare($statement) or die dbh->errstr; $sth->execute or die $sth->errstr; -- cgit v1.2.1 From c4d2226e0cc4bdd6d9f689b061b5f4f5b9609b0b Mon Sep 17 00:00:00 2001 From: ivan Date: Fri, 4 Oct 2002 12:57:06 +0000 Subject: working on the road: - easier "change package" link for changing one package to another - sqlradius export now compatible with Pg - indices on phone numbers - install instructions specify Pg 7.1 (at least until ILIKE thing is changed) - searching on phone number fragments --- FS/bin/freeside-setup | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-setup b/FS/bin/freeside-setup index f6a543fc8..d61e8b0bf 100755 --- a/FS/bin/freeside-setup +++ b/FS/bin/freeside-setup @@ -111,8 +111,9 @@ my($dbdef) = new DBIx::DBSchema ( map { my $cust_main = $dbdef->table('cust_main'); unless ($ship) { #remove ship_ from cust_main $cust_main->delcolumn($_) foreach ( grep /^ship_/, $cust_main->columns ); -} else { #add indices on ship_last and ship_company - push @{$cust_main->index->lol_ref}, ( ['ship_last'], ['ship_company'] ) +} else { #add indices + push @{$cust_main->index->lol_ref}, + map { [ "ship_$_" ] } qw( last company daytime night fax ); } #add radius attributes to svc_acct @@ -496,7 +497,9 @@ sub tables_hash_hack { 'primary_key' => 'custnum', 'unique' => [], #'index' => [ ['last'], ['company'] ], - 'index' => [ ['last'], [ 'company' ], [ 'referral_custnum' ] ], + 'index' => [ ['last'], [ 'company' ], [ 'referral_custnum' ], + [ 'daytime' ], [ 'night' ], [ 'fax' ], + ], }, 'cust_main_invoice' => { -- cgit v1.2.1 From 656b802d26a8eb0dfd6fd71dbcdebfab156041e9 Mon Sep 17 00:00:00 2001 From: ivan Date: Mon, 7 Oct 2002 08:47:10 +0000 Subject: cancel when it is *after* expiration date, not when it is *before* --- FS/bin/freeside-daily | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-daily b/FS/bin/freeside-daily index 52028b773..17ee798ff 100755 --- a/FS/bin/freeside-daily +++ b/FS/bin/freeside-daily @@ -30,7 +30,7 @@ foreach $cust_main ( @cust_main ) { # $^T not $time because -d is for pre-printing invoices foreach my $cust_pkg ( - grep { $_->expire && $_->expire >= $^T } $cust_main->ncancelled_pkgs + grep { $_->expire && $_->expire <= $^T } $cust_main->ncancelled_pkgs ) { my $error = $cust_pkg->cancel; warn "Error cancelling expired pkg ". $cust_pkg->pkgnum. " for custnum ". -- cgit v1.2.1 From 94fb4aafeae9abf099a8a4ee87b72de86c812ce0 Mon Sep 17 00:00:00 2001 From: ivan Date: Fri, 18 Oct 2002 10:28:46 +0000 Subject: adding --- FS/bin/freeside-radgroup | 76 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 FS/bin/freeside-radgroup (limited to 'FS/bin') diff --git a/FS/bin/freeside-radgroup b/FS/bin/freeside-radgroup new file mode 100644 index 000000000..e1a819788 --- /dev/null +++ b/FS/bin/freeside-radgroup @@ -0,0 +1,76 @@ +#!/usr/bin/perl -w + +use strict; +use FS::UID qw(adminsuidsetup); +use FS::Record qw(qsearch); +use FS::cust_svc; +use FS::svc_acct; + +&untaint_argv; #what it sounds like (eww) + +my($user, $action, $groupname, $svcpart) = @ARGV; + +adminsuidsetup $user; + +my @svc_acct = map { $_->svc_x } qsearch('cust_svc', { svcpart => $svcpart } ); + +if ( lc($action) eq 'add' ) { + foreach my $svc_acct ( @svc_acct ) { + my @groups = $svc_acct->radius_groups; + next if grep { $_ eq $groupname } @groups; + push @groups, $groupname; + my %hash = $svc_acct->hash; + $hash{radius_groups} = \@groups; + my $new = new FS::svc_acct \%hash; + my $error = $new->replace($svc_acct); + die $error if $error; + } +} else { + die &usage; +} + +# subroutines + +sub untaint_argv { + foreach $_ ( $[ .. $#ARGV ) { #untaint @ARGV + $ARGV[$_] =~ /^(.*)$/ || die "Illegal arguement \"$ARGV[$_]\""; + $ARGV[$_]=$1; + } +} + +sub usage { + die "Usage:\n\n freeside-radgroup user action groupname svcpart\n"; +} + +=head1 NAME + +freeside-radgroup - Command line utility to manipulate radius groups + +=head1 SYNOPSIS + + freeside-addgroup user action groupname svcpart + +=head1 DESCRIPTION + + B is a freeside user as added with freeside-adduser. + + B is the action to take. Available actions are: I + + B is the group to add (or remove, etc.) + + B specifies which accounts will be updated. + +=head1 EXAMPLES + +freeside-radgroup freesideuser add groupname 3 + +Adds I to all accounts with service definition 3. + +=head1 BUGS + +=head1 SEE ALSO + +L, L, L + +=cut + -- cgit v1.2.1 From 9b1a8ec900ec1f5cd7d1f622f49066510c8f547c Mon Sep 17 00:00:00 2001 From: ivan Date: Fri, 18 Oct 2002 13:28:03 +0000 Subject: argh --- FS/bin/freeside-radgroup | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-radgroup b/FS/bin/freeside-radgroup index e1a819788..ed85626d2 100644 --- a/FS/bin/freeside-radgroup +++ b/FS/bin/freeside-radgroup @@ -20,7 +20,7 @@ if ( lc($action) eq 'add' ) { next if grep { $_ eq $groupname } @groups; push @groups, $groupname; my %hash = $svc_acct->hash; - $hash{radius_groups} = \@groups; + $hash{usergroup} = \@groups; my $new = new FS::svc_acct \%hash; my $error = $new->replace($svc_acct); die $error if $error; -- cgit v1.2.1 From 1583472a6afefb1ad33e05656fd206674f37d9df Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 23 Oct 2002 17:07:59 +0000 Subject: database dump & scp support --- FS/bin/freeside-daily | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-daily b/FS/bin/freeside-daily index 17ee798ff..1db786120 100755 --- a/FS/bin/freeside-daily +++ b/FS/bin/freeside-daily @@ -4,8 +4,9 @@ use strict; use Fcntl qw(:flock); use Date::Parse; use Getopt::Std; -use FS::UID qw(adminsuidsetup driver_name dbh); +use FS::UID qw(adminsuidsetup driver_name dbh datasrc); use FS::Record qw(qsearch qsearchs); +use FS::Conf; use FS::cust_main; &untaint_argv; #what it sounds like (eww) @@ -57,6 +58,22 @@ if ( driver_name eq 'Pg' ) { } } +#local hack +my $conf = new FS::Conf; +my $dest = $conf->config('dump-scpdest'); +if ( $dest ) { + datasrc =~ /dbname=([\w\.]+)$/ or die "unparsable datasrc ". datasrc; + my $database = $1; + eval "use Net::SCP qw(scp);"; + if ( driver_name eq 'Pg' ) { + system("pg_dump $database >/var/tmp/$database.sql") + } else { + die "database dumps not yet supported for ". driver_name; + } + scp("/var/tmp/$database.sql", $dest); + unlink "/var/tmp/$database.sql" or die $!; +} + # subroutines sub untaint_argv { -- cgit v1.2.1 From 749cce349c6801e6d75834065197c3aceddda599 Mon Sep 17 00:00:00 2001 From: ivan Date: Mon, 28 Oct 2002 13:22:45 +0000 Subject: signal-less queued child handling (closes: Bug#477) --- FS/bin/freeside-queued | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-queued b/FS/bin/freeside-queued index 311fe62f9..6ea27c05f 100644 --- a/FS/bin/freeside-queued +++ b/FS/bin/freeside-queued @@ -1,10 +1,10 @@ #!/usr/bin/perl -w use strict; -use vars qw( $log_file $sigterm $sigint $kids $max_kids ); +use vars qw( $log_file $sigterm $sigint $kids $max_kids %kids ); use subs qw( _die _logmsg ); use Fcntl qw(:flock); -use POSIX qw(setsid); +use POSIX qw(:sys_wait_h setsid); use Date::Format; use IO::File; use FS::UID qw(adminsuidsetup forksuidsetup driver_name dbh); @@ -28,8 +28,8 @@ my $pid_file = "/var/run/freeside-queued.pid"; &daemonize1; -sub REAPER { my $pid = wait; $SIG{CHLD} = \&REAPER; $kids--; } -$SIG{CHLD} = \&REAPER; +#sub REAPER { my $pid = wait; $SIG{CHLD} = \&REAPER; $kids--; } +#$SIG{CHLD} = \&REAPER; $sigterm = 0; $sigint = 0; @@ -65,9 +65,11 @@ warn "freeside-queued starting\n"; my $warnkids=0; while (1) { + &reap_kids; #prevent runaway forking if ( $kids >= $max_kids ) { warn "WARNING: maximum $kids children reached\n" unless $warnkids++; + &reap_kids; sleep 1; #waiting for signals is cheap next; } @@ -131,6 +133,7 @@ while (1) { if ( $pid ) { $kids++; + $kids{$pid} = 1; } else { #kid time #get new db handle @@ -230,6 +233,16 @@ sub daemonize2 { open STDERR, '>&STDOUT' or die "Can't dup stdout: $!"; } +sub reap_kids { + foreach my $pid ( keys %kids ) { + my $kid = waitpid($pid, WNOHANG); + if ( $kid > 0 ) { + $kids--; + delete $kids{$kid}; + } + } +} + =head1 NAME freeside-queued - Job queue daemon -- cgit v1.2.1 From fc3b6024fcf0bf0394e6239639cbe31786b0cad8 Mon Sep 17 00:00:00 2001 From: ivan Date: Tue, 5 Nov 2002 20:29:57 +0000 Subject: lost? --- FS/bin/freeside-sqlradius-radacctd | 180 +++++++++++++++++++++++++++++++++++++ 1 file changed, 180 insertions(+) create mode 100644 FS/bin/freeside-sqlradius-radacctd (limited to 'FS/bin') diff --git a/FS/bin/freeside-sqlradius-radacctd b/FS/bin/freeside-sqlradius-radacctd new file mode 100644 index 000000000..4e8d57c51 --- /dev/null +++ b/FS/bin/freeside-sqlradius-radacctd @@ -0,0 +1,180 @@ +#!/usr/bin/perl -Tw + +use strict; +use vars qw( $log_file $sigterm $sigint ); +use subs qw( _die _logmsg ); +use Fcntl qw(:flock); +use POSIX qw(setsid); +use Date::Format; +use IO::File; +use FS::UID qw(adminsuidsetup); +#use FS::Record qw(qsearch qsearchs); +#use FS::part_export; +#use FS::svc_acct; +#use FS::cust_svc; + +#lots of false laziness w/freeside-queued + +my $user = shift or die &usage; + +#my $pid_file = "/var/run/freeside-sqlradius-radacctd.$user.pid"; +my $pid_file = "/var/run/freeside-sqlradius-radacctd.pid"; + +&daemonize1; + +#sub REAPER { my $pid = wait; $SIG{CHLD} = \&REAPER; $kids--; } +#$SIG{CHLD} = \&REAPER; + +$sigterm = 0; +$sigint = 0; +$SIG{INT} = sub { warn "SIGINT received; shutting down\n"; $sigint++; }; +$SIG{TERM} = sub { warn "SIGTERM received; shutting down\n"; $sigterm++; }; + +my $freeside_gid = scalar(getgrnam('freeside')) + or die "can't setgid to freeside group\n"; +$) = $freeside_gid; +$( = $freeside_gid; +#if freebsd can't setuid(), presumably it can't setgid() either. grr fleabsd +($(,$)) = ($),$(); +$) = $freeside_gid; + +$> = $FS::UID::freeside_uid; +$< = $FS::UID::freeside_uid; +#freebsd is sofa king broken, won't setuid() +($<,$>) = ($>,$<); +$> = $FS::UID::freeside_uid; + +#$ENV{HOME} = (getpwuid($>))[7]; #for ssh +adminsuidsetup $user; + +$log_file= "/usr/local/etc/freeside/sqlradius-radacctd-log.". $FS::UID::datasrc; + +&daemonize2; + +$SIG{__DIE__} = \&_die; +$SIG{__WARN__} = \&_logmsg; + +warn "freeside-sqlradius-radacctd starting\n"; + +#eslaf + +#my $machine = shift or die &usage; #would need to be up higher for real +my @exports = qsearch('part_export', { 'exporttype' => 'sqlradius' } ); + +while (1) { + + my %seen = (); + foreach my $export ( @exports ) { + next if $seen{$export->option('datasrc')}++; + my $dbh = DBI->connect( + map { $export->option($_) } qw( datasrc username password ) + ) or do { + warn "can't connect to ". $export->option('datasrc'). ": ". $DBI::errstr; + next; + } + + # find old radacct position + #$lastid = 0; + + # get new radacct records + my $sth = $dbh->prepare('SELECT * FROM radacct WHERE radacctid > ?') or do { + warn "can't select in radacct table from ". $export->option('datasrc'). + ": ". $dbh->errstr; + next; + }; + + while ( my $radacct = $sth->fetchrow_arrayref({}) ) { + + my $session = new FS::session { + portnum => + svcnum => + login => + #logout => + }; + + } + + # look for updated radacct records & replace them + + } + + sleep 5; + +} + +#more false laziness w/freeside-queued + +sub usage { + die "Usage:\n\n freeside-sqlradius-radacctd user\n"; +} + +sub _die { + my $msg = shift; + unlink $pid_file if -e $pid_file; + _logmsg($msg); +} + +sub _logmsg { + chomp( my $msg = shift ); + my $log = new IO::File ">>$log_file"; + flock($log, LOCK_EX); + seek($log, 0, 2); + print $log "[". time2str("%a %b %e %T %Y",time). "] [$$] $msg\n"; + flock($log, LOCK_UN); + close $log; +} + +sub daemonize1 { + + chdir "/" or die "Can't chdir to /: $!"; + open STDIN, '/dev/null' or die "Can't read /dev/null: $!"; + defined(my $pid = fork) or die "Can't fork: $!"; + if ( $pid ) { + print "freeside-sqlradius-radacctd started with pid $pid\n"; + #logging to $log_file\n"; + exit unless $pid_file; + my $pidfh = new IO::File ">$pid_file" or exit; + print $pidfh "$pid\n"; + exit; + } + #open STDOUT, '>/dev/null' + # or die "Can't write to /dev/null: $!"; + #setsid or die "Can't start a new session: $!"; + #open STDERR, '>&STDOUT' or die "Can't dup stdout: $!"; + +} + +sub daemonize2 { + open STDOUT, '>/dev/null' + or die "Can't write to /dev/null: $!"; + setsid or die "Can't start a new session: $!"; + open STDERR, '>&STDOUT' or die "Can't dup stdout: $!"; +} + + +#eslaf + +=head1 NAME + +freeside-sqlradius-radacctd - Real-time radacct import daemon + +=head1 SYNOPSIS + + freeside-sqlradius-radacctd username + +=head1 DESCRIPTION + +Imports records from an SQL radacct table in real-time into the session +monitor. + +This enables per-minute or per-hour charges as well as the +"View active NAS ports" function. + +B is a username added by freeside-adduser. + +=head1 SEE ALSO + +session.html from the base documentation. + +=cut + -- cgit v1.2.1 From 55bfcaa26d8cc7729a8fbaa3a5325e4372588e8b Mon Sep 17 00:00:00 2001 From: ivan Date: Tue, 19 Nov 2002 20:36:43 +0000 Subject: increase length of reczone and recdata fields in domain_record --- FS/bin/freeside-setup | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-setup b/FS/bin/freeside-setup index d61e8b0bf..587f0158b 100755 --- a/FS/bin/freeside-setup +++ b/FS/bin/freeside-setup @@ -805,10 +805,12 @@ sub tables_hash_hack { 'columns' => [ 'recnum', 'serial', '', '', 'svcnum', 'int', '', '', - 'reczone', 'varchar', '', $char_d, + #'reczone', 'varchar', '', $char_d, + 'reczone', 'varchar', '', 255, 'recaf', 'char', '', 2, 'rectype', 'char', '', 5, - 'recdata', 'varchar', '', $char_d, + #'recdata', 'varchar', '', $char_d, + 'recdata', 'varchar', '', 255, ], 'primary_key' => 'recnum', 'unique' => [], -- cgit v1.2.1 From cfd4d4d5fd2c64f0f0512905a465aeb4abce484c Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 20 Nov 2002 09:07:27 +0000 Subject: ugh... need to increase length of payinfo field in cust_pay and cust_refund for ACH --- FS/bin/freeside-setup | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-setup b/FS/bin/freeside-setup index 587f0158b..8f3d99fd5 100755 --- a/FS/bin/freeside-setup +++ b/FS/bin/freeside-setup @@ -541,7 +541,7 @@ sub tables_hash_hack { '_date', @date_type, 'payby', 'char', '', 4, # CARD/BILL/COMP, should be index into # payment type table. - 'payinfo', 'varchar', 'NULL', 16, #see cust_main above + 'payinfo', 'varchar', 'NULL', $char_d, #see cust_main above 'paybatch', 'varchar', 'NULL', $char_d, #for auditing purposes. 'closed', 'char', 'NULL', 1, ], @@ -618,7 +618,7 @@ sub tables_hash_hack { 'reason', 'varchar', '', $char_d, 'payby', 'char', '', 4, # CARD/BILL/COMP, should be index # into payment type table. - 'payinfo', 'varchar', 'NULL', 16, #see cust_main above + 'payinfo', 'varchar', 'NULL', $char_d, #see cust_main above 'paybatch', 'varchar', 'NULL', $char_d, 'closed', 'char', 'NULL', 1, ], -- cgit v1.2.1 From 99076cc92a72f9c578c95d527b14b741434b4a8f Mon Sep 17 00:00:00 2001 From: ivan Date: Tue, 17 Dec 2002 09:24:59 +0000 Subject: adding freeside-sqlradius-seconds --- FS/bin/freeside-sqlradius-seconds | 57 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 FS/bin/freeside-sqlradius-seconds (limited to 'FS/bin') diff --git a/FS/bin/freeside-sqlradius-seconds b/FS/bin/freeside-sqlradius-seconds new file mode 100644 index 000000000..e65b87f89 --- /dev/null +++ b/FS/bin/freeside-sqlradius-seconds @@ -0,0 +1,57 @@ +#!/usr/bin/perl -Tw + +use strict; +use Date::Parse; +use FS::UID qw(adminsuidsetup); +use FS::Record qw(qsearchs); +use FS::svc_acct; + +my $fs_user = shift or die &usage; +adminsuidsetup( $fs_user ); + +my $target_user = shift or die &usage; +my $start = shift or die &usage; +my $stop = shift || time; + +my $svc_acct = qsearchs( 'svc_acct', { 'username' => $target_user } ); +die "username $target_user not found\n" unless $svc_acct; + +print $svc_acct->seconds_since_sqlradacct( str2time($start), str2time($stop) ); + +sub usage { + die "Usage:\n\n freeside-sqlradius-seconds freeside_username target_username start_date stop_date\n"; +} + + +=head1 NAME + +freeside-sqlradius-seconds - Real-time radacct import daemon + +=head1 SYNOPSIS + + freeside-sqlradius-seconds freeside_username target_username start_date [ stop_date ] + +=head1 DESCRIPTION + +Returns the number of seconds the specified username has been online between +start_date (inclusive) and stop_date (exclusive). +See L + +B is a username added by freeside-adduser. +B is the username of the user account to query. +B and B are in any format Date::Parse is happy with. +B defaults to now if not specified. + +=head1 BUGS + +Selection of the account in question is rather simplistic in that +B doesn't necessarily identify a unique account (and wouldn't +even if a domain was specified), and no sqlradius export is checked for. + +=head1 SEE ALSO + +L + +=cut + +1; -- cgit v1.2.1 From 414b0f5b52ac15a4fdec9706727ff541d3bca039 Mon Sep 17 00:00:00 2001 From: ivan Date: Tue, 17 Dec 2002 09:30:52 +0000 Subject: carriage return helps alot --- FS/bin/freeside-sqlradius-seconds | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-sqlradius-seconds b/FS/bin/freeside-sqlradius-seconds index e65b87f89..f785e23c2 100644 --- a/FS/bin/freeside-sqlradius-seconds +++ b/FS/bin/freeside-sqlradius-seconds @@ -16,7 +16,8 @@ my $stop = shift || time; my $svc_acct = qsearchs( 'svc_acct', { 'username' => $target_user } ); die "username $target_user not found\n" unless $svc_acct; -print $svc_acct->seconds_since_sqlradacct( str2time($start), str2time($stop) ); +print $svc_acct->seconds_since_sqlradacct( str2time($start), str2time($stop) ). + "\n"; sub usage { die "Usage:\n\n freeside-sqlradius-seconds freeside_username target_username start_date stop_date\n"; -- cgit v1.2.1 From d86fad39ef5038a76c87e15b03b579f5151eb55b Mon Sep 17 00:00:00 2001 From: ivan Date: Tue, 17 Dec 2002 09:35:36 +0000 Subject: doh --- FS/bin/freeside-sqlradius-seconds | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-sqlradius-seconds b/FS/bin/freeside-sqlradius-seconds index f785e23c2..e40dc91b6 100644 --- a/FS/bin/freeside-sqlradius-seconds +++ b/FS/bin/freeside-sqlradius-seconds @@ -16,7 +16,9 @@ my $stop = shift || time; my $svc_acct = qsearchs( 'svc_acct', { 'username' => $target_user } ); die "username $target_user not found\n" unless $svc_acct; -print $svc_acct->seconds_since_sqlradacct( str2time($start), str2time($stop) ). +print $svc_acct->seconds_since_sqlradacct( + str2time($start), + $stop ? str2time($stop) : time ). "\n"; sub usage { -- cgit v1.2.1 From eb3e4b97673b20b626774b9e000c5c327c991d5b Mon Sep 17 00:00:00 2001 From: ivan Date: Tue, 17 Dec 2002 09:37:12 +0000 Subject: grr double doh --- FS/bin/freeside-sqlradius-seconds | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-sqlradius-seconds b/FS/bin/freeside-sqlradius-seconds index e40dc91b6..d2358cd5e 100644 --- a/FS/bin/freeside-sqlradius-seconds +++ b/FS/bin/freeside-sqlradius-seconds @@ -11,7 +11,7 @@ adminsuidsetup( $fs_user ); my $target_user = shift or die &usage; my $start = shift or die &usage; -my $stop = shift || time; +my $stop = scalar(@_) ? shift : ''; my $svc_acct = qsearchs( 'svc_acct', { 'username' => $target_user } ); die "username $target_user not found\n" unless $svc_acct; -- cgit v1.2.1 From d37105c93eae1366ee72ef93ae3d79cc5b04ade6 Mon Sep 17 00:00:00 2001 From: ivan Date: Tue, 17 Dec 2002 09:47:06 +0000 Subject: is this broken or is the calculation? --- FS/bin/freeside-sqlradius-seconds | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-sqlradius-seconds b/FS/bin/freeside-sqlradius-seconds index d2358cd5e..0539cb4d2 100644 --- a/FS/bin/freeside-sqlradius-seconds +++ b/FS/bin/freeside-sqlradius-seconds @@ -10,16 +10,13 @@ my $fs_user = shift or die &usage; adminsuidsetup( $fs_user ); my $target_user = shift or die &usage; -my $start = shift or die &usage; -my $stop = scalar(@_) ? shift : ''; +my $start = scalar(@_) && str2time(shift) or die &usage; +my $stop = scalar(@_) ? str2time(shift) : time; my $svc_acct = qsearchs( 'svc_acct', { 'username' => $target_user } ); die "username $target_user not found\n" unless $svc_acct; -print $svc_acct->seconds_since_sqlradacct( - str2time($start), - $stop ? str2time($stop) : time ). - "\n"; +print $svc_acct->seconds_since_sqlradacct( $start, $stop ). "\n"; sub usage { die "Usage:\n\n freeside-sqlradius-seconds freeside_username target_username start_date stop_date\n"; -- cgit v1.2.1 From 9f981d37086cea91e17aa2aefeee43388c60eb19 Mon Sep 17 00:00:00 2001 From: ivan Date: Tue, 17 Dec 2002 09:48:46 +0000 Subject: sigh --- FS/bin/freeside-sqlradius-seconds | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-sqlradius-seconds b/FS/bin/freeside-sqlradius-seconds index 0539cb4d2..31450bd2c 100644 --- a/FS/bin/freeside-sqlradius-seconds +++ b/FS/bin/freeside-sqlradius-seconds @@ -10,8 +10,8 @@ my $fs_user = shift or die &usage; adminsuidsetup( $fs_user ); my $target_user = shift or die &usage; -my $start = scalar(@_) && str2time(shift) or die &usage; -my $stop = scalar(@_) ? str2time(shift) : time; +my $start = scalar(@_) ? str2time(shift) : die &usage; +my $stop = scalar(@_) ? str2time(shift) : time; my $svc_acct = qsearchs( 'svc_acct', { 'username' => $target_user } ); die "username $target_user not found\n" unless $svc_acct; -- cgit v1.2.1 From 0d6147067e8d5317d01692f8588b3a0167c664c8 Mon Sep 17 00:00:00 2001 From: ivan Date: Tue, 17 Dec 2002 09:52:46 +0000 Subject: sheesh --- FS/bin/freeside-sqlradius-seconds | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-sqlradius-seconds b/FS/bin/freeside-sqlradius-seconds index 31450bd2c..a61e97730 100644 --- a/FS/bin/freeside-sqlradius-seconds +++ b/FS/bin/freeside-sqlradius-seconds @@ -10,8 +10,9 @@ my $fs_user = shift or die &usage; adminsuidsetup( $fs_user ); my $target_user = shift or die &usage; -my $start = scalar(@_) ? str2time(shift) : die &usage; -my $stop = scalar(@_) ? str2time(shift) : time; +my $start = shift or die &usage; +$start = str2time($start); +my $stop = scalar(@_) ? str2time(shift) : time; my $svc_acct = qsearchs( 'svc_acct', { 'username' => $target_user } ); die "username $target_user not found\n" unless $svc_acct; -- cgit v1.2.1 From 869f3b5401b5111789bf03a7a4cc5699ad2993a7 Mon Sep 17 00:00:00 2001 From: ivan Date: Tue, 17 Dec 2002 10:42:26 +0000 Subject: doh! but finally fixed --- FS/bin/freeside-sqlradius-seconds | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-sqlradius-seconds b/FS/bin/freeside-sqlradius-seconds index a61e97730..1c978fa8a 100644 --- a/FS/bin/freeside-sqlradius-seconds +++ b/FS/bin/freeside-sqlradius-seconds @@ -12,7 +12,7 @@ adminsuidsetup( $fs_user ); my $target_user = shift or die &usage; my $start = shift or die &usage; $start = str2time($start); -my $stop = scalar(@_) ? str2time(shift) : time; +my $stop = scalar(@ARGV) ? str2time(shift) : time; my $svc_acct = qsearchs( 'svc_acct', { 'username' => $target_user } ); die "username $target_user not found\n" unless $svc_acct; -- cgit v1.2.1 From 1a7b34a94745208217187050c1daec5bb31b7eb7 Mon Sep 17 00:00:00 2001 From: ivan Date: Sun, 22 Dec 2002 08:53:25 +0000 Subject: -p option for freeside-daily to only run for a particular payby $disable_agentcheck option for cust_pkg for import optimization --- FS/bin/freeside-daily | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-daily b/FS/bin/freeside-daily index 1db786120..c82dc07a0 100755 --- a/FS/bin/freeside-daily +++ b/FS/bin/freeside-daily @@ -11,16 +11,19 @@ use FS::cust_main; &untaint_argv; #what it sounds like (eww) use vars qw($opt_d $opt_v); -getopts("d:v"); +getopts("p:d:v"); my $user = shift or die &usage; adminsuidsetup $user; $FS::cust_main::Debug = 1 if $opt_v; +my %search; +$search{'payby'} = $opt_p if $opt_p; + my @cust_main = @ARGV - ? map { qsearchs('cust_main', { custnum => $_ } ) } @ARGV - : qsearch('cust_main', {} ) + ? map { qsearchs('cust_main', { custnum => $_, %search } ) } @ARGV + : qsearch('cust_main', \%search ) ; #we're at now now (and later). @@ -95,7 +98,7 @@ freeside-daily - Run daily billing and invoice collection events. =head1 SYNOPSIS - freeside-daily [ -d 'date' ] user [ custnum custnum ... ] + freeside-daily [ -d 'date' ] [ -p 'payby' ] [ -v ] user [ custnum custnum ... ] =head1 DESCRIPTION @@ -110,6 +113,10 @@ the bill and collect methods of a cust_main object. See L. -d: Pretend it's 'date'. Date is in any format Date::Parse is happy with, but be careful. + -p: Only process customers with the specified payby (CARD, CHEK, BILL, COMP, LECB) + + -v: enable debugging + user: From the mapsecrets file - see config.html from the base documentation custnum: if one or more customer numbers are specified, only bills those -- cgit v1.2.1 From b1d4c3b5b5a05d38a4baf9c49bd7fdfb6990531d Mon Sep 17 00:00:00 2001 From: ivan Date: Tue, 24 Dec 2002 22:41:23 +0000 Subject: optimization for ginourmous numbers of packages for intergate, whew --- FS/bin/freeside-setup | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-setup b/FS/bin/freeside-setup index 8f3d99fd5..8b7466222 100755 --- a/FS/bin/freeside-setup +++ b/FS/bin/freeside-setup @@ -669,7 +669,7 @@ sub tables_hash_hack { ], 'primary_key' => 'pkgpart', 'unique' => [], - 'index' => [], + 'index' => [ [ disabled ], ], }, # 'part_title' => { @@ -712,7 +712,7 @@ sub tables_hash_hack { ], 'primary_key' => 'svcpart', 'unique' => [], - 'index' => [], + 'index' => [ [ 'disabled' ] ], }, 'part_svc_column' => { -- cgit v1.2.1 From 7926d92e41b592b08f15d250ac5e78f75a2a29c7 Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 25 Dec 2002 06:59:09 +0000 Subject: declare $opt_p usage --- FS/bin/freeside-daily | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-daily b/FS/bin/freeside-daily index c82dc07a0..579d071ac 100755 --- a/FS/bin/freeside-daily +++ b/FS/bin/freeside-daily @@ -10,7 +10,7 @@ use FS::Conf; use FS::cust_main; &untaint_argv; #what it sounds like (eww) -use vars qw($opt_d $opt_v); +use vars qw($opt_d $opt_v $opt_p); getopts("p:d:v"); my $user = shift or die &usage; -- cgit v1.2.1 From 1bfcd9ce4738e5c9f3c8a309775235e823b2f82c Mon Sep 17 00:00:00 2001 From: ivan Date: Tue, 14 Jan 2003 09:26:49 +0000 Subject: move freeside-selfservice-server to proper MakeMaker install location --- FS/bin/freeside-selfservice-server | 235 +++++++++++++++++++++++++++++++++++++ 1 file changed, 235 insertions(+) create mode 100644 FS/bin/freeside-selfservice-server (limited to 'FS/bin') diff --git a/FS/bin/freeside-selfservice-server b/FS/bin/freeside-selfservice-server new file mode 100644 index 000000000..264cbc56d --- /dev/null +++ b/FS/bin/freeside-selfservice-server @@ -0,0 +1,235 @@ +#!/usr/bin/perl -w +# +# freeside-selfservice-server + +# alas, much false laziness with freeside-queued and fs_signup_server. at +# least it is slated to replace fs_{signup,passwd,mailadmin}_server +# should probably generalize the version in here, or better yet use +# Proc::Daemon or somesuch + +use strict; +use vars qw( $Debug %kids $kids $max_kids $shutdown $log_file $ssh_pid ); +use Fcntl qw(:flock); +use POSIX qw(:sys_wait_h setsid); +use IO::Handle; +use IO::Select; +use IO::File; +use Storable qw(nstore_fd fd_retrieve); +use Net::SSH qw(sshopen2); +use FS::UID qw(adminsuidsetup forksuidsetup); +use FS::ClientAPI; + +use FS::Conf; +use FS::cust_bill; +use FS::cust_pkg; + +$Debug = 2; # >= 2 will log packet contents, including potentially compromising + # information + +$shutdown = 0; +$max_kids = '10'; #? +$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 + +&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; +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); + +# nstore_fd(\*writer, {'hi'=>'there'}); + + warn "entering main loop\n" if $Debug; + my $undisp = 0; + my $s = IO::Select->new( $reader ); + while (1) { + + &reap_kids; + + warn "waiting for packet from client\n" if $Debug && !$undisp; + $undisp = 1; + my @handles = $s->can_read(5); + unless ( @handles ) { + &shutdown if $shutdown; + next; + } + + $undisp = 0; + + warn "receiving packet from client\n" if $Debug; + + my $packet = fd_retrieve($reader); + warn "packet received\n". + join('', map { " $_=>$packet->{$_}\n" } keys %$packet ) + if $Debug > 1; + + #prevent runaway forking + my $warnkids = 0; + while ( $kids >= $max_kids ) { + warn "WARNING: maximum $kids children reached\n" unless $warnkids++; + &reap_kids; + sleep 1; + } + + warn "forking child\n" if $Debug; + defined( my $pid = fork ) or die "can't fork: $!"; + if ( $pid ) { + $kids++; + $kids{$pid} = 1; + warn "child $pid spawned\n" if $Debug; + } else { #kid time + + #get new db handle + $FS::UID::dbh->{InactiveDestroy} = 1; + forksuidsetup($user); + + my $type = $packet->{_packet}; + warn "calling $type handler\n" if $Debug; + my $rv = eval { FS::ClientAPI->dispatch($type, $packet); }; + if ( $@ ) { + warn my $error = "WARNING: error dispatching $type: $@"; + $rv = { _error => $error }; + } + $rv->{_token} = $packet->{_token}; #identifier + + warn "sending response\n" if $Debug; + flock($writer, LOCK_EX) or die "FATAL: can't lock write stream: $!"; + 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: $!"; + + warn "child exiting\n" if $Debug; + exit; #end-of-kid + } + + } + +} + +### +# utility subroutines +### + +sub reap_kids { + #warn "reaping kids\n"; + foreach my $pid ( keys %kids ) { + my $kid = waitpid($pid, WNOHANG); + if ( $kid > 0 ) { + $kids--; + delete $kids{$kid}; + } + } + #warn "done reaping\n"; +} + +sub init { + my $user = shift; + + chdir "/" or die "Can't chdir to /: $!"; + open STDIN, '/dev/null' or die "Can't read /dev/null: $!"; + defined(my $pid = fork) or die "Can't fork: $!"; + if ( $pid ) { + print "freeside-selfservice-server to $machine started with pid $pid\n"; #logging to $log_file + exit unless $pid_file; + my $pidfh = new IO::File ">$pid_file" or exit; + print $pidfh "$pid\n"; + exit; + } + +# sub REAPER { my $pid = wait; $SIG{CHLD} = \&REAPER; $kids--; } +# #sub REAPER { my $pid = wait; $kids--; $SIG{CHLD} = \&REAPER; } +# $SIG{CHLD} = \&REAPER; + + $shutdown = 0; + $SIG{HUP} = sub { warn "SIGHUP received; shutting down\n"; $shutdown++; }; + $SIG{INT} = sub { warn "SIGINT received; shutting down\n"; $shutdown++; }; + $SIG{TERM} = sub { warn "SIGTERM received; shutting down\n"; $shutdown++; }; + $SIG{QUIT} = sub { warn "SIGQUIT received; shutting down\n"; $shutdown++; }; + $SIG{PIPE} = sub { warn "SIGPIPE received; shutting down\n"; $shutdown++; }; + + #false laziness w/freeside-queued + my $freeside_gid = scalar(getgrnam('freeside')) + or die "can't setgid to freeside group\n"; + $) = $freeside_gid; + $( = $freeside_gid; + #if freebsd can't setuid(), presumably it can't setgid() either. grr fleabsd + ($(,$)) = ($),$(); + $) = $freeside_gid; + + $> = $FS::UID::freeside_uid; + $< = $FS::UID::freeside_uid; + #freebsd is sofa king broken, won't setuid() + ($<,$>) = ($>,$<); + $> = $FS::UID::freeside_uid; + #eslaf + + $ENV{HOME} = (getpwuid($>))[7]; #for ssh + adminsuidsetup $user; + + #$log_file = "/usr/local/etc/freeside/selfservice.". $FS::UID::datasrc; #MACHINE NAME + $log_file = "/usr/local/etc/freeside/selfservice.$machine.log"; + + open STDOUT, '>/dev/null' + or die "Can't write to /dev/null: $!"; + setsid or die "Can't start a new session: $!"; + open STDERR, '>&STDOUT' or die "Can't dup stdout: $!"; + + $SIG{__DIE__} = \&_die; + $SIG{__WARN__} = \&_logmsg; + + warn "freeside-selfservice-server starting\n"; + +} + +sub shutdown { + my $wait = 12; #wait up to 1 minute + while ( $kids > 0 && $wait-- ) { + warn "waiting for $kids children to terminate"; + sleep 5; + } + warn "abandoning $kids children" if $kids; + kill 'TERM', $ssh_pid if $ssh_pid; + die "exiting"; +} + +sub _die { + my $msg = shift; + unlink $pid_file if -e $pid_file; + _logmsg($msg); +} + +sub _logmsg { + chomp( my $msg = shift ); + _do_logmsg( "[server] [". scalar(localtime). "] [$$] $msg\n" ); +} + +sub _do_logmsg { + chomp( my $msg = shift ); + my $log = new IO::File ">>$log_file"; + flock($log, LOCK_EX); + seek($log, 0, 2); + print $log "$msg\n"; + flock($log, LOCK_UN); + close $log; +} + +sub usage { + die "Usage:\n\n fs_signup_server user machine\n"; +} + -- cgit v1.2.1 From 39b71146259e7c2eab3b0c3326000087a7dd75b1 Mon Sep 17 00:00:00 2001 From: ivan Date: Tue, 28 Jan 2003 07:47:52 +0000 Subject: eek, and this is what caused connectup to fail too --- FS/bin/freeside-setup | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-setup b/FS/bin/freeside-setup index 8b7466222..0ef3fc81b 100755 --- a/FS/bin/freeside-setup +++ b/FS/bin/freeside-setup @@ -669,7 +669,7 @@ sub tables_hash_hack { ], 'primary_key' => 'pkgpart', 'unique' => [], - 'index' => [ [ disabled ], ], + 'index' => [ [ 'disabled' ], ], }, # 'part_title' => { -- cgit v1.2.1 From 0354f39ed0e74fd2eae1d9da13906625b4f56591 Mon Sep 17 00:00:00 2001 From: khoff Date: Wed, 5 Feb 2003 23:17:17 +0000 Subject: svc_broadband rewrite --- FS/bin/freeside-setup | 89 ++++++++++++++++++++++++++++++++------------------- 1 file changed, 56 insertions(+), 33 deletions(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-setup b/FS/bin/freeside-setup index 0ef3fc81b..19483765e 100755 --- a/FS/bin/freeside-setup +++ b/FS/bin/freeside-setup @@ -1012,76 +1012,99 @@ sub tables_hash_hack { 'index' => [], }, - 'ac_type' => { + 'router' => { 'columns' => [ - 'actypenum', 'serial', '', '', - 'actypename', 'varchar', '', $char_d, + 'routernum', 'serial', '', '', + 'routername', 'varchar', '', $char_d, + 'svcnum', 'int', '0', '', ], - 'primary_key' => 'actypenum', + 'primary_key' => 'routernum', 'unique' => [], 'index' => [], }, - 'ac' => { + 'part_svc_router' => { 'columns' => [ - 'acnum', 'serial', '', '', - 'actypenum', 'int', '', '', - 'acname', 'varchar', '', $char_d, - ], - 'primary_key' => 'acnum', + 'svcpart', 'int', '', '', + 'routernum', 'int', '', '', + ]; + 'primary_key' => '', 'unique' => [], - 'index' => [ [ 'actypenum' ] ], + 'index' => [], }, - 'part_ac_field' => { + 'part_router_field' => { 'columns' => [ - 'acfieldpart', 'serial', '', '', - 'actypenum', 'int', '', '', + 'routerfieldpart', 'serial', '', '', 'name', 'varchar', '', $char_d, - 'ut_type', 'varchar', '', $char_d, + 'length', 'int', '', '', + 'check_block', 'text', 'NULL', '', + 'list_source', 'text', 'NULL', '', ], - 'primary_key' => 'acfieldpart', + 'primary_key' => 'routerfieldpart', 'unique' => [], - 'index' => [ [ 'actypenum' ] ], + 'index' => [], }, - 'ac_field' => { + 'router_field' => { 'columns' => [ - 'acfieldpart', 'int', '', '', - 'acnum', 'int', '', '', - 'value', 'text', '', '', + 'routerfieldpart', 'int', '', '', + 'routernum', 'int', '', '', + 'value', 'varchar', '', 128, ], 'primary_key' => '', - 'unique' => [ [ 'acfieldpart', 'acnum' ] ], - 'index' => [ [ 'acnum' ] ], + 'unique' => [ [ 'routerfieldpart', 'routernum' ] ], + 'index' => [], }, - 'ac_block' => { + 'addr_block' => { 'columns' => [ - 'acnum', 'int', '', '', + 'blocknum', 'int', '', '', + 'routernum', 'int', '', '', 'ip_gateway', 'varchar', '', 15, 'ip_netmask', 'int', '', '', ], + 'primary_key' => 'blocknum', + 'unique' => [ [ 'blocknum', 'routernum' ] ], + 'index' => [], + }, + + 'part_sb_field' => { + 'columns' => [ + 'sbfieldpart', 'int', '', '', + 'svcpart', 'int', '', '', + 'name', 'varchar', '', $char_d, + 'length', 'int', '', '', + 'check_block', 'text', 'NULL', '', + 'list_source', 'text', 'NULL', '', + ], + 'primary_key' => 'sbfieldpart', + 'unique' => [ [ 'sbfieldpart', 'svcpart' ] ], + 'index' => [], + }, + + 'sb_field' => { + 'columns' => [ + 'sbfieldpart', 'int', '', '', + 'svcnum', 'int', '', '', + 'value', 'varchar', '', 128, + ], 'primary_key' => '', - 'unique' => [], - 'index' => [ [ 'acnum' ] ], + 'unique' => [ [ 'sbfieldpart', 'svcnum' ] ], + 'index' => [], }, 'svc_broadband' => { 'columns' => [ 'svcnum', 'int', '', '', - 'actypenum', 'int', '', '', + 'blocknum', 'int', '', '', 'speed_up', 'int', '', '', 'speed_down', 'int', '', '', - 'acnum', 'int', '', '', 'ip_addr', 'varchar', '', 15, - 'ip_netmask', 'int', '', '', - 'mac_addr', 'char', '', 17, - 'location', 'varchar', '', $char_d, ], 'primary_key' => 'svcnum', 'unique' => [], - 'index' => [ [ 'actypenum' ] ], + 'index' => [], }, ); -- cgit v1.2.1 From c232fac0743999105f6948b9fa352fe2293b09f8 Mon Sep 17 00:00:00 2001 From: ivan Date: Thu, 6 Feb 2003 05:26:50 +0000 Subject: time/data detail on invoices --- FS/bin/freeside-setup | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'FS/bin') diff --git a/FS/bin/freeside-setup b/FS/bin/freeside-setup index 19483765e..cf009c249 100755 --- a/FS/bin/freeside-setup +++ b/FS/bin/freeside-setup @@ -421,6 +421,18 @@ sub tables_hash_hack { 'index' => [ ['invnum'] ], }, + 'cust_bill_pkg_detail' => { + 'columns' => [ + 'detailnum', 'serial', '', '', + 'pkgnum', 'int', '', '', + 'invnum', 'int', '', '', + 'detail', 'varchar', '', $char_d, + ], + 'primary_key' => 'detailnum', + 'unique' => [], + 'index' => [ [ 'pkgnum', 'invnum' ] ], + }, + 'cust_credit' => { 'columns' => [ 'crednum', 'serial', '', '', -- cgit v1.2.1 From 2fc87c32cbb509992070b044ed66e2a0e9828a17 Mon Sep 17 00:00:00 2001 From: khoff Date: Wed, 12 Feb 2003 01:21:50 +0000 Subject: s/;/,/ --- FS/bin/freeside-setup | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-setup b/FS/bin/freeside-setup index cf009c249..b3cdb3384 100755 --- a/FS/bin/freeside-setup +++ b/FS/bin/freeside-setup @@ -1039,7 +1039,7 @@ sub tables_hash_hack { 'columns' => [ 'svcpart', 'int', '', '', 'routernum', 'int', '', '', - ]; + ], 'primary_key' => '', 'unique' => [], 'index' => [], -- cgit v1.2.1 From f9dbf311aeddb4356855362d586d1c4643b4f538 Mon Sep 17 00:00:00 2001 From: ivan Date: Mon, 31 Mar 2003 23:48:31 +0000 Subject: add 'last_bill' column --- FS/bin/freeside-setup | 1 + 1 file changed, 1 insertion(+) (limited to 'FS/bin') diff --git a/FS/bin/freeside-setup b/FS/bin/freeside-setup index b3cdb3384..010ec4c14 100755 --- a/FS/bin/freeside-setup +++ b/FS/bin/freeside-setup @@ -609,6 +609,7 @@ sub tables_hash_hack { 'otaker', 'varchar', '', 32, 'setup', @date_type, 'bill', @date_type, + 'last_bill', @date_type, 'susp', @date_type, 'cancel', @date_type, 'expire', @date_type, -- cgit v1.2.1 From 030bef17868168b05a67d9f5866b55da1bb9439c Mon Sep 17 00:00:00 2001 From: ivan Date: Mon, 21 Apr 2003 20:53:57 +0000 Subject: on-demand vs. automatic cards & checks: added DCRD and DCHK payment types --- FS/bin/freeside-daily | 2 +- FS/bin/freeside-expiration-alerter | 6 +++--- FS/bin/freeside-setup | 2 ++ 3 files changed, 6 insertions(+), 4 deletions(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-daily b/FS/bin/freeside-daily index 579d071ac..63e621b57 100755 --- a/FS/bin/freeside-daily +++ b/FS/bin/freeside-daily @@ -113,7 +113,7 @@ the bill and collect methods of a cust_main object. See L. -d: Pretend it's 'date'. Date is in any format Date::Parse is happy with, but be careful. - -p: Only process customers with the specified payby (CARD, CHEK, BILL, COMP, LECB) + -p: Only process customers with the specified payby (I, I, I, I, I, I, I) -v: enable debugging diff --git a/FS/bin/freeside-expiration-alerter b/FS/bin/freeside-expiration-alerter index 5399f6d22..691fd3aa5 100755 --- a/FS/bin/freeside-expiration-alerter +++ b/FS/bin/freeside-expiration-alerter @@ -97,7 +97,7 @@ foreach my $customer (@customers) my $expire_time = timelocal(0,0,0,$payday,--$paymonth,$payyear); #credit cards expire at the end of the month/year of their exp date - if ($payby eq 'CARD') { + if ($payby eq 'CARD' || $payby eq 'DCRD') { ($paymonth < 11) ? $paymonth++ : ($paymonth=0, $payyear++); $expire_time = timelocal(0,0,0,$payday,$paymonth,$payyear); $expire_time--; @@ -127,7 +127,7 @@ foreach my $customer (@customers) $FS::alerter::_template::first = $first; $FS::alerter::_template::last = $last; $FS::alerter::_template::company = $company; - if ($payby eq 'CARD') { + if ($payby eq 'CARD' || $payby eq 'DCRD') { $FS::alerter::_template::payby = "credit card (" . substr($payinfo, 0, 2) . "xxxxxxxxxx" . substr($payinfo, -4) . ")"; @@ -202,7 +202,7 @@ user: From the mapsecrets file - see config.html from the base documentation =head1 VERSION -$Id: freeside-expiration-alerter,v 1.4 2002-09-16 09:27:14 ivan Exp $ +$Id: freeside-expiration-alerter,v 1.5 2003-04-21 20:53:57 ivan Exp $ =head1 BUGS diff --git a/FS/bin/freeside-setup b/FS/bin/freeside-setup index 010ec4c14..8ec014186 100755 --- a/FS/bin/freeside-setup +++ b/FS/bin/freeside-setup @@ -291,6 +291,8 @@ foreach my $aref ( [ 'COMP', 'Comp invoice', '$cust_bill->comp();', 30, 'comp' ], [ 'CARD', 'Batch card', '$cust_bill->batch_card();', 40, 'batch-card' ], [ 'BILL', 'Send invoice', '$cust_bill->send();', 50, 'send' ], + [ 'DCRD', 'Send invoice', '$cust_bill->send();', 50, 'send' ], + [ 'DCHK', 'Send invoice', '$cust_bill->send();', 50, 'send' ], ) { my $part_bill_event = new FS::part_bill_event({ -- cgit v1.2.1 From 970a86aec45df2ab579ac54fc67cba475c7c013b Mon Sep 17 00:00:00 2001 From: khoff Date: Wed, 23 Apr 2003 04:53:17 +0000 Subject: DBD::Pg doesn't handle char types very well. --- FS/bin/freeside-setup | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-setup b/FS/bin/freeside-setup index 8ec014186..518a2ad42 100755 --- a/FS/bin/freeside-setup +++ b/FS/bin/freeside-setup @@ -471,7 +471,7 @@ sub tables_hash_hack { 'last', 'varchar', '', $char_d, # 'middle', 'varchar', 'NULL', $char_d, 'first', 'varchar', '', $char_d, - 'ss', 'char', 'NULL', 11, + 'ss', 'varchar', 'NULL', 11, 'company', 'varchar', 'NULL', $char_d, 'address1', 'varchar', '', $char_d, 'address2', 'varchar', 'NULL', $char_d, @@ -823,7 +823,7 @@ sub tables_hash_hack { #'reczone', 'varchar', '', $char_d, 'reczone', 'varchar', '', 255, 'recaf', 'char', '', 2, - 'rectype', 'char', '', 5, + 'rectype', 'varchar', '', 5, #'recdata', 'varchar', '', $char_d, 'recdata', 'varchar', '', 255, ], -- cgit v1.2.1 From b5e03a09e99ede045b0e3be87085c628d422e3ea Mon Sep 17 00:00:00 2001 From: ivan Date: Tue, 3 Jun 2003 05:49:16 +0000 Subject: router.svcnum nullability fix --- FS/bin/freeside-setup | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-setup b/FS/bin/freeside-setup index 518a2ad42..a1fab5fa0 100755 --- a/FS/bin/freeside-setup +++ b/FS/bin/freeside-setup @@ -1031,7 +1031,7 @@ sub tables_hash_hack { 'columns' => [ 'routernum', 'serial', '', '', 'routername', 'varchar', '', $char_d, - 'svcnum', 'int', '0', '', + 'svcnum', 'int', 'NULL', '', ], 'primary_key' => 'routernum', 'unique' => [], -- cgit v1.2.1 From a60b96753d5c615914fa766b2b0fe8bd2f86c337 Mon Sep 17 00:00:00 2001 From: ivan Date: Tue, 3 Jun 2003 06:09:52 +0000 Subject: use serial for primary keys in new tables too --- FS/bin/freeside-setup | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-setup b/FS/bin/freeside-setup index a1fab5fa0..d2a98dd0c 100755 --- a/FS/bin/freeside-setup +++ b/FS/bin/freeside-setup @@ -1031,7 +1031,7 @@ sub tables_hash_hack { 'columns' => [ 'routernum', 'serial', '', '', 'routername', 'varchar', '', $char_d, - 'svcnum', 'int', 'NULL', '', + 'svcnum', 'int', '0', '', ], 'primary_key' => 'routernum', 'unique' => [], @@ -1074,7 +1074,7 @@ sub tables_hash_hack { 'addr_block' => { 'columns' => [ - 'blocknum', 'int', '', '', + 'blocknum', 'serial', '', '', 'routernum', 'int', '', '', 'ip_gateway', 'varchar', '', 15, 'ip_netmask', 'int', '', '', @@ -1086,7 +1086,7 @@ sub tables_hash_hack { 'part_sb_field' => { 'columns' => [ - 'sbfieldpart', 'int', '', '', + 'sbfieldpart', 'serial', '', '', 'svcpart', 'int', '', '', 'name', 'varchar', '', $char_d, 'length', 'int', '', '', -- cgit v1.2.1 From 9e6413e476a3516a08710efa5ff4d5949c1aa88c Mon Sep 17 00:00:00 2001 From: ivan Date: Sat, 14 Jun 2003 02:02:55 +0000 Subject: add index on cust_bill._date --- FS/bin/freeside-setup | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-setup b/FS/bin/freeside-setup index d2a98dd0c..734744efe 100755 --- a/FS/bin/freeside-setup +++ b/FS/bin/freeside-setup @@ -373,7 +373,7 @@ sub tables_hash_hack { ], 'primary_key' => 'invnum', 'unique' => [], - 'index' => [ ['custnum'] ], + 'index' => [ ['custnum'], ['_date'] ], }, 'cust_bill_event' => { -- cgit v1.2.1 From 70997699eb64ce36ca408214cfe4dbc502d7ca58 Mon Sep 17 00:00:00 2001 From: ivan Date: Mon, 30 Jun 2003 12:22:24 +0000 Subject: adding sqlradius_withdomain export including realms, closes: bug#514 --- FS/bin/freeside-sqlradius-reset | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-sqlradius-reset b/FS/bin/freeside-sqlradius-reset index 9d3a6a700..74f90a582 100755 --- a/FS/bin/freeside-sqlradius-reset +++ b/FS/bin/freeside-sqlradius-reset @@ -12,7 +12,9 @@ adminsuidsetup $user; #my $machine = shift or die &usage; -my @exports = qsearch('part_export', { 'exporttype' => 'sqlradius' } ); +my @exports = qsearch('part_export', { exporttype=>'sqlradius' } ); +push @exports, qsearch('part_export', { exporttype=>'sqlradius_withdomain' } ); + foreach my $export ( @exports ) { my $icradius_dbh = DBI->connect( -- cgit v1.2.1 From 68d5b555f4f51ade6d3a2627e9c3e3b22a21a5a3 Mon Sep 17 00:00:00 2001 From: ivan Date: Mon, 30 Jun 2003 13:18:39 +0000 Subject: removing deprecated freeside-overdue --- FS/bin/freeside-overdue | 196 ------------------------------------------------ 1 file changed, 196 deletions(-) delete mode 100755 FS/bin/freeside-overdue (limited to 'FS/bin') diff --git a/FS/bin/freeside-overdue b/FS/bin/freeside-overdue deleted file mode 100755 index 116245f9c..000000000 --- a/FS/bin/freeside-overdue +++ /dev/null @@ -1,196 +0,0 @@ -#!/usr/bin/perl -w - -use strict; -use vars qw( $days_to_pay $cust_main $cust_pkg - $cust_svc $svc_acct ); -use Getopt::Std; -use FS::cust_main; -use FS::cust_pkg; -use FS::cust_svc; -use FS::svc_acct; -use FS::Record qw(qsearch qsearchs); -use FS::UID qw(adminsuidsetup); - -&untaint_argv; -my %opt; -getopts('ed:qpl:scbyoi', \%opt); -my $user = shift or die &usage; - -adminsuidsetup $user; - -my $now = time; #eventually take a time option like freeside-bill -my ($sec,$min,$hour,$mday,$mon,$year) = - (localtime($now) )[0,1,2,3,4,5]; -$mon++; -$year += 1900; - -foreach $cust_main ( qsearch('cust_main',{} ) ) { - - my ( $eyear, $emon, $eday ) = ( 2037, 12, 31 ); - if ( $cust_main->paydate =~ /^(\d{4})\-(\d{1,2})\-(\d{1,2})$/ - && $cust_main->payby eq 'BILL') { - ( $eyear, $emon, $eday ) = ( $1, $2, $3 ); - } - - if ( ( $opt{d} - && $cust_main->balance_date(time - $opt{d} * 86400) > 0 - && qsearchs( 'cust_pkg', { 'custnum' => $cust_main->custnum, - 'susp' => "" } ) ) - || ( $opt{e} - && $cust_main->payby eq 'BILL' - && ( $eyear < $year - || ( $eyear == $year && $emon < $mon ) ) ) - ) { - - unless ( $opt{q} ) { - print $cust_main->custnum, "\t", - $cust_main->last, "\t", $cust_main->first, "\t", - $cust_main->balance_date(time-$opt{d} * 86400); - } - - if ( $opt{p} && ! grep { $_ eq 'POST' } $cust_main->invoicing_list ) { - print "\n\tAdding postal invoicing" unless $opt{q}; - my @invoicing_list = $cust_main->invoicing_list; - push @invoicing_list, 'POST'; - $cust_main->invoicing_list(\@invoicing_list); - } - - if ( $opt{l} ) { - print "\n\tCharging late fee of \$$opt{l}" unless $opt{q}; - my $error = $cust_main->charge($opt{l}, 'Late fee'); - # comment or plandata with info so we don't redo the same late fee every - # day - } - - foreach $cust_pkg ( qsearch( 'cust_pkg', - { 'custnum' => $cust_main->custnum } ) ) { - - if ($opt{s}) { - print "\n\tSuspending pkgnum " . $cust_pkg->pkgnum unless $opt{q}; - $cust_pkg->suspend; - } - - if ($opt{c}) { - print "\n\tCancelling pkgnum " . $cust_pkg->pkgnum unless $opt{q}; - $cust_pkg->cancel; - } - - } - - if ( $opt{b} ) { - print "\n\tBilling" unless $opt{q}; - my $error = $cust_main->bill('time'=>$now); - warn "Error billing, customer #" . $cust_main->custnum . - ":" . $error if $error; - } - - if ( $opt{y} ) { - print "\n\tApplying outstanding payments and credits" unless $opt{q}; - $cust_main->apply_payments; - $cust_main->apply_credits; - } - - if ( $opt{o} ) { - print "\n\tCollecting" unless $opt{q}; - my $error = $cust_main->collect( - 'invoice_time' => $now, - 'batch_card' => $opt{i} ? 'no' : 'yes', - 'force_print' => 'yes', - ); - warn "Error collecting from customer #" . $cust_main->custnum. ":$error" - if $error; - } - - print "\n" unless $opt{q}; - - } - -} - -sub untaint_argv { - foreach $_ ( $[ .. $#ARGV ) { - $ARGV[$_] =~ /^([\w\-\/\.]*)$/ || die "Illegal arguement \"$ARGV[$_]\""; - $ARGV[$_]=$1; - } -} - -sub usage { - die "Usage:\n\n freeside-overdue [ -e ] [ -d days ] [ -q ] [ -p ] [ -l amount ] [ -s ] [ -c ] [ -b ] [ -y ] [ -o [ -i ] ] user\n"; -} - - -=head1 NAME - -freeside-overdue - Perform actions on overdue and/or expired accounts. - -=head1 SYNOPSIS - - freeside-overdue [ -e ] [ -d days ] [ -q ] [ -p ] [ -l amount ] [ -s ] [ -c ] [ -b ] [ -y ] [ -o [ -i ] ] user - -=head1 DESCRIPTION - -This script is deprecated in 1.4.0. You should use freeside-daily and invoice -events instead. - -Performs actions on overdue and/or expired accounts. - -Selection options (at least one selection option is required): - - -d: Customers with a balance due on invoices older than the supplied number - of days. Requires an integer argument. - - -e: Customers with a billing expiration date in the past. - -Action options: - - -q: Be quiet (by default, selected accounts are printed). - - -p: Add postal invoicing to the relevant customers. - - -l: Add a charge of the given amount to the relevant customers. - - -s: Suspend accounts. - - -c: Cancel accounts. - - -b: Bill customers (create invoices) - - -y: Apply unapplied payments and credits - - -o: Collect from customers (charge cards, print invoices) - - -i: real-time billing (as opposed to batch billing). only relevant - for credit cards. - - user: From the mapsecrets file - see config.html from the base documentation - -=head1 CRONTAB - -Example crontab entries: - -# suspend expired accounts -20 4 * * * freeside-overdue -e -s user - -# quietly add postal invoicing to customers over 30 days past due -20 4 * * * freeside-overdue -d 30 -p -q user - -# suspend accounts and charge a $10.23 fee for customers over 60 days past due -20 4 * * * freeside-overdue -d 60 -s -l 10.23 user - -# cancel accounts over 90 days past due -20 4 * * * freeside-overdue -d 90 -c user - -=head1 ORIGINAL AUTHORS - -Original disable-overdue version by mw/kwh: Mark W.? and Kristian Hoffmann ? - -Ivan seems to be turning it into the "do-everything" CLI. - -=head1 BUGS - -Hell now that this is the do-everything CLI it should have --longoptions - -=cut - -1; - -- cgit v1.2.1 From 58d44fbe5eb9ab32e6d87063a4a3b22ddba9a828 Mon Sep 17 00:00:00 2001 From: khoff Date: Tue, 5 Aug 2003 00:20:51 +0000 Subject: Virtual field merge --- FS/bin/freeside-setup | 77 ++++++++++++++++++--------------------------------- 1 file changed, 27 insertions(+), 50 deletions(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-setup b/FS/bin/freeside-setup index 734744efe..2cb555e18 100755 --- a/FS/bin/freeside-setup +++ b/FS/bin/freeside-setup @@ -1031,7 +1031,7 @@ sub tables_hash_hack { 'columns' => [ 'routernum', 'serial', '', '', 'routername', 'varchar', '', $char_d, - 'svcnum', 'int', '0', '', + 'svcnum', 'int', 'NULL', '', ], 'primary_key' => 'routernum', 'unique' => [], @@ -1048,30 +1048,6 @@ sub tables_hash_hack { 'index' => [], }, - 'part_router_field' => { - 'columns' => [ - 'routerfieldpart', 'serial', '', '', - 'name', 'varchar', '', $char_d, - 'length', 'int', '', '', - 'check_block', 'text', 'NULL', '', - 'list_source', 'text', 'NULL', '', - ], - 'primary_key' => 'routerfieldpart', - 'unique' => [], - 'index' => [], - }, - - 'router_field' => { - 'columns' => [ - 'routerfieldpart', 'int', '', '', - 'routernum', 'int', '', '', - 'value', 'varchar', '', 128, - ], - 'primary_key' => '', - 'unique' => [ [ 'routerfieldpart', 'routernum' ] ], - 'index' => [], - }, - 'addr_block' => { 'columns' => [ 'blocknum', 'serial', '', '', @@ -1084,31 +1060,6 @@ sub tables_hash_hack { 'index' => [], }, - 'part_sb_field' => { - 'columns' => [ - 'sbfieldpart', 'serial', '', '', - 'svcpart', 'int', '', '', - 'name', 'varchar', '', $char_d, - 'length', 'int', '', '', - 'check_block', 'text', 'NULL', '', - 'list_source', 'text', 'NULL', '', - ], - 'primary_key' => 'sbfieldpart', - 'unique' => [ [ 'sbfieldpart', 'svcpart' ] ], - 'index' => [], - }, - - 'sb_field' => { - 'columns' => [ - 'sbfieldpart', 'int', '', '', - 'svcnum', 'int', '', '', - 'value', 'varchar', '', 128, - ], - 'primary_key' => '', - 'unique' => [ [ 'sbfieldpart', 'svcnum' ] ], - 'index' => [], - }, - 'svc_broadband' => { 'columns' => [ 'svcnum', 'int', '', '', @@ -1122,6 +1073,32 @@ sub tables_hash_hack { 'index' => [], }, + 'part_virtual_field' => { + 'columns' => [ + 'vfieldpart', 'int', '', '', + 'dbtable', 'varchar', '', 32, + 'name', 'varchar', '', 32, + 'check_block', 'text', 'NULL', '', + 'length', 'int', 'NULL', '', + 'list_source', 'text', 'NULL', '', + 'label', 'varchar', 'NULL', 80, + ], + 'primary_key' => 'vfieldpart', + 'unique' => [], + 'index' => [], + }, + + 'virtual_field' => { + 'columns' => [ + 'recnum', 'int', '', '', + 'vfieldpart', 'int', '', '', + 'value', 'varchar', '', 128, + ], + 'primary_key' => '', + 'unique' => [ [ 'vfieldpart', 'recnum' ] ], + 'index' => [], + }, + ); %tables; -- cgit v1.2.1 From 26ff2b45ce893fa83baffc60dea898df887e7b1d Mon Sep 17 00:00:00 2001 From: ivan Date: Fri, 5 Sep 2003 07:55:38 +0000 Subject: svc_acct._password from 50 to 72 for blowfish passwords --- FS/bin/freeside-setup | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-setup b/FS/bin/freeside-setup index 2cb555e18..197542086 100755 --- a/FS/bin/freeside-setup +++ b/FS/bin/freeside-setup @@ -776,7 +776,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', '', -- cgit v1.2.1 From daeb70ea28f8a3e0db500f8a0e107221f4542d30 Mon Sep 17 00:00:00 2001 From: ivan Date: Thu, 25 Sep 2003 10:27:11 +0000 Subject: freebsd portability fixes --- FS/bin/freeside-selfservice-server | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-selfservice-server b/FS/bin/freeside-selfservice-server index 264cbc56d..6cfafda58 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; @@ -35,6 +36,9 @@ 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 $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; @@ -109,10 +113,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 @@ -229,7 +233,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"; } -- cgit v1.2.1 From d6436c7251a94c9597c7b2195d63bd7c86f956e9 Mon Sep 17 00:00:00 2001 From: ivan Date: Thu, 25 Sep 2003 10:42:28 +0000 Subject: add setuptax and recurtax fields to cust_main_county --- FS/bin/freeside-setup | 2 ++ 1 file changed, 2 insertions(+) (limited to 'FS/bin') diff --git a/FS/bin/freeside-setup b/FS/bin/freeside-setup index 197542086..27d02529c 100755 --- a/FS/bin/freeside-setup +++ b/FS/bin/freeside-setup @@ -539,6 +539,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' => [], -- cgit v1.2.1 From 74e6f7cb1f048778a417e0124143f6c447c9f87c Mon Sep 17 00:00:00 2001 From: ivan Date: Fri, 26 Sep 2003 13:04:26 +0000 Subject: re-setup option to re-charge setup fee --- FS/bin/freeside-daily | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-daily b/FS/bin/freeside-daily index 63e621b57..80b8edf82 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); +getopts("p:d:vs"); my $user = shift or die &usage; adminsuidsetup $user; @@ -42,7 +42,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 +99,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' ] [ -p 'payby' ] [ -s ] [ -v ] user [ custnum custnum ... ] =head1 DESCRIPTION @@ -115,6 +116,8 @@ the bill and collect methods of a cust_main object. See L. -p: Only process customers with the specified payby (I, I, I, I, I, I, I) + -s: re-charge setup fees + -v: enable debugging user: From the mapsecrets file - see config.html from the base documentation -- cgit v1.2.1 From 4196bc59e8cceb04c6f76fab46ce249ff0178c43 Mon Sep 17 00:00:00 2001 From: ivan Date: Mon, 29 Sep 2003 02:17:51 +0000 Subject: finish removing quiet config options --- FS/bin/freeside-selfservice-server | 5 ----- 1 file changed, 5 deletions(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-selfservice-server b/FS/bin/freeside-selfservice-server index 6cfafda58..107103973 100644 --- a/FS/bin/freeside-selfservice-server +++ b/FS/bin/freeside-selfservice-server @@ -43,11 +43,6 @@ open(LOCKFILE,">$lock_file") or die "can't open $lock_file: $!"; 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; -- cgit v1.2.1 From e17e58178d528e16d45c333996f763afda55e054 Mon Sep 17 00:00:00 2001 From: ivan Date: Mon, 29 Sep 2003 05:51:20 +0000 Subject: added agent.disabled agent.username agent._password --- FS/bin/freeside-setup | 3 +++ 1 file changed, 3 insertions(+) (limited to 'FS/bin') diff --git a/FS/bin/freeside-setup b/FS/bin/freeside-setup index 27d02529c..bb122700a 100755 --- a/FS/bin/freeside-setup +++ b/FS/bin/freeside-setup @@ -336,6 +336,9 @@ sub tables_hash_hack { 'typenum', 'int', '', '', 'freq', 'int', 'NULL', '', 'prog', @perl_type, + 'disabled', 'char', 'NULL', 1, + 'username', 'varchar', '', $char_d, + '_password','varchar', '', $char_d, ], 'primary_key' => 'agentnum', 'unique' => [], -- cgit v1.2.1 From 9d7f2b5a7bd69a3f968277df8e5fb8491a66a1e5 Mon Sep 17 00:00:00 2001 From: ivan Date: Thu, 2 Oct 2003 10:18:24 +0000 Subject: added -y switch to freeside-daily to specify an offset in days --- FS/bin/freeside-daily | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-daily b/FS/bin/freeside-daily index 80b8edf82..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 $opt_s); -getopts("p:d:vs"); +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 ) { @@ -99,7 +100,7 @@ freeside-daily - Run daily billing and invoice collection events. =head1 SYNOPSIS - freeside-daily [ -d 'date' ] [ -p 'payby' ] [ -s ] [ -v ] user [ custnum custnum ... ] + freeside-daily [ -d 'date' ] [ -y days ] [ -p 'payby' ] [ -s ] [ -v ] user [ custnum custnum ... ] =head1 DESCRIPTION @@ -114,6 +115,11 @@ the bill and collect methods of a cust_main object. See L. -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, I, I, I, I, I, I) -s: re-charge setup fees -- cgit v1.2.1 From 7598ece6cac31548505dd610ef418ca001adf5b2 Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 15 Oct 2003 12:08:47 +0000 Subject: fix agent username and password nullability --- FS/bin/freeside-setup | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-setup b/FS/bin/freeside-setup index bb122700a..b7b45dc63 100755 --- a/FS/bin/freeside-setup +++ b/FS/bin/freeside-setup @@ -337,8 +337,8 @@ sub tables_hash_hack { 'freq', 'int', 'NULL', '', 'prog', @perl_type, 'disabled', 'char', 'NULL', 1, - 'username', 'varchar', '', $char_d, - '_password','varchar', '', $char_d, + 'username', 'varchar', 'NULL', $char_d, + '_password','varchar', 'NULL', $char_d, ], 'primary_key' => 'agentnum', 'unique' => [], @@ -1104,6 +1104,20 @@ 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' ] ], + }, + ); %tables; -- cgit v1.2.1 From bacea004a735c7a9c30a35e9184a63897a200e6e Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 15 Oct 2003 15:03:56 +0000 Subject: add tagging ability so we can run multiple self-service clients on one machine --- FS/bin/freeside-selfservice-server | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-selfservice-server b/FS/bin/freeside-selfservice-server index 107103973..05fa72b43 100644 --- a/FS/bin/freeside-selfservice-server +++ b/FS/bin/freeside-selfservice-server @@ -33,6 +33,7 @@ $kids = 0; my $user = shift or die &usage; my $machine = shift or die &usage; +my $tag = scalar(@ARGV) ? shift : ''; 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 @@ -50,7 +51,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'}); -- cgit v1.2.1 From ea1d9968a9439272b58593e6b2ccbb3869002b20 Mon Sep 17 00:00:00 2001 From: ivan Date: Mon, 20 Oct 2003 04:25:18 +0000 Subject: daily/weekly billing --- FS/bin/freeside-setup | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-setup b/FS/bin/freeside-setup index b7b45dc63..375a63c2f 100755 --- a/FS/bin/freeside-setup +++ b/FS/bin/freeside-setup @@ -678,7 +678,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, -- cgit v1.2.1 From f63c0e821610c885f9f49d301eeccf804e1ca6d3 Mon Sep 17 00:00:00 2001 From: ivan Date: Fri, 24 Oct 2003 19:30:44 +0000 Subject: cvv! --- FS/bin/freeside-setup | 1 + 1 file changed, 1 insertion(+) (limited to 'FS/bin') diff --git a/FS/bin/freeside-setup b/FS/bin/freeside-setup index 375a63c2f..80b74c1f1 100755 --- a/FS/bin/freeside-setup +++ b/FS/bin/freeside-setup @@ -502,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, -- cgit v1.2.1 From ef27ba4362bc3ffac006237b5a73c496a5ee51a0 Mon Sep 17 00:00:00 2001 From: ivan Date: Thu, 6 Nov 2003 13:37:21 +0000 Subject: removing (rewritten as a proper html report) --- FS/bin/freeside-receivables-report | 217 ------------------------------------- 1 file changed, 217 deletions(-) delete mode 100755 FS/bin/freeside-receivables-report (limited to 'FS/bin') 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, config.html from the base documentation - -=head1 AUTHOR - -Jeff Finucane - -based on print-batch by Joel Griffiths - -=cut - -- cgit v1.2.1 From 17b3560111539da506f7f6bb575dd3776375466f Mon Sep 17 00:00:00 2001 From: ivan Date: Fri, 14 Nov 2003 08:43:24 +0000 Subject: hopefully recover better from lost ssh connections --- FS/bin/freeside-selfservice-server | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-selfservice-server b/FS/bin/freeside-selfservice-server index 05fa72b43..d2358e33c 100644 --- a/FS/bin/freeside-selfservice-server +++ b/FS/bin/freeside-selfservice-server @@ -74,7 +74,13 @@ 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; + last; + } warn "packet received\n". join('', map { " $_=>$packet->{$_}\n" } keys %$packet ) if $Debug > 1; @@ -120,6 +126,9 @@ while (1) { } + warn "connection lost, reconnecting\n" if $Debug; + sleep 3; + } ### -- cgit v1.2.1 From ded62e3a3ab9b930593d36be3f2b32bda2433f07 Mon Sep 17 00:00:00 2001 From: ivan Date: Sat, 15 Nov 2003 07:28:26 +0000 Subject: kill off ssh process when re-opening connection --- FS/bin/freeside-selfservice-server | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'FS/bin') diff --git a/FS/bin/freeside-selfservice-server b/FS/bin/freeside-selfservice-server index d2358e33c..f9571fa1e 100644 --- a/FS/bin/freeside-selfservice-server +++ b/FS/bin/freeside-selfservice-server @@ -79,6 +79,11 @@ while (1) { 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". -- cgit v1.2.1 From a5bc5bcbadafe55b31d9e97fccb6122477e390fb Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 10 Dec 2003 22:51:06 +0000 Subject: add part_referral.disabled, add disabled indices to agent and part_bill_event --- FS/bin/freeside-setup | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-setup b/FS/bin/freeside-setup index 80b74c1f1..4e3a09aad 100755 --- a/FS/bin/freeside-setup +++ b/FS/bin/freeside-setup @@ -342,7 +342,7 @@ sub tables_hash_hack { ], 'primary_key' => 'agentnum', 'unique' => [], - 'index' => [ ['typenum'] ], + 'index' => [ ['typenum'], ['diabled'] ], }, 'agent_type' => { @@ -408,7 +408,7 @@ sub tables_hash_hack { ], 'primary_key' => 'eventpart', 'unique' => [], - 'index' => [ ['payby'] ], + 'index' => [ ['payby'], ['disabled'], ], }, 'cust_bill_pkg' => { @@ -567,7 +567,7 @@ sub tables_hash_hack { ], 'primary_key' => 'paynum', 'unique' => [], - 'index' => [ [ 'custnum' ], [ 'paybatch' ] ], + 'index' => [ [ 'custnum' ], [ 'paybatch' ], [ 'payby' ], [ '_date' ] ], }, 'cust_bill_pay' => { @@ -718,10 +718,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' => { -- cgit v1.2.1 From cfebba4f8a73501b86d7a14037de88c0c87c758e Mon Sep 17 00:00:00 2001 From: ivan Date: Sun, 21 Dec 2003 21:12:43 +0000 Subject: add outsourced databases with both addresses by default --- FS/bin/freeside-addoutsourceuser | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'FS/bin') 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 ) -- cgit v1.2.1 From d20581bcbf2809d5c2969d773b16a0c8714a6dec Mon Sep 17 00:00:00 2001 From: ivan Date: Tue, 23 Dec 2003 01:49:32 +0000 Subject: add svc_external --- FS/bin/freeside-setup | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'FS/bin') diff --git a/FS/bin/freeside-setup b/FS/bin/freeside-setup index 4e3a09aad..fce8bc750 100755 --- a/FS/bin/freeside-setup +++ b/FS/bin/freeside-setup @@ -1120,6 +1120,17 @@ sub tables_hash_hack { 'index' => [ [ 'svcnum' ] ], }, + 'svc_external' => { + 'columns' => [ + 'svcnum', 'int', '', '', + 'id', 'int', '', '', + 'title', 'varchar', 'NULL', $char_d, + ], + 'primary_key' => 'svcnum', + 'unique' => [], + 'index' => [], + }, + ); %tables; -- cgit v1.2.1 From 9617ce4b230c7dc56b4fa4a50d805ddaef87d090 Mon Sep 17 00:00:00 2001 From: khoff Date: Wed, 24 Dec 2003 18:18:21 +0000 Subject: tyop --- FS/bin/freeside-setup | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-setup b/FS/bin/freeside-setup index fce8bc750..b7a414ae2 100755 --- a/FS/bin/freeside-setup +++ b/FS/bin/freeside-setup @@ -342,7 +342,7 @@ sub tables_hash_hack { ], 'primary_key' => 'agentnum', 'unique' => [], - 'index' => [ ['typenum'], ['diabled'] ], + 'index' => [ ['typenum'], ['disabled'] ], }, 'agent_type' => { -- cgit v1.2.1 From 95558fc7bcc98138db7f2d54cd5e6724bac3beea Mon Sep 17 00:00:00 2001 From: ivan Date: Fri, 30 Jan 2004 01:10:28 +0000 Subject: add support for running selfservice server against multiple machines --- FS/bin/freeside-selfservice-server | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-selfservice-server b/FS/bin/freeside-selfservice-server index f9571fa1e..371a646b4 100644 --- a/FS/bin/freeside-selfservice-server +++ b/FS/bin/freeside-selfservice-server @@ -34,8 +34,9 @@ $kids = 0; my $user = shift or die &usage; my $machine = shift or die &usage; my $tag = scalar(@ARGV) ? shift : ''; -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 + +# $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: $!"; -- cgit v1.2.1 From c7e637f35948396ca2bf760160f2a1a3081e0484 Mon Sep 17 00:00:00 2001 From: ivan Date: Sat, 31 Jan 2004 06:33:40 +0000 Subject: add pkg_svc.primary_svc flag to enable an explicit first package flag --- FS/bin/freeside-setup | 1 + 1 file changed, 1 insertion(+) (limited to 'FS/bin') diff --git a/FS/bin/freeside-setup b/FS/bin/freeside-setup index b7a414ae2..72780e363 100755 --- a/FS/bin/freeside-setup +++ b/FS/bin/freeside-setup @@ -708,6 +708,7 @@ sub tables_hash_hack { 'pkgpart', 'int', '', '', 'svcpart', 'int', '', '', 'quantity', 'int', '', '', + 'primary_svc','char', 'NULL', 1, ], 'primary_key' => '', 'unique' => [ ['pkgpart', 'svcpart'] ], -- cgit v1.2.1 From 07930a9141f823787a7e9c1e88fef453eb850fc7 Mon Sep 17 00:00:00 2001 From: ivan Date: Fri, 13 Feb 2004 10:35:42 +0000 Subject: add svc_forward.src --- FS/bin/freeside-setup | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-setup b/FS/bin/freeside-setup index 72780e363..feebcf9f7 100755 --- a/FS/bin/freeside-setup +++ b/FS/bin/freeside-setup @@ -844,8 +844,9 @@ sub tables_hash_hack { 'columns' => [ 'svcnum', 'int', '', '', 'srcsvc', 'int', '', '', + 'src', 'varchar', 'NULL', 255, 'dstsvc', 'int', '', '', - 'dst', 'varchar', 'NULL', $char_d, + 'dst', 'varchar', 'NULL', 255, ], 'primary_key' => 'svcnum', 'unique' => [], -- cgit v1.2.1 From 1e2a5c920840e046e4e28ca35681cb0912322666 Mon Sep 17 00:00:00 2001 From: ivan Date: Fri, 13 Feb 2004 10:57:55 +0000 Subject: continue adding svc_forward.src: make svc_forward.srcsvc nullable --- FS/bin/freeside-setup | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-setup b/FS/bin/freeside-setup index feebcf9f7..7512cc18c 100755 --- a/FS/bin/freeside-setup +++ b/FS/bin/freeside-setup @@ -842,10 +842,10 @@ sub tables_hash_hack { 'svc_forward' => { 'columns' => [ - 'svcnum', 'int', '', '', - 'srcsvc', 'int', '', '', + 'svcnum', 'int', '', '', + 'srcsvc', 'int', 'NULL', '', 'src', 'varchar', 'NULL', 255, - 'dstsvc', 'int', '', '', + 'dstsvc', 'int', 'NULL', '', 'dst', 'varchar', 'NULL', 255, ], 'primary_key' => 'svcnum', -- cgit v1.2.1 From 1b15d4bbb47875129b8da15331b118a6ad6727f3 Mon Sep 17 00:00:00 2001 From: ivan Date: Fri, 5 Mar 2004 05:59:16 +0000 Subject: fix -v --- FS/bin/freeside-daily | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-daily b/FS/bin/freeside-daily index 5fb966665..00de2987a 100755 --- a/FS/bin/freeside-daily +++ b/FS/bin/freeside-daily @@ -16,7 +16,7 @@ my $user = shift or die &usage; adminsuidsetup $user; -$FS::cust_main::Debug = 1 if $opt_v; +$FS::cust_main::DEBUG = 1 if $opt_v; my %search; $search{'payby'} = $opt_p if $opt_p; -- cgit v1.2.1 From e2a2f2f1a1a793581de4222e582731e7a9692a6b Mon Sep 17 00:00:00 2001 From: ivan Date: Thu, 11 Mar 2004 08:54:52 +0000 Subject: turn down logging level --- FS/bin/freeside-selfservice-server | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-selfservice-server b/FS/bin/freeside-selfservice-server index 371a646b4..03c7135b2 100644 --- a/FS/bin/freeside-selfservice-server +++ b/FS/bin/freeside-selfservice-server @@ -24,7 +24,7 @@ use FS::Conf; use FS::cust_bill; use FS::cust_pkg; -$Debug = 2; # >= 2 will log packet contents, including potentially compromising +$Debug = 1; # >= 2 will log packet contents, including potentially compromising # information $shutdown = 0; -- cgit v1.2.1 From cccf2f33d38b693c2742b5806e32d892d31b4374 Mon Sep 17 00:00:00 2001 From: ivan Date: Thu, 18 Mar 2004 01:46:40 +0000 Subject: require Storable minimum 2.09 --- FS/bin/freeside-selfservice-server | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-selfservice-server b/FS/bin/freeside-selfservice-server index 03c7135b2..864c2d46e 100644 --- a/FS/bin/freeside-selfservice-server +++ b/FS/bin/freeside-selfservice-server @@ -15,7 +15,7 @@ use POSIX qw(:sys_wait_h setsid); use IO::Handle; use IO::Select; use IO::File; -use Storable qw(nstore_fd fd_retrieve); +use Storable 2.09 qw(nstore_fd fd_retrieve); use Net::SSH qw(sshopen2); use FS::UID qw(adminsuidsetup forksuidsetup); use FS::ClientAPI; -- cgit v1.2.1 From db1025e6dcb7b5d68c08a455db0b0326bf8ecc62 Mon Sep 17 00:00:00 2001 From: ivan Date: Thu, 1 Apr 2004 00:44:33 +0000 Subject: get sub-countries from Locale::SubCountry now --- FS/bin/freeside-setup | 82 ++++++++++++++++++++------------------------------- 1 file changed, 32 insertions(+), 50 deletions(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-setup b/FS/bin/freeside-setup index 7512cc18c..522c0a1a2 100755 --- a/FS/bin/freeside-setup +++ b/FS/bin/freeside-setup @@ -6,6 +6,8 @@ BEGIN { $FS::Record::setup_hack = 1; } use strict; use vars qw($opt_s); use Getopt::Std; +use Locale::Country; +use Locale::SubCountry; use DBI; use DBIx::DBSchema 0.21; use DBIx::DBSchema::Table; @@ -230,60 +232,40 @@ foreach my $statement ( $dbdef->sql($dbh) ) { or die "CREATE error: ". $dbh->errstr. "\ndoing statement: $statement"; } -#not really sample data (and shouldn't default to US) - #cust_main_county +foreach my $country ( sort map uc($_), all_country_codes ) { -#USPS state codes -foreach ( qw( -AL AK AS AZ AR CA CO CT DC DE FM FL GA GU HI ID IL IN IA KS KY LA -ME MH MD MA MI MN MS MO MT NC ND NE NH NJ NM NV NY MP OH OK OR PA PW PR RI -SC SD TN TX UT VT VI VA WA WV WI WY AE AA AP -) ) { - my($cust_main_county)=new FS::cust_main_county({ - 'state' => $_, - 'tax' => 0, - 'country' => 'US', - }); - my($error); - $error=$cust_main_county->insert; - die $error if $error; -} + my $subcountry = eval { new Locale::SubCountry($country) }; + my @states = $subcountry ? $subcountry->all_codes : undef; -#AU "offical" state codes ala mark.williamson@ebbs.com.au (Mark Williamson) -foreach ( qw( -VIC NSW NT QLD TAS ACT WA SA -) ) { - my($cust_main_county)=new FS::cust_main_county({ - 'state' => $_, - 'tax' => 0, - 'country' => 'AU', - }); - my($error); - $error=$cust_main_county->insert; - die $error if $error; -} + if ( !scalar(@states) || ( scalar(@states) == 1 && !defined($states[0]) ) ) { -#ISO 2-letter country codes (same as country TLDs) except US and AU -foreach ( qw( -AF AL DZ AS AD AO AI AQ AG AR AM AW AT AZ BS BH BD BB BY BE BZ BJ BM BT BO -BA BW BV BR IO BN BG BF BI KH CM CA CV KY CF TD CL CN CX CC CO KM CG CK CR CI -HR CU CY CZ DK DJ DM DO TP EC EG SV GQ ER EE ET FK FO FJ FI FR FX GF PF TF GA -GM GE DE GH GI GR GL GD GP GU GT GN GW GY HT HM HN HK HU IS IN ID IR IQ IE IL -IT JM JP JO KZ KE KI KP KR KW KG LA LV LB LS LR LY LI LT LU MO MK MG MW MY MV -ML MT MH MQ MR MU YT MX FM MD MC MN MS MA MZ MM NA NR NP NL AN NC NZ NI NE NG -NU NF MP NO OM PK PW PA PG PY PE PH PN PL PT PR QA RE RO RU RW KN LC VC WS SM -ST SA SN SC SL SG SK SI SB SO ZA GS ES LK SH PM SD SR SJ SZ SE CH SY TW TJ TZ -TH TG TK TO TT TN TR TM TC TV UG UA AE GB UM UY UZ VU VA VE VN VG VI WF EH -YE YU ZR ZM ZW -) ) { - my($cust_main_county)=new FS::cust_main_county({ - 'tax' => 0, - 'country' => $_, - }); - my($error); - $error=$cust_main_county->insert; - die $error if $error; + my $cust_main_county = new FS::cust_main_county({ + 'tax' => 0, + 'country' => $country, + }); + my $error = $cust_main_county->insert; + die $error if $error; + + } else { + + if ( $states[0] =~ /^(\d+|\w)$/ ) { + @states = map $subcountry->full_name($_), @states + } + + foreach my $state ( @states ) { + + my $cust_main_county = new FS::cust_main_county({ + 'state' => $state, + 'tax' => 0, + 'country' => $country, + }); + my $error = $cust_main_county->insert; + die $error if $error; + + } + + } } #billing events -- cgit v1.2.1 From 3d7ce17fee0a42b8d476ae7e7eaeef5fc24043d0 Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 7 Apr 2004 13:11:20 +0000 Subject: added options to select username, svcnum, svcpart --- FS/bin/freeside-reexport | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-reexport b/FS/bin/freeside-reexport index b5c50a422..34ccbc715 100644 --- a/FS/bin/freeside-reexport +++ b/FS/bin/freeside-reexport @@ -1,6 +1,8 @@ -#!/usr/bin/perl -Tw +#!/usr/bin/perl -w use strict; +use vars qw($opt_s $opt_u $opt_p); +use Getopt::Std; use FS::UID qw(adminsuidsetup); use FS::Record qw(qsearch qsearchs); use FS::part_export; @@ -20,20 +22,27 @@ if ( $export_x =~ /^(\d+)$/ ) { or die "no exports of type $export_x found\n"; } -my $svc_something = shift or die &usage; -my $svc_x; -if ( $svc_something =~ /^(\d+)$/ ) { - my $cust_svc = qsearchs('cust_svc', { svcnum=>$1 } ) - or die "svcnum $svc_something not found\n"; - $svc_x = $cust_svc->svc_x; -} else { - $svc_x = qsearchs('svc_acct', { username=>$svc_something } ) - or die "username $svc_something not found\n"; +getopts('s:u:p:'); + +my @svc_x = (); +if ( $opt_s ) { + my $cust_svc = qsearchs('cust_svc', { svcnum=>$opt_s } ) + or die "svcnum $opt_s not found\n"; + push @svc_x, $cust_svc->svc_x; +} elsif ( $opt_u ) { + my $svc_x = qsearchs('svc_acct', { username=>$opt_u } ) + or die "username $opt_u not found\n"; + push @svc_x, $svc_x; +} elsif ( $opt_p ) { + push @svc_x, map { $_->svc_x } qsearch('cust_svc', { svcpart=>$opt_p } ); + die "no services with svcpart $opt_p found\n" unless @svc_x; } foreach my $part_export ( @part_export ) { - my $error = $part_export->export_insert($svc_x); - die $error if $error; + foreach my $svc_x ( @svc_x ) { + my $error = $part_export->export_insert($svc_x); + die $error if $error; + } } @@ -47,7 +56,7 @@ freeside-reexport - Command line tool to re-trigger export jobs for existing ser =head1 SYNOPSIS - freeside-reexport user exportnum|exporttype svcnum|username + freeside-reexport user exportnum|exporttype [ -s svcnum | -u username | -p svcpart ] =head1 DESCRIPTION -- cgit v1.2.1 From fad8705f1dacd35d394c8a0290fdd0a372400bc1 Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 7 Apr 2004 13:12:17 +0000 Subject: oops, update the usage too --- FS/bin/freeside-reexport | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-reexport b/FS/bin/freeside-reexport index 34ccbc715..54af9dd80 100644 --- a/FS/bin/freeside-reexport +++ b/FS/bin/freeside-reexport @@ -47,7 +47,7 @@ foreach my $part_export ( @part_export ) { sub usage { - die "Usage:\n\n freeside-reexport user exportnum|exporttype svcnum|username\n"; + die "Usage:\n\n freeside-reexport user exportnum|exporttype [ -s svcnum | -u username | -p svcpart ]\n"; } =head1 NAME -- cgit v1.2.1 From c29fa7acc16efcc86af06077e739fca8b783c3c1 Mon Sep 17 00:00:00 2001 From: ivan Date: Fri, 23 Apr 2004 13:15:17 +0000 Subject: add link to new credit report on main menu, remove old obsolete shell-out reports --- FS/bin/freeside-cc-receipts-report | 270 ------------------------------------- FS/bin/freeside-credit-report | 224 ------------------------------ 2 files changed, 494 deletions(-) delete mode 100755 FS/bin/freeside-cc-receipts-report delete mode 100755 FS/bin/freeside-credit-report (limited to 'FS/bin') diff --git a/FS/bin/freeside-cc-receipts-report b/FS/bin/freeside-cc-receipts-report deleted file mode 100755 index 136851aec..000000000 --- a/FS/bin/freeside-cc-receipts-report +++ /dev/null @@ -1,270 +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 qsearchs); -use FS::cust_pay; -use FS::cust_pay_batch; - - -&untaint_argv; #what it sounds like (eww) -use vars qw($opt_v $opt_p $opt_m $opt_e $opt_t $opt_s $opt_f $report_lines $report_template @buf $header); -getopts("vpmef:s:"); #switches - -#we're at now now (and later). -my($_finishdate)= $opt_f ? str2time($main::opt_f) : $^T; -my($_startdate)= $opt_s ? str2time($main::opt_s) : $^T; - -# Get the current month -my ($ssec,$smin,$shour,$smday,$smon,$syear) = - (localtime($_startdate) )[0,1,2,3,4,5]; -$smon++; -$syear += 1900; - -# Get the current month -my ($fsec,$fmin,$fhour,$fmday,$fmon,$fyear) = - (localtime($_finishdate) )[0,1,2,3,4,5]; -$fmon++; -$fyear += 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(@cust_pays)=qsearch('cust_pay',{}); -if (scalar(@cust_pays) == 0) -{ - exit 1; -} - -# Open print and email pipes -# $lpr and opt_p for printing -# $email and opt_m for email - -if ($lpr && $main::opt_p) -{ - open(LPR, "|$lpr"); -} - -if ($email && $main::opt_m) -{ - $ENV{MAILADDRESS} = $mail_sender; - $header = new Mail::Header ( [ - "From: Account Processor", - "To: $email", - "Sender: $mail_sender", - "Reply-To: $mail_sender", - "Subject: Credit Card Receipts", - ] ); -} - -my $uninvoiced = 0; -my $total = 0; -my $taxed = 0; -my $untaxed = 0; -my $total_tax = 0; - -# Now I can start looping -foreach my $cust_pay (@cust_pays) -{ - my $_date = $cust_pay->getfield('_date'); - my $invnum = $cust_pay->getfield('invnum'); - my $paid = $cust_pay->getfield('paid'); - my $payby = $cust_pay->getfield('payby'); - - - if ($_date >= $_startdate && $_date <= $_finishdate && $payby =~ 'CARD') { - $total += $paid; - - $uninvoiced += $cust_pay->unapplied; - my @cust_bill_pays = $cust_pay->cust_bill_pay; - foreach my $cust_bill_pay (@cust_bill_pays) { - my $invoice_amt =0; - my $invoice_tax =0; - my(@cust_bill_pkgs)= $cust_bill_pay->cust_bill->cust_bill_pkg; - foreach my $cust_bill_pkg (@cust_bill_pkgs) { - - my $recur = $cust_bill_pkg->getfield('recur'); - my $setup = $cust_bill_pkg->getfield('setup'); - my $pkgnum = $cust_bill_pkg->getfield('pkgnum'); - - if ($pkgnum == 0) { - $invoice_tax += $recur; - $invoice_tax += $setup; - } else { - $invoice_amt += $recur; - $invoice_amt += $setup; - } - - } - - if ($invoice_tax > 0) { - if ($invoice_amt != $paid) { - # attempt to prorate partially paid invoices - $total_tax += $paid / ($invoice_amt + $invoice_tax) * $invoice_tax; - $taxed += $paid / ($invoice_amt + $invoice_tax) * $invoice_amt; - } else { - $total_tax += $invoice_tax; - $taxed += $invoice_amt; - } - } else { - $untaxed += $paid; - } - - } - - } - -} - -push @buf, sprintf(qq{\n%25s%14.2f\n}, "Uninvoiced", $uninvoiced); -push @buf, sprintf(qq{%25s%14.2f\n}, "Untaxed", $untaxed); -push @buf, sprintf(qq{%25s%14.2f\n}, "Taxed", $taxed); -push @buf, sprintf(qq{%25s%14.2f\n}, "Tax", $total_tax); -push @buf, sprintf(qq{\n%39s\n%39.2f\n}, "=========", $total); - -sub FS::cc_receipts_report::_template::report_lines { - my $lines = shift; - map { - scalar(@buf) ? shift @buf : '' ; - } - ( 1 .. $lines ); -} - -$FS::cc_receipts_report::_template::title = qq~CREDIT CARD RECEIPTS for period $smon/$smday/$syear through $fmon/$fmday/$fyear~; -$FS::cc_receipts_report::_template::title = $opt_t if $opt_t; -$FS::cc_receipts_report::_template::page = 1; -$FS::cc_receipts_report::_template::date = $^T; -$FS::cc_receipts_report::_template::date = $^T; -$FS::cc_receipts_report::_template::fdate = $_finishdate; -$FS::cc_receipts_report::_template::fdate = $_finishdate; -$FS::cc_receipts_report::_template::sdate = $_startdate; -$FS::cc_receipts_report::_template::sdate = $_startdate; -$FS::cc_receipts_report::_template::total_pages = - int( scalar(@buf) / $report_lines); -$FS::cc_receipts_report::_template::total_pages++ if scalar(@buf) % $report_lines; - -my @report; -while (@buf) { - push @report, split("\n", - $report_template->fill_in( PACKAGE => 'FS::cc_receipts_report::_template' ) - ); - $FS::cc_receipts_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-cc-receipts-report [-v] [-p] [-e] user\n"; -} - -=head1 NAME - -freeside-cc-receipts-report - Prints or emails total credit card receipts in a given period. - -=head1 SYNOPSIS - - freeside-cc-receipts-report [-v] [-p] [-m] [-e] [-t "title"] [-s date] [-f date] user - -=head1 DESCRIPTION - -Prints or emails sales taxes invoiced in a given period. - --v: Verbose - Prints records to STDOUT. - --p: Print to printer lpr as found in the conf directory. - --m: Email output to user found in the Conf email file. - --e: Print a final form feed to the printer. - --t: supply a title for the top of each page. - --s: starting date for inclusion - --f: final date for inclusion - -user: From the mapsecrets file - see config.html from the base documentation - -=head1 VERSION - -$Id: freeside-cc-receipts-report,v 1.5 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, config.html from the base documentation - -=head1 AUTHOR - -Jeff Finucane - -based on print-batch by Joel Griffiths - -=cut - diff --git a/FS/bin/freeside-credit-report b/FS/bin/freeside-credit-report deleted file mode 100755 index 410dabe8f..000000000 --- a/FS/bin/freeside-credit-report +++ /dev/null @@ -1,224 +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_credit; - - -&untaint_argv; #what it sounds like (eww) -use vars qw($opt_v $opt_p $opt_m $opt_e $opt_t $opt_s $opt_f $report_lines $report_template @buf $header); -getopts("vpmef:s:"); #switches - -#we're at now now (and later). -my($_finishdate)= $opt_f ? str2time($main::opt_f) : $^T; -my($_startdate)= $opt_s ? str2time($main::opt_s) : $^T; - -# Get the current month -my ($ssec,$smin,$shour,$smday,$smon,$syear) = - (localtime($_startdate) )[0,1,2,3,4,5]; -$smon++; -$syear += 1900; - -# Get the current month -my ($fsec,$fmin,$fhour,$fmday,$fmon,$fyear) = - (localtime($_finishdate) )[0,1,2,3,4,5]; -$fmon++; -$fyear += 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(@cust_credits)=qsearch('cust_credit',{}); -if (scalar(@cust_credits) == 0) -{ - exit 1; -} - -# Open print and email pipes -# $lpr and opt_p for printing -# $email and opt_m for email - -if ($lpr && $main::opt_p) -{ - open(LPR, "|$lpr"); -} - -if ($email && $main::opt_m) -{ - $ENV{MAILADDRESS} = $mail_sender; - $header = new Mail::Header ( [ - "From: Account Processor", - "To: $email", - "Sender: $mail_sender", - "Reply-To: $mail_sender", - "Subject: In House Credits", - ] ); -} - -my $uninvoiced = 0; -my $total = 0; -my $taxed = 0; -my $untaxed = 0; -my $total_tax = 0; - -# Now I can start looping -foreach my $cust_credit (@cust_credits) -{ - my $_date = $cust_credit->getfield('_date'); - my $amount = $cust_credit->getfield('amount'); - - if ($_date >= $_startdate && $_date <= $_finishdate) { - $total += $amount; - } -} - -push @buf, sprintf(qq{\n%25s%14.2f\n}, "Credits Offered", $total); -push @buf, sprintf(qq{\n%39s\n%39.2f\n}, "=========", $total); - -sub FS::credit_report::_template::report_lines { - my $lines = shift; - map { - scalar(@buf) ? shift @buf : '' ; - } - ( 1 .. $lines ); -} - -$FS::credit_report::_template::title = qq~IN HOUSE CREDITS for $smon/$smday/$syear through $fmon/$fmday/$fyear~; -$FS::credit_report::_template::title = $opt_t if $opt_t; -$FS::credit_report::_template::page = 1; -$FS::credit_report::_template::date = $^T; -$FS::credit_report::_template::date = $^T; -$FS::credit_report::_template::fdate = $_finishdate; -$FS::credit_report::_template::fdate = $_finishdate; -$FS::credit_report::_template::sdate = $_startdate; -$FS::credit_report::_template::sdate = $_startdate; -$FS::credit_report::_template::total_pages = - int( scalar(@buf) / $report_lines); -$FS::credit_report::_template::total_pages++ if scalar(@buf) % $report_lines; - -my @report; -while (@buf) { - push @report, split("\n", - $report_template->fill_in( PACKAGE => 'FS::credit_report::_template' ) - ); - $FS::credit_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-credit-report [-v] [-p] [-e] user\n"; -} - -=head1 NAME - -freeside-credit-report - Prints or emails total credit memos in a given period. - -=head1 SYNOPSIS - - freeside-credit-report [-v] [-p] [-m] [-e] [-t "title"] [-s date] [-f date] user - -=head1 DESCRIPTION - -Prints or emails total credit memos in a given period. - --v: Verbose - Prints records to STDOUT. - --p: Print to printer lpr as found in the conf directory. - --m: Email output to user found in the Conf email file. - --e: Print a final form feed to the printer. - --t: supply a title for the top of each page. - --s: starting date for inclusion - --f: final date for inclusion - -user: From the mapsecrets file - see config.html from the base documentation - -=head1 VERSION - -$Id: freeside-credit-report,v 1.5 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, config.html from the base documentation - -=head1 AUTHOR - -Jeff Finucane - -based on print-batch by Joel Griffiths - -=cut - -- cgit v1.2.1 From 8f6a34b553a7ca9b7fc9c9cf5802ce418e3a5296 Mon Sep 17 00:00:00 2001 From: ivan Date: Fri, 11 Jun 2004 13:44:40 +0000 Subject: tax report! --- FS/bin/freeside-tax-report | 292 --------------------------------------------- 1 file changed, 292 deletions(-) delete mode 100755 FS/bin/freeside-tax-report (limited to 'FS/bin') diff --git a/FS/bin/freeside-tax-report b/FS/bin/freeside-tax-report deleted file mode 100755 index 240f3ad37..000000000 --- a/FS/bin/freeside-tax-report +++ /dev/null @@ -1,292 +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_bill; -use FS::cust_bill_pay; -use FS::cust_pay; - - -&untaint_argv; #what it sounds like (eww) -use vars qw($opt_v $opt_p $opt_m $opt_e $opt_t $opt_s $opt_f $report_lines $report_template @buf $header); -getopts("vpmef:s:"); #switches - -#we're at now now (and later). -my($_finishdate)= $opt_f ? str2time($main::opt_f) : $^T; -my($_startdate)= $opt_s ? str2time($main::opt_s) : $^T; - -# Get the current month -my ($ssec,$smin,$shour,$smday,$smon,$syear) = - (localtime($_startdate) )[0,1,2,3,4,5]; -$smon++; -$syear += 1900; - -# Get the current month -my ($fsec,$fmin,$fhour,$fmday,$fmon,$fyear) = - (localtime($_finishdate) )[0,1,2,3,4,5]; -$fmon++; -$fyear += 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(@cust_bills)=qsearch('cust_bill',{}); -if (scalar(@cust_bills) == 0) -{ - exit 1; -} - -# Open print and email pipes -# $lpr and opt_p for printing -# $email and opt_m for email - -if ($lpr && $main::opt_p) -{ - open(LPR, "|$lpr"); -} - -if ($email && $main::opt_m) -{ - $ENV{MAILADDRESS} = $mail_sender; - $header = new Mail::Header ( [ - "From: Account Processor", - "To: $email", - "Sender: $mail_sender", - "Reply-To: $mail_sender", - "Subject: Sales Taxes Invoiced", - ] ); -} - -my $comped = 0; -my $comped_tax = 0; -my $other = 0; -my $other_tax = 0; -my $total = 0; -my $taxed = 0; -my $untaxed = 0; -my $total_tax = 0; - -# Now I can start looping -foreach my $cust_bill (@cust_bills) -{ - my $_date = $cust_bill->getfield('_date'); - my $invnum = $cust_bill->getfield('invnum'); - my $charged = $cust_bill->getfield('charged'); - - if ($_date >= $_startdate && $_date <= $_finishdate) { - $total += $charged; - - # The following lines were used to produce rather verbose reports - #my ($sec,$min,$hour,$mday,$mon,$year) = - # (localtime($_date) )[0,1,2,3,4,5]; - #$mon++; - #$year -= 100 if $year >= 100; - #$year = "0" . $year if $year < 10; - - my $invoice_amt =0; - my $invoice_tax =0; - my $invoice_comped =0; - my(@cust_bill_pkgs)= $cust_bill->cust_bill_pkg; - foreach my $cust_bill_pkg (@cust_bill_pkgs) { - - my $recur = $cust_bill_pkg->getfield('recur'); - my $setup = $cust_bill_pkg->getfield('setup'); - my $pkgnum = $cust_bill_pkg->getfield('pkgnum'); - - if ($pkgnum == 0) { - # The following line was used to produce rather verbose reports - # push @buf, ('', sprintf(qq{%10s%15s%14.2f}, "$mon/$mday/$year", "Tax $invnum", $recur+$setup)); - $invoice_tax += $recur; - $invoice_tax += $setup; - } else { - # The following line was used to produce rather verbose reports - # push @buf, ('', sprintf(qq{%10s%15s%14.2f}, "$mon/$mday/$year", "Inv $invnum", $recur+$setup)); - $invoice_amt += $recur; - $invoice_amt += $setup; - } - - } - - my(@cust_bill_pays)= $cust_bill->cust_bill_pay; - foreach my $cust_bill_pay (@cust_bill_pays) { - my $payby = $cust_bill_pay->cust_pay->payby; - my $paid = $cust_bill_pay->getfield('amount'); - if ($payby =~ 'COMP') { - $invoice_comped += $paid; - } - } - - if (abs($invoice_comped - ($invoice_amt + $invoice_tax)) < 0.0001){ - $comped += $invoice_amt; - $comped_tax += $invoice_tax; - } elsif ($invoice_comped > 0) { - push @buf, sprintf(qq{\nInvoice %10d has inexpliciable complimentary payments of %14.9f\n}, $invnum, $invoice_comped); - $other += $invoice_amt; - $other_tax += $invoice_tax; - } elsif ($invoice_tax > 0) { - $total_tax += $invoice_tax; - $taxed += $invoice_amt; - } else { - $untaxed += $invoice_amt; - } - - } - -} - -push @buf, ('', sprintf(qq{%25s%14.2f}, "Complimentary", $comped)); -push @buf, sprintf(qq{%25s%14.2f}, "Complimentary Tax", $comped_tax); -push @buf, sprintf(qq{%25s%14.2f}, "Other", $other); -push @buf, sprintf(qq{%25s%14.2f}, "Other Tax", $other_tax); -push @buf, sprintf(qq{%25s%14.2f}, "Untaxed", $untaxed); -push @buf, sprintf(qq{%25s%14.2f}, "Taxed", $taxed); -push @buf, sprintf(qq{%25s%14.2f}, "Tax", $total_tax); -push @buf, ('', sprintf(qq{%39s}, "========="), sprintf(qq{%39.2f}, $total)); - -sub FS::tax_report::_template::report_lines { - my $lines = shift; - map { - scalar(@buf) ? shift @buf : '' ; - } - ( 1 .. $lines ); -} - -$FS::tax_report::_template::title = qq~SALES TAXES INVOICED for $smon/$smday/$syear through $fmon/$fmday/$fyear~; -$FS::tax_report::_template::title = $opt_t if $opt_t; -$FS::tax_report::_template::page = 1; -$FS::tax_report::_template::date = $^T; -$FS::tax_report::_template::date = $^T; -$FS::tax_report::_template::fdate = $_finishdate; -$FS::tax_report::_template::fdate = $_finishdate; -$FS::tax_report::_template::sdate = $_startdate; -$FS::tax_report::_template::sdate = $_startdate; -$FS::tax_report::_template::total_pages = - int( scalar(@buf) / $report_lines); -$FS::tax_report::_template::total_pages++ if scalar(@buf) % $report_lines; - -my @report; -while (@buf) { - push @report, split("\n", - $report_template->fill_in( PACKAGE => 'FS::tax_report::_template' ) - ); - $FS::tax_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-tax-report [-v] [-p] [-e] user\n"; -} - -=head1 NAME - -freeside-tax-report - Prints or emails sales taxes invoiced in a given period. - -=head1 SYNOPSIS - - freeside-tax-report [-v] [-p] [-m] [-e] [-t "title"] [-s date] [-f date] user - -=head1 DESCRIPTION - -Prints or emails sales taxes invoiced in a given period. - --v: Verbose - Prints records to STDOUT. - --p: Print to printer lpr as found in the conf directory. - --m: Email output to user found in the Conf email file. - --e: Print a final form feed to the printer. - --t: supply a title for the top of each page. - --s: starting date for inclusion - --f: final date for inclusion - -user: From the mapsecrets file - see config.html from the base documentation - -=head1 VERSION - -$Id: freeside-tax-report,v 1.5 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, config.html from the base documentation - -=head1 AUTHOR - -Jeff Finucane - -based on print-batch by Joel Griffiths - -=cut - -- cgit v1.2.1 From e7acc4af0a47299644ff2389be3991b708878693 Mon Sep 17 00:00:00 2001 From: ivan Date: Fri, 25 Jun 2004 10:25:02 +0000 Subject: ping the database and retry rather before doing anything --- FS/bin/freeside-queued | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-queued b/FS/bin/freeside-queued index 6ea27c05f..0be3d9d7a 100644 --- a/FS/bin/freeside-queued +++ b/FS/bin/freeside-queued @@ -7,7 +7,7 @@ use Fcntl qw(:flock); use POSIX qw(:sys_wait_h setsid); use Date::Format; use IO::File; -use FS::UID qw(adminsuidsetup forksuidsetup driver_name dbh); +use FS::UID qw(adminsuidsetup forksuidsetup driver_name dbh myconnect); use FS::Record qw(qsearch qsearchs); use FS::queue; use FS::queue_depend; @@ -75,18 +75,27 @@ while (1) { } $warnkids=0; - my $nodepend = driver_name eq 'mysql' - ? '' - : 'AND 0 = ( SELECT COUNT(*) FROM queue_depend'. - ' WHERE queue_depend.jobnum = queue.jobnum ) '; + my $dbh = dbh; + unless ( $dbh->ping ) { + warn "WARNING: connection to database lost, reconnecting...\n"; + myconnect; + unless ( $dbh->ping ) { + warn "WARNING: still no connection to database, sleeping for retry...\n"; + sleep 10; + next; + } + } #my($job, $ljob); #{ # my $oldAutoCommit = $FS::UID::AutoCommit; # local $FS::UID::AutoCommit = 0; $FS::UID::AutoCommit = 0; - my $dbh = dbh; + my $nodepend = driver_name eq 'mysql' + ? '' + : 'AND 0 = ( SELECT COUNT(*) FROM queue_depend'. + ' WHERE queue_depend.jobnum = queue.jobnum ) '; my $job = qsearchs( 'queue', { 'status' => 'new' }, -- cgit v1.2.1 From 157e8bdba110b7aac022bd2c2f7b377d3c5b2f85 Mon Sep 17 00:00:00 2001 From: ivan Date: Tue, 29 Jun 2004 04:02:45 +0000 Subject: add cust_pay_refund table to refund payments --- FS/bin/freeside-setup | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'FS/bin') diff --git a/FS/bin/freeside-setup b/FS/bin/freeside-setup index 522c0a1a2..33b3465e0 100755 --- a/FS/bin/freeside-setup +++ b/FS/bin/freeside-setup @@ -1115,6 +1115,21 @@ sub tables_hash_hack { 'index' => [], }, + 'cust_pay_refund' => { + 'columns' => [ + 'payrefundnum', 'serial', '', '', + 'paynum', 'int', '', '', + 'refundnum', 'int', '', '', + '_date', @date_type, + 'amount', @money_type, + ], + 'primary_key' => 'payrefundnum', + 'unique' => [], + 'index' => [ ['paynum'], ['refundnum'] ], + }, + + + ); %tables; -- cgit v1.2.1 From 6e606e4f3c8a27df62bb2f229a09fccca7bd4d6b Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 30 Jun 2004 10:02:45 +0000 Subject: add option to pgp/gpg encrypt scp dumps --- FS/bin/freeside-daily | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-daily b/FS/bin/freeside-daily index 00de2987a..99d95d5d2 100755 --- a/FS/bin/freeside-daily +++ b/FS/bin/freeside-daily @@ -63,7 +63,6 @@ if ( driver_name eq 'Pg' ) { } } -#local hack my $conf = new FS::Conf; my $dest = $conf->config('dump-scpdest'); if ( $dest ) { @@ -75,7 +74,18 @@ if ( $dest ) { } else { die "database dumps not yet supported for ". driver_name; } - scp("/var/tmp/$database.sql", $dest); + if ( $conf->config('dump-pgpid') ) { + eval 'use GnuPG'; + my $gpg = new GnuPG; + $gpg->encrypt( plaintext => "/var/tmp/$database.sql", + output => "/var/tmp/$database.gpg", + recipient => $conf->config('dump-pgpid'), + ); + scp("/var/tmp/$database.gpg", $dest); + unlink "/var/tmp/$database.gpg" or die $!; + } else { + scp("/var/tmp/$database.sql", $dest); + } unlink "/var/tmp/$database.sql" or die $!; } -- cgit v1.2.1 From cfe85e45bcba97089988b4dc22a895aec687f2c3 Mon Sep 17 00:00:00 2001 From: ivan Date: Tue, 6 Jul 2004 13:26:21 +0000 Subject: add cust_pay_void table and payment voiding web ui part one --- FS/bin/freeside-setup | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'FS/bin') diff --git a/FS/bin/freeside-setup b/FS/bin/freeside-setup index 33b3465e0..119b09d5d 100755 --- a/FS/bin/freeside-setup +++ b/FS/bin/freeside-setup @@ -552,6 +552,26 @@ sub tables_hash_hack { 'index' => [ [ 'custnum' ], [ 'paybatch' ], [ 'payby' ], [ '_date' ] ], }, + 'cust_pay_void' => { + 'columns' => [ + 'paynum', 'int', '', '', + 'custnum', 'int', '', '', + 'paid', @money_type, + '_date', @date_type, + 'payby', 'char', '', 4, # CARD/BILL/COMP, should be index into + # payment type table. + 'payinfo', 'varchar', 'NULL', $char_d, #see cust_main above + 'paybatch', 'varchar', 'NULL', $char_d, #for auditing purposes. + 'closed', 'char', 'NULL', 1, + 'void_date', @date_type, + 'reason', 'varchar', 'NULL', $char_d, + 'otaker', 'varchar', '', 32, + ], + 'primary_key' => 'paynum', + 'unique' => [], + 'index' => [ [ 'custnum' ] ], + }, + 'cust_bill_pay' => { 'columns' => [ 'billpaynum', 'serial', '', '', -- cgit v1.2.1 From c69dd0d922bba433b16e3408f71f1cac0e16a069 Mon Sep 17 00:00:00 2001 From: ivan Date: Thu, 29 Jul 2004 21:49:10 +0000 Subject: add index on cust_main.refnum, speeds up advertising source list --- FS/bin/freeside-setup | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-setup b/FS/bin/freeside-setup index 119b09d5d..386c4c7cd 100755 --- a/FS/bin/freeside-setup +++ b/FS/bin/freeside-setup @@ -498,7 +498,7 @@ sub tables_hash_hack { 'unique' => [], #'index' => [ ['last'], ['company'] ], 'index' => [ ['last'], [ 'company' ], [ 'referral_custnum' ], - [ 'daytime' ], [ 'night' ], [ 'fax' ], + [ 'daytime' ], [ 'night' ], [ 'fax' ], [ 'refnum' ], ], }, -- cgit v1.2.1 From 1df9be4f5d6129a768b809212d83e0648786ac0f Mon Sep 17 00:00:00 2001 From: ivan Date: Fri, 27 Aug 2004 11:16:03 +0000 Subject: add option to specify exports --- FS/bin/freeside-sqlradius-reset | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-sqlradius-reset b/FS/bin/freeside-sqlradius-reset index 74f90a582..95b7ef21e 100755 --- a/FS/bin/freeside-sqlradius-reset +++ b/FS/bin/freeside-sqlradius-reset @@ -12,9 +12,18 @@ adminsuidsetup $user; #my $machine = shift or die &usage; -my @exports = qsearch('part_export', { exporttype=>'sqlradius' } ); -push @exports, qsearch('part_export', { exporttype=>'sqlradius_withdomain' } ); - +my @exports = (); +if ( @_ ) { + foreach my $exportnum ( @_ ) { + foreach my $exporttype (qw( sqlradius sqlradius_withdomain )) { + push @exports, qsearch('part_export', { exportnum => $exportnum, + exporttype => $exporttype, } ); + } + } + } else { + @exports = qsearch('part_export', { exporttype=>'sqlradius' } ); + push @exports, qsearch('part_export', { exporttype=>'sqlradius_withdomain' } ); +} foreach my $export ( @exports ) { my $icradius_dbh = DBI->connect( @@ -47,8 +56,7 @@ foreach my $export ( @exports ) { } sub usage { - #die "Usage:\n\n sqlradius_reset user machine\n"; - die "Usage:\n\n freeside-sqlradius-reset user\n"; + die "Usage:\n\n freeside-sqlradius-reset user [ exportnum, ... ]\n"; } =head1 NAME @@ -57,12 +65,13 @@ freeside-sqlradius-reset - Command line interface to reset and recreate RADIUS S =head1 SYNOPSIS - freeside-sqlradius-reset username + freeside-sqlradius-reset username [ EXPORTNUM, ... ] =head1 DESCRIPTION Deletes the radcheck, radreply and usergroup tables and repopulates them from -the Freeside database, for all sqlradius exports. +the Freeside database, for the specified exports, or, if no exports are +specified, for all sqlradius and sqlradius_withdomain exports. B is a username added by freeside-adduser. -- cgit v1.2.1 From 4f9e876b1e2549e09bafc85289951bbb973194aa Mon Sep 17 00:00:00 2001 From: ivan Date: Fri, 27 Aug 2004 11:33:21 +0000 Subject: oops use @ARGV not @_ --- FS/bin/freeside-sqlradius-reset | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-sqlradius-reset b/FS/bin/freeside-sqlradius-reset index 95b7ef21e..d87cd4511 100755 --- a/FS/bin/freeside-sqlradius-reset +++ b/FS/bin/freeside-sqlradius-reset @@ -13,8 +13,8 @@ adminsuidsetup $user; #my $machine = shift or die &usage; my @exports = (); -if ( @_ ) { - foreach my $exportnum ( @_ ) { +if ( @ARGV ) { + foreach my $exportnum ( @ARGV ) { foreach my $exporttype (qw( sqlradius sqlradius_withdomain )) { push @exports, qsearch('part_export', { exportnum => $exportnum, exporttype => $exporttype, } ); -- cgit v1.2.1 From e9fe829de47a93ac77cacfda6f61b644a78a2929 Mon Sep 17 00:00:00 2001 From: ivan Date: Mon, 6 Sep 2004 09:28:10 +0000 Subject: don't die off even on database failures --- FS/bin/freeside-queued | 72 +++++++++++++++++++++++++++++++++++++------------- 1 file changed, 53 insertions(+), 19 deletions(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-queued b/FS/bin/freeside-queued index 0be3d9d7a..e14ddad8e 100644 --- a/FS/bin/freeside-queued +++ b/FS/bin/freeside-queued @@ -51,7 +51,16 @@ $< = $FS::UID::freeside_uid; $> = $FS::UID::freeside_uid; $ENV{HOME} = (getpwuid($>))[7]; #for ssh -adminsuidsetup $user; + +$@ = 'not connected'; +while ( $@ ) { + eval { adminsuidsetup $user; }; + if ( $@ ) { + warn $@; + warn "sleeping for reconnect...\n"; + sleep 5; + } +} $log_file = "/usr/local/etc/freeside/queuelog.". $FS::UID::datasrc; @@ -75,14 +84,17 @@ while (1) { } $warnkids=0; - my $dbh = dbh; - unless ( $dbh->ping ) { + unless ( dbh && dbh->ping ) { warn "WARNING: connection to database lost, reconnecting...\n"; - myconnect; - unless ( $dbh->ping ) { + + eval { myconnect; }; + + unless ( !$@ && dbh && dbh->ping ) { warn "WARNING: still no connection to database, sleeping for retry...\n"; sleep 10; next; + } else { + warn "WARNING: reconnected to database\n"; } } @@ -91,11 +103,15 @@ while (1) { # my $oldAutoCommit = $FS::UID::AutoCommit; # local $FS::UID::AutoCommit = 0; $FS::UID::AutoCommit = 0; - - my $nodepend = driver_name eq 'mysql' - ? '' - : 'AND 0 = ( SELECT COUNT(*) FROM queue_depend'. - ' WHERE queue_depend.jobnum = queue.jobnum ) '; + + #assuming mysql 4.1 w/subqueries now + #my $nodepend = driver_name eq 'mysql' + # ? '' + # : 'AND 0 = ( SELECT COUNT(*) FROM queue_depend'. + # ' WHERE queue_depend.jobnum = queue.jobnum ) '; + my $nodepend = 'AND 0 = ( SELECT COUNT(*) FROM queue_depend'. + ' WHERE queue_depend.jobnum = queue.jobnum ) '; + my $job = qsearchs( 'queue', { 'status' => 'new' }, @@ -104,25 +120,43 @@ while (1) { ? "$nodepend ORDER BY jobnum LIMIT 1 FOR UPDATE" : "$nodepend ORDER BY jobnum FOR UPDATE LIMIT 1" ) or do { - $dbh->commit or die $dbh->errstr; #if $oldAutoCommit; + # if $oldAutoCommit { + dbh->commit or do { + warn "WARNING: database error, closing connection: ". dbh->errstr; + undef $FS::UID::dbh; + next; + }; + # } sleep 5; #connecting to db is expensive next; }; - if ( driver_name eq 'mysql' - && qsearch('queue_depend', { 'jobnum' => $job->jobnum } ) ) { - $dbh->commit or die $dbh->errstr; #if $oldAutoCommit; - sleep 5; #would be better if mysql could do everything in query above - next; - } + #assuming mysql 4.1 w/subqueries now + #if ( driver_name eq 'mysql' + # && qsearch('queue_depend', { 'jobnum' => $job->jobnum } ) ) { + # dbh->commit or die dbh->errstr; #if $oldAutoCommit; + # sleep 5; #would be better if mysql could do everything in query above + # next; + #} my %hash = $job->hash; $hash{'status'} = 'locked'; my $ljob = new FS::queue ( \%hash ); my $error = $ljob->replace($job); - die $error if $error; + if ( $error ) { + warn "WARNING: database error locking job, closing connection: ". + dbh->errstr; + undef $FS::UID::dbh; + next; + } - $dbh->commit or die $dbh->errstr; #if $oldAutoCommit; + # if $oldAutoCommit { + dbh->commit or do { + warn "WARNING: database error, closing connection: ". dbh->errstr; + undef $FS::UID::dbh; + next; + }; + # } $FS::UID::AutoCommit = 1; #} -- cgit v1.2.1 From 8a56de51d9b1bf26fde1a32ed283edc3b545d5a4 Mon Sep 17 00:00:00 2001 From: ivan Date: Mon, 6 Sep 2004 09:44:42 +0000 Subject: don't open a database connection in the parent process --- FS/bin/freeside-selfservice-server | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-selfservice-server b/FS/bin/freeside-selfservice-server index 864c2d46e..d34e8411c 100644 --- a/FS/bin/freeside-selfservice-server +++ b/FS/bin/freeside-selfservice-server @@ -107,9 +107,12 @@ while (1) { warn "child $pid spawned\n" if $Debug; } else { #kid time - #get new db handle - $FS::UID::dbh->{InactiveDestroy} = 1; - forksuidsetup($user); + ##get new db handle + #$FS::UID::dbh->{InactiveDestroy} = 1; + #forksuidsetup($user); + + #get db handle + adminsuidsetup($user); my $type = $packet->{_packet}; warn "calling $type handler\n" if $Debug; @@ -195,7 +198,7 @@ sub init { #eslaf $ENV{HOME} = (getpwuid($>))[7]; #for ssh - adminsuidsetup $user; + #adminsuidsetup $user; #$log_file = "/usr/local/etc/freeside/selfservice.". $FS::UID::datasrc; #MACHINE NAME $log_file = "/usr/local/etc/freeside/selfservice.$machine.log"; -- cgit v1.2.1 From efccaa2d081bfcaaddcf9d89da3c2a065b4caafb Mon Sep 17 00:00:00 2001 From: ivan Date: Mon, 6 Sep 2004 12:44:17 +0000 Subject: self-service keepalives --- FS/bin/freeside-selfservice-server | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-selfservice-server b/FS/bin/freeside-selfservice-server index d34e8411c..a83664db2 100644 --- a/FS/bin/freeside-selfservice-server +++ b/FS/bin/freeside-selfservice-server @@ -8,7 +8,8 @@ # Proc::Daemon or somesuch use strict; -use vars qw( $Debug %kids $kids $max_kids $shutdown $log_file $ssh_pid ); +use vars qw( $Debug %kids $kids $max_kids $shutdown $log_file $ssh_pid + $keepalives ); use subs qw( lock_write unlock_write ); use Fcntl qw(:flock); use POSIX qw(:sys_wait_h setsid); @@ -29,6 +30,7 @@ $Debug = 1; # >= 2 will log packet contents, including potentially compromising $shutdown = 0; $max_kids = '10'; #? +$keepalives = 0; #let clientd turn it on, so we don't barf on old ones $kids = 0; my $user = shift or die &usage; @@ -58,6 +60,7 @@ while (1) { warn "entering main loop\n" if $Debug; my $undisp = 0; + my $keepalive_count = 0; my $s = IO::Select->new( $reader ); while (1) { @@ -68,6 +71,10 @@ while (1) { my @handles = $s->can_read(5); unless ( @handles ) { &shutdown if $shutdown; + if ( $keepalives && $keepalive_count++ > 10 ) { + $keepalive_count = 0; + nstore_fd( { _token => '_keepalive' }, $writer ); + } next; } @@ -91,6 +98,12 @@ while (1) { join('', map { " $_=>$packet->{$_}\n" } keys %$packet ) if $Debug > 1; + if ( $packet->{_packet} eq '_enable_keepalive' ) { + warn "enabling keep alives\n" if $Debug; + $keepalives=1; + next; + } + #prevent runaway forking my $warnkids = 0; while ( $kids >= $max_kids ) { -- cgit v1.2.1 From 07fd88f7c0cd757eb2f8e635b71acebe6a944602 Mon Sep 17 00:00:00 2001 From: ivan Date: Tue, 14 Sep 2004 06:47:46 +0000 Subject: selfservice: - server: don't reconnect again if we've already been signalled to shutdown - server: add kid reaping to shutdown sequence - server: add another optional logging level to response sending - server: acquire write mutex for keepalives --- FS/bin/freeside-selfservice-server | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-selfservice-server b/FS/bin/freeside-selfservice-server index a83664db2..ad100e83a 100644 --- a/FS/bin/freeside-selfservice-server +++ b/FS/bin/freeside-selfservice-server @@ -25,8 +25,8 @@ use FS::Conf; use FS::cust_bill; use FS::cust_pkg; -$Debug = 1; # >= 2 will log packet contents, including potentially compromising - # information +$Debug = 1; # 2 will turn on more logging + # 3 will log packet contents, including passwords $shutdown = 0; $max_kids = '10'; #? @@ -73,7 +73,9 @@ while (1) { &shutdown if $shutdown; if ( $keepalives && $keepalive_count++ > 10 ) { $keepalive_count = 0; + lock_write; nstore_fd( { _token => '_keepalive' }, $writer ); + unlock_write; } next; } @@ -96,7 +98,7 @@ while (1) { } warn "packet received\n". join('', map { " $_=>$packet->{$_}\n" } keys %$packet ) - if $Debug > 1; + if $Debug > 2; if ( $packet->{_packet} eq '_enable_keepalive' ) { warn "enabling keep alives\n" if $Debug; @@ -136,8 +138,8 @@ while (1) { } $rv->{_token} = $packet->{_token}; #identifier - warn "sending response\n" if $Debug; lock_write; + warn "sending response\n" if $Debug; nstore_fd($rv, $writer) or die "FATAL: can't send response: $!"; $writer->flush or die "FATAL: can't flush: $!"; unlock_write; @@ -148,6 +150,7 @@ while (1) { } + &shutdown if $shutdown; warn "connection lost, reconnecting\n" if $Debug; sleep 3; @@ -229,10 +232,12 @@ sub init { } sub shutdown { + &reap_kids; my $wait = 12; #wait up to 1 minute while ( $kids > 0 && $wait-- ) { warn "waiting for $kids children to terminate"; sleep 5; + &reap_kids; } warn "abandoning $kids children" if $kids; kill 'TERM', $ssh_pid if $ssh_pid; @@ -261,6 +266,8 @@ sub _do_logmsg { } sub lock_write { + warn "locking $lock_file mutex for write to write stream\n" if $Debug > 1; + #broken on freebsd? #flock($writer, LOCK_EX) or die "FATAL: can't lock write stream: $!"; @@ -269,6 +276,8 @@ sub lock_write { } sub unlock_write { + warn "unlocking $lock_file mutex\n" if $Debug > 1; + #broken on freebsd? #flock($writer, LOCK_UN) or die "WARNING: can't release write lock: $!"; -- cgit v1.2.1 From 73b848b45d387a3ca03f9ed64fd48646dd52352d Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 15 Sep 2004 08:30:20 +0000 Subject: obtain a new descriptor for the lock in kids, this should fix locking problems --- FS/bin/freeside-selfservice-server | 1 + 1 file changed, 1 insertion(+) (limited to 'FS/bin') diff --git a/FS/bin/freeside-selfservice-server b/FS/bin/freeside-selfservice-server index ad100e83a..de7e049ba 100644 --- a/FS/bin/freeside-selfservice-server +++ b/FS/bin/freeside-selfservice-server @@ -138,6 +138,7 @@ while (1) { } $rv->{_token} = $packet->{_token}; #identifier + open(LOCKFILE,">$lock_file") or die "can't open $lock_file: $!"; lock_write; warn "sending response\n" if $Debug; nstore_fd($rv, $writer) or die "FATAL: can't send response: $!"; -- cgit v1.2.1 From 83337c0a780c6e26618a7d0c2f228d8c32d30da3 Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 15 Sep 2004 08:57:11 +0000 Subject: it would help to set the permissions on the lockfile right, so the kids can open it... --- FS/bin/freeside-selfservice-server | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-selfservice-server b/FS/bin/freeside-selfservice-server index de7e049ba..1093e10c2 100644 --- a/FS/bin/freeside-selfservice-server +++ b/FS/bin/freeside-selfservice-server @@ -41,7 +41,6 @@ my $tag = scalar(@ARGV) ? shift : ''; 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); @@ -201,6 +200,10 @@ sub init { #false laziness w/freeside-queued my $freeside_gid = scalar(getgrnam('freeside')) or die "can't setgid to freeside group\n"; + + open(LOCKFILE,">$lock_file") or die "can't open $lock_file: $!"; + chown $FS::UID::freeside_uid, $freeside_gid, $lock_file; + $) = $freeside_gid; $( = $freeside_gid; #if freebsd can't setuid(), presumably it can't setgid() either. grr fleabsd -- cgit v1.2.1 From 0247c39288b477060509240ef23a5e7b6bfcd8f8 Mon Sep 17 00:00:00 2001 From: ivan Date: Tue, 5 Oct 2004 12:17:35 +0000 Subject: DO open a database connection in the parent process, this cached the $dbdef and speeds things up significantly --- FS/bin/freeside-selfservice-server | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-selfservice-server b/FS/bin/freeside-selfservice-server index 1093e10c2..c045893d1 100644 --- a/FS/bin/freeside-selfservice-server +++ b/FS/bin/freeside-selfservice-server @@ -218,7 +218,7 @@ sub init { #eslaf $ENV{HOME} = (getpwuid($>))[7]; #for ssh - #adminsuidsetup $user; + adminsuidsetup $user; #$log_file = "/usr/local/etc/freeside/selfservice.". $FS::UID::datasrc; #MACHINE NAME $log_file = "/usr/local/etc/freeside/selfservice.$machine.log"; -- cgit v1.2.1 From dbc6a01ed6a3b4373b01bf985ca735386dd047d4 Mon Sep 17 00:00:00 2001 From: ivan Date: Sat, 16 Oct 2004 10:15:01 +0000 Subject: add artera turbo export --- FS/bin/freeside-setup | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-setup b/FS/bin/freeside-setup index 386c4c7cd..5de71a9ca 100755 --- a/FS/bin/freeside-setup +++ b/FS/bin/freeside-setup @@ -1127,7 +1127,7 @@ sub tables_hash_hack { 'svc_external' => { 'columns' => [ 'svcnum', 'int', '', '', - 'id', 'int', '', '', + 'id', 'int', 'NULL', '', 'title', 'varchar', 'NULL', $char_d, ], 'primary_key' => 'svcnum', -- cgit v1.2.1 From 5d8208573e07b1c72b386b65dc10c6616d9192ac Mon Sep 17 00:00:00 2001 From: ivan Date: Tue, 19 Oct 2004 11:50:02 +0000 Subject: isn't run with elevated privledges, so -T not necessary --- FS/bin/freeside-sqlradius-reset | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-sqlradius-reset b/FS/bin/freeside-sqlradius-reset index d87cd4511..11cbe9e36 100755 --- a/FS/bin/freeside-sqlradius-reset +++ b/FS/bin/freeside-sqlradius-reset @@ -1,4 +1,4 @@ -#!/usr/bin/perl -Tw +#!/usr/bin/perl -w use strict; use FS::UID qw(adminsuidsetup); -- cgit v1.2.1