migrate admin_settings::testmail

Signed-off-by: Michael Kaufmann <d00p@froxlor.org>
This commit is contained in:
Michael Kaufmann
2022-03-24 14:25:29 +01:00
parent 25b9e5b540
commit bf41c84c6a
6 changed files with 99 additions and 15 deletions

View File

@@ -126,7 +126,7 @@ if ($page == 'message') {
'actions_links' => [[ 'actions_links' => [[
'href' => $linker->getLink(['section' => 'settings', 'page' => 'overview', 'part' => 'system', 'em' => 'system_mail_use_smtp']), 'href' => $linker->getLink(['section' => 'settings', 'page' => 'overview', 'part' => 'system', 'em' => 'system_mail_use_smtp']),
'label' => $lng['admin']['smtpsettings'], 'label' => $lng['admin']['smtpsettings'],
'icon' => 'fa-solid fa-wrench', 'icon' => 'fa-solid fa-gears',
'class' => 'btn-outline-secondary' 'class' => 'btn-outline-secondary'
]], ]],
// alert-box // alert-box

View File

@@ -331,7 +331,7 @@ if ($page == 'overview' && $userinfo['change_serversettings'] == '1') {
'href' => $linker->getLink(['section' => 'settings', 'page' => 'overview']), 'href' => $linker->getLink(['section' => 'settings', 'page' => 'overview']),
'label' => $lng['admin']['configfiles']['overview'], 'label' => $lng['admin']['configfiles']['overview'],
'icon' => 'fa fa-grip' 'icon' => 'fa fa-grip'
],[ ], [
'class' => 'btn-outline-secondary', 'class' => 'btn-outline-secondary',
'href' => $linker->getLink(['section' => 'settings', 'page' => $page, 'action' => 'export']), 'href' => $linker->getLink(['section' => 'settings', 'page' => $page, 'action' => 'export']),
'label' => 'Download/export ' . $lng['admin']['serversettings'], 'label' => 'Download/export ' . $lng['admin']['serversettings'],
@@ -340,12 +340,14 @@ if ($page == 'overview' && $userinfo['change_serversettings'] == '1') {
]); ]);
} }
} elseif ($page == 'testmail') { } elseif ($page == 'testmail') {
$note_type = 'info';
$note_msg = $lng['admin']['smtptestnote'];
if (isset($_POST['send']) && $_POST['send'] == 'send') { if (isset($_POST['send']) && $_POST['send'] == 'send') {
$test_addr = isset($_POST['test_addr']) ? $_POST['test_addr'] : null; $test_addr = isset($_POST['test_addr']) ? $_POST['test_addr'] : null;
/** // Initialize the mailingsystem
* Initialize the mailingsystem
*/
$testmail = new \PHPMailer\PHPMailer\PHPMailer(true); $testmail = new \PHPMailer\PHPMailer\PHPMailer(true);
$testmail->CharSet = "UTF-8"; $testmail->CharSet = "UTF-8";
@@ -379,10 +381,12 @@ if ($page == 'overview' && $userinfo['change_serversettings'] == '1') {
$testmail->AddAddress($test_addr); $testmail->AddAddress($test_addr);
$testmail->Send(); $testmail->Send();
} catch (\PHPMailer\PHPMailer\Exception $e) { } catch (\PHPMailer\PHPMailer\Exception $e) {
$mailerr_msg = $e->errorMessage(); $note_type = 'danger';
$note_msg = $e->getMessage();
$_mailerror = true; $_mailerror = true;
} catch (Exception $e) { } catch (Exception $e) {
$mailerr_msg = $e->getMessage(); $note_type = 'danger';
$note_msg = $e->getMessage();
$_mailerror = true; $_mailerror = true;
} }
@@ -396,14 +400,24 @@ if ($page == 'overview' && $userinfo['change_serversettings'] == '1') {
} }
} else { } else {
// invalid sender e-mail // invalid sender e-mail
$mailerr_msg = "Invalid sender e-mail address: " . Settings::Get('panel.adminmail'); $note_type = 'warning';
$_mailerror = true; $note_msg = "Invalid sender e-mail address: " . Settings::Get('panel.adminmail');
} }
} }
$mail_smtp_user = Settings::Get('system.mail_smtp_user'); $mailtest_add_data = include_once dirname(__FILE__) . '/lib/formfields/admin/settings/formfield.settings_mailtest.php';
$mail_smtp_host = Settings::Get('system.mail_smtp_host');
$mail_smtp_port = Settings::Get('system.mail_smtp_port');
eval("echo \"" . \Froxlor\UI\Template::getTemplate("settings/testmail") . "\";"); UI::view('user/form-note.html.twig', [
'formaction' => $linker->getLink(array('section' => 'settings')),
'formdata' => $mailtest_add_data['mailtest'],
'actions_links' => [[
'href' => $linker->getLink(['section' => 'settings', 'page' => 'overview', 'part' => 'system', 'em' => 'system_mail_use_smtp']),
'label' => $lng['admin']['smtpsettings'],
'icon' => 'fa-solid fa-gears',
'class' => 'btn-outline-secondary'
]],
// alert-box
'type' => $note_type,
'alert_msg' => $note_msg
]);
} }

View File

