2017-08-28 19:27:45 +03:00
<!DOCTYPE html>
<html dir="ltr" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
2018-07-06 20:13:19 +03:00
<meta content="text/html;charset=utf-8" http-equiv="Content-Type" />
2017-08-28 19:27:45 +03:00
<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" />
2017-08-29 01:06:29 +03:00
<link type="text/css" href="styles/ol.css" media="screen" rel="stylesheet" title="CSS" />
2017-09-26 01:28:52 +03:00
<link type="text/css" href="styles/ol3-contextmenu.min.css" media="screen" rel="stylesheet" title="CSS" />
2017-08-28 19:27:45 +03:00
<script type="text/javascript" src="scripts/common-0.0.1.js"></script>
<script type="text/javascript" src="scripts/meshcentral.js"></script>
<script type="text/javascript" src="scripts/amt-0.2.0.js"></script>
<script type="text/javascript" src="scripts/amt-wsman-0.2.0.js"></script>
<script type="text/javascript" src="scripts/amt-desktop-0.0.2.js"></script>
<script type="text/javascript" src="scripts/amt-terminal-0.0.2.js"></script>
2018-01-19 02:43:43 +03:00
<script type="text/javascript" src="scripts/zlib.js"></script>
<script type="text/javascript" src="scripts/zlib-inflate.js"></script>
<script type="text/javascript" src="scripts/zlib-adler32.js"></script>
<script type="text/javascript" src="scripts/zlib-crc32.js"></script>
2017-08-28 19:27:45 +03:00
<script type="text/javascript" src="scripts/amt-redir-ws-0.1.0.js"></script>
<script type="text/javascript" src="scripts/amt-wsman-ws-0.2.0.js"></script>
<script type="text/javascript" src="scripts/agent-redir-ws-0.1.0.js"></script>
2018-09-29 01:27:26 +03:00
<script type="text/javascript" src="scripts/agent-redir-rtc-0.1.0.js"></script>
2017-08-28 19:27:45 +03:00
<script type="text/javascript" src="scripts/agent-desktop-0.0.2.js"></script>
2019-01-16 00:51:07 +03:00
<script type="text/javascript" src="scripts/qrcode.min.js"></script>
2019-02-08 09:30:33 +03:00
<script type="text/javascript" src="scripts/u2f-api.js"></script>
2018-09-27 00:58:55 +03:00
<script keeplink=1 type="text/javascript" src="scripts/charts.js"></script>
2018-08-24 02:55:06 +03:00
<script keeplink=1 type="text/javascript" src="scripts/filesaver.1.1.20151003.js"></script>
<script keeplink=1 type="text/javascript" src="scripts/ol.js"></script>
<script keeplink=1 type="text/javascript" src="scripts/ol3-contextmenu.js"></script>
2017-08-28 19:27:45 +03:00
<title>MeshCentral</title>
</head>
2018-09-15 03:42:39 +03:00
<body id="body" onload="if (typeof(startup) !== 'undefined') startup();" oncontextmenu="handleContextMenu(event)" style="display:none">
2017-08-28 19:27:45 +03:00
<!-- right click menu -->
2019-01-30 01:08:29 +03:00
<div id="contextMenu" class="contextMenu noselect" style="display:none">
<div id="cxinfo" class="cmtext" onclick="cmaction(1,event)"><b>Information</b></div>
<div id="cxdesktop" class="cmtext" onclick="cmaction(3,event)">Desktop</div>
<div id="cxterminal" class="cmtext" onclick="cmaction(2,event)">Terminal</div>
<div id="cxfiles" class="cmtext" onclick="cmaction(4,event)">Files</div>
<div id="cxevents" class="cmtext" onclick="cmaction(5,event)">Events</div>
<div id="cxconsole" class="cmtext" onclick="cmaction(6,event)">Console</div>
2017-08-28 19:27:45 +03:00
<hr id="cxmgroupsplit" />
2019-01-30 01:08:29 +03:00
<div id="cxmdesktop" class="cmtext" onclick="cmaction(7,event)" style=display:none>Multi-Desktop</div>
2017-08-28 19:27:45 +03:00
</div>
2019-01-30 01:08:29 +03:00
<div id="meshContextMenu" class="contextMenu,noselect" style="display: none; min-width: 0px">
<div id="cxselectall" class="cmtext" onclick="cmmeshaction(1,event)">Select All</div>
<div id="cxselectnone" class="cmtext" onclick="cmmeshaction(2,event)">Select None</div>
2017-08-28 19:27:45 +03:00
<hr id="cxmgroupsplit2" style=display:none />
2019-01-30 01:08:29 +03:00
<div id="cxmmdesktop" class="cmtext" style=display:none onclick="cmmeshaction(3,event)">Multi-Desktop</div>
2017-08-28 19:27:45 +03:00
</div>
<!-- main page -->
<div id=container style=max-height:100vh;position:relative>
<div id="notifiyBox" class="notifiyBox" style="display:none"></div>
<div id=mastheadx></div>
2018-12-22 01:39:26 +03:00
<div id=masthead class=noselect style="background:url(logo.png) 0px 0px;background-color:#036;background-repeat:no-repeat;height:66px;width:100%;overflow:hidden">
2017-08-28 19:27:45 +03:00
<div style="float:left;height:66px;color:#c8c8c8;padding-left:20px;padding-top:8px">
<strong><font style="font-size:46px;font-family:Arial,Helvetica,sans-serif"> {{{ title }}} </font></strong>
</div>
<div style="float:left;height:66px;color:#c8c8c8;padding-left:5px;padding-top:14px">
<strong><font style="font-size:14px;font-family:Arial,Helvetica,sans-serif"> {{{ title2 }}} </font></strong>
</div>
<div style="float:right">
<div id=notificationCount onclick="clickNotificationIcon()" class="unselectable" style="display:none;min-width:28px;font-size:20px;border-radius:5px;background-color:lightblue;text-align:center;margin:8px;cursor:pointer;padding:4px" title="Click to view current notifications">0</div>
</div>
2017-12-14 01:52:57 +03:00
<p id="logoutControl"> {{{ log outControl }}} </p>
2017-08-28 19:27:45 +03:00
</div>
2018-09-15 03:42:39 +03:00
<div id="page_leftbar" style="height:calc(100vh - 66px);width:90px;position:absolute;z-index:1000;background:#113962;background:linear-gradient(to bottom, #104893 0%,#113962 100%);color:white;display:none">
<div style="height:16px"></div>
<div id=LeftMenuMyDevices class="lbbutton lbbuttonsel" title="My Devices" onclick=go(1)>
<div class="lb2" style="position:absolute;top:6px;left:6px"></div>
</div>
<div id=LeftMenuMyAccount class="lbbutton" title="My Account" onclick=go(2)>
<div class="lb1" style="position:absolute;top:6px;left:6px"></div>
</div>
<div id=LeftMenuMyEvents class="lbbutton" title="My Events" onclick=go(3)>
<div class="lb3" style="position:absolute;top:6px;left:6px"></div>
</div>
<div id=LeftMenuMyFiles class="lbbutton" title="My Files" onclick=go(5)>
<div class="lb4" style="position:absolute;top:6px;left:6px"></div>
</div>
<div id=LeftMenuMyUsers class="lbbutton" title="My Users" onclick=go(4)>
<div class="lb5" style="position:absolute;top:6px;left:6px"></div>
</div>
2018-09-27 00:58:55 +03:00
<div id=LeftMenuMyServer class="lbbutton" title="My Server" onclick=go(6) style="display:none">
<div class="lb6" style="position:absolute;top:6px;left:6px"></div>
</div>
2018-09-15 03:42:39 +03:00
</div>
<div id="page_content" style="max-height:calc(100vh - 130px)">
<div id=topbarmaster>
2018-09-25 03:47:03 +03:00
<div id=topbar class=noselect>
2017-12-14 01:52:57 +03:00
<div>
2018-09-15 03:42:39 +03:00
<div style="position:relative">
<div style="position:absolute;top:3px;right:6px">
<span title="Toggle full width" style="cursor:pointer;color:white" onclick="toggleFullScreen(1)">↔</span>
</div>
<table id=MainMenuSpan style=width:100%;height:22px cellpadding=0 cellspacing=0 class=style1>
2018-04-16 08:22:44 +03:00
<tr>
2018-11-13 05:36:20 +03:00
<td id=MainMenuMyDevices style=width:100px;height:24px;cursor:pointer class=style3x onclick=go(1)>My Devices</td>
<td id=MainMenuMyAccount style=width:100px;height:24px;cursor:pointer class=style3x onclick=go(2)>My Account</td>
<td id=MainMenuMyEvents style=width:100px;height:24px;cursor:pointer class=style3x onclick=go(3)>My Events</td>
<td id=MainMenuMyFiles style=width:100px;height:24px;cursor:pointer class=style3x onclick=go(5)>My Files</td>
<td id=MainMenuMyUsers style=width:100px;height:24px;cursor:pointer;display:none class=style3x onclick=go(4)>My Users</td>
<td id=MainMenuMyServer style=width:100px;height:24px;cursor:pointer;display:none class=style3x onclick=go(6)>My Server</td>
2018-09-15 03:42:39 +03:00
<td class=style3 style="text-align:right;height:24px"> </td>
2018-04-16 08:22:44 +03:00
</tr>
</table>
2018-09-15 03:42:39 +03:00
<div id=MainSubMenuSpan style=display:none>
<table id=MainSubMenu style=width:100%;height:22px cellpadding=0 cellspacing=0 class=style1>
<tr>
2018-11-13 05:36:20 +03:00
<td id=MainDev style=width:100px;height:24px;cursor:pointer class=style3x onclick=go(10)>General</td>
<td id=MainDevDesktop style=width:100px;height:24px;cursor:pointer class=style3x onclick=go(11)>Desktop</td>
<td id=MainDevTerminal style=width:100px;height:24px;cursor:pointer class=style3x onclick=go(12)>Terminal</td>
<td id=MainDevFiles style=width:100px;height:24px;cursor:pointer;display:none class=style3x onclick=go(13)>Files</td>
<td id=MainDevEvents style=width:100px;height:24px;cursor:pointer class=style3x onclick=go(16)>Events</td>
<td id=MainDevAmt style=width:100px;height:24px;cursor:pointer class=style3x onclick=go(14)>Intel® AMT</td>
<td id=MainDevConsole style=width:100px;height:24px;cursor:pointer class=style3x onclick=go(15)>Console</td>
2018-09-15 03:42:39 +03:00
<td class=style3 style=height:24px> </td>
</tr>
</table>
</div>
<div id=MeshSubMenuSpan style=display:none>
<table id=MeshSubMenu style=width:100%;height:22px cellpadding=0 cellspacing=0 class=style1>
<tr>
2018-11-13 05:36:20 +03:00
<td id=MeshGeneral style=width:100px;height:24px;cursor:pointer class=style3x onclick=go(20)>General</td>
2018-09-15 03:42:39 +03:00
<td class=style3 style=height:24px> </td>
</tr>
</table>
</div>
<div id=UserSubMenuSpan style=display:none>
<table id=UserSubMenu style=width:100%;height:22px cellpadding=0 cellspacing=0 class=style1>
<tr>
2018-11-13 05:36:20 +03:00
<td id=UserGeneral style=width:100px;height:24px;cursor:pointer class=style3x onclick=go(30)>General</td>
<td id=UserEvents style=width:100px;height:24px;cursor:pointer class=style3x onclick=go(31)>Events</td>
2018-09-15 03:42:39 +03:00
<td class=style3 style=height:24px> </td>
</tr>
</table>
</div>
2019-02-05 05:06:01 +03:00
<div id=ServerSubMenuSpan style=display:none>
<table id=ServerSubMenu style=width:100%;height:22px cellpadding=0 cellspacing=0 class=style1>
<tr>
<td id=ServerGeneral style=width:100px;height:24px;cursor:pointer class=style3x onclick=go(6)>General</td>
<td id=ServerConsole style=width:100px;height:24px;cursor:pointer class=style3x onclick=go(115)>Console</td>
<td class=style3 style=height:24px> </td>
</tr>
</table>
</div>
2018-09-25 03:47:03 +03:00
<div id=UserDummyMenuSpan>
2018-09-15 03:42:39 +03:00
<table id=UserDummyMenu style=width:100%;height:22px cellpadding=0 cellspacing=0 class=style1>
<tr><td class=style3 style="text-align:right;height:24px"> </td></tr>
</table>
</div>
2018-04-16 08:22:44 +03:00
</div>
2017-08-28 19:27:45 +03:00
</div>
</div>
</div>
<div id="column_l">
<div id=p0 style=display:none>
2019-01-27 23:23:38 +03:00
<div id=p0message style=margin:50px;text-align:center><span id=p0span>Server disconnected</span>, <href onclick=reload() style=cursor:pointer><u>click to reconnect</u></href>.</div>
2017-08-28 19:27:45 +03:00
</div>
<div id=p1 style=display:none>
2019-01-24 23:08:48 +03:00
<div style="float:right;display:none" id="devListToolbarViewIcons">
2018-09-22 02:34:35 +03:00
<div id=devViewButton1 class="viewSelector" onclick=onDeviceViewChange(1) title="Columns"><div class="viewSelector2"></div></div>
<div id=devViewButton2 class=viewSelector onclick=onDeviceViewChange(2) title="List"><div class="viewSelector1"></div></div>
2018-09-19 00:47:17 +03:00
<div id=devViewButton3 class=viewSelector onclick=onDeviceViewChange(3) title="Desktops"><div class="viewSelector3"></div></div>
<div id=devViewButton4 class=viewSelector onclick=onDeviceViewChange(4) title="Map"><div class="viewSelector4"></div></div>
</div><div><h1>My Devices</h1></div>
2019-01-30 01:08:29 +03:00
<table class="noselect" style=width:100%;height:24px;background-color:#d3d9d6;vertical-align:middle;border-spacing:0>
2018-10-11 23:29:50 +03:00
<tr>
<td class=h1></td>
2019-01-24 23:08:48 +03:00
<td id=devListToolbar class=style14 style=display:none>
2018-10-11 23:29:50 +03:00
<input type="button" id="SelectAllButton" onclick="selectallButtonFunction();" value="Select All" />
<input type=button id=GroupActionButton disabled="disabled" value="Group Action" onclick=groupActionFunction() />
2019-01-22 22:44:46 +03:00
<input id=SearchInput type=text style=width:120px placeholder=Filter onchange=masterUpdate(5) onkeyup=masterUpdate(5) autocomplete=off onfocus=onSearchFocus(1) onblur=onSearchFocus(0) />
2019-02-20 02:51:38 +03:00
<label><input type=checkbox id=RealNameCheckBox onclick=onRealNameCheckBox() /><span title="Show devices operating system name">OS Name</span></label>
2018-10-11 23:29:50 +03:00
</td>
2019-01-24 23:08:48 +03:00
<td id=kvmListToolbar class=style14 style=height:100%;display:none>
2018-10-11 23:29:50 +03:00
<input type="button" onclick="connectAllKvmFunction()" value="Connect All" />
<input type="button" onclick="disconnectAllKvmFunction()" value="Disconnect All" />
2019-02-20 02:51:38 +03:00
<label><input type="checkbox" id="autoConnectDesktopCheckbox" onclick="autoConnectDesktops(event)" title="Automatic connect" />Auto </label>
2018-10-11 23:29:50 +03:00
<input type="button" onclick="showMultiDesktopSettings()" value="Settings" />
</td>
2019-01-24 23:08:48 +03:00
<td id=devMapToolbar class=style14 style=height:100%;display:none>
2018-10-11 23:29:50 +03:00
<input type=text id=mapSearchLocation placeholder="Search Location" onfocus=onMapSearchFocus(1) onblur=onMapSearchFocus(0) />
<input type=button value=Search title="Search for location" onclick=getSearchLocation() />
<input type=button id=refreshmap title="Reset map view" value=Reset style=margin-left:5px onclick=refreshMap(false,true) />
</td>
<td class="auto-style1" style=height:100%>
<div style="float:right;display:none" id=devListToolbarView>
View
<select id=viewselect onchange=onDeviceViewChange()>
<option value=1>Columns</option>
<option value=2>List</option>
<option value=3>Desktops</option>
<option id=viewselectmapoption value=4>Map</option>
</select>
</div>
2019-01-24 23:08:48 +03:00
<div style=float:right;display:none id=devListToolbarSort>
2018-10-11 23:29:50 +03:00
Sort
2019-01-22 22:44:46 +03:00
<select id=sortselect onchange=masterUpdate(6)>
2018-10-11 23:29:50 +03:00
<option>Group</option>
<option>Power</option>
<option>Device</option>
<option>Tags</option>
</select>
</div>
2019-01-24 23:08:48 +03:00
<div style=float:right;display:none id=devListToolbarSize>
2018-10-11 23:29:50 +03:00
Size
<select id=sizeselect onchange=onDeviceViewChange()>
<option value=0>Small</option>
<option value=1>Medium</option>
<option value=2>Large</option>
</select>
</div>
</td>
<td class=h2></td>
</tr>
</table>
2017-10-03 00:12:29 +03:00
<div id=NoMeshesPanel style=display:none>
<table style="width:100%;padding:20px">
2017-08-28 19:27:45 +03:00
<tr>
<td valign="top" style="width: 50px">
<img src="images/info.png" height="48" width="47" />
</td>
<td>
2018-09-25 03:47:03 +03:00
To get started, <a onclick=account_createMesh() style=cursor:pointer><strong>click here to create a device group</strong></a>.
2017-08-28 19:27:45 +03:00
</td>
</tr>
</table>
</div>
2019-01-30 01:08:29 +03:00
<div id="xdevices" class="noselect" style="max-height:calc(100vh - 239px);overflow-y:auto;overflow-x:hidden;-webkit-overflow-scrolling:touch;display:none"></div>
2019-01-24 23:08:48 +03:00
<div id="xdevicesmap" style="height:calc(100vh - 239px);width:100%;overflow:hidden;position:relative;display:none">
2017-08-30 00:34:13 +03:00
<div id=xmapSearchResultsDlg style="position:absolute;display:none;max-height:280px;left:5px;top:5px;max-width:250px;z-index:1000;background-color:#EEE;box-shadow:0px 0px 15px #666">
<div style="width:100%;background-color:#003366;color:#FFF;border-radius:5px 5px 0 0">
<div id=xmapSearchClose style=float:right;padding:5px;cursor:pointer onclick=mapCloseSearchWindow()><b>X</b></div>
<div style=padding:5px>Location Results</div>
<div style=width:100%;margin:6px></div>
</div>
<div id=xmapSearchResults style=margin:6px></div>
</div>
</div>
<div id="xmap-info-window" style="text-shadow: 0px 0px 15px #FFF"></div>
2017-08-28 19:27:45 +03:00
</div>
2018-09-15 03:42:39 +03:00
<div id=p2 style="display:none">
2017-08-28 19:27:45 +03:00
<h1>My Account</h1>
2019-02-26 00:14:04 +03:00
<img id="p2AccountImage" alt="" width=150 height=103 src=images/mainaccount.jpg style=margin-bottom:10px;margin-right:20px;float:right />
2019-02-11 03:04:36 +03:00
<div id="p2AccountSecurity" style="display:none">
<p><strong>Account security</strong></p>
<div style="margin-left:25px">
<div id="manageAuthApp"><div style="width:15px;display:inline-block"><span id="authAppSetupCheck" style="color:green;font-size:10px"><strong>✓</strong></span></div><span><a onclick="account_manageAuthApp()" style="cursor:pointer">Manage authenticator app</a><br /></span></div>
<div id="manageHardwareOtp"><div style="width:15px;display:inline-block"><span id="authKeySetupCheck" style="color:green;font-size:10px"><strong>✓</strong></span></div><span><a onclick="account_manageHardwareOtp(0)" style="cursor:pointer">Manage security keys</a><br /></span></div>
<div id="manageOtp"><div style="width:15px;display:inline-block"><span id="authCodesSetupCheck" style="color:green;font-size:10px"><strong>✓</strong></span></div><span><a onclick="account_manageOtp(0)" style="cursor:pointer">Manage backup codes</a><br /></span></div>
</div>
</div>
2017-08-28 19:27:45 +03:00
<div id="p2AccountActions">
2019-02-11 03:04:36 +03:00
<p><strong>Account actions</strong></p>
2017-08-28 19:27:45 +03:00
<p style="margin-left:40px">
2017-12-13 03:04:54 +03:00
<span id="verifyEmailId" style="display:none"><a onclick="account_showVerifyEmail()" style="cursor:pointer">Verify email</a><br /></span>
2017-12-13 05:23:26 +03:00
<a onclick="account_showChangeEmail()" style="cursor:pointer">Change email address</a><br />
2017-08-28 19:27:45 +03:00
<a onclick="account_showChangePassword()" style="cursor:pointer">Change password</a><br />
<a onclick="account_showDeleteAccount()" style="cursor:pointer">Delete account</a><br />
</p>
2019-01-16 23:04:48 +03:00
<br style=clear:both />
2017-08-28 19:27:45 +03:00
</div>
2018-09-25 03:47:03 +03:00
<strong>Device Groups</strong>
2017-08-28 19:27:45 +03:00
( <a onclick=account_createMesh() style=cursor:pointer><img height=12 src="images/icon-addnew.png" width=12 border=0 /> New</a> )
<br /><br />
<div id=p2meshes></div>
2018-09-25 03:47:03 +03:00
<div id=p2noMeshFound style=margin-left:40px;display:none>No device groups. <a onclick=account_createMesh() style=cursor:pointer><strong>Get started here!</strong></a></div>
2018-03-07 04:50:44 +03:00
<br style=clear:both />
2017-08-28 19:27:45 +03:00
</div>
<div id=p3 style=display:none>
<h1>My Events</h1>
2018-10-11 23:29:50 +03:00
<table style=width:100%;height:24px;background-color:#d3d9d6;margin-bottom:4px;vertical-align:middle;border-spacing:0>
<tr>
<td class=h1></td>
<td> <input id=p2deleteall type=button onclick=showDeleteAllEventsDialog() style=display:none value="Delete All..." /></td>
<td class=auto-style1>
Show
<select id=p3limitdropdown onchange=refreshEvents()>
<option value=60>Last 60</option>
<option value=120>Last 120</option>
<option value=250>Last 250</option>
<option value=500>Last 500</option>
<option value=1000>Last 1000</option>
</select>
</td>
<td class=h2></td>
</tr>
</table>
2018-09-15 03:42:39 +03:00
<div id=p3events style="height:calc(100vh - 243px);overflow-y:scroll"></div>
2017-08-28 19:27:45 +03:00
</div>
<div id=p4 style=display:none>
<h1>My Users</h1>
2018-10-11 23:29:50 +03:00
<table style=width:100%;height:24px;background-color:#d3d9d6;margin-bottom:4px;vertical-align:middle;border-spacing:0>
<tr>
<td class=h1></td>
<td class=style14>
2019-02-15 01:44:38 +03:00
<div style="float:right">
<input type=button onclick=showUserBroadcastDialog() value="Broadcast" />
</div>
<div>
<input type=button onclick=showCreateNewAccountDialog() value="New Account..." />
<input id=UserSearchInput type=text style=width:120px placeholder=Filter onchange=onUserSearchInputChanged() onkeyup=onUserSearchInputChanged() autocomplete=off onfocus=onUserSearchFocus(1) onblur=onUserSearchFocus(0) />
</div>
2018-10-11 23:29:50 +03:00
</td>
<td class=h2></td>
</tr>
</table>
2018-09-15 03:42:39 +03:00
<div id="p3users" style="max-height:calc(100vh - 243px);overflow-y:auto"></div>
2017-08-28 19:27:45 +03:00
</div>
<div id=p5 style=display:none>
<h1>My Files</h1>
2018-09-15 03:42:39 +03:00
<table id="p5toolbar" style="width:100%" cellpadding="0" cellspacing="0">
2017-08-28 19:27:45 +03:00
<tr>
<td style="width:100%;background-color:#d3d9d6;text-align:left;padding:4px" valign=bottom>
<div id="p5rightOfButtons" style="float:right;margin-top:3px"></div>
<div>
2018-04-04 03:07:48 +03:00
<input type=button id=p5FolderUp disabled="disabled" onclick="p5folderup();" value="Up" />
<input type=button id=p5SelectAllButton disabled="disabled" onclick="p5selectallfile();" value="Select All" onkeypress="return false;" onkeydown="return false;" />
<input type=button id=p5RenameFileButton disabled="disabled" value="Rename" onclick="p5renamefile();" onkeypress="return false;" onkeydown="return false;" />
<input type=button id=p5DeleteFileButton disabled="disabled" value="Delete" onclick="p5deletefile();" onkeypress="return false;" onkeydown="return false;" />
<input type=button id=p5NewFolderButton disabled="disabled" value="New Folder" onclick="p5createfolder();" onkeypress="return false;" onkeydown="return false;" />
<input type=button id=p5UploadButton disabled="disabled" value="Upload" onclick="p5uploadFile()" onkeypress="return false;" onkeydown="return false;" />
<input type=button id=p5CutButton disabled="disabled" value="Cut" onclick="p5copyFile(1)" onkeypress="return false" onkeydown="return false" />
<input type=button id=p5CopyButton disabled="disabled" value="Copy" onclick="p5copyFile(0)" onkeypress="return false" onkeydown="return false" />
<input type=button id=p5PasteButton disabled="disabled" value="Paste" onclick="p5pasteFile()" onkeypress="return false" onkeydown="return false" />
2017-08-28 19:27:45 +03:00
</div>
</td>
</tr>
<tr>
<td style="background-color:#E4E9E7;height:28px">
<div style=float:right>
<select id=p5sortdropdown onchange=updateFiles()>
<option value="1" selected="selected">Sort by name</option>
<option value="2">Sort by size</option>
<option value="3">Sort by date</option>
<option value="4">Descend by name</option>
<option value="5">Descend by size</option>
<option value="6">Descend by date</option>
</select>
</div>
<div> <span id="p5currentpath"></span></div>
</td>
</tr>
</table>
2018-09-15 03:42:39 +03:00
<div id="p5filetable" style="width:100%;height:calc(100vh - 294px);overflow:auto;-webkit-user-select:none;position:relative">
2017-08-28 19:27:45 +03:00
<!--
<form id=p5fileCatchAll method=post enctype=multipart/form-data action=uploadfile.ashx target=fileUploadFrame>
<input type=file id=p5fileCatchAllInput name=files style="position:absolute;left:0;width:100%;top:0;bottom:0;opacity:0;display:none" onchange="p5fileCatchAllInputChanged(event)" />
<input id=p5fileDragLink2 name="link" style="display:none" />
<input type=submit id=p5fileCatchAllSubmit style="display:none" />
</form>
-->
2018-12-17 00:44:49 +03:00
<div id="p5PublicShare" style="display:none;width:100%;overflow:auto;-webkit-user-select:none;background-color:lightsteelblue"><div style="padding:4px">These files are shared publicly, click "link" to get public url.</div></div>
2017-08-28 19:27:45 +03:00
<div id="bigok" style="width:256px;overflow:hidden;position:absolute;left:337px;top:20px;text-align:center;font-size:1600%;color:#AAAAAA;display:none"><b>✓</b></div>
<div id="bigfail" style="width:256px;overflow:hidden;position:absolute;left:337px;top:20px;text-align:center;font-size:1600%;color:#AAAAAA;display:none"><b>✗</b></div>
<span id="p5files"></span>
</div>
<table id="p5toolbarBottom" style=width:100% cellpadding=0 cellspacing=0>
2018-04-04 03:07:48 +03:00
<tr><td class=style6 style="text-align:left;padding:3px"> <span id="p5bottomstatus"></span></td></tr>
2017-08-28 19:27:45 +03:00
</table>
</div>
2018-09-27 00:58:55 +03:00
<div id=p6 style=display:none>
<img id=MainMeshImage src="serverpic.ashx" style=border-width:0px;height:200px;width:200px;float:right>
<h1>My Server</h1>
<p id="p2ServerActions"><strong>Server actions</strong></p>
<p style="margin-left:40px">
2019-02-06 06:07:12 +03:00
<div id="p2ServerActionsBackup" style="margin-left:40px"><a href="/backup.zip" rel="noreferrer noopener" target="_blank" style="cursor:pointer">Download server backup</a></div>
<div id="p2ServerActionsRestore" style="margin-left:40px"><a onclick="server_showRestoreDlg()" style="cursor:pointer">Restore server with backup</a></div>
<div id="p2ServerActionsVersion" style="margin-left:40px"><a onclick="server_showVersionDlg()" style="cursor:pointer">Check server version</a></div>
<div id="p2ServerActionsErrors" style="margin-left:40px"><a onclick="server_showErrorsDlg()" style="cursor:pointer">Show server error log</a></div>
2018-09-27 00:58:55 +03:00
</p>
<br /><strong>Server Statistics</strong><br /><br />
<div id="serverStats" style="margin-left:40px">
<div id="serverCpuChartView" style="display:none">
<div style="width:60px;display:inline-block"><canvas id="serverCpuChart" style="width:60px;height:60px"></canvas></div>
<div style="width:160px;display:inline-block" id="serverCpuChartText"></div>
</div>
<div id="serverMemoryChartView" style="display:none">
<div style="width:60px;display:inline-block"><canvas id="serverMemoryChart" style="width:60px;height:60px"></canvas></div>
<div style="width:160px;display:inline-block" id="serverMemoryChartText"></div>
</div><br /><br />
<div id="serverStatsTable"></div>
</div>
</div>
2018-09-15 03:42:39 +03:00
<div id=p10 style="display:none">
2017-08-28 19:27:45 +03:00
<table style="width:100%" cellpadding="0" cellspacing="0">
<tr>
<td style=width:auto valign=top>
2018-09-27 03:29:12 +03:00
<div id=p10title>
2019-01-30 01:08:29 +03:00
<div id="p10BackButton" style="float:left"><div class="backButton" onclick=goBack() title="Back"><div class="backButtonEx"></div></div></div>
2018-07-03 00:34:10 +03:00
<h1>General - <span id=p10deviceName></span></h1>
2017-12-14 01:52:57 +03:00
</div>
2017-08-28 19:27:45 +03:00
<div id=p10html></div>
</td>
<td style=width:20px></td>
<td style=width:200px>
<a style=cursor:pointer onclick=p10showiconselector()><img id=MainComputerImage style=border-width:0px;height:200px;width:200px></a>
<div style="width:100%;text-align:center"><strong><span id=MainComputerState></span></strong></div>
</td>
</tr>
</table><br>
<div id=p10html2></div>
<div id=p10html3></div>
</div>
2018-11-28 21:50:25 +03:00
<div id=p11 class=noselect style=display:none>
2017-12-14 01:52:57 +03:00
<div id="p11title">
2018-09-19 19:15:31 +03:00
<div id=p11deviceNameHeader>
2019-01-30 01:08:29 +03:00
<div id="p11BackButton" style="float:left"><div class="backButton" onclick=goBack() title="Back"><div class="backButtonEx"></div></div></div>
2018-11-28 21:50:25 +03:00
<div style="float:right" id="devListToolbarViewIcons"><div class="viewSelector" onclick=deskToggleFull(event) title="Full Screen. Hold shift to browser full screen."><div class="viewSelector5"></div></div></div>
2018-09-19 19:15:31 +03:00
<h1>Desktop - <span id=p11deviceName></span></h1>
</div>
2017-12-14 01:52:57 +03:00
</div>
2017-08-28 19:27:45 +03:00
<div id="p14warning" style='max-width:100%;display:none;cursor:pointer;margin-bottom:5px' onclick="showFeaturesDlg()">
2017-10-24 00:09:58 +03:00
<div class=icon2 style="float:left;margin:7px"></div>
2017-08-28 19:27:45 +03:00
<div style='width:auto;border-radius:8px;padding:8px;background-color:lightsalmon'>Intel® AMT Redirection port or KVM feature is disabled<span id="p14warninga">, click here to enable it.</span></div>
</div>
2017-10-24 00:09:58 +03:00
<div id="p14warning2" style='max-width:100%;display:none;cursor:pointer;margin-bottom:5px' onclick="showPowerActionDlg()">
<div class=icon2 style="float:left;margin:7px"></div>
<div style='width:auto;border-radius:8px;padding:8px;background-color:lightsalmon'>Remote computer is not powered on, click here to issue a power command.</div>
</div>
2018-11-28 21:50:25 +03:00
<table id=deskarea0 cellpadding=0 cellspacing=0 style="width:100%;padding:0px;padding:0px;margin-top:0px">
2017-10-24 00:09:58 +03:00
<tr id=deskarea1>
<td style="padding-top:2px;padding-bottom:2px;background:#C0C0C0">
<div style="float:right;text-align:right">
<span id="p14power"></span>
<div style='cursor:pointer;border:none;float:right;font-size:130%;margin-right:4px' title="Rotate Left" onclick="drotate(-1)">↺</div>
<div style='cursor:pointer;border:none;float:right;font-size:130%;margin-right:4px' title="Rotate Right" onclick="drotate(1)">↻</div>
<input id="deskFocusBtn" type="button" title="Toggle focus mode, when active only the region around the mouse is updated" onkeypress="return false" onkeydown="return false" value="Focus All" onclick="deskToggleFocus()" style="margin-right:3px;display:none">
<input id="deskSaveBtn" type="button" title="Save a screenshot of the remote desktop" onkeypress="return false" onkeydown="return false" value="Save..." onclick=deskSaveImage() style=margin-right:3px>
<input id="deskActionsBtn" type=button title="Perform power actions on the device" onkeypress="return false" onkeydown="return false" value=Actions onclick=deviceActionFunction() style=margin-right:3px />
2018-11-28 21:50:25 +03:00
<input id="deskActionsSettings" type="button" value="Settings..." title="Edit remote desktop settings" onkeypress="return false" onkeydown="return false" onclick="showDesktopSettings()" style="margin-right:3px">
2017-10-24 00:09:58 +03:00
<input type="button" title="Change the power state of the remote machine" onkeypress="return false" onkeydown="return false" value="Power Actions..." onclick="showPowerActionDlg()" style="margin-right:3px;display:none">
</div>
<div>
2018-11-28 21:50:25 +03:00
<div id="idx_deskFullBtn2" onclick=deskToggleFull(event) style="float:left;font-size:large;cursor:pointer;display:none"> ✖</div>
2017-10-24 00:09:58 +03:00
<input type="button" id="autoconnectbutton1" value="AutoConnect" onclick=autoConnectDesktop(event) onkeypress="return false" onkeydown="return false" style="display:none">
<span id=connectbutton1span> <input type=button id=connectbutton1 value="Connect" onclick=connectDesktop(event,1) onkeypress="return false" onkeydown="return false" disabled="disabled"></span>
<span id=connectbutton1hspan> <input type=button id=connectbutton1h value="HW Connect" onclick=connectDesktop(event,2) onkeypress="return false" onkeydown="return false" disabled="disabled"></span>
<span id=disconnectbutton1span> <input type=button id=disconnectbutton1 value="Disconnect" onclick=connectDesktop(event,0) onkeypress="return false" onkeydown="return false"></span>
<span id="deskstatus">Disconnected</span>
</div>
</td>
</tr>
<tr id=deskarea2>
<td>
2018-04-14 00:09:25 +03:00
<div style=background-color:gray><div id=progressbar style=height:2px;width:0%;background-color:red></div></div>
2017-10-24 00:09:58 +03:00
</td>
</tr>
<tr id=deskarea3>
2018-09-17 23:44:14 +03:00
<td id=deskarea3x style="background:black;text-align:center;position:relative;overflow:hidden">
<div id=DeskFocus style="overflow:hidden;color:transparent;border:3px dotted rgba(255,0,0,.2);position:absolute;border-radius:5px" oncontextmenu="return false" onmousedown=dmousedown(event) onmouseup=dmouseup(event) onmousemove=dmousemove(event)></div>
<div id=DeskParent style="overflow:hidden">
<canvas id=Desk width=640 height=480 style="overflow:hidden;width:100%;-ms-touch-action:none;margin-left:0px" oncontextmenu="return false" onmousedown=dmousedown(event) onmouseup=dmouseup(event) onmousemove=dmousemove(event) onmousewheel=dmousewheel(event)></canvas>
2018-03-31 01:26:36 +03:00
</div>
2018-04-14 00:09:25 +03:00
<div id=DeskTools style="position:absolute;width:400px;height:100%;background-color:gray;top:0;right:0;border-left:2px solid lightgray;display:none">
<a id=DeskToolsRefreshButton style="float:right;padding:3px;cursor:pointer" onclick="refreshDeskTools()">Refresh</a>
<div id=DeskToolsBar style="position:absolute;padding:3px;border-radius: 3px 3px 0px 0px;top:5px;left:4px;bottom:26px;background-color:lightgray;cursor:pointer">Processes</div>
2018-04-11 23:49:05 +03:00
<div style="position:absolute;top:26px;left:4px;right:4px;bottom:4px;background-color:lightgray;text-align:left">
<div style="border-bottom:1px solid darkgray;padding:3px"><a style=width:50px;padding-right:5px;float:left;cursor:pointer title="Sort by process id" onclick=sortProcess(0)>PID</a><a style=cursor:pointer title="Sort by name" onclick=sortProcess(1)>Name</a></div>
<div id="DeskToolsProcesses" style="overflow-y:scroll;position:absolute;top:24px;bottom:0px;width:100%"></div>
</div>
</div>
2017-10-24 00:09:58 +03:00
</td>
</tr>
<tr id=deskarea4>
2018-04-14 00:09:25 +03:00
<td style=padding-top:2px;padding-bottom:2px;background:#C0C0C0>
<div style=float:right;text-align:right>
<select id=termdisplays style=display:none onchange=deskSetDisplay(event) onclick=deskGetDisplayNumbers(event)></select>
<input id=DeskToolsButton type=button value=Tools title="Toggle tools view" onkeypress="return false" onkeydown="return false" onclick="toggleDeskTools()">
2018-12-20 23:12:24 +03:00
<span id=DeskChatButton style="float:right;margin-top:1px;margin-right:4px;cursor:pointer" title="Open chat window to this computer"><img src='images/icon-chat.png' onclick=deviceChat() height=16 width=16 style=padding-top:2px /></span>
<span id=DeskNotifyButton style="float:right;margin-top:1px;margin-right:4px;cursor:pointer" title="Display a notification on the remote computer"><img src='images/icon-notify.png' onclick=deviceToastFunction() height=16 width=16 style=padding-top:2px /></span>
<span id=DeskOpenWebButton style="float:right;margin-top:1px;margin-right:4px;cursor:pointer" title="Open a web address on remote computer"><img src='images/icon-url2.png' onclick=deviceUrlFunction() height=16 width=16 style=padding-top:2px /></span>
2018-01-03 03:52:49 +03:00
</div>
2017-10-24 00:09:58 +03:00
<div>
2018-04-29 01:36:10 +03:00
<select style="margin-left:6px" id="deskkeys">
2018-07-14 05:18:43 +03:00
<option value=5>Win</option>
2018-04-29 01:36:10 +03:00
<option value=0>Win+Down</option>
<option value=1>Win+Up</option>
<option value=2>Win+L</option>
<option value=3>Win+M</option>
<option value=4>Shift+Win+M</option>
2018-10-30 23:01:44 +03:00
<option value=6>Win+R</option>
2018-04-29 01:36:10 +03:00
</select>
<input id="DeskWD" type=button value="Send" onkeypress="return false" onkeydown="return false" onclick="deskSendKeys()">
2019-02-17 08:16:39 +03:00
<input id="DeskClip" style="margin-left:6px;display:none" type="button" value="Clipboard" onkeypress="return false" onkeydown="return false" onclick="showDeskClip()">
<input id="DeskCAD" type="button" value="Ctrl-Alt-Del" onkeypress="return false" onkeydown="return false" onclick="sendCAD()">
2019-02-20 02:51:38 +03:00
<label><span id="DeskControlSpan" style="margin-left:6px" title="Toggle mouse and keyboard input"><input id="DeskControl" type="checkbox" onkeypress="return false" onkeydown="return false" onclick="toggleKvmControl()">Input</span></label>
2017-10-24 00:09:58 +03:00
</div>
</td>
</tr>
</table>
2017-08-28 19:27:45 +03:00
</div>
2018-09-15 03:42:39 +03:00
<div id=p12 style="display:none">
2018-09-27 03:29:12 +03:00
<div id="p12title">
2019-01-30 01:08:29 +03:00
<div id="p12BackButton" style="float:left"><div class="backButton" onclick=goBack() title="Back"><div class="backButtonEx"></div></div></div>
2018-09-27 03:29:12 +03:00
<h1>Terminal - <span id=p12deviceName></span></h1>
</div>
2017-10-24 00:09:58 +03:00
<div id="p12warning" style='max-width:100%;display:none;cursor:pointer;margin-bottom:5px' onclick=showFeaturesDlg()>
<div class="icon2" style="float:left;margin:7px"></div>
<div style='width:auto;border-radius:8px;padding:8px;background-color:lightsalmon'>Intel® AMT Redirection port or KVM feature is disabled<span id="p14warninga">, click here to enable it.</span></div>
</div>
<div id="p12warning2" style='max-width:100%;display:none;cursor:pointer;margin-bottom:5px' onclick=showPowerActionDlg()>
<div class="icon2" style="float:left;margin:7px"></div>
<div style='width:auto;border-radius:8px;padding:8px;background-color:lightsalmon'>Remote computer is not powered on, click here to issue a power command.</div>
</div>
<table cellpadding=0 cellspacing=0 style="width:100%;padding:0px;padding:0px;margin-top:0px">
<tr>
<td style="padding-top:2px;padding-bottom:2px;background:#C0C0C0">
<div style="float:right;text-align:right">
<input id="termActionsBtn" type=button title="Perform power actions on the device" onkeypress="return false" onkeydown="return false" value=Actions onclick=deviceActionFunction() style=margin-right:3px />
</div>
<div>
<input type="button" id="autoconnectbutton2" value="AutoConnect" onclick=autoConnectTerminal(event) onkeypress="return false" onkeydown="return false" style="display:none">
<span id="connectbutton2span"> <input type="button" id="connectbutton2" value="Connect" onclick=connectTerminal(event,1) onkeypress="return false" onkeydown="return false" disabled="disabled"></span>
<span id="connectbutton2hspan"> <input type="button" id="connectbutton2h" value="HW Connect" onclick=connectTerminal(event,2) onkeypress="return false" onkeydown="return false" disabled="disabled"></span>
<span id="disconnectbutton2span"> <input type="button" id="disconnectbutton2" value="Disconnect" onclick=connectTerminal(event,0) onkeypress="return false" onkeydown="return false"></span>
<span id="termstatus">Disconnected</span>
</div>
</td>
</tr>
<tr>
<td>
<div style="background-color:gray"><div id="termprogressbar" style="height:2px;width:0%;background-color:red"></div></div>
</td>
</tr>
<tr>
<td style="background:black;text-align:center;height:500px;position:relative">
<pre id="Term" style="background:black;margin:0;padding:0"></pre>
</td>
</tr>
<tr>
<td style="padding-top:2px;padding-bottom:2px;background:#C0C0C0">
<div style="float:right;text-align:right">
2018-09-19 00:47:17 +03:00
<span id="terminalSettingsButtons" style="display:none">
<input id="id_tcrbutton" type="button" onkeypress="return false" onkeydown="return false" class="bottombutton" value="CR+LF" title="Toggle what the return key will send" onclick="termToggleCr()">
<input id="id_tfxkeysbutton" type="button" onkeypress="return false" onkeydown="return false" class="bottombutton" value="Intel (F10 = ESC+[OM)" title="Toggle F1 to F10 keys emulation type" onclick="termToggleFx()">
<input id="id_ttypebutton" type="button" onkeypress="return false" onkeydown="return false" class="bottombutton" value="Extended Ascii" title="Toggle terminal emulation type" onclick="termToggleType()">
</span>
<select id="specialkeylist" onkeypress="return false" style="margin-left:5px"></select>
<input id="specialkeylistinput" type="button" onkeypress="return false" class="bottombutton" value="Send" title="Send the selected special key" onclick="sendSpecialKey()" />
2017-10-24 00:09:58 +03:00
</div>
<div>
<input type=button onkeypress="return false" onkeydown="return false" class="bottombutton" id="ctrlcbutton" value="Ctl-C" onclick="termSendKey(3,'ctrlcbutton')" />
<input type=button onkeypress="return false" onkeydown="return false" class="bottombutton" id="ctrlxbutton" value="Ctl-X" onclick="termSendKey(24,'ctrlxbutton')" />
<input type=button onkeypress="return false" onkeydown="return false" class="bottombutton" id="escbutton" value="ESC" onclick="termSendKey(27,'escbutton')" />
<input type=button onkeypress="return false" onkeydown="return false" class="bottombutton" id="bsbutton" value="Backspace" onclick="termSendKey(8,'bsbutton')" />
<input type=button onkeypress="return false" onkeydown="return false" class="bottombutton" id="pastebutton" value="Paste" title="Paste text into the terminal" onclick="showTermPasteDialog()" />
</div>
</td>
</tr>
</table>
2017-08-28 19:27:45 +03:00
</div>
2017-10-24 00:09:58 +03:00
<div id=p13 style=display:none>
2018-09-27 03:29:12 +03:00
<div id="p13title">
2019-01-30 01:08:29 +03:00
<div id="p13BackButton" style="float:left"><div class="backButton" onclick=goBack() title="Back"><div class="backButtonEx"></div></div></div>
2018-09-27 03:29:12 +03:00
<h1>Files - <span id=p13deviceName></span></h1>
</div>
2017-10-24 00:09:58 +03:00
<table id="p13toolbar" style="width: 100%" cellpadding="0" cellspacing="0">
<tr>
<td style="background-color:#C0C0C0;border-bottom:2px solid black;padding:2px">
<div style="float:right;text-align:right">
<input id="filesActionsBtn" type=button title="Perform power actions on the device" onkeypress="return false" onkeydown="return false" value=Actions onclick=deviceActionFunction() style=margin-right:3px />
</div>
<div>
<input id=p13AutoConnect value="AutoConnect" onclick=autoConnectFiles(event) onkeypress="return false" onkeydown="return false" type="button" style="display:none">
<input id=p13Connect value="Connect" onclick=connectFiles(event) onkeypress="return false" onkeydown="return false" type="button">
<span id=p13Status>Disconnected</span>
</div>
</td>
</tr>
<tr>
<td style="width:100%;background-color:#d3d9d6;text-align:left;padding:4px" valign=bottom>
<div id="p13rightOfButtons" style="float:right;margin-top:3px"></div>
<div>
<input type=button id=p13FolderUp disabled="disabled" onclick="p13folderup()" value="Up" />
<input type=button id=p13SelectAllButton disabled="disabled" onclick="p13selectallfile()" value="Select All" onkeypress="return false" onkeydown="return false" />
<input type=button id=p13RenameFileButton disabled="disabled" value="Rename" onclick="p13renamefile()" onkeypress="return false" onkeydown="return false" />
<input type=button id=p13DeleteFileButton disabled="disabled" value="Delete" onclick="p13deletefile()" onkeypress="return false" onkeydown="return false" />
<input type=button id=p13NewFolderButton disabled="disabled" value="New Folder" onclick="p13createfolder()" onkeypress="return false" onkeydown="return false" />
<input type=button id=p13UploadButton disabled="disabled" value="Upload" onclick="p13uploadFile()" onkeypress="return false" onkeydown="return false" />
2018-04-03 01:34:32 +03:00
<input type=button id=p13CutButton disabled="disabled" value="Cut" onclick="p13copyFile(1)" onkeypress="return false" onkeydown="return false" />
<input type=button id=p13CopyButton disabled="disabled" value="Copy" onclick="p13copyFile(0)" onkeypress="return false" onkeydown="return false" />
<input type=button id=p13PasteButton disabled="disabled" value="Paste" onclick="p13pasteFile()" onkeypress="return false" onkeydown="return false" />
2017-10-24 00:09:58 +03:00
<input type=button id=p13RefreshButton disabled="disabled" value="Refresh" onclick="p13folderup(9999)" onkeypress="return false" onkeydown="return false" />
</div>
</td>
</tr>
<tr>
<td style="background-color:#E4E9E7;height:28px">
<div style=float:right>
<select id=p13sortdropdown onchange=p13updateFiles()>
<option value=1 selected="selected">Sort by name</option>
<option value=2>Sort by size</option>
<option value=3>Sort by date</option>
<option value=4>Descend by name</option>
<option value=5>Descend by size</option>
<option value=6>Descend by date</option>
</select>
</div>
<div> <span id="p13currentpath"></span></div>
</td>
</tr>
</table>
2018-09-15 03:42:39 +03:00
<div id="p13filetable" style="width:100%;height:calc(100vh - 346px);overflow:auto;-webkit-user-select:none">
2017-10-24 00:09:58 +03:00
<div id="p13bigok" style="width:256px;overflow:hidden;position:absolute;left:337px;top:200px;text-align:center;font-size:1600%;color:#AAAAAA;display:none"><b>✓</b></div>
<div id="p13bigfail" style="width:256px;overflow:hidden;position:absolute;left:337px;top:200px;text-align:center;font-size:1600%;color:#AAAAAA;display:none"><b>✗</b></div>
<span id="p13files"></span>
</div>
<table id="p13toolbarBottom" style=width:100% cellpadding=0 cellspacing=0>
2018-04-03 01:34:32 +03:00
<tr><td class=style6 style="text-align:left;padding:3px"> <span id="p13bottomstatus"></span></td></tr>
2017-10-24 00:09:58 +03:00
</table>
2017-08-28 19:27:45 +03:00
</div>
2017-10-24 00:09:58 +03:00
<div id=p14 style=display:none>
2018-09-27 03:29:12 +03:00
<div id="p14title">
2019-01-30 01:08:29 +03:00
<div id="p14BackButton" style="float:left"><div class="backButton" onclick=goBack() title="Back"><div class="backButtonEx"></div></div></div>
2018-09-27 03:29:12 +03:00
<h1>Intel® AMT - <span id=p14deviceName></span></h1>
</div>
2018-09-15 03:42:39 +03:00
<iframe id=p14iframe style="width:100%;height:calc(100vh - 242px);border:0;overflow:hidden" src="/commander.htm"></iframe>
2017-08-28 19:27:45 +03:00
</div>
2017-10-24 00:09:58 +03:00
<div id=p15 style=display:none>
2018-09-27 03:29:12 +03:00
<div id="p15title">
2019-01-30 01:08:29 +03:00
<div id="p15BackButton" style="float:left"><div class="backButton" onclick=goBack() title="Back"><div class="backButtonEx"></div></div></div>
2019-02-05 05:06:01 +03:00
<h1><span id=p15deviceName></span></h1>
2018-09-27 03:29:12 +03:00
</div>
2017-10-24 00:09:58 +03:00
<table cellpadding=0 cellspacing=0 style="width:100%;padding:0px;padding:0px;margin-top:0px">
<tr>
<td style=background:#C0C0C0>
<div style=float:right;padding-right:4px>
2017-12-15 01:57:52 +03:00
<div style=padding:4px;display:inline-block id=p15coreName title="Information about current core running on this agent"></div>
<input type=button id=p15uploadCore value="Agent Action" onclick=p15uploadCore(event) title="Change the agent Java Script code module" />
2017-10-24 00:09:58 +03:00
</div>
<div id="p15statetext" style=padding:4px></div>
</td>
</tr>
<tr>
<td>
<div style="background-color:gray"><div id="consoleprogressbar" style="height:2px;width:0%;background-color:red"></div></div>
</td>
</tr>
<tr>
2018-09-15 03:42:39 +03:00
<td id=p15agentConsole style="background:black;margin:0;padding:0;color:lightgray;width:100%;height:calc(100vh - 296px);max-height:500px;position:relative">
<pre id=p15agentConsoleText style="position:absolute;margin:0;padding:0;top:0;bottom:0;left:0;right:0;overflow-y:scroll;overflow-x:auto"></pre>
2017-10-24 00:09:58 +03:00
</td>
</tr>
<tr>
<td style="padding-top:2px;padding-bottom:2px;background:#C0C0C0">
<table style="width:100%">
<tr>
<td style="width:99%">
<input id=p15consoleText style=width:100% onkeyup=p15consoleSend(event) onfocus=onConsoleFocus(1) onblur=onConsoleFocus(0) />
</td>
<td> </td>
<td style="width:1%"><input id="id_p15consoleClear" type="button" onkeypress="return false" onkeydown="return false" class="bottombutton" value="Clear" onclick="p15consoleClear()"></td>
</tr>
</table>
</td>
</tr>
</table>
2017-08-28 19:27:45 +03:00
</div>
2018-04-17 01:37:41 +03:00
<div id=p16 style=display:none>
2018-09-27 03:29:12 +03:00
<div id="p16title">
2019-01-30 01:08:29 +03:00
<div id="p16BackButton" style="float:left"><div class="backButton" onclick=goBack() title="Back"><div class="backButtonEx"></div></div></div>
2018-09-27 03:29:12 +03:00
<h1>Events - <span id=p16deviceName></span></h1>
</div>
2018-04-17 01:37:41 +03:00
<div style=width:100%;height:24px;background-color:#d3d9d6;margin-bottom:4px>
<div class=style7 style=width:16px;height:100%;float:left> </div>
<div class=h1 style=height:100%;float:left> </div>
<!--<div class=style14 style=height:100%;float:left> <input id=p31deleteall type=button style=display:none value="Delete All..." /> </div>-->
<div class=style14 style=height:100%;float:left> <input type=button value=Refresh onclick=refreshDeviceEvents() /> </div>
<div class="auto-style1" style="height:100%;float:right">
Show
<select id=p16limitdropdown onchange=refreshDeviceEvents()>
<option value=60>Last 60</option>
<option value=120>Last 120</option>
<option value=250>Last 250</option>
<option value=500>Last 500</option>
<option value=1000>Last 1000</option>
</select>
<div style="height:100%;width:20px;float:right;background-color:#ffffff"></div>
<div class=h2 style=height:100%;float:right> </div>
</div>
</div>
2018-09-15 03:42:39 +03:00
<div id=p16events style="max-height:calc(100vh - 267px);overflow-y:auto"></div>
2018-04-17 01:37:41 +03:00
</div>
2018-09-15 03:42:39 +03:00
<div id=p20 style="display:none">
2018-11-03 04:13:32 +03:00
<picture id=MainMeshImage style=border-width:0px;height:200px;width:200px;float:right>
<source type="image/webp" width=200 height=200 srcset="images/webp/mesh-200.webp">
<img alt="" width=200 height=200 src=images/mesh-200.jpg />
</picture>
2018-09-27 03:29:12 +03:00
<div style="float:left"><div class="backButton" onclick=goBack() title="Back"><div class="backButtonEx"></div></div></div>
<h1>General - <span id=p20meshName></span></h1>
2017-10-24 00:09:58 +03:00
<p id=p20info></p>
</div>
2018-04-16 08:22:44 +03:00
<div id=p30 style=display:none>
<table style="width:100%" cellpadding="0" cellspacing="0">
<tr>
<td style=width:auto valign=top>
<div id="p30title">
2018-09-27 03:29:12 +03:00
<div style="float:left"><div class="backButton" onclick=goBack() title="Back"><div class="backButtonEx"></div></div></div>
<h1>General - <span id=p30userName></span></h1>
2018-04-16 08:22:44 +03:00
</div>
<div id=p30html></div>
</td>
<td style=width:20px></td>
<td style=width:200px>
2018-11-03 04:13:32 +03:00
<picture id=MainUserImage style=border-width:0px;height:200px;width:200px;float:right>
<source type="image/webp" width=200 height=200 srcset="images/webp/user-200.webp">
<img alt="" width=200 height=200 src=images/user-200.jpg />
</picture>
2018-04-16 08:22:44 +03:00
<div style="width:100%;text-align:center"><strong><span id=MainUserState></span></strong></div>
</td>
</tr>
</table><br>
<div id=p30html2></div>
<div id=p30html3></div>
</div>
<div id=p31 style=display:none>
2018-09-27 03:29:12 +03:00
<div style="float:left"><div class="backButton" onclick=goBack() title="Back"><div class="backButtonEx"></div></div></div>
<h1>Events - <span id=p31userName></span></h1>
2018-04-16 08:22:44 +03:00
<div style=width:100%;height:24px;background-color:#d3d9d6;margin-bottom:4px>
<div class=style7 style=width:16px;height:100%;float:left> </div>
<div class=h1 style=height:100%;float:left> </div>
<!--<div class=style14 style=height:100%;float:left> <input id=p31deleteall type=button style=display:none value="Delete All..." /> </div>-->
<div class=style14 style=height:100%;float:left> <input type=button value=Refresh onclick=refreshUsersEvents() /> </div>
<div class="auto-style1" style="height:100%;float:right">
Show
<select id=p31limitdropdown onchange=refreshUsersEvents()>
<option value=60>Last 60</option>
<option value=120>Last 120</option>
<option value=250>Last 250</option>
<option value=500>Last 500</option>
<option value=1000>Last 1000</option>
</select>
<div style="height:100%;width:20px;float:right;background-color:#ffffff"></div>
<div class="h2" style="height:100%;float:right;"> </div>
</div>
</div>
2018-09-15 03:42:39 +03:00
<div id=p31events style="max-height:calc(100vh - 267px);overflow-y:scroll"></div>
2018-04-16 08:22:44 +03:00
</div>
2017-10-24 00:09:58 +03:00
<br id="column_l_bottomgap" />
</div>
<div id=footer class=noselect>
<table cellpadding=0 cellspacing=10 style="width:100%">
<tr>
2018-01-10 07:13:41 +03:00
<td style="text-align:left;color:white">
{{{ footer }}}
</td>
2017-12-13 05:23:26 +03:00
<td style="text-align:right">
2017-12-14 01:52:57 +03:00
<a id="verifyEmailId2" style="color:yellow;margin-left:3px;cursor:pointer;display:none" onclick="account_showVerifyEmail()">Verify Email</a>
2017-12-13 05:23:26 +03:00
<a style="margin-left:3px" href="terms">Terms & Privacy</a>
</td>
2017-10-24 00:09:58 +03:00
</tr>
</table>
2017-08-28 19:27:45 +03:00
</div>
2019-01-24 05:07:02 +03:00
<div id=dialog style="z-index:1000;background-color:#EEE;box-shadow:0px 0px 15px #666;font-family:Arial,Helvetica,sans-serif;border-radius:5px;position:fixed;top:160px;width:400px;left:calc((100% / 2) - 200px);display:none">
2017-10-24 00:09:58 +03:00
<div style="width:100%;background-color:#003366;color:#FFF;border-radius:5px 5px 0 0">
2018-09-19 19:15:31 +03:00
<div id=id_dialogclose style=float:right;padding:3px;margin-right:3px;cursor:pointer onclick=setDialogMode()>✖</div>
2017-10-24 00:09:58 +03:00
<div id=id_dialogtitle style=padding:5px></div>
<div style=width:100%;margin:6px></div>
</div>
<div style="margin-right:16px;margin-left:8px">
<div id=dialog1 style="margin:auto;text-align:center;margin:3px">
<div id=id_dialogMessage style="padding:10px"></div>
2017-08-28 19:27:45 +03:00
</div>
2017-10-24 00:09:58 +03:00
<div id=dialog2 style="margin:auto;margin:3px">
<div id=id_dialogOptions></div>
2017-08-28 19:27:45 +03:00
</div>
2017-10-24 00:09:58 +03:00
<div id=dialog3 style="margin:auto;margin:3px">
<div style=height:26px>
<select id=d3uploadMode style=float:right;width:260px onchange=d3modechange()>
<option value=1>Local file upload</option>
<option value=2>Server file selection</option>
</select>
<div>File Selection</div>
</div>
<div id=d3localmode style=height:26px;display:none>
<form id=d3localmodeform method=post enctype=multipart/form-data action=uploadfile.ashx target=fileUploadFrame>
<input type=text id=d3attrib name=attrib style=display:none />
<input type=file id=d3localFile name=files style=float:right;width:260px onchange=d3setActions() />
<input type=submit id=d3submit style=display:none />
</form>
<div>Upload File</div>
</div>
<div id=d3servermode>
<div style="width:100%;background-color:#d3d9d6;text-align:left;padding:3px" valign=bottom>
<input type=button id=p3FolderUp disabled="disabled" onclick=d3folderup() value="Up" />
</div>
<div id=d3serverfiles style="width:100%;height:150px;background-color:white;padding:2px;border:1px solid gray;overflow-y:scroll"></div>
</div>
2017-08-28 19:27:45 +03:00
</div>
2017-10-24 00:09:58 +03:00
<div id=dialog7 style="margin:auto;margin:3px">
<div id="d7meshkvm">
2018-09-25 03:47:03 +03:00
<h4 style="width:100%;border-bottom:1px solid gray">Agent Remote Desktop</h4>
2017-10-24 00:09:58 +03:00
<div style="margin:3px 0 3px 0">
2018-03-21 03:48:03 +03:00
<select id="d7bitmapquality" style="float:right;width:200px;height:20px" dir="rtl"></select>
2017-10-24 00:09:58 +03:00
<div style="height:20px">Quality</div>
</div>
<div style="margin:3px 0 3px 0">
<select id="d7bitmapscaling" style="float:right;width:200px;height:20px" dir="rtl">
<option selected=selected value=1024>100%</option>
<option value=896>87.5%</option>
<option value=768>75%</option>
<option value=640>62.5%</option>
<option value=512>50%</option>
<option value=384>37.5%</option>
<option value=256>25%</option>
<option value=128>12.5%</option>
</select>
<div style="height:20px">Scaling</div>
</div>
2018-04-07 01:56:45 +03:00
<div style="margin:3px 0 3px 0">
<select id="d7framelimiter" style="float:right;width:200px;height:20px" dir="rtl">
<option selected=selected value=50>Fast</option>
<option value=100>Medium</option>
<option value=400>Slow</option>
<option value=1000>Very slow</option>
</select>
<div style="height:20px">Frame rate</div>
</div>
2017-10-24 00:09:58 +03:00
</div>
<div id="d7amtkvm">
<h4 style="width:100%;border-bottom:1px solid gray">Intel® AMT Hardware KVM</h4>
<div style='height:26px'>
<select id="d7desktopmode" style="float:right;width:200px">
<option value="1">RLE8, Fastest</option>
<option value="2">RLE16, Recommended</option>
<option value="3">RAW8, Slow</option>
<option value="4">RAW16, Very Slow</option>
</select>
<div>Image Encoding</div>
</div>
<div style="height:60px">
<div style="float:right;border:1px solid #666;width:200px;height:60px;overflow-y:scroll;background-color:white">
2019-02-20 02:51:38 +03:00
<label><input type="checkbox" id='d7showfocus'>Show Focus Tool<br></label>
<label><input type="checkbox" id='d7showcursor'>Show Local Mouse Cursor<br></label>
2017-10-24 00:09:58 +03:00
</div>
<div>Other Settings</div>
</div>
2017-08-28 19:27:45 +03:00
</div>
</div>
</div>
2017-10-24 00:09:58 +03:00
<div id="idx_dlgButtonBar" style="padding:10px;margin-bottom:4px">
<input id="idx_dlgCancelButton" type="button" value="Cancel" style="float:right;width:80px;margin-left:5px" onclick="dialogclose(0)">
<input id="idx_dlgOkButton" type="button" value="OK" style="float:right;width:80px" onclick="dialogclose(1)">
<div style="height:25px"><input id=idx_dlgDeleteButton type=button value=Delete style="width:80px;display:none" onclick="dialogclose(2)"></div>
</div>
2017-08-28 19:27:45 +03:00
</div>
2017-10-24 00:09:58 +03:00
<iframe name="fileUploadFrame" style=display:none></iframe>
<form style=display:none method=post action=uploadfile.ashx enctype=multipart/form-data target=fileUploadFrame><input id=p5fileDragName name="name"><input id=p5fileDragSize name="size"><input id=p5fileDragType name="type"><input id=p5fileDragData name="data"><input id=p5fileDragLink name="link"><input type=submit id=p5loginSubmit2 style=display:none /></form>
<form style=display:none method=post action=uploadnodefile.ashx enctype=multipart/form-data target=fileUploadFrame><input id=p13fileDragName name="name"><input id=p13fileDragSize name="size"><input id=p13fileDragType name="type"><input id=p13fileDragData name="data"><input id=p13fileDragLink name="link"><input type=submit id=p13loginSubmit2 style=display:none /></form>
<audio id="chimes"><source src="sounds/chimes.mp3" type="audio/mp3"></audio>
2017-08-28 19:27:45 +03:00
</div>
</div>
<script type="text/javascript">
2018-08-27 22:24:15 +03:00
'use strict';
2017-12-14 01:52:57 +03:00
var args;
2019-02-12 01:41:15 +03:00
var autoReconnect = true;
2017-08-28 19:27:45 +03:00
var powerStatetable = ['', 'Powered', 'Sleep', 'Sleep', 'Sleep', 'Hibernating', 'Power off', 'Present'];
var StatusStrs = ['Disconnected', 'Connecting...', 'Setup...', 'Connected', 'Intel® AMT Connected'];
var sort = 0;
var searchFocus = 0;
2017-08-30 00:34:13 +03:00
var mapSearchFocus = 0;
2018-07-17 03:49:55 +03:00
var userSearchFocus = 0;
2017-08-28 19:27:45 +03:00
var consoleFocus = 0;
2018-05-22 02:36:51 +03:00
var showRealNames = false;
2017-08-28 19:27:45 +03:00
var meshserver = null;
var meshes = { };
2017-10-03 00:12:29 +03:00
var meshcount = 0;
2019-01-30 01:08:29 +03:00
var nodes = null;
2017-08-28 19:27:45 +03:00
var filetree = { };
var userinfo = null;
var serverinfo = null;
var events = [];
var users = null;
var wssessions = null;
var nodeShortIdent = 0;
var desktop;
2018-04-07 01:56:45 +03:00
var desktopsettings = { encoding: 2, showfocus: false, showmouse: true, showcad: true, quality: 40, scaling: 1024, framerate: 50 };
var multidesktopsettings = { quality: 20, scaling: 128, framerate: 1000 };
2017-08-28 19:27:45 +03:00
var terminal;
var files;
2018-08-24 02:55:06 +03:00
var debugLevel = parseInt(" {{{ debuglevel }}} ");
var features = parseInt(" {{{ features }}} ");
2018-08-24 23:14:20 +03:00
var sessionTime = parseInt(" {{{ sessiontime }}} ");
var domain = " {{{ domain }}} ";
var domainUrl = " {{{ domainurl }}} ";
2019-01-29 02:47:54 +03:00
var authCookie = " {{{ authCookie }}} ";
2019-01-30 01:08:29 +03:00
var authCookieRenewTimer = null;
2018-03-31 01:26:36 +03:00
var multiDesktop = { };
2018-04-02 21:13:10 +03:00
var multiDesktopFilter = null;
2017-08-28 19:27:45 +03:00
var serverPublicNamePort = " {{{ serverDnsName }}} : {{{ serverPublicPort }}} ";
var amtScanResults = null;
2018-09-19 00:47:17 +03:00
var debugmode = 0;
2018-02-13 23:28:11 +03:00
var clickOnce = (((features & 256) != 0) && detectClickOnce());
var attemptWebRTC = ((features & 128) != 0);
2018-09-15 03:42:39 +03:00
var webPageFullScreen = getstore('webPageFullScreen', true);
2018-03-07 04:50:44 +03:00
if (webPageFullScreen == 'false') { webPageFullScreen = false; }
2018-09-15 03:42:39 +03:00
if (webPageFullScreen == 'true') { webPageFullScreen = true; }
2018-12-21 01:14:37 +03:00
var passRequirements = " {{{ passRequirements }}} ";
if (passRequirements != "") { passRequirements = JSON.parse(decodeURIComponent(passRequirements)); }
2017-08-28 19:27:45 +03:00
function startup() {
2017-12-19 19:50:19 +03:00
if ((features & 32) == 0) {
// Guard against other site's top frames (web bugs).
var loc = null;
try { loc = top.location.toString().toLowerCase(); } catch (e) { }
if (top != self && (loc == null || top.active == false)) { top.location = self.location; return; }
}
2017-08-28 19:27:45 +03:00
2017-10-04 04:31:20 +03:00
// Check if we are in debug mode
2017-12-14 01:52:57 +03:00
args = parseUriArgs();
2018-09-19 00:47:17 +03:00
debugmode = args.debug;
2018-04-18 05:00:31 +03:00
if (args.webrtc != null) { attemptWebRTC = (args.webrtc == 1); }
2017-10-04 04:31:20 +03:00
QV('p13AutoConnect', debugmode); // Files
QV('autoconnectbutton2', debugmode); // Terminal
QV('autoconnectbutton1', debugmode); // Desktop
2019-02-17 08:16:39 +03:00
QV('DeskClip', debugmode); // Clipboard feature, not completed so show in in debug mode only.
2017-10-04 04:31:20 +03:00
2019-01-30 01:08:29 +03:00
toggleFullScreen();
2017-08-28 19:27:45 +03:00
// Setup page visuals
2017-12-14 01:52:57 +03:00
if (args.hide) {
var hide = parseInt(args.hide);
QV('masthead', !(hide & 1));
QV('topbarmaster', !(hide & 2));
QV('footer', !(hide & 4));
QV('p10title', !(hide & 8));
QV('p11title', !(hide & 8));
QV('p12title', !(hide & 8));
QV('p13title', !(hide & 8));
QV('p14title', !(hide & 8));
QV('p15title', !(hide & 8));
2018-04-17 01:37:41 +03:00
QV('p16title', !(hide & 8));
2019-01-30 01:08:29 +03:00
if (hide & 16) {
QV('page_leftbar', false);
QS('page_content').left = '0px';
}
}
// We are looking at a single device, remove all the back buttons
if (' {{ currentNode }} ' != '') {
QV('p10BackButton', false);
QV('p11BackButton', false);
QV('p12BackButton', false);
QV('p13BackButton', false);
QV('p14BackButton', false);
QV('p15BackButton', false);
QV('p16BackButton', false);
2017-12-14 01:52:57 +03:00
}
2017-08-28 19:27:45 +03:00
p1updateInfo();
// Setup the context menu
document.onclick = function (e) { hideContextMenu(); }
document.onkeypress = ondockeypress;
document.onkeydown = ondockeydown;
document.onkeyup = ondockeyup;
2019-01-22 22:44:46 +03:00
window.onresize = function () { masterUpdate(512); }
masterUpdate(512);
2017-08-28 19:27:45 +03:00
// Connect to the mesh server
2019-01-29 02:47:54 +03:00
meshserver = MeshServerCreateControl(domainUrl, authCookie);
2017-08-28 19:27:45 +03:00
meshserver.onStateChanged = onStateChanged;
meshserver.onMessage = onMessage;
meshserver.Start();
// Setup page controls
2018-03-31 01:26:36 +03:00
Q('sortselect').selectedIndex = sort = getstore("sort", 0);
Q('sizeselect').selectedIndex = getstore("viewsize", 1);
2017-08-28 19:27:45 +03:00
Q('SearchInput').value = getstore("search", "");
2018-05-22 02:36:51 +03:00
showRealNames = (getstore("showRealNames", 0) == 1);
Q('RealNameCheckBox').checked = showRealNames;
2017-08-28 19:27:45 +03:00
Q('viewselect').value = getstore("deviceView", 1);
2018-04-02 21:13:10 +03:00
Q('DeskControl').checked = (getstore('DeskControl', 1) == 1);
2017-08-28 19:27:45 +03:00
// Display the page devices
2019-01-22 22:44:46 +03:00
masterUpdate(3)
2018-09-19 00:47:17 +03:00
for (var j = 1; j < 5; j++) { Q('devViewButton' + j).classList.remove('viewSelectorSel'); }
Q('devViewButton' + Q('viewselect').value).classList.add('viewSelectorSel');
2017-08-28 19:27:45 +03:00
// Setup upload drag & drop
Q('p5filetable').addEventListener("drop", p5fileDragDrop, false);
Q('p5filetable').addEventListener("dragover", p5fileDragOver, false);
Q('p5filetable').addEventListener("dragleave", p5fileDragLeave, false);
//Q('p5fileCatchAllInput').addEventListener("drop", p5fileDragDrop, false);
//Q('p5fileCatchAllInput').addEventListener("dragover", p5fileDragOver, false);
//Q('p5fileCatchAllInput').addEventListener("dragleave", p5fileDragLeave, false);
// Setup upload drag & drop
Q('p13filetable').addEventListener("drop", p13fileDragDrop, false);
Q('p13filetable').addEventListener("dragover", p13fileDragOver, false);
Q('p13filetable').addEventListener("dragleave", p13fileDragLeave, false);
// Timeline update interval
setInterval(updateDeviceTimeline, 120000); // Check every 2 minutes
// Load desktop settings
2018-03-31 01:26:36 +03:00
var t = localStorage.getItem('desktopsettings');
2017-08-28 19:27:45 +03:00
if (t != null) { desktopsettings = JSON.parse(t); }
2018-03-31 01:26:36 +03:00
t = localStorage.getItem('multidesktopsettings');
if (t != null) { multidesktopsettings = JSON.parse(t); }
2017-08-28 19:27:45 +03:00
applyDesktopSettings();
// Terminal special keys
var x = '';
for (var c = 1; c < 27; c++) x += "<option value='" + c + "'>Ctrl-" + String.fromCharCode(64 + c) + " (" + c + ")</option>";
QH('specialkeylist', x);
2018-09-27 00:58:55 +03:00
// Setup server stats panel
setupServerStats();
2017-08-28 19:27:45 +03:00
}
2018-03-07 04:50:44 +03:00
// Toggle the web page to full screen
function toggleFullScreen(toggle) {
if (toggle === 1) { webPageFullScreen = !webPageFullScreen; putstore('webPageFullScreen', webPageFullScreen); }
2019-01-30 01:08:29 +03:00
var hide = 0;
if (args.hide) { hide = parseInt(args.hide); }
2018-03-07 04:50:44 +03:00
if (webPageFullScreen == false) {
QS('container').width = '960px';
QS('container')['border-right'] = '1px solid #b7b7b7';
QS('container')['border-left'] = '1px solid #b7b7b7';
QS('container')['min-width'] = '960px';
2018-09-15 03:42:39 +03:00
QS('container')['overflow'] = '';
2018-03-07 04:50:44 +03:00
QS('column_l').width = '930px';
2018-09-15 03:42:39 +03:00
QS('column_l').height = '';
QS('column_l')['margin-left'] = '';
QS('column_l')["overflow-y"] = '';
QS('column_l')["max-height"] = (xxcurrentView >= 10) ? 'calc(100vh - 159px)' : 'calc(100vh - 135px)';
QS('container').position = '';
QS('page_content').position = '';
QV('MainMenuSpan', true);
QV('UserDummyMenuSpan', false);
QV('page_leftbar', false);
2018-03-07 04:50:44 +03:00
} else {
2018-09-15 03:42:39 +03:00
QS('container').position = 'absolute';
2018-03-07 04:50:44 +03:00
QS('container').width = '100%';
2018-09-15 03:42:39 +03:00
QS('container').top = '0px';
QS('container').bottom = '0px';
2018-03-07 04:50:44 +03:00
QS('container')['border-right'] = '0';
QS('container')['border-left'] = '0';
QS('container')['min-width'] = '700px';
2018-09-15 03:42:39 +03:00
QS('container')['overflow'] = 'hidden';
QS('page_content').position = 'absolute';
QS('page_content').top = '66px';
2019-01-30 01:08:29 +03:00
QS('page_content').left = (hide & 16)?'0px':'90px';
2018-09-15 03:42:39 +03:00
QS('page_content').right = '0px';
QS('page_content').bottom = '0px';
QS('column_l').height = 'calc(100vh - 135px)';
2018-03-07 04:50:44 +03:00
QS('column_l').width = 'calc(100% - 30px)';
2018-09-15 03:42:39 +03:00
QS('column_l')["overflow-y"] = 'auto';
QS('column_l')["max-height"] = 'calc(100vh - 135px)';
QV('MainMenuSpan', false);
QV('UserDummyMenuSpan', (xxcurrentView < 10) && webPageFullScreen);
2019-01-30 01:08:29 +03:00
QV('page_leftbar', !(hide & 16));
2018-03-07 04:50:44 +03:00
}
2019-01-22 22:44:46 +03:00
//center();
masterUpdate(512);
2018-09-15 03:42:39 +03:00
QV('body', true);
2018-03-07 04:50:44 +03:00
}
2019-01-30 01:08:29 +03:00
function getNodeFromId(id) { if (nodes != null) { for (var i in nodes) { if (nodes[i]._id == id) return nodes[i]; } } return null; }
2017-08-28 19:27:45 +03:00
function reload() { window.location.href = window.location.href; }
2019-01-27 23:23:38 +03:00
function onStateChanged(server, state, prevState, errorCode) {
2017-08-28 19:27:45 +03:00
if (state == 0) {
// Control web socket disconnected
setDialogMode(0); // Close any dialog boxes if present
go(0); // Go to disconnection panel
// Clean up
powerTimeline = null;
powerTimelineReq = null;
powerTimelineNode = null;
powerTimelineUpdate = null;
deleteAllNotifications(); // Close and clear notifications if present
hideContextMenu(); // Hide the context menu if present
2017-12-14 01:52:57 +03:00
QV('verifyEmailId2', false);
QV('logoutControl', false);
2019-01-29 02:47:54 +03:00
if (errorCode == 'noauth') { QH('p0span', 'Unable to perform authentication'); return; }
2019-02-12 01:41:15 +03:00
if (prevState == 2) { if (autoReconnect) { setTimeout(serverPoll, 5000); } } else { QH('p0span', 'Unable to connect web socket'); }
2019-01-30 01:08:29 +03:00
if (authCookieRenewTimer != null) { clearInterval(authCookieRenewTimer); authCookieRenewTimer = null; }
2017-08-28 19:27:45 +03:00
} else if (state == 2) {
// Fetch list of meshes, nodes, files
2018-02-12 04:13:26 +03:00
meshserver.send( { action: 'meshes' });
2019-01-30 01:08:29 +03:00
meshserver.send( { action: 'nodes', id: ' {{ currentNode }} ' });
if (' {{ currentNode }} ' == '') { meshserver.send( { action: 'files' }); }
2019-01-27 23:23:38 +03:00
go(1);
2019-01-30 01:08:29 +03:00
authCookieRenewTimer = setInterval(function () { meshserver.send( { action: 'authcookie' }); }, 1800000); // Request a cookie refresh every 30 minutes.
2017-08-28 19:27:45 +03:00
}
}
2017-12-16 00:43:04 +03:00
// Poll the server, if it responds, refresh the page.
function serverPoll() {
2018-08-30 04:47:22 +03:00
var xdr = null;
2017-12-16 00:43:04 +03:00
try { xdr = new XDomainRequest(); } catch (e) { }
if (!xdr) xdr = new XMLHttpRequest();
xdr.open("HEAD", window.location.href);
xdr.timeout = 15000;
xdr.onload = function () { reload(); };
2018-01-03 03:52:49 +03:00
xdr.onerror = xdr.ontimeout = function () { setTimeout(serverPoll, 10000); };
2017-12-16 00:43:04 +03:00
xdr.send();
}
2017-10-24 00:09:58 +03:00
// Return true if this browser supports clickonce
function detectClickOnce() {
for (var i in window.navigator.mimeTypes) { if (window.navigator.mimeTypes[i].type == "application/x-ms-application") { return true; } }
var userAgent = window.navigator.userAgent.toUpperCase();
return (userAgent.indexOf('.NET CLR 3.5') >= 0) || (userAgent.indexOf('(WINDOWS NT ') >= 0);
}
2017-08-28 19:27:45 +03:00
function updateSiteAdmin() {
2018-08-24 02:55:06 +03:00
var noServerBackup = " {{{ noServerBackup }}} ";
2017-10-24 00:09:58 +03:00
var siteRights = userinfo.siteadmin;
if (noServerBackup == 1) { siteRights &= 0xFFFFFFFA; } // If not server backups allowed, remove server backup and restore permissions
// Update account actions
2019-02-11 03:04:36 +03:00
QV('p2AccountSecurity', ((features & 4) == 0) && (serverinfo.domainauth == false) && ((features & 4096) != 0)); // Hide Account Security if in single user mode, domain authentication to 2 factor auth not supported.
2019-02-26 00:14:04 +03:00
QV('p2AccountActions', ((features & 4) == 0) && (serverinfo.domainauth == false)); // Hide Account Actions if in single user mode or domain authentication
QV('p2AccountImage', ((features & 4) == 0) && (serverinfo.domainauth == false)); // If account actions are not visible, also remove the image on that panel
2018-09-27 00:58:55 +03:00
QV('p2ServerActions', siteRights & 21);
2019-02-06 06:07:12 +03:00
QV('LeftMenuMyServer', siteRights & 21); // 16 + 4 + 1
2018-09-27 00:58:55 +03:00
QV('MainMenuMyServer', siteRights & 21);
2017-10-24 00:09:58 +03:00
QV('p2ServerActionsBackup', siteRights & 1);
QV('p2ServerActionsRestore', siteRights & 4);
QV('p2ServerActionsVersion', siteRights & 16);
QV('MainMenuMyFiles', siteRights & 8);
2018-11-03 04:13:32 +03:00
QV('LeftMenuMyFiles', siteRights & 8);
2018-04-16 08:22:44 +03:00
if (((siteRights & 8) == 0) && (xxcurrentView == 5)) { setDialogMode(0); go(1); }
2017-12-15 01:57:52 +03:00
if (currentNode != null) { gotoDevice(currentNode._id, xxcurrentView, true); }
2017-10-24 00:09:58 +03:00
// Update user management state
if ((userinfo.siteadmin & 2) != 0)
{
// We are user administrator
2018-02-12 04:13:26 +03:00
if (users == null) { meshserver.send( { action: 'users' }); }
if (wssessions == null) { meshserver.send( { action: 'wssessioncount' }); }
2017-10-24 00:09:58 +03:00
} else {
// We are not user administrator
users = null;
wssessions = null;
updateUsers();
2018-04-16 08:22:44 +03:00
if (xxcurrentView == 4 || ((xxcurrentView >= 30) && (xxcurrentView < 40))) { setDialogMode(0); go(1); currentUser = null; }
2017-10-24 00:09:58 +03:00
}
2018-02-12 04:13:26 +03:00
meshserver.send( { action: 'events', limit: parseInt(p3limitdropdown.value) });
2017-10-24 00:09:58 +03:00
QV('p2deleteall', userinfo.siteadmin == 0xFFFFFFFF);
2019-02-06 06:07:12 +03:00
QV('ServerConsole', userinfo.siteadmin === 0xFFFFFFFF);
if ((xxcurrentView == 115) && (userinfo.siteadmin != 0xFFFFFFFF)) { go(6); }
if ((xxcurrentView == 6) && ((userinfo.siteadmin & 21) == 0)) { go(1); }
2018-09-27 00:58:55 +03:00
// If we are site administrator, register to get server statistics
if ((siteRights & 21) != 0) { meshserver.send( { action: 'serverstats', interval: 10000 }); }
2017-08-28 19:27:45 +03:00
}
2019-01-22 22:44:46 +03:00
// To boost the speed of the web page when even floods occur, this method perform a delayed update on the web page.
var updateNaggleTimer = null;
var updateNaggleFlags = 0;
function masterUpdate(flags) {
updateNaggleFlags |= flags;
if (updateNaggleTimer == null) {
updateNaggleTimer = setTimeout(function () {
if (updateNaggleFlags & 512) { center(); }
if (updateNaggleFlags & 1) { onSearchInputChanged(); }
if (updateNaggleFlags & 2) { onSortSelectChange(true); }
if (updateNaggleFlags & 128) { updateMeshes(); }
if (updateNaggleFlags & 4) { updateDevices(); }
if (updateNaggleFlags & 8) { drawNotifications(); }
if (updateNaggleFlags & 16) { updateMapMarkers(); }
if (updateNaggleFlags & 32) { eventsUpdate(); }
if (updateNaggleFlags & 64) { refreshMap(false, true); }
if (updateNaggleFlags & 256) { drawDeviceTimeline(); }
if (updateNaggleFlags & 1024) { deviceEventsUpdate(); }
if (updateNaggleFlags & 2048) { userEventsUpdate(); }
updateNaggleTimer = null;
updateNaggleFlags = 0;
}, 150);
2019-01-22 01:05:50 +03:00
}
}
2019-02-06 06:07:12 +03:00
function updateSelf() {
QV('verifyEmailId', (userinfo.emailVerified !== true) && (userinfo.email != null) && (serverinfo.emailcheck == true));
QV('verifyEmailId2', (userinfo.emailVerified !== true) && (userinfo.email != null) && (serverinfo.emailcheck == true));
2019-02-11 03:04:36 +03:00
QV('manageOtp', (userinfo.otpsecret == 1) || (userinfo.otphkeys > 0));
QV('authAppSetupCheck', userinfo.otpsecret == 1);
QV('authKeySetupCheck', userinfo.otphkeys > 0);
QV('authCodesSetupCheck', userinfo.otpkeys > 0);
2019-02-06 06:07:12 +03:00
}
2017-08-28 19:27:45 +03:00
function onMessage(server, message) {
switch (message.action) {
2018-09-27 00:58:55 +03:00
case 'serverstats': {
updateServerStats(message);
break;
}
2019-01-30 01:08:29 +03:00
case 'authcookie': {
// Got an authentication cookie refresh
authCookie = message.cookie;
break;
}
2017-12-13 03:04:54 +03:00
case 'serverinfo': {
serverinfo = message.serverinfo;
break;
}
2017-08-28 19:27:45 +03:00
case 'userinfo': {
userinfo = message.userinfo;
updateSiteAdmin();
2019-02-06 06:07:12 +03:00
updateSelf();
2017-08-28 19:27:45 +03:00
break;
}
case 'users': {
users = { };
for (var m in message.users) { users[message.users[m]._id] = message.users[m]; }
updateUsers();
break;
}
case 'wssessioncount': {
wssessions = message.wssessions;
updateUsers();
break;
}
case 'meshes': {
meshes = { };
for (var m in message.meshes) { meshes[message.meshes[m]._id] = message.meshes[m]; }
2019-01-22 22:44:46 +03:00
masterUpdate(4 + 128);
2017-08-28 19:27:45 +03:00
break;
}
case 'files': {
filetree = setupBackPointers(message.filetree);
updateFiles();
d3updatefiles();
break;
}
case 'nodes': {
nodes = [];
for (var m in message.nodes) {
2018-08-30 03:40:30 +03:00
if (!meshes[m]) { console.log('Invalid mesh (1): ' + m); continue; }
2017-08-28 19:27:45 +03:00
for (var n in message.nodes[m]) {
2018-08-30 03:40:30 +03:00
if (message.nodes[m][n]._id == null) { console.log('Invalid node (' + n + '): ' + JSON.stringify(message.nodes)); continue; }
2017-08-28 19:27:45 +03:00
message.nodes[m][n].namel = message.nodes[m][n].name.toLowerCase();
2018-05-22 02:36:51 +03:00
if (message.nodes[m][n].rname) { message.nodes[m][n].rnamel = message.nodes[m][n].rname.toLowerCase(); } else { message.nodes[m][n].rnamel = message.nodes[m][n].namel; }
2017-08-28 19:27:45 +03:00
message.nodes[m][n].meshnamel = meshes[m].name.toLowerCase();
message.nodes[m][n].meshid = m;
message.nodes[m][n].state = (message.nodes[m][n].state)?(message.nodes[m][n].state):0;
message.nodes[m][n].desc = message.nodes[m][n].desc;
if (!message.nodes[m][n].icon) message.nodes[m][n].icon = 1;
message.nodes[m][n].ident = ++nodeShortIdent;
nodes.push(message.nodes[m][n]);
}
}
2019-01-22 22:44:46 +03:00
masterUpdate(1 | 2 | 4 | 64);
2018-08-24 02:55:06 +03:00
if (xxcurrentView == 0) { if (' {{ viewmode }} ' != '') { go(parseInt(' {{ viewmode }} ')); } else { setDialogMode(0); go(1); } }
if (' {{ currentNode }} ' != '') { gotoDevice(' {{ currentNode }} ',parseInt(' {{ viewmode }} '));}
2017-08-28 19:27:45 +03:00
break;
}
case 'powertimeline': {
if (message.nodeid != powerTimelineReq) break;
powerTimelineNode = message.nodeid;
powerTimeline = message.timeline;
powerTimelineUpdate = Date.now() + 300000; // Update every 5 minutes
2019-01-22 22:44:46 +03:00
if (currentNode._id == message.nodeid) { masterUpdate(256); }
2017-08-28 19:27:45 +03:00
break;
}
2018-09-25 03:47:03 +03:00
case 'lastconnect': {
var node = getNodeFromId(message.nodeid);
if (node != null) {
node.lastconnect = message.time;
2019-02-01 02:00:51 +03:00
node.lastaddr = message.addr;
2018-09-25 03:47:03 +03:00
if ((currentNode._id == node._id) && (Q('MainComputerState').innerHTML == '')) {
2018-09-27 00:58:55 +03:00
QH('MainComputerState', '<span style=font-size:12px>Last seen:<br />' + new Date(node.lastconnect).toLocaleDateString() + ', ' + new Date(node.lastconnect).toLocaleTimeString() + '</span>');
2018-09-25 03:47:03 +03:00
}
}
break;
}
2017-08-28 19:27:45 +03:00
case 'msg': {
// Check if this is a message from a node
2017-12-14 01:52:57 +03:00
if (message.nodeid != null) {
2017-08-28 19:27:45 +03:00
var index = -1;
2019-01-30 01:08:29 +03:00
if (nodes != null) { for (var i in nodes) { if (nodes[i]._id == message.nodeid) { index = i; break; } } }
2017-08-28 19:27:45 +03:00
if (index != -1) {
// Node was found, dispatch the message
if (message.type == 'console') { p15consoleReceive(nodes[index], message.value); } // This is a console message.
2018-04-11 23:49:05 +03:00
else if (message.type == 'notify') { // This is a notification message.
2017-08-28 19:27:45 +03:00
var n = { text:message.value };
2017-12-14 01:52:57 +03:00
if (message.nodeid != null) { n.nodeid = message.nodeid; }
if (message.tag != null) { n.tag = message.tag; }
2018-12-02 10:41:57 +03:00
if (message.username != null) { n.username = message.username; }
2017-08-28 19:27:45 +03:00
addNotification(n);
2018-04-11 23:49:05 +03:00
} else if (message.type == 'ps') {
showDeskToolsProcesses(message);
2019-02-17 08:16:39 +03:00
} else if ((message.type == 'getclip') && (xxdialogTag == 'clipboard') && (currentNode != null) && (currentNode._id == message.nodeid)) {
Q('d2clipText').value = message.data;
} else if ((message.type == 'setclip') && (xxdialogTag == 'clipboard') && (currentNode != null) && (currentNode._id == message.nodeid)) {
// Display success/fail on the clipboard dialog box.
QH('dlgClipStatus', message.success ? '<span style=color:green>Success</span>' : '<span style=color:red>Failed</span>')
setTimeout(function () { try { QH('dlgClipStatus', ''); } catch (ex) { } }, 2000);
2017-09-30 00:20:08 +03:00
}
2017-08-28 19:27:45 +03:00
}
2017-12-13 05:23:26 +03:00
} else {
if (message.type == 'notify') { // This is a notification message.
var n = { text:message.value };
2017-12-14 01:52:57 +03:00
if (message.tag != null) { n.tag = message.tag; }
2018-12-02 10:41:57 +03:00
if (message.username != null) { n.username = message.username; }
2017-12-13 05:23:26 +03:00
addNotification(n);
}
2017-08-28 19:27:45 +03:00
}
break;
}
case 'getnetworkinfo': {
if ((currentNode._id == message.nodeid) && (xxdialogMode == 2) && (xxdialogTag == 'if' + message.nodeid)) {
if (message.netif == null) {
QH('d2netinfo', 'No network interface information available for this device.');
} else {
var x = '<div style=width:100%;max-height:260px;overflow-x:hidden;overflow-y:auto;line-height:160%>';
2019-02-01 02:21:28 +03:00
if (currentNode.lastconnect) { x += addHtmlValue2('Last agent connection', new Date(currentNode.lastconnect).toLocaleString()); }
if (currentNode.lastaddr) {
if (isPrivateIP(currentNode.lastaddr)) {
x += addHtmlValue2('Last agent address', currentNode.lastaddr.split(':')[0]);
} else {
2019-02-02 02:16:46 +03:00
x += addHtmlValue2('Last agent address', '<a href="https://iplocation.com/?ip=' + currentNode.lastaddr.split(':')[0] + '" rel="noreferrer noopener" target="MeshIPLoopup">' + currentNode.lastaddr.split(':')[0] + '</a>');
2019-02-01 02:00:51 +03:00
}
}
2019-02-01 02:21:28 +03:00
2019-02-01 02:00:51 +03:00
x += addHtmlValue2('Last interfaces update', new Date(message.updateTime).toLocaleString());
2017-08-28 19:27:45 +03:00
for (var i in message.netif) {
var net = message.netif[i];
x += '<hr />'
if (net.name) { x += addHtmlValue2('Name', '<b>' + EscapeHtml(net.name) + '</b>'); }
if (net.desc) { x += addHtmlValue2('Description', EscapeHtml(net.desc).replace('(R)', '®').replace('(r)', '®')); }
if (net.dnssuffix) { x += addHtmlValue2('DNS suffix', EscapeHtml(net.dnssuffix)); }
2019-02-02 02:16:46 +03:00
if (net.mac) { x += addHtmlValue2('MAC address', '<a href="https://dnslytics.com/mac-address-lookup/' + net.mac.substring(0,6) + '" rel="noreferrer noopener" target="MeshMACLoopup">' + EscapeHtml(net.mac.toLowerCase()) + '</a>'); }
2017-08-28 19:27:45 +03:00
if (net.v4addr) { x += addHtmlValue2('IPv4 address', EscapeHtml(net.v4addr)); }
if (net.v4mask) { x += addHtmlValue2('IPv4 mask', EscapeHtml(net.v4mask)); }
if (net.v4gateway) { x += addHtmlValue2('IPv4 gateway', EscapeHtml(net.v4gateway)); }
2019-02-02 02:16:46 +03:00
if (net.gatewaymac) { x += addHtmlValue2('Gateway MAC', '<a href="https://dnslytics.com/mac-address-lookup/' + net.gatewaymac.substring(0, 6) + '" rel="noreferrer noopener" target="MeshMACLoopup">' + EscapeHtml(net.gatewaymac.toLowerCase()) + '</a>'); }
2017-08-28 19:27:45 +03:00
}
x += '</div>';
QH('d2netinfo', x);
}
}
break;
}
case 'serverversion': {
if ((xxdialogMode == 2) && (xxdialogTag == 'MeshCentralServerUpdate')) {
var x = '<div style=width:100%;max-height:260px;overflow-x:hidden;overflow-y:auto;line-height:160%>';
if (!message.current) { message.current = 'Unknown'; }
if (!message.latest) { message.latest = 'Unknown'; }
x += addHtmlValue2('Current Version', '<b>' + EscapeHtml(message.current) + '</b>');
x += addHtmlValue2('Latest Version', '<b>' + EscapeHtml(message.latest) + '</b>');
x += '</div>';
2018-10-11 23:29:50 +03:00
if ((message.latest.indexOf('.') == -1) || (message.current == message.latest) || ((features & 2048) == 0)) {
2017-09-07 04:10:24 +03:00
setDialogMode(2, "MeshCentral Version", 1, null, x);
} else {
2019-02-20 02:51:38 +03:00
setDialogMode(2, "MeshCentral Version", 3, server_showVersionDlgEx, x + '<br /><label><input id=d2updateCheck type=checkbox onclick=server_showVersionDlgUpdate() /> Check and click OK to start server self-update.</label>');
2018-04-29 01:36:10 +03:00
server_showVersionDlgUpdate();
2017-09-07 04:10:24 +03:00
}
2017-08-28 19:27:45 +03:00
}
break;
}
2018-09-19 05:41:59 +03:00
case 'servererrors': {
if ((xxdialogMode == 2) && (xxdialogTag == 'MeshCentralServerErrors')) {
if (message.data == null) {
setDialogMode(2, "MeshCentral Server Errors", 1, null, 'Server has no error log.');
} else {
var x = '<div style=width:100%;max-height:260px;overflow-x:hidden;overflow:auto;line-height:160%;font-size:10px><pre>' + message.data + '<pre></div>';
2019-02-20 02:51:38 +03:00
setDialogMode(2, "MeshCentral Server Errors", 3, server_showErrorsDlgEx, x + '<br /><label><input id=d2updateCheck type=checkbox onclick=server_showVersionDlgUpdate() /> Check and click OK to clear error log.</label>');
2018-09-19 05:41:59 +03:00
server_showVersionDlgUpdate();
}
}
break;
}
2019-02-05 05:06:01 +03:00
case 'serverconsole': {
p15consoleReceive('serverconsole', message.value);
break;
}
2017-08-28 19:27:45 +03:00
case 'events': {
2018-04-17 01:37:41 +03:00
if ((message.nodeid != null) && (message.nodeid == currentNode._id)) {
currentDeviceEvents = message.events;
2019-01-22 22:44:46 +03:00
masterUpdate(1024);
2018-04-17 01:37:41 +03:00
} else if ((message.user != null) && (message.user == currentUser.name)) {
2018-04-16 08:22:44 +03:00
currentUserEvents = message.events;
2019-01-22 22:44:46 +03:00
masterUpdate(2048);
2018-04-16 08:22:44 +03:00
} else {
events = message.events;
2019-01-22 22:44:46 +03:00
masterUpdate(32);
2018-04-16 08:22:44 +03:00
}
2017-08-28 19:27:45 +03:00
break;
}
2017-10-24 00:09:58 +03:00
case 'getcookie': {
if (message.tag == 'clickonce') {
2018-10-16 20:52:05 +03:00
var basicPort = " {{{ serverRedirPort }}} " == "" ? " {{{ serverPublicPort }}} " : " {{{ serverRedirPort }}} ";
2018-12-06 01:22:34 +03:00
var rdpurl = "http://" + window.location.hostname + ":" + basicPort + "/clickonce/minirouter/MeshMiniRouter.application?WS=wss%3A%2F%2F" + window.location.hostname + "%2Fmeshrelay.ashx%3Fauth=" + message.cookie + "&CH= {{{ webcerthash }}} &AP=" + message.protocol + ((debugmode == 1) ? "" : "&HOL=1");
2019-01-05 04:59:13 +03:00
var newWindow = window.open(rdpurl, '_blank');
newWindow.opener = null;
2017-10-24 00:09:58 +03:00
}
break;
}
2019-01-16 23:04:48 +03:00
case 'getNotes': {
2018-04-13 04:14:03 +03:00
var n = Q('d2devNotes');
2018-04-16 21:57:42 +03:00
if (n && (message.id == decodeURIComponent(n.attributes['noteid'].value))) {
2018-04-13 04:14:03 +03:00
if (message.notes) { QH('d2devNotes', decodeURIComponent(message.notes)); } else { QH('d2devNotes', ''); }
var ro = n.attributes['ro'].value == 'true';
if (ro == false) { // If we have permissions, set read/write on this note.
n.removeAttribute('readonly');
QE('idx_dlgOkButton', true);
QV('idx_dlgOkButton', true);
focusTextBox('d2devNotes');
}
}
break;
}
2019-01-16 00:51:07 +03:00
case 'otpauth-request': {
if ((xxdialogMode == 2) && (xxdialogTag == 'otpauth-request')) {
2019-01-16 05:21:03 +03:00
var secret = message.secret;
if (secret.length == 52) { secret = secret.split(/(.............)/).filter(Boolean).join(' '); }
else if (secret.length == 32) { secret = secret.split(/(....)/).filter(Boolean).join(' '); secret = secret.substring(0, 20) + '<br/>' + secret.substring(20) }
QH('d2optinfo', '<table style=width:380px><tr><td style=vertical-align:top>Install <a href=\"https://play.google.com/store/apps/details?id=com.google.android.apps.authenticator2\" rel=\"noreferrer noopener\" target=_blank>Google Authenticator</a> or a compatible application and scan the barcode, use <a href=\"' + message.url + '\" rel=\"noreferrer noopener\" target=_blank> this link</a> or enter the secret. Then, enter the current 6 digit token below to activate 2-Step login.<br /><br />Secret<br /><tt id=d2optsecret secret=\"' + message.secret + '\" style=font-size:12px>' + secret + '</tt><br /><br /></td><td style=width:1px;vertical-align:top><a href=\"' + message.url + '\" rel=\"noreferrer noopener\" target=_blank><div id="qrcode"></div></a></td><tr><td colspan=2 style="text-align:center;border-top:1px solid black"><br />Enter the token here for 2-step login: <input type=text onkeypress=\"return (event.keyCode == 8) || (event.charCode >= 48 && event.charCode <= 57)\" onkeyup=account_addOtpCheck(event) onkeydown=account_addOtpCheck() maxlength=6 id=d2otpauthinput type=text></td></table>');
2019-01-16 00:51:07 +03:00
new QRCode(Q("qrcode"), { text: message.url, width: 128, height: 128, colorDark: "#000000", colorLight: "#EEE", correctLevel: QRCode.CorrectLevel.H });
QV('idx_dlgOkButton', true);
QE('idx_dlgOkButton', false);
Q('d2otpauthinput').focus();
}
break;
}
case 'otpauth-setup': {
if (xxdialogMode) return;
2019-02-11 03:04:36 +03:00
setDialogMode(2, "Authenticator App", 1, null, message.success ? "<b style=color:green>Authenticator app activation successful</b>. You will now need a valid token to login again." : "<b style=color:red>2-step login activation failed</b>. Clear the secret from the application and try again. You only have a few minutes to enter the proper code.");
2019-01-16 00:51:07 +03:00
break;
}
case 'otpauth-clear': {
if (xxdialogMode) return;
2019-02-11 03:04:36 +03:00
setDialogMode(2, "Authenticator App", 1, null, message.success ? "<b>Authenticator application removed</b>. You can reactivate this feature at any time." : "<b style=color:red>2-step login activation removal failed</b>. Try again.");
2019-01-16 00:51:07 +03:00
break;
}
2019-02-06 06:07:12 +03:00
case 'otpauth-getpasswords': {
if (xxdialogMode) return;
var x = "One time tokens can be used as secondary authentication. Generate a set, print them and keep them in a safe place.";
x += "<div style='border-radius:6px;border: 2px dashed #888;width:100%;margin-top:8px'><div style='padding:8px;font-family:Arial, Helvetica, sans-serif;font-size:20px;font-weight:bold'><table style=width:100%;text-align:center>";
if (message.passwords) {
var j = 0;
for (var i in message.passwords) {
if (++j % 2) { x += '<tr>'; }
var p = '' + message.passwords[i].p;
while (p.length < 8) { p = '0' + p; }
if (message.passwords[i].u === true) { x += '<td>' + p.substring(0, 4) + ' ' + p.substring(4); } else { x += '<td><strike style=color:#BBB>' + p.substring(0, 4) + ' ' + p.substring(4); + '</strike>'; }
}
} else {
x += '<tr><td>No Active Tokens';
}
x += "</table></div></div><br />";
x += "<div><input type=button value='Close' onclick=setDialogMode(0) style=float:right></input>";
x += "<input type=button value='Generate New Tokens' onclick='account_manageOtp(1);'></input>";
if (message.passwords != null) { x += "<input type=button value='Clear Tokens' onclick='account_manageOtp(2);'></input>"; }
x += "</div><br />";
2019-02-11 03:04:36 +03:00
setDialogMode(2, "Manage Backup Codes", 8, null, x, 'otpauth-manage');
2019-02-06 06:07:12 +03:00
break;
}
2019-02-08 07:06:01 +03:00
case 'otp-hkey-get': {
if (xxdialogMode && (xxdialogTag != 'otpauth-hardware-manage')) return;
2019-02-11 03:04:36 +03:00
var start = "<div style='border-radius:6px;border:2px solid #CCC;background-color:#BBB;width:100%;box-sizing:border-box;margin-bottom:6px'><div style='margin:3px;font-family:Arial, Helvetica, sans-serif;font-size:16px;font-weight:bold'><table style=width:100%;text-align:left>";
2019-02-08 07:06:01 +03:00
var end = "</table></div></div>";
var x = "<a href='https://www.yubico.com/' rel='noreferrer noopener' target='_blank'>Hardware keys</a> are used as secondary login authentication.";
2019-02-11 03:04:36 +03:00
x += "<div style='max-height:150px;overflow-y:auto;overflow-x:hidden;margin-top:6px;margin-bottom:6px'>";
2019-02-08 07:06:01 +03:00
if (message.keys && message.keys.length > 0) {
for (var i in message.keys) {
2019-02-11 03:04:36 +03:00
var key = message.keys[i], type = (key.type == 1)?'U2F':'OTP';
2019-02-08 20:24:00 +03:00
x += start + '<tr style=margin:5px><td style=width:30px><img width=24 height=18 src="images/hardware-key-' + type + '-24.png" style=margin-top:4px><td style=width:250px>' + key.name + "<td><input type=button value='Remove' onclick=account_removehkey(" + key.i + ")></input>" + end;
2019-02-08 07:06:01 +03:00
}
} else {
2019-02-11 03:04:36 +03:00
x += start + '<tr style=text-align:center><td>No Keys Configured' + end;
2019-02-08 07:06:01 +03:00
}
2019-02-11 03:04:36 +03:00
x += "</div>";
2019-02-08 07:06:01 +03:00
x += "<div><input type=button value='Close' onclick=setDialogMode(0) style=float:right></input>";
2019-02-08 20:24:00 +03:00
x += "<input id=d2addkey1 type=button value='Add U2F Key' onclick='account_addhkey(1);'></input>";
if ((features & 0x4000) != 0) { x += "<input id=d2addkey2 type=button value='Add OTP Key' onclick='account_addhkey(2);'></input>"; }
2019-02-08 07:06:01 +03:00
x += "</div><br />";
2019-02-11 03:04:36 +03:00
setDialogMode(2, "Manage Security Keys", 8, null, x, 'otpauth-hardware-manage');
if (u2fSupported() == false) { QE('d2addkey1', false); }
2019-02-08 20:24:00 +03:00
break;
}
case 'otp-hkey-yubikey-add': {
if (message.result) {
meshserver.send( { action: 'otp-hkey-get' }); // Success, ask for the full list of keys.
} else {
2019-02-11 03:04:36 +03:00
setDialogMode(2, "Add Security Key", 1, null, '<br />Error, Unable to add key.<br /><br />');
2019-02-08 20:24:00 +03:00
}
2019-02-08 07:06:01 +03:00
break;
}
case 'otp-hkey-setup-request': {
if (xxdialogMode && (xxdialogTag != 'otpauth-hardware-manage')) return;
2019-02-08 20:24:00 +03:00
var x = "Press the key button now.<br /><br /><div style=width:100%;text-align:center><img width=120 height=117 src='images/hardware-keypress-120.png' /></div><input id=dp1keyname style=display:none value=" + message.name + " />";
2019-02-11 03:04:36 +03:00
setDialogMode(2, "Add Security Key", 2, null, x);
window.u2f.register(message.request.appId, message.request.registerRequests, message.request.registeredKeys, function (registrationResponse) {
2019-02-08 09:30:33 +03:00
if (registrationResponse.registrationData) {
2019-02-11 03:04:36 +03:00
meshserver.send( { action: 'otp-hkey-setup-response', response: registrationResponse, name: Q('dp1keyname').value });
setDialogMode(2, "Add Security Key", 0, null, '<br />Checking...<br /><br /><br />', 'otpauth-hardware-manage');
2019-02-08 07:06:01 +03:00
} else {
2019-02-11 03:04:36 +03:00
var errorCodes = ['', 'Unknown error', 'Bad request', 'Unsupported configuration', 'This key was already registered', 'Timeout'];
setDialogMode(2, "Add Security Key", 1, null, '<br />' + errorCodes[registrationResponse.errorCode] + '.<br /><br />');
2019-02-08 07:06:01 +03:00
}
2019-02-11 03:04:36 +03:00
}, message.request.timeoutSeconds);
2019-02-08 07:06:01 +03:00
break;
}
case 'otp-hkey-setup-response': {
if (xxdialogMode && (xxdialogTag != 'otpauth-hardware-manage')) return;
if (message.result == true) {
meshserver.send( { action: 'otp-hkey-get' }); // Success, ask for the full list of keys.
} else {
2019-02-11 03:04:36 +03:00
setDialogMode(2, "Add Security Key", 1, null, '<br />ERROR: Unable to add key.<br /><br />', 'otpauth-hardware-manage');
2019-02-08 07:06:01 +03:00
}
break;
}
2017-08-28 19:27:45 +03:00
case 'event': {
2018-01-05 02:59:57 +03:00
if (!message.event.nolog) {
events.unshift(message.event);
var eventLimit = parseInt(p3limitdropdown.value);
while (events.length > eventLimit) { events.pop(); } // Remove element(s) at the end
2019-01-22 22:44:46 +03:00
masterUpdate(32);
2018-01-05 02:59:57 +03:00
}
2017-08-28 19:27:45 +03:00
switch (message.event.action) {
case 'accountcreate':
case 'accountchange': {
// An account was created or changed
if (userinfo.name == message.event.account.name) {
var newsiteadmin = message.event.account.siteadmin?message.event.account.siteadmin:0;
var oldsiteadmin = userinfo.siteadmin?userinfo.siteadmin:0;
2018-02-12 04:13:26 +03:00
if ((message.event.account.quota != userinfo.quota) || (((userinfo.siteadmin & 8) == 0) && ((message.event.account.siteadmin & 8) != 0))) { meshserver.send( { action: 'files' }); }
2017-08-28 19:27:45 +03:00
userinfo = message.event.account;
if (oldsiteadmin != newsiteadmin) updateSiteAdmin();
2019-02-06 06:07:12 +03:00
updateSelf();
2017-08-28 19:27:45 +03:00
}
if (users == null) break;
users[message.event.account._id] = message.event.account;
updateUsers();
break;
}
case 'accountremove': {
// An account was removed
if (users == null) break;
2018-08-24 23:14:20 +03:00
delete users['user/' + domain + '/' + message.event.username.toLowerCase()];
2017-08-28 19:27:45 +03:00
updateUsers();
break;
}
case 'createmesh': {
// A new mesh was created
2018-08-24 23:14:20 +03:00
if (message.event.links['user/' + domain + '/' + userinfo.name.toLowerCase()] != null) { // Check if this is a mesh create for a mesh we own. If site administrator, we get all messages so need to ignore some.
2017-08-28 19:27:45 +03:00
meshes[message.event.meshid] = { _id: message.event.meshid, name: message.event.name, mtype: message.event.mtype, desc: message.event.desc, links: message.event.links };
2019-01-22 22:44:46 +03:00
masterUpdate(4 + 128);
2018-02-12 04:13:26 +03:00
meshserver.send( { action: 'files' });
2017-08-28 19:27:45 +03:00
}
break;
}
case 'meshchange': {
// Update mesh information
2017-12-14 01:52:57 +03:00
if (meshes[message.event.meshid] == null) {
2017-08-28 19:27:45 +03:00
// This is a new mesh for us
meshes[message.event.meshid] = { _id: message.event.meshid, name: message.event.name, mtype: message.event.mtype, desc: message.event.desc, links: message.event.links };
2018-02-12 04:13:26 +03:00
meshserver.send( { action: 'nodes' }); // Request a refresh of all nodes (TODO: We could optimize this to only request nodes for the new mesh).
2017-08-28 19:27:45 +03:00
} else {
// This is an existing mesh
2019-02-08 02:00:10 +03:00
if (message.event.name) { meshes[message.event.meshid].name = message.event.name; }
if (message.event.desc) { meshes[message.event.meshid].desc = message.event.desc; }
2019-02-27 01:39:45 +03:00
if (message.event.flags != null) { meshes[message.event.meshid].flags = message.event.flags; }
2019-02-08 02:00:10 +03:00
if (message.event.links) { meshes[message.event.meshid].links = message.event.links; }
if (message.event.amt) { meshes[message.event.meshid].amt = message.event.amt; }
2017-08-28 19:27:45 +03:00
// Check if we lost rights to this mesh in this change.
2018-08-24 23:14:20 +03:00
if (meshes[message.event.meshid].links['user/' + domain + '/' + userinfo.name.toLowerCase()] == null) {
2017-08-28 19:27:45 +03:00
if ((xxcurrentView == 20) && (currentMesh == meshes[message.event.meshid])) go(2);
delete meshes[message.event.meshid];
// Delete all nodes in that mesh
var newnodes = [];
for (var i in nodes) { if (nodes[i].meshid != message.event.meshid) { newnodes.push(nodes[i]); } }
nodes = newnodes;
// If we are looking at a node in the deleted mesh, move back to "My Devices"
2018-04-16 08:22:44 +03:00
if (xxcurrentView >= 10 && xxcurrentView < 20 && currentNode && currentNode.meshid == message.event.meshid) { setDialogMode(0); go(1); }
2017-08-28 19:27:45 +03:00
}
}
2019-01-22 22:44:46 +03:00
masterUpdate(4 + 128);
2019-02-08 02:00:10 +03:00
//meshserver.send( { action: 'files' }); // TODO: Why do we need to do this??
2017-08-28 19:27:45 +03:00
// If we are looking at a mesh that is now deleted, move back to "My Account"
if (xxcurrentView == 20 && currentMesh._id == message.event.meshid) { p20updateMesh(); }
break;
}
case 'deletemesh': {
// Delete the mesh
if (meshes[message.event.meshid]) {
delete meshes[message.event.meshid];
2019-01-22 22:44:46 +03:00
masterUpdate(128);
2018-02-12 04:13:26 +03:00
meshserver.send( { action: 'files' });
2017-08-28 19:27:45 +03:00
}
// Delete all nodes in that mesh
var newnodes = [];
2019-01-30 01:08:29 +03:00
if (nodes != null) { for (var i in nodes) { if (nodes[i].meshid != message.event.meshid) { newnodes.push(nodes[i]); } } }
2017-08-28 19:27:45 +03:00
nodes = newnodes;
2019-01-22 22:44:46 +03:00
masterUpdate(4);
2017-08-28 19:27:45 +03:00
// If we are looking at a mesh that is now deleted, move back to "My Account"
2018-04-16 08:22:44 +03:00
if (xxcurrentView >= 20 && xxcurrentView < 30 && currentMesh._id == message.event.meshid) { setDialogMode(0); go(2); }
2017-08-28 19:27:45 +03:00
// If we are looking at a node in the deleted mesh, move back to "My Devices"
2018-04-16 08:22:44 +03:00
if (xxcurrentView >= 10 && xxcurrentView < 20 && currentNode && currentNode.meshid == message.event.meshid) { setDialogMode(0); go(1); }
2017-08-28 19:27:45 +03:00
break;
}
case 'addnode': {
var node = message.event.node;
if (!meshes[node.meshid]) break; // This is a node for a mesh we don't know. Happens when we are site administrator, we get all messages.
node.namel = node.name.toLowerCase();
2018-05-22 02:36:51 +03:00
if (node.rname) { node.rnamel = node.rname.toLowerCase(); } else { node.rnamel = node.namel; }
2017-08-28 19:27:45 +03:00
node.meshnamel = meshes[node.meshid].name.toLowerCase();
node.state = 0;
if (!node.icon) node.icon = 1;
node.ident = ++nodeShortIdent;
2019-01-30 01:08:29 +03:00
if (nodes == null) { }
2017-08-28 19:27:45 +03:00
nodes.push(node);
2019-01-22 01:05:50 +03:00
// Web page update
2019-01-22 22:44:46 +03:00
masterUpdate(1 | 2 | 4 | 16);
2019-01-22 01:05:50 +03:00
2017-08-28 19:27:45 +03:00
break;
}
case 'removenode': {
var index = -1;
for (var i in nodes) { if (nodes[i]._id == message.event.nodeid) { index = i; break; } }
if (index != -1) {
var node = nodes[index];
if (currentNode == node) {
2018-04-16 08:22:44 +03:00
if (xxcurrentView >= 10 && xxcurrentView < 20) { setDialogMode(0); go(1); }
2018-08-27 22:24:15 +03:00
currentNode = null;
// TODO: Correctly disconnect from this node (Desktop/Terminal/Files...)
2017-08-28 19:27:45 +03:00
}
nodes.splice(index, 1);
2019-01-22 01:05:50 +03:00
// Web page update
2019-01-22 22:44:46 +03:00
masterUpdate(4 | 16);
2017-08-28 19:27:45 +03:00
}
break;
}
case 'changenode': {
var index = -1;
for (var i in nodes) { if (nodes[i]._id == message.event.nodeid) { index = i; break; } }
if (index != -1) {
var node = nodes[index];
// Change the node
node.name = message.event.node.name;
2018-06-05 23:28:07 +03:00
node.rname = message.event.node.rname;
2018-09-22 02:34:35 +03:00
node.users = message.event.node.users;
2017-08-28 19:27:45 +03:00
node.host = message.event.node.host;
node.desc = message.event.node.desc;
2018-09-22 02:34:35 +03:00
node.osdesc = message.event.node.osdesc;
2017-08-29 01:06:29 +03:00
node.publicip = message.event.node.publicip;
node.iploc = message.event.node.iploc;
2017-09-26 01:28:52 +03:00
node.wifiloc = message.event.node.wifiloc;
node.gpsloc = message.event.node.gpsloc;
2018-05-01 21:42:20 +03:00
node.tags = message.event.node.tags;
2017-09-26 01:28:52 +03:00
node.userloc = message.event.node.userloc;
2017-12-14 01:52:57 +03:00
if (message.event.node.agent != null) {
if (node.agent == null) node.agent = { };
if (message.event.node.agent.ver != null) { node.agent.ver = message.event.node.agent.ver; }
if (message.event.node.agent.id != null) { node.agent.id = message.event.node.agent.id; }
if (message.event.node.agent.caps != null) { node.agent.caps = message.event.node.agent.caps; }
if (message.event.node.agent.core != null) { node.agent.core = message.event.node.agent.core; } else { if (node.agent.core) { delete node.agent.core; } }
2017-08-28 19:27:45 +03:00
node.agent.tag = message.event.node.agent.tag;
}
2017-12-14 01:52:57 +03:00
if (message.event.node.intelamt != null) {
if (node.intelamt == null) node.intelamt = { };
if (message.event.node.intelamt.host != null) { node.intelamt.user = message.event.node.intelamt.host; }
if (message.event.node.intelamt.user != null) { node.intelamt.user = message.event.node.intelamt.user; }
if (message.event.node.intelamt.tls != null) { node.intelamt.tls = message.event.node.intelamt.tls; }
if (message.event.node.intelamt.ver != null) { node.intelamt.ver = message.event.node.intelamt.ver; }
if (message.event.node.intelamt.state != null) { node.intelamt.state = message.event.node.intelamt.state; }
2017-08-28 19:27:45 +03:00
}
node.namel = node.name.toLowerCase();
2018-05-30 02:57:08 +03:00
if (node.rname) { node.rnamel = node.rname.toLowerCase(); } else { node.rnamel = node.namel; }
2017-08-28 19:27:45 +03:00
if (message.event.node.icon) { node.icon = message.event.node.icon; }
2019-01-22 01:05:50 +03:00
// Web page update
2019-01-24 05:07:02 +03:00
masterUpdate(2 | 4 | 8 | 16);
2017-08-28 19:27:45 +03:00
refreshDevice(node._id);
2017-09-26 01:28:52 +03:00
if ((currentNode == node) && (xxdialogMode != null) && (xxdialogTag == '@xxmap')) { p10showNodeLocationDialog(); }
2017-08-28 19:27:45 +03:00
}
break;
}
2019-02-12 05:02:07 +03:00
case 'nodemeshchange': {
var index = -1;
for (var i in nodes) { if (nodes[i]._id == message.event.nodeid) { index = i; break; } }
if (index != -1) {
var node = nodes[index];
if (meshes[message.event.newMeshId] == null) {
// We don't see the new mesh, remove this device
// TODO: Correctly disconnect from this node (Desktop/Terminal/Files...)
if (currentNode == node) { if (xxcurrentView >= 10 && xxcurrentView < 20) { setDialogMode(0); go(1); } currentNode = null; }
nodes.splice(index, 1);
masterUpdate(4 | 16);
} else {
// We see the new mesh, move this device
node.meshid = message.event.newMeshId;
node.meshnamel = meshes[message.event.newMeshId].name.toLowerCase();
masterUpdate(1 | 2 | 4);
}
refreshDevice(message.event.nodeid);
} else {
// This is a new device, add it.
var node = message.event.node;
if (!meshes[node.meshid]) break; // This is a node for a mesh we don't know. Happens when we are site administrator, we get all messages.
node.namel = node.name.toLowerCase();
if (node.rname) { node.rnamel = node.rname.toLowerCase(); } else { node.rnamel = node.namel; }
node.meshnamel = meshes[node.meshid].name.toLowerCase();
node.state = 0;
if (!node.icon) node.icon = 1;
node.ident = ++nodeShortIdent;
if (nodes == null) { }
nodes.push(node);
// Web page update
masterUpdate(1 | 2 | 4 | 16);
}
break;
}
2017-08-28 19:27:45 +03:00
case 'nodeconnect': {
// Indicated a node has changed connectivity state
var index = -1;
for (var i in nodes) { if (nodes[i]._id == message.event.nodeid) { index = i; break; } }
if (index != -1) {
var node = nodes[index];
// Change the node connection state
node.conn = message.event.conn;
node.pwr = message.event.pwr;
2019-01-22 01:05:50 +03:00
// Web page update
2019-01-22 22:44:46 +03:00
masterUpdate(4 | 16);
2017-08-28 19:27:45 +03:00
refreshDevice(node._id);
}
break;
}
case 'wssessioncount': {
// Update the active web socket session count for a user
if (wssessions != null) {
2018-08-24 23:14:20 +03:00
if (message.event.count == 0 && wssessions['user/' + domain + '/' + message.event.username.toLowerCase()]) {
delete wssessions['user/' + domain + '/' + message.event.username.toLowerCase()];
2017-08-28 19:27:45 +03:00
} else {
2018-08-24 23:14:20 +03:00
wssessions['user/' + domain + '/' + message.event.username.toLowerCase()] = message.event.count;
2017-08-28 19:27:45 +03:00
}
updateUsers();
}
break;
}
case 'clearevents': {
events = [];
2019-01-22 22:44:46 +03:00
masterUpdate(32);
2017-08-28 19:27:45 +03:00
break;
}
case 'login': {
// Update the last login time
2019-01-25 04:01:50 +03:00
if (users != null && users['user/' + domain + '/' + message.event.username.toLowerCase()]) { users['user/' + domain + '/' + message.event.username.toLowerCase()].login = Math.floor(message.event.time / 1000); }
2017-08-28 19:27:45 +03:00
break;
}
case 'scanamtdevice': {
// Populate the Intel AMT scan dialog box with the result of the RMCP scan
2017-12-14 01:52:57 +03:00
if ((xxdialogMode == null) || (!Q('dp1range')) || (Q('dp1range').value != message.event.range)) return;
2017-08-28 19:27:45 +03:00
var x = '';
if (message.event.results == null) {
// The scan could not occur because of an error. Likely the user range was invalid.
x = '<div style=width:100%;text-align:center;margin-top:12px>Unable to scan this address range.</div><div style=width:100%;text-align:center;margin-top:12px;color:gray;line-height:1.5>Sample IP range values<br />192.168.0.100<br />192.168.1.0/24<br />192.167.0.1-192.168.0.100</div>';
} else {
// Go thru all the results and populate the dialog box
amtScanResults = message.event.results;
for (var i in message.event.results) {
var r = message.event.results[i], shortname = r.hostname;
if (shortname.length > 20) { shortname = shortname.substring(0, 20) + '...'; }
var str = '<b title="' + EscapeHtml(r.hostname) + '">' + EscapeHtml(shortname) + '</b> - v' + r.ver;
if (r.state == 2) { if (r.tls == 1) { str += ' with TLS.'; } else { str += ' without TLS.'; } } else { str += ' not activated.'; }
x += '<div style=width:100%;margin-bottom:2px;background-color:lightgray><div style=padding:4px><div style=display:inline-block;margin-right:5px><input class=DevScanCheckbox name=dp1checkbox tag="' + EscapeHtml(i) + '" type=checkbox onclick=addAmtScanToMeshCheckbox() /></div><div class=j1 style=display:inline-block></div><div style=display:inline-block;margin-left:5px;overflow-x:auto;white-space:nowrap>' + str + '</div></div></div>';
}
// If no results where found, display a nice message
if (x == '') { x = '<div style=width:100%;text-align:center;margin-top:12px>Scan returned no results.</div><div style=width:100%;text-align:center;margin-top:12px;color:gray;line-height:1.5>Sample IP range values<br />192.168.0.100<br />192.168.1.0/24<br />192.167.0.1-192.168.0.100</div>'; }
}
// Set the html in the dialog box and re-enable the scan button
QH('dp1results', x);
QE('dp1range', true);
QE('dp1rangebutton', true);
break;
}
2017-12-14 01:52:57 +03:00
case 'notify': {
var n = { text: message.event.value };
if (message.event.tag != null) { n.tag = message.event.tag; }
addNotification(n);
break;
}
2019-02-06 07:01:01 +03:00
case 'stopped': { // Server is stopping.
2019-02-12 01:41:15 +03:00
// Disconnect
2019-02-21 02:26:27 +03:00
//console.log(message.msg);
2019-02-06 07:01:01 +03:00
break;
}
2019-01-05 04:59:13 +03:00
default:
2019-01-07 07:23:29 +03:00
//console.log('Unknown message.event.action', message.event.action);
2019-01-05 04:59:13 +03:00
break;
2017-08-28 19:27:45 +03:00
}
break;
}
2019-02-12 01:41:15 +03:00
case 'stopped': { // Server is stopping.
// Disconnect
autoReconnect = false;
QH('p0span', message.msg);
break;
}
2019-01-05 04:59:13 +03:00
default:
console.log('Unknown message.action', message.action);
break;
2017-08-28 19:27:45 +03:00
}
}
//
// MY DEVICES
//
2018-05-22 02:36:51 +03:00
function onRealNameCheckBox() {
showRealNames = Q('RealNameCheckBox').checked;
putstore("showRealNames", showRealNames ? 1 : 0);
2019-01-22 22:44:46 +03:00
masterUpdate(6)
2017-08-28 19:27:45 +03:00
return;
}
2018-09-19 00:47:17 +03:00
function onDeviceViewChange(i) {
if (i != null) { Q('viewselect').value = i; }
for (var j = 1; j < 5; j++) { Q('devViewButton' + j).classList.remove('viewSelectorSel'); }
Q('devViewButton' + Q('viewselect').value).classList.add('viewSelectorSel');
2017-08-28 19:27:45 +03:00
putstore("deviceView", Q('viewselect').value);
2018-03-31 01:26:36 +03:00
putstore("viewsize", Q('sizeselect').value);
2019-01-22 22:44:46 +03:00
masterUpdate(4);
2017-08-28 19:27:45 +03:00
}
function ondockeypress(e) {
2018-04-02 21:13:10 +03:00
if (!xxdialogMode && xxcurrentView == 11 && desktop && Q("DeskControl").checked) return desktop.m.handleKeys(e);
2017-08-28 19:27:45 +03:00
if (!xxdialogMode && xxcurrentView == 12 && terminal && terminal.State == 3) return terminal.m.TermHandleKeys(e);
2019-02-05 05:06:01 +03:00
if (!xxdialogMode && ((xxcurrentView == 15) || (xxcurrentView == 115))) return agentConsoleHandleKeys(e);
2018-07-17 03:49:55 +03:00
if (!xxdialogMode && xxcurrentView == 4) {
if (e.ctrlKey == true || e.altKey == true || e.metaKey == true) return;
var processed = 0;
if (e.key) {
if (e.key.length === 1 && userSearchFocus == 0) { Q('UserSearchInput').value = ((Q('UserSearchInput').value + e.key)); processed = 1; }
if (e.keyCode == 8 && userSearchFocus == 0) { var x = Q('UserSearchInput').value; Q('UserSearchInput').value = x.substring(0, x.length - 1); processed = 1; }
if (e.keyCode == 27) { Q('UserSearchInput').value = ''; processed = 1; }
} else {
if (e.charCode != 0 && userSearchFocus == 0) { Q('UserSearchInput').value = ((Q('UserSearchInput').value + String.fromCharCode(e.charCode))); processed = 1; }
}
if (processed > 0) { if (processed == 1) { onUserSearchInputChanged(); } return haltEvent(e); }
}
2017-08-28 19:27:45 +03:00
if (xxdialogMode || xxcurrentView != 1) return;
if (e.ctrlKey == true && e.charCode == 96) {
2018-05-22 02:36:51 +03:00
showRealNames = !showRealNames;
Q('RealNameCheckBox').value = showRealNames;
putstore("showRealNames", showRealNames ? 1 : 0);
2019-01-22 22:44:46 +03:00
masterUpdate(6)
2017-08-28 19:27:45 +03:00
return;
}
if (e.ctrlKey == true || e.altKey == true || e.metaKey == true) return;
2017-08-30 00:34:13 +03:00
if (Q('viewselect').value < 3) {
var processed = 0;
if (e.key) {
if (e.key.length === 1 && searchFocus == 0) { Q('SearchInput').value = ((Q('SearchInput').value + e.key)); processed = 1; }
if (e.keyCode == 8 && searchFocus == 0) { var x = Q('SearchInput').value; Q('SearchInput').value = x.substring(0, x.length - 1); processed = 1; }
if (e.keyCode == 27) { Q('SearchInput').value = ''; processed = 1; }
} else {
if (e.charCode != 0 && searchFocus == 0) { Q('SearchInput').value = ((Q('SearchInput').value + String.fromCharCode(e.charCode))); processed = 1; }
}
2019-01-22 22:44:46 +03:00
if (processed > 0) { if (processed == 1) { masterUpdate(5); } return haltEvent(e); }
2017-08-30 00:34:13 +03:00
}
if (Q('viewselect').value == 3) {
if (e.key) {
if (e.key.length === 1 && mapSearchFocus == 0) { Q('mapSearchLocation').value = ((Q('mapSearchLocation').value + e.key)); processed = 1; }
//if (e.keyCode == 8 && mapSearchFocus == 0) { var x = Q('mapSearchLocation').value; Q('mapSearchLocation').value = x.substring(0, x.length - 1); processed = 1; }
if (e.keyCode == 27) { Q('mapSearchLocation').value = ''; mapCloseSearchWindow(); processed = 1; }
if (e.keyCode == 13) { getSearchLocation(); }
} else {
if (e.charCode != 0 && mapSearchFocus == 0) { Q('mapSearchLocation').value = ((Q('mapSearchLocation').value + String.fromCharCode(e.charCode))); processed = 1; }
}
2017-08-28 19:27:45 +03:00
}
}
function ondockeydown(e) {
2018-04-02 21:13:10 +03:00
if (!xxdialogMode && xxcurrentView == 11 && desktop && Q("DeskControl").checked) { return desktop.m.handleKeyDown(e); }
2018-01-24 01:15:59 +03:00
if (!xxdialogMode && xxcurrentView == 12 && terminal && terminal.State == 3) { return terminal.m.TermHandleKeyDown(e); }
2017-08-28 19:27:45 +03:00
if (!xxdialogMode && xxcurrentView == 13 && e.keyCode == 116 && p13filetree != null) { haltEvent(e); return false; } // F5 Refresh on files
2019-02-05 05:06:01 +03:00
if (!xxdialogMode && ((xxcurrentView == 15) || (xxcurrentView == 115))) { return agentConsoleHandleKeys(e); }
2018-08-24 02:55:06 +03:00
if (!xxdialogMode && xxcurrentView == 4) {
2018-07-17 03:49:55 +03:00
if (e.keyCode === 8 && userSearchFocus == 0) { var x = Q('UserSearchInput').value; Q('UserSearchInput').value = (x.substring(0, x.length - 1)); processed = 1; }
if (e.keyCode === 27) { Q('UserSearchInput').value = ''; processed = 1; }
2019-01-22 22:44:46 +03:00
if (processed > 0) { if (processed == 1) { masterUpdate(5); } return haltEvent(e); }
2018-07-17 03:49:55 +03:00
}
2017-08-28 19:27:45 +03:00
if (xxdialogMode || xxcurrentView != 1 || e.ctrlKey == true || e.altKey == true || e.metaKey == true) return;
var processed = 0;
2017-08-30 00:34:13 +03:00
if (Q('viewselect').value < 3) {
if (e.keyCode === 8 && searchFocus == 0) { var x = Q('SearchInput').value; Q('SearchInput').value = (x.substring(0, x.length - 1)); processed = 1; }
if (e.keyCode === 27) { Q('SearchInput').value = ''; processed = 1; }
2019-01-22 22:44:46 +03:00
if (processed > 0) { if (processed == 1) { masterUpdate(5); } return haltEvent(e); }
2017-08-30 00:34:13 +03:00
}
if (Q('viewselect').value == 3) {
if (e.keyCode === 8 && mapSearchFocus == 0) { var x = Q('mapSearchLocation').value; Q('mapSearchLocation').value = (x.substring(0, x.length - 1)); processed = 1; }
if (e.keyCode === 27) { Q('mapSearchLocation').value = ''; mapCloseSearchWindow(); processed = 1; }
}
2017-08-28 19:27:45 +03:00
}
function ondockeyup(e) {
2018-04-02 21:13:10 +03:00
if (!xxdialogMode && xxcurrentView == 11 && desktop && Q("DeskControl").checked) return desktop.m.handleKeyUp(e);
2017-08-28 19:27:45 +03:00
if (!xxdialogMode && xxcurrentView == 12 && terminal && terminal.State == 3) return terminal.m.TermHandleKeyUp(e);
if (!xxdialogMode && xxcurrentView == 13 && e.keyCode == 116 && p13filetree != null) { p13folderup(9999); haltEvent(e); return false; } // F5 Refresh on files
2018-07-17 03:49:55 +03:00
if (!xxdialogMode && xxcurrentView == 4) { if ((e.keyCode === 8 && searchFocus == 0) || e.keyCode === 27) { return haltEvent(e); } }
2017-12-15 01:57:52 +03:00
if (xxdialogMode && e.keyCode == 27) { dialogclose(0); }
2017-08-28 19:27:45 +03:00
if (xxdialogMode || xxcurrentView != 0 || e.ctrlKey == true || e.altKey == true || e.metaKey == true) return;
2017-08-30 00:34:13 +03:00
if (Q('viewselect').value < 3) { if ((e.keyCode === 8 && searchFocus == 0) || e.keyCode === 27) { return haltEvent(e); } }
if (Q('viewselect').value == 3) { if ((e.keyCode === 8 && mapSearchFocus == 0) || e.keyCode === 27) { return haltEvent(e); } }
2017-08-28 19:27:45 +03:00
}
2018-11-13 05:36:20 +03:00
// Highlights the device being hovered
function devMouseHover(element, over) {
2018-11-13 06:30:09 +03:00
var view = Q('viewselect').value;
if (view == 1) {
var e = element.children[1].children[1];
e.children[0].classList.remove('g1s');
e.children[1].classList.remove('e2s');
e.children[2].classList.remove('g2s');
if (over == 1) {
e.children[0].classList.add('g1s');
e.children[1].classList.add('e2s');
e.children[2].classList.add('g2s');
}
} else if (view == 2) {
var e = element;
e.children[2].classList.remove('g1s');
e.children[4].classList.remove('e2s');
e.children[3].classList.remove('g2s');
if (over == 1) {
e.children[2].classList.add('g1s');
e.children[4].classList.add('e2s');
e.children[3].classList.add('g2s');
}
2018-11-13 05:36:20 +03:00
}
}
2017-08-28 19:27:45 +03:00
var deviceHeaderId = 0;
2018-08-27 22:24:15 +03:00
var deviceHeaderTotal = 0;
var deviceHeadersTitles = { };
2017-08-28 19:27:45 +03:00
var deviceHeaderCount;
var deviceHeaders = { };
2018-04-02 21:13:10 +03:00
var oldviewmode = 0;
2019-01-22 22:44:46 +03:00
function updateDevices() {
2019-01-30 01:08:29 +03:00
if (nodes == null) { return; }
2018-05-01 21:42:20 +03:00
var r = '', c = 0, current = null, count = 0, displayedMeshes = { }, view = Q('viewselect').value, groups = { }, groupCount = { };
2018-03-31 01:26:36 +03:00
QV('xdevices', view < 4);
QV('xdevicesmap', view == 4);
2017-08-29 01:57:25 +03:00
QV('devListToolbar', view < 3);
2018-03-31 01:26:36 +03:00
QV('kvmListToolbar', view == 3);
QV('devMapToolbar', view == 4);
QV('devListToolbarSize', view == 3);
2017-10-03 00:12:29 +03:00
QV('NoMeshesPanel', meshcount == 0);
2018-09-19 00:47:17 +03:00
//QV('devListToolbarView', (meshcount != 0) && (nodes.length > 0));
QV('devListToolbarViewIcons', (meshcount != 0) && (nodes.length > 0));
2018-05-01 21:42:20 +03:00
QV('devListToolbarSort', (meshcount != 0) && (nodes.length > 0) && (view < 4));
2018-09-12 00:28:47 +03:00
if ((meshcount == 0) || (nodes.length == 0)) { view = 1; sort = 0; }
2018-03-31 01:26:36 +03:00
if (view == 4) {
2017-09-07 04:10:24 +03:00
setTimeout( function() { if (xxmap.map != null) { xxmap.map.updateSize(); } }, 200);
2017-08-29 01:57:25 +03:00
// TODO
} else {
2018-03-31 01:26:36 +03:00
// 3 wide, list view or desktop view
2017-08-29 01:57:25 +03:00
deviceHeaderId = 0;
deviceHeaderCount = { };
deviceHeaderTotal = 0;
deviceHeaders = { };
deviceHeadersTitles = { };
2018-03-31 01:26:36 +03:00
var kvmDivs = [];
2017-08-28 19:27:45 +03:00
2018-08-21 21:02:35 +03:00
// Perform node sort
if (sort == 0) { nodes.sort(meshSort); }
else if (sort == 1) { nodes.sort(powerSort); }
else if (sort == 2) { if (showRealNames == true) { nodes.sort(deviceHostSort); } else { nodes.sort(deviceSort); } }
2017-08-29 01:57:25 +03:00
// Save the list of currently checked nodeid's
var checkedNodeids = [], elements = document.getElementsByClassName("DeviceCheckbox"), checkcount = 0;
2018-08-21 21:02:35 +03:00
for (var i=0;i<elements.length;i++) { if (elements[i].checked) { checkedNodeids.push(elements[i].value); } }
2018-04-02 21:13:10 +03:00
if ((oldviewmode < 3) && (view == 3)) { multiDesktopFilter = checkedNodeids; }
else if ((oldviewmode == 3) && (view < 3)) { checkedNodeids = multiDesktopFilter; }
2017-08-28 19:27:45 +03:00
2019-01-24 05:07:02 +03:00
// Compute the width of the device view.
var totalDeviceViewWidth = Q('column_l').clientWidth - 60;
var deviceBoxWidth = Math.floor(totalDeviceViewWidth / 301);
deviceBoxWidth = 301 + Math.floor((totalDeviceViewWidth - (deviceBoxWidth * 301)) / deviceBoxWidth);
2017-08-29 01:57:25 +03:00
// Go thru the list of nodes and display them
for (var i in nodes) {
if (nodes[i].v == false) continue;
2018-08-24 23:14:20 +03:00
var mesh2 = meshes[nodes[i].meshid], meshlinks = mesh2.links['user/' + domain + '/' + userinfo.name.toLowerCase()];
2017-12-14 01:52:57 +03:00
if (meshlinks == null) continue;
2018-03-31 01:26:36 +03:00
var meshrights = meshlinks.rights;
if ((view == 3) && (mesh2.mtype == 1)) continue;
2017-08-29 01:57:25 +03:00
if (sort == 0) {
// Mesh header
if (nodes[i].meshid != current) {
deviceHeaderSet();
var extra = '';
if (meshes[nodes[i].meshid].mtype == 1) { extra = '<span class=devHeaderx>, Intel® AMT only</span>'; }
2018-03-31 01:26:36 +03:00
if ((view == 1) && (current != null)) { if (c == 2) { r += '<td><div style=width:301px></div></td>'; } if (r != '') { r += '</tr></table>'; } }
2018-03-07 04:50:44 +03:00
r += '<div class=DevSt style=width:100%;padding-top:4px><span style=float:right>';
2017-08-29 01:57:25 +03:00
r += getMeshActions(mesh2, meshrights);
2018-03-07 04:50:44 +03:00
r += '</span><span id=MxMESH style=cursor:pointer onclick=gotoMesh("' + nodes[i].meshid + '")>' + EscapeHtml(meshes[nodes[i].meshid].name) + '</span>' + extra + '<span id=DevxHeader' + deviceHeaderId + ' class=devHeaderx></span></div>';
2017-08-29 01:57:25 +03:00
current = nodes[i].meshid;
displayedMeshes[current] = 1;
c = 0;
}
} else if (sort == 1) {
// Power header
2018-08-21 21:02:35 +03:00
var pwr = nodes[i].pwr?nodes[i].pwr:0;
if (pwr !== current) {
2017-08-29 01:57:25 +03:00
deviceHeaderSet();
2018-03-31 01:26:36 +03:00
if ((view == 1) && (current !== null)) { if (c == 2) { r += '<td><div style=width:301px></div></td>'; } if (r != '') { r += '</tr></table>'; } }
2018-03-07 04:50:44 +03:00
r += '<div class=DevSt style=width:100%;padding-top:4px><span>' + PowerStateStr2(nodes[i].pwr) + '</span><span id=DevxHeader' + deviceHeaderId + ' class="devHeaderx"></span></div>';
2018-08-21 21:02:35 +03:00
current = pwr;
2017-08-29 01:57:25 +03:00
c = 0;
}
} else if (sort == 2) {
// Device header
2018-03-07 04:50:44 +03:00
if (current == null) { current = '1'; }
2017-08-28 19:27:45 +03:00
}
2017-08-29 01:57:25 +03:00
count++;
var title = EscapeHtml(nodes[i].name);
if (title.length == 0) { title = '<i>None</i>'; }
2018-05-22 02:36:51 +03:00
if ((nodes[i].rname != null) && (nodes[i].rname.length > 0)) { title += " / " + EscapeHtml(nodes[i].rname); }
2017-08-29 01:57:25 +03:00
var name = EscapeHtml(nodes[i].name);
2018-05-22 02:36:51 +03:00
if (showRealNames == true && nodes[i].rname != null) name = EscapeHtml(nodes[i].rname);
2017-08-29 01:57:25 +03:00
if (name.length == 0) { name = '<i>None</i>'; }
2017-08-28 19:27:45 +03:00
2017-08-29 01:57:25 +03:00
// Node
var icon = nodes[i].icon;
var nodestate = NodeStateStr(nodes[i]);
if ((!nodes[i].conn) || (nodes[i].conn == 0)) { icon += ' gray'; }
if (view == 1) {
2019-01-30 01:08:29 +03:00
r += '<div id=devs onmouseover=devMouseHover(this,1) onmouseout=devMouseHover(this,0) style=display:inline-block;width:' + deviceBoxWidth + 'px;height:50px;padding-top:1px;padding-bottom:1px><div style=width:22px;height:50%;float:left;padding-top:12px><input class="' + nodes[i].meshid + ' DeviceCheckbox" onclick=p1updateInfo() value=devid_' + nodes[i]._id + ' type=checkbox></div><div style=height:100%;cursor:pointer onclick=gotoDevice(\'' + nodes[i]._id + '\',null,null,event)><div class="i' + icon + '" style=width:50px;float:left></div><div style=height:100%><div class=g1></div><div class=e2><div class=e1 style=width:' + (deviceBoxWidth - 100) + 'px title="' + title + '">' + name + '</div><div>' + nodestate + '</div></div><div class=g2></div></div></div></div>';
2018-03-31 01:26:36 +03:00
} else if (view == 2) {
2018-11-13 06:30:09 +03:00
r += '<tr><td><div id=devs class=bar18 onmouseover=devMouseHover(this,1) onmouseout=devMouseHover(this,0) style=height:18px;width:100%;font-size:medium>';
2018-03-07 04:50:44 +03:00
r += '<div style=width:22px;float:left;background-color:white><input class="' + nodes[i].meshid + ' DeviceCheckbox" onclick=p1updateInfo() value=devid_' + nodes[i]._id + ' type=checkbox></div>';
2019-01-30 01:08:29 +03:00
r += '<div style=float:left;height:18px;width:18px;background-color:white onclick=gotoDevice(\'' + nodes[i]._id + '\',null,null,event)><div class=j' + icon + ' style=width:16px;margin-top:1px;margin-left:2px;height:16px></div></div>';
2018-03-07 04:50:44 +03:00
r += '<div class=g1 style=height:18px;float:left></div><div class=g2 style=height:18px;float:right></div>';
2019-01-30 01:08:29 +03:00
r += '<div style=cursor:pointer;font-size:14px title="' + title + '" onclick=gotoDevice(\'' + nodes[i]._id + '\',null,null,event)><span style=float:right>' + nodestate + '</span><span style=width:300px>' + name + '</span></div></div></td></tr>';
2018-11-03 04:13:32 +03:00
} else if ((view == 3) && (nodes[i].conn & 1) && (((meshrights & 8) || (meshrights & 256)) != 0) && ((nodes[i].agent.caps & 1) != 0)) { // Check if we have rights and agent is capable of KVM.
2018-04-02 21:13:10 +03:00
if ((multiDesktopFilter.length == 0) || (multiDesktopFilter.indexOf('devid_' + nodes[i]._id) >= 0)) {
2019-01-30 01:08:29 +03:00
r += '<div id=devs style=display:inline-block;margin:1px;background-color:lightgray;border-radius:5px;position:relative><div style=padding:3px;cursor:pointer onclick=gotoDevice(\'' + nodes[i]._id + '\',11,null,event)>';
2018-04-02 21:13:10 +03:00
//r += '<input class="' + nodes[i].meshid + ' DeviceCheckbox" onclick=p1updateInfo() value=devid_' + nodes[i]._id + ' type=checkbox style=float:left>';
r += '<div class="j' + icon + '" style=width:16px;float:left></div> ' + name + '</div>';
2019-01-30 01:08:29 +03:00
r += '<span onclick=gotoDevice(\'' + nodes[i]._id + '\',null,null,event)></span><div id=xkvmid_' + nodes[i]._id.split('/')[2] + '><div id=skvmid_' + nodes[i]._id.split('/')[2] + ' style="position:absolute;color:white;left:5px;top:27px;text-shadow:0px 0px 5px #000;z-index:1000;cursor:default" onclick=toggleKvmDevice(\'' + nodes[i]._id + '\')>Disconnected</div></div>';
2018-04-02 21:13:10 +03:00
r += '</div>';
kvmDivs.push(nodes[i]._id);
}
2017-08-29 01:57:25 +03:00
}
2018-03-07 04:50:44 +03:00
2018-05-01 21:42:20 +03:00
// If we are displaying devices by group, put the device in the right group.
if ((sort == 3) && (r != '')) {
if (nodes[i].tags) {
for (var j in nodes[i].tags) {
var tag = nodes[i].tags[j];
if (groups[tag] == null) { groups[tag] = r; groupCount[tag] = 1; } else { groups[tag] += r; groupCount[tag] += 1; }
if (view == 3) break;
}
}
r = '';
}
2017-08-29 01:57:25 +03:00
deviceHeaderTotal++;
if (typeof deviceHeaderCount[nodes[i].state] == 'undefined') { deviceHeaderCount[nodes[i].state] = 1; } else { deviceHeaderCount[nodes[i].state]++; }
2017-08-28 19:27:45 +03:00
}
2018-05-01 21:42:20 +03:00
// If displaying devices by groups, sort the group names and display the devices.
if (sort == 3) {
var groupNames = [];
for (var i in groups) { groupNames.push(i); }
groupNames.sort(function (a, b) { return a.toLowerCase().localeCompare(b.toLowerCase()); });
for (var j in groupNames) {
var i = groupNames[j]; r += '<div class=DevSt style=width:100%;padding-top:4px><span>' + i + '</span><span class="devHeaderx">, ' + groupCount[i] + ' device' + ((groupCount[i] > 1)?'s':'') + '</span></div>' + groups[i];
}
}
// If there is nothing to display, explain the problem
2018-06-05 23:28:07 +03:00
if ((r == '') && (meshcount > 0) && (Q('SearchInput').value != '')) {
if (sort == 3) {
2018-05-01 21:42:20 +03:00
r = '<div style="margin:30px">No devices are included in any groups, click on a device\'s \"Groups\" to add to a group.</div>';
} else {
r = '<div style="margin:30px">No devices matching this search.</div>';
}
}
2017-08-29 01:57:25 +03:00
if ((view == 1) && (c == 2)) r += '<td><div style=width:301px></div></td>'; // Adds device padding
2017-08-28 19:27:45 +03:00
2017-08-29 01:57:25 +03:00
// Display all empty meshes, we need to do this because users can add devices to these at any time.
2018-03-31 01:26:36 +03:00
if ((sort == 0) && (Q('SearchInput').value == '') && (view < 3)) {
2017-08-29 01:57:25 +03:00
for (var i in meshes) {
2018-08-24 23:14:20 +03:00
var mesh = meshes[i], meshlink = mesh.links['user/' + domain + '/' + userinfo.name.toLowerCase()];
2017-12-14 01:52:57 +03:00
if (meshlink != null) {
2017-08-29 01:57:25 +03:00
var meshrights = meshlink.rights;
2017-12-14 01:52:57 +03:00
if (displayedMeshes[mesh._id] == null) {
2018-03-31 01:26:36 +03:00
if ((current != '') && (r != '')) { r += '</tr></table>'; }
2017-08-29 01:57:25 +03:00
r += '<table style=width:100%;padding-top:4px cellpadding=0 cellspacing=0><tr><td colspan=3 class=DevSt><span style=float:right>';
r += getMeshActions(mesh, meshrights);
r += '</span><span id=MxMESH style=cursor:pointer onclick=gotoMesh("' + mesh._id + '")>' + EscapeHtml(mesh.name) + '</span></td></tr><tr>';
if (mesh.mtype == 1) {
r += '<td><div style=padding:10px><i>No Intel® AMT devices in this mesh';
if ((meshrights & 4) != 0) { r += ', <a style=cursor:pointer onclick=addDeviceToMesh(\"' + mesh._id + '\")>add one</a>'; }
}
if (mesh.mtype == 2) {
r += '<td><div style=padding:10px><i>No devices in this mesh';
if ((meshrights & 4) != 0) { r += ', <a style=cursor:pointer onclick=addAgentToMesh(\"' + mesh._id + '\")>add one</a>'; }
}
r += '.</i></div></td>';
current = mesh._id;
count++;
2017-08-28 19:27:45 +03:00
}
}
}
}
2017-08-29 01:57:25 +03:00
r += '</tr></table><div style=height:1px></div>'; // This height of 1 div fixes a problem in Linux firefox browsers
2017-08-28 19:27:45 +03:00
2018-09-25 03:47:03 +03:00
// Add a "Add Device Group" option
2017-12-16 00:43:04 +03:00
r += '<div style=border-top-style:solid;border-top-width:1px;border-top-color:#DDDDDD;cursor:pointer;font-size:10px>';
2018-09-25 03:47:03 +03:00
if ((view < 3) && (sort == 0) && (meshcount > 0)) { r += '<a onclick=account_createMesh() title="Create a new group of devices." style=cursor:pointer>Add Device Group</a> '; }
2017-12-16 00:43:04 +03:00
r += '<a onclick=p10showMeshCmdDialog(0) style=cursor:pointer title="Download MeshCmd, a command line tool that performs many functions.">MeshCmd</a></div>';
2018-09-15 03:42:39 +03:00
r += '</div><br/>';
2017-10-03 00:12:29 +03:00
2017-08-29 01:57:25 +03:00
QH('xdevices', r);
deviceHeaderSet();
2017-08-28 19:27:45 +03:00
2017-08-29 01:57:25 +03:00
// Re-check nodeid's
var elements = document.getElementsByClassName("DeviceCheckbox"), checkcount = 0;
2018-08-21 21:02:35 +03:00
for (var i=0;i<elements.length;i++) { elements[i].checked = (checkedNodeids.indexOf(elements[i].value) >= 0); }
2017-08-28 19:27:45 +03:00
2017-08-29 01:57:25 +03:00
for (var i in deviceHeaders) { QH(i, deviceHeaders[i]); }
for (var i in deviceHeadersTitles) { Q(i).title = deviceHeadersTitles[i]; }
p1updateInfo();
2018-03-31 01:26:36 +03:00
// Take care of KVM surfaces in desktop view mode
if (view == 3) {
2018-09-19 00:47:17 +03:00
// Figure out and adjust the size to fill the width of the div
var vsize = [ { x: 180, y: 101 }, { x: 302, y: 169 }, { x: 454, y: 255 }][Q('sizeselect').selectedIndex];
2019-01-24 23:08:48 +03:00
//var realw = vsize.x + 2, tw = Q('xdevices').clientWidth - 30, xw = Math.floor(tw / realw);
var realw = vsize.x + 2, tw = totalDeviceViewWidth - 5, xw = Math.floor(tw / realw);
2018-09-19 00:47:17 +03:00
xw = realw + Math.floor((tw - (xw * realw)) / xw);
vsize.y = vsize.y * (xw / vsize.x);
vsize.x = xw;
2018-03-31 01:26:36 +03:00
for (var i in multiDesktop) { multiDesktop[i].xxdelete = true; }
for (var i in kvmDivs) {
var id = kvmDivs[i], shortid = id.split('/')[2], desk = multiDesktop[id];
if (desk != null) {
// This device already has a canvas, use it.
desk.m.CanvasId.setAttribute('style', 'background-color:black;width:' + vsize.x + 'px;height:' + vsize.y + 'px');
Q('xkvmid_' + shortid).appendChild(desk.m.CanvasId);
delete desk.xxdelete;
QH('skvmid_' + shortid, ['Disconnected', 'Connecting...', 'Setup...', '', ''][((desk.m.State == null)?desk.m.state:desk.m.State)]);
} else {
var node = getNodeFromId(id);
if ((desktopNode == node) && (desktop != null)) { // Check if the main desktop is this device, if it is, use that.
// This device already has a canvas, use it.
var c = desktop.m.CanvasId;
c.setAttribute('id', 'kvmid_' + shortid);
c.setAttribute('style', 'background-color:black;width:' + vsize.x + 'px;height:' + vsize.y + 'px');
c.setAttribute('onclick', 'toggleKvmDevice(\'' + id + '\')');
c.removeAttribute('onmousedown');
c.removeAttribute('onmouseup');
c.removeAttribute('onmousemove');
Q('xkvmid_' + shortid).appendChild(c);
QH('skvmid_' + shortid, ['Disconnected', 'Connecting...', 'Setup...', '', ''][((desktop.m.State == null)?desktop.m.state:desktop.m.State)]);
2018-04-07 01:56:45 +03:00
if (desktop.m.SendCompressionLevel) { desktop.m.SendCompressionLevel(1, multidesktopsettings.quality, multidesktopsettings.scaling, multidesktopsettings.framerate); }
2018-03-31 01:26:36 +03:00
desktop.shortid = shortid;
desktop.onStateChanged = onMultiDesktopStateChange;
multiDesktop[id] = desktop;
desktop = desktopNode = currentNode = null;
// Setup a replacement desktop
2018-09-17 23:44:14 +03:00
QH('DeskParent', '<canvas id="Desk" width="640" height="480" style="width:100%;-ms-touch-action:none;margin-left:0px" oncontextmenu="return false" onmousedown=dmousedown(event) onmouseup=dmouseup(event) onmousemove=dmousemove(event)></canvas>');
2018-03-31 01:26:36 +03:00
} else {
// This is a new device, create a canvas for it.
var c = document.createElement('canvas');
c.setAttribute('id', 'kvmid_' + shortid);
c.setAttribute('width', 640);
2018-09-17 23:44:14 +03:00
c.setAttribute('height', 480);
2018-03-31 01:26:36 +03:00
c.setAttribute('oncontextmenu', 'return false');
c.setAttribute('style', 'background-color:black;width:' + vsize.x + 'px;height:' + vsize.y + 'px');
c.setAttribute('onclick', 'toggleKvmDevice(\'' + id + '\')');
2018-05-01 21:42:20 +03:00
try { Q('xkvmid_' + shortid).appendChild(c); } catch (ex) { }
2018-03-31 01:26:36 +03:00
// Check if we need to auto-connect
if (Q('autoConnectDesktopCheckbox').checked == true) { setTimeout(function() { connectMultiDesktop(node, 1); }, 100); }
}
}
}
for (var i in multiDesktop) {
// If a device is no longer viewed, disconnect it.
if (multiDesktop[i].xxdelete == true) { multiDesktop[i].Stop(); delete multiDesktop[i]; }
2018-11-15 02:44:28 +03:00
else if (debugmode && multiDesktop[i].m && multiDesktop[i].m.onScreenSizeChange) {
2018-11-25 23:59:42 +03:00
mdeskAdjust(multiDesktop[i].m, multiDesktop[i].m.ScreenWidth, multiDesktop[i].m.ScreenHeight, multiDesktop[i].m.CanvasId); // Adjust screen size change
2018-11-15 02:44:28 +03:00
}
2018-03-31 01:26:36 +03:00
}
2018-09-17 23:44:14 +03:00
deskAdjust();
2018-03-31 01:26:36 +03:00
} else {
disconnectAllKvmFunction();
Q('autoConnectDesktopCheckbox').checked = false;
}
}
2018-04-02 21:13:10 +03:00
oldviewmode = view;
2018-03-31 01:26:36 +03:00
}
function toggleKvmDevice(nodeid) {
2018-08-24 23:14:20 +03:00
var node = getNodeFromId(nodeid), mesh = meshes[node.meshid], meshrights = mesh.links['user/' + domain + '/' + userinfo.name.toLowerCase()].rights;
2018-11-03 04:13:32 +03:00
if ((meshrights & 8) || (meshrights & 256)) { // Requires remote control rights or desktop view only rights
2018-03-31 01:26:36 +03:00
//var conn = 0;
//if ((node.conn & 1) != 0) { conn = 1; } else if ((node.conn & 6) != 0) { conn = 2; } // Check what type of connect we can do (Agent vs AMT)
if (node.conn & 1) { connectMultiDesktop(node, 1); }
}
}
function autoConnectDesktops() { if (Q('autoConnectDesktopCheckbox').checked == true) { connectAllKvmFunction(); } }
function connectAllKvmFunction() { for (var i in nodes) { if (multiDesktop[nodes[i]._id] == null) { toggleKvmDevice(nodes[i]._id); } } }
function disconnectAllKvmFunction() { for (var nodeid in multiDesktop) { multiDesktop[nodeid].Stop(); } multiDesktop = { }; }
function onMultiDesktopStateChange(desk, state) { try { QH('skvmid_' + desk.shortid, ['Disconnected', 'Connecting...', 'Setup...', '', ''][state]); } catch (ex) { } }
function showMultiDesktopSettings() {
QV('d7amtkvm', false);
QV('d7meshkvm', true);
d7bitmapquality.value = multidesktopsettings.quality;
d7bitmapscaling.value = multidesktopsettings.scaling;
2018-04-07 01:56:45 +03:00
if (multidesktopsettings.framerate) { d7framelimiter.value = multidesktopsettings.framerate; } else { d7framelimiter.value = 1000; }
2018-03-31 01:26:36 +03:00
setDialogMode(7, "Remote Desktop Settings", 3, showMultiDesktopSettingsChanged);
}
function showMultiDesktopSettingsChanged() {
multidesktopsettings.quality = d7bitmapquality.value;
multidesktopsettings.scaling = d7bitmapscaling.value;
2018-04-07 01:56:45 +03:00
multidesktopsettings.framerate = d7framelimiter.value;
2018-03-31 01:26:36 +03:00
localStorage.setItem('multidesktopsettings', JSON.stringify(multidesktopsettings));
// Make changes to all current connections
2018-04-07 01:56:45 +03:00
for (var i in multiDesktop) { multiDesktop[i].m.SendCompressionLevel(1, multidesktopsettings.quality, multidesktopsettings.scaling, multidesktopsettings.framerate); }
2018-03-31 01:26:36 +03:00
}
function connectMultiDesktop(node, contype) {
2018-04-02 21:13:10 +03:00
var nodeid = node._id, shortid = nodeid.split('/')[2];
2018-03-31 01:26:36 +03:00
var desk = multiDesktop[nodeid];
if (desk == null) {
2018-04-02 21:13:10 +03:00
if (Q('kvmid_' + shortid) == null) return; // Check if this device is being displayed, if not, exit now.
2018-03-31 01:26:36 +03:00
if (contype == 2) {
// Setup the Intel AMT remote desktop
if ((node.intelamt.user == null) || (node.intelamt.user == '')) { return; }
2019-01-29 02:47:54 +03:00
desk = CreateAmtRedirect(CreateAmtRemoteDesktop('kvmid_' + shortid), authCookie);
2018-04-02 21:13:10 +03:00
desk.shortid = shortid;
2018-03-31 01:26:36 +03:00
//desk.debugmode = debugmode;
desk.onStateChanged = onMultiDesktopStateChange;
desk.m.bpp = 1;
desk.m.useZRLE = true;
desk.m.showmouse = true;
2018-09-29 01:27:26 +03:00
desk.m.onKvmData = function (data) { console.log('KVM Data received in multi-desktop mode, this is not supported.'); }; // KVM Data Channel not supported in multi-desktop right now.
2018-03-31 01:26:36 +03:00
//desk.m.onScreenSizeChange = deskAdjust;
2018-11-14 06:31:12 +03:00
if (debugmode > 0) { desk.m.onScreenSizeChange = mdeskAdjust; } // Multi-Desktop Adjust
2018-03-31 01:26:36 +03:00
desk.Start(nodeid, 16994, '*', '*', 0);
desk.contype = 2;
multiDesktop[nodeid] = desk;
} else if (contype == 1) {
// Setup the Mesh Agent remote desktop
2019-01-29 02:47:54 +03:00
desk = CreateAgentRedirect(meshserver, CreateAgentRemoteDesktop('kvmid_' + shortid), serverPublicNamePort, authCookie);
2018-04-02 21:13:10 +03:00
desk.shortid = shortid;
2018-03-31 01:26:36 +03:00
desk.attemptWebRTC = attemptWebRTC;
desk.onStateChanged = onMultiDesktopStateChange;
desk.m.CompressionLevel = multidesktopsettings.quality;
desk.m.ScalingLevel = multidesktopsettings.scaling;
2018-04-07 01:56:45 +03:00
desk.m.FrameRateTimer = multidesktopsettings.framerate;
2018-03-31 01:26:36 +03:00
//desk.m.onDisplayinfo = deskDisplayInfo;
//desk.m.onScreenSizeChange = deskAdjust;
2018-11-14 06:31:12 +03:00
if (debugmode > 0) { desk.m.onScreenSizeChange = mdeskAdjust; } // Multi-Desktop Adjust
2018-03-31 01:26:36 +03:00
desk.Start(nodeid);
desk.contype = 1;
multiDesktop[nodeid] = desk;
}
} else {
// Disconnect and clean up the remote desktop
desk.Stop();
delete multiDesktop[nodeid];
2017-08-29 01:57:25 +03:00
}
2017-08-28 19:27:45 +03:00
}
function getMeshActions(mesh, meshrights) {
if ((meshrights & 4) == 0) return '';
var r = '';
2018-06-20 21:07:29 +03:00
if ((features & 1024) == 0) { // If CIRA is allowed
2018-03-27 03:13:32 +03:00
r += ' <a style=cursor:pointer;font-size:10px title="Add a new Intel® AMT computer that is located on the internet." onclick=addCiraDeviceToMesh(\"' + mesh._id + '\")>Add CIRA</a>';
}
2017-08-28 19:27:45 +03:00
if (mesh.mtype == 1) {
if ((features & 1) == 0) { // If not WAN-Only
r += ' <a style=cursor:pointer;font-size:10px title="Add a new Intel® AMT computer that is located on the local network." onclick=addDeviceToMesh(\"' + mesh._id + '\")>Add Local</a>';
r += ' <a style=cursor:pointer;font-size:10px title="Add a new Intel® AMT computer by scanning the local network." onclick=addAmtScanToMesh(\"' + mesh._id + '\")>Scan Network</a>';
}
}
if (mesh.mtype == 2) {
r += ' <a style=cursor:pointer;font-size:10px title="Add a new computer to this mesh by installing the mesh agent." onclick=addAgentToMesh(\"' + mesh._id + '\")>Add Agent</a>';
2018-01-24 01:15:59 +03:00
if (features & 64) {
2018-09-06 03:40:00 +03:00
r += ' <a style=cursor:pointer;font-size:10px title="Invite someone to install the mesh agent on this mesh." onclick=inviteAgentToMesh(\"' + mesh._id + '\")>Invite</a>';
2018-01-24 01:15:59 +03:00
}
2017-08-28 19:27:45 +03:00
}
return r;
}
function addDeviceToMesh(meshid) {
if (xxdialogMode) return;
var mesh = meshes[meshid];
2018-09-25 03:47:03 +03:00
var x = "Add a new Intel® AMT device to device group \"" + EscapeHtml(mesh.name) + "\".<br /><br />";
2017-08-28 19:27:45 +03:00
x += addHtmlValue('Device Name', '<input id=dp1devicename style=width:230px maxlength=32 autocomplete=off onchange=validateDeviceToMesh() onkeyup=validateDeviceToMesh() />');
x += addHtmlValue('Hostname', '<input id=dp1hostname style=width:230px maxlength=32 autocomplete=off placeholder="Same as device name" onchange=validateDeviceToMesh() onkeyup=validateDeviceToMesh() />');
x += addHtmlValue('Username', '<input id=dp1username style=width:230px maxlength=32 autocomplete=off placeholder="admin" onchange=validateDeviceToMesh() onkeyup=validateDeviceToMesh() />');
x += addHtmlValue('Password', '<input id=dp1password type=password style=width:230px autocomplete=off maxlength=32 onchange=validateDeviceToMesh() onkeyup=validateDeviceToMesh() />');
x += addHtmlValue('Security', '<select id=dp1tls style=width:236px><option value=0>No TLS security</option><option value=1>TLS security required</option></select>');
setDialogMode(2, "Add Intel® AMT device", 3, addDeviceToMeshEx, x, meshid);
validateDeviceToMesh();
2017-12-15 01:57:52 +03:00
Q('dp1devicename').focus();
2017-08-28 19:27:45 +03:00
}
// Display the Intel AMT scanning dialog box
function addAmtScanToMesh(meshid) {
if (xxdialogMode) return;
var x = "Enter a range of IP addresses to scan for Intel AMT devices.<br /><br />";
2017-12-15 01:57:52 +03:00
x += addHtmlValue('IP Range', '<input id=dp1range style=width:184px value="192.168.1.0/24" onkeyup=addAmtScanToMeshKeyUp(event) /><input id=dp1rangebutton type=button value=Scan onclick=addAmtScanToMeshButton()></input>');
2017-08-28 19:27:45 +03:00
x += '<div id=dp1results style="width:100%;height:200px;background-color:white;border:1px gray solid;overflow-y:scroll"></div>';
setDialogMode(2, "Scan for Intel® AMT devices", 3, addAmtScanToMeshEx, x, meshid);
QE('idx_dlgOkButton', false);
QH('dp1results', '<div style=width:100%;text-align:center;margin-top:12px;color:gray;line-height:1.5>Sample IP range values<br />192.168.0.100<br />192.168.1.0/24<br />192.167.0.1-192.168.0.100</div>');
2017-12-15 01:57:52 +03:00
focusTextBox('dp1range');
}
function addAmtScanToMeshKeyUp(e) {
if (e.keyCode == 13) { haltEvent(e); addAmtScanToMeshButton(); }
2017-08-28 19:27:45 +03:00
}
// Called when OK is pressed on the Intel AMT scanning box
function addAmtScanToMeshEx(button, meshid) {
var elements = document.getElementsByClassName("DevScanCheckbox"), checkcount = 0;
2018-08-21 21:02:35 +03:00
for (var i=0;i<elements.length;i++) {
2017-08-28 19:27:45 +03:00
if (elements[i].checked) {
var ipaddr = elements[i].getAttribute('tag');
var amtinfo = amtScanResults[ipaddr];
2018-02-12 04:13:26 +03:00
meshserver.send( { action: 'addamtdevice', meshid: meshid, devicename: ipaddr, hostname: amtinfo.hostname, amtusername: '', amtpassword: '', amttls: amtinfo.tls });
2017-08-28 19:27:45 +03:00
}
}
}
// If the user presses the "Scan" button on the Intel AMT scanning dialog box, start a scan.
function addAmtScanToMeshButton() {
QE('dp1range', false);
QE('dp1rangebutton', false);
QH('dp1results', '<div style=width:100%;text-align:center;margin-top:12px>Scanning...</div>');
2018-02-12 04:13:26 +03:00
meshserver.send( { action: 'scanamtdevice', range: Q('dp1range').value });
2017-08-28 19:27:45 +03:00
}
// Called when a scanned computer is checked or unchecked.
function addAmtScanToMeshCheckbox() {
var elements = document.getElementsByClassName("DevScanCheckbox"), checkcount = 0;
2018-08-21 21:02:35 +03:00
for (var i=0;i<elements.length;i++) { if (elements[i].checked) checkcount++; }
2017-08-28 19:27:45 +03:00
QE('idx_dlgOkButton', checkcount > 0);
}
function addCiraDeviceToMesh(meshid) {
if (xxdialogMode) return;
var mesh = meshes[meshid];
2018-03-31 01:26:36 +03:00
// Replace non alphabetic characters (@ and $) with 'X' because MPS username cannot accept it.
var meshidx = meshid.split('/')[2].replace(/\@/g, 'X').replace(/\$/g, 'X');
2017-09-25 21:00:57 +03:00
var y = '<select id=dlgAddCiraSel onclick=dlgAddCiraSelClick() style=width:230px><option value=0>MeshCommander Script</option><option value=1>Manual Username/Password</option>';
if ((features & 16) == 0) { y += '<option value=2>Manual Certificate</option></select>'; } // Only display this option if Intel AMT CIRA with Mutual-Auth is allowed.
2017-08-28 19:27:45 +03:00
var x = '';
2017-09-25 21:00:57 +03:00
x += addHtmlValue('Setup Method', y);
2017-08-28 19:27:45 +03:00
x += '<hr>';
// Setup CIRA using a MeshCommander script (Pretty Simple)
2019-01-05 04:59:13 +03:00
x += "<div id=dlgAddCira0>To add a new Intel® AMT device to device group \"" + EscapeHtml(mesh.name) + "\" with CIRA, download the following script files and use <a href='http://meshcommander.com' rel='noreferrer noopener' target='_blank'>MeshCommander</a> to run the script to configure computers.<br /><br />";
2019-02-19 03:12:39 +03:00
//x += addHtmlValue('Setup CIRA', '<a href="mescript.ashx?type=1&meshid=' + meshidx.substring(0, 16) + '" rel="noreferrer noopener" target="_blank">cira_setup.mescript</a>');
//x += addHtmlValue('Cleanup CIRA', '<a href="mescript.ashx?type=2" rel="noreferrer noopener" target="_blank">cira_clean.mescript</a>');
x += addHtmlValue('Setup CIRA', '<a style=cursor:pointer onclick=fileDownload("mescript.ashx?type=1&meshid=' + meshidx.substring(0, 16) + '","cira_setup.mescript")>cira_setup.mescript</a>');
x += addHtmlValue('Cleanup CIRA', '<a style=cursor:pointer onclick=fileDownload("mescript.ashx?type=2","cira_clean.mescript")>cira_clean.mescript</a>');
2017-08-28 19:27:45 +03:00
x += "</div>";
// Setup CIRA with user/pass authentication (Somewhat difficult)
2018-09-25 03:47:03 +03:00
x += "<div id=dlgAddCira1 style=display:none>To add a new Intel® AMT device to device group \"" + EscapeHtml(mesh.name) + "\" with CIRA, load the following certificate as trusted root within Intel AMT";
2017-08-28 19:27:45 +03:00
if (serverinfo.mpspass) { x += " and authenticate to the server using this username and password.<br /><br />"; } else { x += " and authenticate to the server using this username and any password.<br /><br />"; }
2019-02-19 03:12:39 +03:00
//x += addHtmlValue('Root Certificate', '<a href="MeshServerRootCert.cer" rel="noreferrer noopener" target="_blank">Root Certificate File</a>');
x += addHtmlValue('Root Certificate', '<a style=cursor:pointer onclick=fileDownload("MeshServerRootCert.cer","MeshServerRootCert.cer")>Root Certificate File</a>');
2017-08-28 19:27:45 +03:00
x += addHtmlValue('Username', '<input style=width:230px readonly value="' + meshidx.substring(0, 16) + '" />');
if (serverinfo.mpspass) { x += addHtmlValue('Password', '<input style=width:230px readonly value="' + EscapeHtml(serverinfo.mpspass) + '" />'); }
2018-03-07 04:50:44 +03:00
if (serverinfo != null) { x += addHtmlValue('MPS Server', '<input style=width:230px readonly value="' + EscapeHtml(serverinfo.mpsname) + ':' + serverinfo.mpsport + '" />'); }
2017-08-28 19:27:45 +03:00
x += "</div>";
2018-11-07 06:41:21 +03:00
// Setup CIRA with certificate authentication (Really difficult, only if TLS offload is not used)
2017-09-25 21:00:57 +03:00
if ((features & 16) == 0) {
2018-09-25 03:47:03 +03:00
x += "<div id=dlgAddCira2 style=display:none>To add a new Intel® AMT device to device group \"" + EscapeHtml(mesh.name) + "\" with CIRA, load the following certificate as trusted root within Intel AMT, authenticate using a client certificate with the following common name and connect to the following server.<br /><br />";
2019-02-19 03:12:39 +03:00
//x += addHtmlValue('Root Certificate', '<a href="MeshServerRootCert.cer" rel="noreferrer noopener" target="_blank">Root Certificate File</a>');
x += addHtmlValue('Root Certificate', '<a style=cursor:pointer onclick=fileDownload("MeshServerRootCert.cer","MeshServerRootCert.cer")>Root Certificate File</a>');
2017-09-25 21:00:57 +03:00
x += addHtmlValue('Organization', '<input style=width:230px readonly value="' + meshidx + '" />');
2018-03-07 04:50:44 +03:00
if (serverinfo != null) { x += addHtmlValue('MPS Server', '<input style=width:230px readonly value="' + EscapeHtml(serverinfo.mpsname) + ':' + serverinfo.mpsport + '" />'); }
2017-09-25 21:00:57 +03:00
x += "</div>";
}
2017-08-28 19:27:45 +03:00
2019-02-19 03:12:39 +03:00
setDialogMode(2, "Add Intel® AMT CIRA device", 2, null, x, 'fileDownload');
2017-08-28 19:27:45 +03:00
}
function dlgAddCiraSelClick() {
var val = Q('dlgAddCiraSel').value;
QV('dlgAddCira0', val == 0);
QV('dlgAddCira1', val == 1);
QV('dlgAddCira2', val == 2);
}
2018-01-24 01:15:59 +03:00
// Return true is the input string looks like an email address
function checkEmail(str) {
var x = str.split('@');
var ok = ((x.length == 2) && (x[0].length > 0) && (x[1].split('.').length > 1) && (x[1].length > 2));
if (ok == true) { var y = x[1].split('.'); for (var i in y) { if (y[i].length == 0) { ok = false; } } }
return ok;
}
function inviteAgentToMesh(meshid) {
if (xxdialogMode) return;
var mesh = meshes[meshid];
var x = "Invite someone to install the mesh agent. An email with be sent with the link to the mesh agent installation for " + EscapeHtml(mesh.name) + ".<br /><br />";
2018-09-06 03:40:00 +03:00
x += addHtmlValue('Name (optional)', '<input id=agentInviteName value="" style=width:230px maxlength=64 />');
x += addHtmlValue('Email', '<input id=agentInviteEmail style=width:230px placeholder="example@email.com" onkeyup=validateAgentInvite()></input>');
2018-11-29 00:51:12 +03:00
x += addHtmlValue('Operating System', '<select id=agentInviteNameOs style=width:236px><option value=0>Any supported</option><option value=1>Windows only</option><option value=3>Apple OSX only</option><option value=2>Linux only</option></select>');
x += addHtmlValue('Installation Type', '<select id=agentInviteType style=width:236px><option value=0>Background and interactive</option><option value=2>Background only</option><option value=1>Interactive only</option></select>');
2018-09-06 03:40:00 +03:00
x += addHtmlValue('Message<br />(optional)', '<textarea id=agentInviteMessage value="" style=width:230px;height:100px;resize:none maxlength=1024 /></textarea>');
setDialogMode(2, "Invite", 3, performAgentInvite, x, meshid);
2018-01-24 01:15:59 +03:00
validateAgentInvite();
}
function validateAgentInvite() {
QE('idx_dlgOkButton', checkEmail(Q('agentInviteEmail').value));
}
function performAgentInvite(button, meshid) {
2018-11-29 00:51:12 +03:00
meshserver.send( { action: 'inviteAgent', meshid: meshid, email: Q('agentInviteEmail').value, name: Q('agentInviteName').value, os: Q('agentInviteNameOs').value, flags: Q('agentInviteType').value, msg: Q('agentInviteMessage').value });
2018-01-24 01:15:59 +03:00
}
2017-08-28 19:27:45 +03:00
function addAgentToMesh(meshid) {
if (xxdialogMode) return;
2018-11-29 00:51:12 +03:00
var mesh = meshes[meshid], x = '', installType = 0;
x += addHtmlValue('Operating System', '<select id=aginsSelect onchange=addAgentToMeshClick() style=width:236px><option value=0>Windows</option><option value=1>Linux</option><option value=2>Apple OSX</option><option value=3>Windows (UnInstall)</option><option value=4>Linux (UnInstall)</option></select>');
x += '<div id=aginsTypeDiv>';
x += addHtmlValue('Installation Type', '<select id=aginsType onchange=addAgentToMeshClick() style=width:236px><option value=0>Background & interactive</option><option value=2>Background only</option><option value=1>Interactive only</option></select>');
x += '</div><hr>';
2017-08-28 19:27:45 +03:00
2019-02-26 01:35:08 +03:00
// \/:*?"<>|
var meshfilename = mesh.name
meshfilename = meshfilename.split('\\').join('').split('/').join('').split(':').join('').split('*').join('').split('?').join('').split('"').join('').split('<').join('').split('>').join('').split('|').join('').split(' ').join('').split('\'').join('');
2017-08-28 19:27:45 +03:00
// Windows agent install
2018-09-25 03:47:03 +03:00
//x += "<div id=agins_windows>To add a new computer to device group \"" + EscapeHtml(mesh.name) + "\", download the mesh agent and configuration file and install the agent on the computer to manage.<br /><br />";
x += "<div id=agins_windows>To add a new computer to device group \"" + EscapeHtml(mesh.name) + "\", download the mesh agent and install it the computer to manage. This agent has server and mesh information embedded within it.<br /><br />";
2019-02-19 02:37:02 +03:00
//x += addHtmlValue('Mesh Agent', '<a id=aginsw32lnk href="meshagents?id=3&meshid=' + meshid.split('/')[2] + '&installflags=0" rel="noreferrer noopener" target="_blank" title="32bit version of the MeshAgent">Windows (.exe)</a>');
//x += addHtmlValue('Mesh Agent', '<a id=aginsw64lnk href="meshagents?id=4&meshid=' + meshid.split('/')[2] + '&installflags=0" rel="noreferrer noopener" target="_blank" title="64bit version of the MeshAgent">Windows x64 (.exe)</a>');
2019-02-26 01:35:08 +03:00
x += addHtmlValue('Mesh Agent', '<a id=aginsw32lnk style=cursor:pointer onclick=fileDownload("meshagents?id=3&meshid=' + meshid.split('/')[2] + '&installflags=","MeshAgent-' + meshfilename + '.exe",1) title="32bit version of the MeshAgent">Windows (.exe)</a>');
x += addHtmlValue('Mesh Agent', '<a id=aginsw64lnk style=cursor:pointer onclick=fileDownload("meshagents?id=4&meshid=' + meshid.split('/')[2] + '&installflags=","MeshAgent-' + meshfilename + '.exe",1) title="64bit version of the MeshAgent">Windows x64 (.exe)</a>');
2019-01-05 04:59:13 +03:00
if (debugmode > 0) { x += addHtmlValue('Settings File', '<a id=aginswmshlnk href="meshsettings?id=' + meshid.split('/')[2] + '&installflags=0" rel="noreferrer noopener" target="_blank">' + EscapeHtml(mesh.name) + ' settings (.msh)</a>'); }
2017-08-28 19:27:45 +03:00
x += "</div>";
// Linux agent install
2018-05-17 01:49:12 +03:00
x += "<div id=agins_linux style=display:none>To add a computer to " + EscapeHtml(mesh.name) + " run the following command. Root credentials will be needed.<br />";
2017-08-28 19:27:45 +03:00
x += '<textarea id=agins_linux_area rows=2 cols=20 readonly=readonly style=width:100%;resize:none;height:120px;overflow:scroll;font-size:12px readonly></textarea>';
x += "</div>";
2018-09-08 03:09:02 +03:00
// OSX agent install
2018-09-25 03:47:03 +03:00
x += "<div id=agins_osx style=display:none>To add a new computer to device group \"" + EscapeHtml(mesh.name) + "\", download the mesh agent and install it the computer to manage. This agent installer has server and mesh information embedded within it.<br /><br />";
2019-01-05 04:59:13 +03:00
x += addHtmlValue('Mesh Agent', '<a href="meshosxagent?id=16&meshid=' + meshid.split('/')[2] + '" rel="noreferrer noopener" target="_blank" title="64bit version of OSX Mesh Agent">OSX Agent (64bit)</a>');
2018-09-08 03:09:02 +03:00
x += "</div>";
2017-08-28 19:27:45 +03:00
// Windows agent uninstall
x += "<div id=agins_windows_un style=display:none>To remove a mesh agent, download the file below, run it and click \"uninstall\".<br /><br />";
2019-02-19 02:37:02 +03:00
//x += addHtmlValue('Mesh Agent', '<a href="meshagents?id=3" rel="noreferrer noopener" target="_blank" title="32bit version of the MeshAgent">Windows (.exe)</a>');
//x += addHtmlValue('Mesh Agent', '<a href="meshagents?id=4" rel="noreferrer noopener" target="_blank" title="64bit version of the MeshAgent">Windows x64 (.exe)</a>');
x += addHtmlValue('Mesh Agent', '<a style=cursor:pointer onclick=fileDownload("meshagents?id=3","MeshAgent.exe") title="32bit version of the MeshAgent">Windows (.exe)</a>');
2019-02-19 03:12:39 +03:00
x += addHtmlValue('Mesh Agent', '<a style=cursor:pointer onclick=fileDownload("meshagents?id=4","MeshAgent.exe") title="64bit version of the MeshAgent">Windows x64 (.exe)</a>');
2017-08-28 19:27:45 +03:00
x += "</div>";
// Linux agent uninstall
2018-05-17 01:49:12 +03:00
x += "<div id=agins_linux_un style=display:none>To remove a mesh agent, run the following command. Root credentials will be needed.<br />";
2017-08-28 19:27:45 +03:00
x += '<textarea id=agins_linux_area_un rows=2 cols=20 readonly=readonly style=width:100%;resize:none;height:120px;overflow:scroll;font-size:12px readonly></textarea>';
x += "</div>";
2019-02-19 03:12:39 +03:00
setDialogMode(2, "Add Mesh Agent", 2, null, x, 'fileDownload');
2018-01-27 02:51:05 +03:00
var servername = serverinfo.name;
if ((servername == 'un-configured') || ((features & 2) != 0)) { servername = window.location.hostname; } // If the server name is not set or it's in LAN-only mode, use the URL hostname as server name.
2017-08-28 19:27:45 +03:00
2019-01-31 00:43:42 +03:00
var noProxy = ((features & 0x2000) != 0)?'--no-proxy ':''; // Server asked that agent be installed to preferably not use a HTTP proxy.
2017-08-28 19:27:45 +03:00
if (serverinfo.https == true) {
2018-03-20 03:31:54 +03:00
var portStr = (serverinfo.port == 443)?'':(":" + serverinfo.port);
2019-01-31 00:43:42 +03:00
Q('agins_linux_area').value = "wget https://" + servername + portStr + "/meshagents?script=1 " + noProxy + "--no-check-certificate -O ./meshinstall.sh && chmod 755 ./meshinstall.sh && sudo ./meshinstall.sh https://" + servername + portStr + " '" + meshid.split('/')[2] + "'\r\n";
Q('agins_linux_area_un').value = "wget https://" + servername + portStr + "/meshagents?script=1 " + noProxy + "--no-check-certificate -O ./meshinstall.sh && chmod 755 ./meshinstall.sh && sudo ./meshinstall.sh uninstall\r\n";
2017-08-28 19:27:45 +03:00
} else {
2018-03-20 03:31:54 +03:00
var portStr = (serverinfo.port == 80)?'':(":" + serverinfo.port);
2019-01-31 00:43:42 +03:00
Q('agins_linux_area').value = "wget http://" + servername + portStr + "/meshagents?script=1 " + noProxy + "-O ./meshinstall.sh && chmod 755 ./meshinstall.sh && sudo ./meshinstall.sh http://" + servername + portStr + " '" + meshid.split('/')[2] + "'\r\n";
Q('agins_linux_area_un').value = "wget http://" + servername + portStr + "/meshagents?script=1 " + noProxy + "-O ./meshinstall.sh && chmod 755 ./meshinstall.sh && sudo ./meshinstall.sh uninstall\r\n";
2017-08-28 19:27:45 +03:00
}
2017-12-15 01:57:52 +03:00
Q('aginsSelect').focus();
2018-11-29 00:51:12 +03:00
addAgentToMeshClick();
2017-08-28 19:27:45 +03:00
}
2019-02-19 02:37:02 +03:00
function fileDownload(path, name, appendFlag) {
var xdr = null, flag = '';
2019-02-19 03:12:39 +03:00
if (appendFlag == 1) {
// Download a agent
flag = Q('aginsType').value;
} else if (appendFlag == 2) {
// Download meshcmd
flag = Q('aginsSelect').value;
if (parseInt(flag) >= 5) { name = name.toLowerCase(); } else { name += '.exe'; }
}
2019-02-19 02:37:02 +03:00
try { xdr = new XDomainRequest(); } catch (e) { }
if (!xdr) xdr = new XMLHttpRequest();
xdr.open("GET", window.location.href + path + flag);
xdr.timeout = 15000;
xdr.responseType = "blob";
2019-02-26 01:35:08 +03:00
xdr.onprogress = function (x) { /*console.log(x);*/ };
2019-02-19 03:12:39 +03:00
xdr.onload = function (e) { saveAs(new Blob([e.target.response], { type: "application/octet-stream" }), name); if (xxdialogTag == 'fileDownload') { setDialogMode(0); } };
xdr.onerror = function () { if (xxdialogTag == 'fileDownload') { setDialogMode(0); } alert('Agent downloads timeout.'); };
xdr.ontimeout = function () { if (xxdialogTag == 'fileDownload') { setDialogMode(0); } alert('Unable to download agent.'); };
2019-02-19 02:37:02 +03:00
xdr.send();
}
2017-08-28 19:27:45 +03:00
function addAgentToMeshClick() {
var v = Q('aginsSelect').value;
QV('agins_windows', v == 0);
QV('agins_linux', v == 1);
2018-09-08 03:09:02 +03:00
QV('agins_osx', v == 2);
QV('agins_windows_un', v == 3);
QV('agins_linux_un', v == 4);
2018-11-29 00:51:12 +03:00
QV('aginsTypeDiv', v == 0);
// Fix the links if needed
2019-02-19 02:37:02 +03:00
//Q('aginsw32lnk').href = (Q('aginsw32lnk').href.split('installflags=')[0]) + 'installflags=' + Q('aginsType').value;
//Q('aginsw64lnk').href = (Q('aginsw64lnk').href.split('installflags=')[0]) + 'installflags=' + Q('aginsType').value;
2018-11-29 00:51:12 +03:00
if (debugmode > 0) { Q('aginswmshlnk').href = (Q('aginswmshlnk').href.split('installflags=')[0]) + 'installflags=' + Q('aginsType').value; }
2017-08-28 19:27:45 +03:00
}
function validateDeviceToMesh() {
QE('idx_dlgOkButton', (Q('dp1devicename').value.length > 0) && (passwordcheck(Q('dp1password').value)));
}
function addDeviceToMeshEx(button, meshid) {
var amtuser = Q('dp1username').value;
if (amtuser == '') amtuser = 'admin';
var host = Q('dp1hostname').value;
if (host == '') host = Q('dp1devicename').value;
2018-02-12 04:13:26 +03:00
meshserver.send( { action: 'addamtdevice', meshid: meshid, devicename: Q('dp1devicename').value, hostname: host, amtusername: amtuser, amtpassword: Q('dp1password').value, amttls: Q('dp1tls').value });
2017-08-28 19:27:45 +03:00
}
function deviceHeaderSet() {
if (deviceHeaderId == 0) { deviceHeaderId = 1; return; }
deviceHeaders["DevxHeader" + deviceHeaderId] = ', ' + deviceHeaderTotal + ((deviceHeaderTotal == 1) ? ' node' : ' nodes');
2018-08-24 02:55:06 +03:00
//var title = '';
//for (x in deviceHeaderCount) { if (title.length > 0) title += ', '; title += deviceHeaderCount[x] + ' ' + PowerStateStr2(x); }
//deviceHeadersTitles["DevxHeader" + deviceHeaderId] = title;
2017-08-28 19:27:45 +03:00
deviceHeaderId++;
deviceHeaderCount = { };
deviceHeaderTotal = 0;
}
var powerStateStrings = ['', '<span title="Device is powered on.">Powered</span>', '<span title="Device is in sleep state (S1).">Sleeping</span>', '<span title="Device is in sleep state (S2).">Sleeping</span>', '<span title="Device is in deep sleep state (S3).">Deep Sleep</span>', '<span title="Device is in hibernating state (S4).">Hibernating</span>', '<span title="Device is in powered off state (S5).">Soft-Off</span>', '<span title="Device is detected but power state could not be obtained.">Present</span>'];
var powerStateStrings2 = ['', 'Device is powered', 'Device is in sleep state (S1)', 'Device is in sleep state (S2)', 'Device is in deep sleep state (S3)', 'Device is hibernating (S4)', 'Device is in soft-off state (S5)', 'Device is present, but power state cannot be determined'];
var powerColorTable = ['#00000000', 'black', 'blue', 'blue', 'lightblue', 'blueviolet', 'darkgreen', 'lightseagreen', 'lightseagreen'];
function NodeStateStr(node) {
var states = [];
if (node.state > 0 && node.state < powerStatetable.length) state.push(powerStatetable[node.state]);
if (node.conn) {
if ((node.conn & 1) != 0) states.push('<span title="Mesh agent is connected and ready for use.">Agent</span>');
if ((node.conn & 2) != 0) states.push('<span title="Intel® AMT CIRA is connected and ready for use.">CIRA</span>');
if ((node.conn & 4) != 0) states.push('<span title="Intel® AMT is routable.">Intel® AMT</span>');
if ((node.conn & 8) != 0) states.push('<span title="Mesh agent is reachable using another agent as relay.">Relay</span>');
}
2017-12-14 01:52:57 +03:00
if ((node.pwr != null) && (node.pwr != 0)) { states.push(powerStateStrings[node.pwr]); }
2017-08-28 19:27:45 +03:00
return states.join(', ');
}
function PowerStateStr(x) {
if (x < powerStatetable.length) return powerStatetable[x];
return '';
}
function PowerStateStr2(x) {
if ((x != 0) && (x < powerStatetable.length)) return powerStatetable[x];
return 'Unknown';
}
function selectallButtonFunction() {
var elements = document.getElementsByClassName("DeviceCheckbox"), checkcount = 0;
2018-08-21 21:02:35 +03:00
for (var i=0;i<elements.length;i++) { if (elements[i].checked === true) checkcount++; }
for (var i=0;i<elements.length;i++) { elements[i].checked = (checkcount == 0); }
2017-08-28 19:27:45 +03:00
p1updateInfo();
}
function p1updateInfo() {
var elements = document.getElementsByClassName("DeviceCheckbox"), checkcount = 0;
2018-08-21 21:02:35 +03:00
for (var i=0;i<elements.length;i++) { if (elements[i].checked === true) { checkcount++; } }
2017-08-28 19:27:45 +03:00
if (checkcount > 0) {
QE('GroupActionButton', true);
Q('SelectAllButton').value = 'Select None';
QV('cxmgroupsplit', true);
QV('cxmdesktop', true);
} else {
QE('GroupActionButton', false);
Q('SelectAllButton').value = 'Select All';
QV('cxmgroupsplit', false);
QV('cxmdesktop', false);
}
}
function groupActionFunction() {
2017-09-01 21:23:22 +03:00
var x = "Select an operation to perform on all selected devices. Actions will be performed only with proper rights.<br /><br />";
2019-02-20 02:38:27 +03:00
x += addHtmlValue('Operation', '<select id=d2groupop style=float:right;width:250px><option value=100>Wake-up devices</option><option value=4>Sleep devices</option><option value=3>Reset devices</option><option value=2>Power off devices</option><option value=102>Move to device group</option><option value=101>Delete devices</option></select>');
2017-08-28 19:27:45 +03:00
setDialogMode(2, "Group Action", 3, groupActionFunctionEx, x);
}
2018-05-01 21:42:20 +03:00
// Get the list of checked devices, removes any duplicates.
function getCheckedDevices() {
var nodeids = [], elements = document.getElementsByClassName("DeviceCheckbox"), checkcount = 0;
2018-08-21 21:02:35 +03:00
for (var i=0;i<elements.length;i++) { if (elements[i].checked) { if (elements[i].value) { var nid = elements[i].value.substring(6); if (nodeids.indexOf(nid) == -1) { nodeids.push(nid); } } } }
2018-05-01 21:42:20 +03:00
return nodeids;
}
2017-08-28 19:27:45 +03:00
function groupActionFunctionEx() {
var op = Q('d2groupop').value;
2017-09-01 21:23:22 +03:00
if (op == 100) {
2017-08-28 19:27:45 +03:00
// Group wake
2018-05-01 21:42:20 +03:00
meshserver.send( { action: 'wakedevices', nodeids: getCheckedDevices() });
2017-09-01 21:23:22 +03:00
} else if (op == 101) {
2017-08-28 19:27:45 +03:00
// Group delete, ask for confirmation
var x = "Confirm delete selected devices(s)?<br /><br />";
2019-02-20 02:51:38 +03:00
x += "<label><input id=d2check type=checkbox onchange=d2groupActionFunctionDelEx() />Confirm</label>";
2017-08-28 19:27:45 +03:00
setDialogMode(2, "Delete Nodes", 3, groupActionFunctionDelEx, x);
QE('idx_dlgOkButton', false);
2019-02-19 04:50:10 +03:00
} else if (op == 102) {
// Move computers to a different group
p10showChangeGroupDialog(getCheckedDevices());
2017-09-01 21:23:22 +03:00
} else {
// Power operation
2018-05-01 21:42:20 +03:00
meshserver.send( { action: 'poweraction', nodeids: getCheckedDevices(), actiontype: op });
2017-08-28 19:27:45 +03:00
}
}
function d2groupActionFunctionDelEx() { QE('idx_dlgOkButton', Q('d2check').checked); }
2018-05-01 21:42:20 +03:00
function groupActionFunctionDelEx() { meshserver.send( { action: 'removedevices', nodeids: getCheckedDevices() }); }
2017-08-28 19:27:45 +03:00
function onSortSelectChange(skipsave) {
sort = document.getElementById("sortselect").selectedIndex;
if (!skipsave) { putstore("sort", sort); }
}
2018-05-22 02:36:51 +03:00
function meshSort(a, b) { if (a.meshnamel > b.meshnamel) return 1; if (a.meshnamel < b.meshnamel) return -1; if (a.meshid == b.meshid) { if (showRealNames == true) { if (a.rnamel > b.rnamel) return 1; if (a.rnamel < b.rnamel) return -1; return 0; } else { if (a.namel > b.namel) return 1; if (a.namel < b.namel) return -1; return 0; } } return 0; }
2018-08-21 21:02:35 +03:00
function powerSort(a, b) { var ap = a.pwr?a.pwr:0; var bp = b.pwr?b.pwr:0; if (ap > bp) return -1; if (ap < bp) return 1; if (ap == bp) { if (showRealNames == true) { if (a.rnamel > b.rnamel) return 1; if (a.rnamel < b.rnamel) return -1; return 0; } else { if (a.namel > b.namel) return 1; if (a.namel < b.namel) return -1; return 0; } } return 0; }
2017-08-28 19:27:45 +03:00
function deviceSort(a, b) { if (a.namel > b.namel) return 1; if (a.namel < b.namel) return -1; return 0; }
2018-05-22 02:36:51 +03:00
function deviceHostSort(a, b) { if (a.rnamel > b.rnamel) return 1; if (a.rnamel < b.rnamel) return -1; return 0; }
2017-08-28 19:27:45 +03:00
function onSearchFocus(x) { searchFocus = x; }
2017-08-30 00:34:13 +03:00
function onMapSearchFocus(x) { mapSearchFocus = x; }
2018-07-17 03:49:55 +03:00
function onUserSearchFocus(x) { userSearchFocus = x; }
2017-08-28 19:27:45 +03:00
function onConsoleFocus(x) { consoleFocus = x; }
2018-05-01 23:44:26 +03:00
function onSearchInputChanged() {
2018-05-03 02:19:45 +03:00
var x = Q('SearchInput').value.toLowerCase().trim(); putstore("search", x);
if (x == '') {
for (var d in nodes) { nodes[d].v = true; }
} else {
2018-07-03 00:34:10 +03:00
try {
var rs = x.split(/\s+/).join('|'), rx = new RegExp(rs); // In some cases (like +), this can throw an exception.
for (var d in nodes) {
nodes[d].v = (rx.test(nodes[d].name.toLowerCase())) || (nodes[d].rnamel != null && rx.test(nodes[d].rnamel.toLowerCase()));
if ((nodes[d].v == false) && nodes[d].tags) {
for (var s in nodes[d].tags) {
if (rx.test(nodes[d].tags[s].toLowerCase())) {
nodes[d].v = true;
break;
} else {
nodes[d].v = false;
}
2018-05-03 02:19:45 +03:00
}
}
}
2018-07-03 00:34:10 +03:00
} catch (ex) { for (var d in nodes) { nodes[d].v = true; } }
2018-05-01 23:44:26 +03:00
}
}
2017-08-28 19:27:45 +03:00
var contextelement = null;
function handleContextMenu(event) {
hideContextMenu();
2017-12-14 01:52:57 +03:00
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;
2017-08-28 19:27:45 +03:00
var elem = document.elementFromPoint(event.pageX - scrollLeft, event.pageY - scrollTop);
if (elem && elem != null && elem.id == "MxMESH") {
contextelement = elem;
var contextmenudiv = document.getElementById("meshContextMenu");
contextmenudiv.style.left = event.pageX + "px";
contextmenudiv.style.top = event.pageY + "px";
contextmenudiv.style.display = "block";
} else {
while (elem && elem != null && elem.id != "devs") { elem = elem.parentElement; }
if (!elem || elem == null) return true;
contextelement = elem;
var contextmenudiv = document.getElementById("contextMenu");
contextmenudiv.style.left = event.pageX + "px";
contextmenudiv.style.top = event.pageY + "px";
contextmenudiv.style.display = "block";
}
2018-09-19 20:37:19 +03:00
// Get the node and set the menu options
var nodeid = contextelement.children[1].attributes.onclick.value;
2019-01-30 01:08:29 +03:00
var node = getNodeFromId(nodeid.substring(12, nodeid.length - 18));
2018-09-19 20:37:19 +03:00
var mesh = meshes[node.meshid];
var meshlinks = mesh.links['user/' + domain + '/' + userinfo.name.toLowerCase()];
var meshrights = meshlinks.rights;
var consoleRights = ((meshrights & 16) != 0);
2019-02-27 04:08:55 +03:00
// Check if we have terminal and file access
var terminalAccess = ((meshrights == 0xFFFFFFFF) || ((meshrights & 512) == 0));
var fileAccess = ((meshrights == 0xFFFFFFFF) || ((meshrights & 1024) == 0));
2018-11-03 04:13:32 +03:00
QV('cxdesktop', ((mesh.mtype == 1) || (node.agent == null) || (node.agent.caps == null) || ((node.agent.caps & 1) != 0) || (node.intelamt && (node.intelamt.state == 2))) && ((meshrights & 8) || (meshrights & 256)));
2019-02-27 04:08:55 +03:00
QV('cxterminal', ((mesh.mtype == 1) || (node.agent == null) || (node.agent.caps == null) || ((node.agent.caps & 2) != 0) || (node.intelamt && (node.intelamt.state == 2))) && (meshrights & 8) && terminalAccess);
QV('cxfiles', ((mesh.mtype == 2) && ((node.agent == null) || (node.agent.caps == null) || ((node.agent.caps & 4) != 0))) && (meshrights & 8) && fileAccess);
2018-09-19 20:37:19 +03:00
QV('cxevents', (node.intelamt != null) && ((node.intelamt.state == 2) || (node.conn & 2)) && (meshrights & 8));
QV('cxconsole', (consoleRights && (mesh.mtype == 2) && ((node.agent == null) || (node.agent.caps == null) || ((node.agent.caps & 8) != 0))) && (meshrights & 8));
2017-08-28 19:27:45 +03:00
return haltEvent(event);
}
2019-01-30 01:08:29 +03:00
function cmaction(action,event) {
2017-08-28 19:27:45 +03:00
var nodeid = contextelement.children[1].attributes.onclick.value;
2019-01-30 01:08:29 +03:00
nodeid = nodeid.substring(12, nodeid.length - 18);
2018-04-17 01:37:41 +03:00
if (action == 7) { Q('viewselect').value = 3; Q('viewselect').onchange(); Q('autoConnectDesktopCheckbox').checked = true; Q('autoConnectDesktopCheckbox').onclick(); } // Multi-Desktop
2019-01-30 01:08:29 +03:00
if ((action > 0) && (action < 7)) {
var panel = [0, 10, 12, 11, 13, 16, 15][action]; // (invalid), General, Desktop, Terminal, Files, Events, Console
if (event && (event.shiftKey == true)) {
// Open the device in a different tab
window.open(window.location.origin + '?node=' + nodeid.split('/')[2] + '&viewmode=' + panel + '&hide=16', 'meshcentral:' + nodeid);
} else {
// Go to the right panel
gotoDevice(nodeid, panel);
}
}
2017-08-28 19:27:45 +03:00
}
function cmmeshaction(action) {
var meshid = contextelement.attributes.onclick.value.substring(32, (32 + 69));
var elements = document.getElementsByClassName("DeviceCheckbox");
2018-08-24 02:55:06 +03:00
if (action == 1) { for (var i = 0; i < elements.length; i++) { if ( (elements[i].attributes) && (elements[i].attributes['class']['value'].substring(0, 69) == meshid)) { elements[i].checked = true; } } }
if (action == 2) { for (var i = 0; i < elements.length; i++) { if ( (elements[i].attributes) && (elements[i].attributes['class']['value'].substring(0, 69) == meshid)) { elements[i].checked = false; } } }
2017-08-28 19:27:45 +03:00
//if (action == 3) { window.location = "multidesktop.aspx?mesh=" + meshid + "&auto=1"; }
p1updateInfo();
}
function hideContextMenu() {
QV('contextMenu', false);
QV('meshContextMenu', false);
contextelement = null;
}
2017-08-30 00:34:13 +03:00
//
// DEVICES MAP
//
// Maps code starts from here. Initialize all the variables
var xxmap = {
map: null,
contextmenu: null,
activeInteractions: [], // Save Modified features in this list
showindex: 0,
markersSource: null, // Initialize a Source Vector
markersLayer: null,
mapLayer: null, // Create a tile and use OSM source
mapView: null, // Sets the initial view
}
// Add a feature for every Node and change style if connection status changes
function updateMapMarkers(selectedMesh) {
2018-08-24 02:55:06 +03:00
if ((xxmap != null) && (xxmap.map == null)) { try { loadmap(); } catch (ex) { console.error('loadmap() exception', ex); } }
2017-09-07 21:16:51 +03:00
if (xxmap == null) return;
2017-08-30 00:34:13 +03:00
var boundingBox = null;
for (var i in nodes) {
2018-08-24 02:55:06 +03:00
try {
2018-08-30 22:05:23 +03:00
var loc = map_parseNodeLoc(nodes[i]), feature = xxmap.markersSource.getFeatureById(nodes[i]._id);
if ((loc != null) && ((nodes[i].meshid == selectedMesh) || (selectedMesh == null))) { // Draw markers for devices with locations
2018-08-30 03:40:30 +03:00
var lat = loc[0], lon = loc[1], type = loc[2];
2018-08-24 02:55:06 +03:00
if (boundingBox == null) { boundingBox = [ lat, lon, lat, lon, 0 ]; } else { if (lat < boundingBox[0]) { boundingBox[0] = lat; } if (lon < boundingBox[1]) { boundingBox[1] = lon; } if (lat > boundingBox[2]) { boundingBox[2] = lat; } if (lon > boundingBox[3]) { boundingBox[3] = lon; } }
if (feature == null) { addFeature(nodes[i]); boundingBox[4] = 1; } else { updateFeature(nodes[i], feature); feature.setStyle(markerStyle(nodes[i], loc[2])); } // Update Feature
} else {
if (feature) { xxmap.markersSource.removeFeature(feature); }
}
} catch (ex) { console.error('updateMapMarkers() exception', ex, JSON.stringify(nodes[i])); }
2017-08-30 00:34:13 +03:00
}
return boundingBox;
}
// Show node details on hovering over a feature
var map_cm_popup = new ol.Overlay( { element: Q('xmap-info-window'), positioning: 'bottom-center', stopEvent: false });
// Edit Marker item
2017-09-26 01:28:52 +03:00
var map_cm_editMarker = { text: "Modify node location", callback: function (obj) { modifyMarkerloc(obj.data); } };
// Clear Marker item
var map_cm_clearMarker = { text: "Remove node location", callback: function (obj) {
2018-02-12 04:13:26 +03:00
meshserver.send( { action: 'changedevice', nodeid: obj.data.a, userloc: [] }); // Clear the user position marker
2017-09-26 01:28:52 +03:00
}};
2017-08-30 00:34:13 +03:00
// Save Marker item
2017-09-26 01:28:52 +03:00
var map_cm_saveMarker = { text: "Save node location", callback: function (obj) { saveMarkerloc(obj.data); } };
2017-08-30 00:34:13 +03:00
// Build a context menu for a feature
var map_cm_nodemenu_items = [
{ text: "General information", callback: function (obj) { if (obj.data !=null) { gotoDevice(obj.data, 10); } } },
{ text: "Desktop", callback: function (obj) { if (obj.data !=null) { gotoDevice(obj.data, 11); } } },
{ text: "Terminal", callback: function (obj) { if (obj.data !=null) { gotoDevice(obj.data, 12); } } },
{ text: "Intel® AMT", callback: function (obj) { if (obj.data !=null) { gotoDevice(obj.data, 14); } } },
'-',
{ text: 'Zoom-in to extent', callback: function(obj) { var coords = obj.data.getGeometry().getCoordinates(); zoomToLocation(coords, 19); } },
{ text: 'Zoom-out to extent', callback: function(obj) { var coords = obj.data.getGeometry().getCoordinates(); zoomToLocation(coords, 2); } }
];
// Context menu for clicks other than on feature
var contextmenu_items = [
2017-10-24 00:09:58 +03:00
{ text: 'Refresh', callback: function () { refreshMap(true, true); } },
{ text: 'Zoom to fit extent', callback: function () { zoomToFitExtent(); } },
{ text: 'Center map here', callback: function(obj) { xxmap.mapView.animate( { center: obj.coordinate } ); } },
{ text: 'Place node here', callback: function(obj) { placeNode(obj.coordinate); } }
2017-08-30 00:34:13 +03:00
];
function stringToIntHash(str) {
var hash = 0, i;
for (i = 0; i < str.length; i++) { hash = ((hash << 5) - hash) + str.charCodeAt(i); hash |= 0; }
return hash;
};
// Get the lat/lon from a node
function map_parseNodeLoc(node) {
2017-09-26 01:28:52 +03:00
var loc = null, t = 0;
if (node.iploc) { loc = node.iploc; t = 1; }
if (node.wifiloc) { loc = node.wifiloc; t = 2; }
if (node.gpsloc) { loc = node.gpsloc; t = 3; }
if (node.userloc) { loc = node.userloc; t = 4; }
2018-08-30 22:05:23 +03:00
if ((loc == null) || (typeof loc != 'string')) return null;
2017-09-26 01:28:52 +03:00
loc = loc.split(',');
2017-09-27 22:43:20 +03:00
if (t == 1) {
// If this is IP location, randomize the position a little.
return [ parseFloat(loc[0]) + (stringToIntHash(node._id.substring(0, 20)) / 100000000000), parseFloat(loc[1]) + (stringToIntHash(node._id.substring(20)) / 100000000000), t ];
} else {
// Return the real position
return [ parseFloat(loc[0]), parseFloat(loc[1]), t ];
}
2017-08-30 00:34:13 +03:00
}
// Load the entire map
function loadmap() {
2017-09-07 21:16:51 +03:00
if (xxmap == null) return;
2019-02-27 03:26:33 +03:00
if ((features & 0x8000) == 0) { QV('viewselectmapoption', false); QV('devViewButton4', false); xxmap = null; return; } // Geolocation not supported
2017-09-07 21:16:51 +03:00
try {
// Initialize a Source Vector
xxmap.markersSource = new ol.source.Vector();
xxmap.markersLayer = new ol.layer.Vector( {
source: xxmap.markersSource
});
// Create a tile and use OSM source
xxmap.mapLayer = new ol.layer.Tile( { source: new ol.source.OSM() });
xxmap.mapView = new ol.View( { // Set the initial view
center: ol.proj.transform([0, 0], 'EPSG:4326', 'EPSG:3857'),
zoom: 2,
minZoom: 2,
maxZoom: 20,
extent: ol.proj.transformExtent([-100000, -69.55, 100000, 69.55], 'EPSG:4326', 'EPSG:3857')
});
xxmap.map = new ol.Map( {
target: 'xdevicesmap',
layers: [xxmap.mapLayer, xxmap.markersLayer],
view: xxmap.mapView
});
xxmap.map.addOverlay(map_cm_popup);
// Goto information tab if a user clicks on a feature
xxmap.map.on('click', function(evt) {
var feature = xxmap.map.forEachFeatureAtPixel(evt.pixel, function(feat, layer) { return feat; });
if (feature) {
var nodeid = feature.getId();
2017-12-14 01:52:57 +03:00
if (nodeid != null) { gotoDevice(nodeid, 10); } // Goto general info tab
2017-09-07 21:16:51 +03:00
else { // For pointer
var nodeFeatgoto = getCorrespondingFeature(feature); gotoDevice(nodeFeatgoto.getId(), 10);
}
2017-08-30 00:34:13 +03:00
}
2017-09-07 21:16:51 +03:00
});
// On hover feature show the name of the node. Also add pointer style
xxmap.map.on('pointermove', function(evt) {
var feature = xxmap.map.forEachFeatureAtPixel(evt.pixel, function(feat, layer) { return feat; });
if (feature) {
xxmap.map.getTargetElement().style.cursor = 'pointer';
var coord = feature.getGeometry().getCoordinates();
// map_cm_popup.setPosition(evt.coordinate);
map_cm_popup.setPosition(coord);
2018-08-30 03:40:30 +03:00
var featid = feature.getId();
2017-09-07 21:16:51 +03:00
if (featid) {
QH('xmap-info-window', feature.get('name'));
} else {
var nodeFeat = getCorrespondingFeature(feature); // Return the node feature associated to pointer.
QH('xmap-info-window', nodeFeat.get('name'));
}
2017-08-30 00:34:13 +03:00
} else {
2017-09-07 21:16:51 +03:00
xxmap.map.getTargetElement().style.cursor = '';
QH('xmap-info-window', '');
2017-08-30 00:34:13 +03:00
}
2017-09-07 21:16:51 +03:00
});
// Initialize context menu for openlayers
2018-08-30 03:40:30 +03:00
var contextmenu = new ContextMenu( {
2017-09-07 21:16:51 +03:00
width: 160,
defaultItems: false, // defaultItems are Zoom In/Zoom Out
items: contextmenu_items
});
2017-09-30 00:20:08 +03:00
2017-09-07 21:16:51 +03:00
// On right click open the context menu
contextmenu.on("open", function (evt) {
var feature = xxmap.map.forEachFeatureAtPixel(evt.pixel, function(ft, l) { return ft; });
xxmap.contextmenu.clear(); //Clear the context menu
if (feature) {
2017-09-26 01:28:52 +03:00
var featId = feature.getId();
if (featId) { addContextMenuItems(feature); } // Node feature will have an id
2017-09-07 21:16:51 +03:00
else { // If the feature is a pointer, Get its corresponding Node feature
2017-09-26 01:28:52 +03:00
var nodeFeature = getCorrespondingFeature(feature); //return the node feature associated to pointer.
2017-09-07 21:16:51 +03:00
if (nodeFeature) { addContextMenuItems(nodeFeature); }
else { xxmap.contextmenu.extend(contextmenu_items); }
}
2017-08-30 00:34:13 +03:00
}
2017-09-07 21:16:51 +03:00
else { xxmap.contextmenu.extend(contextmenu_items); }
});
2017-09-26 01:28:52 +03:00
if (xxmap.contextmenu == null) { xxmap.contextmenu = contextmenu; }
2017-09-07 21:16:51 +03:00
xxmap.map.addControl(xxmap.contextmenu);
//addMeshOptions(); // Adds Mesh names to mesh dropdown
2018-08-30 03:40:30 +03:00
} catch (ex) {
console.log(ex);
2017-09-07 21:16:51 +03:00
QV('viewselectmapoption', false);
2018-10-11 23:29:50 +03:00
QV('devViewButton4', false);
2017-09-07 21:16:51 +03:00
xxmap = null;
}
2017-08-30 00:34:13 +03:00
}
// Add feature on to Map for a Node
2017-09-26 01:28:52 +03:00
function addFeature(node, lat, lon) {
2017-08-30 00:34:13 +03:00
var existingfeature = getModifiedFeature(node._id); // Check if Corresponding feature was Modified ( Modifed feature are in active interactions list)
if (existingfeature) { xxmap.markersSource.addFeature(existingfeature); } // Add that existing feature
else { // Add new feature for this node
if (!lat && !lon) { var loc = map_parseNodeLoc(node); lat = loc[0]; lon = loc[1]; }
2018-08-24 02:55:06 +03:00
2018-04-07 01:56:45 +03:00
// Fix the longiture and send an event to patch the db to correct coordinate format. It will cause second unnecessary updateFeature on this node to the map.
if (lon > 180) { lon = 180 - lon; meshserver.send( { action: 'changedevice', nodeid: node._id, userloc: [ lat, lon ] }); }
2017-09-26 01:28:52 +03:00
if ((lat < 90) && (lat > -90) && (lon < 180) && (lon > -180)) { // Check valid lat/lon
var feature = new ol.Feature( { geometry: new ol.geom.Point(ol.proj.transform([lon, lat], 'EPSG:4326','EPSG:3857')), name: node.name, status: node.conn, lat: lat, lon: lon });
feature.setId(node._id); // Set id for the device as nodeid
feature.setStyle(markerStyle(node));
xxmap.markersSource.addFeature(feature); // Add the feature to Marker Source
}
2017-08-30 00:34:13 +03:00
}
}
// Removing any feature from map
function removeFeature(node) {
2017-09-26 01:28:52 +03:00
var feature = xxmap.markersSource.getFeatureById(node._id);
if (feature) { xxmap.markersSource.removeFeature(feature); }
2017-08-30 00:34:13 +03:00
}
// Update feature
function updateFeature(node, feature) {
if (node.conn != feature.get('status') ) { // Update status if changed
feature.set('status',node.conn)
feature.setStyle(markerStyle(node));
}
// Since this is IP address location, add some fixed randomness to the location. Avoid pin pile-up.
2018-08-30 22:05:23 +03:00
var loc = map_parseNodeLoc(node);
if (loc != null) {
var lat = loc[0], lon = loc[1];
if ((lat != feature.get('lat')) || (lon != feature.get('lon'))) { // Update lat and lon if changed
feature.set('lat', lat); feature.set('lon', lon);
var modifiedCoordinates = ol.proj.transform([parseFloat(lon), parseFloat(lat)], 'EPSG:4326', 'EPSG:3857');
feature.getGeometry().setCoordinates(modifiedCoordinates);
}
2017-08-30 00:34:13 +03:00
}
if (node.name != feature.get('name') ) { feature.set('name', node.name); } // Update name
}
// Enable dragging of a marker after edit option is clicked in context menu
function modifyMarkerloc(ft) {
var featid = ft.getId();
if (featid) {
2017-09-26 01:28:52 +03:00
ft.setStyle(markerStyle(getNodeFromId(ft.a), 4)); // Switch to a user marker
2017-08-30 00:34:13 +03:00
if ( !getActiveInteractions(ft)) {
var dragInteration = new ol.interaction.Modify( {
features: new ol.Collection([ft]),
pixelTolerance: 10
});
xxmap.activeInteractions.push( { featureid: featid, feature:ft, interaction: dragInteration }); // Also keep track of Interactions
xxmap.map.addInteraction(dragInteration);
}
}
}
// This will be called when save location option is clicked in context menu
function saveMarkerloc(ft) {
var featid = ft.getId()
if (featid) {
var actInteraction = getActiveInteractions(ft);
if (actInteraction) { // Check if the interaction exists
xxmap.map.removeInteraction(actInteraction); //Clear Interaction for that node
removeInteraction(featid);
var coord = ft.getGeometry().getCoordinates();
var v = ol.proj.transform(coord, 'EPSG:3857', 'EPSG:4326');
2018-04-07 01:56:45 +03:00
if (v[0] > 180) { v[0] = 180 - v[0]; }
2017-09-26 01:28:52 +03:00
var vx = [ v[1], v[0] ]; // Flip the coordinates around, lat/long
2018-02-12 04:13:26 +03:00
meshserver.send( { action: 'changedevice', nodeid: featid, userloc: vx }); // Send them to server to save changes
2017-08-30 00:34:13 +03:00
}
}
}
// Style the Markers
2017-09-26 01:28:52 +03:00
function markerStyle(node, type) {
if (type == null) {
type = 0;
if (node.iploc) { type = 1; }
if (node.wifiloc) { type = 2; }
if (node.gpsloc) { type = 3; }
if (node.userloc) { type = 4; }
}
var types = ['', '-ip','-wifi','-gps','-user'];
2017-08-30 00:34:13 +03:00
var color = connStateColor(node);
var style = new ol.style.Style( {
2017-09-26 01:28:52 +03:00
image: new ol.style.Icon( { color: color, anchor: [0.5, 1], src: 'images/mapmarker' + types[type] + '.png' })
2017-08-30 00:34:13 +03:00
//stroke: new ol.style.Stroke( { color: '#000', width: 20 })
//text: new ol.style.Text( { text: 'bob!', textAlign: 'right', offsetX: -10, fill: new ol.style.Fill( { color: '#000' }), stroke: new ol.style.Stroke( { color: '#fff', width: 2 }) })
});
/*
deviceMark.setStyle(new ol.style.Style( {
text: new ol.style.Text( {
//font: '12px helvetica,sans-serif',
text: currentNode.name,
textAlign: 'right',
offsetX: -10,
fill: new ol.style.Fill( { color: '#000' }),
stroke: new ol.style.Stroke( { color: '#fff', width: 2 })
}),
image: new ol.style.Icon(( { color: [113, 140, 0], src: 'images/dot.png' })) }));
*/
return [ style ];
}
// TODO: Add more connection status types. Currently we only change color if connection status changes
function connStateColor(nodeConn) {
2018-05-03 02:19:45 +03:00
if (nodeConn.conn == 1 || nodeConn.conn == 3 || nodeConn.conn == 5) { return '#00ffdd'; } // Green for connected devices
2017-08-30 00:34:13 +03:00
return '#C70039'; // Red if the Agent is not connected
}
// Add save/edit option to context menu
function addContextMenuItems(feature) {
if (getActiveInteractions(feature)) { // If this feature is modified then display save option in contextmenu
map_cm_saveMarker.data = feature;
xxmap.contextmenu.push(map_cm_saveMarker);
} else {
map_cm_editMarker.data = feature;
xxmap.contextmenu.push(map_cm_editMarker);
2017-09-26 01:28:52 +03:00
var node = getNodeFromId(feature.a);
if (node.userloc) {
map_cm_clearMarker.data = feature;
xxmap.contextmenu.push(map_cm_clearMarker);
}
2017-08-30 00:34:13 +03:00
}
map_cm_nodemenu_items.forEach(function (item) {
if (item.text == 'Zoom-in to extent' || item.text == 'Zoom-out to extent') { item.data = feature; }
2018-09-17 23:44:14 +03:00
else { if (item != "-") { item.data = feature.getId(); } }
2017-08-30 00:34:13 +03:00
});
xxmap.contextmenu.extend(map_cm_nodemenu_items);
}
// Return a active Interaction if it exists in activeInteractions list
function getActiveInteractions(feature) {
var featid = feature.getId();
for (var i = 0; i < xxmap.activeInteractions.length; i++) {
if (xxmap.activeInteractions[i].featureid == featid) { return xxmap.activeInteractions[i].interaction; }
}
return false;
}
// Return Modified feature based on Id
function getModifiedFeature(featid) {
if (featid) {
for (var i = 0; i < xxmap.activeInteractions.length; i++) {
if (xxmap.activeInteractions[i].featureid == featid) { return xxmap.activeInteractions[i].feature; }
}
}
return null;
}
// Remove Interaction
function removeInteraction(ftid) {
var index = -1;
for (var i = 0; i < xxmap.activeInteractions.length; i++) {
if (xxmap.activeInteractions[i].featureid === ftid) { index = i; break; }
}
if (index >= 0) { xxmap.activeInteractions.splice(index, 1); }
}
// Check if pointer coordinates are equal to features and return node feature
function getCorrespondingFeature(pointerFeat) {
var pointerCoord = pointerFeat.getGeometry().getCoordinates();
for (var i = 0; i < xxmap.activeInteractions.length ; i++) {
var modifiedFeatures = xxmap.activeInteractions[i].feature;
var fearCoord = modifiedFeatures.getGeometry().getCoordinates();
if (fearCoord[0].toFixed(5) == pointerCoord[0].toFixed(5) && fearCoord[1].toFixed(5) == pointerCoord[1].toFixed(5) ) { return modifiedFeatures; }
}
return null;
}
// Refresh the map and clear list
function refreshMap(reset, rebound) {
if (reset) {
xxmap.map.setTarget(null);
xxmap.map = null;
xxmap.markersSource = null;
xxmap.mapView = null;
xxmap.mapLayer = null;
xxmap.activeInteractions = []; // Clear Active Interaction list
}
//clearMeshOptions();
//onSelectMeshChange();
var box = updateMapMarkers();
if ((box != null) && (rebound || (box[4] == 1))) {
var clat = (box[0] + box[2]) / 2;
var clon = (box[1] + box[3]) / 2;
var cscale = Math.max(Math.abs(box[0] - box[2]), Math.abs(box[1] - box[3]));
var view = xxmap.map.getView();
view.setCenter(ol.proj.transform([clon, clat], 'EPSG:4326', 'EPSG:3857'));
var i = 360, j = -2;
while (i > cscale) { j++; i = i / 2; }
view.setZoom(j);
}
}
// Called When Place a node option is clicked from context menu
function placeNode(coords) {
if (xxdialogMode) return;
2017-09-30 03:55:36 +03:00
var x = '<div style=margin-bottom:6px><label for=selectnode-search>Search</label>  <input type=text placeholder="Device name" id="selectnode-search" onchange=onPlaceNodeInputChange() onkeyup=onPlaceNodeInputChange() autocomplete=off style=width:120px></div><div id=placenode style="height:254px;overflow-y:auto;width:100%;margin:12px 1px 4px 1px;"><div id=noNodesMapPlace style=text-align:center;width:100%;display:none>No devices found.</div>';
for (var i in nodes) {
x += '<div class=noselect id=' + nodes[i]._id + '-rowid onclick=selectNodeToPlace(event,\''+ nodes[i]._id +'\') style=background-color:lightgray;margin-bottom:4px;border-radius:2px><input name=PlaceMapDeviceCheckbox id=' + nodes[i]._id + '-checkid type=checkbox style=width:16px;display:inline />';
x += '<div class=j' + nodes[i].icon + ' style=width:16px;height:16px;margin-top:2px;margin-right:4px;display:inline-block></div><div style=width:16px;display:inline>' + nodes[i].name + '</div></div>';
2017-08-30 00:34:13 +03:00
}
2017-09-30 03:55:36 +03:00
setDialogMode(2, "Select a node to place", 3, placeNodeEx, x + '</div>', coords);
onPlaceNodeInputChange();
2017-08-30 00:34:13 +03:00
}
2017-09-30 03:55:36 +03:00
function placeNodeEx(button, coords) {
var elements = document.getElementsByName("PlaceMapDeviceCheckbox");
for (var i in elements) {
if (elements[i].checked) {
var node = getNodeFromId(elements[i].id.substring(0, elements[i].id.length - 8));
if (node) {
var feature = xxmap.markersSource.getFeatureById(i);
var v = ol.proj.transform(coords, 'EPSG:3857', 'EPSG:4326');
var vx = [ v[1], v[0] ]; // Flip the coordinates around, lat/long
2017-08-30 00:34:13 +03:00
if (feature) {
feature.getGeometry().setCoordinates(coords);
var activeInteraction = getActiveInteractions(feature);
if (activeInteraction) {
saveMarkerloc(feature);
2017-09-30 00:20:08 +03:00
} else { // If this feature is not saved after its location is changed, then send updated coords to server.
2018-02-12 04:13:26 +03:00
meshserver.send( { action: 'changedevice', nodeid: node._id, userloc: vx }); // Send them to server to save changes
2017-08-30 00:34:13 +03:00
}
} else {
2018-02-12 04:13:26 +03:00
meshserver.send( { action: 'changedevice', nodeid: node._id, userloc: vx }); // This Node is not yet added to maps.
2017-08-30 00:34:13 +03:00
}
}
}
}
}
2017-09-30 03:55:36 +03:00
// Called when the user changes the search box
function onPlaceNodeInputChange() {
updatePlaceNodeTable(Q('selectnode-search').value.trim().toLowerCase());
2017-08-30 00:34:13 +03:00
}
2017-09-30 03:55:36 +03:00
// Update the list of devices in the "place on map" table
function updatePlaceNodeTable(inputSearch) {
var elements = document.getElementsByName("PlaceMapDeviceCheckbox"), count = 0;
2017-08-30 00:34:13 +03:00
for (var i in nodes) {
2018-05-22 02:36:51 +03:00
var visible = ((nodes[i].namel.indexOf(inputSearch) >= 0 || inputSearch == '') || (nodes[i].rnamel != null && nodes[i].rnamel.indexOf(inputSearch) >= 0));
2017-09-30 03:55:36 +03:00
if (visible) { count++; }
QV(nodes[i]._id + '-rowid', visible);
2017-08-30 00:34:13 +03:00
}
2017-09-30 03:55:36 +03:00
QV('noNodesMapPlace', count == 0);
/*
console.log(selected);
for (var i in nodes) {
2018-05-22 02:36:51 +03:00
if ((nodes[i].name.toLowerCase().indexOf(inputSearch) >= 0 || inputSearch == '') || (nodes[i].rnamel != null && nodes[i].rnamel.toLowerCase().indexOf(inputSearch) >= 0)) {
2017-09-30 03:55:36 +03:00
console.log(selected.indexOf(nodes[i]._id));
x += '<div class=noselect id=' + nodes[i]._id + '-rowid onclick=selectNodeToPlace(event,\''+ nodes[i]._id +'\') style=background-color:lightgray;margin-bottom:4px;border-radius:2px><input name=PlaceMapDeviceCheckbox id=' + nodes[i]._id + '-checkid type=checkbox style=width:16px;display:inline ' + ((selected.indexOf(nodes[i]._id) >= 0)?'checked':'') + ' />';
x += '<div class=j' + nodes[i].icon + ' style=width:16px;height:16px;margin-top:2px;margin-right:4px;display:inline-block></div><div style=width:16px;display:inline>' + nodes[i].name + '</div></div>';
}
2017-08-30 00:34:13 +03:00
}
2017-09-30 03:55:36 +03:00
if (x == '') { x = '<div style=text-align:center;width:100%>No devices found.</div>'; }
QH('placenode', '');
*/
2017-08-30 00:34:13 +03:00
}
2017-09-30 03:55:36 +03:00
// Called when a user clicks on a device to toggle selection for placement on map.
function selectNodeToPlace(e, id) {
// Toggle checkbox if needed
if (e.target.name != 'PlaceMapDeviceCheckbox') { var inputElement = Q(id + '-checkid'); inputElement.checked = !inputElement.checked; }
2017-08-30 00:34:13 +03:00
2017-09-30 03:55:36 +03:00
// Check button state
var elements = document.getElementsByName("PlaceMapDeviceCheckbox"), checkcount = 0;
for (var i in elements) { if (elements[i].checked) checkcount++; }
QE('idx_dlgOkButton', checkcount > 0);
2017-08-30 00:34:13 +03:00
}
// Add option for available meshes in mesh Dropdown
function addMeshOptions(addMeshid, meshName) {
/*
var meshOptions = Q('select-mesh');
if (addMeshid && meshName) {
var option = document.createElement('option');
option.value =addMeshid;
option.text = meshName;
meshOptions.add(option); // Add specific option
}
else {
for (var i in meshes) { // Add all options
var option = document.createElement('option');
option.value = i;
option.text = meshes[i].name;
meshOptions.add(option);
}
}
*/
}
// Remove/Modify options in Mesh dropdown (if modMeshname is defined then Modify else Remove)
function meshOptionRmvMod(delMeshid, modMeshname) {
/*
var meshOptions = Q('select-mesh');
if (delMeshid) {
var index=-1;
for (var i = 1; i < meshOptions.options.length; i++) {
if (meshOptions[i].value === delMeshid) { index=i; }
}
if (index > 0) {
if (modMeshname) {
meshOptions[index].innerHTML=modMeshname; // If Mesh name is Modified
}
else { meshOptions.remove(index); }
}
}
*/
}
//Check if there is any mesh created
function meshExists() {
for (var i in meshes) { if (meshes[i]) { return true; } }
return false;
}
// Reset Mesh dropdown option to 'All' when a current view mesh is deleted.
function setMeshView(emeshid) {
var selectMeshElement=Q("select-mesh");
var selectedIndex = selectMeshElement.selectedIndex;
if (selectMeshElement[selectedIndex].value == emeshid) { selectMeshElement[0].selected = true; onSelectMeshChange(); }
}
// Clear all mesh options except 'All'
function clearMeshOptions() {
/*
var meshOptions=Q('select-mesh');
for(var i = meshOptions.options.length - 1 ; i > 0 ; i--) { meshOptions.remove(i); }
*/
}
// Make a http get call- Replace this with AJAX get if jquery is used
function getSearchLocation() {
try {
var searchdata = Q('mapSearchLocation').value.trim();
if (searchdata.length > 0) {
var xmlhttp = new XMLHttpRequest(); // Compatible with Chrome, Opera, Safari, IE7+, Firefox.
xmlhttp.onreadystatechange = function() { if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { formatSearchData(xmlhttp.responseText); } }
xmlhttp.open("GET", 'https://nominatim.openstreetmap.org/search?q=' + searchdata + '&format=json', true); // Get request
xmlhttp.send();
}
} catch (e) { }
}
// Format data recieved from nominatim API and display it on content window
function formatSearchData(data) {
try {
QH('xmapSearchResults','');
var dataInfo = JSON.parse(data), count = 0, x = '<div style="overflow-y:auto;width:100%;max-height:240px">';
for (var i = 0; i < dataInfo.length; i++) {
if (dataInfo[i].display_name && dataInfo[i].boundingbox[0] && dataInfo[i].boundingbox[1] && dataInfo[i].boundingbox[2] && dataInfo[i].boundingbox[3]) {
count++;
var color = (i % 2 == 0)?'F5F5F5':'EBEBEB';
x += '<div style=cursor:pointer;padding:5px;background-color:#' + color + ' onclick=mapGotoSelectedLocation(this)><div>' + dataInfo[i].display_name + '</div><div style=display:none>' + dataInfo[i].boundingbox[0] + '!#!' + dataInfo[i].boundingbox[1] + '!#!' + dataInfo[i].boundingbox[2] + '!#!' + dataInfo[i].boundingbox[3] + '</div></div>';
}
}
x += '</div>';
if (count == 1) {
// If only one result is returned then zoom to that location
var extent = [ parseFloat(dataInfo[0].boundingbox[2]), parseFloat(dataInfo[0].boundingbox[0]), parseFloat(dataInfo[0].boundingbox[3]), parseFloat(dataInfo[0].boundingbox[1]) ];
zoomToExtent(extent);
} else {
if (count == 0) { x = '<div style=width:200px>No location found.<div>'; }
QV('xmapSearchResultsDlg', true);
}
QH('xmapSearchResults', x);
}
catch (e) { }
}
// Zoom into the bounding box
function mapGotoSelectedLocation(obj) {
var objchildren = obj.children;
var boundingBox = objchildren[1].innerHTML.split('!#!');
var extent = [parseFloat(boundingBox[2]), parseFloat(boundingBox[0]), parseFloat(boundingBox[3]), parseFloat(boundingBox[1])];
//Q('search-location').value = objchildren[0].innerHTML;
zoomToExtent(extent);
mapCloseSearchWindow();
}
// Close the search window
function mapCloseSearchWindow() {
QH('xmapSearchResults', '');
QV('xmapSearchResultsDlg', false);
}
// Zoom to specific cordinates
function zoomToLocation(coordinates, zoomVal) {
var view = xxmap.map.getView();
view.setCenter(coordinates);
view.setZoom(zoomVal);
}
function zoomToFitExtent() {
var features = xxmap.markersSource.getFeatures();
if (features.length > 0) {
var extent = xxmap.markersSource.getExtent();
xxmap.map.getView().fit(extent, xxmap.map.getSize());
}
}
function zoomToExtent(extent) {
var boundingExtent = ol.proj.transformExtent(extent, ol.proj.get('EPSG:4326'), ol.proj.get('EPSG:3857'));
xxmap.map.getView().fit(boundingExtent, xxmap.map.getSize());
}
2017-08-28 19:27:45 +03:00
//
// MY DEVICE
//
function refreshDevice(nodeid) {
if (!currentNode || currentNode._id != nodeid) return;
gotoDevice(nodeid, xxcurrentView, true);
}
function getNodeRights(nodeid) {
2018-03-31 01:26:36 +03:00
var node = getNodeFromId(nodeid), mesh = meshes[node.meshid];
2018-08-24 23:14:20 +03:00
return mesh.links['user/' + domain + '/' + userinfo.name.toLowerCase()].rights;
2017-08-28 19:27:45 +03:00
}
var currentNode;
var powerTimelineNode = null;
var powerTimelineReq = null;
var powerTimelineUpdate = null;
var powerTimeline = null;
function getCurrentNode() { return currentNode; };
2019-01-30 01:08:29 +03:00
function gotoDevice(nodeid, panel, refresh, event) {
2019-02-21 02:26:27 +03:00
// Check if we are allowed to create a new device group
if ((userinfo.emailVerified !== true) && (serverinfo.emailcheck == true) && (userinfo.siteadmin != 0xFFFFFFFF)) { setDialogMode(2, "New Device Group", 1, null, "Unable to create a new device group until a email address is verified. This is required for password recovery. Go to the \"My Account\" tab to change and verify an email address."); return; }
2019-01-30 01:08:29 +03:00
if (event && (event.shiftKey == true)) {
// Open the device in a different tab
window.open(window.location.origin + '?node=' + nodeid.split('/')[2] + '&viewmode=10&hide=16', 'meshcentral:' + nodeid);
return;
}
2018-03-31 01:26:36 +03:00
//disconnectAllKvmFunction();
2017-08-28 19:27:45 +03:00
var node = getNodeFromId(nodeid);
var mesh = meshes[node.meshid];
2018-08-24 23:14:20 +03:00
var meshrights = mesh.links['user/' + domain + '/' + userinfo.name.toLowerCase()].rights;
2017-08-28 19:27:45 +03:00
if (!currentNode || currentNode._id != node._id || refresh == true) {
currentNode = node;
// Add node name
var nname = EscapeHtml(node.name);
if (nname.length == 0) { nname = '<i>None</i>'; }
2019-02-09 01:17:35 +03:00
if ((meshrights & 4) != 0) { nname = '<span title="Click here to edit the server-side device name" onclick=showEditNodeValueDialog(0) style=cursor:pointer>' + nname + ' <img class=hoverButton width=10 height=10 src="images/link5.png" /></span>'; }
2017-09-30 00:20:08 +03:00
QH('p10deviceName', nname);
2017-08-28 19:27:45 +03:00
QH('p11deviceName', nname);
QH('p12deviceName', nname);
QH('p13deviceName', nname);
QH('p14deviceName', nname);
2019-02-05 05:06:01 +03:00
QH('p15deviceName', 'Console - ' + nname);
2018-04-17 01:37:41 +03:00
QH('p16deviceName', nname);
2017-08-28 19:27:45 +03:00
// Node attributes
var x = '<table style=width:100%>';
// Attribute: Mesh
2018-09-25 03:47:03 +03:00
x += addDeviceAttribute('<span title="The name of the device group this computer belong to.">Group</span>', '<a title="The name of the device group this computer belong to" onclick=gotoMesh("' + node.meshid + '") style=cursor:pointer>' + EscapeHtml(meshes[node.meshid].name) + '</a>');
2018-05-22 02:36:51 +03:00
// Attribute: Name
2018-07-17 03:49:55 +03:00
if ((node.rname != null) && (node.name != node.rname)) { x += addDeviceAttribute('<span title="The name of this computer as set in the operating system">Name</span>', '<span title="The name of this computer as set in the operating system">' + EscapeHtml(node.rname) + '</span>'); }
2017-08-28 19:27:45 +03:00
// Attribute: Host
2018-07-17 03:49:55 +03:00
if ((features & 1) == 0) { // If not WAN-only, local hostname is in use
2017-08-28 19:27:45 +03:00
if ((meshrights & 4) != 0) {
if (node.host) {
x += addDeviceAttribute('Hostname', '<span onclick=showEditNodeValueDialog(1) style=cursor:pointer>' + EscapeHtml(node.host) + '</span>');
} else {
x += addDeviceAttribute('Hostname', '<span onclick=showEditNodeValueDialog(1) style=cursor:pointer><i>None</i></span>');
}
} else {
x += addDeviceAttribute('Hostname', EscapeHtml(node.host));
}
}
// Attribute: Description
var description = node.desc?EscapeHtml(node.desc):"<i>None</i>";
if ((meshrights & 4) != 0) {
2019-02-09 01:17:35 +03:00
x += addDeviceAttribute('Description', '<span onclick=showEditNodeValueDialog(2) style=cursor:pointer>' + description + ' <img class=hoverButton width=10 height=10 src="images/link5.png" /></span>');
2017-08-28 19:27:45 +03:00
} else {
x += addDeviceAttribute('Description', description);
}
// Attribute: Mesh Agent
2017-09-07 22:28:05 +03:00
var agentsStr = ['Unknown', 'Windows 32bit console', 'Windows 64bit console', 'Windows 32bit service', 'Windows 64bit service', 'Linux 32bit', 'Linux 64bit', 'MIPS', 'XENx86', 'Android ARM', 'Linux ARM', 'OSX 32bit', 'Android x86', 'PogoPlug ARM', 'Android APK', 'Linux Poky x86-32bit', 'OSX 64bit', 'ChromeOS', 'Linux Poky x86-64bit', 'Linux NoKVM x86-32bit', 'Linux NoKVM x86-64bit', 'Windows MinCore console', 'Windows MinCore service', 'NodeJS', 'ARM-Linaro', 'ARMv6l / ARMv7l' ];
2017-12-14 01:52:57 +03:00
if ((node.agent != null) && (node.agent.id != null) && (node.agent.ver != null)) {
2017-08-28 19:27:45 +03:00
var str = '';
if (node.agent.id <= agentsStr.length) { str = agentsStr[node.agent.id]; } else { str = agentsStr[0]; }
if (node.agent.ver != 0) { str += ' v' + node.agent.ver; }
x += addDeviceAttribute('Mesh Agent', str);
}
// Attribute: Intel AMT
2017-12-14 01:52:57 +03:00
if (node.intelamt != null) {
2017-08-28 19:27:45 +03:00
var str = '';
var provisioningStates = { 0: 'Not Activated (Pre)', 1: 'Not Activated (In)', 2: 'Activated' };
2018-05-01 23:44:26 +03:00
if (node.intelamt.ver != null && node.intelamt.state == null) { str += '<i>Unknown State</i>, v' + node.intelamt.ver; } else
2018-06-05 23:28:07 +03:00
if ((node.intelamt.ver == null) && (node.intelamt.state == 2)) { str += '<i>Activated</i>'; }
else if ((node.intelamt.ver == null) || (node.intelamt.state == null)) { str += '<i>Unknown Version & State</i>'; }
else {
2018-04-22 20:47:53 +03:00
str += provisioningStates[node.intelamt.state];
if (node.intelamt.flags) { if (node.intelamt.flags & 2) { str += ' <span title="Intel AMT is activated in Client Control Mode">CCM</span>'; } else if (node.intelamt.flags & 4) { str += ' <span title="Intel AMT is activated in Admin Control Mode">ACM</span>'; } }
str += (', v' + node.intelamt.ver);
}
2018-06-05 23:28:07 +03:00
2018-04-22 20:47:53 +03:00
if (node.intelamt.tls == 1) { str += ', <span title="Intel AMT is setup with TLS network security">TLS</span>'; }
2018-05-01 23:44:26 +03:00
if (node.intelamt.state == 2) {
if (node.intelamt.user == null || node.intelamt.user == '') {
if ((meshrights & 4) != 0) {
str += ', <i style=color:#FF0000;cursor:pointer title="Edit Intel® AMT credentials" onclick=editDeviceAmtSettings("' + node._id + '")>No Credentials</i>';
} else {
str += ', <i style=color:#FF0000>No Credentials</i>';
}
}
str += ' ';
2017-08-28 19:27:45 +03:00
if ((meshrights & 4) != 0) {
2018-05-01 23:44:26 +03:00
str += '<img src=images/link4.png height=10 width=10 title="Edit Intel® AMT credentials" style=cursor:pointer onclick=editDeviceAmtSettings("' + node._id + '")>';
2017-08-28 19:27:45 +03:00
}
}
x += addDeviceAttribute('Intel® AMT', str);
}
// Attribute: Mesh Agent Tag
2018-04-18 05:00:31 +03:00
if ((node.agent != null) && (node.agent.tag != null) && (node.agent.tag != 'mailto:')) {
2018-01-24 01:15:59 +03:00
var tag = EscapeHtml(node.agent.tag);
if (tag.startsWith('mailto:')) { tag = '<a href="' + tag + '">' + tag.substring(7) + '</a>'; }
x += addDeviceAttribute('Agent Tag', tag);
2017-08-28 19:27:45 +03:00
}
// Attribute: Intel AMT
//if (node.intelamt && node.intelamt.user) { x += addDeviceAttribute('Intel® AMT', node.intelamt.user); }
2018-09-22 02:34:35 +03:00
// Operating system description
if (node.osdesc) { x += addDeviceAttribute('Operating System', node.osdesc); }
// Active Users
if (node.users && node.conn && (node.users.length > 0) && (node.conn & 1)) { x += addDeviceAttribute('Active User' + ((node.users.length > 1)?'s':''), node.users.join(', ')); }
2017-08-28 19:27:45 +03:00
// Attribute: Connectivity (Only show this if more than just the agent is connected).
var connectivity = node.conn;
if (connectivity && connectivity > 1) {
var cstate = [];
if ((node.conn & 1) != 0) cstate.push('<span title="Mesh agent is connected and ready for use.">Mesh Agent</span>');
if ((node.conn & 2) != 0) cstate.push('<span title="Intel® AMT CIRA is connected and ready for use.">Intel® AMT CIRA</span>');
if ((node.conn & 4) != 0) cstate.push('<span title="Intel® AMT is routable and ready for use.">Intel® AMT</span>');
if ((node.conn & 8) != 0) cstate.push('<span title="Mesh agent is reachable using another agent as relay.">Mesh Relay</span>');
x += addDeviceAttribute('Connectivity', cstate.join(', '));
}
2018-05-01 21:42:20 +03:00
// Node grouping tags
var groupingTags = '<i>None</i>';
if (node.tags != null) { groupingTags = ''; for (var i in node.tags) { groupingTags += '<span style="background-color:lightgray;padding:3px;margin-right:4px;border-radius:5px">' + node.tags[i] + '</span>'; } }
2019-02-09 01:17:35 +03:00
x += addDeviceAttribute('Tags', '<span onclick=showEditNodeValueDialog(3) style=cursor:pointer>' + groupingTags + ' <img class=hoverButton width=10 height=10 src="images/link5.png" /></span>');
2018-05-01 21:42:20 +03:00
2018-04-13 04:14:03 +03:00
x += '</table><br />';
2017-08-28 19:27:45 +03:00
// Show action button, only show if we have permissions 4, 8, 64
2018-04-13 04:14:03 +03:00
if ((meshrights & 76) != 0) { x += '<input type=button value=Actions title="Perform power actions on the device" onclick=deviceActionFunction() />'; }
2018-04-16 21:57:42 +03:00
x += '<input type=button value=Notes title="View notes about this device" onclick=showNotes(' + ((meshrights & 128) == 0) + ',"' + encodeURIComponent(node._id) + '") />';
2018-04-21 00:23:41 +03:00
//if ((connectivity & 1) && (meshrights & 8) && (node.agent.id < 5)) { x += '<input type=button value=Toast title="Display a text message of the remote device" onclick=deviceToastFunction() />'; }
2017-08-28 19:27:45 +03:00
QH('p10html', x);
// Show node last 7 days timeline
2019-01-22 22:44:46 +03:00
masterUpdate(256);
2017-08-28 19:27:45 +03:00
// Show bottom buttons
x = '<div style=float:right;font-size:x-small>';
2019-02-12 05:02:07 +03:00
if ((meshrights & 4) != 0) {
// TODO: Show change group only if there is another mesh of the same type.
2019-02-19 04:50:10 +03:00
x += ' <a style=cursor:pointer onclick=p10showChangeGroupDialog(["' + node._id + '"]) title="Move this device to a different device group">Change Group</a>';
2019-02-12 05:02:07 +03:00
x += ' <a style=cursor:pointer onclick=p10showDeleteNodeDialog("' + node._id + '") title="Remove this device">Delete Device</a>';
}
2017-08-28 19:27:45 +03:00
x += '</div><div style=font-size:x-small>';
2017-10-24 00:09:58 +03:00
if (mesh.mtype == 2) x += '<a style=cursor:pointer onclick=p10showNodeNetInfoDialog("' + node._id + '") title="Show device network interface information">Interfaces</a> ';
if (xxmap != null) x += '<a style=cursor:pointer onclick=p10showNodeLocationDialog("' + node._id + '") title="Show device locations information">Location</a> ';
2018-03-27 03:13:32 +03:00
if (((meshrights & 8) != 0) && (mesh.mtype == 2)) x += '<a style=cursor:pointer onclick=p10showMeshCmdDialog(1,"' + node._id + '") title="Traffic router used to connect to a device thru this server.">Router</a> ';
2017-11-01 02:19:58 +03:00
2017-10-24 00:09:58 +03:00
// RDP link, show this link only of the remote machine is Windows.
2017-10-25 19:58:14 +03:00
if (((connectivity & 1) != 0) && (clickOnce == true) && (mesh.mtype == 2) && ((meshrights & 8) != 0)) {
if ((node.agent.id > 0) && (node.agent.id < 5)) { x += '<a style=cursor:pointer onclick=p10clickOnce("' + node._id + '","RDP2",3389) title="Requires Microsoft ClickOnce support in your browser.">RDP</a> '; }
if (node.agent.id > 4) {
x += '<a style=cursor:pointer onclick=p10clickOnce("' + node._id + '","PSSH",22) title="Requires Microsoft ClickOnce support in your browser.">Putty</a> ';
x += '<a style=cursor:pointer onclick=p10clickOnce("' + node._id + '","WSCP",22) title="Requires Microsoft ClickOnce support in your browser.">WinSCP</a> ';
}
}
2017-08-28 19:27:45 +03:00
x += '</div><br>'
QH('p10html3', x);
// Set the node power state
2018-08-27 22:24:15 +03:00
var powerstate = PowerStateStr(node.state);
2017-08-28 19:27:45 +03:00
//if (node.state == 0) { powerstate = 'Unknown State'; }
if ((connectivity & 1) != 0) { if (powerstate.length > 0) { powerstate += '<br/>'; } powerstate += '<span style=font-size:12px title="Agent connected">Agent connected</span>'; }
if ((connectivity & 2) != 0) { if (powerstate.length > 0) { powerstate += '<br/>'; } powerstate += '<span style=font-size:12px title="Intel® AMT connected">Intel® AMT connected</span>'; }
if ((connectivity & 4) != 0) { if (powerstate.length > 0) { powerstate += '<br/>'; } powerstate += '<span style=font-size:12px title="Intel® AMT detected">Intel® AMT detected</span>'; }
2018-09-27 00:58:55 +03:00
if ((powerstate == '') && node.lastconnect) { powerstate = '<span style=font-size:12px>Last seen:<br />' + new Date(node.lastconnect).toLocaleDateString() + ', ' + new Date(node.lastconnect).toLocaleTimeString() + '</span>'; }
2017-08-28 19:27:45 +03:00
QH('MainComputerState', powerstate);
// Set the node icon
2018-11-03 04:13:32 +03:00
Q('MainComputerImage').setAttribute("src", "images/icons200-" + node.icon + "-1.jpg");
2017-08-28 19:27:45 +03:00
Q('MainComputerImage').className = ((!node.conn) || (node.conn == 0)?'gray':'');
2019-02-27 04:08:55 +03:00
// Check if we have terminal and file access
var terminalAccess = ((meshrights == 0xFFFFFFFF) || ((meshrights & 512) == 0));
var fileAccess = ((meshrights == 0xFFFFFFFF) || ((meshrights & 1024) == 0));
var amtAccess = ((meshrights == 0xFFFFFFFF) || ((meshrights & 2048) == 0));
2017-08-28 19:27:45 +03:00
// Setup/Refresh the desktop tab
2019-02-27 04:08:55 +03:00
if (terminalAccess) { setupTerminal(); }
if (fileAccess) { setupFiles(); }
2017-08-28 19:27:45 +03:00
var consoleRights = ((meshrights & 16) != 0);
if (consoleRights) { setupConsole(); } else { if (panel == 15) { panel = 10; } }
// Show or hide the tabs
// mesh.mtype: 1 = Intel AMT only, 2 = Mesh Agent
// node.agent.caps (bitmask): 1 = Desktop, 2 = Terminal, 4 = Files, 8 = Console
2018-11-03 04:13:32 +03:00
QV('MainDevDesktop', ((mesh.mtype == 1) || (node.agent == null) || (node.agent.caps == null) || ((node.agent.caps & 1) != 0) || (node.intelamt && (node.intelamt.state == 2))) && ((meshrights & 8) || (meshrights & 256)));
2019-02-27 04:08:55 +03:00
QV('MainDevTerminal', ((mesh.mtype == 1) || (node.agent == null) || (node.agent.caps == null) || ((node.agent.caps & 2) != 0) || (node.intelamt && (node.intelamt.state == 2))) && (meshrights & 8) && terminalAccess);
QV('MainDevFiles', ((mesh.mtype == 2) && ((node.agent == null) || (node.agent.caps == null) || ((node.agent.caps & 4) != 0))) && (meshrights & 8) && fileAccess);
QV('MainDevAmt', (node.intelamt != null) && ((node.intelamt.state == 2) || (node.conn & 2)) && (meshrights & 8) && amtAccess);
2018-03-27 03:13:32 +03:00
QV('MainDevConsole', (consoleRights && (mesh.mtype == 2) && ((node.agent == null) || (node.agent.caps == null) || ((node.agent.caps & 8) != 0))) && (meshrights & 8));
2019-02-16 23:56:33 +03:00
QV('p15uploadCore', (node.agent != null) && (node.agent.caps != null) && ((node.agent.caps & 16) != 0));
2017-12-14 01:52:57 +03:00
QH('p15coreName', ((node.agent != null) && (node.agent.core != null))?node.agent.core:'');
2017-08-28 19:27:45 +03:00
// Setup/Refresh Intel AMT tab
var amtFrameNode = Q('p14iframe').contentWindow.getCurrentMeshNode();
if ((amtFrameNode != null) && (amtFrameNode._id != currentNode._id)) { Q('p14iframe').contentWindow.disconnect(); }
var online = ((node.conn & 6) != 0)?true:false; // If CIRA (2) or AMT (4) connected, enable Commander
Q('p14iframe').contentWindow.setConnectionState(online);
Q('p14iframe').contentWindow.setFrameHeight('650px');
Q('p14iframe').contentWindow.setAuthCallback(updateAmtCredentials);
// Display "action" button on desktop/terminal/files
2017-09-01 21:23:22 +03:00
QV('deskActionsBtn', (meshrights & 72) != 0); // 72 = Wake-up + Remote Control permissions
QV('termActionsBtn', (meshrights & 72) != 0);
QV('filesActionsBtn', (meshrights & 72) != 0);
2017-08-28 19:27:45 +03:00
// Request the power timeline
2018-09-25 03:47:03 +03:00
if ((powerTimelineNode != currentNode._id) && (powerTimelineReq != currentNode._id)) {
QH('p10html2', '');
powerTimelineReq = currentNode._id;
meshserver.send( { action: 'powertimeline', nodeid: currentNode._id });
meshserver.send( { action: 'lastconnect', nodeid: currentNode._id });
}
2018-04-11 23:49:05 +03:00
// Reset the desktop tools
QV('DeskTools', false);
showDeskToolsProcesses();
2018-04-17 01:37:41 +03:00
// Ask for device events
refreshDeviceEvents();
2019-01-30 01:08:29 +03:00
// Update the web page title
if ((currentNode) && (xxcurrentView >= 10) && (xxcurrentView < 20)) { document.title = 'MeshCentral - ' + currentNode.name; } else { document.title = 'MeshCentral'; }
2017-08-28 19:27:45 +03:00
}
2018-03-31 01:26:36 +03:00
setupDesktop(); // Always refresh the desktop, even if we are on the same device, we need to do some canvas switching.
2017-08-28 19:27:45 +03:00
if (!panel) panel = 10;
go(panel);
}
2018-04-16 21:57:42 +03:00
function showNotes(readonly, noteid) {
2018-04-13 04:14:03 +03:00
if (xxdialogMode) return;
2018-04-16 21:57:42 +03:00
setDialogMode(2, "Notes", 2, showNotesEx, '<textarea id=d2devNotes ro=' + readonly + ' noteid=' + noteid + ' readonly style=background-color:#fcf3cf;width:100%;height:200px;resize:none;overflow-y:scroll></textarea><span style=font-size:10px>Notes can be viewed and changed by other administrators.<span>', noteid);
meshserver.send( { action: 'getNotes', id: decodeURIComponent(noteid) });
2018-04-13 04:14:03 +03:00
}
2018-04-16 21:57:42 +03:00
function showNotesEx(buttons, tag) { meshserver.send( { action: 'setNotes', id: decodeURIComponent(tag), notes: encodeURIComponent(Q('d2devNotes').value) }); }
2018-04-13 04:14:03 +03:00
2018-12-08 03:36:27 +03:00
function deviceChat() {
if (xxdialogMode) return;
2019-01-29 02:47:54 +03:00
var url = '/messenger?id=meshmessenger/' + encodeURIComponent(currentNode._id) + '/' + encodeURIComponent(userinfo._id) + '&title=' + currentNode.name;
if ((authCookie != null) && (authCookie != '')) { url += '&auth=' + authCookie; }
window.open(url, 'meshmessenger:' + currentNode._id);
2018-12-08 03:36:27 +03:00
meshserver.send( { action: 'meshmessenger', nodeid: decodeURIComponent(currentNode._id) });
}
function deviceUrlFunction() {
if (xxdialogMode) return;
setDialogMode(2, "Open Page on Device", 3, deviceUrlFunctionEx, '<input id=d2devurl placeholder="http://server.com" style=width:100%;overflow-y:scroll></input>');
}
function deviceUrlFunctionEx() {
meshserver.send( { action: 'msg', type: 'openUrl', nodeid: currentNode._id, url: Q('d2devurl').value });
}
2018-04-20 04:19:15 +03:00
function deviceToastFunction() {
if (xxdialogMode) return;
2018-12-08 03:36:27 +03:00
setDialogMode(2, "Device Notification", 3, deviceToastFunctionEx, '<textarea id=d2devToast style=width:100%;height:80px;resize:none;overflow-y:scroll></textarea>');
2018-04-20 04:19:15 +03:00
}
function deviceToastFunctionEx() {
meshserver.send( { action: 'toast', nodeids: [ currentNode._id ], title: 'MeshCentral', msg: Q('d2devToast').value });
}
2017-08-28 19:27:45 +03:00
function deviceActionFunction() {
2018-04-20 04:19:15 +03:00
if (xxdialogMode) return;
2018-08-24 23:14:20 +03:00
var meshrights = meshes[currentNode.meshid].links['user/' + domain + '/' + userinfo.name.toLowerCase()].rights;
2017-08-28 19:27:45 +03:00
var x = "Select an operation to perform on this device.<br /><br />";
2017-09-01 21:23:22 +03:00
var y = '<select id=d2deviceop style=float:right;width:250px>';
if ((meshrights & 64) != 0) { y += '<option value=100>Wake-up</option>'; } // Wake-up permission
if ((meshrights & 8) != 0) { y += '<option value=4>Sleep</option><option value=3>Reset</option><option value=2>Power off</option>'; } // Remote control permission
y += '</select>';
x += addHtmlValue('Operation', y);
2017-08-28 19:27:45 +03:00
setDialogMode(2, "Device Action", 3, deviceActionFunctionEx, x);
}
function deviceActionFunctionEx() {
var op = Q('d2deviceop').value;
2017-09-01 21:23:22 +03:00
if (op == 100) {
2017-08-28 19:27:45 +03:00
// Device wake
2018-02-12 04:13:26 +03:00
meshserver.send( { action: 'wakedevices', nodeids: [ currentNode._id ] });
2017-09-01 21:23:22 +03:00
} else {
// Power operation
2018-02-12 04:13:26 +03:00
meshserver.send( { action: 'poweraction', nodeids: [ currentNode._id ], actiontype: op });
2017-08-28 19:27:45 +03:00
}
}
// Called when MeshCommander needs new credentials or updated credentials.
function updateAmtCredentials(forceDialog) {
2018-05-03 02:19:45 +03:00
var node = getNodeFromId(currentNode._id);
2017-12-14 01:52:57 +03:00
if ((forceDialog == true) || (node.intelamt.user == null) || (node.intelamt.user == '')) {
2018-05-03 02:19:45 +03:00
editDeviceAmtSettings(currentNode._id, updateAmtCredentialsEx);
2017-08-28 19:27:45 +03:00
} else {
Q('p14iframe').contentWindow.connectButtonfunctionEx();
}
}
function updateAmtCredentialsEx(button, tag) {
Q('p14iframe').contentWindow.connectButtonfunctionEx();
}
// Look to see if we need to update the device timeline
function updateDeviceTimeline() {
if ((meshserver.State != 2) || (powerTimelineNode == null) || (powerTimelineUpdate == null) || (currentNode == null)) return;
2018-09-25 03:47:03 +03:00
if ((powerTimelineNode == powerTimelineReq) && (currentNode._id == powerTimelineNode) && (powerTimelineUpdate < Date.now())) {
powerTimelineUpdate = null;
meshserver.send( { action: 'powertimeline', nodeid: currentNode._id });
meshserver.send( { action: 'lastconnect', nodeid: currentNode._id });
}
2017-08-28 19:27:45 +03:00
}
// Draw device power bars. The bars are 766px wide.
function drawDeviceTimeline() {
2018-06-05 23:28:07 +03:00
if ((currentNode == null) || (xxcurrentView < 10) || (xxcurrentView > 19)) return;
2017-08-28 19:27:45 +03:00
var timeline = null, now = Date.now();
if (currentNode._id == powerTimelineNode) { timeline = powerTimeline; }
// Calculate when the timeline starts
var d = new Date();
d.setHours(0, 0, 0, 0);
d = new Date(d.getTime() - (1000 * 60 * 60 * 24 * 6));
var timelineStart = d.getTime();
// De-compact the timeline
var timeline2 = [];
if (timeline != null && timeline.length > 1) {
timeline2.push([ 0, timeline[1], timeline[0] ]); // Start, End, Power
var ct = timeline[1];
for (var i = 2; i < timeline.length; i += 2) {
var power = timeline[i], dt = now;
if (timeline.length > (i + 1)) { dt = timeline[i + 1]; }
timeline2.push([ ct, ct + dt, power ]); // Start, End, Power
ct = ct + dt;
}
}
// Draw the timeline
var x = '', count = 1, date = new Date();
2018-06-05 23:28:07 +03:00
var totalWidth = Q('masthead').offsetWidth - (160 + 9 + 9 + 14); // Compute the total width of the power bar
2017-08-28 19:27:45 +03:00
date.setHours(0, 0, 0, 0);
for (var i = 0; i < 7; i++) {
var datavalue = '', start = date.getTime(), end = start + (1000 * 60 * 60 * 24);
for (var j in timeline2) {
var block = timeline2[j];
if (isTimeBlockInside(start, end, block[0], block[1]) == true) {
var ts = Math.max(start, block[0]);
var te = Math.min(Math.min(end, block[1]), now);
2018-06-05 23:28:07 +03:00
var width = Math.round(((te - ts) * totalWidth) / 86400000);
2017-08-28 19:27:45 +03:00
if (width > 0) {
var title = powerStateStrings2[block[2]] + ' from ' + new Date(ts).toLocaleTimeString() + ' to ' + new Date(te).toLocaleTimeString() + '.';
datavalue += '<div title="' + title + '" style=display:table-cell;width:' + width + 'px;background-color:' + powerColor(block[2]) + ';height:16px></div>';
}
}
}
x += '<tr style=' + (((count % 2) == 0)?'background-color:#DDD':'') + '><td><div> ' + date.toLocaleDateString() + '<div></div></div></td><td><div>' + datavalue + '</div></td></tr>';
++count;
date = new Date(date.getTime() - (1000 * 60 * 60 * 24)); // Substract one day
}
QH('p10html2', '<table style="color:black;background-color:#EEE;border-color:#AAA;border-width:1px;border-style:solid;border-collapse:collapse" border=0 cellpadding=2 cellspacing=0 width=100%><tbody><tr style=background-color:#AAAAAA;font-weight:bold><th scope=col style=text-align:center;width:150px>Day</th><th scope=col style=text-align:center>7 Day Power State</th></tr>' + x + '</tbody></table>');
}
// Return a color for the given power state
function powerColor(x) { if (x < powerColorTable.length) { return powerColorTable[x]; } return 'yellow'; }
// Return true if the time block is visible within the start/end period
function isTimeBlockInside(start, end, blockStart, blockEnd) {
if ((blockStart < start) && (blockEnd > end)) return true; // Block is wider than timespan
if ((blockStart > start) && (blockStart < end)) return true;
if ((blockEnd > start) && (blockEnd < end)) return true;
return false;
}
function addDeviceAttribute(name, value) { return '<tr><td class=style7 style=width:180px>' + name + '</td><td class=style9 style=max-width:400px;overflow:hidden>' + value + '</td></tr>'; }
function editDeviceAmtSettings(nodeid, func) {
if (xxdialogMode) return;
var x = '', node = getNodeFromId(nodeid), buttons = 3, meshrights = getNodeRights(nodeid);
if ((meshrights & 4) == 0) return;
x += addHtmlValue('Username', '<input id=dp10username style=width:230px maxlength=32 autocomplete=nope placeholder="admin" onchange=validateDeviceAmtSettings() onkeyup=validateDeviceAmtSettings() />');
x += addHtmlValue('Password', '<input id=dp10password type=password style=width:230px autocomplete=nope maxlength=32 onchange=validateDeviceAmtSettings() onkeyup=validateDeviceAmtSettings() />');
x += addHtmlValue('Security', '<select id=dp10tls style=width:236px><option value=0>No TLS security</option><option value=1>TLS security required</option></select>');
2017-12-14 01:52:57 +03:00
if ((node.intelamt.user != null) && (node.intelamt.user != '')) { buttons = 7; }
2017-08-28 19:27:45 +03:00
setDialogMode(2, "Edit Intel® AMT credentials", buttons, editDeviceAmtSettingsEx, x, { node: node, func: func });
2017-12-14 01:52:57 +03:00
if ((node.intelamt.user != null) && (node.intelamt.user != '')) { Q('dp10username').value = node.intelamt.user; } else { Q('dp10username').value = 'admin'; }
2017-08-28 19:27:45 +03:00
Q('dp10tls').value = node.intelamt.tls;
validateDeviceAmtSettings();
}
function validateDeviceAmtSettings() {
QE('idx_dlgOkButton', passwordcheck(Q('dp10password').value));
}
function editDeviceAmtSettingsEx(button, tag) {
if (button == 2) {
// Delete button pressed, remove credentials
2018-02-12 04:13:26 +03:00
meshserver.send( { action: 'changedevice', nodeid: tag.node._id, intelamt: { user: '', pass: '' } });
2017-08-28 19:27:45 +03:00
} else {
// Change Intel AMT credentials
var amtuser = Q('dp10username').value;
if (amtuser == '') amtuser = 'admin';
var amtpass = Q('dp10password').value;
if (amtpass == '') amtuser = '';
2018-02-12 04:13:26 +03:00
meshserver.send( { action: 'changedevice', nodeid: tag.node._id, intelamt: { user: amtuser, pass: amtpass, tls: Q('dp10tls').value } });
2017-08-28 19:27:45 +03:00
tag.node.intelamt.user = amtuser;
tag.node.intelamt.tls = Q('dp10tls').value;
if (tag.func) { setTimeout(tag.func, 300); }
}
}
2019-02-19 04:50:10 +03:00
function p10showChangeGroupDialog(nodeids) {
if (xxdialogMode) return;
var targetMeshId = null;
if (nodeids.length == 1) { try { targetMeshId = meshes[getNodeFromId(nodeids[0])]._id; } catch (ex) { } }
2019-02-12 05:02:07 +03:00
// List all available alternative groups
var y = "<select id=p10newGroup style=width:236px>", count = 0;
for (var i in meshes) {
var meshrights = meshes[i].links['user/' + domain + '/' + userinfo.name.toLowerCase()].rights;
2019-02-19 04:50:10 +03:00
if ((meshes[i]._id != targetMeshId) && (meshrights & 4)) { count++; y += "<option value='" + meshes[i]._id + "'>" + meshes[i].name + "</option>"; }
2019-02-12 05:02:07 +03:00
}
y += "</select>";
if (count > 0) {
2019-02-19 04:50:10 +03:00
var x = (nodeids.length == 1) ? "Select a new group for this device<br /><br />" : "Select a new group for selected devices<br /><br />";
2019-02-12 05:02:07 +03:00
x += addHtmlValue('New Device Group', y);
2019-02-19 04:50:10 +03:00
setDialogMode(2, "Change Group", 3, p10showChangeGroupDialogEx, x, nodeids);
2019-02-12 05:02:07 +03:00
} else {
setDialogMode(2, "Change Group", 1, null, "No other device group of same type exists.");
}
}
2019-02-19 04:50:10 +03:00
function p10showChangeGroupDialogEx(b, nodeids) {
meshserver.send( { action: 'changeDeviceMesh', nodeids: nodeids, meshid: Q('p10newGroup').value });
2019-02-12 05:02:07 +03:00
}
2017-08-28 19:27:45 +03:00
function p10showDeleteNodeDialog(nodeid) {
if (xxdialogMode) return;
var x = "Are you sure you want to delete node \"" + EscapeHtml(currentNode.name) + "\"?<br /><br />";
2019-02-20 02:51:38 +03:00
x += "<label><input id=p10check type=checkbox onchange=p10validateDeleteNodeDialog() />Confirm</label>";
2017-08-28 19:27:45 +03:00
setDialogMode(2, "Delete Node", 3, p10showDeleteNodeDialogEx, x, nodeid);
p10validateDeleteNodeDialog();
}
function p10validateDeleteNodeDialog() {
QE('idx_dlgOkButton', Q('p10check').checked);
}
function p10showDeleteNodeDialogEx(buttons, nodeid) {
2018-02-12 04:13:26 +03:00
meshserver.send( { action: 'removedevices', nodeids: [ nodeid ] });
2017-08-28 19:27:45 +03:00
}
2017-10-25 19:58:14 +03:00
function p10clickOnce(nodeid, protocol, port) {
2018-02-12 04:13:26 +03:00
meshserver.send( { action: 'getcookie', nodeid: nodeid, tcpport: port, tag: 'clickonce', protocol: protocol });
2017-10-24 00:09:58 +03:00
}
2017-08-29 01:06:29 +03:00
// Show current location
var d2map = null;
function p10showNodeLocationDialog() {
2017-09-26 01:28:52 +03:00
if ((xxdialogMode != null) && (xxdialogTag == '@xxmap')) { setDialogMode(0); } else { if (xxdialogMode) return; }
var markers = [], types = ['iploc', 'wifiloc', 'gpsloc', 'userloc'], boundingBox = null;
for (var loctype in types) {
if (currentNode[types[loctype]] != null) {
var loc = currentNode[types[loctype]].split(','), lat = parseFloat(loc[0]), lon = parseFloat(loc[1]);
if ((lat < 90) && (lat > -90) && (lon < 180) && (lon > -180)) { // Check valid lat/lon
var deviceMark = new ol.Feature( { geometry: new ol.geom.Point(ol.proj.fromLonLat([lon, lat])) });
deviceMark.setStyle(markerStyle(currentNode, parseInt(loctype) + 1));
markers.push(deviceMark);
if (boundingBox == null) { boundingBox = [ lat, lon, lat, lon, 0 ]; } else { if (lat < boundingBox[0]) { boundingBox[0] = lat; } if (lon < boundingBox[1]) { boundingBox[1] = lon; } if (lat > boundingBox[2]) { boundingBox[2] = lat; } if (lon > boundingBox[3]) { boundingBox[3] = lon; } }
}
}
}
2017-08-29 01:06:29 +03:00
// Setup the device mark layer
2017-09-26 01:28:52 +03:00
var vectorSource = new ol.source.Vector( { features: markers });
2017-08-29 01:06:29 +03:00
var vectorLayer = new ol.layer.Vector( { source: vectorSource });
2019-01-05 04:59:13 +03:00
//var x = '<div><a href="https://www.google.com/maps/preview/@' + lat + ',' + lng + ',12z" rel="noreferrer noopener" target=_blank>Open in Google maps</a></div>';
2017-09-26 01:28:52 +03:00
var x = '<div id=d2map style=width:100%;height:300px></div>';
setDialogMode(2, "Device Location", 1, null, x, '@xxmap');
var clng = 0, clat = 0, zoom = 8;
if (boundingBox != null) {
var clat = (boundingBox[0] + boundingBox[2]) / 2;
var clng = (boundingBox[1] + boundingBox[3]) / 2;
var cscale = Math.max(Math.abs(boundingBox[0] - boundingBox[2]), Math.abs(boundingBox[1] - boundingBox[3]));
var i = 360, zoom = -2;
while (i > cscale) { zoom++; i = i / 2; }
}
if (markers.length == 1) { zoom = 8; }
2017-08-29 01:06:29 +03:00
// Setup the map
d2map = new ol.Map( {
target: 'd2map',
interactions: ol.interaction.defaults( { dragPan:false, mouseWheelZoom:false}),
layers: [ new ol.layer.Tile( { source: new ol.source.OSM() }), vectorLayer ],
2017-09-26 01:28:52 +03:00
view: new ol.View( { center: ol.proj.fromLonLat([clng, clat]), zoom: zoom })
2017-08-29 01:06:29 +03:00
});
}
2017-08-28 19:27:45 +03:00
// Show network interfaces
function p10showNodeNetInfoDialog() {
if (xxdialogMode) return;
setDialogMode(2, "Network Interfaces", 1, null, "<div id=d2netinfo>Loading...</div>", 'if' + currentNode._id );
2018-02-12 04:13:26 +03:00
meshserver.send( { action: 'getnetworkinfo', nodeid: currentNode._id });
2017-08-28 19:27:45 +03:00
}
2017-11-01 02:19:58 +03:00
// Show router dialog
2017-12-16 00:43:04 +03:00
function p10showMeshCmdDialog(mode, nodeid) {
2017-11-01 02:19:58 +03:00
if (xxdialogMode) return;
var y = "<select id=aginsSelect onclick=meshCmdOsClick() style=width:236px>";
2017-11-10 04:18:30 +03:00
y += "<option value=3>Windows (32bit)</option>";
y += "<option value=4>Windows (64bit)</option>";
2017-11-01 02:19:58 +03:00
y += "<option value=5>Linux x86 (32bit)</option>";
y += "<option value=6>Linux x86 (64bit)</option>";
y += "<option value=25>Linux ARM, Raspberry Pi (32bit)</option>";
y += "</select>";
var x = "";
2017-12-16 00:43:04 +03:00
if (mode == 0) { x += '<div>MeshCmd is a command line tool that performs lots of different operations. The action file can optionally be downloaded and edited to provide server information and credentials.<br /><br />'; }
if (mode == 1) { x += '<div>Download "meshcmd" with an action file to route traffic thru this server to this device. Make sure to edit meshaction.txt and add your account password or make any changes needed.<br /><br />'; }
2017-11-01 02:19:58 +03:00
x += addHtmlValue('Operating System', y);
2019-02-19 03:12:39 +03:00
//x += addHtmlValue('MeshCmd', '<a id=meshcmddownloadid href="meshagents?meshcmd=3" rel="noreferrer noopener" target="_blank"></a>');
//if (mode == 0) { x += addHtmlValue('Action File', '<a href="meshagents?meshaction=generic" rel="noreferrer noopener" target="_blank">MeshAction (.txt)</a>'); }
//if (mode == 1) { x += addHtmlValue('Action File', '<a href="meshagents?meshaction=route&nodeid=' + nodeid + '" rel="noreferrer noopener" target="_blank">MeshAction (.txt)</a>'); }
x += addHtmlValue('MeshCmd', '<a id=meshcmddownloadid style=cursor:pointer onclick=fileDownload("meshagents?meshcmd=","MeshCmd",2)></a>');
if (mode == 0) { x += addHtmlValue('Action File', '<a style=cursor:pointer onclick=fileDownload("meshagents?meshaction=generic","MeshAction.txt")>MeshAction (.txt)</a>'); }
if (mode == 1) { x += addHtmlValue('Action File', '<a style=cursor:pointer onclick=fileDownload("meshagents?meshaction=route&nodeid=' + nodeid + '","MeshAction.txt")>MeshAction (.txt)</a>'); }
2017-11-01 02:19:58 +03:00
x += "</div>";
2019-02-19 03:12:39 +03:00
setDialogMode(2, ["Download MeshCmd","Network Router"][mode], 9, null, x, "fileDownload");
2017-11-01 02:19:58 +03:00
meshCmdOsClick();
}
function meshCmdOsClick() {
var os = Q('aginsSelect').value, osn = '';
2019-02-19 03:12:39 +03:00
//Q('meshcmddownloadid').href = "meshagents?meshcmd=" + os;
2017-11-10 04:18:30 +03:00
if (os == 3) { osn = 'MeshCmd (Win32 executable)'; }
if (os == 4) { osn = 'MeshCmd (Win64 executable)'; }
2017-11-01 02:19:58 +03:00
if (os == 5) { osn = 'MeshCmd (Linux x86, 32bit)'; }
if (os == 6) { osn = 'MeshCmd (Linux x86, 64bit)'; }
if (os == 25) { osn = 'MeshCmd (Linux ARM, 32bit)'; }
QH('meshcmddownloadid', osn);
}
2017-08-28 19:27:45 +03:00
function p10showiconselector() {
if (xxdialogMode) return;
var mesh = meshes[currentNode.meshid];
2018-08-24 23:14:20 +03:00
var meshrights = mesh.links['user/' + domain + '/' + userinfo.name.toLowerCase()].rights;
2017-08-28 19:27:45 +03:00
if ((meshrights & 4) == 0) return;
var x = '<br><div style=display:inline-block;width:40px></div>';
x += '<div style=display:inline-block class=i1 onclick=p10setIcon(1)></div>';
x += '<div style=display:inline-block class=i2 onclick=p10setIcon(2)></div>';
x += '<div style=display:inline-block class=i3 onclick=p10setIcon(3)></div>';
x += '<div style=display:inline-block class=i4 onclick=p10setIcon(4)></div>';
x += '<div style=display:inline-block class=i5 onclick=p10setIcon(5)></div>';
x += '<div style=display:inline-block class=i6 onclick=p10setIcon(6)></div><br><br>';
setDialogMode(2, "Icon Selection", 0, null, x);
QV('id_dialogclose', true);
}
function p10setIcon(icon) {
setDialogMode(0);
2018-02-12 04:13:26 +03:00
meshserver.send( { action: 'changedevice', nodeid: currentNode._id, icon: icon });
2017-08-28 19:27:45 +03:00
}
2018-09-27 03:29:12 +03:00
var showEditNodeValueDialog_modes = ['Device Name', 'Hostname', 'Description', 'Tags'];
2018-05-01 21:42:20 +03:00
var showEditNodeValueDialog_modes2 = ['name', 'host', 'desc', 'tags'];
2018-09-27 03:29:12 +03:00
var showEditNodeValueDialog_modes3 = ['', '', '', 'Tag1, Tag2, Tag3'];
2017-08-28 19:27:45 +03:00
function showEditNodeValueDialog(mode) {
if (xxdialogMode) return;
2018-05-01 21:42:20 +03:00
var x = addHtmlValue(showEditNodeValueDialog_modes[mode], '<input id=dp10devicevalue style=width:230px maxlength=64 placeholder="' + showEditNodeValueDialog_modes3[mode] + '" onchange=p10editdevicevalueValidate(' + mode + ',event) onkeyup=p10editdevicevalueValidate(' + mode + ',event) />');
2017-08-28 19:27:45 +03:00
setDialogMode(2, "Edit Device", 3, showEditNodeValueDialogEx, x, mode);
var v = currentNode[showEditNodeValueDialog_modes2[mode]];
2017-12-14 01:52:57 +03:00
if (v == null) v = '';
2018-05-01 21:42:20 +03:00
if (Array.isArray(v)) { v = v.join(', '); }
2017-08-28 19:27:45 +03:00
Q('dp10devicevalue').value = v;
p10editdevicevalueValidate();
2017-12-15 01:57:52 +03:00
Q('dp10devicevalue').focus();
2017-08-28 19:27:45 +03:00
}
function showEditNodeValueDialogEx(button, mode) {
var x = { action: 'changedevice', nodeid: currentNode._id };
x[showEditNodeValueDialog_modes2[mode]] = Q('dp10devicevalue').value;
2018-02-12 04:13:26 +03:00
meshserver.send(x);
2017-08-28 19:27:45 +03:00
}
2017-12-15 01:57:52 +03:00
function p10editdevicevalueValidate(mode, e) {
var x = ((mode > 1) || (Q('dp10devicevalue').value.length > 0));
QE('idx_dlgOkButton', x);
if ((e != null) && (x == true) && (e.keyCode == 13)) { dialogclose(1); }
2017-08-28 19:27:45 +03:00
}
//
// DESKTOP
//
var desktopNode;
function setupDesktop() {
// Setup the remote desktop
2018-08-27 22:24:15 +03:00
if ((desktopNode != currentNode) && (desktop != null)) { desktop.Stop(); desktopNode = null; desktop = null; }
2018-03-31 01:26:36 +03:00
// If the device desktop is already connected in multi-desktop, use that.
if ((desktopNode != currentNode) || (desktop == null)) {
var xdesk = multiDesktop[currentNode._id];
if (xdesk != null) {
// This device already has a canvas, use it.
QH('DeskParent', '');
var c = xdesk.m.CanvasId;
c.setAttribute('id', 'Desk');
c.setAttribute('style', 'width:100%;-ms-touch-action:none;margin-left:0px');
c.setAttribute('onmousedown', 'dmousedown(event)');
c.setAttribute('onmouseup', 'dmouseup(event)');
c.setAttribute('onmousemove', 'dmousemove(event)');
c.removeAttribute('onclick');
Q('DeskParent').appendChild(c);
desktop = xdesk;
2018-04-07 01:56:45 +03:00
if (desktop.m.SendCompressionLevel) { desktop.m.SendCompressionLevel(1, desktopsettings.quality, desktopsettings.scaling, desktopsettings.framerate); }
2018-03-31 01:26:36 +03:00
desktop.onStateChanged = onDesktopStateChange;
desktopNode = currentNode;
onDesktopStateChange(desktop, desktop.State);
delete multiDesktop[currentNode._id];
} else {
// Device is not already connected, just setup a blank canvas
2018-09-17 23:44:14 +03:00
QH('DeskParent', '<canvas id=Desk width=640 height=480 style="width:100%;-ms-touch-action:none;margin-left:0px" oncontextmenu="return false" onmousedown=dmousedown(event) onmouseup=dmouseup(event) onmousemove=dmousemove(event)></canvas>');
2018-03-31 01:26:36 +03:00
desktopNode = currentNode;
}
2018-04-14 00:09:25 +03:00
// Setup the mouse wheel
Q('Desk').addEventListener('DOMMouseScroll', function (e) { return dmousewheel(e); });
Q('Desk').addEventListener('mousewheel', function (e) { return dmousewheel(e); });
2018-03-31 01:26:36 +03:00
}
2017-08-28 19:27:45 +03:00
desktopNode = currentNode;
updateDesktopButtons();
2018-09-17 23:44:14 +03:00
deskAdjust();
2017-08-28 19:27:45 +03:00
// On some browsers like IE, we can't save screen shots. Hide the scheenshot/capture buttons.
if (!Q('Desk')['toBlob']) { QV('deskSaveBtn', false); }
}
// Show and enable the right buttons
function updateDesktopButtons() {
2018-03-31 01:26:36 +03:00
var mesh = meshes[currentNode.meshid];
2018-04-11 23:49:05 +03:00
var deskState = 0;
if (desktop != null) { deskState = desktop.State; }
2018-11-03 04:13:32 +03:00
var meshrights = mesh.links['user/' + domain + '/' + userinfo.name.toLowerCase()].rights;
2017-08-28 19:27:45 +03:00
// Show the right buttons
2018-04-11 23:49:05 +03:00
QV('disconnectbutton1span', (deskState != 0));
2018-11-03 04:13:32 +03:00
QV('connectbutton1span', (deskState == 0) && ((meshrights & 8) || (meshrights & 256)) && (mesh.mtype == 2) && (currentNode.agent.caps & 1));
QV('connectbutton1hspan', (deskState == 0) && (meshrights & 8) && ((currentNode.intelamt != null) && (mesh.mtype == 1 || currentNode.intelamt.state == 2) && ((currentNode.intelamt.ver != null) || (mesh.mtype == 1))));
2017-08-28 19:27:45 +03:00
// Show the right settings
2018-04-11 23:49:05 +03:00
QV('d7amtkvm', (currentNode.intelamt != null && ((currentNode.intelamt.ver != null) || (mesh.mtype == 1))) && ((deskState == 0) || (desktop.contype == 2)));
2018-09-29 01:27:26 +03:00
QV('d7meshkvm', (webRtcDesktop) || ((mesh.mtype == 2) && (currentNode.agent.caps & 1) && ((deskState == false) || (desktop.contype == 1))));
2017-08-28 19:27:45 +03:00
// Enable buttons
2018-04-21 00:23:41 +03:00
var online = ((currentNode.conn & 1) != 0); // If Agent (1) connected, enable remote desktop
2017-08-28 19:27:45 +03:00
QE('connectbutton1', online);
2018-03-31 01:26:36 +03:00
var hwonline = ((currentNode.conn & 6) != 0); // If CIRA (2) or AMT (4) connected, enable hardware terminal
2017-08-28 19:27:45 +03:00
QE('connectbutton1h', hwonline);
2018-04-11 23:49:05 +03:00
QE('deskSaveBtn', deskState == 3);
QV('deskFocusBtn', (desktop != null) && (desktop.contype == 2) && (deskState != 0) && (desktopsettings.showfocus));
2018-11-03 04:13:32 +03:00
QV('DeskCAD', meshrights & 8);
2018-04-11 23:49:05 +03:00
QE('DeskCAD', deskState == 3);
2019-02-17 08:16:39 +03:00
QE('DeskClip', deskState == 3);
2018-11-03 04:13:32 +03:00
QV('DeskWD', (currentNode.agent) && (currentNode.agent.id < 5) && (meshrights & 8));
2018-04-29 01:36:10 +03:00
QE('DeskWD', deskState == 3);
2018-11-03 04:13:32 +03:00
QV('deskkeys', (currentNode.agent) && (currentNode.agent.id < 5) && (meshrights & 8));
2018-04-29 01:36:10 +03:00
QE('deskkeys', deskState == 3);
2018-12-20 23:12:24 +03:00
QV('DeskToolsButton', (meshrights & 8) && (mesh.mtype == 2) && online);
QV('DeskChatButton', (browserfullscreen == false) && (meshrights & 8) && (mesh.mtype == 2) && online);
QV('DeskNotifyButton', (browserfullscreen == false) && (currentNode.agent) && (currentNode.agent.id < 5) && (meshrights & 8) && (mesh.mtype == 2) && online);
QV('DeskOpenWebButton', (browserfullscreen == false) && (meshrights & 8) && (mesh.mtype == 2) && online);
2018-11-03 04:13:32 +03:00
QV('DeskControlSpan', meshrights & 8)
2018-11-28 21:50:25 +03:00
QV('deskActionsBtn', (browserfullscreen == false));
QV('deskActionsSettings', (browserfullscreen == false));
2018-11-03 04:13:32 +03:00
if (meshrights & 8) { Q('DeskControl').checked = (getstore('DeskControl', 1) == 1); } else { Q('DeskControl').checked = false; }
2018-04-11 23:49:05 +03:00
if (online == false) QV('DeskTools', false);
2017-08-28 19:27:45 +03:00
}
2017-10-04 04:31:20 +03:00
// Debug
var autoConnectDesktopTimer = null;
function autoConnectDesktop(e) { if (autoConnectDesktopTimer == null) { autoConnectDesktopTimer = setInterval(connectDesktop, 100); } else { clearInterval(autoConnectDesktopTimer); autoConnectDesktopTimer = null; } }
2017-08-28 19:27:45 +03:00
function connectDesktop(e, contype) {
2017-12-14 01:52:57 +03:00
if (desktop == null) {
2018-03-31 01:26:36 +03:00
desktopNode = currentNode;
2017-08-28 19:27:45 +03:00
if (contype == 2) {
// Setup the Intel AMT remote desktop
2017-12-14 01:52:57 +03:00
if ((desktopNode.intelamt.user == null) || (desktopNode.intelamt.user == '')) { editDeviceAmtSettings(desktopNode._id, connectDesktop); return; }
2019-01-29 02:47:54 +03:00
desktop = CreateAmtRedirect(CreateAmtRemoteDesktop('Desk'), authCookie);
2018-01-10 07:13:41 +03:00
desktop.debugmode = debugmode;
2017-08-28 19:27:45 +03:00
desktop.onStateChanged = onDesktopStateChange;
desktop.m.bpp = (desktopsettings.encoding == 1 || desktopsettings.encoding == 3) ? 1 : 2;
desktop.m.useZRLE = (desktopsettings.encoding < 3);
desktop.m.showmouse = desktopsettings.showmouse;
desktop.m.onScreenSizeChange = deskAdjust;
2018-09-29 01:27:26 +03:00
desktop.m.onKvmData = function (x) {
//console.log('onKvmData (' + x.length + '): ' + x);
// Send the presense probe only once if needed.
if (x.length == 0) { if (!desktop.m._sentPresence) { desktop.m._sentPresence = true; desktop.m.sendKvmData(JSON.stringify( { action: 'present', ver: 1 })); } return; }
var data = null;
try { data = JSON.parse(x); } catch (e) { }
if ((data != null) && (data.action != null)) {
if (data.action == 'restart') {
// Clear WebRTC channel
webRtcDesktopReset();
desktop.m.sendKvmData(JSON.stringify( { action: 'present', ver: 1 }));
} else if ((data.action == 'present') && (webRtcDesktop == null)) {
// Setup WebRTC channel
webRtcDesktop = { platform: data.platform };
var configuration = null; // { "iceServers": [ { 'urls': 'stun:stun.services.mozilla.com' }, { 'urls': 'stun:stun.l.google.com:19302' } ] };
if (typeof RTCPeerConnection !== 'undefined') { webRtcDesktop.webrtc = new RTCPeerConnection(configuration); }
else if (typeof webkitRTCPeerConnection !== 'undefined') { webRtcDesktop.webrtc = new webkitRTCPeerConnection(configuration); }
webRtcDesktop.webchannel = webRtcDesktop.webrtc.createDataChannel("DataChannel", { }); // { ordered: false, maxRetransmits: 2 }
webRtcDesktop.webchannel.onopen = function () {
// Switch to software KVM
//if (urlvars && urlvars['kvmdatatrace']) { console.log('WebRTC Data Channel Open'); }
console.log('WebRTC Data Channel Open');
Q('deskstatus').textContent = StatusStrs[desktop.State] + ', Soft-KVM';
desktop.m.hold(true);
webRtcDesktop.webRtcActive = true;
webRtcDesktop.softdesktop = CreateKvmDataChannel(webRtcDesktop.webchannel, CreateAgentRemoteDesktop('Desk', Q('id_mainarea')), desktop.m);
webRtcDesktop.softdesktop.m.setRotation(desktop.m.rotation);
webRtcDesktop.softdesktop.m.onScreenSizeChange = deskAdjust;
if (desktopsettings.quality) { webRtcDesktop.softdesktop.m.CompressionLevel = desktopsettings.quality; } // Number from 1 to 100. 50 or less is best.
if (desktopsettings.scaling) { webRtcDesktop.softdesktop.m.ScalingLevel = desktopsettings.scaling; }
webRtcDesktop.softdesktop.Start();
// Check if we can get remote file access
// ###BEGIN### { DesktopInbandFiles}
/*
QV('go24', true); // Files
downloadFile = null;
p24files = webRtcDesktop.softdesktop;
p24targetpath = '';
webRtcDesktop.softdesktop.onControlMsg = onFilesControlData;
webRtcDesktop.softdesktop.sendCtrlMsg(JSON.stringify( { action: 'ls', reqid: 1, path: '' })); // Ask for the root folder
*/
// ###END### { DesktopInbandFiles}
}
webRtcDesktop.webchannel.onclose = function (event) {
//if (urlvars['kvmdatatrace']) { console.log('WebRTC Data Channel Closed'); }
console.log('WebRTC Data Channel Closed');
webRtcDesktopReset();
}
webRtcDesktop.webrtc.onicecandidate = function (e) {
if (e.candidate == null) {
desktop.m.sendKvmData(JSON.stringify( { action: 'offer', ver: 1, sdp: webRtcDesktop.webrtcoffer.sdp }));
} else {
webRtcDesktop.webrtcoffer.sdp += ("a=" + e.candidate.candidate + "\r\n"); // New candidate, add it to the SDP
}
}
webRtcDesktop.webrtc.oniceconnectionstatechange = function () {
if ((webRtcDesktop != null) && (webRtcDesktop.webrtc != null) && ((webRtcDesktop.webrtc.iceConnectionState == 'disconnected') || (webRtcDesktop.webrtc.iceConnectionState == 'failed'))) { /*console.log('WebRTC ICE Failed');*/ webRtcDesktopReset(); }
}
webRtcDesktop.webrtc.createOffer(function (offer) {
// Got the offer
webRtcDesktop.webrtcoffer = offer;
webRtcDesktop.webrtc.setLocalDescription(offer, function () { }, webRtcDesktopReset);
}, webRtcDesktopReset, { mandatory: { OfferToReceiveAudio: false, OfferToReceiveVideo: false } });
} else if ((data.action == 'answer') && (webRtcDesktop != null)) {
// Complete the WebRTC channel
webRtcDesktop.webrtc.setRemoteDescription(new RTCSessionDescription( { type: 'answer', sdp: data.sdp }), function () { }, webRtcDesktopReset);
}
}
};
2017-08-28 19:27:45 +03:00
desktop.Start(desktopNode._id, 16994, '*', '*', 0);
desktop.contype = 2;
2017-10-04 04:31:20 +03:00
} else {
// Setup the Mesh Agent remote desktop
2019-01-29 02:47:54 +03:00
desktop = CreateAgentRedirect(meshserver, CreateAgentRemoteDesktop('Desk'), serverPublicNamePort, authCookie);
2018-01-10 07:13:41 +03:00
desktop.debugmode = debugmode;
desktop.m.debugmode = debugmode;
2018-01-17 04:30:34 +03:00
desktop.attemptWebRTC = attemptWebRTC;
2017-10-04 04:31:20 +03:00
desktop.onStateChanged = onDesktopStateChange;
desktop.m.CompressionLevel = desktopsettings.quality; // Number from 1 to 100. 50 or less is best.
desktop.m.ScalingLevel = desktopsettings.scaling;
2018-04-07 01:56:45 +03:00
desktop.m.FrameRateTimer = desktopsettings.framerate;
2018-01-03 03:52:49 +03:00
desktop.m.onDisplayinfo = deskDisplayInfo;
2018-01-15 08:01:06 +03:00
desktop.m.onScreenSizeChange = deskAdjust;
2017-10-04 04:31:20 +03:00
desktop.Start(desktopNode._id);
desktop.contype = 1;
2017-08-28 19:27:45 +03:00
}
} else {
// Disconnect and clean up the remote desktop
desktop.Stop();
2018-09-29 01:27:26 +03:00
webRtcDesktopReset();
2018-03-31 01:26:36 +03:00
desktopNode = desktop = null;
2017-08-28 19:27:45 +03:00
}
}
2018-09-29 01:27:26 +03:00
var webRtcDesktop = null;
function webRtcDesktopReset() {
if (webRtcDesktop == null) return;
if (webRtcDesktop.softdesktop != null) { webRtcDesktop.softdesktop.Stop(); webRtcDesktop.softdesktop = null; }
if (webRtcDesktop.webchannel != null) { try { webRtcDesktop.webchannel.close(); } catch (e) { } webRtcDesktop.webchannel = null; }
if (webRtcDesktop.webrtc != null) { try { webRtcDesktop.webrtc.close(); } catch (e) { } webRtcDesktop.webrtc = null; }
webRtcDesktop = null;
// Switch back to hardware KVM
if (desktop && desktop.m) {
desktop.m.hold(false);
Q('deskstatus').textContent = StatusStrs[desktop.State];
}
// ###BEGIN### { DesktopInbandFiles}
/*
p24files = null;
p24downloadFileCancel() // If any downloads are in process, cancel them.
p24uploadFileCancel(); // If any uploads are in process, cancel them.
QV('go24', false); // Files
if (currentView == 24) { go(14); }
*/
// ###END### { DesktopInbandFiles}
}
2017-08-28 19:27:45 +03:00
function onDesktopStateChange(xdesktop, state) {
var xstate = state;
if ((xstate == 3) && (xdesktop.contype == 2)) { xstate++; }
2018-01-17 04:30:34 +03:00
var str = StatusStrs[xstate];
2018-04-11 23:49:05 +03:00
if ((desktop != null) && (desktop.webRtcActive == true)) { str += ', WebRTC'; }
2018-01-17 04:30:34 +03:00
//if (desktop.m.stopInput == true) { str += ', Loopback'; }
QH('deskstatus', str);
2017-08-28 19:27:45 +03:00
switch (state) {
case 0:
// Disconnect and clean up the remote desktop
desktop.Stop();
2018-03-31 01:26:36 +03:00
desktopNode = desktop = null;
2017-08-28 19:27:45 +03:00
QV('DeskFocus', false);
2018-01-03 03:52:49 +03:00
QV('termdisplays', false);
2017-08-28 19:27:45 +03:00
deskFocusBtn.value = 'All Focus';
if (fullscreen == true) { deskToggleFull(); }
2018-09-29 01:27:26 +03:00
webRtcDesktopReset();
2017-08-28 19:27:45 +03:00
break;
case 2:
break;
2019-01-05 04:59:13 +03:00
default:
2019-01-07 07:23:29 +03:00
//console.log('Unknown onDesktopStateChange state', state);
2019-01-05 04:59:13 +03:00
break;
2017-08-28 19:27:45 +03:00
}
updateDesktopButtons();
deskAdjust();
setTimeout(deskAdjust, 50);
}
function showDesktopSettings() {
2018-06-07 02:52:21 +03:00
if (xxdialogMode) return;
2018-03-31 01:26:36 +03:00
applyDesktopSettings();
updateDesktopButtons();
2017-08-28 19:27:45 +03:00
setDialogMode(7, "Remote Desktop Settings", 3, showDesktopSettingsChanged);
}
function showDesktopSettingsChanged() {
desktopsettings.encoding = d7desktopmode.value;
desktopsettings.showfocus = d7showfocus.checked;
desktopsettings.showmouse = d7showcursor.checked;
desktopsettings.quality = d7bitmapquality.value;
desktopsettings.scaling = d7bitmapscaling.value;
2018-04-07 01:56:45 +03:00
desktopsettings.framerate = d7framelimiter.value;
2017-08-28 19:27:45 +03:00
localStorage.setItem('desktopsettings', JSON.stringify(desktopsettings));
applyDesktopSettings();
if (desktop) {
if (desktop.contype == 1) {
2018-04-07 01:56:45 +03:00
if (desktop.State != 0) { desktop.m.SendCompressionLevel(1, desktopsettings.quality, desktopsettings.scaling, desktopsettings.framerate); }
2017-08-28 19:27:45 +03:00
}
if (desktop.contype == 2) {
if (desktopsettings.showfocus == false) { desktop.m.focusmode = 0; deskFocusBtn.value = 'All Focus'; }
if (desktop.State != 0) { desktop.Stop(); setTimeout(function () { connectDesktop(null, 2); }, 50); }
}
}
}
function applyDesktopSettings() {
2019-02-21 02:26:27 +03:00
var r = '', ops = (features & 512)?[90,80,70,60,50,40,30,20,10,5,1]:[60,50,40,30,20,10,5,1];
2018-03-21 03:48:03 +03:00
for (var i in ops) { r += '<option value=' + ops[i] + '>' + ops[i] + '%</option>'; }
QH('d7bitmapquality', r);
2017-08-28 19:27:45 +03:00
d7desktopmode.value = desktopsettings.encoding;
d7showfocus.checked = desktopsettings.showfocus;
d7showcursor.checked = desktopsettings.showmouse;
2018-03-21 03:48:03 +03:00
d7bitmapquality.value = 40; // Default value
2018-03-31 01:26:36 +03:00
if (ops.indexOf(parseInt(desktopsettings.quality)) >= 0) { d7bitmapquality.value = desktopsettings.quality; }
2017-08-28 19:27:45 +03:00
d7bitmapscaling.value = desktopsettings.scaling;
2018-04-07 01:56:45 +03:00
if (desktopsettings.framerate) { d7framelimiter.value = desktopsettings.framerate; }
2017-12-14 01:52:57 +03:00
QV('deskFocusBtn', (desktop != null) && (desktop.contype == 2) && (desktop.state != 0) && (desktopsettings.showfocus));
2017-08-28 19:27:45 +03:00
}
2018-11-28 21:50:25 +03:00
// Enter browser fullscreen
function enterBrowserFullscreen(elem) {
if (elem.requestFullscreen) { elem.requestFullscreen(); }
else if (elem.msRequestFullscreen) { elem.msRequestFullscreen(); }
else if (elem.mozRequestFullScreen) { elem.mozRequestFullScreen(); }
else if (elem.webkitRequestFullscreen) { elem.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT); }
}
// Exit browser fullscreen
function exitBrowserFullscreen() {
if (document.exitFullscreen) { document.exitFullscreen(); }
else if (document.msExitFullscreen) { document.msExitFullscreen(); }
else if (document.mozCancelFullScreen) { document.mozCancelFullScreen(); }
else if (document.webkitExitFullscreen) { document.webkitExitFullscreen(); }
}
// Return true if the browser is fullscreen. This is a delayed method that will return true/false late. Not very useful.
function isBrowserFullscreen() {
if (!document.fullscreenElement && !document.mozFullScreenElement && !document.webkitFullscreenElement && !document.msFullscreenElement) { return false; } else { return true; }
}
2017-08-28 19:27:45 +03:00
var fullscreen = false;
2018-11-28 21:50:25 +03:00
var browserfullscreen = false;
function deskToggleFull(e) {
2017-08-28 19:27:45 +03:00
fullscreen = !fullscreen;
QV('mastheadx', !fullscreen);
QV('masthead', !fullscreen);
QV('topbar', !fullscreen);
QV('p11deviceNameHeader', !fullscreen);
QV('footer', !fullscreen);
QV('column_l_bottomgap', !fullscreen);
QV('idx_deskFullBtn2', fullscreen);
QV('deskFullBtn', !fullscreen);
2018-09-15 03:42:39 +03:00
QV('page_leftbar', !fullscreen);
2017-08-28 19:27:45 +03:00
if (fullscreen) {
2018-11-28 21:50:25 +03:00
// If shift is pressed, enter browser full screen.
if (e.shiftKey == true) { enterBrowserFullscreen(Q('deskarea0')); browserfullscreen = true; }
2018-09-15 03:42:39 +03:00
QS('column_l').width = '930px';
QS('column_l').height = '';
QS('column_l')['margin-left'] = '';
QS('column_l')['overflow-y'] = '';
QS('container').position = '';
QS('page_content').position = '';
QV('MainMenuSpan', true);
2017-08-28 19:27:45 +03:00
QS('container').width = '100%';
QS('container')['border-right'] = '0';
QS('container')['border-left'] = '0';
QS('column_l').padding = '0';
QS('column_l').width = '100%';
2018-09-15 03:42:39 +03:00
QS('column_l')["max-height"] = '';
2017-08-28 19:27:45 +03:00
} else {
2018-11-28 21:50:25 +03:00
exitBrowserFullscreen();
browserfullscreen = false;
2017-08-28 19:27:45 +03:00
QS('container').width = '960px';
QS('container')['border-right'] = '1px solid #b7b7b7';
QS('container')['border-left'] = '1px solid #b7b7b7';
QS('column_l').padding = '0 15px';
QS('column_l').width = '930px';
2018-03-07 04:50:44 +03:00
toggleFullScreen();
2017-08-28 19:27:45 +03:00
}
deskAdjust();
2018-09-17 23:44:14 +03:00
deskAdjust();
2018-11-28 21:50:25 +03:00
updateDesktopButtons();
2017-08-28 19:27:45 +03:00
}
function deskToggleFocus() {
desktop.m.focusmode = (desktop.m.focusmode + 64) % 192;
Q('deskFocusBtn').value = ['All Focus', 'Small Focus', 'Large Focus'][desktop.m.focusmode / 64];
}
function deskAdjust() {
var x = (Math.max(document.documentElement.clientHeight, window.innerHeight || 0) - (Q('deskarea1').clientHeight + Q('deskarea2').clientHeight + Q('Desk').clientHeight + Q('deskarea4').clientHeight + 2)) / 2;
if (fullscreen) {
document.documentElement.style.overflow = 'hidden';
QS('deskarea3x').height = null;
if (x < 0) {
var mh = (Math.max(document.documentElement.clientHeight, window.innerHeight || 0) - (Q('deskarea1').clientHeight + Q('deskarea2').clientHeight + Q('deskarea4').clientHeight));
var mw = 9999;
if (desktop) { mw = (desktop.m.width / desktop.m.height) * mh; }
2018-09-29 01:27:26 +03:00
if (webRtcDesktop && webRtcDesktop.softdesktop) { mw = (webRtcDesktop.softdesktop.m.width / webRtcDesktop.softdesktop.m.height) * mh; }
2017-08-28 19:27:45 +03:00
QS('Desk')['max-height'] = mh + 'px';
QS('Desk')['max-width'] = mw + 'px';
x = 0;
} else {
QS('Desk')['max-height'] = null;
QS('Desk')['max-width'] = null;
}
QS('Desk')['margin-top'] = x + 'px';
QS('Desk')['margin-bottom'] = x + 'px';
} else {
2018-09-17 23:44:14 +03:00
var mw = 9999, mh = (Math.max(document.documentElement.clientHeight, window.innerHeight || 0) - (webPageFullScreen?276:290));
if (desktop) { mw = (desktop.m.width / desktop.m.height) * mh; }
2018-09-29 01:27:26 +03:00
if (webRtcDesktop && webRtcDesktop.softdesktop) { mw = (webRtcDesktop.softdesktop.m.width / webRtcDesktop.softdesktop.m.height) * mh; }
2017-08-28 19:27:45 +03:00
document.documentElement.style.overflow = 'auto';
2018-09-17 23:44:14 +03:00
QS('Desk')['max-height'] = mh + 'px';
QS('Desk')['max-width'] = mw + 'px';
2017-08-28 19:27:45 +03:00
QS('Desk')['margin-top'] = '0';
QS('Desk')['margin-bottom'] = '0';
}
}
2018-11-14 06:31:12 +03:00
function mdeskAdjust(mod, sw, sh, cv) {
if (!mod || !sw || !sh || !cv) return;
// Check if we are in single desktop mode
if (cv.id == "Desk") { deskAdjust(); return; }
// Figure out and adjust the size to fill the width of the div
var vsize = [ { x: 180, y: 101 }, { x: 302, y: 169 }, { x: 454, y: 255 }][Q('sizeselect').selectedIndex];
var realw = vsize.x + 2, tw = Q('xdevices').clientWidth - 30, xw = Math.floor(tw / realw);
xw = realw + Math.floor((tw - (xw * realw)) / xw);
vsize.y = vsize.y * (xw / vsize.x);
vsize.x = xw;
var mh = vsize.y, mw = vsize.x;
if (mod.State != 0) { mh = vsize.y; mw = (sw / sh) * vsize.y; }
QS(cv.id)['max-height'] = mh + 'px';
QS(cv.id)['max-width'] = mw + 'px';
QS(cv.id)['margin-top'] = '0';
QS(cv.id)['margin-bottom'] = '0';
}
2018-04-29 01:36:10 +03:00
// Remote desktop special key combos for Windows
function deskSendKeys() {
if (xxdialogMode || desktop == null || desktop.State != 3) return;
var ks = Q('deskkeys').value;
if (ks == 0) { // WIN+Down arrow
if (desktop.contype == 2) {
desktop.m.sendkey([[0xffe7,1],[0xff54,1],[0xff54,0],[0xffe7,0]]); // Intel AMT: Meta-left down, Down arrow press, Down arrow release, Meta-left release
} else {
desktop.m.SendKeyMsgKC([[desktop.m.KeyAction.EXDOWN,0x5B],[desktop.m.KeyAction.DOWN,40],[desktop.m.KeyAction.UP,40],[desktop.m.KeyAction.EXUP,0x5B]]); // Agent: L-Winkey press, Down arrow press, Down arrow release, L-Winkey release
}
} else if (ks == 1) { // WIN+Up arrow
if (desktop.contype == 2) {
desktop.m.sendkey([[0xffe7,1],[0xff52,1],[0xff52,0],[0xffe7,0]]); // Intel AMT: Meta-left down, Up arrow press, Up arrow release, Meta-left release
} else {
desktop.m.SendKeyMsgKC([[desktop.m.KeyAction.EXDOWN,0x5B],[desktop.m.KeyAction.DOWN,38],[desktop.m.KeyAction.UP,38],[desktop.m.KeyAction.EXUP,0x5B]]); // MeshAgent: L-Winkey press, Up arrow press, Up arrow release, L-Winkey release
}
} else if (ks == 2) { // WIN+L arrow
if (desktop.contype == 2) {
desktop.m.sendkey([[0xffe7,1],[0x6c,1],[0x6c,0],[0xffe7,0]]); // Intel AMT: Meta-left down, 'l' press, 'l' release, Meta-left release
} else {
2018-07-24 03:34:24 +03:00
desktop.sendCtrlMsg(' { "action":"lock"}');
2018-07-14 05:18:43 +03:00
//desktop.m.SendKeyMsgKC([[desktop.m.KeyAction.EXDOWN,0x5B],[desktop.m.KeyAction.DOWN,76],[desktop.m.KeyAction.UP,76],[desktop.m.KeyAction.EXUP,0x5B]]); // MeshAgent: L-Winkey press, 'L' press, 'L' release, L-Winkey release
2018-07-24 03:34:24 +03:00
//desktop.m.SendKeyMsgKC(desktop.m.KeyAction.EXDOWN, 0x5B);
2018-07-14 05:18:43 +03:00
//desktop.m.SendKeyMsgKC(desktop.m.KeyAction.DOWN, 76);
//desktop.m.SendKeyMsgKC(desktop.m.KeyAction.UP, 76);
2018-07-24 03:34:24 +03:00
//desktop.m.SendKeyMsgKC(desktop.m.KeyAction.EXUP, 0x5B);
2018-04-29 01:36:10 +03:00
}
} else if (ks == 3) { // WIN+M arrow
if (desktop.contype == 2) {
desktop.m.sendkey([[0xffe7,1],[0x6d,1],[0x6d,0],[0xffe7,0]]); // Intel AMT: Meta-left down, 'm' press, 'm' release, Meta-left release
} else {
desktop.m.SendKeyMsgKC([[desktop.m.KeyAction.EXDOWN,0x5B],[desktop.m.KeyAction.DOWN,77],[desktop.m.KeyAction.UP,77],[desktop.m.KeyAction.EXUP,0x5B]]); // MeshAgent: L-Winkey press, 'M' press, 'M' release, L-Winkey release
}
} else if (ks == 4) { // Shift+WIN+M arrow
if (desktop.contype == 2) {
desktop.m.sendkey([[0xffe1,1],[0xffe7,1],[0x6d,1],[0x6d,0],[0xffe7,0],[0xffe1,0]]); // Intel AMT: Shift-left down, Meta-left down, 'm' press, 'm' release, Meta-left release, Shift-left release
} else {
desktop.m.SendKeyMsgKC([[desktop.m.KeyAction.DOWN,16],[desktop.m.KeyAction.EXDOWN,0x5B],[desktop.m.KeyAction.DOWN,77],[desktop.m.KeyAction.UP,77],[desktop.m.KeyAction.EXUP,0x5B],[desktop.m.KeyAction.UP, 16]]); // MeshAgent: L-shift press, L-Winkey press, 'M' press, 'M' release, L-Winkey release, L-shift release
}
2018-07-14 05:18:43 +03:00
} else if (ks == 5) { // WIN
if (desktop.contype == 2) {
desktop.m.sendkey([[0xffe7,1],[0xffe7,0]]); // Intel AMT: Meta-left down, Meta-left release
} else {
desktop.m.SendKeyMsgKC([[desktop.m.KeyAction.EXDOWN,0x5B], [desktop.m.KeyAction.EXUP,0x5B]]); // MeshAgent: L-Winkey press, L-Winkey release
}
2018-10-30 23:01:44 +03:00
} else if (ks == 6) { // WIN+R
if (desktop.contype == 2) {
desktop.m.sendkey([[0xffe7, 1], [0x72, 1], [0x72, 0], [0xffe7, 0]]); // Intel AMT: Meta-left down, 'l' press, 'l' release, Meta-left release
} else {
desktop.m.SendKeyMsgKC([[desktop.m.KeyAction.EXDOWN, 0x5B], [desktop.m.KeyAction.DOWN, 82], [desktop.m.KeyAction.UP, 82], [desktop.m.KeyAction.EXUP, 0x5B]]); // MeshAgent: L-Winkey press, 'R' press, 'R' release, L-Winkey release
}
2018-04-29 01:36:10 +03:00
}
}
2019-02-17 08:16:39 +03:00
// Show clipboard dialog
function showDeskClip() {
if (xxdialogMode || desktop == null || desktop.State != 3) return;
Q('DeskClip').blur();
var x = '<input id=dlgClipGet type=button value="Get Clipboard" style=width:120px onclick=showDeskClipGet()>';
x += '<input id=dlgClipSet type=button value="Set Clipboard" style=width:120px onclick=showDeskClipSet()>';
x += '<div id=dlgClipStatus style="display:inline-block;margin-left:8px" ></div>';
x += '<textarea id=d2clipText style="width:100%;height:184px;resize:none" maxlength=65535></textarea>';
x += '<input type=button value="Close" style=width:80px;float:right onclick=dialogclose(0)><div style=height:26px> </div>';
setDialogMode(2, "Remote Clipboard", 8, null, x, 'clipboard');
Q('d2clipText').focus();
}
function showDeskClipGet() {
if (desktop == null || desktop.State != 3) return;
meshserver.send( { action: 'msg', type: 'getclip', nodeid: currentNode._id });
}
function showDeskClipSet() {
if (desktop == null || desktop.State != 3) return;
meshserver.send( { action: 'msg', type: 'setclip', nodeid: currentNode._id, data: Q('d2clipText').value });
}
2017-08-28 19:27:45 +03:00
// Send CTRL-ALT-DEL
function sendCAD() {
2017-12-14 01:52:57 +03:00
if (xxdialogMode || desktop == null || desktop.State != 3) return;
2017-08-28 19:27:45 +03:00
desktop.m.sendcad();
}
2018-04-11 23:49:05 +03:00
// Show process dialogs
function toggleDeskTools() {
if (xxdialogMode) return;
if (QS('DeskTools').display == 'none') {
QV('DeskTools', true);
Q('DeskTools').nodeid = currentNode._id;
refreshDeskTools();
} else {
QV('DeskTools', false);
}
}
// Refresh all of the desktop tool panels
function refreshDeskTools() {
QV('DeskToolsRefreshButton', false);
setTimeout(refreshDeskToolsEx, 500);
meshserver.send( { action: 'msg', type:'ps', nodeid: currentNode._id });
}
function refreshDeskToolsEx() { QV('DeskToolsRefreshButton', true); }
var deskTools = { sort: 1, msg: null };
function sortProcess(sort) { deskTools.sort = sort; showDeskToolsProcesses(deskTools.msg); }
function sortProcessPid(a, b) { if (a.p > b.p) return 1; if (a.p < b.p) return (-1); return 0; }
function sortProcessName(a, b) { if (a.d > b.d) return 1; if (a.d < b.d) return (-1); return 0; }
function showDeskToolsProcesses(message) {
deskTools.msg = message;
if (message == null) { QH('DeskToolsProcesses', ''); return; }
if (Q('DeskTools').nodeid != message.nodeid) return;
var p = [], processes = null;
try { processes = JSON.parse(message.value); } catch (e) { }
if (processes != null) {
for (var pid in processes) { p.push( { p:parseInt(pid), c:processes[pid].cmd, d:processes[pid].cmd.toLowerCase(), u: processes[pid].user } ); }
if (deskTools.sort == 0) { p.sort(sortProcessPid); } else if (deskTools.sort == 1) { p.sort(sortProcessName); }
var x = '';
for (var i in p) { if (p[i].p != 0) { x += '<div class=deskToolsBar><div style=width:50px;float:left;text-align:right;padding-right:5px>' + p[i].p + '</div><a style=float:right;padding-right:5px;cursor:pointer title="Stop process" onclick=stopProcess(' + p[i].p + ',"' + p[i].c + '")><img width=10 height=10 src="images/trash.png"></a><div style=float:right;padding-right:5px>' + (p[i].u?p[i].u:'') + '</div><div>' + p[i].c + '</div></div>'; } }
QH('DeskToolsProcesses', x);
}
}
2018-04-02 21:13:10 +03:00
// Toggle mouse and keyboard input
function toggleKvmControl() { putstore('DeskControl', (Q("DeskControl").checked?1:0)); }
2017-08-28 19:27:45 +03:00
// Save the desktop image to file
function deskSaveImage() {
2017-12-14 01:52:57 +03:00
if (xxdialogMode || desktop == null || desktop.State != 3) return;
2017-08-28 19:27:45 +03:00
var d = new Date(), n = 'Desktop-' + currentNode.name + '-' + d.getFullYear() + "-" + ("0" + (d.getMonth() + 1)).slice(-2) + "-" + ("0" + d.getDate()).slice(-2) + "-" + ("0" + d.getHours()).slice(-2) + "-" + ("0" + d.getMinutes()).slice(-2);
Q("Desk")['toBlob'](function (blob) { saveAs(blob, n + ".jpg"); });
}
2018-01-03 03:52:49 +03:00
function deskDisplayInfo(sender, info, selDisplay, selItem) {
var txt = Q('termdisplays').value;
if (info.length > 0) { var options = ''; for (var x in info) { options += '<option' + ((txt == info[x])?' selected':'') + '>' + info[x] + '</option>'; } QH('termdisplays', options); }
QV('termdisplays', info.length > 0);
}
function deskGetDisplayNumbers(e) { desktop.m.GetDisplayNumbers(); }
function deskSetDisplay(e) {
var display = 0, txt = Q('termdisplays').value;
if (txt == "All Displays") display = 65535; else display = parseInt(txt.substring(8));
desktop.m.SetDisplay(display);
}
2019-01-24 05:07:02 +03:00
// Double click detection. This is important for MacOS.
var dblClickDetectArgs = { t:0, x:0, y:0 };
function dblClickDetect(e) {
if (e.buttons != 1) return;
var t = Date.now();
if (((t - dblClickDetectArgs.t) < 250) && (Math.abs(e.clientX - dblClickDetectArgs.x) < 2) && (Math.abs(e.clientY - dblClickDetectArgs.y) < 2)) {
if (!xxdialogMode && desktop != null && Q('DeskControl').checked) { if ((webRtcDesktop != null) && (webRtcDesktop.softdesktop != null)) { webRtcDesktop.softdesktop.m.mousedblclick(e); desktop.m.sendKeepAlive(); } else { desktop.m.mousedblclick(e); } }
}
dblClickDetectArgs.t = t;
dblClickDetectArgs.x = e.clientX;
dblClickDetectArgs.y = e.clientY;
}
function dmousedown(e) { if (!xxdialogMode && desktop != null && Q('DeskControl').checked) { if ((webRtcDesktop != null) && (webRtcDesktop.softdesktop != null)) { webRtcDesktop.softdesktop.m.mousedown(e); desktop.m.sendKeepAlive(); } else { desktop.m.mousedown(e); } } dblClickDetect(e); }
2018-09-29 01:27:26 +03:00
function dmouseup(e) { if (!xxdialogMode && desktop != null && Q('DeskControl').checked) if ((webRtcDesktop != null) && (webRtcDesktop.softdesktop != null)) { webRtcDesktop.softdesktop.m.mouseup(e); desktop.m.sendKeepAlive(); } else { desktop.m.mouseup(e); } }
function dmousemove(e) { if (!xxdialogMode && desktop != null && Q('DeskControl').checked) { if ((webRtcDesktop != null) && (webRtcDesktop.softdesktop != null)) { webRtcDesktop.softdesktop.m.mousemove(e); desktop.m.sendKeepAlive(); } else { desktop.m.mousemove(e); } } }
function dmousewheel(e) { if (!xxdialogMode && desktop != null && Q('DeskControl').checked) { if ((webRtcDesktop != null) && (webRtcDesktop.softdesktop != null)) { webRtcDesktop.softdesktop.m.mousewheel(e); desktop.m.sendKeepAlive(); } else { if (desktop.m.mousewheel) { desktop.m.mousewheel(e); } } haltEvent(e); return true; } return false; }
2017-12-14 01:52:57 +03:00
function drotate(x) { if (!xxdialogMode && desktop != null) { desktop.m.setRotation(desktop.m.rotation + x); deskAdjust(); deskAdjust(); } }
2018-04-11 23:49:05 +03:00
function stopProcess(id, name) { setDialogMode(2, "Process Control", 3, stopProcessEx, 'Stop process #' + id + ' "' + name + '"?', id); }
function stopProcessEx(buttons, tag) { meshserver.send( { action: 'msg', type:'pskill', nodeid: currentNode._id, value: tag }); setTimeout(refreshDeskTools, 300); }
2017-08-28 19:27:45 +03:00
//
// TERMINAL
//
var terminalNode;
function setupTerminal() {
// Setup the terminal
2018-08-27 22:24:15 +03:00
if ((terminalNode != currentNode) && (terminal != null)) { terminal.Stop(); terminal = null; }
2017-08-28 19:27:45 +03:00
terminalNode = currentNode;
updateTerminalButtons();
}
// Show and enable the right buttons
function updateTerminalButtons() {
var mesh = meshes[terminalNode.meshid];
2017-12-14 01:52:57 +03:00
var termState = ((terminal != null) && (terminal.state != 0));
2017-08-28 19:27:45 +03:00
// Show the right buttons
QV('disconnectbutton2span', (termState == true));
2018-09-19 05:41:59 +03:00
QV('connectbutton2span', (termState == false) && (mesh.mtype == 2) && (currentNode.agent.caps & 2));
2018-05-03 02:19:45 +03:00
QV('connectbutton2hspan', (termState == false) && ((terminalNode.intelamt != null) && (mesh.mtype == 1 || terminalNode.intelamt.state == 2) && ((terminalNode.intelamt.ver != null) || (mesh.mtype == 1))));
2017-08-28 19:27:45 +03:00
// Enable buttons
var online = ((terminalNode.conn & 1) != 0); // If Agent (1) connected, enable Terminal
QE('connectbutton2', online);
var hwonline = ((terminalNode.conn & 6) != 0); // If CIRA (2) or AMT (4) connected, enable hardware terminal
QE('connectbutton2h', hwonline);
2018-09-19 00:47:17 +03:00
// Key buttons
2017-08-28 19:27:45 +03:00
QE('ctrlcbutton', termState);
QE('ctrlxbutton', termState);
QE('escbutton', termState);
QE('bsbutton', termState);
QE('pastebutton', termState);
QE('specialkeylist', termState);
QE('specialkeylistinput', termState);
2018-09-19 00:47:17 +03:00
// Terminal settings
QV('terminalSettingsButtons', (terminal) && (terminal.contype == 2));
if (terminal) {
Q('id_ttypebutton').value = terminalEmulations[terminal.m.terminalEmulation];
Q('id_tfxkeysbutton').value = fxEmulations[terminal.m.fxEmulation];
Q('id_tcrbutton').value = (terminal.m.lineFeed == '\r\n')?'CR+LF':'LF';
}
2017-08-28 19:27:45 +03:00
}
// Called when the terminal state changes
function onTerminalStateChange(xterminal, state) {
var xstate = state;
if ((xstate == 3) && (xterminal.contype == 2)) { xstate++; }
2018-01-17 04:30:34 +03:00
var str = StatusStrs[xstate];
if (terminal.webRtcActive == true) { str += ', WebRTC'; }
QH('termstatus', str);
2017-08-28 19:27:45 +03:00
switch (state) {
case 0:
// Disconnected, clear the terminal
xterminal.m.TermResetScreen();
xterminal.m.TermDraw();
2017-12-14 01:52:57 +03:00
if (terminal != null) {
2017-08-28 19:27:45 +03:00
terminal.Stop();
2017-12-14 01:52:57 +03:00
terminal = null;
2017-08-28 19:27:45 +03:00
}
break;
case 3:
break;
2019-01-05 04:59:13 +03:00
default:
2019-01-17 04:58:48 +03:00
//console.log('Unhandled onTerminalStateChange state', state);
2019-01-05 04:59:13 +03:00
break;
2017-08-28 19:27:45 +03:00
}
updateTerminalButtons();
}
2017-10-04 04:31:20 +03:00
// DEBUG
var autoConnectTerminalTimer = null;
function autoConnectTerminal(e) { if (autoConnectTerminalTimer == null) { autoConnectTerminalTimer = setInterval(connectTerminal, 100); } else { clearInterval(autoConnectTerminalTimer); autoConnectTerminalTimer = null; } }
2017-08-28 19:27:45 +03:00
function connectTerminal(e, contype) {
if (!terminal) {
if (contype == 2) {
// Setup the Intel AMT terminal
2017-12-14 01:52:57 +03:00
if ((terminalNode.intelamt.user == null) || (terminalNode.intelamt.user == '')) { editDeviceAmtSettings(terminalNode._id, connectTerminal); return; }
2019-01-29 02:47:54 +03:00
terminal = CreateAmtRedirect(CreateAmtRemoteTerminal('Term'), authCookie);
2018-01-10 07:13:41 +03:00
terminal.debugmode = debugmode;
2018-09-20 21:45:12 +03:00
terminal.m.debugmode = debugmode;
2017-08-28 19:27:45 +03:00
terminal.onStateChanged = onTerminalStateChange;
terminal.Start(terminalNode._id, 16994, '*', '*', 0);
terminal.contype = 2;
2018-07-06 20:13:19 +03:00
Q('id_ttypebutton').value = terminalEmulations[terminal.m.terminalEmulation];
2017-10-04 04:31:20 +03:00
} else {
// Setup a mesh agent terminal
2019-01-29 02:47:54 +03:00
terminal = CreateAgentRedirect(meshserver, CreateAmtRemoteTerminal('Term'), serverPublicNamePort, authCookie);
2018-01-10 07:13:41 +03:00
terminal.debugmode = debugmode;
terminal.m.debugmode = debugmode;
2018-09-20 21:45:12 +03:00
terminal.m.lineFeed = ([1,2,3,4,21,22].indexOf(currentNode.agent.id) >= 0)?'\r\n':'\n'; // On windows, send \r\n, on Linux only \n
2018-01-17 04:30:34 +03:00
terminal.attemptWebRTC = attemptWebRTC;
2017-10-04 04:31:20 +03:00
terminal.onStateChanged = onTerminalStateChange;
terminal.Start(terminalNode._id);
terminal.contype = 1;
2018-07-06 20:13:19 +03:00
terminal.m.terminalEmulation = 0;
2018-09-19 00:47:17 +03:00
terminal.m.fxEmulation = 0;
2018-07-06 20:13:19 +03:00
Q('id_ttypebutton').value = terminalEmulations[0];
2017-08-28 19:27:45 +03:00
}
} else {
//QH('Term', '');
terminal.Stop();
2017-12-14 01:52:57 +03:00
terminal = null;
2017-08-28 19:27:45 +03:00
}
Q('connectbutton2').blur(); // Deselect the connect button so the button does not get key presses.
}
var terminalEmulations = ['UTF8 Terminal', 'Extended ASCII', 'Intel ASCII'];
function termToggleType() {
if (!terminal || xxdialogMode) return;
terminal.m.terminalEmulation = (terminal.m.terminalEmulation + 1) % 3;
Q('id_ttypebutton').value = terminalEmulations[terminal.m.terminalEmulation];
Q('id_ttypebutton').blur(); // Deselect the connect button so the button does not get key presses.
}
var fxEmulations = ['Intel (F10 = ESC+[OM)', 'Alternate (F10 = ESC+0)', 'VT100+ (F10 = ESC+[OY)'];
function termToggleFx() {
if (!terminal || xxdialogMode) return;
terminal.m.fxEmulation = (terminal.m.fxEmulation + 1) % 3;
Q('id_tfxkeysbutton').value = fxEmulations[terminal.m.fxEmulation];
Q('id_tfxkeysbutton').blur(); // Deselect the connect button so the button does not get key presses.
}
2018-09-19 00:47:17 +03:00
function termToggleCr() {
if (!terminal || xxdialogMode) return;
if (terminal.m.lineFeed == '\n') { terminal.m.lineFeed = '\r\n'; } else { terminal.m.lineFeed = '\n'; }
Q('id_tcrbutton').value = (terminal.m.lineFeed == '\r\n') ? 'CR+LF' : 'LF';
}
2017-08-28 19:27:45 +03:00
function termSendKey(key, id) {
if (!terminal || xxdialogMode) return;
terminal.m.TermSendKey(key);
Q(id).blur(); // Deselect the connect button so the button does not get key presses.
}
function showTermPasteDialog() {
if (!terminal || xxdialogMode) return;
Q('pastebutton').blur();
setDialogMode(2, "Paste", 3, showTermPasteDialogEx, '<textarea id=d2pasteText style="width:100%;height:184px;resize:none"></textarea>');
Q('d2pasteText').focus();
}
function showTermPasteDialogEx() {
if (!terminal) return;
terminal.m.TermSendKeys(Q('d2pasteText').value);
}
// Send special key
function sendSpecialKey() {
terminal.m.TermSendKey(Q('specialkeylist').value);
Q('specialkeylist').blur();
Q('specialkeylistinput').blur();
}
//
// FILES
//
var filesNode;
function setupFiles() {
// Setup the files tab
var samenode = (filesNode == currentNode);
filesNode = currentNode;
var online = ((filesNode.conn & 1) != 0)?true:false; // If Agent (1) connected, enable Terminal
QE('p13Connect', online);
2018-08-27 22:24:15 +03:00
if (((samenode == false) || (online == false)) && files) { files.Stop(); files = null; }
2017-08-28 19:27:45 +03:00
}
function onFilesStateChange(xfiles, state) {
p13Connect.value = (state == 0) ? 'Connect' : 'Disconnect';
2018-01-17 04:30:34 +03:00
var str = StatusStrs[state];
if (files.webRtcActive == true) { str += ', WebRTC'; }
Q('p13Status').textContent = str;
2017-08-28 19:27:45 +03:00
switch (state) {
case 0:
// Disconnected, clear the files
QH('p13files', '');
p13filetree = null;
p13filetreelocation = [];
QH('p13currentpath', '');
QE('p13FolderUp', false);
p13setActions();
2018-08-27 22:24:15 +03:00
if (files != null) { files.Stop(); files = null; }
2017-08-28 19:27:45 +03:00
break;
case 3:
2017-12-15 01:57:52 +03:00
p13targetpath = '';
2018-07-06 20:13:19 +03:00
files.sendText( { action: 'ls', reqid: 1, path: '' });
2017-08-28 19:27:45 +03:00
break;
2019-01-05 04:59:13 +03:00
default:
2019-01-22 22:44:46 +03:00
//console.log('Unknown onFilesStateChange state', state);
2019-01-05 04:59:13 +03:00
break;
2017-08-28 19:27:45 +03:00
}
}
function CreateRemoteFiles(onFileUpdate) {
var obj = { protocol: 5 };
obj.onFileUpdate = onFileUpdate;
obj.xxStateChange = function(state) { }
obj.ProcessData = function(data) { obj.onFileUpdate(data); }
return obj;
}
2017-10-04 04:31:20 +03:00
// Debug Only
var autoConnectFilesTimer = null;
function autoConnectFiles(e) { if (autoConnectFilesTimer == null) { autoConnectFilesTimer = setInterval(connectFiles, 100); } else { clearInterval(autoConnectFilesTimer); autoConnectFilesTimer = null; } }
2017-08-28 19:27:45 +03:00
function connectFiles(e) {
if (!files) {
// Setup a mesh agent files
2019-01-29 02:47:54 +03:00
files = CreateAgentRedirect(meshserver, CreateRemoteFiles(p13gotFiles), serverPublicNamePort, authCookie);
2018-02-12 04:13:26 +03:00
files.attemptWebRTC = attemptWebRTC;
2017-08-28 19:27:45 +03:00
files.onStateChanged = onFilesStateChange;
files.Start(filesNode._id);
} else {
//QH('Term', '');
files.Stop();
2017-12-14 01:52:57 +03:00
files = null;
2017-08-28 19:27:45 +03:00
}
2018-04-03 01:34:32 +03:00
p13clipboard = p13clipboardFolder = null;
p13clipboardCut = 0;
p13updateClipview();
2017-08-28 19:27:45 +03:00
}
var p13filetree = null;
2017-12-15 01:57:52 +03:00
var p13targetpath = null;
2017-08-28 19:27:45 +03:00
var p13filetreelocation = [];
function p13gotFiles(data) {
2018-02-12 04:13:26 +03:00
if ((data.length > 0) && (data.charCodeAt(0) != 123)) { p13gotDownloadBinaryData(data); return; }
//console.log('p13gotFiles', data);
2018-07-06 20:13:19 +03:00
data = JSON.parse(decode_utf8(data));
2018-02-12 04:13:26 +03:00
if (data.action == 'download') { p13gotDownloadCommand(data); return; }
2017-08-28 19:27:45 +03:00
data.path = data.path.replace(/\//g, "\\");
if ((p13filetree != null) && (data.path == p13filetree.path)) {
// This is an update to the same folder
var checkedNames = p13getCheckedNames();
p13filetree = data;
p13updateFiles(checkedNames);
} else {
2018-01-31 05:23:57 +03:00
// Make both paths use the same seperator not start with /
2018-07-10 00:12:47 +03:00
var x1 = data.path.replace(/\//g, "\\"), x2 = p13targetpath.replace(/\//g, "\\");
2018-01-31 05:23:57 +03:00
while ((x1.length > 0) && (x1[0] == '\\')) { x1 = x1.substring(1); }
while ((x2.length > 0) && (x2[0] == '\\')) { x2 = x2.substring(1); }
if ((x1 == x2) || ((data.path == '\\') && (p13targetpath == ''))) {
2017-12-15 01:57:52 +03:00
// This is a different folder
p13filetree = data;
p13updateFiles();
}
2017-08-28 19:27:45 +03:00
}
}
2017-09-30 00:20:08 +03:00
2017-08-28 19:27:45 +03:00
function p13getCheckedNames() {
// Save all existing checked boxes
var checkedNames = [], checkboxes = document.getElementsByName('fd');
for (var i = 0; i < checkboxes.length; i++) { if (checkboxes[i].checked) { checkedNames.push(p13filetree.dir[checkboxes[i].value].n) }; }
return checkedNames;
}
function p13updateFiles(checkedNames) {
var html1 = '', html2 = '', displayPath = '<a style=cursor:pointer onclick=p13folderup(0)>Root</a>', fullPath = 'Root';
// Work on parsing the file path
var x = p13filetree.path.split('\\');
p13filetreelocation = [];
for (var i in x) { if (x[i] != '') { p13filetreelocation.push(x[i]); } } // Remove empty spaces
for (var i in p13filetreelocation) { displayPath += ' / <a style=cursor:pointer onclick=p13folderup(' + (parseInt(i) + 1) + ')>' + p13filetreelocation[i] + '</a>' } // Setup the path we display
var newlinkpath = p13filetreelocation.join('/');
// Sort the files
var filetreexx = p13sort_files(p13filetree.dir);
// Display all files and folders at this location
for (var i in filetreexx) {
// Figure out the name and shortname
var f = filetreexx[i], name = f.n, shortname;
shortname = name;
if (name.length > 70) { shortname = '<span title="' + EscapeHtml(name) + '">' + EscapeHtml(name.substring(0, 70)) + "...</span>"; } else { shortname = EscapeHtml(name); }
name = EscapeHtml(name);
// Figure out the date
var fdatestr = '';
2017-12-14 01:52:57 +03:00
if (f.d != null) { var fdate = new Date(f.d), fdatestr = (fdate.getMonth() + 1) + "/" + (fdate.getDate()) + "/" + fdate.getFullYear() + " " + fdate.toLocaleTimeString() + " "; }
2017-08-28 19:27:45 +03:00
// Figure out the size
var fsize = '';
2017-12-14 01:52:57 +03:00
if (f.s != null) { fsize = getFileSizeStr(f.s); }
2017-08-28 19:27:45 +03:00
var h = '';
if (f.t < 3) {
var right = '', title = '';
2019-02-06 06:07:12 +03:00
h = "<div class=filelist file=999><input file=999 style=float:left name=fd class=fcb type=checkbox onchange=p13setActions() value='" + f.nx + "'> <span style=float:right title=\"" + title + "\">" + right + "</span><span><div class=fileIcon" + f.t + " onclick=p13folderset(\"" + encodeURIComponent(f.nx) + "\")></div><a style=cursor:pointer onclick=p13folderset(\"" + encodeURIComponent(f.nx) + "\")>" + shortname + "</a></span></div>";
2017-08-28 19:27:45 +03:00
} else {
var link = shortname;
2019-01-05 04:59:13 +03:00
if (f.s > 0) { link = "<a rel=\"noreferrer noopener\" target=\"_blank\" style=cursor:pointer onclick=\"p13downloadfile('" + encodeURIComponent(newlinkpath + '/' + name) + "','" + encodeURIComponent(name) + "'," + f.s + ")\">" + shortname + "</a>"; }
2018-04-03 01:34:32 +03:00
h = "<div class=filelist file=3><input file=3 style=float:left name=fd class=fcb type=checkbox onchange=p13setActions() value='" + f.nx + "'> <span class=fsize>" + fdatestr + "</span><span style=float:right>" + fsize + "</span><span><div class=fileIcon" + f.t + "></div>" + link + "</span></div>";
2017-08-28 19:27:45 +03:00
}
if (f.t < 3) { html1 += h; } else { html2 += h; }
}
// Display the files and path
QH('p13files', html1 + html2);
QH('p13currentpath', displayPath);
QE('p13FolderUp', p13filetreelocation.length != 0);
// Re-check all boxes if needed using names
2018-04-03 01:34:32 +03:00
if (checkedNames != null) { var checkboxes = document.getElementsByName('fd'); for (var i = 0; i < checkboxes.length; i++) { if (checkedNames.indexOf(p13filetree.dir[checkboxes[i].value].n) >= 0) { checkboxes[i].checked = true; } } }
2017-08-28 19:27:45 +03:00
// Update the actions buttons
p13setActions();
}
function p13folderset(x) {
2017-12-15 01:57:52 +03:00
p13targetpath = joinPaths(p13filetree.path, p13filetree.dir[x].n).split('\\').join('/');
2018-07-06 20:13:19 +03:00
files.sendText( { action: 'ls', reqid: 1, path: p13targetpath });
2017-08-28 19:27:45 +03:00
}
function p13folderup(x) {
2017-12-14 01:52:57 +03:00
if (x == null) { p13filetreelocation.pop(); } else { while (p13filetreelocation.length > x) { p13filetreelocation.pop(); } }
2017-12-15 01:57:52 +03:00
p13targetpath = p13filetreelocation.join('/');
2018-07-06 20:13:19 +03:00
files.sendText( { action: 'ls', reqid: 1, path: p13targetpath });
2017-08-28 19:27:45 +03:00
}
var p13sortorder;
function p13sort_filename(a, b) { if (a.ln > b.ln) return (1 * p13sortorder); if (a.ln < b.ln) return (-1 * p13sortorder); return 0; }
function p13sort_timestamp(a, b) { if (a.d > b.d) return (1 * p13sortorder); if (a.d < b.d) return (-1 * p13sortorder); return 0; }
function p13sort_bysize(a, b) { if (a.s == b.s) return p13sort_filename(a, b); return (((a.s - b.s)) * p13sortorder); }
function p13sort_files(files) {
var r = [], sortselection = Q('p13sortdropdown').value;
2017-12-14 01:52:57 +03:00
for (var i in files) { files[i].nx = i; if (files[i].s == null) { files[i].s = 0; } if (files[i].n == null) { files[i].n = i; } files[i].ln = files[i].n.toLowerCase(); r.push(files[i]); }
2017-08-28 19:27:45 +03:00
p13sortorder = 1;
if (sortselection > 3) { p13sortorder = -1; sortselection -= 3; }
if (sortselection == 1) { r.sort(p13sort_filename); }
else if (sortselection == 2) { r.sort(p13sort_bysize); }
else if (sortselection == 3) { r.sort(p13sort_timestamp); }
return r;
}
function p13setActions() {
if (p13filetree == null) {
QE('p13DeleteFileButton', false);
QE('p13NewFolderButton', false);
QE('p13UploadButton', false);
QE('p13RenameFileButton', false);
QE('p13SelectAllButton', false);
Q('p13SelectAllButton').value = 'Select All';
QE('p13RefreshButton', false);
2018-04-03 01:34:32 +03:00
QE('p13CutButton', false);
QE('p13CopyButton', false);
QE('p13PasteButton', false);
2017-08-28 19:27:45 +03:00
} else {
2018-04-03 01:34:32 +03:00
var cc = p13getFileSelCount(), tc = p13getFileCount(), sfc = p13getFileSelCount(false); // In order: number of entires selected, number of total entries, number of selected entires that are files (not folders)
2017-08-28 19:27:45 +03:00
var winAgent = ((currentNode.agent.id > 0) && (currentNode.agent.id < 5));
QE('p13DeleteFileButton', (cc > 0) && ((p13filetreelocation.length > 0) || (winAgent == false)));
QE('p13NewFolderButton', ((p13filetreelocation.length > 0) || (winAgent == false)));
QE('p13UploadButton', ((p13filetreelocation.length > 0) || (winAgent == false)));
QE('p13RenameFileButton', (cc == 1) && ((p13filetreelocation.length > 0) || (winAgent == false)));
QE('p13SelectAllButton', tc > 0);
Q('p13SelectAllButton').value = (cc > 0 ? 'Select None' : 'Select All');
QE('p13RefreshButton', true);
2018-04-03 01:34:32 +03:00
QE('p13CutButton', (cc > 0) && (cc == sfc) && ((p13filetreelocation.length > 0) || (winAgent == false)));
QE('p13CopyButton', (cc > 0) && (cc == sfc) && ((p13filetreelocation.length > 0) || (winAgent == false)));
QE('p13PasteButton', ((p13filetreelocation.length > 0) || (winAgent == false)) && ((p13clipboard != null) && (p13clipboard.length > 0)));
2017-08-28 19:27:45 +03:00
}
}
2018-04-03 01:34:32 +03:00
function p13getFileSelCount(includeDirs) { var cc = 0; var checkboxes = document.getElementsByName('fd'); for (var i = 0; i < checkboxes.length; i++) { if ((checkboxes[i].checked) && ((includeDirs != false) || (checkboxes[i].attributes.file.value == "3"))) cc++; } return cc; }
2018-09-25 21:51:40 +03:00
function p13getFileSelDirCount() { var cc = 0, checkboxes = document.getElementsByName('fd'); for (var i = 0; i < checkboxes.length; i++) { if ((checkboxes[i].checked) && (checkboxes[i].attributes.file.value == "999")) cc++; } return cc; }
2017-08-28 19:27:45 +03:00
function p13getFileCount() { var cc = 0; var checkboxes = document.getElementsByName('fd'); return checkboxes.length; }
function p13selectallfile() { var nv = (p13getFileSelCount() == 0), checkboxes = document.getElementsByName('fd'); for (var i = 0; i < checkboxes.length; i++) { checkboxes[i].checked = nv; } p13setActions(); }
2017-12-15 01:57:52 +03:00
function p13createfolder() { setDialogMode(2, "New Folder", 3, p13createfolderEx, '<input type=text id=p13renameinput maxlength=64 onkeyup=p13fileNameCheck(event) style=width:100% />'); focusTextBox('p13renameinput'); p13fileNameCheck(); }
2018-07-06 20:13:19 +03:00
function p13createfolderEx() { files.sendText( { action: 'mkdir', reqid: 1, path: p13filetreelocation.join('/') + '/' + Q('p13renameinput').value }); p13folderup(999); }
2018-09-25 21:51:40 +03:00
function p13deletefile() { var cc = p13getFileSelCount(), rec = (p13getFileSelDirCount() > 0) ? "<br /><br /><input type=checkbox id=p13recdeleteinput>Recursive delete<br>" : "<input type=checkbox id=p13recdeleteinput style='display:none'>"; setDialogMode(2, "Delete", 3, p13deletefileEx, (cc > 1) ? ('Delete ' + cc + ' selected items?' + rec) : ('Delete selected item?' + rec)); }
function p13deletefileEx() { var delfiles = [], checkboxes = document.getElementsByName('fd'); for (var i = 0; i < checkboxes.length; i++) { if (checkboxes[i].checked) { delfiles.push(p13filetree.dir[checkboxes[i].value].n); } } files.sendText( { action: 'rm', reqid: 1, path: p13filetreelocation.join('/'), delfiles: delfiles, rec: Q('p13recdeleteinput').checked }); p13folderup(999); }
2017-12-15 01:57:52 +03:00
function p13renamefile() { var renamefile, checkboxes = document.getElementsByName('fd'); for (var i = 0; i < checkboxes.length; i++) { if (checkboxes[i].checked) { renamefile = p13filetree.dir[checkboxes[i].value].n; } } setDialogMode(2, "Rename", 3, p13renamefileEx, '<input type=text id=p13renameinput maxlength=64 onkeyup=p13fileNameCheck(event) style=width:100% value="' + renamefile + '" />', { action: 'rename', path: p13filetreelocation.join('/'), oldname: renamefile}); focusTextBox('p13renameinput'); p13fileNameCheck(); }
2018-07-06 20:13:19 +03:00
function p13renamefileEx(b, t) { t.newname = Q('p13renameinput').value; files.sendText(t); p13folderup(999); }
2018-04-03 01:34:32 +03:00
function p13fileNameCheck(e) { var x = isFilenameValid(Q('p13renameinput').value); QE('idx_dlgOkButton', x); if ((x == true) && (e != null) && (e.keyCode == 13)) { dialogclose(1); } }
2017-08-28 19:27:45 +03:00
function p13uploadFile() { setDialogMode(2, "Upload File", 3, p13uploadFileEx, '<input type=file name=files id=p13uploadinput style=width:100% multiple=multiple onchange="updateUploadDialogOk(\'p13uploadinput\')" />'); updateUploadDialogOk('p13uploadinput'); }
function p13uploadFileEx() { p13doUploadFiles(Q('p13uploadinput').files); }
2018-04-03 01:34:32 +03:00
var p13clipboard = null, p13clipboardFolder = null, p13clipboardCut = 0;
function p13copyFile(cut) { var checkboxes = document.getElementsByName('fd'); p13clipboard = []; p13clipboardCut = cut, p13clipboardFolder = p13targetpath; for (var i = 0; i < checkboxes.length; i++) { if ((checkboxes[i].checked) && (checkboxes[i].attributes.file.value == "3")) { p13clipboard.push(p13filetree.dir[checkboxes[i].value].n); } } p13updateClipview(); }
function p13pasteFile() { var x = ''; if ((p13clipboard != null) && (p13clipboard.length > 0)) { x = 'Confim ' + (p13clipboardCut == 0?'copy':'move') + ' of ' + p13clipboard.length + ' entrie' + ((p13clipboard.length > 1)?'s':'') + ' to this location?' } setDialogMode(2, "Paste", 3, p13pasteFileEx, x); }
2018-07-06 20:13:19 +03:00
function p13pasteFileEx() { files.sendText( { action: (p13clipboardCut == 0?'copy':'move'), reqid: 1, scpath: p13clipboardFolder, dspath: p13targetpath, names: p13clipboard }); p13folderup(999); if (p13clipboardCut == 1) { p13clipboard = null, p13clipboardFolder = null, p13clipboardCut = 0; p13updateClipview(); } }
2018-04-03 01:34:32 +03:00
function p13updateClipview() { var x = ''; if ((p13clipboard != null) && (p13clipboard.length > 0)) { x = 'Holding ' + p13clipboard.length + ' entrie' + ((p13clipboard.length > 1)?'s':'') + ' for ' + (p13clipboardCut == 0?'copy':'move') + ', <a onclick=p13clearClip() style=cursor:pointer>Clear</a>.' } QH('p13bottomstatus', x); p13setActions(); }
function p13clearClip() { p13clipboard = null; p13clipboardFolder = null; p13clipboardCut = 0; p13updateClipview(); }
2017-08-28 19:27:45 +03:00
function p13fileDragDrop(e) {
haltEvent(e);
QV('p13bigfail', false);
QV('p13bigok', false);
if (e.dataTransfer == null || e.dataTransfer.files.length == 0 || p13filetree == null) return;
p13doUploadFiles(e.dataTransfer.files);
}
var p13dragtimer = null;
function p13fileDragOver(e) {
haltEvent(e);
if (p13dragtimer != null) { clearTimeout(p13dragtimer); p13dragtimer = null; }
var ac = (p13filetree != null); // Set to true if we can accept the file
QV('p13bigok', ac);
QV('p13bigfail', !ac);
}
function p13fileDragLeave(e) {
haltEvent(e);
if (e.target.id != "p13filetable") {
QV('p13bigfail', false);
QV('p13bigok', false);
} else {
2018-07-03 00:34:10 +03:00
p13dragtimer = setTimeout(function () { QV('p13bigfail',false); QV('p13bigok',false); p13dragtimer=null; }, 10);
2017-08-28 19:27:45 +03:00
}
}
//
// FILES DOWNLOAD
//
var downloadFile; // Global state for file download
// Called by the html page to start a download, arguments are: path, file name and file size.
function p13downloadfile(x, y, z) {
2018-02-12 04:13:26 +03:00
if (xxdialogMode || downloadFile || !files) return;
downloadFile = { path: decodeURIComponent(x), file: decodeURIComponent(y), size: z, tsize: 0, data: '', state: 0, id: Math.random() }
//console.log('p13downloadFileCancel', downloadFile);
2018-07-06 20:13:19 +03:00
files.sendText( { action: 'download', sub: 'start', id: downloadFile.id, path: downloadFile.path });
2018-02-12 04:13:26 +03:00
setDialogMode(2, "Download File", 10, p13downloadFileCancel, '<div>' + downloadFile.file + '</div><br /><progress id=d2progressBar style=width:100% value=0 max=' + z + ' />');
}
// Called by the html page to cancel the download
2018-07-06 20:13:19 +03:00
function p13downloadFileCancel() { setDialogMode(0); files.sendText( { action: 'download', sub: 'cancel', id: downloadFile.id }); downloadFile = null; }
2018-02-12 04:13:26 +03:00
// Called by the transport when download control command is received
function p13gotDownloadCommand(cmd) {
//console.log('p13gotDownloadCommand', cmd);
if ((downloadFile == null) || (cmd.id != downloadFile.id)) return;
2018-07-06 20:13:19 +03:00
if (cmd.sub == 'start') { downloadFile.state = 1; files.sendText( { action: 'download', sub: 'startack', id: downloadFile.id }); }
2018-02-12 04:13:26 +03:00
else if (cmd.sub == 'cancel') { downloadFile = null; setDialogMode(0); }
}
// Called by the transport when binary data is received
function p13gotDownloadBinaryData(data) {
if (!downloadFile || downloadFile.state == 0) return;
2018-02-13 23:28:11 +03:00
if (data.length > 4) {
downloadFile.tsize += (data.length - 4); // Add to the total bytes received
downloadFile.data += data.substring(4); // Append the data
Q('d2progressBar').value = downloadFile.tsize; // Change the progress bar
}
if ((ReadInt(data, 0) & 1) != 0) { // Check end flag
saveAs(data2blob(downloadFile.data), downloadFile.file); downloadFile = null; setDialogMode(0); // Save the file
} else {
2018-07-06 20:13:19 +03:00
files.sendText( { action: 'download', sub: 'ack', id: downloadFile.id }); // Send the ACK
2018-02-13 23:28:11 +03:00
}
2018-02-12 04:13:26 +03:00
}
/*
var downloadFile; // Global state for file download
// Called by the html page to start a download, arguments are: path, file name and file size.
function p13downloadfile(x, y, z) {
if (xxdialogMode) return;
2019-01-29 02:47:54 +03:00
downloadFile = CreateAgentRedirect(meshserver, CreateRemoteFiles(p13gotDownloadData), serverPublicNamePort, authCookie); // Create our websocket file transport
2018-02-12 04:13:26 +03:00
downloadFile.ctrlMsgAllowed = false;
2017-08-28 19:27:45 +03:00
downloadFile.onStateChanged = onFileDownloadStateChange;
downloadFile.xpath = decodeURIComponent(x);
downloadFile.xfile = decodeURIComponent(y);
downloadFile.xsize = z;
downloadFile.xtsize = 0;
downloadFile.xstate = 0;
downloadFile.Start(filesNode._id);
setDialogMode(2, "Download File", 10, p13downloadFileCancel, '<div>' + downloadFile.xfile + '</div><br /><progress id=d2progressBar style=width:100% value=0 max=' + z + ' />');
}
// Called by the html page to cancel the download
function p13downloadFileCancel(button, tag) {
//console.log('p13downloadFileCancel');
downloadFile.Stop();
delete downloadFile;
2017-12-14 01:52:57 +03:00
downloadFile = null;
2017-08-28 19:27:45 +03:00
}
// Called by the file transport to indicate when the transport connection state has changed
function onFileDownloadStateChange(xdownloadFile, state) {
switch (state) {
case 0: // Transport as disconnected. If this is not part of an abort, we need to save the file
setDialogMode(0); // Close any dialog boxes if present
2017-12-14 01:52:57 +03:00
if ((downloadFile != null) && (downloadFile.xstate == 1)) { saveAs(data2blob(downloadFile.xdata), downloadFile.xfile); } // Save the file
2017-08-28 19:27:45 +03:00
break;
case 3: // Transport as connected, send a command to indicate we want to start a file download
2018-02-12 04:13:26 +03:00
downloadFile.send(JSON.stringify( { action: 'download', reqid: 1, path: downloadFile.xpath }));
2017-08-28 19:27:45 +03:00
break;
2019-01-05 04:59:13 +03:00
default:
console.log('Unknown onFileDownloadStateChange state', state);
break;
2017-08-28 19:27:45 +03:00
}
}
// Called by the transport when data is received
function p13gotDownloadData(data) {
if (downloadFile.xstate == 0) { // If state is 0, this is a command confirming if the file will be transfered.
var cmd = JSON.parse(data);
if (cmd.action == 'downloadstart') { // Yes, the file is about to start
downloadFile.xstate = 1; // Switch to state 1, we will start receiving the file data
downloadFile.xdata = ''; // Start with empty data
2018-02-12 04:13:26 +03:00
downloadFile.send('a'); // Send the first ACK
2017-08-28 19:27:45 +03:00
} else if (cmd.action == 'downloaderror') { // Problem opening this file, cancel
p13downloadFileCancel();
}
} else { // We are in the process of receiving the file
downloadFile.xtsize += (data.length); // Add to the total bytes received
downloadFile.xdata += data; // Append the data
Q('d2progressBar').value = downloadFile.xtsize; // Change the progress bar
2018-02-12 04:13:26 +03:00
downloadFile.send('a'); // Send the ACK
2017-08-28 19:27:45 +03:00
}
}
2018-02-12 04:13:26 +03:00
*/
2017-08-28 19:27:45 +03:00
//
// FILES UPLOAD
//
var uploadFile;
function p13doUploadFiles(files) {
2018-02-12 04:13:26 +03:00
if (xxdialogMode) return;
2017-08-28 19:27:45 +03:00
uploadFile = { };
uploadFile.xpath = p13filetreelocation.join('/');
uploadFile.xfiles = files;
uploadFile.xfilePtr = -1;
setDialogMode(2, "Upload File", 10, p13uploadFileCancel, '<div id=p13dfileName>Connecting...</div><br /><progress id=d2progressBar style=width:100% value=0 max=0 />');
p13uploadReconnect();
}
function onFileUploadStateChange(xdownloadFile, state) {
switch (state) {
case 0:
2017-12-15 01:57:52 +03:00
p13folderup(9999);
2017-08-28 19:27:45 +03:00
break;
case 3:
p13uploadNextFile();
break;
2019-01-05 04:59:13 +03:00
default:
console.log('Unknown onFileUploadStateChange state', state);
break;
2017-08-28 19:27:45 +03:00
}
}
// Connect again
function p13uploadReconnect() {
2019-01-29 02:47:54 +03:00
uploadFile.ws = CreateAgentRedirect(meshserver, CreateRemoteFiles(p13gotUploadData), serverPublicNamePort, authCookie);
2018-01-17 04:30:34 +03:00
uploadFile.ws.attemptWebRTC = false;
2018-02-12 04:13:26 +03:00
uploadFile.ws.ctrlMsgAllowed = false;
2017-08-28 19:27:45 +03:00
uploadFile.ws.onStateChanged = onFileUploadStateChange;
uploadFile.ws.Start(filesNode._id);
}
// Push the next file
function p13uploadNextFile() {
uploadFile.xfilePtr++;
if (uploadFile.xfiles.length > uploadFile.xfilePtr) {
uploadFile.xptr = 0;
var file = uploadFile.xfiles[uploadFile.xfilePtr];
QH('p13dfileName', file.name);
Q('d2progressBar').max = file.size;
Q('d2progressBar').value = 0;
uploadFile.xreader = new FileReader();
uploadFile.xreader.onload = function() {
uploadFile.xdata = uploadFile.xreader.result;
2018-07-10 00:12:47 +03:00
uploadFile.ws.sendText(JSON.stringify( { action: 'upload', reqid: uploadFile.xfilePtr, path: uploadFile.xpath, name: file.name, size: uploadFile.xdata.byteLength }));
2017-08-28 19:27:45 +03:00
};
uploadFile.xreader.readAsArrayBuffer(file);
} else {
p13uploadFileCancel();
}
}
// Used to cancel the entire transfer.
function p13uploadFileCancel(button, tag) {
2017-12-14 01:52:57 +03:00
if (uploadFile != null) {
if (uploadFile.ws != null) {
2017-08-28 19:27:45 +03:00
uploadFile.ws.Stop();
2017-12-14 01:52:57 +03:00
uploadFile.ws = null;
2017-08-28 19:27:45 +03:00
}
2017-12-14 01:52:57 +03:00
uploadFile = null;
2017-08-28 19:27:45 +03:00
}
setDialogMode(0); // Close any dialog boxes if present
}
// Receive upload ack from the mesh agent, use this to keep sending more data
function p13gotUploadData(data) {
var cmd = JSON.parse(data);
2017-12-14 01:52:57 +03:00
if ((uploadFile == null) || (parseInt(uploadFile.xfilePtr) != parseInt(cmd.reqid))) { return; }
2017-08-28 19:27:45 +03:00
if (cmd.action == 'uploadstart') {
p13uploadNextPart(false);
for (var i = 0; i < 8; i++) { p13uploadNextPart(true); } // Send 8 more blocks of 4 k to full the websocket.
} else if (cmd.action == 'uploadack') {
p13uploadNextPart(false);
} else if (cmd.action == 'uploaderror') {
p13uploadFileCancel();
}
}
// Push the next part of the file into the websocket. If dataPriming is true, push more data only if it's not the last block of the file.
function p13uploadNextPart(dataPriming) {
var data = uploadFile.xdata;
var start = uploadFile.xptr;
var end = uploadFile.xptr + 4096;
if (end > data.byteLength) { if (dataPriming == true) { return; } end = data.byteLength; }
if (start == data.byteLength) {
2017-12-14 01:52:57 +03:00
if (uploadFile.ws != null) { uploadFile.ws.Stop(); uploadFile.ws = null; }
2017-08-28 19:27:45 +03:00
if (uploadFile.xfiles.length > uploadFile.xfilePtr + 1) { p13uploadReconnect(); } else { p13uploadFileCancel(); }
} else {
var datapart = data.slice(start, end);
2018-02-12 04:13:26 +03:00
uploadFile.ws.send(datapart);
2017-08-28 19:27:45 +03:00
uploadFile.xptr = end;
Q('d2progressBar').value = end;
}
}
2018-04-17 01:37:41 +03:00
//
// DEVICE EVENTS
//
var currentDeviceEvents = null;
2019-01-22 22:44:46 +03:00
function deviceEventsUpdate() {
2018-04-17 01:37:41 +03:00
var x = '', dateHeader = null;
for (var i in currentDeviceEvents) {
var event = currentDeviceEvents[i];
var time = new Date(event.time);
if (time.toLocaleDateString() != dateHeader) {
if (dateHeader != null) x += '</table>';
2018-09-15 03:42:39 +03:00
x += '<table style=width:100% cellpadding=0 cellspacing=0><tr><td class=DevSt colspan=4>' + time.toLocaleDateString() + '</td></tr>';
2018-04-17 01:37:41 +03:00
dateHeader = time.toLocaleDateString();
}
var icon = 'si3';
if (event.etype == 'user') icon = 'm2';
if (event.etype == 'server') icon = 'si3';
var msg = event.msg.split('(R)').join('®');
//if (event.username && event.username != userinfo.name) { msg += ': ' + event.username; }
2018-09-15 03:42:39 +03:00
x += '<tr><td style=width:18px><div class=' + icon + '></div></td><td class=g1 style=float:none> </td><td style=background-color:#C9C9C9>' + time.toLocaleTimeString() + ' - ' + msg + '</td><td class=g2 style=float:none> </td></tr><tr style=height:2px></tr>';
2018-04-17 01:37:41 +03:00
}
if (dateHeader != null) x += '</table>';
if (x == '') x = "<br><i>No Events Found</i><br><br>";
QH('p16events', x);
}
/*
function showDeleteAllEventsDialog() {
if (xxdialogMode) return;
var x = "Delete all events in the server event log?<br /><br />";
x += "<input id=p3check type=checkbox onchange=validateDeleteAllEventsDialog() />Confirm";
setDialogMode(2, "Delete All Events", 3, showDeleteAllEventsDialogEx, x);
validateDeleteAllEventsDialog();
}
function validateDeleteAllEventsDialog() {
QE('idx_dlgOkButton', Q('p3check').checked);
}
function showDeleteAllEventsDialogEx(buttons, tag) {
meshserver.send( { action: 'clearevents' });
}
*/
function refreshDeviceEvents() {
//currentDeviceEvents = null;
//QH('p16events', '');
meshserver.send( { action: 'events', nodeid: currentNode._id, limit: parseInt(p16limitdropdown.value) });
}
2017-08-28 19:27:45 +03:00
//
2018-02-02 00:45:26 +03:00
// CONSOLE
2017-08-28 19:27:45 +03:00
//
function agentConsoleHandleKeys(e) {
2019-02-26 04:30:19 +03:00
if ((e.ctrlKey) || (e.altKey)) { return true; }
2017-08-28 19:27:45 +03:00
var processed = 0, box = Q('p15consoleText');
if (e.key) {
if (e.keyCode == 13 && consoleFocus == 0) { p15consoleSend(e); processed = 1; }
else if (e.keyCode == 8 && consoleFocus == 0) { var x = box.value; box.value = x.substring(0, x.length - 1); processed = 1; }
else if (e.keyCode == 27) { box.value = ''; processed = 1; }
else if ((e.keyCode == 38) || (e.keyCode == 40)) { // Arrow up || Arrow down
var hindex = consoleHistory.indexOf(box.value);
//console.log(hindex, consoleHistory);
if ((e.keyCode == 38) && ((consoleHistory.length - 1) > hindex)) { box.value = consoleHistory[hindex + 1]; }
else if ((e.keyCode == 40) && (hindex > 0)) { box.value = consoleHistory[hindex - 1]; }
else if ((e.keyCode == 40) && (hindex == 0)) { box.value = ''; }
2018-01-10 07:13:41 +03:00
processed = 1;
2017-08-28 19:27:45 +03:00
}
2018-01-24 01:15:59 +03:00
else if (e.key.length === 1) {
//box.value = ((box.value + e.key));
insertTextAtCursor(box, e.key);
processed = 1;
}
2017-08-28 19:27:45 +03:00
} else {
if (e.charCode != 0 && consoleFocus == 0) { box.value = ((box.value + String.fromCharCode(e.charCode))); processed = 1; }
}
if (processed > 0) { return haltEvent(e); }
}
2018-08-24 02:55:06 +03:00
// Insert text at the cursor location on the
2018-01-24 01:15:59 +03:00
function insertTextAtCursor(ctrl, val) {
if (document.selection) { ctrl.focus(); sel = document.selection.createRange(); sel.text = val; }
else if (ctrl.selectionStart || ctrl.selectionStart == '0') {
var start = ctrl.selectionStart, end = ctrl.selectionEnd;
ctrl.value = ctrl.value.substring(0, start) + val + ctrl.value.substring(end, ctrl.value.length);
ctrl.setSelectionRange(end + 1, end + 1);
} else { ctrl.value += myValue; }
}
2017-08-28 19:27:45 +03:00
var consoleNode;
2019-02-05 05:06:01 +03:00
var consoleServerText = '';
2017-08-28 19:27:45 +03:00
function setupConsole() {
2019-02-05 05:06:01 +03:00
if (xxcurrentView == 115) {
// Setup server console
var samenode = (consoleNode == 'server');
consoleNode = 'server';
QH('p15deviceName', 'My Server Console');
2019-02-26 04:30:19 +03:00
QE('p15consoleText', true);
2019-02-05 05:06:01 +03:00
QH('p15statetext', '');
QH('p15coreName', '');
2017-08-28 19:27:45 +03:00
if (samenode == false) {
2019-02-05 05:06:01 +03:00
QH('p15agentConsoleText', consoleServerText);
2018-09-19 00:47:17 +03:00
Q('p15agentConsoleText').scrollTop = Q('p15agentConsoleText').scrollHeight;
2017-08-28 19:27:45 +03:00
}
} else {
2019-02-05 05:06:01 +03:00
// Setup the console
var samenode = (consoleNode == currentNode);
consoleNode = currentNode;
var mesh = meshes[consoleNode.meshid];
var meshrights = mesh.links['user/' + domain + '/' + userinfo.name.toLowerCase()].rights;
if ((meshrights & 16) != 0) {
if (consoleNode.consoleText == null) { consoleNode.consoleText = ''; }
if (samenode == false) {
QH('p15agentConsoleText', consoleNode.consoleText);
Q('p15agentConsoleText').scrollTop = Q('p15agentConsoleText').scrollHeight;
}
var online = ((consoleNode.conn & 1) != 0) ? true : false;
QH('p15statetext', online ? "Agent is online" : "Agent is offline");
QE('p15consoleText', online);
QE('p15uploadCore', online);
} else {
QH('p15statetext', 'Access Denied');
QE('p15consoleText', false);
QE('p15uploadCore', false);
}
2017-08-28 19:27:45 +03:00
}
}
// Clear the console for this node
function p15consoleClear() {
2018-01-10 07:13:41 +03:00
QH('p15agentConsoleText', '');
2017-08-28 19:27:45 +03:00
Q('id_p15consoleClear').blur();
2019-02-05 05:06:01 +03:00
if (xxcurrentView == 115) {
consoleServerText = '';
} else {
consoleNode.consoleText = '';
}
2017-08-28 19:27:45 +03:00
}
// Send a command to the agent
var consoleHistory = [];
function p15consoleSend(e) {
if (e && e.keyCode != 13) return;
var v = Q('p15consoleText').value, t = '<div style=color:green>> ' + EscapeHtml(Q('p15consoleText').value) + '<br/></div>';
2018-01-10 07:13:41 +03:00
Q('p15agentConsoleText').innerHTML += t;
2018-09-19 00:47:17 +03:00
Q('p15agentConsoleText').scrollTop = Q('p15agentConsoleText').scrollHeight;
2017-08-28 19:27:45 +03:00
Q('p15consoleText').value = '';
2019-02-05 05:06:01 +03:00
if (xxcurrentView == 115) {
// Send the command to the server - TODO: In the future, we may support multiple servers.
consoleServerText += t;
meshserver.send( { action: 'serverconsole', value: v });
} else {
// Send the command to the mesh agent
consoleNode.consoleText += t;
meshserver.send( { action: 'msg', type: 'console', nodeid: consoleNode._id, value: v });
}
2017-08-28 19:27:45 +03:00
// Add command to history list
if (v.length > 0) {
// Move this command to the top if it already exists
var j = consoleHistory.indexOf(v);
if (j >= 0) { consoleHistory.splice(j, 1); }
consoleHistory.unshift(v);
consoleHistory.splice(10);
}
}
// Handle Mesh Agent console data
function p15consoleReceive(node, data) {
2018-02-02 00:45:26 +03:00
data = '<div>' + data + '</div>'
2019-02-05 05:06:01 +03:00
if (node === 'serverconsole') {
// Server console data
consoleServerText += data;
if (consoleNode == 'server') {
Q('p15agentConsoleText').innerHTML += data;
Q('p15agentConsoleText').scrollTop = Q('p15agentConsoleText').scrollHeight;
}
} else {
// Agent console data
if (node.consoleText == null) { node.consoleText = data; } else { node.consoleText += data; }
if (consoleNode == node) {
Q('p15agentConsoleText').innerHTML += data;
Q('p15agentConsoleText').scrollTop = Q('p15agentConsoleText').scrollHeight;
}
2017-08-28 19:27:45 +03:00
}
}
// Called then user presses the "Change Core" button
function p15uploadCore(e) {
if (xxdialogMode) return;
2019-02-08 07:06:01 +03:00
if (e.shiftKey == true) { meshserver.send( { action: 'uploadagentcore', nodeid: consoleNode._id, type: 'default' }); } // Upload default core
else if (e.altKey == true) { meshserver.send( { action: 'uploadagentcore', nodeid: consoleNode._id, type: 'clear' }); } // Clear the core
2017-08-28 19:27:45 +03:00
else if (e.ctrlKey == true) { p15uploadCore2(); } // Upload the core from a file
2019-01-22 01:05:50 +03:00
else { setDialogMode(2, "Change Mesh Agent Core", 3, p15uploadCoreEx, '<select id=d3coreMode style=float:right;width:260px><option value=1>Upload default server core</option><option value=2>Clear the core</option><option value=6>Upload recovery core</option><option value=3>Upload a core file</option><option value=4>Soft disconnect agent</option><option value=5>Hard disconnect agent</option></select><div>Change Core</div>'); }
2017-08-28 19:27:45 +03:00
}
function p15uploadCoreEx() {
if (Q('d3coreMode').value == 1) {
// Upload default core
2019-01-22 01:05:50 +03:00
meshserver.send( { action: 'uploadagentcore', nodeid: consoleNode._id, type: 'default' });
2017-08-28 19:27:45 +03:00
} else if (Q('d3coreMode').value == 2) {
// Clear the core
2019-01-22 01:05:50 +03:00
meshserver.send( { action: 'uploadagentcore', nodeid: consoleNode._id, type: 'clear' });
2017-08-28 19:27:45 +03:00
} else if (Q('d3coreMode').value == 3) {
// Upload file as core
p15uploadCore2();
} else if (Q('d3coreMode').value == 4) {
2017-08-31 21:03:02 +03:00
// Soft disconnect the mesh agent
2018-02-12 04:13:26 +03:00
meshserver.send( { action: 'agentdisconnect', nodeid: consoleNode._id, disconnectMode: 1 });
2017-08-31 21:03:02 +03:00
} else if (Q('d3coreMode').value == 5) {
// Hard disconnect the mesh agent
2018-02-12 04:13:26 +03:00
meshserver.send( { action: 'agentdisconnect', nodeid: consoleNode._id, disconnectMode: 2 });
2019-01-22 01:05:50 +03:00
} else if (Q('d3coreMode').value == 6) {
// Upload a recovery core
meshserver.send( { action: 'uploadagentcore', nodeid: consoleNode._id, type:'recovery' });
2017-08-28 19:27:45 +03:00
}
}
// Called then user opts to upload a file as core
function p15uploadCore2() {
if (xxdialogMode) return;
Q('d3localmodeform').action = 'uploadmeshcorefile.ashx';
Q('d3attrib').value = currentNode._id;
setDialogMode(3, "Upload Mesh Agent Core", 3, p15uploadCoreEx2);
d3init();
}
function p15uploadCoreEx2() {
var mode = Q('d3uploadMode').value;
if (mode == 1) {
// Upload local mesh agent core
Q('d3submit').click();
} else {
// Upload server mesh agent code
var files = d3getFileSel();
2019-01-22 01:05:50 +03:00
if (files.length == 1) { meshserver.send( { action: 'uploadagentcore', nodeid: consoleNode._id, type: 'custom', path: d3filetreelocation.join('/') + '/' + files[0] }); }
2017-08-28 19:27:45 +03:00
}
}
//
// MY ACCOUNT
//
2019-02-11 03:04:36 +03:00
function account_manageAuthApp() {
if (xxdialogMode || ((features & 4096) == 0)) return;
if (userinfo.otpsecret == 1) { account_removeOtp(); } else { account_addOtp(); }
}
2019-01-16 00:51:07 +03:00
function account_addOtp() {
if (xxdialogMode || (userinfo.otpsecret == 1) || ((features & 4096) == 0)) return;
2019-02-11 03:04:36 +03:00
setDialogMode(2, "Authenticator App", 2, function () { meshserver.send( { action: 'otpauth-setup', secret: Q('d2optsecret').attributes.secret.value, token: Q('d2otpauthinput').value }); }, "<div id=d2optinfo>Loading...</div>", 'otpauth-request');
2019-01-16 00:51:07 +03:00
meshserver.send( { action: 'otpauth-request' });
2019-01-15 20:20:21 +03:00
}
2019-01-16 05:21:03 +03:00
function account_addOtpCheck(e) {
2019-01-16 23:04:48 +03:00
var tokenIsValid = (Q('d2otpauthinput').value.length == 6);
QE('idx_dlgOkButton', tokenIsValid);
if (e && (e.keyCode == 13) && tokenIsValid) { dialogclose(1); }
2019-01-16 00:51:07 +03:00
}
2019-01-15 20:20:21 +03:00
2019-01-16 00:51:07 +03:00
function account_removeOtp() {
if (xxdialogMode || (userinfo.otpsecret != 1) || ((features & 4096) == 0)) return;
2019-02-11 03:04:36 +03:00
setDialogMode(2, "Authenticator App", 3, function () { meshserver.send( { action: 'otpauth-clear' }); }, "Confirm removal of authenticator application 2-step login?");
2019-01-15 20:20:21 +03:00
}
2019-02-06 06:07:12 +03:00
function account_manageOtp(action) {
if ((xxdialogMode == 2) && (xxdialogTag == 'otpauth-manage')) { dialogclose(0); }
2019-02-08 09:30:33 +03:00
if (xxdialogMode || ((features & 4096) == 0)) return;
if ((userinfo.otpsecret == 1) || (userinfo.otphkeys > 0)) { meshserver.send( { action: 'otpauth-getpasswords', subaction: action }); }
2019-02-06 06:07:12 +03:00
}
2019-02-08 07:06:01 +03:00
function account_manageHardwareOtp() {
if ((xxdialogMode == 2) && (xxdialogTag == 'otpauth-hardware-manage')) { dialogclose(0); }
if (xxdialogMode || ((features & 4096) == 0)) return;
meshserver.send( { action: 'otp-hkey-get' });
}
2019-02-08 20:24:00 +03:00
function account_addhkey(type) {
if (type == 1) {
var x = "Type in the name of the key to add.<br /><br />";
x += addHtmlValue('Key Name', '<input id=dp1keyname style=width:230px maxlength=20 autocomplete=off placeholder="MyKey" onkeyup=account_addhkeyValidate(event,2) />');
} else if (type == 2) {
2019-02-11 03:04:36 +03:00
var x = "Type in a key name, select the OTP box and press the button on the YubiKey™.<br /><br />";
2019-02-08 20:24:00 +03:00
x += addHtmlValue('Key Name', '<input id=dp1keyname style=width:230px maxlength=20 autocomplete=off placeholder="MyKey" onkeyup=account_addhkeyValidate(event,1) />');
2019-02-11 03:04:36 +03:00
x += addHtmlValue('YubiKey™ OTP', '<input id=dp1key style=width:230px autocomplete=off onkeyup=account_addhkeyValidate(event,2) />');
2019-02-08 20:24:00 +03:00
}
2019-02-11 03:04:36 +03:00
setDialogMode(2, "Add Security Key", 3, account_addhkeyEx, x, type);
2019-02-08 09:30:33 +03:00
Q('dp1keyname').focus();
2019-02-08 07:06:01 +03:00
}
2019-02-08 20:24:00 +03:00
function account_addhkeyValidate(e,action) {
if ((e != null) && (e.keyCode == 13)) { if (action == 2) { dialogclose(1); } else { Q('dp1key').focus(); } }
2019-02-08 07:06:01 +03:00
}
2019-02-08 20:24:00 +03:00
function account_addhkeyEx(button, type) {
2019-02-08 09:30:33 +03:00
var name = Q('dp1keyname').value;
if (name == '') { name = 'MyKey'; }
2019-02-08 20:24:00 +03:00
if (type == 1) {
meshserver.send( { action: 'otp-hkey-setup-request', name: name });
} else if (type == 2) {
meshserver.send( { action: 'otp-hkey-yubikey-add', name: name, otp: Q('dp1key').value });
2019-02-11 03:04:36 +03:00
setDialogMode(2, "Add Security Key", 0, null, "<br />Checking...<br /><br /><br />", 'otpauth-hardware-manage');
2019-02-08 20:24:00 +03:00
}
2019-02-08 07:06:01 +03:00
}
function account_removehkey(index) {
meshserver.send( { action: 'otp-hkey-remove', index: index });
meshserver.send( { action: 'otp-hkey-get' });
}
2017-12-13 03:04:54 +03:00
function account_showVerifyEmail() {
if (xxdialogMode || (userinfo.emailVerified == true) || (serverinfo.emailcheck != true)) return;
var x = "Click ok to send a verification mail to:<br /><div style=padding:8px><b>" + EscapeHtml(userinfo.email) + "</b></div>Please wait a few minute to receive the verification.";
setDialogMode(2, "Email Verification", 3, account_showVerifyEmailEx, x);
}
function account_showVerifyEmailEx() {
2018-02-12 04:13:26 +03:00
meshserver.send( { action: 'verifyemail', email: userinfo.email });
2017-12-13 03:04:54 +03:00
}
function account_showChangeEmail() {
if (xxdialogMode) return;
2018-09-06 03:40:00 +03:00
var x = "Change your account email address here.<br /><br />";
2018-05-17 01:49:12 +03:00
x += addHtmlValue('Email', '<input id=dp2email style=width:230px maxlength=256 onchange=account_validateEmail() onkeyup=account_validateEmail(event) />');
2017-12-13 03:04:54 +03:00
setDialogMode(2, "Email Address Change", 3, account_changeEmail, x);
if (userinfo.email != null) { Q('dp2email').value = userinfo.email; }
account_validateEmail();
2017-12-15 01:57:52 +03:00
Q('dp2email').focus();
2017-12-13 03:04:54 +03:00
}
2018-04-17 01:37:41 +03:00
function account_validateEmail(e, email) {
2018-05-17 01:49:12 +03:00
QE('idx_dlgOkButton', validateEmail(Q('dp2email').value) && (Q('dp2email').value != userinfo.email));
2018-12-21 01:14:37 +03:00
if ((e != null) && (e.keyCode == 13)) { dialogclose(1); }
2017-12-13 03:04:54 +03:00
}
function account_changeEmail() {
2018-02-12 04:13:26 +03:00
meshserver.send( { action: 'changeemail', email: Q('dp2email').value });
2017-12-13 03:04:54 +03:00
}
2017-08-28 19:27:45 +03:00
function account_showDeleteAccount() {
if (xxdialogMode) return;
var x = "To delete this account, type in the account password in both boxes below and hit ok.<br /><br />";
2018-08-24 23:14:20 +03:00
x += "<form action='" + domainUrl + "deleteaccount' method=post><table style=margin-left:80px><tr>";
2017-08-28 19:27:45 +03:00
x += "<td align=right>Password:</td><td><input id=apassword1 type=password name=apassword1 autocomplete=off onchange=account_validateDeleteAccount() onkeyup=account_validateDeleteAccount() /></td>";
2018-05-17 01:49:12 +03:00
x += "</tr><tr><td align=right>Password:</td><td><input id=apassword2 type=password name=apassword2 autocomplete=off onchange=account_validateDeleteAccount() onkeyup=account_validateDeleteAccount() /></td>";
x += '</tr></table><br /><div style=padding:10px;margin-bottom:4px>';
x += '<input id=account_dlgCancelButton type=button value=Cancel style=float:right;width:80px;margin-left:5px onclick=dialogclose(0)>';
x += '<input id=account_dlgOkButton type=submit value=OK style="float:right;width:80px" onclick=dialogclose(1)>';
2017-08-28 19:27:45 +03:00
x += '</div><br /></form>';
setDialogMode(2, "Delete Account", 0, null, x);
account_validateDeleteAccount();
2017-12-15 01:57:52 +03:00
Q('apassword1').focus();
2017-08-28 19:27:45 +03:00
}
function account_showChangePassword() {
if (xxdialogMode) return;
2019-02-13 06:23:40 +03:00
var x = "Change your account password by entering the old password and new password twice in the boxes below. Password hint can be used but is not recommanded.<br /><br />";
//x += "<form action='" + domainUrl + "changepassword' method=post>";
x += "<table style=margin-left:60px>";
x += "<tr><td align=right>Old password:</td><td><input id=apassword0 type=password name=apassword0 autocomplete=off onchange=account_validateNewPassword() onkeyup=account_validateNewPassword() onkeydown=account_validateNewPassword() /> <b></b></td></tr>";
x += "<tr><td align=right>New password:</td><td><input id=apassword1 type=password name=apassword1 autocomplete=off onchange=account_validateNewPassword() onkeyup=account_validateNewPassword() onkeydown=account_validateNewPassword() /> <b><span id=dxPassWarn></span></b></td></tr>";
x += "<tr><td align=right>New password:</td><td><input id=apassword2 type=password name=apassword2 autocomplete=off onchange=account_validateNewPassword() onkeyup=account_validateNewPassword() onkeydown=account_validateNewPassword() /></td></tr>";
x += "<tr><td align=right>Password hint:</td><td><input id=apasswordhint name=apasswordhint maxlength=250 type=text autocomplete=off onchange=account_validateNewPassword() onkeyup=account_validateNewPassword() onkeydown=account_validateNewPassword() /></td></tr>";
x += '</table>'
if (passRequirements) { var r = []; for (var i in passRequirements) { r.push(i + ':' + passRequirements[i]); } x += '<br /><span style=font-size:x-small>Requirements: ' + r.join(', ') + '.</span>'; }
x += '<br />';
//x += '<br /><div style=padding:10px;margin-bottom:4px>';
//x += '<input id=account_dlgCancelButton type=button value=Cancel style=float:right;width:80px;margin-left:5px onclick=dialogclose(0)>';
//x += '<input id=account_dlgOkButton type=submit value=OK style="float:right;width:80px" onclick=dialogclose(1)>';
//x += '</div><br /></form>';
setDialogMode(2, "Change Password", 3, account_showChangePasswordEx, x);
Q('apassword0').focus();
2018-12-21 01:14:37 +03:00
account_validateNewPassword();
2017-08-28 19:27:45 +03:00
}
2019-02-13 06:23:40 +03:00
function account_showChangePasswordEx() {
if (Q('apassword1').value == Q('apassword2').value) {
meshserver.send( { action: 'changepassword', oldpass: Q('apassword0').value, newpass: Q('apassword1').value, hint: Q('apasswordhint').value });
}
}
2017-08-28 19:27:45 +03:00
function account_createMesh() {
if (xxdialogMode) return;
2019-01-16 23:04:48 +03:00
// Check if we are allowed to create a new device group
2019-02-21 02:26:27 +03:00
if ((userinfo.emailVerified !== true) && (serverinfo.emailcheck == true) && (userinfo.siteadmin != 0xFFFFFFFF)) { setDialogMode(2, "New Device Group", 1, null, "Unable to create a new device group until a email address is verified. This is required for password recovery. Go to the \"My Account\" tab to change and verify an email address."); return; }
2019-01-16 23:04:48 +03:00
// We are allowed, let's prompt to information
2018-09-25 03:47:03 +03:00
var x = "Create a new device group using the options below.<br /><br />";
x += addHtmlValue('Name', '<input id=dp2meshname style=width:230px maxlength=64 onchange=account_validateMeshCreate() onkeyup=account_validateMeshCreate() />');
x += addHtmlValue('Type', '<div style=width:230px;margin:0;padding:0><select id=dp2meshtype style=width:100% onchange=account_validateMeshCreate() ><option value=2>Manage using a software agent</option><option value=1>Intel® AMT only, no agent</option></select></div>');
2017-08-28 19:27:45 +03:00
x += addHtmlValue('Description', '<div style=width:230px;margin:0;padding:0><textarea id=dp2meshdesc maxlength=1024 style=width:100%;resize:none></textarea></div>');
2018-09-25 03:47:03 +03:00
setDialogMode(2, "New Device Group", 3, account_createMeshEx, x);
2017-08-28 19:27:45 +03:00
account_validateMeshCreate();
2017-12-15 01:57:52 +03:00
Q('dp2meshname').focus();
2017-08-28 19:27:45 +03:00
}
function account_validateMeshCreate() {
QE('idx_dlgOkButton', Q('dp2meshname').value.length > 0);
}
function account_createMeshEx(button, tag) {
2018-02-12 04:13:26 +03:00
meshserver.send( { action: 'createmesh', meshname: Q('dp2meshname').value, meshtype: Q('dp2meshtype').value, desc: Q('dp2meshdesc').value });
2017-08-28 19:27:45 +03:00
}
function account_validateDeleteAccount() {
QE('account_dlgOkButton', (Q('apassword1').value.length > 0) && (Q('apassword1').value == Q('apassword2').value));
}
function account_validateNewPassword() {
2019-02-13 06:23:40 +03:00
var r = '', ok = (Q('apassword0').value.length > 0) && (Q('apassword1').value.length > 0) && (Q('apassword1').value == Q('apassword2').value) && (Q('apassword0').value != Q('apassword1').value) && (Q('apasswordhint').value != Q('apassword1').value);
2017-08-28 19:27:45 +03:00
if (Q('apassword1').value != '') {
2018-12-21 01:14:37 +03:00
if (passRequirements == null || passRequirements == '') {
// No password requirements, display password strength
var passStrength = checkPasswordStrength(Q('apassword1').value);
if (passStrength >= 80) { r = '<span style=color:green>Strong<span>'; } else if (passStrength >= 60) { r = '<span style=color:blue>Good<span>'; } else { r = '<span style=color:red>Weak<span>'; }
} else {
// Password requirements provided, use that
var passReq = checkPasswordRequirements(Q('apassword1').value, passRequirements);
if (passReq == false) { ok = false; r = '<span style=color:red>Policy<span>' }
}
2017-08-28 19:27:45 +03:00
}
QH('dxPassWarn', r);
2019-02-13 06:23:40 +03:00
//QE('account_dlgOkButton', ok);
QE('idx_dlgOkButton', ok);
2017-08-28 19:27:45 +03:00
}
// Return a password strength score
function checkPasswordStrength(password) {
var r = 0, letters = { }, varCount = 0, variations = { digits: /\d/.test(password), lower: /[a-z]/.test(password), upper: /[A-Z]/.test(password), nonWords: /\W/.test(password) }
if (!password) return 0;
for (var i = 0; i< password.length; i++) { letters[password[i]] = (letters[password[i]] || 0) + 1; r += 5.0 / letters[password[i]]; }
for (var c in variations) { varCount += (variations[c] == true) ? 1 : 0; }
return parseInt(r + (varCount - 1) * 10);
}
2018-12-21 01:14:37 +03:00
// Check password requirements
function checkPasswordRequirements(password, requirements) {
if ((requirements == null) || (requirements == '') || (typeof requirements != 'object')) return true;
if (requirements.min) { if (password.length < requirements.min) return false; }
if (requirements.max) { if (password.length > requirements.max) return false; }
var num = 0, lower = 0, upper = 0, nonalpha = 0;
for (var i = 0; i < password.length; i++) {
if (/\d/.test(password[i])) { num++; }
if (/[a-z]/.test(password[i])) { lower++; }
if (/[A-Z]/.test(password[i])) { upper++; }
if (/\W/.test(password[i])) { nonalpha++; }
}
if (requirements.num && (num < requirements.num)) return false;
if (requirements.lower && (lower < requirements.lower)) return false;
if (requirements.upper && (upper < requirements.upper)) return false;
if (requirements.nonalpha && (nonalpha < requirements.nonalpha)) return false;
return true;
}
2017-08-28 19:27:45 +03:00
function updateMeshes() {
2018-03-07 04:50:44 +03:00
var r = '';
2017-08-28 19:27:45 +03:00
var c = 0, count = 0;
for (i in meshes) {
// Mesh positioning
if (c > 1) { r += '</tr><tr>'; c = 0; }
c++;
count++;
2018-03-27 03:13:32 +03:00
// Mesh rights
2019-01-25 04:01:50 +03:00
var meshrights = 0;
if (meshes[i].links['user/' + domain + '/' + userinfo.name.toLowerCase()]) { meshrights = meshes[i].links['user/' + domain + '/' + userinfo.name.toLowerCase()].rights; }
2018-03-27 03:13:32 +03:00
var rights = 'Partial Rights';
if (meshrights == 0xFFFFFFFF) rights = 'Full Administrator'; else if (meshrights == 0) rights = 'No Rights';
// Print the mesh information
2018-11-13 05:36:20 +03:00
r += '<div onmouseover=devMouseHover(this,1) onmouseout=devMouseHover(this,0) style=display:inline-block;width:431px;height:50px;padding-top:1px;padding-bottom:1px;float:left><div style=float:left;width:30px;height:100%></div><div style=height:100%;cursor:pointer onclick=gotoMesh(\'' + i + '\')><div class=mi style=float:left;width:50px;height:50px></div><div style=height:100%><div class=g1></div><div class=e2 style=width:300px><div class=e1>' + EscapeHtml(meshes[i].name) + '</div><div>' + rights + '</div></div><div class=g2 style=float:left></div></div></div></div>';
2017-08-28 19:27:45 +03:00
}
2017-10-03 00:12:29 +03:00
meshcount = count;
2017-08-28 19:27:45 +03:00
QH('p2meshes', r);
QV('p2noMeshFound', count == 0);
}
function gotoMesh(meshid) {
currentMesh = meshes[meshid];
p20updateMesh();
go(20);
}
function server_showRestoreDlg() {
if (xxdialogMode) return;
var x = 'Restore the server using a backup, <span style=color:red>this will delete the existing server data</span>. Only do this if you know what you are doing.<br /><br />';
x += '<form action="/restoreserver.ashx" enctype="multipart/form-data" method="post"><div>';
x += '<input id=account_dlgFileInput type=file name=datafile style=width:100% accept=".zip,application/octet-stream,application/zip,application/x-zip,application/x-zip-compressed" onchange=account_validateServerRestore()>';
x += '<input id=account_dlgCancelButton type=button value=Cancel style=float:right;width:80px;margin-left:5px onclick=dialogclose(0)>';
x += '<input id=account_dlgOkButton type=submit value=OK style=float:right;width:80px onclick=dialogclose(1)>';
x += '</div><br /><br /></form>';
setDialogMode(2, "Restore Server", 0, null, x);
account_validateServerRestore();
}
function account_validateServerRestore() {
QE('account_dlgOkButton', Q('account_dlgFileInput').files.length == 1);
}
function server_showVersionDlg() {
if (xxdialogMode) return;
2017-09-07 04:10:24 +03:00
setDialogMode(2, "MeshCentral Version", 1, null, "Loading...", 'MeshCentralServerUpdate');
2018-02-12 04:13:26 +03:00
meshserver.send( { action: 'serverversion' });
2017-08-28 19:27:45 +03:00
}
2018-04-29 01:36:10 +03:00
function server_showVersionDlgUpdate() { QE('idx_dlgOkButton', Q('d2updateCheck').checked); }
function server_showVersionDlgEx() { meshserver.send( { action: 'serverupdate' }); }
2017-09-07 04:10:24 +03:00
2018-09-19 05:41:59 +03:00
function server_showErrorsDlg() {
if (xxdialogMode) return;
setDialogMode(2, "MeshCentral Errors", 1, null, "Loading...", 'MeshCentralServerErrors');
meshserver.send( { action: 'servererrors' });
}
function server_showErrorsDlgUpdate() { QE('idx_dlgOkButton', Q('d2updateCheck').checked); }
function server_showErrorsDlgEx() { meshserver.send( { action: 'serverclearerrorlog' }); }
2017-08-28 19:27:45 +03:00
//
// MY MESHS
//
var currentMesh;
function p20updateMesh() {
2018-06-05 23:28:07 +03:00
if (currentMesh == null) return;
2017-08-28 19:27:45 +03:00
QH('p20meshName', EscapeHtml(currentMesh.name));
var meshtype = 'Unknown #' + currentMesh.mtype;
2019-02-25 22:13:13 +03:00
var meshrights = 0;
try { meshrights = currentMesh.links['user/' + domain + '/' + userinfo.name.toLowerCase()].rights; } catch (ex) { }
2018-09-25 03:47:03 +03:00
if (currentMesh.mtype == 1) meshtype = 'Intel® AMT only, no agent';
if (currentMesh.mtype == 2) meshtype = 'Managed using a software agent';
2017-08-28 19:27:45 +03:00
var x = '';
2017-12-15 01:57:52 +03:00
x += addHtmlValue('Name', addLinkConditional(EscapeHtml(currentMesh.name), 'p20editmesh(1)', (meshrights & 1) != 0));
x += addHtmlValue('Description', addLinkConditional(((currentMesh.desc && currentMesh.desc != '')?EscapeHtml(currentMesh.desc):'<i>None</i>'), 'p20editmesh(2)', (meshrights & 1) != 0));
2018-09-27 00:58:55 +03:00
// Display features
var meshFeatures = [];
if (currentMesh.flags) { if (currentMesh.flags & 1) { meshFeatures.push('Auto-Remove'); } }
meshFeatures = meshFeatures.join(', ');
if (meshFeatures == '') { meshFeatures = '<i>None</i>'; }
x += addHtmlValue('Features', addLinkConditional(meshFeatures, 'p20editmeshfeatures()', (meshrights & 1) != 0));
// Display group type
2017-08-28 19:27:45 +03:00
x += addHtmlValue('Type', meshtype);
2018-09-27 00:58:55 +03:00
//x += addHtmlValue('Identifier', currentMesh._id.split('/')[2]);
2017-08-28 19:27:45 +03:00
2019-02-08 02:00:10 +03:00
// Intel AMT setup
if (currentMesh.mtype == 2) {
var intelAmtPolicy = 'No Policy';
if (currentMesh.amt) {
if (currentMesh.amt.type == 1) { intelAmtPolicy = 'Deactivate Client Control Mode (CCM)'; }
else if (currentMesh.amt.type == 2) {
intelAmtPolicy = 'Simple Client Control Mode (CCM)';
if (currentMesh.amt.cirasetup == 2) { intelAmtPolicy += ' + CIRA'; }
}
}
x += addHtmlValue('Intel® AMT', addLinkConditional(intelAmtPolicy, 'p20editMeshAmt()', (meshrights & 0xFFFFFFFF) != 0));
}
2018-09-27 00:58:55 +03:00
// Display group note support
2018-11-03 04:13:32 +03:00
if (meshrights & 1) { x += '<br><input type=button value=Notes title="View notes about this device group" onclick=showNotes(false,"' + encodeURIComponent(currentMesh._id) + '") />'; }
2018-04-16 21:57:42 +03:00
2018-04-20 04:19:15 +03:00
x += '<br style=clear:both><br>';
2018-08-24 23:14:20 +03:00
var currentMeshLinks = currentMesh.links['user/' + domain + '/' + userinfo.name.toLowerCase()];
2017-08-28 19:27:45 +03:00
if (currentMeshLinks && ((currentMeshLinks.rights & 2) != 0)) { x += '<a onclick=p20showAddMeshUserDialog() style=cursor:pointer;margin-right:10px><img src=images/icon-addnew.png border=0 height=12 width=12> Add User</a>'; }
if ((meshrights & 4) != 0) {
if (currentMesh.mtype == 1) {
x += '<a onclick=addCiraDeviceToMesh(\"' + currentMesh._id + '\") style=cursor:pointer;margin-right:10px title="Add a new Intel® AMT computer that is located on the internet."><img src=images/icon-installmesh.png border=0 height=12 width=12> Install CIRA</a>';
x += '<a onclick=addDeviceToMesh(\"' + currentMesh._id + '\") style=cursor:pointer;margin-right:10px title="Add a new Intel® AMT computer that is located on the local network."><img src=images/icon-installmesh.png border=0 height=12 width=12> Install local</a>';
}
if (currentMesh.mtype == 2) {
x += '<a onclick=addAgentToMesh(\"' + currentMesh._id + '\") style=cursor:pointer;margin-right:10px title="Add a new computer to this mesh by installing the mesh agent."><img src=images/icon-addnew.png border=0 height=12 width=12> Install</a>';
2018-09-06 03:40:00 +03:00
if (features & 64) {
x += '<a onclick=inviteAgentToMesh(\"' + currentMesh._id + '\") style=cursor:pointer;margin-right:10px title="Invite someone to install the mesh agent on this mesh."><img src=images/icon-addnew.png border=0 height=12 width=12> Invite</a>';
}
2017-08-28 19:27:45 +03:00
}
}
/*
function getMeshActions(mesh, meshrights) {
if ((meshrights & 4) == 0) return '';
var r = '';
if (mesh.mtype == 1) {
r += ' <a style=cursor:pointer;font-size:10px title="Add a new Intel® AMT computer that is located on the internet." onclick=addCiraDeviceToMesh(\"' + mesh._id + '\")>Add CIRA</a>';
r += ' <a style=cursor:pointer;font-size:10px title="Add a new Intel® AMT computer that is located on the local network." onclick=addDeviceToMesh(\"' + mesh._id + '\")>Add Local</a>';
}
if (mesh.mtype == 2) {
r += ' <a style=cursor:pointer;font-size:10px title="Add a new computer to this mesh by installing the mesh agent." onclick=addAgentToMesh(\"' + mesh._id + '\")>Add Agent</a>';
}
return r;
}
*/
x += '<table style="color:black;background-color:#EEE;border-color:#AAA;border-width:1px;border-style:solid;border-collapse:collapse" border=0 cellpadding=2 cellspacing=0 width=100%><tbody><tr style=background-color:#AAAAAA;font-weight:bold><th scope=col style=text-align:left;width:430px>User Authorizations</th><th scope=col style=text-align:left></th></tr>';
2018-05-17 01:49:12 +03:00
// Sort the users for this mesh
var count = 1, sortedusers = [];
for (var i in currentMesh.links) { sortedusers.push( { id: i, name: i.split('/')[2], rights: currentMesh.links[i].rights }); }
sortedusers.sort(function(a, b) { if (a.name > b.name) return 1; if (a.name < b.name) return -1; return 0; });
// Display all users for this mesh
for (var i in sortedusers) {
var trash = '', rights = 'Partial Rights', r = sortedusers[i].rights;
2017-08-28 19:27:45 +03:00
if (r == 0xFFFFFFFF) rights = 'Full Administrator'; else if (r == 0) rights = 'No Rights';
2018-05-17 01:49:12 +03:00
if ((i != userinfo._id) && (meshrights == 0xFFFFFFFF || (((meshrights & 2) != 0)))) { trash = '<a onclick=p20deleteUser(event,"' + encodeURIComponent(sortedusers[i].id) + '") title="Remote user rights to this mesh" style=cursor:pointer><img src=images/trash.png border=0 height=10 width=10></a>'; }
2019-02-27 04:08:55 +03:00
x += '<tr onclick=p20viewuser("' + encodeURIComponent(sortedusers[i].id) + '") style=cursor:pointer' + (((count % 2) == 0) ? ';background-color:#DDD' : '') + '><td><div title="User" class=m2></div><div> ' + EscapeHtml(decodeURIComponent(sortedusers[i].name)) + '<div></div></div></td><td><div style=float:right>' + trash + '</div><div>' + rights + '</div></td></tr>';
2017-08-28 19:27:45 +03:00
++count;
}
x += '</tbody></table>';
// If we are full administrator on this mesh, allow deletion of the mesh
2019-02-12 05:02:07 +03:00
if (meshrights == 0xFFFFFFFF) { x += '<div style=font-size:x-small;text-align:right><span><a onclick=p20showDeleteMeshDialog() style=cursor:pointer>Delete Group</a></span></div>'; }
2017-08-28 19:27:45 +03:00
QH('p20info', x);
}
2019-02-08 02:00:10 +03:00
function p20editMeshAmt() {
if (xxdialogMode) return;
var x = '';
x += addHtmlValue('Type', '<select id=dp20amtpolicy style=width:230px onchange=p20editMeshAmtChange()><option value=0>No Policy</option><option value=1>Deactivate Client Control Mode (CCM)</option><option value=2>Simple Client Control Mode (CCM)</option></select>');
x += '<div id=dp20amtpolicydiv></div>';
setDialogMode(2, "Intel® AMT Policy", 3, p20editMeshAmtEx, x);
if (currentMesh.amt) { Q('dp20amtpolicy').value = currentMesh.amt.type; }
p20editMeshAmtChange();
// Set the current Intel AMT policy
if (currentMesh.amt && currentMesh.amt.type == 2) {
Q('dp20amtpolicypass').value = currentMesh.amt.password;
Q('dp20amtbadpass').value = currentMesh.amt.badpass;
Q('dp20amtcira').value = currentMesh.amt.cirasetup;
}
dp20amtValidatePolicy();
}
function p20editMeshAmtChange() {
var ptype = Q('dp20amtpolicy').value, x = '';
if (ptype == 2) {
x = addHtmlValue('Password*', '<input id=dp20amtpolicypass style=width:230px maxlength=32 onchange=dp20amtValidatePolicy() onkeyup=dp20amtValidatePolicy() />')
x += addHtmlValue('Password mismatch', "<select id=dp20amtbadpass style=width:230px><option value=0>Do nothing</option><option value=1>Reactivate Intel® AMT</option></select>");
x += addHtmlValue('<span title="Client Initiated Remote Access">CIRA</span>', "<select id=dp20amtcira style=width:230px><option value=0>Don't configure</option><option value=1>Don't connect to server</option><option value=2>Connect to server</option></select>");
x += '<br/><span style="font-size:10px">* Recommanded, leave blank to assign a random password to each device.</span><br/>';
x += '<span style="font-size:10px">This policy will not impact devices with Intel® AMT in ACM mode.</span><br/>';
x += '<span style="font-size:10px">This is not a secure policy as agents will be performing activation.</span>';
}
QH('dp20amtpolicydiv', x);
}
function dp20amtValidatePolicy() {
var ok = true, ptype = Q('dp20amtpolicy').value;
if (ptype == 2) { var pass = Q('dp20amtpolicypass').value; ok = (pass == '') ? true : passwordcheck(pass); }
QE('idx_dlgOkButton', ok);
}
function p20editMeshAmtEx() {
var ptype = parseInt(Q('dp20amtpolicy').value), amtpolicy = { type: ptype };
if (ptype == 2) { amtpolicy = { type: ptype, password: Q('dp20amtpolicypass').value, badpass: parseInt(Q('dp20amtbadpass').value), cirasetup: parseInt(Q('dp20amtcira').value) }; }
meshserver.send( { action: 'meshamtpolicy', meshid: currentMesh._id, amtpolicy: amtpolicy });
}
2017-08-28 19:27:45 +03:00
function p20showDeleteMeshDialog() {
if (xxdialogMode) return;
2019-02-12 05:02:07 +03:00
var x = "Are you sure you want to delete group \"" + EscapeHtml(currentMesh.name) + "\"? Deleting the device group will also delete all information about devices within this group.<br /><br />";
2017-08-28 19:27:45 +03:00
x += "<input id=p20check type=checkbox onchange=p20validateDeleteMeshDialog() />Confirm";
2019-02-12 05:02:07 +03:00
setDialogMode(2, "Delete Group", 3, p20showDeleteMeshDialogEx, x);
2017-08-28 19:27:45 +03:00
p20validateDeleteMeshDialog();
}
function p20validateDeleteMeshDialog() {
QE('idx_dlgOkButton', Q('p20check').checked);
}
function p20showDeleteMeshDialogEx(buttons, tag) {
2018-02-12 04:13:26 +03:00
meshserver.send( { action: 'deletemesh', meshid: currentMesh._id, meshname: currentMesh.name });
2017-08-28 19:27:45 +03:00
}
2017-12-15 01:57:52 +03:00
function p20editmesh(focus) {
2017-08-28 19:27:45 +03:00
if (xxdialogMode) return;
2018-09-25 03:47:03 +03:00
var x = addHtmlValue('Name', '<input id=dp20meshname style=width:230px maxlength=32 onchange=p20editmeshValidate() onkeyup=p20editmeshValidate() />');
2017-08-28 19:27:45 +03:00
x += addHtmlValue('Description', '<div style=width:230px;margin:0;padding:0><textarea id=dp20meshdesc maxlength=1024 style=width:100%;resize:none></textarea></div>');
2018-09-25 03:47:03 +03:00
setDialogMode(2, "Edit Device Group", 3, p20editmeshEx, x);
2017-08-28 19:27:45 +03:00
Q('dp20meshname').value = currentMesh.name;
if (currentMesh.desc) Q('dp20meshdesc').value = currentMesh.desc;
p20editmeshValidate();
2017-12-15 01:57:52 +03:00
if (focus == 2) { Q('dp20meshdesc').focus(); } else { Q('dp20meshname').focus(); }
2017-08-28 19:27:45 +03:00
}
function p20editmeshEx() {
2018-02-12 04:13:26 +03:00
meshserver.send( { action: 'editmesh', meshid: currentMesh._id, meshname: Q('dp20meshname').value, desc: Q('dp20meshdesc').value });
2017-08-28 19:27:45 +03:00
}
function p20editmeshValidate() {
QE('idx_dlgOkButton', Q('dp20meshname').value.length > 0);
}
2018-09-27 00:58:55 +03:00
function p20editmeshfeatures() {
if (xxdialogMode) return;
var flags = (currentMesh.flags)?currentMesh.flags:0;
var x = "<div><input type=checkbox id=d20flag1 " + ((flags & 1)?'checked':'') + ">Remove device on disconnect<br></div>";
setDialogMode(2, "Edit Device Group Features", 3, p20editmeshfeaturesEx, x);
}
function p20editmeshfeaturesEx() {
var flags = 0;
if (Q('d20flag1').checked) { flags += 1; }
meshserver.send( { action: 'editmesh', meshid: currentMesh._id, flags: flags });
}
2017-08-28 19:27:45 +03:00
function p20showAddMeshUserDialog() {
if (xxdialogMode) return;
2018-09-25 03:47:03 +03:00
var x = "Allow a user to manage this device group and devices in this group<br /><br />";
2017-08-28 19:27:45 +03:00
x += addHtmlValue('User Name', '<input id=dp20username style=width:230px maxlength=32 onchange=p20validateAddMeshUserDialog() onkeyup=p20validateAddMeshUserDialog() />');
2019-02-27 04:08:55 +03:00
x += '<br><div style="height:120px;overflow-y:scroll;border:1px solid gray">';
2017-08-28 19:27:45 +03:00
x += '<input type=checkbox onchange=p20validateAddMeshUserDialog() id=p20fulladmin>Full Administrator<br>';
2018-09-27 03:29:12 +03:00
x += '<input type=checkbox onchange=p20validateAddMeshUserDialog() id=p20editmesh>Edit Device Group<br>';
x += '<input type=checkbox onchange=p20validateAddMeshUserDialog() id=p20manageusers>Manage Device Group Users<br>';
x += '<input type=checkbox onchange=p20validateAddMeshUserDialog() id=p20managecomputers>Manage Device Group Computers<br>';
2017-08-28 19:27:45 +03:00
x += '<input type=checkbox onchange=p20validateAddMeshUserDialog() id=p20remotecontrol>Remote Control<br>';
2019-02-27 04:08:55 +03:00
x += '<input type=checkbox onchange=p20validateAddMeshUserDialog() id=p20remoteview style=margin-left:12px>Remote View Only<br>';
x += '<input type=checkbox onchange=p20validateAddMeshUserDialog() id=p20noterminal style=margin-left:12px>No Terminal Access<br>';
x += '<input type=checkbox onchange=p20validateAddMeshUserDialog() id=p20nofiles style=margin-left:12px>No File Access<br>';
x += '<input type=checkbox onchange=p20validateAddMeshUserDialog() id=p20noamt style=margin-left:12px>No Intel® AMT<br>';
2017-08-28 19:27:45 +03:00
x += '<input type=checkbox onchange=p20validateAddMeshUserDialog() id=p20meshagentconsole>Mesh Agent Console<br>';
x += '<input type=checkbox onchange=p20validateAddMeshUserDialog() id=p20meshserverfiles>Server Files<br>';
x += '<input type=checkbox onchange=p20validateAddMeshUserDialog() id=p20wakedevices>Wake Devices<br>';
2018-04-16 21:57:42 +03:00
x += '<input type=checkbox onchange=p20validateAddMeshUserDialog() id=p20editnotes>Edit Device Notes<br>';
2017-08-28 19:27:45 +03:00
x += '</div>';
2018-09-25 03:47:03 +03:00
setDialogMode(2, "Add User to Device Group", 3, p20showAddMeshUserDialogEx, x);
2017-08-28 19:27:45 +03:00
p20validateAddMeshUserDialog();
2017-12-15 01:57:52 +03:00
Q('dp20username').focus();
2017-08-28 19:27:45 +03:00
}
function p20validateAddMeshUserDialog() {
2018-08-24 23:14:20 +03:00
var meshrights = currentMesh.links['user/' + domain + '/' + userinfo.name.toLowerCase()].rights;
2017-08-28 19:27:45 +03:00
QE('idx_dlgOkButton', (Q('dp20username').value.length > 0));
QE('p20fulladmin', meshrights == 0xFFFFFFFF);
QE('p20editmesh', (!Q('p20fulladmin').checked) && (meshrights == 0xFFFFFFFF));
QE('p20manageusers', !Q('p20fulladmin').checked);
QE('p20managecomputers', !Q('p20fulladmin').checked);
QE('p20remotecontrol', !Q('p20fulladmin').checked);
QE('p20meshagentconsole', !Q('p20fulladmin').checked);
QE('p20meshserverfiles', !Q('p20fulladmin').checked);
QE('p20wakedevices', !Q('p20fulladmin').checked);
2018-04-13 04:14:03 +03:00
QE('p20editnotes', !Q('p20fulladmin').checked);
2019-02-27 04:08:55 +03:00
QE('p20remoteview', !Q('p20fulladmin').checked && Q('p20remotecontrol').checked);
QE('p20noterminal', !Q('p20fulladmin').checked && Q('p20remotecontrol').checked);
QE('p20nofiles', !Q('p20fulladmin').checked && Q('p20remotecontrol').checked);
QE('p20noamt', !Q('p20fulladmin').checked && Q('p20remotecontrol').checked);
2017-08-28 19:27:45 +03:00
}
function p20showAddMeshUserDialogEx() {
var meshadmin = 0;
if (Q('p20fulladmin').checked == true) { meshadmin = 0xFFFFFFFF; } else {
if (Q('p20editmesh').checked == true) meshadmin += 1;
if (Q('p20manageusers').checked == true) meshadmin += 2;
if (Q('p20managecomputers').checked == true) meshadmin += 4;
if (Q('p20remotecontrol').checked == true) meshadmin += 8;
if (Q('p20meshagentconsole').checked == true) meshadmin += 16;
if (Q('p20meshserverfiles').checked == true) meshadmin += 32;
if (Q('p20wakedevices').checked == true) meshadmin += 64;
2018-04-13 04:14:03 +03:00
if (Q('p20editnotes').checked == true) meshadmin += 128;
2018-11-03 04:13:32 +03:00
if (Q('p20remoteview').checked == true) meshadmin += 256;
2019-02-27 04:08:55 +03:00
if (Q('p20noterminal').checked == true) meshadmin += 512;
if (Q('p20nofiles').checked == true) meshadmin += 1024;
if (Q('p20noamt').checked == true) meshadmin += 2048;
2017-08-28 19:27:45 +03:00
}
2018-02-12 04:13:26 +03:00
meshserver.send( { action: 'addmeshuser', meshid: currentMesh._id, meshname: currentMesh.name, username: Q('dp20username').value , meshadmin: meshadmin});
2017-08-28 19:27:45 +03:00
}
function p20viewuser(userid) {
if (xxdialogMode) return;
2018-05-17 01:49:12 +03:00
userid = decodeURIComponent(userid);
2018-08-24 23:14:20 +03:00
var r = '', cmeshrights = currentMesh.links['user/' + domain + '/' + userinfo.name.toLowerCase()].rights, meshrights = currentMesh.links[userid].rights;
2017-08-28 19:27:45 +03:00
if (meshrights == 0xFFFFFFFF) r = ', Full Administrator (all rights)'; else {
2019-02-27 04:08:55 +03:00
if ((meshrights & 1) != 0) r += ', Edit Device Group';
if ((meshrights & 2) != 0) r += ', Manage Device Group Users';
if ((meshrights & 4) != 0) r += ', Manage Device Group Computers';
if ((meshrights & 8) != 0) r += ', Remote Control';
if ((meshrights & 16) != 0) r += ', Agent Console';
if ((meshrights & 32) != 0) r += ', Server Files';
if ((meshrights & 64) != 0) r += ', Wake Devices';
if ((meshrights & 128) != 0) r += ', Edit Notes';
if ((meshrights & 256) != 0) r += ', Remote View Only';
if ((meshrights & 512) != 0) r += ', No Terminal';
if ((meshrights & 1024) != 0) r += ', No Files';
if ((meshrights & 2048) != 0) r += ', No Intel® AMT';
2017-08-28 19:27:45 +03:00
}
r = r.substring(2);
2018-03-27 03:13:32 +03:00
if (r == '') { r = 'No Rights'; }
2019-02-27 04:08:55 +03:00
var buttons = 1, x = addHtmlValue('User Name', EscapeHtml(decodeURIComponent(userid.split('/')[2])));
2017-08-28 19:27:45 +03:00
x += addHtmlValue('Permissions', r);
2018-08-24 23:14:20 +03:00
if ((('user/' + domain + '/' + userinfo.name.toLowerCase()) != userid) && (cmeshrights == 0xFFFFFFFF || (((cmeshrights & 2) != 0) && (meshrights != 0xFFFFFFFF)))) buttons += 4;
2018-09-25 03:47:03 +03:00
setDialogMode(2, "Device Group User", buttons, p20viewuserEx, x, userid);
2017-08-28 19:27:45 +03:00
}
2018-05-17 01:49:12 +03:00
function p20viewuserEx(button, userid) { if (button != 2) return; setDialogMode(2, "Remote Mesh User", 3, p20viewuserEx2, "Confirm removal of user " + userid.split('/')[2] + "?", userid); }
function p20deleteUser(e, userid) { haltEvent(e); p20viewuserEx(2, decodeURIComponent(userid)); }
function p20viewuserEx2(button, userid) { meshserver.send( { action: 'removemeshuser', meshid: currentMesh._id, meshname: currentMesh.name, userid: userid}); }
2017-08-28 19:27:45 +03:00
//
// MY FILES
//
var filetreelinkpath;
var filetreelocation = [];
function updateFiles() {
QV('MainMenuMyFiles', ((features & 8) == 0));
if ((features & 8) != 0) return; // If running on a server without files, exit now.
var html1 = '', html2 = '', displayPath = '<a style=cursor:pointer onclick=p5folderup(0)>Root</a>', fullPath = 'Root', publicPath, filetreex = filetree, folderdepth = 1;
// Navigate to path location, build the paths at the same time
var filetreelocation2 = [], oldlinkpath = filetreelinkpath, checkedBoxes = [], checkboxes = document.getElementsByName('fc');
for (var i = 0; i < checkboxes.length; i++) { if (checkboxes[i].checked) { checkedBoxes.push(checkboxes[i].value) }; } // Save all existing checked boxes
filetreelinkpath = '';
for (var i in filetreelocation) {
2017-12-14 01:52:57 +03:00
if ((filetreex.f != null) && (filetreex.f[filetreelocation[i]] != null)) {
2017-08-28 19:27:45 +03:00
filetreelocation2.push(filetreelocation[i]);
fullPath += ' / ' + filetreelocation[i];
if ((folderdepth == 1)) {
var sp = filetreelocation[i].split('/');
publicPath = window.location + sp[0] + 'files/' + sp[2];
//if (filetreelocation[i] === userinfo._id) { filetreelinkpath += 'self'; } else { filetreelinkpath += (sp[0] + '/' + sp[2]); }
filetreelinkpath += filetreelocation[i];
} else {
if (filetreelinkpath != '') { filetreelinkpath += '/' + filetreelocation[i]; if (folderdepth > 2) { publicPath += '/' + filetreelocation[i]; } }
}
filetreex = filetreex.f[filetreelocation[i]];
2017-12-14 01:52:57 +03:00
displayPath += ' / <a style=cursor:pointer onclick=p5folderup(' + folderdepth + ')>' + (filetreex.n != null?filetreex.n:filetreelocation[i]) + '</a>';
2017-08-28 19:27:45 +03:00
folderdepth++;
} else {
break;
}
}
filetreelocation = filetreelocation2; // In case we could not go down the full path, we set the new path location here.
var publicfolder = fullPath.toLowerCase().startsWith("root / " + userinfo._id + " / public");
// Sort the files
var filetreexx = p5sort_files(filetreex.f);
// Display all files and folders at this location
for (var i in filetreexx) {
// Figure out the name and shortname
var f = filetreexx[i], name = f.n, shortname;
shortname = name;
if (name.length > 70) { shortname = '<span title="' + EscapeHtml(name) + '">' + EscapeHtml(name.substring(0, 70)) + "...</span>"; } else { shortname = EscapeHtml(name); }
name = EscapeHtml(name);
// Figure out the date
var fdatestr = '';
2017-12-14 01:52:57 +03:00
if (f.d != null) { var fdate = new Date(f.d), fdatestr = (fdate.getMonth() + 1) + "/" + (fdate.getDate()) + "/" + fdate.getFullYear() + " " + fdate.toLocaleTimeString() + " "; }
2017-08-28 19:27:45 +03:00
// Figure out the size
var fsize = '';
2017-12-14 01:52:57 +03:00
if (f.s != null) { fsize = getFileSizeStr(f.s); }
2017-08-28 19:27:45 +03:00
var h = '';
2018-06-19 22:25:57 +03:00
if (f.t < 3 || f.t == 4) {
var right = (f.t == 1 || f.t == 4)?p5getQuotabar(f):'', title = '';
2019-02-06 06:07:12 +03:00
h = "<div class=filelist file=999><input file=999 style=float:left name=fc class=fcb type=checkbox onchange=p5setActions() value='" + name + "'> <span style=float:right title=\"" + title + "\">" + right + "</span><span><div class=fileIcon" + f.t + " onclick=p5folderset(\"" + encodeURIComponent(f.nx) + "\")></div><a style=cursor:pointer onclick=p5folderset(\"" + encodeURIComponent(f.nx) + "\")>" + shortname + "</a></span></div>";
2017-08-28 19:27:45 +03:00
} else {
var link = shortname;
var publiclink = '';
if (publicfolder) { publiclink = ' (<a style=cursor:pointer title=\"Display public link\" onclick=\'p5showPublicLink(\"' + publicPath + '/' + f.nx + '\")\'>Link</a>)'; }
2019-01-05 04:59:13 +03:00
if (f.s > 0) { link = "<a rel=\"noreferrer noopener\" target=\"_blank\" href=\"downloadfile.ashx?link=" + encodeURIComponent(filetreelinkpath + '/' + f.nx) + "\">" + shortname + "</a>" + publiclink; }
2018-04-04 03:07:48 +03:00
h = "<div class=filelist file=3><input file=3 style=float:left name=fc class=fcb type=checkbox onchange=p5setActions() value='" + f.nx + "'> <span class=fsize>" + fdatestr + "</span><span style=float:right>" + fsize + "</span><span><div class=fileIcon" + f.t + "></div>" + link + "</span></div>";
2017-08-28 19:27:45 +03:00
}
if (f.t < 3) { html1 += h; } else { html2 += h; }
}
2017-12-14 01:52:57 +03:00
//if (f.parent == null) { }
2017-08-28 19:27:45 +03:00
QH('p5rightOfButtons', p5getQuotabar(filetreex));
QH('p5files', html1 + html2);
QH('p5currentpath', displayPath);
QE('p5FolderUp', filetreelocation.length != 0);
QV('p5PublicShare', publicfolder);
// Re-check all boxes if needed
if (oldlinkpath == filetreelinkpath) {
checkboxes = document.getElementsByName('fc');
for (var i = 0; i < checkboxes.length; i++) {
checkboxes[i].checked = (checkedBoxes.indexOf(checkboxes[i].value) >= 0);
}
}
p5setActions();
}
2018-09-01 01:23:42 +03:00
function getNiceSize(bytes) {
if (bytes <= 0) return 'Storage limit exceed';
if (bytes < 2048) return bytes + ' bytes remaining';
if (bytes < 2097152) return Math.round(bytes / 1024) + ' kilobytes remaining';
if (bytes < 2147483648) return Math.round(bytes / 1024 / 1024) + ' megabytes remaining';
return Math.round(bytes / 1024 / 1024 / 1024) + ' gigabytes remaining';
}
2018-09-27 00:58:55 +03:00
function getNiceSize2(bytes) {
if (bytes <= 0) return 'None';
if (bytes < 2048) return bytes + ' b';
if (bytes < 2097152) return Math.round(bytes / 1024) + ' Kb';
if (bytes < 2147483648) return Math.round(bytes / 1024 / 1024) + ' Mb';
return Math.round(bytes / 1024 / 1024 / 1024) + ' Gb';
}
2017-08-28 19:27:45 +03:00
function p5getQuotabar(f) {
2018-06-19 22:25:57 +03:00
while (f.t > 1 && f.t != 4) { f = f.parent; }
if ((f.t != 1 && f.t != 4) || (f.maxbytes == null)) return '';
2018-09-01 01:23:42 +03:00
var tf = Math.floor(f.s / 1024), tq = (f.maxbytes - f.s);
return '<span title="' + tf + "k in " + f.c + " file" + (f.c > 1 ? 's' : '') + ". " + (Math.floor(f.maxbytes / 1024 / 1024)) + 'k maxinum">' + getNiceSize(tq) + ' <progress style=height:10px;width:100px value=' + f.s + ' max=' + f.maxbytes + ' /></span>';
2017-08-28 19:27:45 +03:00
}
function p5showPublicLink(u) { setDialogMode(2, "Public Link", 1, null, '<input type=text style=width:100% value="' + u + '" readonly />'); }
var sortorder;
function p5sort_filename(a, b) { if (a.ln > b.ln) return (1 * sortorder); if (a.ln < b.ln) return (-1 * sortorder); return 0; }
function p5sort_timestamp(a, b) { if (a.d > b.d) return (1 * sortorder); if (a.d < b.d) return (-1 * sortorder); return 0; }
function p5sort_bysize(a, b) { if (a.s == b.s) return p5sort_filename(a, b); return (((a.s - b.s)) * sortorder); }
function p5sort_files(files) {
var r = [], sortselection = Q('p5sortdropdown').value;
2017-12-14 01:52:57 +03:00
for (var i in files) { files[i].nx = i; if (files[i].n == null) { files[i].n = i; } files[i].ln = files[i].n.toLowerCase(); r.push(files[i]); }
2017-08-28 19:27:45 +03:00
sortorder = 1;
if (sortselection > 3) { sortorder = -1; sortselection -= 3; }
if (sortselection == 1) { r.sort(p5sort_filename); }
else if (sortselection == 2) { r.sort(p5sort_bysize); }
else if (sortselection == 3) { r.sort(p5sort_timestamp); }
return r;
}
function p5setActions() {
2018-04-04 03:07:48 +03:00
var cc = getFileSelCount(), tc = getFileCount(), sfc = getFileSelCount(false); // In order: number of entires selected, number of total entries, number of selected entires that are files (not folders)
2017-08-28 19:27:45 +03:00
QE('p5DeleteFileButton', (cc > 0) && (filetreelocation.length > 0));
QE('p5NewFolderButton', filetreelocation.length > 0);
QE('p5UploadButton', filetreelocation.length > 0);
QE('p5RenameFileButton', (cc == 1) && (filetreelocation.length > 0));
2018-04-04 03:07:48 +03:00
QE('p5SelectAllButton', tc > 0);
2017-08-28 19:27:45 +03:00
Q('p5SelectAllButton').value = (cc > 0 ? 'Select None' : 'Select All');
2018-04-04 03:07:48 +03:00
QE('p5CutButton', (sfc > 0) && (cc == sfc));
QE('p5CopyButton', (sfc > 0) && (cc == sfc));
2018-06-19 22:25:57 +03:00
QE('p5PasteButton', (p5clipboard != null) && (p5clipboard.length > 0) && (filetreelocation.length > 0));
2017-08-28 19:27:45 +03:00
}
2018-09-25 21:51:40 +03:00
function getFileSelCount(includeDirs) { var cc = 0, checkboxes = document.getElementsByName('fc'); for (var i = 0; i < checkboxes.length; i++) { if ((checkboxes[i].checked) && ((includeDirs != false) || (checkboxes[i].attributes.file.value == "3"))) cc++; } return cc; }
function getFileSelDirCount() { var cc = 0, checkboxes = document.getElementsByName('fc'); for (var i = 0; i < checkboxes.length; i++) { if ((checkboxes[i].checked) && (checkboxes[i].attributes.file.value == "999")) cc++; } return cc; }
2017-08-28 19:27:45 +03:00
function getFileCount() { var cc = 0; var checkboxes = document.getElementsByName('fc'); return checkboxes.length; }
function p5selectallfile() { var nv = (getFileSelCount() == 0), checkboxes = document.getElementsByName('fc'); for (var i = 0; i < checkboxes.length; i++) { checkboxes[i].checked = nv; } p5setActions(); }
2017-12-14 01:52:57 +03:00
function setupBackPointers(x) { if (x.f != null) { var fs = 0, fc = 0; for (var i in x.f) { setupBackPointers(x.f[i]); x.f[i].parent = x; if (x.f[i].s) { fs += x.f[i].s; } if (x.f[i].c) { fc += x.f[i].c; } if (x.f[i].t == 3) { fc++; } } x.s = fs; x.c = fc; } return x; }
2017-08-28 19:27:45 +03:00
function getFileSizeStr(size) { if (size == 1) return "1 byte"; return "" + size + " bytes"; }
2017-12-14 01:52:57 +03:00
function p5folderup(x) { if (x == null) { filetreelocation.pop(); } else { while (filetreelocation.length > x) { filetreelocation.pop(); } } updateFiles(); }
2017-08-28 19:27:45 +03:00
function p5folderset(x) { filetreelocation.push(decodeURIComponent(x)); updateFiles(); }
2017-12-15 01:57:52 +03:00
function p5createfolder() { setDialogMode(2, "New Folder", 3, p5createfolderEx, '<input type=text id=p5renameinput maxlength=64 onkeyup=p5fileNameCheck(event) style=width:100% />'); focusTextBox('p5renameinput'); p5fileNameCheck(); }
2018-02-12 04:13:26 +03:00
function p5createfolderEx() { meshserver.send( { action: 'fileoperation', fileop: 'createfolder', path: filetreelocation, newfolder: Q('p5renameinput').value}); }
2018-09-25 21:51:40 +03:00
function p5deletefile() { var cc = getFileSelCount(), rec = (getFileSelDirCount() > 0) ? "<br /><br /><input type=checkbox id=p5recdeleteinput>Recursive delete<br>" : "<input type=checkbox id=p5recdeleteinput style='display:none'>"; setDialogMode(2, "Delete", 3, p5deletefileEx, (cc > 1) ? ('Delete ' + cc + ' selected items?' + rec) : ('Delete selected item?' + rec)); }
function p5deletefileEx() { var delfiles = [], checkboxes = document.getElementsByName('fc'); for (var i = 0; i < checkboxes.length; i++) { if (checkboxes[i].checked) { delfiles.push(checkboxes[i].value); } } meshserver.send( { action: 'fileoperation', fileop: 'delete', path: filetreelocation, delfiles: delfiles, rec: Q('p5recdeleteinput').checked }); }
2017-12-15 01:57:52 +03:00
function p5renamefile() { var renamefile, checkboxes = document.getElementsByName('fc'); for (var i = 0; i < checkboxes.length; i++) { if (checkboxes[i].checked) { renamefile = checkboxes[i].value; } } setDialogMode(2, "Rename", 3, p5renamefileEx, '<input type=text id=p5renameinput maxlength=64 onkeyup=p5fileNameCheck(event) style=width:100% value="' + renamefile + '" />', { action: 'fileoperation', fileop: 'rename', path: filetreelocation, oldname: renamefile}); focusTextBox('p5renameinput'); p5fileNameCheck(); }
2018-02-12 04:13:26 +03:00
function p5renamefileEx(b, t) { t.newname = Q('p5renameinput').value; meshserver.send(t); }
2018-09-25 21:51:40 +03:00
function p5fileNameCheck(e) { var x = isFilenameValid(Q('p5renameinput').value); QE('idx_dlgOkButton', x); if ((x == true) && (e && e.keyCode == 13)) { dialogclose(1); } }
2017-08-28 19:27:45 +03:00
var isFilenameValid = (function() { var x1=/^[^\\/:\*\?"<>\|]+$/, x2=/^\./, x3=/^(nul|prn|con|lpt[0-9]|com[0-9])(\.|$)/i; return function isFilenameValid(fname) { return x1.test(fname)&&!x2.test(fname)&&!x3.test(fname)&&(fname[0] != '.'); } })();
function p5uploadFile() { setDialogMode(2, "Upload File", 3, p5uploadFileEx, '<form method=post enctype=multipart/form-data action=uploadfile.ashx target=fileUploadFrame><input type=text name=link style=display:none id=p5uploadpath value=\"' + encodeURIComponent(filetreelinkpath) + '\" /><input type=file name=files id=p5uploadinput style=width:100% multiple=multiple onchange="updateUploadDialogOk(\'p5uploadinput\')" /><input type=submit id=p5loginSubmit style=display:none /></form>'); updateUploadDialogOk('p5uploadinput'); }
function p5uploadFileEx() { Q('p5loginSubmit').click(); }
function updateUploadDialogOk(x) { QE('idx_dlgOkButton', Q(x).value != ''); }
2018-04-04 03:07:48 +03:00
var p5clipboard = null, p5clipboardFolder = null, p5clipboardCut = 0;
function p5copyFile(cut) { var checkboxes = document.getElementsByName('fc'); p5clipboard = []; p5clipboardCut = cut, p5clipboardFolder = Clone(filetreelocation); for (var i = 0; i < checkboxes.length; i++) { if ((checkboxes[i].checked) && (checkboxes[i].attributes.file.value == "3")) { p5clipboard.push(checkboxes[i].value); } } p5updateClipview(); }
function p5pasteFile() { var x = ''; if ((p5clipboard != null) && (p5clipboard.length > 0)) { x = 'Confim ' + (p5clipboardCut == 0?'copy':'move') + ' of ' + p5clipboard.length + ' entrie' + ((p5clipboard.length > 1)?'s':'') + ' to this location?' } setDialogMode(2, "Paste", 3, p5pasteFileEx, x); }
function p5pasteFileEx() { meshserver.send( { action: 'fileoperation', fileop: (p5clipboardCut == 0?'copy':'move'), scpath: p5clipboardFolder, path: filetreelocation, names: p5clipboard }); p5folderup(999); if (p5clipboardCut == 1) { p5clipboard = null, p5clipboardFolder = null, p5clipboardCut = 0; p5updateClipview(); } }
function p5updateClipview() { var x = ''; if ((p5clipboard != null) && (p5clipboard.length > 0)) { x = 'Holding ' + p5clipboard.length + ' entrie' + ((p5clipboard.length > 1)?'s':'') + ' for ' + (p5clipboardCut == 0?'copy':'move') + ', <a onclick=p5clearClip() style=cursor:pointer>Clear</a>.' } QH('p5bottomstatus', x); p5setActions(); }
function p5clearClip() { p5clipboard = null; p5clipboardFolder = null; p5clipboardCut = 0; p5updateClipview(); }
2017-08-28 19:27:45 +03:00
function p5fileDragDrop(e) {
2018-09-08 03:09:02 +03:00
if (xxdialogMode) return;
2017-08-28 19:27:45 +03:00
haltEvent(e);
QV('bigfail', false);
QV('bigok', false);
//QV('p5fileCatchAllInput', false);
2018-09-08 03:09:02 +03:00
// For Chrome & Firefox
var error = 0;
p5uploadFile(); // Display the the dialog box
try { Q('p5uploadinput').files = e.dataTransfer.files; } catch (ex) { error = 1; } // Set the files in the dialog box
if (error == 0) { p5uploadFileEx(); } // Press the submit button
setDialogMode(0); // Close the dialog box
// For IE browser - This will not work with very large files
if (error == 1) {
if (e.dataTransfer == null || e.dataTransfer.files.length == 0 || filetreelocation.length == 0) return;
var names = [], sizes = [], types = [], datas = [], readercount = e.dataTransfer.files.length, totalSize = 0;
for (var i = 0; i < e.dataTransfer.files.length; i++) { totalSize += e.dataTransfer.files[i].size; }
if (totalSize > 1300000) { p5uploadFile(); return; } // File is too large, not sure what the real maximum is.
for (var i = 0; i < e.dataTransfer.files.length; i++) {
var reader = new FileReader(), file = e.dataTransfer.files[i];
names.push(file.name);
sizes.push(file.size);
types.push(file.type);
reader.onload = function (event) {
datas.push(event.target.result);
if (--readercount == 0) {
Q('p5fileDragName').value = names.join('*');
Q('p5fileDragSize').value = sizes.join('*');
Q('p5fileDragType').value = types.join('*');
Q('p5fileDragData').value = datas.join('*'); // This will not work for large files, there is a limit on the data size in a field.
Q('p5fileDragLink').value = encodeURIComponent(filetreelinkpath);
Q('p5loginSubmit2').click();
}
2017-08-28 19:27:45 +03:00
}
2018-09-08 03:09:02 +03:00
reader.readAsDataURL(file);
2017-08-28 19:27:45 +03:00
}
}
}
var p5dragtimer = null;
function p5fileDragOver(e) {
2018-09-08 03:09:02 +03:00
if (xxdialogMode) return;
2017-08-28 19:27:45 +03:00
haltEvent(e);
if (p5dragtimer != null) { clearTimeout(p5dragtimer); p5dragtimer = null; }
var ac = true; // TODO: Set to true if we can accept the file
if (filetreelocation.length == 0) { ac = false; }
QV('bigok', ac);
QV('bigfail', !ac);
//QV('p5fileCatchAllInput', ac);
}
function p5fileDragLeave(e) {
2018-09-08 03:09:02 +03:00
if (xxdialogMode) return;
2017-08-28 19:27:45 +03:00
haltEvent(e);
if (e.target.id != "p5filetable") {
QV('bigfail', false);
QV('bigok', false);
//QV('p5fileCatchAllInput', false);
} else {
2018-07-03 00:34:10 +03:00
p5dragtimer = setTimeout(function () { QV('bigfail',false); QV('bigok',false); p5dragtimer=null; }, 10);
2017-08-28 19:27:45 +03:00
}
}
/*
function p5fileCatchAllInputChanged(e) {
p5fileDragLeave(e);
Q('p5fileDragLink2').value = encodeURIComponent(filetreelinkpath);
Q('p5fileCatchAllSubmit').click();
}
*/
//
// MY EVENTS
//
2018-11-13 05:36:20 +03:00
// Highlights the device being hovered
function eventMouseHover(e, over) {
e.children[1].classList.remove('g1s');
e.children[2].style['background-color'] = ((over == 0) ? '#c9c9c9' : '#b9b9b9');
e.children[3].classList.remove('g2s');
2018-11-13 06:30:09 +03:00
if (over == 1) { e.children[1].classList.add('g1s'); e.children[3].classList.add('g2s'); }
2018-11-13 05:36:20 +03:00
}
2019-01-22 22:44:46 +03:00
function eventsUpdate() {
2017-08-28 19:27:45 +03:00
var x = '', dateHeader = null;
for (var i in events) {
2019-02-19 01:32:55 +03:00
var event = events[i], time = new Date(event.time);
2017-08-28 19:27:45 +03:00
if (time.toLocaleDateString() != dateHeader) {
if (dateHeader != null) x += '</table>';
2018-09-15 03:42:39 +03:00
x += '<table style=width:100% cellpadding=0 cellspacing=0><tr><td colspan=4 class=DevSt>' + time.toLocaleDateString() + '</td></tr>';
2017-08-28 19:27:45 +03:00
dateHeader = time.toLocaleDateString();
}
var icon = 'si3';
if (event.etype == 'user') icon = 'm2';
if (event.etype == 'server') icon = 'si3';
var msg = event.msg.split('(R)').join('®');
if (event.username && event.username != userinfo.name) { msg += ': ' + event.username; }
2018-11-13 05:36:20 +03:00
x += '<tr onmouseover=eventMouseHover(this,1) onmouseout=eventMouseHover(this,0) style=cursor:pointer><td style=width:18px><div class=' + icon + '></div></td><td class=g1 style=float:none> </td><td style=background-color:#C9C9C9>' + time.toLocaleTimeString() + ' - ' + msg + '</td><td class=g2 style=float:none> </td></tr><tr style=height:2px></tr>';
2017-08-28 19:27:45 +03:00
}
if (dateHeader != null) x += '</table>';
if (x == '') x = "<br><i>No Events Found</i><br><br>";
QH('p3events', x);
}
function showDeleteAllEventsDialog() {
if (xxdialogMode) return;
var x = "Delete all events in the server event log?<br /><br />";
x += "<input id=p3check type=checkbox onchange=validateDeleteAllEventsDialog() />Confirm";
setDialogMode(2, "Delete All Events", 3, showDeleteAllEventsDialogEx, x);
validateDeleteAllEventsDialog();
}
function validateDeleteAllEventsDialog() {
QE('idx_dlgOkButton', Q('p3check').checked);
}
function showDeleteAllEventsDialogEx(buttons, tag) {
2018-02-12 04:13:26 +03:00
meshserver.send( { action: 'clearevents' });
2017-08-28 19:27:45 +03:00
}
2018-01-05 02:59:57 +03:00
function refreshEvents() {
2018-02-12 04:13:26 +03:00
meshserver.send( { action: 'events', limit: parseInt(p3limitdropdown.value) });
2018-01-05 02:59:57 +03:00
}
2017-08-28 19:27:45 +03:00
//
// MY USERS
//
function updateUsers() {
QV('MainMenuMyUsers', (users != null) && ((features & 4) == 0));
2018-09-15 03:42:39 +03:00
QV('LeftMenuMyUsers', (users != null) && ((features & 4) == 0));
2017-08-28 19:27:45 +03:00
if ((users == null) || ((features & 4) != 0)) { QH('p3users', ''); return; }
2018-04-06 02:45:56 +03:00
// Sort the list of user id's
2018-07-17 03:49:55 +03:00
var sortedUserIds = [], maxUsers = 100, hiddenUsers = 0;
2018-04-06 02:45:56 +03:00
for (var i in users) { sortedUserIds.push(i); }
sortedUserIds.sort();
2018-07-17 03:49:55 +03:00
// Get search
var userSearch = Q('UserSearchInput').value.toLowerCase();
2018-04-06 02:45:56 +03:00
// Display the users using the sorted list
2018-04-18 05:00:31 +03:00
var x = '<table style=width:100% cellpadding=0 cellspacing=0>', addHeader = true;
// Online users
2018-04-06 02:45:56 +03:00
for (var i in sortedUserIds) {
2018-04-18 05:00:31 +03:00
var user = users[sortedUserIds[i]], sessions = null;
if (wssessions != null) { sessions = wssessions[user._id]; }
2018-07-17 03:49:55 +03:00
if ((sessions != null) && (user.name.toLowerCase().indexOf(userSearch) >= 0)) {
if (maxUsers > 0) {
if (addHeader) { x += '<tr><td class=userTableHeader>Online Users'; addHeader = false; }
x += addUserHtml(user, sessions);
2018-08-23 02:18:01 +03:00
maxUsers--;
2018-07-17 03:49:55 +03:00
} else {
hiddenUsers++;
}
2017-08-28 19:27:45 +03:00
}
2018-04-18 05:00:31 +03:00
}
addHeader = true;
// Offline users
for (var i in sortedUserIds) {
var user = users[sortedUserIds[i]], sessions = null;
if (wssessions != null) { sessions = wssessions[user._id]; }
2018-07-17 03:49:55 +03:00
if ((sessions == null) && (user.name.toLowerCase().indexOf(userSearch) >= 0)) {
if (maxUsers > 0) {
if (addHeader) { x += '<tr><td class=userTableHeader>Offline Users'; addHeader = false; }
x += addUserHtml(user, sessions);
2018-08-24 02:55:06 +03:00
maxUsers--;
2018-07-17 03:49:55 +03:00
} else {
hiddenUsers++;
}
2017-08-28 19:27:45 +03:00
}
}
x += '</table>';
2018-07-17 03:49:55 +03:00
if (hiddenUsers == 1) { x += '<br />1 more user not shown, use search box to look for users...<br />'; }
else if (hiddenUsers > 1) { x += '<br />' + hiddenUsers + ' more users not shown, use search box to look for users...<br />'; }
2018-07-24 03:34:24 +03:00
if (maxUsers == 100) { x += '<br />No users found.<br />'; }
2017-08-28 19:27:45 +03:00
QH('p3users', x);
2018-04-16 08:22:44 +03:00
// Update current user panel if needed
if ((currentUser != null) && (xxcurrentView == 30)) { gotoUser(encodeURIComponent(currentUser._id),true); }
2017-08-28 19:27:45 +03:00
}
2018-04-18 05:00:31 +03:00
function addUserHtml(user, sessions) {
2018-12-02 10:41:57 +03:00
var x = '', gray = ' gray', icon = 'm2', msg = '', msg2 = '', self = (user.name != userinfo.name);
2018-04-18 05:00:31 +03:00
if (sessions != null) {
gray = '';
2018-12-02 10:41:57 +03:00
if (self) {
2018-12-08 03:36:27 +03:00
msg2 = "<span style=float:right;margin-top:1px;margin-right:4px title=Chat><a onclick=userChat(event,\"" + encodeURIComponent(user._id) + "\",\"" + encodeURIComponent(user.name) + "\")><img src='images/icon-chat.png' height=16 width=16 style=padding-top:2px /></a></span>";
msg2 += "<span style=float:right;margin-top:1px;margin-left:4px;margin-right:4px title=Notify><a onclick=showUserAlertDialog(event,\"" + encodeURIComponent(user._id) + "\")><img src='images/icon-notify.png' height=16 width=16 style=padding-top:2px /></a></span>";
2018-12-02 10:41:57 +03:00
}
2018-04-18 05:00:31 +03:00
if (sessions == 1) { msg += '1 active session'; } else { msg += sessions + ' active sessions'; }
} else {
2019-01-25 04:01:50 +03:00
if (user.login) { msg += '<span title="Last login: ' + new Date(user.login * 1000).toLocaleString() + '">' + new Date(user.login * 1000).toLocaleDateString() + '</span>'; }
2018-04-18 05:00:31 +03:00
}
if (msg != '') msg += ', ';
if (self) { msg += "<a onclick=showUserAdminDialog(event,\"" + encodeURIComponent(user._id) + "\")>"; }
if ((user.siteadmin != null) && ((user.siteadmin & 32) != 0) && (user.siteadmin != 0xFFFFFFFF)) { msg += "Locked, "; }
msg += "<span title='Server Permissions'>";
if ((user.siteadmin == null) || (user.siteadmin == 0) || (user.siteadmin == 32)) {
msg += "User";
} else if (user.siteadmin == 8) {
msg += "User with server files";
} else if (user.siteadmin == 0xFFFFFFFF) {
msg += "Administrator";
} else {
msg += "Partial";
}
msg += "</span>";
if ((user.quota != null) && ((user.siteadmin & 8) != 0)) { msg += ", " + (user.quota / 1024) + " k"; }
if (self) { msg += "</a>"; }
var username = EscapeHtml(user.name), emailVerified = '';
2019-02-11 07:13:03 +03:00
if (serverinfo.emailcheck == true) { emailVerified = ((user.emailVerified != true) ? ' <b style=color:red title="Email is not verified">🗴</b>' : ' <b style=color:green title="Email is verified">🗸</b>'); }
2018-04-18 05:00:31 +03:00
if (user.email != null) { username += ', <a onclick=doemail(event,\"' + user.email + '\")>' + user.email + '</a>' + emailVerified; }
2019-02-11 07:13:03 +03:00
if ((user.otpsecret > 0) || (user.otphkeys > 0)) { username += ' <img src="images/key12.png" height=12 width=11 title="2nd factor authentication enabled" style="margin-top:2px" />'; }
if ((user.siteadmin != null) && ((user.siteadmin & 32) != 0) && (user.siteadmin != 0xFFFFFFFF)) { username += ' <img src="images/padlock12.png" height=12 width=8 title="Account is locked" style="margin-top:2px" />'; }
2018-11-13 06:30:09 +03:00
x += '<tr onmouseover=userMouseHover(this,1) onmouseout=userMouseHover(this,0)><td style=cursor:pointer onclick=gotoUser(\"' + encodeURIComponent(user._id) + '\")>';
2018-04-18 05:00:31 +03:00
x += '<div class=bar style=height:24px;width:100%;font-size:medium>';
x += '<div style=float:left;height:24px;width:24px;background-color:white><div class="' + icon + gray + '" style=width:16px;margin-top:4px;margin-left:2px;height:16px></div></div>';
x += '<div class=g1 style=height:24px;float:left></div><div class=g2 style=height:24px;float:right></div>';
2018-12-02 10:41:57 +03:00
x += '<div><span>' + username + '</span>' + msg2 + '<span style=float:right>' + msg + '</span></div></div>'; // </td></tr>
2018-04-18 05:00:31 +03:00
return x;
}
2018-11-13 06:30:09 +03:00
// Highlights the user being hovered
function userMouseHover(element, over) {
var e = element.children[0].children[0];
e.children[1].classList.remove('g1s');
e.children[2].classList.remove('g2s');
if (over == 1) { e.children[1].classList.add('g1s'); e.children[2].classList.add('g2s'); }
element.children[0].children[0].style['background-color'] = ((over == 0) ? '#c9c9c9' : '#b9b9b9');
}
2018-12-02 10:41:57 +03:00
function userChat(e, userid, name) {
haltEvent(e);
2019-01-29 02:47:54 +03:00
var url = '/messenger?id=meshmessenger/' + userid + '/' + encodeURIComponent(userinfo._id) + '&title=' + name;
if ((authCookie != null) && (authCookie != '')) { url += '&auth=' + authCookie; }
window.open(url, 'meshmessenger:' + userid);
2018-12-02 10:41:57 +03:00
meshserver.send( { action: 'meshmessenger', userid: decodeURIComponent(userid) });
return false;
}
2018-04-06 02:45:56 +03:00
function showUserAlertDialog(e, userid) {
if (xxdialogMode) return;
haltEvent(e);
2018-04-16 08:22:44 +03:00
setDialogMode(2, "Notify " + EscapeHtml(users[decodeURIComponent(userid)].name), 3, showUserAlertDialogEx, 'Send a text notification to this user.<textarea id=d2notifyText maxlength=2048 style="width:100%;height:184px;resize:none"></textarea>', userid);
2018-04-06 02:45:56 +03:00
Q('d2notifyText').focus();
return false;
}
2018-04-16 08:22:44 +03:00
function showUserAlertDialogEx(button, userid) { meshserver.send( { action: 'notifyuser', userid: decodeURIComponent(userid), msg: Q('d2notifyText').value }); }
2018-04-06 02:45:56 +03:00
2017-08-28 19:27:45 +03:00
function doemail(e, addr) {
if (xxdialogMode) return;
haltEvent(e);
window.open("mailto:" + addr);
return false;
}
2019-02-15 01:44:38 +03:00
function showUserBroadcastDialog() {
if (xxdialogMode) return;
var x = 'Broadcast a message to all connected users.<textarea id=broadcastMessage value="" style=width:370px;height:100px;resize:none maxlength=256 /></textarea>';
setDialogMode(2, "Broadcast Message", 3, showUserBroadcastDialogEx, x);
Q('broadcastMessage').focus();
}
function showUserBroadcastDialogEx() {
meshserver.send( { action: 'userbroadcast', msg: Q('broadcastMessage').value });
}
2017-08-28 19:27:45 +03:00
function showCreateNewAccountDialog() {
if (xxdialogMode) return;
var x = '';
2018-04-06 02:45:56 +03:00
x += addHtmlValue('Name', '<input id=p4name style=width:230px maxlength=64 onchange=showCreateNewAccountDialogValidate() onkeyup=showCreateNewAccountDialogValidate() />');
x += addHtmlValue('Email', '<input id=p4email style=width:230px maxlength=256 onchange=showCreateNewAccountDialogValidate() onkeyup=showCreateNewAccountDialogValidate() />');
x += addHtmlValue('Password', '<input id=p4pass1 type=password style=width:230px maxlength=256 onchange=showCreateNewAccountDialogValidate() onkeyup=showCreateNewAccountDialogValidate() />');
x += addHtmlValue('Password', '<input id=p4pass2 type=password style=width:230px maxlength=256 onchange=showCreateNewAccountDialogValidate() onkeyup=showCreateNewAccountDialogValidate() />');
2019-02-13 06:23:40 +03:00
if (passRequirements) { var r = []; for (var i in passRequirements) { r.push(i + ':' + passRequirements[i]); } x += '<div style=font-size:x-small;padding:6px>Requirements: ' + r.join(', ') + '.</div>'; }
2017-08-28 19:27:45 +03:00
setDialogMode(2, "Create Account", 3, showCreateNewAccountDialogEx, x);
showCreateNewAccountDialogValidate();
2017-12-15 01:57:52 +03:00
Q('p4name').focus();
2017-08-28 19:27:45 +03:00
}
2019-02-11 07:13:03 +03:00
function showCreateNewAccountDialogValidate(x) {
if ((x == null) && (Q('p4email').value.length > 0) && (validateEmail(Q('p4email').value)) == false) { QE('idx_dlgOkButton', false); return; }
2019-02-13 06:23:40 +03:00
var ok = (!Q('p4name') || ((Q('p4name').value.length > 0) && (Q('p4name').value.indexOf(' ') == -1))) && Q('p4pass1').value.length > 0 && Q('p4pass1').value == Q('p4pass2').value && checkPasswordRequirements(Q('p4pass1').value, passRequirements);
if (ok && passRequirements) { if (checkPasswordRequirements(Q('p4pass1').value, passRequirements) == false) { ok = false; } }
QE('idx_dlgOkButton', ok);
2017-08-28 19:27:45 +03:00
}
function showCreateNewAccountDialogEx() {
2018-02-12 04:13:26 +03:00
meshserver.send( { action: 'adduser', username: Q('p4name').value, email: Q('p4email').value, pass: Q('p4pass1').value });
2017-08-28 19:27:45 +03:00
}
function showUserAdminDialog(e, userid) {
if (xxdialogMode) return;
haltEvent(e);
2018-04-14 01:26:57 +03:00
userid = decodeURIComponent(userid);
2017-08-28 19:27:45 +03:00
var x = '<div>';
x += '<input type=checkbox onchange=showUserAdminDialogValidate() id=ua_fileaccess>Server Files, <input type=number onchange=showUserAdminDialogValidate() maxlength=10 style=width:80px;text-align:right id=ua_fileaccessquota>k max, blank for default<br><hr/>';
x += '<input type=checkbox onchange=showUserAdminDialogValidate() id=ua_fulladmin>Full Administrator<br>';
x += '<input type=checkbox onchange=showUserAdminDialogValidate() id=ua_serverbackup>Server Backup<br>';
x += '<input type=checkbox onchange=showUserAdminDialogValidate() id=ua_serverrestore>Server Restore<br>';
x += '<input type=checkbox onchange=showUserAdminDialogValidate() id=ua_serverupdate>Server Updates<br>';
x += '<input type=checkbox onchange=showUserAdminDialogValidate() id=ua_manageusers>Manage Users<br>';
2018-04-14 01:26:57 +03:00
x += '<hr/><input type=checkbox onchange=showUserAdminDialogValidate() id=ua_lockedaccount>Lock Account<br>';
2017-08-28 19:27:45 +03:00
x += '</div>';
2018-04-14 01:26:57 +03:00
var user = users[userid.toLowerCase()];
setDialogMode(2, "Server Permissions", 3, showUserAdminDialogEx, x, user);
2017-08-28 19:27:45 +03:00
if (user.siteadmin && user.siteadmin != 0) {
Q('ua_fulladmin').checked = (user.siteadmin == 0xFFFFFFFF);
Q('ua_serverbackup').checked = ((user.siteadmin != 0xFFFFFFFF) && ((user.siteadmin & 1) != 0)); // Server Backup
Q('ua_manageusers').checked = ((user.siteadmin != 0xFFFFFFFF) && ((user.siteadmin & 2) != 0)); // Manage Users
Q('ua_serverrestore').checked = ((user.siteadmin != 0xFFFFFFFF) && ((user.siteadmin & 4) != 0)); // Server Restore
Q('ua_fileaccess').checked = ((user.siteadmin != 0xFFFFFFFF) && ((user.siteadmin & 8) != 0)); // Server Files
Q('ua_serverupdate').checked = ((user.siteadmin != 0xFFFFFFFF) && ((user.siteadmin & 16) != 0)); // Server Update
2018-04-14 01:26:57 +03:00
Q('ua_lockedaccount').checked = ((user.siteadmin != 0xFFFFFFFF) && ((user.siteadmin & 32) != 0)); // Account locked
2017-08-28 19:27:45 +03:00
}
QE('ua_fulladmin', userinfo.siteadmin == 0xFFFFFFFF);
QE('ua_serverbackup', userinfo.siteadmin == 0xFFFFFFFF);
QE('ua_manageusers', userinfo.siteadmin == 0xFFFFFFFF);
QE('ua_serverrestore', userinfo.siteadmin == 0xFFFFFFFF);
QE('ua_fileaccess', userinfo.siteadmin == 0xFFFFFFFF);
QE('ua_serverupdate', userinfo.siteadmin == 0xFFFFFFFF);
2017-12-14 01:52:57 +03:00
Q('ua_fileaccessquota').value = (user.quota != null)?(user.quota / 1024):'';
2017-08-28 19:27:45 +03:00
showUserAdminDialogValidate();
return false;
}
function showUserAdminDialogValidate() {
if (userinfo.siteadmin == 0xFFFFFFFF) {
QE('ua_serverbackup', !Q('ua_fulladmin').checked);
QE('ua_manageusers', !Q('ua_fulladmin').checked);
QE('ua_serverrestore', !Q('ua_fulladmin').checked);
QE('ua_fileaccess', !Q('ua_fulladmin').checked);
QE('ua_serverupdate', !Q('ua_fulladmin').checked);
2018-04-14 01:26:57 +03:00
QE('ua_fileaccessquota', Q('ua_fileaccess').checked && !Q('ua_fulladmin').checked);
2017-08-28 19:27:45 +03:00
}
}
function showUserAdminDialogEx(button, user) {
var siteadmin = 0, quota = parseInt(Q('ua_fileaccessquota').value);
if (Q('ua_fulladmin').checked == true) { siteadmin = 0xFFFFFFFF; } else {
if (Q('ua_serverbackup').checked == true) siteadmin += 1;
if (Q('ua_manageusers').checked == true) siteadmin += 2;
if (Q('ua_serverrestore').checked == true) siteadmin += 4;
if (Q('ua_fileaccess').checked == true) siteadmin += 8;
if (Q('ua_serverupdate').checked == true) siteadmin += 16;
2018-04-14 01:26:57 +03:00
if (Q('ua_lockedaccount').checked == true) siteadmin += 32;
2017-08-28 19:27:45 +03:00
}
var x = { action: 'edituser', name: user.name, siteadmin: siteadmin };
if (isNaN(quota) == false) { x.quota = (quota * 1024); }
2018-02-12 04:13:26 +03:00
meshserver.send(x);
2017-08-28 19:27:45 +03:00
}
2018-07-17 03:49:55 +03:00
function onUserSearchInputChanged() { updateUsers(); }
2018-04-16 08:22:44 +03:00
//
// MY USERS GENERAL
//
var currentUser = null;
function gotoUser(userid, force) {
if (xxdialogMode && !force) return;
var user = currentUser = users[decodeURIComponent(userid)];
if (user == null) { setDialogMode(0); go(4); return; }
QH('p30userName', user.name);
QH('p31userName', user.name);
var self = (user.name == userinfo.name), activeSessions = 0;
if (wssessions != null && wssessions[user._id]) { activeSessions = wssessions[user._id]; }
2018-04-18 05:00:31 +03:00
// Change user grayscale
Q('MainUserImage').classList.remove('gray');
if (activeSessions == 0) { Q('MainUserImage').classList.add('gray'); }
2018-04-16 08:22:44 +03:00
// Server permissions
2019-02-13 06:23:40 +03:00
var msg = '', premsg = '';
if ((user.siteadmin != null) && ((user.siteadmin & 32) != 0) && (user.siteadmin != 0xFFFFFFFF)) { premsg = '<img src="images/padlock12.png" height=12 width=8 title="Account is locked" style="margin-top:2px" /> '; msg += 'Locked account, '; }
2018-04-16 08:22:44 +03:00
if ((user.siteadmin == null) || (user.siteadmin == 0) || (user.siteadmin == 32)) { msg += "No server rights"; } else if (user.siteadmin == 8) { msg += "Access to server files"; } else if (user.siteadmin == 0xFFFFFFFF) { msg += "Full administrator"; } else { msg += "Partial rights"; }
// Show user attributes
var x = '<div style=min-height:80px><table style=width:100%>';
2018-04-17 01:37:41 +03:00
var email = user.email?EscapeHtml(user.email):'<i>Not set</i>', everify = '';
2018-04-18 05:00:31 +03:00
if (serverinfo.emailcheck) { everify = ((user.emailVerified == true)?'<b style=color:green;cursor:pointer title="Email is verified">🗸</b> ':'<b style=color:red;cursor:pointer title="Email not verified">🗴</b> '); }
2019-02-09 01:17:35 +03:00
x += addDeviceAttribute('Email', everify + "<a style=cursor:pointer onclick=p30showUserEmailChangeDialog(event,\"" + userid + "\")>" + email + '</a> <a style=cursor:pointer onclick=doemail(event,\"' + user.email + '\")><img class=hoverButton width=10 height=10 src="images/link1.png" /></a>');
2019-02-13 06:23:40 +03:00
x += addDeviceAttribute('Server Rights', premsg + "<a style=cursor:pointer onclick=showUserAdminDialog(event,\"" + userid + "\")>" + msg + "</a>");
2018-04-16 08:22:44 +03:00
if (user.quota) x += addDeviceAttribute('Server Quota', EscapeHtml(parseInt(user.quota) / 1024) + ' k');
2019-01-25 04:01:50 +03:00
x += addDeviceAttribute('Creation', new Date(user.creation * 1000).toLocaleString());
if (user.login) x += addDeviceAttribute('Last Login', new Date(user.login * 1000).toLocaleString());
2019-02-27 01:39:45 +03:00
var linkCount = 0, linkCountStr = '<i>None<i>';
if (user.links) {
for (var i in user.links) { linkCount++; }
if (linkCount == 1) { linkCountStr = '1 group'; } else if (linkCount > 1) { linkCountStr = linkCount + ' groups'; }
}
x += addDeviceAttribute('Device Groups', linkCountStr);
2019-02-11 07:13:03 +03:00
var multiFactor = 0;
2019-02-12 01:41:15 +03:00
if ((user.otpsecret > 0) || (user.otphkeys > 0)) {
2019-02-11 07:13:03 +03:00
multiFactor = 1;
var factors = [];
if (user.otpsecret > 0) { factors.push('Authentication App'); }
if (user.otphkeys > 0) { factors.push('Security Key'); }
if (user.otpkeys > 0) { factors.push('Backup Codes'); }
2019-02-13 06:23:40 +03:00
x += addDeviceAttribute('Security', '<img src="images/key12.png" height=12 width=11 title="2nd factor authentication enabled" style="margin-top:2px" /> ' + factors.join(', '));
2019-02-11 07:13:03 +03:00
}
2018-08-24 02:55:06 +03:00
2018-04-16 08:22:44 +03:00
x += '</table></div><br />';
// Add action buttons
2018-04-16 21:57:42 +03:00
x += '<input type=button value=Notes title="View notes about this user" onclick=showNotes(false,"' + userid + '") />';
2018-04-16 08:22:44 +03:00
if (!self && (activeSessions > 0)) { x += '<input type=button value=Notify title="Send user notification" onclick=showUserAlertDialog(event,"' + userid + '") />'; }
// Setup the panel
QH('p30html', x);
// Draw the user timeline
drawUserTimeline();
// Check if we can delete this user
var deletePossible = true;
if (user._id == userinfo._id) deletePossible = false;
if (user.siteadmin && user.siteadmin > 0 && userinfo.siteadmin != 0xFFFFFFFF) deletePossible = false;
// Show bottom buttons
x = '<div style=float:right;font-size:x-small>';
if (deletePossible) x += '<a style=cursor:pointer onclick=p30showDeleteUserDialog() title="Remove this user">Delete User</a>';
x += '</div><div style=font-size:x-small>';
2019-02-11 07:13:03 +03:00
if (userinfo.siteadmin == 0xFFFFFFFF) x += '<a style=cursor:pointer onclick=p30showUserChangePassDialog(' + multiFactor + ') title="Change the password for this user">Change Password</a>';
2018-04-16 08:22:44 +03:00
x += '</div><br>'
QH('p30html3', x);
// Update user's connection state
x = '';
if (activeSessions == 1) { x = '1 active session'; } else if (activeSessions > 1) { x = activeSessions + ' active sessions'; }
QH('MainUserState', x);
go(30);
// Update user events (TODO: do this only if we change users)
QH('p31events', '');
refreshUsersEvents();
}
2018-04-17 01:37:41 +03:00
// Display the user's email change dialog box
function p30showUserEmailChangeDialog(event) {
if (xxdialogMode) return;
var x = '';
x += addHtmlValue('Email', '<input id=dp30email style=width:230px maxlength=32 onchange=p30validateEmail() onkeyup=p30validateEmail() />');
if (serverinfo.emailcheck) { x += addHtmlValue('Status', '<select id=dp30verified style=width:230px onchange=p30validateEmail()><option value=0>Not verified</option><option value=1>Verified</option></select>'); }
setDialogMode(2, "Change Email for " + EscapeHtml(currentUser.name), 3, p30showUserEmailChangeDialogEx, x);
Q('dp30email').focus();
Q('dp30email').value = currentUser.email;
if (serverinfo.emailcheck) { Q('dp30verified').value = currentUser.emailVerified?1:0; }
p30validateEmail();
}
// Perform validation on the user's email change dialog box
function p30validateEmail() {
var v = Q('dp30email').value, x = v.split('@');
x = (x.length == 2) && (x[0].length > 0) && (x[1].split('.').length > 1) && (x[1].length > 2) && (v.length < 1024) && ((v != userinfo.email) || ((serverinfo.emailcheck == true) && (Q('dp30verified').value != (userinfo.emailVerified?1:0))));
QE('idx_dlgOkButton', x);
}
// Send to the server the new user's email address and validation status
function p30showUserEmailChangeDialogEx() {
var x = { action: 'edituser', name: currentUser.name, email: Q('dp30email').value };
if (serverinfo.emailcheck) { x.emailVerified = (Q('dp30verified').value == 1); }
meshserver.send(x);
}
// Display the user's password change dialog box
2019-02-11 07:13:03 +03:00
function p30showUserChangePassDialog(multiFactor) {
2018-04-16 08:22:44 +03:00
if (xxdialogMode) return;
var x = '';
2019-02-11 07:13:03 +03:00
x += addHtmlValue('Password', '<input id=p4pass1 type=password style=width:230px maxlength=256 onchange=showCreateNewAccountDialogValidate(1) onkeyup=showCreateNewAccountDialogValidate(1)></input>');
x += addHtmlValue('Password', '<input id=p4pass2 type=password style=width:230px maxlength=256 onchange=showCreateNewAccountDialogValidate(1) onkeyup=showCreateNewAccountDialogValidate(1)></input>');
x += addHtmlValue('Password hint', '<input id=p4hint type=text style=width:230px maxlength=256></input>');
2019-02-13 06:23:40 +03:00
if (passRequirements) { var r = []; for (var i in passRequirements) { r.push(i + ':' + passRequirements[i]); } x += '<div style=font-size:x-small;padding:6px>Requirements: ' + r.join(', ') + '.</div>'; }
if (multiFactor == 1) { x += '<div><input id=p4twoFactorRemove type=checkbox />Remove all 2nd factor authentication.</div>'; }
2019-02-11 07:13:03 +03:00
setDialogMode(2, "Change Password for " + EscapeHtml(currentUser.name), 3, p30showUserChangePassDialogEx, x, multiFactor);
showCreateNewAccountDialogValidate(1);
2018-04-16 08:22:44 +03:00
Q('p4pass1').focus();
}
2019-02-11 07:13:03 +03:00
function p30showUserChangePassDialogEx(b, tag) {
var removeMultiFactor = false;
if ((tag == 1) && (Q('p4twoFactorRemove').checked == true)) { removeMultiFactor = true; }
if (Q('p4pass1').value == Q('p4pass2').value) { meshserver.send( { action: 'changeuserpass', user: currentUser.name, pass: Q('p4pass1').value, hint: Q('p4hint').value, removeMultiFactor: removeMultiFactor }); }
}
2018-04-16 08:22:44 +03:00
function p30showDeleteUserDialog() {
if (xxdialogMode) return;
setDialogMode(2, "Delete User " + EscapeHtml(currentUser.name), 3, p30showDeleteUserDialogEx, 'Confirm deletion of user ' + EscapeHtml(currentUser.name) + '?');
}
function p30showDeleteUserDialogEx() {
meshserver.send( { action: 'deleteuser', userid: currentUser._id, username: currentUser.name });
}
// Draw device power bars. The bars are 766px wide.
function drawUserTimeline() {
var timeline = null, now = Date.now();
//if (currentNode._id == powerTimelineNode) { timeline = powerTimeline; }
timeline = [];
// Calculate when the timeline starts
var d = new Date();
d.setHours(0, 0, 0, 0);
d = new Date(d.getTime() - (1000 * 60 * 60 * 24 * 6));
var timelineStart = d.getTime();
// De-compact the timeline
var timeline2 = [];
if (timeline != null && timeline.length > 1) {
timeline2.push([ 0, timeline[1], timeline[0] ]); // Start, End, Power
var ct = timeline[1];
for (var i = 2; i < timeline.length; i += 2) {
var power = timeline[i], dt = now;
if (timeline.length > (i + 1)) { dt = timeline[i + 1]; }
timeline2.push([ ct, ct + dt, power ]); // Start, End, Power
ct = ct + dt;
}
}
// Draw the timeline
var x = '', count = 1, date = new Date();
date.setHours(0, 0, 0, 0);
for (var i = 0; i < 7; i++) {
var datavalue = '', start = date.getTime(), end = start + (1000 * 60 * 60 * 24);
for (var j in timeline2) {
var block = timeline2[j];
if (isTimeBlockInside(start, end, block[0], block[1]) == true) {
var ts = Math.max(start, block[0]);
var te = Math.min(Math.min(end, block[1]), now);
var width = Math.round((te - ts) / 112794);
if (width > 0) {
var title = powerStateStrings2[block[2]] + ' from ' + new Date(ts).toLocaleTimeString() + ' to ' + new Date(te).toLocaleTimeString() + '.';
datavalue += '<div title="' + title + '" style=display:table-cell;width:' + width + 'px;background-color:' + powerColor(block[2]) + ';height:16px></div>';
}
}
}
x += '<tr style=' + (((count % 2) == 0)?'background-color:#DDD':'') + '><td><div> ' + date.toLocaleDateString() + '<div></div></div></td><td><div>' + datavalue + '</div></td></tr>';
++count;
date = new Date(date.getTime() - (1000 * 60 * 60 * 24)); // Substract one day
}
QH('p30html2', '<table style="color:black;background-color:#EEE;border-color:#AAA;border-width:1px;border-style:solid;border-collapse:collapse" border=0 cellpadding=2 cellspacing=0 width=100%><tbody><tr style=background-color:#AAAAAA;font-weight:bold><th scope=col style=text-align:center;width:150px>Day</th><th scope=col style=text-align:center>7 Day Login State</th></tr>' + x + '</tbody></table>');
}
//
// MY USERS EVENTS
//
var currentUserEvents = null;
2019-01-22 22:44:46 +03:00
function userEventsUpdate() {
2018-04-16 08:22:44 +03:00
var x = '', dateHeader = null;
for (var i in currentUserEvents) {
var event = currentUserEvents[i];
var time = new Date(event.time);
if (time.toLocaleDateString() != dateHeader) {
if (dateHeader != null) x += '</table>';
x += '<table style=width:100% cellpadding=0 cellspacing=0><tr><td class=DevSt>' + time.toLocaleDateString() + '</td></tr>';
dateHeader = time.toLocaleDateString();
}
var icon = 'si3';
if (event.etype == 'user') icon = 'm2';
if (event.etype == 'server') icon = 'si3';
var msg = event.msg.split('(R)').join('®');
if (event.username && event.username != userinfo.name) { msg += ': ' + event.username; }
x += '<tr><td><div class=bar18 style=height:18px;width:100%;font-size:medium>';
x += '<div style=float:left;height:18px;width:18px;background-color:white><div class=' + icon + ' style=width:16px;margin-top:1px;margin-left:2px;height:16px></div></div>';
x += '<div class=g1 style=height:18px;float:left></div><div class=g2 style=height:18px;float:right></div>';
x += '<div style=font-size:14px><span style=width:300px>' + time.toLocaleTimeString() + ' - ' + msg + '</span></div></div></td></tr>';
}
if (dateHeader != null) x += '</table>';
if (x == '') x = "<br><i>No Events Found</i><br><br>";
QH('p31events', x);
}
function refreshUsersEvents() {
meshserver.send( { action: 'events', limit: parseInt(p31limitdropdown.value), user: currentUser.name });
}
2017-08-28 19:27:45 +03:00
//
// FILE SELECTOR, DIALOG 3
//
function d3init() {
Q('d3localFile').value = '';
d3modechange();
}
function d3modechange() {
var mode = Q('d3uploadMode').value;
QV('d3localmode', mode == 1);
QV('d3servermode', mode == 2);
if (mode == 1) { d3setActions(); } else { d3updatefiles(); }
}
var d3filetreelinkpath;
var d3filetreelocation = [];
function d3updatefiles() {
if (Q('d3uploadMode').value == 1) return;
var html1 = '', html2 = '', filetreex = filetree, folderdepth = 1;
// Navigate to path location, build the paths at the same time
var d3filetreelocation2 = [], oldlinkpath = d3filetreelinkpath, checkedBoxes = [], checkboxes = document.getElementsByName('fc');
for (var i = 0; i < checkboxes.length; i++) { if (checkboxes[i].checked) { checkedBoxes.push(checkboxes[i].value) }; } // Save all existing checked boxes
d3filetreelinkpath = '';
for (var i in d3filetreelocation) {
2017-12-14 01:52:57 +03:00
if ((filetreex.f != null) && (filetreex.f[d3filetreelocation[i]] != null)) {
2017-08-28 19:27:45 +03:00
d3filetreelocation2.push(d3filetreelocation[i]);
if ((folderdepth == 1)) {
var sp = d3filetreelocation[i].split('/');
publicPath = window.location + sp[0] + 'files/' + sp[2];
if (d3filetreelocation[i] === userinfo._id) { d3filetreelinkpath += 'self'; } else { d3filetreelinkpath += (sp[0] + '/' + sp[2]); }
} else {
if (d3filetreelinkpath != '') { d3filetreelinkpath += '/' + d3filetreelocation[i]; if (folderdepth > 2) { publicPath += '/' + d3filetreelocation[i]; } }
}
filetreex = filetreex.f[d3filetreelocation[i]];
folderdepth++;
} else {
break;
}
}
d3filetreelocation = d3filetreelocation2; // In case we could not go down the full path, we set the new path location here.
// Sort the files
var filetreexx = p5sort_files(filetreex.f);
// Display all files and folders at this location
for (var i in filetreexx) {
// Figure out the name and shortname
var f = filetreexx[i], name = f.n, shortname;
shortname = name;
if (name.length > 70) { shortname = '<span title="' + EscapeHtml(name) + '">' + EscapeHtml(name.substring(0, 70)) + "...</span>"; } else { shortname = EscapeHtml(name); }
name = EscapeHtml(name);
// Figure out the size
var fsize = '';
2017-12-14 01:52:57 +03:00
if (f.s != null) { fsize = getFileSizeStr(f.s); }
2017-08-28 19:27:45 +03:00
var h = '';
if (f.t < 3) {
var title = '';
2019-02-06 06:07:12 +03:00
h = "<div class=filelist file=999><span style=float:right title=\"" + title + "\"></span><span><div class=fileIcon" + f.t + " onclick=d3folderset(\"" + encodeURIComponent(f.nx) + "\")></div> <a style=cursor:pointer onclick=d3folderset(\"" + encodeURIComponent(f.nx) + "\")>" + shortname + "</a></span></div>";
2017-08-28 19:27:45 +03:00
} else {
var link = shortname;
2019-01-05 04:59:13 +03:00
//if (f.s > 0) { link = "<a rel=\"noreferrer noopener\" target=\"_blank\" href=\"downloadfile.ashx?link=" + encodeURIComponent(filetreelinkpath + '/' + f.nx) + "\">" + shortname + "</a>"; }
2017-08-28 19:27:45 +03:00
h = "<div class=filelist file=3><input style=float:left name=fcx class=fcb type=checkbox onchange=d3setActions() value='" + f.nx + "'> <span style=float:right>" + fsize + "</span><span><div class=fileIcon" + f.t + "></div>" + link + "</span></div>";
}
if (f.t < 3) { html1 += h; } else { html2 += h; }
}
QH('d3serverfiles', html1 + html2);
QE('p3FolderUp', d3filetreelocation.length > 0);
d3setActions();
}
function d3folderset(x) { d3filetreelocation.push(decodeURIComponent(x)); d3updatefiles(); }
2017-12-14 01:52:57 +03:00
function d3folderup(x) { if (x == null) { d3filetreelocation.pop(); } else { while (d3filetreelocation.length > x) { d3filetreelocation.pop(); } } d3updatefiles(); }
2017-08-28 19:27:45 +03:00
function d3getFileSel() { var cc = []; var checkboxes = document.getElementsByName('fcx'); for (var i = 0; i < checkboxes.length; i++) { if (checkboxes[i].checked) { cc.push(checkboxes[i].value) } } return cc; }
function d3setActions() {
var mode = Q('d3uploadMode').value;
if (mode == 1) {
QE('idx_dlgOkButton', Q('d3localFile').value.length > 0);
} else {
QE('idx_dlgOkButton', d3getFileSel().length == 1);
}
}
//
// NOTIFICATIONS
//
var notifications = [];
// Toggle showing notifications
function clickNotificationIcon(show) {
//addNotification( { icon:0, text:'test' });
if (show == true) { QV('notifiyBox', true); } else if (show == false) { QV('notifiyBox', false); } else { QV('notifiyBox', QS('notifiyBox')['display'] == 'none'); }
drawNotifications();
}
// Set the notification count on the upper right oft he screen
function setNotificationCount(c) {
if (parseInt(Q('notificationCount').innerHTML) == c) return; // If the count did not change, exit now.
QH('notificationCount', c);
QS('notificationCount')['background-color'] = (c == 0)?'lightblue':'orange';
QV('notificationCount', c > 0);
}
// Refresh the notification box
function drawNotifications() {
var r = '';
if (notifications.length == 0) {
r = '<div style=margin:5px>There are currently no notifications</div>';
} else {
for (var i in notifications) {
var n = notifications[i];
var t = '';
var d = new Date(n.time);
var icon = 0;
2017-12-14 01:52:57 +03:00
if (n.nodeid != null) {
2017-08-28 19:27:45 +03:00
var node = getNodeFromId(n.nodeid);
if (node != null) {
//console.log(node);
icon = node.icon;
t = '<b>' + node.name + '</b>: '
}
}
r += '<div title="Occured at ' + d.toLocaleString() + '" id="notifyx' + n.id + '" class=notification style="cursor:pointer;border-top:1px solid ' + ((r == '')?'transparent':'orange') + '"><div class=j' + icon + ' onclick="notificationSelected(' + n.id + ')" style=margin:5px;float:left></div><div onclick="notificationDelete(' + n.id + ')" class=unselectable title="Clear this notification" style=margin:5px;float:right;color:orange><b>X</b></div><div onclick="notificationSelected(' + n.id + ')" style=margin:5px>' + t + n.text + '</div></div>';
}
}
var deleteall = '';
if (notifications.length > 1) { deleteall = '<div id="notifyRemoveAll" onclick="deleteAllNotifications()" style="cursor:pointer;border-top:1px solid orange;margin:5px;color:orange;text-align:right;padding-right:3px">Clear all</div>'; }
QH('notifiyBox', '<div class=customScroll style="max-height:170px;overflow-y:auto;margin:5px">' + r + '</div>' + deleteall );
}
// A notification was selected
function notificationSelected(id) {
var j = -1;
for (var i in notifications) { if (notifications[i].id == id) { j = i; } }
if (j != -1) {
var n = notifications[j];
2017-12-14 01:52:57 +03:00
if (n.nodeid != null) {
2017-08-28 19:27:45 +03:00
if (n.tag == 'desktop') gotoDevice(n.nodeid, 12); // Desktop
else if (n.tag == 'terminal') gotoDevice(n.nodeid, 11); // Terminal
else if (n.tag == 'files') gotoDevice(n.nodeid, 13); // Files
else if (n.tag == 'intelamt') gotoDevice(n.nodeid, 14); // Intel AMT
else if (n.tag == 'console') gotoDevice(n.nodeid, 15); // Files
else gotoDevice(n.nodeid, 10); // General
2018-12-02 10:41:57 +03:00
} else {
if (n.tag.startsWith('meshmessenger/')) {
2018-12-20 23:12:24 +03:00
window.open('/messenger?id=' + n.tag + '&title=' + encodeURIComponent(n.username), n.tag.split('/')[2]);
2018-12-02 10:41:57 +03:00
notificationDelete(id);
}
2017-08-28 19:27:45 +03:00
}
}
}
// Remove one notification
function notificationDelete(id) {
2018-08-30 03:40:30 +03:00
var j = -1, e = Q('notifyx' + id);
2017-08-28 19:27:45 +03:00
if (e != null) {
for (var i in notifications) { if (notifications[i].id == id) { j = i; } }
if (j != -1) {
notifications.splice(j, 1);
e.parentNode.removeChild(e);
setNotificationCount(notifications.length);
if (notifications.length == 0) { QV('notifiyBox', false); }
if (notifications.length == 1) { QV('notifyRemoveAll', false); }
if ((notifications.length > 0) && (j == 0)) {
var n = notifications[0];
QS('notifyx' + n.id)['border-top'] = '1px solid transparent';
}
}
}
}
// Add a new notification and play the notification sound
function addNotification(n) {
2017-12-14 01:52:57 +03:00
if (n.time == null) { n.time = Date.now(); }
if (n.id == null) { n.id = Math.random(); }
2017-08-28 19:27:45 +03:00
notifications.unshift(n);
setNotificationCount(notifications.length);
Q('chimes').play();
clickNotificationIcon(true);
}
// Remove all notifications
function deleteAllNotifications() {
notifications = [];
setNotificationCount(0);
drawNotifications();
QV('notifiyBox', false);
}
2018-09-27 00:58:55 +03:00
//
// Server Statistics
//
function setupServerStats() {
window.serverStatCpu = new Chart(document.getElementById('serverCpuChart').getContext('2d'), {
type: 'doughnut',
data: { datasets: [ { data: [0, 0], backgroundColor: ['#AAAAAA', '#00AA00'] }], labels: ['Used', 'Free'] },
options: { responsive: true, legend: { position: 'none', }, animation: { animateScale: true, animateRotate: true }, width: '60px' }
});
window.serverStatMemory = new Chart(document.getElementById('serverMemoryChart').getContext('2d'), {
type: 'doughnut',
data: { datasets: [ { data: [0, 0], backgroundColor: ['#AAAAAA', '#00AA00'] }], labels: ['Used', 'Free'] },
options: { responsive: true, legend: { position: 'none', }, animation: { animateScale: true, animateRotate: true }, width: '60px' }
});
}
var lastServerStats = null;
function updateServerStats(message) {
if (message != null) { lastServerStats = message; } else { message = lastServerStats; }
if (message == null) return;
// Paint the pie graphs
if (typeof message.cpuavg == 'object') {
var m = Math.min(message.cpuavg[0], 1);
window.serverStatCpu.config.data.datasets[0].data = [m, 1 - m];
2018-09-27 03:29:12 +03:00
QH('serverCpuChartText', '<div style=margin-bottom:5px>CPU Load</div><div><b title="CPU load in the last minute">' + (Math.round(message.cpuavg[0] * 100.0) / 100.0) + '</b>, <b title="CPU load in the last 5 minutes">' + (Math.round(message.cpuavg[1] * 100.0) / 100.0) + '</b>, <b title="CPU load in the 15 minutes">' + (Math.round(message.cpuavg[2] * 100.0) / 100.0) + '</b></div>');
2018-09-27 00:58:55 +03:00
QS('serverCpuChartView')['display'] = 'inline-block';
window.serverStatCpu.update();
}
if ((typeof message.totalmem == 'number') && (typeof message.freemem == 'number')) {
window.serverStatMemory.config.data.datasets[0].data = [message.totalmem - message.freemem, message.freemem];
QH('serverMemoryChartText', '<div style=margin-bottom:5px>Memory</div><div><b>' + getNiceSize2(message.freemem) + '</b> free, <b>' + getNiceSize2(message.totalmem) + '</b> total</div>');
QS('serverMemoryChartView')['display'] = 'inline-block';
window.serverStatMemory.update();
}
// Display all of the server values
var x = '<div style=width:100% cellpadding=0 cellspacing=0>';
if (typeof message.values == 'object') {
for (var i in message.values) {
x += '<div class=userTableHeader style=margin-bottom:4px;width:200px>' + i + '</div>';
for (var j in message.values[i]) {
2018-10-11 23:29:50 +03:00
x += '<div style=display:inline-block><table style=width:300px;height:24px;background-color:#d3d9d6;margin-bottom:4px;vertical-align:middle;border-spacing:0><tr><td class=h1></td><td><span>' + j + '</span><span style=float:right>' + message.values[i][j] + '</span></td><td class=h2></td></tr></table></div>';
2018-09-27 00:58:55 +03:00
}
}
}
x += '</div>';
QH('serverStatsTable', x);
}
2017-08-28 19:27:45 +03:00
//
// POPUP DIALOG
//
2017-12-14 01:52:57 +03:00
// null = Hidden, 1 = Generic Message
2017-08-28 19:27:45 +03:00
var xxdialogMode;
var xxdialogFunc;
var xxdialogButtons;
var xxdialogTag;
2019-01-27 23:23:38 +03:00
var xxcurrentView = -1;
2017-08-28 19:27:45 +03:00
// 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 < 24; 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); } }
}
function dialogclose(x) {
2018-09-19 05:41:59 +03:00
var f = xxdialogFunc, b = xxdialogButtons, t = xxdialogTag;
2017-08-28 19:27:45 +03:00
setDialogMode();
if (((b & 8) || x) && f) f(x, t);
}
2018-11-13 06:30:09 +03:00
function center() {
2019-01-22 22:44:46 +03:00
if (xxcurrentView == 11) { deskAdjust(); } //deskAdjust(); }
else if (xxcurrentView == 10) { masterUpdate(256); }
else if (xxcurrentView == 1) { masterUpdate(4); }
2018-11-13 06:30:09 +03:00
}
2017-08-28 19:27:45 +03:00
function messagebox(t, m) { QH('id_dialogMessage', m); setDialogMode(1, t, 1); }
function statusbox(t, m) { QH('id_dialogMessage', m); setDialogMode(1, t); }
2018-09-27 03:29:12 +03:00
function goBack() {
if (xxdialogMode) return;
if ((xxcurrentView >= 10) && (xxcurrentView < 20)) { go(1); } // Return to My Devices
if ((xxcurrentView >= 20) && (xxcurrentView < 30)) { go(2); } // Return to My Account
if ((xxcurrentView >= 30) && (xxcurrentView < 40)) { go(4); } // Return to My Users
}
2017-08-28 19:27:45 +03:00
function go(x) {
if (xxdialogMode || xxcurrentView == x) return;
// Edit this line when adding a new screen
2018-04-16 08:22:44 +03:00
for (var i = 0; i < 32; i++) { QV('p' + i, i == x); }
2017-08-28 19:27:45 +03:00
xxcurrentView = x;
2018-09-15 03:42:39 +03:00
// Remove left bar selection
2018-09-27 00:58:55 +03:00
var leftBarItems = ['LeftMenuMyDevices', 'LeftMenuMyAccount', 'LeftMenuMyEvents', 'LeftMenuMyFiles', 'LeftMenuMyUsers', 'LeftMenuMyServer'];
2018-09-19 19:15:31 +03:00
for (var i in leftBarItems) { Q(leftBarItems[i]).classList.remove('lbbuttonsel'); Q(leftBarItems[i]).classList.remove('lbbuttonsel2'); }
2018-09-15 03:42:39 +03:00
// My Devices
2017-08-28 19:27:45 +03:00
QV('topbar', x != 0);
if (x >= 10 && x < 20) { QS('MainMenuMyDevices').backgroundColor = "#606060"; } else { QS('MainMenuMyDevices').backgroundColor = ((x == 1) ? "#003366" : "#808080"); }
2018-09-15 03:42:39 +03:00
if (x == 1 || (x >= 10 && x < 20)) { Q('LeftMenuMyDevices').classList.add('lbbuttonsel'); }
if (x == 1) { Q('LeftMenuMyDevices').classList.add('lbbuttonsel2'); }
// My Account
2017-08-28 19:27:45 +03:00
if (x >= 20 && x < 30) { QS('MainMenuMyAccount').backgroundColor = "#606060"; } else { QS('MainMenuMyAccount').backgroundColor = ((x == 2) ? "#003366" : "#808080"); }
2018-09-15 03:42:39 +03:00
if (x == 2 || (x >= 20 && x < 30)) { Q('LeftMenuMyAccount').classList.add('lbbuttonsel'); }
if (x == 2) { Q('LeftMenuMyAccount').classList.add('lbbuttonsel2'); }
// My Events
2017-08-28 19:27:45 +03:00
QS('MainMenuMyEvents').backgroundColor = ((x == 3) ? "#003366" : "#808080");
2018-09-15 03:42:39 +03:00
if (x == 3) { Q('LeftMenuMyEvents').classList.add('lbbuttonsel', 'lbbuttonsel2'); }
// My Users
2018-04-16 08:22:44 +03:00
if (x >= 30 && x < 40) { QS('MainMenuMyUsers').backgroundColor = "#606060"; } else { QS('MainMenuMyUsers').backgroundColor = ((x == 4) ? "#003366" : "#808080"); }
2018-09-15 03:42:39 +03:00
if (x == 4 || (x >= 30 && x < 40)) { Q('LeftMenuMyUsers').classList.add('lbbuttonsel'); }
if (x == 4) { Q('LeftMenuMyUsers').classList.add('lbbuttonsel2'); }
// My Files
2017-08-28 19:27:45 +03:00
QS('MainMenuMyFiles').backgroundColor = ((x == 5) ? "#003366" : "#808080");
2018-09-15 03:42:39 +03:00
if (x == 5) { Q('LeftMenuMyFiles').classList.add('lbbuttonsel', 'lbbuttonsel2'); }
2018-09-27 00:58:55 +03:00
// My Server
2019-02-05 05:06:01 +03:00
QS('MainMenuMyServer').backgroundColor = (((x == 6) || (x == 115)) ? "#003366" : "#808080");
if (((x == 6) || (x == 115))) { Q('LeftMenuMyServer').classList.add('lbbuttonsel', 'lbbuttonsel2'); }
2018-09-27 00:58:55 +03:00
2018-09-15 03:42:39 +03:00
// column_l max-height
if (webPageFullScreen) {
QS('column_l')["max-height"] = 'calc(100vh - 135px)';
} else {
QS('column_l')["max-height"] = (x >= 10) ? 'calc(100vh - 159px)' : 'calc(100vh - 135px)';
}
if ((x == 0) && (webPageFullScreen)) {
QS('page_content').position = '';
QV('page_leftbar', false);
QS('column_l').height = 'calc(100vh - 110px)';
QS('column_l')["max-height"] = '';
}
2017-08-28 19:27:45 +03:00
QV('MainSubMenuSpan', x >= 10 && x < 20);
2019-02-05 05:06:01 +03:00
QV('UserDummyMenuSpan', (x < 10) && (x != 6) && webPageFullScreen);
2017-08-28 19:27:45 +03:00
QV('MeshSubMenuSpan', x >= 20 && x < 30);
2018-04-16 08:22:44 +03:00
QV('UserSubMenuSpan', x >= 30 && x < 40);
2019-02-05 05:06:01 +03:00
QV('ServerSubMenuSpan', x == 6 || x == 115);
var panels = { 10: 'MainDev', 11: 'MainDevDesktop', 12: 'MainDevTerminal', 13: 'MainDevFiles', 14: 'MainDevAmt', 15: 'MainDevConsole', 20: 'MeshGeneral', 30: 'UserGeneral', 31: 'UserEvents', 6: 'ServerGeneral', 115: 'ServerConsole' };
2018-11-13 05:36:20 +03:00
for (var i in panels) {
Q(panels[i]).classList.remove('style3x');
Q(panels[i]).classList.remove('style3sel');
Q(panels[i]).classList.add((x == i) ? 'style3sel' : 'style3x');
}
2019-02-05 05:06:01 +03:00
// Panel 115 is weird, it's panel 15 for device console but used as a server console.
if (x == 115) { QV('p15', true); }
QV('p15uploadCore', x != 115);
QV('p15BackButton', x != 115);
if ((x == 15) || (x == 115)) { setupConsole(); }
2019-01-22 22:44:46 +03:00
if (x == 1) masterUpdate(4);
2019-01-30 01:08:29 +03:00
// Update the web page title
if ((currentNode) && (x >= 10) && (x < 20)) { document.title = 'MeshCentral - ' + currentNode.name; } else { document.title = 'MeshCentral'; }
2017-08-28 19:27:45 +03:00
}
// Generic methods
function joinPaths() { var x = []; for (var i in arguments) { var w = arguments[i]; if ((w != null) && (w != '')) { while (w.endsWith('/') || w.endsWith('\\')) { w = w.substring(0, w.length - 1); } while (w.startsWith('/') || w.startsWith('\\')) { w = w.substring(1); } x.push(w); } } return x.join('/'); }
2017-12-14 01:52:57 +03:00
function putstore(name, val) { try { if (typeof (localStorage) === 'undefined') return; localStorage.setItem(name, val); } catch (e) { } }
function getstore(name, val) { try { if (typeof (localStorage) === 'undefined') return val; var v = localStorage.getItem(name); if ((v == null) || (v == null)) return val; return v; } catch (e) { return val; } }
2018-09-27 00:58:55 +03:00
//function addLink(x, f) { return "<a style=cursor:pointer;color:darkblue;text-decoration:none onclick='" + f + "'>♦ " + x + "</a>"; }
2019-02-09 01:17:35 +03:00
function addLink(x, f) { return "<span style=cursor:pointer;text-decoration:none onclick='" + f + "'>" + x + " <img class=hoverButton width=10 height=10 src=images/link5.png></span>"; }
2017-08-28 19:27:45 +03:00
function addLinkConditional(x, f, c) { if (c) return addLink(x, f); return x; }
function haltEvent(e) { if (e.preventDefault) e.preventDefault(); if (e.stopPropagation) e.stopPropagation(); return false; }
function addOption(q, t, i) { var option = document.createElement("option"); option.text = t; option.value = i; Q(q).add(option); }
2018-12-06 01:22:34 +03:00
function passwordcheck(p) { return (p.length > 7) && (/\d/.test(p)) && (/[a-z]/.test(p)) && (/[A-Z]/.test(p)) && (/\W/.test(p)); }
2017-08-28 19:27:45 +03:00
function methodcheck(r) { if (r && r != null && r.Body && r.Body.ReturnValueStr != "SUCCESS") { messagebox("Call Error", r.Header.Method + ": " + r.Body.ReturnValueStr.replace("_", " ")); return true; } return false; }
function TableStart() { return "<table cellpadding=0 cellspacing=0 style=width:100%;border-radius:8px><tr><td width=200px><p><td>"; }
function TableStart2() { return "<table cellpadding=0 cellspacing=0 style=width:100%;border-radius:8px><tr><td><p><td>"; }
function TableEntry(n, v) { return "<tr><td><p>" + n + "<td>" + v; }
function FullTable(x, e) { var r = TableStart(); for (i in x) { if (i && x[i]) r += TableEntry(i, x[i]); } return r + TableEnd(e); }
function TableEnd(n) { return "<tr><td colspan=2><p>" + (n?n:'') + "</table>"; }
function AddButton(v, f) { return "<input type=button value='" + v + "' onclick='" + f + "' style=margin:4px>"; }
function AddButton2(v, f) { return "<input type=button value='" + v + "' onclick='" + f + "'>"; }
function AddRefreshButton(f) { return "<input type=button name=refreshbtn value=Refresh onclick='refreshButtons(false);" + f + "' style=margin:4px " + (refreshButtonsState==false?"disabled":"") + ">"; }
function MoreStart() { return "<a style=cursor:pointer;color:blue id=morexxx1 onclick=QV(\"morexxx1\",false);QV(\"morexxx2\",true)>▼ More</a><div id=morexxx2 style=display:none><br><hr>"; };
function MoreEnd() { return "<a style=cursor:pointer;color:blue onclick=QV(\"morexxx2\",false);QV(\"morexxx1\",true)>▲ Less</a></div>"; };
function getSelectedOptions(sel) { var opts = [], opt; for (var i = 0, len = sel.options.length; i < len; i++) { opt = sel.options[i]; if (opt.selected) { opts.push(opt.value); } } return opts; }
function getInstance(x, y) { for (var i in x) { if (x[i]["InstanceID"] == y) return x[i]; } return null; }
function getItem(x, y, z) { for (var i in x) { if (x[i][y] == z) return x[i]; } return null; }
function guidToStr(g) { return g.substring(6, 8) + g.substring(4, 6) + g.substring(2, 4) + g.substring(0, 2) + "-" + g.substring(10, 12) + g.substring(8, 10) + "-" + g.substring(14, 16) + g.substring(12, 14) + "-" + g.substring(16, 20) + "-" + g.substring(20); }
function getUrlVars() { var j, hash, vars = [], hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&'); for (var i = 0; i < hashes.length; i++) { j = hashes[i].indexOf('='); if (j > 0) { vars[hashes[i].substring(0, j)] = hashes[i].substring(j + 1, hashes[i].length); } } return vars; }
2019-01-24 05:07:02 +03:00
//function getDocWidth() { if (window.innerWidth) return window.innerWidth; if (document.documentElement && document.documentElement.clientWidth && document.documentElement.clientWidth != 0) return document.documentElement.clientWidth; return document.getElementsByTagName('body')[0].clientWidth; }
2017-08-28 19:27:45 +03:00
//function addHtmlValue(t, v) { return '<div style=height:20px><div style=float:right;width:220px><b>' + v + '</b></div><div>' + t + '</div></div>'; }
function addHtmlValue(t, v) { return '<table><td style=width:120px>' + t + '<td><b>' + v + '</b></table>'; }
function addHtmlValue2(t, v) { return '<div><div style=display:inline-block;float:right>' + v + '</div><div style=display:inline-block>' + t + '</div></div>'; }
2019-01-23 04:47:51 +03:00
function parseUriArgs() { var name, r = { }, parsedUri = window.document.location.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]); var x = parseInt(r[name]); if (x == r[name]) { r[name] = x; } break; } default: { break; } } } return r; }
2017-12-15 01:57:52 +03:00
function focusTextBox(x) { setTimeout(function() { Q(x).selectionStart = Q(x).selectionEnd = 65535; Q(x).focus(); }, 0); }
2018-10-17 00:51:54 +03:00
function validateEmail(v) { var emailReg = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9] { 1,3}\.[0-9] { 1,3}\.[0-9] { 1,3}\.[0-9] { 1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z] { 2,}))$/; return emailReg.test(v); } // New version
2019-02-01 02:00:51 +03:00
function isPrivateIP(a) { return (a.startsWith('10.') || a.startsWith('172.16.') || a.startsWith('192.168.')); }
2019-02-08 09:30:33 +03:00
function u2fSupported() { return (window.u2f && ((navigator.userAgent.indexOf('Chrome/') > 0) || (navigator.userAgent.indexOf('Firefox/') > 0) || (navigator.userAgent.indexOf('Opera/') > 0) || (navigator.userAgent.indexOf('Safari/') > 0))); }
2017-08-28 19:27:45 +03:00
</script>
2018-08-24 02:55:06 +03:00
</body>
2017-08-28 19:27:45 +03:00
</html>