|
6 | 6 |
|
7 | 7 | $TAB = 'login'; |
8 | 8 |
|
| 9 | +/* |
9 | 10 | // Logout |
10 | 11 | if (isset($_GET['logout'])) { |
11 | 12 | setcookie('limit2fa','',time() - 3600,"/"); |
12 | 13 | session_destroy(); |
13 | 14 | } |
| 15 | +*/ |
14 | 16 |
|
15 | | -// Login as someone else |
| 17 | +/* ACTIONS FOR CURRENT USER SESSION */ |
16 | 18 | if (isset($_SESSION['user'])) { |
17 | 19 |
|
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 |
26 | 24 | if ((!$_GET['token']) || ($_SESSION['token'] != $_GET['token'])) { |
27 | 25 | header('location: /list/user/'); |
28 | 26 | exit(); |
29 | 27 | } 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); |
31 | 30 | if ( $return_var == 0 ) { |
32 | 31 | $data = json_decode(implode('', $output), true); |
33 | 32 | reset($data); |
34 | 33 | $_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 |
37 | 35 | unset($_SESSION['_sf2_attributes']); |
38 | 36 | unset($_SESSION['_sf2_meta']); |
| 37 | + header("Location: /login/"); |
39 | 38 | } |
40 | 39 | } |
| 40 | + exit; |
41 | 41 | } |
42 | 42 |
|
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; |
48 | 85 | } |
| 86 | + |
49 | 87 | exit; |
50 | 88 | } |
51 | 89 |
|
@@ -177,7 +215,7 @@ function authenticate_user($user, $password, $twofa = ''){ |
177 | 215 | } else if ($data[$user]['BACKUPS'] != "0") { |
178 | 216 | header("Location: /list/backup/"); |
179 | 217 | } else { |
180 | | - header("Location: /list/web/"); |
| 218 | + header("Location: /error/"); |
181 | 219 | } |
182 | 220 | } |
183 | 221 | exit; |
|
0 commit comments