From 0ebb0068885d3b7f3e5049bbe49710076cb0104d Mon Sep 17 00:00:00 2001 From: Andrey Miroshnichenko Date: Thu, 13 May 2021 00:23:05 +0300 Subject: [PATCH 01/13] Adds an ability to update password_expity field when user changes own password --- model/Login.php | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/model/Login.php b/model/Login.php index 4018d867..60578da2 100644 --- a/model/Login.php +++ b/model/Login.php @@ -91,6 +91,32 @@ class Login return false; } + /** + * returns user's domain name + * @param $username + * @return mixed|null + * @throws Exception + */ + protected function getUserDomain($username) + { + $sql = "SELECT domain FROM {$this->table} WHERE username = :username AND active = :active"; + + $active = db_get_boolean(true); + + $values = [ + 'username' => $username, + 'active' => $active, + ]; + + // Fetch the domain + $result = db_query_one($sql, $values); + + if (is_array($result) && isset($result['domain'])) { + return $result['domain']; + } else { + return NULL; + } + } /** * @param string $username @@ -115,6 +141,14 @@ class Login 'password' => pacrypt($new_password), ); + if (Config::bool('password_expiration')) { + $domain = $this->getUserDomain($username); + if (!is_null($domain)) { + $password_expiration_value = (int)get_password_expiration_value($domain); + $set['password_expiry'] = date('Y-m-d H:i', strtotime("+$password_expiration_value day")); + } + } + $result = db_update($this->table, 'username', $username, $set); if ($result != 1) { From 9cda7f402c253ba46ac0c40dad1a320f0ba9a48d Mon Sep 17 00:00:00 2001 From: Andrey Miroshnichenko Date: Thu, 13 May 2021 00:54:41 +0300 Subject: [PATCH 02/13] Minor fixes of the password expiration checker script example. --- DOCUMENTS/Password_Expiration.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DOCUMENTS/Password_Expiration.md b/DOCUMENTS/Password_Expiration.md index 2008d0c1..0d9fb826 100644 --- a/DOCUMENTS/Password_Expiration.md +++ b/DOCUMENTS/Password_Expiration.md @@ -85,7 +85,7 @@ do QUERY="SELECT username,password_expiry FROM mailbox WHERE password_expiry > now() + interval $LOWER DAY AND password_expiry < NOW() + interval $INTERVAL DAY" - mysql --defaults-extra-file="$MYSQL_CREDENTIALS_FILE" "$POSTFIX_DB" -B -e "$QUERY" | while read -a RESULT ; do + mysql --defaults-extra-file="$MYSQL_CREDENTIALS_FILE" "$POSTFIX_DB" -B -N -e "$QUERY" | while IFS=$'\t' read -a RESULT ; do echo -e "Dear User, \n Your password will expire on ${RESULT[1]}" | mail -s "Password 30 days before expiration notication" -r $REPLY_ADDRESS ${RESULT[0]} done done From 44f2f94f786ce04ef0c4d549bf17857b694a4419 Mon Sep 17 00:00:00 2001 From: David Goodwin Date: Fri, 7 May 2021 20:25:54 +0100 Subject: [PATCH 03/13] update CHANGELOG --- CHANGELOG.TXT | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.TXT b/CHANGELOG.TXT index f1d716d2..ebb86851 100644 --- a/CHANGELOG.TXT +++ b/CHANGELOG.TXT @@ -12,6 +12,11 @@ MASTER (should have all changes from 3.3.9 plus) - Add optional Dovecot mail-crypt plugin support - see https://github.com/postfixadmin/postfixadmin/issues/408 - Add $CONF['site_url'] to allow administrators to override a detected site url (e.g. used in password recovery emails; see https://github.com/postfixadmin/postfixadmin/issues/446 ) - Code reformat as PHPCS has a mind of it's own (function/method opening brace change of position) + - Improved UTF8 support in vacation (see https://github.com/postfixadmin/postfixadmin/pull/484) + - Fix quota levels losing config control (see bfc7af5c8efe2a68c47286cc870b56cb4f929a3f) + - Improve vacation.pl's autoreply detection (see https://github.com/postfixadmin/postfixadmin/pull/482 + - Improve vacation.pl's headers in auto-reply mails (add: "Auto-Submitted: auto-replied") see https://github.com/postfixadmin/postfixadmin/pull/483 + Version 3.3.9 - ?????????? ------------------------------------------------- From 584e4ef41d272cf29ec5a3387be0660b53fb10b2 Mon Sep 17 00:00:00 2001 From: David Goodwin Date: Thu, 13 May 2021 12:56:38 +0100 Subject: [PATCH 04/13] type hinting changes --- model/Login.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/model/Login.php b/model/Login.php index 60578da2..d63e39dc 100644 --- a/model/Login.php +++ b/model/Login.php @@ -94,18 +94,16 @@ class Login /** * returns user's domain name * @param $username - * @return mixed|null + * @return string|null * @throws Exception */ - protected function getUserDomain($username) + protected function getUserDomain(string $username) { $sql = "SELECT domain FROM {$this->table} WHERE username = :username AND active = :active"; - $active = db_get_boolean(true); - $values = [ 'username' => $username, - 'active' => $active, + 'active' => db_get_boolean(true), ]; // Fetch the domain From ad342e1d67127b555def97406fc1f810e18f7347 Mon Sep 17 00:00:00 2001 From: David Goodwin Date: Thu, 13 May 2021 13:07:36 +0100 Subject: [PATCH 05/13] remove readonly attribute from user vacation page - see https://sourceforge.net/p/postfixadmin/discussion/676076/thread/5637ae3bc5 --- templates/vacation.tpl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/vacation.tpl b/templates/vacation.tpl index 654522ea..b57134fd 100644 --- a/templates/vacation.tpl +++ b/templates/vacation.tpl @@ -17,7 +17,7 @@ class="form-control hidden"/>
+ class="form-control" />
@@ -31,7 +31,7 @@
+ class="form-control" />
From 8518d53906293ae3f0bdf4db6e67f53975a112a9 Mon Sep 17 00:00:00 2001 From: David Goodwin Date: Thu, 13 May 2021 13:15:27 +0100 Subject: [PATCH 06/13] merge postfixadmin_3.3 into master --- CHANGELOG.TXT | 15 ++++++++++++--- functions.inc.php | 2 +- languages/ua.lang | 6 ++++-- model/Login.php | 2 +- public/upgrade.php | 5 +++-- 5 files changed, 21 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.TXT b/CHANGELOG.TXT index ebb86851..3025b71d 100644 --- a/CHANGELOG.TXT +++ b/CHANGELOG.TXT @@ -6,7 +6,7 @@ # # Further details on the project are available at https://github.com/postfixadmin/postfixadmin -MASTER (should have all changes from 3.3.9 plus) +MASTER (should have all changes from 3.3.10 plus) ------ - Add optional Dovecot mail-crypt plugin support - see https://github.com/postfixadmin/postfixadmin/issues/408 @@ -18,11 +18,20 @@ MASTER (should have all changes from 3.3.9 plus) - Improve vacation.pl's headers in auto-reply mails (add: "Auto-Submitted: auto-replied") see https://github.com/postfixadmin/postfixadmin/pull/483 -Version 3.3.9 - ?????????? +Version 3.3.10 - ??? ------------------------------------------------- - - Improve Ukrainian language (thanks: andrew.kudrinov) (forgot to cherry-pick 4a960a0ce06b0754fa7b39aed0d5c57a88b20720 from master) + - Merge password expiration fixes from https://github.com/postfixadmin/postfixadmin/pull/493 + - Remove html readonly attribute from user's vacation page to/from selectors. + + +Version 3.3.9 - 2021/05/12 +------------------------------------------------- + - Improve Ukrainian language (ua.lang) (thanks: andrew.kudrinov) - Ensure we update timestamp fields (created / modified) when performing db operations, see: https://github.com/postfixadmin/postfixadmin/issues/469 - Add domain_admins.id pk column for non-sqlite users, see: https://github.com/postfixadmin/postfixadmin/issues/475 + - Add fix for MySQL error where a default datetime value in the domain field breaks the upgrade.php db schema update, see https://github.com/postfixadmin/postfixadmin/issues/489 + - Bug fix quota levels (now user configurable again; thanks @csware, see https://github.com/postfixadmin/postfixadmin/commit/bfc7af5c8efe2a68c47286cc870b56cb4f929a3f +>>>>>>> postfixadmin_3.3 Version 3.3.8 - 2021/03/04 ------------------------------------------------- diff --git a/functions.inc.php b/functions.inc.php index cc951417..3e647b84 100644 --- a/functions.inc.php +++ b/functions.inc.php @@ -15,7 +15,7 @@ */ -$min_db_version = 1843; # update (at least) before a release with the latest function numbrer in upgrade.php +$min_db_version = 1844; # update (at least) before a release with the latest function numbrer in upgrade.php /** * check_session diff --git a/languages/ua.lang b/languages/ua.lang index cfcdb561..c060ba7d 100644 --- a/languages/ua.lang +++ b/languages/ua.lang @@ -275,12 +275,14 @@ $PALANG['domain_updated'] = 'Домен %s успішно оновлено.'; $PALANG['pAdminDelete_admin_error'] = 'Неможливо видалити адміністратора!'; $PALANG['domain_postdel_failed'] = 'Не вдалося коректно виконати скрипт після видалення домену, подробиці дивіться у журналі помилок!'; -$PALANG['domain_postedit_failed'] = 'The domain postedit script failed, check the error log for details!'; # XXX +$PALANG['domain_postedit_failed'] = 'Не вдалося коректно виконати скрипт після редагування домену, подробиці дивіться у журналі помилок!'; + $PALANG['domain_postcreate_failed'] = 'Не вдалося коректно виконати скрипт після створення домену, подробиці дивіться у журналі помилок!'; $PALANG['mailbox_postdel_failed'] = 'Не вдалося коректно виконати скрипт після видалення поштової скриньки, подробиці дивіться у журналі помилок!'; $PALANG['mailbox_postedit_failed'] = 'Не вдалося коректно виконати скрипт після редагування поштової скриньки, подробиці дивіться у журналі помилок!'; $PALANG['mailbox_postcreate_failed'] = 'Не вдалося коректно виконати скрипт після створення поштової скриньки, подробиці дивіться у журналі помилок!'; -$PALANG['mailbox_postpassword_failed'] = 'The mailbox postpassword script failed, check the error log for details!'; # XXX +$PALANG['mailbox_postpassword_failed'] = 'Не вдалося коректно виконати скрипт після зміни пароля поштової скриньки, подробиці дивіться у журналі помилок!'; + $PALANG['pAdminDelete_alias_domain_error'] = 'Неможливо видалити псевдоним (аліас) домену!'; $PALANG['domain_conflict_vacation_domain'] = 'Ви не можете використовувати домен автовідповідача у якості поштового домену!'; diff --git a/model/Login.php b/model/Login.php index d63e39dc..6b7419c7 100644 --- a/model/Login.php +++ b/model/Login.php @@ -112,7 +112,7 @@ class Login if (is_array($result) && isset($result['domain'])) { return $result['domain']; } else { - return NULL; + return null; } } diff --git a/public/upgrade.php b/public/upgrade.php index afb8346b..d58014ed 100644 --- a/public/upgrade.php +++ b/public/upgrade.php @@ -256,7 +256,7 @@ function db_query_parsed($sql, $ignore_errors = 0, $attach_mysql = "") '{UNSIGNED}' => 'unsigned' , '{FULLTEXT}' => 'FULLTEXT', '{BOOLEAN}' => "tinyint(1) NOT NULL DEFAULT '" . db_get_boolean(false) . "'", - '{UTF-8}' => '/*!40100 CHARACTER SET utf8 */', + '{UTF-8}' => '/*!40100 CHARACTER SET utf8mb4 */', '{LATIN1}' => '/*!40100 CHARACTER SET latin1 COLLATE latin1_general_ci */', '{IF_NOT_EXISTS}' => 'IF NOT EXISTS', '{RENAME_COLUMN}' => 'CHANGE COLUMN', @@ -1890,7 +1890,7 @@ function upgrade_1836_mysql() /** * @return void */ -function upgrade_1837() +function upgrade_1837() { if (db_sqlite()) { return; @@ -1903,6 +1903,7 @@ function upgrade_1837() _db_add_field($table, 'token_validity', '{DATETIME}', 'token'); } } + # TODO MySQL: # - various varchar fields do not have a default value # https://sourceforge.net/projects/postfixadmin/forums/forum/676076/topic/3419725 From b271ae8cb804e701298564fa87dabba1d59d6f52 Mon Sep 17 00:00:00 2001 From: David Goodwin Date: Thu, 13 May 2021 13:17:07 +0100 Subject: [PATCH 07/13] composer format! --- public/upgrade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/upgrade.php b/public/upgrade.php index d58014ed..577b9f0d 100644 --- a/public/upgrade.php +++ b/public/upgrade.php @@ -1890,7 +1890,7 @@ function upgrade_1836_mysql() /** * @return void */ -function upgrade_1837() +function upgrade_1837() { if (db_sqlite()) { return; From 5a305bc830936a302cf7e0a228651ef292069f2b Mon Sep 17 00:00:00 2001 From: David Goodwin Date: Thu, 13 May 2021 16:15:45 +0100 Subject: [PATCH 08/13] allow vacation settings to include a time (but specify a time if one is not), this should stop us overwriting the time - see https://sourceforge.net/p/postfixadmin/discussion/676076/thread/5637ae3bc5/?limit=25#24a5 --- model/VacationHandler.php | 12 +++++++++--- public/vacation.php | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/model/VacationHandler.php b/model/VacationHandler.php index 73d6b91b..c01f7db8 100644 --- a/model/VacationHandler.php +++ b/model/VacationHandler.php @@ -231,9 +231,15 @@ class VacationHandler extends PFAHandler { $this->remove(); // clean out any notifications that might already have been sent. - $E_username = escape_string($this->username); - $activeFrom = date("Y-m-d 00:00:00", strtotime($activeFrom)); # TODO check if result looks like a valid date - $activeUntil = date("Y-m-d 23:59:59", strtotime($activeUntil)); # TODO check if result looks like a valid date + if (preg_match('/^\d{4}-\d{2}-\d{2}$/', $activeFrom)) { + $activeFrom .= ' 00:00:00'; + } + if (preg_match('/^\d{4}-\d{2}-\d{2}$/', $activeUntil)) { + $activeUntil .= ' 23:59:59'; + } + + $activeFrom = date("Y-m-d H:i", strtotime($activeFrom)); # TODO check if result looks like a valid date + $activeUntil = date("Y-m-d H:i", strtotime($activeUntil)); # TODO check if result looks like a valid date list(/*NULL*/, $domain) = explode('@', $this->username); $vacation_data = array( diff --git a/public/vacation.php b/public/vacation.php index 36558c01..59b662b0 100644 --- a/public/vacation.php +++ b/public/vacation.php @@ -154,7 +154,7 @@ if ($_SERVER['REQUEST_METHOD'] == "POST") { if ($action == 'fChange') { - ## check if ActiveUnitl is not back in time, + ## check if ActiveUntil is not back in time, ## because vacation.pl will report SMTP recipient $smtp_recipient which resolves to $email does not have an active vacation (rv: $rv, email: $email)" ## and will not send message From 7bf1bb9ffac0a20ccd45040097cae02ee1ec8e4a Mon Sep 17 00:00:00 2001 From: Christian Boltz Date: Thu, 13 May 2021 21:38:25 +0200 Subject: [PATCH 09/13] fix merge conflict leftover in changelog --- CHANGELOG.TXT | 1 - 1 file changed, 1 deletion(-) diff --git a/CHANGELOG.TXT b/CHANGELOG.TXT index 3025b71d..4ae7ef69 100644 --- a/CHANGELOG.TXT +++ b/CHANGELOG.TXT @@ -31,7 +31,6 @@ Version 3.3.9 - 2021/05/12 - Add domain_admins.id pk column for non-sqlite users, see: https://github.com/postfixadmin/postfixadmin/issues/475 - Add fix for MySQL error where a default datetime value in the domain field breaks the upgrade.php db schema update, see https://github.com/postfixadmin/postfixadmin/issues/489 - Bug fix quota levels (now user configurable again; thanks @csware, see https://github.com/postfixadmin/postfixadmin/commit/bfc7af5c8efe2a68c47286cc870b56cb4f929a3f ->>>>>>> postfixadmin_3.3 Version 3.3.8 - 2021/03/04 ------------------------------------------------- From f35bceabb82bc9034f9cb1cb2faa816a6621fe72 Mon Sep 17 00:00:00 2001 From: Christophe Gherardi <44464440+AltiUP@users.noreply.github.com> Date: Sat, 15 May 2021 11:17:41 +0200 Subject: [PATCH 10/13] Modification HELO information/parameters Modification of the comments for the HELO configuration, and addition of the HELO parameter in the transport. --- VIRTUAL_VACATION/vacation.pl | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/VIRTUAL_VACATION/vacation.pl b/VIRTUAL_VACATION/vacation.pl index bc2e3983..824aa79d 100644 --- a/VIRTUAL_VACATION/vacation.pl +++ b/VIRTUAL_VACATION/vacation.pl @@ -58,9 +58,12 @@ our $smtp_server = 'localhost'; # port to connect to; defaults to 25 for non-SSL, 465 for 'ssl', 587 for 'starttls' our $smtp_server_port = 25; +# this is the local address from which to connect +our $smtp_client = 'localhost'; + # this is the helo we [the vacation script] use on connection; you may need to change this to your hostname or something, # depending upon what smtp helo restrictions you have in place within Postfix. -our $smtp_client = 'localhost'; +our $smtp_helo = 'localhost.localdomain'; # send mail encrypted or plaintext # if 'starttls', use STARTTLS; if 'ssl' (or 1), connect securely; otherwise, no security @@ -479,6 +482,7 @@ sub send_vacation_email { ssl => $smtp_ssl, timeout => $smtp_timeout, localaddr => $smtp_client, + helo => $smtp_helo, debug => 0, }; From 93f38e659b61c28da7542ee1ec3c87dfd85d5037 Mon Sep 17 00:00:00 2001 From: David Goodwin Date: Sat, 15 May 2021 11:24:32 +0100 Subject: [PATCH 11/13] update changelog --- CHANGELOG.TXT | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.TXT b/CHANGELOG.TXT index 4ae7ef69..53538e81 100644 --- a/CHANGELOG.TXT +++ b/CHANGELOG.TXT @@ -14,9 +14,9 @@ MASTER (should have all changes from 3.3.10 plus) - Code reformat as PHPCS has a mind of it's own (function/method opening brace change of position) - Improved UTF8 support in vacation (see https://github.com/postfixadmin/postfixadmin/pull/484) - Fix quota levels losing config control (see bfc7af5c8efe2a68c47286cc870b56cb4f929a3f) - - Improve vacation.pl's autoreply detection (see https://github.com/postfixadmin/postfixadmin/pull/482 - - Improve vacation.pl's headers in auto-reply mails (add: "Auto-Submitted: auto-replied") see https://github.com/postfixadmin/postfixadmin/pull/483 - + - vacation.pl: improve autoreply detection (see https://github.com/postfixadmin/postfixadmin/pull/482 + - vacation.pl: improve headers in auto-reply mails (add: "Auto-Submitted: auto-replied") see https://github.com/postfixadmin/postfixadmin/pull/483 + - vacation.pl: allow smtp helo to be customised; see https://github.com/postfixadmin/postfixadmin/pull/495 Version 3.3.10 - ??? ------------------------------------------------- From ba17fbe6d64c070e4b39ada633388685815380b4 Mon Sep 17 00:00:00 2001 From: David Goodwin Date: Sat, 15 May 2021 11:40:40 +0100 Subject: [PATCH 12/13] improve setup.php to apply database updates and avoid deadlock with not being able to login - see https://github.com/postfixadmin/postfixadmin/issues/494 --- public/setup.php | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/public/setup.php b/public/setup.php index a538f417..9bd621a3 100644 --- a/public/setup.php +++ b/public/setup.php @@ -334,23 +334,29 @@ EOF;

Database Update

getMessage()); + echo "

