master
handlebars 341 lines 17 KB
Raw
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>{{{name}}}</title>
23 </head>
24 <body style="overflow:hidden;background-color:black" oncontextmenu="handleContextMenu(event)">
25 <!-- right click menu -->
26 <div id="termShellContextMenu" class="contextMenu noselect" style="display:none;min-width:0px">
27 <div id="cxtermnorm" class="cmtext" onclick="cmtermaction(1,event)"><b>Admin Shell</b></div>
28 <div id="cxtermps" class="cmtext" onclick="cmtermaction(6,event)">Admin PowerShell</div>
29 <div id="cxtermunorm" class="cmtext" onclick="cmtermaction(8,event)">User Shell</div>
30 <div id="cxtermups" class="cmtext" onclick="cmtermaction(9,event)">User PowerShell</div>
31 </div>
32 <div id="termShellContextMenuLinux" class="contextMenu noselect" style="display:none;min-width:0px">
33 <div id="cxtermnorm" class="cmtext" onclick="cmtermaction(1,event)"><b>Root Shell</b></div>
34 <div id="cxtermps" class="cmtext" onclick="cmtermaction(8,event)">User Shell</div>
35 <div id="cxtermps" class="cmtext" onclick="cmtermaction(100,event)">Login Shell</div>
36 </div>
37 <div id=p11 class="noselect" style="overflow:hidden">
38 <div id=deskarea0 style="position:relative">
39 <div id=deskarea1 class="areaHead">
40 <div class="toright2">
41 </div>
42 <div>
43 <input id="ConnectButton" style="display:none" type=button value="Connect" onclick="connectButton()">
44 <input id="DisconnectButton" type=button value="Disconnect" onclick="connectButton()">
45 <span><b>{{{name}}}</b></span> - <span id="termstatus"></span>
46 </div>
47 </div>
48 <div id=deskarea2 style="">
49 <div class="areaProgress"><div id="progressbar" style=""></div></div>
50 </div>
51 <div id=deskarea3x style="max-height:calc(100vh - 54px);height:calc(100vh - 54px);">
52 <div id="bigok" style="display:none;left:calc((100vh / 2))"><b>&checkmark;</b></div>
53 <div id="bigfail" style="display:none;left:calc((100vh / 2))"><b>&#10007;</b></div>
54 <div id="metadatadiv" style="padding:20px;color:lightgrey;text-align:left;display:none"></div>
55 <div id=terminal style="max-height:calc(100vh - 54px);height:calc(100vh - 54px);"></div>
56 <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>
57 </div>
58 <div id=deskarea4 class="areaHead">
59 <div class="toright2">
60 </div>
61 <div style="height:21px;max-height:21px">
62 </div>
63 </div>
64 </div>
65 <div id=dialog class="noselect" style="display:none">
66 <div id=dialogHeader>
67 <div tabindex=0 id=id_dialogclose onclick=setDialogMode() onkeypress="if (event.key == 'Enter') setDialogMode()">&#x2716;</div>
68 <div id=id_dialogtitle></div>
69 </div>
70 <div id=dialogBody>
71 <div id=dialog1>
72 <div id=id_dialogMessage style=""></div>
73 </div>
74 <div id=dialog2 style="">
75 <div id=id_dialogOptions></div>
76 </div>
77 </div>
78 <div id="idx_dlgButtonBar">
79 <input id="idx_dlgCancelButton" type="button" value="Cancel" style="" onclick="dialogclose(0)">
80 <input id="idx_dlgOkButton" type="button" value="OK" style="" onclick="dialogclose(1)">
81 <div><input id="idx_dlgDeleteButton" type="button" value="Delete" style="display:none" onclick="dialogclose(2)"></div>
82 </div>
83 </div>
84 </div>
85 <script>
86 var random = '{{{randomlength}}}' // Random length string for BREACH mitigation
87 var term = null;
88 var termfit = null;
89 var termimage = null;
90 var tunnel = null;
91 var domain = '{{{domain}}}';
92 var domainUrl = '{{{domainurl}}}';
93 var authCookie = '{{{authCookie}}}';
94 var authRelayCookie = '{{{authRelayCookie}}}';
95 var serverPublicNamePort = '{{{serverDnsName}}}:{{{serverPublicPort}}}';
96 var StatusStrs = ["Disconnected", "Connecting...", "Setup...", "Connected", "Intel&reg; AMT Connected"];
97 var resizeTimer = null;
98
99 function start() {
100 // Parse any URL arguments
101 args = parseUriArgs();
102 if (args.key && (isAlphaNumeric(args.key) == false)) { delete args.key; }
103
104 // Connect to the mesh server
105 meshserver = MeshServerCreateControl(domainUrl, authCookie);
106 meshserver.onStateChanged = onStateChanged;
107 meshserver.onMessage = onMessage;
108 meshserver.trace = (args.trace == 1);
109 meshserver.Start();
110
111 // When the user resizes the window, re-fit
112 window.onresize = function () { if (termfit != null) { termfit.fit(); } }
113
114 // Hide the context menu
115 document.onclick = function (e) { hideContextMenu(); }
116
117 // Update the terminal status and buttons
118 QH('termstatus', StatusStrs[0]);
119 updateButtons();
120 }
121
122 // Show the correct button state
123 function updateButtons() {
124 var tunnelState = ((tunnel != null) && (tunnel.state != 0) && (meshserver.State == 2));
125 QE('ConnectButton', meshserver.State == 2);
126 QV('ConnectButton', !tunnelState);
127 QV('DisconnectButton', tunnelState);
128 }
129
130 // MeshServer - Change State
131 function onStateChanged(server, state, prevState, errorCode) {
132 QE('ConnectButton', (state == 2));
133 if ((state == 2) && (args.auto == 1)) { delete args.auto; connectButton(); }
134 updateButtons();
135 }
136
137 // MeshServer - Handle messages
138 function onMessage(server, message) { }
139
140 // Handles a tunnel to a remote shell
141 function CreateRemoteTunnel(onTunnelUpdate, options) {
142 var obj = { protocol: 1 };
143 if ((options != null) && (typeof options.protocol == 'number')) { obj.protocol = options.protocol; }
144 obj.onTunnelUpdate = onTunnelUpdate;
145 obj.xxStateChange = function (state) { }
146 obj.ProcessBinaryData = function (data) { obj.onTunnelUpdate(data); }
147 obj.ProcessData = function (data) { obj.onTunnelUpdate(data); }
148 return obj;
149 }
150
151 // Send the new terminal size to the agent
152 function sendResize() {
153 resizeTimer = null;
154 if ((term != null) && (tunnel != null)) { tunnel.sendCtrlMsg(JSON.stringify({ ctrlChannel: '102938', type: 'termsize', cols: term.cols, rows: term.rows })); }
155 }
156
157 // Called when the connect/disconnect button is pressed
158 function connectButton(options) {
159 if (!tunnel) {
160 // Setup the terminal with auto-fit
161 if (term != null) { term.dispose(); }
162 if (args.fixsize != 1) { termfit = new FitAddon.FitAddon(); }
163 termimage = new ImageAddon.ImageAddon();
164 term = new Terminal({ allowProposedApi: true });
165 if (termfit) { term.loadAddon(termfit); }
166 term.loadAddon(termimage);
167 term.open(Q('terminal'));
168 term.onData(function (data) { if (tunnel != null) { tunnel.sendText(data); } })
169 if (termfit) { termfit.fit(); }
170 term.onResize(function (size) {
171 // Despam resize
172 if (resizeTimer) clearTimeout(resizeTimer);
173 resizeTimer = setTimeout(sendResize, 200);
174 });
175 //term.setOption('convertEol', true); // Consider \n to be \r\n, this should be taken care of by "termios"
176
177 // Setup a terminal tunnel to the agent
178 tunnel = CreateAgentRedirect(meshserver, CreateRemoteTunnel(tunnelUpdate, options), serverPublicNamePort, authCookie, authRelayCookie, domainUrl);
179 tunnel.options = { cols: term.cols, rows: term.rows };
180 if (options && options.requireLogin) { tunnel.options.requireLogin = true; }
181 tunnel.Start(args.nodeid);
182 tunnel.onStateChanged = onTunnelStateChange;
183 tunnel.onConsoleMessageChange = function (server, msg) { setConsoleMsg(msg); };
184 } else {
185 tunnel.Stop();
186 }
187 }
188
189 function tunnelUpdate(data) {
190 if (term.writeUtf8) {
191 if (typeof data == 'string') { term.writeUtf8(data); } else { term.writeUtf8(new Uint8Array(data)); }
192 } else {
193 if (typeof data == 'string') { term.write(data); } else { term.write(new Uint8Array(data)); }
194 }
195 }
196
197 // Called when the terminal state changes
198 function onTunnelStateChange(xterminal, state) {
199 var xstate = state;
200 if ((xstate == 3) && (xterminal.contype == 2)) { xstate++; }
201 var str = StatusStrs[xstate];
202 if (tunnel.webRtcActive == true) { str += ", WebRTC"; }
203 QH('termstatus', str);
204 switch (state) {
205 case 0:
206 // Disconnected, clear the terminal
207 term.dispose();
208 term = termfit = termimage = tunnel = null;
209 break;
210 case 3:
211 // Connected
212 term.focus();
213 break;
214 default:
215 // Other
216 break;
217 }
218 updateButtons();
219 }
220
221 // Console messages
222 var termConsoleMsgTimer = null;
223 function clearConsoleMsg() { QV('TermConsoleMsg', false); if (termConsoleMsgTimer) { clearTimeout(termConsoleMsgTimer); termConsoleMsgTimer = null; } }
224 function setConsoleMsg(msg) { QH('TermConsoleMsg', EscapeHtml(msg).split('\n').join('<br />')); QV('TermConsoleMsg', true); termConsoleMsgTimer = setTimeout(clearConsoleMsg, 8000); }
225
226 //
227 // CONTEXT MENU
228 //
229
230 var contextelement = null;
231 function handleContextMenu(event) {
232 hideContextMenu();
233 var scrollLeft = (window.pageXOffset !== null) ? window.pageXOffset : (document.documentElement || document.body.parentNode || document.body).scrollLeft;
234 var scrollTop = (window.pageYOffset !== null) ? window.pageYOffset : (document.documentElement || document.body.parentNode || document.body).scrollTop;
235 var elem = document.elementFromPoint(event.pageX - scrollLeft, event.pageY - scrollTop);
236 if (elem && elem != null && elem.id == 'ConnectButton') {
237 contextelement = elem;
238 var contextmenudiv;
239 if (args.os == 'win') {
240 contextmenudiv = document.getElementById('termShellContextMenu');
241 } else {
242 contextmenudiv = document.getElementById('termShellContextMenuLinux');
243 }
244 showContextMenuDiv(contextmenudiv, event.pageX, event.pageY);
245 return haltEvent(event);
246 }
247 }
248
249 function showContextMenuDiv(element, x, y) {
250 var clientRect = document.documentElement.getBoundingClientRect();
251 var docHeight = clientRect.height;
252 var docWidth = clientRect.width;
253 element.style.left = element.style.right = element.style.top = element.style.bottom = null;
254 if (x > (docWidth / 2)) { element.style.right = (docWidth - event.pageX) + 'px'; } else { element.style.left = event.pageX + 'px'; }
255 if (y > (docHeight / 2)) { element.style.bottom = (docHeight - event.pageY) + 'px'; } else { element.style.top = event.pageY + 'px'; }
256 element.style.display = 'block';
257 }
258
259 function cmtermaction(action) {
260 if (action < 100) {
261 connectButton({ protocol: action })
262 } else if (action == 100) {
263 connectButton({ protocol: 1, requireLogin: true })
264 }
265 }
266
267 function hideContextMenu() {
268 QV('contextMenu', false);
269 QV('termShellContextMenu', false);
270 QV('termShellContextMenuLinux', false);
271 contextelement = null;
272 }
273
274 //
275 // POPUP DIALOG
276 //
277
278 // null = Hidden, 1 = Generic Message
279 var xxdialogMode;
280 var xxdialogFunc;
281 var xxdialogButtons;
282 var xxdialogTag;
283 var xxcurrentView = -1;
284
285 // Display a dialog box
286 // 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)
287 function setDialogMode(x, y, b, f, c, tag) {
288 xxdialogMode = x;
289 xxdialogFunc = f;
290 xxdialogButtons = b;
291 xxdialogTag = tag;
292 QE('idx_dlgOkButton', true);
293 QV('idx_dlgOkButton', b & 1);
294 QV('idx_dlgCancelButton', b & 2);
295 QV('id_dialogclose', (b & 2) || (b & 8));
296 QV('idx_dlgDeleteButton', b & 4);
297 QV('idx_dlgButtonBar', b & 7);
298 if (y) QH('id_dialogtitle', y);
299 for (var i = 1; i < 3; i++) { QV('dialog' + i, i == x); } // Edit this line when more dialogs are added
300 QV('dialog', x);
301 if (c) { if (x == 2) { QH('id_dialogOptions', c); } else { QH('id_dialogMessage', c); } }
302 }
303
304 // Called when the dialog box must be closed
305 function dialogclose(x) {
306 var f = xxdialogFunc, b = xxdialogButtons, t = xxdialogTag;
307 setDialogMode();
308 if (((b & 8) || x) && f) f(x, t);
309 }
310
311 function messagebox(t, m) { setSessionActivity(); QH('id_dialogMessage', m); setDialogMode(1, t, 1); }
312 function statusbox(t, m) { setSessionActivity(); QH('id_dialogMessage', m); setDialogMode(1, t); }
313 function haltEvent(e) { if (e.preventDefault) e.preventDefault(); if (e.stopPropagation) e.stopPropagation(); return false; }
314 function pad2(num) { var s = '00' + num; return s.substr(s.length - 2); }
315 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; }); };
316 function isAlphaNumeric(str) { return (str.match(/^[A-Za-z0-9]+$/) != null); };
317 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)) };
318
319 // Parse URL arguments, only keep safe values
320 function parseUriArgs() {
321 var href = window.document.location.href;
322 if (href.endsWith('#')) { href = href.substring(0, href.length - 1); }
323 var name, r = {}, parsedUri = href.split(/[\?&|\=]/);
324 parsedUri.splice(0, 1);
325 for (x in parsedUri) {
326 switch (x % 2) {
327 case 0: { name = decodeURIComponent(parsedUri[x]); break; }
328 case 1: {
329 r[name] = decodeURIComponent(parsedUri[x]);
330 if (!isSafeString(r[name])) { delete r[name]; } else { var x = parseInt(r[name]); if (x == r[name]) { r[name] = x; } }
331 break;
332 } default: { break; }
333 }
334 }
335 return r;
336 }
337
338 start();
339 </script>
340 </body>
341 </html>