Skip to content

Commit 19ea994

Browse files
authored
Merge pull request hestiacp#1 from serghey-rodin/master
Update fork
2 parents f014e38 + f5ef047 commit 19ea994

File tree

2 files changed

+57
-47
lines changed

2 files changed

+57
-47
lines changed

web/login/index.php

Lines changed: 56 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -34,62 +34,68 @@
3434

3535
// Basic auth
3636
if (isset($_POST['user']) && isset($_POST['password'])) {
37-
$v_user = escapeshellarg($_POST['user']);
37+
if(isset($_SESSION['token']) && isset($_POST['token']) && $_POST['token'] == $_SESSION['token']) {
38+
$v_user = escapeshellarg($_POST['user']);
3839

39-
// Send password via tmp file
40-
$v_password = exec('mktemp -p /tmp');
41-
$fp = fopen($v_password, "w");
42-
fwrite($fp, $_POST['password']."\n");
43-
fclose($fp);
40+
// Send password via tmp file
41+
$v_password = exec('mktemp -p /tmp');
42+
$fp = fopen($v_password, "w");
43+
fwrite($fp, $_POST['password']."\n");
44+
fclose($fp);
4445

45-
// Check user & password
46-
exec(VESTA_CMD ."v-check-user-password ".$v_user." ".$v_password." ".escapeshellarg($_SERVER['REMOTE_ADDR']), $output, $return_var);
47-
unset($output);
46+
// Check user & password
47+
exec(VESTA_CMD ."v-check-user-password ".$v_user." ".$v_password." ".escapeshellarg($_SERVER['REMOTE_ADDR']), $output, $return_var);
48+
unset($output);
4849

49-
// Remove tmp file
50-
unlink($v_password);
50+
// Remove tmp file
51+
unlink($v_password);
5152

52-
// Check API answer
53-
if ( $return_var > 0 ) {
54-
$ERROR = "<a class=\"error\">".__('Invalid username or password')."</a>";
53+
// Check API answer
54+
if ( $return_var > 0 ) {
55+
$ERROR = "<a class=\"error\">".__('Invalid username or password')."</a>";
5556

56-
} else {
57-
58-
// Make root admin user
59-
if ($_POST['user'] == 'root') $v_user = 'admin';
60-
61-
// Get user speciefic parameters
62-
exec (VESTA_CMD . "v-list-user ".$v_user." json", $output, $return_var);
63-
$data = json_decode(implode('', $output), true);
64-
65-
// Define session user
66-
$_SESSION['user'] = key($data);
67-
$v_user = $_SESSION['user'];
68-
69-
// Get user favorites
70-
get_favourites();
57+
} else {
7158

72-
// Define language
73-
$output = '';
74-
exec (VESTA_CMD."v-list-sys-languages json", $output, $return_var);
75-
$languages = json_decode(implode('', $output), true);
76-
if(in_array($data[$v_user]['LANGUAGE'], $languages)){
77-
$_SESSION['language'] = $data[$v_user]['LANGUAGE'];
78-
}
79-
else {
80-
$_SESSION['language'] = 'en';
81-
}
59+
// Make root admin user
60+
if ($_POST['user'] == 'root') $v_user = 'admin';
8261

62+
// Get user speciefic parameters
63+
exec (VESTA_CMD . "v-list-user ".$v_user." json", $output, $return_var);
64+
$data = json_decode(implode('', $output), true);
8365

84-
// Redirect request to control panel interface
85-
if (!empty($_SESSION['request_uri'])) {
86-
header("Location: ".$_SESSION['request_uri']);
87-
unset($_SESSION['request_uri']);
88-
exit;
89-
} else {
90-
header("Location: /");
91-
exit;
66+
// Define session user
67+
$_SESSION['user'] = key($data);
68+
$v_user = $_SESSION['user'];
69+
70+
// Get user favorites
71+
get_favourites();
72+
73+
// Define language
74+
$output = '';
75+
exec (VESTA_CMD."v-list-sys-languages json", $output, $return_var);
76+
$languages = json_decode(implode('', $output), true);
77+
if(in_array($data[$v_user]['LANGUAGE'], $languages)){
78+
$_SESSION['language'] = $data[$v_user]['LANGUAGE'];
79+
}
80+
else {
81+
$_SESSION['language'] = 'en';
82+
}
83+
84+
// Regenerate session id to prevent session fixation
85+
session_regenerate_id();
86+
87+
// Redirect request to control panel interface
88+
if (!empty($_SESSION['request_uri'])) {
89+
header("Location: ".$_SESSION['request_uri']);
90+
unset($_SESSION['request_uri']);
91+
exit;
92+
} else {
93+
header("Location: /");
94+
exit;
95+
}
9296
}
97+
} else {
98+
$ERROR = "<a class=\"error\">".__('Invalid or missing token')."</a>";
9399
}
94100
}
95101

@@ -119,6 +125,9 @@
119125
}
120126
}
121127

128+
// Generate CSRF token
129+
$_SESSION['token'] = md5(uniqid(mt_rand(), true));
130+
122131
require_once($_SERVER['DOCUMENT_ROOT'].'/inc/i18n/'.$_SESSION['language'].'.php');
123132
require_once('../templates/header.html');
124133
require_once('../templates/login.html');

web/templates/login.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
</td>
1010
<td style="padding: 20px 0 0 0;">
1111
<form method="post" action="/login/" >
12+
<input type="hidden" name="token" value="<?php echo $_SESSION['token']; ?>">
1213
<table class="login-box">
1314
<tr>
1415
<td syle="padding: 12px 0 0 2px;">

0 commit comments

Comments
 (0)