function errorHandler($errno, $errstr, $errfile = NULL, $errline = NULL, $errcontext = NULL) { global $user; if ($user["adminlevel"] != "developer") { dbDisconnect(); printHTMLFooter(); semUnlock(); exit; } print "Error encountered<br>\n"; switch ($errno) { case E_USER_ERROR: echo "<b>FATAL</b> [{$errno}] {$errstr}<br />\n"; echo " Fatal error in line {$errline} of file {$errfile}"; echo ", PHP " . PHP_VERSION . " (" . PHP_OS . ")<br />\n"; echo "Aborting...<br />\n"; semUnlock(); exit(1); break; case E_USER_WARNING: echo "<b>ERROR</b> [{$errno}] {$errstr}<br />\n"; break; case E_USER_NOTICE: echo "<b>WARNING</b> [{$errno}] {$errstr}<br />\n"; break; default: echo "Unkown error type: [{$errno}] {$errstr}<br />\n"; break; } if (!empty($errfile) && !empty($errline)) { print "Error at {$errline} in {$errfile}<br>\n"; } if (!empty($errcontext)) { print "<pre>\n"; print_r($errcontext); print "</pre>\n"; } print "<br><br><br>\n"; print "<pre>\n"; print getBacktraceString(); print "</pre>\n"; dbDisconnect(); printHTMLFooter(); semUnlock(); exit; }
require_once '.ht-inc/errors.php'; require_once '.ht-inc/utils.php'; dbConnect(); initGlobals(); $modes = array_keys($actions['mode']); $args = array_keys($actions['args']); $hasArg = 0; if (in_array($mode, $modes)) { $actionFunction = $actions['mode'][$mode]; if (in_array($mode, $args)) { $hasArg = 1; $arg = $actions['args'][$mode]; } } else { $actionFunction = "main"; } checkAccess(); sendHeaders(); printHTMLHeader(); if ($viewmode == ADMIN_DEVELOPER) { set_error_handler("errorHandler"); } if ($hasArg) { $actionFunction($arg); } else { $actionFunction(); } printHTMLFooter(); dbDisconnect(); semUnlock();
function AJupdateWaitTime() { global $user, $requestInfo; # proccess length $length = processInputVar('length', ARG_NUMERIC); $times = getUserMaxTimes(); if (empty($length) || $length > $times['initial']) { dbDisconnect(); exit; } # process imageid $imageid = processInputVar('imageid', ARG_NUMERIC); $resources = getUserResources(array("imageAdmin", "imageCheckOut")); $validImageids = array_keys($resources['image']); if (!in_array($imageid, $validImageids)) { dbDisconnect(); exit; } $desconly = processInputVar('desconly', ARG_NUMERIC, 1); $imagenotes = getImageNotes($imageid); if (preg_match('/\\w/', $imagenotes['description'])) { $desc = preg_replace("/\n/", '<br>', $imagenotes['description']); $desc = preg_replace("/\r/", '', $desc); $desc = preg_replace("/'/", ''', $desc); print "dojo.byId('imgdesc').innerHTML = '<strong>Image Description</strong>:<br>"; print "{$desc}<br><br>'; "; } if ($desconly) { return; } $images = getImages(); $now = time(); $start = unixFloor15($now); $end = $start + $length * 60; if ($start < $now) { $end += 15 * 60; } $rc = isAvailable($images, $imageid, $start, $end, ''); semUnlock(); print "dojo.byId('waittime').innerHTML = "; if ($rc < 1) { print "'<font color=red>Selection not currently available</font>'; "; print "if(dojo.byId('newsubmit')) dojo.byId('newsubmit').value = 'View Time Table';"; } elseif (array_key_exists(0, $requestInfo['loaded']) && $requestInfo['loaded'][0]) { print "'Estimated load time: < 1 minute';"; } else { $loadtime = (int) (getImageLoadEstimate($imageid) / 60); if ($loadtime == 0) { print "'Estimated load time: < {$images[$imageid]['reloadtime']} minutes';"; } else { printf("'Estimated load time: < %2.0f minutes';", $loadtime + 1); } } }
function xmlRPCabort($errcode, $query = '') { global $mysql_link_vcl, $mysql_link_acct, $ERRORS, $user, $mode; global $XMLRPCERRORS; if (ONLINEDEBUG && $user["adminlevel"] == "developer") { $msg = ''; if ($errcode >= 100 && $errcode < 400) { $msg .= mysql_error($mysql_link_vcl) . " {$query} "; } $msg .= $ERRORS["{$errcode}"]; $XMLRPCERRORS[100] = $msg; $faultcode = 100; } else { $message = ""; if ($errcode >= 100 && $errcode < 400) { $message .= mysql_error($mysql_link_vcl) . "\n"; $message .= mysql_error($mysql_link_acct) . "\n"; $message .= $query . "\n"; } $message .= "ERROR({$errcode}): " . $ERRORS["{$errcode}"] . "\n"; $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"; } $message .= getBacktraceString(FALSE); $mailParams = "-f" . ENVELOPESENDER; mail(ERROREMAIL, "Error with VCL XMLRPC call", $message, '', $mailParams); $faultcode = 1; } printXMLRPCerror($faultcode); dbDisconnect(); semUnlock(); exit; }
function checkExpiredDemoUser($userid, $groups = 0) { global $mode, $skin, $noHTMLwrappers; if ($groups == 0) { $groups = getUsersGroups($userid, 1); } if (count($groups) != 1) { return; } $tmp = array_values($groups); if ($tmp[0] != 'demo') { return; } $query = "SELECT start " . "FROM log " . "WHERE userid = {$userid} " . "AND finalend < NOW() " . "ORDER BY start " . "LIMIT 3"; $qh = doQuery($query, 101); $expire = time() - SECINDAY * 3; $rows = mysql_num_rows($qh); if ($row = mysql_fetch_assoc($qh)) { if ($rows >= 3 || datetimeToUnix($row['start']) < $expire) { if (in_array($mode, $noHTMLwrappers)) { # do a redirect and handle removal on next page load so user can # be notified - doesn't always work, but handles a few extra # cases header("Location: " . BASEURL . SCRIPT); } else { $nodemoid = getUserGroupID('nodemo', getAffiliationID('ITECS')); $query = "DELETE FROM usergroupmembers " . "WHERE userid = {$userid}"; # because updateGroups doesn't # delete from custom groups doQuery($query, 101); updateGroups(array($nodemoid), $userid); if (empty($skin)) { $skin = 'default'; require_once "themes/{$skin}/page.php"; } $mode = 'expiredemouser'; printHTMLHeader(); print "<h2>Account Expired</h2>\n"; print "The account you are using is a demo account that has now expired. "; print "You cannot make any more reservations. Please contact <a href=\""; print "mailto:" . HELPEMAIL . "\">" . HELPEMAIL . "</a> if you need "; print "further access to VCL.<br>\n"; } semUnlock(); printHTMLFooter(); dbDisconnect(); exit; } } }
function XMLRPCprocessBlockTime($blockTimesid, $ignoreprivileges = 0) { global $requestInfo, $user, $xmlrpcBlockAPIUsers; if (!in_array($user['id'], $xmlrpcBlockAPIUsers)) { return array('status' => 'error', 'errorcode' => 34, 'errormsg' => 'access denied for managing block allocations'); } $return = array('status' => 'success'); $query = "SELECT bt.start, " . "bt.end, " . "br.imageid, " . "br.numMachines, " . "br.groupid, " . "br.expireTime " . "FROM blockRequest br, " . "blockTimes bt " . "WHERE bt.blockRequestid = br.id AND " . "bt.id = {$blockTimesid}"; $qh = doQuery($query, 101); if (!($rqdata = mysql_fetch_assoc($qh))) { return array('status' => 'error', 'errorcode' => 8, 'errormsg' => 'unknown blockTimesid'); } if (datetimeToUnix($rqdata['expireTime']) < time()) { return array('status' => 'error', 'errorcode' => 9, 'errormsg' => 'expired block reservation'); } $images = getImages(0, $rqdata['imageid']); if (empty($images)) { return array('status' => 'error', 'errorcode' => 10, 'errormsg' => 'invalid image associated with block request'); } # check to see if all computers have been allocated $query = "SELECT COUNT(computerid) AS allocated " . "FROM blockComputers " . "WHERE blockTimeid = {$blockTimesid}"; $qh = doQuery($query, 101); if (!($row = mysql_fetch_assoc($qh))) { return array('status' => 'error', 'errorcode' => 15, 'errormsg' => 'failure to communicate with database'); } $compCompleted = $row['allocated']; $compsPerRequest = 1 + count($images[$rqdata['imageid']]['subimages']); $toallocate = $rqdata['numMachines'] * $compsPerRequest - $compCompleted; if ($toallocate == 0) { return array('status' => 'completed'); } $reqToAlloc = $toallocate / $compsPerRequest; if (!$ignoreprivileges) { # get userids in user group $tmp = getUserGroupMembers($rqdata['groupid']); if (empty($tmp)) { return array('status' => 'error', 'errorcode' => 11, 'errormsg' => 'empty user group and ignoreprivileges set to 0'); } $userids = array_keys($tmp); # make length of $userids match $reqToAlloc by duplicating or trimming some users while ($reqToAlloc > count($userids)) { $userids = array_merge($userids, $userids); } if ($reqToAlloc < count($userids)) { $userids = array_splice($userids, 0, $reqToAlloc); } } # staggering: stagger start times for this round (ie, don't worry about # previous processing of this block time) such that there is 1 minute # between the start times for each request $stagExtra = $reqToAlloc * 60; # determine estimated load time $imgLoadTime = getImageLoadEstimate($rqdata['imageid']); if ($imgLoadTime == 0) { $imgLoadTime = $images[$rqdata['imageid']]['reloadtime'] * 60; } $loadtime = $imgLoadTime + 10 * 60; # add 10 minute fudge factor $unixstart = datetimeToUnix($rqdata['start']); if (time() + $loadtime + $stagExtra > $unixstart) { $return['status'] = 'warning'; $return['warningcode'] = 13; $return['warningmsg'] = 'possibly insufficient time to load machines'; } $start = unixToDatetime($unixstart - $loadtime); $unixend = datetimeToUnix($rqdata['end']); $userid = 0; $allocated = 0; $vclreloadid = getUserlistID('vclreload@Local'); $revisionid = getProductionRevisionid($rqdata['imageid']); $blockCompVals = array(); # FIXME (maybe) - if some subset of users in the user group have available # computers, but others do not, $allocated will be less than the desired # number of machines; however, calling this function enough times will # result in enough machines being allocated because they will continue to be # allocated based on the ones with machines available; this seems like odd # behavior $stagCnt = 0; for ($i = 0; $i < $reqToAlloc; $i++) { $stagunixstart = $unixstart - $loadtime - $stagCnt * 60; $stagstart = unixToDatetime($stagunixstart); if (!$ignoreprivileges) { $userid = array_pop($userids); } # use end of block time to find available computers, but... $rc = isAvailable($images, $rqdata['imageid'], $stagunixstart, $unixend, 0, 0, $userid, $ignoreprivileges); if ($rc < 1) { continue; } $compid = $requestInfo['computers'][0]; # ...use start of block time as end of reload reservation $reqid = simpleAddRequest($compid, $rqdata['imageid'], $revisionid, $stagstart, $rqdata['start'], 19, $vclreloadid); if ($reqid == 0) { continue; } $stagCnt++; $allocated++; $blockCompVals[] = "({$blockTimesid}, {$compid}, {$rqdata['imageid']})"; # process any subimages for ($key = 1; $key < count($requestInfo['computers']); $key++) { $subimageid = $requestInfo['images'][$key]; $subrevid = getProductionRevisionid($subimageid); $compid = $requestInfo['computers'][$key]; $mgmtnodeid = $requestInfo['mgmtnodes'][$key]; $blockCompVals[] = "({$blockTimesid}, {$compid}, {$subimageid})"; $query = "INSERT INTO reservation " . "(requestid, " . "computerid, " . "imageid, " . "imagerevisionid, " . "managementnodeid) " . "VALUES " . "({$reqid}, " . "{$compid}, " . "{$subimageid}, " . "{$subrevid}, " . "{$mgmtnodeid})"; doQuery($query, 101); } semUnlock(); $blockComps = implode(',', $blockCompVals); $query = "INSERT INTO blockComputers " . "(blockTimeid, computerid, imageid) " . "VALUES {$blockComps}"; doQuery($query, 101); $blockCompVals = array(); } if ($allocated == 0) { $return['status'] = 'warning'; $return['warningcode'] = 14; $return['warningmsg'] = 'unable to allocate any machines'; } $return['allocated'] = $compCompleted / $compsPerRequest + $allocated; $return['unallocated'] = $rqdata['numMachines'] - $return['allocated']; return $return; }
function submitCompStateChange() { global $user; print "<H2>Change State of Computers</H2>\n"; $data = getContinuationVar(); $computers = getComputers(1); # switching to available if ($data['stateid'] == 2) { $compids = implode(',', $data['computerids']); $query = "UPDATE computer " . "SET stateid = 2, " . "notes = '' " . "WHERE id IN ({$compids})"; doQuery($query, 101); print "The following computers were changed to the available state:\n"; print "<TABLE>\n"; foreach ($data['computerids'] as $compid) { print " <TR>\n"; print " <TD>{$computers[$compid]['hostname']}</TD>\n"; print " </TR>\n"; } print "</TABLE>\n"; } elseif ($data['stateid'] == 10) { $data['notes'] = processInputVar('notes', ARG_STRING); if (get_magic_quotes_gpc()) { $data['notes'] = stripslashes($data['notes']); } $data['notes'] = mysql_escape_string($data['notes']); $data["notes"] = $user["unityid"] . " " . unixToDatetime(time()) . "@" . $data["notes"]; $vclreloadid = getUserlistID('vclreload@Local'); // get semaphore lock if (!semLock()) { abort(3); } $noaction = array(); $changenow = array(); $changeasap = array(); $changetimes = array(); foreach ($data['computerids'] as $compid) { if ($computers[$compid]['state'] == 'maintenance') { array_push($noaction, $compid); } else { array_push($changeasap, $compid); } } $passes = array(); $fails = array(); foreach ($changeasap as $compid) { # TODO what about blockComputers? # try to move future reservations off of computer moveReservationsOffComputer($compid); # get end time of last reservation $query = "SELECT rq.end " . "FROM request rq, " . "reservation rs " . "WHERE rs.requestid = rq.id AND " . "rs.computerid = {$compid} AND " . "rq.stateid NOT IN (1,5,12) " . "ORDER BY end DESC " . "LIMIT 1"; $qh = doQuery($query, 101); # create a really long reservation starting at that time in state tomaintenance if ($row = mysql_fetch_assoc($qh)) { $start = $row['end']; $changetimes[$compid] = $start; $end = datetimeToUnix($start) + SECINWEEK; // hopefully keep future reservations off of it $end = unixToDatetime($end); if (simpleAddRequest($compid, 4, 3, $start, $end, 18, $vclreloadid)) { $passes[] = $compid; } else { $fails[] = $compid; } } else { $query = "UPDATE computer " . "SET stateid = 10, " . "notes = '{$data['notes']}' " . "WHERE id = {$compid}"; doQuery($query, 101); unset_by_val($compid, $changeasap); array_push($changenow, $compid); } } // release semaphore lock semUnlock(); if (count($noaction) || count($changeasap)) { $comparr = array_merge($noaction, $changeasap); $compids = implode(',', $comparr); $query = "UPDATE computer " . "SET notes = '{$data['notes']}' " . "WHERE id IN ({$compids})"; doQuery($query, 101); } if (count($changenow)) { print "The following computers were immediately placed into the "; print "maintenance state:\n"; print "<TABLE>\n"; foreach ($changenow as $compid) { print " <TR>\n"; print " <TD><font color=\"#008000\">{$computers[$compid]['hostname']}</font></TD>\n"; print " </TR>\n"; } print "</TABLE>\n"; print "<br>\n"; } if (count($passes)) { print "The following computers currently have reservations on them "; print "and will be placed in the maintenance state at the time listed "; print "for each computer:\n"; print "<TABLE>\n"; print " <TR>\n"; print " <TH>Computer</TH>\n"; print " <TH>Maintenance time</TH>\n"; print " </TR>\n"; foreach ($passes as $compid) { print " <TR>\n"; print " <TD align=center><font color=\"ff8c00\">{$computers[$compid]['hostname']}</font></TD>\n"; $time = date('n/j/y g:i a', datetimeToUnix($changetimes[$compid])); print " <TD align=center>{$time}</TD>\n"; print " </TR>\n"; } print "</TABLE>\n"; print "<br>\n"; } if (count($fails)) { print "The following computers currently have reservations on them "; print "but no functional management node was found for them. Nothing "; print "be done with them at this time:\n"; print "<TABLE>\n"; print " <TR>\n"; print " <TH>Computer</TH>\n"; print " </TR>\n"; foreach ($passes as $compid) { print " <TR>\n"; print " <TD align=center><font color=\"ff0000\">{$computers[$compid]['hostname']}</font></TD>\n"; print " </TR>\n"; } print "</TABLE>\n"; print "<br>\n"; } if (count($noaction)) { print "The following computers were already in the maintenance "; print "state and had their notes on being in the maintenance state "; print "updated:\n"; print "<TABLE>\n"; foreach ($noaction as $compid) { print " <TR>\n"; print " <TD>{$computers[$compid]['hostname']}</TD>\n"; print " </TR>\n"; } print "</TABLE>\n"; print "<br>\n"; } } elseif ($data['stateid'] == 20) { $profileid = processInputVar('profileid', ARG_NUMERIC); if (!array_key_exists($profileid, $data['profiles'])) { $keys = array_keys($data['profiles']); $profileid = $keys[0]; } $noaction = array(); $changenow = array(); $changeasap = array(); $changetimes = array(); foreach ($data['computerids'] as $compid) { if ($computers[$compid]['state'] == 'vmhostinuse') { array_push($noaction, $compid); } else { array_push($changeasap, $compid); } } if (!semLock()) { abort(3); } foreach ($changeasap as $compid) { # TODO what about blockComputers? moveReservationsOffComputer($compid); # get end time of last reservation $query = "SELECT rq.end " . "FROM request rq, " . "reservation rs " . "WHERE rs.requestid = rq.id AND " . "rs.computerid = {$compid} AND " . "rq.stateid NOT IN (1,5,12) " . "ORDER BY end DESC " . "LIMIT 1"; $qh = doQuery($query, 101); if ($row = mysql_fetch_assoc($qh)) { // if there is a reservation, leave in $changeasap so we can # notify that we can't change this one } else { # create a reload reservation to load machine with image # corresponding to selected vm profile $start = getReloadStartTime(); $end = $start + SECINYEAR; # don't want anyone making a future reservation for this machine $start = unixToDatetime($start); $end = unixToDatetime($end); $imagerevisionid = getProductionRevisionid($data['profiles'][$profileid]['imageid']); $vclreloadid = getUserlistID('vclreload@Local'); simpleAddRequest($compid, $data['profiles'][$profileid]['imageid'], $imagerevisionid, $start, $end, 21, $vclreloadid); unset_by_val($compid, $changeasap); array_push($changenow, $compid); # check for existing vmhost entry $query = "SELECT id, " . "vmprofileid " . "FROM vmhost " . "WHERE computerid = {$compid}"; $qh = doQuery($query, 101); if ($row = mysql_fetch_assoc($qh)) { if ($row['vmprofileid'] != $profileid) { # update vmprofile $query = "UPDATE vmhost " . "SET vmprofileid = {$profileid} " . "WHERE id = {$row['id']}"; doQuery($query, 101); } } else { # create vmhost entry $query = "INSERT INTO vmhost " . "(computerid, " . "vmlimit, " . "vmprofileid) " . "VALUES ({$compid}, " . "2, " . "{$profileid})"; doQuery($query, 101); } } } // release semaphore lock semUnlock(); if (count($changenow)) { print "The following computers were placed into the "; print "vmhostinuse state:\n"; print "<TABLE>\n"; foreach ($changenow as $compid) { print " <TR>\n"; print " <TD><font color=\"#008000\">{$computers[$compid]['hostname']}</font></TD>\n"; print " </TR>\n"; } print "</TABLE>\n"; print "<br>\n"; } if (count($changeasap)) { print "The following computers currently have reservations on them "; print "and cannot be placed in the vmhostinuse state at this time:\n"; print "<TABLE>\n"; foreach ($changeasap as $compid) { print " <TR>\n"; print " <TD><font color=\"ff0000\">{$computers[$compid]['hostname']}</font></TD>\n"; print " </TR>\n"; } print "</TABLE>\n"; print "<br>\n"; } if (count($noaction)) { print "The following computers were already in the vmhostinuse "; print "state:\n"; print "<TABLE>\n"; foreach ($noaction as $compid) { print " <TR>\n"; print " <TD>{$computers[$compid]['hostname']}</TD>\n"; print " </TR>\n"; } print "</TABLE>\n"; print "<br>\n"; } } elseif ($data['stateid'] == 23) { $noaction = array(); $changenow = array(); $changeasap = array(); $changetimes = array(); foreach ($data['computerids'] as $compid) { if ($computers[$compid]['state'] == 'hpc') { array_push($noaction, $compid); } else { array_push($changeasap, $compid); } } if (!semLock()) { abort(3); } foreach ($changeasap as $compid) { # TODO what about blockComputers? moveReservationsOffComputer($compid); # get end time of last reservation $query = "SELECT rq.end " . "FROM request rq, " . "reservation rs " . "WHERE rs.requestid = rq.id AND " . "rs.computerid = {$compid} AND " . "rq.stateid NOT IN (1,5,12) " . "ORDER BY end DESC " . "LIMIT 1"; $qh = doQuery($query, 101); if ($row = mysql_fetch_assoc($qh)) { // if there is a reservation, leave in $changeasap so we can # notify that we can't change this one } else { $query = "UPDATE computer " . "SET stateid = 23 " . "WHERE id = {$compid}"; doQuery($query, 101); unset_by_val($compid, $changeasap); array_push($changenow, $compid); } } // release semaphore lock semUnlock(); if (count($changenow)) { print "The following computers were placed into the "; print "hpc state:\n"; print "<TABLE>\n"; foreach ($changenow as $compid) { print " <TR>\n"; print " <TD><font color=\"#008000\">{$computers[$compid]['hostname']}</font></TD>\n"; print " </TR>\n"; } print "</TABLE>\n"; print "<br>\n"; } if (count($changeasap)) { print "The following computers currently have reservations on them "; print "and cannot be placed in the hpc state at this time:\n"; print "<TABLE>\n"; foreach ($changeasap as $compid) { print " <TR>\n"; print " <TD><font color=\"ff0000\">{$computers[$compid]['hostname']}</font></TD>\n"; print " </TR>\n"; } print "</TABLE>\n"; print "<br>\n"; } if (count($noaction)) { print "The following computers were already in the hpc "; print "state:\n"; print "<TABLE>\n"; foreach ($noaction as $compid) { print " <TR>\n"; print " <TD>{$computers[$compid]['hostname']}</TD>\n"; print " </TR>\n"; } print "</TABLE>\n"; print "<br>\n"; } } else { abort(50); } }