From f975eab7b6899583d2f3b6c920caff694c50bea4 Mon Sep 17 00:00:00 2001 From: Clark Chen <9372896+clarkchentw@users.noreply.github.com> Date: Wed, 3 Aug 2022 08:36:56 -0400 Subject: [PATCH] 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> --- web/inc/mail-wrapper.php | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/web/inc/mail-wrapper.php b/web/inc/mail-wrapper.php index 978047d5d0..4070a9fd5f 100755 --- a/web/inc/mail-wrapper.php +++ b/web/inc/mail-wrapper.php @@ -25,8 +25,26 @@ $_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'); $to = $argv[3]."\n"; $subject = $argv[2]."\n";