Add settings to speficy smtp auth data for mails sent by froxlor

Signed-off-by: Michael Kaufmann (d00p) <d00p@froxlor.org>
This commit is contained in:
Michael Kaufmann (d00p)
2016-09-20 09:41:36 +02:00
parent 6a85c37b48
commit 6197a97dc1
10 changed files with 164 additions and 8 deletions

View File

@@ -152,6 +152,65 @@ return array(
'default' => 90,
'save_method' => 'storeSettingField',
),
'system_mail_use_smtp' => array(
'label' => $lng['serversettings']['mail_use_smtp'],
'settinggroup' => 'system',
'varname' => 'mail_use_smtp',
'type' => 'bool',
'default' => false,
'save_method' => 'storeSettingField',
),
'system_mail_smtp_host' => array(
'label' => $lng['serversettings']['mail_smtp_host'],
'settinggroup' => 'system',
'varname' => 'mail_smtp_host',
'type' => 'string',
'default' => 'localhost',
'save_method' => 'storeSettingField',
),
'system_mail_smtp_port' => array(
'label' => $lng['serversettings']['mail_smtp_port'],
'settinggroup' => 'system',
'varname' => 'mail_smtp_port',
'type' => 'int',
'int_min' => 1,
'int_max' => 65535,
'default' => 25,
'save_method' => 'storeSettingField',
),
'system_mail_smtp_usetls' => array(
'label' => $lng['serversettings']['mail_smtp_usetls'],
'settinggroup' => 'system',
'varname' => 'mail_smtp_usetls',
'type' => 'bool',
'default' => true,
'save_method' => 'storeSettingField',
),
'system_mail_smtp_auth' => array(
'label' => $lng['serversettings']['mail_smtp_auth'],
'settinggroup' => 'system',
'varname' => 'mail_smtp_auth',
'type' => 'bool',
'default' => true,
'save_method' => 'storeSettingField',
),
'system_mail_smtp_user' => array(
'label' => $lng['serversettings']['mail_smtp_user'],
'settinggroup' => 'system',
'varname' => 'mail_smtp_user',
'type' => 'string',
'default' => '',
'save_method' => 'storeSettingField',
),
'system_mail_smtp_passwd' => array(
'label' => $lng['serversettings']['mail_smtp_passwd'],
'settinggroup' => 'system',
'varname' => 'mail_smtp_passwd',
'type' => 'hiddenString',
'default' => '',
'save_method' => 'storeSettingField',
),
),
),
),

View File

@@ -535,6 +535,13 @@ INSERT INTO `panel_settings` (`settinggroup`, `varname`, `value`) VALUES
('system', 'le_froxlor_enabled', '0'),
('system', 'le_froxlor_redirect', '0'),
('system', 'letsencryptacmeconf', '/etc/apache2/conf-enabled/acme.conf'),
('system', 'mail_use_smtp', '0'),
('system', 'mail_smtp_host', 'localhost'),
('system', 'mail_smtp_port', '25'),
('system', 'mail_smtp_usetls', '1'),
('system', 'mail_smtp_auth', '1'),
('system', 'mail_smtp_user', ''),
('system', 'mail_smtp_passwd', ''),
('panel', 'decimal_places', '4'),
('panel', 'adminmail', 'admin@SERVERNAME'),
('panel', 'phpmyadmin_url', ''),
@@ -566,7 +573,7 @@ INSERT INTO `panel_settings` (`settinggroup`, `varname`, `value`) VALUES
('panel', 'password_special_char_required', '0'),
('panel', 'password_special_char', '!?<>§$%+#=@'),
('panel', 'version', '0.9.37'),
('panel', 'db_version', '201609120');
('panel', 'db_version', '201609200');
DROP TABLE IF EXISTS `panel_tasks`;

View File

