vcl-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jftho...@apache.org
Subject svn commit: r1779664 - in /vcl/trunk/web/.ht-inc: privileges.php utils.php xmlrpcWrappers.php
Date Fri, 20 Jan 2017 18:21:46 GMT
Author: jfthomps
Date: Fri Jan 20 18:21:45 2017
New Revision: 1779664

URL: http://svn.apache.org/viewvc?rev=1779664&view=rev
Log:
VCL-1006 - performance improvements for 2.5

privileges.php:
-added conditionals to skip configAdmin user privilege in several places in these functions:
viewNodes, selectNode, and getUserPrivRowHTML
-changed uses of array_key_exists to isset in these functions: printUserPrivRow, getUserPrivRowHTML,
getResourcePrivRowHTML, getNodePrivileges, getNodeCascadePrivileges, AJchangeUserPrivs, AJchangeUserGroupPrivs,
AJsubmitAddUserGroupPriv, and AJsubmitAddResourcePriv
-reverted a few places that were mistakingly changed from in_array to isset in these functions:
AJchangeResourcePrivs, AJsubmitAddUserPriv, AJsubmitAddUserGroupPriv, AJsubmitAddResourcePriv,
and checkUserHasPriv
-modified AJchangeResourcePrivs: fixed issue preventing setting a resource attribute at a
node where the same attribute was being blocked from being cascaded down

xmlrpcWrappers.php:
-changed uses of array_key_exists to isset in XMLRPCgetResourceGroupPrivs and _XMLRPCchangeResourceGroupPriv_sub

utils.php:
-removed places where subarrays were created by calling array() in these functions since it
is unnecessary: getImages, getChildNodes, getResourceGroupMemberships, getResourceGroupMembers,
findAvailableTimes
-changed uses of array_key_exists to isset in these functions: getImages, getServerProfiles,
getServerProfileImages, getImageConnectMethods, getImageConnectMethodTexts, getProductionRevisionid,
removeNoCheckout, getUserResources, getUserResourcesUp, addNodeUserResourcePrivs, addOwnedResources,
addOwnedResourceGroups, getParentNodes, getChildNodes, getUserGroups, getResourceGroupMembers,
getUserUnityID, checkUserHasPerm, findAvailableTimes, selectInputHTML, prettyDatetime, getMaintItemsForTimeTable,
getNodeInfo, and sortKeepIndex
-changed uses of foreach(array_keys(...) as $) to foreach(... as $ => $tmp) in these functions:
getUserResourcesDown, addNodeUserResourcePrivs
-modified getImageConnectMethods: split query to get all methods from a single query to a
temporary table with 3 individual queries due to slowness caused by the OR's in the conditional
of the "LEFT JOIN connectmethodmap"

Modified:
    vcl/trunk/web/.ht-inc/privileges.php
    vcl/trunk/web/.ht-inc/utils.php
    vcl/trunk/web/.ht-inc/xmlrpcWrappers.php

