From a3bc7f207b863f7e60a0e6bd964c2894a2887ab8 Mon Sep 17 00:00:00 2001 From: fermin831 Date: Wed, 13 Sep 2017 18:07:37 +0200 Subject: [PATCH 1/3] Fixed remote config on local transfer mode --- pandora_agents/unix/pandora_agent | 45 +++++++++++++++++++------------ 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/pandora_agents/unix/pandora_agent b/pandora_agents/unix/pandora_agent index 34492724e6..5791e1582c 100755 --- a/pandora_agents/unix/pandora_agent +++ b/pandora_agents/unix/pandora_agent @@ -128,6 +128,9 @@ my @BrokerPid; my %DefaultConf = ( 'server_ip' => 'localhost', 'server_path' => '/var/spool/pandora/data_in', + 'server_path_md5' => 'md5', + 'server_path_conf' => 'conf', + 'server_path_zip' => 'collections', 'logfile' =>'/var/log/pandora/pandora_agent.log', 'logsize' => DEFAULT_MAX_LOG_SIZE, 'logrotate' => DEFAULT_LOG_ROTATE, @@ -906,13 +909,17 @@ sub fix_directory ($) { ################################################################################ # Sends a file to the server. ################################################################################ -#sub send_file ($;$$$) { sub send_file { - my ($file, $secondary, $rc_primary, $flag_always) = @_; + my ($file, $secondary, $rc_primary, $flag_always, $relative) = @_; + my $output; my $pid = fork(); return 1 unless defined $pid; + # Fix remote dir to some transfer mode + my $remote_dir = $Conf{'server_path'} . "/"; + $remote_dir .= fix_directory($relative) . '/' if defined($relative); + if ($pid == 0) { # execute the transfer program by child process. eval { @@ -935,7 +942,7 @@ sub send_file { quit FEOF1` } elsif ($Conf{'transfer_mode'} eq 'local') { - $output = `cp "$file" "$Conf{'server_path'}/" 2>&1 >$DevNull`; + $output = `cp "$file" "$remote_dir" 2>&1 >$DevNull`; } alarm (0); }; @@ -966,7 +973,7 @@ sub send_file { $rc_primary = 1; } swap_servers (); - $rc = send_file ($file, undef, $rc_primary); + $rc = send_file ($file, undef, $rc_primary, undef, $relative); swap_servers (); return $rc; @@ -1024,7 +1031,7 @@ sub send_file { return $rc unless ($Conf{'secondary_mode'} eq 'always' || ($Conf{'secondary_mode'} eq 'on_error' && $rc != 0)); swap_servers (); - $rc = send_file ($file); + $rc = send_file ($file, undef, undef, undef, $relative); swap_servers (); return $rc; } @@ -1075,12 +1082,16 @@ sub swap_servers () { ################################################################################ # Receive a file from the server. ################################################################################ -sub recv_file ($) { - my $file = shift; +sub recv_file { + my ($file, $relative) = @_; my $output; - + my $pid = fork(); - return 1 unless defined $pid; + return 1 unless defined $pid; + + # Fix remote dir to some transfer mode + my $remote_dir = $Conf{'server_path'}; + $remote_dir .= "/" . fix_directory($relative) if defined($relative); if ($pid == 0) { # execute the transfer program by child process. @@ -1104,7 +1115,7 @@ sub recv_file ($) { quit FEOF1` } elsif ($Conf{'transfer_mode'} eq 'local') { - $output = `cp $Conf{'server_path'}/$file $Conf{'temporal'} 2>&1 >$DevNull`; + $output = `cp "$remote_dir/$file" $Conf{'temporal'} 2>&1 >$DevNull`; } alarm (0); }; @@ -1148,14 +1159,14 @@ sub check_remote_config () { } # Get the remote MD5 file - if (recv_file ($RemoteMD5File) != 0) { + if (recv_file ($RemoteMD5File, $Conf{'server_path_md5'}) != 0) { + log_message ('remote config', 'Uploading configuration for the first time.'); open (MD5_FILE, "> $Conf{'temporal'}/$RemoteMD5File") || error ("Could not open file '$ConfDir/$RemoteMD5File' for writing: $!."); print MD5_FILE $conf_md5; close (MD5_FILE); copy ("$ConfDir/$ConfFile", "$Conf{'temporal'}/$RemoteConfFile"); - send_file ("$Conf{'temporal'}/$RemoteConfFile"); - send_file ("$Conf{'temporal'}/$RemoteMD5File"); - log_message ('remote config', 'Uploading configuration for the first time.'); + send_file ("$Conf{'temporal'}/$RemoteConfFile", undef, undef, undef, $Conf{'server_path_conf'}); + send_file ("$Conf{'temporal'}/$RemoteMD5File", undef, undef, undef, $Conf{'server_path_md5'}); unlink ("$Conf{'temporal'}/$RemoteConfFile"); unlink ("$Conf{'temporal'}/$RemoteMD5File"); return; @@ -1169,7 +1180,7 @@ sub check_remote_config () { return if ($remote_conf_md5 eq $conf_md5); # Get the new configuration file - return if (recv_file ($RemoteConfFile) != 0); + return if (recv_file ($RemoteConfFile, $Conf{'server_path_conf'}) != 0); log_message ('remote config', 'Configuration has changed!'); # Save the new configuration @@ -1255,7 +1266,7 @@ sub check_collections () { # Get remote md5 error ("File '$Conf{'temporal'}/$collection_md5_file' already exists as a symlink and could not be removed: $!.") if (-l "$Conf{'temporal'}/$collection_md5_file" && !unlink("$Conf{'temporal'}/$collection_md5_file")); - next unless (recv_file ($collection_md5_file) == 0); + next unless (recv_file ($collection_md5_file, $Conf{'server_path_md5'}) == 0); open (MD5_FILE, "< $Conf{'temporal'}/$collection_md5_file") || error ("Could not open file '$Conf{'temporal'}/$collection_md5_file' for reading: $!."); my $remote_collection_md5 = ; close (MD5_FILE); @@ -1273,7 +1284,7 @@ sub check_collections () { next if ($local_collection_md5 eq $remote_collection_md5); # Download and unzip - next unless (recv_file ($collection_file) == 0); + next unless (recv_file ($collection_file, $Conf{'server_path_zip'}) == 0); rmrf ("$ConfDir/collections/$collection"); `unzip -d "$ConfDir/collections/$collection" "$Conf{'temporal'}/$collection_file" 2>$DevNull`; unlink ("$Conf{'temporal'}/$collection_file"); From 7eecf38378d77d56a4efb3ba1e5a008d6c3fcd0b Mon Sep 17 00:00:00 2001 From: fermin831 Date: Wed, 13 Sep 2017 18:58:24 +0200 Subject: [PATCH 2/3] Added transfer_mode_user to change owner of local copies files --- pandora_agents/unix/pandora_agent | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pandora_agents/unix/pandora_agent b/pandora_agents/unix/pandora_agent index 5791e1582c..32a98d3574 100755 --- a/pandora_agents/unix/pandora_agent +++ b/pandora_agents/unix/pandora_agent @@ -149,6 +149,7 @@ my %DefaultConf = ( 'encoding' => 'UTF-8', 'server_port' => 41121, 'transfer_mode' => 'tentacle', + 'transfer_mode_user' => 'apache', 'transfer_timeout' => 30, 'server_user' => 'pandora', 'server_pwd' => '', @@ -942,7 +943,7 @@ sub send_file { quit FEOF1` } elsif ($Conf{'transfer_mode'} eq 'local') { - $output = `cp "$file" "$remote_dir" 2>&1 >$DevNull`; + $output = `cp -p "$file" "$remote_dir" 2>&1 >$DevNull`; } alarm (0); }; @@ -1165,6 +1166,11 @@ sub check_remote_config () { print MD5_FILE $conf_md5; close (MD5_FILE); copy ("$ConfDir/$ConfFile", "$Conf{'temporal'}/$RemoteConfFile"); + if ($Conf{'transfer_mode'} eq 'local') { + my (undef, undef, $uid, $gid) = getpwnam($Conf{'transfer_mode_user'}); + chown ($uid, $gid, "$Conf{'temporal'}/$RemoteMD5File"); + chown ($uid, $gid, "$Conf{'temporal'}/$RemoteConfFile"); + } send_file ("$Conf{'temporal'}/$RemoteConfFile", undef, undef, undef, $Conf{'server_path_conf'}); send_file ("$Conf{'temporal'}/$RemoteMD5File", undef, undef, undef, $Conf{'server_path_md5'}); unlink ("$Conf{'temporal'}/$RemoteConfFile"); From 484022a7c93535840af2b7341eefdedd8d524c60 Mon Sep 17 00:00:00 2001 From: fermin831 Date: Thu, 21 Sep 2017 10:09:06 +0200 Subject: [PATCH 3/3] Marked some config options like undocumented and added transfer_mode_user on all unix confs --- pandora_agents/unix/AIX/pandora_agent.conf | 3 +++ pandora_agents/unix/Darwin/pandora_agent.conf | 3 +++ pandora_agents/unix/FreeBSD/pandora_agent.conf | 3 +++ pandora_agents/unix/HP-UX/pandora_agent.conf | 3 +++ pandora_agents/unix/Linux/pandora_agent.conf | 3 +++ pandora_agents/unix/NetBSD/pandora_agent.conf | 3 +++ pandora_agents/unix/SunOS/pandora_agent.conf | 3 +++ pandora_agents/unix/pandora_agent | 6 +++--- 8 files changed, 24 insertions(+), 3 deletions(-) diff --git a/pandora_agents/unix/AIX/pandora_agent.conf b/pandora_agents/unix/AIX/pandora_agent.conf index 4fc8c757ba..d78044b76d 100644 --- a/pandora_agents/unix/AIX/pandora_agent.conf +++ b/pandora_agents/unix/AIX/pandora_agent.conf @@ -58,6 +58,9 @@ server_port 41121 # Transfer mode: tentacle, ftp, ssh or local transfer_mode tentacle +# Transfer mode user: Owner of files copied on local transfer mode (default apache) +#transfer_mode_user apache + # Server password (Tentacle or FTP). Leave empty for no password (default). # server_pwd mypassword diff --git a/pandora_agents/unix/Darwin/pandora_agent.conf b/pandora_agents/unix/Darwin/pandora_agent.conf index 41c6747052..11a58e3225 100644 --- a/pandora_agents/unix/Darwin/pandora_agent.conf +++ b/pandora_agents/unix/Darwin/pandora_agent.conf @@ -88,6 +88,9 @@ server_port 41121 # Transfer mode: tentacle, ftp, ssh or local transfer_mode tentacle +# Transfer mode user: Owner of files copied on local transfer mode (default apache) +#transfer_mode_user apache + # Server password (Tentacle or FTP). Leave empty for no password (default). #server_pwd mypassword diff --git a/pandora_agents/unix/FreeBSD/pandora_agent.conf b/pandora_agents/unix/FreeBSD/pandora_agent.conf index 29d6e893b7..6d988c94ac 100644 --- a/pandora_agents/unix/FreeBSD/pandora_agent.conf +++ b/pandora_agents/unix/FreeBSD/pandora_agent.conf @@ -98,6 +98,9 @@ server_port 41121 # Transfer mode: tentacle, ftp, ssh or local transfer_mode tentacle +# Transfer mode user: Owner of files copied on local transfer mode (default apache) +#transfer_mode_user apache + # timeout in seconds for file transfer programs execution (30 by default) #transfer_timeout 30 diff --git a/pandora_agents/unix/HP-UX/pandora_agent.conf b/pandora_agents/unix/HP-UX/pandora_agent.conf index 9db22b3b47..01bc718c43 100644 --- a/pandora_agents/unix/HP-UX/pandora_agent.conf +++ b/pandora_agents/unix/HP-UX/pandora_agent.conf @@ -60,6 +60,9 @@ server_port 41121 # Transfer mode: tentacle, ftp, ssh or local transfer_mode tentacle +# Transfer mode user: Owner of files copied on local transfer mode (default apache) +#transfer_mode_user apache + # Server password (Tentacle or FTP). Leave empty for no password (default). # server_pwd mypassword diff --git a/pandora_agents/unix/Linux/pandora_agent.conf b/pandora_agents/unix/Linux/pandora_agent.conf index fcfa94b429..00fa91f85f 100644 --- a/pandora_agents/unix/Linux/pandora_agent.conf +++ b/pandora_agents/unix/Linux/pandora_agent.conf @@ -104,6 +104,9 @@ server_port 41121 # Transfer mode: tentacle, ftp, ssh or local transfer_mode tentacle +# Transfer mode user: Owner of files copied on local transfer mode (default apache) +#transfer_mode_user apache + # timeout in seconds for file transfer programs execution (30 by default) #transfer_timeout 30 diff --git a/pandora_agents/unix/NetBSD/pandora_agent.conf b/pandora_agents/unix/NetBSD/pandora_agent.conf index 4f89baee8b..088a6b5159 100644 --- a/pandora_agents/unix/NetBSD/pandora_agent.conf +++ b/pandora_agents/unix/NetBSD/pandora_agent.conf @@ -66,6 +66,9 @@ server_port 41121 # Transfer mode: tentacle, ftp, ssh or local transfer_mode tentacle +# Transfer mode user: Owner of files copied on local transfer mode (default apache) +#transfer_mode_user apache + # timeout in seconds for file transfer programs execution (30 by default) #transfer_timeout 30 diff --git a/pandora_agents/unix/SunOS/pandora_agent.conf b/pandora_agents/unix/SunOS/pandora_agent.conf index 94bc194a05..3c50a12bfa 100644 --- a/pandora_agents/unix/SunOS/pandora_agent.conf +++ b/pandora_agents/unix/SunOS/pandora_agent.conf @@ -60,6 +60,9 @@ server_port 41121 # Transfer mode: tentacle, ftp, ssh or local transfer_mode tentacle +# Transfer mode user: Owner of files copied on local transfer mode (default apache) +#transfer_mode_user apache + # timeout in seconds for file transfer programs execution (30 by default) #transfer_timeout 30 diff --git a/pandora_agents/unix/pandora_agent b/pandora_agents/unix/pandora_agent index 32a98d3574..9f40e3b263 100755 --- a/pandora_agents/unix/pandora_agent +++ b/pandora_agents/unix/pandora_agent @@ -128,9 +128,9 @@ my @BrokerPid; my %DefaultConf = ( 'server_ip' => 'localhost', 'server_path' => '/var/spool/pandora/data_in', - 'server_path_md5' => 'md5', - 'server_path_conf' => 'conf', - 'server_path_zip' => 'collections', + 'server_path_md5' => 'md5', #undocumented + 'server_path_conf' => 'conf', #undocumented + 'server_path_zip' => 'collections', #undocumented 'logfile' =>'/var/log/pandora/pandora_agent.log', 'logsize' => DEFAULT_MAX_LOG_SIZE, 'logrotate' => DEFAULT_LOG_ROTATE,