summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorcvs2git <cvs2git>2010-11-05 19:05:57 +0000
committercvs2git <cvs2git>2010-11-05 19:05:57 +0000
commitaaf8baf3662e16e9414de236a39f8801a8c41b01 (patch)
tree2cda603e4311b3e80f79b93d9bcce3a7c7c2d053 /bin
parent995a145c931164347683071c95c6754379d36604 (diff)
parent9b2de4257b6a2877434008188e52b8ef71ff339d (diff)
This commit was manufactured by cvs2svn to create branch
'FREESIDE_2_1_BRANCH'.
Diffstat (limited to 'bin')
-rwxr-xr-xbin/19add20
-rwxr-xr-xbin/19commit26
-rwxr-xr-xbin/19diff12
-rwxr-xr-xbin/cdr-mysql.import88
-rwxr-xr-xbin/cust_main-find_bogus_geocode36
-rw-r--r--bin/freeside-backup42
-rwxr-xr-xbin/generate-table-module13
-rw-r--r--bin/merge-referrals20
-rwxr-xr-xbin/opensrs_domain_pkgs18
-rwxr-xr-xbin/rt-trim-whitespace38
-rw-r--r--bin/select-cust-desync_bill_dates.sql9
-rw-r--r--bin/test_scrub12
-rwxr-xr-xbin/test_scrub_sql58
-rw-r--r--bin/wipe-customers30
-rwxr-xr-xbin/xmlrpc-customer_status.pl23
-rwxr-xr-xbin/xmlrpc-order_pkg.pl31
16 files changed, 469 insertions, 7 deletions
diff --git a/bin/19add b/bin/19add
new file mode 100755
index 000000000..726cd66a0
--- /dev/null
+++ b/bin/19add
@@ -0,0 +1,20 @@
+#!/usr/bin/perl
+
+use Cwd;
+use String::ShellQuote;
+
+my $USER = $ENV{USER};
+
+my $dir = getcwd;
+( my $prefix = $dir ) =~ s(^/home/$USER/freeside/?)() or die $dir; #eventually from anywhere
+
+system join('',
+ #"cvs add @ARGV && ",
+ "cvs add @ARGV ; ",
+ "( for file in @ARGV; do ",
+ "cp -i \$file /home/$USER/freeside1.9/$prefix/`dirname \$file`;",
+ "done ) && ",
+ "cd /home/$USER/freeside1.9/$prefix/ && ",
+ "cvs add @ARGV"
+);
+
diff --git a/bin/19commit b/bin/19commit
new file mode 100755
index 000000000..0b4cd05db
--- /dev/null
+++ b/bin/19commit
@@ -0,0 +1,26 @@
+#!/usr/bin/perl
+
+# usage: 19commit 'log message' filename filename ...
+
+use Cwd;
+use String::ShellQuote;
+
+my $USER = $ENV{USER};
+
+my $dir = getcwd;
+( my $prefix = $dir ) =~ s(^/home/$USER/freeside/?)() or die $dir; #eventually from anywhere
+
+my $desc = shell_quote(shift @ARGV); # -m
+
+die "no files!" unless @ARGV;
+
+#warn "$prefix";
+
+#print <<END;
+system join('',
+ "( cd /home/$USER/freeside1.9/$prefix; cvs update @ARGV ) && ",
+ "cvs diff -u @ARGV | ( cd /home/$USER/freeside1.9/$prefix; patch -p0 ) ",
+ " && ( ( cvs commit -m $desc @ARGV & ); ",
+ "( sleep 1;cd /home/$USER/freeside1.9/$prefix; cvs commit -m $desc @ARGV & ) )"
+);
+
diff --git a/bin/19diff b/bin/19diff
new file mode 100755
index 000000000..dcc516536
--- /dev/null
+++ b/bin/19diff
@@ -0,0 +1,12 @@
+#!/usr/bin/perl
+
+my $file = shift;
+
+chomp(my $dir = `pwd`);
+$dir =~ s/freeside\//freeside1.9\//;
+
+#$cmd = "diff -u $file $dir/$file";
+$cmd = "diff -u $dir/$file $file";
+print "$cmd\n";
+system($cmd);
+
diff --git a/bin/cdr-mysql.import b/bin/cdr-mysql.import
new file mode 100755
index 000000000..608a8dcc3
--- /dev/null
+++ b/bin/cdr-mysql.import
@@ -0,0 +1,88 @@
+#!/usr/bin/perl
+
+use strict;
+use vars qw( $DEBUG );
+use Date::Parse 'str2time';
+use Date::Format 'time2str';
+use FS::UID qw(adminsuidsetup dbh);
+use FS::cdr;
+use DBI;
+use Getopt::Std;
+
+my %opt;
+getopts('H:U:P:D:T:', \%opt);
+my $user = shift or die &usage;
+
+my $dsn = 'dbi:mysql';
+$dsn .= ":database=$opt{D}" if $opt{D};
+$dsn .= ":host=$opt{H}" if $opt{H};
+
+my $mysql = DBI->connect($dsn, $opt{U}, $opt{P})
+ or die $DBI::errstr;
+
+adminsuidsetup $user;
+
+my $fsdbh = FS::UID::dbh;
+
+# check for existence of freesidestatus
+my $table = $opt{T} || 'cdr';
+my $status = $mysql->selectall_arrayref("SHOW COLUMNS FROM $table WHERE Field = 'freesidestatus'");
+if( ! @$status ) {
+ print "Adding freesidestatus column...\n";
+ $mysql->do("ALTER TABLE $table ADD COLUMN freesidestatus varchar(32)")
+ or die $mysql->errstr;
+}
+else {
+ print "freesidestatus column present\n";
+}
+
+my @cols = ( qw(
+calldate clid src dst dcontext channel lastapp lastdata duration
+ billsec disposition amaflags accountcode uniqueid userfield) );
+my $sql = 'SELECT '.join(',', @cols). " FROM $table WHERE freesidestatus IS NULL";
+my $sth = $mysql->prepare($sql);
+$sth->execute;
+print "Importing ".$sth->rows." records...\n";
+
+my $cdr_batch = new FS::cdr_batch({
+ 'cdrbatch' => 'mysql-import-'. time2str('%Y/%m/%d-%T',time),
+ });
+my $error = $cdr_batch->insert;
+die $error if $error;
+my $cdrbatchnum = $cdr_batch->cdrbatchnum;
+my $imports = 0;
+my $updates = 0;
+
+my $row;
+while ( $row = $sth->fetchrow_hashref ) {
+ my $cdr = FS::cdr->new($row);
+ $cdr->startdate(str2time($cdr->calldate));
+ $cdr->cdrbatchnum($cdrbatchnum);
+ my $error = $cdr->insert;
+ if($error) {
+ print "failed import: $error\n";
+ }
+ else {
+ $imports++;
+ if( $mysql->do("UPDATE cdr SET freesidestatus = 'done'
+ WHERE calldate = ? AND src = ? AND dst = ?",
+ undef,
+ $row->{'calldate'},
+ $row->{'src'},
+ $row->{'dst'},
+
+ ) ) {
+ $updates++;
+ }
+ else {
+ print "failed to set status: ".$mysql->errstr."\n";
+ }
+ }
+}
+print "Done.\nImported $imports CDRs, marked $updates CDRs as done.\n";
+$mysql->disconnect;
+
+sub usage {
+ "Usage: \n cdr-mysql.import\n\t[ -H host ]\n\t-D database\n\t-U user\n\t-P password\n\tfreesideuser\n";
+}
+
diff --git a/bin/cust_main-find_bogus_geocode b/bin/cust_main-find_bogus_geocode
new file mode 100755
index 000000000..04a38a9c4
--- /dev/null
+++ b/bin/cust_main-find_bogus_geocode
@@ -0,0 +1,36 @@
+#!/usr/bin/perl -w
+
+use strict;
+use FS::UID qw(adminsuidsetup);
+use FS::Record qw( qsearch );
+use FS::cust_main;
+
+my $user = shift or die "usage: cust_main-find_bogus_geocode username\n";
+adminsuidsetup $user;
+
+my @cust_main = qsearch({
+ 'table' => 'cust_main',
+ 'extra_sql' => 'WHERE geocode IS NOT NULL',
+});
+
+foreach my $cust_main ( @cust_main ) {
+
+ my $db_geocode = $cust_main->geocode;
+
+ $cust_main->set('geocode', '');
+
+ my $calc_geocode = $cust_main->geocode('cch');
+
+ next unless $calc_geocode;
+
+ my $cust = $cust_main->custnum.': '. $cust_main->name. "\n";
+
+ if ( $db_geocode eq $calc_geocode ) {
+ warn "unnecessary geocode override for $cust";
+ } else {
+ warn "bogus geocode override $db_geocode overrides $calc_geocode for $cust";
+ }
+
+}
+
+1;
diff --git a/bin/freeside-backup b/bin/freeside-backup
new file mode 100644
index 000000000..97a4899e6
--- /dev/null
+++ b/bin/freeside-backup
@@ -0,0 +1,42 @@
+#!/usr/bin/perl -w
+
+use strict;
+use Getopt::Std;
+use FS::UID qw(adminsuidsetup);
+use FS::Conf;
+
+my $user = shift or die &usage;
+adminsuidsetup $user;
+
+#you can skip this just by not having the config
+use FS::Cron::backup qw(backup_scp);
+backup_scp();
+
+sub usage {
+ die "Usage:\n\n freeside-backup user\n";
+}
+
+###
+# documentation
+###
+
+=head1 NAME
+
+freeside-backup - Runs a backup
+
+=head1 SYNOPSIS
+
+ freeside-backup user
+
+=head1 DESCRIPTION
+
+Runs a backup. See the dump-scpdest configuration option.
+
+=head1 BUGS
+
+=head1 SEE ALSO
+
+=cut
+
+1;
+
diff --git a/bin/generate-table-module b/bin/generate-table-module
index 16a23e5b7..e7fc99258 100755
--- a/bin/generate-table-module
+++ b/bin/generate-table-module
@@ -1,7 +1,11 @@
#!/usr/bin/perl
+use strict;
+use vars qw( $opt_n );
use FS::Schema qw( dbdef_dist );
+use Getopt::Std;
+getopts('n');
my $table = shift;
###
@@ -69,12 +73,9 @@ close DEST;
# add to FS/FS/Mason.pm
###
-# it needs to be:
-# 1. disablable (have an option to turn it off)
-# 2. documented in the schema change docs
-#
-#my $magic = '# Sammath Naur';
-#system("perl -pi -e 's/$magic/use FS::$table;\n $magic/' FS/FS/Mason.pm");
+my $magic = '# Sammath Naur';
+system("perl -pi -e 's/$magic/use FS::$table;\n $magic/' FS/FS/Mason.pm")
+ unless $opt_n;
###
# add FS/t/table.t
diff --git a/bin/merge-referrals b/bin/merge-referrals
new file mode 100644
index 000000000..ba07a81c6
--- /dev/null
+++ b/bin/merge-referrals
@@ -0,0 +1,20 @@
+#!/usr/bin/perl
+
+use strict;
+use FS::UID qw(adminsuidsetup);
+use FS::Record qw(qsearchs);
+use FS::cust_main;
+
+my $user = shift or die "usage: merge-customers username custnum\n";
+adminsuidsetup $user;
+
+my $custnum = shift or die "usage: merge-customers username custnum\n";
+
+foreach my $cust_main (
+ qsearch('cust_main', { 'referral_custnum' => $custnum })
+) {
+ my $error = $cust_main->merge($custnum);
+ die $error if $error;
+}
+
+1;
diff --git a/bin/opensrs_domain_pkgs b/bin/opensrs_domain_pkgs
index ae1476104..242009550 100755
--- a/bin/opensrs_domain_pkgs
+++ b/bin/opensrs_domain_pkgs
@@ -73,7 +73,23 @@ foreach my $svc_domain ( $part_export->svc_x ) {
second => $second,
time_zone => 'America/New_York',#timezone of opensrs
);
- my $expiretime = $exp->epoch;
+ #my $expiretime = $exp->epoch;
+
+ #set the bill date early enough to allow a couple chances to pay
+ $month--;
+ if ($month < 1) {
+ $year--;
+ $month=12;
+ }
+ my $bill = DateTime->new( year => $year,
+ month => $month,
+ day => 1,
+ hour => 0,
+ minute => 0,
+ second => 0,
+ time_zone => 'America/Chicago',#timezone of customer
+ );
+ my $expiretime = $bill->epoch;
my $error = $part_export->is_supported_domain($svc_domain);
warn $error if $error;
diff --git a/bin/rt-trim-whitespace b/bin/rt-trim-whitespace
new file mode 100755
index 000000000..503d9cff7
--- /dev/null
+++ b/bin/rt-trim-whitespace
@@ -0,0 +1,38 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use FS::Record;
+use FS::UID qw(adminsuidsetup dbh driver_name);
+
+# Remove trailing whitespace from custom field option lists and values.
+
+my $dbh = adminsuidsetup(shift) or die "Usage: rt-trim-whitespace username\n";
+die "rt-trim-whitespace only works on Pg databases" if driver_name ne 'Pg';
+
+my @updates = (
+ customfieldvalues => 'name',
+ objectcustomfieldvalues => 'content',
+);
+
+while(@updates) {
+ my $table = shift @updates;
+ my $field = shift @updates;
+ my $select =
+"SELECT $field FROM $table WHERE $field != substring($field from ".
+ q!E'^(.*\\\\S)\\\\s*$'! . ')';
+
+ print "$select\n";
+ my $rows = $dbh->do($select);
+ print "$rows rows found.\n";
+
+ if($rows) {
+ my $update =
+"UPDATE $table SET $field = substring($field from ".q!E'^(.*\\\\S)\\\\s*$'!.')'.
+" WHERE $field != substring($field from ".q!E'^(.*\\\\S)\\\\s*$'!.')';
+ print "$update\n";
+ my $rows = $dbh->do($update);
+ print "$rows updated.\n";
+ }
+}
+$dbh->commit or die $dbh->errstr;
diff --git a/bin/select-cust-desync_bill_dates.sql b/bin/select-cust-desync_bill_dates.sql
new file mode 100644
index 000000000..5506f90ed
--- /dev/null
+++ b/bin/select-cust-desync_bill_dates.sql
@@ -0,0 +1,9 @@
+SELECT DISTINCT custnum, agent_custid, first, last, company
+ FROM cust_pkg LEFT JOIN cust_main USING ( custnum )
+ WHERE cancel IS NULL AND 0 < (
+ SELECT COUNT(*) FROM cust_pkg AS others
+ WHERE cust_pkg.custnum = others.custnum
+ AND cust_pkg.pkgnum != others.pkgnum
+ AND cust_pkg.bill != others.bill
+ AND others.cancel IS NULL
+ );
diff --git a/bin/test_scrub b/bin/test_scrub
index 5766925a6..88edc335b 100644
--- a/bin/test_scrub
+++ b/bin/test_scrub
@@ -12,8 +12,13 @@
#-business-onlinepayment and business-onlinepayment-ach config
use strict;
+use vars qw( $opt_h );
+use Getopt::Std;
use FS::UID qw(adminsuidsetup dbh);
use FS::Conf;
+use FS::Schema qw(dbdef);
+
+getopts('h');
adminsuidsetup shift;
@@ -45,4 +50,11 @@ foreach my $item (qw(
$conf->delete($item);
}
+if ($opt_h) { # not all history can be safely deleted
+ foreach my $table (grep { /^h_\w+$/ } dbdef->tables) {
+ my $sth = dbh->prepare("DELETE FROM $table") or die dbh->errstr;
+ $sth->execute or die $sth->errstr;
+ }
+}
+
dbh->commit or die dbh->errstr;
diff --git a/bin/test_scrub_sql b/bin/test_scrub_sql
new file mode 100755
index 000000000..fb26fe940
--- /dev/null
+++ b/bin/test_scrub_sql
@@ -0,0 +1,58 @@
+#!/usr/bin/perl -w
+
+#This drops anything from the database that could cause live things to happen.
+#You'd want to do this on a test copy of your live database but NEVER on the
+#live database itself.
+
+#-all exports (all records in part_export, part_export_option export_svc)
+#-all non-POST invoice destinations (cust_main_invoice)
+#-all payment gateways and agent payment gw overrides (payment_gateway,
+# payment_gateway_option, agent_payment_gateway)
+#-everything in the job queue (queue and queue_arg)
+#-business-onlinepayment and business-onlinepayment-ach config
+#AND
+#-masks all payment info
+
+foreach my $table (qw(
+ part_export_option
+ payment_gateway
+ payment_gateway_option
+ agent_payment_gateway
+ queue
+ queue_arg
+ cust_pay_batch
+)) {
+ print "DELETE FROM $table;\n";
+ print "DELETE FROM h_$table;\n";
+}
+
+foreach my $table (qw(
+ part_export
+ export_svc
+)) {
+ print "DELETE FROM $table;\n";
+}
+
+print "DELETE FROM cust_main_invoice WHERE dest != 'POST';\n";
+
+foreach my $item (qw(
+ business-onlinepayment
+ business-onlinepayment-ach
+)) {
+ print "DELETE FROM conf WHERE name = '$item';\n";
+ print "DELETE FROM h_conf WHERE name = '$item';\n";
+}
+
+my @ptables = map { ($_, "h_$_") } qw(
+ cust_main
+ cust_pay
+ cust_pay_pending
+ cust_pay_void
+ cust_refund
+);
+foreach my $table (@ptables) {
+ print "UPDATE $table SET payinfo = paymask WHERE payby IN ( 'CARD','DCRD','CHEK','DCHK' );\n";
+}
+
+print "UPDATE cust_main set paycvv = NULL;\n";
+print "UPDATE h_cust_main set paycvv = NULL;\n";
diff --git a/bin/wipe-customers b/bin/wipe-customers
new file mode 100644
index 000000000..e65ed61be
--- /dev/null
+++ b/bin/wipe-customers
@@ -0,0 +1,30 @@
+#!/usr/bin/perl
+
+use strict;
+use FS::UID qw(adminsuidsetup);
+use FS::Record qw(qsearch);
+use FS::cust_main;
+
+die "this removes all customers in your database except for customer 1 - remove this line to enable";
+
+my $user = shift or die "usage: wipe-customers username\n";
+adminsuidsetup $user;
+
+#this isn't terribly efficient, but the idea was clearing out a test database,
+#not actually destroying a large amount of data
+
+foreach my $cust_main (
+
+ qsearch('cust_main', { 'custnum' => { op=>'!=', value=>'1' } } )
+
+) {
+
+ my @cerrors = $cust_main->cancel( quiet=>1, nobill=>1 );
+ if ( @cerrors ) {
+ die join(' / ', @cerrors);
+ }
+
+ my $error = $cust_main->delete( 'delete_financials' => 1);
+ die $error if $error;
+
+}
diff --git a/bin/xmlrpc-customer_status.pl b/bin/xmlrpc-customer_status.pl
new file mode 100755
index 000000000..3840b2089
--- /dev/null
+++ b/bin/xmlrpc-customer_status.pl
@@ -0,0 +1,23 @@
+#!/usr/bin/perl
+#
+# xmlrpc-customer_status.pl username password custnum
+
+use strict;
+use Frontier::Client;
+use Data::Dumper;
+
+my( $u, $p, $custnum ) = ( @ARGV );
+my $userinfo = $u.':'.$p;
+
+my $uri = new URI 'http://localhost/freeside/misc/xmlrpc.cgi';
+$uri->userinfo( $userinfo );
+
+my $server = new Frontier::Client ( 'url' => $uri );
+
+my $result = $server->call('Maestro.customer_status', $custnum );
+
+#die $result->{'error'} if $result->{'error'};
+
+print Dumper($result);
+
+1;
diff --git a/bin/xmlrpc-order_pkg.pl b/bin/xmlrpc-order_pkg.pl
new file mode 100755
index 000000000..90d1ff3be
--- /dev/null
+++ b/bin/xmlrpc-order_pkg.pl
@@ -0,0 +1,31 @@
+#!/usr/bin/perl
+#
+# xmlrpc-order_pkg.pl username password
+
+use strict;
+use Frontier::Client;
+use Data::Dumper;
+
+my( $u, $p, $custnum ) = ( @ARGV );
+my $userinfo = $u.':'.$p;
+
+my $uri = new URI 'http://localhost/freeside/misc/xmlrpc.cgi';
+$uri->userinfo( $userinfo );
+
+my $server = new Frontier::Client ( 'url' => $uri );
+
+my $result = $server->call('Maestro.order_pkg',
+ {
+ 'custnum' => 8,
+ 'pkgpart' => 3,
+ 'id' => $$, #unique
+ 'title' => 'John Q. Public', #'name' also works
+ #(turn off global_unique-pbx_title)
+ },
+);
+
+#die $result->{'error'} if $result->{'error'};
+
+print Dumper($result);
+
+1;