@@ -0,0 +1,64 @@
<?php
use Froxlor\Settings;
/**
* This file is part of the Froxlor project.
* Copyright (c) 2010 the Froxlor Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.froxlor.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Froxlor team <team@froxlor.org> (2010-)
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
* @package Formfields
*
*/
return array(
'mailtest' => array(
'title' => $lng['admin']['testmail'],
'image' => 'fa-solid fa-paper-plane',
'sections' => array(
'section_a' => array(
'fields' => array(
'smtp_user' => array(
'label' => $lng['serversettings']['mail_smtp_user'],
'type' => 'label',
'value' => (empty(Settings::Get('system.mail_smtp_user')) ? $lng['panel']['unspecified'] : Settings::Get('system.mail_smtp_user'))
),
'smtp_host' => array(
'label' => $lng['serversettings']['mail_smtp_host'],
'type' => 'label',
'value' => (empty(Settings::Get('system.mail_smtp_host')) ? $lng['panel']['unspecified'] : Settings::Get('system.mail_smtp_host'))
),
'smtp_port' => array(
'label' => $lng['serversettings']['mail_smtp_port'],
'type' => 'label',
'value' => (empty(Settings::Get('system.mail_smtp_port')) ? $lng['panel']['unspecified'] : Settings::Get('system.mail_smtp_port'))
),
'smtp_auth' => array(
'label' => $lng['serversettings']['mail_smtp_auth'],
'type' => 'checkbox',
'value' => 1,
'checked' => (bool) Settings::Get('system.mail_use_smtp'),
'disabled' => true
),
'smtp_tls' => array(
'label' => $lng['serversettings']['mail_smtp_usetls'],
'type' => 'checkbox',
'value' => 1,
'checked' => (bool) Settings::Get('system.mail_smtp_usetls'),
'disabled' => true
),
'test_addr' => array(
'label' => $lng['admin']['smtptestaddr'],
'type' => 'email',
'mandatory' => true
)
)
)
)
)
);

View File

@@ -2153,3 +2153,6 @@ $lng['admin']['configfiles']['recommendednote'] = 'Recommended/required services
$lng['admin']['configfiles']['selectrecommended'] = 'Select recommended'; $lng['admin']['configfiles']['selectrecommended'] = 'Select recommended';
$lng['update']['description'] = 'Running database updates for your froxlor installation'; $lng['update']['description'] = 'Running database updates for your froxlor installation';
$lng['admin']['smtpsettings'] = 'SMTP settings'; $lng['admin']['smtpsettings'] = 'SMTP settings';
$lng['panel']['unspecified'] = 'unspecified';
$lng['admin']['smtptestaddr'] = 'Send test-mail to';
$lng['admin']['smtptestnote'] = 'Note that the values below reflect your current settings and can only be adjusted there (see link in top right corner)';

View File

@@ -1795,3 +1795,6 @@ $lng['admin']['configfiles']['recommendednote'] = 'Empfohlene/benötigte Dienste
$lng['admin']['configfiles']['selectrecommended'] = 'Empfohlene wählen'; $lng['admin']['configfiles']['selectrecommended'] = 'Empfohlene wählen';
$lng['update']['description'] = 'Aktualisierung der froxlor Datenbank'; $lng['update']['description'] = 'Aktualisierung der froxlor Datenbank';
$lng['admin']['smtpsettings'] = 'SMTP Einstellungen'; $lng['admin']['smtpsettings'] = 'SMTP Einstellungen';
$lng['panel']['unspecified'] = 'keine Angabe';
$lng['admin']['smtptestaddr'] = 'Test-Email senden an';
$lng['admin']['smtptestnote'] = 'Bitte beachten: Die untenstehenden Werte reflektieren die aktuellen Einstellungen und können auch nur dort angepasst werden (siehe Link in der oberen rechten Ecke)';

View File

@@ -65,7 +65,7 @@
{% if field.is_array is defined and field.is_array == 1 and field.values is not empty %} {% if field.is_array is defined and field.is_array == 1 and field.values is not empty %}
{% for subfield in field.values %} {% for subfield in field.values %}
<div class="form-check form-switch"> <div class="form-check form-switch">
<input type="checkbox" {% if field.visible is defined and field.visible == false %} disabled {% endif %} value="{{ subfield.value }}" name="{{ id }}[]" class="form-check-input" {% if field.value is defined and subfield.value in field.value %} checked="checked" {% endif %}> <input type="checkbox" {% if (field.visible is defined and field.visible == false) or (field.disabled is defined and field.disabled == true) %} disabled {% endif %} value="{{ subfield.value }}" name="{{ id }}[]" class="form-check-input" {% if field.value is defined and subfield.value in field.value %} checked="checked" {% endif %}>
<label class="form-check-label"> <label class="form-check-label">
{{ subfield.label|raw }} {{ subfield.label|raw }}
</label> </label>
@@ -74,7 +74,7 @@
{% else %} {% else %}
<div class="form-check form-switch"> <div class="form-check form-switch">
<input type="hidden" value="0" name="{{ id }}" /> <input type="hidden" value="0" name="{{ id }}" />
<input type="checkbox" {% if field.visible is defined and field.visible == false %} disabled {% endif %} value="{{ field.value }}" id="{{ id }}" name="{{ id }}" class="form-check-input {% if field.valid is defined and field.valid == false %}is-invalid{% endif %}" {% if field.checked is defined and field.checked == 1 %} checked="checked" {% endif %}> <input type="checkbox" {% if (field.visible is defined and field.visible == false) or (field.disabled is defined and field.disabled == true) %} disabled {% endif %} value="{{ field.value }}" id="{{ id }}" name="{{ id }}" class="form-check-input {% if field.valid is defined and field.valid == false %}is-invalid{% endif %}" {% if field.checked is defined and field.checked == 1 %} checked="checked" {% endif %}>
</div> </div>
{% endif %} {% endif %}
{% endmacro %} {% endmacro %}