Beispiel #1
0
function getUserResources($userprivs, $resourceprivs = array("available"), $onlygroups = 0, $includedeleted = 0, $userid = 0)
{
    global $user, $viewmode;
    $key = getKey(array($userprivs, $resourceprivs, $onlygroups, $includedeleted, $userid));
    if (array_key_exists($key, $_SESSION['userresources'])) {
        return $_SESSION['userresources'][$key];
    }
    #FIXME this whole function could be much more efficient
    if (!$userid) {
        $userid = $user["id"];
    }
    $return = array();
    $nodeprivs = array();
    $startnodes = array();
    # build a list of nodes where user is granted $userprivs
    $inlist = "'" . implode("','", $userprivs) . "'";
    $query = "SELECT u.privnodeid " . "FROM userpriv u, " . "userprivtype t " . "WHERE u.userprivtypeid = t.id AND " . "t.name IN ({$inlist}) AND " . "(u.userid = {$userid} OR " . "u.usergroupid IN (SELECT usergroupid " . "FROM usergroupmembers " . "WHERE userid = {$userid}))";
    $qh = doQuery($query, 101);
    while ($row = mysql_fetch_assoc($qh)) {
        array_push($startnodes, $row["privnodeid"]);
    }
    # travel up tree looking at privileges granted at parent nodes
    foreach ($startnodes as $nodeid) {
        getUserResourcesUp($nodeprivs, $nodeid, $userid, $userprivs);
    }
    # travel down tree looking at privileges granted at child nodes if cascade privs at this node
    foreach ($startnodes as $nodeid) {
        getUserResourcesDown($nodeprivs, $nodeid, $userid, $userprivs);
    }
    $nodeprivs = simplifyNodePrivs($nodeprivs, $userprivs);
    // call this before calling addUserResources
    addUserResources($nodeprivs, $userid);
    # build a list of resource groups user has access to
    $resourcegroups = array();
    $types = getTypes("resources");
    foreach ($types["resources"] as $type) {
        $resourcegroups[$type] = array();
    }
    foreach (array_keys($nodeprivs) as $nodeid) {
        // if user doesn't have privs at this node, no need to look
        // at any resource groups here
        $haspriv = 0;
        foreach ($userprivs as $priv) {
            if ($nodeprivs[$nodeid][$priv]) {
                $haspriv = 1;
            }
        }
        if (!$haspriv) {
            continue;
        }
        # check to see if resource groups has any of $resourceprivs at this node
        foreach (array_keys($nodeprivs[$nodeid]["resources"]) as $resourceid) {
            foreach ($resourceprivs as $priv) {
                if (in_array($priv, $nodeprivs[$nodeid]["resources"][$resourceid])) {
                    list($type, $name, $id) = split('/', $resourceid);
                    if (!array_key_exists($type, $resourcegroups)) {
                        $resourcegroups[$type] = array();
                    }
                    if (!in_array($name, $resourcegroups[$type])) {
                        $resourcegroups[$type][$id] = $name;
                    }
                }
            }
        }
        # check to see if resource groups has any of $resourceprivs cascaded to this node
        foreach (array_keys($nodeprivs[$nodeid]["cascaderesources"]) as $resourceid) {
            foreach ($resourceprivs as $priv) {
                if (in_array($priv, $nodeprivs[$nodeid]["cascaderesources"][$resourceid]) && !(array_key_exists($resourceid, $nodeprivs[$nodeid]["resources"]) && in_array("block", $nodeprivs[$nodeid]["resources"][$resourceid]))) {
                    list($type, $name, $id) = split('/', $resourceid);
                    if (!array_key_exists($type, $resourcegroups)) {
                        $resourcegroups[$type] = array();
                    }
                    if (!in_array($name, $resourcegroups[$type])) {
                        $resourcegroups[$type][$id] = $name;
                    }
                }
            }
        }
    }
    addOwnedResourceGroups($resourcegroups, $userid);
    if ($onlygroups) {
        foreach (array_keys($resourcegroups) as $type) {
            uasort($resourcegroups[$type], "sortKeepIndex");
        }
        $_SESSION['userresources'][$key] = $resourcegroups;
        return $resourcegroups;
    }
    $resources = array();
    foreach (array_keys($resourcegroups) as $type) {
        $resources[$type] = getResourcesFromGroups($resourcegroups[$type], $type, $includedeleted);
    }
    addOwnedResources($resources, $includedeleted, $userid);
    $_SESSION['userresources'][$key] = $resources;
    return $resources;
}
Beispiel #2
0
 function AJfilterCompGroups()
 {
     $groupids = processInputVar('groupids', ARG_STRING);
     if (!preg_match('/^[0-9,]+$/', $groupids)) {
         $ret = array('status' => 'error', 'errormsg' => "Invalid data submitted.");
         sendJSON($ret);
         return;
     }
     $groupids = explode(',', $groupids);
     $tmp = getUserResources(array($this->restype . 'Admin'), array('manageGroup'), 1);
     $groups = $tmp[$this->restype];
     $groupnames = array();
     foreach ($groupids as $id) {
         if (array_key_exists($id, $groups)) {
             $groupnames[] = $groups[$id];
         }
     }
     $comps = getResourcesFromGroups($groupnames, 'computer', 1);
     $regids = "^" . implode('$|^', array_keys($comps)) . "\$";
     $arr = array('status' => 'success', 'regids' => $regids);
     sendJSON($arr);
 }
Beispiel #3
0
function getMnsFromImage($imageid)
{
    $comps = getMappedResources($imageid, 'image', 'computer');
    if (empty($comps)) {
        return array();
    }
    $inlist = implode(',', $comps);
    $query = "SELECT DISTINCT rgm.resourcegroupid " . "FROM resourcegroupmembers rgm, " . "resource r, " . "computer c " . "WHERE c.id = r.subid AND " . "r.resourcetypeid = 12 AND " . "r.id = rgm.resourceid AND " . "c.id in ({$inlist})";
    $qh = doQuery($query);
    $compgroups = array();
    while ($row = mysql_fetch_assoc($qh)) {
        $compgroups[] = $row['resourcegroupid'];
    }
    $mngrps = array();
    foreach ($compgroups as $grpid) {
        $mngrpset = getResourceMapping('managementnode', 'computer', '', implode(',', $compgroups));
        foreach ($mngrpset as $mngrpid => $compgrpset) {
            $mngrps[$mngrpid] = 1;
        }
    }
    $mngrpnames = array();
    foreach (array_keys($mngrps) as $mnid) {
        $mngrpnames[] = getResourceGroupName($mnid);
    }
    $mns = getResourcesFromGroups($mngrpnames, 'managementnode', 0);
    $mnids = array();
    foreach ($mns as $mnid => $name) {
        $mnids[$mnid] = 1;
    }
    return array_keys($mnids);
}