From fbf8e063780f970002a3a9ce26f8a434225e72c9 Mon Sep 17 00:00:00 2001 From: Akhil Date: Tue, 30 Mar 2021 18:44:20 +0530 Subject: [PATCH 01/10] Added function to set recovery email --- htdocs/create.php | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/htdocs/create.php b/htdocs/create.php index d691039..d81cee1 100644 --- a/htdocs/create.php +++ b/htdocs/create.php @@ -97,6 +97,34 @@ function checkIfUserExists($mail) } } +function setRecoveryEmail($id, $recoveryEmail) { + global $domain; + + global $NC_ADM; + global $NC_ADM_PWD; + $ch = curl_init(); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT"); + curl_setopt($ch, CURLOPT_HTTPHEADER, array( + 'OCS-APIRequest: true' + )); + + $data = array( + "email" => $recoveryEmail + ); + + + curl_setopt($ch, CURLOPT_URL, "https://" . $NC_ADM . ":" . $NC_ADM_PWD . "@" . $domain . "/apps/email-recovery/api/recovery-email/" . $id); + curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data)); + $output = curl_exec($ch); + $statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); + + curl_close($ch); + + return $statusCode; + +} + function curlCallNextcloud($mail, $key, $value) { global $domain; @@ -164,6 +192,8 @@ function createMailAccount($resultmail, $pw, $pw2, $name, $quota, $authmail) if (($detailSetMail->ocs->meta->status == "ok") && ($detailSetQuota->ocs->meta->status == "ok")) { // ALL GOOD, account correctly created + $recoveryEmailStatusCode = setRecoveryEmail($resultmail, $authmail); + /* Add potential code to handle failure here */ $answer->success = true; return $answer; } else { -- GitLab From 02b0a67f035b800ff6143bbbbb252e4fd9978b82 Mon Sep 17 00:00:00 2001 From: Akhil Date: Wed, 31 Mar 2021 06:18:05 +0530 Subject: [PATCH 02/10] Fixed wrong variable usage --- htdocs/create.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/htdocs/create.php b/htdocs/create.php index d81cee1..5f49c80 100644 --- a/htdocs/create.php +++ b/htdocs/create.php @@ -113,7 +113,6 @@ function setRecoveryEmail($id, $recoveryEmail) { "email" => $recoveryEmail ); - curl_setopt($ch, CURLOPT_URL, "https://" . $NC_ADM . ":" . $NC_ADM_PWD . "@" . $domain . "/apps/email-recovery/api/recovery-email/" . $id); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data)); $output = curl_exec($ch); @@ -202,7 +201,7 @@ function createMailAccount($resultmail, $pw, $pw2, $name, $quota, $authmail) $answer->success = false; $answer->type = "error_setting_mail"; return $answer; - } elseif (($detailSetMail->ocs->meta->status != "ok")) { + } elseif (($detailSetQuota->ocs->meta->status != "ok")) { $answer->success = false; $answer->type = "error_setting_quota"; return $answer; -- GitLab From d97c77f1a485d82bf6f3f190d3b390c1fef66fdc Mon Sep 17 00:00:00 2001 From: akhil Date: Thu, 8 Apr 2021 15:36:00 +0530 Subject: [PATCH 03/10] Added token to call to update recovery email --- htdocs/create.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/htdocs/create.php b/htdocs/create.php index 5f49c80..fa21456 100644 --- a/htdocs/create.php +++ b/htdocs/create.php @@ -108,14 +108,15 @@ function setRecoveryEmail($id, $recoveryEmail) { curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'OCS-APIRequest: true' )); - + $token = getenv("NEXTCLOUD_EMAIL_RECOVERY_APP_SECRET"); $data = array( - "email" => $recoveryEmail + "email" => $recoveryEmail, + "token" => $token ); - curl_setopt($ch, CURLOPT_URL, "https://" . $NC_ADM . ":" . $NC_ADM_PWD . "@" . $domain . "/apps/email-recovery/api/recovery-email/" . $id); + curl_setopt($ch, CURLOPT_URL, "https://" . $domain . "/apps/email-recovery/api/recovery-email/" . $id); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data)); - $output = curl_exec($ch); + curl_exec($ch); $statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); -- GitLab From ace849cb2e89208d87fad11d5a40cdfa96927235 Mon Sep 17 00:00:00 2001 From: akhil Date: Thu, 8 Apr 2021 17:24:48 +0530 Subject: [PATCH 04/10] Sets email to resultmail instead of authmail --- htdocs/create.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/create.php b/htdocs/create.php index fa21456..d547551 100644 --- a/htdocs/create.php +++ b/htdocs/create.php @@ -184,7 +184,7 @@ function createMailAccount($resultmail, $pw, $pw2, $name, $quota, $authmail) // 2 - the account was created, set some settings //set user's Email setting on NC - $resultSetMail = curlCallNextcloud($resultmail, "email", $authmail); + $resultSetMail = curlCallNextcloud($resultmail, "email", $resultmail); $detailSetMail = json_decode($resultSetMail); //set user's Quota setting on NC $resultSetQuota = curlCallNextcloud($resultmail, "quota", $quota . " MB"); -- GitLab From c7013756ea63347cec5067f93223fc28f279132d Mon Sep 17 00:00:00 2001 From: akhil Date: Fri, 9 Apr 2021 09:53:14 +0530 Subject: [PATCH 05/10] Added log in case recovery email not set correctly --- htdocs/create.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/htdocs/create.php b/htdocs/create.php index d547551..0883d84 100644 --- a/htdocs/create.php +++ b/htdocs/create.php @@ -193,7 +193,10 @@ function createMailAccount($resultmail, $pw, $pw2, $name, $quota, $authmail) if (($detailSetMail->ocs->meta->status == "ok") && ($detailSetQuota->ocs->meta->status == "ok")) { // ALL GOOD, account correctly created $recoveryEmailStatusCode = setRecoveryEmail($resultmail, $authmail); - /* Add potential code to handle failure here */ + if($recoveryEmailStatusCode !== 200) { + $message = 'Setting recovery email of user' . $resultmail . 'failed with status code: ' . $recoveryEmailStatusCode. '\n' ; + error_log($message, 3, '/var/log/errors.log'); + } $answer->success = true; return $answer; } else { -- GitLab From d763eed03aabaacaef5545e2675115c42a0da751 Mon Sep 17 00:00:00 2001 From: akhil Date: Fri, 9 Apr 2021 10:07:39 +0530 Subject: [PATCH 06/10] Removed unnecessary declarations --- htdocs/create.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/htdocs/create.php b/htdocs/create.php index 0883d84..22e6242 100644 --- a/htdocs/create.php +++ b/htdocs/create.php @@ -99,9 +99,7 @@ function checkIfUserExists($mail) function setRecoveryEmail($id, $recoveryEmail) { global $domain; - - global $NC_ADM; - global $NC_ADM_PWD; + $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT"); -- GitLab From 8bc6e647943c221bd8b617bd4753d4c7ddb522c9 Mon Sep 17 00:00:00 2001 From: akhil Date: Fri, 9 Apr 2021 10:09:53 +0530 Subject: [PATCH 07/10] Removed singlequoted \n --- htdocs/create.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/create.php b/htdocs/create.php index 22e6242..6e68cbc 100644 --- a/htdocs/create.php +++ b/htdocs/create.php @@ -99,7 +99,7 @@ function checkIfUserExists($mail) function setRecoveryEmail($id, $recoveryEmail) { global $domain; - + $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT"); @@ -192,7 +192,7 @@ function createMailAccount($resultmail, $pw, $pw2, $name, $quota, $authmail) // ALL GOOD, account correctly created $recoveryEmailStatusCode = setRecoveryEmail($resultmail, $authmail); if($recoveryEmailStatusCode !== 200) { - $message = 'Setting recovery email of user' . $resultmail . 'failed with status code: ' . $recoveryEmailStatusCode. '\n' ; + $message = 'Setting recovery email of user' . $resultmail . 'failed with status code: ' . $recoveryEmailStatusCode . PHP_EOL ; error_log($message, 3, '/var/log/errors.log'); } $answer->success = true; -- GitLab From 988efffbd22e9bf96fdae42d464f51048aac7fd1 Mon Sep 17 00:00:00 2001 From: akhil Date: Fri, 9 Apr 2021 10:13:43 +0530 Subject: [PATCH 08/10] Added recovery email also to log(easier to set it for admin in case of failure) --- htdocs/create.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/create.php b/htdocs/create.php index 6e68cbc..b5391dd 100644 --- a/htdocs/create.php +++ b/htdocs/create.php @@ -192,7 +192,7 @@ function createMailAccount($resultmail, $pw, $pw2, $name, $quota, $authmail) // ALL GOOD, account correctly created $recoveryEmailStatusCode = setRecoveryEmail($resultmail, $authmail); if($recoveryEmailStatusCode !== 200) { - $message = 'Setting recovery email of user' . $resultmail . 'failed with status code: ' . $recoveryEmailStatusCode . PHP_EOL ; + $message = 'Setting recovery email of user' . $resultmail . 'failed with status code: ' . $recoveryEmailStatusCode . '(recovery email: ' . $authmail . ')' . PHP_EOL ; error_log($message, 3, '/var/log/errors.log'); } $answer->success = true; -- GitLab From cf19d40bd4798808ff82e7c0d1acb90625526a51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arnau=20V=C3=A0zquez?= Date: Fri, 9 Apr 2021 07:46:06 +0000 Subject: [PATCH 09/10] Apply 1 suggestion(s) to 1 file(s) --- htdocs/create.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/create.php b/htdocs/create.php index b5391dd..f8193c7 100644 --- a/htdocs/create.php +++ b/htdocs/create.php @@ -192,7 +192,7 @@ function createMailAccount($resultmail, $pw, $pw2, $name, $quota, $authmail) // ALL GOOD, account correctly created $recoveryEmailStatusCode = setRecoveryEmail($resultmail, $authmail); if($recoveryEmailStatusCode !== 200) { - $message = 'Setting recovery email of user' . $resultmail . 'failed with status code: ' . $recoveryEmailStatusCode . '(recovery email: ' . $authmail . ')' . PHP_EOL ; + $message = 'Setting recovery email of user ' . $resultmail . ' failed with status code: ' . $recoveryEmailStatusCode . ' (recovery email: ' . $authmail . ')' . PHP_EOL ; error_log($message, 3, '/var/log/errors.log'); } $answer->success = true; -- GitLab From de66f72d043c7e15166edf4f0a0eb78e3b0b38ad Mon Sep 17 00:00:00 2001 From: akhil Date: Fri, 9 Apr 2021 18:48:10 +0530 Subject: [PATCH 10/10] added line in Dockerfile to change log location --- Dockerfile | 1 + htdocs/create.php | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 5869d93..66c9300 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,6 +12,7 @@ COPY --chown=www-data:www-data --from=build /tmp/build/ /var/www/html/ COPY htdocs/.htaccess /var/www/html/.htaccess # Use the default production configuration RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini" +RUN echo 'error_log = /var/log/errors.log' >> "$PHP_INI_DIR/php.ini" RUN chmod u+x /var/www/html/welcome_mails/generate-signup-link.sh # copy composer executable from official Docker image diff --git a/htdocs/create.php b/htdocs/create.php index b5391dd..dccd57f 100644 --- a/htdocs/create.php +++ b/htdocs/create.php @@ -192,8 +192,8 @@ function createMailAccount($resultmail, $pw, $pw2, $name, $quota, $authmail) // ALL GOOD, account correctly created $recoveryEmailStatusCode = setRecoveryEmail($resultmail, $authmail); if($recoveryEmailStatusCode !== 200) { - $message = 'Setting recovery email of user' . $resultmail . 'failed with status code: ' . $recoveryEmailStatusCode . '(recovery email: ' . $authmail . ')' . PHP_EOL ; - error_log($message, 3, '/var/log/errors.log'); + $message = 'Setting recovery email of user ' . $resultmail . ' failed with status code: ' . $recoveryEmailStatusCode . '(recovery email: ' . $authmail . ')' . PHP_EOL ; + error_log($message, 0); } $answer->success = true; return $answer; -- GitLab