Update imapsync_cron.pl

Fix executing imapsync command containing quoted strings in parameters.
master
hunter-nl 2019-05-04 11:45:51 +02:00 committed by GitHub
parent b09fab9125
commit 59882b443a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 27 additions and 36 deletions

View File

@ -18,14 +18,6 @@ if ($imapsync_running eq 1)
exit; exit;
} }
sub qqw($) {
my @values = split('(?=--)', $_[0]);
foreach my $val (@values) {
$val=trim($val);
}
return @values
}
$run_dir="/tmp"; $run_dir="/tmp";
$dsn = 'DBI:mysql:database=__DBNAME__;mysql_socket=/var/run/mysqld/mysqld.sock'; $dsn = 'DBI:mysql:database=__DBNAME__;mysql_socket=/var/run/mysqld/mysqld.sock';
$lock_file = $run_dir . "/imapsync_busy"; $lock_file = $run_dir . "/imapsync_busy";
@ -114,36 +106,35 @@ while ($row = $sth->fetchrow_arrayref()) {
print $passfile1 "$password1\n"; print $passfile1 "$password1\n";
print $passfile2 trim($master_pass) . "\n"; print $passfile2 trim($master_pass) . "\n";
my @custom_params_a = qqw($custom_params); my $command = "/usr/local/bin/imapsync";
my $custom_params_ref = \@custom_params_a; $command .= " --tmpdir /tmp";
$command .= " --pidfile /tmp/imapsync.pid";
my $generated_cmds = [ "/usr/local/bin/imapsync", $command .= " --nofoldersizes";
"--tmpdir", "/tmp", ($timeout1 gt "0" ? () : ($command .= " --timeout1 ${timeout1}"));
"--nofoldersizes", ($timeout2 gt "0" ? () : ($command .= " --timeout2 ${timeout2}"));
($timeout1 gt "0" ? () : ('--timeout1', $timeout1)), ($exclude eq "" ? () : ($command .= qq` --exclude ${exclude}`));
($timeout2 gt "0" ? () : ('--timeout2', $timeout2)), ($subfolder2 eq "" ? () : ($command .= qq` --subfolder2 ${subfolder2}`));
($exclude eq "" ? () : ("--exclude", $exclude)), ($maxage eq "0" ? () : ($command .= " --maxage ${maxage}"));
($subfolder2 eq "" ? () : ('--subfolder2', $subfolder2)), ($maxbytespersecond eq "0" ? () : ($command .= " --maxbytespersecond ${maxbytespersecond}"));
($maxage eq "0" ? () : ('--maxage', $maxage)), ($delete2duplicates ne "1" ? () : ($command .= " --delete2duplicates"));
($maxbytespersecond eq "0" ? () : ('--maxbytespersecond', $maxbytespersecond)), ($subscribeall ne "1" ? () : ($command .= " --subscribeall"));
($delete2duplicates ne "1" ? () : ('--delete2duplicates')), ($delete1 ne "1" ? () : ($command .= " --delete"));
($subscribeall ne "1" ? () : ('--subscribeall')), ($delete2 ne "1" ? () : ($command .= " --delete2"));
($delete1 ne "1" ? () : ('--delete')), ($automap ne "1" ? () : ($command .= " --automap"));
($delete2 ne "1" ? () : ('--delete2')), ($skipcrossduplicates ne "1" ? () : ($command .= " --skipcrossduplicates"));
($automap ne "1" ? () : ('--automap')), (!defined($enc1) ? () : ($command .= " ${enc1}"));
($skipcrossduplicates ne "1" ? () : ('--skipcrossduplicates')), $command .= " --host1 ${host1}";
(!defined($enc1) ? () : ($enc1)), $command .= qq` --user1 ${user1}`;
"--host1", $host1, $command .= " --passfile1 $passfile1->filename";
"--user1", $user1, $command .= " --port1 ${port1}";
"--passfile1", $passfile1->filename, $command .= " --host2 localhost";
"--port1", $port1, $command .= " --user2 ${user2}" . '*' . trim($master_user);
"--host2", "localhost", $command .= " --passfile2 $passfile2->filename";
"--user2", $user2 . '*' . trim($master_user), $command .= " --no-modulesversion";
"--passfile2", $passfile2->filename, ($custom_params eq "" ? () : ($command .= qq` ${custom_params}`));
'--no-modulesversion'];
try { try {
run [@$generated_cmds, @$custom_params_ref], '&>', \my $stdout; my $stdout = `${command}`
$update = $dbh->prepare("UPDATE imapsync SET returned_text = ?, last_run = NOW(), is_running = 0 WHERE id = ?"); $update = $dbh->prepare("UPDATE imapsync SET returned_text = ?, last_run = NOW(), is_running = 0 WHERE id = ?");
$update->bind_param( 1, ${stdout} ); $update->bind_param( 1, ${stdout} );
$update->bind_param( 2, ${id} ); $update->bind_param( 2, ${id} );