Skip to content

Commit 5111e44

Browse files
committed
Fix hestiacp#2048 Unable to send mail with proxmox lxc
1 parent 6018381 commit 5111e44

File tree

8 files changed

+26
-35
lines changed

8 files changed

+26
-35
lines changed

web/add/db/index.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@
114114
if ((!empty($v_db_email)) && (empty($_SESSION['error_msg']))) {
115115
$to = $v_db_email;
116116
$subject = _("Database Credentials");
117-
$hostname = exec('hostname');
117+
$hostname = get_hostname();
118118
$from = "noreply@".$hostname;
119119
$from_name = _('Hestia Control Panel');
120120
$mailtext = sprintf(_('DATABASE_READY'), $user_plain."_".$_POST['v_database'], $user_plain."_".$_POST['v_dbuser'], $_POST['v_password'], $db_admin_link);

web/add/mail/index.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@
287287
if ((!empty($v_send_email)) && (empty($_SESSION['error_msg']))) {
288288
$to = $v_send_email;
289289
$subject = _("Email Credentials");
290-
$hostname = exec('hostname');
290+
$hostname = get_hostname();
291291
$from = "noreply@".$hostname;
292292
$from_name = _('Hestia Control Panel');
293293
$mailtext = $v_credentials;

web/add/user/index.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@
112112
putenv("LANGUAGE=".$_POST['v_language']);
113113

114114
$subject = _("Welcome to Hestia Control Panel");
115-
$hostname = exec('hostname');
115+
$hostname = get_hostname();
116116
unset($output);
117117
$from = "noreply@".$hostname;
118118
$from_name = _('Hestia Control Panel');

web/edit/mail/index.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,7 @@
652652
if ((!empty($v_send_email)) && (empty($_SESSION['error_msg']))) {
653653
$to = $v_send_email;
654654
$subject = _("Email Credentials");
655-
$hostname = exec('hostname');
655+
$hostname = get_hostname();
656656
$from = "noreply@".$hostname;
657657
$from_name = _('Hestia Control Panel');
658658
$mailtext = $v_credentials;

web/edit/web/index.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,7 @@
787787
if ((!empty($v_ftp_user_data['v_ftp_email'])) && (empty($_SESSION['error_msg']))) {
788788
$to = $v_ftp_user_data['v_ftp_email'];
789789
$subject = _("FTP login credentials");
790-
$hostname = exec('hostname');
790+
$hostname = get_hostname();
791791
$from = "noreply@".$hostname;
792792
$from_name = _('Hestia Control Panel');
793793
$mailtext = sprintf(_('FTP_ACCOUNT_READY'), quoteshellarg($_GET['domain']), $user, $v_ftp_username, $v_ftp_user_data['v_ftp_password']);
@@ -864,7 +864,7 @@
864864

865865
$to = $v_ftp_user_data['v_ftp_email'];
866866
$subject = _("FTP login credentials");
867-
$hostname = exec('hostname');
867+
$hostname = get_hostname();
868868
$from = "noreply@".$hostname;
869869
$from_name = _('Hestia Control Panel');
870870
$mailtext = sprintf(_('FTP_ACCOUNT_READY'), quoteshellarg($_GET['domain']), $user, $v_ftp_username_for_emailing, $v_ftp_user_data['v_ftp_password']);

web/inc/helpers.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,20 @@ function hst_add_history_log($message, $category = 'System', $level = 'Info', $u
134134
return $return_var;
135135
}
136136

137+
function get_hostname(){
138+
$badValues = array(false, null, 0, '', "localhost", "127.0.0.1", "::1", "0000:0000:0000:0000:0000:0000:0000:0001");
139+
$ret = gethostname();
140+
if(in_array($ret, $badValues, true)){
141+
throw new Exception('gethostname() failed');
142+
}
143+
$ret2 = gethostbyname($ret);
144+
if(in_array($ret2, $badValues, true)){
145+
return $ret;
146+
}
147+
$ret3 = gethostbyaddr($ret2);
148+
if(in_array($ret3, $badValues, true)){
149+
return $ret2;
150+
}
151+
return $ret3;
152+
}
153+

web/inc/mail-wrapper.php

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,7 @@
2727

2828
//define vars
2929
//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-
})();
30+
$hostname = get_hostname();
4631

4732
$from = 'noreply@'.$hostname;
4833
$from_name = _('Hestia Control Panel');

web/reset/index.php

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,9 @@
4444
$contact = $data[$user]['CONTACT'];
4545
$to = $data[$user]['CONTACT'];
4646
$subject = sprintf(_('MAIL_RESET_SUBJECT'), date("Y-m-d H:i:s"));
47-
$hostname = exec('hostname');
48-
$hostname_full = exec('hostname -f');
49-
if ($hostname.":".$_SERVER['SERVER_PORT'] == $_SERVER['HTTP_HOST']) {
50-
$check = true;
51-
$hostname_email = $hostname;
52-
}else if ($hostname_full.":".$_SERVER['SERVER_PORT'] == $_SERVER['HTTP_HOST']) {
53-
$check = true;
54-
$hostname_email = $hostname_full;
55-
}else{
56-
$check = false;
57-
$ERROR = "<a class=\"error\">"._('Invalid host domain')."</a>";
58-
}
47+
$hostname = get_hostname();
5948
if ($check == true){
60-
$from = "noreply@".$hostname_email;
49+
$from = "noreply@".$hostname;
6150
$from_name = _('Hestia Control Panel');
6251
if (!empty($name)) {
6352
$mailtext = sprintf(_('GREETINGS_GORDON'), $name);

0 commit comments

Comments
 (0)