Exemplo n.º 1
0
 function Reservation()
 {
     $node_id = $this->node_id();
     $query_result = DBQueryFatal("select pid,eid from reserved " . "where node_id='{$node_id}'");
     if (mysql_num_rows($query_result) == 0) {
         return null;
     }
     $row = mysql_fetch_array($query_result);
     $pid = $row["pid"];
     $eid = $row["eid"];
     return Experiment::LookupByPidEid($pid, $eid);
 }
Exemplo n.º 2
0
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;
}
Exemplo n.º 3
0
    echo "<blockquote><pre>{$suexec_output}<pre></blockquote>";
    PAGEFOOTER();
    exit;
}
# Display a useful message.
$message = "";
if ($nonsfile) {
    $message = "Since you did not provide an NS script, no nodes have been\n          allocated. You will not be able to modify or swap this experiment,\n          nor do most other neat things you can do with a real experiment.";
} elseif ($exp_preload) {
    $message = "Since you are only pre-loading the experiment, this will typically\n          take less than one minute. If you do not receive email notification\n          within a reasonable amount of time, please contact {$TBMAILADDR}.";
} elseif ($exp_batched) {
    $message = "Batch Mode experiments will be run when enough resources become\n          available. This might happen immediately, or it may take hours\n\t  or days. You will be notified via email when the experiment has\n          been run. If you do not receive email notification within a\n          reasonable amount of time, please contact {$TBMAILADDR}.";
} else {
    $message = "You will be notified via email when the experiment has been fully\n\t  configured and you are able to proceed. This typically takes less\n          than 10 minutes, depending on the number of nodes you have requested.\n          If you do not receive email notification within a reasonable amount\n          of time, please contact {$TBMAILADDR}.";
}
# Map to the actual experiment and show the log.
if ($experiment = Experiment::LookupByPidEid($formfields["exp_pid"], $formfields["exp_id"])) {
    echo $experiment->PageHeader();
    echo "<br>\n";
    echo "<b>Starting experiment configuration!</b> " . $message;
    echo "<br><br>\n";
    STARTLOG($experiment);
} else {
    echo "<br>\n";
    echo "<b>Starting experiment configuration!</b> " . $message;
    echo "<br>\n";
}
#
# Standard Testbed Footer
#
PAGEFOOTER();
Exemplo n.º 4
0
 function Lookup($exptidx)
 {
     global $experiment_cache;
     $args = func_get_args();
     # Look in cache first
     if (array_key_exists("{$exptidx}", $experiment_cache)) {
         return $experiment_cache["{$exptidx}"];
     }
     $foo = new Experiment($exptidx);
     if ($foo->IsValid()) {
         # Insert into cache.
         $experiment_cache["{$exptidx}"] =& $foo;
         return $foo;
     }
     # Try lookup with pid,eid.
     if (count($args) == 2) {
         $pid = array_shift($args);
         $eid = array_shift($args);
         $foo = Experiment::LookupByPidEid($pid, $eid);
         # Already in the cache from LookupByPidEid() so just return it.
         if ($foo && $foo->IsValid()) {
             return $foo;
         }
     }
     return null;
 }
Exemplo n.º 5
0
 function ShowExperiments($user)
 {
     global $TBOPSPID;
     global $TB_EXPT_READINFO;
     $uid = $user->uid();
     $pid = $this->pid();
     $osname = $this->osname();
     #
     # Due to the funny way we handle 'global' images in the emulab-ops
     # project, we have to treat its images specially - namely, we
     # have to make sure there is not an osname in that project, which
     # takes priority over the global ones.
     #
     if ($pid == $TBOPSPID) {
         $query_result = DBQueryFatal("select distinct v.pid, v.eid, e.state " . "     from virt_nodes as v " . "left join os_info as o on " . "     v.osname=o.osname and v.pid=o.pid " . "left join experiments as e on v.pid=e.pid and " . "     v.eid=e.eid " . "where v.osname='{$osname}' and o.osname is NULL " . "order by v.pid, v.eid, e.state");
     } else {
         $query_result = DBQueryFatal("select distinct v.pid, v.eid, e.state " . "  from virt_nodes as v " . "left join experiments as e " . "     on v.pid=e.pid and v.eid=e.eid " . "where v.pid='{$pid}' and v.osname='{$osname}' " . "order by v.pid, v.eid, e.state");
     }
     if (mysql_num_rows($query_result) == 0) {
         echo "<h4 align='center'>No experiments are using this OS</h3>";
     } else {
         $other_exps = 0;
         echo "<h3 align='center'>Experiments using this OS</h3>\n";
         echo "<table align=center border=1>\n";
         echo "  <tr> \n\t\t        <th>PID</th>\n   \t\t        <th>EID</th>\n\t\t        <th>State</th>\n\t\t    </tr>\n";
         while ($row = mysql_fetch_array($query_result)) {
             $pid = $row[0];
             $eid = $row[1];
             $state = $row[2];
             #
             # Gotta make sure that the user actually has the right to
             # see this experiment - summarize all the experiments that
             # he/she cannot see at the bottom
             #
             if (!($experiment = Experiment::LookupByPidEid($pid, $eid))) {
                 continue;
             }
             if (!$experiment->AccessCheck($user, $TB_EXPT_READINFO)) {
                 $other_exps++;
                 continue;
             }
             $showexp_url = CreateURL("showexp", $experiment);
             echo "<tr>\n";
             echo "  <td>{$pid}</td>\n";
             echo "  <td><a href='{$showexp_url}'>{$eid}</td>\n";
             echo "  <td>{$state}</td>\n";
             echo "</tr>\n";
         }
         if ($other_exps) {
             echo "<tr><td colspan=3>\n                        {$other_exps} experiments in other projects</td></tr>\n";
         }
         echo "</table>\n";
     }
 }