@@ -3451,3 +3451,27 @@ if (isDatabaseVersion('201609050')) {
updateToDbVersion('201609120');
}
if (isDatabaseVersion('201609120')) {
showUpdateStep("Adding new SMTP settings for emails sent by froxlor");
// get user-chosen value
$smtp_enable = isset($_POST['smtp_enable']) ? (int) $_POST['smtp_enable'] : 0;
$smtp_host = isset($_POST['smtp_host']) ? $_POST['smtp_host'] : "localhost";
$smtp_port = isset($_POST['smtp_port']) ? (int)$_POST['smtp_port'] : 25;
$smtp_usetls = isset($_POST['smtp_usetls']) ? (int) $_POST['smtp_usetls'] : 1;
$smtp_useauth = isset($_POST['smtp_auth']) ? (int) $_POST['smtp_auth'] : 1;
$smtp_user = isset($_POST['smtp_user']) ? $_POST['smtp_user'] : "";
$smtp_passwd = isset($_POST['smtp_passwd']) ? $_POST['smtp_passwd'] : "";
Settings::AddNew("system.mail_use_smtp", $smtp_enable);
Settings::AddNew("system.mail_smtp_host", $smtp_host);
Settings::AddNew("system.mail_smtp_port", $smtp_port);
Settings::AddNew("system.mail_smtp_usetls", $smtp_usetls);
Settings::AddNew("system.mail_smtp_auth", $smtp_useauth);
Settings::AddNew("system.mail_smtp_user", $smtp_user);
Settings::AddNew("system.mail_smtp_passwd", $smtp_passwd);
lastStepStatus(0);
updateToDbVersion('201609200');
}

View File

@@ -689,4 +689,24 @@ function parseAndOutputPreconfig(&$has_preconfig, &$return, $current_version, $c
eval("\$return.=\"" . getTemplate("update/preconfigitem") . "\";");
}
}
if (versionInUpdate($current_db_version, '201609200')) {
$has_preconfig = true;
$description = 'Specify SMTP settings which froxlor should use to send mail (optional)<br /><br />';
$question = '<strong>Enable sending mails via SMTP?</strong><br />';
$question .= makeyesno('smtp_enable', '1', '0', '0') . '<br />';
$question .= '<strong>Enable sending mails via SMTP?</strong><br />';
$question .= '<input type="text" class="text" name="smtp_host" value="localhost" /><br />';
$question .= '<strong>TCP port to connect to?</strong><br />';
$question .= '<input type="text" class="text" name="smtp_port" value="25" /><br />';
$question .= '<strong>Enable TLS encryption?</strong><br />';
$question .= makeyesno('smtp_usetls', '1', '0', '1') . '<br />';
$question .= '<strong>Enable SMTP authentication?</strong><br />';
$question .= makeyesno('smtp_auth', '1', '0', '1') . '<br />';
$question .= '<strong>SMTP user?</strong><br />';
$question .= '<input type="text" class="text" name="smtp_user" value="" /><br />';
$question .= '<strong>SMTP password?</strong><br />';
$question .= '<input type="password" class="text" name="smtp_passwd" value="" /><br />';
eval("\$return.=\"" . getTemplate("update/preconfigitem") . "\";");
}
}

View File

