function submitMgmtnodeMapping() { $mapinput = processInputVar("mapping", ARG_MULTINUMERIC); $mntypeid = getResourceTypeID("managementnode"); $comptypeid = getResourceTypeID("computer"); # build an array of memberships currently in the db $tmp = getUserResources(array("mgmtNodeAdmin"), array("manageGroup"), 1); $mngroups = $tmp["managementnode"]; $tmp = getUserResources(array("computerAdmin"), array("manageGroup"), 1); $compgroups = $tmp["computer"]; $mninlist = implode(',', array_keys($mngroups)); $compinlist = implode(',', array_keys($compgroups)); $mapping = getResourceMapping("managementnode", "computer", $mninlist, $compinlist); # build an array of posted in memberships $newmembers = array(); foreach (array_keys($mapinput) as $key) { list($mnid, $compid) = explode(':', $key); if (array_key_exists($mnid, $newmembers)) { array_push($newmembers[$mnid], $compid); } else { $newmembers[$mnid] = array($compid); } } $adds = array(); $removes = array(); foreach (array_keys($mngroups) as $mnid) { // if $mnid is not in $newmembers and not in $mapping, do nothing if (!array_key_exists($mnid, $newmembers) && !array_key_exists($mnid, $mapping)) { continue; } // check that $mnid is in $newmembers, if not, remove it from all groups // user has access to if (!array_key_exists($mnid, $newmembers)) { $removes[$mnid] = $mapping[$mnid]; continue; } // check that $mnid is in $mapping, if not, add all groups in // $newmembers if (!array_key_exists($mnid, $mapping)) { $adds[$mnid] = $newmembers[$mnid]; continue; } // adds are groupids that are in $newmembers, but not in $mapping $adds[$mnid] = array_diff($newmembers[$mnid], $mapping[$mnid]); if (count($adds[$mnid]) == 0) { unset($adds[$mnid]); } // removes are groupids that are in $mapping, but not in $newmembers $removes[$mnid] = array_diff($mapping[$mnid], $newmembers[$mnid]); if (count($removes[$mnid]) == 0) { unset($removes[$mnid]); } } foreach (array_keys($adds) as $mnid) { foreach ($adds[$mnid] as $compid) { $query = "INSERT INTO resourcemap " . "(resourcegroupid1, " . "resourcetypeid1, " . "resourcegroupid2, " . "resourcetypeid2) " . "VALUES ({$mnid}, " . "{$mntypeid}, " . "{$compid}, " . "{$comptypeid})"; doQuery($query, 101); } } foreach (array_keys($removes) as $mnid) { foreach ($removes[$mnid] as $compid) { $query = "DELETE FROM resourcemap " . "WHERE resourcegroupid1 = {$mnid} AND " . "resourcetypeid1 = {$mntypeid} AND " . "resourcegroupid2 = {$compid} AND " . "resourcetypeid2 = {$comptypeid}"; doQuery($query, 101); } } viewMgmtnodeMapping(); }
function AJaddRemGroupMapTo() { $mapgroupid = processInputVar('id', ARG_NUMERIC); $mapgroups = getUserResources(array($this->maptype . "Admin"), array("manageMapping"), 1); if (!array_key_exists($mapgroupid, $mapgroups[$this->maptype])) { $arr = array('status' => 'noaccess'); sendJSON($arr); return; } $groups = getUserResources(array($this->restype . "Admin"), array("manageMapping"), 1); $tmp = processInputVar('listids', ARG_STRING); $tmp = explode(',', $tmp); $groupids = array(); foreach ($tmp as $id) { if (!is_numeric($id)) { continue; } if (!array_key_exists($id, $groups[$this->restype])) { $arr = array('status' => 'noaccess'); sendJSON($arr); return; } $groupids[] = $id; } $mytypeid = getResourceTypeID($this->restype); $maptypeid = getResourceTypeID($this->maptype); $mode = getContinuationVar('mode'); if ($mode == 'add') { $adds = array(); foreach ($groupids as $id) { $adds[] = "({$id}, {$mytypeid}, {$mapgroupid}, {$maptypeid})"; } $query = "INSERT IGNORE INTO resourcemap " . "(resourcegroupid1, resourcetypeid1, " . "resourcegroupid2, resourcetypeid2) " . "VALUES "; $query .= implode(',', $adds); doQuery($query); } else { foreach ($groupids as $id) { $query = "DELETE FROM resourcemap " . "WHERE resourcegroupid1 = {$id} AND " . "resourcetypeid1 = {$mytypeid} AND " . "resourcegroupid2 = {$mapgroupid} AND " . "resourcetypeid2 = {$maptypeid}"; doQuery($query); } } $regids = "^" . implode('$|^', $groupids) . "\$"; $arr = array('status' => 'success', 'regids' => $regids, 'inselobj' => 'inmaptogroups', 'outselobj' => 'outmaptogroups'); sendJSON($arr); }
function getResourceMapping($resourcetype1, $resourcetype2, $resource1inlist = "", $resource2inlist = "") { if (!is_numeric($resourcetype1)) { $resourcetype1 = getResourceTypeID($resourcetype1); } if (!is_numeric($resourcetype2)) { $resourcetype2 = getResourceTypeID($resourcetype2); } $return = array(); $query = "SELECT resourcegroupid1, " . "resourcetypeid1, " . "resourcegroupid2, " . "resourcetypeid2 " . "FROM resourcemap " . "WHERE ((resourcetypeid1 = {$resourcetype1} AND " . "resourcetypeid2 = {$resourcetype2}) OR " . "(resourcetypeid1 = {$resourcetype2} AND " . "resourcetypeid2 = {$resourcetype1})) "; if (!empty($resource1inlist)) { $query .= "AND resourcegroupid1 IN ({$resource1inlist}) "; } if (!empty($resource2inlist)) { $query .= "AND resourcegroupid2 IN ({$resource2inlist}) "; } $qh = doQuery($query, 101); while ($row = mysql_fetch_assoc($qh)) { if ($resourcetype1 == $row['resourcetypeid1']) { if (array_key_exists($row["resourcegroupid1"], $return)) { array_push($return[$row["resourcegroupid1"]], $row["resourcegroupid2"]); } else { $return[$row["resourcegroupid1"]] = array($row["resourcegroupid2"]); } } else { if (array_key_exists($row["resourcegroupid2"], $return)) { array_push($return[$row["resourcegroupid2"]], $row["resourcegroupid1"]); } else { $return[$row["resourcegroupid2"]] = array($row["resourcegroupid1"]); } } } return $return; }
function XMLRPCaddResourceGroup($name, $managingGroup, $type) { global $user; if (!in_array("groupAdmin", $user['privileges'])) { return array('status' => 'error', 'errorcode' => 16, 'errormsg' => 'access denied for managing groups'); } $validate = array('managingGroup' => $managingGroup); $rc = validateAPIgroupInput($validate, 0); if ($rc['status'] == 'error') { return $rc; } if ($typeid = getResourceTypeID($type)) { if (checkForGroupName($name, 'resource', '', $typeid)) { return array('status' => 'error', 'errorcode' => 76, 'errormsg' => 'resource group already exists'); } if (get_magic_quotes_gpc()) { $name = stripslashes($name); } if (!preg_match('/^[-a-zA-Z0-9_\\. ]{3,30}$/', $name)) { return array('status' => 'error', 'errorcode' => 87, 'errormsg' => 'Name must be between 3 and 30 characters and can only contain letters, numbers, spaces, and these characters: - . _'); } $name = mysql_real_escape_string($name); $data = array('type' => 'resource', 'ownergroup' => $rc['managingGroupID'], 'resourcetypeid' => $typeid, 'name' => $name); if (!addGroup($data)) { return array('status' => 'error', 'errorcode' => 26, 'errormsg' => 'failure while adding group to database'); } } else { return array('status' => 'error', 'errorcode' => 68, 'errormsg' => 'invalid resource type'); } return array('status' => 'success'); }