quickvm_sup.php 4.08 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 35
        <link rel='stylesheet' href='quickvm.css'>
        <script src='quickvm_sup.js'></script>
36
        <script src='date.format.js'></script>
Leigh B Stoller's avatar
Leigh B Stoller committed
37 38
        <script src='/emulab_sup.js'></script>
        <script src='https://code.jquery.com/jquery.js'></script>
39
        <script src='bootstrap/js/bootstrap.js'></script>
Leigh B Stoller's avatar
Leigh B Stoller committed
40
      </head>
Leigh B Stoller's avatar
Leigh B Stoller committed
41 42 43 44 45 46 47
    <body>\n";
    
    if ($TBMAINSITE && file_exists("../google-analytics.php")) {
	readfile("../google-analytics.php");
    }
    
    echo "
Leigh B Stoller's avatar
Leigh B Stoller committed
48
    <!-- Container for body, needed for sticky footer -->
49 50 51 52 53 54 55
    <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
56 57 58 59 60 61 62 63

}

function SPITFOOTER()
{
    echo "</div>
      </div>
      <!--- Footer -->
64 65 66
      <div>
       <div id='footer'>
        <div class='pull-left'>Powered by
Leigh B Stoller's avatar
Leigh B Stoller committed
67
             <img src='emulab-whiteout.png' id='elabpower'></div>
68 69
        <div class='pull-right'>&copy; 2013 The University of Utah</div>
       </div>
Leigh B Stoller's avatar
Leigh B Stoller committed
70
      </div>
71
      <!-- Placed at the end of the document so the pages load faster -->
Leigh B Stoller's avatar
Leigh B Stoller committed
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
     </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
87
function SPITAJAX_ERROR($code, $msg)
Leigh B Stoller's avatar
Leigh B Stoller committed
88 89
{
    $results = array(
Leigh B Stoller's avatar
Leigh B Stoller committed
90
	'code'  => code,
Leigh B Stoller's avatar
Leigh B Stoller committed
91 92 93 94 95
	'value' => $msg
	);
    echo json_encode($results);
}

Leigh B Stoller's avatar
Leigh B Stoller committed
96 97 98 99 100
#
# Spit out an info tooltip.
#
function SpitToolTip($info)
{
101 102 103 104
    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
105 106
}

Leigh B Stoller's avatar
Leigh B Stoller committed
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
function GateOneAuthObject($uid)
{
    #
    # We need the secret that is shared with ops.
    #
    $fp = fopen("/usr/testbed/etc/gateone.key", "r");
    if (! $fp) {
	TBERROR("Error opening /usr/testbed/etc/gateone.key", 0);
	return null;
    }
    list($api_key,$secret) = preg_split('/:/', fread($fp, 128));
    fclose($fp);
    if (!($secret && $api_key)) {
	TBERROR("Could not get kets from gateone.key", 0);
	return null;
    }
    $secret = chop($secret);

    $authobj = array(
	'api_key' => $api_key,
	'upn' => $uid,
	'timestamp' => time() . '000',
	'signature_method' => 'HMAC-SHA1',
	'api_version' => '1.0'
    );
    $authobj['signature'] = hash_hmac('sha1',
				      $authobj['api_key'] . $authobj['upn'] .
				      $authobj['timestamp'], $secret);
    $valid_json_auth_object = json_encode($authobj);

    return $valid_json_auth_object;
}

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

?>