diff --git a/Dockerfile b/Dockerfile index 5869d93b029e7aaae188a4f434a6f3ea16ffe129..66c93005738e3fabe32dda582e44e110e9b728d5 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 d6910393351dc5177423b2e7aa8e058b9102081e..dccd57f56c3afa22a2b8ee52890cf4587556f62f 100644 --- a/htdocs/create.php +++ b/htdocs/create.php @@ -97,6 +97,32 @@ function checkIfUserExists($mail) } } +function setRecoveryEmail($id, $recoveryEmail) { + global $domain; + + $ch = curl_init(); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT"); + curl_setopt($ch, CURLOPT_HTTPHEADER, array( + 'OCS-APIRequest: true' + )); + $token = getenv("NEXTCLOUD_EMAIL_RECOVERY_APP_SECRET"); + $data = array( + "email" => $recoveryEmail, + "token" => $token + ); + + curl_setopt($ch, CURLOPT_URL, "https://" . $domain . "/apps/email-recovery/api/recovery-email/" . $id); + curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data)); + curl_exec($ch); + $statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); + + curl_close($ch); + + return $statusCode; + +} + function curlCallNextcloud($mail, $key, $value) { global $domain; @@ -156,7 +182,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"); @@ -164,6 +190,11 @@ 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); + if($recoveryEmailStatusCode !== 200) { + $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; } else { @@ -172,7 +203,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;