Skip to content

Commit f975eab

Browse files
Ensure mail-wrapper.php use FQDN for hostname (hestiacp#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>
1 parent eca25ef commit f975eab

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

web/inc/mail-wrapper.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,26 @@
2525
$_SESSION['language'] = 'en';
2626
}
2727

28-
// Define vars
29-
$from = 'noreply@'.gethostname();
28+
//define vars
29+
//make hostname detection a bit more feature proof
30+
$hostname = (function():string{
31+
$badValues = array(false, null, 0, '', "localhost", "127.0.0.1", "::1", "0000:0000:0000:0000:0000:0000:0000:0001");
32+
$ret = gethostname();
33+
if(in_array($ret, $badValues, true)){
34+
throw new Exception('gethostname() failed');
35+
}
36+
$ret2 = gethostbyname($ret);
37+
if(in_array($ret2, $badValues, true)){
38+
return $ret;
39+
}
40+
$ret3 = gethostbyaddr($ret2);
41+
if(in_array($ret3, $badValues, true)){
42+
return $ret2;
43+
}
44+
return $ret3;
45+
})();
46+
47+
$from = 'noreply@'.$hostname;
3048
$from_name = _('Hestia Control Panel');
3149
$to = $argv[3]."\n";
3250
$subject = $argv[2]."\n";

0 commit comments

Comments
 (0)