-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
178 lines (152 loc) · 4.72 KB
/
index.html
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
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
176
177
178
<!DOCTYPE html>
<html>
<head>
<title>Percona Training Servers</title>
<style>
.content {
margin-bottom: 50px;
}
.footer {
position: fixed;
bottom: 0px;
width: 100%;
text-align: center;
height: 30px;
padding-top: 10px;
border-top: 1px solid black;
background-color: #fff;
}
table.paleBlueRows {
width: 100%;
}
table.paleBlueRows thead {
background: #0B6FA4;
}
table.paleBlueRows thead th {
font-size: 17px;
font-weight: bold;
color: #FFFFFF;
text-align: center;
}
table.paleBlueRows tfoot td {
font-size: 14px;
}
.oddRow {
background: #D0E4F5;
}
.centered {
text-align: center;
}
span.command {
padding: 5px;
background-color: #88f;
font-family: monospace;
}
</style>
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
<script>
$(document).ready(function() {
getAndDisplayInstances();
});
function getAndDisplayInstances()
{
var urlVars = getUrlVars();
if (!("tag" in urlVars)) {
handleNoTag();
return;
}
// get servers from AWS API Gateway
$.ajax({
method: "GET",
url: "https://hdm6b3hep4.execute-api.us-east-1.amazonaws.com/prod/instances?tag=" + urlVars['tag'],
crossDomain: true,
success: function(data) {
var pTag = urlVars['tag'];
var prettyTag = pTag.replace(/[_-]/gi, " ").toUpperCase();
$("#prettyTag").text(prettyTag);
if (data.length < 1) {
$("body").append($("<p/>").text("No instances found. Check with your instructor."))
return
}
// Some globals
var tbody = $("#serverListTableBody")
var thead = $("#serverListTableHead")
var theadrow = thead.append($("<tr/>"))
var oddRow = true
// Determine which columns we need to create by examining
// first result and looking at its keys. Remove 2 fields
// because their sorting from Lambda is odd
var _columns = Object.keys(data[0]);
var columns = _columns.filter(function(e) {
return (e != "teamTag" && e != "teamId");
});
columns.sort();
// add teamId as first column
theadrow.append($("<th/>").text("Team Id"))
// add remaining columns as THs to the table
$.each(columns, function(i, o) {
theadrow.append($("<th/>").text(o).attr("colspan", "2"));
});
// Loop over data from DynamoDB and construct table.
// This data should already be in sorted teamId order from AWS Lambda
$.each(data, function(i, o) {
var pubRow = $("<tr/>")
if (oddRow) { pubRow.addClass("oddRow"); }
var privRow = $("<tr/>")
if (oddRow) { privRow.addClass("oddRow"); }
var teamTd = $("<td/>")
.attr("rowspan", "2")
.attr("class", "centered")
.text(o["teamId"])
pubRow.append(teamTd)
// Loop again over each machine type, and add ips
$.each(columns, function(j, p) {
if (p == "teamId") { return true; } // skip this one
pubRow.append($("<td/>").text("Public IP:"))
pubRow.append($("<td/>").text(o[p]["publicIp"]))
privRow.append($("<td/>").text("Internal IP:"))
privRow.append($("<td/>").text(o[p]["privateIp"]))
});
// append the created rows to the main table
tbody.append(pubRow)
tbody.append(privRow)
oddRow = (!oddRow)
});
},
error: function(xhr, e, d) {
$("body").append("p").text(xhr.responseText)
}
});
}
function handleNoTag() {
$("body").append("p").text("No tag. Check the URL provided by your instructor.")
}
function getUrlVars()
{
var vars = [], hash;
var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
for(var i = 0; i < hashes.length; i++)
{
hash = hashes[i].split('=');
vars.push(hash[0]);
vars[hash[0]] = hash[1];
}
return vars;
}
</script>
</head>
<body>
<div class="content">
<h1 style="text-align: center;" id="prettyTag"></h1>
<table class="paleBlueRows" id="serverListTable">
<thead id="serverListTableHead"></thead>
<tbody id="serverListTableBody"></tbody>
</table>
</div>
<div class="footer">
<a href="/percona_training_keys.zip" target="_blank">Download SSH Keys</a> |
Login: ec2-user |
Example: <span class="command">ssh -i Percona-Training.key [email protected]</span>
</div>
</body>
</html>