Skip to content

Commit 8023d4f

Browse files
author
Kristan Kenney
committed
Set correct view when impersonating users
1 parent 88c1bc6 commit 8023d4f

File tree

3 files changed

+60
-19
lines changed

3 files changed

+60
-19
lines changed

web/inc/main.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,10 @@ function top_panel($user, $TAB) {
160160

161161
// Set home location URLs
162162
if (($_SESSION['userContext'] === 'admin') && (!isset($_SESSION['look']))) {
163+
// Display users list for administrators unless they are impersonating a user account
163164
$home_url = "/list/user/";
164165
} else {
166+
// Set home location URL based on available package features from account
165167
if($panel[$user]['WEB_DOMAINS'] != "0") {
166168
$home_url = "/list/web/";
167169
} else if ($panel[$user]['DNS_DOMAINS'] != "0") {

web/login/index.php

Lines changed: 56 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,46 +6,84 @@
66

77
$TAB = 'login';
88

9+
/*
910
// Logout
1011
if (isset($_GET['logout'])) {
1112
setcookie('limit2fa','',time() - 3600,"/");
1213
session_destroy();
1314
}
15+
*/
1416

15-
// Login as someone else
17+
/* ACTIONS FOR CURRENT USER SESSION */
1618
if (isset($_SESSION['user'])) {
1719

18-
// Default location
19-
if (empty($_GET['loginas']) ){
20-
header("Location: /list/web/");
21-
exit;
22-
}
23-
24-
if ($_SESSION['userContext'] === 'admin' && !empty($_GET['loginas'])) {
25-
// Ensure token is passed and matches before granting user impersonation
20+
// User impersonation
21+
// Allow administrators to view and manipulate contents of other user accounts
22+
if (($_SESSION['userContext'] === 'admin') && (!empty($_GET['loginas']))) {
23+
// Ensure token is passed and matches before granting user impersonation access
2624
if ((!$_GET['token']) || ($_SESSION['token'] != $_GET['token'])) {
2725
header('location: /list/user/');
2826
exit();
2927
} else {
30-
exec (HESTIA_CMD . "v-list-user ".escapeshellarg($_GET['loginas'])." json", $output, $return_var);
28+
$v_user = escapeshellarg($_GET['loginas']);
29+
exec (HESTIA_CMD . "v-list-user ".$v_user." json", $output, $return_var);
3130
if ( $return_var == 0 ) {
3231
$data = json_decode(implode('', $output), true);
3332
reset($data);
3433
$_SESSION['look'] = key($data);
35-
$_SESSION['look_alert'] = 'yes';
36-
# Remove current path for filemanager
34+
// Reset account details for File Manager to impersonated user
3735
unset($_SESSION['_sf2_attributes']);
3836
unset($_SESSION['_sf2_meta']);
37+
header("Location: /login/");
3938
}
4039
}
40+
exit;
4141
}
4242

43-
// Set correct entry point into the panel
44-
if ($_SESSION['userContext'] === 'admin' && empty($_GET['loginas'])) {
45-
header("Location: /list/user/");
46-
} else {
47-
header("Location: /list/web/");
43+
// Set view based on account properties
44+
if (empty($_GET['loginas'])) {
45+
// Default view to Users list for administrator accounts
46+
if (($_SESSION['userContext'] === 'admin') && (!isset($_SESSION['look']))) {
47+
header("Location: /list/user/");
48+
exit;
49+
}
50+
51+
// Obtain account properties
52+
if (($_SESSION['userContext'] === 'admin') && (isset($_SESSION['look']))) {
53+
$v_user = escapeshellarg($_SESSION['look']);
54+
} else {
55+
$v_user = escapeshellarg($_SESSION['user']);
56+
}
57+
58+
exec (HESTIA_CMD . "v-list-user ".$v_user." json", $output, $return_var);
59+
$data = json_decode(implode('', $output), true);
60+
unset($output);
61+
62+
// Determine package features and land user at the first available page
63+
if ($data[$user]['WEB_DOMAINS'] !== "0") {
64+
header("Location: /list/web/");
65+
} else if ($data[$user]['DNS_DOMAINS'] !== "0") {
66+
header("Location: /list/dns/");
67+
} else if ($data[$user]['MAIL_DOMAINS'] !== "0") {
68+
header("Location: /list/mail/");
69+
} else if ($data[$user]['DATABASES'] !== "0") {
70+
header("Location: /list/db/");
71+
} else if ($data[$user]['CRON_JOBS'] !== "0") {
72+
header("Location: /list/cron/");
73+
} else if ($data[$user]['BACKUPS'] !== "0") {
74+
header("Location: /list/backup/");
75+
} else {
76+
header("Location: /error/");
77+
}
78+
exit;
79+
}
80+
81+
// Do not allow non-administrators to access account impersonation
82+
if (($_SESSION['userContext'] !== 'admin') && (!empty($_GET['loginas']))) {
83+
header("Location: /login/");
84+
exit;
4885
}
86+
4987
exit;
5088
}
5189

@@ -177,7 +215,7 @@ function authenticate_user($user, $password, $twofa = ''){
177215
} else if ($data[$user]['BACKUPS'] != "0") {
178216
header("Location: /list/backup/");
179217
} else {
180-
header("Location: /list/web/");
218+
header("Location: /error/");
181219
}
182220
}
183221
exit;

web/logout/index.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55

66
if (!empty($_SESSION['look'])) {
77
unset($_SESSION['look']);
8-
unset($_SESSION['look_alert']);
8+
unset($_SESSION['LANDING_POINT_SOURCE']);
9+
unset($_SESSION['LANDING_POINT_VAR_DATA']);
910
# Remove current path for filemanager
1011
unset($_SESSION['_sf2_attributes']);
1112
unset($_SESSION['_sf2_meta']);

0 commit comments

Comments
 (0)