Skip to content

Commit e161b4a

Browse files
committed
Fix autologout issue on cloudflare proxy and rearange 2FA auth part.
1 parent 9bd84c9 commit e161b4a

File tree

4 files changed

+33
-24
lines changed

4 files changed

+33
-24
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ All notable changes to this project will be documented in this file.
2828
- Fixed different permission issues on user restore.
2929
- Stop trying to renew LE certs after multiple consecutive failed attempts. Thanks to @dpeca!
3030
- Implement a validation function to verify the correct version in hestia.conf prior to install a new one.
31+
- Fix autologout issue on cloudflare proxy and rearange 2FA authentification part. Thanks to @rmj-s!
3132
- Roundcube fixes for PHP 7.4 compatibility.
3233

3334
## [1.1.1] - 2020-03-24 - Hotfix

web/inc/main.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@
2929
if(isset($_SERVER['HTTP_FORWARDED'])){
3030
$user_combined_ip .= '|'. $_SERVER['HTTP_FORWARDED'];
3131
}
32+
if(isset($_SERVER['HTTP_CF_CONNECTING_IP'])){
33+
if(!empty($_SERVER['HTTP_CF_CONNECTING_IP'])){
34+
$user_combined_ip = $_SERVER['HTTP_CF_CONNECTING_IP'];
35+
}
36+
}
3237

3338
if(!isset($_SESSION['user_combined_ip'])){
3439
$_SESSION['user_combined_ip'] = $user_combined_ip;
@@ -348,10 +353,10 @@ function list_timezones() {
348353
* Explaination:
349354
* $_SESSION['DB_SYSTEM'] has 'mysql' value even if MariaDB is installed, so you can't figure out is it really MySQL or it's MariaDB.
350355
* So, this function will make it clear.
351-
*
356+
*
352357
* If MySQL is installed, function will return 'mysql' as a string.
353358
* If MariaDB is installed, function will return 'mariadb' as a string.
354-
*
359+
*
355360
* Hint: if you want to check if PostgreSQL is installed - check value of $_SESSION['DB_SYSTEM']
356361
*
357362
* @return string

web/login/index.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@
3838
if(isset($_SESSION['token']) && isset($_POST['token']) && $_POST['token'] == $_SESSION['token']) {
3939
$v_user = escapeshellarg($_POST['user']);
4040
$v_ip = escapeshellarg($_SERVER['REMOTE_ADDR']);
41+
if(isset($_SERVER['HTTP_CF_CONNECTING_IP'])){
42+
if(!empty($_SERVER['HTTP_CF_CONNECTING_IP'])){
43+
$v_ip = escapeshellarg($_SERVER['HTTP_CF_CONNECTING_IP']);
44+
}
45+
}
4146
if (isset($_POST['twofa'])) {
4247
$v_twofa = escapeshellarg($_POST['twofa']);
4348
}

web/templates/login.html

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,8 @@
88
<a href="/"><img border=0 src="/images/logo.png" alt="Hestia Control Panel" style="margin: 20px; margin-top: 40px;" /></a>
99
</td>
1010
<td style="padding: 40px 60px 0 0;">
11-
<form method="post" action="/login/" >
11+
<form method="post" action="/login/" id="form_login">
1212
<input type="hidden" name="token" value="<?php echo $_SESSION['token']; ?>">
13-
<script>
14-
function show2FA(str) {
15-
if (str.length == 0) {
16-
$('.twofa').fadeOut();
17-
return;
18-
} else {
19-
var xmlhttp = new XMLHttpRequest();
20-
xmlhttp.onreadystatechange = function() {
21-
if (this.readyState == 4 && this.status == 200) {
22-
var x = document.getElementById("twofa");
23-
$('.twofa').fadeIn();
24-
} else {
25-
$('.twofa').fadeOut();
26-
}
27-
};
28-
xmlhttp.open("GET", "/inc/2fa/active.php?user=" + str, true);
29-
xmlhttp.send();
30-
}
31-
}
32-
</script>
3313
<table class="login-box">
3414
<tr>
3515
<td syle="padding: 12px 0 0 2px;" class="login-welcome">
@@ -43,7 +23,7 @@
4323
</tr>
4424
<tr>
4525
<td>
46-
<input tabindex="1" type="text" size="20px" style="width:240px;" name="user" class="vst-input" onfocusout="show2FA(this.value)">
26+
<input tabindex="1" type="text" size="20px" style="width:240px;" name="user" class="vst-input">
4727
</td>
4828
</tr>
4929
<tr>
@@ -100,5 +80,23 @@
10080
</tr>
10181
</table>
10282
</center>
83+
<script type="text/javascript">
84+
$(document).ready(function () {
85+
$('#form_login').on('input', 'input[name="user"]', function() {
86+
var username = this.value;
87+
$.ajax({
88+
type: 'GET',
89+
url: '/inc/2fa/active.php?user=' + username,
90+
complete: function(xhr) {
91+
if(xhr.status == '200'){
92+
$('.twofa').show();
93+
}else if(xhr.status == '404'){
94+
$('.twofa').hide();
95+
}
96+
}
97+
});
98+
});
99+
});
100+
</script>
103101
</body>
104102
</html>

0 commit comments

Comments
 (0)