Exemplo n.º 6
0
        PAGEARGERROR("Experiment {$pid}/{$eid} is not a valid experiment!");
    }
    $zapurl = CreateURL("showexp", $experiment);
    $experiment->SetLockDown($value);
} elseif ($type == "skipvlans") {
    # Must validate the pid,eid since we allow non-admins to do this.
    if (!TBvalid_pid($pid)) {
        PAGEARGERROR("Invalid characters in {$pid}");
    }
    if (!TBvalid_eid($eid)) {
        PAGEARGERROR("Invalid characters in {$eid}");
    }
    if (!($isadmin || STUDLY() || OPSGUY())) {
        USERERROR("You do not have permission to toggle {$type}!", 1);
    }
    if (!($experiment = Experiment::LookupByPidEid($pid, $eid))) {
        PAGEARGERROR("Experiment {$pid}/{$eid} is not a valid experiment!");
    }
    if (!$isadmin && !TBMinTrust(TBGrpTrust($uid, $pid, $pid), $TBDB_TRUST_LOCALROOT)) {
        USERERROR("You do not have permission to toggle {$type}!", 1);
    }
    $zapurl = CreateURL("showexp", $experiment);
    $experiment->SetSkipVlans($value);
} elseif ($type == "imageglobal" || $type == "imagedoesxen") {
    include "imageid_defs.php";
    # Must validate since we allow non-admins to do this.
    if (!TBvalid_imageid($imageid)) {
        PAGEARGERROR("Invalid characters in {$imageid}");
    }
    if (!($image = Image::Lookup($imageid))) {
        PAGEARGERROR("Image {$image} is not a valid image!");
Exemplo n.º 7
0
# Only known and logged in users can look at experiments.
#
$this_user = CheckLoginOrDie();
$uid = $this_user->uid();
$isadmin = ISADMIN();
#
# Verify page arguments.
#
$optargs = OptionalPageArguments("sortby", PAGEARG_STRING);
if (!isset($sortby)) {
    $sortby = "";
}
PAGEHEADER("Shared Pool");
$experiment = Experiment::LookupByPidEid("emulab-ops", "shared-nodes");
if (!$experiment) {
    $experiment = Experiment::LookupByPidEid("emulab-ops", "shared-node");
}
if (!$experiment) {
    USERERROR("No shared pool experiment!", 1);
}
$pid = $experiment->pid();
$eid = $experiment->eid();
$counts = array();
$nodes = array();
#
# Get the counts per node.
#
$query_result = DBQueryFatal("select phys_nodeid,count(phys_nodeid) as vcount " . "  from reserved as r " . "left join nodes as n on n.node_id=r.node_id " . "where n.node_id!=n.phys_nodeid and " . "      r.sharing_mode is not null " . "group by phys_nodeid");
while ($row = mysql_fetch_array($query_result)) {
    $node_id = $row["phys_nodeid"];
    $count = $row["vcount"];
Exemplo n.º 8
0
 function ShowInstances()
 {
     $guid = $this->guid();
     $vers = $this->vers();
     $query_result = DBQueryFatal("select e.*,count(r.node_id) as nodes, " . "    round(minimum_nodes+.1,0) as min_nodes " . "from experiment_template_instances as i " . "left join experiments as e on e.idx=i.exptidx " . "left join reserved as r on e.pid=r.pid and " . "     e.eid=r.eid " . "where e.pid is not null and " . "      (i.parent_guid='{$guid}' and " . "       i.parent_vers='{$vers}') " . "group by e.pid,e.eid order by e.state,e.eid");
     if (!mysql_num_rows($query_result)) {
         return;
     }
     echo "<center>\n               <h3>Template Instances</h3>\n             </center> \n             <table align=center border=1 cellpadding=5 cellspacing=2>\n";
     echo "<tr>\n               <th>EID</th>\n               <th>State</th>\n               <th align=center>Nodes</th>\n              </tr>\n";
     $idlemark = "<b>*</b>";
     $stalemark = "<b>?</b>";
     while ($row = mysql_fetch_array($query_result)) {
         $pid = $row['pid'];
         $eid = $row['eid'];
         $state = $row['state'];
         $nodes = $row['nodes'];
         $minnodes = $row['min_nodes'];
         $ignore = $row['idle_ignore'];
         $name = $row['expt_name'];
         if (!($experiment = Experiment::LookupByPidEid($pid, $eid))) {
             TBERROR("Could not map {$pid}/{$eid} to its object", 1);
         }
         $idlehours = $experiment->IdleTime();
         $stale = $experiment->IdleStale();
         if ($nodes == 0) {
             $nodes = "<font color=green>{$minnodes}</font>";
         } elseif ($row["swap_requests"] > 0) {
             $nodes .= $idlemark;
         }
         $idlestr = $idlehours;
         if ($idlehours > 0) {
             if ($stale) {
                 $idlestr .= $stalemark;
             }
             if ($ignore) {
                 $idlestr = "({$idlestr})";
             }
         } elseif ($idlehours == -1) {
             $idlestr = "&nbsp;";
         }
         echo "<tr>\n                   <td><A href='showexp.php3?pid={$pid}&eid={$eid}'>{$eid}</A></td>\n  \t\t   <td>{$state}</td>\n                   <td align=center>{$nodes}</td>\n                 </tr>\n";
     }
     echo "</table>\n";
 }
Exemplo n.º 9
0
 function LookupExperiment($eid)
 {
     return Experiment::LookupByPidEid($this->pid(), $eid);
 }