Example #1
0
    listRequestsByCacheId($cacheid);
} elseif ($action == 'add') {
    $tpl->assign('action', 'listbycache');
    $cacheid = isset($_REQUEST['cacheid']) ? $_REQUEST['cacheid'] + 0 : 0;
    $tou = isset($_REQUEST['tou']) ? $_REQUEST['tou'] + 0 : 0;
    $submit = isset($_REQUEST['submit']) ? $_REQUEST['submit'] + 0 : 0;
    $username = isset($_REQUEST['username']) ? $_REQUEST['username'] : '';
    $tpl->assign('adoptusername', $username);
    if ($submit == 1) {
        $userid = sql_value("SELECT `user_id` FROM `user` WHERE `username`='&1'", 0, $username);
        if ($userid == 0) {
            $tpl->assign('error', 'userunknown');
        } elseif ($tou != 1) {
            $tpl->assign('error', 'tou');
        } else {
            addRequest($cacheid, $userid);
        }
    }
    listRequestsByCacheId($cacheid);
} elseif ($action == 'cancel') {
    $cacheid = isset($_REQUEST['cacheid']) ? $_REQUEST['cacheid'] + 0 : 0;
    $userid = isset($_REQUEST['userid']) ? $_REQUEST['userid'] + 0 : 0;
    cancelRequest($cacheid, $userid);
} elseif ($action == 'commit') {
    $cacheid = isset($_REQUEST['cacheid']) ? $_REQUEST['cacheid'] + 0 : 0;
    $submit = isset($_REQUEST['submit']) ? $_REQUEST['submit'] + 0 : 0;
    $tou = isset($_REQUEST['tou']) ? $_REQUEST['tou'] + 0 : 0;
    if ($submit == 1 && $tou == 1) {
        commitRequest($cacheid);
    } else {
        showAdoptScreen($cacheid, $submit);
Example #2
0
function AJnewRequest()
{
    global $user, $remoteIP;
    $data = processRequestInput();
    #$data['err'] = 1;
    #$data['errmsg'] = 'none';
    if ($data['err']) {
        sendJSON($data);
        return;
    }
    if ($data['start'] == 0) {
        $nowfuture = 'now';
        $startts = unixFloor15();
        if ($data['ending'] == 'duration') {
            $endts = $startts + $data['duration'] * 60;
            $nowArr = getdate();
            if ($nowArr['minutes'] % 15 != 0) {
                $endts += 900;
            }
        }
    } else {
        $nowfuture = 'future';
        $startts = $data['start'];
        if ($data['ending'] == 'duration') {
            $endts = $startts + $data['duration'] * 60;
        }
    }
    if ($data['ending'] == 'indefinite') {
        $endts = datetimeToUnix('2038-01-01 00:00:00');
    } elseif ($data['ending'] == 'endat') {
        $endts = $data['end'];
    }
    $images = getImages();
    # TODO initially, this is a hack where we munge the datastructure
    # finishconfigs
    /*if($data['type'] == 'server') {
    		$tmp = getConfigClusters($data['imageid'], 1);
    		if(count($tmp)) {
    			$subimages = array();
    			foreach($tmp as $cluster) {
    				for($i = 0; $i < $cluster['maxinstance']; $i++)
    					$subimages[] = $cluster['childimageid'];
    			}
    			$images[$data['imageid']]['subimages'] = $subimages;
    			if($images[$data['imageid']]['imagemetaid'] == NULL)
    				$images[$data['imageid']]['imagemetaid'] = 1;
    		}
    		elseif($images[$data['imageid']]['imagemetaid'] != NULL &&
    			count($images[$data['imageid']]['subimages'])) {
    			$images[$data['imageid']]['subimages'] = array();
    		}
    	}*/
    # check for exceeding max overlaps
    $max = getMaxOverlap($user['id']);
    if (checkOverlap($startts, $endts, $max)) {
        print "dojo.byId('deployerr').innerHTML = '";
        print i("The selected time overlaps with another reservation you have.");
        print "<br>";
        if ($max == 0) {
            print i("You cannot have any overlapping reservations.");
        } else {
            printf(i("You can have up to %d overlapping reservations."), $max);
        }
        print "'; dojo.removeClass('deployerr', 'hidden');";
        return;
    }
    $imaging = 0;
    if ($data['type'] == 'imaging') {
        $imaging = 1;
    }
    $availablerc = isAvailable($images, $data['imageid'], $data['revisionids'], $startts, $endts, 1, 0, 0, 0, $imaging, $data['ipaddr'], $data['macaddr']);
    if ($availablerc == -4) {
        $msg = i("The IP address you specified is assigned to another VCL node and cannot be used at this time. Submitting a time in the future may allow you to make the reservation, but if the IP remains assigned to the other node, the reservation will fail at deploy time.");
        $data = array('err' => 1, 'errmsg' => $msg);
        sendJSON($data);
        return;
    } elseif ($availablerc == -3) {
        $msg = i("The IP or MAC address you specified overlaps with another reservation using the same IP or MAC address you specified. Please use a different IP or MAC or select a different time to deploy the server.");
        $data = array('err' => 1, 'errmsg' => $msg);
        sendJSON($data);
        return;
    } elseif ($availablerc == -2) {
        $msg = i("The time you requested overlaps with a maintenance window.");
        $data = array('err' => 1, 'errmsg' => $msg);
        sendJSON($data);
        return;
    } elseif ($availablerc == -1) {
        cleanSemaphore();
        $msg = i("You have requested an environment that is limited in the number of concurrent reservations that can be made. No further reservations for the environment can be made for the time you have selected.");
        $data = array('err' => 1, 'errmsg' => $msg);
        sendJSON($data);
        return;
    } elseif ($availablerc == 0) {
        cleanSemaphore();
        $data = array('err' => 2);
        sendJSON($data);
        return;
    }
    $requestid = addRequest($imaging, $data['revisionids'], 1 - $data['nousercheck']);
    if ($data['type'] == 'server') {
        if ($data['ipaddr'] != '') {
            # save additional network info in variable table
            $allnets = getVariable('fixedIPavailnetworks', array());
            $key = long2ip($data['network']) . "/{$data['netmask']}";
            $allnets[$key] = array('router' => $data['router'], 'dns' => $data['dnsArr']);
            setVariable('fixedIPavailnetworks', $allnets, 'yaml');
        }
        $query = "UPDATE reservation " . "SET remoteIP = '{$remoteIP}' " . "WHERE requestid = {$requestid}";
        doQuery($query);
        $fields = array('requestid', 'serverprofileid');
        $values = array($requestid, $data['profileid']);
        if ($data['name'] == '') {
            $fields[] = 'name';
            $name = $images[$data['imageid']]['prettyname'];
            $values[] = "'{$name}'";
        } else {
            $fields[] = 'name';
            $name = mysql_real_escape_string($data['name']);
            $values[] = "'{$name}'";
        }
        if ($data['ipaddr'] != '') {
            $fields[] = 'fixedIP';
            $values[] = "'{$data['ipaddr']}'";
        }
        if ($data['macaddr'] != '') {
            $fields[] = 'fixedMAC';
            $values[] = "'{$data['macaddr']}'";
        }
        if ($data['admingroupid'] != 0) {
            $fields[] = 'admingroupid';
            $values[] = $data['admingroupid'];
        }
        if ($data['logingroupid'] != 0) {
            $fields[] = 'logingroupid';
            $values[] = $data['logingroupid'];
        }
        if ($data['monitored'] != 0) {
            $fields[] = 'monitored';
            $values[] = 1;
        }
        $allfields = implode(',', $fields);
        $allvalues = implode(',', $values);
        $query = "INSERT INTO serverrequest ({$allfields}) VALUES ({$allvalues})";
        doQuery($query, 101);
        if ($data['ipaddr'] != '') {
            $srqid = dbLastInsertID();
            $var = array('netmask' => $data['netmask'], 'router' => $data['router'], 'dns' => $data['dnsArr']);
            setVariable("fixedIPsr{$srqid}", $var, 'yaml');
        }
        # TODO configs
        //saveRequestConfigs($requestid, $data['imageid'], $data['configs'], $data['configvars']);
    }
    $data = array('err' => 0);
    sendJSON($data);
}
Example #3
0
function submitRequest()
{
    global $submitErr, $user, $viewmode, $HTMLheader, $mode, $printedHTMLheader;
    if ($mode == 'submitTestProd') {
        $data = getContinuationVar();
        $data["revisionid"] = processInputVar("revisionid", ARG_MULTINUMERIC);
        # TODO check for valid revisionids for each image
        if (!empty($data["revisionid"])) {
            foreach ($data['revisionid'] as $key => $val) {
                if (!is_numeric($val) || $val < 0) {
                    unset($data['revisionid']);
                }
            }
        }
    } else {
        $data = processRequestInput(1);
    }
    if ($submitErr) {
        $printedHTMLheader = 1;
        print $HTMLheader;
        print "<H2>New Reservation</H2>\n";
        newReservation();
        print getFooter();
        return;
    }
    // FIXME hack to make sure user didn't submit a request for an image he
    // doesn't have access to
    $resources = getUserResources(array("imageAdmin", "imageCheckOut"));
    $validImageids = array_keys($resources['image']);
    if (!in_array($data['imageid'], $validImageids)) {
        $data['imageid'] = array_shift($validImageids);
    }
    $showrevisions = 0;
    $subimages = 0;
    $images = getImages();
    $revcount = count($images[$data['imageid']]['imagerevision']);
    if ($revcount > 1) {
        $showrevisions = 1;
    }
    if ($images[$data['imageid']]['imagemetaid'] != NULL && count($images[$data['imageid']]['subimages'])) {
        $subimages = 1;
        foreach ($images[$data['imageid']]['subimages'] as $subimage) {
            $revcount = count($images[$subimage]['imagerevision']);
            if ($revcount > 1) {
                $showrevisions = 1;
            }
        }
    }
    if ($data["time"] == "now") {
        $nowArr = getdate();
        if ($nowArr["minutes"] == 0) {
            $subtract = 0;
            $add = 0;
        } elseif ($nowArr["minutes"] < 15) {
            $subtract = $nowArr["minutes"] * 60;
            $add = 900;
        } elseif ($nowArr["minutes"] < 30) {
            $subtract = ($nowArr["minutes"] - 15) * 60;
            $add = 900;
        } elseif ($nowArr["minutes"] < 45) {
            $subtract = ($nowArr["minutes"] - 30) * 60;
            $add = 900;
        } elseif ($nowArr["minutes"] < 60) {
            $subtract = ($nowArr["minutes"] - 45) * 60;
            $add = 900;
        }
        $start = time() - $subtract;
        $start -= $start % 60;
        $nowfuture = "now";
    } else {
        $add = 0;
        $hour = $data["hour"];
        if ($data["hour"] == 12) {
            if ($data["meridian"] == "am") {
                $hour = 0;
            }
        } elseif ($data["meridian"] == "pm") {
            $hour = $data["hour"] + 12;
        }
        $tmp = explode('/', $data["day"]);
        $start = mktime($hour, $data["minute"], "0", $tmp[0], $tmp[1], $tmp[2]);
        if ($start < time()) {
            $printedHTMLheader = 1;
            print $HTMLheader;
            print "<H2>New Reservation</H2>\n";
            print "<font color=\"#ff0000\">The time you requested is in the past.";
            print " Please select \"Now\" or use a time in the future.</font><br>\n";
            $submitErr = 1;
            newReservation();
            print getFooter();
            return;
        }
        $nowfuture = "future";
    }
    if ($data["ending"] == "length") {
        $end = $start + $data["length"] * 60 + $add;
    } else {
        $end = datetimeToUnix($data["enddate"]);
        if ($end % (15 * 60)) {
            $end = unixFloor15($end) + 15 * 60;
        }
    }
    // get semaphore lock
    if (!semLock()) {
        abort(3);
    }
    $availablerc = isAvailable($images, $data["imageid"], $start, $end, $data["os"]);
    $max = getMaxOverlap($user['id']);
    if ($availablerc != 0 && checkOverlap($start, $end, $max)) {
        $printedHTMLheader = 1;
        print $HTMLheader;
        print "<H2>New Reservation</H2>\n";
        if ($max == 0) {
            print "<font color=\"#ff0000\">The time you requested overlaps with ";
            print "another reservation you currently have.  You are only allowed ";
            print "to have a single reservation at any given time. Please select ";
            print "another time to use the application. If you are finished with ";
            print "an active reservation, click \"Current Reservations\", ";
            print "then click the \"End\" button of your active reservation.";
            print "</font><br><br>\n";
        } else {
            print "<font color=\"#ff0000\">The time you requested overlaps with ";
            print "another reservation you currently have.  You are allowed ";
            print "to have {$max} overlapping reservations at any given time. ";
            print "Please select another time to use the application. If you are ";
            print "finished with an active reservation, click \"Current ";
            print "Reservations\", then click the \"End\" button of your active ";
            print "reservation.</font><br><br>\n";
        }
        $submitErr = 1;
        newReservation();
        print getFooter();
        return;
    }
    // if user is owner of the image and there is a test version of the image
    #   available, ask user if production or test image desired
    if ($mode != "submitTestProd" && $showrevisions && $images[$data["imageid"]]["ownerid"] == $user["id"]) {
        #unset($data["testprod"]);
        $printedHTMLheader = 1;
        print $HTMLheader;
        print "<H2>New Reservation</H2>\n";
        if ($subimages) {
            print "This is a cluster environment. At least one image in the ";
            print "cluster has more than one version available. Please select ";
            print "the version you desire for each image listed below:<br>\n";
        } else {
            print "There are multiple versions of this environment available.  Please ";
            print "select the version you would like to check out:<br>\n";
        }
        print "<FORM action=\"" . BASEURL . SCRIPT . "\" method=post><br>\n";
        if (!array_key_exists('subimages', $images[$data['imageid']])) {
            $images[$data['imageid']]['subimages'] = array();
        }
        array_unshift($images[$data['imageid']]['subimages'], $data['imageid']);
        foreach ($images[$data['imageid']]['subimages'] as $subimage) {
            print "{$images[$subimage]['prettyname']}:<br>\n";
            print "<table summary=\"lists versions of the selected environment, one must be selected to continue\">\n";
            print "  <TR>\n";
            print "    <TD></TD>\n";
            print "    <TH>Version</TH>\n";
            print "    <TH>Creator</TH>\n";
            print "    <TH>Created</TH>\n";
            print "    <TH>Currently in Production</TH>\n";
            print "  </TR>\n";
            foreach ($images[$subimage]['imagerevision'] as $revision) {
                print "  <TR>\n";
                if (array_key_exists($subimage, $data['revisionid']) && $data['revisionid'][$subimage] == $revision['id']) {
                    print "    <TD align=center><INPUT type=radio name=revisionid[{$subimage}] value={$revision['id']} checked></TD>\n";
                } elseif ($revision['production']) {
                    print "    <TD align=center><INPUT type=radio name=revisionid[{$subimage}] value={$revision['id']} checked></TD>\n";
                } else {
                    print "    <TD align=center><INPUT type=radio name=revisionid[{$subimage}] value={$revision['id']}></TD>\n";
                }
                print "    <TD align=center>{$revision['revision']}</TD>\n";
                print "    <TD align=center>{$revision['user']}</TD>\n";
                print "    <TD align=center>{$revision['prettydate']}</TD>\n";
                if ($revision['production']) {
                    print "    <TD align=center>Yes</TD>\n";
                } else {
                    print "    <TD align=center>No</TD>\n";
                }
                print "  </TR>\n";
            }
            print "</table>\n";
        }
        $cont = addContinuationsEntry('submitTestProd', $data);
        print "<br><INPUT type=hidden name=continuation value=\"{$cont}\">\n";
        print "<INPUT type=submit value=\"Create Reservation\">\n";
        print "</FORM>\n";
        print getFooter();
        return;
    }
    if ($availablerc == -1) {
        $printedHTMLheader = 1;
        print $HTMLheader;
        print "<H2>New Reservation</H2>\n";
        print "You have requested an environment that is limited in the number ";
        print "of concurrent reservations that can be made. No further ";
        print "reservations for the environment can be made for the time you ";
        print "have selected. Please select another time to use the ";
        print "environment.<br>";
        addLogEntry($nowfuture, unixToDatetime($start), unixToDatetime($end), 0, $data["imageid"]);
        print getFooter();
    } elseif ($availablerc > 0) {
        $requestid = addRequest(0, $data["revisionid"]);
        $time = prettyLength($data["length"]);
        if ($data["time"] == "now") {
            $cdata = array('lengthchanged' => $data['lengthchanged']);
            $cont = addContinuationsEntry('viewRequests', $cdata);
            header("Location: " . BASEURL . SCRIPT . "?continuation={$cont}");
            dbDisconnect();
            exit;
        } else {
            if ($data["minute"] == 0) {
                $data["minute"] = "00";
            }
            $printedHTMLheader = 1;
            print $HTMLheader;
            print "<H2>New Reservation</H2>\n";
            if ($data["ending"] == "length") {
                if ($data['testjavascript'] == 0 && $data['lengthchanged']) {
                    print "<font color=red>NOTE: The maximum allowed reservation ";
                    print "length for this environment is {$time}, and the length of ";
                    print "this reservation has been adjusted accordingly.</font>\n";
                    print "<br><br>\n";
                }
                print "Your request to use <b>" . $images[$data["imageid"]]["prettyname"];
                print "</b> on " . prettyDatetime($start) . " for {$time} has been ";
                print "accepted.<br><br>\n";
            } else {
                print "Your request to use <b>" . $images[$data["imageid"]]["prettyname"];
                print "</b> starting " . prettyDatetime($start) . " and ending ";
                print prettyDatetime($end) . " has been accepted.<br><br>\n";
            }
            print "When your reservation time has been reached, the <strong>";
            print "Current Reservations</strong> page will have further ";
            print "instructions on connecting to the reserved computer.  If you ";
            print "would like to modify your reservation, you can do that from ";
            print "the <b>Current Reservations</b> page as well.<br>\n";
            print getFooter();
        }
    } else {
        $cdata = array('imageid' => $data['imageid'], 'length' => $data['length'], 'showmessage' => 1);
        $cont = addContinuationsEntry('selectTimeTable', $cdata);
        addLogEntry($nowfuture, unixToDatetime($start), unixToDatetime($end), 0, $data["imageid"]);
        header("Location: " . BASEURL . SCRIPT . "?continuation={$cont}");
        /*print "<H2>New Reservation</H2>\n";
        		print "The reservation you have requested is not available. You may ";
        		print "<a href=\"" . BASEURL . SCRIPT . "?continuation=$cont\">";
        		print "view a timetable</a> of free and reserved times to find ";
        		print "a time that will work for you.<br>\n";*/
    }
}
Example #4
0
<?php

session_start();
require "pdo.php";
$userID = $_SESSION["userID"];
$targetID = $_POST["targetID"];
$daySlot = $_POST["daySlot"];
if (verifyRequest($userID, $targetID, $daySlot) == false) {
    $status = addRequest($userID, $targetID, $daySlot);
    echo $status;
} else {
    echo false;
}
Example #5
0
<!DOCTYPE html>

<?php 
require_once '/var/www/html/app/library/function.php';
if (!isset($_SESSION['current_user_name']) && !isset($_COOKIE[$cookie_name])) {
    header('Location: ../login.php');
    exit;
}
require_once 'controllerTest.php';
if (isset($_POST['addBuildingSubmit']) && !empty($_POST['EmpSelect']) && !empty($_POST['ZoneSelect'])) {
    addRequest();
}
?>

<html lang="en">

<head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>Zoo - Maintenance</title>

    <!-- Bootstrap Core CSS -->
    <link href="css/bootstrap.min.css" rel="stylesheet">

    <!-- Custom CSS -->
    <link href="css/agency.css" rel="stylesheet">
Example #6
0
function submitCreateImage()
{
    global $submitErr, $user, $viewmode, $HTMLheader, $printedHTMLheader, $mode;
    if ($mode == 'submitCreateTestProd') {
        $data = getContinuationVar();
        $data["revisionid"] = processInputVar("revisionid", ARG_MULTINUMERIC);
        # TODO check for valid revisionid
    } else {
        $data = processRequestInput(0);
        $data['length'] = getContinuationVar('length');
    }
    $showrevisions = 0;
    $subimages = 0;
    $images = getImages();
    $revcount = count($images[$data['imageid']]['imagerevision']);
    if ($revcount > 1) {
        $showrevisions = 1;
    }
    if ($images[$data['imageid']]['imagemetaid'] != NULL && count($images[$data['imageid']]['subimages'])) {
        $subimages = 1;
        foreach ($images[$data['imageid']]['subimages'] as $subimage) {
            $revcount = count($images[$subimage]['imagerevision']);
            if ($revcount > 1) {
                $showrevisions = 1;
            }
        }
    }
    if ($data["time"] == "now") {
        $nowArr = getdate();
        if ($nowArr["minutes"] == 0) {
            $subtract = 0;
            $add = 0;
        } elseif ($nowArr["minutes"] < 15) {
            $subtract = $nowArr["minutes"] * 60;
            $add = 900;
        } elseif ($nowArr["minutes"] < 30) {
            $subtract = ($nowArr["minutes"] - 15) * 60;
            $add = 900;
        } elseif ($nowArr["minutes"] < 45) {
            $subtract = ($nowArr["minutes"] - 30) * 60;
            $add = 900;
        } elseif ($nowArr["minutes"] < 60) {
            $subtract = ($nowArr["minutes"] - 45) * 60;
            $add = 900;
        }
        $start = time() - $subtract;
        $start -= $start % 60;
        $nowfuture = "now";
    } else {
        $add = 0;
        $hour = $data["hour"];
        if ($data["hour"] == 12) {
            if ($data["meridian"] == "am") {
                $hour = 0;
            }
        } elseif ($data["meridian"] == "pm") {
            $hour = $data["hour"] + 12;
        }
        $tmp = explode('/', $data["day"]);
        $start = mktime($hour, $data["minute"], "0", $tmp[0], $tmp[1], $tmp[2]);
        if ($start < time()) {
            print $HTMLheader;
            print "<H2>Create / Update an Image</H2>\n";
            print "<font color=\"#ff0000\">The time you requested is in the past.";
            print " Please select \"Now\" or use a time in the future.</font><br>\n";
            $submitErr = 1;
            createSelectImage();
            return;
        }
        $nowfuture = "future";
    }
    // FIXME hard code length to 8 hours
    $data["length"] = 480;
    $end = $start + $data["length"] * 60 + $add;
    // get semaphore lock
    if (!semLock()) {
        abort(3);
    }
    $max = getMaxOverlap($user['id']);
    if (checkOverlap($start, $end, $max)) {
        $printedHTMLheader = 1;
        print $HTMLheader;
        print "<H2>New Reservation</H2>\n";
        if ($max == 0) {
            print "<font color=\"#ff0000\">The time you requested overlaps with ";
            print "another reservation you currently have.  You are only allowed ";
            print "to have a single reservation at any given time. Please select ";
            print "another time to use the application. If you are finished with ";
            print "an active reservation, click \"Current Reservations\", ";
            print "then click the \"End\" button of your active reservation.";
            print "</font><br><br>\n";
        } else {
            print "<font color=\"#ff0000\">The time you requested overlaps with ";
            print "another reservation you currently have.  You are allowed ";
            print "to have {$max} overlapping reservations at any given time. ";
            print "Please select another time to use the application. If you are ";
            print "finished with an active reservation, click \"Current ";
            print "Reservations\", then click the \"End\" button of your active ";
            print "reservation.</font><br><br>\n";
        }
        $submitErr = 1;
        createSelectImage();
        return;
    }
    // if user is owner of the image and there is a test revision of the image
    #   available, ask user if production or test image desired
    if ($mode != "submitCreateTestProd" && $showrevisions && $images[$data["imageid"]]["ownerid"] == $user["id"]) {
        $printedHTMLheader = 1;
        print $HTMLheader;
        print "<H2>New Reservation</H2>\n";
        if ($subimages) {
            print "This is a cluster environment. At least one image in the ";
            print "cluster has more than one revision available. Please select ";
            print "the revision you desire for each image listed below:<br>\n";
        } else {
            print "There are multiple revisions of this environment available.  Please ";
            print "select the revision you would like to check out:<br>\n";
        }
        print "<FORM action=\"" . BASEURL . SCRIPT . "\" method=post><br>\n";
        if (!array_key_exists('subimages', $images[$data['imageid']])) {
            $images[$data['imageid']]['subimages'] = array();
        }
        array_unshift($images[$data['imageid']]['subimages'], $data['imageid']);
        foreach ($images[$data['imageid']]['subimages'] as $subimage) {
            print "{$images[$subimage]['prettyname']}:<br>\n";
            print "<table summary=\"lists revisions of the selected environment, one must be selected to continue\">\n";
            print "  <TR>\n";
            print "    <TD></TD>\n";
            print "    <TH>Revision</TH>\n";
            print "    <TH>Creator</TH>\n";
            print "    <TH>Created</TH>\n";
            print "    <TH>Currently in Production</TH>\n";
            print "  </TR>\n";
            foreach ($images[$subimage]['imagerevision'] as $revision) {
                print "  <TR>\n";
                if (array_key_exists($subimage, $data['revisionid']) && $data['revisionid'][$subimage] == $revision['id']) {
                    print "    <TD align=center><INPUT type=radio name=revisionid[{$subimage}] value={$revision['id']} checked></TD>\n";
                } elseif ($revision['production']) {
                    print "    <TD align=center><INPUT type=radio name=revisionid[{$subimage}] value={$revision['id']} checked></TD>\n";
                } else {
                    print "    <TD align=center><INPUT type=radio name=revisionid[{$subimage}] value={$revision['id']}></TD>\n";
                }
                print "    <TD align=center>{$revision['revision']}</TD>\n";
                print "    <TD align=center>{$revision['user']}</TD>\n";
                print "    <TD align=center>{$revision['prettydate']}</TD>\n";
                if ($revision['production']) {
                    print "    <TD align=center>Yes</TD>\n";
                } else {
                    print "    <TD align=center>No</TD>\n";
                }
                print "  </TR>\n";
            }
            print "</TABLE>\n";
        }
        addContinuationsEntry('submitCreateImage', array(), SECINDAY, 1, 0);
        // we add this continuation back
        //   so the currently displayed
        //   page can be reloaded
        $cont = addContinuationsEntry('submitCreateTestProd', $data);
        print "<br><INPUT type=hidden name=continuation value=\"{$cont}\">\n";
        print "<INPUT type=submit value=Submit>\n";
        print "</FORM>\n";
        return;
    }
    $rc = isAvailable($images, $data["imageid"], $start, $end, $data["os"], 0, 0, 0, 1);
    if ($rc == -1) {
        $printedHTMLheader = 1;
        print $HTMLheader;
        print "<H2>Create / Update an Image</H2>\n";
        print "You have requested an environment that is limited in the number ";
        print "of concurrent reservations that can be made. No further ";
        print "reservations for the environment can be made for the time you ";
        print "have selected. Please select another time to use the ";
        print "environment.<br>";
    } elseif ($rc > 0) {
        $requestid = addRequest(1, $data['revisionid']);
        if ($data["time"] == "now") {
            header("Location: " . BASEURL . SCRIPT . "?mode=viewRequests");
            dbDisconnect();
            exit;
        } else {
            $time = prettyLength($data["length"]);
            if ($data["minute"] == 0) {
                $data["minute"] = "00";
            }
            $printedHTMLheader = 1;
            print $HTMLheader;
            print "<H2>Create / Update an Image</H2>\n";
            print "Your request to use <b>" . $images[$data["imageid"]]["prettyname"];
            print "</b> on " . prettyDatetime($start) . " for {$time} has been ";
            print "accepted.<br><br>\n";
            print "When your reservation time has been reached, the ";
            print "<b>Current Reservations</b> page will give you more ";
            print "information on connecting to the reserved computer. If you ";
            print "would like to modify your reservation, you can do that from ";
            print "the <b>Current Reservations</b> page as well.<br>\n";
        }
    } else {
        $printedHTMLheader = 1;
        print $HTMLheader;
        $cdata = array('imageid' => $data['imageid'], 'length' => $data['length']);
        $cont = addContinuationsEntry('selectTimeTable', $cdata);
        print "<H2>Create / Update an Image</H2>\n";
        print "The reservation you have requested is not available. You may ";
        print "<a href=\"" . BASEURL . SCRIPT . "?continuation={$cont}\">";
        print "view a timetable</a> of free and reserved times to find ";
        print "a time that will work for you.<br>\n";
        #addLogEntry($nowfuture, unixToDatetime($start),
        #            unixToDatetime($end), 0, $data["imageid"]);
    }
}
Example #7
0
 /**
  * Returns the lists available for the given user.
  *
  * @param string $user
  * @return array
  */
 public function getLists($user)
 {
     $url = sprintf('http://api.twitter.com/1/%s/lists.%s', $user, $this->format);
     return $this > addRequest('getLists', $url, true, false);
 }
Example #8
0
function XMLRPCaddRequest($imageid, $start, $length, $foruser = '')
{
    global $user;
    $imageid = processInputData($imageid, ARG_NUMERIC);
    $start = processInputData($start, ARG_STRING, 1);
    $length = processInputData($length, ARG_NUMERIC);
    #$foruser = processInputData($foruser, ARG_STRING, 1);
    // make sure user didn't submit a request for an image he
    // doesn't have access to
    $resources = getUserResources(array("imageAdmin", "imageCheckOut"));
    $validImageids = array_keys($resources['image']);
    if (!in_array($imageid, $validImageids)) {
        return array('status' => 'error', 'errorcode' => 3, 'errormsg' => "access denied to {$imageid}");
    }
    # validate $start
    if ($start != 'now' && !is_numeric($start)) {
        return array('status' => 'error', 'errorcode' => 4, 'errormsg' => "received invalid input");
    }
    # validate $length
    $maxtimes = getUserMaxTimes();
    if ($maxtimes['initial'] < $length) {
        return array('status' => 'error', 'errorcode' => 6, 'errormsg' => "max allowed initial length is {$maxtimes['initial']} minutes");
    }
    $nowfuture = 'future';
    if ($start == 'now') {
        $start = time();
        $nowfuture = 'now';
    } else {
        if ($start < time() - 30) {
            return array('status' => 'error', 'errorcode' => 5, 'errormsg' => "start time is in the past");
        }
    }
    $start = unixFloor15($start);
    $end = $start + $length * 60;
    if ($end % (15 * 60)) {
        $end = unixFloor15($end) + 15 * 60;
    }
    $max = getMaxOverlap($user['id']);
    if (checkOverlap($start, $end, $max)) {
        return array('status' => 'error', 'errorcode' => 7, 'errormsg' => "reservation overlaps with another one you " . "have, and you are allowed {$max} " . "overlapping reservations at a time");
    }
    $images = getImages();
    $rc = isAvailable($images, $imageid, $start, $end, '');
    if ($rc < 1) {
        addLogEntry($nowfuture, unixToDatetime($start), unixToDatetime($end), 0, $imageid);
        return array('status' => 'notavailable');
    }
    $return['requestid'] = addRequest();
    $return['status'] = 'success';
    return $return;
}
Example #9
0
function XMLRPCdeployServer($imageid, $start, $end, $admingroup = '', $logingroup = '', $ipaddr = '', $macaddr = '', $monitored = 0, $foruser = '', $name = '', $userdata = '')
{
    global $user, $remoteIP;
    if (!in_array("serverCheckOut", $user["privileges"])) {
        return array('status' => 'error', 'errorcode' => 60, 'errormsg' => "access denied to deploy server");
    }
    $imageid = processInputData($imageid, ARG_NUMERIC);
    $resources = getUserResources(array("imageAdmin", "imageCheckOut"));
    $images = removeNoCheckout($resources["image"]);
    $extraimages = getServerProfileImages($user['id']);
    if (!array_key_exists($imageid, $images) && !array_key_exists($imageid, $extraimages)) {
        return array('status' => 'error', 'errorcode' => 3, 'errormsg' => "access denied to {$imageid}");
    }
    if ($admingroup != '') {
        $admingroup = processInputData($admingroup, ARG_STRING);
        if (get_magic_quotes_gpc()) {
            $admingroup = stripslashes($admingroup);
        }
        if (preg_match('/@/', $admingroup)) {
            $tmp = explode('@', $admingroup);
            $escadmingroup = mysql_real_escape_string($tmp[0]);
            $affilid = getAffiliationID($tmp[1]);
            if (is_null($affilid)) {
                return array('status' => 'error', 'errorcode' => 51, 'errormsg' => "unknown affiliation for admin user group: {$tmp[1]}");
            }
        } else {
            $escadmingroup = mysql_real_escape_string($admingroup);
            $affilid = DEFAULT_AFFILID;
        }
        $admingroupid = getUserGroupID($escadmingroup, $affilid, 1);
        if (is_null($admingroupid)) {
            return array('status' => 'error', 'errorcode' => 52, 'errormsg' => "unknown admin user group: {$admingroup}");
        }
    } else {
        $admingroupid = '';
    }
    if ($logingroup != '') {
        $logingroup = processInputData($logingroup, ARG_STRING);
        if (get_magic_quotes_gpc()) {
            $logingroup = stripslashes($logingroup);
        }
        if (preg_match('/@/', $logingroup)) {
            $tmp = explode('@', $logingroup);
            $esclogingroup = mysql_real_escape_string($tmp[0]);
            $affilid = getAffiliationID($tmp[1]);
            if (is_null($affilid)) {
                return array('status' => 'error', 'errorcode' => 54, 'errormsg' => "unknown affiliation for login user group: {$tmp[1]}");
            }
        } else {
            $esclogingroup = mysql_real_escape_string($logingroup);
            $affilid = DEFAULT_AFFILID;
        }
        $logingroupid = getUserGroupID($esclogingroup, $affilid, 1);
        if (is_null($logingroupid)) {
            return array('status' => 'error', 'errorcode' => 55, 'errormsg' => "unknown login user group: {$logingroup}");
        }
    } else {
        $logingroupid = '';
    }
    $ipaddr = processInputData($ipaddr, ARG_STRING);
    $ipaddrArr = explode('.', $ipaddr);
    if ($ipaddr != '' && (!preg_match('/^(([0-9]){1,3}\\.){3}([0-9]){1,3}$/', $ipaddr) || $ipaddrArr[0] < 1 || $ipaddrArr[0] > 255 || $ipaddrArr[1] < 0 || $ipaddrArr[1] > 255 || $ipaddrArr[2] < 0 || $ipaddrArr[2] > 255 || $ipaddrArr[3] < 0 || $ipaddrArr[3] > 255)) {
        return array('status' => 'error', 'errorcode' => 57, 'errormsg' => "Invalid IP address. Must be w.x.y.z with each of " . "w, x, y, and z being between 1 and 255 (inclusive)");
    }
    $macaddr = processInputData($macaddr, ARG_STRING);
    if ($macaddr != '' && !preg_match('/^(([A-Fa-f0-9]){2}:){5}([A-Fa-f0-9]){2}$/', $macaddr)) {
        return array('status' => 'error', 'errorcode' => 58, 'errormsg' => "Invalid MAC address.  Must be XX:XX:XX:XX:XX:XX " . "with each pair of XX being from 00 to FF (inclusive)");
    }
    $monitored = processInputData($monitored, ARG_NUMERIC);
    if ($monitored != 0 && $monitored != 1) {
        $monitored = 0;
    }
    $start = processInputData($start, ARG_STRING, 1);
    $end = processInputData($end, ARG_STRING, 1);
    #$foruser = processInputData($foruser, ARG_STRING, 1);
    $name = processInputData($name, ARG_STRING);
    if (get_magic_quotes_gpc()) {
        $name = stripslashes($name);
    }
    if (!preg_match('/^([-a-zA-Z0-9_\\. ]){0,255}$/', $name)) {
        return array('status' => 'error', 'errorcode' => 58, 'errormsg' => "Invalid name. Can only contain letters, numbers, " . "spaces, dashes(-), underscores(_), and periods(.) " . "and be up to 255 characters long");
    }
    $name = mysql_real_escape_string($name);
    # validate $start
    if ($start != 'now' && !is_numeric($start)) {
        return array('status' => 'error', 'errorcode' => 4, 'errormsg' => "received invalid input for start");
    }
    # validate $end
    if ($end != 'indefinite' && !is_numeric($end)) {
        return array('status' => 'error', 'errorcode' => 59, 'errormsg' => "received invalid input for end");
    }
    $nowfuture = 'future';
    if ($start == 'now') {
        $start = unixFloor15(time());
        $nowfuture = 'now';
    } else {
        if ($start < time() - 30) {
            return array('status' => 'error', 'errorcode' => 5, 'errormsg' => "start time is in the past");
        }
    }
    if ($end == 'indefinite') {
        $end = datetimeToUnix("2038-01-01 00:00:00");
    } elseif ($end % (15 * 60)) {
        $end = unixFloor15($end) + 15 * 60;
    } elseif ($end < $start + 900) {
        return array('status' => 'error', 'errorcode' => 88, 'errormsg' => "end time must be at least 15 minutes after start time");
    }
    $max = getMaxOverlap($user['id']);
    if (checkOverlap($start, $end, $max)) {
        return array('status' => 'error', 'errorcode' => 7, 'errormsg' => "reservation overlaps with another one you " . "have, and you are allowed {$max} " . "overlapping reservations at a time");
    }
    $images = getImages();
    $revisionid = getProductionRevisionid($imageid);
    $rc = isAvailable($images, $imageid, $revisionid, $start, $end, 1, 0, 0, 0, 0, $ipaddr, $macaddr);
    if ($rc < 1) {
        addLogEntry($nowfuture, unixToDatetime($start), unixToDatetime($end), 0, $imageid);
        return array('status' => 'notavailable');
    }
    $return['requestid'] = addRequest();
    $query = "UPDATE reservation " . "SET remoteIP = '{$remoteIP}' " . "WHERE requestid = {$return['requestid']}";
    doQuery($query);
    if ($userdata != '') {
        if (get_magic_quotes_gpc()) {
            $userdata = stripslashes($userdata);
        }
        $esc_userdata = mysql_real_escape_string($userdata);
        $query = "INSERT INTO variable " . "(name, " . "serialization, " . "value, " . "setby, " . "timestamp) " . "SELECT CONCAT('userdata|', id), " . "'none', " . "'{$esc_userdata}', " . "'webcode', " . "NOW() " . "FROM reservation " . "WHERE requestid = {$return['requestid']}";
        doQuery($query);
    }
    $fields = array('requestid');
    $values = array($return['requestid']);
    if ($name != '') {
        $fields[] = 'name';
        $values[] = "'{$name}'";
    }
    if ($ipaddr != '') {
        $fields[] = 'fixedIP';
        $values[] = "'{$ipaddr}'";
    }
    if ($macaddr != '') {
        $fields[] = 'fixedMAC';
        $values[] = "'{$macaddr}'";
    }
    if ($admingroupid != 0) {
        $fields[] = 'admingroupid';
        $values[] = $admingroupid;
    }
    if ($logingroupid != 0) {
        $fields[] = 'logingroupid';
        $values[] = $logingroupid;
    }
    if ($monitored != 0) {
        $fields[] = 'monitored';
        $values[] = 1;
    }
    $allfields = implode(',', $fields);
    $allvalues = implode(',', $values);
    $query = "INSERT INTO serverrequest ({$allfields}) VALUES ({$allvalues})";
    doQuery($query, 101);
    $return['status'] = 'success';
    return $return;
}