@@ -34,6 +34,18 @@ function dieWithMail($message, $subject = "[froxlor] Cronjob error") {
$_mail = new PHPMailer(true);
$_mail->CharSet = "UTF-8";
if (Settings::Get('system.mail_use_smtp')) {
$_mail->isSMTP();
$_mail->Host = Settings::Get('system.mail_smtp_host');
$_mail->SMTPAuth = Settings::Get('system.mail_smtp_auth') == '1' ? true : false;
$_mail->Username = Settings::Get('system.mail_smtp_user');
$_mail->Password = Settings::Get('system.mail_smtp_passwd');
if (Settings::Get('system.mail_smtp_usetls')) {
$_mail->SMTPSecure = 'tls';
}
$_mail->Port = Settings::Get('system.mail_smtp_port');
}
if (PHPMailer::ValidateAddress(Settings::Get('panel.adminmail')) !== false) {
// set return-to address and custom sender-name, see #76
$_mail->SetFrom(Settings::Get('panel.adminmail'), Settings::Get('panel.adminmail_defname'));

View File

@@ -142,7 +142,7 @@ if (version_compare(PHP_VERSION, "5.4.0", "<")) {
*/
if (get_magic_quotes_gpc()) {
$in = array(&$_GET, &$_POST, &$_COOKIE);
while (list($k, $v) = each($in)) {
foreach ($v as $key => $val) {
if (!is_array($val)) {
@@ -265,7 +265,7 @@ while ($row = $result_stmt->fetch(PDO::FETCH_ASSOC)) {
// versions didn't have that and it will
// lead to a lot of undfined variables
// before the admin can even update
if (isset($row['iso'])) {
if (isset($row['iso'])) {
$iso[$row['iso']] = $row['language'];
}
}
@@ -542,6 +542,18 @@ if ($page == '') {
$mail = new PHPMailer(true);
$mail->CharSet = "UTF-8";
if (Settings::Get('system.mail_use_smtp')) {
$mail->isSMTP();
$mail->Host = Settings::Get('system.mail_smtp_host');
$mail->SMTPAuth = Settings::Get('system.mail_smtp_auth') == '1' ? true : false;
$mail->Username = Settings::Get('system.mail_smtp_user');
$mail->Password = Settings::Get('system.mail_smtp_passwd');
if (Settings::Get('system.mail_smtp_usetls')) {
$mail->SMTPSecure = 'tls';
}
$mail->Port = Settings::Get('system.mail_smtp_port');
}
if (PHPMailer::ValidateAddress(Settings::Get('panel.adminmail')) !== false) {
// set return-to address and custom sender-name, see #76
$mail->SetFrom(Settings::Get('panel.adminmail'), Settings::Get('panel.adminmail_defname'));

View File

@@ -19,7 +19,7 @@
$version = '0.9.37';
// Database version (YYYYMMDDC where C is a daily counter)
$dbversion = '201609120';
$dbversion = '201609200';
// Distribution branding-tag (used for Debian etc.)
$branding = '';

View File

@@ -2042,7 +2042,12 @@ $lng['serversettings']['option_unavailable_websrv'] = '<br><em class="red">Avail
$lng['serversettings']['option_unavailable'] = '<br><em class="red">Option not availble due to other settings.</em>';
$lng['serversettings']['letsencryptacmeconf']['title'] = "Path to the acme.conf snippet";
$lng['serversettings']['letsencryptacmeconf']['description'] = "File name of the config snippet which allows the web server to serve the acme challenge.";
// Added in froxlor 0.9.38
$lng['admin']['hostname'] = 'Hostname';
$lng['admin']['memory'] = 'Memory usage';
$lng['serversettings']['mail_use_smtp'] = 'Set mailer to use SMTP';
$lng['serversettings']['mail_smtp_host'] = 'Specify SMTP server';
$lng['serversettings']['mail_smtp_usetls'] = 'Enable TLS encryption';
$lng['serversettings']['mail_smtp_auth'] = 'Enable SMTP authentication';
$lng['serversettings']['mail_smtp_port'] = 'TCP port to connect to';
$lng['serversettings']['mail_smtp_user'] = 'SMTP username';
$lng['serversettings']['mail_smtp_passwd'] = 'SMTP password';

View File

@@ -1693,7 +1693,12 @@ $lng['serversettings']['option_unavailable_websrv'] = '<br><em class="red">Nur v
$lng['serversettings']['option_unavailable'] = '<br><em class="red">Option aufgrund anderer Einstellungen nicht verfügbar.</em>';
$lng['serversettings']['letsencryptacmeconf']['title'] = "Pfad zu acme.conf";
$lng['serversettings']['letsencryptacmeconf']['description'] = "Dateiname der Konfiguration, die dem Webserver erlaubt, die ACME-Challenges zu bedienen.";
// Added in froxlor 0.9.38
$lng['admin']['hostname'] = 'Hostname';
$lng['admin']['memory'] = 'Speicherauslastung';
$lng['serversettings']['mail_use_smtp'] = 'Nutze SMTP für das Senden von E-Mails';
$lng['serversettings']['mail_smtp_host'] = 'SMTP Server';
$lng['serversettings']['mail_smtp_usetls'] = 'Aktiviere TLS Verschlüsselung';
$lng['serversettings']['mail_smtp_auth'] = 'Nutze SMTP Authentifizierung';
$lng['serversettings']['mail_smtp_port'] = 'TCP Port für SMTP';
$lng['serversettings']['mail_smtp_user'] = 'SMTP Benutzer';
$lng['serversettings']['mail_smtp_passwd'] = 'SMTP Passwort';

View File

@@ -26,6 +26,18 @@ $yesterday = time() - (60 * 60 * 24);
$mail = new PHPMailer(true);
$mail->CharSet = "UTF-8";
if (Settings::Get('system.mail_use_smtp')) {
$mail->isSMTP();
$mail->Host = Settings::Get('system.mail_smtp_host');
$mail->SMTPAuth = Settings::Get('system.mail_smtp_auth') == '1' ? true : false;
$mail->Username = Settings::Get('system.mail_smtp_user');
$mail->Password = Settings::Get('system.mail_smtp_passwd');
if (Settings::Get('system.mail_smtp_usetls')) {
$mail->SMTPSecure = 'tls';
}
$mail->Port = Settings::Get('system.mail_smtp_port');
}
if (PHPMailer::ValidateAddress(Settings::Get('panel.adminmail')) !== false) {
// set return-to address and custom sender-name, see #76
$mail->SetFrom(Settings::Get('panel.adminmail'), Settings::Get('panel.adminmail_defname'));