Просмотр исходного кода

Fix #2048 Unable to send mail with proxmox lxc

Jaap Marcus 3 лет назад
Родитель
Сommit
5111e44142

+ 1 - 1
web/add/db/index.php

@@ -114,7 +114,7 @@ if (!empty($_POST['ok'])) {
     if ((!empty($v_db_email)) && (empty($_SESSION['error_msg']))) {
         $to = $v_db_email;
         $subject = _("Database Credentials");
-        $hostname = exec('hostname');
+        $hostname = get_hostname();
         $from = "noreply@".$hostname;
         $from_name = _('Hestia Control Panel');
         $mailtext = sprintf(_('DATABASE_READY'), $user_plain."_".$_POST['v_database'], $user_plain."_".$_POST['v_dbuser'], $_POST['v_password'], $db_admin_link);

+ 1 - 1
web/add/mail/index.php

@@ -287,7 +287,7 @@ if (!empty($_POST['ok_acc'])) {
     if ((!empty($v_send_email)) && (empty($_SESSION['error_msg']))) {
         $to = $v_send_email;
         $subject = _("Email Credentials");
-        $hostname = exec('hostname');
+        $hostname = get_hostname();
         $from = "noreply@".$hostname;
         $from_name = _('Hestia Control Panel');
         $mailtext = $v_credentials;

+ 1 - 1
web/add/user/index.php

@@ -112,7 +112,7 @@ if (!empty($_POST['ok'])) {
         putenv("LANGUAGE=".$_POST['v_language']);
 
         $subject = _("Welcome to Hestia Control Panel");
-        $hostname = exec('hostname');
+        $hostname = get_hostname();
         unset($output);
         $from = "noreply@".$hostname;
         $from_name = _('Hestia Control Panel');

+ 1 - 1
web/edit/mail/index.php

@@ -652,7 +652,7 @@ if ((!empty($_POST['save'])) && (!empty($_GET['domain'])) && (!empty($_GET['acco
     if ((!empty($v_send_email)) && (empty($_SESSION['error_msg']))) {
         $to = $v_send_email;
         $subject = _("Email Credentials");
-        $hostname = exec('hostname');
+        $hostname = get_hostname();
         $from = "noreply@".$hostname;
         $from_name = _('Hestia Control Panel');
         $mailtext = $v_credentials;

+ 2 - 2
web/edit/web/index.php

@@ -787,7 +787,7 @@ if (!empty($_POST['save'])) {
                     if ((!empty($v_ftp_user_data['v_ftp_email'])) && (empty($_SESSION['error_msg']))) {
                         $to = $v_ftp_user_data['v_ftp_email'];
                         $subject = _("FTP login credentials");
-                        $hostname = exec('hostname');
+                        $hostname = get_hostname();
                         $from = "noreply@".$hostname;
                         $from_name = _('Hestia Control Panel');
                         $mailtext = sprintf(_('FTP_ACCOUNT_READY'), quoteshellarg($_GET['domain']), $user, $v_ftp_username, $v_ftp_user_data['v_ftp_password']);
@@ -864,7 +864,7 @@ if (!empty($_POST['save'])) {
 
                     $to = $v_ftp_user_data['v_ftp_email'];
                     $subject = _("FTP login credentials");
-                    $hostname = exec('hostname');
+                    $hostname = get_hostname();
                     $from = "noreply@".$hostname;
                     $from_name = _('Hestia Control Panel');
                     $mailtext =  sprintf(_('FTP_ACCOUNT_READY'), quoteshellarg($_GET['domain']), $user, $v_ftp_username_for_emailing, $v_ftp_user_data['v_ftp_password']);

+ 17 - 0
web/inc/helpers.php

@@ -134,3 +134,20 @@ function hst_add_history_log($message, $category = 'System', $level = 'Info', $u
     return $return_var;
 }
 
+function get_hostname(){
+        $badValues = array(false, null, 0, '', "localhost", "127.0.0.1", "::1", "0000:0000:0000:0000:0000:0000:0000:0001");
+        $ret = gethostname();
+        if(in_array($ret, $badValues, true)){
+            throw new Exception('gethostname() failed');
+        }
+        $ret2 = gethostbyname($ret);
+        if(in_array($ret2, $badValues, true)){
+            return $ret;
+        }
+        $ret3 = gethostbyaddr($ret2);
+        if(in_array($ret3, $badValues, true)){
+            return $ret2;
+        }
+        return $ret3;
+}
+

+ 1 - 16
web/inc/mail-wrapper.php

@@ -27,22 +27,7 @@ if (!empty( $data['config']['LANGUAGE'])) {
 
 //define vars 
 //make hostname detection a bit more feature proof
-$hostname = (function():string{
-    $badValues = array(false, null, 0, '', "localhost", "127.0.0.1", "::1", "0000:0000:0000:0000:0000:0000:0000:0001");
-    $ret = gethostname();
-    if(in_array($ret, $badValues, true)){
-        throw new Exception('gethostname() failed');
-    }
-    $ret2 = gethostbyname($ret);
-    if(in_array($ret2, $badValues, true)){
-        return $ret;
-    }
-    $ret3 = gethostbyaddr($ret2);
-    if(in_array($ret3, $badValues, true)){
-        return $ret2;
-    }
-    return $ret3;
-})();
+$hostname = get_hostname();
 
 $from = 'noreply@'.$hostname;
 $from_name = _('Hestia Control Panel');

+ 2 - 13
web/reset/index.php

@@ -44,20 +44,9 @@ if ((!empty($_POST['user'])) && (empty($_POST['code']))) {
                 $contact = $data[$user]['CONTACT'];
                 $to = $data[$user]['CONTACT'];
                 $subject = sprintf(_('MAIL_RESET_SUBJECT'), date("Y-m-d H:i:s"));
-                $hostname = exec('hostname');
-                $hostname_full = exec('hostname -f');
-                if ($hostname.":".$_SERVER['SERVER_PORT'] == $_SERVER['HTTP_HOST']) {
-                    $check = true; 
-                    $hostname_email = $hostname;
-                }else if ($hostname_full.":".$_SERVER['SERVER_PORT'] == $_SERVER['HTTP_HOST']) {
-                    $check = true;
-                    $hostname_email = $hostname_full;
-                }else{
-                    $check = false;
-                    $ERROR = "<a class=\"error\">"._('Invalid host domain')."</a>";
-                }
+                $hostname = get_hostname();
                 if ($check == true){
-                    $from = "noreply@".$hostname_email;
+                    $from = "noreply@".$hostname;
                     $from_name = _('Hestia Control Panel');
                     if (!empty($name)) {
                         $mailtext = sprintf(_('GREETINGS_GORDON'), $name);