diff --git a/.gitignore b/.gitignore index 09646c6c5846ec4e285dae34616fde58bc18eea2..a6c676ba32452d5c7a80affe855c208129e905c4 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ htdocs/.jekyll-metadata htdocs/vendor htdocs/.env htdocs/.php_cs.cache +.php_cs.cache diff --git a/htdocs/_i18n/en.yml b/htdocs/_i18n/en.yml index a87ce0c5f2fe3a5c1c562f8263cf815c36a5e85e..2ed38ae332cf1b57953430297fc7fe158feac594 100644 --- a/htdocs/_i18n/en.yml +++ b/htdocs/_i18n/en.yml @@ -86,4 +86,4 @@ what_next_paragraph: 'If your email address is valid, you will receive an invita domain: '@@@domain@@@' invalid_registration_message: Invalid registration link! Please check if this is the same link as sent to your E-mail! -server_not_responding: Server not responding right now! Please try again later! +server_not_responding: Server not responding right now! Please try again later! \ No newline at end of file diff --git a/htdocs/captcha_check.php b/htdocs/captcha_check.php index 2ff71907114508c160ec38c5def44c521e99b789..dd0bbdb2853a39261fc52f8a7b54f73d57120238 100644 --- a/htdocs/captcha_check.php +++ b/htdocs/captcha_check.php @@ -1,18 +1,18 @@ \ No newline at end of file diff --git a/htdocs/captcha_img.php b/htdocs/captcha_img.php index dab7720c52057358b932af992fed80d540edb093..0fff3b44f282f5aa61d053c3b329da6d8dd535c7 100644 --- a/htdocs/captcha_img.php +++ b/htdocs/captcha_img.php @@ -23,11 +23,11 @@ for ($i=0; $i<10; $i++) { mt_rand(0, $width), mt_rand(0, $height), imagecolorallocate( - $image, - mt_rand(200, 255), - mt_rand(200, 255), - mt_rand(200, 255) - ) + $image, + mt_rand(200, 255), + mt_rand(200, 255), + mt_rand(200, 255) + ) ); } diff --git a/htdocs/create.php b/htdocs/create.php index 0317757863ddebf3d692093f8f5f1bf6c60efe8b..d6910393351dc5177423b2e7aa8e058b9102081e 100644 --- a/htdocs/create.php +++ b/htdocs/create.php @@ -2,8 +2,9 @@ //ini_set('display_errors', 1); //ini_set('display_startup_errors', 1); //error_reporting(E_ALL); -require '/var/www/html/vendor/autoload.php'; -require_once('./language.php'); +require 'vendor/autoload.php'; +require_once('language.php'); +require_once('helpers.php'); use phpseclib3\Net\SSH2; @@ -11,27 +12,15 @@ $NC_ADM = getenv("NEXTCLOUD_ADMIN_USER"); $NC_ADM_PWD = getenv("NEXTCLOUD_ADMIN_PASSWORD"); $domain = getenv("DOMAIN"); $mail_domain = getenv("MAIL_DOMAIN"); -if (empty($mail_domain)) $mail_domain = $domain; +if (empty($mail_domain)) { + $mail_domain = $domain; +} function respond_with_message($response_code, $message) { http_response_code($response_code); - echo(json_encode($message)); - return; -} - -function get_message($type, $message) -{ - $object_message = new \stdClass(); - $object_message->type = $type; - $object_message->message = $message; - return $object_message; + respond_with_json($message); } -function startsWith($haystack, $needle) -{ - $length = strlen($needle); - return (substr($haystack, 0, $length) === $needle); -} function sendWelcomeMsg($authmail, $mbox, $domain) { @@ -72,51 +61,48 @@ function sendWelcomeMsg($authmail, $mbox, $domain) $mail = $smtp->send($to, $mime->headers($headers), $body); } -function authUsed($authstr) +function checkIfUserExists($mail) { - clearstatcache(); - if (file_exists("/var/accounts/auth.file.done")) { - $handle = fopen("/var/accounts/auth.file.done", "r"); - while (($line = fgets($handle)) !== false) { - if (startsWith($line, $authstr)) { - $account = explode(":", $line); - return trim($account[2]); - } - } - fclose($handle); - return "okay"; - } else { - return "okay"; - } -} + global $domain; + global $NC_ADM; + global $NC_ADM_PWD; + global $strings; + $ch = curl_init(); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET"); + curl_setopt($ch, CURLOPT_HTTPHEADER, array( + 'OCS-APIRequest: true' + )); -function isAuthorized($mail, $secret) -{ - $handle = fopen("/var/accounts/auth.file", "r"); - if ($handle) { - while (($line = fgets($handle)) !== false) { - if (strcmp(trim($line), "$mail:$secret") == 0) { - $account = authUsed(trim($line)); - if (strcmp($account, "okay") == 0) { - return true; - } else { - return false; - } - } - } - fclose($handle); + $data = array( + "format" => "json" + ); + curl_setopt($ch, CURLOPT_URL, "https://" . $NC_ADM . ":" . $NC_ADM_PWD . "@" . $domain . "/ocs/v1.php/cloud/users/" . $mail . "?format=json"); + $output = curl_exec($ch); + $statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); + + curl_close($ch); + + $output = json_decode($output); + + if($statusCode !== 200) { + $error_string = $strings["error_server_side"]; + respond_with_message(500, get_message("general", $error_string)); } else { - return false; + if ($output->ocs->meta->statuscode === 404) { + return false; + } else { + return true; + } } - return false; } function curlCallNextcloud($mail, $key, $value) { global $domain; - $NC_ADM = getenv("NEXTCLOUD_ADMIN_USER"); - $NC_ADM_PWD = getenv("NEXTCLOUD_ADMIN_PASSWORD"); + global $NC_ADM; + global $NC_ADM_PWD; $ch = curl_init(); @@ -152,7 +138,6 @@ function createMailAccount($resultmail, $pw, $pw2, $name, $quota, $authmail) if (!$ssh->login($PF_USER, $PF_PWD)) { $error_string = $strings["error_server_side"]; respond_with_message(500, get_message("general", $error_string)); - exit('Login Failed'); } @@ -200,14 +185,11 @@ function createMailAccount($resultmail, $pw, $pw2, $name, $quota, $authmail) if (!isset($_POST['username']) || !isset($_POST['password']) || !isset($_POST['displayname']) || !isset($_POST['repassword'])) { $error_string = $strings["error_mandatory_missing"]; respond_with_message(400, get_message("general", $error_string)); - - exit; } if (!isset($_POST['authmail']) || !isset($_POST['authsecret'])) { $error_string = $strings["error_unauthorized"]; respond_with_message(400, get_message("general", $error_string)); - exit; } $mbox = mb_strtolower($_POST['username'], 'UTF-8'); @@ -224,33 +206,40 @@ $resultmail = $mbox . "@" . $mail_domain; if (strlen($mbox) > 30 || strlen($name) > 30 || strlen($pw) > 1024 || strlen($pw2) > 1024 || strlen($authmail) > 1024 || strlen($authsecret) > 1024) { $error_string = $strings["error_input_too_large"]; respond_with_message(400, get_message("general", $error_string)); - exit; } if (!preg_match("/^(?=.{3,30}$)(?![_.-])(?!.*[_.-]{2})[a-zA-Z0-9._-]+(?success) { + if (!empty($auth->account)) { + $error_string = $strings["error_account_done"]; + $error_string = str_replace("@@@username@@@", $auth->account, $error_string); + respond_with_message(400, get_message("general", $error_string)); + } else { + $error_string = $strings["error_unauthorized"]; + respond_with_message(400, get_message("general", $error_string)); + } } +if (checkIfUserExists($resultmail)) { + $error_string = $strings["error_account_taken"]; + $error_string = str_replace("@@@username@@@", $mbox, $error_string); + respond_with_message(400, get_message("general", $error_string)); +} if (strcmp($pw, $pw2)) { $error_string = $strings["error_pw_mismatch"]; respond_with_message(400, get_message("password_match", $error_string)); - exit; } @@ -263,14 +252,12 @@ if ($answer->success) { if ($myfile === false) { $error_string = $strings["error_persisting"]; respond_with_message(500, get_message("general", $error_string)); - exit; } $success_string = $strings["success_message1"] . $strings["success_message2"] . $strings["success_message3"] . $strings["success_message4"] . $strings["success_message5"]; $success_string = str_replace("@@@mail_domain@@@", $mail_domain, $success_string); $success_string = str_replace("@@@domain@@@", $domain, $success_string); $success_string = str_replace("@@@username@@@", $mbox, $success_string); respond_with_message(200, get_message("success", $success_string)); - exit; } else { respond_with_message(400, get_message("general", $strings[$answer->type])); } diff --git a/htdocs/helpers.php b/htdocs/helpers.php new file mode 100644 index 0000000000000000000000000000000000000000..26739f67ebbc5af55dc52903aae4a8fccd02257e --- /dev/null +++ b/htdocs/helpers.php @@ -0,0 +1,156 @@ +type = $type; + $object_message->message = $message; + return $object_message; +} +function get_easy_installer_message($code) +{ + $ret = array( + 'errcode' => $code + ); + return $ret; +} + +function validateWithBlackList($email) +{ + $domain = substr($email, strrpos($email, '@') + 1, strlen($email)); + $blacklisted = array(); + if (file_exists("/var/accounts/blacklist")) { + $content = file_get_contents("/var/accounts/blacklist"); + $blacklisted = explode("\n", $content); + } + return !(in_array($domain, $blacklisted)); +} + +function sendInviteMail($to, $secret, $lang) +{ + $encoded_email = urlencode($to); + $domain = getenv("DOMAIN"); + if ($lang != "en") { + $signup_url = "https://welcome.$domain/$lang/register?authmail=$encoded_email&authsecret=$secret"; + } else { + $signup_url = "https://welcome.$domain/register?authmail=$encoded_email&authsecret=$secret"; + } + $template = null; + $from = getenv("SMTP_FROM"); + if (file_exists("/var/www/html/invite_template/$lang.json")) { + $content = file_get_contents("/var/www/html/invite_template/$lang.json"); + $template = json_decode($content); + } else { + $content = file_get_contents("/var/www/html/invite_template/en.json"); + $template = json_decode($content); + } + $subject = $template->subject; + $headers = ['From' => $from, 'To' => $to, 'Subject' => $subject, + 'Content-Type' => 'text/html; charset=UTF-8', 'Date' => date('D, d M Y H:i:s O')]; + + // include text and HTML versions + $text = $template->text; + $html = $template->html; + + $text = str_replace("@@@TARGETURL@@@", $signup_url, $text); + $html = str_replace("@@@TARGETURL@@@", $signup_url, $html); + + + $mime = new Mail_mime( + array( + "head_charset" => "utf-8", + "text_charset" => "utf-8", + "html_charset" => "utf-8", + "eol" => "\n" + ) + ); + $mime->setTXTBody($text); + $mime->setHTMLBody($html); + + $body = $mime->get(); + $headers = $mime->headers($headers); + + $host = getenv("SMTP_HOST"); + $username = getenv("SMTP_FROM"); + $password = getenv("SMTP_PW"); + $port = getenv("SMTP_PORT"); + + + $smtp = Mail::factory('smtp', [ + 'host' => $host, + 'auth' => true, + 'username' => $username, + 'password' => $password, + 'port' => $port + ]); + + $mail = $smtp->send($to, $headers, $body); + + if (PEAR::isError($mail)) { + return false; + } else { + return true; + } +} + +function respond_with_json($response) +{ + header('Content-type: application/json'); + exit(json_encode($response)); +} + +function check_if_lang_exists($lang) +{ + $available_langs = array("en", "de", "fr", "it", "es"); + return in_array($lang, $available_langs); +} + +function startsWith($haystack = "", $needle) +{ + $length = strlen($needle); + return $length > 0 ? (substr($haystack, 0, $length) === $needle) : 0; +} + +function authUsed($authstr) +{ + clearstatcache(); + if (file_exists("/var/accounts/auth.file.done")) { + $handle = fopen("/var/accounts/auth.file.done", "r"); + while (($line = fgets($handle)) !== false) { + if (startsWith($line, $authstr)) { + $account = explode(":", $line); + return trim($account[2]); + } + } + fclose($handle); + return; + } else { + return; + } +} + +function isAuthorized($mail, $secret) +{ + $handle = fopen("/var/accounts/auth.file", "r"); + $res = new \stdClass(); + if ($handle) { + while (($line = fgets($handle)) !== false) { + if (strcmp(trim($line), "$mail:$secret") == 0) { + $account = authUsed(trim($line)); + if (empty($account)) { + $res->success = true; + return $res; + } else { + $res->account = $account; + $res->success = false; + return $res; + } + } + } + fclose($handle); + } else { + $res->success = false; + return $res; + } + $res->success = false; + return $res; +} diff --git a/htdocs/i18n.php b/htdocs/i18n.php index 5ca616275756c6f17ddaf743ca9b7f170b3b4a1f..3e9d4f1d52cb22e988fce323d8c7e2ca8c472eee 100644 --- a/htdocs/i18n.php +++ b/htdocs/i18n.php @@ -14,7 +14,10 @@ $parsed = yaml_parse_file("./_i18n/$lang.yml"); $domain = getenv("DOMAIN"); $mail_domain = getenv("MAIL_DOMAIN"); $parsed["domain"] = $domain; -if(!empty($mail_domain)) $parsed["mail_domain"] = $mail_domain; -else $parsed["mail_domain"] = $domain; +if (!empty($mail_domain)) { + $parsed["mail_domain"] = $mail_domain; +} else { + $parsed["mail_domain"] = $domain; +} header("Content-Type: application/json"); echo json_encode($parsed); diff --git a/htdocs/index.php b/htdocs/index.php index f11a205a07ad0f7ec4d40432ffc32610748fb3a6..7408035c49a4aa22d9c6341259ff210d027b49cb 100644 --- a/htdocs/index.php +++ b/htdocs/index.php @@ -2,11 +2,10 @@ $domain = getenv("DOMAIN"); $qs = $_SERVER['QUERY_STRING']; -if(strpos($qs, "authmail") !== false && strpos($qs, "authsecret") !== false) { - header("Location: https://welcome.$domain/register?" . $qs); - die(); +if (strpos($qs, "authmail") !== false && strpos($qs, "authsecret") !== false) { + header("Location: https://welcome.$domain/register?" . $qs); + die(); +} else { + header("Location: https://welcome.$domain/e-email-invite"); + die(); } -else { - header("Location: https://welcome.$domain/e-email-invite"); - die(); -} \ No newline at end of file diff --git a/htdocs/language.php b/htdocs/language.php index c50667aebc2a1e9b262d0403d814466736aa4084..45f382278ddd925dcf9b90e1fb2bbb201140ef02 100644 --- a/htdocs/language.php +++ b/htdocs/language.php @@ -1,14 +1,14 @@ $line) { - if (preg_match($regex, $line) == 1) unset($lines[$key]); + if (preg_match($regex, $line) == 1) { + unset($lines[$key]); + } } $lines[] = ""; $data = implode(PHP_EOL, $lines); @@ -81,8 +83,9 @@ function purgeAccountFiles() // return MAIL_USED_FOR_REGISTRATION return $mail; - } else return null; //NO line was found for this user - + } else { + return null; + } //NO line was found for this user } /** @@ -93,7 +96,6 @@ function purgeAccountFiles() */ function deleteMailAccount() { - $PF_HOSTNAME = "postfixadmin"; $PF_USER = "pfexec"; $PF_PWD = getenv("POSTFIXADMIN_SSH_PASSWORD"); @@ -122,9 +124,12 @@ function deleteMailAccount() if (($delDbConfirm == "Error: The EMAIL is not valid!") && ($delDirConfirm == "DELETED")) { return true; - } else return false; // one of the deletion did not go well! - } else return null; // $domain OR $userOnly empty, do nothing!! - + } else { + return false; + } // one of the deletion did not go well! + } else { + return null; + } // $domain OR $userOnly empty, do nothing!! } if (sha1($_POST['sec']) !== getenv("WELCOME_SECRET_SHA")) { @@ -147,9 +152,8 @@ if (sha1($_POST['sec']) !== getenv("WELCOME_SECRET_SHA")) { * - handle onlyoffice part * */ - } // STEP 2 : Purge system files AUTH_FILE & AUTH_FILE_DONE $registrationMail = purgeAccountFiles(); return ($registrationMail !== null); -} \ No newline at end of file +} diff --git a/htdocs/process_email_invite.php b/htdocs/process_email_invite.php index 28ee613caff82e1fa1cf47d5ccc6dc0a09ebe42e..853fc33d45a76aabb67faa1c3a003feb59feeec1 100644 --- a/htdocs/process_email_invite.php +++ b/htdocs/process_email_invite.php @@ -1,14 +1,31 @@ key"; } - header("Location: $redirect_url"); - exit; + exit(header("Location: $redirect_url")); } else { http_response_code($code); - header('Content-Type: application/json'); - $result = new \stdClass(); - $result->type = $message->type; - $message = $strings[$message->key]; - if(!empty($subs)) { - foreach($subs as $key => $sub) { - $message = str_replace($key, $sub, $message); + $result_message = $strings[$message->key]; + if (!empty($subs)) { + foreach ($subs as $key => $sub) { + $result_message = str_replace($key, $sub, $message); } } - $result->message = $message; - echo(json_encode($result)); - exit(); + $result = get_message($message->type, $result_message); + respond_with_json($result); } } -function validateWithBlackList($email) +function email_check($email1, $email2, $from_easy_installer) { - $domain = substr($email, strrpos($email, '@') + 1, strlen($email)); - $blacklisted = array(); - if (file_exists("/var/accounts/blacklist")) { - $content = file_get_contents("/var/accounts/blacklist"); - $blacklisted = explode("\n", $content); + $result = new \stdClass(); + if (($email1 != $email2) || !strstr($email1, '@') || !strstr($email1, '.')) { + if ($from_easy_installer) { + $ret = get_easy_installer_message(300); + respond_with_json($ret); + } + unset($_SESSION['securecode']); + $result->type = "general"; + $result->key = "error_email_not_identical"; + respond_with_message(400, $result, false, $email1); + } + if (!validateWithBlackList($email1)) { + if ($from_easy_installer) { + $ret = get_easy_installer_message(300); + respond_with_json($ret); + } + $result->type = "general"; + $result->key = "error_blacklisted_domain"; + $domain_name = substr(strrchr($email1, "@"), 1); + $subs = array("@@@email_suffix@@@" => $domain_name); + respond_with_message(400, $result, false, $email1, $subs); } - return !(in_array($domain, $blacklisted)); } -function sendInviteMail($to, $secret, $lang) + +function captcha_check($email, $from_easy_installer) { - $encoded_email = urlencode($to); - global $domain; - if ($lang != "en") { - $signup_url = "https://welcome.$domain/$lang/register?authmail=$encoded_email&authsecret=$secret"; - } else { - $signup_url = "https://welcome.$domain/register?authmail=$encoded_email&authsecret=$secret"; - } - $template = null; - $from = getenv("SMTP_FROM"); - if (file_exists("./invite_template/$lang.json")) { - $content = file_get_contents("./invite_template/$lang.json"); - $template = json_decode($content); - } else { - $content = file_get_contents("./invite_template/en.json"); - $template = json_decode($content); - } - $subject = $template->subject; - $headers = ['From' => $from, 'To' => $to, 'Subject' => $subject, - 'Content-Type' => 'text/html; charset=UTF-8']; - - // include text and HTML versions - $text = $template->text; - $html = $template->html; - - $text = str_replace("@@@TARGETURL@@@", $signup_url, $text); - $html = str_replace("@@@TARGETURL@@@", $signup_url, $html); - - - $mime = new Mail_mime( - array( - "head_charset" => "utf-8", - "text_charset" => "utf-8", - "html_charset" => "utf-8", - "eol" => "\n" - ) - ); - $mime->setTXTBody($text); - $mime->setHTMLBody($html); - - $body = $mime->get(); - $headers = $mime->headers($headers); - - $host = getenv("SMTP_HOST"); - $username = getenv("SMTP_FROM"); - $password = getenv("SMTP_PW"); - $port = getenv("SMTP_PORT"); - - - $smtp = Mail::factory('smtp', [ - 'host' => $host, - 'auth' => true, - 'username' => $username, - 'password' => $password, - 'port' => $port - ]); - - $mail = $smtp->send($to, $headers, $body); - - if (PEAR::isError($mail)) { - return false; + if ($from_easy_installer) { + global $ei_secret; + $to_check = htmlspecialchars($_POST["check"]); + $check = md5($email. $ei_secret); + if ($to_check !== $check) { + $ret = get_easy_installer_message(500); + respond_with_json($ret); + } } else { - return true; + $result = new \stdClass(); + $secure = isset($_POST['secure']) ? strtolower($_POST['secure']) : ''; + if ($secure !== $_SESSION['securecode']) { + unset($_SESSION['securecode']); + $result->type = "secure_code"; + $result->key = "error_secure_code"; + respond_with_message(400, $result, false, $email1); + } } } session_set_cookie_params(['SameSite' => 'None', 'Secure' => true]); session_start(); header("Access-Control-Allow-Origin: *"); -$email1 = strtolower(htmlspecialchars($_POST["mail1"])); -$email2 = strtolower(htmlspecialchars($_POST["mail2"])); -$result = new \stdClass(); - -if (($email1 != $email2) || !strstr($email1, '@') || !strstr($email1, '.')) { - unset($_SESSION['securecode']); - $result->type = "general"; - $result->key = "error_email_not_identical"; - respond_with_message(400, $result, false, $email1); -} else { - $secure = isset($_POST['secure']) ? strtolower($_POST['secure']) : ''; - - if ($secure != $_SESSION['securecode']) { - unset($_SESSION['securecode']); - $result->type = "secure_code"; - $result->key = "error_secure_code"; - respond_with_message(400, $result, false, $email1); - } - unset($_SESSION['securecode']); - if (!validateWithBlackList($email1)) { - $result->type = "general"; - $result->key = "error_blacklisted_domain"; - $domain_name = substr(strrchr($email1, "@"), 1); - $subs = array("@@@email_suffix@@@" => $domain_name); - respond_with_message(400, $result, false, $email1, $subs); - exit(); +$email1 = ""; +$email2 = ""; + +if ($from_easy_installer) { + $email1 = strtolower(htmlspecialchars($_POST["email"])); + $email2 = $email1; + if (!isset($_POST["email"])) { + $ret = get_easy_installer_message(400); + respond_with_json($ret); } +} +else { + $email1 = strtolower(htmlspecialchars($_POST["mail1"])); + $email2 = strtolower(htmlspecialchars($_POST["mail2"])); +} - $AUTH_FILE = "/var/accounts/auth.file"; - $AUTH_FILE_DONE = "/var/accounts/auth.file.done"; +captcha_check($email1, $from_easy_installer); +email_check($email1, $email2, $from_easy_installer); - $pending = file_get_contents($AUTH_FILE); - $processed = file_get_contents($AUTH_FILE_DONE); +unset($_SESSION['securecode']); + +$AUTH_FILE = "/var/accounts/auth.file"; +$AUTH_FILE_DONE = "/var/accounts/auth.file.done"; - $found_in_pending = false; - $found_in_processed = false; +$pending = file_get_contents($AUTH_FILE); +$processed = file_get_contents($AUTH_FILE_DONE); - $separator = "\n"; - $creds_in_processed = array(); - $line = strtok($pending, $separator); +$found_in_pending = false; +$found_in_processed = false; - while ($line !== false && $found_in_pending === false) { - $occurences = explode(':', $line); - if ($occurences[0] === $email1) { - $found_in_pending = true; - $creds_in_processed = $occurences; - } - $line = strtok($separator); - } +$separator = "\n"; +$creds_in_processed = array(); +$line = strtok($pending, $separator); - $line = strtok($processed, $separator); +while ($line !== false && $found_in_pending === false) { + $occurences = explode(':', $line); + if ($occurences[0] === $email1) { + $found_in_pending = true; + $creds_in_processed = $occurences; + } + $line = strtok($separator); +} - while ($line !== false && $found_in_processed === false) { - $occurences = explode(':', $line); - if ($occurences[1] && ($occurences[1] === $email1)) { - $found_in_processed = true; - } +$line = strtok($processed, $separator); - $line = strtok($separator); +while ($line !== false && $found_in_processed === false) { + $occurences = explode(':', $line); + if ($occurences[1] && ($occurences[1] === $email1)) { + $found_in_processed = true; } - if ($found_in_processed !== false) { - $result->type = "general"; - $result->key = "error_already_registered"; - respond_with_message(400, $result, false, $email1); - exit(); + $line = strtok($separator); +} +$result = new \stdClass(); +if ($found_in_processed !== false) { + $result->type = "general"; + $result->key = "error_already_registered"; + if ($from_easy_installer) { + $ret = get_easy_installer_message(200); + respond_with_json($ret); + } + respond_with_message(400, $result, false, $email1); +} else { + $unique_key = ""; + $email = ""; + if ($found_in_pending !== false) { + $email = $creds_in_processed[0]; + $unique_key = $creds_in_processed[1]; } else { - $unique_key = ""; - $email = ""; - if ($found_in_pending !== false) { - $email = $creds_in_processed[0]; - $unique_key = $creds_in_processed[1]; - } else { - $unique_key = uniqid(); - $to_append = "$email1:$unique_key\n"; + $unique_key = uniqid(); + $to_append = "$email1:$unique_key\n"; + } + $sent = sendInviteMail($email1, $unique_key, $lang); + if ($sent) { + if (!$found_in_pending) { + $auth_file_in_append_mode = fopen("/var/accounts/auth.file", "a"); + fwrite($auth_file_in_append_mode, $to_append); + fclose($auth_file_in_append_mode); } - $sent = sendInviteMail($email1, $unique_key, $lang); - if ($sent) { - if (!$found_in_pending) { - $auth_file_in_append_mode = fopen("/var/accounts/auth.file", "a"); - fwrite($auth_file_in_append_mode, $to_append); - fclose($auth_file_in_append_mode); - } - $result->type = "success"; - $result->key = 'success_registration_link'; - respond_with_message(200, $result, true, $email1); - } else { - $result->type = "general"; - $result->key = "error_internal_registration"; - respond_with_message(400, $result, false, $email1); + if ($from_easy_installer) { + $ret = get_easy_installer_message(100); + respond_with_json($ret); + } + $result->type = "success"; + $result->key = 'success_registration_link'; + respond_with_message(200, $result, true, $email1); + } else { + if ($from_easy_installer) { + $ret = get_easy_installer_message(500); + respond_with_json($ret); } + $result->type = "general"; + $result->key = "error_internal_registration"; + respond_with_message(400, $result, false, $email1); } -} +} \ No newline at end of file diff --git a/htdocs/welcome_mails/sendmail.php b/htdocs/welcome_mails/sendmail.php index 670b485a278f54b4286b23be0ee5dc66c08de5da..15e0f16fc87dc4a922b6b1909b270dc046593a8c 100644 --- a/htdocs/welcome_mails/sendmail.php +++ b/htdocs/welcome_mails/sendmail.php @@ -1,72 +1,27 @@ subject; - $headers = [ - 'From' => $from, - 'To' => $to, - 'Subject' => $subject, - "Content-Type" => "Content-Type: text/html; charset=UTF-8" - ]; - - // include text and HTML versions - $text = $decoded->text; - $html = $decoded->html; - - $text = str_replace("@@@TARGETURL@@@", $signup_url, $text); - $html = str_replace("@@@TARGETURL@@@", $signup_url, $html); - - - $mime = new Mail_mime(array("text_charset" => "utf-8", - "head_charset" => "utf-8", - "html_charset" => "utf-8", - "eol" => "\n")); - $mime->setTXTBody($text); - $mime->setHTMLBody($html); - - $body = $mime->get(); - $headers = $mime->headers($headers); - - $host = getenv("SMTP_HOST"); - $username = getenv("SMTP_FROM"); - $password = getenv("SMTP_PW"); - $port = getenv("SMTP_PORT"); - - - $smtp = Mail::factory('smtp', [ - 'host' => $host, - 'auth' => true, - 'username' => $username, - 'password' => $password, - 'port' => $port - ]); - - $mail = $smtp->send($to, $headers, $body); - - if (PEAR::isError($mail)) { - return $mail->getMessage(); - } else { - return "Sent E-mail successfully"; - } -} +require_once('../helpers.php'); $to = getenv("SIGNUP_RECIPIENT"); $signup_url = getenv("SIGNUP_URL"); $ENCODED_EMAIL = urlencode($to); $DOMAIN = getenv("DOMAIN"); $AUTH_SECRET = $unique_key = uniqid(); +$lang = getenv("LANG"); + $auth_file_in_append_mode = fopen("/var/accounts/auth.file", "a"); fwrite($auth_file_in_append_mode, "$to:$AUTH_SECRET\n"); fclose($auth_file_in_append_mode); - -$SIGNUP_URL = "https://welcome.$DOMAIN/register?authmail=$ENCODED_EMAIL&authsecret=$AUTH_SECRET"; +if (!check_if_lang_exists($lang)) { + $lang = "en"; +} +$SIGNUP_URL = ""; +$lang == "en" ? $SIGNUP_URL = "https://welcome.$DOMAIN/register?authmail=$ENCODED_EMAIL&authsecret=$AUTH_SECRET" : $SIGNUP_URL = "https://welcome.$DOMAIN/$lang/register?authmail=$ENCODED_EMAIL&authsecret=$AUTH_SECRET"; echo "The new user can sign up now at $SIGNUP_URL\n"; -$result = sendInviteMail($to, $SIGNUP_URL); -echo $result; \ No newline at end of file +$result = sendInviteMail($to, $AUTH_SECRET, $lang); +if ($result) { + echo "Email Invite sent successfully\n"; +} else { + echo "Error sending email\n"; +}