From c6f36f01c83cf435bbc338443a357f81c49cbbca Mon Sep 17 00:00:00 2001
From: Marius Cramer <m.cramer@pixcept.de>
Date: Wed, 20 Nov 2013 09:21:47 -0500
Subject: [PATCH] Implemented FS#2531 - switch from a reseller to a client
---
interface/web/login/login_as.php | 25 ++++++++++++++++++++-----
1 files changed, 20 insertions(+), 5 deletions(-)
diff --git a/interface/web/admin/login_as.php b/interface/web/login/login_as.php
similarity index 75%
rename from interface/web/admin/login_as.php
rename to interface/web/login/login_as.php
index 3d0fbf8..ed2dc9e 100644
--- a/interface/web/admin/login_as.php
+++ b/interface/web/login/login_as.php
@@ -31,11 +31,13 @@
require_once '../../lib/config.inc.php';
require_once '../../lib/app.inc.php';
-/* Check permissions for module */
-$app->auth->check_module_permissions('admin');
+/* check if the user is logged in */
+if(!isset($_SESSION['s']['user'])) {
+ die ("You have to be logged in to login as other user!");
+}
-/* for security reasons ONLY the admin can login as other user */
-if ($_SESSION["s"]["user"]["typ"] != 'admin') {
+/* for security reasons ONLY the admin or a reseller can login as other user */
+if ($_SESSION["s"]["user"]["typ"] != 'admin' && !$app->auth->has_clients($_SESSION['s']['user']['userid'])) {
die ("You don't have the right to login as other user!");
}
@@ -45,13 +47,26 @@
}
if(isset($_GET['id'])) {
+ if($_SESSION["s"]["user"]["typ"] != 'admin') {
+ die ("You don't have the right to login as system user!");
+ }
$userId = $app->functions->intval($_GET['id']);
$backlink = 'admin/users_list.php';
} else {
$client_id = $app->functions->intval($_GET['cid']);
- $tmp_client = $app->db->queryOneRecord("SELECT username FROM client WHERE client_id = $client_id");
+ $tmp_client = $app->db->queryOneRecord("SELECT username, parent_client_id FROM client WHERE client_id = $client_id");
$tmp_sys_user = $app->db->queryOneRecord("SELECT userid FROM sys_user WHERE username = '".$app->db->quote($tmp_client['username'])."'");
$userId = $app->functions->intval($tmp_sys_user['userid']);
+ /* check if this client belongs to reseller that tries to log in, if we are not admin */
+ if($_SESSION["s"]["user"]["typ"] != 'admin') {
+ $client_group_id = $app->functions->intval($_SESSION["s"]["user"]["default_group"]);
+ $client = $app->db->queryOneRecord("SELECT client.client_id FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $client_group_id");
+ if(!$client || $tmp_client["parent_client_id"] != $client["client_id"]) {
+ die("You don't have the right to login as this user!");
+ }
+ unset($client);
+ }
+
unset($tmp_client);
unset($tmp_sys_user);
$backlink = 'client/client_list.php';
--
Gitblit v1.9.1