-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
171 lines (149 loc) · 5.91 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>SSH Now</title>
<script src="node_modules/xterm/lib/xterm.js"></script>
<script src="node_modules/xterm-addon-fit/lib/xterm-addon-fit.js"></script>
<script src="node_modules/local-echo/dist/local-echo.js"></script>
<link rel="stylesheet" href="node_modules/xterm/css/xterm.css" />
<style>
html {
width: 100%;
height: 100%;
padding: 0;
margin: 0;
}
body {
height: 100%;
padding: 0;
margin: 0;
background: black;
min-height: 500px;
position: relative;
}
.command {
font-family: monospace;
color: white;
max-width: 800px;
font-size: 20px;
text-align: center;
padding: 50px;
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
}
.command-main {
font-weight: bold;
}
.command-disclaimer {
margin-top: 2em;
font-size: 16px;
font-family: Tahoma, Verdana, Segoe, sans-serif;
color: #ccc;
}
#terminal {
width: 100%;
height: 100%;
}
.disclaimer {
position: absolute;
bottom: 1em;
right: 1em;
max-width: 300px;
text-align: right;
font-size: 12px;
font-family: Tahoma, Verdana, Segoe, sans-serif;
color: #ccc;
z-index: 1000000000;
}
a, a:visited {
color: #ccc;
}
a:hover, a:active {
color: white;
}
</style>
<script>
// Redirect to https if we're not local.
// (We also do this on the server side, but just for good measure.)
if ("{{LOCAL}}" === "false" && window.location.protocol === "http:") {
window.location.href = "https:" + window.location.href.substring(window.location.protocol.length);
}
let term;
let localEcho;
let dataReceivedSinceLastSend = false;
let socket;
function connectWebsocket() {
dataReceivedSinceLastSend = false;
// Extract session id from the URL (e.g. http://localhost:3000/12345)
const longSessionId = window.location.pathname.substring(1);
// Connect to websocket for the session id.
socket = new WebSocket(`{{WEBSOCKET_PROTOCOL}}://${window.location.host}/ws/${longSessionId}`);
socket.binaryType = 'arraybuffer';
function readLine() {
if (localEcho) {
localEcho.read("$ ")
.then(data => {
if (socket.readyState !== 1) {
return;
}
console.log("Sending data to server: ", data);
dataReceivedSinceLastSend = false;
socket.send(data + "\n");
setTimeout(() => {
if (!dataReceivedSinceLastSend) {
readLine();
}
}, 100);
});
}
}
// Handle incoming data from the websocket.
socket.addEventListener('message', function (event) {
dataReceivedSinceLastSend = true;
console.log("Received from server: ", event.data);
if (!term) {
// Create a new terminal instance.
term = new Terminal({ convertEol: true });
const fitAddon = new FitAddon.FitAddon();
term.loadAddon(fitAddon);
term.open(document.getElementById('terminal'));
// Make the terminal's size and geometry fit the size of #terminal
fitAddon.fit();
// And keep resizing when the window is resized.
window.addEventListener('resize', () => fitAddon.fit());
localEcho = new LocalEchoController();
term.loadAddon(localEcho);
document.querySelector(".command").style.display = "none";
}
localEcho.abortRead();
term.write(typeof event.data === 'string' ? event.data : new Uint8Array(event.data));
readLine();
});
socket.addEventListener('close', function () {
console.log("Reconnecting websocket...");
setTimeout(() => {
connectWebsocket();
}, 500);
});
}
document.addEventListener('DOMContentLoaded', function () {
connectWebsocket();
});
</script>
</head>
<body>
<div class="command">
<div class="command-main">/bin/bash -c 'while true; do SSH_NOW_SHORT_SESSION_ID={{SSH_NOW_SHORT_SESSION_ID}} PS1= PS2= /bin/bash >& /dev/tcp/{{PUBLIC_IP}}/1337 0>&1; sleep 0.1; done'</div>
<div class="command-disclaimer">
Run on the machine you want to access. Do not share publicly.<br>
<br>
<a href="https://github.com/janpaul123/ssh-now">Github</a> | <a href="https://www.youtube.com/watch?v=oAnc6Rih63I">Explainer video</a> | <a href="/faq">FAQ</a>
</div>
</div>
<div id="terminal"></div>
<div class="disclaimer"><a href="/faq">FAQ.</a> Use at your own risk. By using this website, you agree to the following. The software is provided “as is”, without warranty of any kind, express or implied. In no event shall the author of the tool be liable for any claim or other liability in connection with the software.</div>
</body>
</html>