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') 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') 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') 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') 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') 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') 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 641e3f253b22c54c8970213ef86e04337caab948 Mon Sep 17 00:00:00 2001 From: ivan Date: Tue, 17 Dec 2002 10:36:39 +0000 Subject: sqlradius time calculation fix wrt open sessions --- FS/FS/cust_svc.pm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'FS') diff --git a/FS/FS/cust_svc.pm b/FS/FS/cust_svc.pm index 8bcb0fcca..66daec17b 100644 --- a/FS/FS/cust_svc.pm +++ b/FS/FS/cust_svc.pm @@ -394,11 +394,12 @@ sub seconds_since_sqlradacct { FROM radacct WHERE UserName = ? AND $str2time AcctStartTime ) >= ? + AND $str2time AcctStartTime ) < ? AND ( ? - $str2time AcctStartTime ) ) < 86400 AND ( $str2time AcctStopTime ) = 0 OR AcctStopTime IS NULL )"; $sth = $dbh->prepare($query) or die $dbh->errstr; - $sth->execute($end, $username, $start, $end) + $sth->execute($end, $username, $start, $end, $end) or die $sth->errstr. " executing query $query"; my $start_during = $sth->fetchrow_arrayref->[0]; -- 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') 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 f800872bff0d887ee096dfef186e6da7275ce5ae Mon Sep 17 00:00:00 2001 From: ivan Date: Tue, 17 Dec 2002 21:31:20 +0000 Subject: invoice_lines() fix --- FS/FS/cust_bill.pm | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'FS') diff --git a/FS/FS/cust_bill.pm b/FS/FS/cust_bill.pm index 1742f604f..23e8731dc 100644 --- a/FS/FS/cust_bill.pm +++ b/FS/FS/cust_bill.pm @@ -1032,9 +1032,9 @@ sub print_text { or die "cannot load config file $templatefile"; $invoice_lines = 0; my $wasfunc = 0; - foreach ( grep /invoice_lines\(\d+\)/, @invoice_template ) { #kludgy - /invoice_lines\((\d+)\)/; - $invoice_lines += $1; + foreach ( grep /invoice_lines\(\d*\)/, @invoice_template ) { #kludgy + /invoice_lines\((\d*)\)/; + $invoice_lines += $1 || scalar(@buf); $wasfunc=1; } die "no invoice_lines() functions in template?" unless $wasfunc; @@ -1119,7 +1119,7 @@ sub print_text { =head1 VERSION -$Id: cust_bill.pm,v 1.56 2002-12-04 12:31:49 ivan Exp $ +$Id: cust_bill.pm,v 1.57 2002-12-17 21:31:20 ivan Exp $ =head1 BUGS -- cgit v1.2.1 From a6339c3ac72353911a0b7f585b758a4b6aada899 Mon Sep 17 00:00:00 2001 From: ivan Date: Sat, 21 Dec 2002 04:31:05 +0000 Subject: kludge around uninitialized value errors --- FS/FS/svc_acct.pm | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'FS') diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index 2062eb9ba..83af6ff52 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -266,7 +266,11 @@ sub insert { # qsearch('export_svc', { 'exportnum' => $part_export->exportnum }); #} - my $nodomain = $exports->{$part_export->exporttype}{'nodomain'}; + #my $nodomain = $exports->{$part_export->exporttype}{'nodomain'}; + #silly kludge to avoid uninitialized value errors + my $nodomain = exists( $exports->{$part_export->exporttype}{'nodomain'} ) + ? $exports->{$part_export->exporttype}{'nodomain'} + : ''; if ( $nodomain =~ /^Y/i ) { $conflict_user_svcpart{$_} = $part_export->exportnum foreach @svcparts; -- cgit v1.2.1 From 8c679e623c0e21d3d4e1b1966b310db61871e119 Mon Sep 17 00:00:00 2001 From: ivan Date: Sat, 21 Dec 2002 07:36:52 +0000 Subject: $noexport hack moved to svc_Common --- FS/FS/svc_acct.pm | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'FS') diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index 83af6ff52..659835626 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -1,7 +1,7 @@ package FS::svc_acct; use strict; -use vars qw( @ISA $DEBUG $me $noexport_hack $conf +use vars qw( @ISA $DEBUG $me $conf $dir_prefix @shells $usernamemin $usernamemax $passwordmin $passwordmax $username_ampersand $username_letter $username_letterfirst @@ -186,7 +186,7 @@ sqlradius export only) (TODOC: L and L) -(TODOC: new exports! $noexport_hack) +(TODOC: new exports!) =cut @@ -411,7 +411,7 @@ error, otherwise returns false. The corresponding FS::cust_svc record will be deleted as well. -(TODOC: new exports! $noexport_hack) +(TODOC: new exports!) =cut -- cgit v1.2.1 From 3ed2aae6b3e6b303b4058f9cd6e54ea377196b0a Mon Sep 17 00:00:00 2001 From: ivan Date: Sat, 21 Dec 2002 10:02:24 +0000 Subject: better qsearchs warning --- FS/FS/Record.pm | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'FS') diff --git a/FS/FS/Record.pm b/FS/FS/Record.pm index ebcbbb497..40215100f 100644 --- a/FS/FS/Record.pm +++ b/FS/FS/Record.pm @@ -330,9 +330,11 @@ for a single item, or your data is corrupted. =cut sub qsearchs { # $result_record = &FS::Record:qsearchs('table',\%hash); + my $table = $_[0]; my(@result) = qsearch(@_); - carp "warning: Multiple records in scalar search!" if scalar(@result) > 1; - #should warn more vehemently if the search was on a primary key? + carp "warning: Multiple records in scalar search ($table)" + if scalar(@result) > 1; + #should warn more vehemently if the search was on a primary key? scalar(@result) ? ($result[0]) : (); } -- cgit v1.2.1 From cbb506ec10170d3f77d618596ca8cd25d08b2bd2 Mon Sep 17 00:00:00 2001 From: ivan Date: Sat, 21 Dec 2002 10:14:48 +0000 Subject: could be multiple returns from these searches, with taxclasses --- FS/FS/cust_main.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'FS') diff --git a/FS/FS/cust_main.pm b/FS/FS/cust_main.pm index 890371de7..1727c4b94 100644 --- a/FS/FS/cust_main.pm +++ b/FS/FS/cust_main.pm @@ -591,13 +591,13 @@ sub check { # bad idea to disable, causes billing to fail because of no tax rates later # unless ( $import ) { - unless ( qsearchs('cust_main_county', { + unless ( qsearch('cust_main_county', { 'country' => $self->country, 'state' => '', } ) ) { return "Unknown state/county/country: ". $self->state. "/". $self->county. "/". $self->country - unless qsearchs('cust_main_county',{ + unless qsearch('cust_main_county',{ 'state' => $self->state, 'county' => $self->county, 'country' => $self->country, -- 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/FS/cust_pkg.pm | 15 ++++++++++----- FS/bin/freeside-daily | 15 +++++++++++---- 2 files changed, 21 insertions(+), 9 deletions(-) (limited to 'FS') diff --git a/FS/FS/cust_pkg.pm b/FS/FS/cust_pkg.pm index e83b95156..c15e2fe9d 100644 --- a/FS/FS/cust_pkg.pm +++ b/FS/FS/cust_pkg.pm @@ -1,7 +1,7 @@ package FS::cust_pkg; use strict; -use vars qw(@ISA); +use vars qw(@ISA $disable_agentcheck); use FS::UID qw( getotaker dbh ); use FS::Record qw( qsearch qsearchs ); use FS::cust_svc; @@ -21,6 +21,8 @@ use FS::svc_forward; @ISA = qw( FS::Record ); +$disable_agentcheck = 0; + sub _cache { my $self = shift; my ( $hashref, $cache ) = @_; @@ -142,10 +144,13 @@ sub insert { my $cust_main = $self->cust_main; return "Unknown customer ". $self->custnum unless $cust_main; - my $agent = qsearchs( 'agent', { 'agentnum' => $cust_main->agentnum } ); - my $pkgpart_href = $agent->pkgpart_hashref; - return "agent ". $agent->agentnum. " can't purchase pkgpart ". $self->pkgpart - unless $pkgpart_href->{ $self->pkgpart }; + unless ( $disable_agentcheck ) { + my $agent = qsearchs( 'agent', { 'agentnum' => $cust_main->agentnum } ); + my $pkgpart_href = $agent->pkgpart_hashref; + return "agent ". $agent->agentnum. + " can't purchase pkgpart ". $self->pkgpart + unless $pkgpart_href->{ $self->pkgpart }; + } $self->SUPER::insert; 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 a7ac7ab3af0dd4f9773aec7c59515fefc8eaedec Mon Sep 17 00:00:00 2001 From: steve Date: Mon, 23 Dec 2002 14:24:06 +0000 Subject: added stuff for selfservice_server-quiet, signup_server-quiet, and emailcancel messages. --- FS/FS/Conf.pm | 35 +++++++++++++++++++++++++++++++++++ FS/FS/cust_bill.pm | 5 +++-- 2 files changed, 38 insertions(+), 2 deletions(-) (limited to 'FS') diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm index 6de311596..f0a4c9f45 100644 --- a/FS/FS/Conf.pm +++ b/FS/FS/Conf.pm @@ -879,6 +879,20 @@ httemplate/docs/config.html 'select_enum' => [ qw(en_US) ], }, + { + 'key' => 'selfservice_server-quiet', + 'section' => '', + 'description' => 'Disable decline and cancel emails generated by transactions initiated by the selfservice server. Not recommended, unless the customer will get instant feedback from a customer service UI, and receiving an email would be confusing/overkill.', + 'type' => 'checkbox', + }, + + { + 'key' => 'signup_server-quiet', + 'section' => '', + 'description' => 'Disable decline and cancel emails generated by transactions initiated by the signup server. Not recommended, unless the customer will get instant feedback from a customer service UI, and receiving an email would be confusing/overkill. Does not disable welcome emails.', + 'type' => 'checkbox', + }, + { 'key' => 'signup_server-payby', 'section' => '', @@ -923,6 +937,27 @@ httemplate/docs/config.html 'type' => 'checkbox', }, + { + 'key' => 'cancelmessage', + 'section' => 'billing', + 'description' => 'Template file for cancellation emails.', + 'type' => 'textarea', + }, + + { + 'key' => 'cancelsubject', + 'section' => 'billing', + 'description' => 'Subject line for cancellation emails.', + 'type' => 'text', + }, + + { + 'key' => 'emailcancel', + 'section' => 'billing', + 'description' => 'Enable emailing of cancellation notices.', + 'type' => 'checkbox', + }, + { 'key' => 'require_cardname', 'section' => 'billing', diff --git a/FS/FS/cust_bill.pm b/FS/FS/cust_bill.pm index 23e8731dc..48315199a 100644 --- a/FS/FS/cust_bill.pm +++ b/FS/FS/cust_bill.pm @@ -7,6 +7,7 @@ use vars qw( $xaction $E_NoErr ); use vars qw( $bop_processor $bop_login $bop_password $bop_action @bop_options ); use vars qw( $ach_processor $ach_login $ach_password $ach_action @ach_options ); use vars qw( $invoice_lines @buf ); #yuck +use vars qw( $quiet ); use Date::Format; use Mail::Internet 1.44; use Mail::Header; @@ -823,7 +824,7 @@ sub realtime_bop { my $perror = "$processor error, invnum #". $self->invnum. ': '. $transaction->result_code. ": ". $transaction->error_message; - if ( $conf->exists('emaildecline') + if ( !$quiet && $conf->exists('emaildecline') && grep { $_ ne 'POST' } $cust_main->invoicing_list ) { my @templ = $conf->config('declinetemplate'); @@ -1119,7 +1120,7 @@ sub print_text { =head1 VERSION -$Id: cust_bill.pm,v 1.57 2002-12-17 21:31:20 ivan Exp $ +$Id: cust_bill.pm,v 1.58 2002-12-23 14:22:48 steve Exp $ =head1 BUGS -- cgit v1.2.1 From b47b05fdc4af937a2df1a3b4017f550183814efc Mon Sep 17 00:00:00 2001 From: steve Date: Mon, 23 Dec 2002 14:54:24 +0000 Subject: added stuff for selfservice_server-quiet, signup_server-quiet, and emailcancel messages. --- FS/FS/cust_pkg.pm | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'FS') diff --git a/FS/FS/cust_pkg.pm b/FS/FS/cust_pkg.pm index c15e2fe9d..88ffd4d17 100644 --- a/FS/FS/cust_pkg.pm +++ b/FS/FS/cust_pkg.pm @@ -2,6 +2,7 @@ package FS::cust_pkg; use strict; use vars qw(@ISA $disable_agentcheck); +use vars qw( $quiet ); use FS::UID qw( getotaker dbh ); use FS::Record qw( qsearch qsearchs ); use FS::cust_svc; @@ -19,6 +20,13 @@ use FS::svc_domain; use FS::svc_www; use FS::svc_forward; +# need all this for sending cancel emails in sub cancel + +use FS::Conf; +use Date::Format; +use Mail::Internet 1.44; +use Mail::Header; + @ISA = qw( FS::Record ); $disable_agentcheck = 0; @@ -295,7 +303,43 @@ sub cancel { $dbh->commit or die $dbh->errstr if $oldAutoCommit; + my $conf = new FS::Conf; + + if ( !$quiet && $conf->exists('emailcancel') + && grep { $_ ne 'POST' } $self->cust_main->invoicing_list) { + + my @invoicing_list = $self->cust_main->invoicing_list; + + my $invoice_from = $conf->config('invoice_from'); + my @print_text = map "$_\n", $conf->config('cancelmessage'); + my $subject = $conf->config('cancelsubject'); + my $smtpmachine = $conf->config('smtpmachine'); + + if ( grep { $_ ne 'POST' } @invoicing_list ) { #email invoice + #false laziness w/FS::cust_pay::delete & fs_signup_server && ::realtime_card + #$ENV{SMTPHOSTS} = $smtpmachine; + $ENV{MAILADDRESS} = $invoice_from; + my $header = new Mail::Header ( [ + "From: $invoice_from", + "To: ". join(', ', grep { $_ ne 'POST' } @invoicing_list ), + "Sender: $invoice_from", + "Reply-To: $invoice_from", + "Date: ". time2str("%a, %d %b %Y %X %z", time), + "Subject: $subject", + ] ); + my $message = new Mail::Internet ( + 'Header' => $header, + 'Body' => [ @print_text ], + ); + $!=0; + $message->smtpsend( Host => $smtpmachine ) + or $message->smtpsend( Host => $smtpmachine, Debug => 1 ); + #should this return an error? + } + } + ''; #no errors + } =item suspend -- cgit v1.2.1 From 21771a118aaf154f605cfae05ee830eaeb4dd818 Mon Sep 17 00:00:00 2001 From: steve Date: Mon, 23 Dec 2002 15:05:10 +0000 Subject: add email address to shellcommands don't error out when importing unaudited accounts (even though should probably be using $FS::svc_Common::noexport_hack anyway) --- FS/FS/part_export/shellcommands.pm | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'FS') diff --git a/FS/FS/part_export/shellcommands.pm b/FS/FS/part_export/shellcommands.pm index 04e5041c3..dbd4017f8 100644 --- a/FS/FS/part_export/shellcommands.pm +++ b/FS/FS/part_export/shellcommands.pm @@ -34,17 +34,27 @@ sub _export_command { my ( $self, $action, $svc_acct) = (shift, shift, shift); my $command = $self->option($action); my $stdin = $self->option($action."_stdin"); + no strict 'vars'; { no strict 'refs'; ${$_} = $svc_acct->getfield($_) foreach $svc_acct->fields; } + + my $cust_pkg = $svc_acct->cust_svc->cust_pkg; + if ( $cust_pkg ) { + $email = ( grep { $_ ne 'POST' } $cust_pkg->cust_main->invoicing_list )[0]; + } else { + $email = ''; + } + $finger = shell_quote $finger; $quoted_password = shell_quote $_password; $domain = $svc_acct->domain; $crypt_password = ''; #surpress "used only once" warnings $crypt_password = crypt( $svc_acct->_password, $saltset[int(rand(64))].$saltset[int(rand(64))] ); + $self->shellcommands_queue( $svc_acct->svcnum, user => $self->option('user')||'root', host => $self->machine, -- cgit v1.2.1 From 1014e988be16a7158ff7ca0d0a6e7aac730517a0 Mon Sep 17 00:00:00 2001 From: ivan Date: Mon, 23 Dec 2002 15:21:55 +0000 Subject: make agent available to invoice templates --- FS/FS/cust_bill.pm | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'FS') diff --git a/FS/FS/cust_bill.pm b/FS/FS/cust_bill.pm index 48315199a..331c809bc 100644 --- a/FS/FS/cust_bill.pm +++ b/FS/FS/cust_bill.pm @@ -1048,11 +1048,12 @@ sub print_text { #setup template variables package FS::cust_bill::_template; #! - use vars qw( $invnum $date $page $total_pages @address $overdue @buf ); + use vars qw( $invnum $date $page $total_pages @address $overdue @buf $agent ); $invnum = $self->invnum; $date = $self->_date; $page = 1; + $agent = $self->cust_main->agent->agent; if ( $FS::cust_bill::invoice_lines ) { $total_pages = @@ -1120,7 +1121,7 @@ sub print_text { =head1 VERSION -$Id: cust_bill.pm,v 1.58 2002-12-23 14:22:48 steve Exp $ +$Id: cust_bill.pm,v 1.59 2002-12-23 15:21:55 ivan Exp $ =head1 BUGS -- cgit v1.2.1 From 022f47d636bcec1699a0e8ebce394f5756af5f8c Mon Sep 17 00:00:00 2001 From: ivan Date: Mon, 23 Dec 2002 23:56:26 +0000 Subject: remove gratuitous warning and better error messages --- FS/FS/svc_acct.pm | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'FS') diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index 659835626..456c965af 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -366,7 +366,6 @@ sub insert { 'svcnum' => $self->svcnum, 'job' => 'FS::svc_acct::send_email' }; - warn "attempting to queue email to $to"; my $error = $wqueue->insert( 'to' => $to, 'from' => $welcome_from, @@ -383,14 +382,14 @@ sub insert { ); if ( $error ) { $dbh->rollback if $oldAutoCommit; - return "queuing welcome email: $error"; + return "error queuing welcome email: $error"; } foreach my $jobnum ( @jobnums ) { my $error = $wqueue->depend_insert($jobnum); if ( $error ) { $dbh->rollback if $oldAutoCommit; - return "queuing welcome email job dependancy: $error"; + return "error queuing welcome email job dependancy: $error"; } } -- 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') 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') 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 652526712a97a71381b08b89b389d526bcbc85d1 Mon Sep 17 00:00:00 2001 From: ivan Date: Fri, 27 Dec 2002 12:56:58 +0000 Subject: better times on failed billing events --- FS/FS/cust_main.pm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'FS') diff --git a/FS/FS/cust_main.pm b/FS/FS/cust_main.pm index 1727c4b94..91ffa451a 100644 --- a/FS/FS/cust_main.pm +++ b/FS/FS/cust_main.pm @@ -1335,7 +1335,8 @@ sub collect { my $cust_bill_event = new FS::cust_bill_event { 'invnum' => $cust_bill->invnum, 'eventpart' => $part_bill_event->eventpart, - '_date' => $invoice_time, + #'_date' => $invoice_time, + '_date' => time, 'status' => $status, 'statustext' => $statustext, }; -- cgit v1.2.1 From c423f1b4bdad5f4dea96c27f998215ca18745f6f Mon Sep 17 00:00:00 2001 From: ivan Date: Sat, 28 Dec 2002 09:16:49 +0000 Subject: prevent edge-case business-onlinepayment mod_perl leakage in multi-database installs. ugh. --- FS/FS/cust_bill.pm | 7 ++++++- FS/FS/svc_acct.pm | 3 +++ 2 files changed, 9 insertions(+), 1 deletion(-) (limited to 'FS') diff --git a/FS/FS/cust_bill.pm b/FS/FS/cust_bill.pm index 331c809bc..af248a7a8 100644 --- a/FS/FS/cust_bill.pm +++ b/FS/FS/cust_bill.pm @@ -36,6 +36,11 @@ $FS::UID::callback{'FS::cust_bill'} = sub { $invoice_from = $conf->config('invoice_from'); $smtpmachine = $conf->config('smtpmachine'); + ( $bop_processor,$bop_login, $bop_password, $bop_action ) = ( '', '', '', ''); + @bop_options = (); + ( $ach_processor,$ach_login, $ach_password, $ach_action ) = ( '', '', '', ''); + @ach_options = (); + if ( $conf->exists('business-onlinepayment') ) { ( $bop_processor, $bop_login, @@ -1121,7 +1126,7 @@ sub print_text { =head1 VERSION -$Id: cust_bill.pm,v 1.59 2002-12-23 15:21:55 ivan Exp $ +$Id: cust_bill.pm,v 1.60 2002-12-28 09:16:49 ivan Exp $ =head1 BUGS diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index 456c965af..9b953eac8 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -62,6 +62,9 @@ $FS::UID::callback{'FS::svc_acct'} = sub { $welcome_mimetype = $conf->config('welcome_email-mimetype') || 'text/plain'; } else { $welcome_template = ''; + $welcome_from = ''; + $welcome_subject = ''; + $welcome_mimetype = ''; } $smtpmachine = $conf->config('smtpmachine'); $radius_password = $conf->config('radius-password') || 'Password'; -- cgit v1.2.1 From fd69668cd33e9cfc2f1c8469c6e6b7089243d3e6 Mon Sep 17 00:00:00 2001 From: ivan Date: Fri, 10 Jan 2003 07:41:05 +0000 Subject: pop off an extra blank line in business-onlinepayment options --- FS/FS/cust_bill.pm | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'FS') diff --git a/FS/FS/cust_bill.pm b/FS/FS/cust_bill.pm index af248a7a8..c661baa95 100644 --- a/FS/FS/cust_bill.pm +++ b/FS/FS/cust_bill.pm @@ -667,6 +667,10 @@ sub realtime_lec { sub realtime_bop { my( $self, $method, $processor, $login, $password, $action, $options ) = @_; + + #trim an extraneous blank line + pop @$options if scalar(@$options) % 2 && $options->[-1] =~ /^\s*$/; + my $cust_main = $self->cust_main; my $amount = $self->owed; @@ -1126,7 +1130,7 @@ sub print_text { =head1 VERSION -$Id: cust_bill.pm,v 1.60 2002-12-28 09:16:49 ivan Exp $ +$Id: cust_bill.pm,v 1.61 2003-01-10 07:41:05 ivan Exp $ =head1 BUGS -- cgit v1.2.1 From 2f9eb7976dca75dc6c585ea9c62f1b0898e3e953 Mon Sep 17 00:00:00 2001 From: ivan Date: Tue, 14 Jan 2003 08:49:57 +0000 Subject: add freeside-selfservice-server to init script add domsvc checking as a foreign key --- FS/FS/svc_acct.pm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'FS') diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index 9b953eac8..e0c4662b2 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -673,7 +673,8 @@ sub check { } my $error = $self->ut_numbern('svcnum') - || $self->ut_number('domsvc') + #|| $self->ut_number('domsvc') + || $self->ut_foreign_key('domsvc', 'svc_domain', 'svcnum' ) || $self->ut_textn('sec_phrase') ; return $error if $error; -- 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/MANIFEST | 1 + FS/bin/freeside-selfservice-server | 235 +++++++++++++++++++++++++++++++++++++ 2 files changed, 236 insertions(+) create mode 100644 FS/bin/freeside-selfservice-server (limited to 'FS') diff --git a/FS/MANIFEST b/FS/MANIFEST index 9c387d42e..b3de623d7 100644 --- a/FS/MANIFEST +++ b/FS/MANIFEST @@ -19,6 +19,7 @@ bin/freeside-setinvoice bin/freeside-overdue bin/freeside-radgroup bin/freeside-receivables-report +bin/freeside-selfservice-server bin/freeside-sqlradius-radacctd bin/freeside-sqlradius-reset bin/freeside-sqlradius-seconds 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