forked from novnc/websockify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wstelnet.html
191 lines (182 loc) · 6.59 KB
/
wstelnet.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
<!DOCTYPE HTML>
<html lang="en" style="padding: 5px;">
<head>
<meta charset="ISO-8859-1">
<title>Telnet client using WebSockets</title>
<script src="include/base64.js"></script>
<script src="include/util.js"></script>
<script src="include/websock.js"></script>
<script src="include/webutil.js"></script>
<script src="include/keysym2.js"></script>
<script src="include/TANSI.js"></script>
<script src="include/wstelnet.js"></script>
<style type="text/css">
<!--
body {
font-family: Monaco,Consolas,Lucida Console,DejaVu Sans Mono,Courier New,Droid Sans Mono,monospace; background-color: #1D1D1D; color: #C0C0C0; height: 100%; width: 100%; min-width: 700px; margin: 0; padding: 0; font-size: 85%;
}
#terminal {
height: auto; width: 100%; margin: 0 auto;
}
hr {
background: 0; outline: 0; width: 100%;
}
.breakLines {
word-break: break-word; overflow-wrap: break-word; white-space: pre-wrap; overflow-x: auto;
}
* {
font-family: Monaco,Consolas,Lucida Console,DejaVu Sans Mono,Courier New,Droid Sans Mono,monospace; font-size: 100%;
}
input, textarea {
background: 0; border: 0; color: #C0C0C0; outline: 0;
}
#cmdline {
width: 100%;
height: 1.5em;
margin-top: 1px;
}
::-webkit-resizer {
display: none;
background: 0;
}
#optionsBlock {
display: block; position: fixed; top: 3px; right: 3px; color: #C0C0C0; background-color: rgba(29,29,29,0.4);
}
-->
</style>
</head>
<body>
<noscript style="color: #ff0000;">Please enable Javascript.</noscript>
<audio id="bellSound" style="display: none;">
<source src="./include/notification.mp3" type="audio/mpeg">
<source src="./include/notification.wav" type="audio/wav">
</audio>
<div style="height: 100%; width: 100%; margin: 0 auto; color: #C0C0C0; background-color: #1D1D1D;">
Host: <input id='host' style='width:100'>
Port: <input id='port' style='width:50'>
Encrypt: <input id='encrypt' type='checkbox'>
<input id='connectButton' type='button' value='Connect' style='width:100px' onclick="connect();">
<br><br>
<pre id="terminal" class="breakLines"></pre>
<hr style="border: 0; border-bottom: 1px dashed #C0C0C0;"/>
<div id="cmd">
<div id="prompt" style="float: left;">></div><div style="margin-left: 1.5em;">
<textarea name="i" id="cmdline"></textarea>
</div>
</div>
<div id="optionsBlock">
<input type="checkbox" id="beep" name="beep" value="1" /><label for="beep">Activate sounds</label><br />
<input type="checkbox" id="noClrCmd" name="noClrCmd" value="1" /><label for="noClrCmd">Don't clear input on send</label><br />
<input type="checkbox" id="breakLines" name="breakLines" value="1" checked /><label for="breakLines">Break long lines</label><br />
<input type="checkbox" id="keepAlive" name="keepAlive" value="1" /><label for="keepAlive" title="Send a line break every 295 minutes to prevent the MUD from disconnecting.">Keep alive</label><br />
<input type="checkbox" id="directPaste" name="directPaste" value="0" /><label for="directPaste" title="Send pasted content directly to MUD (rather than inserting it into the prompt).">Paste directly</label><br />
</div>
</div>
<script>
var telnet;
var timeout = 0;
var isConnected = false;
window.onbeforeunload = function (e) {
if (isConnected) {
e.preventDefault();
}
};
function connect() {
telnet.connect($D('host').value,
$D('port').value,
$D('encrypt').checked);
$D('connectButton').disabled = true;
$D('connectButton').value = "Connecting";
}
function disconnect() {
$D('connectButton').disabled = true;
$D('connectButton').value = "Disconnecting";
telnet.disconnect();
}
function connected() {
isConnected = true;
$D('connectButton').disabled = false;
$D('connectButton').value = "Disconnect";
$D('connectButton').onclick = disconnect;
}
function disconnected() {
isConnected = false;
$D('connectButton').disabled = false;
$D('connectButton').value = "Connect";
$D('connectButton').onclick = connect;
document.getElementById("cmd").innerHTML = "<span style='font-style: italic; color: #00FF00;'>Disconnected.</span><br>";
}
window.onload = function() {
var url = document.location.href;
$D('host').value = (url.match(/host=([^&#]*)/) || ['',''])[1];
$D('port').value = (url.match(/port=([^&#]*)/) || ['',''])[1];
telnet = Telnet('terminal', connected, disconnected, 'cmdline', 'prompt');
Util.addEvent(document.getElementById("noClrCmd"), 'change', telnet.toggleClr);
Util.addEvent(document.getElementById("breakLines"), 'change', () => document.getElementById("terminal").classList.toggle("breakLines"));
Util.addEvent(document.getElementById("keepAlive"), 'change', (t) => {
if (!t.target.checked) {
telnet.timeoutCallback = (() => {});
}
else {
telnet.timeoutCallback = (e => e.send("\n"));
telnet.setTimeout(60 * 60 * 295); // 295 minutes
telnet.send("\n");
}
});
document.getElementById("cmdline").addEventListener("paste", e => {
if (!document.getElementById("directPaste").checked) {
return;
}
let text = e.clipboardData.getData("text");
if (!text.length) {
return;
}
let r = text.match(/\r/g);
if (r === null) {
r = 0;
}
else {
r = r.length;
}
let n = text.match(/\n/g);
if (n === null) {
n = 0;
}
else {
n = n.length;
}
let parts = [];
if (r == n && r == 0) {
return false;
}
if (r == n) { // Windows
parts = text.split("\r\n");
}
else if (r < n) { // Linux
parts = text.split("\n");
}
else { // r > n, Mac
parts = text.split("\r");
}
for (let line of parts) {
telnet.send(line + "\n");
let tansi = telnet.getTANSI();
if (tansi._echo) {
tansi.addText(line + "\n", 1);
tansi._history.push(line);
}
}
e.preventDefault();
return true;
});
}
window.onresize = function(event) {
try {
window.clearTimeout(timeout);
} finally {
timeout = window.setTimeout(telnet.setPageSize, 300);
}
}
</script>
</body>
</html>