diff options
Diffstat (limited to 'FS/bin')
-rwxr-xr-x | FS/bin/freeside-cdr-sftp_and_import | 2 | ||||
-rw-r--r-- | FS/bin/freeside-cdrrated | 16 | ||||
-rw-r--r-- | FS/bin/freeside-cdrrewrited | 60 | ||||
-rw-r--r-- | FS/bin/freeside-ipifony-download | 30 | ||||
-rwxr-xr-x | FS/bin/freeside-phonenum_list | 86 | ||||
-rw-r--r-- | FS/bin/freeside-queued | 4 | ||||
-rw-r--r-- | FS/bin/freeside-selfservice-server | 24 | ||||
-rwxr-xr-x | FS/bin/freeside-upgrade | 2 | ||||
-rwxr-xr-x | FS/bin/freeside-username_list | 84 | ||||
-rwxr-xr-x | FS/bin/freeside-wkhtmltopdf | 8 |
10 files changed, 249 insertions, 67 deletions
diff --git a/FS/bin/freeside-cdr-sftp_and_import b/FS/bin/freeside-cdr-sftp_and_import index 7f2693fcb..c37ff11d6 100755 --- a/FS/bin/freeside-cdr-sftp_and_import +++ b/FS/bin/freeside-cdr-sftp_and_import @@ -218,6 +218,8 @@ or FTP and then import them into the database. -c: cdrtypenum to set, defaults to none +-g: File is gzipped + user: freeside username format: CDR format name diff --git a/FS/bin/freeside-cdrrated b/FS/bin/freeside-cdrrated index 131b56a7e..99ea67594 100644 --- a/FS/bin/freeside-cdrrated +++ b/FS/bin/freeside-cdrrated @@ -33,9 +33,11 @@ if ( @cdrtypenums ) { $extra_sql .= ' AND cdrtypenum IN ('. join(',', @cdrtypenums ). ')'; } -our %svcnum = (); -our %pkgpart = (); -our %part_pkg = (); +our %svcnum = (); # phonenum => svcnum +our %pkgnum = (); # phonenum => pkgnum +our %cust_pkg = (); # pkgnum => cust_pkg (NOT phonenum => cust_pkg!) +our %pkgpart = (); # phonenum => pkgpart +our %part_pkg = (); # phonenum => part_pkg #some false laziness w/freeside-cdrrewrited @@ -91,6 +93,9 @@ while (1) { next; } + $pkgnum{$number} = $cust_pkg->pkgnum; + $cust_pkg{$cust_pkg->pkgnum} ||= $cust_pkg; + #get the package, search through the part_pkg and linked for a voip_cdr def w/matching cdrtypenum (or no use_cdrtypenum) my @part_pkg = grep { $_->plan eq 'voip_cdr' @@ -126,10 +131,11 @@ while (1) { #} #XXX if $part_pkg->option('min_included') then we can't prerate this CDR - + my $error = $cdr->rate( 'part_pkg' => $part_pkg{ $pkgpart{$number} }, - 'svcnum' => $svcnum{ $number }, + 'cust_pkg' => $cust_pkg{ $pkgnum{$number} }, + 'svcnum' => $svcnum{$number}, ); if ( $error ) { #XXX ??? diff --git a/FS/bin/freeside-cdrrewrited b/FS/bin/freeside-cdrrewrited index f2c3926fb..16f931fbf 100644 --- a/FS/bin/freeside-cdrrewrited +++ b/FS/bin/freeside-cdrrewrited @@ -30,9 +30,9 @@ die "not running; cdr-asterisk_forward_rewrite, cdr-charged_party_rewrite ". #-- -my %accountcode_unmatch = (); -my $accountcode_retry = 4 * 60 * 60; # 4 hours -my $accountcode_giveup = 4 * 24 * 60 * 60; # 4 days +my %sessionnum_unmatch = (); +my $sessionnum_retry = 4 * 60 * 60; # 4 hours +my $sessionnum_giveup = 4 * 24 * 60 * 60; # 4 days my %cdr_type = map { lc($_->cdrtypename) => $_->cdrtypenum } qsearch('cdr_type',{}); @@ -45,8 +45,8 @@ while (1) { # instead of just doing this search like normal CDRs #hmm :/ - my @recent = grep { ($accountcode_unmatch{$_} + $accountcode_retry) > time } - keys %accountcode_unmatch; + my @recent = grep { ($sessionnum_unmatch{$_} + $sessionnum_retry) > time } + keys %sessionnum_unmatch; my $extra_sql = scalar(@recent) ? ' AND acctid NOT IN ('. join(',', @recent). ') ' : ''; @@ -136,45 +136,62 @@ while (1) { } - if ( $conf->exists('cdr-taqua-accountcode_rewrite') - && $cdr->lastapp eq 'acctcode' && $cdr->cdrtypenum == 1 + if ( $cdr->cdrtypenum == 1 + and $cdr->lastapp + and ( + $conf->exists('cdr-taqua-accountcode_rewrite') or + $conf->exists('cdr-taqua-callerid_rewrite') ) ) { #find the matching CDR - my $primary = qsearchs('cdr', { - 'sessionnum' => $cdr->sessionnum, - 'src' => $cdr->subscriber, - #'accountcode' => '', - }); + my %search = ( 'sessionnum' => $cdr->sessionnum ); + if ( $cdr->lastapp eq 'acctcode' ) { + $search{'src'} = $cdr->subscriber; + } elsif ( $cdr->lastapp eq 'CallerId' ) { + $search{'dst'} = $cdr->subscriber; + } + my $primary = qsearchs('cdr', \%search); unless ( $primary ) { my $cantfind = "can't find primary CDR with session ". $cdr->sessionnum. ", src ". $cdr->subscriber; - if ( $cdr->calldate_unix + $accountcode_giveup < time ) { + if ( $cdr->calldate_unix + $sessionnum_giveup < time ) { warn "ERROR: $cantfind; giving up\n"; - push @status, 'taqua-accountcode-NOTFOUND'; + push @status, 'taqua-sessionnum-NOTFOUND'; $cdr->status('done'); #so it doesn't try to rate - delete $accountcode_unmatch{$cdr->acctid}; #so it doesn't suck mem + delete $sessionnum_unmatch{$cdr->acctid}; #so it doesn't suck mem } else { warn "WARNING: $cantfind; will keep trying\n"; - $accountcode_unmatch{$cdr->acctid} = time; + $sessionnum_unmatch{$cdr->acctid} = time; next; } } else { - $primary->accountcode( $cdr->lastdata ); + if ( $cdr->lastapp eq 'acctcode' ) { + # lastdata contains the dialed account code + $primary->accountcode( $cdr->lastdata ); + push @status, 'taqua-accountcode'; + } elsif ( $cdr->lastapp eq 'CallerId' ) { + # lastdata contains "allowed" or "restricted" + # or case variants thereof + if ( lc($cdr->lastdata) eq 'restricted' ) { + $primary->clid( 'PRIVATE' ); + } + push @status, 'taqua-callerid'; + } else { + warn "unknown Taqua service name: ".$cdr->lastapp."\n"; + } #$primary->freesiderewritestatus( 'taqua-accountcode-primary' ); - my $error = $primary->replace; + my $error = $primary->replace if $primary->modified; if ( $error ) { warn "WARNING: error rewriting primary CDR (will retry): $error\n"; next; } $skip{$primary->acctid} = 1; - push @status, 'taqua-accountcode'; $cdr->status('done'); #so it doesn't try to rate } @@ -214,7 +231,10 @@ sub _shouldrun { $conf->exists('cdr-asterisk_forward_rewrite') || $conf->exists('cdr-asterisk_australia_rewrite') || $conf->exists('cdr-charged_party_rewrite') - || $conf->exists('cdr-taqua-accountcode_rewrite'); + || $conf->exists('cdr-taqua-accountcode_rewrite') + || $conf->exists('cdr-taqua-callerid_rewrite') + || 0 + ; } sub usage { diff --git a/FS/bin/freeside-ipifony-download b/FS/bin/freeside-ipifony-download index 837cc3329..9df4db08a 100644 --- a/FS/bin/freeside-ipifony-download +++ b/FS/bin/freeside-ipifony-download @@ -9,6 +9,7 @@ use FS::UID qw(adminsuidsetup); use FS::Record qw(qsearch qsearchs); use FS::cust_main; use FS::Conf; +use File::Copy qw(copy); use Text::CSV; my %opt; @@ -116,7 +117,7 @@ die "failed to connect to '$sftpuser\@$host'\n(".$sftp->error.")\n" $sftp->setcwd($path) if $path; -my $files = $sftp->ls('.', wanted => qr/\.csv$/, names_only => 1); +my $files = $sftp->ls('ready', wanted => qr/\.csv$/, names_only => 1); if (!@$files) { print STDERR "No charge files found.\n" if $opt{v}; exit(-1); @@ -129,23 +130,23 @@ my %is_e911 = map {$_ => 1} @E911_CODES; FILE: foreach my $filename (@$files) { print STDERR "Retrieving $filename\n" if $opt{v}; - $sftp->get("$filename", "$tmpdir/$filename"); + $sftp->get("ready/$filename", "$tmpdir/$filename"); if($sftp->error) { warn "failed to download $filename\n"; next FILE; } # make sure server archive dir exists - if ( !$sftp->stat('Archive') ) { - print STDERR "Creating $path/Archive\n" if $opt{v}; - $sftp->mkdir('Archive'); + if ( !$sftp->stat('done') ) { + print STDERR "Creating $path/done\n" if $opt{v}; + $sftp->mkdir('done'); if($sftp->error) { # something is seriously wrong die "failed to create archive directory on server:\n".$sftp->error."\n"; } } #move to server archive dir - $sftp->rename("$filename", "Archive/$filename"); + $sftp->rename("ready/$filename", "done/$filename"); if($sftp->error) { warn "failed to archive $filename on server:\n".$sftp->error."\n"; } # process it anyway, I guess/ @@ -159,11 +160,6 @@ FILE: foreach my $filename (@$files) { } open my $fh, "<$tmpdir/$filename"; - my $header = <$fh>; - if ($header !~ /^"cust_id"/) { - warn "warning: $filename has incorrect header row:\n$header\n"; - # but try anyway - } my $csv = Text::CSV->new; # orthodox CSV my %hash; while (my $line = <$fh>) { @@ -172,6 +168,11 @@ FILE: foreach my $filename (@$files) { next FILE; }; @hash{@fields} = $csv->fields(); + if ( $hash{custnum} =~ /^cust/ ) { + # there appears to be a header row + print STDERR "skipping header row\n" if $opt{v}; + next; + } my $cust_main = $cust_main{$hash{custnum}} ||= FS::cust_main->by_key($hash{custnum}); if (!$cust_main) { @@ -184,10 +185,11 @@ FILE: foreach my $filename (@$files) { my $amount = sprintf('%.2f',$hash{quantity} * $hash{unit_price}); # construct arguments for $cust_main->charge my %charge_opt = ( - amount => $amount, + amount => $hash{unit_price}, quantity => $hash{quantity}, start_date => $cust_main->next_bill_date, - pkg => $hash{date_desc}, + pkg => $hash{date_desc} . + ' (' . $hash{quantity} . ' @ $' . $hash{unit_price} . ' ea)', taxclass => $TAXCLASSES{ $hash{taxclass} }, ); if (my $classname = $hash{classname}) { @@ -221,7 +223,7 @@ FILE: foreach my $filename (@$files) { $num_errors++; } else { $num_charges++; - $sum_charges += $hash{amount}; + $sum_charges += $amount; } if ( $opt{e} and $is_e911{$hash{classname}} ) { diff --git a/FS/bin/freeside-phonenum_list b/FS/bin/freeside-phonenum_list new file mode 100755 index 000000000..19b564dee --- /dev/null +++ b/FS/bin/freeside-phonenum_list @@ -0,0 +1,86 @@ +#!/usr/bin/perl + +use strict; +use vars qw( $opt_c $opt_o $opt_l $opt_p $opt_b $opt_d $opt_s $opt_t ); +use Getopt::Std; +use FS::UID qw(adminsuidsetup); +use FS::Conf; +use FS::Record qw(qsearch); +use FS::svc_phone; + +getopts('colp:b:d:s:t:'); + +my $user = shift or &usage; +adminsuidsetup $user; + +my $conf = new FS::Conf; +my $default_locale = $conf->config('locale') || 'en_US'; + +my %search = (); + +$search{payby} = [ split(/\s*,\s*/, $opt_p) ] if $opt_p; +$search{balance} = $opt_b if $opt_b; +$search{balance_days} = $opt_d if $opt_d; +$search{svcpart} = [ split(/\s*,\s*/, $opt_s) ] if $opt_s; +$search{cust_status} = lc($opt_t) if $opt_t; + +my @svc_phone = qsearch( FS::svc_phone->search(\%search) ); + +foreach my $svc_phone (@svc_phone) { + print $svc_phone->countrycode if $opt_c; + print $svc_phone->phonenum; + print '@'. $svc_phone->domain if $opt_o; + if ( $opt_l ) { + my $cust_pkg = $svc_phone->cust_svc->cust_pkg; + print ','. ($cust_pkg && $cust_pkg->cust_main->locale || $default_locale); + } + print "\n"; +} + +sub usage { + die "usage: freeside-phonenum_list [ -c ] [ -o ] [ -l ] [ -p payby,payby... ] [ -b balance [ -d balance_days ] ] [ -s svcpart,svcpart... ] username \n"; +} + +=head1 NAME + +freeside-phonenum_list + +=head1 SYNOPSIS + freeside-phonenum_list [ -c ] [ -o ] [ -l ] [ -p payby,payby... ] [ -b balance [ -d balance_days ] ] [ -s svcpart,svcpart... ] username + +=head1 DESCRIPTION + +Command-line tool to list phone numbers. + +Display options: + +-c: Include country code + +-o: Include domain + +-l: Include customer locale + +Selection options: + +-p: Customer payby (CARD, BILL, etc.). Separate multiple values with commas. + +-b: Customer balance over (or equal to) this amount + +-d: Customer balance age over this many days + +-s: Service definition (svcpart). Separate multiple values with commas. + +-t: Customer status: prospect, active, ordered, inactive, suspended or cancelled + +username: Employee username + +=head1 BUGS + +=head1 SEE ALSO + +L<FS::svc_phone>, L<FS::cust_main> + +=cut + +1; + diff --git a/FS/bin/freeside-queued b/FS/bin/freeside-queued index 2fd80255e..dcc6ac4ba 100644 --- a/FS/bin/freeside-queued +++ b/FS/bin/freeside-queued @@ -212,8 +212,10 @@ while (1) { # don't put @args in the log, may expose passwords $log->info('starting job ('.$ljob->job.')'); warn 'running "&'. $ljob->job. '('. join(', ', @args). ")\n" if $DEBUG; + local $FS::UID::AutoCommit = 0; # so that we can clean up failures eval $eval; #throw away return value? suppose so if ( $@ ) { + dbh->rollback; my %hash = $ljob->hash; $hash{'statustext'} = $@; if ( $hash{'statustext'} =~ /\/misc\/queued_report/ ) { #use return? @@ -225,8 +227,10 @@ while (1) { my $fjob = new FS::queue( \%hash ); my $error = $fjob->replace($ljob); die $error if $error; + dbh->commit; # for the status change only } else { $ljob->delete; + dbh->commit; # for the job itself } if ( UNIVERSAL::can(dbh, 'sprintProfile') ) { diff --git a/FS/bin/freeside-selfservice-server b/FS/bin/freeside-selfservice-server index c10623c96..9df313fec 100644 --- a/FS/bin/freeside-selfservice-server +++ b/FS/bin/freeside-selfservice-server @@ -108,31 +108,7 @@ while (1) { if ( $keepalives && $keepalive_count++ > 10 ) { $keepalive_count = 0; lock_write; - nstore_fd( { _token => '_keepalive' }, $writer ); - -#commenting izoom stuff out until we can move it to a branch (or just remove) -# foreach my $agent ( qsearch( 'agent', { disabled => '' } ) ) { -# my $config = qsearchs( 'conf', { name => 'selfservice-bulk_ftp_dir', -# agentnum => $agent->agentnum, -# } ) -# or next; -# -# my $session = -# FS::ClientAPI->dispatch( 'Agent/agent_login', -# { username => $agent->username, -# password => $agent->_password, -# } -# ); -# -# nstore_fd( { _token => '_ftp_scan', -# dir => $config->value, -# session_id => $session->{session_id}, -# }, -# $writer -# ); -# } - unlock_write; } next; diff --git a/FS/bin/freeside-upgrade b/FS/bin/freeside-upgrade index b08a8401f..3d1c2e072 100755 --- a/FS/bin/freeside-upgrade +++ b/FS/bin/freeside-upgrade @@ -123,6 +123,8 @@ my $cf; while ( $cf = $cfsth->fetchrow_hashref ) { my $tbl = $cf->{'dbtable'}; my $name = $cf->{'name'}; + $name = lc($name) unless driver_name =~ /^mysql/i; + @statements = grep { $_ !~ /^\s*ALTER\s+TABLE\s+(h_|)$tbl\s+DROP\s+COLUMN\s+cf_$name\s*$/i } @statements; push @statements, diff --git a/FS/bin/freeside-username_list b/FS/bin/freeside-username_list new file mode 100755 index 000000000..5352f02eb --- /dev/null +++ b/FS/bin/freeside-username_list @@ -0,0 +1,84 @@ +#!/usr/bin/perl + +use strict; +use vars qw( $opt_o $opt_l $opt_p $opt_b $opt_d $opt_s $opt_t ); +use Getopt::Std; +use FS::UID qw(adminsuidsetup); +use FS::Conf; +use FS::Record qw(qsearch); +use FS::svc_acct; + +getopts('olp:b:d:s:t:'); + +my $user = shift or &usage; +adminsuidsetup $user; + +my $conf = new FS::Conf; +my $default_locale = $conf->config('locale') || 'en_US'; + +my %search = (); + +$search{payby} = [ split(/\s*,\s*/, $opt_p) ] if $opt_p; +$search{balance} = $opt_b if $opt_b; +$search{balance_days} = $opt_d if $opt_d; +$search{svcpart} = [ split(/\s*,\s*/, $opt_s) ] if $opt_s; +$search{cust_status} = lc($opt_t) if $opt_t; + +my @svc_acct = qsearch( FS::svc_acct->search(\%search) ); + +foreach my $svc_acct (@svc_acct) { + print $svc_acct->username; + print '@'. $svc_acct->domain if $opt_o; + if ( $opt_l ) { + my $cust_pkg = $svc_acct->cust_svc->cust_pkg; + print ','. ($cust_pkg && $cust_pkg->cust_main->locale || $default_locale); + } + print "\n"; +} + +sub usage { + die "usage: freeside-username_list [ -c ] [ -l ] [ -p payby,payby... ] [ -b balance [ -d balance_days ] ] [ -s svcpart,svcpart... ] username \n"; +} + +=head1 NAME + +freeside-username_list + +=head1 SYNOPSIS + + freeside-username_list [ -c ] [ -l ] [ -p payby,payby... ] [ -b balance [ -d balance_days ] ] [ -s svcpart,svcpart... ] username + +=head1 DESCRIPTION + +Command-line tool to list usernames. + +Display options: + +-o: Include domain + +-l: Include customer locale + +Selection options: + +-p: Customer payby (CARD, BILL, etc.). Separate multiple values with commas. + +-b: Customer balance over (or equal to) this amount + +-d: Customer balance age over this many days + +-s: Service definition (svcpart). Separate multiple values with commas. + +-t: Customer status: prospect, active, ordered, inactive, suspended or cancelled + +username: Employee username + +=head1 BUGS + +=head1 SEE ALSO + +L<FS::svc_acct>, L<FS::cust_main> + +=cut + +1; + diff --git a/FS/bin/freeside-wkhtmltopdf b/FS/bin/freeside-wkhtmltopdf index c6c5531a5..f0c53e6da 100755 --- a/FS/bin/freeside-wkhtmltopdf +++ b/FS/bin/freeside-wkhtmltopdf @@ -1,7 +1,7 @@ #!/bin/sh -if [ $DISPLAY ] ; then - wkhtmltopdf $@ -else +#if [ $DISPLAY ] ; then +# wkhtmltopdf $@ +#else xvfb-run -- wkhtmltopdf $@ -fi +#fi |