-
-
Notifications
You must be signed in to change notification settings - Fork 150
/
Copy pathhome.html
231 lines (209 loc) · 6.5 KB
/
home.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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
<!DOCTYPE html>
<html lang="en">
<head>
<title>Arduino Create Agent Debug Console</title>
<link href="https://fonts.googleapis.com/css?family=Open+Sans:400,600,700&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Roboto+Mono:400,600,700&display=swap" rel="stylesheet">
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/1.3.5/socket.io.min.js"></script>
<script type="text/javascript">
$(function() {
var socket;
var input = $('#input');
var log = document.getElementById('log');
var autoscroll = document.getElementById('autoscroll');
var listenabled = document.getElementById('list');
var messages = [];
var MESSAGES_MAX_COUNT = 2000;
function appendLog(msg) {
let jsonMsg = {};
let portListing = false;
try {
jsonMsg = JSON.parse(msg);
portsListing = jsonMsg.Ports;
} catch {
// no valid json
}
var startsWithList = msg.indexOf('list') == 0;
if (listenabled.checked || (!portsListing && !startsWithList)) {
let printMsg = msg;
if (jsonMsg.Ports) {
const validKeys = ['Name', 'SerialNumber', 'IsOpen', 'VendorID', 'ProductID'];
if (jsonMsg.Network) {
printMsg = "<b>Network Ports</b>:<br>"+JSON.stringify(jsonMsg.Ports, validKeys, 2);
} else {
printMsg = "<b>Serial Ports</b>:<br>"+JSON.stringify(jsonMsg.Ports, validKeys, 2);
}
} else if (Object.keys(jsonMsg).length !== 0) {
printMsg = JSON.stringify(jsonMsg, undefined, 2);
}
messages.push(printMsg);
if (messages.length > MESSAGES_MAX_COUNT) {
messages.shift();
}
log.innerHTML = messages.join('<br><br>');
if (autoscroll.checked) {
log.scrollTop = log.scrollHeight - log.clientHeight;
}
}
}
$('#form').submit(function(e) {
e.preventDefault();
if (!socket) {
return false;
}
if (!input.val()) {
return false;
}
socket.emit('command', input.val());
});
$('#export').click(function() {
var link = document.createElement('a');
link.setAttribute('download', 'agent-log.txt');
var text = log.innerHTML.replace(/<br>/g, '\n');
text = text.replace(/<b>|<\/b>/g, '');
link.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
link.click();
});
$('#clear').click(function() {
messages = [];
log.innerHTML = '';
});
if (window['WebSocket']) {
if (window.location.protocol === 'https:') {
socket = io('https://{{$}}')
} else {
socket = io('http://{{$}}');
}
socket.on('disconnect', function(evt) {
appendLog($('<div><b>Connection closed.</b></div>'))
});
socket.on('message', function(evt) {
appendLog(evt);
});
} else {
appendLog($('<div><b>Your browser does not support WebSockets.</b></div>'))
}
$("#input").focus();
});
</script>
<style type="text/css">
html, body {
overflow: hidden;
height: 100%;
}
body {
margin: 0px;
padding: 0px;
background: #F8F9F9;
font-size: 16px;
font-family: "Open Sans", "Lucida Grande", Lucida, Verdana, sans-serif;
}
#container {
display: flex;
flex-direction: column;
height: 100vh;
width: 100%;
}
#log {
flex-grow: 1;
font-family: "Roboto Mono", "Courier", "Lucida Grande", Verdana, sans-serif;
background-color: #DAE3E3;
height: calc(100vh - 61px);
margin: 15px 15px 10px;
padding: 8px 10px;
overflow-y: auto;
}
#footer {
display: flex;
flex-wrap: wrap;
align-items: flex-start;
justify-content: space-between;
margin: 0px 15px 0px;
}
#form {
display: flex;
flex-grow: 1;
margin-bottom: 15px;
}
#input {
flex-grow: 1;
}
#secondary-controls div {
display: inline-block;
padding: 10px 15px;
}
#autoscroll,
#list {
vertical-align: middle;
width: 20px;
height: 20px;
}
#secondary-controls button {
margin-bottom: 15px;
vertical-align: top;
}
.button {
background-color: #b5c8c9;
border: 1px solid #b5c8c9;
border-radius: 2px 2px 0 0;
box-shadow: 0 4px #95a5a6;
margin-bottom: 4px;
color: #000;
cursor: pointer;
font-size: 14px;
letter-spacing: 1.28px;
line-height: normal;
outline: none;
padding: 9px 18px;
text-align: center;
text-transform: uppercase;
transition: box-shadow .1s ease-out, transform .1s ease-out;
}
.button:hover {
box-shadow: 0 2px #95a5a6;
outline: none;
transform: translateY(2px);
}
.button:active {
box-shadow: none;
transform: translateY(4px);
}
.textfield {
background-color: #dae3e3;
width: auto;
height: auto;
padding: 10px 8px;
margin-left: 8px;
vertical-align: top;
border: none;
font-family: "Open Sans", "Lucida Grande", Lucida, Verdana, sans-serif;
font-size: 1em;
outline: none;
}
</style>
</head>
<body>
<div id="container">
<pre id="log"></pre>
<div id="footer">
<form id="form">
<input type="submit" class="button" value="Send" />
<input type="text" id="input" class="textfield" aria-label="send command" />
</form>
<div id="secondary-controls">
<div>
<input name="pause" type="checkbox" checked id="autoscroll" />
<label for="autoscroll">Autoscroll</label>
</div>
<div>
<input name="list" type="checkbox" checked id="list" />
<label for="list">Enable List Command</label>
</div>
<button id="clear" class="button">Clear Log</button>
<button id="export" class="button">Export Log</button>
</div>
</div>
</div>
</body>
</html>