quickvm_sup.php 4.29 KB
Newer Older
Leigh B Stoller's avatar
Leigh B Stoller committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
<?php
#
# Copyright (c) 2000-2013 University of Utah and the Flux Group.
# 
# {{{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/>.
# 
# }}}
#
function SPITHEADER($thinheader = 0)
{
Leigh B Stoller's avatar
Leigh B Stoller committed
26 27
    global $TBMAINSITE;
    
Leigh B Stoller's avatar
Leigh B Stoller committed
28 29 30 31
    $height = ($thinheader ? 150 : 250);
    
    echo "<html>
      <head>
Leigh B Stoller's avatar
Leigh B Stoller committed
32
        <title>AptLab</title>
33
        <link rel='stylesheet' href='bootstrap/css/bootstrap.css'>
Leigh B Stoller's avatar
Leigh B Stoller committed
34
        <link rel='stylesheet' href='quickvm.css'>
35
	<script src='js/lib/require.js' data-main='js/main'></script>
Leigh B Stoller's avatar
Leigh B Stoller committed
36
        <script src='https://www.emulab.net/emulab_sup.js'></script>
Leigh B Stoller's avatar
Leigh B Stoller committed
37
      </head>
38
    <body style='display: none'>\n";
Leigh B Stoller's avatar
Leigh B Stoller committed
39 40 41 42 43 44
    
    if ($TBMAINSITE && file_exists("../google-analytics.php")) {
	readfile("../google-analytics.php");
    }
    
    echo "
Leigh B Stoller's avatar
Leigh B Stoller committed
45
    <!-- Container for body, needed for sticky footer -->
46 47 48 49 50 51 52
    <div id='wrap'>
      <div style='background-color: #ff6600'>
         <img class='align-center' style='width: ${height}px'
               src='aptlogo.png'/>
      </div>
     <!-- Page content -->
     <div class='container'>\n";
Leigh B Stoller's avatar
Leigh B Stoller committed
53 54 55 56 57 58 59 60

}

function SPITFOOTER()
{
    echo "</div>
      </div>
      <!--- Footer -->
61 62 63
      <div>
       <div id='footer'>
        <div class='pull-left'>Powered by
Leigh B Stoller's avatar
Leigh B Stoller committed
64
             <img src='emulab-whiteout.png' id='elabpower'></div>
65 66
        <div class='pull-right'>&copy; 2013 The University of Utah</div>
       </div>
Leigh B Stoller's avatar
Leigh B Stoller committed
67
      </div>
68
      <!-- Placed at the end of the document so the pages load faster -->
Leigh B Stoller's avatar
Leigh B Stoller committed
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
     </body></html>\n";
}

#
# Does not return; page exits.
#
function SPITAJAX_RESPONSE($value)
{
    $results = array(
	'code'  => 0,
	'value' => $value
	);
    echo json_encode($results);
}

Leigh B Stoller's avatar
Leigh B Stoller committed
84
function SPITAJAX_ERROR($code, $msg)
Leigh B Stoller's avatar
Leigh B Stoller committed
85 86
{
    $results = array(
Leigh B Stoller's avatar
Leigh B Stoller committed
87
	'code'  => code,
Leigh B Stoller's avatar
Leigh B Stoller committed
88 89 90 91 92
	'value' => $msg
	);
    echo json_encode($results);
}

Leigh B Stoller's avatar
Leigh B Stoller committed
93 94 95 96 97
#
# Spit out an info tooltip.
#
function SpitToolTip($info)
{
98 99 100 101
    echo "<a href='#' class='btn btn-xs' data-toggle='popover' ".
	"data-content='$info'> ".
        "<span class='glyphicon glyphicon-question-sign'></span> ".
        "</a>\n";
Leigh B Stoller's avatar
Leigh B Stoller committed
102 103
}

104 105 106 107 108 109 110 111
#
# Generate an authentication object to pass to the browser that
# is passed to the web server on boss. This is used to grant
# permission to the user to invoke ssh to a local node using their
# emulab generated (no passphrase) key. This is basically a clone
# of what GateOne does, but that code was a mess. 
#
function SSHAuthObject($uid, $nodeid)
Leigh B Stoller's avatar
Leigh B Stoller committed
112
{
113 114 115 116
    global $USERNODE;
	
    $file = "/usr/testbed/etc/sshauth.key";
    
Leigh B Stoller's avatar
Leigh B Stoller committed
117 118 119
    #
    # We need the secret that is shared with ops.
    #
120
    $fp = fopen($file, "r");
Leigh B Stoller's avatar
Leigh B Stoller committed
121
    if (! $fp) {
122
	TBERROR("Error opening $file", 0);
Leigh B Stoller's avatar
Leigh B Stoller committed
123 124
	return null;
    }
125
    $key = fread($fp, 128);
Leigh B Stoller's avatar
Leigh B Stoller committed
126
    fclose($fp);
127 128
    if (!$key) {
	TBERROR("Could not get key from $file", 0);
Leigh B Stoller's avatar
Leigh B Stoller committed
129 130
	return null;
    }
131 132 133
    $key   = chop($key);
    $stuff = GENHASH();
    $now   = time();
Leigh B Stoller's avatar
Leigh B Stoller committed
134 135


136 137 138 139 140 141 142 143 144 145 146 147
    $authobj = array('uid'       => $uid,
		     'stuff'     => $stuff,
		     'nodeid'    => $nodeid,
		     'timestamp' => $now,
		     'baseurl'   => "https://${USERNODE}",
		     'signature_method' => 'HMAC-SHA1',
		     'api_version' => '1.0',
		     'signature' => hash_hmac('sha1',
					      $uid . $stuff . $nodeid . $now,
					      $key),
    );
    return json_encode($authobj);
Leigh B Stoller's avatar
Leigh B Stoller committed
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
}

#
# This is a little odd; since we are using our local CM to create
# the experiment, we can just ask for the graphic directly.
#
function GetTopoMap($uid, $pid, $eid)
{
    global $TBSUEXEC_PATH;
    $xmlstuff = "";
    
    if ($fp = popen("$TBSUEXEC_PATH nobody nobody webvistopology ".
		    "-x -s $uid $pid $eid", "r")) {

	while (!feof($fp) && connection_status() == 0) {
	    $string = fgets($fp);
	    if ($string) {
		$xmlstuff .= $string;
	    }
	}
	return $xmlstuff;
    }
    else {
	return "";
    }
}

?>