2020-01-23 18:15:56 -05:00
|
|
|
<!DOCTYPE html>
|
|
|
|
<html dir="ltr" xmlns="http://www.w3.org/1999/xhtml">
|
2020-06-12 17:16:24 -04:00
|
|
|
<head lang="en">
|
2020-01-23 18:15:56 -05:00
|
|
|
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
|
|
|
<meta content="text/html;charset=utf-8" http-equiv="Content-Type" />
|
|
|
|
<meta name="viewport" content="user-scalable=1.0,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0" />
|
|
|
|
<meta name="apple-mobile-web-app-capable" content="yes" />
|
|
|
|
<meta name="format-detection" content="telephone=no" />
|
|
|
|
<link type="text/css" href="styles/style.css" media="screen" rel="stylesheet" title="CSS" />
|
|
|
|
<link type="text/css" href="styles/xterm.css" media="screen" rel="stylesheet" title="CSS" />
|
2020-05-02 02:11:43 -04:00
|
|
|
<script type="text/javascript" src="scripts/common-0.0.1{{min}}.js"></script>
|
|
|
|
<script type="text/javascript" src="scripts/meshcentral{{min}}.js"></script>
|
|
|
|
<script type="text/javascript" src="scripts/agent-redir-ws-0.1.1{{min}}.js"></script>
|
|
|
|
<script type="text/javascript" src="scripts/agent-redir-rtc-0.1.0{{min}}.js"></script>
|
|
|
|
<script type="text/javascript" src="scripts/xterm-min.js"></script>
|
|
|
|
<script type="text/javascript" src="scripts/xterm-addon-fit-min.js"></script>
|
2020-01-23 18:15:56 -05:00
|
|
|
<title>{{{name}}}</title>
|
|
|
|
</head>
|
2020-01-26 14:27:13 -05:00
|
|
|
<body style="overflow:hidden;background-color:black" oncontextmenu="handleContextMenu(event)">
|
|
|
|
<!-- right click menu -->
|
|
|
|
<div id="termShellContextMenu" class="contextMenu noselect" style="display:none;min-width:0px">
|
|
|
|
<div id="cxtermnorm" class="cmtext" onclick="cmtermaction(1,event)"><b>Admin Shell</b></div>
|
|
|
|
<div id="cxtermps" class="cmtext" onclick="cmtermaction(6,event)">Admin PowerShell</div>
|
|
|
|
<div id="cxtermunorm" class="cmtext" onclick="cmtermaction(8,event)">User Shell</div>
|
|
|
|
<div id="cxtermups" class="cmtext" onclick="cmtermaction(9,event)">User PowerShell</div>
|
|
|
|
</div>
|
|
|
|
<div id="termShellContextMenuLinux" class="contextMenu noselect" style="display:none;min-width:0px">
|
|
|
|
<div id="cxtermnorm" class="cmtext" onclick="cmtermaction(1,event)"><b>Root Shell</b></div>
|
|
|
|
<div id="cxtermps" class="cmtext" onclick="cmtermaction(8,event)">User Shell</div>
|
2020-02-05 13:59:52 -05:00
|
|
|
<div id="cxtermps" class="cmtext" onclick="cmtermaction(100,event)">Login Shell</div>
|
2020-01-26 14:27:13 -05:00
|
|
|
</div>
|
2020-01-23 18:15:56 -05:00
|
|
|
<div id=p11 class="noselect" style="overflow:hidden">
|
2020-01-24 15:49:41 -05:00
|
|
|
<div id=deskarea0 style="position:relative">
|
2020-01-23 18:15:56 -05:00
|
|
|
<div id=deskarea1 class="areaHead">
|
|
|
|
<div class="toright2">
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<input id="ConnectButton" style="display:none" type=button value="Connect" onclick="connectButton()">
|
|
|
|
<input id="DisconnectButton" type=button value="Disconnect" onclick="connectButton()">
|
|
|
|
<span><b>{{{name}}}</b></span> - <span id="termstatus"></span>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div id=deskarea2 style="">
|
|
|
|
<div class="areaProgress"><div id="progressbar" style=""></div></div>
|
|
|
|
</div>
|
|
|
|
<div id=deskarea3x style="max-height:calc(100vh - 54px);height:calc(100vh - 54px);">
|
|
|
|
<div id="bigok" style="display:none;left:calc((100vh / 2))"><b>✓</b></div>
|
|
|
|
<div id="bigfail" style="display:none;left:calc((100vh / 2))"><b>✗</b></div>
|
|
|
|
<div id="metadatadiv" style="padding:20px;color:lightgrey;text-align:left;display:none"></div>
|
|
|
|
<div id=terminal style="max-height:calc(100vh - 54px);height:calc(100vh - 54px);"></div>
|
2020-01-24 17:10:37 -05:00
|
|
|
<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>
|
2020-01-23 18:15:56 -05:00
|
|
|
</div>
|
|
|
|
<div id=deskarea4 class="areaHead">
|
|
|
|
<div class="toright2">
|
|
|
|
</div>
|
|
|
|
<div style="height:21px;max-height:21px">
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div id=dialog class="noselect" style="display:none">
|
|
|
|
<div id=dialogHeader>
|
|
|
|
<div tabindex=0 id=id_dialogclose onclick=setDialogMode() onkeypress="if (event.key == 'Enter') setDialogMode()">✖</div>
|
|
|
|
<div id=id_dialogtitle></div>
|
|
|
|
</div>
|
|
|
|
<div id=dialogBody>
|
|
|
|
<div id=dialog1>
|
|
|
|
<div id=id_dialogMessage style=""></div>
|
|
|
|
</div>
|
|
|
|
<div id=dialog2 style="">
|
|
|
|
<div id=id_dialogOptions></div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div id="idx_dlgButtonBar">
|
|
|
|
<input id="idx_dlgCancelButton" type="button" value="Cancel" style="" onclick="dialogclose(0)">
|
|
|
|
<input id="idx_dlgOkButton" type="button" value="OK" style="" onclick="dialogclose(1)">
|
|
|
|
<div><input id="idx_dlgDeleteButton" type="button" value="Delete" style="display:none" onclick="dialogclose(2)"></div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<script>
|
|
|
|
var term = null;
|
|
|
|
var termfit = null;
|
|
|
|
var tunnel = null;
|
|
|
|
var domain = '{{{domain}}}';
|
|
|
|
var domainUrl = '{{{domainurl}}}';
|
|
|
|
var authCookie = '{{{authCookie}}}';
|
|
|
|
var authRelayCookie = '{{{authRelayCookie}}}';
|
|
|
|
var serverPublicNamePort = '{{{serverDnsName}}}:{{{serverPublicPort}}}';
|
|
|
|
var StatusStrs = ["Disconnected", "Connecting...", "Setup...", "Connected", "Intel® AMT Connected"];
|
2020-01-24 15:49:41 -05:00
|
|
|
var resizeTimer = null;
|
2020-01-23 18:15:56 -05:00
|
|
|
|
|
|
|
function start() {
|
|
|
|
// Parse any URL arguments
|
|
|
|
args = parseUriArgs();
|
2020-06-21 16:41:36 -04:00
|
|
|
if (args.key && (isAlphaNumeric(args.key) == false)) { delete args.key; }
|
2020-01-23 18:15:56 -05:00
|
|
|
|
|
|
|
// Connect to the mesh server
|
|
|
|
meshserver = MeshServerCreateControl(domainUrl, authCookie);
|
|
|
|
meshserver.onStateChanged = onStateChanged;
|
|
|
|
meshserver.onMessage = onMessage;
|
|
|
|
meshserver.trace = (args.trace == 1);
|
|
|
|
meshserver.Start();
|
|
|
|
|
|
|
|
// When the user resizes the window, re-fit
|
2020-01-26 14:27:13 -05:00
|
|
|
window.onresize = function () { if (termfit != null) { termfit.fit(); } }
|
|
|
|
|
|
|
|
// Hide the context menu
|
|
|
|
document.onclick = function (e) { hideContextMenu(); }
|
2020-01-23 18:15:56 -05:00
|
|
|
|
|
|
|
// Update the terminal status and buttons
|
|
|
|
QH('termstatus', StatusStrs[0]);
|
|
|
|
updateButtons();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Show the correct button state
|
|
|
|
function updateButtons() {
|
|
|
|
var tunnelState = ((tunnel != null) && (tunnel.state != 0) && (meshserver.State == 2));
|
|
|
|
QE('ConnectButton', meshserver.State == 2);
|
|
|
|
QV('ConnectButton', !tunnelState);
|
|
|
|
QV('DisconnectButton', tunnelState);
|
|
|
|
}
|
|
|
|
|
|
|
|
// MeshServer - Change State
|
|
|
|
function onStateChanged(server, state, prevState, errorCode) {
|
|
|
|
QE('ConnectButton', (state == 2));
|
|
|
|
if ((state == 2) && (args.auto == 1)) { delete args.auto; connectButton(); }
|
|
|
|
updateButtons();
|
|
|
|
}
|
|
|
|
|
|
|
|
// MeshServer - Handle messages
|
|
|
|
function onMessage(server, message) { }
|
|
|
|
|
|
|
|
// Handles a tunnel to a remote shell
|
2020-01-26 14:27:13 -05:00
|
|
|
function CreateRemoteTunnel(onTunnelUpdate, options) {
|
2020-01-23 18:15:56 -05:00
|
|
|
var obj = { protocol: 1 };
|
2020-01-26 14:27:13 -05:00
|
|
|
if ((options != null) && (typeof options.protocol == 'number')) { obj.protocol = options.protocol; }
|
2020-01-23 18:15:56 -05:00
|
|
|
obj.onTunnelUpdate = onTunnelUpdate;
|
|
|
|
obj.xxStateChange = function (state) { }
|
|
|
|
obj.ProcessBinaryData = function (data) { obj.onTunnelUpdate(data); }
|
|
|
|
obj.ProcessData = function (data) { obj.onTunnelUpdate(data); }
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
2020-01-24 15:49:41 -05:00
|
|
|
// Send the new terminal size to the agent
|
|
|
|
function sendResize() {
|
|
|
|
resizeTimer = null;
|
|
|
|
if ((term != null) && (tunnel != null)) { tunnel.sendCtrlMsg(JSON.stringify({ ctrlChannel: '102938', type: 'termsize', cols: term.cols, rows: term.rows })); }
|
|
|
|
}
|
|
|
|
|
2020-01-23 18:15:56 -05:00
|
|
|
// Called when the connect/disconnect button is pressed
|
2020-01-26 14:27:13 -05:00
|
|
|
function connectButton(options) {
|
2020-01-23 18:15:56 -05:00
|
|
|
if (!tunnel) {
|
|
|
|
// Setup the terminal with auto-fit
|
|
|
|
if (term != null) { term.dispose(); }
|
|
|
|
if (args.fixsize != 1) { termfit = new FitAddon.FitAddon(); }
|
|
|
|
term = new Terminal();
|
|
|
|
if (termfit) { term.loadAddon(termfit); }
|
|
|
|
term.open(Q('terminal'));
|
|
|
|
term.onData(function (data) { if (tunnel != null) { tunnel.sendText(data); } })
|
|
|
|
if (termfit) { termfit.fit(); }
|
2020-01-25 06:08:01 -05:00
|
|
|
term.onResize(function (size) {
|
|
|
|
// Despam resize
|
|
|
|
if (resizeTimer) clearTimeout(resizeTimer);
|
|
|
|
resizeTimer = setTimeout(sendResize, 200);
|
|
|
|
});
|
2020-02-05 13:59:52 -05:00
|
|
|
//term.setOption('convertEol', true); // Consider \n to be \r\n, this should be taken care of by "termios"
|
2020-01-23 18:15:56 -05:00
|
|
|
|
|
|
|
// Setup a terminal tunnel to the agent
|
2020-01-26 14:27:13 -05:00
|
|
|
tunnel = CreateAgentRedirect(meshserver, CreateRemoteTunnel(tunnelUpdate, options), serverPublicNamePort, authCookie, authRelayCookie, domainUrl);
|
2020-01-24 15:49:41 -05:00
|
|
|
tunnel.options = { cols: term.cols, rows: term.rows };
|
2020-02-05 13:59:52 -05:00
|
|
|
if (options && options.requireLogin) { tunnel.options.requireLogin = true; }
|
2020-01-23 18:15:56 -05:00
|
|
|
tunnel.Start(args.nodeid);
|
|
|
|
tunnel.onStateChanged = onTunnelStateChange;
|
2020-01-24 15:49:41 -05:00
|
|
|
tunnel.onConsoleMessageChange = function (server, msg) { setConsoleMsg(msg); };
|
2020-01-23 18:15:56 -05:00
|
|
|
} else {
|
|
|
|
tunnel.Stop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-24 17:10:37 -05:00
|
|
|
function tunnelUpdate(data) {
|
|
|
|
if (typeof data == 'string') {
|
|
|
|
term.writeUtf8(data);
|
|
|
|
} else {
|
|
|
|
term.writeUtf8(new Uint8Array(data));
|
|
|
|
}
|
|
|
|
}
|
2020-01-23 18:15:56 -05:00
|
|
|
|
|
|
|
// Called when the terminal state changes
|
|
|
|
function onTunnelStateChange(xterminal, state) {
|
|
|
|
var xstate = state;
|
|
|
|
if ((xstate == 3) && (xterminal.contype == 2)) { xstate++; }
|
|
|
|
var str = StatusStrs[xstate];
|
|
|
|
if (tunnel.webRtcActive == true) { str += ", WebRTC"; }
|
|
|
|
QH('termstatus', str);
|
|
|
|
switch (state) {
|
|
|
|
case 0:
|
|
|
|
// Disconnected, clear the terminal
|
|
|
|
term.dispose();
|
2020-01-24 15:49:41 -05:00
|
|
|
term = termfit = tunnel = null;
|
2020-01-23 18:15:56 -05:00
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
// Connected
|
|
|
|
term.focus();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
// Other
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
updateButtons();
|
|
|
|
}
|
|
|
|
|
2020-01-24 15:49:41 -05:00
|
|
|
// Console messages
|
|
|
|
var termConsoleMsgTimer = null;
|
|
|
|
function clearConsoleMsg() { QV('TermConsoleMsg', false); if (termConsoleMsgTimer) { clearTimeout(termConsoleMsgTimer); termConsoleMsgTimer = null; } }
|
|
|
|
function setConsoleMsg(msg) { QH('TermConsoleMsg', EscapeHtml(msg).split('\n').join('<br />')); QV('TermConsoleMsg', true); termConsoleMsgTimer = setTimeout(clearConsoleMsg, 8000); }
|
|
|
|
|
2020-01-26 14:27:13 -05:00
|
|
|
//
|
|
|
|
// CONTEXT MENU
|
|
|
|
//
|
|
|
|
|
|
|
|
var contextelement = null;
|
|
|
|
function handleContextMenu(event) {
|
|
|
|
hideContextMenu();
|
|
|
|
var scrollLeft = (window.pageXOffset !== null) ? window.pageXOffset : (document.documentElement || document.body.parentNode || document.body).scrollLeft;
|
|
|
|
var scrollTop = (window.pageYOffset !== null) ? window.pageYOffset : (document.documentElement || document.body.parentNode || document.body).scrollTop;
|
|
|
|
var elem = document.elementFromPoint(event.pageX - scrollLeft, event.pageY - scrollTop);
|
|
|
|
if (elem && elem != null && elem.id == 'ConnectButton') {
|
|
|
|
contextelement = elem;
|
|
|
|
var contextmenudiv;
|
|
|
|
if (args.os == 'win') {
|
|
|
|
contextmenudiv = document.getElementById('termShellContextMenu');
|
|
|
|
} else {
|
|
|
|
contextmenudiv = document.getElementById('termShellContextMenuLinux');
|
|
|
|
}
|
|
|
|
showContextMenuDiv(contextmenudiv, event.pageX, event.pageY);
|
2020-01-27 18:26:13 -05:00
|
|
|
return haltEvent(event);
|
2020-01-26 14:27:13 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function showContextMenuDiv(element, x, y) {
|
|
|
|
var clientRect = document.documentElement.getBoundingClientRect();
|
|
|
|
var docHeight = clientRect.height;
|
|
|
|
var docWidth = clientRect.width;
|
|
|
|
element.style.left = element.style.right = element.style.top = element.style.bottom = null;
|
|
|
|
if (x > (docWidth / 2)) { element.style.right = (docWidth - event.pageX) + 'px'; } else { element.style.left = event.pageX + 'px'; }
|
|
|
|
if (y > (docHeight / 2)) { element.style.bottom = (docHeight - event.pageY) + 'px'; } else { element.style.top = event.pageY + 'px'; }
|
|
|
|
element.style.display = 'block';
|
|
|
|
}
|
|
|
|
|
|
|
|
function cmtermaction(action) {
|
2020-02-05 13:59:52 -05:00
|
|
|
if (action < 100) {
|
|
|
|
connectButton({ protocol: action })
|
|
|
|
} else if (action == 100) {
|
|
|
|
connectButton({ protocol: 1, requireLogin: true })
|
|
|
|
}
|
2020-01-26 14:27:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
function hideContextMenu() {
|
|
|
|
QV('contextMenu', false);
|
|
|
|
QV('termShellContextMenu', false);
|
|
|
|
QV('termShellContextMenuLinux', false);
|
|
|
|
contextelement = null;
|
|
|
|
}
|
|
|
|
|
2020-01-23 18:15:56 -05:00
|
|
|
//
|
|
|
|
// POPUP DIALOG
|
|
|
|
//
|
|
|
|
|
|
|
|
// null = Hidden, 1 = Generic Message
|
|
|
|
var xxdialogMode;
|
|
|
|
var xxdialogFunc;
|
|
|
|
var xxdialogButtons;
|
|
|
|
var xxdialogTag;
|
|
|
|
var xxcurrentView = -1;
|
|
|
|
|
|
|
|
// Display a dialog box
|
|
|
|
// 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)
|
|
|
|
function setDialogMode(x, y, b, f, c, tag) {
|
|
|
|
xxdialogMode = x;
|
|
|
|
xxdialogFunc = f;
|
|
|
|
xxdialogButtons = b;
|
|
|
|
xxdialogTag = tag;
|
|
|
|
QE('idx_dlgOkButton', true);
|
|
|
|
QV('idx_dlgOkButton', b & 1);
|
|
|
|
QV('idx_dlgCancelButton', b & 2);
|
|
|
|
QV('id_dialogclose', (b & 2) || (b & 8));
|
|
|
|
QV('idx_dlgDeleteButton', b & 4);
|
|
|
|
QV('idx_dlgButtonBar', b & 7);
|
|
|
|
if (y) QH('id_dialogtitle', y);
|
|
|
|
for (var i = 1; i < 3; i++) { QV('dialog' + i, i == x); } // Edit this line when more dialogs are added
|
|
|
|
QV('dialog', x);
|
|
|
|
if (c) { if (x == 2) { QH('id_dialogOptions', c); } else { QH('id_dialogMessage', c); } }
|
|
|
|
}
|
|
|
|
|
|
|
|
// Called when the dialog box must be closed
|
|
|
|
function dialogclose(x) {
|
|
|
|
var f = xxdialogFunc, b = xxdialogButtons, t = xxdialogTag;
|
|
|
|
setDialogMode();
|
|
|
|
if (((b & 8) || x) && f) f(x, t);
|
|
|
|
}
|
|
|
|
|
|
|
|
function messagebox(t, m) { setSessionActivity(); QH('id_dialogMessage', m); setDialogMode(1, t, 1); }
|
|
|
|
function statusbox(t, m) { setSessionActivity(); QH('id_dialogMessage', m); setDialogMode(1, t); }
|
|
|
|
function haltEvent(e) { if (e.preventDefault) e.preventDefault(); if (e.stopPropagation) e.stopPropagation(); return false; }
|
|
|
|
function pad2(num) { var s = '00' + num; return s.substr(s.length - 2); }
|
|
|
|
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; }); };
|
2020-06-21 16:41:36 -04:00
|
|
|
function isAlphaNumeric(str) { return (str.match(/^[A-Za-z0-9]+$/) != null); };
|
|
|
|
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) && (str.indexOf('-') == -1)) };
|
|
|
|
|
|
|
|
// Parse URL arguments, only keep safe values
|
|
|
|
function parseUriArgs() {
|
|
|
|
var href = window.document.location.href;
|
|
|
|
if (href.endsWith('#')) { href = href.substring(0, href.length - 1); }
|
|
|
|
var name, r = {}, parsedUri = href.split(/[\?&|\=]/);
|
|
|
|
parsedUri.splice(0, 1);
|
|
|
|
for (x in parsedUri) {
|
|
|
|
switch (x % 2) {
|
|
|
|
case 0: { name = decodeURIComponent(parsedUri[x]); break; }
|
|
|
|
case 1: {
|
|
|
|
r[name] = decodeURIComponent(parsedUri[x]);
|
|
|
|
if (!isSafeString(r[name])) { delete r[name]; } else { var x = parseInt(r[name]); if (x == r[name]) { r[name] = x; } }
|
|
|
|
break;
|
|
|
|
} default: { break; }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return r;
|
|
|
|
}
|
2020-01-23 18:15:56 -05:00
|
|
|
|
|
|
|
start();
|
|
|
|
</script>
|
|
|
|
</body>
|
|
|
|
</html>
|