Modified: vcl/trunk/web/.ht-inc/privileges.php
URL: http://svn.apache.org/viewvc/vcl/trunk/web/.ht-inc/privileges.php?rev=1779664&r1=1779663&r2=1779664&view=diff
==============================================================================
--- vcl/trunk/web/.ht-inc/privileges.php (original)
+++ vcl/trunk/web/.ht-inc/privileges.php Fri Jan 20 18:21:45 2017
@@ -364,8 +364,11 @@ function viewNodes() {
 	print "    <TD></TD>\n";
 	print "    <TH class=\"privBlock\" bgcolor=gray style=\"color: black;\">Block<br>Cascaded<br>Rights</TH>\n";
 	print "    <TH class=\"privCascade\" bgcolor=\"#008000\" style=\"color: black;\">Cascade<br>to
Child<br>Nodes</TH>\n";
-	foreach($usertypes["users"] as $type)
+	foreach($usertypes["users"] as $type) {
+		if($type == 'configAdmin')
+			continue;
 		print "    <TH class=\"privheader\"><div><span>$type</span></div></TH>\n";
+	}
 	print "  </TR>\n";
 	print "  <TR>\n";
 	print "    <TD><INPUT type=text id=newuser name=newuser size=15";
@@ -384,6 +387,8 @@ function viewNodes() {
 	# normal rights
 	$j = 1;
 	foreach($usertypes["users"] as $type) {
+		if($type == 'configAdmin')
+			continue;
 		print "    <TD align=center id=usercell0:$j><INPUT type=checkbox ";
 		print "dojoType=dijit.form.CheckBox name=\"$type\" id=userck0:$j></TD>\n";
 		$j++;
@@ -428,8 +433,11 @@ function viewNodes() {
 	print "    <TD></TD>\n";
 	print "    <TH class=\"privBlock\" bgcolor=gray style=\"color: black;\">Block<br>Cascaded<br>Rights</TH>\n";
 	print "    <TH class=\"privCascade\" bgcolor=\"#008000\" style=\"color: black;\">Cascade<br>to
Child<br>Nodes</TH>\n";
-	foreach($usertypes["users"] as $type)
+	foreach($usertypes["users"] as $type) {
+		if($type == 'configAdmin')
+			continue;
 		print "    <TH class=\"privheader\"><div><span>$type</span></div></TH>\n";
+	}
 	print "  </TR>\n";
 	print "  <TR>\n";
 	print "    <TD>\n";
@@ -450,6 +458,8 @@ function viewNodes() {
 	# normal rights
 	$j = 1;
 	foreach($usertypes["users"] as $type) {
+		if($type == 'configAdmin')
+			continue;
 		print "    <TD align=center id=usergrpcell0:$j><INPUT type=checkbox ";
 		print "dojoType=dijit.form.CheckBox name=\"$type\" id=usergrpck0:$j></TD>\n";
 		$j++;
@@ -889,8 +899,11 @@ function selectNode() {
 		$text .= "    <TD></TD>";
 		$text .= "    <TH class=\"privBlock\" bgcolor=gray style=\"color: black;\">Block<br>Cascaded<br>Rights</TH>";
 		$text .= "    <TH class=\"privCascade\" bgcolor=\"#008000\" style=\"color: black;\">Cascade<br>to
Child<br>Nodes</TH>";
-		foreach($usertypes["users"] as $type)
+		foreach($usertypes["users"] as $type) {
+			if($type == 'configAdmin')
+				continue;
 			$text .= "    <TH class=\"privheader\"><div><span>$type</span></div></TH>";
+		}
 		$text .= "  </TR>";
 		$users = array_unique(array_merge(array_keys($privs["users"]), 
 		                      array_keys($cascadePrivs["users"])));
@@ -937,8 +950,11 @@ function selectNode() {
 		$text .= "    <TD></TD>";
 		$text .= "    <TH class=\"privBlock\" bgcolor=gray style=\"color: black;\">Block<br>Cascaded<br>Rights</TH>";
 		$text .= "    <TH class=\"privCascade\" bgcolor=\"#008000\" style=\"color: black;\">Cascade<br>to
Child<br>Nodes</TH>";
-		foreach($usertypes["users"] as $type)
+		foreach($usertypes["users"] as $type) {
+			if($type == 'configAdmin')
+				continue;
 			$text .= "    <TH class=\"privheader\"><div><span>$type</span></div></TH>";
+		}
 		$text .= "  </TR>";
 		$groupids = array_unique(array_merge(array_keys($privs["usergroups"]), 
 		                         array_keys($cascadePrivs["usergroups"])));
@@ -2171,7 +2187,7 @@ function printUserPrivRow($privname, $ro
 		$disabled = '';
 
 	# block rights
-	if(array_key_exists($privname, $privs) && 
+	if(isset($privs[$privname]) && 
 	   (($usergroup == 'user' &&
 	   isset($privs[$privname]['block'])) ||
 	   ($usergroup == 'group' &&
@@ -2198,7 +2214,7 @@ function printUserPrivRow($privname, $ro
 	print "$count, 1, $usergroup);\" $checked $disabled></TD>\n";
 
 	#cascade rights
-	if(array_key_exists($privname, $privs) && 
+	if(isset($privs[$privname]) && 
 	   (($usergroup == 1 &&
 	   isset($privs[$privname]['cascade'])) ||
 	   ($usergroup == 2 &&
@@ -2221,17 +2237,17 @@ function printUserPrivRow($privname, $ro
 		$checked = "";
 		$value = "";
 		$cascaded = 0;
-		if(array_key_exists($privname, $cascadeprivs) && 
+		if(isset($cascadeprivs[$privname]) && 
 		   (($usergroup == 1 &&
 		   isset($cascadeprivs[$privname][$type])) ||
 		   ($usergroup == 2 &&
 		   isset($cascadeprivs[$privname]['privs'][$type])))) {
-			$bgcolor = "class=\"privCascade\" bgcolor=\"#008000\"";
+			$bgcolor = "class=\"privCascade\"";
 			$checked = "checked";
 			$value = "value=cascade";
 			$cascaded = 1;
 		}
-		if(array_key_exists($privname, $privs) && 
+		if(isset($privs[$privname]) && 
 		   (($usergroup == 1 &&
 		   isset($privs[$privname][$type])) ||
 		   ($usergroup == 2 &&
@@ -2304,7 +2320,7 @@ function getUserPrivRowHTML($privname, $
 		$disabled = '';
 
 	# block rights
-	if(array_key_exists($privname, $privs) && 
+	if(isset($privs[$privname]) && 
 	   (($usergroup == 'user' &&
 	   isset($privs[$privname]["block"])) ||
 	   ($usergroup == 'group' &&
@@ -2328,7 +2344,7 @@ function getUserPrivRowHTML($privname, $
 	$text .= "(this.checked, $rownum, $count, 1, $usergroup)\"></TD>";
 
 	#cascade rights
-	if(array_key_exists($privname, $privs) && 
+	if(isset($privs[$privname]) && 
 	   (($usergroup == 1 &&
 	   isset($privs[$privname]["cascade"])) ||
 	   ($usergroup == 2 &&
@@ -2345,21 +2361,23 @@ function getUserPrivRowHTML($privname, $
 	# normal rights
 	$j = 1;
 	foreach($types as $type) {
+		if($type == 'configAdmin')
+			continue;
 		$bgcolor = "";
 		$checked = "";
 		$value = "";
 		$cascaded = 0;
-		if(array_key_exists($privname, $cascadeprivs) && 
+		if(isset($cascadeprivs[$privname]) && 
 		   (($usergroup == 1 &&
 		   isset($cascadeprivs[$privname][$type])) ||
 		   ($usergroup == 2 &&
 		   isset($cascadeprivs[$privname]['privs'][$type])))) {
-			$bgcolor = "class=\"privCascade\" bgcolor=\"#008000\"";
+			$bgcolor = "class=\"privCascade\"";
 			$checked = "checked";
 			$value = "value=cascade";
 			$cascaded = 1;
 		}
-		if(array_key_exists($privname, $privs) && 
+		if(isset($privs[$privname]) && 
 		   (($usergroup == 1 &&
 		   isset($privs[$privname][$type])) ||
 		   ($usergroup == 2 &&
@@ -2483,8 +2501,7 @@ function getResourcePrivRowHTML($privnam
 		$disabled = '';
 
 	# block rights
-	if(array_key_exists($privname, $privs) && 
-	   isset($privs[$privname]["block"])) {
+	if(isset($privs[$privname]["block"])) {
 		$checked = "checked";
 		$blocked = 1;
 	}
@@ -2500,8 +2517,7 @@ function getResourcePrivRowHTML($privnam
 	$text .= "(this.checked, $rownum, $count, 1, 3)\"></TD>\n";
 
 	#cascade rights
-	if(array_key_exists($privname, $privs) && 
-	   isset($privs[$privname]["cascade"]))
+	if(isset($privs[$privname]["cascade"]))
 		$checked = "checked";
 	else
 		$checked = "";
@@ -2520,15 +2536,13 @@ function getResourcePrivRowHTML($privnam
 		$checked = "";
 		$value = "";
 		$cascaded = 0;
-		if(array_key_exists($privname, $cascadeprivs) && 
-		   isset($cascadeprivs[$privname][$type])) {
-			$bgcolor = "class=\"privCascade\" bgcolor=\"#008000\"";
+		if(isset($cascadeprivs[$privname][$type])) {
+			$bgcolor = "class=\"privCascade\"";
 			$checked = "checked";
 			$value = "value=cascade";
 			$cascaded = 1;
 		}
-		if(array_key_exists($privname, $privs) && 
-		   isset($privs[$privname][$type])) {
+		if(isset($privs[$privname][$type])) {
 			if($cascaded) {
 				$value = "value=cascadesingle";
 			}
@@ -2671,7 +2685,7 @@ function jsonGetResourceGroupMembers() {
 function getNodePrivileges($node, $type="all", $privs=0) {
 	global $user;
 	$key = getKey(array($node, $type, $privs));
-	if(array_key_exists($key, $_SESSION['nodeprivileges']))
+	if(isset($_SESSION['nodeprivileges'][$key]))
 		return $_SESSION['nodeprivileges'][$key];
 	if(! $privs)
 		$privs = array("resources" => array(),
@@ -2692,16 +2706,14 @@ function getNodePrivileges($node, $type=
 		       . "ORDER BY p.privnodeid";
 		$qh = doQuery($query, 350);
 		while($row = mysql_fetch_assoc($qh)) {
-			if(! array_key_exists($row['privnodeid'], $resourcedata))
-				$resourcedata[$row['privnodeid']] = array();
 			$resourcedata[$row['privnodeid']][] = $row;
 		}
 	}
 	if($type == "resources" || $type == "all") {
-		if(array_key_exists($node, $resourcedata)) {
+		if(isset($resourcedata[$node])) {
 			foreach($resourcedata[$node] as $data) {
 				$name = "{$data["type"]}/{$data["name"]}/{$data["id"]}";
-				$privs["resources"][$name][] = $data["privtype"];
+				$privs["resources"][$name][$data["privtype"]] = 1;
 			}
 		}
 	}
@@ -2739,7 +2751,7 @@ function getNodePrivileges($node, $type=
 		       . "ORDER BY g.name";
 		$qh = doQuery($query, 352);
 		while($row = mysql_fetch_assoc($qh)) {
-			if(array_key_exists($row["id"], $privs["usergroups"]))
+			if(isset($privs["usergroups"][$row["id"]]))
 				$privs["usergroups"][$row["id"]]['privs'][$row['priv']] = 1;
 			else
 				$privs["usergroups"][$row["id"]] = array('id' => $row['id'],
@@ -2797,7 +2809,7 @@ function getNodePrivileges($node, $type=
 ////////////////////////////////////////////////////////////////////////////////
 function getNodeCascadePrivileges($node, $type="all", $privs=0) {
 	$key = getKey(array($node, $type, $privs));
-	if(array_key_exists($key, $_SESSION['cascadenodeprivileges']))
+	if(isset($_SESSION['cascadenodeprivileges'][$key]))
 		return $_SESSION['cascadenodeprivileges'][$key];
 	if(! $privs)
 		$privs = array("resources" => array(),
@@ -2822,7 +2834,7 @@ function getNodeCascadePrivileges($node,
 		       .       "p.type = 'block'";
 		$qh = doQuery($query);
 		while($row = mysql_fetch_assoc($qh)) {
-			if(! array_key_exists($row['privnodeid'], $allblockdata))
+			if(! isset($allblockdata[$row['privnodeid']]))
 				$allblockdata[$row['privnodeid']] = array();
 			# TODO adding the id at the end will fix the bug where blocking cascaded resource
 			#   privileges are only blocked at the node and the block is not cascaded to
@@ -2836,7 +2848,7 @@ function getNodeCascadePrivileges($node,
 	$inlist = implode(',', $nodelist);
 	$blockdata = array();
 	foreach($nodelist as $nodeid) {
-		if(array_key_exists($nodeid, $allblockdata))
+		if(isset($allblockdata[$nodeid]))
 			$blockdata[$nodeid] = $allblockdata[$nodeid];
 	}
 
@@ -2861,7 +2873,7 @@ function getNodeCascadePrivileges($node,
 		       .       "p2.type = 'cascade'";
 		$qh = doQuery($query);
 		while($row = mysql_fetch_assoc($qh)) {
-			if(! array_key_exists($row['privnodeid'], $allcascadedata))
+			if(! isset($allcascadedata[$row['privnodeid']]))
 				$allcascadedata[$row['privnodeid']] = array();
 			$allcascadedata[$row['privnodeid']][] =
 			   array('name' => "{$row["type"]}/{$row["name"]}/{$row["id"]}",
@@ -2872,7 +2884,7 @@ function getNodeCascadePrivileges($node,
 	# get all privs for users with cascaded privs
 	$cascadedata = array();
 	foreach($nodelist as $nodeid) {
-		if(array_key_exists($nodeid, $allcascadedata))
+		if(isset($allcascadedata[$nodeid]))
 			$cascadedata[$nodeid] = $allcascadedata[$nodeid];
 	}
 
@@ -2882,13 +2894,13 @@ function getNodeCascadePrivileges($node,
 		while(count($mynodelist)) {
 			$mynode = array_pop($mynodelist);
 			# get all resource groups with block set at this node and remove any cascaded privs
-			if(array_key_exists($mynode, $blockdata)) {
+			if(isset($blockdata[$mynode])) {
 				foreach($blockdata[$mynode] as $name)
 					unset($privs["resources"][$name]);
 			}
 
 			# get all privs for users with cascaded privs
-			if(array_key_exists($mynode, $cascadedata)) {
+			if(isset($cascadedata[$mynode])) {
 				foreach($cascadedata[$mynode] as $data) {
 					$privs["resources"][$data['name']][$data["type"]] = 1;
 				}
@@ -3078,8 +3090,7 @@ function AJchangeUserPrivs() {
 
 	if($newprivval == 'true') {
 		// if $newuser already has $newpriv cascaded to it, do nothing
-		if(array_key_exists($newuser, $cascadePrivs['users']) &&
-		   isset($cascadePrivs['users'][$newuser][$newpriv]))
+		if(isset($cascadePrivs['users'][$newuser][$newpriv]))
 			return;
 		// add priv
 		$adds = array($newpriv);
@@ -3136,8 +3147,7 @@ function AJchangeUserGroupPrivs() {
 
 	if($newprivval == 'true') {
 		// if $newusergrp already has $newpriv cascaded to it, do nothing
-		if(array_key_exists($newusergrp, $cascadePrivs['usergroups']) &&
-		   isset($cascadePrivs['usergroups'][$newusergrp]['privs'][$newpriv]))
+		if(isset($cascadePrivs['usergroups'][$newusergrp]['privs'][$newpriv]))
 			return;
 		// add priv
 		$adds = array($newpriv);
@@ -3150,7 +3160,7 @@ function AJchangeUserGroupPrivs() {
 	}
 	updateUserOrGroupPrivs($newusergrpid, $node, $adds, $removes, "group");
 	$_SESSION['dirtyprivs'] = 1;
-	if(array_key_exists($newusergrpid, $user['groups']) &&
+	if(isset($user['groups'][$newusergrpid]) &&
 	   in_array($newpriv, array('nodeAdmin', 'block', 'cascade')))
 		print "refreshNodeDropData();";
 }
@@ -3176,7 +3186,7 @@ function AJchangeResourcePrivs() {
 	$newprivval = processInputVar('value', ARG_STRING);
 
 	$allprivs = getResourcePrivs();
-	if(! isset($allprivs[$newpriv])) {
+	if(! in_array($newpriv, $allprivs)) {
 		$text = "Invalid resource privilege submitted.";
 		print "alert('$text');";
 		return;
@@ -3211,13 +3221,14 @@ function AJchangeResourcePrivs() {
 		return;
 	}
 
-	# get cascade privs at this node
+	# get privs at this node
+	$privs = getNodePrivileges($node, 'resources');
 	$cascadePrivs = getNodeCascadePrivileges($node, "resources");
 
 	if($newprivval == 'true') {
 		// if $resourcegrp already has $newpriv cascaded to it, do nothing
-		if(array_key_exists($resourcegrp, $cascadePrivs['resources']) &&
-		   isset($cascadePrivs['resources'][$resourcegrp][$newpriv]))
+		if(isset($cascadePrivs['resources'][$resourcegrp][$newpriv]) &&
+		   ! isset($privs['resources'][$resourcegrp]['block']))
 			return;
 		// add priv
 		$adds = array($newpriv);
@@ -3262,7 +3273,7 @@ function AJsubmitAddUserPriv() {
 	array_push($usertypes["users"], "cascade");
 	$newuserprivs = array();
 	foreach($usertypes["users"] as $type) {
-		if(isset($perms[$type]))
+		if(in_array($type, $perms))
 			array_push($newuserprivs, $type);
 	}
 	if(empty($newuserprivs) || (count($newuserprivs) == 1 && 
@@ -3317,7 +3328,7 @@ function AJsubmitAddUserGroupPriv() {
 	array_push($usertypes["users"], "cascade");
 	$newgroupprivs = array();
 	foreach($usertypes["users"] as $type) {
-		if(isset($perms[$type]))
+		if(in_array($type, $perms))
 			array_push($newgroupprivs, $type);
 	}
 	if(empty($newgroupprivs) || (count($newgroupprivs) == 1 && 
@@ -3331,7 +3342,7 @@ function AJsubmitAddUserGroupPriv() {
 	clearPrivCache();
 	print "refreshPerms(); ";
 	print "addUserGroupPaneHide(); ";
-	if(array_key_exists($newgroupid, $user['groups']) &&
+	if(isset($user['groups'][$newgroupid]) &&
 	   (isset($perms['nodeAdmin']) ||
 	   isset($perms['cascade']) ||
 	   isset($perms['block'])))
@@ -3370,7 +3381,7 @@ function AJsubmitAddResourcePriv() {
 	}
 
 	list($newtype, $tmp) = explode('/', $groupdata[$newgroupid]['name']);
-	if(! array_key_exists($newgroupid, $resourcegroups[$newtype])) {
+	if(! isset($resourcegroups[$newtype][$newgroupid])) {
 		$text = "You do not have rights to manage the specified resource group.";
 		print "addResourceGroupPaneHide(); ";
 		print "alert('$text');";
@@ -3381,11 +3392,11 @@ function AJsubmitAddResourcePriv() {
 	$privtypes = getResourcePrivs();
 	$newgroupprivs = array();
 	foreach($privtypes as $type) {
-		if(isset($perms[$type]))
+		if(in_array($type, $perms))
 			array_push($newgroupprivs, $type);
 	}
 	if(empty($newgroupprivs) || (count($newgroupprivs) == 1 && 
-	   isset($newgroupprivs["cascade"]))) {
+	   in_array("cascade", $newgroupprivs))) {
 		$text = "<font color=red>No resource group privileges were specified</font>";
 		print setAttribute('addResourceGroupPrivStatus', 'innerHTML', $text);
 		return;
@@ -3417,7 +3428,7 @@ function AJsubmitAddResourcePriv() {
 function checkUserHasPriv($priv, $uid, $node, $privs=0, $cascadePrivs=0) {
 	global $user;
 	$key = getKey(array($priv, $uid, $node, $privs, $cascadePrivs));
-	if(array_key_exists($key, $_SESSION['userhaspriv']))
+	if(isset($_SESSION['userhaspriv'][$key]))
 		return $_SESSION['userhaspriv'][$key];
 	if($user["id"] != $uid) {
 		$_user = getUserInfo($uid, 0, 1);
@@ -3438,12 +3449,9 @@ function checkUserHasPriv($priv, $uid, $
 	}
 	// if user (has $priv at this node) || 
 	# (has cascaded $priv && ! have block at this node) return 1
-	if((array_key_exists($affilUserid, $privs["users"]) &&
-	   isset($privs["users"][$affilUserid][$priv])) ||
-	   ((array_key_exists($affilUserid, $cascadePrivs["users"]) &&
-	   isset($cascadePrivs["users"][$affilUserid][$priv])) &&
-	   (! array_key_exists($affilUserid, $privs["users"]) ||
-	   ! isset($privs["users"][$affilUserid]['block'])))) {
+	if(isset($privs["users"][$affilUserid][$priv]) ||
+	   (isset($cascadePrivs["users"][$affilUserid][$priv]) &&
+	   ! isset($privs["users"][$affilUserid]['block']))) {
 		$_SESSION['userhaspriv'][$key] = 1;
 		return 1;
 	}
@@ -3451,12 +3459,9 @@ function checkUserHasPriv($priv, $uid, $
 	foreach($_user["groups"] as $groupid => $groupname) {
 		// if group (has $priv at this node) ||
 		# (has cascaded $priv && ! have block at this node) return 1
-		if((array_key_exists($groupid, $privs["usergroups"]) &&
-		   isset($privs["usergroups"][$groupid]['privs'][$priv])) ||
-		   ((array_key_exists($groupid, $cascadePrivs["usergroups"]) &&
-		   isset($cascadePrivs["usergroups"][$groupid]['privs'][$priv])) &&
-		   (! array_key_exists($groupid, $privs["usergroups"]) ||
-		   (! isset($privs["usergroups"][$groupid]['privs']['block']))))) {
+		if(isset($privs["usergroups"][$groupid]['privs'][$priv]) ||
+		   (isset($cascadePrivs["usergroups"][$groupid]['privs'][$priv]) &&
+		   ! isset($privs["usergroups"][$groupid]['privs']['block']))) {
 			$_SESSION['userhaspriv'][$key] = 1;
 			return 1;
 		}

Modified: vcl/trunk/web/.ht-inc/utils.php
URL: http://svn.apache.org/viewvc/vcl/trunk/web/.ht-inc/utils.php?rev=1779664&r1=1779663&r2=1779664&view=diff
==============================================================================
--- vcl/trunk/web/.ht-inc/utils.php (original)
+++ vcl/trunk/web/.ht-inc/utils.php Fri Jan 20 18:21:45 2017
@@ -1306,8 +1306,6 @@ function getImages($includedeleted=0, $i
 	while($row = mysql_fetch_assoc($qh)) {
 		$id = $row['imageid'];
 		unset($row['imageid']);
-		if(! array_key_exists($id, $allrevisiondata))
-			$allrevisiondata[$id] = array();
 		$allrevisiondata[$id][$row['id']] = $row;
 	}
 	$query = "SELECT i.id AS id,"
@@ -1374,7 +1372,7 @@ function getImages($includedeleted=0, $i
 		if($row['addomainid'] != NULL)
 			$imagelist[$includedeleted][$row['id']]['adauthenabled'] = 1;
 		if($row["imagemetaid"] != NULL) {
-			if(array_key_exists($row['imagemetaid'], $allmetadata)) {
+			if(isset($allmetadata[$row['imagemetaid']])) {
 				$metaid = $row['imagemetaid'];
 				$imagelist[$includedeleted][$row['id']]['checkuser'] = $allmetadata[$metaid]['checkuser'];
 				$imagelist[$includedeleted][$row['id']]['rootaccess'] = $allmetadata[$metaid]['rootaccess'];
@@ -1394,7 +1392,7 @@ function getImages($includedeleted=0, $i
 			else
 				$imagelist[$includedeleted][$row["id"]]["imagemetaid"] = NULL;
 		}
-		if(array_key_exists($row['id'], $allrevisiondata))
+		if(isset($allrevisiondata[$row['id']]))
 			$imagelist[$includedeleted][$row['id']]['imagerevision'] = $allrevisiondata[$row['id']];
 		$imagelist[$includedeleted][$row['id']]['connectmethods'] = getImageConnectMethods($row['id']);
 	}
@@ -1431,7 +1429,7 @@ function getImages($includedeleted=0, $i
 ////////////////////////////////////////////////////////////////////////////////
 function getServerProfiles($id=0) {
 	$key = getKey(array('getServerProfiles', $id));
-	if(array_key_exists($key, $_SESSION['usersessiondata']))
+	if(isset($_SESSION['usersessiondata'][$key]))
 		return $_SESSION['usersessiondata'][$key];
 
 	$fixeddata = array();
@@ -1475,7 +1473,7 @@ function getServerProfiles($id=0) {
 	$profiles = array();
 	while($row = mysql_fetch_assoc($qh)) {
 		$profiles[$row['id']] = $row;
-		if(array_key_exists($row['id'], $fixeddata)) {
+		if(isset($fixeddata[$row['id']])) {
 			$profiles[$row['id']]['netmask'] = $fixeddata[$row['id']]['netmask'];
 			$profiles[$row['id']]['router'] = $fixeddata[$row['id']]['router'];
 			$profiles[$row['id']]['dns'] = implode(',', $fixeddata[$row['id']]['dns']);
@@ -1504,7 +1502,7 @@ function getServerProfiles($id=0) {
 ////////////////////////////////////////////////////////////////////////////////
 function getServerProfileImages($userid) {
 	$key = getKey(array('getServerProfileImages', $userid));
-	if(array_key_exists($key, $_SESSION['usersessiondata']))
+	if(isset($_SESSION['usersessiondata'][$key]))
 		return $_SESSION['usersessiondata'][$key];
 	$resources = getUserResources(array('serverCheckOut', 'serverProfileAdmin'),
 	                              array('available', 'administer'));
@@ -1621,7 +1619,7 @@ function getImageNotes($imageid) {
 ////////////////////////////////////////////////////////////////////////////////
 function getImageConnectMethods($imageid, $revisionid=0, $nostatic=0) {
 	$key = getKey(array('getImageConnectMethods', (int)$imageid, (int)$revisionid));
-	if(array_key_exists($key, $_SESSION['usersessiondata']))
+	if(isset($_SESSION['usersessiondata'][$key]))
 		return $_SESSION['usersessiondata'][$key];
 	if($revisionid == 0)
 		$revisionid = getProductionRevisionid($imageid, $nostatic);
@@ -1633,54 +1631,68 @@ function getImageConnectMethods($imageid
 	static $allmethods = array();
 	if($nostatic)
 		$allmethods = array();
+
 	if(empty($allmethods)) {
-		$query = "SELECT DISTINCT c.id, "
-		      .                  "c.description, "
-		      .                  "cm.disabled, "
-		      .                  "i.id AS imageid, "
-		      .                  "cm.imagerevisionid AS cmimagerevisionid, "
-		      .                  "ir.id AS imagerevisionid, "
-		      .                  "ir.imagename "
-		      . "FROM image i "
-		      . "LEFT JOIN OS o ON (o.id = i.OSid) "
-		      . "LEFT JOIN OStype ot ON (ot.name = o.type) "
-		      . "LEFT JOIN imagerevision ir ON (ir.imageid = i.id) "
-		      . "LEFT JOIN connectmethodmap cm ON (cm.OStypeid = ot.id OR "
-		      .                                   "cm.OSid = o.id OR "
-		      .                                   "cm.imagerevisionid = ir.id) "
-		      . "LEFT JOIN connectmethod c ON (cm.connectmethodid = c.id) "
-		      . "WHERE cm.autoprovisioned IS NULL  "
-		      . "ORDER BY i.id, "
-		      .          "cm.disabled, "
-		      .          "c.description";
+		$query = "DROP TEMPORARY TABLE IF EXISTS imageconnectmethods";
+		doQuery($query);
+		$query = "CREATE TEMPORARY TABLE imageconnectmethods ( "
+		       .    "imageid smallint(5) unsigned NOT NULL, "
+		       .    "imagerevisionid mediumint(8) unsigned NOT NULL, "
+		       .    "connectmethodid tinyint unsigned NOT NULL, "
+		       .    "description varchar(255) NOT NULL, "
+		       .    "disabled tinyint(1) unsigned NOT NULL, "
+		       .    "UNIQUE KEY (imagerevisionid, connectmethodid, disabled) "
+		       . ") ENGINE=MEMORY";
+		doQuery($query, 101);
+
+		$qbase = "INSERT IGNORE INTO imageconnectmethods "
+		       . "SELECT DISTINCT i.id, "
+		       .                 "ir.id, "
+		       .                 "c.id, "
+		       .                 "c.description, "
+		       .                 "cm.disabled "
+		       . "FROM image i "
+		       . "LEFT JOIN OS o ON (o.id = i.OSid) "
+		       . "LEFT JOIN OStype ot ON (ot.name = o.type) "
+		       . "LEFT JOIN imagerevision ir ON (ir.imageid = i.id) "
+		       . "LEFT JOIN connectmethodmap cm ON (%s) "
+		       . "LEFT JOIN connectmethod c ON (cm.connectmethodid = c.id) "
+		       . "WHERE cm.autoprovisioned IS NULL "
+		       . "HAVING c.id IS NOT NULL "
+		       . "ORDER BY i.id, "
+		       .          "cm.disabled, "
+		       .          "c.description";
+		$query = sprintf($qbase, "cm.OStypeid = ot.id");
+		doQuery($query);
+		$query = sprintf($qbase, "cm.OSid = o.id");
+		doQuery($query);
+		$query = sprintf($qbase, "cm.imagerevisionid = ir.id");
+		doQuery($query);
+
+		$query = "SELECT imageid, "
+		       .        "imagerevisionid, "
+		       .        "connectmethodid, "
+		       .        "description, "
+		       .        "disabled "
+		       . "FROM imageconnectmethods "
+		       . "ORDER BY imagerevisionid, "
+		       .          "connectmethodid, "
+		       .          "disabled";
+
 		$qh = doQuery($query);
 		while($row = mysql_fetch_assoc($qh)) {
-			$_imageid = $row['imageid'];
-			$_revid = $row['imagerevisionid'];
-			unset($row['imageid']);
-			unset($row['imagerevisionid']);
-			if(! array_key_exists($_imageid, $allmethods))
-				$allmethods[$_imageid] = array();
-			if(! array_key_exists($_revid, $allmethods[$_imageid]))
-				$allmethods[$_imageid][$_revid] = array();
-			$allmethods[$_imageid][$_revid][] = $row;
+			if($row['disabled'] &&
+			   isset($allmethods[$row['imageid']][$row['imagerevisionid']][$row['connectmethodid']]))
+				unset($allmethods[$row['imageid']][$row['imagerevisionid']][$row['connectmethodid']]);
+			else
+				$allmethods[$row['imageid']][$row['imagerevisionid']][$row['connectmethodid']] = $row['description'];
 		}
 	}
-	if(! array_key_exists($imageid, $allmethods) ||
-	   ! array_key_exists($revisionid, $allmethods[$imageid])) {
+	if(! isset($allmethods[$imageid][$revisionid])) {
 		$_SESSION['usersessiondata'][$key] = array();
 		return array();
 	}
-	$methods = array();
-	foreach($allmethods[$imageid][$revisionid] as $data) {
-		if($data['disabled']) {
-		  if(array_key_exists($data['id'], $methods))
-			unset($methods[$data['id']]);
-		}
-		else
-			$methods[$data['id']] = $data['description'];
-	}
-
+	$methods = $allmethods[$imageid][$revisionid];
 	$_SESSION['usersessiondata'][$key] = $methods;
 	return $methods;
 }
@@ -1746,7 +1758,7 @@ function getImageConnectMethodTexts($ima
 	$qh = doQuery($query, 101);
 	while($row = mysql_fetch_assoc($qh)) {
 		if($row['disabled']) {
-		  if(array_key_exists($row['id'], $methods))
+		  if(isset($methods[$row['id']]))
 			unset($methods[$row['id']]);
 		}
 		else
@@ -1845,7 +1857,7 @@ function getProductionRevisionid($imagei
 	if($nostatic)
 		$alldata = array();
 	if(! empty($alldata))
-		if(array_key_exists($imageid, $alldata))
+		if(isset($alldata[$imageid]))
 			return $alldata[$imageid];
 		else
 			return '';
@@ -1874,7 +1886,7 @@ function getProductionRevisionid($imagei
 function removeNoCheckout($images) {
 	$allimages = getImages();
 	foreach(array_keys($images) as $id) {
-		if(array_key_exists($id, $allimages) && ! $allimages[$id]["forcheckout"])
+		if(isset($allimages[$id]) && ! $allimages[$id]["forcheckout"])
 			unset($images[$id]);
 	}
 	return $images;
@@ -1927,7 +1939,7 @@ function getUserResources($userprivs, $r
 	if(isset($userprivs['managementnodeAdmin']))
 		$userprivs[] = 'mgmtNodeAdmin';
 	$key = getKey(array($userprivs, $resourceprivs, $onlygroups, $includedeleted, $userid, $groupid));
-	if(array_key_exists($key, $_SESSION['userresources']))
+	if(isset($_SESSION['userresources'][$key]))
 		return $_SESSION['userresources'][$key];
 	#FIXME this whole function could be much more efficient
 	$bygroup = 0;
@@ -1970,11 +1982,8 @@ function getUserResources($userprivs, $r
 	       .       "u.userid = $userid AND "
 	       .       "t.name IN ('block','cascade',$inlist)";
 	$qh = doQuery($query);
-	while($row = mysql_fetch_assoc($qh)) {
-		if(! array_key_exists($row['privnodeid'], $privdataset['user']))
-			$privdataset['user'][$row['privnodeid']] = array();
+	while($row = mysql_fetch_assoc($qh))
 		$privdataset['user'][$row['privnodeid']][] = $row['name'];
-	}
 	$query = "SELECT t.name, "
 	       .        "u.usergroupid, "
 	       .        "u.privnodeid "
@@ -1992,11 +2001,8 @@ function getUserResources($userprivs, $r
 	       . "ORDER BY u.privnodeid, "
 	       .          "u.usergroupid";
 	$qh = doQuery($query, 101);
-	while($row = mysql_fetch_assoc($qh)) {
-		if(! array_key_exists($row['privnodeid'], $privdataset['usergroup']))
-			$privdataset['usergroup'][$row['privnodeid']] = array();
+	while($row = mysql_fetch_assoc($qh))
 		$privdataset['usergroup'][$row['privnodeid']][] = array('name' => $row['name'], 'groupid'
=> $row['usergroupid']);
-	}
 
 	# travel up tree looking at privileges granted at parent nodes
 	foreach($startnodes as $nodeid) {
@@ -2030,7 +2036,7 @@ function getUserResources($userprivs, $r
 			foreach($resourceprivs as $priv) {
 				if(isset($nodeprivs[$nodeid]["resources"][$resourceid][$priv])) {
 					list($type, $name, $id) = explode('/', $resourceid);
-					if(! array_key_exists($type, $resourcegroups))
+					if(! isset($resourcegroups[$type]))
 						$resourcegroups[$type] = array();
 					if(! isset($resourcegroups[$type][$name]))
 						$resourcegroups[$type][$id] = $name;
@@ -2041,10 +2047,9 @@ function getUserResources($userprivs, $r
 		foreach(array_keys($nodeprivs[$nodeid]["cascaderesources"]) as $resourceid) {
 			foreach($resourceprivs as $priv) {
 				if(isset($nodeprivs[$nodeid]["cascaderesources"][$resourceid][$priv]) &&
-					! (array_key_exists($resourceid, $nodeprivs[$nodeid]["resources"]) &&
-					isset($nodeprivs[$nodeid]["resources"][$resourceid]["block"]))) {
+					! (isset($nodeprivs[$nodeid]["resources"][$resourceid]["block"]))) {
 					list($type, $name, $id) = explode('/', $resourceid);
-					if(! array_key_exists($type, $resourcegroups))
+					if(! isset($resourcegroups[$type]))
 						$resourcegroups[$type] = array();
 					if(! isset($resourcegroups[$type][$name]))
 						$resourcegroups[$type][$id] = $name;
@@ -2070,7 +2075,7 @@ function getUserResources($userprivs, $r
 	if(! $bygroup)
 		addOwnedResources($resources, $includedeleted, $userid);
 	$noimageid = getImageId('noimage');
-	if(array_key_exists($noimageid, $resources['image']))
+	if(isset($resources['image'][$noimageid]))
 		unset($resources['image'][$noimageid]);
 	$_SESSION['userresources'][$key] = $resources;
 	return $resources;
@@ -2102,7 +2107,7 @@ function getUserResourcesUp(&$nodeprivs,
 	$lastid = 0;
 	while(count($nodelist)) {
 		$id = array_pop($nodelist);
-		if(array_key_exists($id, $nodeprivs))
+		if(isset($nodeprivs[$id]))
 			continue;
 
 		addNodeUserResourcePrivs($nodeprivs, $id, $lastid, $userid, $resourceprivs, $privdataset);
@@ -2131,7 +2136,7 @@ function getUserResourcesDown(&$nodepriv
                               $resourceprivs, $privdataset) {
 	# FIXME can we check for cascading and if not there, don't descend?
 	$children = getChildNodes($nodeid);
-	foreach(array_keys($children) as $id) {
+	foreach($children as $id => $tmp) {
 		addNodeUserResourcePrivs($nodeprivs, $id, $nodeid, $userid, $resourceprivs, $privdataset);
 		getUserResourcesDown($nodeprivs, $id, $userid, $resourceprivs, $privdataset);
 	}
@@ -2164,7 +2169,7 @@ function addNodeUserResourcePrivs(&$node
 
 	# add permissions for user
 	$block = 0;
-	if(array_key_exists($id, $privdataset['user'])) {
+	if(isset($privdataset['user'][$id])) {
 		foreach($privdataset['user'][$id] as $name) {
 			if($name != 'block')
 				$nodeprivs[$id]['user'][$name] = 1;
@@ -2198,23 +2203,22 @@ function addNodeUserResourcePrivs(&$node
 	                   "block" => 0);
 	foreach($resourceprivs as $priv)
 		$basearray[$priv] = 0;
-	if(array_key_exists($id, $privdataset['usergroup'])) {
+	if(isset($privdataset['usergroup'][$id])) {
 		foreach($privdataset['usergroup'][$id] as $data) {
-			if(! array_key_exists($data["groupid"], $nodeprivs[$id]))
+			if(! isset($nodeprivs[$id][$data["groupid"]]))
 				$nodeprivs[$id][$data["groupid"]] = $basearray;
 			$nodeprivs[$id][$data["groupid"]][$data["name"]] = 1;
 		}
 	}
 	# add groups from $lastid if it is not 0
-	$groupkeys = array_keys($nodeprivs[$id]);
 	if($lastid) {
-		foreach(array_keys($nodeprivs[$lastid]) as $groupid) {
-			if(isset($groupkeys[$groupid]))
+		foreach($nodeprivs[$lastid] as $groupid => $tmp) {
+			if(isset($nodeprivs[$id][$groupid]))
 				continue;
 			$nodeprivs[$id][$groupid] = $basearray;
 		}
 	}
-	foreach(array_keys($nodeprivs[$id]) as $groupid) {
+	foreach($nodeprivs[$id] as $groupid => $tmp) {
 		if(! is_numeric($groupid))
 			continue;
 		// if don't have anything in $resourceprivs, set cascade = 0
@@ -2230,7 +2234,7 @@ function addNodeUserResourcePrivs(&$node
 		// if group not blocking at this node, and group had cascade at previous 
 		# node
 		if($lastid && ! $nodeprivs[$id][$groupid]["block"] && 
-		   array_key_exists($groupid, $nodeprivs[$lastid]) &&
+		   isset($nodeprivs[$lastid][$groupid]) &&
 		   $nodeprivs[$lastid][$groupid]["cascade"]) {
 			# set cascade = 1
 			$nodeprivs[$id][$groupid]["cascade"] = 1;
@@ -2336,7 +2340,7 @@ function addOwnedResources(&$resources,
 			$query .= " AND deleted = 0";
 		$qh = doQuery($query, 101);
 		while($row = mysql_fetch_assoc($qh)) {
-			if(! array_key_exists($row["id"], $resources[$type]))
+			if(! isset($resources[$type][$row["id"]]))
 				$resources[$type][$row["id"]] = $row[$field];
 		}
 	}
@@ -2370,7 +2374,7 @@ function addOwnedResourceGroups(&$resour
 	       .       "g.ownerusergroupid IN ($groupids)";
 	$qh = doQuery($query, 101);
 	while($row = mysql_fetch_assoc($qh)) {
-		if(! array_key_exists($row["id"], $resourcegroups[$row["type"]]))
+		if(! isset($resourcegroups[$row["type"]][$row["id"]]))
 			$resourcegroups[$row["type"]][$row["id"]] = $row["name"];
 	}
 }
@@ -2647,7 +2651,7 @@ function encryptDataAsymmetric($data, $p
 ////////////////////////////////////////////////////////////////////////////////
 function getParentNodes($node) {
 	global $nodeparents;
-	if(array_key_exists($node, $nodeparents))
+	if(isset($nodeparents[$node]))
 		return $nodeparents[$node];
 
 	$nodelist = array();
@@ -2676,7 +2680,7 @@ function getParentNodes($node) {
 ////////////////////////////////////////////////////////////////////////////////
 function getChildNodes($parent=DEFAULT_PRIVNODE) {
 	global $cache;
-	if(! array_key_exists('nodes', $cache))
+	if(! isset($cache['nodes']))
 		# call getNodeInfo to populate $cache['nodes']
 		getNodeInfo($parent);
 
@@ -2684,12 +2688,10 @@ function getChildNodes($parent=DEFAULT_P
 	if(empty($allnodes)) {
 		foreach($cache['nodes'] as $id => $node) {
 			unset($node['id']);
-			if(! array_key_exists($node['parent'], $allnodes))
-				$allnodes[$node['parent']] = array();
 			$allnodes[$node['parent']][$id] = $node;
 		}
 	}
-	if(array_key_exists($parent, $allnodes))
+	if(isset($allnodes[$parent]))
 		return $allnodes[$parent];
 	else
 		return array();
@@ -2730,7 +2732,7 @@ function getChildNodes($parent=DEFAULT_P
 function getUserGroups($groupType=0, $affiliationid=0) {
 	global $user;
 	$key = getKey(array($groupType, $affiliationid, $user['showallgroups']));
-	if(array_key_exists($key, $_SESSION['usersessiondata']))
+	if(isset($_SESSION['usersessiondata'][$key]))
 		return $_SESSION['usersessiondata'][$key];
 	$return = array();
 	$query = "SELECT ug.id, "
@@ -2965,14 +2967,8 @@ function getResourceGroupMemberships($ty
 		       .       "gm.resourceid = r.id AND "
 		       .       "r.resourcetypeid = t.id";
 		$qh = doQuery($query, 282);
-		while($row = mysql_fetch_assoc($qh)) {
-			if(array_key_exists($row["id"], $return[$type])) {
-				array_push($return[$type][$row["id"]], $row["groupid"]);
-			}
-			else {
-				$return[$type][$row["id"]] = array($row["groupid"]);
-			}
-		}
+		while($row = mysql_fetch_assoc($qh))
+			$return[$type][$row["id"]][] = $row["groupid"];
 	}
 	return $return;
 }
@@ -3004,7 +3000,7 @@ function getResourceGroupMemberships($ty
 ////////////////////////////////////////////////////////////////////////////////
 function getResourceGroupMembers($type="all") {
 	$key = getKey(array('getResourceGroupMembers', $type));
-	if(array_key_exists($key, $_SESSION['userresources']))
+	if(isset($_SESSION['userresources'][$key]))
 		return $_SESSION['userresources'][$key];
 	$return = array();
 
@@ -3076,14 +3072,10 @@ function getResourceGroupMembers($type="
 	       .          $orders;
 	$qh = doQuery($query, 282);
 	while($row = mysql_fetch_assoc($qh)) {
-		if(array_key_exists('deleted', $row) && $row['deleted'] == 1)
+		if(isset($row['deleted']) && $row['deleted'] == 1)
 			continue;
-		if(array_key_exists('deleted2', $row) && $row['deleted2'] == 1)
+		if(isset($row['deleted2']) && $row['deleted2'] == 1)
 			continue;
-		if(! array_key_exists($row['resourcetype'], $return))
-			$return[$row['resourcetype']] = array();
-		if(! array_key_exists($row['resourcegroupid'], $return[$row['resourcetype']]))
-			$return[$row['resourcetype']][$row['resourcegroupid']] = array();
 		$return[$row['resourcetype']][$row['resourcegroupid']][$row['resourceid']] =
 		      array('subid' => $row['subid'],
 		            'name' => $row[$row['resourcetype']]);
@@ -3258,9 +3250,9 @@ function getAffiliations() {
 ////////////////////////////////////////////////////////////////////////////////
 function getUserUnityID($userid) {
 	global $cache;
-	if(! array_key_exists('unityids', $cache))
+	if(! isset($cache['unityids']))
 		$cache['unityids'] = array();
-	if(array_key_exists($userid, $cache['unityids']))
+	if(isset($cache['unityids'][$userid]))
 		return $cache['unityids'][$userid];
 	$query = "SELECT unityid FROM user WHERE id = $userid";
 	$qh = doQuery($query, 101);
@@ -3837,7 +3829,7 @@ function getUsersGroupPerms($usergroupid
 function checkUserHasPerm($perm, $userid=0) {
 	global $user;
 	if($userid == 0) {
-		if(is_array($user) && array_key_exists('groupperms', $user))
+		if(isset($user['groupperms']))
 			$perms = $user['groupperms'];
 		else
 			return 0;
@@ -7865,8 +7857,6 @@ function findAvailableTimes($start, $end
 				if($row['duration'] > $reqduration)
 					$row['duration'] = $reqduration;
 				$row['endts'] = $row['startts'] + $row['duration'];
-				if(! array_key_exists($row['compid'], $slots))
-					$slots[$row['compid']] = array();
 				$slots[$row['compid']][] = $row;
 				if($row['startts'] < $minstart)
 					$minstart = $row['startts'];
@@ -7923,8 +7913,6 @@ function findAvailableTimes($start, $end
 				$row['duration'] = $reqduration;
 			$row['start'] = $startdt;
 			$row['startts'] = $start;
-			if(! array_key_exists($row['compid'], $slots))
-				$slots[$row['compid']] = array();
 			$slots[$row['compid']][] = $row;
 			if($row['endts'] > $maxend)
 				$maxend = $row['endts'];
@@ -7980,8 +7968,6 @@ function findAvailableTimes($start, $end
 		}
 		$row['endts'] = $row['startts'] + $reqduration;
 		$row['duration'] = $reqduration;
-		if(! array_key_exists($row['compid'], $slots))
-			$slots[$row['compid']] = array();
 		$slots[$row['compid']][] = $row;
 		if($row['endts'] > $maxend)
 			$maxend = $row['endts'];
@@ -8011,7 +7997,7 @@ function findAvailableTimes($start, $end
 	$query .=      "bc.computerid IN ($newincompids)";
 	$qh = doQuery($query);
 	while($row = mysql_fetch_assoc($qh)) {
-		if(array_key_exists($row['compid'], $slots))
+		if(isset($slots[$row['compid']]))
 			fATremoveOverlaps($slots, $row['compid'], $row['start'], $row['end'], 0);
 	}
 
@@ -8040,7 +8026,7 @@ function findAvailableTimes($start, $end
 			$query .=   "s.fixedIP = '$mac'";
 		$qh = doQuery($query);
 		while($row = mysql_fetch_assoc($qh)) {
-			if(array_key_exists($row['compid'], $slots))
+			if(isset($slots[$row['compid']]))
 				fATremoveOverlaps($slots, $row['compid'], $row['start'], $row['end'], 0);
 		}
 	}
@@ -8081,7 +8067,7 @@ function findAvailableTimes($start, $end
 				                     $imgdata[$imageid]['maxconcurrent'], $ignorestates,
 				                     $extendonly, $reqid))
 				continue;
-			if(array_key_exists($data['startts'], $options)) {
+			if(isset($options[$data['startts']])) {
 				if($data['duration'] > $options[$data['startts']]['duration']) {
 					$options[$data['startts']]['duration'] = $data['duration'];
 					if(checkUserHasPerm('View Debug Information'))
@@ -9141,11 +9127,11 @@ function selectInputHTML($name, $dataArr
 		   $h .= "        <option value=\"$id\" selected=\"selected\">";
 		else
 		   $h .= "        <option value=\"$id\">";
-		if(is_array($dataArr[$id]) && array_key_exists("prettyname", $dataArr[$id]))
+		if(isset($dataArr[$id]['prettyname']))
 			$h .= $dataArr[$id]["prettyname"] . "</option>\n";
-		elseif(is_array($dataArr[$id]) && array_key_exists("name", $dataArr[$id]))
+		elseif(isset($dataArr[$id]['name']))
 			$h .= $dataArr[$id]["name"] . "</option>\n";
-		elseif(is_array($dataArr[$id]) && array_key_exists("hostname", $dataArr[$id]))
+		elseif(isset($dataArr[$id]['hostname']))
 			$h .= $dataArr[$id]["hostname"] . "</option>\n";
 		else
 			$h .= $dataArr[$id] . "</option>\n";
@@ -9442,7 +9428,7 @@ function prettyDatetime($stamp, $showyea
 	global $locale;
 	if(! preg_match('/^[\d]+$/', $stamp))
 		$stamp = datetimeToUnix($stamp);
-	if(! $notzoffset && array_key_exists('tzoffset', $_SESSION['persistdata']))
+	if(! $notzoffset && isset($_SESSION['persistdata']['tzoffset']))
 		$stamp += $_SESSION['persistdata']['tzoffset'] * 60;
 	if($showyear)
 		$return = strftime('%A, %b&nbsp;%-d,&nbsp;%Y, %l:%M %P', $stamp);
@@ -9832,7 +9818,7 @@ function getMaintItems($id=0) {
 ////////////////////////////////////////////////////////////////////////////////
 function getMaintItemsForTimeTable($start, $end) {
 	$key = getKey(array('getMaintItemsForTimeTable', $start, $end));
-	if(array_key_exists($key, $_SESSION['usersessiondata']))
+	if(isset($_SESSION['usersessiondata'][$key]))
 		return $_SESSION['usersessiondata'][$key];
 	$startdt = unixToDatetime($start);
 	$enddt = unixToDatetime($end);
@@ -11057,14 +11043,14 @@ function getConfigSubimages($configs) {
 ////////////////////////////////////////////////////////////////////////////////
 function getNodeInfo($nodeid) {
 	global $cache;
-	if(! array_key_exists('nodes', $cache))
+	if(! isset($cache['nodes']))
 		$cache['nodes'] = array();
-	if(array_key_exists($nodeid, $cache['nodes']))
+	if(isset($cache['nodes'][$nodeid]))
 		return $cache['nodes'][$nodeid];
 	$qh = doQuery("SELECT id, parent, name FROM privnode", 330);
 	while($row = mysql_fetch_assoc($qh))
 		$cache['nodes'][$row['id']] = $row;
-	if(array_key_exists($nodeid, $cache['nodes']))
+	if(isset($cache['nodes'][$nodeid]))
 		return $cache['nodes'][$nodeid];
 	else
 		return NULL;
@@ -11112,7 +11098,7 @@ function getNodePath($nodeid) {
 ////////////////////////////////////////////////////////////////////////////////
 function sortKeepIndex($a, $b) {
 	if(is_array($a)) {
-		if(array_key_exists("prettyname", $a)) {
+		if(isset($a["prettyname"])) {
 			if(preg_match('/[0-9]-[0-9]/', $a['prettyname']) ||
 			   preg_match('/\.edu$|\.com$|\.net$|\.org$/', $a['prettyname']) ||
 			   preg_match('/[0-9]-[0-9]/', $b['prettyname']) ||
@@ -11120,7 +11106,7 @@ function sortKeepIndex($a, $b) {
 				return compareDashedNumbers($a["prettyname"], $b["prettyname"]);
 			return strcasecmp($a["prettyname"], $b["prettyname"]);
 		}
-		elseif(array_key_exists("name", $a)) {
+		elseif(isset($a["name"])) {
 			if(preg_match('/[0-9]-[0-9]/', $a['name']) ||
 			   preg_match('/\.edu$|\.com$|\.net$|\.org$/', $a['name']) ||
 			   preg_match('/[0-9]-[0-9]/', $b['name']) ||

Modified: vcl/trunk/web/.ht-inc/xmlrpcWrappers.php
URL: http://svn.apache.org/viewvc/vcl/trunk/web/.ht-inc/xmlrpcWrappers.php?rev=1779664&r1=1779663&r2=1779664&view=diff
==============================================================================
--- vcl/trunk/web/.ht-inc/xmlrpcWrappers.php (original)
+++ vcl/trunk/web/.ht-inc/xmlrpcWrappers.php Fri Jan 20 18:21:45 2017
@@ -2130,17 +2130,14 @@ function XMLRPCgetResourceGroupPrivs($na
 		$np = getNodePrivileges($nodeid, 'resources');
 		$cnp = getNodeCascadePrivileges($nodeid, 'resources'); 
 		$key = "$type/$name/$groupid";
-		if(array_key_exists($key, $np['resources']) &&
-			(in_array('block', $np['resources'][$key]) ||
-		   ! array_key_exists($key, $cnp['resources'])))
-			$privs = $np['resources'][$key];
-		elseif(array_key_exists($key, $cnp['resources']) &&
-		   array_key_exists($key, $np['resources'])) {
+		if(isset($np['resources'][$key]['block']) || ! isset($cnp['resources'][$key]))
+			$privs = array_keys($np['resources'][$key]);
+		elseif(isset($cnp['resources'][$key]) && isset($np['resources'][$key])) {
 			$allprivs = array_merge($cnp['resources'][$key], $np['resources'][$key]);
-			$privs = array_unique($allprivs);
+			$privs = array_keys($allprivs);
 		}
-		elseif(array_key_exists($key, $cnp['resources']))
-			$privs = $cnp['resources'][$key];
+		elseif(isset($cnp['resources'][$key]))
+			$privs = array_keys($cnp['resources'][$key]);
 		else
 			$privs = array();
 		return array('status' => 'success',
@@ -2283,10 +2280,8 @@ function _XMLRPCchangeResourceGroupPriv_
 	$key = "$type/$name/$groupid";
 	$cnp = getNodeCascadePrivileges($nodeid, "resources");
 	$np = getNodePrivileges($nodeid, 'resources');
-	if(array_key_exists($key, $cnp['resources']) &&
-	   (! array_key_exists($key, $np['resources']) ||
-	   ! in_array('block', $np['resources'][$key]))) {
-		$intersect = array_intersect($cnp['resources'][$key], $changeperms);
+	if(isset($cnp['resources'][$key]) && ! isset($np['resources'][$key]['block'])) {
+		$intersect = array_intersect(array_keys($cnp['resources'][$key]), $changeperms);
 		if(count($intersect)) {
 			return array('status' => 'error',
 			             'errorcode' => 80,
@@ -2295,7 +2290,9 @@ function _XMLRPCchangeResourceGroupPriv_
 	}
 
 	if($mode == 'remove') {
-		$diff = array_diff($np['resources'][$key], $changeperms);
+		if(! isset($np['resources'][$key]))
+			return array('status' => 'success');
+		$diff = array_diff(array_keys($np['resources'][$key]), $changeperms);
 		if(count($diff) == 1 && in_array("cascade", $diff))
 			$changeperms[] = 'cascade';
 	}



Mime
View raw message