function AJfetchRouterDNS() { $data = array('status' => 'none'); $page = processInputVar('page', ARG_STRING); if ($page != 'deploy' && $page != 'profile') { sendJSON($data); return; } $ipaddr = processInputVar('ipaddr', ARG_STRING); # validate fixed IP address if (!validateIPv4addr($ipaddr)) { sendJSON($data); return; } # validate netmask $netmask = processInputVar('netmask', ARG_STRING); $bnetmask = ip2long($netmask); if (!preg_match('/^[1]+0[^1]+$/', sprintf('%032b', $bnetmask))) { sendJSON($data); return; } $network = ip2long($ipaddr) & $bnetmask; $availnets = getVariable('fixedIPavailnetworks', array()); $key = long2ip($network) . "/{$netmask}"; if (array_key_exists($key, $availnets)) { $data = array('status' => 'success', 'page' => $page, 'router' => $availnets[$key]['router'], 'dns' => implode(',', $availnets[$key]['dns'])); } sendJSON($data); }
function processRequestInput() { global $user; $baseaccess = getContinuationVar('baseaccess', 0); $imagingaccess = getContinuationVar('imagingaccess', 0); $serveraccess = getContinuationVar('serveraccess', 0); $openend = getContinuationVar('openend', 0); $nousercheck = getContinuationVar('nousercheck', 0); $return['imaging'] = getContinuationVar('imaging', 0); $maxinitial = getContinuationVar('maxinitial', 0); $noimaging = getContinuationVar('noimaging', array()); $return = array('err' => 0); # type $return['type'] = processInputVar('type', ARG_STRING); if (!preg_match('/^basic|imaging|server$/', $return['type'])) { $return['err'] = 1; $return['errmsg'] = i('Invalid data submitted'); return $return; } if ($return['type'] == 'basic' && !$baseaccess || $return['type'] == 'imaging' && !$imagingaccess || $return['type'] == 'server' && !$serveraccess) { $return['err'] = 1; $return['errmsg'] = i('No access to submitted reservation type'); return $return; } # ending $return['ending'] = processInputVar('ending', ARG_STRING); if (!preg_match('/^indefinite|endat|duration$/', $return['ending'])) { $return['err'] = 1; $return['errmsg'] = i('Invalid data submitted'); return $return; } if ($return['ending'] == 'duration' && !$baseaccess || $return['ending'] == 'indefinite' && !$serveraccess || $return['ending'] == 'endat' && !$openend && !$serveraccess) { $return['err'] = 1; $return['errmsg'] = i('No access to submitted end type'); return $return; } # imageid $return['imageid'] = processInputVar('imageid', ARG_NUMERIC); $resources = getUserResources(array("imageAdmin", "imageCheckOut")); $withnocheckout = $resources['image']; $images = removeNoCheckout($resources["image"]); $extraimages = getServerProfileImages($user['id']); if (!array_key_exists($return['imageid'], $images) && ($return['type'] != 'server' || !array_key_exists($return['imageid'], $extraimages)) && ($return['type'] != 'imaging' || !array_key_exists($return['imageid'], $withnocheckout)) || $return['type'] == 'imaging' && array_key_exists($return['imageid'], $noimaging)) { $return['err'] = 1; $return['errmsg'] = i('No access to submitted environment'); return $return; } # nousercheck $return['nousercheck'] = processInputVar('nousercheck', ARG_NUMERIC); if (!$nousercheck || $return['nousercheck'] != 1) { $return['nousercheck'] = 0; } # revisionid $revids = processInputVar("revisionid", ARG_STRING); $revids = explode(':', $revids); $images = getImages(0, $return['imageid']); $return['revisionids'] = array(); if (array_key_exists('subimages', $images[$return['imageid']])) { $subimages = $images[$return['imageid']]['subimages']; array_unshift($subimages, $return['imageid']); foreach ($subimages as $key => $imgid) { $revisions = getImageRevisions($imgid); if (!array_key_exists($key, $revids) || !is_numeric($revids[$key]) || !array_key_exists($revids[$key], $revisions)) { $revid = getProductionRevisionid($imgid); } else { $revid = $revids[$key]; } if (!array_key_exists($imgid, $return['revisionids'])) { $return['revisionids'][$imgid] = array(); } $return['revisionids'][$imgid][] = $revid; } } elseif ($revids[0] != '' && is_numeric($revids[0])) { $return['revisionids'][$return['imageid']][] = $revids[0]; } else { $return['revisionids'][$return['imageid']][] = getProductionRevisionid($return['imageid']); } # duration if ($return['ending'] == 'duration') { $return['duration'] = processInputVar('duration', ARG_NUMERIC, 0); if ($return['duration'] > $maxinitial) { $return['duration'] = $maxinitial; } } # start/end $return['start'] = processInputVar('start', ARG_NUMERIC); $return['end'] = processInputVar('end', ARG_NUMERIC, 0); $now = time(); if ($return['start'] == 0) { $start = $now; } else { $start = $return['start']; } if ($return['ending'] == 'endat') { $end = $return['end']; } if ($return['ending'] == 'indefinite') { $end = datetimeToUnix('2038-01-01 00:00:00'); } elseif ($return['ending'] == 'duration') { $end = $start + $return['duration'] * 60; } if ($start < $now) { $return['err'] = 1; $return['errmsg'] = i('The submitted start time is in the past.'); return $return; } if ($start + 900 > $end) { $return['err'] = 1; $return['errmsg'] = i('The end time must be at least 15 minutes later than the start time.'); return $return; } $return['ipaddr'] = ''; $return['macaddr'] = ''; # server specific input if ($return['type'] == 'server') { # name $return['name'] = processInputVar('name', ARG_STRING); if (!preg_match('/^([-a-zA-Z0-9_\\. ]){0,255}$/', $return['name'])) { $return['err'] = 1; $return['errmsg'] = i('The reservation name can only contain letters, numbers, spaces, dashes(-), underscores(_), and periods(.) and can be up to 255 characters long'); return $return; } # ipaddr $return['ipaddr'] = processInputVar('ipaddr', ARG_STRING); if ($return['ipaddr'] != '') { # validate fixed IP address if (!validateIPv4addr($return['ipaddr'])) { $return['err'] = 1; $return['errmsg'] = i('Invalid IP address. Must be w.x.y.z with each of w, x, y, and z being between 1 and 255 (inclusive)'); return $return; } # validate netmask $return['netmask'] = processInputVar('netmask', ARG_STRING); $bnetmask = ip2long($return['netmask']); if (!preg_match('/^[1]+0[^1]+$/', sprintf('%032b', $bnetmask))) { $return['err'] = 1; $return['errmsg'] = i('Invalid netmask specified'); return $return; } # validate router $return['router'] = processInputVar('router', ARG_STRING); if (!validateIPv4addr($return['router'])) { $return['err'] = 1; $return['errmsg'] = i('Invalid router address. Must be w.x.y.z with each of w, x, y, and z being between 1 and 255 (inclusive)'); return $return; } $return['network'] = ip2long($return['ipaddr']) & $bnetmask; if ($return['network'] != (ip2long($return['router']) & $bnetmask)) { $return['err'] = 1; $return['errmsg'] = i('IP address and router are not on the same subnet based on the specified netmask.'); return $return; } # validate dns server(s) $dns = processInputVar('dns', ARG_STRING); $tmp = explode(',', $dns); $cnt = 0; $return['dnsArr'] = array(); foreach ($tmp as $dnsaddr) { if ($cnt && $dnsaddr == '') { continue; } if ($cnt == 3) { $return['err'] = 1; $return['errmsg'] = i('Too many DNS servers specified - up to 3 are allowed.'); return $return; } if (!validateIPv4addr($dnsaddr)) { $return['err'] = 1; $return['errmsg'] = i('Invalid DNS server specified.'); return $return; } $return['dnsArr'][] = $dnsaddr; $cnt++; } # check that a management node can handle the network $mappedmns = getMnsFromImage($return['imageid']); $mnnets = checkAvailableNetworks($return['ipaddr']); $intersect = array_intersect($mappedmns, $mnnets); if (empty($intersect)) { $return['err'] = 1; $return['errmsg'] = i('There are no management nodes that can deploy the selected image with the specified IP address.'); return $return; } } # macaddr $return['macaddr'] = processInputVar('macaddr', ARG_STRING); if ($return['macaddr'] != '' && !preg_match('/^(([A-Fa-f0-9]){2}:){5}([A-Fa-f0-9]){2}$/', $return['macaddr'])) { $return['err'] = 1; $return['errmsg'] = i('Invalid MAC address. Must be XX:XX:XX:XX:XX:XX with each pair of XX being from 00 to FF (inclusive)'); return $return; } # profileid $return['profileid'] = processInputVar('profileid', ARG_NUMERIC, 0); $resources = getUserResources(array("serverCheckOut", "serverProfileAdmin"), array("available", "administer")); if (!array_key_exists($return['profileid'], $resources['serverprofile'])) { $return['profileid'] = 0; } elseif ($return['profileid'] != 0) { $tmp = getServerProfiles($return['profileid']); $tmp = $tmp[$return['profileid']]; if ($tmp['imageid'] != $return['imageid'] && ($tmp['fixedIP'] != $return['ipaddr'] && $tmp['fixedMAC'] != $return['macaddr'] || $tmp['fixedIP'] == $return['ipaddr'] && $return['ipaddr'] == '' && $tmp['fixedMAC'] == $return['macaddr'] && $return['macaddr'] == '')) { $return['profileid'] = 0; } } # admingroupid $usergroups = getUserGroups(); $return['admingroupid'] = processInputVar('admingroupid', ARG_NUMERIC); if ($return['admingroupid'] != 0 && !array_key_exists($return['admingroupid'], $usergroups)) { $return['err'] = 1; $return['errmsg'] = i('You do not have access to use the specified admin user group.'); return $return; } # logingroupid $return['logingroupid'] = processInputVar('logingroupid', ARG_NUMERIC); if ($return['logingroupid'] != 0 && !array_key_exists($return['logingroupid'], $usergroups)) { $return['err'] = 1; $return['errmsg'] = i('You do not have access to use the specified access user group.'); return $return; } # monitored $return['monitored'] = processInputVar('monitored', ARG_NUMERIC, 0); if ($return['monitored'] != 0 && $return['monitored'] != 1) { $return['monitored'] = 0; } # configs # TODO configs /*$tmp = getUserResources(array("configAdmin")); $userconfigs = $tmp['config']; $initconfigs = getMappedConfigs($return['imageid']); if(array_key_exists('configdata', $_POST)) { if(get_magic_quotes_gpc()) $_POST['configdata'] = stripslashes($_POST['configdata']); $configdata = json_decode($_POST['configdata']); } if(array_key_exists('configdata', $_POST) && isset($configdata->configs)) $configs = $configdata->configs; else $configs = (object)array(); $return['configs'] = array(); foreach($initconfigs as $id => $config) { if(isset($configs->{$id}) && isset($configs->{$id}->applied) && $configs->{$config['id']}->applied != 'true' && $configs->{$config['id']}->applied != 'false') unset($configs->{$config['id']}); if($config['optional'] && (! isset($configs->{$id}) || ! $configs->{$id}->applied)) continue; $return['configs'][$id] = array('configid' => $config['configid'], 'configmapid' => $config['configmapid'], 'imageid' => $config['subimageid']); if(isset($configs->{$id})) unset($configs->{$id}); } $rescfgmapids = array(); foreach($configs as $id => $config) { if(! array_key_exists($config->configid, $userconfigs)) continue; $return['configs'][$id] = array('configid' => $config->configid, 'configstageid' => $config->configstageid, 'imageid' => $config->imageid); $tmp = explode('/', $id); $rescfgmapids[$tmp[1]] = 1; } # configvars $tmp = array_splice($initconfigs, 0); $initconfigvars = getImageConfigVariables($tmp); if(array_key_exists('configdata', $_POST) && isset($configdata->configvars)) $configvars = $configdata->configvars; else $configvars = (object)array(); #print "/*"; #printArray($initconfigvars); #printArray($configvars); #print "*" . "/"; $return['configvars'] = array(); foreach($initconfigvars as $id => $configvar) { $tmp = explode('/', $id); $cfgid = "{$tmp[0]}/{$tmp[1]}"; $varid = $tmp[2]; if($configvar['ask'] == 0 || ! isset($configvars->{$id}) || ! isset($configvars->{$id}->value)) { $return['configvars'][$cfgid][$varid] = array('value' => $configvar['defaultvalue']); } else { switch($configvar['datatype']) { case 'bool': case 'int': case 'float': $value = processInputData($configvars->{$id}->value, ARG_NUMERIC); break; default: $value = processInputData($configvars->{$id}->value, ARG_STRING); break; } $return['configvars'][$cfgid][$varid] = array('value' => $value); } if(isset($configvars->{$id})) unset($configvars->{$id}); }*/ /*print "/*"; printArray($rescfgmapids); foreach($configvars as $id => $var) { $cfgid = explode('/', $id); print "cfgid: {$cfgid[1]}\n"; if(! array_key_exists($cfgid[1], $rescfgmapids)) continue; // TODO validate based on var type $value = processInputData($configvars->{$id}->value, ARG_STRING); $return['configvars']["{$cfgid[0]}/{$cfgid[1]}"][$cfgid[2]] = array('value' => $value); } printArray($configvars);*/ #print "*/"; } return $return; }
function processMgmtnodeInput($checks = 1) { global $submitErr, $submitErrMsg, $user, $mode; $return = array(); $mgmtnodes = getManagementNodes(); $return["mgmtnodeid"] = getContinuationVar("mgmtnodeid"); $return["hostname"] = getContinuationVar("hostname", processInputVar("hostname", ARG_STRING)); $return["IPaddress"] = getContinuationVar("IPaddress", processInputVar("IPaddress", ARG_STRING)); $return["owner"] = getContinuationVar("owner", processInputVar("owner", ARG_STRING, $user["unityid"])); $return["stateid"] = getContinuationVar("stateid", processInputVar("stateid", ARG_STRING)); $return["premoduleid"] = getContinuationVar("premoduleid", processInputVar("premoduleid", ARG_NUMERIC)); $return["checkininterval"] = getContinuationVar("checkininterval", processInputVar("checkininterval", ARG_NUMERIC)); $return["installpath"] = getContinuationVar("installpath", processInputVar("installpath", ARG_STRING)); $return["keys"] = getContinuationVar("keys", processInputVar("keys", ARG_STRING)); $return["sshport"] = getContinuationVar("sshport", processInputVar("sshport", ARG_NUMERIC)); $return["imagelibenable"] = getContinuationVar("imagelibenable", processInputVar("imagelibenable", ARG_NUMERIC)); $return["imagelibgroupid"] = getContinuationVar("imagelibgroupid", processInputVar("imagelibgroupid", ARG_NUMERIC)); $return["imagelibuser"] = getContinuationVar("imagelibuser", processInputVar("imagelibuser", ARG_STRING)); $return["imagelibkey"] = getContinuationVar("imagelibkey", processInputVar("imagelibkey", ARG_STRING)); if ($return['checkininterval'] < 5) { $return['checkininterval'] = 5; } if ($return['checkininterval'] > 30) { $return['checkininterval'] = 30; } if ($return['sshport'] < 1 || $return['sshport'] > 65535) { $return['sshport'] = 22; } if ($return['imagelibenable'] != '' && $return['imagelibenable'] != 1) { $return['imagelibenable'] = ''; } if ($return['imagelibenable'] != 1) { $return["imagelibgroupid"] = 'NULL'; $return["imagelibuser"] = '******'; $return["imagelibkey"] = 'NULL'; } if (!$checks) { return $return; } if (!ereg('^[a-zA-Z0-9_][-a-zA-Z0-9_\\.]{1,49}$', $return["hostname"])) { $submitErr |= MNHOSTNAMEERR; $submitErrMsg[MNHOSTNAMEERR] = "Hostname can only contain letters, numbers, dashes(-), periods(.), and underscores(_). It can be from 1 to 50 characters long"; } if (!($submitErr & MNHOSTNAMEERR) && $mode != "confirmEditMgmtnode" && checkForMgmtnodeHostname($return["hostname"])) { $submitErr |= MNHOSTNAMEERR; $submitErrMsg[MNHOSTNAMEERR] = "A node already exists with this hostname."; } $ipaddrArr = explode('.', $return["IPaddress"]); if (!ereg('^(([0-9]){1,3}\\.){3}([0-9]){1,3}$', $return["IPaddress"]) || $ipaddrArr[0] < 1 || $ipaddrArr[0] > 255 || $ipaddrArr[1] < 0 || $ipaddrArr[1] > 255 || $ipaddrArr[2] < 0 || $ipaddrArr[2] > 255 || $ipaddrArr[3] < 1 || $ipaddrArr[3] > 255) { $submitErr |= IPADDRESSERR; $submitErrMsg[IPADDRESSERR] = "Invalid IP address. Must be w.x.y.z with each of " . "w, x, y, and z being between 1 and 255 (inclusive)"; } if ($mode != "confirmEditMgmtnode" && !($submitErr & IPADDRESSERR) && checkForMgmtnodeIPaddress($return["IPaddress"])) { $submitErr |= IPADDRESSERR; $submitErrMsg[IPADDRESSERR] = "A node already exists with this IP address."; } if (!validateUserid($return["owner"])) { $submitErr |= MNOWNERERR; $submitErrMsg[MNOWNERERR] = "Submitted ID is not valid"; } if (!preg_match('/^([-a-zA-Z0-9_\\.\\/]){2,100}$/', $return["installpath"])) { $submitErr |= MNINSTPATHERR; $submitErrMsg[MNINSTPATHERR] = "This can only contain letters, numbers, dashes(-), periods(.), underscores(_), and forward slashes(/). It can be from 2 to 100 characters long"; } if (!empty($return['keys']) && !preg_match('/^([-a-zA-Z0-9_\\.\\/,]){2,1024}$/', $return["keys"])) { $submitErr |= MNSSHIDKEYSERR; $submitErrMsg[MNSSHIDKEYSERR] = "This can only contain letters, numbers, dashes(-), periods(.), underscores(_), forward slashes(/), and commas(,). It can be from 2 to 1024 characters long"; } if ($return['imagelibenable'] == 1) { $validgroups = getUserResources(array('mgmtNodeAdmin'), array("manageGroup"), 1); if (!in_array($return['imagelibgroupid'], array_keys($validgroups['managementnode']))) { $submitErr |= MNIMGLIBGRPIDERR; $submitErrMsg[MNIMGLIBGRPIDERR] = "The selected group was invalid"; } if (!preg_match('/^([-a-zA-Z0-9_\\.\\/,]){2,20}$/', $return["imagelibuser"])) { $submitErr |= MNIMGLIBUSERERR; $submitErrMsg[MNIMGLIBUSERERR] = "This can only contain letters, numbers, and dashes(-) and can be from 2 to 20 characters long"; } if (!preg_match('/^([-a-zA-Z0-9_\\.\\/,]){2,100}$/', $return["imagelibkey"])) { $submitErr |= MNIMGLIBKEYERR; $submitErrMsg[MNIMGLIBKEYERR] = "This can only contain letters, numbers, dashes(-), periods(.), underscores(_), and forward slashes(/). It can be from 2 to 100 characters long"; } } else { $return["imagelibgroupid"] = 'NULL'; $return["imagelibuser"] = '******'; $return["imagelibkey"] = 'NULL'; } return $return; }
function RESTresourceDetail() { $type = validatetype(processRESTarg(1, ARG_STRING)); $deleted = processInputVar('deleted', ARG_NUMERIC, 0); if ($deleted != 0 && $deleted != 1) { $deleted = 0; } $name = processInputVar('name', ARG_STRING, '*'); $tmp = processInputVar('prettyname', ARG_STRING, '*'); if ($name == '*' && $tmp != '*') { $name = $tmp; } if (is_null($type)) { RESTresponse(404, "invalid resource type"); return; } $subid = processRESTarg(2, ARG_NUMERIC, 0); if ($type == 'image') { $resources = getUserResources(array("imageAdmin", "imageCheckOut"), array('available'), 0, $deleted); } elseif ($type == 'computer') { $resources = getUserResources(array("computerAdmin"), array("administer"), 0, $deleted); } elseif ($type == 'config') { $resources = getUserResources(array("configAdmin"), array('available'), 0, $deleted); } # TODO #elseif ... if ($subid && !array_key_exists($subid, $resources[$type])) { RESTresponse(404, "specified resource does not exist"); printArray($resources[$type]); return; } if ($_SERVER['REQUEST_METHOD'] == 'DELETE') { if (RESTdeleteResource($type, $subid)) { RESTresponse(204); } else { RESTresponse(404, "specified resource does not exist 2"); } return; } if ($type == 'image') { $items = getImages($deleted, $subid); $data = array(); foreach (array_keys($resources[$type]) as $id) { if ($name != '*' && !preg_match("/^{$name}\$/i", $items[$id]['prettyname'])) { continue; } if (array_key_exists($id, $items)) { $data[$id] = $items[$id]; } } } elseif ($type == 'computer') { $data = getComputers(1, 0, $subid); } elseif ($type == 'config') { $cluster = processInputVar('cluster', ARG_NUMERIC, -1); $cfg = new Config(); $items = $cfg->getData($cfg->defaultGetDataArgs); $data = array(); foreach (array_keys($resources[$type]) as $id) { if ($name != '*' && !preg_match("/^{$name}\$/i", $items[$id]['name'])) { continue; } if (array_key_exists($id, $items)) { if ($cluster == -1 || $cluster == 0 && $items[$id]['configtype'] != 'Cluster' || $cluster == 1 && $items[$id]['configtype'] == 'Cluster') { $data[$id] = $items[$id]; } } } } #elseif ... if ($subid == 0) { sendREST(dataToJSON($data)); return; } sendREST(dataToJSON($data[$subid], 1)); }
function viewStatistics() { global $submitErr, $submitErrMsg, $user; define("30MIN", 1800); define("1HOUR", 3600); define("2HOURS", 7200); define("4HOURS", 14400); $month1 = processInputVar("month1", ARG_NUMERIC); $day1 = processInputVar("day1", ARG_NUMERIC); $year1 = processInputVar("year1", ARG_NUMERIC); $month2 = processInputVar("month2", ARG_NUMERIC); $day2 = processInputVar("day2", ARG_NUMERIC); $year2 = processInputVar("year2", ARG_NUMERIC); $affilid = processInputVar("affilid", ARG_NUMERIC, $user['affiliationid']); $mode2 = getContinuationVar('mode', 'default'); $provid = processInputVar('provid', ARG_NUMERIC, 0); if ($mode2 == 'provisioning') { $affilid = 0; $provs = getContinuationVar('provs'); if (!array_key_exists($provid, $provs)) { $ids = array_keys($provs); $provid = $ids[0]; } } else { $provid = 0; } $affils = getAffiliations(); if (!checkUserHasPerm('View Statistics by Affiliation') || $affilid != 0 && !array_key_exists($affilid, $affils)) { $affilid = $user['affiliationid']; } if ($affilid == 0) { $statsfor = i("All Affiliations"); } else { $statsfor = $affils[$affilid]; } $start = "{$year1}-{$month1}-{$day1} 00:00:00"; $end = "{$year2}-{$month2}-{$day2} 23:59:59"; if (!checkdate($month1, $day1, $year1)) { $submitErr |= STARTERR; $submitErrMsg[STARTERR] = i("The selected start date is not valid. Please select a valid date.") . "<br>\n"; } if (!checkdate($month2, $day2, $year2)) { $submitErr |= ENDERR; $submitErrMsg[ENDERR] = i("The selected end date is not valid. Please select a valid date.") . "<br>\n"; } if (datetimeToUnix($start) > datetimeToUnix($end)) { $submitErr |= ORDERERR; $submitErrMsg[ORDERERR] = i("The selected end date is before the selected start date. Please select an end date equal to or greater than the start date.") . "<br>\n"; } if ($submitErr) { selectStatistics(); return; } $timestart = microtime(1); if ($mode2 == 'default') { print "<H2>" . i("Statistic Information for") . " {$statsfor}</H2>\n"; } elseif ($mode2 == 'provisioning') { print "<H2>" . i("Statistic Information for") . " {$provs[$provid]}</H2>\n"; } print "<H3>"; $tmp = mktime(0, 0, 0, $month1, $day1, $year1); $starttime = strftime('%x', $tmp); $tmp = mktime(0, 0, 0, $month2, $day2, $year2); $endtime = strftime('%x', $tmp); printf(i("Reservation information between %s and %s:"), $starttime, $endtime); print "</H3>\n"; $reloadid = getUserlistID('vclreload@Local'); if ($mode2 == 'default') { $query = "SELECT l.userid, " . "u.affiliationid, " . "l.nowfuture, " . "UNIX_TIMESTAMP(l.start) AS start, " . "(UNIX_TIMESTAMP(l.loaded) - UNIX_TIMESTAMP(l.start)) AS loadtime, " . "UNIX_TIMESTAMP(l.finalend) AS finalend, " . "l.wasavailable, " . "l.ending, " . "i.prettyname, " . "o.prettyname AS OS " . "FROM log l, " . "image i, " . "user u, " . "OS o " . "WHERE l.start >= '{$start}' AND " . "l.finalend <= '{$end}' AND " . "i.id = l.imageid AND " . "i.OSid = o.id AND " . "l.userid != {$reloadid} AND "; } elseif ($mode2 == 'provisioning') { $query = "SELECT l.userid, " . "u.affiliationid, " . "l.nowfuture, " . "UNIX_TIMESTAMP(l.start) AS start, " . "(UNIX_TIMESTAMP(l.loaded) - UNIX_TIMESTAMP(l.start)) AS loadtime, " . "UNIX_TIMESTAMP(l.finalend) AS finalend, " . "l.wasavailable, " . "l.ending, " . "i.prettyname, " . "o.prettyname AS OS " . "FROM image i, " . "user u, " . "OS o, " . "log l " . "JOIN (" . "SELECT s.logid, " . "MIN(s.computerid) AS computerid " . "FROM sublog s, " . "computer c " . "WHERE s.computerid = c.id AND " . "c.provisioningid = {$provid} " . "GROUP BY logid " . ") AS s ON (s.logid = l.id) " . "WHERE l.start >= '{$start}' AND " . "l.finalend <= '{$end}' AND " . "i.id = l.imageid AND " . "i.OSid = o.id AND " . "l.userid != {$reloadid} AND "; } if ($affilid != 0) { $query .= "u.affiliationid = {$affilid} AND "; } $query .= "l.userid = u.id " . "ORDER BY i.prettyname"; $qh = doQuery($query, 275); $totalreservations = 0; $users = array(); $nows = 0; $futures = 0; $notavailable = 0; $loadtimes = array("2less" => 0, "2to6" => 0, "6to8" => 0, "8more" => 0); $ending = array("deleted" => 0, "released" => 0, "failed" => 0, "noack" => 0, "nologin" => 0, "timeout" => 0, "EOR" => 0, "none" => 0); $imagecount = array(); $imageusers = array(); $imagehours = array(); $imageload2less = array(); $imageload2to6 = array(); $imageload6to8 = array(); $imageload8more = array(); $imagefails = array(); $lengths = array("30min" => 0, "1hour" => 0, "2hours" => 0, "4hours" => 0, "6hours" => 0, "8hours" => 0, "10hours" => 0, "10hrsplus" => 0); $totalhours = 0; $osusers = array(); while ($row = mysql_fetch_assoc($qh)) { if (!array_key_exists($row["prettyname"], $imageload2less)) { $imageload2less[$row["prettyname"]] = 0; } if (!array_key_exists($row["prettyname"], $imageload2to6)) { $imageload2to6[$row["prettyname"]] = 0; } if (!array_key_exists($row["prettyname"], $imageload6to8)) { $imageload6to8[$row["prettyname"]] = 0; } if (!array_key_exists($row["prettyname"], $imageload8more)) { $imageload8more[$row["prettyname"]] = 0; } # notavailable if ($row["wasavailable"] == 0) { $notavailable++; } else { $totalreservations++; # load times if ($row['loadtime'] <= 120) { $loadtimes['2less']++; # imageload2less $imageload2less[$row['prettyname']]++; } elseif ($row['loadtime'] > 120 && $row['loadtime'] <= 360) { $loadtimes['2to6']++; $imageload2to6[$row['prettyname']]++; } elseif ($row['loadtime'] > 360 && $row['loadtime'] <= 480) { $loadtimes['6to8']++; $imageload6to8[$row['prettyname']]++; } else { $loadtimes['8more']++; $imageload8more[$row['prettyname']]++; } } # users $users[$row['userid']] = 1; # nowfuture if ($row["nowfuture"] == "now") { $nows++; } else { $futures++; } # ending $ending[$row["ending"]]++; # imagecount if (!array_key_exists($row["prettyname"], $imagecount)) { $imagecount[$row["prettyname"]] = 0; } $imagecount[$row["prettyname"]]++; # imageusers if (!array_key_exists($row["prettyname"], $imageusers)) { $imageusers[$row["prettyname"]] = array(); } $imageusers[$row['prettyname']][$row['userid']] = 1; # lengths $length = $row["finalend"] - $row["start"]; if ($length < 0) { $length = 0; } if ($length <= 1800) { $lengths["30min"]++; } elseif ($length <= 3600) { $lengths["1hour"]++; } elseif ($length <= 7200) { $lengths["2hours"]++; } elseif ($length <= 14400) { $lengths["4hours"]++; } elseif ($length <= 21600) { $lengths["6hours"]++; } elseif ($length <= 28800) { $lengths["8hours"]++; } elseif ($length <= 36000) { $lengths["10hours"]++; } else { $lengths["10hrsplus"]++; } # imagehours if (!array_key_exists($row["prettyname"], $imagehours)) { $imagehours[$row["prettyname"]] = 0; } $imagehours[$row["prettyname"]] += $length / 3600; # imagefails if (!array_key_exists($row["prettyname"], $imagefails)) { $imagefails[$row["prettyname"]] = 0; } if ($row['ending'] == 'failed') { $imagefails[$row["prettyname"]] += 1; } # total hours $totalhours += $length; # osusers if (!array_key_exists($row["OS"], $osusers)) { $osusers[$row["OS"]] = array(); } $osusers[$row['OS']][$row['userid']] = 1; } print "<DIV align=center>\n"; print "<TABLE>\n"; print " <TR>\n"; print " <TH align=right>" . i("Total Reservations:") . "</TH>\n"; print " <TD>{$totalreservations}</TD>\n"; print " </TR>\n"; print " <TR>\n"; print " <TH align=right>" . i("Total Hours Used:") . "</TH>\n"; print " <TD>" . (int) ($totalhours / 3600) . "</TD>\n"; print " </TR>\n"; print " <TR>\n"; print " <TH align=right>" . i("\"Now\" Reservations:") . "</TH>\n"; print " <TD>{$nows}</TD>\n"; print " </TR>\n"; print " <TR>\n"; print " <TH align=right>" . i("\"Later\" Reservations:") . "</TH>\n"; print " <TD>{$futures}</TD>\n"; print " </TR>\n"; print " <TR>\n"; print " <TH align=right>" . i("Unavailable:") . "</TH>\n"; print " <TD>{$notavailable}</TD>\n"; print " </TR>\n"; print " <TR>\n"; print " <TH align=right>" . i("Load times < 2 minutes:") . "</TH>\n"; print " <TD>{$loadtimes['2less']}</TD>\n"; print " </TR>\n"; print " <TH align=right>" . i("Load times 2-6 minutes:") . "</TH>\n"; print " <TD>{$loadtimes['2to6']}</TD>\n"; print " </TR>\n"; print " <TH align=right>" . i("Load times 6-8 minutes:") . "</TH>\n"; print " <TD>{$loadtimes['6to8']}</TD>\n"; print " <TR>\n"; print " <TH align=right>" . i("Load times >= 8 minutes:") . "</TH>\n"; print " <TD>{$loadtimes['8more']}</TD>\n"; print " </TR>\n"; print " <TR>\n"; print " <TH align=right>" . i("Total Unique Users:") . "</TH>\n"; print " <TD>" . count($users) . "</TD>\n"; print " </TR>\n"; foreach (array_keys($osusers) as $key) { print " <TR>\n"; print " <TH align=right>"; printf(i("Unique Users of %s:"), $key); print "</TH>\n"; print " <TD>" . count($osusers[$key]) . "</TD>\n"; print " </TR>\n"; } print "</TABLE>\n"; print "<TABLE>\n"; print " <TR>\n"; print " <TD></TD>\n"; print " <TH>" . i("Reservations") . "</TH>\n"; print " <TH>" . i("Unique Users") . "</TH>\n"; print " <TH>" . i("Hours Used") . "</TH>\n"; print " <TH>" . i("< 2 min wait") . "</TH>\n"; print " <TH>" . i("2-6 min wait") . "</TH>\n"; print " <TH>" . i("6-8 min wait") . "</TH>\n"; print " <TH>" . i(">= 8 min wait") . "</TH>\n"; print " <TH>" . i("Failures") . "</TH>\n"; print " </TR>\n"; foreach ($imagecount as $key => $value) { print " <TR>\n"; print " <TH align=right>{$key}:</TH>\n"; print " <TD align=center>{$value}</TD>\n"; print " <TD align=center>" . count($imageusers[$key]) . "</TD>\n"; if ((int) $imagehours[$key] == 0) { print " <TD align=center>1</TD>\n"; } else { print " <TD align=center>" . (int) $imagehours[$key] . "</TD>\n"; } print " <TD align=center>{$imageload2less[$key]}</TD>\n"; print " <TD align=center>{$imageload2to6[$key]}</TD>\n"; print " <TD align=center>{$imageload6to8[$key]}</TD>\n"; print " <TD align=center>{$imageload8more[$key]}</TD>\n"; if ($imagefails[$key]) { $percent = $imagefails[$key] * 100 / $value; if ($percent < 1) { $percent = sprintf('%.1f%%', $percent); } else { $percent = sprintf('%d%%', $percent); } print " <TD align=center><font color=red>{$imagefails[$key]} "; print "({$percent})</font></TD>\n"; } else { print " <TD align=center>{$imagefails[$key]}</TD>\n"; } print " </TR>\n"; } print "</TABLE>\n"; print "<H3>" . i("Durations:") . "</H3>\n"; print "<TABLE>\n"; print " <TR>\n"; print " <TH align=right>" . i("0 - 30 Min:") . "</TH>\n"; print " <TD>" . $lengths["30min"] . "</TD>\n"; print " </TR>\n"; print " <TR>\n"; print " <TH align=right>" . i("30 Min - 1 Hour:") . "</TH>\n"; print " <TD>" . $lengths["1hour"] . "</TD>\n"; print " </TR>\n"; print " <TR>\n"; print " <TH align=right>" . i("1 Hour - 2 Hours:") . "</TH>\n"; print " <TD>" . $lengths["2hours"] . "</TD>\n"; print " </TR>\n"; print " <TR>\n"; print " <TH align=right>" . i("2 Hours - 4 Hours:") . "</TH>\n"; print " <TD>" . $lengths["4hours"] . "</TD>\n"; print " </TR>\n"; print " <TR>\n"; print " <TH align=right>" . i("4 Hours - 6 Hours:") . "</TH>\n"; print " <TD>" . $lengths["6hours"] . "</TD>\n"; print " </TR>\n"; print " <TR>\n"; print " <TH align=right>" . i("6 Hours - 8 Hours:") . "</TH>\n"; print " <TD>" . $lengths["8hours"] . "</TD>\n"; print " </TR>\n"; print " <TR>\n"; print " <TH align=right>" . i("8 Hours - 10 Hours:") . "</TH>\n"; print " <TD>" . $lengths["10hours"] . "</TD>\n"; print " </TR>\n"; print " <TR>\n"; print " <TH align=right>" . i("> 10 Hours:") . "</TH>\n"; print " <TD>" . $lengths["10hrsplus"] . "</TD>\n"; print " </TR>\n"; print "</TABLE>\n"; print "<H3>" . i("Ending information:") . "</H3>\n"; print "<TABLE>\n"; print " <TR>\n"; print " <TH align=right>" . i("Deleted:") . "</TH>\n"; print " <TD>" . $ending["deleted"] . "</TD>\n"; print " <TD rowspan=7><img src=\"images/blank.gif\" width=5></TD>\n"; print " <TD>" . i("(Future reservation deleted before start time reached)") . "</TD>\n"; print " </TR>\n"; print " <TR>\n"; print " <TH align=right>" . i("Released:") . "</TH>\n"; print " <TD>" . $ending["released"] . "</TD>\n"; print " <TD>" . i("(Reservation released before end time reached)") . "</TD>\n"; print " </TR>\n"; print " <TR>\n"; print " <TH align=right>" . i("Not Acknowledged:") . "</TH>\n"; print " <TD>" . $ending["noack"] . "</TD>\n"; print " <TD>" . i("(\"Connect!\" button never clicked)") . "</TD>\n"; print " </TR>\n"; print " <TR>\n"; print " <TH align=right>" . i("No Login:"******"</TH>\n"; print " <TD>" . $ending["nologin"] . "</TD>\n"; print " <TD>" . i("(User never logged in)") . "</TD>\n"; print " </TR>\n"; print " <TR>\n"; print " <TH align=right>" . i("End of Reservation:") . "</TH>\n"; print " <TD>" . $ending["EOR"] . "</TD>\n"; print " <TD>" . i("(End of reservation reached)") . "</TD>\n"; print " </TR>\n"; print " <TR>\n"; print " <TH align=right>" . i("Timed Out:") . "</TH>\n"; print " <TD>" . $ending["timeout"] . "</TD>\n"; print " <TD>" . i("(Disconnect and no reconnection within 15 minutes)") . "</TD>\n"; print " </TR>\n"; print " <TR>\n"; print " <TH align=right>" . i("Failed:") . "</TH>\n"; print " <TD>" . $ending["failed"] . "</TD>\n"; print " <TD>" . i("(Reserved computer failed to get prepared for user)") . "</TD>\n"; print " </TR>\n"; print "</TABLE>\n"; print "<br>\n"; print "</div>\n"; $unixstart = datetimeToUnix($start); $unixend = datetimeToUnix($end); $start = date('Y-m-d', $unixstart); $end = date('Y-m-d', $unixend); $cdata = array('start' => $start, 'end' => $end, 'affilid' => $affilid, 'mode' => $mode2, 'provid' => $provid); print "<H2>" . i("Reservations by Day") . "</H2>\n"; print "<small>" . i("(Reservations with start time on given day)") . "</small><br>\n"; $cdata['divid'] = 'resbyday'; $cont = addContinuationsEntry('AJgetStatData', $cdata); print "<input type=hidden id=statdaycont value=\"{$cont}\">\n"; print "<div id=\"resbyday\" class=\"statgraph\">(Loading...)</div>\n"; print "<H2>" . i("Max Concurrent Reservations By Day") . "</H2>\n"; $cdata['divid'] = 'maxconcurresday'; $cont = addContinuationsEntry('AJgetStatData', $cdata); print "<input type=hidden id=statconcurrescont value=\"{$cont}\">\n"; print "<div id=\"maxconcurresday\" class=\"statgraph\">Loading graph data...</div>\n"; print "<H2>" . i("Max Concurrent Blade Reservations By Day") . "</H2>\n"; $cdata['divid'] = 'maxconcurbladeday'; $cont = addContinuationsEntry('AJgetStatData', $cdata); print "<input type=hidden id=statconcurbladecont value=\"{$cont}\">\n"; print "<div id=\"maxconcurbladeday\" class=\"statgraph\">Loading graph data...</div>\n"; print "<H2>" . i("Max Concurrent Virtual Machine Reservations By Day") . "</H2>\n"; $cdata['divid'] = 'maxconcurvmday'; $cont = addContinuationsEntry('AJgetStatData', $cdata); print "<input type=hidden id=statconcurvmcont value=\"{$cont}\">\n"; print "<div id=\"maxconcurvmday\" class=\"statgraph\">Loading graph data...</div>\n"; print "<H2>" . i("Reservations by Hour") . "</H2>\n"; print "<small>(" . i("Active reservations during given hour averaged over selected dates") . ")</small><br><br>\n"; $cdata['divid'] = 'resbyhour'; $cont = addContinuationsEntry('AJgetStatData', $cdata); print "<input type=hidden id=statreshourcont value=\"{$cont}\">\n"; print "<div id=\"resbyhour\" class=\"statgraph\">Loading graph data...</div>\n"; $endtime = microtime(1); $end = $endtime - $timestart; #print "running time: $endtime - $timestart = $end<br>\n"; }
function AJdeleteRevisions() { $revids = getContinuationVar('revids'); $imageid = getContinuationVar('imageid'); $checkedids = processInputVar('checkedids', ARG_STRING); $ids = explode(',', $checkedids); if (empty($ids)) { sendJSON(array()); return; } foreach ($ids as $id) { if (!is_numeric($id) || !in_array($id, $revids)) { sendJSON(array()); return; } } $query = "SELECT DISTINCT ir.revision " . "FROM request rq, " . "reservation rs, " . "imagerevision ir " . "WHERE rs.requestid = rq.id AND " . "rs.imagerevisionid = ir.id AND " . "rs.imagerevisionid IN ({$checkedids}) AND " . "rq.stateid NOT IN (1, 5, 11, 12)"; $qh = doQuery($query); if (mysql_num_rows($qh)) { $inuseids = array(); while ($row = mysql_fetch_assoc($qh)) { $inuseids[] = $row['revision']; } $inuseids = implode(',', $inuseids); $rc = array('status' => 'error', 'msg' => i("The following revisions are in use and cannot be deleted at this time:") . " {$inuseids}"); sendJSON($rc); return; } $query = "UPDATE imagerevision " . "SET deleted = 1, " . "datedeleted = NOW() " . "WHERE id IN ({$checkedids}) " . "AND production != 1"; doQuery($query, 101); $html = $this->getRevisionHTML($imageid); $arr = array('html' => $html); sendJSON($arr); }
function jsonGetGroupInfo() { $groupid = processInputVar('groupid', ARG_NUMERIC); $mousex = processInputVar('mousex', ARG_NUMERIC); $mousey = processInputVar('mousey', ARG_NUMERIC); $userresources = getUserResources(array("groupAdmin"), array("manageGroup"), 1); $found = 0; foreach (array_keys($userresources) as $type) { if (array_key_exists($groupid, $userresources[$type])) { $found = 1; break; } } if (!$found || $mousex < 0 || $mousex > 5000 || $mousey < 0 || $mousey > 500000) { header('Content-Type: text/json; charset=utf-8'); print '{} && {"items":' . json_encode(array()) . '}'; return; } $members = getResourceGroupMembers($type); $data = ''; if (!empty($members[$type][$groupid])) { uasort($members[$type][$groupid], "sortKeepIndex"); foreach ($members[$type][$groupid] as $mem) { $data .= "{$mem['name']}<br>"; } } else { $data = '(empty group)'; } $arr = array('members' => $data, 'x' => $mousex, 'y' => $mousey, 'groupid' => $groupid); header('Content-Type: text/json-comment-filtered; charset=utf-8'); print '{} && {"items":' . json_encode($arr) . '}'; }
function submitHelpForm() { global $user, $submitErr, $submitErrMsg; $name = processInputVar("name", ARG_STRING); $email = processInputVar("email", ARG_STRING); $summary = processInputVar("summary", ARG_STRING); $text = processInputVar("comments", ARG_STRING); if (!ereg('^([A-Za-z]{1,}( )([A-Za-z]){2,})$', $name)) { $submitErr |= NAMEERR; $submitErrMsg[NAMEERR] = "You must submit your first and last name"; } if (!eregi('^[_a-z0-9-]+(\\.[_a-z0-9-]+)*@[a-z0-9-]+(\\.[a-z0-9-]+)*(\\.[a-z]{2,3})$', $email)) { $submitErr |= EMAILERR; $submitErrMsg[EMAILERR] = "Invalid email address, please correct"; } if (empty($summary)) { $submitErr |= SUMMARYERR; $submitErrMsg[SUMMARYERR] = "Please fill in a very short summary of the " . "problem"; } if (empty($text)) { $submitErr |= TEXTERR; $submitErrMsg[TEXTERR] = "Please fill in your problem in the box below.<br>"; } if ($submitErr) { printHelpForm(); return; } $computers = getComputers(); $requests = getUserRequests("all"); $query = "SELECT l.start AS start, " . "l.finalend AS end, " . "l.computerid AS computerid, " . "i.prettyname AS prettyimage " . "FROM log l, " . "image i " . "WHERE l.userid = " . $user["id"] . " AND " . "i.id = l.imageid AND " . "(unix_timestamp(NOW()) - unix_timestamp(l.finalend)) < 14400"; $qh = doQuery($query, 290); while ($row = mysql_fetch_assoc($qh)) { array_push($requests, $row); } $from = $user["email"]; if (get_magic_quotes_gpc()) { $text = stripslashes($text); } $message = "Problem report submitted from VCL web form:\n\n" . "User: "******"unityid"] . "\n" . "Name: " . $name . "\n" . "Email: " . $email . "\n" . "Problem description:\n\n{$text}\n\n"; $end = time(); $start = $end - 14400; $recentrequests = ""; foreach ($requests as $request) { if (datetimeToUnix($request["end"]) > $start || datetimeToUnix($request["start"] < $end)) { $thisstart = str_replace(' ', ' ', prettyDatetime($request["start"])); $thisend = str_replace(' ', ' ', prettyDatetime($request["end"])); $recentrequests .= "Image: " . $request["prettyimage"] . "\n" . "Computer: " . $computers[$request["computerid"]]["hostname"] . "\n" . "Start: {$thisstart}\n" . "End: {$thisend}\n\n"; } } if (!empty($recentrequests)) { $message .= "-----------------------------------------------\n"; $message .= "User's recent reservations:\n\n" . $recentrequests . "\n"; } else { $message .= "User has no recent reservations\n"; } $indrupal = getContinuationVar('indrupal', 0); if (!$indrupal) { print "<H2>VCL Help</H2>\n"; } $mailParams = "-f" . ENVELOPESENDER; if (!mail(HELPEMAIL, "{$summary}", $message, "From: {$from}\r\nReply-To: {$email}\r\n", $mailParams)) { print "The Server was unable to send mail at this time. Please e-mail "; print "<a href=\"mailto:" . HELPEMAIL . "\">" . HELPEMAIL . "</a> for "; print "help with your problem."; } else { print "Your problem report has been submitted. Thank you for letting "; print "us know of your problem so that we can improve this site.<br>\n"; } }
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; }
function AJdelProfile() { if (!checkUserHasPerm('Manage VM Profiles')) { sendJSON(array('failed' => 'noaccess')); return; } $profileid = processInputVar('profileid', ARG_NUMERIC); # check to see if profile is in use $query = "SELECT vh.computerid, " . "s.name " . "FROM vmhost vh, " . "computer c, " . "state s " . "WHERE vh.computerid = c.id AND " . "c.stateid = s.id AND " . "s.name IN ('vmhostinuse', 'tovmhostinuse') AND " . "vh.vmprofileid = {$profileid}"; $qh = doQuery($query, 101); if ($row = mysql_fetch_assoc($qh)) { sendJSON(array('failed' => 'inuse')); return; } $query = "DELETE FROM vmprofile WHERE id = {$profileid}"; doQuery($query, 101); sendJSON(array('SUCCESS')); }
function processUserPrefsInput($checks = 1) { global $submitErr, $submitErrMsg, $user; $return = array(); $defaultres = $user["width"] . 'x' . $user["height"]; $return["preferredname"] = processInputVar("preferredname", ARG_STRING, $user["preferredname"]); $return["resolution"] = processInputVar("resolution", ARG_STRING, $defaultres); $return["bpp"] = processInputVar("bpp", ARG_NUMERIC, $user["bpp"]); $return["audiomode"] = processInputVar("audiomode", ARG_STRING, $user["audiomode"]); $return["mapdrives"] = processInputVar("mapdrives", ARG_NUMERIC, $user["mapdrives"]); $return["mapprinters"] = processInputVar("mapprinters", ARG_NUMERIC, $user["mapprinters"]); $return["mapserial"] = processInputVar("mapserial", ARG_NUMERIC, $user["mapserial"]); $return['unityid'] = "{$user['unityid']}@{$user['affiliation']}"; if (!$checks) { return $return; } if (strlen($return["preferredname"]) > 25) { $submitErr |= PREFNAMEERR; $submitErrMsg[PREFNAMEERR] = "Preferred name can only be up to 25 characters"; } if (!ereg('^[a-zA-Z ]*$', $return["preferredname"])) { $submitErr |= PREFNAMEERR; $submitErrMsg[PREFNAMEERR] = "Preferred name can only contain letters and spaces"; } if (array_key_exists('unityid', $return) && !validateUserid($return['unityid'])) { $submitErr |= VIEWASUSERERR; $submitErrMsg[VIEWASUSERERR] = "Invalid user id"; } if ($user['affiliation'] == 'Local') { $return['newpassword'] = $_POST['newpassword']; $confirmpwd = $_POST['confirmpassword']; $curr = $_POST['currentpassword']; if (get_magic_quotes_gpc()) { $return['newpassword'] = stripslashes($return['newpassword']); $confirmpwd = stripslashes($confirmpwd); $curr = stripslashes($curr); } if (!empty($return['newpassword']) && !empty($confirmpwd) && !validateLocalAccount($user['unityid'], $curr)) { $submitErr |= LOCALPASSWORDERR; $submitErrMsg[LOCALPASSWORDERR] = "Password incorrect"; } elseif (empty($return['newpassword']) && !empty($confirmpwd) || !empty($return['newpassword']) && empty($confirmpwd) || $return['newpassword'] != $confirmpwd) { $submitErr |= LOCALPASSWORDERR; $submitErrMsg[LOCALPASSWORDERR] = "Passwords do not match"; } } return $return; }
function submitHelpForm() { global $user, $submitErr, $submitErrMsg; $name = processInputVar("name", ARG_STRING); $email = processInputVar("email", ARG_STRING); $summary = processInputVar("summary", ARG_STRING); $text = processInputVar("comments", ARG_STRING); $testname = $name; if (get_magic_quotes_gpc()) { $testname = stripslashes($name); } if (!preg_match('/^([-A-Za-z \']{1,} [-A-Za-z \']{2,})*$/', $testname)) { $submitErr |= NAMEERR; $submitErrMsg[NAMEERR] = "Name can only contain letters, spaces, apostrophes ('), and dashes (-)"; } if (!preg_match('/^[_a-z0-9-]+(\\.[_a-z0-9-]+)*@[a-z0-9-]+(\\.[a-z0-9-]+)*(\\.[a-z]{2,3})$/i', $email)) { $submitErr |= EMAILERR; $submitErrMsg[EMAILERR] = "Invalid email address, please correct"; } if (empty($summary)) { $submitErr |= SUMMARYERR; $submitErrMsg[SUMMARYERR] = "Please fill in a very short summary of the " . "problem"; } if (empty($text)) { $submitErr |= TEXTERR; $submitErrMsg[TEXTERR] = "Please fill in your problem in the box below.<br>"; } if ($submitErr) { printHelpForm(); return; } $computers = getComputers(); $requests = array(); $query = "SELECT l.id, " . "l.start, " . "l.finalend AS end, " . "s.computerid, " . "i.prettyname AS prettyimage " . "FROM log l, " . "image i, " . "sublog s " . "WHERE l.userid = {$user["id"]} AND " . "i.id = l.imageid AND " . "s.logid = l.id AND " . "l.finalend < DATE_ADD(NOW(), INTERVAL 1 DAY) " . "ORDER BY l.finalend DESC " . "LIMIT 5"; $qh = doQuery($query, 290); while ($row = mysql_fetch_assoc($qh)) { # only include 1 computer from cluster reservations if (array_key_exists($row['id'], $requests)) { continue; } $requests[$row['id']] = $row; } $from = $user["email"]; if (get_magic_quotes_gpc()) { $text = stripslashes($text); } $message = "Problem report submitted from VCL web form:\n\n" . "User: "******"unityid"] . "\n" . "Name: " . $testname . "\n" . "Email: " . $email . "\n" . "Problem description:\n\n{$text}\n\n"; $recentrequests = ""; foreach ($requests as $request) { $thisstart = str_replace(' ', ' ', prettyDatetime($request["start"])); $thisend = str_replace(' ', ' ', prettyDatetime($request["end"])); $recentrequests .= "Image: {$request["prettyimage"]}\n" . "Computer: {$computers[$request["computerid"]]["hostname"]}\n" . "Start: {$thisstart}\n" . "End: {$thisend}\n\n"; } if (!empty($recentrequests)) { $message .= "-----------------------------------------------\n"; $message .= "User's recent reservations:\n\n" . $recentrequests . "\n"; } else { $message .= "User has no recent reservations\n"; } $indrupal = getContinuationVar('indrupal', 0); if (!$indrupal) { print "<H2>VCL Help</H2>\n"; } $mailParams = "-f" . ENVELOPESENDER; if (get_magic_quotes_gpc()) { $summary = stripslashes($summary); } if (!mail(HELPEMAIL, "{$summary}", $message, "From: {$from}\r\nReply-To: {$email}\r\n", $mailParams)) { print "The Server was unable to send mail at this time. Please e-mail "; print "<a href=\"mailto:" . HELPEMAIL . "\">" . HELPEMAIL . "</a> for "; print "help with your problem."; } else { print "Your problem report has been submitted. Thank you for letting "; print "us know of your problem so that we can improve this site.<br>\n"; } }
function processScheduleInput($checks = 1) { global $submitErr, $submitErrMsg; $return = array(); $return["start"] = array(); $return["end"] = array(); $return["scheduleid"] = getContinuationVar("scheduleid", processInputVar("scheduleid", ARG_NUMERIC)); $return["name"] = getContinuationVar("name", processInputVar("name", ARG_STRING)); $return["owner"] = getContinuationVar("owner", processInputVar("owner", ARG_STRING)); $return["submode"] = processInputVar("submode", ARG_STRING); $return["selrow"] = processInputVar("selrow", ARG_NUMERIC); $return["count"] = getContinuationVar("count", processInputVar("count", ARG_NUMERIC, 0)); $return["startDay"] = processInputVar("startDay", ARG_MULTINUMERIC); $return["startTime"] = processInputVar("startTime", ARG_MULTISTRING); $return["endDay"] = processInputVar("endDay", ARG_MULTINUMERIC); $return["endTime"] = processInputVar("endTime", ARG_MULTISTRING); if (!$checks) { return $return; } if (strlen($return["name"]) > 25 || strlen($return["name"]) < 2) { $submitErr |= SCHNAMEERR; $submitErrMsg[SCHNAMEERR] = "Name must be from 2 to 30 characters"; } if (!($submitErr & SCHNAMEERR) && checkForScheduleName($return["name"], $return["scheduleid"])) { $submitErr |= SCHNAMEERR; $submitErrMsg[SCHNAMEERR] = "A schedule already exists with this name."; } if (!validateUserid($return["owner"])) { $submitErr |= SCHOWNERERR; $submitErrMsg[SCHOWNERERR] = "The submitted unity ID is invalid."; } for ($i = 0; $i < $return["count"]; $i++) { if (!ereg('^((0?[1-9])|(1[0-2])):([0-5][0-9]) (am|pm)$', $return["startTime"][$i]) || !ereg('^((0?[1-9])|(1[0-2])):([0-5][0-9]) (am|pm)$', $return["endTime"][$i])) { $submitErr |= 1 << $i; $submitErrMsg[1 << $i] = "Time must be of the form [H]H:MM am/pm"; } elseif (daytimeToMin($return["startDay"][$i], $return["startTime"][$i], "start") >= daytimeToMin($return["endDay"][$i], $return["endTime"][$i], "end")) { $submitErr |= 1 << $i; $submitErrMsg[1 << $i] = "The start day/time must be before the end day/time"; } } for ($i = 0; $i < $return["count"] - 1; $i++) { for ($j = $i + 1; $j < $return["count"]; $j++) { if (daytimeToMin($return["startDay"][$i], $return["startTime"][$i], "start") < daytimeToMin($return["endDay"][$j], $return["endTime"][$j], "end") && daytimeToMin($return["endDay"][$i], $return["endTime"][$i], "end") > daytimeToMin($return["startDay"][$j], $return["startTime"][$j], "start")) { $submitErr |= OVERLAPERR; $submitErrMsg[OVERLAPERR] = "At least 2 of the time periods overlap. Please combine them into a single entry."; break 2; } } } return $return; }
function AJsaveUserGroupPrivs() { global $user; $groups = getUserGroups(0, $user['affiliationid']); $groupid = processInputVar('groupid', ARG_NUMERIC); if (!array_key_exists($groupid, $groups)) { sendJSON(array('failed' => 'noaccess')); return; } $permids = processInputVar('permids', ARG_STRING); if (!preg_match('/^[0-9,]*$/', $permids)) { sendJSON(array('failed' => 'invalid input')); return; } $perms = explode(',', $permids); $query = "DELETE FROM usergrouppriv WHERE usergroupid = {$groupid}"; doQuery($query, 101); if (empty($perms[0])) { sendJSON(array('success' => 1)); return; } $values = array(); foreach ($perms as $permid) { $values[] = "({$groupid}, {$permid})"; } $allvals = implode(',', $values); $query = "INSERT INTO usergrouppriv " . "(usergroupid, " . "userprivtypeid) " . "VALUES {$allvals}"; doQuery($query, 101); sendJSON(array('success' => 1)); $_SESSION['user']["groupperms"] = getUsersGroupPerms(array_keys($user['groups'])); }
function getDojoHTML($refresh) { global $mode, $actions, $skin; $rt = ''; $dojoRequires = array(); switch ($mode) { case 'viewNodes': case 'changeUserPrivs': case 'submitAddResourcePriv': case 'changeResourcePrivs': $dojoRequires = array('dojo.io.*', 'dojo.lfx.*', 'dojo.html.*', 'dojo.widget.*', 'dojo.widget.Button', 'dojo.widget.Tree', 'dojo.widget.TreeSelector', 'dojo.widget.FloatingPane'); break; case 'newRequest': case 'submitRequest': case 'createSelectImage': case 'submitCreateImage': $dojoRequires = array('dojo.io.*', 'dojo.widget.*', 'dojo.html.*'); break; case 'viewRequests': $dojoRequires = array('dojo.io.*', 'dojo.html.*', 'dojo.widget.*', 'dojo.widget.FloatingPane'); break; case 'viewImages': /*$dojoRequires = array('dojo.data.ItemFileWriteStore', 'dojox.grid.Grid', 'dojox.grid.data.model', 'dojo.parser');*/ break; case 'viewImageGrouping': case 'submitImageGroups': case 'viewImageMapping': case 'submitImageMapping': $dojoRequires = array('dojo.parser', 'dijit.layout.LinkPane', 'dijit.layout.ContentPane', 'dijit.layout.TabContainer', 'dijit.form.Button'); break; case 'newImage': case 'submitImageButton': case 'confirmEditOrAddImage': case 'submitEditImageButtons': case 'submitAddSubimage': case 'updateExistingImageComments': case 'updateExistingImage': $dojoRequires = array('dojo.parser', 'dijit.InlineEditBox', 'dijit.form.Textarea', 'dijit.TitlePane'); break; case 'selectComputers': case 'viewComputerGroups': case 'submitComputerGroups': $dojoRequires = array('dojo.parser', 'dijit.layout.LinkPane', 'dijit.layout.ContentPane', 'dijit.layout.TabContainer', 'dijit.form.Button'); break; case 'viewGroups': case 'submitEditGroup': case 'submitAddGroup': case 'submitDeleteGroup': $dojoRequires = array('dojo.parser'); break; case 'editMgmtNode': case 'addMgmtNode': case 'confirmEditMgmtnode': case 'confirmAddMgmtnode': $dojoRequires = array('dojo.parser'); $dojoRequires = array('dijit.form.NumberSpinner'); break; case 'selectauth': $dojoRequires = array('dojo.parser'); break; case 'editVMInfo': $dojoRequires = array('dojo.parser', 'dijit.InlineEditBox', 'dijit.form.NumberSpinner', 'dijit.form.Button', 'dijit.form.TextBox', 'dijit.form.FilteringSelect', 'dijit.TitlePane', 'dijit.layout.ContentPane', 'dijit.layout.TabContainer', 'dojo.data.ItemFileReadStore', 'dijit.Dialog'); break; } if (empty($dojoRequires)) { return ''; } switch ($mode) { case "viewImageGrouping": case "submitImageGroups": case "viewImageMapping": case "submitImageMapping": $rt .= "<style type=\"text/css\">\n"; $rt .= " @import \"themes/{$skin}/css/dojo/{$skin}.css\";\n"; #$rt .= " @import \"dojo/dojo/resources/dojo.css\";\n"; $rt .= "</style>\n"; $rt .= "<script type=\"text/javascript\" src=\"js/images.js\"></script>\n"; $rt .= "<script type=\"text/javascript\" src=\"dojo/dojo/dojo.js\"\n"; $rt .= " djConfig=\"parseOnLoad: true\">\n"; $rt .= "</script>\n"; $rt .= "<script type=\"text/javascript\">\n"; $rt .= " dojo.addOnLoad(function() {\n"; foreach ($dojoRequires as $req) { $rt .= " dojo.require(\"{$req}\");\n"; } $rt .= " });\n"; if ($mode == "viewImageGrouping" || $mode == "submitImageGroups") { $rt .= " dojo.addOnLoad(getImagesButton);\n"; $rt .= " dojo.addOnLoad(getGroupsButton);\n"; } elseif ($mode == "viewImageMapping" || $mode == "submitImageMapping") { $rt .= " dojo.addOnLoad(getMapCompGroupsButton);\n"; $rt .= " dojo.addOnLoad(getMapImgGroupsButton);\n"; } $rt .= "</script>\n"; return $rt; case 'newImage': case 'submitImageButton': case 'confirmEditOrAddImage': case 'submitEditImageButtons': case 'submitAddSubimage': case 'updateExistingImageComments': case 'updateExistingImage': $rt .= "<style type=\"text/css\">\n"; $rt .= " @import \"themes/{$skin}/css/dojo/{$skin}.css\";\n"; #$rt .= " @import \"dojo/dojo/resources/dojo.css\";\n"; $rt .= "</style>\n"; $rt .= "<script type=\"text/javascript\" src=\"js/images.js\"></script>\n"; $rt .= "<script type=\"text/javascript\" src=\"dojo/dojo/dojo.js\"\n"; $rt .= " djConfig=\"parseOnLoad: true\">\n"; $rt .= "</script>\n"; $rt .= "<script type=\"text/javascript\">\n"; $rt .= " dojo.addOnLoad(function() {\n"; foreach ($dojoRequires as $req) { $rt .= " dojo.require(\"{$req}\");\n"; } $rt .= " });\n"; $rt .= " dojo.addOnLoad(function() {\n"; $rt .= " if(document.getElementById('hide1')) {\n"; $rt .= " document.getElementById('hide1').className = 'hidden';\n"; $rt .= " document.getElementById('hide2').className = 'hidden';\n"; $rt .= " document.getElementById('hide3').className = 'hidden';\n"; $rt .= " }\n"; $rt .= " });\n"; $rt .= "</script>\n"; return $rt; case 'viewGroups': case 'submitEditGroup': case 'submitAddGroup': case 'submitDeleteGroup': $rt .= "<style type=\"text/css\">\n"; $rt .= " @import \"themes/{$skin}/css/dojo/{$skin}.css\";\n"; #$rt .= " @import \"dojo/dojo/resources/dojo.css\";\n"; $rt .= "</style>\n"; $rt .= "<script type=\"text/javascript\" src=\"dojo/dojo/dojo.js\"></script>\n"; $rt .= "<script type=\"text/javascript\">\n"; $rt .= " dojo.addOnLoad(function() {\n"; foreach ($dojoRequires as $req) { $rt .= " dojo.require(\"{$req}\");\n"; } $rt .= " });\n"; $rt .= " dojo.addOnLoad(function() {document.onmousemove = updateMouseXY;});\n"; $rt .= "</script>\n"; $rt .= "<script type=\"text/javascript\" src=\"js/groups.js\"></script>\n"; return $rt; case 'editMgmtNode': case 'addMgmtNode': case 'confirmEditMgmtnode': case 'confirmAddMgmtnode': $rt .= "<style type=\"text/css\">\n"; $rt .= " @import \"themes/{$skin}/css/dojo/{$skin}.css\";\n"; #$rt .= " @import \"dojo/dijit/themes/tundra/tundra.css\";\n"; #$rt .= " @import \"dojo/dojo/resources/dojo.css\";\n"; $rt .= "</style>\n"; $rt .= "<script type=\"text/javascript\" src=\"dojo/dojo/dojo.js\"\n"; $rt .= " djConfig=\"parseOnLoad: true\">\n"; $rt .= "</script>\n"; $rt .= "<script type=\"text/javascript\">\n"; $rt .= " dojo.addOnLoad(function() {\n"; foreach ($dojoRequires as $req) { $rt .= " dojo.require(\"{$req}\");\n"; } $rt .= " });\n"; $rt .= " dojo.addOnLoad(function() {document.onmousemove = updateMouseXY;});\n"; $rt .= "</script>\n"; $rt .= "<script type=\"text/javascript\" src=\"js/managementnodes.js\"></script>\n"; return $rt; case "selectComputers": case "viewComputerGroups": case "submitComputerGroups": $rt .= "<style type=\"text/css\">\n"; $rt .= " @import \"themes/{$skin}/css/dojo/{$skin}.css\";\n"; #$rt .= " @import \"dojo/dojo/resources/dojo.css\";\n"; $rt .= "</style>\n"; $rt .= "<script type=\"text/javascript\" src=\"js/computers.js\"></script>\n"; $rt .= "<script type=\"text/javascript\" src=\"dojo/dojo/dojo.js\"\n"; $rt .= " djConfig=\"parseOnLoad: true\">\n"; $rt .= "</script>\n"; $rt .= "<script type=\"text/javascript\">\n"; $rt .= " dojo.addOnLoad(function() {\n"; foreach ($dojoRequires as $req) { $rt .= " dojo.require(\"{$req}\");\n"; } $rt .= " });\n"; if ($mode != 'selectComputers') { $rt .= " dojo.addOnLoad(getCompsButton);\n"; $rt .= " dojo.addOnLoad(getGroupsButton);\n"; } $rt .= "</script>\n"; return $rt; case 'selectauth': $rt .= "<script type=\"text/javascript\" src=\"dojo/dojo/dojo.js\"></script>\n"; $rt .= "<script type=\"text/javascript\">\n"; foreach ($dojoRequires as $req) { $rt .= " dojo.require(\"{$req}\");\n"; } $authtype = processInputVar("authtype", ARG_STRING); $rt .= " dojo.addOnLoad(function() {document.loginform.userid.focus(); document.loginform.userid.select();});\n"; $rt .= "</script>\n"; return $rt; case "editVMInfo": $rt .= "<style type=\"text/css\">\n"; $rt .= " @import \"themes/{$skin}/css/dojo/{$skin}.css\";\n"; #$rt .= " @import \"dojo/dojo/resources/dojo.css\";\n"; $rt .= "</style>\n"; $rt .= "<script type=\"text/javascript\" src=\"js/vm.js\"></script>\n"; $rt .= "<script type=\"text/javascript\" src=\"dojo/dojo/dojo.js\"\n"; $rt .= " djConfig=\"parseOnLoad: true\">\n"; $rt .= "</script>\n"; $rt .= "<script type=\"text/javascript\">\n"; $rt .= " dojo.addOnLoad(function() {\n"; foreach ($dojoRequires as $req) { $rt .= " dojo.require(\"{$req}\");\n"; } $rt .= " });\n"; $rt .= "dojo.addOnLoad(function() {"; $rt .= "var dialog = dijit.byId('profileDlg'); "; $rt .= "dojo.connect(dialog, 'hide', cancelVMprofileChange);});"; /*if($mode != 'selectComputers') { $rt .= " dojo.addOnLoad(getCompsButton);\n"; $rt .= " dojo.addOnLoad(getGroupsButton);\n"; }*/ $rt .= "</script>\n"; return $rt; } $rt .= "<script type=\"text/javascript\" src=\"dojoAjax/dojo.js\"></script>"; $rt .= "<script type=\"text/javascript\">\n"; foreach ($dojoRequires as $req) { $rt .= " dojo.require(\"{$req}\");\n"; } $rt .= " function RPCwrapper(data, callback) {\n"; $rt .= " dojo.io.bind({\n"; $rt .= " url: \"" . BASEURL . SCRIPT . "\",\n"; $rt .= " method: \"post\",\n"; $rt .= " content: data,\n"; $rt .= " load: callback,\n"; $rt .= " error: errorHandler\n"; $rt .= " });\n"; $rt .= " }\n"; if ($actions['pages'][$mode] == 'privileges') { $rt .= " var treeListener = {\n"; $rt .= " nodeExpand: function(message) {\n"; $rt .= " var nodes = dojo.io.cookie.get('VCLNODES');\n"; $rt .= " if(nodes) {\n"; $rt .= " var nodesArr = nodes.split(':');\n"; $rt .= " if(! nodesArr.inArray(message.source.widgetId)) {\n"; $rt .= " nodesArr.push(message.source.widgetId);\n"; $rt .= " nodes = nodesArr.join(':');\n"; $rt .= " }\n"; $rt .= " }\n"; $rt .= " else {\n"; $rt .= " nodes = message.source.widgetId;\n"; $rt .= " }\n"; $rt .= " dojo.io.cookie.set('VCLNODES', nodes, 365, '/', '" . COOKIEDOMAIN . "');\n"; $rt .= " },\n"; $rt .= " nodeCollapse: function(message) {\n"; $rt .= " checkSelectParent(message);\n"; $rt .= " var nodes = dojo.io.cookie.get('VCLNODES');\n"; $rt .= " var nodesArr = nodes.split(':');\n"; $rt .= " var index;\n"; $rt .= " if(index = nodesArr.search(message.source.widgetId)) {\n"; $rt .= " nodesArr.splice(index, 1);\n"; $rt .= " nodes = nodesArr.join(':');\n"; $rt .= " dojo.io.cookie.set('VCLNODES', nodes, 365, '/', '" . COOKIEDOMAIN . "');\n"; $rt .= " }\n"; $rt .= " }\n"; $rt .= " };\n"; } $rt .= " dojo.addOnLoad(function() {\n"; $rt .= " testJS();\n"; $rt .= " document.onmousemove = updateMouseXY;\n"; if ($actions['pages'][$mode] == 'privileges') { $rt .= " initPrivTree();\n"; } if ($mode == 'newRequest' || $mode == 'submitRequest') { $rt .= " if(dojo.byId('waittime'))\n"; $rt .= " dojo.byId('waittime').className = 'shown';\n"; } if ($refresh && $mode == 'viewRequests') { $rt .= " setTimeout(function() {if(! dojo.widget.byId('resStatusPane')) {AJdojoCreate('resStatusPane');}}, 1200);\n"; $rt .= " refresh_timer = setTimeout(resRefresh, 20000);\n"; } $rt .= " });\n"; $rt .= "</script>\n"; return $rt; }
function processUserPrefsInput($checks = 1) { global $submitErr, $submitErrMsg, $user; $return = array(); $defaultres = $user["width"] . 'x' . $user["height"]; $return["preferredname"] = processInputVar("preferredname", ARG_STRING, $user["preferredname"]); $return["resolution"] = processInputVar("resolution", ARG_STRING, $defaultres); $return["bpp"] = processInputVar("bpp", ARG_NUMERIC, $user["bpp"]); $return["audiomode"] = processInputVar("audiomode", ARG_STRING, $user["audiomode"]); $return["mapdrives"] = processInputVar("mapdrives", ARG_NUMERIC, $user["mapdrives"]); $return["mapprinters"] = processInputVar("mapprinters", ARG_NUMERIC, $user["mapprinters"]); $return["mapserial"] = processInputVar("mapserial", ARG_NUMERIC, $user["mapserial"]); $return["rdpport"] = processInputVar("rdpport", ARG_NUMERIC, 3389); if (!$checks) { return $return; } if (strlen($return["preferredname"]) > 25) { $submitErr |= PREFNAMEERR; $submitErrMsg[PREFNAMEERR] = i("Preferred name can only be up to 25 characters"); } if (!preg_match('/^[a-zA-Z ]*$/', $return["preferredname"])) { $submitErr |= PREFNAMEERR; $submitErrMsg[PREFNAMEERR] = i("Preferred name can only contain letters and spaces"); } if ($user['affiliation'] == 'Local' && array_key_exists('newpassword', $_POST)) { $return['newpassword'] = $_POST['newpassword']; $confirmpwd = $_POST['confirmpassword']; $curr = $_POST['currentpassword']; if (get_magic_quotes_gpc()) { $return['newpassword'] = stripslashes($return['newpassword']); $confirmpwd = stripslashes($confirmpwd); $curr = stripslashes($curr); } if (!empty($return['newpassword']) && !empty($confirmpwd) && !validateLocalAccount($user['unityid'], $curr)) { $submitErr |= LOCALPASSWORDERR; $submitErrMsg[LOCALPASSWORDERR] = i("Password incorrect"); } elseif (empty($return['newpassword']) && !empty($confirmpwd) || !empty($return['newpassword']) && empty($confirmpwd) || $return['newpassword'] != $confirmpwd) { $submitErr |= LOCALPASSWORDERR; $submitErrMsg[LOCALPASSWORDERR] = i("Passwords do not match"); } } if ($return['rdpport'] != $user['rdpport']) { $requests = getUserRequests('all'); $nochange = 0; foreach ($requests as $req) { if (preg_match('/^(3|8|24|25|26|27|28|29)$/', $req['currstateid']) || $req['currstateid'] == 14 && preg_match('/^(3|8|24|25|26|27|28|29)$/', $req['laststateid'])) { $nochange = 1; break; } } if ($nochange) { $submitErr |= RDPPORTERR; $submitErrMsg[RDPPORTERR] = i("RDP Port cannot be changed while you have active reservations"); } } if (!($submitErr & RDPPORTERR) && ($return['rdpport'] < 1024 || $return['rdpport'] > 65535)) { $submitErr |= RDPPORTERR; $submitErrMsg[RDPPORTERR] = i("RDP Port must be between 1024 and 65535"); } return $return; }
function processBlockRequestInput($checks = 1) { global $submitErr, $submitErrMsg, $mode, $user, $days; $return = array(); $return['blockname'] = getContinuationVar("blockname", processInputVar("blockname", ARG_STRING)); $return['imageid'] = getContinuationVar("imageid", processInputVar("imageid", ARG_NUMERIC)); $return['machinecnt'] = getContinuationVar("machinecnt", processInputVar("machinecnt", ARG_NUMERIC, 0)); $return['swhour'] = getContinuationVar("swhour", processInputVar("swhour", ARG_MULTINUMERIC)); $return['swminute'] = getContinuationVar("swminute", processInputVar("swminute", ARG_MULTINUMERIC)); $return['swmeridian'] = getContinuationVar("swmeridian", processInputVar("swmeridian", ARG_MULTISTRING)); $return['ewhour'] = getContinuationVar("ewhour", processInputVar("ewhour", ARG_MULTINUMERIC)); $return['ewminute'] = getContinuationVar("ewminute", processInputVar("ewminute", ARG_MULTINUMERIC)); $return['ewmeridian'] = getContinuationVar("ewmeridian", processInputVar("ewmeridian", ARG_MULTISTRING)); $return['smhour'] = getContinuationVar("smhour", processInputVar("smhour", ARG_MULTINUMERIC)); $return['smminute'] = getContinuationVar("smminute", processInputVar("smminute", ARG_MULTINUMERIC)); $return['smmeridian'] = getContinuationVar("smmeridian", processInputVar("smmeridian", ARG_MULTISTRING)); $return['emhour'] = getContinuationVar("emhour", processInputVar("emhour", ARG_MULTINUMERIC)); $return['emminute'] = getContinuationVar("emminute", processInputVar("emminute", ARG_MULTINUMERIC)); $return['emmeridian'] = getContinuationVar("emmeridian", processInputVar("emmeridian", ARG_MULTISTRING)); $return['slhour'] = getContinuationVar("slhour", processInputVar("slhour", ARG_MULTINUMERIC)); $return['slminute'] = getContinuationVar("slminute", processInputVar("slminute", ARG_MULTINUMERIC)); $return['slmeridian'] = getContinuationVar("slmeridian", processInputVar("slmeridian", ARG_MULTISTRING)); $return['elhour'] = getContinuationVar("elhour", processInputVar("elhour", ARG_MULTINUMERIC)); $return['elminute'] = getContinuationVar("elminute", processInputVar("elminute", ARG_MULTINUMERIC)); $return['elmeridian'] = getContinuationVar("elmeridian", processInputVar("elmeridian", ARG_MULTISTRING)); $return['weeknum'] = getContinuationVar("weeknum", processInputVar("weeknum", ARG_NUMERIC)); $return['day'] = getContinuationVar("day", processInputVar("day", ARG_NUMERIC)); $return['date'] = getContinuationVar("date", processInputVar("date", ARG_MULTISTRING)); $return['available'] = getContinuationVar("available", processInputVar("available", ARG_STRING, 'weekly')); $return['usergroupid'] = getContinuationVar("usergroupid", processInputVar("usergroupid", ARG_NUMERIC)); $return['admingroupid'] = getContinuationVar("admingroupid", processInputVar("admingroupid", ARG_NUMERIC)); $return['swdate'] = getContinuationVar("swdate", processInputVar("swdate", ARG_STRING)); $return['ewdate'] = getContinuationVar("ewdate", processInputVar("ewdate", ARG_STRING)); $return['smdate'] = getContinuationVar("smdate", processInputVar("smdate", ARG_STRING)); $return['emdate'] = getContinuationVar("emdate", processInputVar("emdate", ARG_STRING)); $return['wdays'] = getContinuationVar("wdays", processInputVar("wdays", ARG_MULTISTRING)); $return['state'] = getContinuationVar("state", 0); $return['blockRequestid'] = getContinuationVar("blockRequestid", processInputVar("blockRequestid", ARG_NUMERIC)); $return['wdayschecked'] = array(); foreach ($days as $day) { if (in_array($day, $return['wdays'])) { $return['wdayschecked'][$day] = 'checked'; } else { $return['wdayschecked'][$day] = ''; } } if (!$checks) { return $return; } if (!preg_match('/^([-a-zA-Z0-9\\. ]){3,80}$/', $return["blockname"])) { $submitErr |= BLOCKNAMEERR; $submitErrMsg[BLOCKNAMEERR] = "Name can only contain letters, numbers, spaces, dashes(-),<br>and periods(.) and can be from 3 to 80 characters long"; } $resources = getUserResources(array("imageAdmin", "imageCheckOut")); $resources["image"] = removeNoCheckout($resources["image"]); if (!in_array($return['imageid'], array_keys($resources['image']))) { $submitErr |= IMAGEIDERR; $submitErrMsg[IMAGEIDERR] = "The submitted image is invalid."; } if ($return['machinecnt'] < MIN_BLOCK_MACHINES) { $submitErr |= BLOCKCNTERR; $submitErrMsg[BLOCKCNTERR] = "You must request at least " . MIN_BLOCK_MACHINES . " machines"; } elseif ($return['machinecnt'] > MAX_BLOCK_MACHINES) { $submitErr |= BLOCKCNTERR; $submitErrMsg[BLOCKCNTERR] = "You cannot request more than " . MAX_BLOCK_MACHINES . " machines"; } // FIXME should we limit the course groups that show up? $groups = getUserGroups(); if (!array_key_exists($return['usergroupid'], $groups)) { $submitErr |= USERGROUPIDERR; $submitErrMsg[USERGROUPIDERR] = "The submitted user group is invalid."; } if (!array_key_exists($return['admingroupid'], $groups) && $return['admingroupid'] != 0) { $submitErr |= ADMINGROUPIDERR; $submitErrMsg[ADMINGROUPIDERR] = "The submitted user group is invalid."; } if ($return['available'] == 'weekly') { $keys = array('1' => 'swhour', '2' => 'ewhour', '3' => 'swminute', '4' => 'ewminute', '5' => 'swmeridian', '6' => 'ewmeridian', '7' => 'swdate', '8' => 'ewdate'); // check days of week foreach ($return['wdays'] as $index => $day) { if (!in_array($day, $days)) { unset($return['wdays'][$index]); } } /*foreach($days as $day) { if(in_array($day, $return['wdays'])) $return['wdayschecked'][$day] = 'checked'; }*/ if (!count($return['wdays'])) { $submitErr |= STARTDAYERR; $submitErrMsg[STARTDAYERR] = "You must select at least one day of the week"; } } elseif ($return['available'] == 'monthly') { $keys = array('1' => 'smhour', '2' => 'emhour', '3' => 'smminute', '4' => 'emminute', '5' => 'smmeridian', '6' => 'emmeridian', '7' => 'smdate', '8' => 'emdate'); // check weeknum if ($return['weeknum'] < 1 || $return['weeknum'] > 5) { $submitErr |= WEEKNUMERR; $submitErrMsg[WEEKNUMERR] = "Invalid week of the month submitted"; } // check day if ($return['day'] < 1 || $return['day'] > 7) { $submitErr |= DAYERR; $submitErrMsg[DAYERR] = "Invalid day of the week submitted"; } } elseif ($return['available'] == 'list') { $keys = array('1' => 'slhour', '2' => 'elhour', '3' => 'slminute', '4' => 'elminute', '5' => 'slmeridian', '6' => 'elmeridian'); } // check each timeslot for ($i = 0; $i < 4; $i++) { $submitErrMsg[STARTHOURERR][$i] = ""; $submitErrMsg[ENDHOURERR][$i] = ""; // start hour if ($return[$keys[1]][$i] < 1 || $return[$keys[1]][$i] > 12) { $submitErr |= STARTHOURERR; $submitErrMsg[STARTHOURERR][$i] = "The start hour must be between 1 and 12."; } // end hour if ($return[$keys[2]][$i] < 1 || $return[$keys[2]][$i] > 12) { $submitErr |= ENDHOURERR; $submitErrMsg[ENDHOURERR][$i] = " The end hour must be between 1 and 12."; } // start minute if ($return[$keys[3]][$i] < 0 || $return[$keys[3]][$i] > 59) { $submitErr |= STARTHOURERR; // we reuse STARTHOURERR here, it overwrites the last one, but oh well $submitErrMsg[STARTHOURERR][$i] = "The start minute must be between 0 and 59."; } // end minute if ($return[$keys[4]][$i] < 0 || $return[$keys[4]][$i] > 59) { $submitErr |= ENDHOURERR; $submitErrMsg[ENDHOURERR][$i] = " The end minute must be between 0 and 59."; } // start meridian if ($return[$keys[5]][$i] != 'am' && $return[$keys[5]][$i] != 'pm') { $return[$keys[5]][$i] = 'pm'; // just set it to one of them } // end meridian if ($return[$keys[6]][$i] != 'am' && $return[$keys[6]][$i] != 'pm') { $return[$keys[6]][$i] = 'am'; // just set it to one of them } // check that start is before end $return['stime'][$i] = minuteOfDay2("{$return[$keys[1]][$i]}:{$return[$keys[3]][$i]} {$return[$keys[5]][$i]}"); $return['etime'][$i] = minuteOfDay2("{$return[$keys[2]][$i]}:{$return[$keys[4]][$i]} {$return[$keys[6]][$i]}"); if ($return['stime'][$i] > $return['etime'][$i]) { $submitErr |= STARTHOURERR; // we reuse STARTHOURERR here, it overwrites the last one, but oh well $submitErrMsg[STARTHOURERR][$i] = "The start time must be before the end time (or be equal to ignore this slot)"; } } if ($return['available'] == 'weekly' || $return['available'] == 'monthly') { // check that timeslots do not overlap if (!($submitErr & STARTHOURERR) && !($submitErr & ENDHOURERR)) { for ($i = 0; $i < 4; $i++) { for ($j = $i + 1; $j < 4; $j++) { if ($return['etime'][$i] > $return['stime'][$j] && $return['stime'][$i] < $return['etime'][$j]) { $submitErr |= STARTHOURERR; $submitErrMsg[STARTHOURERR][$i] = "This timeslot overlaps with Slot" . ($j + 1); } } } } // check that start date is valid $startarr = split('/', $return[$keys[7]]); if (!preg_match('/^((\\d){1,2})\\/((\\d){1,2})\\/(\\d){2}$/', $return[$keys[7]])) { $submitErr |= STARTDATEERR; $submitErrMsg[STARTDATEERR] = "The start date must be in the form mm/dd/yy."; } elseif (!checkdate($startarr[0], $startarr[1], $startarr[2])) { $submitErr |= STARTDATEERR; $submitErrMsg[STARTDATEERR] = "This is an invalid date."; } elseif (datetimeToUnix("{$startarr[2]}-{$startarr[0]}-{$startarr[1]} 23:59:59") < time()) { $submitErr |= STARTDATEERR; $submitErrMsg[STARTDATEERR] = "The start date must be today or later."; } // check that end date is valid $endarr = split('/', $return[$keys[8]]); if (!preg_match('/^((\\d){1,2})\\/((\\d){1,2})\\/(\\d){2}$/', $return[$keys[8]])) { $submitErr |= ENDDATEERR; $submitErrMsg[ENDDATEERR] = "The end date must be in the form mm/dd/yy."; } elseif (!checkdate($endarr[0], $endarr[1], $endarr[2])) { $submitErr |= ENDDATEERR; $submitErrMsg[ENDDATEERR] = "This is an invalid date."; } elseif (datetimeToUnix("{$startarr[2]}-{$startarr[0]}-{$startarr[1]} 00:00:00") > datetimeToUnix("{$endarr[2]}-{$endarr[0]}-{$endarr[1]} 00:00:00")) { $submitErr |= ENDDATEERR; $submitErrMsg[ENDDATEERR] = "The end date must be later than the start date."; } } elseif ($return['available'] == 'list') { if (!($submitErr & STARTHOURERR) && !($submitErr & ENDHOURERR)) { // check date[1-n] for ($i = 0; $i < 4; $i++) { $submitErrMsg[STARTDATEERR][$i] = ""; if ($return['stime'][$i] == $return['etime'][$i]) { continue; } $submitErrMsg[STARTDATEERR][$i] = ""; $datearr = split('/', $return['date'][$i]); if (!preg_match('/^((\\d){1,2})\\/((\\d){1,2})\\/(\\d){2}$/', $return['date'][$i])) { $submitErr |= STARTDATEERR; $submitErrMsg[STARTDATEERR][$i] = "The date must be in the form mm/dd/yy."; } elseif (!checkdate($datearr[0], $datearr[1], $datearr[2])) { $submitErr |= STARTDATEERR; $submitErrMsg[STARTDATEERR][$i] = "Invalid date submitted."; } elseif (datetimeToUnix("{$datearr[2]}-{$datearr[0]}-{$datearr[1]} 23:59:59") < time()) { $submitErr |= STARTDATEERR; $submitErrMsg[STARTDATEERR][$i] = "The date must be today or later."; } } } } if (0) { # FIXME $submitErr |= AVAILABLEERR; $submitErrMsg[AVAILABLEERR] = "The submitted availability selection is invalid."; } return $return; }
function AJupdateAllSettings() { if (!checkUserHasPerm('Site Configuration (global)')) { $arr = array('status' => 'noaccess', 'msg' => i('You do not have access to modify the submitted settings.')); sendJSON($arr); return; } switch ($this->type) { case 'numeric': $newval = processInputVar('newval', ARG_NUMERIC); if ($newval < $this->minval || $newval > $this->maxval) { $arr = array('status' => 'failed', 'msgid' => "{$this->domidbase}msg", 'btn' => "{$this->domidbase}btn", 'errmsg' => i("Invalid value submitted")); sendJSON($arr); return; } break; case 'boolean': $newval = processInputVar('newval', ARG_NUMERIC); if ($newval !== '0' && $newval !== '1') { $arr = array('status' => 'failed', 'msgid' => "{$this->domidbase}msg", 'btn' => "{$this->domidbase}btn", 'errmsg' => i("Invalid value submitted")); sendJSON($arr); return; } break; case 'text': # TODO $newval = processInputVar('newval', ARG_STRING); $arr = array('status' => 'failed', 'msgid' => "{$this->domidbase}msg", 'btn' => "{$this->domidbase}btn", 'errmsg' => i("unsupported type")); sendJSON($arr); return; case 'textarea': $newval = processInputVar('newval', ARG_STRING); if (!$this->validateValue($newval)) { $arr = array('status' => 'failed', 'msgid' => "{$this->domidbase}msg", 'btn' => "{$this->domidbase}btn", 'errmsg' => i("Invalid value submitted")); if (isset($this->invalidvaluemsg)) { $arr['errmsg'] = $this->invalidvaluemsg; } sendJSON($arr); return; } break; default: $arr = array('status' => 'failed', 'msgid' => "{$this->domidbase}msg", 'btn' => "{$this->domidbase}btn", 'errmsg' => i("Invalid value submitted")); sendJSON($arr); return; } setVariable($this->key, $newval, 'none'); $arr = array('status' => 'success', 'msgid' => "{$this->domidbase}msg", 'btn' => "{$this->domidbase}btn", 'msg' => $this->updatemsg); sendJSON($arr); }
function viewStatistics() { global $submitErr, $submitErrMsg, $user, $viewmode; define("30MIN", 1800); define("1HOUR", 3600); define("2HOURS", 7200); define("4HOURS", 14400); $month1 = processInputVar("month1", ARG_NUMERIC); $day1 = processInputVar("day1", ARG_NUMERIC); $year1 = processInputVar("year1", ARG_NUMERIC); $month2 = processInputVar("month2", ARG_NUMERIC); $day2 = processInputVar("day2", ARG_NUMERIC); $year2 = processInputVar("year2", ARG_NUMERIC); $affilid = processInputVar("affilid", ARG_NUMERIC, $user['affiliationid']); $affils = getAffiliations(); if ($viewmode < ADMIN_FULL || $affilid != 0 && !array_key_exists($affilid, $affils)) { $affilid = $user['affiliationid']; } $start = "{$year1}-{$month1}-{$day1} 00:00:00"; $end = "{$year2}-{$month2}-{$day2} 23:59:59"; if (!checkdate($month1, $day1, $year1)) { $submitErr |= STARTERR; $submitErrMsg[STARTERR] = "The selected start date is not valid. Please " . "select a valid date.<br>\n"; } if (!checkdate($month2, $day2, $year2)) { $submitErr |= ENDERR; $submitErrMsg[ENDERR] = "The selected end date is not valid. Please " . "select a valid date.<br>\n"; } if (datetimeToUnix($start) > datetimeToUnix($end)) { $submitErr |= ORDERERR; $submitErrMsg[ORDERERR] = "The selected end date is before the selected " . "start date. Please select an end date equal " . "to or greater than the start date.<br>\n"; } if ($submitErr) { selectStatistics(); return; } $timestart = microtime(1); print "<H2>Statistic Information</H2>\n"; print "<H3>Reservation information between {$month1}/{$day1}/{$year1} and "; print "{$month2}/{$day2}/{$year2}:\n"; print "</H3>\n"; $reloadid = getUserlistID('vclreload@Local'); $query = "SELECT l.userid, " . "l.nowfuture, " . "UNIX_TIMESTAMP(l.start) AS start, " . "(UNIX_TIMESTAMP(l.loaded) - UNIX_TIMESTAMP(l.start)) AS loadtime, " . "UNIX_TIMESTAMP(l.finalend) AS finalend, " . "l.wasavailable, " . "l.ending, " . "i.prettyname, " . "o.prettyname AS OS " . "FROM log l, " . "image i, " . "user u, " . "OS o " . "WHERE l.start >= '{$start}' AND " . "l.finalend <= '{$end}' AND " . "i.id = l.imageid AND " . "i.OSid = o.id AND " . "l.userid != {$reloadid} AND "; if ($affilid != 0) { $query .= "u.affiliationid = {$affilid} AND "; } $query .= "l.userid = u.id " . "ORDER BY i.prettyname"; $qh = doQuery($query, 275); $totalreservations = 0; $users = array(); $nows = 0; $futures = 0; $notavailable = 0; $loadtimes = array("2less" => 0, "2more" => 0); $ending = array("deleted" => 0, "released" => 0, "failed" => 0, "noack" => 0, "nologin" => 0, "timeout" => 0, "EOR" => 0, "none" => 0); $imagecount = array(); $imageusers = array(); $imagehours = array(); $imageload2less = array(); $imageload2more = array(); $lengths = array("30min" => 0, "1hour" => 0, "2hours" => 0, "4hours" => 0, "4hrsplus" => 0); $totalhours = 0; $osusers = array(); while ($row = mysql_fetch_assoc($qh)) { if (!array_key_exists($row["prettyname"], $imageload2less)) { $imageload2less[$row["prettyname"]] = 0; } if (!array_key_exists($row["prettyname"], $imageload2more)) { $imageload2more[$row["prettyname"]] = 0; } # notavailable if ($row["wasavailable"] == 0) { $notavailable++; } else { $totalreservations++; # load times if ($row['loadtime'] < 120) { $loadtimes['2less']++; # imageload2less $imageload2less[$row['prettyname']]++; } else { $loadtimes['2more']++; # imageload2more $imageload2more[$row['prettyname']]++; } } # users $users[$row['userid']] = 1; # nowfuture if ($row["nowfuture"] == "now") { $nows++; } else { $futures++; } # ending $ending[$row["ending"]]++; # imagecount if (!array_key_exists($row["prettyname"], $imagecount)) { $imagecount[$row["prettyname"]] = 0; } $imagecount[$row["prettyname"]]++; # imageusers if (!array_key_exists($row["prettyname"], $imageusers)) { $imageusers[$row["prettyname"]] = array(); } $imageusers[$row['prettyname']][$row['userid']] = 1; # lengths $length = $row["finalend"] - $row["start"]; if ($length <= 1800) { $lengths["30min"]++; } elseif ($length <= 3600) { $lengths["1hour"]++; } elseif ($length <= 7200) { $lengths["2hours"]++; } elseif ($length <= 14400) { $lengths["4hours"]++; } else { $lengths["4hrsplus"]++; } # imagehours if (!array_key_exists($row["prettyname"], $imagehours)) { $imagehours[$row["prettyname"]] = 0; } $imagehours[$row["prettyname"]] += $length / 3600; # total hours $totalhours += $length / 3600; # osusers if (!array_key_exists($row["OS"], $osusers)) { $osusers[$row["OS"]] = array(); } $osusers[$row['OS']][$row['userid']] = 1; } print "<DIV align=center>\n"; print "<TABLE>\n"; print " <TR>\n"; print " <TH align=right>Total Reservations:</TH>\n"; print " <TD>{$totalreservations}</TD>\n"; print " </TR>\n"; print " <TR>\n"; print " <TH align=right>Total Hours Used:</TH>\n"; print " <TD>" . (int) $totalhours . "</TD>\n"; print " </TR>\n"; print " <TR>\n"; print " <TH align=right>\"Now\" Reservations:</TH>\n"; print " <TD>{$nows}</TD>\n"; print " </TR>\n"; print " <TR>\n"; print " <TH align=right>\"Later\" Reservations:</TH>\n"; print " <TD>{$futures}</TD>\n"; print " </TR>\n"; print " <TR>\n"; print " <TH align=right>Unavailable:</TH>\n"; print " <TD>{$notavailable}</TD>\n"; print " </TR>\n"; if ($viewmode >= ADMIN_FULL) { print " <TR>\n"; print " <TH align=right>Load times < 2 minutes:</TH>\n"; print " <TD>{$loadtimes['2less']}</TD>\n"; print " </TR>\n"; print " <TR>\n"; print " <TH align=right>Load times >= 2 minutes:</TH>\n"; print " <TD>{$loadtimes['2more']}</TD>\n"; print " </TR>\n"; } print " <TR>\n"; print " <TH align=right>Total Unique Users:</TH>\n"; print " <TD>" . count($users) . "</TD>\n"; print " </TR>\n"; foreach (array_keys($osusers) as $key) { print " <TR>\n"; print " <TH align=right>Unique Users of {$key}:</TH>\n"; print " <TD>" . count($osusers[$key]) . "</TD>\n"; print " </TR>\n"; } print "</TABLE>\n"; print "<TABLE>\n"; print " <TR>\n"; print " <TD></TD>\n"; print " <TH>Reservations</TH>\n"; print " <TH>Unique Users</TH>\n"; print " <TH>Hours Used</TH>\n"; if ($viewmode >= ADMIN_FULL) { print " <TH>< 2 min load time</TH>\n"; print " <TH>>= 2 min load time</TH>\n"; } print " </TR>\n"; foreach ($imagecount as $key => $value) { print " <TR>\n"; print " <TH align=right>{$key}:</TH>\n"; print " <TD align=center>{$value}</TD>\n"; print " <TD align=center>" . count($imageusers[$key]) . "</TD>\n"; if ((int) $imagehours[$key] == 0) { print " <TD align=center>1</TD>\n"; } else { print " <TD align=center>" . (int) $imagehours[$key] . "</TD>\n"; } if ($viewmode >= ADMIN_FULL) { print " <TD align=center>{$imageload2less[$key]}</TD>\n"; print " <TD align=center>{$imageload2more[$key]}</TD>\n"; } print " </TR>\n"; } print "</TABLE>\n"; print "<H3>Durations:</H3>\n"; print "<TABLE>\n"; print " <TR>\n"; print " <TH align=right>0 - 30 Min:</TH>\n"; print " <TD>" . $lengths["30min"] . "</TD>\n"; print " </TR>\n"; print " <TR>\n"; print " <TH align=right>30 Min - 1 Hour:</TH>\n"; print " <TD>" . $lengths["1hour"] . "</TD>\n"; print " </TR>\n"; print " <TR>\n"; print " <TH align=right>1 Hour - 2 Hours:</TH>\n"; print " <TD>" . $lengths["2hours"] . "</TD>\n"; print " </TR>\n"; print " <TR>\n"; print " <TH align=right>2 Hours - 4 Hours:</TH>\n"; print " <TD>" . $lengths["4hours"] . "</TD>\n"; print " </TR>\n"; print " <TR>\n"; print " <TH align=right>> 4 Hours:</TH>\n"; print " <TD>" . $lengths["4hrsplus"] . "</TD>\n"; print " </TR>\n"; print "</TABLE>\n"; print "<H3>Ending information:</H3>\n"; print "<TABLE>\n"; print " <TR>\n"; print " <TH align=right>Deleted:</TH>\n"; print " <TD>" . $ending["deleted"] . "</TD>\n"; print " <TD rowspan=7><img src=\"images/blank.gif\" width=5></TD>\n"; print " <TD>(Future reservation deleted before start time reached)</TD>\n"; print " </TR>\n"; print " <TR>\n"; print " <TH align=right>Released:</TH>\n"; print " <TD>" . $ending["released"] . "</TD>\n"; print " <TD>(Reservation released before end time reached)</TD>\n"; print " </TR>\n"; print " <TR>\n"; print " <TH align=right>Not Acknowledged:</TH>\n"; print " <TD>" . $ending["noack"] . "</TD>\n"; print " <TD>(\"Connect!\" button never clicked)</TD>\n"; print " </TR>\n"; print " <TR>\n"; print " <TH align=right>No Login:</TH>\n"; print " <TD>" . $ending["nologin"] . "</TD>\n"; print " <TD>(User never logged in)</TD>\n"; print " </TR>\n"; print " <TR>\n"; print " <TH align=right>End of Reservation:</TH>\n"; print " <TD>" . $ending["EOR"] . "</TD>\n"; print " <TD>(End of reservation reached)</TD>\n"; print " </TR>\n"; print " <TR>\n"; print " <TH align=right>Timed Out:</TH>\n"; print " <TD>" . $ending["timeout"] . "</TD>\n"; print " <TD>(Disconnect and no reconnection within 15 minutes)</TD>\n"; print " </TR>\n"; print " <TR>\n"; print " <TH align=right>Failed:</TH>\n"; print " <TD>" . $ending["failed"] . "</TD>\n"; print " <TD>(Reserved computer failed to get prepared for user)</TD>\n"; print " </TR>\n"; print "</TABLE>\n"; print "<br>\n"; $unixstart = datetimeToUnix($start); $unixend = datetimeToUnix($end); $start = date('Y-m-d', $unixstart); $end = date('Y-m-d', $unixend); $cdata = array('start' => $start, 'end' => $end, 'affilid' => $affilid); print "<H2>Reservations by Day</H2>\n"; $cont = addContinuationsEntry('statgraphday', $cdata); print "<img src=" . BASEURL . SCRIPT . "?continuation={$cont}>"; print "<H2>Max Concurrent Reservations By Day</H2>\n"; if ($unixend - $unixstart > SECINMONTH) { print "(this graph only available for up to a month of data)<br>\n"; } else { $cont = addContinuationsEntry('statgraphdayconcuruser', $cdata); print "<img src=" . BASEURL . SCRIPT . "?continuation={$cont}>"; } print "<H2>Max Concurrent Blade Reservations By Day</H2>\n"; if ($unixend - $unixstart > SECINMONTH) { print "(this graph only available for up to a month of data)<br>\n"; } else { $cont = addContinuationsEntry('statgraphdayconcurblade', $cdata); print "<img src=" . BASEURL . SCRIPT . "?continuation={$cont}>"; } print "<H2>Reservations by Hour</H2>\n"; print "(Averaged over the time period)<br><br>\n"; $cont = addContinuationsEntry('statgraphhour', $cdata); print "<img src=" . BASEURL . SCRIPT . "?continuation={$cont}>"; print "</div>\n"; $endtime = microtime(1); $end = $endtime - $timestart; #print "running time: $endtime - $timestart = $end<br>\n"; }
function AJdeleteRevisions() { $revids = getContinuationVar('revids'); $imageid = getContinuationVar('imageid'); $checkedids = processInputVar('checkedids', ARG_STRING); $ids = explode(',', $checkedids); foreach ($ids as $id) { if (!is_numeric($id) || !in_array($id, $revids)) { header('Content-Type: text/json-comment-filtered; charset=utf-8'); print '/*{"items":' . json_encode(array()) . '}*/'; return; } } $query = "UPDATE imagerevision " . "SET deleted = 1 " . "WHERE id IN ({$checkedids}) " . "AND production != 1"; doQuery($query, 101); $html = getRevisionHTML($imageid); $arr = array('html' => $html); header('Content-Type: text/json-comment-filtered; charset=utf-8'); print '/*{"items":' . json_encode($arr) . '}*/'; }
function AJaddRemGroupResource() { $newids = getContinuationVar('newids'); if (is_null($newids)) { $rscid = processInputVar('id', ARG_NUMERIC); $resources = getUserResources(array($this->restype . "Admin"), array("manageGroup")); if (!array_key_exists($rscid, $resources[$this->restype])) { $arr = array('status' => 'noaccess'); sendJSON($arr); return; } } $groups = getUserResources(array($this->restype . "Admin"), array("manageGroup"), 1); $tmp = processInputVar('listids', ARG_STRING); $tmp = explode(',', $tmp); $groupids = array(); foreach ($tmp as $id) { if (!is_numeric($id)) { continue; } if (!array_key_exists($id, $groups[$this->restype])) { $arr = array('status' => 'noaccess'); sendJSON($arr); return; } $groupids[] = $id; } $args = $this->defaultGetDataArgs; if (is_null($newids)) { $args['rscid'] = $rscid; } $resdata = $this->getData($args); $mode = getContinuationVar('mode'); if ($mode == 'add') { $adds = array(); if (is_null($newids)) { foreach ($groupids as $id) { $adds[] = "({$resdata[$rscid]['resourceid']}, {$id})"; } } else { foreach ($newids as $newrscid) { foreach ($groupids as $id) { $adds[] = "({$resdata[$newrscid]['resourceid']}, {$id})"; } } } $query = "INSERT IGNORE INTO resourcegroupmembers " . "(resourceid, resourcegroupid) VALUES "; $query .= implode(',', $adds); doQuery($query); } else { $rems = implode(',', $groupids); if (is_null($newids)) { $query = "DELETE FROM resourcegroupmembers " . "WHERE resourceid = {$resdata[$rscid]['resourceid']} AND " . "resourcegroupid IN ({$rems})"; } else { $allrscids = array(); foreach ($newids as $newrscid) { $allrscids[] = $resdata[$newrscid]['resourceid']; } $allrscids = implode(',', $allrscids); $query = "DELETE FROM resourcegroupmembers " . "WHERE resourceid IN ({$allrscids}) AND " . "resourcegroupid IN ({$rems})"; } doQuery($query); } $_SESSION['userresources'] = array(); $regids = "^" . implode('$|^', $groupids) . "\$"; $arr = array('status' => 'success', 'regids' => $regids, 'inselobj' => 'ingroups', 'outselobj' => 'outgroups'); sendJSON($arr); }
function AJdelProfile() { global $viewmode; if ($viewmode != ADMIN_DEVELOPER) { $arr = array('failed' => 'noaccess'); header('Content-Type: text/json-comment-filtered; charset=utf-8'); print '/*{"items":' . json_encode($arr) . '}*/'; return; } $profileid = processInputVar('profileid', ARG_NUMERIC); $query = "DELETE FROM vmprofile WHERE id = {$profileid}"; doQuery($query, 101); header('Content-Type: text/json-comment-filtered; charset=utf-8'); $arr = array('SUCCESS'); print '/*{"items":' . json_encode($arr) . '}*/'; }
function processSiteMaintenanceInput() { $start = processInputVar('start', ARG_NUMERIC); $end = processInputVar('end', ARG_NUMERIC); $data['hoursahead'] = processInputVar('hoursahead', ARG_NUMERIC); $data['allowreservations'] = processInputVar('allowreservations', ARG_NUMERIC); $data['reason'] = processInputVar('reason', ARG_STRING); $data['usermessage'] = processInputVar('usermessage', ARG_STRING); $err = 0; $now = time(); $data['startdt'] = numdatetimeToDatetime($start . '00'); $data['startts'] = datetimeToUnix($data['startdt']); $data['enddt'] = numdatetimeToDatetime($end . '00'); $data['endts'] = datetimeToUnix($data['enddt']); $reg = "/^[-0-9a-zA-Z\\.,\\?:;_@!#\\(\\)\n ]+\$/"; if (!preg_match($reg, $data['reason'])) { $errmsg = "Reason can only contain letters, numbers, spaces,\\nand these characters: . , ? : ; - _ @ ! # ( )"; $err = 1; } if (!preg_match($reg, $data['usermessage'])) { $errmsg = "User Message can only contain letters, numbers, spaces,\\nand these characters: . , ? : ; - _ @ ! # ( )"; $err = 1; } if (!$err && $data['startts'] < $now) { $errmsg = 'The start time and date must be later than the current time.'; $err = 1; } if (!$err && $data['endts'] <= $data['startts']) { $errmsg = 'The end time and date must be later than the start time and date.'; $err = 1; } if (!$err && $data['hoursahead'] < 1) { $errmsg = 'Inform Hours Ahead must be at least 1.'; $err = 1; } if (!$err && $data['hoursahead'] > 65535) { $errmsg = 'Inform Hours Ahead must be less than 65536.'; $err = 1; } if (!$err && ($data['allowreservations'] != 0 && $data['allowreservations'] != 1)) { $data['allowreservations'] = 0; } if (!$err && !preg_match('/[A-Za-z]{2,}/', $data['usermessage'])) { $errmsg = 'Something must be filled in for the User Message.'; $err = 1; } if ($err) { print "alert('{$errmsg}');"; } $data['err'] = $err; return $data; }
function getDashboardAffilID() { global $user; if (!checkUserHasPerm('View Dashboard (global)')) { return $user['affiliationid']; } $affilid = processInputVar('affilid', ARG_NUMERIC); $affils = getAffiliations(); if ($affilid != 0 && !array_key_exists($affilid, $affils)) { return 0; } return $affilid; }
function processMappingInput($maptypes) { # configid $return['configid'] = processInputVar('configid', ARG_NUMERIC); $tmp = getUserResources(array("configAdmin"), array("administer")); # TODO is this the criteria we want for which configs can be selected? if (!array_key_exists($return['configid'], $tmp['config'])) { $this->errmsg = "Invalid config submitted"; return 0; } # maptypeid $return['maptypeid'] = processInputVar('maptypeid', ARG_NUMERIC); if (!array_key_exists($return['maptypeid'], $maptypes)) { $this->errmsg = "Invalid map type submitted"; return 0; } # subid $return['subid'] = processInputVar('subid', ARG_NUMERIC); if ($maptypes[$return['maptypeid']] == 'Image') { $tmp = getUserResources(array("imageAdmin"), array("administer")); # TODO is this the criteria we want for which images can be selected? if (!array_key_exists($return['subid'], $tmp['image'])) { $this->errmsg = "Invalid image submitted"; return 0; } $return['mapto'] = $tmp['image'][$return['subid']]; } elseif ($maptypes[$return['maptypeid']] == 'OS Type') { $ostypes = getOStypes(); if (!array_key_exists($return['subid'], $ostypes)) { $this->errmsg = "Invalid os type submitted"; return 0; } $return['mapto'] = $ostypes[$return['subid']]; } elseif ($maptypes[$return['maptypeid']] == 'OS') { $oses = getOSList(); if (!array_key_exists($return['subid'], $oses)) { $this->errmsg = "Invalid OS submitted"; return 0; } $return['mapto'] = $oses[$return['subid']]['prettyname']; } elseif ($maptypes[$return['maptypeid']] == 'Config') { $tmp = getUserResources(array("configAdmin"), array("administer")); # TODO is this the criteria we want for which configs can be selected? $configs = $this->getUserConfigsNoCluster($tmp['config']); if (!array_key_exists($return['subid'], $configs)) { $this->errmsg = "Invalid config submitted"; return 0; } $return['mapto'] = $configs[$return['subid']]; } elseif ($maptypes[$return['maptypeid']] == 'Subimage') { $configsubimages = getConfigSubimages($tmp['config']); if (!array_key_exists($return['subid'], $configsubimages)) { $this->errmsg = "Invalid cluster submitted"; return 0; } $return['mapto'] = $configsubimages[$return['subid']]; } elseif ($maptypes[$return['maptypeid']] == 'Management Node') { $managementnodes = getManagementNodes(); if (!array_key_exists($return['subid'], $managementnodes)) { $this->errmsg = "Invalid managementnode submitted"; return 0; } $return['mapto'] = $managementnodes[$return['subid']]['hostname']; } # check for creating a loop - cannot have a parent that maps to # submitted config if ($maptypes[$return['maptypeid']] == 'Config' || $maptypes[$return['maptypeid']] == 'Subimage') { $rc = $this->mappingLoopCheck($maptypes[$return['maptypeid']], $return['configid'], $return['subid']); if ($rc != '') { $this->errmsg = "This mapping would create a loop. {$rc} is a<br>" . "parent/grandparent and is mapped to the selected config."; return 0; } } # affiliationid $return['affiliationid'] = processInputVar('affiliationid', ARG_NUMERIC); $affils = getAffiliations(); if (!array_key_exists($return['affiliationid'], $affils)) { $this->errmsg = "Invalid affiliation submitted"; return 0; } # stageid $return['stageid'] = processInputVar('stageid', ARG_NUMERIC); $stages = $this->getConfigMapStages(); if (!array_key_exists($return['stageid'], $stages)) { $this->errmsg = "Invalid stage submitted"; return 0; } # duplicate check # TODO do we also need to check the disabled field? $configmapid = getContinuationVar('configmapid', 0); $query = "SELECT id " . "FROM configmap " . "WHERE configid = {$return['configid']} AND " . "configmaptypeid = {$return['maptypeid']} AND " . "subid = {$return['subid']} AND " . "affiliationid = {$return['affiliationid']} AND " . "configstageid = {$return['stageid']} AND " . "id != {$configmapid}"; $qh = doQuery($query); if (mysql_num_rows($qh)) { $this->errmsg = "The specified mapping already exists."; return 0; } return $return; }
function AJeditResource() { $rscid = processInputVar('rscid', ARG_NUMERIC); $resources = getUserResources(array($this->restype . 'Admin'), array('administer'), 0, 1); if (!array_key_exists($rscid, $resources[$this->restype])) { $ret = array('status' => 'noaccess'); sendJSON($ret); return; } $args = $this->defaultGetDataArgs; $args['rscid'] = $rscid; $tmp = $this->getData($args); $data = $tmp[$rscid]; $cdata = $this->basecdata; $cdata['rscid'] = $rscid; $cdata['olddata'] = $data; # save continuation $cont = addContinuationsEntry('AJsaveResource', $cdata); $ret = $this->jsondata; $ret['title'] = "Edit {$this->restypename}"; $ret['cont'] = $cont; $ret['resid'] = $rscid; $ret['data'] = $data; $ret['status'] = 'success'; sendJSON($ret); }
function AJviewBlockAllocationUsage() { $blockid = processInputVar('blockid', ARG_NUMERIC); $allowedblockids = getContinuationVar('blockids'); if (!in_array($blockid, $allowedblockids)) { sendJSON(array('status' => 'failed', 'message' => 'noaccess')); return; } $query = "SELECT COUNT(s.computerid) AS used, " . "br.numMachines AS allocated, " . "s.blockStart " . "FROM blockRequest br " . "LEFT JOIN sublog s ON (s.blockRequestid = br.id) " . "WHERE br.id = {$blockid} " . "GROUP BY s.blockRequestid, s.blockStart, s.blockEnd " . "ORDER BY s.blockStart"; $qh = doQuery($query); $usage = array(); $first = 1; $firststart = ''; $laststart = ''; while ($row = mysql_fetch_assoc($qh)) { if ($first && !is_null($row['blockStart'])) { $firststart = datetimeToUnix($row['blockStart']); $first = 0; } elseif (!is_null($row['blockStart'])) { $laststart = datetimeToUnix($row['blockStart']); } if (is_null($row['blockStart'])) { continue; } $percent = (int) ($row['used'] / $row['allocated'] * 100); $startts = datetimeToUnix($row['blockStart']); $usage[$startts] = array('percent' => $percent, 'label' => $row['blockStart']); } if ($firststart == '') { sendJSON(array('status' => 'empty', 'message' => 'nousage')); return; } $data = array('points' => array(), 'xlabels' => array()); $cnt = 0; $tmp = localtime($firststart, 1); $firstisdst = 0; if ($tmp['tm_isdst']) { $firstisdst = 1; } for ($i = $firststart; $i <= $laststart + 3600; $i += SECINDAY) { $tmp = localtime($i, 1); $time = $i; if ($firstisdst && !$tmp['tm_isdst']) { $time += 3600; } if (!$firstisdst && $tmp['tm_isdst']) { $time -= 3600; } $cnt++; $label = date('m/d g:i a', $time); if (array_key_exists($time, $usage)) { $data['points'][] = array('y' => $usage[$time]['percent'], 'tooltip' => "{$label}: " . $usage[$time]['percent'] . " %"); } else { $data['points'][] = array('y' => 0, 'tooltip' => "{$label}: 0"); } $data['xlabels'][] = array('value' => $cnt, 'text' => $label); } sendJSON(array('status' => 'success', 'usage' => $data)); }
function getSelectLanguagePulldown() { global $locale, $user, $remoteIP, $mode, $authMechs; $tmp = explode('/', $_SERVER['SCRIPT_FILENAME']); array_pop($tmp); array_push($tmp, 'locale'); $locales = getFSlocales(); if (count($locales) < 1) { return ''; } if (!is_array($user)) { $user['id'] = 0; } $rt = "<form name=\"localeform\" id=\"localeform\" action=\"" . BASEURL . SCRIPT . "\" method=post>\n"; $rt .= "<select name=\"continuation\" onChange=\"document.localeform.submit();\">\n"; $cdata = array('IP' => $remoteIP, 'oldmode' => $mode); if ($mode == 'selectauth') { $type = processInputVar('authtype', ARG_STRING); if (!empty($type) && array_key_exists($type, $authMechs)) { $cdata['authtype'] = $type; } } foreach ($locales as $dir => $lang) { $cdata['locale'] = $dir; $tmp = explode('/', $dir); $testlocale = array_pop($tmp); $cont = addContinuationsEntry('changeLocale', $cdata, 86400); if ($locale == $testlocale) { $rt .= "<option value=\"{$cont}\" selected>{$lang}</option>\n"; } else { $rt .= "<option value=\"{$cont}\">{$lang}</option>\n"; } } $rt .= "</select>\n"; $rt .= "</form> \n"; return $rt; }
function submitLogin() { global $authMechs; $authtype = getContinuationVar("authtype", processInputVar('authtype', ARG_STRING)); if (!array_key_exists($authtype, $authMechs)) { // FIXME - hackerish dbDisconnect(); exit; } if (isset($_GET['userid'])) { unset($_GET['userid']); } $userid = processInputVar('userid', ARG_STRING, ''); $passwd = $_POST['password']; if (empty($userid) || empty($passwd)) { selectAuth(); return; } if (get_magic_quotes_gpc()) { $userid = stripslashes($userid); $passwd = stripslashes($passwd); } if ($authMechs[$authtype]['type'] == 'ldap') { ldapLogin($authtype, $userid, $passwd); } elseif ($authMechs[$authtype]['type'] == 'local') { localLogin($userid, $passwd, $authtype); } else { selectAuth(); } }
function AJremGroupFromComp() { $compid = processInputVar('id', ARG_NUMERIC); $resources = getUserResources(array("computerAdmin"), array("manageGroup")); if (!array_key_exists($compid, $resources['computer'])) { $arr = array('groups' => array(), 'addrem' => 0); header('Content-Type: text/json-comment-filtered; charset=utf-8'); print '/*{"items":' . json_encode($arr) . '}*/'; return; } $groups = getUserResources(array("computerAdmin"), array("manageGroup"), 1); $tmp = processInputVar('listids', ARG_STRING); $tmp = explode(',', $tmp); $groupids = array(); foreach ($tmp as $id) { if (!is_numeric($id)) { continue; } if (!array_key_exists($id, $groups['computer'])) { $arr = array('groups' => array(), 'addrem' => 0); header('Content-Type: text/json-comment-filtered; charset=utf-8'); print '/*{"items":' . json_encode($arr) . '}*/'; return; } $groupids[] = $id; } $comp = getComputers(0, $compid); foreach ($groupids as $id) { $query = "DELETE FROM resourcegroupmembers " . "WHERE resourceid = {$comp[$compid]['resourceid']} AND " . "resourcegroupid = {$id}"; doQuery($query, 288); } $_SESSION['userresources'] = array(); $arr = array('groups' => $groupids, 'addrem' => 0); header('Content-Type: text/json-comment-filtered; charset=utf-8'); print '/*{"items":' . json_encode($arr) . '}*/'; }