Commit acbd1169 authored by Chad Barb's avatar Chad Barb

Changed /tmp file saving to be based on a randomly generated number,
not UID. This way, POSTing NSFiles from netbuild doesnt require being logged
in (since Macs dont seem to want to send the appropriate login cookies
along for the Java POST.) This should fix the Mac OS X problem.

Maintained backward compatability with old methods.
parent 3602ead9
......@@ -43,7 +43,7 @@ function SPITFORM($formfields, $errors)
{
global $TBDB_PIDLEN, $TBDB_GIDLEN, $TBDB_EIDLEN;
global $nsdata, $nsref, $projlist, $priorities, $exp_nsfile;
global $uid;
global $uid, $guid;
PAGEHEADER("Begin a Testbed Experiment");
......@@ -149,12 +149,22 @@ function SPITFORM($formfields, $errors)
View NS File</a></td>
</tr>\n";
} elseif (isset($nsref)) {
if (isset($guid)) {
echo "<tr>
<td colspan=2>*Your Auto Generated NS file: &nbsp</td>
<input type=hidden name=nsref value=$nsref>
<input type=hidden name=guid value=$guid>
<td><a target=_blank href=\"spitnsdata.php3?nsref=$nsref&guid=$guid\">
View NS File</a></td>
</tr>\n";
} else {
echo "<tr>
<td colspan=2>*Your Auto Generated NS file: &nbsp</td>
<input type=hidden name=nsref value=$nsref>
<td><a target=_blank href=spitnsdata.php3?nsref=$nsref>
View NS File</a></td>
</tr>\n";
}
}
else {
echo "<tr>
......@@ -344,6 +354,11 @@ if (isset($nsref)) {
unset($nsref);
}
if (isset($guid)) {
if (strcmp($guid, "") == 0 || !ereg("^[0-9]+$", $guid))
unset($guid);
}
#
# See if nsdata was provided. Clear it if an empty string, otherwise
# reencode it *only* if not from the form. It appears that php decodes
......@@ -554,7 +569,11 @@ elseif ($specupload) {
$nonsfile = 0;
}
elseif (isset($nsref) && strcmp($nsref, "")) {
$nsfile = "/tmp/$uid-$nsref.nsfile";
if (isset($guid)) {
$nsfile = "/tmp/$guid-$nsref.nsfile";
} else {
$nsfile = "/tmp/$uid-$nsref.nsfile";
}
$delnsfile = 1;
$nonsfile = 0;
}
......
......@@ -338,8 +338,11 @@ public class Netbuild extends java.applet.Applet
g.setPaintMode();
}
public int postIt( String s ) {
public String postIt( String s ) {
int hash = s.hashCode();
Random rand = new Random();
String randVal = String.valueOf(rand.nextInt() % 102010201);
if (hash < 0) { hash = -hash; }
if (hash == 0) { hash = 1; }
try {
......@@ -365,7 +368,8 @@ public class Netbuild extends java.applet.Applet
printout = new DataOutputStream (urlConn.getOutputStream ());
String content =
"nsdata=" + URLEncoder.encode ( s ) +
"&nsref=" + String.valueOf(hash);
"&nsref=" + String.valueOf(hash) +
"&guid=" + randVal;
printout.writeBytes (content);
printout.flush ();
printout.close ();
......@@ -380,9 +384,10 @@ public class Netbuild extends java.applet.Applet
} catch (Exception ex) {
System.out.println("exception: " + ex.getMessage());
ex.printStackTrace();
return -1;
return "posterror=1";
}
return hash;
return "nsref=" + String.valueOf(hash) +
"&guid=" + randVal;
}
......@@ -405,12 +410,12 @@ public class Netbuild extends java.applet.Applet
startAppropriatePropertiesArea(); // make sure strings are up'd
String ns = workArea.toNS();
System.out.println( ns );
int refid = postIt( ns );
String ref = postIt( ns );
//String url = getParameter("exporturl") + "?nsdata=" +
//URLEncoder.encode( ns );
//toCookie( ns );
//String url = getParameter("exporturl") + "?nsdataincookie=1";
String url = getParameter("expcreateurl") + "?nsref=" + String.valueOf(refid);
String url = getParameter("expcreateurl") + "?" + ref;
System.out.println( url );
try {
getAppletContext().showDocument( new URL( url ), "_blank" );
......
......@@ -13,8 +13,17 @@ include("defs.php3");
#
# Only known and logged in users can begin experiments.
#
$uid = GETLOGIN();
LOGGEDINORDIE($uid);
if (isset($guid) && ereg("^[0-9]+$", $guid)) {
$uid = $guid;
} else {
if (isset($uid)) {
$uid = GETLOGIN();
LOGGEDINORDIE($uid);
} else {
USERERROR( "Need to send guid or uid!" );
}
}
if (!isset($nsdata)) {
USERERROR( "Need to send NSFILE!" );
......@@ -50,10 +59,4 @@ if (! ($fp = fopen($nsfilename, "w"))) {
fwrite($fp, $nsdata);
fclose($fp);
?>
?>
\ No newline at end of file
......@@ -26,14 +26,23 @@ LOGGEDINORDIE($uid);
if (isset($nsdata) && strcmp($nsdata, "") != 0) {
header("Content-Type: text/plain");
echo "$nsdata";
} elseif (isset($nsref) && strcmp($nsref,"") != 0 && ereg("^[0-9]+$", $nsref)) {
$nsfile = "/tmp/$uid-$nsref.nsfile";
} elseif (isset($nsref) && strcmp($nsref,"") != 0 &&
ereg("^[0-9]+$", $nsref)) {
if (isset($guid) && ereg("^[0-9]+$", $guid)) {
$nsfile = "/tmp/$guid-$nsref.nsfile";
$id = $guid;
} else {
$nsfile = "/tmp/$uid-$nsref.nsfile";
$id = $uid;
}
if (! file_exists($nsfile)) {
PAGEHEADER("View Generated NS File");
USERERROR("Could not find temporary file for user \"$uid\" with id \"$nsref\".<br>\n" .
USERERROR("Could not find temporary file for user/guid \"" . $id .
"\" with id \"$nsref\".<br>\n" .
"You likely copy-and-pasted an URL incorrectly,<br>\n" .
"or you've already used the file to create an experiment (thus erasing it),<br>\n" .
"or you've already used the file to create an experiment" .
"(thus erasing it),<br>\n" .
"or the file has expired.\n", 1 );
PAGEFOOTER();
} else {
......
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