showlogfile_sup.php3 3.77 KB
Newer Older
1 2 3
<?php
#
# EMULAB-COPYRIGHT
4
# Copyright (c) 2005, 2006, 2007 University of Utah and the Flux Group.
5 6
# All rights reserved.
#
7
require_once("Sajax.php");
8
sajax_init();
9
sajax_export("GetPNodes", "GetExpState");
10 11 12 13 14 15 16 17

# If this call is to client request function, then turn off interactive mode.
# All errors will go to above function and get reported back through the
# Sajax interface.
if (sajax_client_request()) {
    $session_interactive = 0;
}

18 19 20
#
# This will return the experiment object to the caller.
#
21
function CHECKPAGEARGS($pid, $eid) {
22
    global $this_user, $TB_EXPT_READINFO;
23

24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
    #
    # Verify page arguments.
    # 
    if (!isset($pid) ||
	strcmp($pid, "") == 0) {
	USERERROR("You must provide a Project ID.", 1);
    }
    if (!isset($eid) ||
	strcmp($eid, "") == 0) {
	USERERROR("You must provide an Experiment ID.", 1);
    }
    if (!TBvalid_pid($pid)) {
	PAGEARGERROR("Invalid project ID.");
    }
    if (!TBvalid_eid($eid)) {
	PAGEARGERROR("Invalid experiment ID.");
    }

42 43 44 45 46 47 48
    #
    # If $this_user is not set, someone got confused. 
    #
    if (!isset($this_user)) {
	TBERROR("Current user is not defined in CHECKPAGEARGS()", 1);
    }

49 50 51
    #
    # Check to make sure this is a valid PID/EID tuple.
    #
52 53
    $experiment = Experiment::LookupByPidEid($pid, $eid);
    if (! $experiment) {
54 55
	USERERROR("The experiment $pid/$eid is not a valid experiment!", 1);
    }
56
    
57 58 59
    #
    # Verify permission.
    #
60
    if (! $experiment->AccessCheck($this_user, $TB_EXPT_READINFO)) {
61 62
	USERERROR("You do not have permission to view the log for $pid/$eid!", 1);
    }
63
    return $experiment;
64 65 66 67
}

function GetPNodes($pid, $eid) {
    CHECKPAGEARGS($pid, $eid);
68

69 70 71 72 73 74 75 76 77 78 79 80 81
    $retval = array();

    $query_result = DBQueryFatal(
	"select r.node_id from reserved as r ".
	"where r.eid='$eid' and r.pid='$pid' order by LENGTH(node_id) desc");

    while ($row = mysql_fetch_array($query_result)) {
      $retval[] = $row[node_id];
    }

    return $retval;
}

82 83
function GetExpState($pid, $eid)
{
84 85
    $experiment = CHECKPAGEARGS($pid, $eid);
    $expstate   = $experiment->state();
86 87 88 89

    return $expstate;
}

90
function STARTWATCHER($experiment)
91 92 93
{
    echo "<script type='text/javascript' language='javascript'
                  src='showexp.js'></script>\n";
94

95 96 97
    $pid   = $experiment->pid();
    $eid   = $experiment->eid();
    $state = $experiment->state();
98 99 100
    
    echo "<script type='text/javascript' language='javascript'>\n";
    sajax_show_javascript();
101
    echo "StartStateChangeWatch('$pid', '$eid', '$state');\n";
102 103 104
    echo "</script>\n";
}

105
function STARTLOG($experiment)
106 107
{
    global $BASEPATH;
108 109 110
    $pid = $experiment->pid();
    $eid = $experiment->eid();
    $url = CreateURL("spewlogfile", $experiment);
111

112
    STARTWATCHER($experiment);
113

114 115 116 117
    echo "<center>\n";
    echo "<img id='busy' src='busy.gif'>
                   <span id='loading'> Working ...</span>";
    echo "</center>\n";
118 119
    echo "<br>\n";
    
120 121
    echo "<div><iframe class='outputframe' ".
	"id='outputframe' name='outputframe'></iframe></div>\n";
122

123 124 125 126 127 128 129
    echo "<script type='text/javascript' language='javascript' src='json.js'>
          </script>".
	 "<script type='text/javascript' language='javascript'
                  src='mungelog.js'>
          </script>\n";
    echo "<script type='text/javascript' language='javascript'>\n";

130
    echo "SetupOutputArea('outputframe');\n"; 
131 132 133

    echo "exp_pid = \"$pid\";\n";
    echo "exp_eid = \"$eid\";\n";
134
    echo "</script><div>
135
         <iframe id='downloader' name='downloader' width=0 height=0 src='$url'
136
                 onload='ml_handleReadyState(LOG_STATE_LOADED);'
137 138
                 border=0 frameborder=0>
         </iframe></div>\n";
139 140 141 142 143 144 145 146 147
}

# See if this request is to one of the above functions. Does not return
# if it is. Otherwise return and continue on.
sajax_handle_client_request();

#
# We return to the including script ...
#