quickvm_sup.php 3.73 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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
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
<?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>
        <title>AptLab.io - SSH</title>
        <!-- UIKit -->
        <link rel='stylesheet' href='uikit/css/uikit.almost-flat.css'>
        <link rel='stylesheet' href='quickvm.css'>
        <script src='gateone.js'></script>
        <script src='quickvm_sup.js'></script>
        <script src='/emulab_sup.js'></script>
        <script src='https://code.jquery.com/jquery.js'></script>
        <script src='uikit/js/uikit.js'></script>
      </head>
    <body>
    <!-- Container for body, needed for sticky footer -->
    <div id='bodycontainer'>
    <div id='bodycontent'>
    <div class='uk-width-100 uk-container-center'
         style='background-color: #ff6600'>
        <img class='uk-align-center' style='width: ${height}px'
             src='aptlogo.png'/>
    </div>\n";

}

function SPITFOOTER()
{
    echo "</div>
      </div>
      <!--- Footer -->
      <div id='footer' class='uk-width-100' style='background-color: #ff6600;'>
        <div class='uk-align-left'>Powered by
             <img src='emulab-whiteout.png' id='elabpower'></div>
        <div class='uk-align-right'>&copy; 2013 The University of Utah</div>
        </div>
      </div>
     </body></html>\n";
}

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

function SPITAJAX_ERROR($msg)
{
    $results = array(
	'code'  => 1,
	'value' => $msg
	);
    echo json_encode($results);
    exit();
}

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

?>