showlogfile_sup.php3 3.6 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
18

# 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;
}

function CHECKPAGEARGS($pid, $eid) {
19
    global $this_user, $TB_EXPT_READINFO;
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
    
    #
    # 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.");
    }

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

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

function GetPNodes($pid, $eid) {
    CHECKPAGEARGS($pid, $eid);
    
    $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;
}

78
79
80
81
82
83
84
85
86
87
88
89
90
function GetExpState($pid, $eid)
{
    CHECKPAGEARGS($pid, $eid);
    
    $expstate = TBExptState($pid, $eid);

    return $expstate;
}

function STARTWATCHER($pid, $eid)
{
    echo "<script type='text/javascript' language='javascript'
                  src='showexp.js'></script>\n";
91
92

    $currentstate = TBExptState($pid, $eid);
93
94
95
    
    echo "<script type='text/javascript' language='javascript'>\n";
    sajax_show_javascript();
96
    echo "StartStateChangeWatch('$pid', '$eid', '$currentstate');\n";
97
98
99
    echo "</script>\n";
}

100
101
102
function STARTLOG($pid, $eid)
{
    global $BASEPATH;
103
104

    STARTWATCHER($pid, $eid);
105

106
107
108
109
    echo "<center>\n";
    echo "<img id='busy' src='busy.gif'>
                   <span id='loading'> Working ...</span>";
    echo "</center>\n";
110
111
112
113
114
115
116
117
118
119
120
121
    echo "<br>\n";
    
    echo "<div><iframe id='outputframe' src='busy.gif' ".
	"width=100% height=600 scrolling=auto border=4></iframe></div>\n";
    
    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";

122
    echo "SetupOutputArea('outputframe');\n"; 
123
124
125

    echo "exp_pid = \"$pid\";\n";
    echo "exp_eid = \"$eid\";\n";
126
    echo "</script><div>
127
128
129
         <iframe id='downloader' name='downloader' width=0 height=0
                 src='spewlogfile.php3?pid=$pid&eid=$eid'
                 onload='ml_handleReadyState(LOG_STATE_LOADED);'
130
131
                 border=0 frameborder=0>
         </iframe></div>\n";
132
133
134
135
136
137
138
139
140
}

# 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 ...
#