Example #1
0
function submitDeleteGroup()
{
    $groupid = getContinuationVar("groupid");
    $type = getContinuationVar("type");
    if ($type == "user") {
        $query = "UPDATE blockRequest " . "SET groupid = 0 " . "WHERE groupid = {$groupid}";
        doQuery($query);
        $table = "usergroup";
    } else {
        $table = "resourcegroup";
    }
    $query = "DELETE FROM {$table} " . "WHERE id = {$groupid}";
    doQuery($query, 315);
    clearPrivCache();
    viewGroups();
}
Example #2
0
function submitAddMgmtnode()
{
    $data = processMgmtnodeInput(0);
    addMgmtnode($data);
    clearPrivCache();
    viewMgmtnodes();
}
Example #3
0
function setupSession()
{
    global $mode;
    if ($mode == 'xmlrpccall') {
        $_SESSION = array();
    } else {
        session_start();
    }
    if (!array_key_exists('cachetimestamp', $_SESSION)) {
        $_SESSION['cachetimestamp'] = time();
    } else {
        if ($_SESSION['cachetimestamp'] + PRIV_CACHE_TIMEOUT * 60 < time()) {
            clearPrivCache();
            $_SESSION['cachetimestamp'] = time();
            return;
        }
    }
    if (!array_key_exists('userresources', $_SESSION)) {
        $_SESSION['userresources'] = array();
    }
    if (!array_key_exists('nodeprivileges', $_SESSION)) {
        $_SESSION['nodeprivileges'] = array();
    }
    if (!array_key_exists('cascadenodeprivileges', $_SESSION)) {
        $_SESSION['cascadenodeprivileges'] = array();
    }
    if (!array_key_exists('userhaspriv', $_SESSION)) {
        $_SESSION['userhaspriv'] = array();
    }
    if (!array_key_exists('compstateflow', $_SESSION)) {
        $_SESSION['compstateflow'] = array();
    }
    if (!array_key_exists('usersessiondata', $_SESSION)) {
        $_SESSION['usersessiondata'] = array();
    }
}
Example #4
0
function abort($errcode, $query = "")
{
    global $mysql_link_vcl, $mysql_link_acct, $ERRORS, $user, $mode;
    global $ENABLE_ITECSAUTH, $requestInfo, $aborting;
    if (!isset($aborting)) {
        $aborting = 1;
    } elseif ($aborting == 1) {
        return;
    }
    if ($mode == 'xmlrpccall') {
        xmlRPCabort($errcode, $query);
    }
    if (ONLINEDEBUG && checkUserHasPerm('View Debug Information')) {
        if ($errcode >= 100 && $errcode < 400) {
            print "<font color=red>" . mysql_error($mysql_link_vcl) . "</font><br>\n";
            error_log(mysql_error($mysql_link_vcl));
            if ($ENABLE_ITECSAUTH) {
                print "<font color=red>" . mysql_error($mysql_link_acct) . "</font><br>\n";
                error_log(mysql_error($mysql_link_acct));
            }
            print "{$query}<br>\n";
            error_log($query);
        }
        print "ERROR({$errcode}): " . $ERRORS["{$errcode}"] . "<BR>\n";
        error_log("ERROR({$errcode}): " . $ERRORS["{$errcode}"]);
        $backtrace = getBacktraceString(FALSE);
        print "<pre>\n";
        print $backtrace;
        print "</pre>\n";
        error_log($backtrace);
    } else {
        $message = "";
        if ($errcode >= 100 && $errcode < 400) {
            $message .= mysql_error($mysql_link_vcl) . "\n";
            if ($ENABLE_ITECSAUTH) {
                $message .= mysql_error($mysql_link_acct) . "\n";
            }
            $message .= $query . "\n";
        }
        $message .= "ERROR({$errcode}): " . $ERRORS["{$errcode}"] . "\n";
        if (is_array($user) && array_key_exists('unityid', $user)) {
            $message .= "Logged in user was " . $user["unityid"] . "\n";
        }
        $message .= "Mode was {$mode}\n\n";
        if ($errcode == 20) {
            $urlArray = explode('?', $_SERVER["HTTP_REFERER"]);
            $message .= "HTTP_REFERER URL - " . $urlArray[0] . "\n";
            $message .= "correct URL - " . BASEURL . SCRIPT . "\n";
        }
        if ($errcode == 40) {
            $message .= "One of the following computers didn't get a mgmt node:\n";
            foreach ($requestInfo["images"] as $key => $imageid) {
                $message .= "imageid: {$imageid}\n";
                $message .= "compid: {$requestInfo['computers'][$key]}\n";
            }
        }
        $message .= getBacktraceString(FALSE);
        if ($errcode == 8) {
            $message = preg_replace("/Argument#: 3 => .*\n/", "Argument#: 3 => *********\n", $message);
        }
        $mailParams = "-f" . ENVELOPESENDER;
        error_log($message);
        mail(ERROREMAIL, "Error with VCL pages ({$errcode})", $message, '', $mailParams);
        $subj = rawurlencode(i("Problem With VCL"));
        $href = "<a href=\"mailto:" . HELPEMAIL . "?Subject={$subj}\">" . HELPEMAIL . "</a>";
        printf(i("An error has occurred. If this problem persists, please email %s for further assistance. Please include the steps you took that led up to this problem in your email message."), $href);
    }
    // call clearPrivCache in case that helps clear up what caused the error
    clearPrivCache();
    // release semaphore lock
    cleanSemaphore();
    dbDisconnect();
    printHTMLFooter();
    exit;
}
Example #5
0
function AJsubmitAddResourcePriv()
{
    global $user;
    $node = processInputVar("activeNode", ARG_NUMERIC);
    if (!checkUserHasPriv("resourceGrant", $user["id"], $node)) {
        $text = "You do not have rights to add new resource groups at this node.";
        print "addUserGroupPaneHide(); ";
        print "alert('{$text}');";
        dbDisconnect();
        exit;
    }
    $newgroupid = processInputVar("newgroupid", ARG_NUMERIC);
    # FIXME validate newgroupid
    $perms = explode(':', processInputVar('perms', ARG_STRING));
    $privtypes = array("block", "cascade", "available", "administer", "manageGroup");
    $newgroupprivs = array();
    foreach ($privtypes as $type) {
        if (in_array($type, $perms)) {
            array_push($newgroupprivs, $type);
        }
    }
    if (empty($newgroupprivs) || count($newgroupprivs) == 1 && in_array("cascade", $newgroupprivs)) {
        $text = "<font color=red>No resource group privileges were specified</font>";
        print setAttribute('addResourceGroupPrivStatus', 'innerHTML', $text);
        dbDisconnect();
        exit;
    }
    updateResourcePrivs($newgroupid, $node, $newgroupprivs, array());
    clearPrivCache();
    print "addResourceGroupPaneHide(); ";
    print "refreshPerms(); ";
    dbDisconnect();
    exit;
}
Example #6
0
function AJsubmitAddResourcePriv()
{
    global $user;
    $node = processInputVar("activeNode", ARG_NUMERIC);
    if (!checkUserHasPriv("resourceGrant", $user["id"], $node)) {
        $text = "You do not have rights to add new resource groups at this node.";
        print "addResourceGroupPaneHide(); ";
        print "alert('{$text}');";
        return;
    }
    $newgroupid = processInputVar("newgroupid", ARG_NUMERIC);
    $privs = array("computerAdmin", "mgmtNodeAdmin", "imageAdmin", "scheduleAdmin", "serverProfileAdmin");
    $resourcegroups = getUserResources($privs, array("manageGroup"), 1);
    $groupdata = getResourceGroups('', $newgroupid);
    if (empty($groupdata)) {
        $text = "Invalid resource group submitted.";
        print "addResourceGroupPaneHide(); ";
        print "alert('{$text}');";
        return;
    }
    list($newtype, $tmp) = explode('/', $groupdata[$newgroupid]['name']);
    if (!array_key_exists($newgroupid, $resourcegroups[$newtype])) {
        $text = "You do not have rights to manage the specified resource group.";
        print "addResourceGroupPaneHide(); ";
        print "alert('{$text}');";
        return;
    }
    $perms = explode(':', processInputVar('perms', ARG_STRING));
    $privtypes = getResourcePrivs();
    $newgroupprivs = array();
    foreach ($privtypes as $type) {
        if (in_array($type, $perms)) {
            array_push($newgroupprivs, $type);
        }
    }
    if (empty($newgroupprivs) || count($newgroupprivs) == 1 && in_array("cascade", $newgroupprivs)) {
        $text = "<font color=red>No resource group privileges were specified</font>";
        print setAttribute('addResourceGroupPrivStatus', 'innerHTML', $text);
        return;
    }
    updateResourcePrivs($newgroupid, $node, $newgroupprivs, array());
    clearPrivCache();
    print "refreshPerms(); ";
    print "addResourceGroupPaneHide(); ";
}
Example #7
0
function submitAddBulkComputers()
{
    global $mysql_link_vcl;
    $data = processBulkComputerInput(0);
    $ownerid = getUserlistID($data["owner"]);
    $tmpArr = explode('.', $data["startipaddress"]);
    $startip = $tmpArr[3];
    $tmpArr = explode('.', $data["endipaddress"]);
    $endip = $tmpArr[3];
    array_pop($tmpArr);
    $baseaddr = implode('.', $tmpArr);
    $dopr = 0;
    if (!empty($data['startpripaddress'])) {
        $dopr = 1;
        $tmpArr = explode('.', $data["startpripaddress"]);
        $startprip = $tmpArr[3];
        $tmpArr = explode('.', $data["endpripaddress"]);
        $endprip = $tmpArr[3];
        array_pop($tmpArr);
        $basepraddr = implode('.', $tmpArr);
    }
    $domacs = 0;
    if (!empty($data['macs'])) {
        $domacs = 1;
        $maccnt = 0;
    }
    $dhcpdata = array();
    $count = 0;
    $addedrows = 0;
    for ($i = $startip, $j = $data["starthostval"]; $i <= $endip; $i++, $j++, $count++) {
        $hostname = str_replace('%', $j, $data["hostname"]);
        $ipaddress = $baseaddr . ".{$i}";
        $dhcpdata[$count] = array('hostname' => $hostname);
        if ($dopr) {
            $pripaddress = $basepraddr . '.' . $startprip++;
            $dhcpdata[$count]['prip'] = $pripaddress;
        }
        if ($domacs) {
            $eth0 = $data['macs'][$maccnt++];
            $eth1 = $data['macs'][$maccnt++];
            $dhcpdata[$count]['eth0mac'] = $eth0;
        }
        $query = "INSERT INTO computer " . "(stateid, " . "ownerid, " . "platformid, " . "provisioningid, " . "scheduleid, " . "currentimageid, " . "RAM, " . "procnumber, " . "procspeed, " . "network, " . "hostname, " . "IPaddress, ";
        if ($dopr) {
            $query .= "privateIPaddress, ";
        }
        if ($domacs) {
            $query .= "eth0macaddress, " . "eth1macaddress, ";
        }
        $query .= "type) " . "VALUES ({$data["stateid"]}, " . "{$ownerid}, " . "{$data["platformid"]}, " . "{$data["provisioningid"]}, " . "{$data["scheduleid"]}, " . "4, " . "{$data["ram"]}, " . "{$data["numprocs"]}, " . "{$data["procspeed"]}, " . "{$data["network"]}, " . "'{$hostname}', " . "'{$ipaddress}', ";
        if ($dopr) {
            $query .= "'{$pripaddress}', ";
        }
        if ($domacs) {
            $query .= "'{$eth0}', " . "'{$eth1}', ";
        }
        $query .= "'{$data["type"]}')";
        $qh = doQuery($query, 235);
        $addedrows += mysql_affected_rows($mysql_link_vcl);
        $qh = doQuery("SELECT LAST_INSERT_ID() FROM computer", 236);
        if (!($row = mysql_fetch_row($qh))) {
            abort(237);
        }
        $query = "INSERT INTO resource " . "(resourcetypeid, " . "subid) " . "VALUES (12, " . $row[0] . ")";
        doQuery($query, 238);
        // add computer into selected groups
        $qh = doQuery("SELECT LAST_INSERT_ID() FROM resource", 101);
        if (!($row = mysql_fetch_row($qh))) {
            abort(237);
        }
        foreach (array_keys($data["computergroup"]) as $groupid) {
            $query = "INSERT INTO resourcegroupmembers " . "(resourceid, " . "resourcegroupid) " . "VALUES ({$row[0]}, " . "{$groupid})";
            doQuery($query, 101);
        }
    }
    print "<DIV align=center>\n";
    print "<H2>Add Multiple Computers</H2>\n";
    if ($count == $addedrows) {
        print "The computers were added successfully.<br><br>\n";
    } else {
        print $count - $addedrows . " computers failed to get added<br><br>\n";
    }
    print "</div>\n";
    if ($domacs) {
        generateDhcpForm($dhcpdata);
    }
    clearPrivCache();
}