Commit 218e73c5 authored by Logan Axon's avatar Logan Axon

Initial Version of Testbed Database Web Interface.

parent 80d8bcff
<?php
if (!isset($PHP_AUTH_USER) || !empty($HTTP_GET_VARS)) {
Header("WWW-Authenticate: Basic realm=\"testbed\"");
Header("HTTP/1.0 401 Unauthorized");
die ("User authentication is required to view these pages\n");
} else {
addslashes($PHP_AUTH_USER);
$PSWD = crypt("$PHP_AUTH_PW", strlen($PHP_AUTH_USER));
$query = "SELECT * FROM users WHERE uid=\"$PHP_AUTH_USER\" AND usr_pswd=\"$PSWD\" AND trust_level!=\"0\"";
$result = mysql_db_query("tbdb", $query);
$valid = mysql_num_rows($result);
$query2 = "SELECT timeout FROM login WHERE uid=\"$PHP_AUTH_USER\"";
$result2 = mysql_db_query("tbdb", $query2);
$n = mysql_num_rows($result2);
if (($n == 0) && ($valid != 0)) {
$cmnd = "INSERT INTO login VALUES ('$PHP_AUTH_USER', '0')";
mysql_db_query("tbdb", $cmnd);
} else {
$row = mysql_fetch_row($result2);
if (($valid == 0) || ($row[0] < time())) {
$cmnd = "DELETE FROM login WHERE uid=\"$PHP_AUTH_USER\"";
mysql_db_query("tbdb", $cmnd);
Header("WWW-Authenticate: Basic realm=\"testbed\"");
Header("HTTP/1.0 401 Unauthorized");
die ("Authorization Failed\n");
}
}
$timeout = time() + 1800;
$cmnd = "UPDATE login SET timeout=\"$timeout\" where uid=\"$PHP_AUTH_USER\"";
mysql_db_query("tbdb", $cmnd);
}
echo "
<html>
<head>
<title>Altering TBDB</title>
</head>
<body>
<h1>Adding information to the testbed database...</h1>\n";
array_walk($HTTP_POST_VARS, 'addslashes');
if (isset($pid)) { #add a project to the database
$cmnd = "INSERT INTO projects VALUES ('$pid',
now(),
'$proj_expires',
'$proj_name',
'$PHP_AUTH_USER')";
$result = mysql_db_query("tbdb", $cmnd);
if (!$result) {
$err = mysql_error();
echo "<H3>Couldn't add project to the database: $err</h3>\n";
exit;
}
$cmnd2 = "INSERT INTO proj_grps VALUES ('$pid', '$grp_assoc')";
mysql_db_query("tbdb", $cmnd2);
$cmnd3 = "INSERT INTO proj_memb VALUES ('$PHP_AUTH_USER', '$pid')";
mysql_db_query("tbdb", $cmnd3);
if ($proj_memb != "") {
$memb = preg_split("/\s/", "$proj_memb");
function add_memb ($item) {
global $pid;
trim($item);
$insert = "INSERT INTO proj_memb VALUES ('$item', '$pid')";
mysql_db_query("tbdb", $insert);
}
array_walk ($memb, "add_memb");
}
echo "<h1>Success</h1>";
} elseif (!empty($uid) && ($pswd == $pswd2)) { #add a user to the database
$query = "SELECT unix_uid FROM users ORDER BY unix_uid DESC";
$res = mysql_db_query("tbdb", $query);
$row = mysql_fetch_row($res);
$unix_uid = $row[0];
++$unix_uid;
$enc = crypt("$pswd", strlen($uid));
$cmnd = "INSERT INTO users VALUES (
'$uid',
now(),
'$usr_expires',
'$usr_name',
'$usr_email',
'$usr_addr',
'$usr_phones',
'1',
'$enc',
'$unix_uid')";
$result = mysql_db_query("tbdb", $cmnd); #put the user into users
if (!$result) {
$err = mysql_error();
echo "<H3>Could not add user to the database: $err</h3>\n";
exit;
}
$cmnd2 = "INSERT INTO grp_memb VALUES ('$uid', '$grp')";
mysql_db_query("tbdb", $cmnd2); #put the user and group into grp_memb
$fp = fopen("/usr/local/share/apache/htdocs/testbed/maillist/users.txt", "a");
fwrite($fp, "$usr_email\n"); #write the user's email to the mail list
} elseif ($filename != "" && isset($filename) && ($pswd == $pswd2)) {
/* if a file of user information is specified, load the file into the database. Then update all the entries just made, and add them to grp_memb. */
$cmnd = "LOAD DATA LOCAL INFILE '$filename' INTO TABLE users";
$result = mysql_db_query("tbdb", $cmnd);
if (!$result) {
$err = mysql_error();
echo "<H3>Could not query database: $err</h3>\n";
exit;
}
$time = mysql_db_query("tbdb", "SELECT now()");
$row = mysql_fetch_row($time);
$now = $row[0]; #get the current time in mysql format
$query = "UPDATE users SET usr_created='$now' where usr_created=\"0000-00-00 00:00:00\"";
mysql_db_query("tbdb", $query); #set the time of creation of the users to now
$query2 = "SELECT uid, usr_email FROM users WHERE usr_created=\"$now\"";
$result2 = mysql_db_query("tbdb", $query2); #get all the users just added
$query3 = "SELECT unix_uid FROM users ORDER BY unix_uid DESC";
$result3 = mysql_db_query("tbdb", $query3);
$row3 = mysql_fetch_row($result3);
$unix_uid = $row3[0];
while ($row = mysql_fetch_array($result2)) {
++$unix_uid;
$uid = $row[uid];
$enc = crypt("$pswd", strlen($uid));
$email = $row[usr_email];
$cmnd2 = "INSERT INTO grp_memb VALUES ('$uid', '$grp')";
mysql_db_query("tbdb", $cmnd2); #add users to grp_memb
$cmnd3 = "UPDATE users SET usr_pswd='$enc', unix_uid='$unix_uid' where uid='$uid'";
mysql_db_query('tbdb', $cmnd3); #give users unix_uids
$fp = fopen("/usr/local/share/apache/htdocs/testbed/maillist/users.txt", "a");
fwrite($fp, "$email\n"); #write email addresses to the mail list
}
} elseif (isset($eid) && isset($proj)) { #start an experiment for a project
$cmnd = "INSERT INTO experiments VALUES ('$eid',
'$proj',
now(),
'$expt_expires',
'expt_name',
'$PHP_AUTH_USER',
'$expt_start',
'$expt_end')";
$result = mysql_db_query("tbdb", $cmnd);
if (!result) {
$err = mysql_error();
echo "<H3>Failed to add experiment: $err</h3>\n";
exit;
}
} else {
echo "<H3>There was a problem with the information recieved, please return to the form and check to be sure you have correctly filled all required fields. </h3>\n";
}
?>
</body>
</html>
\ No newline at end of file
<?php
if (!isset($PHP_AUTH_USER)) {
Header("WWW-Authenticate: Basic realm=\"testbed\"");
Header("HTTP/1.0 401 Unauthorized");
echo "User authenication is required to view these pages\n";
exit;
} else {
addslashes($PHP_AUTH_USER);
$PSWD = crypt("$PHP_AUTH_PW", strlen($PHP_AUTH_USER));
$query = "SELECT * FROM users WHERE uid=\"$PHP_AUTH_USER\" AND usr_pswd=\"$PSWD\"";
$result = mysql_db_query("tbdb", $query);
$numusers = mysql_num_rows($result);
$query2 = "SELECT timeout FROM login WHERE uid=\"$PHP_AUTH_USER\"";
$result2 = mysql_db_query("tbdb", $query2);
$n = mysql_num_rows($result2);
if (($n == 0) && ($numusers != 0)) {
$cmnd = "INSERT INTO login VALUES ('$PHP_AUTH_USER', '0')";
mysql_db_query("tbdb", $cmnd);
} else {
$row = mysql_fetch_row($result2);
if (($numusers == 0) || ($row[0] < time())) {
$cmnd = "DELETE FROM login WHERE uid=\"$PHP_AUTH_USER\"";
mysql_db_query("tbdb", $cmnd);
Header("WWW-Authenticate: Basic realm=\"testbed\"");
Header("HTTP/1.0 401 Unauthorized");
die ("Authorization Failed\n");
}
}
$timeout = time() + 1800;
$cmnd = "UPDATE login SET timeout=\"$timeout\" where uid=\"$PHP_AUTH_USER\"";
mysql_db_query("tbdb", $cmnd);
}
?>
<html>
<head>
<title>New Experiment</title>
<link rel="stylesheet" href="tbstyle.css" type="text/css">
</head>
<body>
<H1>Begin an experiment on the testbed</h1>
<table border="1" align="center">
<tr><td colspan="2">Only those fields in bold, red type are required.</td></tr>
<form action=added.php3 method="post">
<tr><th>Experiment Name:</th><td><input type="text" name="eid"></td></tr>
<?php
addslashes($PHP_AUTH_USER);
$query = "SELECT pid FROM proj_memb WHERE uid=\"$PHP_AUTH_USER\"";
$result = mysql_db_query("tbdb", $query);
$n = mysql_num_rows($result);
if ($n == 1) {
echo "<tr><th>Project ID:</th>";
$row = mysql_fetch_row($result);
echo "<td><input type=\"readonly\" value=\"$row[0]\" name=\"proj\"></td></tr>\n";
} elseif ($n > 1) {
echo "<tr><th>Project ID:</th><td><select name=\"proj\">\n";
while ($row = mysql_fetch_row($result)) {
echo "<option value=\"$row[0]\">$row[0]</option>\n";
}
echo "</select></td></tr>\n";
} else {
echo "<tr><th colspan=\"2\">You must be part of a project if you wan to run an experiment</th></tr>";
}
$utime = time();
$year = date("Y", $utime);
$month = date("m", $utime);
$thismonth = $month++;
if ($month > 12) {
$month -= 12;
$month = "0".$month;
}
$rest = date("d H:i:s", $utime);
echo "<tr><th>Expiration date:</th><td><input type=\"text\" value=\"$year:$month:$rest\" name=\"expt_expires\"></td></tr>
<tr><td>Experiment long name:</td><td><input type=\"text\" name=\"expt_name\"></td></tr>
<tr><td>Experiment starts:</td><td><input type=\"text\" value=\"$year:$thismonth:$rest\" name=\"expt_start\"></td></tr>
<tr><td>Experiment ends:</td><td><input type=\"text\" value=\"$year:$month:$rest\" name=\"expt_end\"></td></tr>
<tr><th colspan=\"2\"><input type=\"submit\" value=\"Submit\"></th></tr>\n";
?>
</form>
</table>
</body>
</html>
\ No newline at end of file
<html>
<head>
<title>New Group</title>
<link rel="stylesheet" href="tbstyle.css" type="text/css">
</head>
<body>
<H1 align="center">Apply to use the University of Utah's network testbed</h1>
<table align="center" width="80%" border="1">
<tr><td colspan="4">Only fields in bold, red type are required</td></tr>
<form action=grpadded.php3 method="post">
<tr><th colspan=2>Group Information</th>
<th colspan=2>Group Head Information</th></tr>
<tr><th>Group Name:</th><td><input type="text" name="gid"></td>
<th>Username</th><td>
<?php
if (isset($PHP_AUTH_USER)) {
/* if this person is logged into the database,
fill the user info fields with info from the database */
$uid = addslashes($PHP_AUTH_USER);
$query = "SELECT * FROM users WHERE uid=\"$uid\"";
$result = mysql_db_query("tbdb", $query);
$row = mysql_fetch_array($result);
echo "<input type=\"readonly\" value=\"$row[uid]\" name=\"grp_head_uid\"></td></tr>\n";
} else {
echo "<input type=\"text\" name=\"grp_head_uid\"></td></tr>\n";
}
echo "<tr><td>Group long name:</td><td><input type=\"text\" name=\"grp_name\"></td>
<th>Full Name:</th><td>";
if (isset($row)) {
echo "<input type=\"readonly\" value=\"$row[usr_name]\"";
} else {
echo "<input type=\"text\"";
}
echo "name=\"usr_name\"></td></tr>
<tr><td>Group URL:</td><td><input type=\"text\" name=\"grp_URL\"></td>
<th>Email Address:</th><td>";
if (isset($row)) {
echo "<input type=\"readonly\" value=\"$row[usr_email]\" ";
} else {
echo "<input type=\"text\" ";
}
echo "name=\"email\"></td></tr>
<tr><th>When do you expect to be done using the testbed?</th>
<td><input type=\"text\" value="; #set a default expiration date
$time = time();
$year = date("Y", $time);
++$year;
$mytime = date("m:d H:i:s", $time);
echo "\"$year:$mytime\"";
echo "name=\"grp_expires\"></td>
<th>Mailing Address:</th><td>";
if (isset($row)) {
echo "<input type=\"readonly\" value=\"$row[usr_addr]\" name=\"usr_addr\">";
} else {
echo "<input type=\"text\" name=\"usr_addr\">";
}
echo "</td></tr>
<tr><td>Group Affiliation:</td><td><input type=\"text\" name=\"grp_affil\"></td>
<th>Phone #:</th><td><input ";
if (isset($row)) {
echo "type=\"readonly\" value=\"$row[usr_phones]\"";
} else {
echo "type=\"text\"";
}
echo "name=\"usr_phones\"></td></tr>\n";
?>
<tr><th>Password:</th><td><input type="password" name="password1"></td>
<th>Retype Password:</th><td><input type="password" name="password2"></td></tr>
<tr><th colspan="4">Please describe how and why you plan to use the testbed</th></tr>
<tr><td colspan="4" align="center"><textarea name="why" rows="10" cols="70"></textarea></td></tr>
<tr><th colspan="4" align="center"><input type="submit" value="Submit"></th></tr>
</form>
</table>
</body>
</html>
<?php
if (!isset($PHP_AUTH_USER)) {
Header("WWW-Authenticate: Basic realm=\"testbed\"");
Header("HTTP/1.0 401 Unauthorized");
die("User authenication is required to view these pages\n");
} else {
addslashes($PHP_AUTH_USER);
$PSWD = crypt("$PHP_AUTH_PW", strlen($PHP_AUTH_USER));
$query = "SELECT * FROM users WHERE uid=\"$PHP_AUTH_USER\" AND usr_pswd=\"$PSWD\" AND trust_level > 0";
$result = mysql_db_query("tbdb", $query);
$numusers = mysql_num_rows($result);
$query2 = "SELECT timeout FROM login WHERE uid=\"$PHP_AUTH_USER\"";
$result2 = mysql_db_query("tbdb", $query2);
$n = mysql_num_rows($result2);
if (($n == 0) && ($numusers != 0)){
$cmnd = "INSERT INTO login VALUES ('$PHP_AUTH_USER', '0')";
mysql_db_query("tbdb", $cmnd);
} else {
$row = mysql_fetch_row($result2);
if (($numusers == 0) || ($row[0] < time())) {
$cmnd = "DELETE FROM login WHERE uid=\"$PHP_AUTH_USER\"";
mysql_db_query("tbdb", $cmnd);
Header("WWW-Authenticate: Basic realm=\"testbed\"");
Header("HTTP/1.0 401 Unauthorized");
die ("Authorization Failed\n");
}
}
$timeout = time() + 1800;
$cmnd = "UPDATE login SET timeout=\"$timeout\" where uid=\"$PHP_AUTH_USER\"";
mysql_db_query("tbdb", $cmnd);
}
?>
<html>
<head>
<title>New Project</title>
<link rel="stylesheet" href="tbstyle.css" type="text/css">
</head>
<body>
<H1>Begin a project</h1>
<?php
addslashes($PHP_AUTH_USER);
$utime = time();
$year = date("Y", $utime);
$month = date("m", $utime);
$month += 6;
if ($month > 12) {
$month -= 12;
$month = "0".$month;
}
$rest = date("d H:i:s", $utime);
echo "<table border=\"1\" align=\"center\">
<form action=added.php3 method=\"post\">
<tr><td colspan=\"2\">Only fields in bold red are required</td></tr>
<tr><th>Project Name:</th><td><input type=\"text\" name=\"pid\"></td></tr>
<tr><th>Group association:</th>\n";
$query = "SELECT gid FROM grp_memb WHERE uid=\"$PHP_AUTH_USER\"";
$result = mysql_db_query("tbdb", $query);
$n = mysql_num_rows($result);
if ($n > 1) {
echo "<td><select name=\"grp_assoc\">\n";
while ($row = mysql_fetch_row($result)) {
echo "<option value=\"$row[0]\">$row[0]</option>\n";
}
echo "</select></td></tr>\n";
} else {
$row = mysql_fetch_row($result);
echo "<td><input type=\"readonly\" value=\"$row[0]\" name=\"grp_assoc\"></td></tr>\n";
}
echo "<tr><th>Expiration date:</th><td><input type=\"text\" value=\"$year:$month:$rest\" name=\"proj_expires\"></td></tr>\n";
?>
<tr><td>Project Long Name:</td><td><input type="text" name="proj_name"></td></tr>
<tr><td>Project Members:</td><td><textarea cols="20" rows="2" name="proj_memb"></textarea></td>
<tr><th colspan="2"><input type="submit" value="Submit"></th></tr>
</form>
</table>
</body>
</html>
\ No newline at end of file
<?php
if (!isset($PHP_AUTH_USER)) {
Header("WWW-Authenticate: Basic realm=\"Testbed\"");
Header("HTTP/1.0 401 Unauthorized");
echo "User authentication is required to view these pages\n";
exit;
} else {
addslashes($PHP_AUTH_USER);
$PSWD = crypt("$PHP_AUTH_PW", strlen($PHP_AUTH_USER));
$query = "SELECT * FROM users WHERE uid=\"$PHP_AUTH_USER\" AND usr_pswd=\"$PSWD\" AND trust_level > 0";
$result = mysql_db_query("tbdb", $query);
$numusers = mysql_num_rows($result);
$query2 = "SELECT timeout FROM login WHERE uid=\"$PHP_AUTH_USER\"";
$result2 = mysql_db_query("tbdb", $query2);
$n = mysql_num_rows($result2);
if (($n == 0) && ($numusers != 0)) {
$cmnd = "INSERT INTO login VALUES ('$PHP_AUTH_USER', '0')";
mysql_db_query("tbdb", $cmnd);
} else {
$row = mysql_fetch_row($result2);
if (($numusers == 0) || ($row[0] < time())) {
$cmnd = "DELETE FROM login WHERE uid=\"$PHP_AUTH_USER\"";
mysql_db_query("tbdb", $cmnd);
Header("WWW-Authenticate: Basic realm=\"Testbed\"");
Header("HTTP/1.0 401 Unauthorized");
die ("Authorization Failed\n");
}
}
$timeout = time() + 1800;
$cmnd = "UPDATE login SET timeout=\"$timeout\" where uid=\"$PHP_AUTH_USER\"";
mysql_db_query("tbdb", $cmnd);
}
echo "
<html>
<head>
<title>New User</title>
<link rel=\"stylesheet\" href=\"tbstyle.css\" type=\"text/css\">
</head>
<body>
<H1>Add a new user to the testbed database</h1>\n";
$utime = time();
$year = date("Y", $utime);
++$year;
$time = date("m:d H:i:s", $utime);
echo "<table align=\"center\" border=\"1\">
<tr><td colspan=\"4\">Only fields in bold, red type are required</td></tr>
<form enctype=\"multipart/form-data\" action=\"added.php3\" method=\"post\">
<tr><th>Username:</th><td><input type=\"text\" name=\"uid\"></td>
<td>Expiration date:</td><td><input type=\"text\" name=\"usr_expires\" value=\"$year:$time\"></td></tr>
<tr><th>email:</th><td><input type=\"text\" name=\"usr_email\"></td>
<td>Mailing Address:</td><td><input type\"text\" name=\"usr_addr\"></td></tr>
<tr><th>Full Name:</th><td><input type=\"text\" name=\"usr_name\"></td>
<td>Phone #:</td><td><input type=\"text\" name=\"usr_phones\"></td></tr>
<tr><th>Password:</th><td><input type=\"password\" name=\"pswd\"></td>
<td rowspan=\"3\" colspan=\"2\">Or enter the name of a file containing a list of users to be added. Users should be separated by a newline. Each field of information should be separated by a tab. The second field should be \"now\". Each of these users will be given the password specified in the form above and assigned to the specified group.</td></tr>
<tr><th>Retype Password:</th><td><input type=\"password\" name=\"pswd2\"></td></tr>
<tr><th>Group:</th><th>\n";
$query = "SELECT gid FROM grp_memb WHERE uid=\"$PHP_AUTH_USER\"";
$result = mysql_db_query("tbdb", $query);
$n = mysql_num_rows($result);
if ($n == 1) { # if only one option make a readonly field
$row = mysql_fetch_row($result);
echo "<input type=\"readonly\" value=\"$row[0]\" name=\"grp\"></th></tr>\n";
} elseif ($n > 1) { # if more than one option make a select button
echo "<select name=\"grp\">\n";
while ($row = mysql_fetch_row($result)) {
$gid = $row[gid];
echo "<option value=$gid>$gid</option>\n";
}
echo "</select></th></tr>\n";
} else { # if no options say this
echo "You don't seem to belong to any group. This may be a problem.</th></tr>\n";
}
?>
<tr><th colspan="2" align="center"><input type="submit" value="Submit"></th>
<td>Filename:</td><td><input type="file" name="filename"></td></tr>
</form>
</table>
</body>
</html>
<?php
if (!empty($HTTP_GET_VARS)) {
die("This form does not accept variables sent by get");
}
?>
<html>
<head>
<title>Group Request</title>
</head>
<body>
<?php
array_walk($HTTP_POST_VARS, 'addslashes');
if (isset($gid) && isset($password1) && isset($email) && ($password1 == $password2)) {
$salt = strlen("$grp_head_uid");
$enc = crypt("$password1", "$salt");
$query = "SELECT usr_pswd FROM users WHERE uid=\"$grp_head_uid\"";
$result = mysql_db_query("tbdb", $query);
$query2 = "SELECT gid FROM groups WHERE gid=\"$gid\"";
$result2 = mysql_db_query("tbdb", $query2);
if ($row = mysql_fetch_row($result2)) {
die("The group name you have chosen is already in use. Please select another");
} elseif ($row = mysql_fetch_row($result)) {
$usr_pswd = $row[0];
if ($usr_pswd != $enc) {
die("<H3>The username that you have chosen is already in use.</h3>\n");
}
} else { #The uid and gid are not already in use
$query3 = "SELECT unix_uid FROM users ORDER BY unix_uid DESC";
$result3 = mysql_db_query("tbdb", $query2);
$row = mysql_fetch_row($result3);
$unix_uid = $row[0];
++$unix_uid;
$cmnd1 = "INSERT INTO users VALUES ('$grp_head_uid',
now(),
'$grp_expires',
'$usr_name',
'$email',
'$usr_addr',
'$usr_phones',
'0',
'$enc',
'$unix_uid')";
$cmndres1 = mysql_db_query("tbdb", $cmnd1);
if (!$cmndres1) {
$err = mysql_error();
echo "<H3>Failed to add you to the database: $err</h3>\n";
exit;
}
}
$fp = fopen("/usr/local/share/apache/htdocs/testbed/maillist/leaders.txt", "a");
$fp2 = fopen("/usr/local/share/apache/htdocs/testbed/maillist/users.txt", "a");
fwrite($fp, "$email\n"); #Writes the email address to mailing lists
fwrite($fp2, "$email\n");
mail("axon@cs.utah.edu", "New Group", "$usr_name wants to start $gid. $why", "From $grp_head_uid <$email>");
$ques = "SELECT unix_gid FROM groups ORDER BY unix_gid DESC";
$resp = mysql_db_query("tbdb", $ques);
$row = mysql_fetch_row($resp);
$unix_gid = $row[0];
++$unix_gid;
$cmnd2 = "INSERT INTO groups VALUES ('$gid',
now(),
'$grp_expires',
'$grp_name',
'$grp_URL',
'$grp_affil',
'$grp_addr',
'$grp_head_uid', '',
'$unix_gid')";
$cresult = mysql_db_query("tbdb", $cmnd2);
if (!cresult) {
$err = mysql_error();
echo "<H3>Failed to add group: $err</h3>\n";
exit;
}
$cmnd3 = "INSERT INTO grp_memb VALUES ('$grp_head_uid', '$gid')";
mysql_db_query("tbdb", $cmnd3);
echo "<H3>Information succesfully added</h3>\n";
} else { #if not enough information was given
echo "<H3>Please return to <A href=\"addgrp.php3\">the form</A> and enter your user ID and/or email address and/or password.</h3>\n";
}
?>
</body>
</html>
<?php
if (!isset($PHP_AUTH_USER)) {
Header("WWW-Authenticate: Basic realm=\"testbed\"");
Header("HTTP/1.0 401 Unauthorized");
} elseif (isset($logout)) { # a logout clause
addslashes($PHP_AUTH_USER);
$cmnd = "UPDATE login SET timeout=\"0\" WHERE uid=\"$PHP_AUTH_USER\"";
$result = mysql_db_query("tbdb", $cmnd);
if (!$result) {
$err = mysql_error();
echo "Logout failed: $err";
}
echo "<html><head><title>Testbed Logout</title></head></html>\n";
exit;
} else {
addslashes($PHP_AUTH_USER);
$PSWD = crypt("$PHP_AUTH_PW", strlen("$PHP_AUTH_USER"));
$query = "SELECT * FROM users WHERE uid=\"$PHP_AUTH_USER\" AND usr_pswd=\"$PSWD\" AND trust_level > 0";
$result = mysql_db_query("tbdb", $query);
$valid = mysql_num_rows($result);
$query2 = "SELECT timeout FROM login WHERE uid=\"$PHP_AUTH_USER\"";
$result2 = mysql_db_query("tbdb", $query2);
$n = mysql_num_rows($result2);
if (($n == 0) && ($valid != 0)) {
$cmnd = "INSERT INTO login VALUES ('$PHP_AUTH_USER', '0')";
mysql_db_query("tbdb", $cmnd);
} else {
$row = mysql_fetch_row($result2);
if (($valid == 0) || ($row[0] < time())) {
$cmnd = "DELETE FROM login WHERE uid=\"$PHP_AUTH_USER\"";
mysql_db_query("tbdb", $cmnd);
Header("WWW-Authenticate: Basic realm=\"testbed\"");
Header("HTTP/1.0 401 Unauthorized");
die ("Authorization Failed\n");
}
}
$timeout = time() + 1800;
$cmnd = "UPDATE login SET timeout=\"$timeout\" where uid=\"$PHP_AUTH_USER\"";
mysql_db_query("tbdb", $cmnd);
}
?>
<html>
<head>
<title>Databse Index</title>
<link rel="stylesheet" href="tbstyle.css" type="text/css">
<base href="https://plastic.cs.utah.edu/testbed/" target="dynamic">
</head>
<body>
<H3 align="center">Guide to the testbed database</h3>
<p>
<A href="addusr.php3">
Add a new user
</A>
</p>
<p>
<A href="addgrp.php3">
Apply for a group
</A>
</p>
<p>
<A href="addproj.php3">
Begin a project
</A>
</p>
<p>
<A href="addexp.php3">
Begin an experiment
</A>
</p>
<p>
<A href="modify.html">
Update user information
</A>
</p>
<p>
<A href="reserved.php3">
Node status
</A>
</p>
<table cellpadding="0" cellspacing="0" width="100%"> <!--a logout button-->
<form action=index.php3 method="post" target="dynamic">
<tr><th><input type="submit" value="Logout" name="logout"></th></tr>
</form>
</table>
</body>
</html>
<html>
<head>
<title>Foo</title>
</head>
<body bgcolor="#ffffff">
<H1>Utah Testbed Machine Status</h1>
<P>
<?
mysql_connect("localhost", "webuser", "");
$query = "SELECT n.node_id, n.type, j.eid from nodes as n left join reserved AS j ON n.node_id = j.node_id";
$result = mysql_db_query("tbdb", $query);
if (!$result) {
$err = mysql_error();
echo "<H1>Could not query the database: $err</h1>\n";
exit;
}
echo "<table border=1 padding=1>\n";
echo "<tr><td><b>ID</b></td> <td><b>Type</b></td> <td><b>Reservation Status</b></td></tr>\n";
while ($r = mysql_fetch_array($result)) {
$id = $r["node_id"]; $type = $r["type"];
$res = $r["eid"];
if (!$res || $res == "NULL") {
$res = " ";
}
echo "<tr><td>$id</td> <td>$type</td> <td>$res</td></tr>\n";
}
echo "</table>\n";
?>
</body>
</html>
<?php
if (!isset($PHP_AUTH_USER) || !empty($HTTP_GET_VARS)) {
Header("WWW-Authenticate: Basic realm=\"testbed\"");
Header("HTTP/1.0 401 Unauthorized");
echo ("User authentication is required to view these pages\n");
} else {
addslashes($PHP_AUTH_USER);
$PSWD = crypt("$PHP_AUTH_PW", strlen($PHP_AUTH_USER));
$query = "SELECT * FROM users WHERE uid='$PHP_AUTH_USER' AND usr_pswd='$PSWD' AND trust_level > 0";
$result = mysql_db_query("tbdb", $query);
$valid = mysql_num_rows($result);
$query2 = "SELECT timeout FROM login WHERE uid=\"$PHP_AUTH_USER\"";
$result2 = mysql_db_query("tbdb", $query2);
$n = mysql_num_rows($result2);
if (($n == 0) && ($valid != 0)){
$cmnd = "INSERT INTO login VALUES ('$PHP_AUTH_USER', '0')";
mysql_db_query("tbdb", $cmnd);
} else {
$row = mysql_fetch_row($result2);
if (($valid == 0) || ($row[0] < time())) {
$cmnd = "DELETE FROM login WHERE uid=\"$PHP_AUTH_USER\"";
mysql_db_query("tbdb", $cmnd);
Header("WWW-Authenticate: Basic realm=\"testbed\"");
Header("HTTP/1.0 401 Unauthorized");
die ("Authorization Failed\n");
}
}
$timeout = time() + 1800;
$cmnd = "UPDATE login SET timeout=\"$timeout\" where uid=\"$PHP_AUTH_USER\"";
mysql_db_query("tbdb", $cmnd);
}
echo "
<html>
<head>
<title>Modify $uid</title>
</head>
<body>