-
Notifications
You must be signed in to change notification settings - Fork 0
/
console.html
280 lines (269 loc) · 8.82 KB
/
console.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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
<!DOCTYPE html>
<html>
<head>
<title>InstantMerge-Console</title>
</head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<body>
<div style='bottom: 1em;'>
<style>
*{
background: #000;
font-family: monospace;
color: #0f0;
-webkit-font-smoothing: none;
font-size: 17px;
}
#input{outline: none;border: none;}
</style>
<pre id="log"></pre>
<label>><input id='input' autofocus'></label>
<script>
var host = 'instant-merge.herokuapp.com';
var idx=0;
buffer =[];
var el = document.getElementById('input');
el.focus();
el.onblur = function () { setTimeout(function () { el.focus(); });};
document.onkeydown = function(e) {
switch (e.keyCode) {
case 38: // up
prevCommand();
break;
case 40: // down
nextCommand();
break;
case 37: // left
el.value='';
break;
case 27: // escape - logout
el.value='';
window.location = 'http://log:out@'+Host+'/';
break;
case 13: // enter
{
if(el.value==='logout') { // logout
window.location = 'http://log:out@'+Host+'/';
break;
}
buffer.push(el.value);
ws.send("/" + el.value);
el.value="";
}
}
};
function prevCommand(){
if (idx >= buffer.length-1) idx=0;
else idx +=1;
el.value = buffer[idx];
}
function nextCommand(){
if (idx <= 0) idx=buffer.length-1;
else idx -=1;
el.value = buffer[idx];
}
(function(){
function declare(module_name, exports) {
if (typeof module != 'undefined') module.exports = exports
else window[module_name] = exports
}
function ansi2html(str) {
var props = {}
, open = false
var stylemap =
{ bold: "font-weight"
, underline: "text-decoration"
, color: "color"
, background: "background"
}
function style() {
var key, val, style = []
for (var key in props) {
val = props[key]
if (!val) continue
if (val == true) {
style.push(stylemap[key] + ':' + key)
} else {
style.push(stylemap[key] + ':' + val)
}
}
return style.join(';')
}
function tag(code) {
var i
, tag = ''
, n = ansi2html.table[code]
if (open) tag += '</span>'
open = false
if (n) {
for (i in n) props[i] = n[i]
tag += '<span style="' + style() + '">'
open = true
} else {
props = {}
}
return tag
}
return str.replace(/</g, '<').replace(/>/g, '>').replace(/\[(\d+;)?(\d+)+m/g, function(match, b1, b2) {
var i, code, res = ''
if (b2 == '' || b2 == null) b2 = '0'
for (i = 1; i < arguments.length - 2; i++) {
if (!arguments[i]) continue
code = parseInt(arguments[i])
res += tag(code)
}
return res
}) + tag()
}
/* not implemented:
* italic
* blink
* invert
* strikethrough
*/
ansi2html.table =
{ 0: null
, 1: { bold: true }
, 3: { italic: true }
, 4: { underline: true }
, 5: { blink: true }
, 6: { blink: true }
, 7: { invert: true }
, 9: { strikethrough: true }
, 23: { italic: false }
, 24: { underline: false }
, 25: { blink: false }
, 27: { invert: false }
, 29: { strikethrough: false }
, 30: { color: 'black' }
, 31: { color: 'red' }
, 32: { color: 'green' }
, 33: { color: 'yellow' }
, 34: { color: 'blue' }
, 35: { color: 'magenta' }
, 36: { color: 'cyan' }
, 37: { color: 'white' }
, 39: { color: null }
, 40: { background: 'black' }
, 41: { background: 'red' }
, 42: { background: 'green' }
, 43: { background: 'yellow' }
, 44: { background: 'blue' }
, 45: { background: 'magenta' }
, 46: { background: 'cyan' }
, 47: { background: 'white' }
, 49: { background: null }
}
declare('ansi2html', ansi2html) // ansi2html colors
})()
var h2 = window.location.hostname;
var ws = new WebSocket('wss://' + h2);
function sendCommand() {
var data = document.getElementById('console').value;
ws.send(data);
}
function ansi2html(str) {
var props = {}
, open = false
var stylemap =
{ bold: "font-weight"
, underline: "text-decoration"
, color: "color"
, background: "background"
}
}
//function keepAlive() {
// ws.send('keepAlive packet');
//}
var json;
var auth;
var wsClosed = false;
ws.addEventListener("message", function(e) {
if (e.data == "CAccepted") {
if (wsClosed == false) {
alert("Login Succesful");
if (window.localStorage.getItem('auth') == null) {
window.localStorage.setItem('auth', '{"password": "' + pass + '", "username": "' + user + '"}');
} else {
console.log("Autologged in");
}
} else if (wsClosed == true) {
var today = new Date();
var date = today.getFullYear()+'-'+(today.getMonth()+1)+'-'+today.getDate();
var time = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds();
var dateTime = date+' '+time;
var $log = document.getElementById('log');
$log.innerHTML = log.innerHTML + '\n' + dateTime + ": " + "Restarted Socket!";
}
} else if (e.data == "CDenied") {
alert("Login Failed");
var url= "/loginfail";
window.location = url;
if ((pass == "undefined") || (user == 'undefined') || (user == null) || (pass == null)) {
window.localStorage.removeItem('auth');
//window.localStorage.setItem('auth', '{"password": "' + json['password'] + '", "username": "' + json['username'] + '"}');
}
} else if (e.data == "KEEPALIVE") {
}else {
var today = new Date();
var date = today.getFullYear()+'-'+(today.getMonth()+1)+'-'+today.getDate();
var time = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds();
var dateTime = date+' '+time;
console.log("get "+e.data);
var msg = e.data;
if (msg == ">") msg='';
var $log = document.getElementById('log');
$log.innerHTML = log.innerHTML + '\n' + dateTime + ": " + e.data;
window.scrollTo(0,document.body.scrollHeight);
//setTimeout(keepAlive(), 10000);
}
});
ws.addEventListener("open", function(data) {
console.log("COnnection Opened");
var jsondata = '{"console": "true"}'
ws.send(jsondata);
});
ws.addEventListener("close", function(data) {
wsClosed = true;
//window.top.location = window.top.location;
});
var user;
var pass;
function xd() {
if ((user != null) && (pass != null)) {
var jsondata = '{"console": "true", "password": "' + pass + '", "username": "' + user + '"}'
ws.send(jsondata)
}
}
function hitCancel() {
if ((user == null) || (pass == null)) {
ws.close();
alert("Login Failed");
}
}
function keepAlive() {
ws.ping();
}
function interval() {
setInterval(hitCancel(), 100);
setInterval(keepAlive(), 1000);
}
ws.onopen = function (event) {
if (window.localStorage.getItem('auth') != null) {
auth = window.localStorage.getItem('auth');
json = JSON.parse(auth);
ws.send('{"console": "true", "password": "' + json['password'] + '", "username": "' + json['username'] + '"}');
//console.log("Autologged in!");
} else {
user = prompt("Username");
pass = prompt("Password");
setTimeout(xd(), 1000)
interval();
}
//xd()
}
setTimeout(xd(), 10000)
</script>
</form>
</body>
</html>