showlogfile_sup.php3 4.5 KB
Newer Older
1 2
<?php
#
3
# Copyright (c) 2005-2014 University of Utah and the Flux Group.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
# 
# {{{EMULAB-LICENSE
# 
# This file is part of the Emulab network testbed software.
# 
# This file is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
# 
# This file is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public
# License for more details.
# 
# You should have received a copy of the GNU Affero General Public License
# along with this file.  If not, see <http://www.gnu.org/licenses/>.
# 
# }}}
23
#
24
require_once("Sajax.php");
25
sajax_init();
26
sajax_export("GetPNodes", "GetExpState");
27 28 29 30 31 32 33 34

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

35 36 37
#
# This will return the experiment object to the caller.
#
38
function CHECKPAGEARGS($pid, $eid) {
39
    global $this_user, $TB_EXPT_READINFO;
40

41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
    #
    # 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.");
    }

59 60 61 62 63 64 65
    #
    # If $this_user is not set, someone got confused. 
    #
    if (!isset($this_user)) {
	TBERROR("Current user is not defined in CHECKPAGEARGS()", 1);
    }

66 67 68
    #
    # Check to make sure this is a valid PID/EID tuple.
    #
69 70
    $experiment = Experiment::LookupByPidEid($pid, $eid);
    if (! $experiment) {
71 72
	USERERROR("The experiment $pid/$eid is not a valid experiment!", 1);
    }
73
    
74 75 76
    #
    # Verify permission.
    #
77
    if (! $experiment->AccessCheck($this_user, $TB_EXPT_READINFO)) {
78 79
	USERERROR("You do not have permission to view the log for $pid/$eid!", 1);
    }
80
    return $experiment;
81 82 83 84
}

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

86 87 88 89 90 91 92 93 94 95 96 97 98
    $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;
}

99 100
function GetExpState($pid, $eid)
{
101 102
    $experiment = CHECKPAGEARGS($pid, $eid);
    $expstate   = $experiment->state();
103 104 105 106

    return $expstate;
}

107
function STARTWATCHER($experiment)
108 109 110
{
    echo "<script type='text/javascript' language='javascript'
                  src='showexp.js'></script>\n";
111

112 113 114
    $pid   = $experiment->pid();
    $eid   = $experiment->eid();
    $state = $experiment->state();
115 116 117
    
    echo "<script type='text/javascript' language='javascript'>\n";
    sajax_show_javascript();
118
    echo "StartStateChangeWatch('$pid', '$eid', '$state');\n";
119 120 121
    echo "</script>\n";
}

122
function STARTLOG($object)
123
{
124 125 126
    if (is_a($object, 'Experiment')) {
	STARTWATCHER($object);
    }
127 128 129
    if (!is_a($object, 'Logfile')) {
	$object = $object->GetLogfile();
    }
130
    $url = CreateURL("spewlogfile", $object);
131

132 133 134 135 136 137
    #
    # If the logfile is open, put up the spinner.
    #
    if ($object->isopen()) {
	echo "<center>\n";
	echo "<img id='load_busy' src='busy.gif'>
138
                   <span id='load_loading'> Working ...</span>";
139 140 141 142 143 144 145 146 147 148 149 150 151 152
	echo "</center>\n";
	echo "<br>\n";

        echo "<script>
              function loadFinished() {
                  var busyimg     = getObjbyName('load_busy');
                  var loadingspan = getObjbyName('load_loading');

                  busyimg.style.display = 'none';
                  busyimg.src           = '1px.gif';
                  loadingspan.innerHTML = '<center><b>Done!</b></center>';
              }
              </script>\n";
    }
153
    echo "<iframe id='downloader' name='downloader'
154
                 class='downloader' src='$url'>
155
         </iframe></div>\n";
156
    echo "<script type='text/javascript' language='javascript'>\n";
157
    echo "  ShowDownLoader('downloader');\n";
158
    echo "</script>";
159 160 161 162 163 164 165 166 167
}

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