Пример #1
0
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();
}
Пример #2
0
function getResourceMapping($dt_code)
{
    $arrdt = explode(".", $dt_code);
    if (count($arrdt) > 2) {
        $dt_code = array_shift($arrdt);
        // $arrdt[0];
        $resource_rt_id = array_shift($arrdt);
        //$arrdt[1]; //resource record type
        $resource_dt_id = $arrdt[0];
    } else {
        return "  wrong resource mapping " . $dt_code;
    }
    $dt_id = getDetailTypeLocalID($dt_code);
    if ($dt_id == null) {
        return " detail type not found " . $dt_code;
    }
    $res_rt_id = getRecTypeLocalID($resource_rt_id);
    if ($res_rt_id == null) {
        return " resource record type not recognized: " . $resource_rt_id;
    }
    $res_dt_id = getDetailTypeLocalID($resource_dt_id);
    if ($res_dt_id == null) {
        return " detail type for resource not recognized " . $resource_dt_id;
    }
    if (count($arrdt) > 1) {
        // next level
        $subres = getResourceMapping(implode(".", $arrdt));
        if (is_array($subres)) {
            $res = array($dt_id, $res_rt_id, $subres);
        } else {
            return $subres;
        }
    } else {
        //pointer detail type and detail type in resource record
        $res = array($dt_id, $res_rt_id, $res_dt_id);
    }
    return $res;
}
Пример #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);
}
Пример #4
0
 function jsonResourceMappingGroups()
 {
     $resmaptogrpid = processInputVar('id', ARG_NUMERIC);
     $resources = getUserResources(array($this->maptype . "Admin"), array("manageMapping"), 1);
     if (!array_key_exists($resmaptogrpid, $resources[$this->maptype])) {
         sendJSON(array('status' => 'noaccess'));
         return;
     }
     $groups = getUserResources(array($this->restype . 'Admin'), array('manageMapping'), 1);
     $mapping = getResourceMapping($this->maptype, $this->restype);
     $all = array();
     foreach ($groups[$this->restype] as $id => $group) {
         if (array_key_exists($resmaptogrpid, $mapping) && in_array($id, $mapping[$resmaptogrpid])) {
             $all[] = array('id' => $id, 'name' => $group, 'inout' => 1);
         } else {
             $all[] = array('id' => $id, 'name' => $group, 'inout' => 0);
         }
     }
     $arr = array('items' => $all, 'intitle' => getContinuationVar('intitle'), 'outtitle' => getContinuationVar('outtitle'));
     sendJSON($arr);
 }
Пример #5
0
function jsonImageMapImgGroups()
{
    $compgrpid = processInputVar('compgrpid', ARG_NUMERIC);
    $resources = getUserResources(array("computerAdmin"), array("manageGroup"), 1);
    if (!array_key_exists($compgrpid, $resources['computer'])) {
        $arr = array('ingroups' => array(), 'outgroups' => array(), 'all' => array());
        header('Content-Type: text/json-comment-filtered; charset=utf-8');
        print '/*{"items":' . json_encode($arr) . '}*/';
        return;
    }
    $imagegroups = getUserResources(array('imageAdmin'), array('manageGroup'), 1);
    $mapping = getResourceMapping('computer', 'image');
    $in = array();
    $out = array();
    $all = array();
    foreach ($imagegroups['image'] as $id => $group) {
        if (array_key_exists($compgrpid, $mapping) && in_array($id, $mapping[$compgrpid])) {
            $all[] = array('inout' => 1, 'id' => $id, 'name' => $group);
            $in[] = array('name' => $group, 'id' => $id);
        } else {
            $all[] = array('inout' => 0, 'id' => $id, 'name' => $group);
            $out[] = array('name' => $group, 'id' => $id);
        }
    }
    $arr = array('ingroups' => $in, 'outgroups' => $out, 'all' => $all);
    print '/*{"items":' . json_encode($arr) . '}*/';
}
Пример #6
0
function XMLRPCremoveImageGroupFromComputerGroup($imageGroup, $computerGroup)
{
    $imageid = getResourceGroupID("image/{$imageGroup}");
    $compid = getResourceGroupID("computer/{$computerGroup}");
    if ($imageid && $compid) {
        $tmp = getUserResources(array("imageAdmin"), array("manageMapping"), 1);
        $imagegroups = $tmp['image'];
        $tmp = getUserResources(array("computerAdmin"), array("manageMapping"), 1);
        $computergroups = $tmp['computer'];
        if (array_key_exists($compid, $computergroups) && array_key_exists($imageid, $imagegroups)) {
            $mapping = getResourceMapping("image", "computer", $imageid, $compid);
            if (array_key_exists($imageid, $mapping) && in_array($compid, $mapping[$imageid])) {
                $query = "DELETE FROM resourcemap " . "WHERE resourcegroupid1 = {$imageid} AND " . "resourcetypeid1 = 13 AND " . "resourcegroupid2 = {$compid} AND " . "resourcetypeid2 = 12";
                doQuery($query, 101);
            }
            return array('status' => 'success');
        } else {
            return array('status' => 'error', 'errorcode' => 84, 'errormsg' => 'cannot access computer and/or image group');
        }
    } else {
        return array('status' => 'error', 'errorcode' => 83, 'errormsg' => 'invalid resource group name');
    }
}