quickvm_sup.php 4.4 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
}

107
108
109
110
111
112
113
114
#
# 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
115
{
116
117
118
119
    global $USERNODE;
	
    $file = "/usr/testbed/etc/sshauth.key";
    
Leigh B Stoller's avatar
Leigh B Stoller committed
120
121
122
    #
    # We need the secret that is shared with ops.
    #
123
    $fp = fopen($file, "r");
Leigh B Stoller's avatar
Leigh B Stoller committed
124
    if (! $fp) {
125
	TBERROR("Error opening $file", 0);
Leigh B Stoller's avatar
Leigh B Stoller committed
126
127
	return null;
    }
128
    $key = fread($fp, 128);
Leigh B Stoller's avatar
Leigh B Stoller committed
129
    fclose($fp);
130
131
    if (!$key) {
	TBERROR("Could not get key from $file", 0);
Leigh B Stoller's avatar
Leigh B Stoller committed
132
133
	return null;
    }
134
135
136
    $key   = chop($key);
    $stuff = GENHASH();
    $now   = time();
Leigh B Stoller's avatar
Leigh B Stoller committed
137
138


139
140
141
142
143
144
145
146
147
148
149
150
    $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
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
176
177
178
}

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

?>