diff options
Diffstat (limited to 'bin')
| -rwxr-xr-x | bin/agent_email | 30 | ||||
| -rwxr-xr-x | bin/cdr-a2billing.import | 164 | ||||
| -rwxr-xr-x | bin/cust_main-bulk_change | 13 | ||||
| -rwxr-xr-x | bin/msg_template_http-demo.pl | 76 |
4 files changed, 86 insertions, 197 deletions
diff --git a/bin/agent_email b/bin/agent_email deleted file mode 100755 index 2fe47c4ba..000000000 --- a/bin/agent_email +++ /dev/null @@ -1,30 +0,0 @@ -#!/usr/bin/perl - -use strict; -use Getopt::Std; -use FS::UID qw(adminsuidsetup); - -&untaint_argv; #what it sounds like (eww) -use vars qw(%opt); -getopts("a:", \%opt); - -my $user = shift or die &usage; -adminsuidsetup $user; - -use FS::Cron::agent_email qw(agent_email); -agent_email(%opt); - -### -# subroutines -### - -sub untaint_argv { - foreach $_ ( $[ .. $#ARGV ) { #untaint @ARGV - #$ARGV[$_] =~ /^([\w\-\/]*)$/ || die "Illegal arguement \"$ARGV[$_]\""; - # Date::Parse - $ARGV[$_] =~ /^(.*)$/ || die "Illegal arguement \"$ARGV[$_]\""; - $ARGV[$_]=$1; - } -} - -1; diff --git a/bin/cdr-a2billing.import b/bin/cdr-a2billing.import deleted file mode 100755 index 6677fa0a0..000000000 --- a/bin/cdr-a2billing.import +++ /dev/null @@ -1,164 +0,0 @@ -#!/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:s:e:c:', \%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; - -my ($start, $end) = ('', ''); -if ( $opt{s} ) { - $start = str2time($opt{s}) or die "can't parse start date $opt{s}\n"; - $start = time2str('%Y-%m-%d', $start); -} -if ( $opt{e} ) { - $end = str2time($opt{e}) or die "can't parse end date $opt{e}\n"; - $end = time2str('%Y-%m-%d', $end); -} - -adminsuidsetup $user; - -my $fsdbh = FS::UID::dbh; - -# check for existence of freesidestatus -my $table = $opt{T} || 'cc_call'; -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"; -} - -# Fields: -# id - primary key, sequential -# session_id - Local/<digits>-<digits> or SIP/<digits>-<digits> -# uniqueid - a decimal number, seems to be close to the unix timestamp -# card_id - probably the equipment port, 1 - 10 -# nasipaddress - we don't care -# starttime, stoptime - timestamps -# sessiontime - duration, seconds -# calledstation - dst -# sessionbill - upstream_price -# id_tariffgroup - null, 0, 1 -# id_tariffplan - null, 0, 3, 4, 5, 6, 7, 8, 9 -# id_ratecard - larger numbers -# (all of the id_* fields are foreign keys: cc_tariffgroup, cc_ratecard, etc.) -# id_trunk - we don't care -# sipiax - probably don't care -# src - src. Usually a phone number, but not always. -# id_did - always null -# buycost - wholesale price? correlated with sessionbill -# id_card_package_offer - no idea -# real_sessiontime - close to sessiontime, except when it's null -# (When sessiontime = 0, real_sessiontime is either 0 or null, and -# sessionbill is 0. When sessiontime > 0, but real_sessiontime is null, -# sessionbill is 0. So real_sessiontime seems to be the billable time, and -# is null when the call is non-billable.) -# dnid - sometimes equals calledstation, or calledstation without the leading -# "1". But not always. -# terminatecauseid - integer, 0 - 7 -# destination - seems to be the NPA or NPA+NXX sometimes, or "0". - -# terminatecauseid values: -my %disposition = ( - 0 => '', - 1 => 'ANSWER', #the only one that's billable - 2 => 'BUSY', - 3 => 'NOANSWER', - 4 => 'CANCEL', - 5 => 'CONGESTION', - 6 => 'CHANUNAVAIL', - 7 => 'DONTCALL', - 8 => 'TORTURE', #??? - 9 => 'INVALIDARGS', -); - -my @cols = ( qw( - id sessionid - starttime stoptime sessiontime real_sessiontime - terminatecauseid - calledstation src - id_tariffplan id_ratecard sessionbill -) ); - -my $sql = 'SELECT '.join(',', @cols). " FROM $table". - ' WHERE freesidestatus IS NULL' . - ($start && " AND starttime >= '$start'") . - ($end && " AND starttime < '$end'") ; -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 ) { - $row->{calledstation} =~ s/^1//; - $row->{src} =~ s/^1//; - my $cdr = FS::cdr->new ({ - uniqueid => $row->{sessionid}, - cdrbatchnum => $cdrbatchnum, - startdate => time2str($row->{starttime}), - enddate => time2str($row->{stoptime}), - duration => $row->{sessiontime}, - billsec => $row->{real_sessiontime}, - dst => $row->{calledstation}, - src => $row->{src}, - upstream_rateplanid => $row->{id_tariffplan}, - upstream_rateid => $row->{id_ratecard}, # I think? - upstream_price => $row->{sessionbill}, - }); - $cdr->cdrtypenum($opt{c}) if $opt{c}; - - my $error = $cdr->insert; - if($error) { - print "failed import: $error\n"; - } else { - $imports++; - my $updated = $mysql->do( - "UPDATE $table SET freesidestatus = 'done' WHERE id = ?", - undef, - $row->{'id'} - ); - $updates += $updated; - print "failed to set status: ".$mysql->errstr."\n" unless $updated; - } -} -print "Done.\nImported $imports CDRs, marked $updates as done in source database.\n"; -$mysql->disconnect; - -sub usage { - "Usage: - cdr-a2billing.import - [ -H host ] - -D database - -U user - -P password - [ -s start ] [ -e end ] [ -c cdrtypenum ] - freesideuser -"; -} diff --git a/bin/cust_main-bulk_change b/bin/cust_main-bulk_change index 32a6d7bd6..e03901272 100755 --- a/bin/cust_main-bulk_change +++ b/bin/cust_main-bulk_change @@ -1,7 +1,7 @@ #!/usr/bin/perl use strict; -use vars qw( $opt_a $opt_p $opt_t $opt_k ); +use vars qw( $opt_a $opt_p $opt_t $opt_k $opt_c ); use Getopt::Std; use FS::UID qw(adminsuidsetup); use FS::Record qw(qsearch qsearchs); @@ -9,7 +9,7 @@ use FS::cust_main; use FS::cust_tag; use FS::cust_pkg; -getopts('a:p:t:k:'); +getopts('a:p:t:k:c:'); my $user = shift or &usage; adminsuidsetup $user; @@ -64,6 +64,11 @@ while (<STDIN>) { } } + if ( $opt_c ) { + my @error = $cust_main->cancel( 'reason' => $opt_c ); + die join(' / ', @error). "\n" if @error; + } + } sub usage { @@ -76,7 +81,7 @@ cust_main-bulk_change =head1 SYNOPSIS - cust_main-bulk_change [ -a agentnum ] [ -p NEW_PAYBY ] [ -t tagnum ] [ -k old_pkgpart:new_pkgpart,... ] username <custnums.txt + cust_main-bulk_change [ -a agentnum ] [ -p NEW_PAYBY ] [ -t tagnum ] [ -k old_pkgpart:new_pkgpart,... ] [ -c reasonnum ] username <custnums.txt =head1 DESCRIPTION @@ -90,6 +95,8 @@ Command-line tool to make bulk changes to a group of customers. -k: old_pkgpart:new_pkgpart, for example, I<5:4>. Multiple entries can be comma-separated. +-c: Cancel customer + user: Employee username =head1 BUGS diff --git a/bin/msg_template_http-demo.pl b/bin/msg_template_http-demo.pl new file mode 100755 index 000000000..8d184fc85 --- /dev/null +++ b/bin/msg_template_http-demo.pl @@ -0,0 +1,76 @@ +=head1 NAME + +FS::msg_template::http example server. + +=head1 DESCRIPTION + +This is an incredibly crude Mojo web service for demonstrating how to talk +to the HTTP customer messaging interface in Freeside. + +It implements an endpoint for the "password reset" messaging case which +creates a simple password reset message using some template variables, +and a "send" endpoint that just delivers the message by sendmail. The +configuration to use this as your password reset handler would be: + +prepare_url = 'http://localhost:3000/prepare/password_reset' +send_url = 'http://localhost:3000/send' +No username, no password, no additional content. + +=cut + +use Mojolicious::Lite; +use Mojo::JSON qw(decode_json encode_json); +use Email::Simple; +use Email::Simple::Creator; +use Email::Sender::Simple qw(sendmail); + +post '/prepare/password_reset' => sub { + my $self = shift; + + my $json_data = $self->req->body; + #print STDERR $json_data; + my $input = decode_json($json_data); + if ( $input->{username} ) { + my $output = { + 'to' => $input->{invoicing_email}, + 'subject' => "Password reset for $input->{username}", + 'body' => " +To complete your $input->{company_name} password reset, please go to +$input->{selfservice_server_base_url}/selfservice.cgi?action=process_forgot_password;session_id=$input->{session_id} + +This link will expire in 24 hours.", + }; + + return $self->render( json => $output ); + + } else { + + return $self->render( text => 'Username required', status => 500 ); + + } +}; + +post '/send' => sub { + my $self = shift; + + my $json_data = $self->req->body; + my $input = decode_json($json_data); + my $email = Email::Simple->create( + header => [ + From => $ENV{USER}.'@localhost', + To => $input->{to}, + Subject => $input->{subject}, + ], + body => $input->{body}, + ); + local $@; + eval { sendmail($email) }; + if ( $@ ) { + return $self->render( text => $@->message, status => 500 ); + } else { + return $self->render( text => '' ); + } +}; + +app->start; + |
