Browse Source

Ensure mail-wrapper.php use FQDN for hostname (#2805)

* Support ensure it output the FQDN for hostname

* Make detection more feature proof

Co-authored-by: Jaap Marcus <9754650+jaapmarcus@users.noreply.github.com>
Clark Chen 3 năm trước cách đây
mục cha
commit
f975eab7b6
1 tập tin đã thay đổi với 20 bổ sung2 xóa
  1. 20 2
      web/inc/mail-wrapper.php

+ 20 - 2
web/inc/mail-wrapper.php

@@ -25,8 +25,26 @@ if (!empty( $data['config']['LANGUAGE'])) {
     $_SESSION['language'] = 'en';
     $_SESSION['language'] = 'en';
 }
 }
 
 
-// Define vars
-$from = 'noreply@'.gethostname();
+//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;
+})();
+
+$from = 'noreply@'.$hostname;
 $from_name = _('Hestia Control Panel');
 $from_name = _('Hestia Control Panel');
 $to = $argv[3]."\n";
 $to = $argv[3]."\n";
 $subject = $argv[2]."\n";
 $subject = $argv[2]."\n";