From 472a99ff00da3e935564a4fb98ed3fc187c5421d Mon Sep 17 00:00:00 2001 From: emericklaw Date: Fri, 3 May 2019 13:31:10 +0100 Subject: [PATCH 1/9] Handle mobileconfig display names with special characters If the account display name contained special characters like & the mobileconfig would fail to import on the iOS device. --- data/web/mobileconfig.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/web/mobileconfig.php b/data/web/mobileconfig.php index ade4f606..abdf2cb8 100644 --- a/data/web/mobileconfig.php +++ b/data/web/mobileconfig.php @@ -22,7 +22,7 @@ try { $stmt = $pdo->prepare("SELECT `name` FROM `mailbox` WHERE `username`= :username"); $stmt->execute(array(':username' => $email)); $MailboxData = $stmt->fetch(PDO::FETCH_ASSOC); - $displayname = empty($MailboxData['name']) ? $email : $MailboxData['name']; + $displayname = htmlspecialchars(empty($MailboxData['name']) ? $email : $MailboxData['name']); } catch(PDOException $e) { $displayname = $email; From 12d46cf072875a7703681765db3c092f951edd3e Mon Sep 17 00:00:00 2001 From: emericklaw Date: Fri, 3 May 2019 17:54:33 +0100 Subject: [PATCH 2/9] Updated to not convert quotes I missed using ENT_NOQUOTES since XML only needs & and <> to be replaced in tags, spotted by @mkuron --- data/web/mobileconfig.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/web/mobileconfig.php b/data/web/mobileconfig.php index abdf2cb8..38b249c6 100644 --- a/data/web/mobileconfig.php +++ b/data/web/mobileconfig.php @@ -22,7 +22,7 @@ try { $stmt = $pdo->prepare("SELECT `name` FROM `mailbox` WHERE `username`= :username"); $stmt->execute(array(':username' => $email)); $MailboxData = $stmt->fetch(PDO::FETCH_ASSOC); - $displayname = htmlspecialchars(empty($MailboxData['name']) ? $email : $MailboxData['name']); + $displayname = htmlspecialchars(empty($MailboxData['name']) ? $email : $MailboxData['name'], ENT_NOQUOTES); } catch(PDOException $e) { $displayname = $email; From 59882b443ad6cd39f9483fa0665210794df89179 Mon Sep 17 00:00:00 2001 From: hunter-nl Date: Sat, 4 May 2019 11:45:51 +0200 Subject: [PATCH 3/9] Update imapsync_cron.pl Fix executing imapsync command containing quoted strings in parameters. --- data/Dockerfiles/dovecot/imapsync_cron.pl | 63 ++++++++++------------- 1 file changed, 27 insertions(+), 36 deletions(-) diff --git a/data/Dockerfiles/dovecot/imapsync_cron.pl b/data/Dockerfiles/dovecot/imapsync_cron.pl index 4fad97ab..f9e53bf3 100755 --- a/data/Dockerfiles/dovecot/imapsync_cron.pl +++ b/data/Dockerfiles/dovecot/imapsync_cron.pl @@ -18,14 +18,6 @@ if ($imapsync_running eq 1) exit; } -sub qqw($) { - my @values = split('(?=--)', $_[0]); - foreach my $val (@values) { - $val=trim($val); - } - return @values -} - $run_dir="/tmp"; $dsn = 'DBI:mysql:database=__DBNAME__;mysql_socket=/var/run/mysqld/mysqld.sock'; $lock_file = $run_dir . "/imapsync_busy"; @@ -114,36 +106,35 @@ while ($row = $sth->fetchrow_arrayref()) { print $passfile1 "$password1\n"; print $passfile2 trim($master_pass) . "\n"; - my @custom_params_a = qqw($custom_params); - my $custom_params_ref = \@custom_params_a; - - my $generated_cmds = [ "/usr/local/bin/imapsync", - "--tmpdir", "/tmp", - "--nofoldersizes", - ($timeout1 gt "0" ? () : ('--timeout1', $timeout1)), - ($timeout2 gt "0" ? () : ('--timeout2', $timeout2)), - ($exclude eq "" ? () : ("--exclude", $exclude)), - ($subfolder2 eq "" ? () : ('--subfolder2', $subfolder2)), - ($maxage eq "0" ? () : ('--maxage', $maxage)), - ($maxbytespersecond eq "0" ? () : ('--maxbytespersecond', $maxbytespersecond)), - ($delete2duplicates ne "1" ? () : ('--delete2duplicates')), - ($subscribeall ne "1" ? () : ('--subscribeall')), - ($delete1 ne "1" ? () : ('--delete')), - ($delete2 ne "1" ? () : ('--delete2')), - ($automap ne "1" ? () : ('--automap')), - ($skipcrossduplicates ne "1" ? () : ('--skipcrossduplicates')), - (!defined($enc1) ? () : ($enc1)), - "--host1", $host1, - "--user1", $user1, - "--passfile1", $passfile1->filename, - "--port1", $port1, - "--host2", "localhost", - "--user2", $user2 . '*' . trim($master_user), - "--passfile2", $passfile2->filename, - '--no-modulesversion']; + my $command = "/usr/local/bin/imapsync"; + $command .= " --tmpdir /tmp"; + $command .= " --pidfile /tmp/imapsync.pid"; + $command .= " --nofoldersizes"; + ($timeout1 gt "0" ? () : ($command .= " --timeout1 ${timeout1}")); + ($timeout2 gt "0" ? () : ($command .= " --timeout2 ${timeout2}")); + ($exclude eq "" ? () : ($command .= qq` --exclude ${exclude}`)); + ($subfolder2 eq "" ? () : ($command .= qq` --subfolder2 ${subfolder2}`)); + ($maxage eq "0" ? () : ($command .= " --maxage ${maxage}")); + ($maxbytespersecond eq "0" ? () : ($command .= " --maxbytespersecond ${maxbytespersecond}")); + ($delete2duplicates ne "1" ? () : ($command .= " --delete2duplicates")); + ($subscribeall ne "1" ? () : ($command .= " --subscribeall")); + ($delete1 ne "1" ? () : ($command .= " --delete")); + ($delete2 ne "1" ? () : ($command .= " --delete2")); + ($automap ne "1" ? () : ($command .= " --automap")); + ($skipcrossduplicates ne "1" ? () : ($command .= " --skipcrossduplicates")); + (!defined($enc1) ? () : ($command .= " ${enc1}")); + $command .= " --host1 ${host1}"; + $command .= qq` --user1 ${user1}`; + $command .= " --passfile1 $passfile1->filename"; + $command .= " --port1 ${port1}"; + $command .= " --host2 localhost"; + $command .= " --user2 ${user2}" . '*' . trim($master_user); + $command .= " --passfile2 $passfile2->filename"; + $command .= " --no-modulesversion"; + ($custom_params eq "" ? () : ($command .= qq` ${custom_params}`)); 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->bind_param( 1, ${stdout} ); $update->bind_param( 2, ${id} ); From 95fe217ce1b4c9df36c6a30d6e56477b315b84c9 Mon Sep 17 00:00:00 2001 From: hunter-nl Date: Sat, 4 May 2019 11:58:19 +0200 Subject: [PATCH 4/9] Update imapsync_cron.pl Fix: Reset is_running status in case of exception occurs in running imapsync. Else it will stuck in "running" status. --- data/Dockerfiles/dovecot/imapsync_cron.pl | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/data/Dockerfiles/dovecot/imapsync_cron.pl b/data/Dockerfiles/dovecot/imapsync_cron.pl index f9e53bf3..01cd0ad8 100755 --- a/data/Dockerfiles/dovecot/imapsync_cron.pl +++ b/data/Dockerfiles/dovecot/imapsync_cron.pl @@ -140,12 +140,17 @@ while ($row = $sth->fetchrow_arrayref()) { $update->bind_param( 2, ${id} ); $update->execute(); } catch { - $update = $dbh->prepare("UPDATE imapsync SET returned_text = 'Could not start or finish imapsync', last_run = NOW(), is_running = 0 WHERE id = ?"); + $update = $dbh->prepare("UPDATE imapsync SET returned_text = 'Could not start or finish imapsync' WHERE id = ?"); + $update->bind_param( 1, ${id} ); + $update->execute(); + } finally { + $update = $dbh->prepare("UPDATE imapsync SET last_run = NOW(), is_running = 0 WHERE id = ?"); $update->bind_param( 1, ${id} ); $update->execute(); $lockmgr->unlock($lock_file); }; + } $sth->finish(); From f9cd9927b1143b6ee12f725f87b08c5e5b2f49f4 Mon Sep 17 00:00:00 2001 From: hunter-nl Date: Sat, 4 May 2019 12:02:41 +0200 Subject: [PATCH 5/9] Update imapsync_cron.pl Moved setting "is_running" status to just before the actual execution of imapsync command. --- data/Dockerfiles/dovecot/imapsync_cron.pl | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/data/Dockerfiles/dovecot/imapsync_cron.pl b/data/Dockerfiles/dovecot/imapsync_cron.pl index 01cd0ad8..cff2852b 100755 --- a/data/Dockerfiles/dovecot/imapsync_cron.pl +++ b/data/Dockerfiles/dovecot/imapsync_cron.pl @@ -93,10 +93,6 @@ while ($row = $sth->fetchrow_arrayref()) { $timeout1 = @$row[19]; $timeout2 = @$row[20]; - $is_running = $dbh->prepare("UPDATE imapsync SET is_running = 1 WHERE id = ?"); - $is_running->bind_param( 1, ${id} ); - $is_running->execute(); - if ($enc1 eq "TLS") { $enc1 = "--tls1"; } elsif ($enc1 eq "SSL") { $enc1 = "--ssl1"; } else { undef $enc1; } my $template = $run_dir . '/imapsync.XXXXXXX'; @@ -134,6 +130,9 @@ while ($row = $sth->fetchrow_arrayref()) { ($custom_params eq "" ? () : ($command .= qq` ${custom_params}`)); try { + $is_running = $dbh->prepare("UPDATE imapsync SET is_running = 1 WHERE id = ?"); + $is_running->bind_param( 1, ${id} ); + $is_running->execute(); my $stdout = `${command}` $update = $dbh->prepare("UPDATE imapsync SET returned_text = ?, last_run = NOW(), is_running = 0 WHERE id = ?"); $update->bind_param( 1, ${stdout} ); From 99eb61a449ede688d392dd0263c29b434acad006 Mon Sep 17 00:00:00 2001 From: hunter-nl Date: Sat, 4 May 2019 12:13:51 +0200 Subject: [PATCH 6/9] Update init_db.inc.php imapsync table column "returned_text" changed into type "longtext". "mediumtext" is to small for imapsync output on large mailbox. db version value updated. --- data/web/inc/init_db.inc.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/data/web/inc/init_db.inc.php b/data/web/inc/init_db.inc.php index 3c553bfd..27db8c1f 100644 --- a/data/web/inc/init_db.inc.php +++ b/data/web/inc/init_db.inc.php @@ -3,7 +3,7 @@ function init_db_schema() { try { global $pdo; - $db_version = "30032019_1905"; + $db_version = "04052019_1210"; $stmt = $pdo->query("SHOW TABLES LIKE 'versions'"); $num_results = count($stmt->fetchAll(PDO::FETCH_ASSOC)); @@ -502,7 +502,7 @@ function init_db_schema() { "timeout2" => "SMALLINT NOT NULL DEFAULT '600'", "subscribeall" => "TINYINT(1) NOT NULL DEFAULT '1'", "is_running" => "TINYINT(1) NOT NULL DEFAULT '0'", - "returned_text" => "MEDIUMTEXT", + "returned_text" => "LONGTEXT", "last_run" => "TIMESTAMP NULL DEFAULT NULL", "created" => "DATETIME(0) NOT NULL DEFAULT NOW(0)", "modified" => "DATETIME ON UPDATE CURRENT_TIMESTAMP", From e59417ed781e584296a386cd2eb3eb1d88aee330 Mon Sep 17 00:00:00 2001 From: hunter-nl Date: Sat, 4 May 2019 13:07:23 +0200 Subject: [PATCH 7/9] Update imapsync_cron.pl Second unlocking lock_file failed because it was already unlocked. --- data/Dockerfiles/dovecot/imapsync_cron.pl | 1 - 1 file changed, 1 deletion(-) diff --git a/data/Dockerfiles/dovecot/imapsync_cron.pl b/data/Dockerfiles/dovecot/imapsync_cron.pl index cff2852b..c583e810 100755 --- a/data/Dockerfiles/dovecot/imapsync_cron.pl +++ b/data/Dockerfiles/dovecot/imapsync_cron.pl @@ -146,7 +146,6 @@ while ($row = $sth->fetchrow_arrayref()) { $update = $dbh->prepare("UPDATE imapsync SET last_run = NOW(), is_running = 0 WHERE id = ?"); $update->bind_param( 1, ${id} ); $update->execute(); - $lockmgr->unlock($lock_file); }; From 189ea89a7189a0fc3e20601e52254b563014f8ae Mon Sep 17 00:00:00 2001 From: andryyy Date: Sat, 4 May 2019 23:08:35 +0200 Subject: [PATCH 8/9] [Dovecot] Revert to previous imapsync cron script --- data/Dockerfiles/dovecot/imapsync_cron.pl | 78 ++++++++++++----------- 1 file changed, 42 insertions(+), 36 deletions(-) mode change 100755 => 100644 data/Dockerfiles/dovecot/imapsync_cron.pl diff --git a/data/Dockerfiles/dovecot/imapsync_cron.pl b/data/Dockerfiles/dovecot/imapsync_cron.pl old mode 100755 new mode 100644 index c583e810..c63769f0 --- a/data/Dockerfiles/dovecot/imapsync_cron.pl +++ b/data/Dockerfiles/dovecot/imapsync_cron.pl @@ -18,6 +18,14 @@ if ($imapsync_running eq 1) exit; } +sub qqw($) { + my @values = split('(?=--)', $_[0]); + foreach my $val (@values) { + $val=trim($val); + } + return @values +} + $run_dir="/tmp"; $dsn = 'DBI:mysql:database=__DBNAME__;mysql_socket=/var/run/mysqld/mysqld.sock'; $lock_file = $run_dir . "/imapsync_busy"; @@ -93,6 +101,10 @@ while ($row = $sth->fetchrow_arrayref()) { $timeout1 = @$row[19]; $timeout2 = @$row[20]; + $is_running = $dbh->prepare("UPDATE imapsync SET is_running = 1 WHERE id = ?"); + $is_running->bind_param( 1, ${id} ); + $is_running->execute(); + if ($enc1 eq "TLS") { $enc1 = "--tls1"; } elsif ($enc1 eq "SSL") { $enc1 = "--ssl1"; } else { undef $enc1; } my $template = $run_dir . '/imapsync.XXXXXXX'; @@ -102,53 +114,47 @@ while ($row = $sth->fetchrow_arrayref()) { print $passfile1 "$password1\n"; print $passfile2 trim($master_pass) . "\n"; - my $command = "/usr/local/bin/imapsync"; - $command .= " --tmpdir /tmp"; - $command .= " --pidfile /tmp/imapsync.pid"; - $command .= " --nofoldersizes"; - ($timeout1 gt "0" ? () : ($command .= " --timeout1 ${timeout1}")); - ($timeout2 gt "0" ? () : ($command .= " --timeout2 ${timeout2}")); - ($exclude eq "" ? () : ($command .= qq` --exclude ${exclude}`)); - ($subfolder2 eq "" ? () : ($command .= qq` --subfolder2 ${subfolder2}`)); - ($maxage eq "0" ? () : ($command .= " --maxage ${maxage}")); - ($maxbytespersecond eq "0" ? () : ($command .= " --maxbytespersecond ${maxbytespersecond}")); - ($delete2duplicates ne "1" ? () : ($command .= " --delete2duplicates")); - ($subscribeall ne "1" ? () : ($command .= " --subscribeall")); - ($delete1 ne "1" ? () : ($command .= " --delete")); - ($delete2 ne "1" ? () : ($command .= " --delete2")); - ($automap ne "1" ? () : ($command .= " --automap")); - ($skipcrossduplicates ne "1" ? () : ($command .= " --skipcrossduplicates")); - (!defined($enc1) ? () : ($command .= " ${enc1}")); - $command .= " --host1 ${host1}"; - $command .= qq` --user1 ${user1}`; - $command .= " --passfile1 $passfile1->filename"; - $command .= " --port1 ${port1}"; - $command .= " --host2 localhost"; - $command .= " --user2 ${user2}" . '*' . trim($master_user); - $command .= " --passfile2 $passfile2->filename"; - $command .= " --no-modulesversion"; - ($custom_params eq "" ? () : ($command .= qq` ${custom_params}`)); + my @custom_params_a = qqw($custom_params); + my $custom_params_ref = \@custom_params_a; + + my $generated_cmds = [ "/usr/local/bin/imapsync", + "--tmpdir", "/tmp", + "--nofoldersizes", + ($timeout1 gt "0" ? () : ('--timeout1', $timeout1)), + ($timeout2 gt "0" ? () : ('--timeout2', $timeout2)), + ($exclude eq "" ? () : ("--exclude", $exclude)), + ($subfolder2 eq "" ? () : ('--subfolder2', $subfolder2)), + ($maxage eq "0" ? () : ('--maxage', $maxage)), + ($maxbytespersecond eq "0" ? () : ('--maxbytespersecond', $maxbytespersecond)), + ($delete2duplicates ne "1" ? () : ('--delete2duplicates')), + ($subscribeall ne "1" ? () : ('--subscribeall')), + ($delete1 ne "1" ? () : ('--delete')), + ($delete2 ne "1" ? () : ('--delete2')), + ($automap ne "1" ? () : ('--automap')), + ($skipcrossduplicates ne "1" ? () : ('--skipcrossduplicates')), + (!defined($enc1) ? () : ($enc1)), + "--host1", $host1, + "--user1", $user1, + "--passfile1", $passfile1->filename, + "--port1", $port1, + "--host2", "localhost", + "--user2", $user2 . '*' . trim($master_user), + "--passfile2", $passfile2->filename, + '--no-modulesversion']; try { - $is_running = $dbh->prepare("UPDATE imapsync SET is_running = 1 WHERE id = ?"); - $is_running->bind_param( 1, ${id} ); - $is_running->execute(); - my $stdout = `${command}` + run [@$generated_cmds, @$custom_params_ref], '&>', \my $stdout; $update = $dbh->prepare("UPDATE imapsync SET returned_text = ?, last_run = NOW(), is_running = 0 WHERE id = ?"); $update->bind_param( 1, ${stdout} ); $update->bind_param( 2, ${id} ); $update->execute(); } catch { - $update = $dbh->prepare("UPDATE imapsync SET returned_text = 'Could not start or finish imapsync' WHERE id = ?"); - $update->bind_param( 1, ${id} ); - $update->execute(); - } finally { - $update = $dbh->prepare("UPDATE imapsync SET last_run = NOW(), is_running = 0 WHERE id = ?"); + $update = $dbh->prepare("UPDATE imapsync SET returned_text = 'Could not start or finish imapsync', last_run = NOW(), is_running = 0 WHERE id = ?"); $update->bind_param( 1, ${id} ); $update->execute(); + $lockmgr->unlock($lock_file); }; - } $sth->finish(); From 14627645dab12053850b4ccfff0c50d000ee30fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Peters?= Date: Sat, 4 May 2019 23:32:32 +0200 Subject: [PATCH 9/9] Update README.md --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index ec500d9c..3425de00 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,8 @@ # mailcow: dockerized - 🐮 + 🐋 = 💕 +## 💡 Entwickler gesucht! +Wir möchten die Kuh clustern und noch sicherererer machen, daher suchen wir dringend Entwickler, die dabei unterstützen. Bis hin zur Festanstellung alle Möglichkeiten offen. Bitte meldet euch bei info@servercow.de + ## Want to support mailcow? Donate via **PayPal** [![Donate](https://www.paypalobjects.com/en_US/i/btn/btn_donate_LG.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=JWBSYHF4SMC68) or via **Liberapay** [![Liberapay.com](https://mailcow.email/img/lp.png)](https://liberapay.com/mailcow)