| 1 | <!DOCTYPE html> |
| 2 | <html dir="ltr" xmlns="http://www.w3.org/1999/xhtml"> |
| 3 | <head lang="en"> |
| 4 | <meta http-equiv="X-UA-Compatible" content="IE=edge" /> |
| 5 | <meta content="text/html;charset=utf-8" http-equiv="Content-Type" /> |
| 6 | <meta name="viewport" content="user-scalable=1.0,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0" /> |
| 7 | <meta name="apple-mobile-web-app-capable" content="yes" /> |
| 8 | <meta name="format-detection" content="telephone=no" /> |
| 9 | <meta name="robots" content="noindex,nofollow"> |
| 10 | <link type="text/css" href="styles/style.css" media="screen" rel="stylesheet" title="CSS" /> |
| 11 | <link type="text/css" href="styles/xterm.css" media="screen" rel="stylesheet" title="CSS" /> |
| 12 | {{{customCSSTags}}} |
| 13 | <link rel="apple-touch-icon" href="/favicon-303x303.png" /> |
| 14 | <script type="text/javascript" src="scripts/common-0.0.1{{min}}.js"></script> |
| 15 | <script type="text/javascript" src="scripts/meshcentral{{min}}.js"></script> |
| 16 | <script type="text/javascript" src="scripts/agent-redir-ws-0.1.1{{min}}.js"></script> |
| 17 | <script type="text/javascript" src="scripts/agent-redir-rtc-0.1.0{{min}}.js"></script> |
| 18 | <script type="text/javascript" src="scripts/xterm-min.js"></script> |
| 19 | <script type="text/javascript" src="scripts/xterm-addon-fit-min.js"></script> |
| 20 | <script type="text/javascript" src="scripts/xterm-addon-image-min.js"></script> |
| 21 | {{{customJSTags}}} |
| 22 | <title>SSH</title> |
| 23 | </head> |
| 24 | <body style="overflow:hidden;background-color:black" onload="start()"> |
| 25 | <div id=p11 class="noselect" style="overflow:hidden"> |
| 26 | <div id=deskarea0 style="position:relative"> |
| 27 | <div id=deskarea1 class="areaHead"> |
| 28 | <div class="toright2"> |
| 29 | </div> |
| 30 | <div> |
| 31 | <input id="ConnectButton" style="display:none" type=button value="Connect" onclick="connectButton()"> |
| 32 | <input id="DisconnectButton" type=button value="Disconnect" onclick="connectButton()"> |
| 33 | <span><b id="computerName"></b></span> - <span id="termstatus"></span> |
| 34 | </div> |
| 35 | </div> |
| 36 | <div id=deskarea2 style=""> |
| 37 | <div class="areaProgress"><div id="progressbar" style=""></div></div> |
| 38 | </div> |
| 39 | <div id=deskarea3x style="max-height:calc(100vh - 54px);height:calc(100vh - 54px);"> |
| 40 | <div id="bigok" style="display:none;left:calc((100vh / 2))"><b>✓</b></div> |
| 41 | <div id="bigfail" style="display:none;left:calc((100vh / 2))"><b>✗</b></div> |
| 42 | <div id="metadatadiv" style="padding:20px;color:lightgrey;text-align:left;display:none"></div> |
| 43 | <div id=terminal style="max-height:calc(100vh - 54px);height:calc(100vh - 54px);text-align:left"></div> |
| 44 | <div id=TermConsoleMsg style="display:none;cursor:pointer;z-index:10;position:absolute;left:30px;top:17px;color:yellow;background-color:rgba(0,0,0,0.6);padding:10px;border-radius:5px" onclick=clearConsoleMsg()></div> |
| 45 | </div> |
| 46 | <div id=deskarea4 class="areaHead"> |
| 47 | <div class="toright2"></div> |
| 48 | <div style="height:21px;max-height:21px"></div> |
| 49 | </div> |
| 50 | </div> |
| 51 | <div id=dialog class="noselect" style="display:none"> |
| 52 | <div id=dialogHeader> |
| 53 | <div tabindex=0 id=id_dialogclose onclick=setDialogMode() onkeypress="if (event.key == 'Enter') setDialogMode()">✖</div> |
| 54 | <div id=id_dialogtitle></div> |
| 55 | </div> |
| 56 | <div id=dialogBody> |
| 57 | <div id=dialog1> |
| 58 | <div id=id_dialogMessage style=""></div> |
| 59 | </div> |
| 60 | <div id=dialog2 style=""> |
| 61 | <div id=id_dialogOptions></div> |
| 62 | </div> |
| 63 | </div> |
| 64 | <div id="idx_dlgButtonBar"> |
| 65 | <input id="idx_dlgCancelButton" type="button" value="Cancel" style="" onclick="dialogclose(0)"> |
| 66 | <input id="idx_dlgOkButton" type="button" value="OK" style="" onclick="dialogclose(1)"> |
| 67 | <div><input id="idx_dlgDeleteButton" type="button" value="Delete" style="display:none" onclick="dialogclose(2)"></div> |
| 68 | </div> |
| 69 | </div> |
| 70 | </div> |
| 71 | <script> |
| 72 | var random = '{{{randomlength}}}' // Random length string for BREACH mitigation |
| 73 | var term = null; |
| 74 | var termfit = null; |
| 75 | var termimage = null; |
| 76 | var resizeTimer = null; |
| 77 | var urlargs = parseUriArgs(); |
| 78 | if (urlargs.key && (isAlphaNumeric(urlargs.key) == false)) { delete urlargs.key; } |
| 79 | var cookie = '{{{cookie}}}'; |
| 80 | var domainurl = '{{{domainurl}}}'; |
| 81 | var features = parseInt('{{{features}}}'); |
| 82 | var name = decodeURIComponent('{{{name}}}'); |
| 83 | if (name != '') { document.title = name + ' - ' + document.title; } |
| 84 | var StatusStrs = ["Disconnected", "Connecting...", "Setup...", "Connected"]; |
| 85 | var state = 0; |
| 86 | var socket = null; |
| 87 | var user = ''; |
| 88 | var pass = ''; |
| 89 | |
| 90 | function start() { |
| 91 | // Set the computer name |
| 92 | QH('computerName', name); |
| 93 | |
| 94 | // When the user resizes the window, re-fit |
| 95 | window.onresize = function () { if (termfit != null) { termfit.fit(); } } |
| 96 | |
| 97 | // Update the terminal status and buttons |
| 98 | updateState(); |
| 99 | resetTerminal(); |
| 100 | |
| 101 | connectButton(); |
| 102 | } |
| 103 | |
| 104 | function resetTerminal() { |
| 105 | // Setup the terminal with auto-fit |
| 106 | if (term != null) { term.dispose(); } |
| 107 | if (urlargs.fixsize != 1) { termfit = new FitAddon.FitAddon(); } |
| 108 | termimage = new ImageAddon.ImageAddon(); |
| 109 | term = new Terminal({ allowProposedApi: true }); |
| 110 | if (termfit) { term.loadAddon(termfit); } |
| 111 | term.loadAddon(termimage); |
| 112 | term.open(Q('terminal')); |
| 113 | term.onData(function (data) { if (state == 3) { socket.send('~' + data); } }); |
| 114 | if (termfit) { termfit.fit(); } |
| 115 | term.onResize(function (size) { |
| 116 | // Despam resize |
| 117 | if (resizeTimer) clearTimeout(resizeTimer); |
| 118 | resizeTimer = setTimeout(sendResize, 200); |
| 119 | }); |
| 120 | //term.setOption('convertEol', true); // Consider \n to be \r\n, this should be taken care of by "termios" |
| 121 | } |
| 122 | |
| 123 | // Send the new terminal size to the agent |
| 124 | function sendResize() { |
| 125 | resizeTimer = null; |
| 126 | if (socket != null) { socket.send(JSON.stringify({ action: 'resize', cols: term.cols, rows: term.rows, width: Q('terminal').offsetWidth, height: Q('terminal').offsetHeight })); } |
| 127 | } |
| 128 | |
| 129 | function connectButton() { |
| 130 | if (state == 0) { |
| 131 | connectEx2({ action: 'connect', cols: term.cols, rows: term.rows, width: Q('terminal').offsetWidth, height: Q('terminal').offsetHeight, useexisting: true }); |
| 132 | } else { |
| 133 | disconnect(); |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | function sshAuthUpdate(e) { |
| 138 | QV('d2userauth', Q('dp2authmethod').value != 3); |
| 139 | QV('d2passauth', Q('dp2authmethod').value == 1); |
| 140 | QV('d2keyauth', Q('dp2authmethod').value == 2); |
| 141 | QV('d2keyauth2', Q('dp2authmethod').value == 3); |
| 142 | if (Q('dp2authmethod').value == 1) { |
| 143 | QE('idx_dlgOkButton', (Q('dp2user').value.length > 0) && (Q('dp2pass').value.length > 0)); |
| 144 | } else if (Q('dp2authmethod').value == 3) { |
| 145 | QE('idx_dlgOkButton', Q('dp2keypass2').value.length > 0); |
| 146 | } else { |
| 147 | QE('idx_dlgOkButton', false); |
| 148 | if ((features & 1) == 0) { QE('dp2keep2', Q('dp2keep1').checked); } |
| 149 | var ok = (Q('dp2user').value.length > 0) && (Q('dp2key').files != null) && (Q('dp2key').files.length == 1) && (Q('dp2key').files[0].size < 8000); |
| 150 | if (ok == true) { |
| 151 | var reader = new FileReader(); |
| 152 | reader.onload = function (e) { |
| 153 | var validkey = |
| 154 | ((e.target.result.indexOf('-----BEGIN OPENSSH PRIVATE KEY-----') >= 0) && (e.target.result.indexOf('-----END OPENSSH PRIVATE KEY-----') >= 0)) || |
| 155 | ((e.target.result.indexOf('-----BEGIN RSA PRIVATE KEY-----') >= 0) && (e.target.result.indexOf('-----END RSA PRIVATE KEY-----') >= 0)); |
| 156 | QE('idx_dlgOkButton', validkey); |
| 157 | QS('d2badkey')['color'] = validkey ? '#000' : '#F00'; |
| 158 | } |
| 159 | reader.readAsText(Q('dp2key').files[0]); |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | // When the enter key is pressed, move to the next field |
| 164 | if (e && (e.keyCode == 13) && (e.target) && (Q('dp2authmethod').value == 1)) { |
| 165 | if (e.target.id == 'dp2user') { Q('dp2pass').focus(); } |
| 166 | if (e.target.id == 'dp2pass') { dialogclose(1); } |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | function connectEx() { |
| 171 | var cmd = { action: 'connect', cols: term.cols, rows: term.rows, width: Q('terminal').offsetWidth, height: Q('terminal').offsetHeight, username: Q('dp2user').value, keep: 0 }; |
| 172 | |
| 173 | if (Q('dp2authmethod').value == 1) { |
| 174 | cmd.password = Q('dp2pass').value; |
| 175 | if ((features & 1) == 0) { cmd.keep = Q('dp2keep').checked ? 1 : 0; } |
| 176 | connectEx2(cmd); |
| 177 | } else if (Q('dp2authmethod').value == 3) { |
| 178 | cmd.action = 'connectKeyPass'; |
| 179 | cmd.keypass = Q('dp2keypass2').value; |
| 180 | connectEx2(cmd); |
| 181 | } else { |
| 182 | if ((features & 1) == 0) { cmd.keep = (Q('dp2keep1').checked ? 1 : 0); if (cmd.keep == 1) { cmd.keep += (Q('dp2keep2').checked ? 1 : 0); } } // Keep: 1 = user & key, 2 = User, key and password |
| 183 | cmd.keypass = Q('dp2keypass').value; |
| 184 | var reader = new FileReader(); |
| 185 | reader.onload = function (e) { cmd.key = e.target.result; connectEx2(cmd); } |
| 186 | reader.readAsText(Q('dp2key').files[0]); |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | function sshTunnelAuthDialog(j, func) { |
| 191 | var x = ''; |
| 192 | if (j.askkeypass) { |
| 193 | x += addHtmlValue("Authentication", '<select id=dp2authmethod style=width:230px onchange=sshAuthUpdate(event)><option value=3 selected>' + "Stored Key" + '</option><option value=1>' + "Username & Password" + '</option><option value=2>' + "Username and Key" + '</option></select>'); |
| 194 | } else { |
| 195 | x += addHtmlValue("Authentication", '<select id=dp2authmethod style=width:230px onchange=sshAuthUpdate(event)><option value=1 selected>' + "Username & Password" + '</option><option value=2>' + "Username and Key" + '</option></select>'); |
| 196 | } |
| 197 | x += '<div id=d2userauth style=display:none>'; |
| 198 | x += addHtmlValue("Username", '<input id=dp2user style=width:230px maxlength=64 autocomplete=off onkeyup=sshAuthUpdate(event) />'); |
| 199 | x += '</div>'; |
| 200 | x += '<div id=d2passauth style=display:none>'; |
| 201 | x += addHtmlValue("Password", '<input type=password id=dp2pass style=width:230px maxlength=64 autocomplete=off onkeyup=sshAuthUpdate(event) />'); |
| 202 | if ((features & 1) == 0) { x += addHtmlValue('', '<label><input id=dp2keep type=checkbox>' + "Remember credentials" + '</label>'); } |
| 203 | x += '</div><div id=d2keyauth style=display:none>'; |
| 204 | x += addHtmlValue("Key File", '<input type=file id=dp2key style=width:230px maxlength=64 autocomplete=off onchange=sshAuthUpdate(event) />' + '<div id=d2badkey style=font-size:x-small>' + "Key file must be in OpenSSH format." + '</div>'); |
| 205 | x += addHtmlValue("Key Password", '<input type=password id=dp2keypass style=width:230px maxlength=64 autocomplete=off onkeyup=sshAuthUpdate(event) />'); |
| 206 | if ((features & 1) == 0) { |
| 207 | x += addHtmlValue('', '<label><input id=dp2keep1 type=checkbox onchange=sshAuthUpdate(event)>' + "Remember user & key" + '</label>'); |
| 208 | x += addHtmlValue('', '<label><input id=dp2keep2 type=checkbox>' + "Remember password" + '</label>'); |
| 209 | } |
| 210 | x += '</div>'; |
| 211 | if (j.askkeypass) { |
| 212 | x += '<div id=d2keyauth2 style=display:none>'; |
| 213 | x += addHtmlValue("Password", '<input type=password id=dp2keypass2 style=width:230px maxlength=64 autocomplete=off onkeyup=sshAuthUpdate(event) />'); |
| 214 | x += '</div>'; |
| 215 | } |
| 216 | setDialogMode(2, "Authentication", 11, func, x, 'ssh'); |
| 217 | Q('dp2user').focus(); |
| 218 | sshAuthUpdate(); |
| 219 | setTimeout(sshAuthUpdate, 50); |
| 220 | } |
| 221 | |
| 222 | function connectEx2(cmd) { |
| 223 | state = 1; |
| 224 | var url = window.location.protocol.replace('http', 'ws') + '//' + window.location.host + domainurl + 'sshrelay.ashx?auth=' + cookie + (urlargs.key ? ('&key=' + urlargs.key) : ''); |
| 225 | socket = new WebSocket(url); |
| 226 | socket.onopen = function (e) { |
| 227 | state = 2; |
| 228 | updateState(); |
| 229 | term.reset(); |
| 230 | |
| 231 | // Send username and terminal width and height |
| 232 | socket.send(JSON.stringify(cmd)); |
| 233 | pass = ''; |
| 234 | } |
| 235 | socket.onmessage = function (data) { |
| 236 | if (typeof data.data != 'string') return; |
| 237 | if (data.data[0] == '{') { |
| 238 | var json = null; |
| 239 | try { json = JSON.parse(data.data); } catch (ex) { } |
| 240 | if ((json == null) || (typeof json != 'object')) return; |
| 241 | if ((json.ctrlChannel == 102938) && (json.type == 'ping')) { socket.send('{"ctrlChannel":"102938","type":"pong"}'); return; } |
| 242 | switch (json.action) { |
| 243 | case 'connected': { state = 3; updateState(); term.focus(); break; } |
| 244 | case 'sshauth': { sshTunnelAuthDialog(json, connectEx); break; } |
| 245 | case 'autherror': { setDialogMode(2, "Authentication", 1, null, "Unable to authenticate."); break; } |
| 246 | case 'sessionerror': { setDialogMode(2, "Session", 1, null, "Session expired."); break; } |
| 247 | case 'sessiontimeout': { setDialogMode(2, "Session", 1, null, "Session timeout."); break; } |
| 248 | } |
| 249 | } else if (data.data[0] == '~') { |
| 250 | if (term.writeUtf8) { term.writeUtf8(data.data.substring(1)); } else { term.write(data.data.substring(1)); } |
| 251 | } |
| 252 | } |
| 253 | socket.onclose = function (e) { disconnect(); } |
| 254 | socket.onerror = function (e) { disconnect(); } |
| 255 | updateState(); |
| 256 | } |
| 257 | |
| 258 | function disconnect() { |
| 259 | if (socket != null) { socket.close(); socket = null; } |
| 260 | state = 0; |
| 261 | updateState(); |
| 262 | resetTerminal(); |
| 263 | } |
| 264 | |
| 265 | function updateState() { |
| 266 | QV('ConnectButton', state == 0); |
| 267 | QV('DisconnectButton', state != 0); |
| 268 | QH('termstatus', StatusStrs[state]); |
| 269 | } |
| 270 | |
| 271 | |
| 272 | // |
| 273 | // POPUP DIALOG |
| 274 | // |
| 275 | |
| 276 | // null = Hidden, 1 = Generic Message |
| 277 | var xxdialogMode; |
| 278 | var xxdialogFunc; |
| 279 | var xxdialogButtons; |
| 280 | var xxdialogTag; |
| 281 | var xxcurrentView = -1; |
| 282 | |
| 283 | // Display a dialog box |
| 284 | // Parameters: Dialog Mode (0 = none), Dialog Title, Buttons (1 = OK, 2 = Cancel, 3 = OK & Cancel), Call back function(0 = Cancel, 1 = OK), Dialog Content (Mode 2 only) |
| 285 | function setDialogMode(x, y, b, f, c, tag) { |
| 286 | xxdialogMode = x; |
| 287 | xxdialogFunc = f; |
| 288 | xxdialogButtons = b; |
| 289 | xxdialogTag = tag; |
| 290 | QE('idx_dlgOkButton', true); |
| 291 | QV('idx_dlgOkButton', b & 1); |
| 292 | QV('idx_dlgCancelButton', b & 2); |
| 293 | QV('id_dialogclose', (b & 2) || (b & 8)); |
| 294 | QV('idx_dlgDeleteButton', b & 4); |
| 295 | QV('idx_dlgButtonBar', b & 7); |
| 296 | if (y) QH('id_dialogtitle', y); |
| 297 | for (var i = 1; i < 3; i++) { QV('dialog' + i, i == x); } // Edit this line when more dialogs are added |
| 298 | QV('dialog', x); |
| 299 | if (c) { if (x == 2) { QH('id_dialogOptions', c); } else { QH('id_dialogMessage', c); } } |
| 300 | } |
| 301 | |
| 302 | // Called when the dialog box must be closed |
| 303 | function dialogclose(x) { |
| 304 | var f = xxdialogFunc, b = xxdialogButtons, t = xxdialogTag; |
| 305 | setDialogMode(); |
| 306 | if (((b & 8) || x) && f) f(x, t); |
| 307 | } |
| 308 | |
| 309 | function messagebox(t, m) { setSessionActivity(); QH('id_dialogMessage', m); setDialogMode(1, t, 1); } |
| 310 | function statusbox(t, m) { setSessionActivity(); QH('id_dialogMessage', m); setDialogMode(1, t); } |
| 311 | function haltEvent(e) { if (e.preventDefault) e.preventDefault(); if (e.stopPropagation) e.stopPropagation(); return false; } |
| 312 | function pad2(num) { var s = '00' + num; return s.substr(s.length - 2); } |
| 313 | function format(format) { var args = Array.prototype.slice.call(arguments, 1); return format.replace(/{(\d+)}/g, function (match, number) { return typeof args[number] != 'undefined' ? args[number] : match; }); }; |
| 314 | function isAlphaNumeric(str) { return (str.match(/^[A-Za-z0-9]+$/) != null); }; |
| 315 | function isSafeString(str) { return ((typeof str == 'string') && (str.indexOf('<') == -1) && (str.indexOf('>') == -1) && (str.indexOf('&') == -1) && (str.indexOf('"') == -1) && (str.indexOf('\'') == -1) && (str.indexOf('+') == -1) && (str.indexOf('(') == -1) && (str.indexOf(')') == -1) && (str.indexOf('#') == -1) && (str.indexOf('%') == -1) && (str.indexOf(':') == -1)) }; |
| 316 | function addHtmlValue(t, v) { return '<table><td style=width:120px>' + t + '<td><b>' + v + '</b></table>'; } |
| 317 | |
| 318 | // Parse URL arguments, only keep safe values |
| 319 | function parseUriArgs() { |
| 320 | var href = window.document.location.href; |
| 321 | if (href.endsWith('#')) { href = href.substring(0, href.length - 1); } |
| 322 | var name, r = {}, parsedUri = href.split(/[\?&|\=]/); |
| 323 | parsedUri.splice(0, 1); |
| 324 | for (x in parsedUri) { |
| 325 | switch (x % 2) { |
| 326 | case 0: { name = decodeURIComponent(parsedUri[x]); break; } |
| 327 | case 1: { |
| 328 | r[name] = decodeURIComponent(parsedUri[x]); |
| 329 | if (!isSafeString(r[name])) { delete r[name]; } else { var x = parseInt(r[name]); if (x == r[name]) { r[name] = x; } } |
| 330 | break; |
| 331 | } default: { break; } |
| 332 | } |
| 333 | } |
| 334 | return r; |
| 335 | } |
| 336 | |
| 337 | start(); |
| 338 | </script> |
| 339 | </body> |
| 340 | </html> |