From c12b5ff1afa59d293efd0f73640353fbd44d7f13 Mon Sep 17 00:00:00 2001 From: mattf Date: Tue, 3 Jun 2025 12:51:03 +0000 Subject: [PATCH] Added --ftp... connection CLI options to VDsales_export SFTP script git-svn-id: svn://192.168.202.10@3926 3d104415-ff17-0410-8863-d5cf3c621b8a --- bin/AST_VDsales_export_SFTP.pl | 162 ++++++++++++++++++++++----------- 1 file changed, 110 insertions(+), 52 deletions(-) diff --git a/bin/AST_VDsales_export_SFTP.pl b/bin/AST_VDsales_export_SFTP.pl index bf8c1bff..394e5575 100644 --- a/bin/AST_VDsales_export_SFTP.pl +++ b/bin/AST_VDsales_export_SFTP.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # -# AST_VDsales_export_SFTP.pl version: 2.6 -# +# AST_VDsales_export_SFTP.pl version: 2.14 +# # !!!!!! IMPORTANT NOTE !!!!! # !!!!!! THIS SCRIPT REQUIRES THE Net::SFTP PERL MODULE TO RUN !!!!! # @@ -10,7 +10,7 @@ # # /usr/share/astguiclient/AST_VDsales_export_SFTP.pl --campaign=GOODB-GROUP1-GROUP3-GROUP4-SPECIALS-DNC_BEDS --output-format=fixed-as400 --sale-statuses=SALE --debug --filename=BEDSsaleMMDD.txt --date=yesterday --email-list=test@gmail.com --email-sender=test@test.com # -# Copyright (C) 2013 Matt Florell LICENSE: AGPLv2 +# Copyright (C) 2025 Matt Florell LICENSE: AGPLv2 # # CHANGES # 61219-1118 - First version @@ -33,6 +33,7 @@ # 110829-1045 - Changed recording lookup to try to find by vicidial_id first # 120228-1855 - Added SFTP(Net::SFTP) file transmission option # 130312-1016 - Added several SFTP tweeks +# 250603-0831 - Added --ftp... connection CLI options # $txt = '.txt'; @@ -97,6 +98,54 @@ if ($Tmin < 10) {$Tmin = "0$Tmin";} if ($Tsec < 10) {$Tsec = "0$Tsec";} +# default path to astguiclient configuration file: +$PATHconf = '/etc/astguiclient.conf'; + +open(conf, "$PATHconf") || die "can't open $PATHconf: $!\n"; +@conf = ; +close(conf); +$i=0; +foreach(@conf) + { + $line = $conf[$i]; + $line =~ s/ |>|\n|\r|\t|\#.*|;.*//gi; + if ( ($line =~ /^PATHhome/) && ($CLIhome < 1) ) + {$PATHhome = $line; $PATHhome =~ s/.*=//gi;} + if ( ($line =~ /^PATHlogs/) && ($CLIlogs < 1) ) + {$PATHlogs = $line; $PATHlogs =~ s/.*=//gi;} + if ( ($line =~ /^PATHagi/) && ($CLIagi < 1) ) + {$PATHagi = $line; $PATHagi =~ s/.*=//gi;} + if ( ($line =~ /^PATHweb/) && ($CLIweb < 1) ) + {$PATHweb = $line; $PATHweb =~ s/.*=//gi;} + if ( ($line =~ /^PATHsounds/) && ($CLIsounds < 1) ) + {$PATHsounds = $line; $PATHsounds =~ s/.*=//gi;} + if ( ($line =~ /^PATHmonitor/) && ($CLImonitor < 1) ) + {$PATHmonitor = $line; $PATHmonitor =~ s/.*=//gi;} + if ( ($line =~ /^VARserver_ip/) && ($CLIserver_ip < 1) ) + {$VARserver_ip = $line; $VARserver_ip =~ s/.*=//gi;} + if ( ($line =~ /^VARDB_server/) && ($CLIDB_server < 1) ) + {$VARDB_server = $line; $VARDB_server =~ s/.*=//gi;} + if ( ($line =~ /^VARDB_database/) && ($CLIDB_database < 1) ) + {$VARDB_database = $line; $VARDB_database =~ s/.*=//gi;} + if ( ($line =~ /^VARDB_user/) && ($CLIDB_user < 1) ) + {$VARDB_user = $line; $VARDB_user =~ s/.*=//gi;} + if ( ($line =~ /^VARDB_pass/) && ($CLIDB_pass < 1) ) + {$VARDB_pass = $line; $VARDB_pass =~ s/.*=//gi;} + if ( ($line =~ /^VARDB_port/) && ($CLIDB_port < 1) ) + {$VARDB_port = $line; $VARDB_port =~ s/.*=//gi;} + if ( ($line =~ /^VARREPORT_host/) && ($CLIREPORT_host < 1) ) + {$VARREPORT_host = $line; $VARREPORT_host =~ s/.*=//gi;} + if ( ($line =~ /^VARREPORT_user/) && ($CLIREPORT_user < 1) ) + {$VARREPORT_user = $line; $VARREPORT_user =~ s/.*=//gi;} + if ( ($line =~ /^VARREPORT_pass/) && ($CLIREPORT_pass < 1) ) + {$VARREPORT_pass = $line; $VARREPORT_pass =~ s/.*=//gi;} + if ( ($line =~ /^VARREPORT_port/) && ($CLIREPORT_port < 1) ) + {$VARREPORT_port = $line; $VARREPORT_port =~ s/.*=//gi;} + if ( ($line =~ /^VARREPORT_dir/) && ($CLIREPORT_dir < 1) ) + {$VARREPORT_dir = $line; $VARREPORT_dir =~ s/.*=//gi;} + $i++; + } + ### begin parsing run-time options ### if (length($ARGV[0])>1) { @@ -127,6 +176,11 @@ if (length($ARGV[0])>1) print " [--ftp-transfer] = Send results file by FTP to another server\n"; print " [--ftp-audio-transfer] = Send associated audio files to FTP server, dated directories\n"; print " [--ftp-norun] = Stop program when you get to the FTP transfer\n"; + print " [--ftp-server=XXXXXXXX] = FTP server to send file to\n"; + print " [--ftp-login=XXXXXXXX] = FTP user\n"; + print " [--ftp-pass=XXXXXXXX] = FTP pass\n"; + print " [--ftp-port=XXXXXXXX] = remote FTP server port\n"; + print " [--ftp-dir=XXXXXXXX] = remote FTP server directory to post files to\n"; print " [--with-transfer-audio] = Different method for finding audio, also grabs transfer audio filenames\n"; print " [--with-did-lookup] = Looks up the DID pattern and name the call came in on if possible\n"; print " [--email-list=test@test.com:test2@test.com] = send email results to these addresses\n"; @@ -140,7 +194,6 @@ if (length($ARGV[0])>1) print " pipe-standard|csv-standard|tab-standard|pipe-triplep|pipe-vici|html-rec|fixed-as400|tab-QMcustomUSA|tab-SCcustomUSA\n"; print "\n"; - exit; } else @@ -352,6 +405,58 @@ if (length($ARGV[0])>1) {print "\n----- FTP NORUN MODE -----\n\n";} $ftp_norun=1; } + + if ($args =~ /--ftp-server=/i) + { + @data_in = split(/--ftp-server=/,$args); + $VARREPORT_host = $data_in[1]; + $VARREPORT_host =~ s/ .*//gi; + $VARREPORT_host =~ s/:/,/gi; + if ($DB > 0) {print "\n----- FTP SERVER: $VARREPORT_host -----\n\n";} + } + else + {$VARREPORT_host = '';} + if ($args =~ /--ftp-login=/i) + { + @data_in = split(/--ftp-login=/,$args); + $VARREPORT_user = $data_in[1]; + $VARREPORT_user =~ s/ .*//gi; + $VARREPORT_user =~ s/:/,/gi; + if ($DB > 0) {print "\n----- FTP LOGIN: $VARREPORT_user -----\n\n";} + } + else + {$VARREPORT_user = '';} + if ($args =~ /--ftp-pass=/i) + { + @data_in = split(/--ftp-pass=/,$args); + $VARREPORT_pass = $data_in[1]; + $VARREPORT_pass =~ s/ .*//gi; + $VARREPORT_pass =~ s/:/,/gi; + if ($DB > 0) {print "\n----- FTP PASS: -----\n\n";} + } + else + {$VARREPORT_pass = '';} + if ($args =~ /--ftp-port=/i) + { + @data_in = split(/--ftp-port=/,$args); + $VARREPORT_port = $data_in[1]; + $VARREPORT_port =~ s/ .*//gi; + $VARREPORT_port =~ s/:/,/gi; + if ($DB > 0) {print "\n----- FTP port: $VARREPORT_port -----\n\n";} + } + else + {$VARREPORT_port = '';} + if ($args =~ /--ftp-dir=/i) + { + @data_in = split(/--ftp-dir=/,$args); + $VARREPORT_dir = $data_in[1]; + $VARREPORT_dir =~ s/ .*//gi; + $VARREPORT_dir =~ s/:/,/gi; + if ($DB > 0) {print "\n----- FTP DIR: $VARREPORT_dir -----\n\n";} + } + else + {$VARREPORT_dir = '';} + if ($args =~ /-with-transfer-audio/i) { if (!$Q) @@ -398,54 +503,6 @@ else } ### end parsing run-time options ### -# default path to astguiclient configuration file: -$PATHconf = '/etc/astguiclient.conf'; - -open(conf, "$PATHconf") || die "can't open $PATHconf: $!\n"; -@conf = ; -close(conf); -$i=0; -foreach(@conf) - { - $line = $conf[$i]; - $line =~ s/ |>|\n|\r|\t|\#.*|;.*//gi; - if ( ($line =~ /^PATHhome/) && ($CLIhome < 1) ) - {$PATHhome = $line; $PATHhome =~ s/.*=//gi;} - if ( ($line =~ /^PATHlogs/) && ($CLIlogs < 1) ) - {$PATHlogs = $line; $PATHlogs =~ s/.*=//gi;} - if ( ($line =~ /^PATHagi/) && ($CLIagi < 1) ) - {$PATHagi = $line; $PATHagi =~ s/.*=//gi;} - if ( ($line =~ /^PATHweb/) && ($CLIweb < 1) ) - {$PATHweb = $line; $PATHweb =~ s/.*=//gi;} - if ( ($line =~ /^PATHsounds/) && ($CLIsounds < 1) ) - {$PATHsounds = $line; $PATHsounds =~ s/.*=//gi;} - if ( ($line =~ /^PATHmonitor/) && ($CLImonitor < 1) ) - {$PATHmonitor = $line; $PATHmonitor =~ s/.*=//gi;} - if ( ($line =~ /^VARserver_ip/) && ($CLIserver_ip < 1) ) - {$VARserver_ip = $line; $VARserver_ip =~ s/.*=//gi;} - if ( ($line =~ /^VARDB_server/) && ($CLIDB_server < 1) ) - {$VARDB_server = $line; $VARDB_server =~ s/.*=//gi;} - if ( ($line =~ /^VARDB_database/) && ($CLIDB_database < 1) ) - {$VARDB_database = $line; $VARDB_database =~ s/.*=//gi;} - if ( ($line =~ /^VARDB_user/) && ($CLIDB_user < 1) ) - {$VARDB_user = $line; $VARDB_user =~ s/.*=//gi;} - if ( ($line =~ /^VARDB_pass/) && ($CLIDB_pass < 1) ) - {$VARDB_pass = $line; $VARDB_pass =~ s/.*=//gi;} - if ( ($line =~ /^VARDB_port/) && ($CLIDB_port < 1) ) - {$VARDB_port = $line; $VARDB_port =~ s/.*=//gi;} - if ( ($line =~ /^VARREPORT_host/) && ($CLIREPORT_host < 1) ) - {$VARREPORT_host = $line; $VARREPORT_host =~ s/.*=//gi;} - if ( ($line =~ /^VARREPORT_user/) && ($CLIREPORT_user < 1) ) - {$VARREPORT_user = $line; $VARREPORT_user =~ s/.*=//gi;} - if ( ($line =~ /^VARREPORT_pass/) && ($CLIREPORT_pass < 1) ) - {$VARREPORT_pass = $line; $VARREPORT_pass =~ s/.*=//gi;} - if ( ($line =~ /^VARREPORT_port/) && ($CLIREPORT_port < 1) ) - {$VARREPORT_port = $line; $VARREPORT_port =~ s/.*=//gi;} - if ( ($line =~ /^VARREPORT_dir/) && ($CLIREPORT_dir < 1) ) - {$VARREPORT_dir = $line; $VARREPORT_dir =~ s/.*=//gi;} - $i++; - } - # Customized Variables $server_ip = $VARserver_ip; # Asterisk server IP @@ -803,6 +860,7 @@ if ($ftp_transfer > 0) use Net::SFTP; if (!$Q) {print "Sending File Over SFTP: $outfile\n";} + if ($DBX > 0) {print " Connecting to: $VARREPORT_user".'@'."$VARREPORT_host:$VARREPORT_port \n";} my $sftp = Net::SFTP->new($VARREPORT_host, user => "$VARREPORT_user", password => "$VARREPORT_pass", ssh_args => [ port => "$VARREPORT_port", debug => 1 ]); if ($DBX > 0) {print "put $PATHweb/vicidial/server_reports/$outfile $VARREPORT_dir/$outfile\n";} $sftp_status = $sftp->put("$PATHweb/vicidial/server_reports/$outfile", "$VARREPORT_dir/$outfile", \&writecallback);