From 6b192309bb879a5c04c005683d41569feed91f4e Mon Sep 17 00:00:00 2001 From: erickson Date: Fri, 18 Dec 2009 20:59:38 +0000 Subject: [PATCH] Patch from Joe Atzberger to add a generic SendFile reactor. Can be used for sending files to 3rd parties for process (e.g. mailed notices) git-svn-id: svn://svn.open-ils.org/ILS/trunk@15199 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../Application/Trigger/Reactor/SendFile.pm | 101 +++++++++++++++++++++ Open-ILS/src/sql/Pg/002.schema.config.sql | 2 +- Open-ILS/src/sql/Pg/950.data.seed-values.sql | 10 ++ .../sql/Pg/upgrade/0120.data.reactor_SendFile.sql | 16 ++++ 4 files changed, 128 insertions(+), 1 deletion(-) create mode 100644 Open-ILS/src/perlmods/OpenILS/Application/Trigger/Reactor/SendFile.pm create mode 100644 Open-ILS/src/sql/Pg/upgrade/0120.data.reactor_SendFile.sql diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Reactor/SendFile.pm b/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Reactor/SendFile.pm new file mode 100644 index 0000000000..6a89da6cf9 --- /dev/null +++ b/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Reactor/SendFile.pm @@ -0,0 +1,101 @@ +package OpenILS::Application::Trigger::Reactor::SendFile; +use OpenILS::Application::Trigger::Reactor; +use base 'OpenILS::Application::Trigger::Reactor'; + +# use OpenSRF::Utils::SettingsClient; +use OpenSRF::Utils::Logger qw/:logger/; + +use Data::Dumper; +use Net::uFTP; +use File::Temp; + +$Data::Dumper::Indent = 0; + +use strict; +use warnings; + +sub ABOUT { + return <{params}; + + my $host = $params->{remote_host}; + unless ($host) { + $logger->error("No remote_host specified in env"); + return; + } + + my %options = (); + foreach (qw/debug type port/) { + $options{$_} = $params->{$_} if $params->{$_}; + } + my $ftp = Net::uFTP->new($host, %options); + + # my $conf = OpenSRF::Utils::SettingsClient->new; + # $$env{something_hardcoded} = $conf->config_value('category', 'whatever'); + + my $text = $self->run_TT($env) or return; + my $tmp = File::Temp->new(); # magical self-destructing tempfile + print $tmp $text; + $logger->info("SendFile Reactor: using tempfile $tmp"); + + my @login_args = (); + foreach (qw/remote_user remote_password remote_account/) { + push @login_args, $params->{$_} if $params->{$_}; + } + unless ($ftp->login(@login_args)) { + $logger->error("SendFile Reactor: failed login to $host w/ args(" . join(',', @login_args) . ")"); + return; + } + + my @put_args = ($tmp); + push @put_args, $params->{remote_file} if $params->{remote_file}; # user can specify remote_file name, optionally + my $filename = $ftp->put(@put_args); + if ($filename) { + $logger->info("SendFile Reactor: successfully sent ${host} $filename"); + return 1; + } + + $logger->error("SendFile Reactor: put to $host failed with error: $!"); + return; +} + +1; + diff --git a/Open-ILS/src/sql/Pg/002.schema.config.sql b/Open-ILS/src/sql/Pg/002.schema.config.sql index ec33e7dd2c..f25d1018b0 100644 --- a/Open-ILS/src/sql/Pg/002.schema.config.sql +++ b/Open-ILS/src/sql/Pg/002.schema.config.sql @@ -51,7 +51,7 @@ CREATE TABLE config.upgrade_log ( install_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW() ); -INSERT INTO config.upgrade_log (version) VALUES ('0119'); -- miker +INSERT INTO config.upgrade_log (version) VALUES ('0120'); -- atz CREATE TABLE config.bib_source ( id SERIAL PRIMARY KEY, diff --git a/Open-ILS/src/sql/Pg/950.data.seed-values.sql b/Open-ILS/src/sql/Pg/950.data.seed-values.sql index 096bc2722e..c93830099a 100644 --- a/Open-ILS/src/sql/Pg/950.data.seed-values.sql +++ b/Open-ILS/src/sql/Pg/950.data.seed-values.sql @@ -2578,6 +2578,16 @@ INSERT INTO action_trigger.environment (event_def, path) VALUES INSERT INTO action_trigger.reactor (module,description) VALUES ('ApplyPatronPenalty','Applies the conifigured penalty to a patron. Required named environment variables are "user", which refers to the user object, and "context_org", which refers to the org_unit object that acts as the focus for the penalty.'); +INSERT INTO action_trigger.reactor (module,description) VALUES +( 'SendFile', + oils_i18n_gettext( + 'SendFile', + 'Build and transfer a file to a remote server. Required parameter "remote_host" specifying target server. Optional parameters: remote_user, remote_password, remote_account, port, type (FTP, SFTP or SCP), and debug.', + 'atreact', + 'description' + ) +); + INSERT INTO config.org_unit_setting_type (name, label, description, datatype, fm_class) VALUES ( diff --git a/Open-ILS/src/sql/Pg/upgrade/0120.data.reactor_SendFile.sql b/Open-ILS/src/sql/Pg/upgrade/0120.data.reactor_SendFile.sql new file mode 100644 index 0000000000..b9b8cd0a07 --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/0120.data.reactor_SendFile.sql @@ -0,0 +1,16 @@ +BEGIN; + +INSERT INTO config.upgrade_log (version) VALUES ('0120'); -- atz + +INSERT INTO action_trigger.reactor (module,description) VALUES +( 'SendFile', + oils_i18n_gettext( + 'SendFile', + 'Build and transfer a file to a remote server. Required parameter "remote_host" specifying target server. Optional parameters: remote_user, remote_password, remote_account, port, type (FTP, SFTP or SCP), and debug.', + 'atreact', + 'description' + ) +); + +COMMIT; + -- 2.11.0