spitnsdata.php3 2.57 KB
Newer Older
1
<?php
Leigh Stoller's avatar
Leigh Stoller committed
2 3
#
# EMULAB-COPYRIGHT
4
# Copyright (c) 2000-2003 University of Utah and the Flux Group.
Leigh Stoller's avatar
Leigh Stoller committed
5 6
# All rights reserved.
#
7 8
include("defs.php3");

9 10 11 12 13 14
#
# Only known and logged in users can begin experiments.
#
$uid = GETLOGIN();
LOGGEDINORDIE($uid);

15
#
16
# Spit back an NS file to the user. 
17
#
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
# if requesting a specific pid,eid must have permission.
#
if (isset($pid) && isset($eid)) {
    #
    # Check to make sure this is a valid PID/EID tuple.
    #
    if (! TBValidExperiment($pid, $eid)) {
	USERERROR("Experiment $eid is not a valid experiment ".
		  "in project $pid.", 1);
    }

    #
    # Verify Permission.
    #
    if (! TBExptAccessCheck($uid, $pid, $eid, $TB_EXPT_READINFO)) {
	USERERROR("You do not have permission to view the NS file for ".
		  "experiment $eid in project $pid!", 1);
    }

    #
    # Grab the NS file from the DB.
    #
    $query_result =
	DBQueryFatal("select nsfile from nsfiles ".
		     "where pid='$pid' and eid='$eid'");
    if (mysql_num_rows($query_result) == 0) {
	USERERROR("There is no NS file recorded for ".
		  "experiment $eid in project $pid!", 1);
    }
    $row    = mysql_fetch_array($query_result);
    $nsfile = stripslashes($row["nsfile"]);
    
    header("Content-Type: text/plain");
    echo "$nsfile\n";
    return;
}
54 55

#
56 57 58 59 60 61 62 63
# Otherwise:
#
# See if nsdata was provided. I think nsdata is deprecated now, and
# netbuild uses the nsref variant (LBS).
#
# See if nsref was provided. This is how the current netbuild works, by 
# uploading the nsfile with nssave.php3, to a randomly generated name in 
# /tmp. Spit that file back.
64
#
65 66 67
if (isset($nsdata) && strcmp($nsdata, "") != 0) {
    header("Content-Type: text/plain");
    echo "$nsdata";
68 69 70 71 72 73 74 75 76
} 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;
    }
77 78 79

    if (! file_exists($nsfile)) {
	PAGEHEADER("View Generated NS File");
80 81
	USERERROR("Could not find temporary file for user/guid \"" . $id .
                  "\" with id \"$nsref\".<br>\n" . 
82
	          "You likely copy-and-pasted an URL incorrectly,<br>\n" .
83 84
 		  "or you've already used the file to create an experiment" . 
                  "(thus erasing it),<br>\n" .
85
		  "or the file has expired.\n", 1 );
86
	PAGEFOOTER();
87
    } else {
88
	$fp = fopen($nsfile, "r");
89 90 91 92 93 94
	header("Content-Type: text/plain");
	$contents = fread ($fp, filesize ($nsfile));
	fclose($fp);
	echo "$contents";
    }
} else {
95
    USERERROR("No NS file provided!",1);
96 97 98
}

?>
99 100 101 102 103 104