Something went wrong while trying to connect to the database. A message should be logged - check PHP's error_log (" . ini_get('error_log') . ')

\n'; + error_log("Couldn't perform PostfixAdmin database update - failed to connect to db? " . $e->getMessage() . " Trace: " . $e->getTraceAsString()); } if ($db) { - print "

Everything seems fine... attempting to create/update database structure

\n"; - require_once(dirname(__FILE__) . '/upgrade.php'); + echo "

Everything seems fine... attempting to create/update database structure

\n"; + try { + require_once(dirname(__FILE__) . '/upgrade.php'); + } + catch(\Exception $e) { + if($authenticated) { + echo "

Exception message: {$e->getMessage()} - check logs!

"; + } + echo "

Something went wrong while trying to apply database updates, a message should be logged - check PHP's error_log (" . ini_get('error_log') . ')

\n'; + error_log("Couldn't perform PostfixAdmin database update via upgrade.php - " . $e->getMessage() . " Trace: " . $e->getTraceAsString()); + } } else { echo "

Could not connect to database to perform updates; check PHP error log.

"; } - } else { - echo "

Please login to see perform database update.

"; - } ?> From 884147e6df6d6b41aaaebff3695dd2846bd6db48 Mon Sep 17 00:00:00 2001 From: David Goodwin Date: Sat, 15 May 2021 11:43:06 +0100 Subject: [PATCH 13/13] composer format time ... i shouldh ave a commit hook for this --- public/setup.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/public/setup.php b/public/setup.php index 9bd621a3..c1e7acb8 100644 --- a/public/setup.php +++ b/public/setup.php @@ -346,9 +346,8 @@ EOF; echo "

Everything seems fine... attempting to create/update database structure

\n"; try { require_once(dirname(__FILE__) . '/upgrade.php'); - } - catch(\Exception $e) { - if($authenticated) { + } catch (\Exception $e) { + if ($authenticated) { echo "

Exception message: {$e->getMessage()} - check logs!

"; } echo "

Something went wrong while trying to apply database updates, a message should be logged - check PHP's error_log (" . ini_get('error_log') . ')

\n';