Skip to content

Commit da3a0e0

Browse files
authored
Improve hostname detection (hestiacp#3494)
* Remove HTTP_HOST check but depend on hostname received from function * Improve port detection Incase cp.tpl is used. Bu by default it should also default to hostname.domain.com
1 parent 74c227f commit da3a0e0

File tree

1 file changed

+31
-19
lines changed

1 file changed

+31
-19
lines changed

web/reset/index.php

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,29 @@
4949
$to = $data[$user]["CONTACT"];
5050
$subject = sprintf(_("MAIL_RESET_SUBJECT"), date("Y-m-d H:i:s"));
5151
$hostname = get_hostname();
52-
if ($hostname . ":" . $_SERVER["SERVER_PORT"] == $_SERVER["HTTP_HOST"]) {
53-
$check = true;
54-
$hostname_email = $hostname;
55-
} elseif ($hostname_full . ":" . $_SERVER["SERVER_PORT"] == $_SERVER["HTTP_HOST"]) {
56-
$check = true;
57-
$hostname_email = $hostname_full;
58-
} else {
59-
$check = false;
60-
$ERROR = "<p class=\"error\">" . _("Invalid host domain") . "</p>";
61-
}
62-
if ($check == true) {
52+
if ($hostname) {
53+
$host = preg_replace(
54+
"/(\[?[^]]*\]?):([0-9]{1,5})$/",
55+
"$1",
56+
$_SERVER["HTTP_HOST"],
57+
);
58+
if ($host == $hostname) {
59+
$port_is_defined = preg_match(
60+
"/\[?[^]]*\]?:[0-9]{1,5}$/",
61+
$_SERVER["HTTP_HOST"],
62+
);
63+
if ($port_is_defined) {
64+
$port = preg_replace(
65+
"/(\[?[^]]*\]?):([0-9]{1,5})$/",
66+
"$2",
67+
$_SERVER["HTTP_HOST"],
68+
);
69+
} else {
70+
$port = "";
71+
}
72+
} else {
73+
$port = ":" . $_SERVER["SERVER_PORT"];
74+
}
6375
$from = "noreply@" . $hostname;
6476
$from_name = _("Hestia Control Panel");
6577
if (!empty($name)) {
@@ -69,10 +81,10 @@
6981
}
7082
$mailtext .= sprintf(
7183
_("PASSWORD_RESET_REQUEST"),
72-
$_SERVER["HTTP_HOST"],
84+
$hostname . $port,
7385
$user,
7486
$rkey,
75-
$_SERVER["HTTP_HOST"],
87+
$hostname . $port,
7688
$user,
7789
$rkey,
7890
);
@@ -86,13 +98,13 @@
8698
$data[$user]["NAME"],
8799
);
88100
}
89-
$ERROR =
90-
"<p class=\"error\">" .
91-
_(
92-
"Password reset instructions have been sent to the email address associated with this account.",
93-
) .
94-
"</p>";
95101
}
102+
$ERROR =
103+
"<p class=\"error\">" .
104+
_(
105+
"Password reset instructions have been sent to the email address associated with this account.",
106+
) .
107+
"</p>";
96108
} else {
97109
# Prevent user enumeration and let hackers guess username and working email
98110
$ERROR =

0 commit comments

Comments
 (0)