From a9c8414692c1777da3ff78b83a1e6bbb0729f6eb Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 1 Feb 2006 23:13:48 +0000 Subject: finish adding freeside-monthly and monthly events --- FS/bin/freeside-daily | 160 +++++------------------------------------------- FS/bin/freeside-monthly | 91 +++++++++++++++++++++++++++ 2 files changed, 108 insertions(+), 143 deletions(-) create mode 100755 FS/bin/freeside-monthly (limited to 'FS/bin') diff --git a/FS/bin/freeside-daily b/FS/bin/freeside-daily index 603da12b8..b9742c4d1 100755 --- a/FS/bin/freeside-daily +++ b/FS/bin/freeside-daily @@ -1,157 +1,29 @@ #!/usr/bin/perl -w use strict; -use Fcntl qw(:flock); -use Date::Parse; use Getopt::Std; -use FS::UID qw(adminsuidsetup driver_name dbh datasrc); -use FS::Record qw(qsearch qsearchs dbdef); -use FS::Conf; -use FS::cust_main; +use FS::UID qw(adminsuidsetup); &untaint_argv; #what it sounds like (eww) -use vars qw($opt_d $opt_v $opt_p $opt_a $opt_s $opt_y); -getopts("p:a:d:vsy:"); -my $user = shift or die &usage; +#use vars qw($opt_d $opt_v $opt_p $opt_a $opt_s $opt_y); +use vars qw(%opt); +getopts("p:a:d:vsy:", \%opt); +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; -$search{'agentnum'} = $opt_a if $opt_a; - -#we're at now now (and later). -my($time)= $opt_d ? str2time($opt_d) : $^T; -$time += $opt_y * 86400 if $opt_y; - -# select * from cust_main where -my $where_pkg = <<"END"; - 0 < ( select count(*) from cust_pkg - where cust_main.custnum = cust_pkg.custnum - and ( cancel is null or cancel = 0 ) - and ( setup is null or setup = 0 - or bill is null or bill <= $time - or ( expire is not null and expire <= $^T ) - ) - ) -END - -# or -my $where_bill_event = <<"END"; - 0 < ( select count(*) from cust_bill - where cust_main.custnum = cust_bill.custnum - and 0 < charged - - coalesce( - ( select sum(amount) from cust_bill_pay - where cust_bill.invnum = cust_bill_pay.invnum ) - ,0 - ) - - coalesce( - ( select sum(amount) from cust_credit_bill - where cust_bill.invnum = cust_credit_bill.invnum ) - ,0 - ) - and 0 < ( select count(*) from part_bill_event - where payby = cust_main.payby - and ( disabled is null or disabled = '' ) - and seconds <= $time - cust_bill._date - and 0 = ( select count(*) from cust_bill_event - where cust_bill.invnum = cust_bill_event.invnum - and part_bill_event.eventpart = cust_bill_event.eventpart - and status = 'done' - ) - - ) - ) -END - -my $extra_sql = ( scalar(%search) ? ' AND ' : ' WHERE ' ). "( $where_pkg OR $where_bill_event )"; - -my @cust_main; -if ( @ARGV ) { - @cust_main = map { qsearchs('cust_main', { custnum => $_, %search } ) } @ARGV -} else { - @cust_main = qsearch('cust_main', \%search, '', $extra_sql ); -} -; - -my($cust_main,%saw); -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 - ) { - my $error = $cust_pkg->cancel; - warn "Error cancelling expired pkg ". $cust_pkg->pkgnum. " for custnum ". - $cust_main->custnum. ": $error" - if $error; - } - # $^T not $time because -d is for pre-printing invoices - foreach my $cust_pkg ( - grep { $_->part_pkg->is_prepaid - && $_->bill && $_->bill < $^T && ! $_->susp - } - $cust_main->ncancelled_pkgs - ) { - my $error = $cust_pkg->suspend; - warn "Error suspending package ". $cust_pkg->pkgnum. - " for custnum ". $cust_main->custnum. - ": $error" - if $error; - } +use FS::Cron::bill qw(bill); +bill(%opt); - my $error = $cust_main->bill( 'time' => $time, - 'resetup' => $opt_s, ); - warn "Error billing, custnum ". $cust_main->custnum. ": $error" if $error; +use FS::Cron::vacuum qw(vacuum); +vacuum(); - $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; - -} - -if ( driver_name eq 'Pg' ) { - dbh->{AutoCommit} = 1; #so we can vacuum - foreach my $table ( dbdef->tables ) { - my $sth = dbh->prepare("VACUUM ANALYZE $table") or die dbh->errstr; - $sth->execute or die $sth->errstr; - } -} - -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; - } - 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'), - ); - chmod 0600, '/var/tmp/$database.gpg'; - scp("/var/tmp/$database.gpg", $dest); - unlink "/var/tmp/$database.gpg" or die $!; - } else { - chmod 0600, '/var/tmp/$database.sql'; - scp("/var/tmp/$database.sql", $dest); - } - unlink "/var/tmp/$database.sql" or die $!; -} +use FS::Cron::backup qw(backup_scp); +backup_scp(); +### # subroutines +### sub untaint_argv { foreach $_ ( $[ .. $#ARGV ) { #untaint @ARGV @@ -166,6 +38,10 @@ sub usage { die "Usage:\n\n freeside-daily [ -d 'date' ] user [ custnum custnum ... ]\n"; } +### +# documentation +### + =head1 NAME freeside-daily - Run daily billing and invoice collection events. @@ -179,8 +55,6 @@ freeside-daily - Run daily billing and invoice collection events. 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. diff --git a/FS/bin/freeside-monthly b/FS/bin/freeside-monthly new file mode 100755 index 000000000..a6c75e715 --- /dev/null +++ b/FS/bin/freeside-monthly @@ -0,0 +1,91 @@ +#!/usr/bin/perl -w + +use strict; +use Getopt::Std; +use FS::UID qw(adminsuidsetup); + +&untaint_argv; #what it sounds like (eww) +#use vars qw($opt_d $opt_v $opt_p $opt_a $opt_s $opt_y); +use vars qw(%opt); +getopts("p:a:d:vsy:", \%opt); + +my $user = shift or die &usage; +adminsuidsetup $user; + +use FS::Cron::bill qw(bill); +bill(%opt, 'freq'=>'1m' ); + +### +# 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-monthly [ -d 'date' ] user [ custnum custnum ... ]\n"; +} + +### +# documentation +### + +=head1 NAME + +freeside-monthly - Run monthly billing and invoice collection events. + +=head1 SYNOPSIS + + freeside-monthly [ -d 'date' ] [ -y days ] [ -p 'payby' ] [ -a agentnum ] [ -s ] [ -v ] user [ custnum custnum ... ] + +=head1 DESCRIPTION + +Bills customers and runs invoice collection events, for the alternate monthly +event chain. If you have defined monthly event checks, should be run from +crontab monthly. + +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. + + -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) + + -a: Only process customers with the specified agentnum + + -s: re-charge setup fees + + -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 +customers. Otherwise, bills all customers. + +=head1 NOTE + +In most cases, you would use freeside-daily only and not freeside-monthly. +freeside-monthly would only be used in cases where you have events that can +only be run once each month, for example, batching invoices to a third-party +print/mail provider. + +=head1 BUGS + +=head1 SEE ALSO + +L, L, config.html from the base documentation + +=cut + -- cgit v1.2.1 From 37220994fec0ec4f8913be99f66aa082c78897a4 Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 8 Feb 2006 22:53:18 +0000 Subject: don't leave ssh zombies around either --- FS/bin/freeside-selfservice-server | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-selfservice-server b/FS/bin/freeside-selfservice-server index c73349a60..6026fd18f 100644 --- a/FS/bin/freeside-selfservice-server +++ b/FS/bin/freeside-selfservice-server @@ -1,7 +1,7 @@ #!/usr/bin/perl -w use strict; -use vars qw( $Debug %kids $kids $max_kids $ssh_pid $keepalives ); +use vars qw( $Debug %kids $kids $max_kids $ssh_pid %old_ssh_pid $keepalives ); use subs qw( lock_write unlock_write myshutdown usage ); use Fcntl qw(:flock); use POSIX qw(:sys_wait_h); @@ -102,6 +102,7 @@ while (1) { if ( $ssh_pid ) { warn "sending TERM signal to ssh process $ssh_pid\n" if $Debug; kill 'TERM', $ssh_pid; + $old_ssh_pid{$ssh_pid} = 1; $ssh_pid = 0; } last; @@ -180,6 +181,10 @@ sub reap_kids { delete $kids{$kid}; } } + + foreach my $pid ( keys %old_ssh_pid ) { + waitpid($pid, WNOHANG) and delete $old_ssh_pid{$pid}; + } #warn "done reaping\n"; } -- cgit v1.2.1 From a2b0b3e8500b08a5cf017c85693d9649853f8569 Mon Sep 17 00:00:00 2001 From: ivan Date: Thu, 16 Feb 2006 21:43:02 +0000 Subject: automate more of the initial data adding... --- FS/bin/freeside-setup | 73 ++++++--------------------------------------------- 1 file changed, 8 insertions(+), 65 deletions(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-setup b/FS/bin/freeside-setup index a16e51749..bff2bcc63 100755 --- a/FS/bin/freeside-setup +++ b/FS/bin/freeside-setup @@ -4,23 +4,20 @@ BEGIN { $FS::Schema::setup_hack = 1; } use strict; -use vars qw($opt_s); +use vars qw($opt_s $opt_d $opt_v); use Getopt::Std; -use Locale::Country; -use Locale::SubCountry; use FS::UID qw(adminsuidsetup datasrc checkeuid getsecrets); use FS::Schema qw( dbdef_dist reload_dbdef ); use FS::Record; -use FS::cust_main_county; #use FS::raddb; -use FS::part_bill_event; +use FS::Setup qw(create_initial_data); die "Not running uid freeside!" unless checkeuid(); #my %attrib2db = # map { lc($FS::raddb::attrib{$_}) => $_ } keys %FS::raddb::attrib; -getopts("s"); +getopts("svd:"); my $user = shift or die &usage; getsecrets($user); @@ -94,6 +91,7 @@ my $dbh = adminsuidsetup $user; $|=1; foreach my $statement ( $dbdef->sql($dbh) ) { + warn $statement if $statement =~ /TABLE cdr/; $dbh->do( $statement ) or die "CREATE error: ". $dbh->errstr. "\ndoing statement: $statement"; } @@ -104,69 +102,14 @@ dbdef_create($dbh, $dbdef_file); delete $FS::Schema::dbdef_cache{$dbdef_file}; #force an actual reload reload_dbdef($dbdef_file); -#cust_main_county -foreach my $country ( sort map uc($_), all_country_codes ) { +create_initial_data('domain' => $opt_d); - my $subcountry = eval { new Locale::SubCountry($country) }; - my @states = $subcountry ? $subcountry->all_codes : undef; - - if ( !scalar(@states) || ( scalar(@states) == 1 && !defined($states[0]) ) ) { - - 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 -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({ - '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; - -} +warn "Freeside database initialized - commiting transaction\n" if $opt_v; $dbh->commit or die $dbh->errstr; $dbh->disconnect or die $dbh->errstr; -#print "Freeside database initialized sucessfully\n"; +warn "Database initialization committed sucessfully\n" if $opt_v; sub dbdef_create { # reverse engineer the schema from the DB and save to file my( $dbh, $file ) = @_; @@ -175,7 +118,7 @@ sub dbdef_create { # reverse engineer the schema from the DB and save to file } sub usage { - die "Usage:\n freeside-setup user\n"; + die "Usage:\n freeside-setup -d domain.name [ -v ] user\n"; } 1; -- cgit v1.2.1 From b9f9a5dc444a66ca138073a0e5229d85569e51b4 Mon Sep 17 00:00:00 2001 From: ivan Date: Sat, 25 Mar 2006 02:23:26 +0000 Subject: successfully correct the spelling of sucessful --- 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 bff2bcc63..9f87f10b7 100755 --- a/FS/bin/freeside-setup +++ b/FS/bin/freeside-setup @@ -109,7 +109,7 @@ warn "Freeside database initialized - commiting transaction\n" if $opt_v; $dbh->commit or die $dbh->errstr; $dbh->disconnect or die $dbh->errstr; -warn "Database initialization committed sucessfully\n" if $opt_v; +warn "Database initialization committed successfully\n" if $opt_v; sub dbdef_create { # reverse engineer the schema from the DB and save to file my( $dbh, $file ) = @_; -- cgit v1.2.1 From ee8ec98f0161b6fe11a231c7ac44e50811723b99 Mon Sep 17 00:00:00 2001 From: ivan Date: Thu, 30 Mar 2006 14:22:38 +0000 Subject: move all the schema-updating magic into DBIx::DBSchema --- FS/bin/freeside-upgrade | 92 +++---------------------------------------------- 1 file changed, 4 insertions(+), 88 deletions(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-upgrade b/FS/bin/freeside-upgrade index 419384c2a..25d883fcf 100755 --- a/FS/bin/freeside-upgrade +++ b/FS/bin/freeside-upgrade @@ -3,14 +3,11 @@ use strict; use vars qw($DEBUG $DRY_RUN); use Term::ReadKey; -use DBIx::DBSchema 0.27; +use DBIx::DBSchema 0.31; use FS::UID qw(adminsuidsetup checkeuid datasrc ); #getsecrets); use FS::Schema qw( dbdef dbdef_dist reload_dbdef ); - $DEBUG = 1; -$DRY_RUN = 0; - die "Not running uid freeside!" unless checkeuid(); @@ -25,63 +22,9 @@ dbdef_create($dbh, $dbdef_file); delete $FS::Schema::dbdef_cache{$dbdef_file}; #force an actual reload reload_dbdef($dbdef_file); - -foreach my $table ( dbdef_dist->tables ) { - - if ( dbdef->table($table) ) { - - warn "$table exists\n" if $DEBUG > 1; - - foreach my $column ( dbdef_dist->table($table)->columns ) { - if ( dbdef->table($table)->column($column) ) { - warn " $table.$column exists\n" if $DEBUG > 2; - } else { - - if ( $DEBUG ) { - print STDERR "column $table.$column does not exist. create?"; - next unless yesno(); - } - - foreach my $statement ( - dbdef_dist->table($table)->column($column)->sql_add_column( $dbh ) - ) { - warn "$statement\n" if $DEBUG || $DRY_RUN; - unless ( $DRY_RUN ) { - $dbh->do( $statement) - or die "CREATE error: ". $dbh->errstr. "\nexecuting: $statement"; - } - } - - } - - } - - #should eventually check & create missing indices - - #should eventually drop columns not in dbdef_dist... - - } else { - - if ( $DEBUG ) { - print STDERR "table $table does not exist. create?"; - next unless yesno(); - } - - foreach my $statement ( - dbdef_dist->table($table)->sql_create_table( $dbh ) - ) { - warn "$statement\n" if $DEBUG || $DRY_RUN; - unless ( $DRY_RUN ) { - $dbh->do( $statement) - or die "CREATE error: ". $dbh->errstr. "\nexecuting: $statement"; - } - } - - } - -} - -# should eventually drop tables not in dbdef_dist too i guess... +$DBIx::DBSchema::DEBUG = $DEBUG; +$DBIx::DBSchema::Table::DEBUG = $DEBUG; +dbdef->update_schema( dbdef_dist, $dbh ); $dbh->commit or die $dbh->errstr; @@ -91,32 +34,6 @@ $dbh->disconnect or die $dbh->errstr; ### -my $all = 0; -sub yesno { - print STDERR ' [yes/no/all] '; - if ( $all ) { - warn "yes\n"; - return 1; - } else { - while ( 1 ) { - ReadMode 4; - my $x = lc(ReadKey); - ReadMode 0; - if ( $x eq 'n' ) { - warn "no\n"; - return 0; - } elsif ( $x eq 'y' ) { - warn "yes\n"; - return 1; - } elsif ( $x eq 'a' ) { - warn "yes\n"; - $all = 1; - return 1; - } - } - } -} - sub dbdef_create { # reverse engineer the schema from the DB and save to file my( $dbh, $file ) = @_; my $dbdef = new_native DBIx::DBSchema $dbh; @@ -128,4 +45,3 @@ sub usage { } 1; - -- cgit v1.2.1 From af4493b92157f6e443df148b88d9f65613da1e91 Mon Sep 17 00:00:00 2001 From: ivan Date: Sun, 9 Apr 2006 20:36:06 +0000 Subject: error out if you try to add duplicates; this should lower my annoyance-level --- FS/bin/freeside-adduser | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-adduser b/FS/bin/freeside-adduser index c3ee05b9b..67ffef612 100644 --- a/FS/bin/freeside-adduser +++ b/FS/bin/freeside-adduser @@ -1,6 +1,6 @@ #!/usr/bin/perl -w # -# $Id: freeside-adduser,v 1.8 2002-09-27 05:36:29 ivan Exp $ +# $Id: freeside-adduser,v 1.9 2006-04-09 20:36:06 ivan Exp $ use strict; use vars qw($opt_h $opt_b $opt_c $opt_s); @@ -13,6 +13,14 @@ getopts("bch:s:"); die &usage if $opt_c && ! $opt_h; my $user = shift or die &usage; +open(MAPSECRETS,"<$FREESIDE_CONF/mapsecrets") + or die "can't open $FREESIDE_CONF/mapsecrets: $!"; +while () { + /^(\S+) / or die "unparsable line in mapsecrets: $_"; + die "user $user already exists\n" if $user eq $1; +} +close MAPSECRETS; + if ( $opt_h ) { my @args = ( 'htpasswd' ); push @args, '-b' if $opt_b; -- cgit v1.2.1 From b5b3d4ad4663657fcc980ed8c421b3558d4b7482 Mon Sep 17 00:00:00 2001 From: ivan Date: Thu, 13 Apr 2006 21:29:01 +0000 Subject: don't do the duplicate check unless there's a file already; fixes problem with first use of freeside-adduser --- FS/bin/freeside-adduser | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-adduser b/FS/bin/freeside-adduser index 67ffef612..2eef75827 100644 --- a/FS/bin/freeside-adduser +++ b/FS/bin/freeside-adduser @@ -1,6 +1,6 @@ #!/usr/bin/perl -w # -# $Id: freeside-adduser,v 1.9 2006-04-09 20:36:06 ivan Exp $ +# $Id: freeside-adduser,v 1.10 2006-04-13 21:29:01 ivan Exp $ use strict; use vars qw($opt_h $opt_b $opt_c $opt_s); @@ -13,13 +13,15 @@ getopts("bch:s:"); die &usage if $opt_c && ! $opt_h; my $user = shift or die &usage; -open(MAPSECRETS,"<$FREESIDE_CONF/mapsecrets") - or die "can't open $FREESIDE_CONF/mapsecrets: $!"; -while () { - /^(\S+) / or die "unparsable line in mapsecrets: $_"; - die "user $user already exists\n" if $user eq $1; +if ( -e "$FREESIDE_CONF/mapsecrets" ) { + open(MAPSECRETS,"<$FREESIDE_CONF/mapsecrets") + or die "can't open $FREESIDE_CONF/mapsecrets: $!"; + while () { + /^(\S+) / or die "unparsable line in mapsecrets: $_"; + die "user $user already exists\n" if $user eq $1; + } + close MAPSECRETS; } -close MAPSECRETS; if ( $opt_h ) { my @args = ( 'htpasswd' ); -- cgit v1.2.1 From 2c757d7db4cb6a7b9655de13206fcc84fb7ce61f Mon Sep 17 00:00:00 2001 From: ivan Date: Sun, 14 May 2006 16:47:31 +0000 Subject: first part of ACL and re-skinning work and some other small stuff --- 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 cad07f1fd..02a435141 100644 --- a/FS/bin/freeside-addoutsourceuser +++ b/FS/bin/freeside-addoutsourceuser @@ -3,6 +3,7 @@ username=$1 domain=$2 password=$3 +realdomain=$4 freeside-adduser -h /usr/local/etc/freeside/htpasswd \ -s conf.DBI:Pg:dbname=$domain/secrets \ @@ -10,6 +11,5 @@ freeside-adduser -h /usr/local/etc/freeside/htpasswd \ $username $password 2>/dev/null [ -e /usr/local/etc/freeside/dbdef.DBI:Pg:dbname=$domain ] \ - || ( freeside-setup -s $username 2>/dev/null; \ - /home/ivan/freeside/bin/populate-msgcat $username 2>/dev/null ) + || ( freeside-setup -d $realdomain $username 2>/dev/null ) -- cgit v1.2.1 From 1ed201c9f897f768e3ec8b9e7aee0fcb8b2bfed1 Mon Sep 17 00:00:00 2001 From: ivan Date: Mon, 19 Jun 2006 12:15:32 +0000 Subject: ACL bootstrapping --- FS/bin/freeside-upgrade | 2 ++ 1 file changed, 2 insertions(+) (limited to 'FS/bin') diff --git a/FS/bin/freeside-upgrade b/FS/bin/freeside-upgrade index 25d883fcf..a1212ae98 100755 --- a/FS/bin/freeside-upgrade +++ b/FS/bin/freeside-upgrade @@ -5,6 +5,7 @@ use vars qw($DEBUG $DRY_RUN); use Term::ReadKey; use DBIx::DBSchema 0.31; use FS::UID qw(adminsuidsetup checkeuid datasrc ); #getsecrets); +use FS::CurrentUser; use FS::Schema qw( dbdef dbdef_dist reload_dbdef ); $DEBUG = 1; @@ -12,6 +13,7 @@ $DEBUG = 1; die "Not running uid freeside!" unless checkeuid(); my $user = shift or die &usage; +$FS::CurrentUser::upgrade_hack = 1; my $dbh = adminsuidsetup($user); #needs to match FS::Schema... -- cgit v1.2.1 From c930d34504a46a50eb2438f12dc896efbb15b49d Mon Sep 17 00:00:00 2001 From: ivan Date: Fri, 30 Jun 2006 14:30:26 +0000 Subject: checkin freeside-adduser with the -g flag! sheesh --- FS/bin/freeside-adduser | 77 +++++++++++++++++++++++++++++++++++-------------- 1 file changed, 55 insertions(+), 22 deletions(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-adduser b/FS/bin/freeside-adduser index 2eef75827..3ec2e72cd 100644 --- a/FS/bin/freeside-adduser +++ b/FS/bin/freeside-adduser @@ -1,27 +1,27 @@ #!/usr/bin/perl -w # -# $Id: freeside-adduser,v 1.10 2006-04-13 21:29:01 ivan Exp $ +# $Id: freeside-adduser,v 1.11 2006-06-30 14:30:26 ivan Exp $ use strict; -use vars qw($opt_h $opt_b $opt_c $opt_s); +use vars qw($opt_h $opt_b $opt_c $opt_g); use Fcntl qw(:flock); use Getopt::Std; my $FREESIDE_CONF = "/usr/local/etc/freeside"; -getopts("bch:s:"); +getopts("bch:g:"); die &usage if $opt_c && ! $opt_h; my $user = shift or die &usage; -if ( -e "$FREESIDE_CONF/mapsecrets" ) { - open(MAPSECRETS,"<$FREESIDE_CONF/mapsecrets") - or die "can't open $FREESIDE_CONF/mapsecrets: $!"; - while () { - /^(\S+) / or die "unparsable line in mapsecrets: $_"; - die "user $user already exists\n" if $user eq $1; - } - close MAPSECRETS; -} +#if ( -e "$FREESIDE_CONF/mapsecrets" ) { +# open(MAPSECRETS,"<$FREESIDE_CONF/mapsecrets") +# or die "can't open $FREESIDE_CONF/mapsecrets: $!"; +# while () { +# /^(\S+) / or die "unparsable line in mapsecrets: $_"; +# die "user $user already exists\n" if $user eq $1; +# } +# close MAPSECRETS; +#} if ( $opt_h ) { my @args = ( 'htpasswd' ); @@ -32,16 +32,49 @@ if ( $opt_h ) { system(@args) == 0 or die "htpasswd failed: $?"; } -my $secretfile = $opt_s || 'secrets'; +#my $secretfile = $opt_s || 'secrets'; +# +#open(MAPSECRETS,">>$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: $!"; + +### + +use FS::UID qw(adminsuidsetup); +use FS::CurrentUser; +use FS::access_user; +use FS::access_usergroup; + +$FS::CurrentUser::upgrade_hack = 1; +#adminsuidsetup $rootuser; +adminsuidsetup $user; + +my $access_user = new FS::access_user { + 'username' => $user, + '_password' => 'notyet', + 'first' => 'Firstname', # $opt_f || + 'last' => 'Lastname', # $opt_l || +}; +my $au_error = $access_user->insert; +die $au_error if $au_error; + +if ( $opt_g ) { + + my $access_usergroup = new FS::access_usergroup { + 'usernum' => $access_user->usernum, + 'groupnum' => $opt_g, + }; + my $aug_error = $access_usergroup->insert; + die $aug_error if $aug_error; + +} -open(MAPSECRETS,">>$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: $!"; +### sub usage { - die "Usage:\n\n freeside-adduser [ -h htpasswd_file [ -c ] [ -b ] ] [ -s secretfile ] username" + die "Usage:\n\n freeside-adduser [ -h htpasswd_file [ -c ] [ -b ] ] [ -g groupnum ] username" } =head1 NAME @@ -50,7 +83,7 @@ freeside-adduser - Command line interface to add (freeside) users. =head1 SYNOPSIS - freeside-adduser [ -h htpasswd_file [ -c ] ] [ -s secretfile ] username + freeside-adduser [ -h htpasswd_file [ -c ] ] -g 1 username =head1 DESCRIPTION @@ -61,10 +94,10 @@ sales/tech folks) to the web interface, not for adding customer accounts. -c: Passed to htpasswd(1) - -s: Specify an alternate secret file - -b: same as htpasswd(1), probably insecure, not recommended + -g: initial groupnum + =head1 SEE ALSO L(1), base Freeside documentation -- cgit v1.2.1 From 079be338fb0e200309777249f9e3ea1d115d374e Mon Sep 17 00:00:00 2001 From: ivan Date: Tue, 4 Jul 2006 12:01:03 +0000 Subject: adding freeside-addgroup --- FS/bin/freeside-addgroup | 50 ++++++++++++++++++++++++++++++++++++++++++++++++ FS/bin/freeside-adduser | 2 -- 2 files changed, 50 insertions(+), 2 deletions(-) create mode 100755 FS/bin/freeside-addgroup (limited to 'FS/bin') diff --git a/FS/bin/freeside-addgroup b/FS/bin/freeside-addgroup new file mode 100755 index 000000000..7b30f7d95 --- /dev/null +++ b/FS/bin/freeside-addgroup @@ -0,0 +1,50 @@ +#!/usr/bin/perl + +use strict; +use vars qw($opt_s); +use Getopt::Std; +use FS::UID qw(adminsuidsetup); +use FS::Record qw(qsearch); +use FS::CurrentUser; +use FS::AccessRight; +use FS::access_group; +use FS::access_right; +use FS::access_groupagent; + +getopts("s"); +my $user = shift or die &usage; #just for adminsuidsetup +my $group = shift or die &usage; + +$FS::CurrentUser::upgrade_hack = 1; +#adminsuidsetup $rootuser; +adminsuidsetup $user; + +my $access_group = new FS::access_group { 'groupname' => $group }; +my $error = $access_group->insert; +die $error if $error; + +if ( $opt_s ) { + foreach my $rightname ( FS::AccessRight->rights ) { + my $access_right = new FS::access_right { + 'righttype' => 'FS::access_group', + 'rightobjnum' => $access_group->groupnum, + 'rightname' => $rightname, + }; + my $ar_error = $access_right->insert; + die $ar_error if $ar_error; + } + + foreach my $agent ( qsearch('agent', {} ) ) { + my $access_groupagent = new FS::access_groupagent { + 'groupnum' => $access_group->groupnum, + 'agentnum' => $agent->agentnum, + }; + my $aga_error = $access_groupagent->insert; + die $aga_error if $aga_error; + } +} + +sub usage { + die "Usage:\n\n freeside-addgroup [ -s ] username groupname" +} + diff --git a/FS/bin/freeside-adduser b/FS/bin/freeside-adduser index 3ec2e72cd..0d8b454bf 100644 --- a/FS/bin/freeside-adduser +++ b/FS/bin/freeside-adduser @@ -1,6 +1,4 @@ #!/usr/bin/perl -w -# -# $Id: freeside-adduser,v 1.11 2006-06-30 14:30:26 ivan Exp $ use strict; use vars qw($opt_h $opt_b $opt_c $opt_g); -- cgit v1.2.1 From e5742a8ccfca16427631a45fc8895d6fc1a493dd Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 12 Jul 2006 23:33:56 +0000 Subject: add acl bootstrapping - should be installable again now --- 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 9f87f10b7..138011430 100755 --- a/FS/bin/freeside-setup +++ b/FS/bin/freeside-setup @@ -7,6 +7,7 @@ use strict; use vars qw($opt_s $opt_d $opt_v); use Getopt::Std; use FS::UID qw(adminsuidsetup datasrc checkeuid getsecrets); +use FS::CurrentUser; use FS::Schema qw( dbdef_dist reload_dbdef ); use FS::Record; #use FS::raddb; @@ -85,6 +86,7 @@ $dbdef->save($dbdef_file); # create 'em ### +$FS::CurrentUser::upgrade_hack = 1; my $dbh = adminsuidsetup $user; #create tables -- cgit v1.2.1 From 9bc0e873966642f415795525f8a2a57381afb080 Mon Sep 17 00:00:00 2001 From: ivan Date: Fri, 14 Jul 2006 00:32:12 +0000 Subject: should be able to freeside-setup without a username now --- 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 138011430..2ba717cb3 100755 --- a/FS/bin/freeside-setup +++ b/FS/bin/freeside-setup @@ -19,8 +19,8 @@ die "Not running uid freeside!" unless checkeuid(); # map { lc($FS::raddb::attrib{$_}) => $_ } keys %FS::raddb::attrib; getopts("svd:"); -my $user = shift or die &usage; -getsecrets($user); +#my $user = shift or die &usage; +getsecrets(); #$user); #needs to match FS::Record my($dbdef_file) = "/usr/local/etc/freeside/dbdef.". datasrc; @@ -87,7 +87,7 @@ $dbdef->save($dbdef_file); ### $FS::CurrentUser::upgrade_hack = 1; -my $dbh = adminsuidsetup $user; +my $dbh = adminsuidsetup; #$user; #create tables $|=1; -- cgit v1.2.1 From 65fc97717e093e8ff35d6f4c0efd04e3af334c8d Mon Sep 17 00:00:00 2001 From: ivan Date: Sun, 6 Aug 2006 23:39:02 +0000 Subject: slightly better bootstrapping for htpasswd kludge... hopefully that will go away in 1.7.1 --- FS/bin/freeside-adduser | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-adduser b/FS/bin/freeside-adduser index 0d8b454bf..3976caece 100644 --- a/FS/bin/freeside-adduser +++ b/FS/bin/freeside-adduser @@ -1,13 +1,13 @@ #!/usr/bin/perl -w use strict; -use vars qw($opt_h $opt_b $opt_c $opt_g); +use vars qw($opt_s $opt_h $opt_b $opt_c $opt_g $opt_n); use Fcntl qw(:flock); use Getopt::Std; my $FREESIDE_CONF = "/usr/local/etc/freeside"; -getopts("bch:g:"); +getopts("s:bch:g:n"); die &usage if $opt_c && ! $opt_h; my $user = shift or die &usage; @@ -27,16 +27,21 @@ if ( $opt_h ) { push @args, '-c' if $opt_c; push @args, $opt_h, $user; push @args, shift if $opt_b; + warn join(', ', 'htpasswd', @args)."\n"; system(@args) == 0 or die "htpasswd failed: $?"; } -#my $secretfile = $opt_s || 'secrets'; -# -#open(MAPSECRETS,">>$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: $!"; +if ( $opt_s ) { + open(MAPSECRETS,">>$FREESIDE_CONF/mapsecrets") + and flock(MAPSECRETS,LOCK_EX) + or die "can't open $FREESIDE_CONF/mapsecrets: $!"; + print MAPSECRETS "$user $opt_s\n"; + close MAPSECRETS or die "can't close $FREESIDE_CONF/mapsecrets: $!"; +} + +### + +exit if $opt_n; ### @@ -72,7 +77,7 @@ if ( $opt_g ) { ### sub usage { - die "Usage:\n\n freeside-adduser [ -h htpasswd_file [ -c ] [ -b ] ] [ -g groupnum ] username" + die "Usage:\n\n freeside-adduser [ -h htpasswd_file [ -c ] [ -b ] ] [ -g groupnum ] username [ password ]" } =head1 NAME @@ -81,7 +86,7 @@ freeside-adduser - Command line interface to add (freeside) users. =head1 SYNOPSIS - freeside-adduser [ -h htpasswd_file [ -c ] ] -g 1 username + freeside-adduser [ -n ] [ -h htpasswd_file [ -c ] [ -b ] ] [ -g groupnum ] username [ password ] =head1 DESCRIPTION @@ -96,6 +101,12 @@ sales/tech folks) to the web interface, not for adding customer accounts. -g: initial groupnum + Development/multi-DB options: + + -s: alternate secrets file + + -n: no ACL added, for bootstrapping + =head1 SEE ALSO L(1), base Freeside documentation -- cgit v1.2.1 From 020d74d3e1ce242990486a3fc7b61be5d666c2de Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 16 Aug 2006 08:19:47 +0000 Subject: get rid of too-verbose debugging --- FS/bin/freeside-adduser | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-adduser b/FS/bin/freeside-adduser index 3976caece..b955902ba 100644 --- a/FS/bin/freeside-adduser +++ b/FS/bin/freeside-adduser @@ -27,7 +27,7 @@ if ( $opt_h ) { push @args, '-c' if $opt_c; push @args, $opt_h, $user; push @args, shift if $opt_b; - warn join(', ', 'htpasswd', @args)."\n"; + #warn join(', ', @args)."\n"; system(@args) == 0 or die "htpasswd failed: $?"; } -- cgit v1.2.1 From 0815da7f25324df1040ba64c84ace44e49d7387c Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 30 Aug 2006 15:41:29 +0000 Subject: get rid of all the htpasswd stuff in freeside-adduser --- FS/bin/freeside-adduser | 55 +++++++++++++++++++++---------------------------- 1 file changed, 24 insertions(+), 31 deletions(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-adduser b/FS/bin/freeside-adduser index b955902ba..8f9d4a33f 100644 --- a/FS/bin/freeside-adduser +++ b/FS/bin/freeside-adduser @@ -1,42 +1,33 @@ #!/usr/bin/perl -w use strict; -use vars qw($opt_s $opt_h $opt_b $opt_c $opt_g $opt_n); +use vars qw($opt_s $opt_g $opt_n); use Fcntl qw(:flock); use Getopt::Std; my $FREESIDE_CONF = "/usr/local/etc/freeside"; -getopts("s:bch:g:n"); -die &usage if $opt_c && ! $opt_h; +getopts("s:g:n"); my $user = shift or die &usage; -#if ( -e "$FREESIDE_CONF/mapsecrets" ) { -# open(MAPSECRETS,"<$FREESIDE_CONF/mapsecrets") -# or die "can't open $FREESIDE_CONF/mapsecrets: $!"; -# while () { -# /^(\S+) / or die "unparsable line in mapsecrets: $_"; -# die "user $user already exists\n" if $user eq $1; -# } -# close MAPSECRETS; -#} - -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; - #warn join(', ', @args)."\n"; - system(@args) == 0 or die "htpasswd failed: $?"; -} - if ( $opt_s ) { + + #if ( -e "$FREESIDE_CONF/mapsecrets" ) { + # open(MAPSECRETS,"<$FREESIDE_CONF/mapsecrets") + # or die "can't open $FREESIDE_CONF/mapsecrets: $!"; + # while () { + # /^(\S+) / or die "unparsable line in mapsecrets: $_"; + # die "user $user already exists\n" if $user eq $1; + # } + # close MAPSECRETS; + #} + open(MAPSECRETS,">>$FREESIDE_CONF/mapsecrets") and flock(MAPSECRETS,LOCK_EX) or die "can't open $FREESIDE_CONF/mapsecrets: $!"; print MAPSECRETS "$user $opt_s\n"; close MAPSECRETS or die "can't close $FREESIDE_CONF/mapsecrets: $!"; + } ### @@ -77,7 +68,7 @@ if ( $opt_g ) { ### sub usage { - die "Usage:\n\n freeside-adduser [ -h htpasswd_file [ -c ] [ -b ] ] [ -g groupnum ] username [ password ]" + die "Usage:\n\n freeside-adduser [ -n ] [ -s ] [ -g groupnum ] username [ password ]" } =head1 NAME @@ -86,18 +77,15 @@ freeside-adduser - Command line interface to add (freeside) users. =head1 SYNOPSIS - freeside-adduser [ -n ] [ -h htpasswd_file [ -c ] [ -b ] ] [ -g groupnum ] username [ password ] + freeside-adduser [ -n ] [ -s ] [ -g groupnum ] username [ password ] =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 call htpasswd for this user with the given filename - - -c: Passed to htpasswd(1) - - -b: same as htpasswd(1), probably insecure, not recommended +This functionality is now available in the web interface as well, under +B. -g: initial groupnum @@ -107,9 +95,14 @@ sales/tech folks) to the web interface, not for adding customer accounts. -n: no ACL added, for bootstrapping +=head1 NOTE + +No explicit htpasswd options are available in 1.7 - passwordsa are now +maintained automatically. + =head1 SEE ALSO -L(1), base Freeside documentation +Base Freeside documentation =cut -- cgit v1.2.1 From 31b3104093a59887fd0ec7fc86ef3249de233265 Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 6 Sep 2006 01:08:20 +0000 Subject: new world ACLs --- FS/bin/freeside-setup | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-setup b/FS/bin/freeside-setup index 2ba717cb3..a51dfd7a0 100755 --- a/FS/bin/freeside-setup +++ b/FS/bin/freeside-setup @@ -4,7 +4,7 @@ BEGIN { $FS::Schema::setup_hack = 1; } use strict; -use vars qw($opt_s $opt_d $opt_v); +use vars qw($opt_u $opt_d $opt_v); use Getopt::Std; use FS::UID qw(adminsuidsetup datasrc checkeuid getsecrets); use FS::CurrentUser; @@ -18,9 +18,10 @@ die "Not running uid freeside!" unless checkeuid(); #my %attrib2db = # map { lc($FS::raddb::attrib{$_}) => $_ } keys %FS::raddb::attrib; -getopts("svd:"); +getopts("u:vd:"); #my $user = shift or die &usage; -getsecrets(); #$user); + +getsecrets($opt_u); #$user); #needs to match FS::Record my($dbdef_file) = "/usr/local/etc/freeside/dbdef.". datasrc; @@ -87,7 +88,7 @@ $dbdef->save($dbdef_file); ### $FS::CurrentUser::upgrade_hack = 1; -my $dbh = adminsuidsetup; #$user; +my $dbh = adminsuidsetup $opt_u; #$user; #create tables $|=1; @@ -120,7 +121,8 @@ sub dbdef_create { # reverse engineer the schema from the DB and save to file } sub usage { - die "Usage:\n freeside-setup -d domain.name [ -v ] user\n"; + die "Usage:\n freeside-setup -d domain.name [ -v ]\n" + # [ -u user ] for devel/multi-db installs } 1; -- cgit v1.2.1 From 5ca0a811040aa6037b8423571236705df4bd3db1 Mon Sep 17 00:00:00 2001 From: ivan Date: Mon, 9 Oct 2006 01:05:27 +0000 Subject: update the tools for dev installs --- FS/bin/freeside-addoutsource | 5 +++-- FS/bin/freeside-addoutsourceuser | 14 +++++++++----- FS/bin/freeside-adduser | 15 +++++++++++++-- 3 files changed, 25 insertions(+), 9 deletions(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-addoutsource b/FS/bin/freeside-addoutsource index db4e7a307..386e76315 100644 --- a/FS/bin/freeside-addoutsource +++ b/FS/bin/freeside-addoutsource @@ -8,8 +8,9 @@ mkdir /usr/local/etc/freeside/conf.DBI:Pg:dbname=$domain && \ \ chown freeside /usr/local/etc/freeside/conf.DBI:Pg:dbname=$domain && \ \ -cp /home/ivan/freeside/conf/[a-z]* /usr/local/etc/freeside/conf.DBI:Pg:dbname=$domain && \ -\ +cp /home/ivan/freeside/conf/[a-z]* /usr/local/etc/freeside/conf.DBI:Pg:dbname=$domain + + touch /usr/local/etc/freeside/conf.DBI:Pg:dbname=$domain/secrets && \ \ chown freeside /usr/local/etc/freeside/conf.DBI:Pg:dbname=$domain/secrets && \ diff --git a/FS/bin/freeside-addoutsourceuser b/FS/bin/freeside-addoutsourceuser index 02a435141..889d28adb 100644 --- a/FS/bin/freeside-addoutsourceuser +++ b/FS/bin/freeside-addoutsourceuser @@ -5,11 +5,15 @@ domain=$2 password=$3 realdomain=$4 -freeside-adduser -h /usr/local/etc/freeside/htpasswd \ - -s conf.DBI:Pg:dbname=$domain/secrets \ - -b \ - $username $password 2>/dev/null + +freeside-adduser -s conf.DBI:Pg:dbname=$domain/secrets \ + -n \ + $username #2>/dev/null [ -e /usr/local/etc/freeside/dbdef.DBI:Pg:dbname=$domain ] \ - || ( freeside-setup -d $realdomain $username 2>/dev/null ) + || ( freeside-setup -d $realdomain -u $username ) +# 2>/dev/null + +freeside-adduser -g 1 $username +htpasswd -b /usr/local/etc/freeside/htpasswd $username $password diff --git a/FS/bin/freeside-adduser b/FS/bin/freeside-adduser index 8f9d4a33f..a315f1082 100644 --- a/FS/bin/freeside-adduser +++ b/FS/bin/freeside-adduser @@ -22,11 +22,22 @@ if ( $opt_s ) { # close MAPSECRETS; #} - open(MAPSECRETS,">>$FREESIDE_CONF/mapsecrets") + #insert new entry before a wildcard... + open(MAPSECRETS,"<$FREESIDE_CONF/mapsecrets") and flock(MAPSECRETS,LOCK_EX) or die "can't open $FREESIDE_CONF/mapsecrets: $!"; - print MAPSECRETS "$user $opt_s\n"; + open(NEW,">$FREESIDE_CONF/mapsecrets.new") + or die "can't open $FREESIDE_CONF/mapsecrets.new: $!"; + while() { + if ( /^\*\s/ ) { + print NEW "$user $opt_s\n"; + } + print NEW $_; + } close MAPSECRETS or die "can't close $FREESIDE_CONF/mapsecrets: $!"; + close NEW or die "can't close $FREESIDE_CONF/mapsecrets.new: $!"; + rename("$FREESIDE_CONF/mapsecrets.new", "$FREESIDE_CONF/mapsecrets") + or die "can't move mapsecrets.new into place: $!"; } -- cgit v1.2.1 From dfa5a456854a8a31c671f363be9a7a7bde9b94bf Mon Sep 17 00:00:00 2001 From: ivan Date: Sun, 22 Oct 2006 05:18:37 +0000 Subject: add price plan option for prepaid packages to cancel instead of suspend --- FS/bin/freeside-prepaidd | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-prepaidd b/FS/bin/freeside-prepaidd index e51a56350..1f5731626 100644 --- a/FS/bin/freeside-prepaidd +++ b/FS/bin/freeside-prepaidd @@ -37,8 +37,12 @@ while (1) { " AND ( cancel IS NULL OR cancel = 0)" } ) ) { - my $error = $cust_pkg->suspend; - warn "Error suspended package ". $cust_pkg->pkgnum. + + my $action = $cust_pkg->part_pkg->option('recur_action') || 'suspend'; + + my $error = $cust_pkg->$action(); + + warn "Error ${action}ing package ". $cust_pkg->pkgnum. " for custnum ". $cust_pkg->custnum. ": $error\n" if $error; @@ -65,8 +69,8 @@ freeside-prepaidd - Real-time daemon for prepaid packages =head1 DESCRIPTION -Runs continuously and suspendes any prepaid customer packages which have -passed their renewal date (next bill date). +Runs continuously and suspends or cancels any prepaid customer packages which +have passed their renewal date (next bill date). =head1 SEE ALSO -- cgit v1.2.1 From e2ebab296df15704115bdb2048ab0ebd4015732f Mon Sep 17 00:00:00 2001 From: ivan Date: Mon, 30 Oct 2006 00:26:51 +0000 Subject: removing pre-1.4 freeside-bill --- FS/bin/freeside-bill | 128 --------------------------------------------------- 1 file changed, 128 deletions(-) delete mode 100755 FS/bin/freeside-bill (limited to 'FS/bin') diff --git a/FS/bin/freeside-bill b/FS/bin/freeside-bill deleted file mode 100755 index 49ad4a768..000000000 --- a/FS/bin/freeside-bill +++ /dev/null @@ -1,128 +0,0 @@ -#!/usr/bin/perl -w -# don't take any world-facing input -#!/usr/bin/perl -Tw - -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_a $opt_c $opt_d $opt_p); -getopts("acd:p"); -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)= $opt_d ? str2time($opt_d) : $^T; - -# find packages w/ bill < time && cancel != '', and create corresponding -# customer objects - -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 ( - ( $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"; - - my($error); - - $error=$cust_main->bill('time'=>$time); - warn "Error billing, customer #" . $cust_main->getfield('custnum') . - ":" . $error if $error; - - if ($opt_p) { - $cust_main->apply_payments; - $cust_main->apply_credits; - } - - if ($opt_c) { - $error=$cust_main->collect( 'invoice_time' => $time); - warn "Error collecting from customer #" . $cust_main->custnum. ":$error" - if $error; - - #sleep 1; - } - -} - -# 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-bill [ -c [ -p ] ] [ -d 'date' ] user [ custnum custnum ... ]\n"; -} - -=head1 NAME - -freeside-bill - Command line (crontab, script) interface to customer billing. - -=head1 SYNOPSIS - - freeside-bill [ -c [ -p ] [ -a ] ] [ -d 'date' ] user [ custnum custnum ... ] - -=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. - - -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) - - -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, L, config.html from the base documentation - -=cut - -- cgit v1.2.1 From e832476aeab5f4da2b342b30ee9eed84bf451e80 Mon Sep 17 00:00:00 2001 From: ivan Date: Sun, 5 Nov 2006 16:58:19 +0000 Subject: fix spurious disconnection errors in selfservice server log --- FS/bin/freeside-selfservice-server | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-selfservice-server b/FS/bin/freeside-selfservice-server index 6026fd18f..0ba97f6fb 100644 --- a/FS/bin/freeside-selfservice-server +++ b/FS/bin/freeside-selfservice-server @@ -134,11 +134,11 @@ while (1) { } else { #kid time ##get new db handle - #$FS::UID::dbh->{InactiveDestroy} = 1; - #forksuidsetup($user); + $FS::UID::dbh->{InactiveDestroy} = 1; + forksuidsetup($user); #get db handle - adminsuidsetup($user); + #adminsuidsetup($user); my $type = $packet->{_packet}; warn "calling $type handler\n" if $Debug; -- cgit v1.2.1 From 7b28c0c12fe5e623324102a5ee4114f42b5ede3e Mon Sep 17 00:00:00 2001 From: ivan Date: Fri, 17 Nov 2006 10:16:10 +0000 Subject: initial fix for prepaid renewal problem; attempt to use an existing credit/payment before suspending --- FS/bin/freeside-prepaidd | 39 ++++++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 7 deletions(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-prepaidd b/FS/bin/freeside-prepaidd index 1f5731626..73f7523c4 100644 --- a/FS/bin/freeside-prepaidd +++ b/FS/bin/freeside-prepaidd @@ -3,7 +3,7 @@ use strict; use FS::Daemon qw(daemonize1 drop_root logfile daemonize2 sigint sigterm); use FS::UID qw(adminsuidsetup); -use FS::Record qw(qsearch); # qsearchs); +use FS::Record qw(qsearch qsearchs); use FS::cust_pkg; my $user = shift or die &usage; @@ -38,12 +38,37 @@ while (1) { } ) ) { - my $action = $cust_pkg->part_pkg->option('recur_action') || 'suspend'; - - my $error = $cust_pkg->$action(); - - warn "Error ${action}ing package ". $cust_pkg->pkgnum. - " for custnum ". $cust_pkg->custnum. + my $work_cust_pkg = $cust_pkg; + + my $cust_main = $cust_pkg->cust_main; + if ( $cust_main->total_unapplied_payments > 0 + or $cust_main->total_credited > 0 + ) + { + #this needs a flag to say only do the prepaid packages... + # and only try em if the renewal price matches.. but this will do for now + my $b_error = $cust_main->bill; + if ( $b_error ) { + warn "Error billing customer #". $cust_main->custnum; + next; + } + #$b_error = $cust_main->apply_payments_and_credits; + $b_error = $cust_main->apply_payments; + $b_error = $cust_main->apply_credits; + + $work_cust_pkg = qsearchs('cust_pkg', { 'pkgnum' => $work_cust_pkg->pkgnum } ); + + next + if $cust_main->balance <= 0 + and $work_cust_pkg->bill >= time; + } + + my $action = $work_cust_pkg->part_pkg->option('recur_action') || 'suspend'; + + my $error = $work_cust_pkg->$action(); + + warn "Error ${action}ing package ". $work_cust_pkg->pkgnum. + " for custnum ". $work_cust_pkg->custnum. ": $error\n" if $error; } -- cgit v1.2.1 From d70031daf3aaf984fbca5ef265e160eb5d0a3c45 Mon Sep 17 00:00:00 2001 From: ivan Date: Fri, 1 Dec 2006 01:34:38 +0000 Subject: begone $Id$ and your diff noise! --- FS/bin/freeside-email | 4 ---- 1 file changed, 4 deletions(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-email b/FS/bin/freeside-email index 400dc2ac7..7a93f78ee 100755 --- a/FS/bin/freeside-email +++ b/FS/bin/freeside-email @@ -47,10 +47,6 @@ 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.2 2002-09-18 22:50:44 ivan Exp $ - =head1 BUGS =head1 SEE ALSO -- cgit v1.2.1 From 35580de188bd48ec0394493d1698bedcc9794204 Mon Sep 17 00:00:00 2001 From: ivan Date: Fri, 1 Dec 2006 01:35:24 +0000 Subject: go away and never come back, $Id$ --- FS/bin/freeside-expiration-alerter | 4 ---- 1 file changed, 4 deletions(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-expiration-alerter b/FS/bin/freeside-expiration-alerter index 691fd3aa5..e49bd62aa 100755 --- a/FS/bin/freeside-expiration-alerter +++ b/FS/bin/freeside-expiration-alerter @@ -200,10 +200,6 @@ 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.5 2003-04-21 20:53:57 ivan Exp $ - =head1 BUGS Yes..... Use at your own risk. No guarantees or warrantees of any -- cgit v1.2.1 From 898496d879275cb04d75d88ec9b78400609b2179 Mon Sep 17 00:00:00 2001 From: ivan Date: Fri, 1 Dec 2006 01:41:39 +0000 Subject: remove unnecessary service use (in an awfully odd place) --- FS/bin/freeside-queued | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-queued b/FS/bin/freeside-queued index 3a0a9b4e5..9c2867963 100644 --- a/FS/bin/freeside-queued +++ b/FS/bin/freeside-queued @@ -10,11 +10,8 @@ use FS::Record qw(qsearch qsearchs); use FS::queue; use FS::queue_depend; -# no autoloading just yet -use FS::cust_main; -use FS::svc_acct; +# no autoloading for non-FS classes... use Net::SSH 0.07; -use FS::part_export; $DEBUG = 0; -- cgit v1.2.1 From 7422aa77086326ba1e6032150ce5704d1003ea6f Mon Sep 17 00:00:00 2001 From: ivan Date: Thu, 14 Dec 2006 09:27:26 +0000 Subject: make the config directory configurable --- FS/bin/freeside-addoutsource | 29 +++++++++++++--------- FS/bin/freeside-addoutsourceuser | 7 +++--- FS/bin/freeside-adduser | 2 +- FS/bin/freeside-deloutsource | 11 +++++---- FS/bin/freeside-deloutsourceuser | 2 +- FS/bin/freeside-deluser | 2 +- FS/bin/freeside-queued | 2 +- FS/bin/freeside-selfservice-server | 5 ++-- FS/bin/freeside-setup | 3 ++- FS/bin/freeside-sqlradius-radacctd | 2 +- FS/bin/freeside-upgrade | 50 ++++++++++++++++++++++++++++++++------ 11 files changed, 79 insertions(+), 36 deletions(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-addoutsource b/FS/bin/freeside-addoutsource index 386e76315..8291c6434 100644 --- a/FS/bin/freeside-addoutsource +++ b/FS/bin/freeside-addoutsource @@ -2,24 +2,29 @@ domain=$1 +FREESIDE_CONF=%%%FREESIDE_CONF%%% + +#without this, [a-z]* matches CVS/, the copy doesn't return a sucessful error +# status, and the rest of the commands aren't run +export LANG=C + createdb $domain && \ \ -mkdir /usr/local/etc/freeside/conf.DBI:Pg:dbname=$domain && \ +mkdir $FREESIDE_CONF/conf.DBI:Pg:dbname=$domain && \ \ -chown freeside /usr/local/etc/freeside/conf.DBI:Pg:dbname=$domain && \ +chown freeside $FREESIDE_CONF/conf.DBI:Pg:dbname=$domain && \ \ -cp /home/ivan/freeside/conf/[a-z]* /usr/local/etc/freeside/conf.DBI:Pg:dbname=$domain - - -touch /usr/local/etc/freeside/conf.DBI:Pg:dbname=$domain/secrets && \ +cp /home/ivan/freeside/conf/[a-z]* $FREESIDE_CONF/conf.DBI:Pg:dbname=$domain && \ +\ +touch $FREESIDE_CONF/conf.DBI:Pg:dbname=$domain/secrets && \ \ -chown freeside /usr/local/etc/freeside/conf.DBI:Pg:dbname=$domain/secrets && \ +chown freeside $FREESIDE_CONF/conf.DBI:Pg:dbname=$domain/secrets && \ \ -chmod 600 /usr/local/etc/freeside/conf.DBI:Pg:dbname=$domain/secrets && \ +chmod 600 $FREESIDE_CONF/conf.DBI:Pg:dbname=$domain/secrets && \ \ -echo -e "DBI:Pg:dbname=$domain\nfreeside\n" >/usr/local/etc/freeside/conf.DBI:Pg:dbname=$domain/secrets && \ +echo -e "DBI:Pg:dbname=$domain\nfreeside\n" >$FREESIDE_CONF/conf.DBI:Pg:dbname=$domain/secrets && \ \ -mkdir /usr/local/etc/freeside/counters.DBI:Pg:dbname=$domain && \ -mkdir /usr/local/etc/freeside/cache.DBI:Pg:dbname=$domain && \ -mkdir /usr/local/etc/freeside/export.DBI:Pg:dbname=$domain +mkdir $FREESIDE_CONF/counters.DBI:Pg:dbname=$domain && \ +mkdir $FREESIDE_CONF/cache.DBI:Pg:dbname=$domain && \ +mkdir $FREESIDE_CONF/export.DBI:Pg:dbname=$domain diff --git a/FS/bin/freeside-addoutsourceuser b/FS/bin/freeside-addoutsourceuser index 889d28adb..cbe792acc 100644 --- a/FS/bin/freeside-addoutsourceuser +++ b/FS/bin/freeside-addoutsourceuser @@ -4,16 +4,15 @@ username=$1 domain=$2 password=$3 realdomain=$4 - +FREESIDE_CONF=%%%FREESIDE_CONF%%% freeside-adduser -s conf.DBI:Pg:dbname=$domain/secrets \ -n \ $username #2>/dev/null -[ -e /usr/local/etc/freeside/dbdef.DBI:Pg:dbname=$domain ] \ +[ -e $FREESIDE_CONF/dbdef.DBI:Pg:dbname=$domain ] \ || ( freeside-setup -d $realdomain -u $username ) -# 2>/dev/null freeside-adduser -g 1 $username -htpasswd -b /usr/local/etc/freeside/htpasswd $username $password +htpasswd -b $FREESIDE_CONF/htpasswd $username $password diff --git a/FS/bin/freeside-adduser b/FS/bin/freeside-adduser index a315f1082..237e29ef8 100644 --- a/FS/bin/freeside-adduser +++ b/FS/bin/freeside-adduser @@ -5,7 +5,7 @@ use vars qw($opt_s $opt_g $opt_n); use Fcntl qw(:flock); use Getopt::Std; -my $FREESIDE_CONF = "/usr/local/etc/freeside"; +my $FREESIDE_CONF = "%%%FREESIDE_CONF%%%"; getopts("s:g:n"); my $user = shift or die &usage; diff --git a/FS/bin/freeside-deloutsource b/FS/bin/freeside-deloutsource index 561853539..72aca048f 100644 --- a/FS/bin/freeside-deloutsource +++ b/FS/bin/freeside-deloutsource @@ -1,11 +1,12 @@ #!/bin/sh domain=$1 +FREESIDE_CONF=%%%FREESIDE_CONF%%% 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 +rm -rf $FREESIDE_CONF/conf.DBI:Pg:host=localhost\;dbname=$domain && \ +rm -rf $FREESIDE_CONF/counters.DBI:Pg:host=localhost\;dbname=$domain && \ +rm -rf $FREESIDE_CONF/cache.DBI:Pg:host=localhost\;dbname=$domain && \ +rm -rf $FREESIDE_CONF/export.DBI:Pg:host=localhost\;dbname=$domain && \ +rm $FREESIDE_CONF/dbdef.DBI:Pg:host=localhost\;dbname=$domain diff --git a/FS/bin/freeside-deloutsourceuser b/FS/bin/freeside-deloutsourceuser index 96871e50c..dc4ff9cdc 100644 --- a/FS/bin/freeside-deloutsourceuser +++ b/FS/bin/freeside-deloutsourceuser @@ -2,5 +2,5 @@ username=$1 -freeside-deluser -h /usr/local/etc/freeside/htpasswd $username 2>/dev/null +freeside-deluser -h %%%FREESIDE_CONF%%%/htpasswd $username 2>/dev/null diff --git a/FS/bin/freeside-deluser b/FS/bin/freeside-deluser index 57d6ce165..a2a361a83 100644 --- a/FS/bin/freeside-deluser +++ b/FS/bin/freeside-deluser @@ -5,7 +5,7 @@ use vars qw($opt_h); use Fcntl qw(:flock); use Getopt::Std; -my $FREESIDE_CONF = "/usr/local/etc/freeside"; +my $FREESIDE_CONF = "%%%FREESIDE_CONF%%%"; getopts("h:"); my $user = shift or die &usage; diff --git a/FS/bin/freeside-queued b/FS/bin/freeside-queued index 9c2867963..d16513bdd 100644 --- a/FS/bin/freeside-queued +++ b/FS/bin/freeside-queued @@ -41,7 +41,7 @@ while ( $@ ) { } } -logfile( "/usr/local/etc/freeside/queuelog.". $FS::UID::datasrc ); +logfile( "%%%FREESIDE_CONF%%%/queuelog.". $FS::UID::datasrc ); warn "completing daemonization (detaching))\n" if $DEBUG; daemonize2(); diff --git a/FS/bin/freeside-selfservice-server b/FS/bin/freeside-selfservice-server index 0ba97f6fb..fc04ee91e 100644 --- a/FS/bin/freeside-selfservice-server +++ b/FS/bin/freeside-selfservice-server @@ -18,6 +18,8 @@ use FS::Conf; use FS::cust_bill; use FS::cust_pkg; +$FREESIDE_CONF = "%%%FREESIDE_CONF%%%"; + $Debug = 1; # 2 will turn on more logging # 3 will log packet contents, including passwords @@ -50,11 +52,10 @@ $ENV{HOME} = (getpwuid($>))[7]; #for ssh adminsuidsetup $user; #logfile("/usr/local/etc/freeside/selfservice.". $FS::UID::datasrc); #MACHINE -logfile("/usr/local/etc/freeside/selfservice.$machine.log"); +logfile("$FREESIDE_SERVER/selfservice.$machine.log"); daemonize2(); - my $conf = new FS::Conf; my $clientd = "/usr/local/sbin/freeside-selfservice-clientd"; #better name? diff --git a/FS/bin/freeside-setup b/FS/bin/freeside-setup index a51dfd7a0..ddc210f50 100755 --- a/FS/bin/freeside-setup +++ b/FS/bin/freeside-setup @@ -24,7 +24,7 @@ getopts("u:vd:"); getsecrets($opt_u); #$user); #needs to match FS::Record -my($dbdef_file) = "/usr/local/etc/freeside/dbdef.". datasrc; +my($dbdef_file) = "%%%FREESIDE_CONF%%%/dbdef.". datasrc; ### @@ -127,3 +127,4 @@ sub usage { 1; + diff --git a/FS/bin/freeside-sqlradius-radacctd b/FS/bin/freeside-sqlradius-radacctd index e98eaa015..bf415961c 100644 --- a/FS/bin/freeside-sqlradius-radacctd +++ b/FS/bin/freeside-sqlradius-radacctd @@ -23,7 +23,7 @@ drop_root(); adminsuidsetup $user; -logfile( "/usr/local/etc/freeside/sqlradius-radacctd-log.". $FS::UID::datasrc ); +logfile( "%%%FREESIDE_CONF%%%/sqlradius-radacctd-log.". $FS::UID::datasrc ); daemonize2(); diff --git a/FS/bin/freeside-upgrade b/FS/bin/freeside-upgrade index a1212ae98..3a4e4f8e3 100755 --- a/FS/bin/freeside-upgrade +++ b/FS/bin/freeside-upgrade @@ -1,23 +1,29 @@ #!/usr/bin/perl -w use strict; +use vars qw($opt_d $opt_q $opt_v); use vars qw($DEBUG $DRY_RUN); -use Term::ReadKey; +use Getopt::Std; use DBIx::DBSchema 0.31; use FS::UID qw(adminsuidsetup checkeuid datasrc ); #getsecrets); use FS::CurrentUser; use FS::Schema qw( dbdef dbdef_dist reload_dbdef ); -$DEBUG = 1; - die "Not running uid freeside!" unless checkeuid(); +getopts("dq"); + +$DEBUG = !$opt_q; +#$DEBUG = $opt_v; + +$DRY_RUN = $opt_d; + my $user = shift or die &usage; $FS::CurrentUser::upgrade_hack = 1; my $dbh = adminsuidsetup($user); #needs to match FS::Schema... -my $dbdef_file = "/usr/local/etc/freeside/dbdef.". datasrc; +my $dbdef_file = "%%%FREESIDE_CONF%%%/dbdef.". datasrc; dbdef_create($dbh, $dbdef_file); @@ -26,7 +32,13 @@ reload_dbdef($dbdef_file); $DBIx::DBSchema::DEBUG = $DEBUG; $DBIx::DBSchema::Table::DEBUG = $DEBUG; -dbdef->update_schema( dbdef_dist, $dbh ); + +if ( $DRY_RUN ) { + print join(";\n", dbdef->sql_update_schema( dbdef_dist, $dbh ) ). ";\n"; + exit; +} else { + dbdef->update_schema( dbdef_dist, $dbh ); +} $dbh->commit or die $dbh->errstr; @@ -43,7 +55,31 @@ sub dbdef_create { # reverse engineer the schema from the DB and save to file } sub usage { - die "Usage:\n freeside-upgrade user\n"; + die "Usage:\n freeside-upgrade [ -d ] [ -q | -v ] user\n"; } -1; +=head1 NAME + +freeside-upgrade - Upgrades database schema for new freeside verisons. + +=head1 SYNOPSIS + + freeside-adduser [ -d ] [ -q | -v ] + +=head1 DESCRIPTION + +Reads your existing database schema and updates it to match the current schema, +adding any columns or tables necessary. + + [ -d ]: Dry run; output SQL statements (to STDOUT) only, but do not execute + them. + + [ -q ]: Run quietly. This may become the default at some point. + + [ -v ]: Run verbosely, sending debugging information to STDERR. This is the + current default. + +=head1 SEE ALSO + +=cut + -- cgit v1.2.1 From 1163d4d5044ca487ae9cf2176346e297979aa1e1 Mon Sep 17 00:00:00 2001 From: ivan Date: Fri, 15 Dec 2006 00:28:46 +0000 Subject: tiny bit of cleanup from the conf merge --- FS/bin/freeside-addoutsource | 8 +++++--- FS/bin/freeside-deloutsource | 8 +++++--- FS/bin/freeside-queued | 2 +- FS/bin/freeside-selfservice-server | 9 +++++---- FS/bin/freeside-sqlradius-radacctd | 2 +- 5 files changed, 17 insertions(+), 12 deletions(-) (limited to 'FS/bin') diff --git a/FS/bin/freeside-addoutsource b/FS/bin/freeside-addoutsource index 8291c6434..9cb12195a 100644 --- a/FS/bin/freeside-addoutsource +++ b/FS/bin/freeside-addoutsource @@ -3,6 +3,8 @@ domain=$1 FREESIDE_CONF=%%%FREESIDE_CONF%%% +FREESIDE_CACHE=%%%FREESIDE_CACHE%%% +FREESIDE_EXPORT=%%%FREESIDE_EXPORT%%% #without this, [a-z]* matches CVS/, the copy doesn't return a sucessful error # status, and the rest of the commands aren't run @@ -24,7 +26,7 @@ chmod 600 $FREESIDE_CONF/conf.DBI:Pg:dbname=$domain/secrets && \ \ echo -e "DBI:Pg:dbname=$domain\nfreeside\n" >$FREESIDE_CONF/conf.DBI:Pg:dbname=$domain/secrets && \ \ -mkdir $FREESIDE_CONF/counters.DBI:Pg:dbname=$domain && \ -mkdir $FREESIDE_CONF/cache.DBI:Pg:dbname=$domain && \ -mkdir $FREESIDE_CONF/export.DBI:Pg:dbname=$domain +mkdir $FREESIDE_CACHE/counters.DBI:Pg:dbname=$domain && \ +mkdir $FREESIDE_CACHE/cache.DBI:Pg:dbname=$domain && \ +mkdir $FREESIDE_EXPORT/export.DBI:Pg:dbname=$domain diff --git a/FS/bin/freeside-deloutsource b/FS/bin/freeside-deloutsource index 72aca048f..afc3a0118 100644 --- a/FS/bin/freeside-deloutsource +++ b/FS/bin/freeside-deloutsource @@ -2,11 +2,13 @@ domain=$1 FREESIDE_CONF=%%%FREESIDE_CONF%%% +FREESIDE_CACHE=%%%FREESIDE_CACHE%%% +FREESIDE_EXPORT=%%%FREESIDE_EXPORT%%% dropdb $domain && \ rm -rf $FREESIDE_CONF/conf.DBI:Pg:host=localhost\;dbname=$domain && \ -rm -rf $FREESIDE_CONF/counters.DBI:Pg:host=localhost\;dbname=$domain && \ -rm -rf $FREESIDE_CONF/cache.DBI:Pg:host=localhost\;dbname=$domain && \ -rm -rf $FREESIDE_CONF/export.DBI:Pg:host=localhost\;dbname=$domain && \ +rm -rf $FREESIDE_CACHE/counters.DBI:Pg:host=localhost\;dbname=$domain && \ +rm -rf $FREESIDE_CACHE/cache.DBI:Pg:host=localhost\;dbname=$domain && \ +rm -rf $FREESIDE_EXPORT/export.DBI:Pg:host=localhost\;dbname=$domain && \ rm $FREESIDE_CONF/dbdef.DBI:Pg:host=localhost\;dbname=$domain diff --git a/FS/bin/freeside-queued b/FS/bin/freeside-queued index d16513bdd..93d735d1a 100644 --- a/FS/bin/freeside-queued +++ b/FS/bin/freeside-queued @@ -41,7 +41,7 @@ while ( $@ ) { } } -logfile( "%%%FREESIDE_CONF%%%/queuelog.". $FS::UID::datasrc ); +logfile( "%%%FREESIDE_LOG%%%/queuelog.". $FS::UID::datasrc ); warn "completing daemonization (detaching))\n" if $DEBUG; daemonize2(); diff --git a/FS/bin/freeside-selfservice-server b/FS/bin/freeside-selfservice-server index fc04ee91e..187bc1469 100644 --- a/FS/bin/freeside-selfservice-server +++ b/FS/bin/freeside-selfservice-server @@ -1,6 +1,7 @@ #!/usr/bin/perl -w use strict; +use vars qw( $FREESIDE_LOG $FREESIDE_LOCK ); use vars qw( $Debug %kids $kids $max_kids $ssh_pid %old_ssh_pid $keepalives ); use subs qw( lock_write unlock_write myshutdown usage ); use Fcntl qw(:flock); @@ -18,7 +19,8 @@ use FS::Conf; use FS::cust_bill; use FS::cust_pkg; -$FREESIDE_CONF = "%%%FREESIDE_CONF%%%"; +$FREESIDE_LOG = "%%%FREESIDE_LOG%%%"; +$FREESIDE_LOCK = "%%%FREESIDE_LOCK%%%"; $Debug = 1; # 2 will turn on more logging # 3 will log packet contents, including passwords @@ -31,8 +33,7 @@ my $user = shift or die &usage; my $machine = shift or die &usage; my $tag = scalar(@ARGV) ? shift : ''; -my $lock_file = "/usr/local/etc/freeside/selfservice.$machine.writelock"; - +my $lock_file = "$FREESIDE_LOCK/selfservice.$machine.writelock"; # to keep pid files unique w/multi machines (and installs!) # $FS::UID::datasrc not posible @@ -52,7 +53,7 @@ $ENV{HOME} = (getpwuid($>))[7]; #for ssh adminsuidsetup $user; #logfile("/usr/local/etc/freeside/selfservice.". $FS::UID::datasrc); #MACHINE -logfile("$FREESIDE_SERVER/selfservice.$machine.log"); +logfile("$FREESIDE_LOG/selfservice.$machine.log"); daemonize2(); diff --git a/FS/bin/freeside-sqlradius-radacctd b/FS/bin/freeside-sqlradius-radacctd index bf415961c..83fd4bfd1 100644 --- a/FS/bin/freeside-sqlradius-radacctd +++ b/FS/bin/freeside-sqlradius-radacctd @@ -23,7 +23,7 @@ drop_root(); adminsuidsetup $user; -logfile( "%%%FREESIDE_CONF%%%/sqlradius-radacctd-log.". $FS::UID::datasrc ); +logfile( "%%%FREESIDE_LOG%%%/sqlradius-radacctd-log.". $FS::UID::datasrc ); daemonize2(); -- cgit v1.2.1 From 56be01c046fe4aad7f9a9aacc41b509483cc05f1 Mon Sep 17 00:00:00 2001 From: jeff Date: Tue, 23 Jan 2007 23:43:00 +0000 Subject: notices before first charge on flat_delayed --- FS/bin/freeside-daily | 3 +++ 1 file changed, 3 insertions(+) (limited to 'FS/bin') diff --git a/FS/bin/freeside-daily b/FS/bin/freeside-daily index b9742c4d1..a06a2b185 100755 --- a/FS/bin/freeside-daily +++ b/FS/bin/freeside-daily @@ -15,6 +15,9 @@ adminsuidsetup $user; use FS::Cron::bill qw(bill); bill(%opt); +use FS::Cron::notify qw(notify_flat_delay); +notify_flat_delay(%opt); + use FS::Cron::vacuum qw(vacuum); vacuum(); -- cgit v1.2.1 From 14e3560b43ca8a747f4210bd784a0315daeb5e9e Mon Sep 17 00:00:00 2001 From: jeff Date: Sat, 3 Feb 2007 02:39:51 +0000 Subject: do a setfixed --- FS/bin/freeside-reset-fixed | 69 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100755 FS/bin/freeside-reset-fixed (limited to 'FS/bin') diff --git a/FS/bin/freeside-reset-fixed b/FS/bin/freeside-reset-fixed new file mode 100755 index 000000000..5829d441b --- /dev/null +++ b/FS/bin/freeside-reset-fixed @@ -0,0 +1,69 @@ +#!/usr/bin/perl -w + +use strict; +use vars qw($opt_p $opt_s $opt_r); +use Getopt::Std; +use FS::UID qw(adminsuidsetup); +use FS::Record qw(qsearch qsearchs); +use FS::cust_svc; +use FS::svc_Common; + +getopts('p:s:r'); + +my $user = shift or die &usage; +adminsuidsetup $user; + +die &usage + if ($opt_p && $opt_s); + +$FS::Record::nowarn_identical = 1; +$FS::svc_Common::noexport_hack = 1 + unless $opt_r; + +my @svc_x = (); +if ( $opt_s ) { + $opt_s =~ /^(\d+)$/ or die "invalid svcnum"; + my $cust_svc = qsearchs('cust_svc', { svcnum => $1 } ) + or die "svcnum $opt_s not found\n"; + push @svc_x, $cust_svc->svc_x; +} elsif ( $opt_p ) { + $opt_p =~ /^(\d+)$/ or die "invalid svcpart"; + push @svc_x, map { $_->svc_x } qsearch('cust_svc', { svcpart => $1 } ); + die "no services with svcpart $opt_p found\n" unless @svc_x; +} else { + push @svc_x, map { $_->svc_x } qsearch('cust_svc', {} ); + die "no services found\n" unless @svc_x; +} + +foreach my $svc_x ( @svc_x ) { + my $result = $svc_x->setfixed; + die $result unless ref($result); + my $error = $svc_x->replace + if $svc_x->modified; + die $error if $error; +} + + +sub usage { + die "Usage:\n\n freeside-reset-fixed user [ -s svcnum | -p svcpart ] [ -r ]\n"; +} + +=head1 NAME + +freeside-reset-fixed - Command line tool to set the fixed columns for existing services + +=head1 SYNOPSIS + + freeside-reset-fixed user [ -s svcnum | -p svcpart ] [ -r ] + +=head1 DESCRIPTION + + Resets the fixed columns for the specified service part or service number. + Re-exports the service if -r is specified. + +=head1 SEE ALSO + +L, L + +=cut + -- cgit v1.2.1 From 2ad0e0e11a03687ffa22da4750c831933bc6268b Mon Sep 17 00:00:00 2001 From: jeff Date: Tue, 13 Feb 2007 00:45:15 +0000 Subject: for dumping addr_blocks --- FS/bin/freeside-delete-addr_blocks | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100755 FS/bin/freeside-delete-addr_blocks (limited to 'FS/bin') diff --git a/FS/bin/freeside-delete-addr_blocks b/FS/bin/freeside-delete-addr_blocks new file mode 100755 index 000000000..a7e99766a --- /dev/null +++ b/FS/bin/freeside-delete-addr_blocks @@ -0,0 +1,31 @@ +#!/usr/bin/perl -Tw + +use strict; +use vars qw( $user $block @blocks ); +use FS::UID qw(adminsuidsetup); +use FS::Record qw(qsearch); +use FS::addr_block; +use FS::svc_broadband; + +$user = shift or die &usage; +&adminsuidsetup( $user ); + +@blocks = qsearch('addr_block', {} ); +die "No address blocks" unless (scalar(@blocks) > 0); + +foreach $block (@blocks) { + my @devices = qsearch('svc_broadband', { 'blocknum' => $block->blocknum } ); + if (@devices) { + print "Skipping block " . $block->ip_gateway . " / " . $block->ip_netmask; + print "\n"; + }else{ + print "Deleting block " . $block->ip_gateway . " / " . $block->ip_netmask; + print "\n"; + $block->delete; + } +} + + +sub usage { + "Usage:\n freeside-delete-addr_blocks user \n"; +} -- cgit v1.2.1