Commit c404b414 authored by Leigh Stoller's avatar Leigh Stoller

Quick and hacky code to show the geni slice/uer hrns (later urns),

on the showexp page for geni derived experiments. Got tired of
typing the db queries over and over.
parent 3771c93d
......@@ -712,6 +712,20 @@ if (!mysql_select_db($TBDBNAME)) {
TBERROR("Could not select DB after connecting!", 1);
}
#
# Connect to alternate DB.
#
function DBConnect($dbname)
{
$linkid = mysql_connect("localhost", basename($SCRIPT_NAME), "none", 1);
if ($linkid) {
if (!mysql_select_db($dbname, $linkid)) {
return null;
}
}
return $linkid;
}
#
# Record last DB error string.
#
......@@ -734,11 +748,13 @@ $DBErrorString = "";
# the error string from the DB module. Use DBFatal (below) to print/email
# that string, and then exit.
#
function DBQuery($query)
function DBQuery($query, $linkid = NULL)
{
global $TBDBNAME;
global $DBErrorString;
global $DBlinkid;
$linkid = is_null($linkid) ? $DBlinkid : $linkid;
# Support for SQL-injection vulnerability checking. Labeled probe strings
# should be caught in page input argument checking before they get here.
......@@ -753,12 +769,12 @@ function DBQuery($query)
USERERROR("Probe label: " . substr($query, $lbl, $end-$lbl), 1);
}
$result = mysql_query($query, $DBlinkid);
$result = mysql_query($query, $linkid);
if (! $result) {
$DBErrorString =
" Query: $query\n".
" Error: " . mysql_error();
" Error: " . mysql_error($linkid);
}
return $result;
}
......@@ -766,9 +782,9 @@ function DBQuery($query)
#
# Same as above, but die on error.
#
function DBQueryFatal($query)
function DBQueryFatal($query, $linkid = NULL)
{
$result = DBQuery($query);
$result = DBQuery($query, $linkid);
if (! $result) {
DBFatal("DB Query failed");
......@@ -780,9 +796,9 @@ function DBQueryFatal($query)
# Same as above, but just send email on error. This info is useful
# to the TB system, but the caller has to retain control.
#
function DBQueryWarn($query)
function DBQueryWarn($query, $linkid = NULL)
{
$result = DBQuery($query);
$result = DBQuery($query, $linkid);
if (! $result) {
DBWarn("DB Query failed");
......@@ -827,11 +843,13 @@ function DBFatal($message)
# Return the number of affected rows, for the last query. Why is this
# not stored in the query result?
#
function DBAffectedRows()
function DBAffectedRows($linkid = NULL)
{
global $DBlinkid;
return mysql_affected_rows($DBlinkid);
$linkid = is_null($linkid) ? $DBlinkid : $linkid;
return mysql_affected_rows($linkid);
}
?>
......@@ -1062,6 +1062,49 @@ class Experiment
echo " </td>
</tr>\n";
}
if (!$short && ISADMIN() && $this->geniflags()) {
$dbid = DBConnect("geni-cm");
$slice_hrn = null;
$user_hrn = null;
if ($dbid) {
$geni_result =
DBQueryFatal("select hrn,creator_uuid from geni_slices ".
"where uuid='$uuid'", $dbid);
if ($geni_result &&
mysql_num_rows($geni_result)) {
$genirow = mysql_fetch_array($geni_result);
$creator_uuid = $genirow["creator_uuid"];
$slice_hrn = $genirow["hrn"];
$geni_result =
DBQueryFatal("select hrn from geni_users ".
"where uuid='$creator_uuid'", $dbid);
if ($geni_result &&
mysql_num_rows($geni_result)) {
$genirow = mysql_fetch_array($geni_result);
$user_hrn = $genirow["hrn"];
}
else {
$user = User::LookupByUUID($creator_uuid);
if ($user) {
$user_hrn = $user->uid();
}
}
if (! is_null($slice_hrn)) {
echo "<tr>
<td>Geni Slice HRN: </td>
<td class=\"left\">$slice_hrn</td>
</tr>\n";
}
if (! is_null($user_hrn)) {
echo "<tr>
<td>Geni User HRN: </td>
<td class=\"left\">$user_hrn</td>
</tr>\n";
}
}
}
}
echo "</table>\n";
}
......
......@@ -130,6 +130,24 @@ class User
return User::Lookup($idx);
}
function LookupByUUID($uuid) {
$safe_uuid = addslashes($uuid);
$status_archived = TBDB_USERSTATUS_ARCHIVED;
$query_result =
DBQueryWarn("select uid_idx from users ".
"where uid_uuid='$safe_uuid' and ".
" status!='$status_archived'");
if (!$query_result || !mysql_num_rows($query_result)) {
return null;
}
$row = mysql_fetch_array($query_result);
$idx = $row['uid_idx'];
return User::Lookup($idx);
}
#
# Refresh an instance by reloading from the DB.
#
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment