Commit 4b8cbd97 authored by Leigh Stoller's avatar Leigh Stoller

Add an NS Check page for users to check their NS files. Runs a new

perl script in the bin dir, so its available as a command line program
too. The link is available from the Begin Experiment page.
parent 950a0f91
......@@ -956,6 +956,7 @@ outfiles="$outfiles Makeconf GNUmakefile \
security/GNUmakefile security/paperbag \
tbsetup/GNUmakefile tbsetup/console_setup tbsetup/mkacct-ctrl \
tbsetup/os_load tbsetup/os_setup tbsetup/mkprojdir tbsetup/power \
tbsetup/node_reboot tbsetup/webnscheck tbsetup/nscheck \
tbsetup/resetvlans tbsetup/rmacct-ctrl tbsetup/rmproj \
tbsetup/sched_reload tbsetup/reload_daemon \
tbsetup/batchexp tbsetup/killbatchexp tbsetup/batch_daemon \
......
......@@ -115,6 +115,7 @@ outfiles="$outfiles Makeconf GNUmakefile \
security/GNUmakefile security/paperbag \
tbsetup/GNUmakefile tbsetup/console_setup tbsetup/mkacct-ctrl \
tbsetup/os_load tbsetup/os_setup tbsetup/mkprojdir tbsetup/power \
tbsetup/node_reboot tbsetup/webnscheck tbsetup/nscheck \
tbsetup/resetvlans tbsetup/rmacct-ctrl tbsetup/rmproj \
tbsetup/sched_reload tbsetup/reload_daemon \
tbsetup/batchexp tbsetup/killbatchexp tbsetup/batch_daemon \
......
......@@ -12,16 +12,16 @@ SUBDIRS = checkpass ir ns2ir
BIN_STUFF = power snmpit tbend tbrun tbprerun tbreport \
os_load savevlans startexp endexp batchexp killbatchexp \
node_reboot
node_reboot nscheck
# Stuff that mere users get on plastic.
USERBINS = snmpit os_load node_reboot
USERBINS = snmpit os_load node_reboot nscheck
SBIN_STUFF = resetvlans console_setup.proxy sched_reload named_setup \
batch_daemon exports_setup reload_daemon
LIBEXEC_STUFF = mkprojdir rmproj mkacct-ctrl rmacct-ctrl \
os_setup mkexpdir console_setup \
os_setup mkexpdir console_setup webnscheck \
webstartexp webendexp webbatchexp webkillbatchexp
LIB_STUFF = libtbsetup.pm
......
#!/usr/bin/perl -wT
use English;
use Getopt::Std;
#
# Syntax check an NS file.
#
# usage: nscheck <nsfile>
#
sub usage()
{
print STDOUT "Usage: nscheck <nsfile>\n";
exit(-1);
}
my $optlist = "";
#
# Configure variables
#
my $TB = "@prefix@";
my $tbbindir = "$TB/bin/";
#
# Turn off line buffering on output
#
$| = 1;
#
# Untaint the path
#
$ENV{'PATH'} = "/bin:/usr/bin:$TB/libexec:$TB/libexec/ir".
":$TB/libexec/ns2ir:$TB/sbin:$TB/bin";
delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
$TBIRLIB = "$TB/lib/ir";
push(@INC,$TBIRLIB);
require libir;
#
# Parse command arguments. Once we return from getopts, all that should
# left are the required arguments.
#
%options = ();
if (! getopts($optlist, \%options)) {
usage();
}
if (@ARGV != 1) {
usage();
}
my $tempfile = $ARGV[0];
#
# Untaint the arguments.
#
# Note different taint check (allow /).
if ($tempfile =~ /^([-\@\w.\/]+)$/) {
$tempfile = $1;
}
else {
fatal("Tainted argument $tempfile");
}
$tbcmdfile = "tbcmds";
$id = "foo-bar";
$nsfile = "foo.ns";
$irfile = "foo.ir";
#
# Make a temp dir and copy the NS file into it. We run the scripts
# from that directory cause it writes temp files.
#
$dirname = "/tmp/parse-$$";
mkdir($dirname, 0775) or
fatal("Could not mkdir $dirname");
chdir($dirname) or
fatal("Could not chdir to $dirname");
if (system("/bin/cp", "$tempfile", "$nsfile")) {
fatal("Could not copy $tempfile to $dirname");
}
#
# Do a firstcut parse on the NS file, converting it to IR format. This
# operates as a syntax check on the NS file, so we can kick back bad NS
# files now instead of later.
#
if (system("parse.tcl $id $nsfile $irfile") != 0) {
fatal("NS Parse failed!");
}
if (system("extract_tb $nsfile $tbcmdfile") != 0) {
fatal("NS extract_tb pass failed!");
}
if (system("postparse $tbcmdfile $irfile") != 0) {
fatal("NS postparse pass failed!");
}
system("/bin/rm", "-rf", "$dirname");
exit 0;
sub fatal($)
{
my($mesg) = $_[0];
print STDOUT "$mesg\n";
system("/bin/rm", "-rf", "$dirname");
exit(-1);
}
#!/usr/bin/perl -w
use English;
#
# This gets invoked from the Web interface. Simply a wrapper ...
#
# usage: webnscheck nsfile
#
#
# Configure variables
#
my $TB = "@prefix@";
#
# Run the real thing, and never return.
#
exec "$TB/bin/nscheck", @ARGV;
die("webnscheck: Could not exec nscheck: $!");
......@@ -141,6 +141,11 @@ echo "<tr>
</form>
</table>
<p>
<center>
Please <a href="nscheck_form.php3">syntax check</a> your NS file first!
</center>
<?php
#
# Standard Testbed Footer
......
<?php
include("defs.php3");
#
# Standard Testbed Header
#
PAGEHEADER("Syntax Check and NS File");
#
# Only known and logged in users can begin experiments.
#
$uid = GETLOGIN();
LOGGEDINORDIE($uid);
#
# I am not going to allow shell experiments to be created (No NS file).
#
if (!isset($exp_nsfile) ||
strcmp($exp_nsfile, "") == 0 ||
strcmp($exp_nsfile, "none") == 0) {
USERERROR("You must supply an NS file!", 1);
}
#
# XXX
# Set the permissions on the NS file so that the scripts can get to it.
# It is owned by nobody, and most likely protected. This leaves the
# script open for a short time. A potential security hazard we should
# deal with at some point.
#
chmod($exp_nsfile, 0666);
#
# Run the script. We use a script wrapper to deal with changing
# to the proper directory and to keep most of these details out
# of this.
#
$output = array();
$retval = 0;
$result = exec("$TBSUEXEC_PATH $uid flux webnscheck $exp_nsfile",
$output, $retval);
echo "<center>";
echo "<h1>Syntax Check Results</h1>";
echo "</center>\n";
if ($retval) {
echo "<br><br><h2>
Parse Failure($retval): Output as follows:
</h2>
<br>
<XMP>\n";
for ($i = 0; $i < count($output); $i++) {
echo "$output[$i]\n";
}
echo "</XMP>\n";
die("");
}
echo "<center><br>";
echo "<img alt=\"Yippie!\" src=\"burstx.gif\">\n";
echo "<br>";
echo "<h2>Your NS file looks good!</h2>";
echo "</center>\n";
#
# Standard Testbed Footer
#
PAGEFOOTER();
?>
<?php
include("defs.php3");
#
# Standard Testbed Header
#
PAGEHEADER("Syntax Check your NS file");
#
# Only known and logged in users can begin experiments.
#
$uid = GETLOGIN();
LOGGEDINORDIE($uid);
?>
<table align="center" border="1">
<tr>
<td align="center" colspan="2">
<h1>Syntax check an NS file</h1>
</td>
</tr>
<?php
echo "<form enctype=\"multipart/form-data\"
action=\"nscheck.php3\" method=\"post\">\n";
#
# NS file upload.
#
echo "<tr>
<td>Your NS file (20K max):</td>
<td><input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"20000\">
<input type=\"file\" name=\"exp_nsfile\" size=\"30\">
</td>
</tr>\n";
?>
<tr>
<td align="center" colspan="2">
<b><input type="submit" value="Submit"></b></td>
</tr>
</form>
</table>
<?php
#
# Standard Testbed Footer
#
PAGEFOOTER();
?>
......@@ -81,7 +81,7 @@ echo "<tr>
</tr>\n";
echo "<tr>
<td colspan='2'>Why?</td>
<td colspan='2'>Why?:</td>
</tr>\n";
echo "<tr>
......
......@@ -100,7 +100,7 @@ function SHOWPROJECT($pid, $thisuid) {
echo "</tr>\n";
echo "<tr>
<td colspan='2'>Why?</td>
<td colspan='2'>Why?:</td>
</tr>\n";
echo "<tr>
......
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