quickvm_sup.php 3.92 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
26
27
28
29
<?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)
{
    $height = ($thinheader ? 150 : 250);
    
    echo "<html>
      <head>
Leigh B Stoller's avatar
Leigh B Stoller committed
30
        <title>AptLab</title>
31
        <link rel='stylesheet' href='bootstrap/css/bootstrap.css'>
Leigh B Stoller's avatar
Leigh B Stoller committed
32
33
        <link rel='stylesheet' href='quickvm.css'>
        <script src='quickvm_sup.js'></script>
34
        <script src='date.format.js'></script>
Leigh B Stoller's avatar
Leigh B Stoller committed
35
36
        <script src='/emulab_sup.js'></script>
        <script src='https://code.jquery.com/jquery.js'></script>
37
        <script src='bootstrap/js/bootstrap.js'></script>
Leigh B Stoller's avatar
Leigh B Stoller committed
38
39
40
      </head>
    <body>
    <!-- Container for body, needed for sticky footer -->
41
42
43
44
45
46
47
    <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
48
49
50
51
52
53
54
55

}

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

Leigh B Stoller's avatar
Leigh B Stoller committed
88
89
90
91
92
#
# Spit out an info tooltip.
#
function SpitToolTip($info)
{
93
94
95
96
    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
97
98
}

Leigh B Stoller's avatar
Leigh B Stoller committed
99
100
101
102
103
104
105
106
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
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 "";
    }
}

?>