From 25e30814bed42ead03a3d58db0eed79377041da8 Mon Sep 17 00:00:00 2001 From: Ylian Saint-Hilaire Date: Fri, 18 Sep 2020 00:57:36 -0700 Subject: [PATCH] control.ashx now behind 3FA --- public/scripts/agent-desktop-0.0.2-min.js | 2 +- public/scripts/common-0.0.1-min.js | 2 +- public/scripts/common-0.0.1.js | 2 +- public/scripts/meshcentral-min.js | 2 +- public/scripts/meshcentral.js | 2 +- views/default.handlebars | 3 ++- webserver.js | 7 ++++++- 7 files changed, 13 insertions(+), 7 deletions(-) diff --git a/public/scripts/agent-desktop-0.0.2-min.js b/public/scripts/agent-desktop-0.0.2-min.js index ec9f3a30..38ce6da7 100644 --- a/public/scripts/agent-desktop-0.0.2-min.js +++ b/public/scripts/agent-desktop-0.0.2-min.js @@ -1 +1 @@ -Uint8Array.prototype.slice||Object.defineProperty(Uint8Array.prototype,"slice",{value:function(e,t){return new Uint8Array(Array.prototype.slice.call(this,e,t))}});var CreateAgentRemoteDesktop=function(e,t){var h={};"string"==typeof(h.CanvasId=e)&&(h.CanvasId=Q(e)),h.Canvas=h.CanvasId.getContext("2d"),h.scrolldiv=t,h.State=0,h.PendingOperations=[],h.tilesReceived=0,h.TilesDrawn=0,h.KillDraw=0,h.ipad=!1,h.tabletKeyboardVisible=!1,h.LastX=0,h.LastY=0,h.touchenabled=0,h.submenuoffset=0,h.touchtimer=null,h.TouchArray={},h.connectmode=0,h.connectioncount=0,h.rotation=0,h.protocol=2,h.debugmode=0,h.firstUpKeys=[],h.stopInput=!1,h.localKeyMap=!0,h.pressedKeys=[],h.sessionid=0,h.username,h.oldie=!1,h.CompressionLevel=50,h.ScalingLevel=1024,h.FrameRateTimer=100,h.FirstDraw=!1,h.ScreenWidth=960,h.ScreenHeight=700,h.width=960,h.height=960,h.displays=null,h.selectedDisplay=null,h.onScreenSizeChange=null,h.onMessage=null,h.onConnectCountChanged=null,h.onDebugMessage=null,h.onTouchEnabledChanged=null,h.onDisplayinfo=null;var g=!(h.accumulator=null),p="default";h.mouseCursorActive=function(e){g!=e&&(g=e,h.CanvasId.style.cursor=1==e?p:"default")};var v=["default","progress","crosshair","pointer","help","text","no-drop","move","nesw-resize","ns-resize","nwse-resize","w-resize","alias","wait","none","not-allowed","col-resize","row-resize","copy","zoom-in","zoom-out"];h.Start=function(){h.State=0,h.accumulator=null},h.Stop=function(){h.setRotation(0),h.UnGrabKeyInput(),h.UnGrabMouseInput(),h.touchenabled=0,null!=h.onScreenSizeChange&&h.onScreenSizeChange(h,h.ScreenWidth,h.ScreenHeight,h.CanvasId),h.Canvas.clearRect(0,0,h.CanvasId.width,h.CanvasId.height)},h.xxStateChange=function(e){if(h.State!=e)switch(h.State=e,h.CanvasId.style.cursor="default",e){case 0:h.Stop()}},h.send=function(e){1>32)+h.intToStr(32&o)):(h.recordedSize+=n.length,h.shortToStr(e)+h.shortToStr(t)+h.intToStr(n.length)+h.intToStr(o>>32)+h.intToStr(32&o)+n)}return h.SendKeyMsg=function(e,t){var n;null!=e&&((t=t||window.event).code&&0==h.localKeyMap?null!=(n=function(e){return e.code.startsWith("Key")&&4==e.code.length?e.code.charCodeAt(3):e.code.startsWith("Digit")&&6==e.code.length?e.code.charCodeAt(5):e.code.startsWith("Numpad")&&7==e.code.length?e.code.charCodeAt(6)+48:o[e.code]}(t))&&h.SendKeyMsgKC(e,n):(59==(n=t.keyCode)?n=186:173==n?n=189:61==n&&(n=187),h.SendKeyMsgKC(e,n)))},h.SendMessage=function(e){3==h.State&&h.send(String.fromCharCode(0,17)+h.shortToStr(4+e.length)+e)},h.SendKeyMsgKC=function(e,t){if(3==h.State)if("object"==typeof e)for(var n in e)h.SendKeyMsgKC(e[n][0],e[n][1]);else{if(1==e)-1==h.pressedKeys.indexOf(t)&&h.pressedKeys.unshift(t);else if(2==e){-1!=(n=h.pressedKeys.indexOf(t))&&h.pressedKeys.splice(n,1)}h.send(String.fromCharCode(0,h.InputType.KEY,0,6,e-1,t))}},h.sendcad=function(){h.SendCtrlAltDelMsg()},h.SendCtrlAltDelMsg=function(){3==h.State&&h.send(String.fromCharCode(0,h.InputType.CTRLALTDEL,0,4))},h.SendEscKey=function(){3==h.State&&h.send(String.fromCharCode(0,h.InputType.KEY,0,6,0,27,0,h.InputType.KEY,0,6,1,27))},h.SendStartMsg=function(){h.SendKeyMsgKC(h.KeyAction.EXDOWN,91),h.SendKeyMsgKC(h.KeyAction.EXUP,91)},h.SendCharmsMsg=function(){h.SendKeyMsgKC(h.KeyAction.EXDOWN,91),h.SendKeyMsgKC(h.KeyAction.DOWN,67),h.SendKeyMsgKC(h.KeyAction.UP,67),h.SendKeyMsgKC(h.KeyAction.EXUP,91)},h.SendTouchMsg1=function(e,t,n,o){3==h.State&&h.send(String.fromCharCode(0,h.InputType.TOUCH)+h.shortToStr(14)+String.fromCharCode(1,e)+h.intToStr(t)+h.shortToStr(n)+h.shortToStr(o))},h.SendTouchMsg2=function(e,t){var n,o="";for(var a in h.TouchArray)a==e?n=t:1==h.TouchArray[a].f?(n=65542,h.TouchArray[a].f=3,"START"+a):2==h.TouchArray[a].f?(n=262144,"STOP"+a):n=131078,o+=String.fromCharCode(a)+h.intToStr(n)+h.shortToStr(h.TouchArray[a].x)+h.shortToStr(h.TouchArray[a].y),2==h.TouchArray[a].f&&delete h.TouchArray[a];3==h.State&&h.send(String.fromCharCode(0,h.InputType.TOUCH)+h.shortToStr(5+o.length)+String.fromCharCode(2)+o),0==Object.keys(h.TouchArray).length&&null!=h.touchtimer&&(clearInterval(h.touchtimer),h.touchtimer=null)},h.SendMouseMsg=function(e,t){if(3==h.State&&null!=e&&null!=h.Canvas){if(!t)t=window.event;var n=h.Canvas.canvas.height/h.CanvasId.clientHeight,o=h.Canvas.canvas.width/h.CanvasId.clientWidth,a=h.GetPositionOfControl(h.Canvas.canvas),r=(t.pageX-a[0])*o,s=(t.pageY-a[1])*n;if(t.addx&&(r+=t.addx),t.addy&&(s+=t.addy),0<=r&&r<=h.Canvas.canvas.width&&0<=s&&s<=h.Canvas.canvas.height){var i=0,c=0;e==h.KeyAction.UP||e==h.KeyAction.DOWN?t.which?i=1==t.which?h.MouseButton.LEFT:2==t.which?h.MouseButton.MIDDLE:h.MouseButton.RIGHT:t.button&&(i=0==t.button?h.MouseButton.LEFT:1==t.button?h.MouseButton.MIDDLE:h.MouseButton.RIGHT):e==h.KeyAction.SCROLL&&(t.detail?c=120*t.detail*-1:t.wheelDelta&&(c=3*t.wheelDelta));var u="";if(e==h.KeyAction.DBLCLICK)u=String.fromCharCode(0,h.InputType.MOUSE,0,10,0,136,r/256&255,255&r,s/256&255,255&s);else if(e==h.KeyAction.SCROLL){var l=0,d=0;d=c<0?(l=255-(Math.abs(c)>>8),255-(255&Math.abs(c))):(l=c>>8,255&c),u=String.fromCharCode(0,h.InputType.MOUSE,0,12,0,0,r/256&255,255&r,s/256&255,255&s,l,d)}else u=String.fromCharCode(0,h.InputType.MOUSE,0,10,0,e==h.KeyAction.DOWN?i:2*i&255,r/256&255,255&r,s/256&255,255&s);h.Action==h.KeyAction.NONE?0==h.Alternate||h.ipad?(h.send(u),h.Alternate=1):h.Alternate=0:h.send(u)}}},h.GetDisplayNumbers=function(){h.send(String.fromCharCode(0,11,0,4))},h.SetDisplay=function(e){h.send(String.fromCharCode(0,12,0,6,e>>8,255&e))},h.intToStr=function(e){return String.fromCharCode(e>>24&255,e>>16&255,e>>8&255,255&e)},h.shortToStr=function(e){return String.fromCharCode(e>>8&255,255&e)},h.onResize=function(){0!=h.ScreenWidth&&0!=h.ScreenHeight&&(h.Canvas.canvas.width==h.ScreenWidth&&h.Canvas.canvas.height==h.ScreenHeight||(h.FirstDraw&&(h.Canvas.canvas.width=h.ScreenWidth,h.Canvas.canvas.height=h.ScreenHeight,h.Canvas.fillRect(0,0,h.ScreenWidth,h.ScreenHeight),null!=h.onScreenSizeChange&&h.onScreenSizeChange(h,h.ScreenWidth,h.ScreenHeight,h.CanvasId)),h.FirstDraw=!1))},h.xxMouseInputGrab=!1,h.xxKeyInputGrab=!1,h.xxMouseMove=function(e){return 3==h.State&&h.SendMouseMsg(h.KeyAction.NONE,e),e.preventDefault&&e.preventDefault(),e.stopPropagation&&e.stopPropagation(),!1},h.xxMouseUp=function(e){return 3==h.State&&h.SendMouseMsg(h.KeyAction.UP,e),e.preventDefault&&e.preventDefault(),e.stopPropagation&&e.stopPropagation(),!1},h.xxMouseDown=function(e){return 3==h.State&&h.SendMouseMsg(h.KeyAction.DOWN,e),e.preventDefault&&e.preventDefault(),e.stopPropagation&&e.stopPropagation(),!1},h.xxMouseDblClick=function(e){return 3==h.State&&h.SendMouseMsg(h.KeyAction.DBLCLICK,e),e.preventDefault&&e.preventDefault(),e.stopPropagation&&e.stopPropagation(),!1},h.xxDOMMouseScroll=function(e){return 3!=h.State||(h.SendMouseMsg(h.KeyAction.SCROLL,e),!1)},h.xxMouseWheel=function(e){return 3!=h.State||(h.SendMouseMsg(h.KeyAction.SCROLL,e),!1)},h.xxKeyUp=function(e){return 3==h.State&&h.SendKeyMsg(h.KeyAction.UP,e),e.preventDefault&&e.preventDefault(),e.stopPropagation&&e.stopPropagation(),!1},h.xxKeyDown=function(e){return 3==h.State&&h.SendKeyMsg(h.KeyAction.DOWN,e),e.preventDefault&&e.preventDefault(),e.stopPropagation&&e.stopPropagation(),!1},h.xxKeyPress=function(e){return e.preventDefault&&e.preventDefault(),e.stopPropagation&&e.stopPropagation(),!1},h.handleKeys=function(e){return 1!=h.stopInput&&3==desktop.State&&h.xxKeyPress(e)},h.handleKeyUp=function(e){if(1==h.stopInput||3!=desktop.State)return!1;if(h.firstUpKeys.length<5&&(h.firstUpKeys.push(e.keyCode),5==h.firstUpKeys.length)){var t=h.firstUpKeys.join(",");"16,17,91,91,16"!=t&&"16,17,18,91,92"!=t||(h.stopInput=!0)}return h.xxKeyUp(e)},h.handleKeyDown=function(e){return 1!=h.stopInput&&3==desktop.State&&h.xxKeyDown(e)},h.handleReleaseKeys=function(){var e=JSON.parse(JSON.stringify(h.pressedKeys));for(var t in e)h.SendKeyMsgKC(h.KeyAction.UP,e[t])},h.mousedblclick=function(e){return 1!=h.stopInput&&h.xxMouseDblClick(e)},h.mousedown=function(e){return 1!=h.stopInput&&h.xxMouseDown(e)},h.mouseup=function(e){return 1!=h.stopInput&&h.xxMouseUp(e)},h.mousemove=function(e){return 1!=h.stopInput&&h.xxMouseMove(e)},h.mousewheel=function(e){return 1!=h.stopInput&&h.xxMouseWheel(e)},h.xxMsTouchEvent=function(e){if(4!=e.originalEvent.pointerType){if(e.preventDefault&&e.preventDefault(),e.stopPropagation&&e.stopPropagation(),"MSPointerDown"==e.type||"MSPointerMove"==e.type||"MSPointerUp"==e.type){var t=0,n=e.originalEvent.pointerId%256,o=e.offsetX*(Canvas.canvas.width/h.CanvasId.clientWidth),a=e.offsetY*(Canvas.canvas.height/h.CanvasId.clientHeight);"MSPointerDown"==e.type?t=65542:"MSPointerMove"==e.type?t=131078:"MSPointerUp"==e.type&&(t=262144),h.TouchArray[n]||(h.TouchArray[n]={x:o,y:a}),h.SendTouchMsg2(n,t),"MSPointerUp"==e.type&&delete h.TouchArray[n]}else alert(e.type);return!0}},h.xxTouchStart=function(e){if(3==h.State)if(e.preventDefault&&e.preventDefault(),0==h.touchenabled||1==h.touchenabled){if(1>32)+h.intToStr(32&o)):(h.recordedSize+=n.length,h.shortToStr(e)+h.shortToStr(t)+h.intToStr(n.length)+h.intToStr(o>>32)+h.intToStr(32&o)+n)}return h.SendKeyMsg=function(e,t){var n;null!=e&&((t=t||window.event).code&&0==h.localKeyMap?null!=(n=function(e){return e.code.startsWith("Key")&&4==e.code.length?e.code.charCodeAt(3):e.code.startsWith("Digit")&&6==e.code.length?e.code.charCodeAt(5):e.code.startsWith("Numpad")&&7==e.code.length?e.code.charCodeAt(6)+48:o[e.code]}(t))&&h.SendKeyMsgKC(e,n):(59==(n=t.keyCode)?n=186:173==n?n=189:61==n&&(n=187),h.SendKeyMsgKC(e,n)))},h.SendMessage=function(e){3==h.State&&h.send(String.fromCharCode(0,17)+h.shortToStr(4+e.length)+e)},h.SendKeyMsgKC=function(e,t){if(3==h.State)if("object"==typeof e)for(var n in e)h.SendKeyMsgKC(e[n][0],e[n][1]);else{if(1==e)-1==h.pressedKeys.indexOf(t)&&h.pressedKeys.unshift(t);else if(2==e){-1!=(n=h.pressedKeys.indexOf(t))&&h.pressedKeys.splice(n,1)}h.send(String.fromCharCode(0,h.InputType.KEY,0,6,e-1,t))}},h.sendcad=function(){h.SendCtrlAltDelMsg()},h.SendCtrlAltDelMsg=function(){3==h.State&&h.send(String.fromCharCode(0,h.InputType.CTRLALTDEL,0,4))},h.SendEscKey=function(){3==h.State&&h.send(String.fromCharCode(0,h.InputType.KEY,0,6,0,27,0,h.InputType.KEY,0,6,1,27))},h.SendStartMsg=function(){h.SendKeyMsgKC(h.KeyAction.EXDOWN,91),h.SendKeyMsgKC(h.KeyAction.EXUP,91)},h.SendCharmsMsg=function(){h.SendKeyMsgKC(h.KeyAction.EXDOWN,91),h.SendKeyMsgKC(h.KeyAction.DOWN,67),h.SendKeyMsgKC(h.KeyAction.UP,67),h.SendKeyMsgKC(h.KeyAction.EXUP,91)},h.SendTouchMsg1=function(e,t,n,o){3==h.State&&h.send(String.fromCharCode(0,h.InputType.TOUCH)+h.shortToStr(14)+String.fromCharCode(1,e)+h.intToStr(t)+h.shortToStr(n)+h.shortToStr(o))},h.SendTouchMsg2=function(e,t){var n,o="";for(var a in h.TouchArray)a==e?n=t:1==h.TouchArray[a].f?(n=65542,h.TouchArray[a].f=3,"START"+a):2==h.TouchArray[a].f?(n=262144,"STOP"+a):n=131078,o+=String.fromCharCode(a)+h.intToStr(n)+h.shortToStr(h.TouchArray[a].x)+h.shortToStr(h.TouchArray[a].y),2==h.TouchArray[a].f&&delete h.TouchArray[a];3==h.State&&h.send(String.fromCharCode(0,h.InputType.TOUCH)+h.shortToStr(5+o.length)+String.fromCharCode(2)+o),0==Object.keys(h.TouchArray).length&&null!=h.touchtimer&&(clearInterval(h.touchtimer),h.touchtimer=null)},h.SendMouseMsg=function(e,t){if(3==h.State&&null!=e&&null!=h.Canvas){if(!t)t=window.event;var n=h.Canvas.canvas.height/h.CanvasId.clientHeight,o=h.Canvas.canvas.width/h.CanvasId.clientWidth,a=h.GetPositionOfControl(h.Canvas.canvas),r=(t.pageX-a[0])*o,s=(t.pageY-a[1])*n;if(t.addx&&(r+=t.addx),t.addy&&(s+=t.addy),0<=r&&r<=h.Canvas.canvas.width&&0<=s&&s<=h.Canvas.canvas.height){var i=0,c=0;e==h.KeyAction.UP||e==h.KeyAction.DOWN?t.which?i=1==t.which?h.MouseButton.LEFT:2==t.which?h.MouseButton.MIDDLE:h.MouseButton.RIGHT:t.button&&(i=0==t.button?h.MouseButton.LEFT:1==t.button?h.MouseButton.MIDDLE:h.MouseButton.RIGHT):e==h.KeyAction.SCROLL&&(t.detail?c=120*t.detail*-1:t.wheelDelta&&(c=3*t.wheelDelta));var u="";if(e==h.KeyAction.DBLCLICK)u=String.fromCharCode(0,h.InputType.MOUSE,0,10,0,136,r/256&255,255&r,s/256&255,255&s);else if(e==h.KeyAction.SCROLL){var l=0,d=0;d=c<0?(l=255-(Math.abs(c)>>8),255-(255&Math.abs(c))):(l=c>>8,255&c),u=String.fromCharCode(0,h.InputType.MOUSE,0,12,0,0,r/256&255,255&r,s/256&255,255&s,l,d)}else u=String.fromCharCode(0,h.InputType.MOUSE,0,10,0,e==h.KeyAction.DOWN?i:2*i&255,r/256&255,255&r,s/256&255,255&s);h.Action==h.KeyAction.NONE?0==h.Alternate||h.ipad?(h.send(u),h.Alternate=1):h.Alternate=0:h.send(u)}}},h.GetDisplayNumbers=function(){h.send(String.fromCharCode(0,11,0,4))},h.SetDisplay=function(e){h.send(String.fromCharCode(0,12,0,6,e>>8,255&e))},h.intToStr=function(e){return String.fromCharCode(e>>24&255,e>>16&255,e>>8&255,255&e)},h.shortToStr=function(e){return String.fromCharCode(e>>8&255,255&e)},h.onResize=function(){0!=h.ScreenWidth&&0!=h.ScreenHeight&&(h.Canvas.canvas.width==h.ScreenWidth&&h.Canvas.canvas.height==h.ScreenHeight||(h.FirstDraw&&(h.Canvas.canvas.width=h.ScreenWidth,h.Canvas.canvas.height=h.ScreenHeight,h.Canvas.fillRect(0,0,h.ScreenWidth,h.ScreenHeight),null!=h.onScreenSizeChange&&h.onScreenSizeChange(h,h.ScreenWidth,h.ScreenHeight,h.CanvasId)),h.FirstDraw=!1,1>8&255,255&n)}function ShortToStrX(n){return String.fromCharCode(255&n,n>>8&255)}function IntToStr(n){return String.fromCharCode(n>>24&255,n>>16&255,n>>8&255,255&n)}function IntToStrX(n){return String.fromCharCode(255&n,n>>8&255,n>>16&255,n>>24&255)}function MakeToArray(n){return n&&null!=n&&"object"!=typeof n?[n]:n}function SplitArray(n){return n.split(",")}function Clone(n){return JSON.parse(JSON.stringify(n))}function EscapeHtml(n){return"string"==typeof n?n.replace(/&/g,"&").replace(/>/g,">").replace(//g,">").replace(/").replace(/\n/g,"").replace(/\t/g,"  "):"boolean"==typeof n?n:"number"==typeof n?n:void 0}function ArrayElementMove(n,t,e){n.splice(e,0,n.splice(t,1)[0])}function ObjectToStringEx(n,t){var e="";if(0!=n&&(!n||null==n))return"(Null)";if(n instanceof Array)for(var r in n)e+="
"+gap(t)+"Item #"+r+": "+ObjectToStringEx(n[r],t+1);else if(n instanceof Object)for(var r in n)e+="
"+gap(t)+r+" = "+ObjectToStringEx(n[r],t+1);else e+=EscapeHtml(n);return e}function ObjectToStringEx2(n,t){var e="";if(0!=n&&(!n||null==n))return"(Null)";if(n instanceof Array)for(var r in n)e+="\r\n"+gap2(t)+"Item #"+r+": "+ObjectToStringEx2(n[r],t+1);else if(n instanceof Object)for(var r in n)e+="\r\n"+gap2(t)+r+" = "+ObjectToStringEx2(n[r],t+1);else e+=EscapeHtml(n);return e}function gap(n){for(var t="",e=0;e<4*n;e++)t+=" ";return t}function gap2(n){for(var t="",e=0;e<4*n;e++)t+=" ";return t}function ObjectToString(n){return ObjectToStringEx(n,0)}function ObjectToString2(n){return ObjectToStringEx2(n,0)}function hex2rstr(n){if("string"!=typeof n||0==n.length)return"";for(var t,e="",r=(""+n).match(/../g);t=r.shift();)e+=String.fromCharCode("0x"+t);return e}function char2hex(n){return(n+256).toString(16).substr(-2).toUpperCase()}function rstr2hex(n){var t,e="";for(t=0;t")&&-1==n.indexOf("&")&&-1==n.indexOf('"')&&-1==n.indexOf("'")&&-1==n.indexOf("+")&&-1==n.indexOf("(")&&-1==n.indexOf(")")&&-1==n.indexOf("#")&&-1==n.indexOf("%")&&-1==n.indexOf(":")}function isSafeString2(n){return"string"==typeof n&&-1==n.indexOf("<")&&-1==n.indexOf(">")&&-1==n.indexOf("&")&&-1==n.indexOf('"')&&-1==n.indexOf("'")&&-1==n.indexOf("+")&&-1==n.indexOf("(")&&-1==n.indexOf(")")&&-1==n.indexOf("#")&&-1==n.indexOf("%")}function parseUriArgs(){var n=window.document.location.href;n.endsWith("#")&&(n=n.substring(0,n.length-1));var t,e={},r=n.split(/[\?&|\=]/);for(o in r.splice(0,1),r)switch(o%2){case 0:t=decodeURIComponent(r[o]);break;case 1:if(e[t]=decodeURIComponent(r[o]),isSafeString2(e[t])){var o=parseInt(e[t]);o==e[t]&&(e[t]=o)}else delete e[t]}return e}String.prototype.startsWith||(String.prototype.startsWith=function(n){return 0===this.lastIndexOf(n,0)}),String.prototype.endsWith||(String.prototype.endsWith=function(n){return-1!==this.indexOf(n,this.length-n.length)}) \ No newline at end of file +function Q(n){return document.getElementById(n)}function QS(n){try{return Q(n).style}catch(n){}}function QE(n,t){try{Q(n).disabled=!t}catch(n){}}function QV(n,t){try{QS(n).display=t?"":"none"}catch(n){}}function QA(n,t){Q(n).innerHTML+=t}function QH(n,t){Q(n).innerHTML=t}function QC(n){try{return Q(n).classList}catch(n){}}function inputBoxFocus(n){Q(n).focus();var t=Q(n).value;Q(n).value="",Q(n).value=t}function ReadShort(n,t){return(n.charCodeAt(t)<<8)+n.charCodeAt(t+1)}function ReadShortX(n,t){return(n.charCodeAt(t+1)<<8)+n.charCodeAt(t)}function ReadInt(n,t){return 16777216*n.charCodeAt(t)+(n.charCodeAt(t+1)<<16)+(n.charCodeAt(t+2)<<8)+n.charCodeAt(t+3)}function ReadSInt(n,t){return(n.charCodeAt(t)<<24)+(n.charCodeAt(t+1)<<16)+(n.charCodeAt(t+2)<<8)+n.charCodeAt(t+3)}function ReadIntX(n,t){return 16777216*n.charCodeAt(t+3)+(n.charCodeAt(t+2)<<16)+(n.charCodeAt(t+1)<<8)+n.charCodeAt(t)}function ShortToStr(n){return String.fromCharCode(n>>8&255,255&n)}function ShortToStrX(n){return String.fromCharCode(255&n,n>>8&255)}function IntToStr(n){return String.fromCharCode(n>>24&255,n>>16&255,n>>8&255,255&n)}function IntToStrX(n){return String.fromCharCode(255&n,n>>8&255,n>>16&255,n>>24&255)}function MakeToArray(n){return n&&null!=n&&"object"!=typeof n?[n]:n}function SplitArray(n){return n.split(",")}function Clone(n){return JSON.parse(JSON.stringify(n))}function EscapeHtml(n){return"string"==typeof n?n.replace(/&/g,"&").replace(/>/g,">").replace(//g,">").replace(/").replace(/\n/g,"").replace(/\t/g,"  "):"boolean"==typeof n?n:"number"==typeof n?n:void 0}function ArrayElementMove(n,t,e){n.splice(e,0,n.splice(t,1)[0])}function ObjectToStringEx(n,t){var e="";if(0!=n&&(!n||null==n))return"(Null)";if(n instanceof Array)for(var r in n)e+="
"+gap(t)+"Item #"+r+": "+ObjectToStringEx(n[r],t+1);else if(n instanceof Object)for(var r in n)e+="
"+gap(t)+r+" = "+ObjectToStringEx(n[r],t+1);else e+=EscapeHtml(n);return e}function ObjectToStringEx2(n,t){var e="";if(0!=n&&(!n||null==n))return"(Null)";if(n instanceof Array)for(var r in n)e+="\r\n"+gap2(t)+"Item #"+r+": "+ObjectToStringEx2(n[r],t+1);else if(n instanceof Object)for(var r in n)e+="\r\n"+gap2(t)+r+" = "+ObjectToStringEx2(n[r],t+1);else e+=EscapeHtml(n);return e}function gap(n){for(var t="",e=0;e<4*n;e++)t+=" ";return t}function gap2(n){for(var t="",e=0;e<4*n;e++)t+=" ";return t}function ObjectToString(n){return ObjectToStringEx(n,0)}function ObjectToString2(n){return ObjectToStringEx2(n,0)}function hex2rstr(n){if("string"!=typeof n||0==n.length)return"";for(var t,e="",r=(""+n).match(/../g);t=r.shift();)e+=String.fromCharCode("0x"+t);return e}function char2hex(n){return(n+256).toString(16).substr(-2).toUpperCase()}function rstr2hex(n){var t,e="";for(t=0;t")&&-1==n.indexOf("&")&&-1==n.indexOf('"')&&-1==n.indexOf("'")&&-1==n.indexOf("+")&&-1==n.indexOf("(")&&-1==n.indexOf(")")&&-1==n.indexOf("#")&&-1==n.indexOf("%")&&-1==n.indexOf(":")}function isSafeString2(n){return"string"==typeof n&&-1==n.indexOf("<")&&-1==n.indexOf(">")&&-1==n.indexOf("&")&&-1==n.indexOf('"')&&-1==n.indexOf("'")&&-1==n.indexOf("+")&&-1==n.indexOf("(")&&-1==n.indexOf(")")&&-1==n.indexOf("#")&&-1==n.indexOf("%")}function parseUriArgs(){var n=window.document.location.href;n.endsWith("#")&&(n=n.substring(0,n.length-1));var t,e={},r=n.split(/[\?&|\=]/);for(o in r.splice(0,1),r)switch(o%2){case 0:t=decodeURIComponent(r[o]);break;case 1:if(e[t]=decodeURIComponent(r[o]),isSafeString2(e[t])){var o=parseInt(e[t]);o==e[t]&&(e[t]=o)}else delete e[t]}return e}String.prototype.startsWith||(String.prototype.startsWith=function(n){return 0===this.lastIndexOf(n,0)}),String.prototype.endsWith||(String.prototype.endsWith=function(n){return-1!==this.indexOf(n,this.length-n.length)}) \ No newline at end of file diff --git a/public/scripts/common-0.0.1.js b/public/scripts/common-0.0.1.js index 1f28e369..49c3c67d 100644 --- a/public/scripts/common-0.0.1.js +++ b/public/scripts/common-0.0.1.js @@ -110,7 +110,7 @@ function trademarks(x) { return x.replace(/\(R\)/g, '®').replace(/\(TM\)/g, function zeroPad(num, c) { if (c == null) { c = 2; } var s = "00000000" + num; return s.substr(s.length - c); } // String validation -function isAlphaNumeric(str) { return (str.match(/^[A-Za-z0-9]+$/) != null); }; +function isAlphaNumeric(str) { if (typeof str == 'number') { return true; } return (str.match(/^[A-Za-z0-9]+$/) != null); }; function isSafeString(str) { return ((typeof str == 'string') && (str.indexOf('<') == -1) && (str.indexOf('>') == -1) && (str.indexOf('&') == -1) && (str.indexOf('"') == -1) && (str.indexOf('\'') == -1) && (str.indexOf('+') == -1) && (str.indexOf('(') == -1) && (str.indexOf(')') == -1) && (str.indexOf('#') == -1) && (str.indexOf('%') == -1) && (str.indexOf(':') == -1)) }; function isSafeString2(str) { return ((typeof str == 'string') && (str.indexOf('<') == -1) && (str.indexOf('>') == -1) && (str.indexOf('&') == -1) && (str.indexOf('"') == -1) && (str.indexOf('\'') == -1) && (str.indexOf('+') == -1) && (str.indexOf('(') == -1) && (str.indexOf(')') == -1) && (str.indexOf('#') == -1) && (str.indexOf('%') == -1)) }; diff --git a/public/scripts/meshcentral-min.js b/public/scripts/meshcentral-min.js index 7bdd001b..0867bc27 100644 --- a/public/scripts/meshcentral-min.js +++ b/public/scripts/meshcentral-min.js @@ -1 +1 @@ -var MeshServerCreateControl=function(e,t){var o={State:0,connectstate:0,pingTimer:null};return o.authCookie=t,o.trace=!1,o.xxStateChange=function(t,e){if(o.State!=t){var n=o.State;o.State=t,o.onStateChanged&&o.onStateChanged(o,o.State,n,e)}},o.Start=function(){if(0==o.connectstate){o.connectstate=0;var t=window.location.protocol.replace("http","ws")+"//"+window.location.host+e+"control.ashx";o.authCookie&&""!=o.authCookie&&(t+="?auth="+o.authCookie),o.socket=new WebSocket(t),o.socket.onopen=function(t){o.connectstate=1},o.socket.onmessage=o.xxOnMessage,o.socket.onclose=function(t){o.Stop(t.code)},o.xxStateChange(1,0),null!=o.pingTimer&&clearInterval(o.pingTimer),o.pingTimer=setInterval(function(){o.send({action:"ping"})},29e3)}},o.Stop=function(t){o.connectstate=0,o.socket&&(o.socket.close(),delete o.socket),null!=o.pingTimer&&(clearInterval(o.pingTimer),o.pingTimer=null),o.xxStateChange(0,t)},o.xxOnMessage=function(t){var e;1==o.State&&o.xxStateChange(2);try{e=JSON.parse(t.data)}catch(t){return}if("object"==typeof e&&"pong"!=e.action){if("ping"==e.action&&o.send({action:"pong"}),"close"==e.action)return e.msg&&console.log(e.msg),void o.Stop(e.cause);o.trace&&console.log("RECV",e),o.onMessage&&o.onMessage(o,e)}},o.send=function(t){null!=o.socket&&1==o.connectstate&&(o.trace&&"ping"!=t.action&&console.log("SEND",t),o.socket.send(JSON.stringify(t)))},o} \ No newline at end of file +var MeshServerCreateControl=function(t,e){var o={State:0,connectstate:0,pingTimer:null};return o.authCookie=e,o.trace=!1,o.xxStateChange=function(e,t){if(o.State!=e){var n=o.State;o.State=e,o.onStateChanged&&o.onStateChanged(o,o.State,n,t)}},o.Start=function(){if(0==o.connectstate){o.connectstate=0;var e=window.location.protocol.replace("http","ws")+"//"+window.location.host+t+"control.ashx"+(urlargs.key?"?key="+urlargs.key:"");o.authCookie&&""!=o.authCookie&&(e+="?auth="+o.authCookie),o.socket=new WebSocket(e),o.socket.onopen=function(e){o.connectstate=1},o.socket.onmessage=o.xxOnMessage,o.socket.onclose=function(e){o.Stop(e.code)},o.xxStateChange(1,0),null!=o.pingTimer&&clearInterval(o.pingTimer),o.pingTimer=setInterval(function(){o.send({action:"ping"})},29e3)}},o.Stop=function(e){o.connectstate=0,o.socket&&(o.socket.close(),delete o.socket),null!=o.pingTimer&&(clearInterval(o.pingTimer),o.pingTimer=null),o.xxStateChange(0,e)},o.xxOnMessage=function(e){var t;1==o.State&&o.xxStateChange(2);try{t=JSON.parse(e.data)}catch(e){return}if("object"==typeof t&&"pong"!=t.action){if("ping"==t.action&&o.send({action:"pong"}),"close"==t.action)return t.msg&&console.log(t.msg),void o.Stop(t.cause);o.trace&&console.log("RECV",t),o.onMessage&&o.onMessage(o,t)}},o.send=function(e){null!=o.socket&&1==o.connectstate&&(o.trace&&"ping"!=e.action&&console.log("SEND",e),o.socket.send(JSON.stringify(e)))},o} \ No newline at end of file diff --git a/public/scripts/meshcentral.js b/public/scripts/meshcentral.js index 260723a0..cd95251b 100644 --- a/public/scripts/meshcentral.js +++ b/public/scripts/meshcentral.js @@ -22,7 +22,7 @@ var MeshServerCreateControl = function (domain, authCookie) { obj.Start = function () { if (obj.connectstate != 0) return; obj.connectstate = 0; - var url = window.location.protocol.replace("http", "ws") + "//" + window.location.host + domain + "control.ashx"; + var url = window.location.protocol.replace('http', 'ws') + '//' + window.location.host + domain + 'control.ashx' + (urlargs.key ? ('?key=' + urlargs.key) : ''); if (obj.authCookie && (obj.authCookie != '')) { url += '?auth=' + obj.authCookie; } obj.socket = new WebSocket(url); obj.socket.onopen = function (e) { obj.connectstate = 1; } diff --git a/views/default.handlebars b/views/default.handlebars index 3ac200e7..971ad1dd 100644 --- a/views/default.handlebars +++ b/views/default.handlebars @@ -1298,6 +1298,7 @@ // Fetch URL arguments & do sanitation urlargs = parseUriArgs(); + if (urlargs.key != null) { urlargs.key = "" + urlargs.key; } if (urlargs.key && (isAlphaNumeric(urlargs.key) == false)) { delete urlargs.key; } if (urlargs.locale && (isAlphaNumeric(urlargs.locale) == false)) { delete urlargs.locale; } delete urlargs.viewmode; @@ -6366,7 +6367,7 @@ if ((servername.indexOf('.') == -1) || ((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. var domainUrlNoSlash = domainUrl.substring(0, domainUrl.length - 1); var portStr = (serverinfo.port == 443) ? '' : (':' + serverinfo.port); - var url = 'mcrouter://' + servername + portStr + domainUrl + 'control.ashx?c=' + authCookie + '&t=' + serverinfo.tlshash + '&l={{{lang}}}'; + var url = 'mcrouter://' + servername + portStr + domainUrl + 'control.ashx?c=' + authCookie + '&t=' + serverinfo.tlshash + '&l={{{lang}}}' + (urlargs.key?('&key=' + urlargs.key):''); //x += addHtmlValue("Launch", 'Start MeshCentral Router'); //x += '
' + "Start MeshCentral Router" + '' + ", for this link to work you must download MeshCentral Router run it and click the install button." + '
'; x += '
' + "Run MeshCentral Router and click \"install\" to make it launchable from the browser." + '
'; diff --git a/webserver.js b/webserver.js index fbca1886..db56241a 100644 --- a/webserver.js +++ b/webserver.js @@ -4801,7 +4801,12 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) { obj.app.get(url + 'health.ashx', function (req, res) { res.send('ok'); }); // TODO: Perform more server checking. obj.app.ws(url + 'webrelay.ashx', function (ws, req) { PerformWSSessionAuth(ws, req, false, handleRelayWebSocket); }); obj.app.ws(url + 'webider.ashx', function (ws, req) { PerformWSSessionAuth(ws, req, false, function (ws1, req1, domain, user, cookie) { obj.meshIderHandler.CreateAmtIderSession(obj, obj.db, ws1, req1, obj.args, domain, user); }); }); - obj.app.ws(url + 'control.ashx', function (ws, req) { PerformWSSessionAuth(ws, req, false, function (ws1, req1, domain, user, cookie) { obj.meshUserHandler.CreateMeshUser(obj, obj.db, ws1, req1, obj.args, domain, user); }); }); + obj.app.ws(url + 'control.ashx', function (ws, req) { + PerformWSSessionAuth(ws, req, false, function (ws1, req1, domain, user, cookie) { + if ((domain.loginkey != null) && (domain.loginkey.indexOf(req.query.key) == -1)) { ws.close(); return; } // Check 3FA URL key + obj.meshUserHandler.CreateMeshUser(obj, obj.db, ws1, req1, obj.args, domain, user); + }); + }); obj.app.ws(url + 'devicefile.ashx', function (ws, req) { obj.meshDeviceFileHandler.CreateMeshDeviceFile(obj, ws, null, req, domain); }); obj.app.get(url + 'devicefile.ashx', handleDeviceFile); obj.app.get(url + 'logo.png', handleLogoRequest);