Commit d3ef76bc authored by Chad Barb's avatar Chad Barb

Changed netbuild to use POST, rather than GET.
This should alleviate some of the truncation problems we've been having, and
also is a bit cleaner looking to the client.

The applet posts to nssave.php3, which writes the ns file to /tmp/$uid-$hash.nsfile
The applet then launches beginexp/php3 in a new browser window, passing it the $hash.
It can then pass that $hash to spitnsdata.php3, or build "/tmp/$uid-$hash.nsfile"
as $nsfile (the NS file to use in expt creation.)

There are, as of yet, no file size restrictions, nor is there a mechanism to clean up
old nsfiles (which really only need to stick around for a short while, <<1hr.)
parent a9be8e45
......@@ -37,7 +37,7 @@ function RESPIT($tag, $value)
function SPITFORM($formfields, $errors)
{
global $TBDB_PIDLEN, $TBDB_GIDLEN, $TBDB_EIDLEN;
global $nsdata, $projlist, $priorities, $exp_nsfile;
global $nsdata, $nsref, $projlist, $priorities, $exp_nsfile;
global $uid;
PAGEHEADER("Begin a Testbed Experiment");
......@@ -137,6 +137,13 @@ function SPITFORM($formfields, $errors)
<td><a target=_blank href=spitnsdata.php3?nsdata=$nsdata>
View NS File</a></td>
</tr>\n";
} elseif (isset($nsref)) {
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>
......@@ -324,12 +331,18 @@ function SPITFORM($formfields, $errors)
</blockquote>\n";
}
if (isset($nsref)) {
if (strcmp($nsref, "") == 0 || !ereg("^[0-9]+$", $nsref))
unset($nsref);
}
#
# 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
# it for you when it comes in as GET argument, but leaves it encoded
# when its a POST argument.
#
if (isset($nsdata)) {
if (strcmp($nsdata, "") == 0)
unset($nsdata);
......@@ -532,6 +545,11 @@ elseif ($specupload) {
$nsfile = $exp_nsfile;
$nonsfile = 0;
}
elseif (isset($nsref) && strcmp($nsref, "")) {
$nsfile = "/tmp/$uid-$nsref.nsfile";
$delnsfile = 1;
$nonsfile = 0;
}
elseif (isset($nsdata) && strcmp($nsdata, "")) {
#
# The NS file is encoded in the URL. Must create a temp file
......
......@@ -15,9 +15,11 @@
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import java.lang.*;
import java.net.*;
//import netscape.javascript.*;
//import java.io.*;
public class Netbuild extends java.applet.Applet
......@@ -336,13 +338,79 @@ public class Netbuild extends java.applet.Applet
g.setPaintMode();
}
public int postIt( String s ) {
int hash = s.hashCode();
if (hash < 0) { hash = -hash; }
if (hash == 0) { hash = 1; }
try {
URL url;
URLConnection urlConn;
DataOutputStream printout;
DataInputStream input;
// URL of CGI-Bin script.
//url = new URL (getCodeBase().toString() + "env.tcgi");
url = new URL ( getParameter("exporturl") );
// URL connection channel.
urlConn = url.openConnection();
// Let the run-time system (RTS) know that we want input.
urlConn.setDoInput (true);
// Let the RTS know that we want to do output.
urlConn.setDoOutput (true);
// No caching, we want the real thing.
urlConn.setUseCaches (false);
// Specify the content type.
urlConn.setRequestProperty("Content-Type",
"application/x-www-form-urlencoded");
// Send POST output.
printout = new DataOutputStream (urlConn.getOutputStream ());
String content =
"nsdata=" + URLEncoder.encode ( s ) +
"&nsref=" + String.valueOf(hash);
printout.writeBytes (content);
printout.flush ();
printout.close ();
// Get response data.
input = new DataInputStream (urlConn.getInputStream ());
String str;
while (null != ((str = input.readLine()))) {
System.out.println (str);
}
input.close();
} catch (Exception ex) {
System.out.println("exception: " + ex.getMessage());
ex.printStackTrace();
return -1;
}
return hash;
}
// public void toCookie( String s ) {
// java.util.Calendar c = java.util.Calendar.getInstance();
// c.add(java.util.Calendar.MONTH, 1);
// String expires = "; expires=" + c.getTime().toString();
// String s1 = s + expires;
// System.out.println(s1);
// JSObject myBrowser = JSObject.getWindow(this);
// JSObject myDocument = (JSObject) myBrowser.getMember("document");
// myDocument.setMember("cookie", s1);
//}
public void actionPerformed( ActionEvent e ) {
if (e.getSource() == exportButton) {
startAppropriatePropertiesArea(); // make sure strings are up'd
String ns = workArea.toNS();
System.out.println( ns );
String url = getParameter("exporturl") + "?nsdata=" +
URLEncoder.encode( ns );
System.out.println( ns );
int refid = 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);
System.out.println( url );
try {
getAppletContext().showDocument( new URL( url ), "_blank" );
......
......@@ -19,8 +19,10 @@ chdir("buildui");
?>
<applet code="Netbuild.class" width=800 height=600>
<applet code="Netbuild.class" width=800 height=600 MAYSCRIPT>
<param name=exporturl
value="<?php echo $TBBASE?>/buildui/nssave.php3">
<param name=expcreateurl
value="<?php echo $TBBASE?>/beginexp.php3">
<pre>
We're sorry, NetBuild in unable to run,
......
<?php
chdir("..");
include("defs.php3");
# this is just saving data; it isnt human readable.
#
# Only known and logged in users can begin experiments.
#
$uid = GETLOGIN();
LOGGEDINORDIE($uid);
if (!isset($nsdata)) {
ERROR( "Need to send NSFILE!" );
}
if (!isset($nsref) || !ereg("^[0-9]+$", $nsref)) {
ERROR( "Need to send valid NSREF!" );
}
#if (isset($nsdata)) {
# if (strcmp($nsdata, "") == 0)
# unset($nsdata);
# elseif (! isset($submit))
# $nsdata = rawurlencode($nsdata);
#}
#$nsfile_safe = addslashes($nsdata);
#$nsref_safe = addslashes($nsref);
#DBQueryFatal("INSERT INTO nsfiles_transient ".
# "(nsfileid, time, uid, nsfile) ".
# "VALUES ('$nsref_safe', now(), '$uid', '$nsfile_safe') " );
#echo "INSERT INTO nsfiles_transient ".
# "(nsfileid, time, uid, nsfile) ".
# "VALUES ('$nsref_safe', now(), '$uid', '$nsfile_safe') ";
$nsfilename = "/tmp/$uid-$nsref.nsfile";
if (! ($fp = fopen($nsfilename, "w"))) {
TBERROR("Could not create temporary file $nsfile", 1);
}
fwrite($fp, $nsdata);
fclose($fp);
?>
<?php
include("defs.php3");
#
# Only known and logged in users can begin experiments.
#
$uid = GETLOGIN();
LOGGEDINORDIE($uid);
#
# Spit back an NS file to the user. It comes in as an urlencoded argument
# and we send it back as plain text so that user can write it out. This
......@@ -11,12 +17,28 @@ include("defs.php3");
#
# See if nsdata was provided.
#
if (!isset($nsdata) ||
strcmp($nsdata, "") == 0) {
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";
if (! ($fp = fopen($nsfile, "r"))) {
TBERROR("Could not read temporary file $nsfile", 1);
} else {
header("Content-Type: text/plain");
$contents = fread ($fp, filesize ($nsfile));
fclose($fp);
echo "$contents";
}
} else {
PAGEERROR("No NS file provided!");
}
header("Content-Type: text/plain");
echo "$nsdata";
?>
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