-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathterminal.js
513 lines (465 loc) · 19.2 KB
/
terminal.js
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
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
var con = 0;
function getOS() {
var userAgent = window.navigator.userAgent,
platform = window.navigator.platform,
macosPlatforms = ['Macintosh',
'MacIntel',
'MacPPC',
'Mac68K'],
windowsPlatforms = ['Win32',
'Win64',
'Windows',
'WinCE'],
iosPlatforms = ['iPhone',
'iPad',
'iPod'],
os = null;
if (macosPlatforms.indexOf(platform) !== -1) {
os = 'Mac OS';
} else if (iosPlatforms.indexOf(platform) !== -1) {
os = 'iOS';
} else if (windowsPlatforms.indexOf(platform) !== -1) {
os = 'Windows';
} else if (/Android/.test(userAgent)) {
os = 'Android';
} else if (!os && /Linux/.test(platform)) {
os = 'Linux';
}
return os;
}
os = getOS();
var os, os_v;
try {
var userAgent = window.navigator.userAgent,
platform = window.navigator.platform,
macosPlatforms = ['Macintosh',
'MacIntel',
'MacPPC',
'Mac68K'],
windowsPlatforms = ['Win32',
'Win64',
'Windows',
'WinCE'],
iosPlatforms = ['iPhone',
'iPad',
'iPod'];
if (/Android/.test(userAgent)) {
function getAndroidVersion(ua) {
var ua = (ua || navigator.userAgent).toLowerCase();
var match = ua.match(/android\s([0-9\.]*)/i);
return match ? match[1]: undefined;
}
os_v = "Android "+ getAndroidVersion();
} else if (iosPlatforms.indexOf(platform) !== -1) {
os_v = getOS()+iOSversion();
function iOSversion() {
if (/iP(hone|od|ad)/.test(navigator.platform)) {
var v = (navigator.appVersion).match(/OS (\d+)_(\d+)_?(\d+)?/);
return [parseInt(v[1], 10),
parseInt(v[2], 10),
parseInt(v[3] || 0, 10)];
}
}
} else if (navigator.appVersion.indexOf("Windows ")!=-1) {
os_v = getWindowsOS();
function getWindowsOS() {
if (navigator.appVersion.indexOf("Windows NT 10.")!=-1) {
return 'Windows 10';
} else if (navigator.appVersion.indexOf("Windows NT 6.3")!=-1) {
return "Windows 8.1";
} else if (navigator.appVersion.indexOf("Windows NT 6.2")!=-1) {
return "Windows 8";
} else if (navigator.appVersion.indexOf("Windows NT 6.1")!=-1) {
return "Windows 7";
} else if (navigator.appVersion.indexOf("Windows NT 6.0")!=-1) {
return "Windows Vista";
} else if (navigator.appVersion.indexOf("Windows NT 5.2")!=-1) {
return "Windows Server 2003; Windows XP x64 Edition";
} else if (navigator.appVersion.indexOf("Windows NT 5.1")!=-1) {
return "Windows XP";
} else if (navigator.appVersion.indexOf("Windows NT 5.01")!=-1) {
return "Windows 2000, Service Pack 1 (SP1)";
} else if (navigator.appVersion.indexOf("Windows NT 5.0")!=-1) {
return "Windows 2000";
} else if (navigator.appVersion.indexOf("Windows NT 4.0")!=-1) {
return "Windows NT 4.0";
} else if (navigator.appVersion.indexOf("Windows 98; Win 9x 4.90")!=-1) {
return "Windows Millennium Edition (Windows Me)";
} else if (navigator.appVersion.indexOf("Windows 98")!=-1) {
return "Windows 98";
} else if (navigator.appVersion.indexOf("Windows 95")!=-1) {
return "Windows 95";
} else if (navigator.appVersion.indexOf("Windows CE")!=-1) {
return "Windows CE";
} else {
return "Windows OS, Version:Unknown";
}
}
}
}
catch {
os_v = undefined;
}
var mat = false;
function haltmatrix() {
var canvas = document.querySelector('canvas'),
ctx = canvas.getContext('2d');
canvas.width = 0;
canvas.height = 0;
}
var conp = false;
function matrix() {
var canvas = document.querySelector('canvas'),
ctx = canvas.getContext('2d');
canvas.width = document.body.clientWidth;
canvas.height = document.body.clientHeight;
var letters = '1010';
letters = letters.split('');
var fontSize = 20,
columns = canvas.width / fontSize;
var drops = [];
for (var i = 0; i < columns; i++) {
drops[i] = 1;
}
function draw() {
ctx.fillStyle = 'rgba(0, 0, 0, .1)';
ctx.fillRect(0, 0, canvas.width, canvas.height);
for (var i = 0; i < drops.length; i++) {
var text = letters[Math.floor(Math.random() * letters.length)];
ctx.fillStyle = color();
ctx.fillText(text, (i)* fontSize, drops[i] * fontSize);
drops[i]++;
if (drops[i] * fontSize > canvas.height && Math.random() > .95) {
drops[i] = 0;
}
}
}
function color() {
var colors = ['#ff6666',
'#ff8c66',
'#ffb366',
'#ffd966',
'#ffff66',
'#d9ff66',
'#b3ff66',
'#66ff66',
'#66ff8c',
'#66b3ff',
'#66ffd9',
'#66ffff',
'#66d9ff',
'#668cff',
'#6666ff',
'#8c66ff',
'#b366ff',
'#d966ff',
'#ff66ff',
'#ff66d9',
'#ff66b3',
'#ff668c',
'#ff6666'];
return (colors[Math.floor(Math.random() * colors.length)]);
}
setInterval(draw, 33);
if (conp == true) {
document.getElementById("user-input").style.visibility = "hidden";
} else {
document.getElementById("user-input").style.visibility = "visible";
document.getElementById("user-input").focus();
}
}
var text,
prev,
temp,
c,
d,
b;
prev = "";
c = 0;
var name = "[snehil]~";
d = name+ "$ ";
b = d.toLowerCase();
var x;
function init() {
x = "Type \'<g>list</g>\' to get all command supported.<br>";
text = document.getElementById("user-input");
text.value = d;
text.addEventListener('keypress',
count);
text.addEventListener('keyup',
whenPressed);
text.addEventListener('keydown',
whenDown);
if (text.value != d) {
document.querySelector('body').innerHTML = "<o><b>ERROR</b></o>"
}
if (conp == true) {
document.getElementById("user-input").style.visibility = "hidden";
}
}
function count(e) {
c++;
}
function whenPressed(e) {
if (e.keyCode == 8) {
c--;
if (c < 0) {
text.value = d;
}
}
if (text.value == "") {
text.value = d;
}
}
function whenDown(e) {
temp = text.value;
if (e.keyCode == 13) {
while (true) {
if (temp != d) {
if ((temp.substring(temp.length - 1) == " ") && (temp != d+"echo ")) {
prev = temp.substring(0, (temp.length-1));
temp = prev;
} else {
prev = text.value;
temp = prev;
}
if ((temp.substring(temp.length - 1) == " ") && (temp != d+"echo ")) {
continue;
} else
break;
} else
prev = text.value;
break;
}
prev = prev.replace (/&/g, "&");
prev = prev.replace (/</g, "<");
prev = prev.replace (/>/g, ">");
e.preventDefault();
text.value = d;
document.getElementById('out').innerHTML += prev+"<br>";
var ags = (prev.substring(b.length)).split(";");
if (conp == true) {
setTimeout(function() {
return ags.forEach(command);
}, 5000);
} else {
return ags.forEach(command);
}
}
}
function load() {
document.getElementById('out').innerHTML = "<c>@root</c>\u2015[terminal]<br><w>"+x+"</w>";
}
function command(p, l) {
if (conp == true) {
document.getElementById("user-input").style.visibility = "hidden";
}
p = p.trim();
//console.log(p);
temp = p;
if ((p.toLowerCase() == p) || (p.toUpperCase() == p)) {
temp = p.toLowerCase();
} else if ((((p.toLowerCase()) != p)) || ((p.toUpperCase()) != p)) {
temp = p.toLowerCase();
} else {
temp = "e";
}
temp = temp.trim();
var ecnt = 0;
today = new Date();
if (temp == "cls\\?") {
document.getElementById('out').innerHTML += "<y>USES: </y><w>CLEARS THE TERMINAL SCREEN</w><br>";
} else if (temp == "cls") {
if (conp == false) {
x = "";
p = "";
return load();
} else {
document.getElementById('out').innerHTML += "<o>ERROR: </o><w> CANNOT CLEAR SCREEN CONNECTION IN PROGRESS</w><br>";
}
} else if (temp == "network\\gateway") {
if (navigator.onLine == true) {
document.getElementById('out').innerHTML += "<y>GATEWAY ADDRESS: </y>";
return gip();
} else
document.getElementById('out').innerHTML += "<o>ERROR: </o><w>YOU ARE NOT CONNECTED TO INTERNET</w><br>";
} else if (temp == "network\\ip") {
if (navigator.onLine == true) {
document.getElementById("user-input").style.visibility = "hidden";
document.getElementById('out').innerHTML += "<y>PUBLIC IP: </y>";
setTimeout(function () {
document.getElementById("user-input").style.visibility = "visible";
document.getElementById("user-input").focus();
}, 2500);
return ip();
} else
document.getElementById('out').innerHTML += "<o>ERROR: </o><w>YOU ARE NOT CONNECTED TO INTERNET</w><br>";
} else if (temp == "connect\\?") {
document.getElementById('out').innerHTML += "<y>USES:</y><w> SHOWS A PROGRESS BAR UI </w><br>";
} else if (temp == "connect") {
con++;
if (conp == false) {
conp = true;
document.getElementById('out').innerHTML += "<w>Connecting to nearest server...<br><lsk id =\"pbar"+con.toString()+"\">hi</lsk></w><br>";
return connect(con);
} else {
document.getElementById('out').innerHTML += "<o>ERROR: </o><w>CONNECT IS ALREADY RUNNING</w><br>";
}
} else if (temp == "system\\res") {
var sW = window.screen.width*window.devicePixelRatio;
var sH = window.screen.height*window.devicePixelRatio;
document.getElementById('out').innerHTML += "<y>HEIGHT :<w>" + sH.toString() + " px<br></w>WIDTH :</y><w>" + sW.toString() + " px<br></w>";
} else if ((temp == "engage")) {
if (mat == false) {
mat = true;
document.getElementById("user-input").style.visibility = "hidden";
setTimeout(function () {
return matrix();
}, 1500);
} else {
document.getElementById('out').innerHTML += "<o>ERROR: </o><w>ENGAGE IS ALREADY RUNNING</w><br>";
}
} else if (temp == "echo\\?") {
document.getElementById('out').innerHTML += "<y>USES: </y><w>PRINTS THE TEXT WRITTEN</w><br>";
} else if (temp.substring(0, 4) == "echo") {
document.getElementById('out').innerHTML += "<w>"+p.substring(4)+"</w><br>";
} else if (temp == "system\\date") {
document.getElementById('out').innerHTML += "<y>DATE: </y><w>"+today.getDate()+'-'+(today.getMonth()+1)+'-'+today.getFullYear()+"</w><br>";
} else if (temp == "system\\time") {
document.getElementById('out').innerHTML += "<y>TIME: </y><w>"+today.getHours() + ": " + today.getMinutes() + ": " + today.getSeconds()+"</w><br>";
} else if (temp == "terminal\\v") {
document.getElementById('out').innerHTML += "<y>TERMINAL VERSION: </y><w>"+v+"</w><br>";
} else if (temp == "engage\\abort") {
if (mat == true) {
mat = false;
return haltmatrix();
} else
document.getElementById('out').innerHTML += "<o>ERROR: </o><w>ENGAGE COMMAND IS NOT RUNNING</w><br>";
} else if (temp == "network\\?") {
document.getElementById('out').innerHTML += "<y>USES: </y><w>IT DOES THE FOLLOWING COMMANDS: <br></w> \\gateway :<w>TELLS YOUR GATEWAY ADDRESS</w><br> \\ip :<w>TELLS YOUR PUBLIC IP</w><br> \\isp :<w>TELLS YOUR INTERNET SERVICE PROVIDER</w><br>";
} else if (temp == "engage\\?") {
document.getElementById('out').innerHTML += "<y>USES: </y><w>TRANSFORMS THE TERMINAL INTO A MATRIX-INSPIRED DISPLAY WHERE SYMBOLS ARE RAINING FROM THE TOP OF THE SCREEN IN DIFFERENT COLORS</w><br> <y>SUB-COMMANDS:</y><br> \\abort : <w>ABORT ENGAGE COMMAND</w><br>";
} else if (temp == "list\\?") {
document.getElementById('out').innerHTML += "<y>USES: </y><w>LISTS ALL THE SUPPORTED COMMANDS</w><br>";
} else if (temp == "list") {
document.getElementById('out').innerHTML += "<g>list :<w>LISTS ALL THE SUPPORTED COMMANDS</w><br>terminal :<w>STARTS A NEW TERMINAL</w><br>cls :<w>CLEARS THE TERMINAL SCREEN</w><br><g>connect :<w>THIS SHOWS A PROGRESS BAR UI</w><br>engage :<w>TRANSFORMS THE TERMINAL INTO A MATRIX-INSPIRED DISPLAY WHERE SYMBOLS ARE RAINING FROM THE TOP OF THE SCREEN IN DIFFERENT COLORS</w><br>network :<w>CONTAINS SUB COMMAND RELATED TO NETWORK</w><br>system :<w>CONTAINS SUB COMMAND RELATED TO SYSTEM</w><br>echo <w>text</w>:<w>PRINTS THE TEXT WRITTEN</w><br></g><w> <br>PUT \'<y>\\?</y>\' AFTER ANY COMMAND TO KNOW ABOUT IT</w><br>";
} else if (temp == "system\\?") {
document.getElementById('out').innerHTML += "<y>USES: </y><w>IT DOES THE FOLLOWING COMMANDS: <br></w> \\time : <w>TELLS SYSTEM TIME</w><br> \\date   : <w>TELLS SYSTEM DATE</w><br> \\platform: <w>TELLS YOUR DEVICE'S OPERATING SYSTEM</w><br> \\version :<w>TELLS YOUR DEVICE'S VERSION</w><br> \\res :<w>TELLS YOUR DEVICE'S SCREEN RESOLUTION</w><br> \\battery :<w>TELLS YOUR DEVICE'S BATTERY STATUS AND LEVEL</w><br>";
} else if (temp == "terminal") {
x = "Type \'<g>list</g>\' to get all command supported.<br>";
load();
} else if (temp == "system\\platform") {
document.getElementById('out').innerHTML += "<y>DEVICE PLATFORM:</y> <w>"+os+"</y><br>";
} else if (temp == "system\\version") {
document.getElementById('out').innerHTML += "<y>DEVICE VERSION:</y> <w>"+os_v+"</w><br>"
} else if (temp == "network") {
document.getElementById('out').innerHTML += "<o>ERROR:</o><w>THIS COMMAND HAS SOME SUB COMMANDS TO LEARN ABOUT THEM TYPE '</w>network\\?<w>'</w><br>";
} else if (temp == "system") {
document.getElementById('out').innerHTML += "<o>ERROR:</o><w>THIS COMMAND HAS SOME SUB COMMANDS TO LEARN ABOUT THEM TYPE '</w>system\\?<w>'</w><br>";
} else if (p == "network\\isp") {
document.getElementById('out').innerHTML += "<y>ISP: </y>";
document.getElementById("user-input").style.visibility = "hidden";
setTimeout(function () {
document.getElementById("user-input").style.visibility = "visible";
document.getElementById("user-input").focus();
}, 2500);
return isp();
} else if (p == "terminal\\?") {
document.getElementById('out').innerHTML += "<y>USES:</y><w> STARTS A NEW TERMINAL<br><y>SUB-COMMANDS:</y><br> <g>\\rn</g>:TO GET TERMINAL RELEASE NOTES ON <a href=\"https://github.com/Uthando993\" style=\"text-decoration:none;color:cyan\">GitHub</a><br> <g>\\v</g> :TO GET TERMINAL VERSION";
} else if (p == "system\\battery") {
return batt();
} else if (p == "terminal\\rn") {
location.assign('https://github.com/Uthando993/Terminal/blob/main/release%20notes.md');
document.getElementById('out').innerHTML += "<w>PLEASE CLICK OK IF IT ASK FOR REDIRECT MESSAGE... "
} else if (p == "") {
//no condition
} else {
if (conp == true) {
document.getElementById("user-input").style.visibility = "hidden";
}
document.getElementById('out').innerHTML += "<o>ERROR: </o><w>ILLEGAL COMMAND \'</w>"+p+"<w>\' AT COMMAND POSITION "+l+"</w><br>";
}
if (conp == true) {
document.getElementById("user-input").style.visibility = "hidden";
}
}
function gip() {
var one = window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection;
var two = new one({
iceServers: []});
var nullfn = function() {};
two.createDataChannel("");
two.createOffer(two.setLocalDescription.bind(two),
nullfn);
two.onicecandidate = function(obj) {
var regex = /([0-9]{1,3}(\.[0-9]{1,3}){3}|[a-f0-9]{1,4}(: [a-f0-9]{1,4}){7})/;
var candidates = obj.candidate.candidate.match(regex);
document.querySelector("#out").innerHTML += "<w>"+candidates[1]+"</w><br>";
two.onicecandidate = nullfn;
}
}
function ip() {
let ip = "";
fetch('https://api.ipify.org?format=json')
.then(res => res.json())
.then(function (json) {
var x = "";
x = json.ip;
document.getElementById('out').innerHTML += "<w>"+x+"</w><br>";
});
}
function connect(y) {
var pbar,
bars = bar = "|||";
var count = 0;
var idel = "#pbar"+y.toString();
var t = setInterval(function() {
count = (count < 100)? count+1: 100;
if (count == 0)
bars = bar;
else if ((count%5 == 0) && (count != 100))
bars += bar;
document.querySelector(idel). innerHTML = `<r><lsk>${bars}</r></lsk><iv>${count}%</iv>`;
if (count == 100) {
conp = false;
document.querySelector(idel). innerHTML += `<w><br>Connected Successfully...</w>`;
document.getElementById("user-input").style.visibility = "visible";
document.getElementById("user-input").focus();
return clearTimeout(t);
} else
document.getElementById("user-input").style.visibility = "hidden";
},
100);
}
function isp() {
let ok = "";
$.ajax({
type: 'GET',
dataType: 'json',
url: 'http://ip-api.com/json?callback=?',
success: function(data) {
ok = JSON.stringify(data["isp"]);
document.getElementById('out').innerHTML += "<w>"+ok.replace(/\"/g, "")+"</w><br>";
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
document.getElementById('out').innerHTML += "<w>undefined</w><br>";
}
});
}
function batt() {
if ('getBattery' in navigator) {
navigator.getBattery().then(function(battery) {
document.getElementById('out').innerHTML += "<y>BATTERY LEVEL : </y><w>" + Math.round(battery.level* 100) + "%</w><br>";
});
navigator.getBattery().then(function(battery) {
if (battery.charging) {
document.getElementById('out').innerHTML += "<y>CHARGING STATUS: <y><w>CHARGING</w><br>";
} else {
document.getElementById('out').innerHTML += "<y>CHARGING STATUS: <y><w>NOT CHARGING</w><br>";
}
});
} else {
document.getElementById('out').innerHTML += "<w>THIS API FUNCTION IS NOT SUPPORTED ON THIS BROWSER</w>";
}
}
var v = "v.2.2";