diff --git a/actions/admin/settings/120.system.php b/actions/admin/settings/120.system.php index 464244c5..b08ce88e 100644 --- a/actions/admin/settings/120.system.php +++ b/actions/admin/settings/120.system.php @@ -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', + ), ), ), ), diff --git a/install/froxlor.sql b/install/froxlor.sql index b323b917..f30c943a 100644 --- a/install/froxlor.sql +++ b/install/froxlor.sql @@ -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`; diff --git a/install/updates/froxlor/0.9/update_0.9.inc.php b/install/updates/froxlor/0.9/update_0.9.inc.php index 5f3c5a8b..7da2b984 100644 --- a/install/updates/froxlor/0.9/update_0.9.inc.php +++ b/install/updates/froxlor/0.9/update_0.9.inc.php @@ -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'); +} diff --git a/install/updates/preconfig/0.9/preconfig_0.9.inc.php b/install/updates/preconfig/0.9/preconfig_0.9.inc.php index 22406220..a25b78fc 100644 --- a/install/updates/preconfig/0.9/preconfig_0.9.inc.php +++ b/install/updates/preconfig/0.9/preconfig_0.9.inc.php @@ -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)

'; + $question = 'Enable sending mails via SMTP?
'; + $question .= makeyesno('smtp_enable', '1', '0', '0') . '
'; + $question .= 'Enable sending mails via SMTP?
'; + $question .= '
'; + $question .= 'TCP port to connect to?
'; + $question .= '
'; + $question .= 'Enable TLS encryption?
'; + $question .= makeyesno('smtp_usetls', '1', '0', '1') . '
'; + $question .= 'Enable SMTP authentication?
'; + $question .= makeyesno('smtp_auth', '1', '0', '1') . '
'; + $question .= 'SMTP user?
'; + $question .= '
'; + $question .= 'SMTP password?
'; + $question .= '
'; + eval("\$return.=\"" . getTemplate("update/preconfigitem") . "\";"); + } } diff --git a/lib/functions/output/function.dieWithMail.php b/lib/functions/output/function.dieWithMail.php index 77ac2604..21890bdd 100644 --- a/lib/functions/output/function.dieWithMail.php +++ b/lib/functions/output/function.dieWithMail.php @@ -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')); diff --git a/lib/init.php b/lib/init.php index 585588ec..1c116a2c 100644 --- a/lib/init.php +++ b/lib/init.php @@ -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')); diff --git a/lib/version.inc.php b/lib/version.inc.php index d0e8de30..8a1d56d3 100644 --- a/lib/version.inc.php +++ b/lib/version.inc.php @@ -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 = ''; diff --git a/lng/english.lng.php b/lng/english.lng.php index 8d7fc200..6d2b9608 100644 --- a/lng/english.lng.php +++ b/lng/english.lng.php @@ -2042,7 +2042,12 @@ $lng['serversettings']['option_unavailable_websrv'] = '
Avail $lng['serversettings']['option_unavailable'] = '
Option not availble due to other settings.'; $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'; diff --git a/lng/german.lng.php b/lng/german.lng.php index dd77baba..a1ebeba4 100644 --- a/lng/german.lng.php +++ b/lng/german.lng.php @@ -1693,7 +1693,12 @@ $lng['serversettings']['option_unavailable_websrv'] = '
Nur v $lng['serversettings']['option_unavailable'] = '
Option aufgrund anderer Einstellungen nicht verfügbar.'; $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'; diff --git a/scripts/jobs/cron_usage_report.php b/scripts/jobs/cron_usage_report.php index 8de32c71..2ff94b52 100644 --- a/scripts/jobs/cron_usage_report.php +++ b/scripts/jobs/cron_usage_report.php @@ -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'));