diff options
Diffstat (limited to 'FS/bin')
-rwxr-xr-x | FS/bin/freeside-cdr-sftp_and_import | 33 | ||||
-rwxr-xr-x | FS/bin/freeside-dbdef-create | 2 | ||||
-rwxr-xr-x | FS/bin/freeside-fetch | 2 | ||||
-rwxr-xr-x | FS/bin/freeside-selfservice-xmlrpcd | 349 | ||||
-rwxr-xr-x | FS/bin/freeside-setup | 32 | ||||
-rwxr-xr-x | FS/bin/freeside-upgrade | 33 |
6 files changed, 27 insertions, 424 deletions
diff --git a/FS/bin/freeside-cdr-sftp_and_import b/FS/bin/freeside-cdr-sftp_and_import index ba9d6f3cc..d90695f8f 100755 --- a/FS/bin/freeside-cdr-sftp_and_import +++ b/FS/bin/freeside-cdr-sftp_and_import @@ -11,8 +11,8 @@ use FS::cdr; # parse command line ### -use vars qw( $opt_m $opt_p $opt_r $opt_e $opt_d $opt_v $opt_P $opt_a ); -getopts('m:p:r:e:d:v:P:a'); +use vars qw( $opt_m $opt_p $opt_r $opt_e $opt_d $opt_v ); +getopts('m:p:r:e:d:v'); $opt_e ||= 'csv'; #$opt_e = ".$opt_e" unless $opt_e =~ /^\./; @@ -20,13 +20,11 @@ $opt_e =~ s/^\.//; $opt_p ||= ''; -my %options = (); - my $user = shift or die &usage; adminsuidsetup $user; # %%%FREESIDE_CACHE%%% -my $cachedir = '%%%FREESIDE_CACHE%%%/cache.'. datasrc. '/cdrs'; +my $cachedir = '/usr/local/etc/freeside/cache.'. datasrc. '/cdrs'; mkdir $cachedir unless -d $cachedir; my $format = shift or die &usage; @@ -46,18 +44,11 @@ $opt_m = lc($opt_m); my $ls; if($opt_m eq 'ftp') { - $options{'Port'} = $opt_P if $opt_P; - $options{'Debug'} = $opt_v if $opt_v; - $options{'Passive'} = $opt_a if $opt_a; - my $ls_ftp = ftp(); $ls = [ grep { /^$opt_p.*\.$opt_e$/i } $ls_ftp->ls ]; } elsif($opt_m eq 'sftp') { - $options{'port'} = $opt_P if $opt_P; - $options{'debug'} = $opt_v if $opt_v; - my $ls_sftp = sftp(); $ls_sftp->setcwd($opt_r) or die "can't chdir to $opt_r\n" @@ -133,8 +124,7 @@ sub ftp { my ($hostname, $user) = reverse split('@', $servername); my ($user, $pass) = split(':', $user); - my $ftp = Net::FTP->new($hostname, %options) - or die "FTP connection to '$hostname' failed."; + my $ftp = Net::FTP->new($hostname) or die "FTP connection to '$hostname' failed."; $ftp->login($user, $pass) or die "FTP login failed: ".$ftp->message; $ftp->cwd($opt_r) or die "can't chdir to $opt_r\n" if $opt_r; return $ftp; @@ -159,14 +149,12 @@ cdr.sftp_and_import - Download CDR files from a remote server via SFTP =head1 SYNOPSIS - cdr.sftp_and_import [ -m method ] [ -p prefix ] [ -e extension ] - [ -r remotefolder ] [ -d donefolder ] [ -v level ] [ -P port ] - [ -a ] user format [sftpuser@]servername + cdr.sftp_and_import [ -m method ][ -p prefix ] [ -e extension ] [ -r remotefolder ] [ -d donefolder ] [ -v ] user format [sftpuser@]servername =head1 DESCRIPTION -Command line tool to download CDR files from a remote server via SFTP -or FTP and then import them into the database. +Command line tool to download CDR files from a remote server via SFTP or FTP and then +import them into the database. -m: transfer method (sftp or ftp), defaults to sftp @@ -178,12 +166,7 @@ or FTP and then import them into the database. -d: if specified, moves files to the specified folder when done --P: if specified, sets the port to use - --a: use ftp passive mode - --v: set verbosity level; this script only has one level, but it will - be passed as the 'debug' argument to the transport method +-v: verbose user: freeside username diff --git a/FS/bin/freeside-dbdef-create b/FS/bin/freeside-dbdef-create index 6c448c74c..a04f42521 100755 --- a/FS/bin/freeside-dbdef-create +++ b/FS/bin/freeside-dbdef-create @@ -1,4 +1,4 @@ -#!/usr/bin/perl -w +#!/usr/bin/perl -Tw use strict; use DBI; diff --git a/FS/bin/freeside-fetch b/FS/bin/freeside-fetch index f689bfd93..7b674ed7e 100755 --- a/FS/bin/freeside-fetch +++ b/FS/bin/freeside-fetch @@ -1,4 +1,4 @@ -#!/usr/bin/perl -w +#!/usr/bin/perl -Tw use strict; use LWP::UserAgent; diff --git a/FS/bin/freeside-selfservice-xmlrpcd b/FS/bin/freeside-selfservice-xmlrpcd deleted file mode 100755 index fa745ecf2..000000000 --- a/FS/bin/freeside-selfservice-xmlrpcd +++ /dev/null @@ -1,349 +0,0 @@ -#!/usr/bin/perl -# -# based on http://www.perlmonks.org/?node_id=582781 by Justin Hawkins -# and http://poe.perl.org/?POE_Cookbook/Web_Server_With_Forking - -### -# modules and constants and variables, oh my -### - -use warnings; -use strict; - -use constant DEBUG => 1; # Enable much runtime information. -use constant MAX_PROCESSES => 10; # Total server process count. -use constant SERVER_PORT => 8080; # Server port. -use constant TESTING_CHURN => 0; # Randomly test process respawning. - -use POE 1.2; # Base features. -use POE::Filter::HTTPD; # For serving HTTP content. -use POE::Wheel::ReadWrite; # For socket I/O. -use POE::Wheel::SocketFactory; # For serving socket connections. - -use XMLRPC::Transport::HTTP; #SOAP::Transport::HTTP; -use XMLRPC::Lite; # for XMLRPC::Serializer - -use FS::Daemon qw( daemonize1 drop_root logfile daemonize2 ); -use FS::UID qw( adminsuidsetup forksuidsetup dbh ); -use FS::Conf; -use FS::ClientAPI qw( load_clientapi_modules ); -use FS::ClientAPI_XMLRPC; #FS::SelfService::XMLRPC; - -#freeside -my $FREESIDE_LOG = "%%%FREESIDE_LOG%%%"; -my $FREESIDE_LOCK = "%%%FREESIDE_LOCK%%%"; -my $lock_file = "$FREESIDE_LOCK/selfservice-xmlrpcd.writelock"; - -#freeside xmlrpc.cgi -my %typelookup = ( - base64 => [10, sub {$_[0] =~ /[^\x09\x0a\x0d\x20-\x7f]/}, 'as_base64'], - dateTime => [35, sub {$_[0] =~ /^\d{8}T\d\d:\d\d:\d\d$/}, 'as_dateTime'], - string => [40, sub {1}, 'as_string'], -); - -### -# freeside init -### - -my $user = shift or die &usage; - -$FS::Daemon::NOSIG = 1; -$FS::Daemon::PID_NEWSTYLE = 1; -daemonize1('selfservice-xmlrpcd'); - -POE::Kernel->has_forked(); #daemonize forks... - -drop_root(); - -adminsuidsetup($user); - -load_clientapi_modules; - -logfile("$FREESIDE_LOG/selfservice-xmlrpcd.log"); - -daemonize2(); - -my $conf = new FS::Conf; - -die "not running; selfservice-xmlrpc conf option is off\n" - unless $conf->exists('selfservice-xmlrpc'); - -#parent doesn't need to hold a DB connection open -dbh->disconnect; -undef $FS::UID::dbh; - -### -# the main loop -### - -server_spawn(MAX_PROCESSES); -POE::Kernel->run(); -exit; - -### -# the subroutines -### - -### Spawn the main server. This will run as the parent process. - -sub server_spawn { - my ($max_processes) = @_; - - POE::Session->create( - inline_states => { - _start => \&server_start, - _stop => \&server_stop, - do_fork => \&server_do_fork, - got_error => \&server_got_error, - got_sig_int => \&server_got_sig_int, - got_sig_child => \&server_got_sig_child, - got_connection => \&server_got_connection, - _child => sub { undef }, - }, - heap => { max_processes => MAX_PROCESSES }, - ); -} - -### The main server session has started. Set up the server socket and -### bookkeeping information, then fork the initial child processes. - -sub server_start { - my ( $kernel, $heap ) = @_[ KERNEL, HEAP ]; - - $heap->{server} = POE::Wheel::SocketFactory->new - ( BindPort => SERVER_PORT, - SuccessEvent => "got_connection", - FailureEvent => "got_error", - Reuse => "yes", - ); - - $kernel->sig( INT => "got_sig_int" ); - $kernel->sig( TERM => "got_sig_int" ); #huh - - $heap->{children} = {}; - $heap->{is_a_child} = 0; - - warn "Server $$ has begun listening on port ", SERVER_PORT, "\n"; - - $kernel->yield("do_fork"); -} - -### The server session has shut down. If this process has any -### children, signal them to shutdown too. - -sub server_stop { - my $heap = $_[HEAP]; - DEBUG and warn "Server $$ stopped.\n"; - - if ( my @children = keys %{ $heap->{children} } ) { - DEBUG and warn "Server $$ is signaling children to stop.\n"; - kill INT => @children; - } -} - -### The server session has encountered an error. Shut it down. - -sub server_got_error { - my ( $heap, $syscall, $errno, $error ) = @_[ HEAP, ARG0 .. ARG2 ]; - warn( "Server $$ got $syscall error $errno: $error\n", - "Server $$ is shutting down.\n", - ); - delete $heap->{server}; -} - -### The server has a need to fork off more children. Only honor that -### request form the parent, otherwise we would surely "forkbomb". -### Fork off as many child processes as we need. - -sub server_do_fork { - my ( $kernel, $heap ) = @_[ KERNEL, HEAP ]; - - return if $heap->{is_a_child}; - - #my $current_children = keys %{ $heap->{children} }; - #for ( $current_children + 2 .. $heap->{max_processes} ) { - while (scalar(keys %{$heap->{children}}) < $heap->{max_processes}) { - - DEBUG and warn "Server $$ is attempting to fork.\n"; - - my $pid = fork(); - - unless ( defined($pid) ) { - DEBUG and - warn( "Server $$ fork failed: $!\n", - "Server $$ will retry fork shortly.\n", - ); - $kernel->delay( do_fork => 1 ); - return; - } - - # Parent. Add the child process to its list. - if ($pid) { - $heap->{children}->{$pid} = 1; - $kernel->sig_child($pid, "got_sig_child"); - next; - } - - # Child. Clear the child process list. - $kernel->has_forked(); - DEBUG and warn "Server $$ forked successfully.\n"; - $heap->{is_a_child} = 1; - $heap->{children} = {}; - - #freeside db connection, etc. - forksuidsetup($user); - - return; - } -} - -### The server session received SIGINT. Don't handle the signal, -### which in turn will trigger the process to exit gracefully. - -sub server_got_sig_int { - my ( $kernel, $heap ) = @_[ KERNEL, HEAP ]; - DEBUG and warn "Server $$ received SIGINT/TERM.\n"; - - if ( my @children = keys %{ $heap->{children} } ) { - DEBUG and warn "Server $$ is signaling children to stop.\n"; - kill INT => @children; - } - - delete $heap->{server}; - $kernel->sig_handled(); -} - -### The server session received a SIGCHLD, indicating that some child -### server has gone away. Remove the child's process ID from our -### list, and trigger more fork() calls to spawn new children. - -sub server_got_sig_child { - my ( $kernel, $heap, $child_pid ) = @_[ KERNEL, HEAP, ARG1 ]; - - return unless delete $heap->{children}->{$child_pid}; - - DEBUG and warn "Server $$ reaped child $child_pid.\n"; - $kernel->yield("do_fork") if exists $_[HEAP]->{server}; -} - -### The server session received a connection request. Spawn off a -### client handler session to parse the request and respond to it. - -sub server_got_connection { - my ( $heap, $socket, $peer_addr, $peer_port ) = @_[ HEAP, ARG0, ARG1, ARG2 ]; - - DEBUG and warn "Server $$ received a connection.\n"; - - POE::Session->create( - inline_states => { - _start => \&client_start, - _stop => \&client_stop, - got_request => \&client_got_request, - got_flush => \&client_flushed_request, - got_error => \&client_got_error, - _parent => sub { 0 }, - }, - heap => { - socket => $socket, - peer_addr => $peer_addr, - peer_port => $peer_port, - }, - ); - - # Gracefully exit if testing process churn. - delete $heap->{server} - if TESTING_CHURN and $heap->{is_a_child} and ( rand() < 0.1 ); -} - -### The client handler has started. Wrap its socket in a ReadWrite -### wheel to begin interacting with it. - -sub client_start { - my $heap = $_[HEAP]; - - $heap->{client} = POE::Wheel::ReadWrite->new - ( Handle => $heap->{socket}, - Filter => POE::Filter::HTTPD->new(), - InputEvent => "got_request", - ErrorEvent => "got_error", - FlushedEvent => "got_flush", - ); - - DEBUG and warn "Client handler $$/", $_[SESSION]->ID, " started.\n"; -} - -### The client handler has stopped. Log that fact. - -sub client_stop { - DEBUG and warn "Client handler $$/", $_[SESSION]->ID, " stopped.\n"; -} - -### The client handler has received a request. If it's an -### HTTP::Response object, it means some error has occurred while -### parsing the request. Send that back and return immediately. -### Otherwise parse and process the request, generating and sending an -### HTTP::Response object in response. - -sub client_got_request { - my ( $heap, $request ) = @_[ HEAP, ARG0 ]; - - forksuidsetup($user) unless dbh && dbh->ping; - - my $serializer = new XMLRPC::Serializer(typelookup => \%typelookup); - - #my $soap = SOAP::Transport::HTTP::Server - my $soap = XMLRPC::Transport::HTTP::Server - -> new - -> dispatch_to('FS::ClientAPI_XMLRPC') - -> serializer($serializer); - - DEBUG and - warn "Client handler $$/", $_[SESSION]->ID, " is handling a request.\n"; - - if ( $request->isa("HTTP::Response") ) { - $heap->{client}->put($request); - return; - } - - $soap->request($request); - $soap->handle; - my $response = $soap->response; - - $heap->{client}->put($response); -} - -### The client handler received an error. Stop the ReadWrite wheel, -### which also closes the socket. - -sub client_got_error { - my ( $heap, $operation, $errnum, $errstr ) = @_[ HEAP, ARG0, ARG1, ARG2 ]; - DEBUG and - warn( "Client handler $$/", $_[SESSION]->ID, - " got $operation error $errnum: $errstr\n", - "Client handler $$/", $_[SESSION]->ID, " is shutting down.\n" - ); - delete $heap->{client}; -} - -### The client handler has flushed its response to the socket. We're -### done with the client connection, so stop the ReadWrite wheel. - -sub client_flushed_request { - my $heap = $_[HEAP]; - DEBUG and - warn( "Client handler $$/", $_[SESSION]->ID, - " flushed its response.\n", - "Client handler $$/", $_[SESSION]->ID, " is shutting down.\n" - ); - delete $heap->{client}; -} - -sub usage { - die "Usage:\n\n freeside-selfservice-xmlrpcd user\n"; -} - -### -# the end -### - -1; diff --git a/FS/bin/freeside-setup b/FS/bin/freeside-setup index 155c74aa0..ddff81ef9 100755 --- a/FS/bin/freeside-setup +++ b/FS/bin/freeside-setup @@ -1,4 +1,4 @@ -#!/usr/bin/perl -w +#!/usr/bin/perl -Tw #to delay loading dbdef until we're ready BEGIN { $FS::Schema::setup_hack = 1; } @@ -9,7 +9,7 @@ $FS::part_pkg::setup_hack = 1; $FS::part_pkg::setup_hack = 1; use strict; -use vars qw($opt_u $opt_d $opt_v $opt_q); +use vars qw($opt_u $opt_d $opt_v); use Getopt::Std; use FS::UID qw(adminsuidsetup datasrc checkeuid getsecrets); use FS::CurrentUser; @@ -24,9 +24,7 @@ die "Not running uid freeside!" unless checkeuid(); #my %attrib2db = # map { lc($FS::raddb::attrib{$_}) => $_ } keys %FS::raddb::attrib; -getopts("u:vqd:"); -$opt_v = 1 unless $opt_q; #verbose by default now - +getopts("u:vd:"); my $config_dir = shift || '%%%DIST_CONF%%%' ; $config_dir =~ /^([\w.:=\/]+)$/ or die "unacceptable configuration directory name"; @@ -86,8 +84,6 @@ my $username_len = 32; # create a dbdef object from the old data structure ### -warn "Loading schema objects\n" if $opt_v; - my $dbdef = dbdef_dist(datasrc); #important @@ -98,8 +94,6 @@ $dbdef->save($dbdef_file); # create 'em ### -warn "Connecting to database\n" if $opt_v; - $FS::CurrentUser::upgrade_hack = 1; $FS::UID::callback_hack = 1; my $dbh = adminsuidsetup $opt_u; #$user; @@ -108,8 +102,6 @@ $FS::UID::callback_hack = 0; #create tables $|=1; -warn "Creating tables and indices\n" if $opt_v; - foreach my $statement ( $dbdef->sql($dbh) ) { $dbh->do( $statement ) or die "CREATE error: ". $dbh->errstr. "\ndoing statement: $statement"; @@ -121,12 +113,14 @@ dbdef_create($dbh, $dbdef_file); delete $FS::Schema::dbdef_cache{$dbdef_file}; #force an actual reload reload_dbdef($dbdef_file); -warn "Tables and indices created - commiting transaction\n" if $opt_v; +warn "Freeside schema initialized - commiting transaction\n" if $opt_v; + $dbh->commit or die $dbh->errstr; $dbh->disconnect or die $dbh->errstr; + warn "Database schema committed successfully\n" if $opt_v; -warn "Initializing configuration\n" if $opt_v; +warn "Initializing freeside configuration\n" if $opt_v; $FS::UID::callback_hack = 1; $dbh = adminsuidsetup $opt_u; $FS::UID::callback_hack = 0; @@ -138,17 +132,21 @@ if (!scalar(qsearch('conf', {}))) { } } -warn "Configuration initialized - commiting transaction\n" if $opt_v; +warn "Freeside configuration initialized - commiting transaction\n" if $opt_v; + $dbh->commit or die $dbh->errstr; $dbh->disconnect or die $dbh->errstr; -warn "Configuration committed successfully\n" if $opt_v; + +warn "Freeside configuration committed successfully\n" if $opt_v; $dbh = adminsuidsetup $opt_u; create_initial_data('domain' => $opt_d); -warn "Database initialized - commiting transaction\n" if $opt_v; +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 successfully\n" if $opt_v; sub dbdef_create { # reverse engineer the schema from the DB and save to file @@ -158,7 +156,7 @@ sub dbdef_create { # reverse engineer the schema from the DB and save to file } sub usage { - die "Usage:\n freeside-setup -d domain.name [ -q ] [ config/dir ]\n" + die "Usage:\n freeside-setup -d domain.name [ -v ] [ config/dir ]\n" # [ -u user ] for devel/multi-db installs } diff --git a/FS/bin/freeside-upgrade b/FS/bin/freeside-upgrade index 4a6fac293..f4ff1c28e 100755 --- a/FS/bin/freeside-upgrade +++ b/FS/bin/freeside-upgrade @@ -61,33 +61,6 @@ if (dbdef->table('cust_main')->column('agent_custid') && ! $opt_s) { if (dbdef->table('h_cust_main')); } -if ( dbdef->table('cgp_rule_condition') && - dbdef->table('cgp_rule_condition')->column('condition') - ) -{ - push @bugfix, - "ALTER TABLE ${_}cgp_rule_condition RENAME COLUMN condition TO conditionname" - for '', 'h_'; - -} - -if ( $DRY_RUN ) { - print - join(";\n", @bugfix ). ";\n"; -} elsif ( @bugfix ) { - - foreach my $statement ( @bugfix ) { - warn "$statement\n"; - $dbh->do( $statement ) - or die "Error: ". $dbh->errstr. "\n executing: $statement"; - } - - dbdef_create($dbh, $dbdef_file); - delete $FS::Schema::dbdef_cache{$dbdef_file}; #force an actual reload - reload_dbdef($dbdef_file); - -} - #you should have run fs-migrate-part_svc ages ago, when you upgraded #from 1.3 to 1.4... if not, it needs to be hooked into -upgrade here or #you'll lose all the part_svc settings it migrates to part_svc_column @@ -110,10 +83,10 @@ unless ( driver_name =~ /^mysql/i ) { if ( $DRY_RUN ) { print - join(";\n", @statements ). ";\n"; + join(";\n", @bugfix, @statements ). ";\n"; exit; } else { - foreach my $statement ( @statements ) { + foreach my $statement ( @bugfix, @statements ) { warn "$statement\n"; $dbh->do( $statement ) or die "Error: ". $dbh->errstr. "\n executing: $statement"; @@ -190,8 +163,6 @@ unless ( $DRY_RUN || $opt_s ) { $dbh->commit or die $dbh->errstr; $dbh->disconnect or die $dbh->errstr; -$FS::UID::AutoCommit = 1; - $dbh = adminsuidsetup($user); warn "Re-initialization with updated schema completed in ". (time-$start). " seconds\n"; # if $DEBUG; |