From a6bcde3ee0b4cc8175dcbc08e2561890d6bf2488 Mon Sep 17 00:00:00 2001
From: Kristian <feldsam@gmail.com>
Date: Thu, 18 Jan 2018 19:14:18 +0100
Subject: [PATCH 1/6] [WEB] Make quarantine action column more wider

---
 data/web/js/quarantaine.js | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/data/web/js/quarantaine.js b/data/web/js/quarantaine.js
index 8c8ee3a0..09a3b2df 100644
--- a/data/web/js/quarantaine.js
+++ b/data/web/js/quarantaine.js
@@ -15,7 +15,7 @@ jQuery(function($){
         {"name":"sender","title":lang.sender,"breakpoints":"xs sm"},
         {"name":"rcpt","title":lang.rcpt, "type": "text"},
         {"name":"created","formatter":function unix_time_format(tm) { var date = new Date(tm ? tm * 1000 : 0); return date.toLocaleString();},"title":lang.received,"style":{"width":"170px"}},
-        {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right"},"style":{"width":"205px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
+        {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right"},"style":{"width":"220px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
       ],
       "rows": $.ajax({
         dataType: 'json',
@@ -81,4 +81,4 @@ jQuery(function($){
   }
   // Initial table drawings
   draw_quarantaine_table();
-});
\ No newline at end of file
+});

From 5c3a2888a00dcf3e7b1da76ea78e47258288de7f Mon Sep 17 00:00:00 2001
From: "andre.peters" <andre.peters@servercow.de>
Date: Thu, 18 Jan 2018 22:12:35 +0100
Subject: [PATCH 2/6] [Web] Fix u2f I previously messed up, sorry

---
 data/web/json_api.php | 25 +++++++++++++++++++------
 1 file changed, 19 insertions(+), 6 deletions(-)

diff --git a/data/web/json_api.php b/data/web/json_api.php
index cb0e5784..856facfc 100644
--- a/data/web/json_api.php
+++ b/data/web/json_api.php
@@ -1453,10 +1453,13 @@ if (isset($_SESSION['mailcow_cc_role']) || isset($_SESSION['pending_mailcow_cc_u
           case "u2f-registration":
             header('Content-Type: application/javascript');
             if (($_SESSION["mailcow_cc_role"] == "admin" || $_SESSION["mailcow_cc_role"] == "domainadmin") && $_SESSION["mailcow_cc_username"] == $object) {
-              $data = $u2f->getRegisterData(get_u2f_registrations($object));
-              list($req, $sigs) = $data;
+              list($req, $sigs) = $u2f->getRegisterData(get_u2f_registrations($object));
               $_SESSION['regReq'] = json_encode($req);
-              echo 'var req = ' . json_encode($req) . '; var sigs = ' . json_encode($sigs) . ';';
+              $_SESSION['regSigs'] = json_encode($sigs);
+              echo 'var req = ' . json_encode($req) . ';';
+              echo 'var registeredKeys = ' . json_encode($sigs) . ';';
+              echo 'var appId = req.appId;';
+              echo 'var registerRequests = [{version: req.version, challenge: req.challenge}];';
             }
             else {
               return;
@@ -1465,9 +1468,19 @@ if (isset($_SESSION['mailcow_cc_role']) || isset($_SESSION['pending_mailcow_cc_u
           case "u2f-authentication":
             header('Content-Type: application/javascript');
             if (isset($_SESSION['pending_mailcow_cc_username']) && $_SESSION['pending_mailcow_cc_username'] == $object) {
-              $reqs = json_encode($u2f->getAuthenticateData(get_u2f_registrations($object)));
-              $_SESSION['authReq']  = $reqs;
-              echo 'var req = ' . $reqs . ';';
+              $auth_data = $u2f->getAuthenticateData(get_u2f_registrations($object));
+              $challenge = $auth_data[0]->challenge;
+              $appId = $auth_data[0]->appId;
+              foreach ($auth_data as $each) {
+                $key = array(); // Empty array
+                $key['version']   = $each->version;
+                $key['keyHandle'] = $each->keyHandle;
+                $registeredKey[]  = $key;
+              }
+              $_SESSION['authReq']  = json_encode($auth_data);
+              echo 'var appId = "' . $appId . '";';
+              echo 'var challenge = ' . json_encode($challenge) . ';';
+              echo 'var registeredKeys = ' . json_encode($registeredKey) . ';';
             }
             else {
               return;

From 838ab6cb6d4d998be8001932ebee656cb956e0c4 Mon Sep 17 00:00:00 2001
From: "andre.peters" <andre.peters@servercow.de>
Date: Thu, 18 Jan 2018 22:17:43 +0100
Subject: [PATCH 3/6] [Helper] Should fix nc script issue #938

---
 helper-scripts/nextcloud.sh | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/helper-scripts/nextcloud.sh b/helper-scripts/nextcloud.sh
index d466cd5a..98f99fe6 100755
--- a/helper-scripts/nextcloud.sh
+++ b/helper-scripts/nextcloud.sh
@@ -16,9 +16,10 @@ done
 
 [[ ${NC_PURGE} == "y" ]] && [[ ${NC_INSTALL} == "y" ]] && { echo "Cannot use -p and -i at the same time"; }
 
-  SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
+SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
+source ${SCRIPT_DIR}/../mailcow.conf
 
-  source ${SCRIPT_DIR}/../mailcow.conf
+if [[ ${NC_PURGE} == "y" ]]; then
 
 	docker exec -it $(docker ps -f name=mysql-mailcow -q) mysql -uroot -p${DBROOT} -e \
 	  "$(docker exec -it $(docker ps -f name=mysql-mailcow -q) mysql -uroot -p${DBROOT} -e "SELECT GROUP_CONCAT('DROP TABLE ', TABLE_SCHEMA, '.', TABLE_NAME SEPARATOR ';') FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME LIKE 'nc_%' AND TABLE_SCHEMA = '${DBNAME}';" -BN)"

From c38fad27e5c65b25ea1bc6ab61e9ac333e04d6d5 Mon Sep 17 00:00:00 2001
From: "andre.peters" <andre.peters@servercow.de>
Date: Fri, 19 Jan 2018 06:48:38 +0100
Subject: [PATCH 4/6] [Helper] Fix config val

---
 helper-scripts/nextcloud.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/helper-scripts/nextcloud.sh b/helper-scripts/nextcloud.sh
index 98f99fe6..1c9df670 100755
--- a/helper-scripts/nextcloud.sh
+++ b/helper-scripts/nextcloud.sh
@@ -95,7 +95,7 @@ elif [[ ${NC_INSTALL} == "y" ]]; then
 
 	if [[ ${NC_TYPE} == "subdomain" ]]; then
 		docker exec -it -u www-data $(docker ps -f name=php-fpm-mailcow -q) /web/nextcloud/occ config:system:set overwritewebroot --value=/
-		docker exec -it -u www-data $(docker ps -f name=php-fpm-mailcow -q) /web/nextcloud/occ config:system:set overwritehost --value=nextcloud.develcow.de
+		docker exec -it -u www-data $(docker ps -f name=php-fpm-mailcow -q) /web/nextcloud/occ config:system:set overwritehost --value=${NC_SUBD}
 		cp ./data/assets/nextcloud/nextcloud.conf ./data/conf/nginx/
 		sed -i 's/NC_SUBD/${NC_SUBD}/g' ./data/conf/nginx/nextcloud.conf
 	elif [[ ${NC_TYPE} == "subfolder" ]]; then

From ea6c6a5e84cb261593b29a3a4d4b1498b6879b2b Mon Sep 17 00:00:00 2001
From: "andre.peters" <andre.peters@servercow.de>
Date: Fri, 19 Jan 2018 11:52:59 +0100
Subject: [PATCH 5/6] [Web] Fixes super annoying password verification bug #867

---
 data/web/inc/functions.inc.php | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/data/web/inc/functions.inc.php b/data/web/inc/functions.inc.php
index 20d82a92..b19792e2 100644
--- a/data/web/inc/functions.inc.php
+++ b/data/web/inc/functions.inc.php
@@ -129,7 +129,9 @@ function generate_tlsa_digest($hostname, $port, $starttls = null) {
 }
 function verify_ssha256($hash, $password) {
 	// Remove tag if any
-	$hash = ltrim($hash, '{SSHA256}');
+  if (substr($hash, 0, strlen('{SSHA256}')) == '{SSHA256}') {
+    $hash = substr($hash, strlen('{SSHA256}'));
+  }
 	// Decode hash
 	$dhash = base64_decode($hash);
 	// Get first 32 bytes of binary which equals a SHA256 hash

From 40c5566d0df27d05ac39e1fc9813090541ad2cd3 Mon Sep 17 00:00:00 2001
From: Phoenix Eve Aspacio <aspaciop@gmail.com>
Date: Sat, 20 Jan 2018 06:51:22 +0800
Subject: [PATCH 6/6] lang consistent

---
 data/web/lang/lang.en.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/data/web/lang/lang.en.php b/data/web/lang/lang.en.php
index ef60bd22..37cf6661 100644
--- a/data/web/lang/lang.en.php
+++ b/data/web/lang/lang.en.php
@@ -565,7 +565,7 @@ $lang['admin']['api_key'] = "API key";
 $lang['admin']['activate_api'] = "Activate API";
 $lang['admin']['regen_api_key'] = "Regenerate API key";
 
-$lang['admin']['quarantine'] = "Quarantine";
+$lang['admin']['quarantine'] = "Quarantaine";
 $lang['admin']['quarantine_retention_size'] = "Retentions per mailbox:";
 $lang['admin']['quarantine_max_size'] = "Maximum size in MiB (larger elements are discarded):";
 $lang['admin']['quarantine_exclude_domains'] = "Exclude domains and alias-domains:";