From a07f9d3f23ed42b1168ca92c85634392f01f41e4 Mon Sep 17 00:00:00 2001 From: samerton Date: Tue, 24 Aug 2021 17:32:25 +0100 Subject: [PATCH] Validate email port before updating config in StaffCP --- .../languages/Chinese(Simplified)/admin.php | 1 + custom/languages/Chinese/admin.php | 1 + custom/languages/Czech/admin.php | 1 + custom/languages/Danish/admin.php | 1 + custom/languages/Dutch/admin.php | 1 + custom/languages/EnglishUK/admin.php | 1 + custom/languages/EnglishUS/admin.php | 1 + custom/languages/French/admin.php | 1 + custom/languages/German/admin.php | 1 + custom/languages/Greek/admin.php | 1 + custom/languages/Italian/admin.php | 1 + custom/languages/Japanese/admin.php | 1 + custom/languages/Lithuanian/admin.php | 1 + custom/languages/Norwegian/admin.php | 1 + custom/languages/Polish/admin.php | 1 + custom/languages/Portuguese/admin.php | 1 + custom/languages/Romanian/admin.php | 1 + custom/languages/Russian/admin.php | 1 + custom/languages/Slovak/admin.php | 1 + custom/languages/Spanish/admin.php | 1 + custom/languages/SpanishES/admin.php | 1 + custom/languages/SwedishSE/admin.php | 1 + custom/languages/Turkish/admin.php | 1 + modules/Core/pages/panel/emails.php | 108 +++++++++--------- 24 files changed, 80 insertions(+), 51 deletions(-) diff --git a/custom/languages/Chinese(Simplified)/admin.php b/custom/languages/Chinese(Simplified)/admin.php index f489fa598f..51c0892f3b 100644 --- a/custom/languages/Chinese(Simplified)/admin.php +++ b/custom/languages/Chinese(Simplified)/admin.php @@ -117,6 +117,7 @@ 'mailer_settings_info' => '如果启用了 PHPMailer,则必须填写以下字段。 更多的填写信息请点击 NamelessMC Wiki相关页面.', 'host' => '主机 IP', 'email_port' => '端口', + 'email_port_invalid' => 'Please insert a valid email port.', 'email_password_hidden' => '出于安全原因,未显示密码。', 'send_test_email' => '发送测试邮件', 'send_test_email_info' => '以下按钮将尝试向您的电子邮件地址 {x} 发送电子邮件. 发送电子邮件时抛出的任何错误都将显示。', // Don't replace {x} diff --git a/custom/languages/Chinese/admin.php b/custom/languages/Chinese/admin.php index da734291d5..2a83f54331 100644 --- a/custom/languages/Chinese/admin.php +++ b/custom/languages/Chinese/admin.php @@ -119,6 +119,7 @@ 'mailer_settings_info' => '如果您啟用的PHPMailer,則以下字段都必須要,不知道是什麼請造訪 維基.', 'host' => '伺服器', 'email_port' => '端口', + 'email_port_invalid' => 'Please insert a valid email port.', 'email_password_hidden' => '安全原因,密碼不顯示.', 'send_test_email' => '傳送測試電子郵件', 'send_test_email_info' => '下面按鈕將會傳送測試電子郵件至 {x}. 任何錯誤都會被顯示.', // Don't replace {x} diff --git a/custom/languages/Czech/admin.php b/custom/languages/Czech/admin.php index f43e0ca2d4..9dbe07bf74 100755 --- a/custom/languages/Czech/admin.php +++ b/custom/languages/Czech/admin.php @@ -105,6 +105,7 @@ 'mailer_settings_info' => 'Pro povolení PHPMaileru jsou vyžadována následující pole. Pro více informací, jak vyplnit tato pole, se podívejte na wiki.', 'host' => 'Hostitel', 'email_port' => 'Port', + 'email_port_invalid' => 'Please insert a valid email port.', 'email_password_hidden' => 'Heslo není z bezpečnostních důvodů zobrazeno.', 'edit_email_messages' => 'E-mailové zprávy', 'email_language_info' => 'Nevidíte váš jazyk? Zkontrolujte, zda je v adresáři vašeho jazyka soubor \'emails.php\' a že je zapisovatelný vaším webovým serverem.', diff --git a/custom/languages/Danish/admin.php b/custom/languages/Danish/admin.php index 171cd039de..1709bbbaf8 100644 --- a/custom/languages/Danish/admin.php +++ b/custom/languages/Danish/admin.php @@ -103,6 +103,7 @@ 'mailer_settings_info' => 'The following fields are required if you have enabled PHPMailer. For more information on how to fill out these fields, check out the wiki.', 'host' => 'Host', 'email_port' => 'Port', + 'email_port_invalid' => 'Please insert a valid email port.', 'email_password_hidden' => 'The password is not shown for security reasons.', 'edit_email_messages' => 'Email Messages', 'email_language_info' => 'Not seeing your language? Make sure \'emails.php\' is in your language directory and it is writable by your webserver.', diff --git a/custom/languages/Dutch/admin.php b/custom/languages/Dutch/admin.php index 081c2eb2fa..f9bed3cb17 100644 --- a/custom/languages/Dutch/admin.php +++ b/custom/languages/Dutch/admin.php @@ -117,6 +117,7 @@ 'mailer_settings_info' => 'De volgende velden zijn nodig als je PHPMailer aan hebt gezet. Voor meer informatie hoe je deze velden moet invullen, bekijk dan de wiki.', 'host' => 'Host', 'email_port' => 'Poort', + 'email_port_invalid' => 'Please insert a valid email port.', 'email_password_hidden' => 'Het wachtwoord wordt om veiligheidsredenen niet getoond.', 'send_test_email' => 'Verzend test email', 'send_test_email_info' => 'Deze knop zorgt ervoor dat er een email naar het email addres, {x} wordt verzonden. Eventuele fouten tijdens het versturen van die e-mail, worden weergegeven.', // Verander {x} niet diff --git a/custom/languages/EnglishUK/admin.php b/custom/languages/EnglishUK/admin.php index 4b8bbef1b2..4bb5bfcbbd 100644 --- a/custom/languages/EnglishUK/admin.php +++ b/custom/languages/EnglishUK/admin.php @@ -104,6 +104,7 @@ 'mailer_settings_info' => 'The following fields are required if you have enabled PHPMailer. For more information on how to fill out these fields, check out the wiki.', 'host' => 'Host', 'email_port' => 'Port', + 'email_port_invalid' => 'Please insert a valid email port.', 'email_password_hidden' => 'The password is not shown for security reasons.', 'edit_email_messages' => 'Email Messages', 'email_language_info' => 'Not seeing your language? Make sure \'emails.php\' is in your language directory and it is writable by your webserver.', diff --git a/custom/languages/EnglishUS/admin.php b/custom/languages/EnglishUS/admin.php index 9597a512b6..581a249415 100644 --- a/custom/languages/EnglishUS/admin.php +++ b/custom/languages/EnglishUS/admin.php @@ -115,6 +115,7 @@ 'mailer_settings_info' => 'The following fields are required if you have enabled PHPMailer. For more information on how to fill out these fields, check out the wiki.', 'host' => 'Host', 'email_port' => 'Port', + 'email_port_invalid' => 'Please insert a valid email port.', 'email_password_hidden' => 'The password is not shown for security reasons.', 'send_test_email' => 'Send Test Email', 'send_test_email_info' => 'The following button will attempt to send an email to your email address, {x}. Any errors thrown whilst sending the email will be displayed.', // Don't replace {x} diff --git a/custom/languages/French/admin.php b/custom/languages/French/admin.php index de76f6743f..17c117b31d 100644 --- a/custom/languages/French/admin.php +++ b/custom/languages/French/admin.php @@ -112,6 +112,7 @@ 'mailer_settings_info' => 'Les champs suivants sont requis si vous avez activé PHPMailer. Pour plus d’informations sur la façon de remplir ces champs, consultez le wiki.', 'host' => 'Hôte', 'email_port' => 'Port', + 'email_port_invalid' => 'Please insert a valid email port.', 'email_password_hidden' => 'Le mot de passe n’est pas affiché pour des raisons de sécurité.', 'send_test_email' => 'Envoyer un email de test', 'send_test_email_info' => 'Le bouton suivant tentera d\'envoyer un courriel à votre adresse électronique, {x}. Toute erreur commise lors de l\'envoi du courriel sera affichée.', // Don't replace {x} diff --git a/custom/languages/German/admin.php b/custom/languages/German/admin.php index ceb943ea9c..b4b9e0a80f 100644 --- a/custom/languages/German/admin.php +++ b/custom/languages/German/admin.php @@ -115,6 +115,7 @@ 'mailer_settings_info' => 'Die folgenden Felder sind erforderlich, wenn Sie PHPMailer aktiviert haben. Weitere Informationen zum Ausfüllen dieser Felder finden Sie unter NamelessMC Wiki.', 'host' => 'Host', 'email_port' => 'Port', + 'email_port_invalid' => 'Please insert a valid email port.', 'email_password_hidden' => 'Das Password wird aus Sicherheitsgründen nicht angezeigt.', 'send_test_email' => 'Sende Test Email', 'send_test_email_info' => 'Die folgende Schaltfläche versucht, eine E-Mail an Ihre E-Mail-Adresse zu senden, {x} . Falls Irgendwelche Fehler, die beim Senden der E-Mail enstehen, werden angezeigt.', // Don't replace {x} diff --git a/custom/languages/Greek/admin.php b/custom/languages/Greek/admin.php index 016309fb48..6a5205e07a 100644 --- a/custom/languages/Greek/admin.php +++ b/custom/languages/Greek/admin.php @@ -117,6 +117,7 @@ 'mailer_settings_info' => 'The following fields are required if you have enabled PHPMailer. For more information on how to fill out these fields, check out the wiki.', 'host' => 'Host', 'email_port' => 'Port', + 'email_port_invalid' => 'Please insert a valid email port.', 'email_password_hidden' => 'The password is not shown for security reasons.', 'send_test_email' => 'Send Test Email', 'send_test_email_info' => 'The following button will attempt to send an email to your email address, {x}. Any errors thrown whilst sending the email will be displayed.', // Don't replace {x} diff --git a/custom/languages/Italian/admin.php b/custom/languages/Italian/admin.php index d8da584158..b9ffe95f7c 100644 --- a/custom/languages/Italian/admin.php +++ b/custom/languages/Italian/admin.php @@ -115,6 +115,7 @@ 'mailer_settings_info' => 'I seguenti campi sono obbligatori se hai attivato PHPMailer. Per maggiori informazioni su come riempire questi campi controlla la wiki.', 'host' => 'Host', 'email_port' => 'Porta', + 'email_port_invalid' => 'Please insert a valid email port.', 'email_password_hidden' => 'La password non è mostrata per motivi di sicurezza.', 'send_test_email' => 'Invia email di test', 'send_test_email_info' => "Il seguente bottone tenterà di inviare un'email al tuo indirizzo email, {x}. Verranno visualizzati eventuali errori generati durante l'invio dell'email.", // Don't replace {x} diff --git a/custom/languages/Japanese/admin.php b/custom/languages/Japanese/admin.php index 35a6fa81bb..2e34c9690b 100644 --- a/custom/languages/Japanese/admin.php +++ b/custom/languages/Japanese/admin.php @@ -120,6 +120,7 @@ 'mailer_settings_info' => 'PHPMailerを有効にした場合、以下のフィールドに必要事項を記入する必要があります。以下のフィールドに記入する方法については Wikiを確認して下さい。', 'host' => 'ホスト', 'email_port' => 'ポート', + 'email_port_invalid' => 'Please insert a valid email port.', 'email_password_hidden' => 'セキュリティ保護のためパスワードは非表示です。', 'send_test_email' => 'テストメール 送信', 'send_test_email_info' => '{x}にNamelessMCからテストメールを送信します。テストを実行することで、メール設定が正しくされているかを確認できます。テスト終了後確認されたエラーは表示されます。送信するには「送信」を押してください。', // Don't replace {x} diff --git a/custom/languages/Lithuanian/admin.php b/custom/languages/Lithuanian/admin.php index 78554e61bc..03eb465edf 100644 --- a/custom/languages/Lithuanian/admin.php +++ b/custom/languages/Lithuanian/admin.php @@ -113,6 +113,7 @@ 'mailer_settings_info' => 'Šie laukai reikalingi, jei įjungėte PHPMailer. Norėdami gauti daugiau informacijos, kaip užpildyti šiuos laukus, patikrinkite wiki.', 'host' => 'Host', 'email_port' => 'Port', + 'email_port_invalid' => 'Please insert a valid email port.', 'email_password_hidden' => 'Saugos sumetimais slaptažodis nerodomas.', 'send_test_email' => 'Siųsti bandomajį el. laišką', 'send_test_email_info' => 'Sekantis mygtukas bandys išsiųsti el. Laišką į jūsų el. Pašto adresą, {x}. Bus rodomos klaidos siunčiant el. Laišką.', // Don't replace {x} diff --git a/custom/languages/Norwegian/admin.php b/custom/languages/Norwegian/admin.php index 877c92cbef..b3cac3da32 100644 --- a/custom/languages/Norwegian/admin.php +++ b/custom/languages/Norwegian/admin.php @@ -115,6 +115,7 @@ 'mailer_settings_info' => 'De markerte feltene må være utfylt hvis du har PHPMailer aktivert. For mer informasjon om hvordan du fyller ut disse feltene, sjekk ut wiki.', 'host' => 'Vert', 'email_port' => 'Port', + 'email_port_invalid' => 'Please insert a valid email port.', 'email_password_hidden' => 'Passordet vises ikke på grunn av sikkerhetsmessige årsaker.', 'send_test_email' => 'Send test e-post', 'send_test_email_info' => 'Denne knappen vil prøve å sende en test e-post til din e-postadressse, {x}. Alle feilmeldinger som blir oppdaget vil bli listet her.', // Don't replace {x} diff --git a/custom/languages/Polish/admin.php b/custom/languages/Polish/admin.php index b736480a60..42f02a6e4f 100755 --- a/custom/languages/Polish/admin.php +++ b/custom/languages/Polish/admin.php @@ -115,6 +115,7 @@ 'mailer_settings_info' => 'Następujące pola są wymagane, jeśli masz włączony PHPMailer. Aby uzyskać więcej informacji na temat wypełniania tych pól, przeczytaj ten artykuł w NamelessMC wiki.', 'host' => 'Host', 'email_port' => 'Port', + 'email_port_invalid' => 'Please insert a valid email port.', 'email_password_hidden' => 'Hasło nie jest pokazane ze względów bezpieczeństwa.', 'send_test_email' => 'Wyślij testowy email', 'send_test_email_info' => 'Poniższy przycisk wyśle wiadomość e-mail na twój adres e-mail {x} . Zostaną wyświetlone wszystkie błędy wygenerowane podczas wysyłania wiadomości.', // Don't replace {x} diff --git a/custom/languages/Portuguese/admin.php b/custom/languages/Portuguese/admin.php index 6a0e8edd21..3aae097a51 100644 --- a/custom/languages/Portuguese/admin.php +++ b/custom/languages/Portuguese/admin.php @@ -117,6 +117,7 @@ 'mailer_settings_info' => 'Os campos a seguir são necessários se você tiver habilitado o PHPMailer. Para obter mais informações sobre como preencher esses campos, confira a wiki.', 'host' => 'Host', 'email_port' => 'Porta', + 'email_port_invalid' => 'Please insert a valid email port.', 'email_password_hidden' => 'A senha não é mostrada por razões de segurança.', 'send_test_email' => 'Enviar email de teste', 'send_test_email_info' => 'O seguinte botão irá tentar enviar um email para o seu endereço de email, {x}. Qualquer erro que occora enquanto envia o email será exibido.', // Don't replace {x} diff --git a/custom/languages/Romanian/admin.php b/custom/languages/Romanian/admin.php index a7556a3324..f47bf474f2 100644 --- a/custom/languages/Romanian/admin.php +++ b/custom/languages/Romanian/admin.php @@ -120,6 +120,7 @@ 'mailer_settings_info' => 'Următoarele câmpuri sunt necesare dacă ați activat PHPMailer. Pentru mai multe informații despre completarea acestor câmpuri, consultați wiki-ul.', 'host' => 'Gazdă', 'email_port' => 'Port', + 'email_port_invalid' => 'Please insert a valid email port.', 'email_password_hidden' => 'Parola nu este afișată din motive de securitate.', 'send_test_email' => 'Trimiteți e-mail de încercare (test)', 'send_test_email_info' => 'Următorul buton va încerca să trimită un e-mail la adresa dvs. de e-mail, {x}. Orice erori întâmpinate în timp ce trimiteți e-mailul vor fi afișate.', // Don't replace {x} diff --git a/custom/languages/Russian/admin.php b/custom/languages/Russian/admin.php index faa2f3c421..f0fa750f6b 100644 --- a/custom/languages/Russian/admin.php +++ b/custom/languages/Russian/admin.php @@ -116,6 +116,7 @@ 'mailer_settings_info' => 'Следующие поля обязательны для заполнения, если вы включили PHPMailer. Для получения дополнительной информации о том, как заполнить эти поля, ознакомьтесь с Wiki.', 'host' => 'Хост', 'email_port' => 'Порт', + 'email_port_invalid' => 'Please insert a valid email port.', 'email_password_hidden' => 'Пароль не отображается по соображениям безопасности.', 'send_test_email' => 'Отправить тестовое письмо', 'send_test_email_info' => 'Следующая кнопка попытается отправить электронное письмо на ваш адрес электронной почты, {x}. Любые ошибки, возникшие при отправке письма, будут отображены.', // Don't replace {x} diff --git a/custom/languages/Slovak/admin.php b/custom/languages/Slovak/admin.php index 5c2e21f030..69aa9510be 100644 --- a/custom/languages/Slovak/admin.php +++ b/custom/languages/Slovak/admin.php @@ -104,6 +104,7 @@ 'mailer_settings_info' => 'Nasledujúce polia sú povinné, ak ste povolili PHPMailer. Ďalšie informácie o tom, ako vyplniť tieto polia, nájdete na wiki.', 'host' => 'Host', 'email_port' => 'Port', + 'email_port_invalid' => 'Please insert a valid email port.', 'email_password_hidden' => 'Heslo sa z bezpečnostných dôvodov nezobrazuje.', 'edit_email_messages' => 'Emailové správy', 'email_language_info' => 'Nevidíte svoj jazyk? Uistite sa, že súbor \'emails.php\' je vo vašom jazykovom adresári a je zapisovateľný vašim webovým serverom.', diff --git a/custom/languages/Spanish/admin.php b/custom/languages/Spanish/admin.php index 201a23bb7f..11d6597fc3 100755 --- a/custom/languages/Spanish/admin.php +++ b/custom/languages/Spanish/admin.php @@ -115,6 +115,7 @@ 'mailer_settings_info' => 'Los campos siguientes son obligatorios si ha habilitado PHPMailer. Para obtener más información sobre como rellenar estos campos, consulta en the wiki.', 'host' => 'Dirección IP', 'email_port' => 'Puerto', + 'email_port_invalid' => 'Please insert a valid email port.', 'email_password_hidden' => 'La contraseña no se muestra por razones de seguridad.', 'send_test_email' => 'Enviar prueba de correo electrónico', 'send_test_email_info' => 'El siguiente botón intentará enviar un correo electrónico a su dirección de correo electrónico, {x}. Se mostrarán todos los errores lanzados mientras se envía el correo.', // Don't replace {x} diff --git a/custom/languages/SpanishES/admin.php b/custom/languages/SpanishES/admin.php index 2cc22fe9e4..f905992d81 100755 --- a/custom/languages/SpanishES/admin.php +++ b/custom/languages/SpanishES/admin.php @@ -104,6 +104,7 @@ 'mailer_settings_info' => 'Los siguientes campos son obligatorios si ha activado PHPMailer. Para más información sobre cómo rellenar estos campos, consulte la wiki.', 'host' => 'Servidor', 'email_port' => 'Puerto', + 'email_port_invalid' => 'Please insert a valid email port.', 'email_password_hidden' => 'La contraseña no se muestra por razones de seguridad.', 'edit_email_messages' => 'Mensajes de correo electrónico', 'email_language_info' => '¿No ve su idioma? Asegúrese de que \'emails.php\' está en su directorio de idiomas y es escribible por su servidor web.', diff --git a/custom/languages/SwedishSE/admin.php b/custom/languages/SwedishSE/admin.php index 8980950303..4d7bdf1f6f 100644 --- a/custom/languages/SwedishSE/admin.php +++ b/custom/languages/SwedishSE/admin.php @@ -116,6 +116,7 @@ 'mailer_settings_info' => 'The following fields are required if you have enabled PHPMailer. For more information on how to fill out these fields, check out the wiki.', 'host' => 'Host', 'email_port' => 'Port', + 'email_port_invalid' => 'Please insert a valid email port.', 'email_password_hidden' => 'Lösenordet visas inte av säkerhetsskäl.', 'send_test_email' => 'Skicka Test E-post', 'send_test_email_info' => 'Följande knapp kommer att försöka skicka ett mail till din e-postadress, {x} . Eventuella fel när du skickar e-postmeddelandet visas.', // Don't replace {x} diff --git a/custom/languages/Turkish/admin.php b/custom/languages/Turkish/admin.php index 0cd7b65d2d..0d658ce586 100644 --- a/custom/languages/Turkish/admin.php +++ b/custom/languages/Turkish/admin.php @@ -115,6 +115,7 @@ 'mailer_settings_info' => 'PHPMailer\'ı etkinleştirdiyseniz aşağıdaki alanlar gereklidir. Bu alanları doldurma hakkında daha fazla bilgi için iki.', 'host' => 'Host', 'email_port' => 'Port', + 'email_port_invalid' => 'Please insert a valid email port.', 'email_password_hidden' => 'Güvenlik nedeniyle şifre gösterilmez.', 'send_test_email' => 'Test E-Postası Gönder', 'send_test_email_info' => 'Aşağıdaki düğme, e-posta adresinize {x} bir e-posta göndermeye çalışacaktır. E-posta gönderilirken atılan hatalar görüntülenir.', // Don't replace {x} diff --git a/modules/Core/pages/panel/emails.php b/modules/Core/pages/panel/emails.php index 784e38309c..f0f648fca9 100644 --- a/modules/Core/pages/panel/emails.php +++ b/modules/Core/pages/panel/emails.php @@ -202,60 +202,66 @@ )); } - // Update config - $config_path = ROOT_PATH . DIRECTORY_SEPARATOR . 'core' . DIRECTORY_SEPARATOR . 'email.php'; - if (file_exists($config_path)) { - if (is_writable($config_path)) { - require(ROOT_PATH . '/core/email.php'); - - // Build new email config - $config = ' \'' . str_replace('\'', '\\\'', (!empty($_POST['email']) ? $_POST['email'] : $GLOBALS['email']['email'])) . '\',' . PHP_EOL . - ' \'username\' => \'' . str_replace('\'', '\\\'', (!empty($_POST['username']) ? $_POST['username'] : $GLOBALS['email']['username'])) . '\',' . PHP_EOL . - ' \'password\' => \'' . str_replace('\'', '\\\'', ((!empty($_POST['password'])) ? $_POST['password'] : $GLOBALS['email']['password'])) . '\',' . PHP_EOL . - ' \'name\' => \'' . str_replace('\'', '\\\'', (!empty($_POST['name']) ? $_POST['name'] : $GLOBALS['email']['name'])) . '\',' . PHP_EOL . - ' \'host\' => \'' . str_replace('\'', '\\\'', (!empty($_POST['host']) ? $_POST['host'] : $GLOBALS['email']['host'])) . '\',' . PHP_EOL . - ' \'port\' => ' . str_replace('\'', '\\\'', (!empty($_POST['port']) ? $_POST['port'] : $GLOBALS['email']['port'])) . ',' . PHP_EOL . - ' \'secure\' => \'' . str_replace('\'', '\\\'', $GLOBALS['email']['secure']) . '\',' . PHP_EOL . - ' \'smtp_auth\' => ' . (($GLOBALS['email']['smtp_auth']) ? 'true' : 'false') . PHP_EOL . - ');'; - - $file = fopen($config_path, 'w'); - fwrite($file, $config); - fclose($file); - } else { - // Permissions incorrect - $errors[] = $language->get('admin', 'unable_to_write_email_config'); - } - } else { - // Create one now - if (is_writable(ROOT_PATH . DIRECTORY_SEPARATOR . 'core')) { - // Build new email config - $config = ' \'' . str_replace('\'', '\\\'', (!empty($_POST['email']) ? $_POST['email'] : '')) . '\',' . PHP_EOL . - ' \'username\' => \'' . str_replace('\'', '\\\'', (!empty($_POST['username']) ? $_POST['username'] : '')) . '\',' . PHP_EOL . - ' \'password\' => \'' . str_replace('\'', '\\\'', ((!empty($_POST['password'])) ? $_POST['password'] : '')) . '\',' . PHP_EOL . - ' \'name\' => \'' . str_replace('\'', '\\\'', (!empty($_POST['name']) ? $_POST['name'] : '')) . '\',' . PHP_EOL . - ' \'host\' => \'' . str_replace('\'', '\\\'', (!empty($_POST['host']) ? $_POST['host'] : '')) . '\',' . PHP_EOL . - ' \'port\' => \'' . str_replace('\'', '\\\'', (!empty($_POST['port']) ? $_POST['host'] : 587)) . ',' . PHP_EOL . - ' \'secure\' => \'tls\',' . PHP_EOL . - ' \'smtp_auth\' => true' . PHP_EOL . - ');'; - $file = fopen($config_path, 'w'); - fwrite($file, $config); - fclose($file); - } else { - $errors[] = $language->get('admin', 'unable_to_write_email_config'); - } + if ($_POST['port'] && !is_numeric($_POST['port'])) { + $errors[] = $language->get('admin', 'email_port_invalid'); } if (!count($errors)) { - // Redirect to refresh config values - Session::flash('emails_success', $language->get('admin', 'email_settings_updated_successfully')); - Redirect::to(URL::build('/panel/core/emails')); - die(); + // Update config + $config_path = ROOT_PATH . DIRECTORY_SEPARATOR . 'core' . DIRECTORY_SEPARATOR . 'email.php'; + if (file_exists($config_path)) { + if (is_writable($config_path)) { + require(ROOT_PATH . '/core/email.php'); + + // Build new email config + $config = ' \'' . str_replace('\'', '\\\'', (!empty($_POST['email']) ? $_POST['email'] : $GLOBALS['email']['email'])) . '\',' . PHP_EOL . + ' \'username\' => \'' . str_replace('\'', '\\\'', (!empty($_POST['username']) ? $_POST['username'] : $GLOBALS['email']['username'])) . '\',' . PHP_EOL . + ' \'password\' => \'' . str_replace('\'', '\\\'', ((!empty($_POST['password'])) ? $_POST['password'] : $GLOBALS['email']['password'])) . '\',' . PHP_EOL . + ' \'name\' => \'' . str_replace('\'', '\\\'', (!empty($_POST['name']) ? $_POST['name'] : $GLOBALS['email']['name'])) . '\',' . PHP_EOL . + ' \'host\' => \'' . str_replace('\'', '\\\'', (!empty($_POST['host']) ? $_POST['host'] : $GLOBALS['email']['host'])) . '\',' . PHP_EOL . + ' \'port\' => ' . str_replace('\'', '\\\'', (!empty($_POST['port']) ? $_POST['port'] : $GLOBALS['email']['port'])) . ',' . PHP_EOL . + ' \'secure\' => \'' . str_replace('\'', '\\\'', $GLOBALS['email']['secure']) . '\',' . PHP_EOL . + ' \'smtp_auth\' => ' . (($GLOBALS['email']['smtp_auth']) ? 'true' : 'false') . PHP_EOL . + ');'; + + $file = fopen($config_path, 'w'); + fwrite($file, $config); + fclose($file); + } else { + // Permissions incorrect + $errors[] = $language->get('admin', 'unable_to_write_email_config'); + } + } else { + // Create one now + if (is_writable(ROOT_PATH . DIRECTORY_SEPARATOR . 'core')) { + // Build new email config + $config = ' \'' . str_replace('\'', '\\\'', (!empty($_POST['email']) ? $_POST['email'] : '')) . '\',' . PHP_EOL . + ' \'username\' => \'' . str_replace('\'', '\\\'', (!empty($_POST['username']) ? $_POST['username'] : '')) . '\',' . PHP_EOL . + ' \'password\' => \'' . str_replace('\'', '\\\'', ((!empty($_POST['password'])) ? $_POST['password'] : '')) . '\',' . PHP_EOL . + ' \'name\' => \'' . str_replace('\'', '\\\'', (!empty($_POST['name']) ? $_POST['name'] : '')) . '\',' . PHP_EOL . + ' \'host\' => \'' . str_replace('\'', '\\\'', (!empty($_POST['host']) ? $_POST['host'] : '')) . '\',' . PHP_EOL . + ' \'port\' => \'' . str_replace('\'', '\\\'', (!empty($_POST['port']) ? $_POST['host'] : 587)) . ',' . PHP_EOL . + ' \'secure\' => \'tls\',' . PHP_EOL . + ' \'smtp_auth\' => true' . PHP_EOL . + ');'; + $file = fopen($config_path, 'w'); + fwrite($file, $config); + fclose($file); + } else { + $errors[] = $language->get('admin', 'unable_to_write_email_config'); + } + } + + if (!count($errors)) { + // Redirect to refresh config values + Session::flash('emails_success', $language->get('admin', 'email_settings_updated_successfully')); + Redirect::to(URL::build('/panel/core/emails')); + die(); + } } } } else