Skip to content

Commit e189251

Browse files
authored
Move HTML error (hestiacp#3553)
1 parent 9bed324 commit e189251

File tree

9 files changed

+56
-54
lines changed

9 files changed

+56
-54
lines changed

web/inc/main.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -245,12 +245,6 @@ function show_alert_message($data) {
245245
}
246246
}
247247

248-
function show_error_message($error) {
249-
if (isset($error)) {
250-
echo $error;
251-
}
252-
}
253-
254248
function top_panel($user, $TAB) {
255249
$command = HESTIA_CMD . "v-list-user " . $user . " 'json'";
256250
exec($command, $output, $return_var);

web/login/index.php

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,11 @@ function authenticate_user($user, $password, $twofa = "") {
135135
if ($return_var > 0) {
136136
sleep(2);
137137
if ($return_var == 5) {
138-
$error = '<p class="error">' . _("Account has been suspended") . "</p>";
138+
$error = _("Account has been suspended");
139139
} elseif ($return_var == 1) {
140-
$error = '<p class="error">' . _("Unsupported hash method") . "</p>";
140+
$error = _("Unsupported hash method");
141141
} else {
142-
$error = '<p class="error">' . _("Invalid username or password") . "</p>";
142+
$error = _("Invalid username or password");
143143
}
144144
return $error;
145145
} else {
@@ -196,7 +196,7 @@ function authenticate_user($user, $password, $twofa = "") {
196196
// Check API answer
197197
if ($return_var > 0) {
198198
sleep(2);
199-
$error = '<p class="error">' . _("Invalid username or password") . "</p>";
199+
$error = _("Invalid username or password");
200200
$v_session_id = quoteshellarg($_POST["token"]);
201201
exec(
202202
HESTIA_CMD .
@@ -219,7 +219,7 @@ function authenticate_user($user, $password, $twofa = "") {
219219
unset($output);
220220
if ($data[$user]["LOGIN_DISABLED"] === "yes") {
221221
sleep(2);
222-
$error = '<p class="error">' . _("Invalid username or password") . "</p>";
222+
$error = _("Invalid username or password");
223223
$v_session_id = quoteshellarg($_POST["token"]);
224224
exec(
225225
HESTIA_CMD .
@@ -243,7 +243,7 @@ function authenticate_user($user, $password, $twofa = "") {
243243
$v_login_user_allowed_ips = array_map("trim", $v_login_user_allowed_ips);
244244
if (!in_array($ip, $v_login_user_allowed_ips, true)) {
245245
sleep(2);
246-
$error = '<p class="error">' . _("Invalid username or password") . "</p>";
246+
$error = _("Invalid username or password");
247247
$v_session_id = quoteshellarg($_POST["token"]);
248248
exec(
249249
HESTIA_CMD .
@@ -269,7 +269,7 @@ function authenticate_user($user, $password, $twofa = "") {
269269
$output,
270270
$return_var,
271271
);
272-
$error = "<p class=\"error\">" . _("Invalid or missing 2FA token") . "</p>";
272+
$error = "<p class=\"error\">" . _("Invalid or missing 2FA token");
273273
if (empty($twofa)) {
274274
$_SESSION["login"]["username"] = $user;
275275
$_SESSION["login"]["password"] = $password;
@@ -284,8 +284,7 @@ function authenticate_user($user, $password, $twofa = "") {
284284
unset($output);
285285
if ($return_var > 0) {
286286
sleep(2);
287-
$error =
288-
'<p class="error">' . _("Invalid or missing 2FA token") . "</p>";
287+
$error = _("Invalid or missing 2FA token");
289288
$_SESSION["login"]["username"] = $user;
290289
$_SESSION["login"]["password"] = $password;
291290
$v_session_id = quoteshellarg($_POST["token"]);

web/reset/index.php

Lines changed: 18 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -132,42 +132,27 @@
132132

133133
send_email($to, $subject, $mailtext, $from, $from_name, $data[$user]["NAME"]);
134134
putenv("LANGUAGE=" . detect_user_language());
135-
$error =
136-
"<p class=\"error\">" .
137-
_(
138-
"Password reset instructions have been sent to the email address associated with this account.",
139-
) .
140-
"</p>";
141-
}
142-
$ERROR =
143-
"<p class=\"error\">" .
144-
_(
135+
$error = _(
145136
"Password reset instructions have been sent to the email address associated with this account.",
146-
) .
147-
"</p>";
137+
);
138+
}
139+
$error = _(
140+
"Password reset instructions have been sent to the email address associated with this account.",
141+
);
148142
} else {
149143
# Prevent user enumeration and let hackers guess username and working email
150-
$error =
151-
"<p class=\"error\">" .
152-
_(
153-
"Password reset instructions have been sent to the email address associated with this account.",
154-
) .
155-
"</p>";
144+
$error = _(
145+
"Password reset instructions have been sent to the email address associated with this account.",
146+
);
156147
}
157148
} else {
158-
$error =
159-
"<p class=\"error\">" .
160-
_("Please wait 15 minutes before sending a new request.") .
161-
"</p>";
149+
$error = _("Please wait 15 minutes before sending a new request.");
162150
}
163151
} else {
164152
# Prevent user enumeration and let hackers guess username and working email
165-
$error =
166-
"<p class=\"error\">" .
167-
_(
168-
"Password reset instructions have been sent to the email address associated with this account.",
169-
) .
170-
"</p>";
153+
$error = _(
154+
"Password reset instructions have been sent to the email address associated with this account.",
155+
);
171156
}
172157
unset($output);
173158
}
@@ -198,15 +183,15 @@
198183
unlink($v_password);
199184
if ($return_var > 0) {
200185
sleep(5);
201-
$ERROR = "<p class=\"error\">" . _("An internal error occurred") . "</p>";
186+
$error = _("An internal error occurred");
202187
} else {
203188
$_SESSION["user"] = $_POST["user"];
204189
header("Location: /");
205190
exit();
206191
}
207192
} else {
208193
sleep(5);
209-
$ERROR = "<p class=\"error\">" . _("Code has been expired") . "</p>";
194+
$error = _("Code has been expired");
210195
exec(
211196
HESTIA_CMD .
212197
"v-log-user-login " .
@@ -224,7 +209,7 @@
224209
}
225210
} else {
226211
sleep(5);
227-
$ERROR = "<p class=\"error\">" . _("Invalid username or code") . "</p>";
212+
$error = _("Invalid username or code");
228213
exec(
229214
HESTIA_CMD .
230215
"v-log-user-login " .
@@ -242,10 +227,10 @@
242227
}
243228
} else {
244229
sleep(5);
245-
$error = "<p class=\"error\">" . _("Invalid username or code") . "</p>";
230+
$error = _("Invalid username or code");
246231
}
247232
} else {
248-
$error = "<p class=\"error\">" . _("Passwords not match") . "</p>";
233+
$error = _("Passwords do not match");
249234
}
250235
}
251236

web/templates/pages/login/login.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@
77
<h1 class="login-title">
88
<?= sprintf(_("Welcome to %s"),htmlentities($_SESSION['APP_NAME'])) ?>
99
</h1>
10-
<?php if(!empty($error)){ show_error_message($error); } ?>
10+
<?php if(!empty($error)){
11+
?>
12+
<p class="error"><?=$error;?></p>
13+
<?php
14+
} ?>
1115
<div class="u-mb20">
1216
<label for="user" class="form-label"><?= _("Username") ?></label>
1317
<input type="text" class="form-control" name="user" id="user" required autofocus>

web/templates/pages/login/login_2.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@
77
<h1 class="login-title">
88
<?= _("Two-factor Authentication") ?>
99
</h1>
10-
<?php if(!empty($error){ show_error_message($error); } ?>
10+
<?php if(!empty($error)){
11+
?>
12+
<p class="error"><?=$error;?></p>
13+
<?php
14+
} ?>
1115
<div class="u-mb20">
1216
<label for="twofa" class="form-label u-side-by-side">
1317
<?= _("2FA Token") ?>

web/templates/pages/login/login_a.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@
77
<h1 class="login-title">
88
<?= sprintf(_("Welcome to %s"),htmlentities($_SESSION['APP_NAME'])) ?>
99
</h1>
10-
<?php if(!empty($error)){ show_error_message($error); } ?>
10+
<?php if(!empty($error)){
11+
?>
12+
<p class="error"><?=$error;?></p>
13+
<?php
14+
} ?>
1115
<div class="u-mb10">
1216
<label for="user" class="form-label"><?= _("Username") ?></label>
1317
<input type="text" class="form-control" name="user" id="user" required autofocus>

web/templates/pages/login/reset2fa.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@
2020
<h1 class="login-title">
2121
<?= _("Unlock Account") ?>
2222
</h1>
23-
<?php if(!empty($error){ show_error_message($error);} ?>
23+
<?php if(!empty($error)){
24+
?>
25+
<p class="error"><?=$error;?></p>
26+
<?php
27+
} ?>
2428
<div class="u-mb10">
2529
<label for="user" class="form-label"><?= _("Username") ?></label>
2630
<input type="text" class="form-control" name="user" id="user" required>

web/templates/pages/login/reset_1.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@
77
<h1 class="login-title">
88
<?= _("Forgot Password") ?>
99
</h1>
10-
<?php if(!empty($error)){ show_error_message($error); } ?>
10+
<?php if(!empty($error)){
11+
?>
12+
<p class="error"><?=$error;?></p>
13+
<?php
14+
} ?>
1115
<div class="u-mb10">
1216
<label for="user" class="form-label"><?= _("Username") ?></label>
1317
<input type="text" class="form-control" name="user" id="user" required>

web/templates/pages/login/reset_3.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@
66
<h1 class="login-title">
77
<?= _("Forgot Password") ?>
88
</h1>
9-
<?php if(!empty($error){ show_error_message($error); } ?>
9+
<?php if(!empty($error)){
10+
?>
11+
<p class="error"><?=$error;?></p>
12+
<?php
13+
} ?>
1014
<div class="u-mb10">
1115
<input type="hidden" name="action" value="confirm">
1216
<input type="hidden" name="token" value="<?= htmlentities($_SESSION["token"]) ?>">

0 commit comments

Comments
 (0)