function ShowNodeHistory($node_id = null, $record = null, $count = 200, $showall = 0, $reverse = 0, $date = null, $IP = null, $mac = null, $node_opt = "") { global $TBSUEXEC_PATH; global $PROTOGENI; $atime = 0; $ftime = 0; $rtime = 0; $dtime = 0; $nodestr = ""; $arg = ""; $opt = "-ls -n " . escapeshellarg($count); if (!$showall) { $opt .= " -a"; } if ($reverse) { $opt .= " -r"; } if ($date) { $date = date("Y-m-d H:i:s", strtotime($date)); $opt .= " -d " . escapeshellarg($date); } elseif ($record) { $opt .= " -x " . escapeshellarg($record); } if ($node_id || $IP || $mac) { if ($IP) { $opt .= " -i " . escapeshellarg($IP); $nodestr = "<th>Node</th>"; } if ($mac) { $opt .= " -m " . escapeshellarg($mac); $nodestr = "<th>Node</th>"; } else { $arg = escapeshellarg($node_id); } } else { $opt .= " -A"; $node_id = ""; $nodestr = "<th>Node</th>"; # # When supplying a date, we want a summary of all nodes at that # point in time, not a listing. # if ($date) { $opt .= " -c"; } } if ($fp = popen("{$TBSUEXEC_PATH} nobody nobody " . " webnode_history {$opt} {$arg}", "r")) { if (!$showall) { $str = "Allocation"; } else { $str = ""; } if ($node_id == "") { echo "<center><b>\n {$str} History for All Nodes.\n </b></center>\n"; } else { $node_url = CreateURL("shownode", URLARG_NODEID, $node_id); echo "<center><b>\n {$str} History for Node <a href='{$node_url}'>{$node_id}</a>.\n </b></center>\n"; } # Keep track of history record bounds, for paging through. $max_history_id = 0; # Build up table contents ob_start(); $line = fgets($fp); while (!feof($fp)) { # # Formats: # nodeid REC tstamp duration uid pid eid # nodeid SUM alloctime freetime reloadtime downtime # $results = preg_split("/[\\s]+/", $line, 9, PREG_SPLIT_NO_EMPTY); $nodeid = $results[0]; $type = $results[1]; if ($type == "SUM") { # Save summary info for later $atime = $results[2]; $ftime = $results[3]; $rtime = $results[4]; $dtime = $results[5]; } elseif ($type == "REC") { $stamp = $results[2]; $datestr = date("Y-m-d H:i:s", $stamp); $duration = $results[3]; $durstr = ""; if ($duration >= 24 * 60 * 60) { $durstr = sprintf("%dd", $duration / (24 * 60 * 60)); $duration %= 24 * 60 * 60; } if ($duration >= 60 * 60) { $durstr = sprintf("%s%dh", $durstr, $duration / (60 * 60)); $duration %= 60 * 60; } if ($duration >= 60) { $durstr = sprintf("%s%dm", $durstr, $duration / 60); $duration %= 60; } $durstr = sprintf("%s%ds", $durstr, $duration); $uid = $results[4]; $pid = $results[5]; $thisid = intval($results[8]); if ($thisid >= $max_history_id) { $max_history_id = $thisid; } $slice = "--"; $expurl = null; if ($pid == "FREE") { $pid = "--"; $eid = "--"; $uid = "--"; } else { $eid = $results[6]; if ($results[7]) { $experiment = Experiment::Lookup($results[7]); $experiment_stats = ExperimentStats::Lookup($results[7]); if ($experiment_stats && $experiment_stats->slice_uuid()) { $url = CreateURL("genihistory", "slice_uuid", $experiment_stats->slice_uuid()); $slice = "<a href='{$url}'>" . "<img src=\"greenball.gif\" border=0></a>"; } if ($experiment) { $expurl = CreateURL("showexp", URLARG_EID, $experiment->idx()); } else { $expurl = CreateURL("showexpstats", "record", $experiment_stats->exptidx()); } } } if ($node_id == "") { $nodeurl = CreateURL("shownodehistory", URLARG_NODEID, $nodeid); echo "<tr>\n <td><a href='{$nodeurl}'>{$nodeid}</a></td>\n <td>{$pid}</td>"; if ($expurl) { echo "<td><a href='{$expurl}'>{$eid}</a></td>"; } else { echo "<td>{$eid}</td>"; } if ($PROTOGENI) { echo "<td>{$slice}</td>"; } echo "<td>{$uid}</td>\n <td>{$datestr}</td>\n <td>{$durstr}</td>\n </tr>\n"; } else { echo "<tr>\n <td>{$pid}</td>"; if ($expurl) { echo "<td><a href='{$expurl}'>{$eid}</a></td>"; } else { echo "<td>{$eid}</td>"; } if ($PROTOGENI) { echo "<td>{$slice}</td>"; } echo "<td>{$uid}</td>\n <td>{$datestr}</td>\n <td>{$durstr}</td>\n </tr>\n"; } } $line = fgets($fp, 1024); } pclose($fp); $table_html = ob_get_contents(); ob_end_clean(); echo "<center><a href='shownodehistory.php3?record={$max_history_id}" . "&count={$count}&{$node_opt}'>Next {$count} records</a></center>\n"; echo "<table border=1 cellpadding=2 cellspacing=2 align='center'>\n"; echo "<tr>\n\t {$nodestr}\n <th>Pid</th>\n <th>Eid</th>"; if ($PROTOGENI) { echo "<th>Slice</th>"; } echo " <th>Allocated By</th>\n <th>Allocation Date</th>\n\t <th>Duration</th>\n </tr>\n"; echo $table_html; echo "</table>\n"; echo "<center><a href='shownodehistory.php3?record={$max_history_id}" . "&count={$count}&{$node_opt}'>Next {$count} records</a></center>\n"; $ttime = $atime + $ftime + $rtime + $dtime; if ($ttime) { echo "<br>\n <center><b>\n Usage Summary for Node {$node_id}.\n </b></center><br>\n"; echo "<table border=1 align=center>\n"; $str = "Allocated"; $pct = sprintf("%5.1f", $atime * 100.0 / $ttime); echo "<tr><td>{$str}</td><td>{$pct}%</td></tr>\n"; $str = "Free"; $pct = sprintf("%5.1f", $ftime * 100.0 / $ttime); echo "<tr><td>{$str}</td><td>{$pct}%</td></tr>\n"; $str = "Reloading"; $pct = sprintf("%5.1f", $rtime * 100.0 / $ttime); echo "<tr><td>{$str}</td><td>{$pct}%</td></tr>\n"; $str = "Down"; $pct = sprintf("%5.1f", $dtime * 100.0 / $ttime); echo "<tr><td>{$str}</td><td>{$pct}%</td></tr>\n"; echo "</table>\n"; } } }
function VerifyPageArguments($argspec, $required) { global $drewheader; if ($drewheader) { trigger_error("PAGEHEADER called before VerifyPageArguments " . "(called by RequiredPageArguments or OptionalPageArguments). " . "Won't be able to return proper HTTP status code on Error " . "in " . $_SERVER['SCRIPT_FILENAME'] . ",", E_USER_WARNING); } $result = array(); while ($argspec and count($argspec) > 1) { $name = array_shift($argspec); $type = array_shift($argspec); $yep = 0; unset($object); switch ($type) { case PAGEARG_EXPERIMENT: if (isset($_REQUEST[URL_EXPERIMENT])) { $idx = $_REQUEST[URL_EXPERIMENT]; $yep = 1; if (ValidateArgument(PAGEARG_EXPERIMENT, $idx)) { $object = Experiment::Lookup($idx); } } elseif (isset($_REQUEST[URL_EXPTIDX])) { $idx = $_REQUEST[URL_EXPTIDX]; $yep = 1; if (ValidateArgument(PAGEARG_EXPERIMENT, $idx)) { $object = Experiment::Lookup($idx); } } elseif (isset($_REQUEST[URL_PID]) && isset($_REQUEST[URL_EID])) { $pid = $_REQUEST[URL_PID]; $eid = $_REQUEST[URL_EID]; $yep = 1; if (ValidateArgument(PAGEARG_PID, $pid) && ValidateArgument(PAGEARG_EID, $eid)) { $object = Experiment::LookupByPidEid($pid, $eid); } } break; case PAGEARG_TEMPLATE: if (isset($_REQUEST[URL_GUID]) && isset($_REQUEST[URL_VERS])) { $guid = $_REQUEST[URL_GUID]; $vers = $_REQUEST[URL_VERS]; $yep = 1; if (ValidateArgument(PAGEARG_GUID, $guid) && ValidateArgument(PAGEARG_VERS, $vers)) { $object = Template::Lookup($guid, $vers); } } elseif (isset($_REQUEST[URL_TEMPLATE])) { $guidvers = $_REQUEST[URL_TEMPLATE]; $yep = 1; if (preg_match("/^([\\d]+)\\/([\\d]+)\$/", $guidvers, $matches)) { $guid = $matches[1]; $vers = $matches[2]; $object = Template::Lookup($guid, $vers); } else { PAGEARGERROR("Invalid argument for '{$type}': {$guidvers}"); } } break; case PAGEARG_INSTANCE: if (isset($_REQUEST[URL_INSTANCE])) { $idx = $_REQUEST[URL_INSTANCE]; $yep = 1; if (ValidateArgument(PAGEARG_INSTANCE, $idx)) { $object = TemplateInstance::LookupByExptidx($idx); } } break; case PAGEARG_METADATA: if (isset($_REQUEST[URL_METADATA])) { $guidvers = $_REQUEST[URL_METADATA]; $yep = 1; if (preg_match("/^([\\d]+)\\/([\\d]+)\$/", $guidvers, $matches)) { $guid = $matches[1]; $vers = $matches[2]; $object = TemplateMetadata::Lookup($guid, $vers); } else { PAGEARGERROR("Invalid argument for '{$type}': {$guidvers}"); } } break; case PAGEARG_PROJECT: if (isset($_REQUEST[URL_PROJECT])) { $idx = $_REQUEST[URL_PROJECT]; $yep = 1; if (ValidateArgument(PAGEARG_PROJECT, $idx)) { $object = Project::Lookup($idx); } } elseif (isset($_REQUEST[URL_PID])) { $pid = $_REQUEST[URL_PID]; $yep = 1; if (ValidateArgument(PAGEARG_PID, $pid)) { $object = Project::Lookup($pid); } } break; case PAGEARG_GROUP: if (isset($_REQUEST[URL_GROUP])) { $idx = $_REQUEST[URL_GROUP]; $yep = 1; if (ValidateArgument(PAGEARG_GROUP, $idx)) { $object = Group::Lookup($idx); } } elseif (isset($_REQUEST[URL_PID]) && isset($_REQUEST[URL_GID])) { $pid = $_REQUEST[URL_PID]; $gid = $_REQUEST[URL_GID]; $yep = 1; if (ValidateArgument(PAGEARG_PID, $pid) && ValidateArgument(PAGEARG_GID, $gid)) { $object = Group::LookupByPidGid($pid, $gid); } } break; case PAGEARG_NODE: if (isset($_REQUEST[URL_NODE])) { $idx = $_REQUEST[URL_NODE]; $yep = 1; if (ValidateArgument(PAGEARG_NODE, $idx)) { $object = Node::Lookup($idx); } } elseif (isset($_REQUEST[URL_NODEID])) { $nodeid = $_REQUEST[URL_NODEID]; $yep = 1; if (ValidateArgument(PAGEARG_NODEID, $nodeid)) { $object = Node::Lookup($nodeid); } } elseif (isset($_REQUEST[URL_NODEID_ALT])) { $nodeid = $_REQUEST[URL_NODEID_ALT]; $yep = 1; if (ValidateArgument(PAGEARG_NODEID, $nodeid)) { $object = Node::Lookup($nodeid); } } break; case PAGEARG_USER: if (isset($_REQUEST[URL_USER])) { $idx = $_REQUEST[URL_USER]; $yep = 1; if (ValidateArgument(PAGEARG_USER, $idx)) { $object = User::Lookup($idx); } } elseif (isset($_REQUEST[URL_UID])) { $uid = $_REQUEST[URL_UID]; $yep = 1; if (ValidateArgument(PAGEARG_UID, $uid)) { $object = User::Lookup($uid); } } break; case PAGEARG_IMAGE: if (isset($_REQUEST[URL_IMAGEID])) { $imageid = $_REQUEST[URL_IMAGEID]; $yep = 1; if (ValidateArgument(PAGEARG_IMAGE, $imageid)) { $object = Image::Lookup($imageid); } } elseif (isset($_REQUEST[$name]) && $_REQUEST[$name] != "") { $imageid = $_REQUEST[$name]; $yep = 1; if (ValidateArgument(PAGEARG_IMAGE, $imageid)) { $object = Image::Lookup($imageid); } } break; case PAGEARG_OSINFO: if (isset($_REQUEST[URL_OSID])) { $osid = $_REQUEST[URL_OSID]; $yep = 1; if (ValidateArgument(PAGEARG_OSINFO, $osid)) { $object = OSinfo::Lookup($osid); } } break; case PAGEARG_BOOLEAN: if (isset($_REQUEST[$name]) && $_REQUEST[$name] != "") { $object = $_REQUEST[$name]; $yep = 1; if (strcasecmp("{$object}", "yes") == 0 || strcasecmp("{$object}", "1") == 0 || strcasecmp("{$object}", "true") == 0 || strcasecmp("{$object}", "on") == 0) { $object = True; } elseif (strcasecmp("{$object}", "no") == 0 || strcasecmp("{$object}", "0") == 0 || strcasecmp("{$object}", "false") == 0 || strcasecmp("{$object}", "off") == 0) { $object = False; } } break; case PAGEARG_INTEGER: case PAGEARG_NUMERIC: case PAGEARG_ARRAY: if (isset($_REQUEST[$name]) && $_REQUEST[$name] != "") { $object = $_REQUEST[$name]; $yep = 1; if (!ValidateArgument($type, $object)) { unset($object); } } break; case PAGEARG_ANYTHING: if (isset($_REQUEST[$name])) { $object = $_REQUEST[$name]; $yep = 1; # Anything allowed, caller BETTER check it. } break; case PAGEARG_ALPHALIST: if (isset($_REQUEST[$name])) { $object = $_REQUEST[$name]; if (!preg_match("/^[\\d\\w\\-\\ \\,]+\$/", $object)) { unset($object); } else { $object = preg_split("/[\\,\\;]+\\s*/", $_REQUEST[$name]); } } break; case PAGEARG_STRING: default: if (isset($_REQUEST[$name])) { $object = $_REQUEST[$name]; $yep = 1; # Pages never get arguments with special chars. Check. if (preg_match("/[\\'\"]/", $object)) { $object = htmlspecialchars($object); PAGEARGERROR("Invalid characters in '{$name}': {$object}"); } } break; case PAGEARG_PASSWORD: default: if (isset($_REQUEST[$name])) { $object = $_REQUEST[$name]; $yep = 1; # Only printable chars. if (!preg_match("/^[ -~]+\$/", $object)) { PAGEARGERROR("Invalid characters in '{$name}'"); } } break; case PAGEARG_LOGFILE: if (isset($_REQUEST[URL_LOGFILE])) { $logid = $_REQUEST[URL_LOGFILE]; $yep = 1; if (ValidateArgument(PAGEARG_LOGFILE, $logid)) { $object = Logfile::Lookup($logid); } } break; } if (isset($object)) { $result[$name] = $object; $GLOBALS[$name] = $object; } elseif ($yep) { # # Value supplied but could not be mapped to object. # Lets make that clear in the error message. # USERERROR("Could not map page arguments to '{$name}'", 1); } elseif ($required) { PAGEARGERROR("Must provide '{$name}' page argument"); } else { unset($GLOBALS[$name]); } } return $result; }
function ExperimentList($listify = 1, $group = null) { $uid_idx = $this->uid_idx(); $gclause = ""; # within optional group only. if ($group) { $pid = $group->pid(); $gid = $group->gid(); $gclause = "and pid='{$pid}' and gid='{$gid}'"; } $query_result = DBQueryFatal("select idx from experiments " . "where creator_idx='{$uid_idx}' {$gclause}"); if (!$listify) { return mysql_num_rows($query_result); } # Else, create a list of the groups. $result = array(); while ($row = mysql_fetch_array($query_result)) { $idx = $row["idx"]; if (!($experiment = Experiment::Lookup($idx))) { TBERROR("Group::ExperimentList: " . "Could not load experiment {$idx}!", 1); } $result[] = $experiment; } return $result; }
function LookupByUUID($uuid) { $safe_uuid = addslashes($uuid); $query_result = DBQueryWarn("select idx from experiments " . "where eid_uuid='{$safe_uuid}'"); if (!$query_result || !mysql_num_rows($query_result)) { return null; } $row = mysql_fetch_array($query_result); $idx = $row['idx']; return Experiment::Lookup($idx); }
function ExperimentList($listify = 1) { $pid = $this->pid(); $gid = $this->gid(); $query_result = DBQueryFatal("select idx from experiments " . "where pid='{$pid}' and gid='{$gid}'"); if (!$listify) { return mysql_num_rows($query_result); } # Else, create a list of the groups. $result = array(); while ($row = mysql_fetch_array($query_result)) { $idx = $row["idx"]; if (!($experiment = Experiment::Lookup($idx))) { TBERROR("Group::ExperimentList: " . "Could not load experiment {$idx}!", 1); } $result[] = $experiment; } return $result; }
PAGEARGERROR("Must provide one of experiment, instance or template"); } # # An instance might be a current or historical. If its a template, use # the underlying experiment of the template. # if (isset($instance)) { if ($foo = $instance->GetExperiment()) { $experiment = $foo; } else { $index = $instance->exptidx(); } } elseif (isset($template)) { $experiment = $template->GetExperiment(); } elseif (isset($index)) { $experiment = Experiment::Lookup($index); } # # If we got a current experiment, great. Otherwise we have to lookup # data for a historical experiment. # if (isset($experiment) && $experiment) { # Need these below. $pid = $experiment->pid(); $gid = $experiment->gid(); $eid = $experiment->eid(); $idx = $experiment->idx(); $stats = $experiment->GetStats(); if (!$stats) { TBERROR("Could not load stats object for experiment {$pid}/{$eid}", 1); }
$thistag = $row["tag"]; $exptidx = $row["exptidx"]; $pid = $row["pid"]; $eid = $row["eid"]; $alloc = $row["allocated"]; $id = 0; $slice = "--"; if (isset($row["released"])) { $free = $row["released"]; } else { $free = " "; } if (isset($row["history_id"])) { $id = $row["history_id"]; } $experiment = Experiment::Lookup($exptidx); $experiment_stats = ExperimentStats::Lookup($exptidx); if ($experiment_stats && $experiment_stats->slice_uuid()) { $url = CreateURL("genihistory", "slice_uuid", $experiment_stats->slice_uuid()); $slice = "<a href='{$url}'>" . "<img src=\"greenball.gif\" border=0></a>"; } if ($experiment) { $expurl = CreateURL("showexp", URLARG_EID, $experiment->idx()); } else { $expurl = CreateURL("showexpstats", "record", $experiment_stats->exptidx()); } if ($id > $max_history_id) { $max_history_id = $id; } $html .= "<tr>"; if (!$tag) {
function GetExperiment() { if ($this->experiment) { return $this->experiment; } if ($this->exptidx()) { $this->experiment = Experiment::Lookup($this->exptidx()); } return $this->experiment; }
} elseif (!isset($formfields)) { PAGEARGERROR(); } # # Okay, validate form arguments. # $errors = array(); $eid = ""; # # EID: # if (!isset($formfields["eid"]) || $formfields["eid"] == "") { $errors["ID"] = "Missing Field"; } elseif (!TBvalid_eid($formfields["eid"])) { $errors["ID"] = TBFieldErrorString(); } elseif (Experiment::Lookup($pid, $formfields["eid"])) { $errors["ID"] = "Already in use"; } else { $eid = $formfields["eid"]; } # Set up command options $command_options = ""; # # Swappable # if (!isset($formfields["exp_swappable"]) || strcmp($formfields["exp_swappable"], "1")) { $formfields["exp_swappable"] = 0; if (!isset($formfields["exp_noswap_reason"]) || !strcmp($formfields["exp_noswap_reason"], "")) { if (!$isadmin) { $errors["Not Swappable"] = "No justification provided"; } else {