function DoesXen($does) { $imageid = $this->imageid(); if ($does) { $parentosinfo = OSinfo::LookupByName("emulab-ops", "XEN41-64-STD"); if (!$parentosinfo) { return -1; } $parentosid = $parentosinfo->osid(); DBQueryFatal("update os_info set def_parentosid='{$parentosid}' " . "where osid='{$imageid}'"); DBQueryFatal("replace into os_submap set " . " osid='{$imageid}', parent_osid='{$parentosid}'"); DBQueryFatal("replace into osidtoimageid set " . " osid='{$imageid}', type='pcvm', imageid='{$imageid}'"); } else { DBQueryFatal("delete from osidtoimageid " . "where osid='{$imageid}' and type='pcvm'"); DBQueryFatal("delete from os_submap " . "where osid='{$imageid}'"); DBQueryFatal("update os_info set def_parentosid=NULL " . "where osid='{$imageid}'"); } return 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; }
function Show() { $osid = $this->osid(); $os_description = $this->description(); $os_OS = $this->OS(); $os_version = $this->version(); $os_path = $this->path(); $os_magic = $this->magic(); $os_osfeatures = $this->osfeatures(); $os_op_mode = $this->op_mode(); $os_pid = $this->pid(); $os_shared = $this->shared(); $os_osname = $this->osname(); $creator = $this->creator(); $created = $this->created(); $mustclean = $this->mustclean(); $nextosid = $this->nextosid(); $def_parentosid = $this->def_parentosid(); $max_concurrent = $this->max_concurrent(); $reboot_waittime = $this->reboot_waittime(); $uuid = $this->uuid(); $ezid = $this->ezid(); $mfs = $this->mfs(); if (!($creator_user = User::Lookup($creator))) { TBERROR("Error getting object for user {$creator}", 1); } $showuser_url = CreateURL("showuser", $creator_user); if (!$os_description) { $os_description = " "; } if (!$os_version) { $os_version = " "; } if (!$os_path) { $os_path = " "; } if (!$os_magic) { $os_magic = " "; } if (!$os_osfeatures) { $os_osfeatures = " "; } if (!$os_op_mode) { $os_op_mode = " "; } if (!$created) { $created = "N/A"; } if (!$reboot_waittime) { $reboot_waittime = " "; } # # Generate the table. # echo "<table align=center border=1>\n"; echo "<tr>\n <td>Name: </td>\n <td class=\"left\">{$os_osname}</td>\n </tr>\n"; echo "<tr>\n <td>Project: </td>\n <td class=\"left\">\n <a href='showproject.php3?pid={$os_pid}'>{$os_pid}</a></td>\n </tr>\n"; echo "<tr>\n <td>Creator: </td>\n <td class=left>\n <a href='{$showuser_url}'>{$creator}</a></td>\n \t </tr>\n"; echo "<tr>\n <td>Created: </td>\n <td class=left>{$created}</td>\n \t </tr>\n"; echo "<tr>\n <td>Description: </td>\n <td class=\"left\">{$os_description}</td>\n </tr>\n"; echo "<tr>\n <td>Operating System: </td>\n <td class=\"left\">{$os_OS}</td>\n </tr>\n"; echo "<tr>\n <td>Version: </td>\n <td class=\"left\">{$os_version}</td>\n </tr>\n"; echo "<tr>\n <td>Path: </td>\n <td class=\"left\">{$os_path}</td>\n </tr>\n"; echo "<tr>\n <td>Magic (uname -r -s): </td>\n <td class=\"left\">{$os_magic}</td>\n </tr>\n"; echo "<tr>\n <td>Features: </td>\n <td class=\"left\">{$os_osfeatures}</td>\n </tr>\n"; echo "<tr>\n <td>Operational Mode: </td>\n <td class=\"left\">{$os_op_mode}</td>\n </tr>\n"; if (isset($max_concurrent) and $max_concurrent > 0) { echo "<tr>\n <td>Max Concurrent Usage: </td>\n <td class=\"left\">{$max_concurrent}</td>\n </tr>\n"; } echo "<tr>\n <td>Reboot Waittime: </td>\n <td class=\"left\">{$reboot_waittime}</td>\n </tr>\n"; echo "<tr>\n <td>Shared?: </td>\n <td class=left>" . YesNo($os_shared) . "</td>\n </tr>\n"; echo "<tr>\n <td>Must Clean?: </td>\n <td class=left>" . YesNo($mustclean) . "</td>\n </tr>\n"; if ($nextosid) { if ($nextosid == 0) { echo "<tr>\n\t\t <td>Next Osid: </td>\n\t\t <td class=left>\n\t\t\t Mapped via DB table: osid_map</td></tr>\n"; } else { $nextosinfo = OSinfo::Lookup($nextosid); $nextosname = $nextosinfo->osname(); echo "<tr>\n <td>Next Osid: </td>\n <td class=left>\n <a href='showosinfo.php3?osid={$nextosid}'>\n {$nextosname}</a></td>\n </tr>\n"; } } if ($def_parentosid) { $nextosinfo = OSinfo::Lookup($def_parentosid); $nextosname = $nextosinfo->osname(); echo "<tr>\n <td>Parent Osid: </td>\n <td class=left>\n <a href='showosinfo.php3?osid={$def_parentosid}'>\n {$nextosname}</a></td>\n </tr>\n"; } if ($ezid) { echo "<tr>\n <td>Image Link: </td>\n <td class=left>\n <a href='showimageid.php3?imageid={$osid}'>\n {$os_osname}</a></td>\n </tr>\n"; } if ($mfs) { echo "<tr>\n <td>MFS: </td>\n <td class=left>Yes</td>\n </tr>\n"; } echo "<tr>\n <td>Internal ID: </td>\n <td class=\"left\">{$osid}</td>\n </tr>\n"; echo "<tr>\n <td>UUID: </td>\n <td class=left>{$uuid}</td>\n </tr>\n"; if ($def_parentosid) { $parent_result = DBQueryFatal("select m.parent_osid,o.osname,o.pid " . " from os_submap as m " . "left join os_info as o on o.osid=m.parent_osid " . "where m.osid='{$osid}'"); if (mysql_num_rows($parent_result)) { while ($prow = mysql_fetch_array($parent_result)) { $posid = $prow["parent_osid"]; $posname = $prow["osname"]; echo "<tr>"; echo " <td>Parent {$posid}:</td>"; echo " <td class=left>"; echo " <a href='showosinfo.php3?osid={$posid}'>"; echo "{$posname}</a></td>\n"; echo "</tr>\n"; } } } echo "</table>\n"; }