From 2ab6d6d6debca507797110bf2157d0cead584602 Mon Sep 17 00:00:00 2001 From: lxsang Date: Mon, 6 Dec 2021 19:41:55 +0100 Subject: [PATCH] allow execute code from server --- Antunnel/build/debug/main.js | 2 +- Antunnel/build/debug/package.json | 2 +- Antunnel/build/release/Antunnel.zip | Bin 2807 -> 2973 bytes Antunnel/coffees/AntunnelService.coffee | 30 +++++++++++++++++++++++- Antunnel/package.json | 2 +- packages.json | 2 +- 6 files changed, 33 insertions(+), 5 deletions(-) diff --git a/Antunnel/build/debug/main.js b/Antunnel/build/debug/main.js index 67a3c92..668f24b 100644 --- a/Antunnel/build/debug/main.js +++ b/Antunnel/build/debug/main.js @@ -1 +1 @@ -(function(){var e,n,t,s,i;(t=class e{constructor(){this.header={sid:0,cid:0,type:0,size:0},this.data=void 0}as_raw(){var n,t,s;return s=5+this.header.size,(n=new Uint8Array(s))[0]=this.header.type,t=e.bytes_of(this.header.cid),n.set(t,1),t=e.bytes_of(this.header.sid),n.set(t,3),this.data&&n.set(this.data,5),n.buffer}}).decode=function(e){return new Promise((function(n,s){var i;return i=new t,!e||e.length<5?s("Invalid message format"):(i.header.type=e[0],i.header.cid=t.int_from(e,1),i.header.sid=t.int_from(e,3),i.header.size=e.length-5,i.data=e.slice(5,5+i.header.size),n(i))}))},t.bytes_of=function(e,n){var t;return 4!==n&&(n=2),t=new Uint8Array(n),2===n?(t[1]=255&e,e>>=8,t[0]=255&e,t):(t[3]=255&e,e>>=8,t[2]=255&e,e>>=8,t[1]=255&e,e>>=8,t[0]=255&e,t)},t.int_from=function(e,n,t){return 4!==t?e[n+1]|e[n]<<8:e[n+3]|e[n+2]<<8|e[n+1]<<16|e[n]<<24},t.OK=0,t.ERROR=1,t.DATA=6,t.CLOSE=5,t.SUBSCRIBE=2,t.UNSUBSCRIBE=3,t.CTRL=7,t.PING=8,s=class{constructor(e){this.channel=e,this.id=void 0,this.channel_id=void 0,this.onmessage=void 0,this.onerror=void 0,this.onopen=void 0,this.onclose=void 0,this.tunnel=void 0,this.is_opened=!1}send(e,n){if(this.tunnel){if(this.is_opened)return this.tunnel.send(this.genmsg(e,n));this.onerror&&this.onerror("Channel is not opened yet")}else this.onerror&&this.onerror("Tunnel is not opened")}genmsg(e,n){var s;return(s=new t).header.sid=this.id,s.header.cid=this.channel_id,s.header.type=e,s.header.size=n?n.length:0,s.data=n,s}close(e){if(this.is_opened=!1,this.tunnel)return this.tunnel.unsubscribe(this,e)}},e=class{constructor(e){this.uri=e,this.socket=void 0,this.pending={},this.subscribers={},this.onclose=void 0}ready(){return new Promise((e,n)=>this.uri?void 0!==this.socket?e():(console.log("Connect to "+this.uri),this.socket=new WebSocket(this.uri),this.socket.binaryType="arraybuffer",this.socket.onmessage=e=>this.process(e),this.socket.onclose=e=>{var n,t,s,i;for(n in this.socket=void 0,t=this.pending)(i=t[n]).tunnel=void 0,i.onclose&&i.onclose();for(n in s=this.subscribers)(i=s[n]).tunnel=void 0,i.is_opened=!1,i.onclose&&i.onclose();if(this.pending={},this.subscribe={},this.onclose())return this.onclose()},this.socket.onerror=e=>{var n,t,s,i,r;for(n in t=this.pending)(r=t[n]).onerror&&r.onerror(e.toString());for(n in i=[],s=this.subscribers)(r=s[n]).onerror&&i.push(r.onerror(e.toString()));return i},this.socket.onopen=n=>e()):n())}process(e){return t.decode(new Uint8Array(e.data)).then(e=>{var n,s;switch(n=(e,n)=>{var t;if(!(t=this.pending[e.header.sid]))return(t=this.subscribers[e.header.sid])&&t[n]?t[n](e):void 0;t[n]&&t[n](e)},e.header.type){case t.OK:if(!(s=this.pending[e.header.sid]))return n(e,"onmessage");if(delete this.pending[e.header.sid],s.id=t.int_from(e.data,0),s.channel_id=e.header.cid,this.subscribers[s.id]=s,s.is_opened=!0,s.onopen)return s.onopen();break;case t.DATA:return n(e,"onmessage");case t.CTRL:return n(e,"onctrl");case t.ERROR:return n(e,"onerror");case t.UNSUBSCRIBE:if(!(s=this.subscribers[e.header.sid]))return;return s.close(!0);case t.PING:break;default:return console.error(`Message of type ${e.header.type} is unsupported`,e)}}).catch(e=>{var n,t,s,i;for(n in t=this.pending)(i=t[n]).onerror&&i.onerror(e);for(n in s=this.subscribers)(i=s[n]).onerror&&i.onerror(e);return console.log(e)})}subscribe(e){return this.ready().then(()=>{for(e.tunnel=this,e.id=Math.floor(1e3*Math.random())+1;this.subscribers[e.id]||this.pending[e.id];)e.id=Math.floor(1e3*Math.random())+1;return this.pending[e.id]=e,this.send(e.genmsg(t.SUBSCRIBE,(new TextEncoder).encode(e.channel)))}).catch((function(n){if(e.onerror)return e.onerror(n.toString())}))}unsubscribe(e,n){return this.ready().then(()=>{if(this.subscribers[e.id])return n||this.send(e.genmsg(t.UNSUBSCRIBE,void 0)),e.onclose&&e.onclose(),delete this.subscribers[e.id],e.tunnel=void 0,e.is_opened=!1}).catch((function(n){if(e.onerror)return e.onerror(n.toString())}))}send(e){return this.socket.send(e.as_raw())}close(){if(console.log("Close connection to "+this.uri),this.socket&&this.socket.close(),this.onclose())return this.onclose()}},(i=this).Antunnel||(i.Antunnel={tunnel:void 0,init:function(n){return new Promise((function(t,s){return i.Antunnel.tunnel?t(i.Antunnel.tunnel):(i.Antunnel.tunnel=new e(n),i.Antunnel.tunnel.onclose=function(){return i.Antunnel.tunnel=void 0},i.Antunnel.tunnel.ready().then((function(){return t(i.Antunnel.tunnel)})).catch((function(e){return s(e)})))}))},Subscriber:s,Msg:t}),n=class extends OS.application.BaseService{constructor(e){super("AntunnelService",e),this.text=__("Tunnel"),this.iconclass="fa fa-close",this.is_connect=!1,this.nodes=[{text:__("Connect"),id:1},{text:__("Disconnect"),id:2},{text:__("Enter uri"),id:3},{text:__("Exit"),id:4}],this.onchildselect=e=>this.action(e)}init(){return this.watch(1500,()=>{var e;if(e=!1,void 0!==Antunnel.tunnel&&(e=!0),e!==this.is_connect)return this.is_connect=e,this.iconclass="fa fa-circle",this.is_connect||(this.iconclass="fa fa-close"),this.update()}),OS.onexit("cleanupAntunnel",()=>new Promise((e,n)=>(Antunnel.tunnel&&Antunnel.tunnel.close(),this.quit(),e(!0))))}action(e){var n;switch(n=()=>this._gui.openDialog("PromptDialog",{title:__("Tunnel uri"),label:__("Please enter tunnel uri"),value:"wss://localhost/tunnel"}).then(e=>{if(e&&""!==e)return this.systemsetting.system.tunnel_uri=e,this.start()}),e.data.item.data.id){case 1:if(this.is_connect)return;return this.systemsetting.system.tunnel_uri?this.start():n();case 2:if(Antunnel.tunnel)return Antunnel.tunnel.close();break;case 3:return Antunnel.tunnel&&Antunnel.tunnel.close(),n();case 4:return Antunnel.tunnel&&Antunnel.tunnel.close(),this.quit()}}start(){if(this.systemsetting.system.tunnel_uri&&!Antunnel.tunnel)return Antunnel.init(this.systemsetting.system.tunnel_uri).then(e=>this.notify(__("Tunnel now connected to the server at: {0}",this.systemsetting.system.tunnel_uri))).catch(e=>(Antunnel.tunnel&&Antunnel.tunnel.close(),this.error(__("Unable to connect to the tunnel: {0}",e.toString()),e)))}awake(){}},this.OS.register("AntunnelService",n)}).call(this); \ No newline at end of file +(function(){var e,n,t,s,i;(t=class e{constructor(){this.header={sid:0,cid:0,type:0,size:0},this.data=void 0}as_raw(){var n,t,s;return s=5+this.header.size,(n=new Uint8Array(s))[0]=this.header.type,t=e.bytes_of(this.header.cid),n.set(t,1),t=e.bytes_of(this.header.sid),n.set(t,3),this.data&&n.set(this.data,5),n.buffer}}).decode=function(e){return new Promise((function(n,s){var i;return i=new t,!e||e.length<5?s("Invalid message format"):(i.header.type=e[0],i.header.cid=t.int_from(e,1),i.header.sid=t.int_from(e,3),i.header.size=e.length-5,i.data=e.slice(5,5+i.header.size),n(i))}))},t.bytes_of=function(e,n){var t;return 4!==n&&(n=2),t=new Uint8Array(n),2===n?(t[1]=255&e,e>>=8,t[0]=255&e,t):(t[3]=255&e,e>>=8,t[2]=255&e,e>>=8,t[1]=255&e,e>>=8,t[0]=255&e,t)},t.int_from=function(e,n,t){return 4!==t?e[n+1]|e[n]<<8:e[n+3]|e[n+2]<<8|e[n+1]<<16|e[n]<<24},t.OK=0,t.ERROR=1,t.DATA=6,t.CLOSE=5,t.SUBSCRIBE=2,t.UNSUBSCRIBE=3,t.CTRL=7,t.PING=8,s=class{constructor(e){this.channel=e,this.id=void 0,this.channel_id=void 0,this.onmessage=void 0,this.onerror=void 0,this.onopen=void 0,this.onclose=void 0,this.tunnel=void 0,this.is_opened=!1}send(e,n){if(this.tunnel){if(this.is_opened)return this.tunnel.send(this.genmsg(e,n));this.onerror&&this.onerror("Channel is not opened yet")}else this.onerror&&this.onerror("Tunnel is not opened")}genmsg(e,n){var s;return(s=new t).header.sid=this.id,s.header.cid=this.channel_id,s.header.type=e,s.header.size=n?n.length:0,s.data=n,s}close(e){if(this.is_opened=!1,this.tunnel)return this.tunnel.unsubscribe(this,e)}},e=class{constructor(e){this.uri=e,this.socket=void 0,this.pending={},this.subscribers={},this.onclose=void 0}ready(){return new Promise((e,n)=>this.uri?void 0!==this.socket?e():(console.log("Connect to "+this.uri),this.socket=new WebSocket(this.uri),this.socket.binaryType="arraybuffer",this.socket.onmessage=e=>this.process(e),this.socket.onclose=e=>{var n,t,s,i;for(n in this.socket=void 0,t=this.pending)(i=t[n]).tunnel=void 0,i.onclose&&i.onclose();for(n in s=this.subscribers)(i=s[n]).tunnel=void 0,i.is_opened=!1,i.onclose&&i.onclose();if(this.pending={},this.subscribe={},this.onclose())return this.onclose()},this.socket.onerror=e=>{var n,t,s,i,r;for(n in t=this.pending)(r=t[n]).onerror&&r.onerror(e.toString());for(n in i=[],s=this.subscribers)(r=s[n]).onerror&&i.push(r.onerror(e.toString()));return i},this.socket.onopen=n=>e()):n())}process(e){return t.decode(new Uint8Array(e.data)).then(e=>{var n,s;switch(n=(e,n)=>{var t;if(!(t=this.pending[e.header.sid]))return(t=this.subscribers[e.header.sid])&&t[n]?t[n](e):void 0;t[n]&&t[n](e)},e.header.type){case t.OK:if(!(s=this.pending[e.header.sid]))return n(e,"onmessage");if(delete this.pending[e.header.sid],s.id=t.int_from(e.data,0),s.channel_id=e.header.cid,this.subscribers[s.id]=s,s.is_opened=!0,s.onopen)return s.onopen();break;case t.DATA:return n(e,"onmessage");case t.CTRL:return n(e,"onctrl");case t.ERROR:return n(e,"onerror");case t.UNSUBSCRIBE:if(!(s=this.subscribers[e.header.sid]))return;return s.close(!0);case t.PING:break;default:return console.error(`Message of type ${e.header.type} is unsupported`,e)}}).catch(e=>{var n,t,s,i;for(n in t=this.pending)(i=t[n]).onerror&&i.onerror(e);for(n in s=this.subscribers)(i=s[n]).onerror&&i.onerror(e);return console.log(e)})}subscribe(e){return this.ready().then(()=>{for(e.tunnel=this,e.id=Math.floor(1e3*Math.random())+1;this.subscribers[e.id]||this.pending[e.id];)e.id=Math.floor(1e3*Math.random())+1;return this.pending[e.id]=e,this.send(e.genmsg(t.SUBSCRIBE,(new TextEncoder).encode(e.channel)))}).catch((function(n){if(e.onerror)return e.onerror(n.toString())}))}unsubscribe(e,n){return this.ready().then(()=>{if(this.subscribers[e.id])return n||this.send(e.genmsg(t.UNSUBSCRIBE,void 0)),e.onclose&&e.onclose(),delete this.subscribers[e.id],e.tunnel=void 0,e.is_opened=!1}).catch((function(n){if(e.onerror)return e.onerror(n.toString())}))}send(e){return this.socket.send(e.as_raw())}close(){if(console.log("Close connection to "+this.uri),this.socket&&this.socket.close(),this.onclose())return this.onclose()}},(i=this).Antunnel||(i.Antunnel={tunnel:void 0,init:function(n){return new Promise((function(t,s){return i.Antunnel.tunnel?t(i.Antunnel.tunnel):(i.Antunnel.tunnel=new e(n),i.Antunnel.tunnel.onclose=function(){return i.Antunnel.tunnel=void 0},i.Antunnel.tunnel.ready().then((function(){return t(i.Antunnel.tunnel)})).catch((function(e){return s(e)})))}))},Subscriber:s,Msg:t}),n=class extends OS.application.BaseService{constructor(e){super("AntunnelService",e),this.text=__("Tunnel"),this.iconclass="fa fa-close",this.is_connect=!1,this.rsub=void 0,this.nodes=[{text:__("Connect"),id:1},{text:__("Disconnect"),id:2},{text:__("Enter uri"),id:3},{text:__("Exit"),id:4}],this.onchildselect=e=>this.action(e)}init(){return this.watch(1500,()=>{var e;if(e=!1,void 0!==Antunnel.tunnel&&(e=!0),e!==this.is_connect)return this.is_connect=e,this.iconclass="fa fa-circle",this.is_connect||(this.iconclass="fa fa-close"),this.update()}),OS.onexit("cleanupAntunnel",()=>new Promise((e,n)=>(Antunnel.tunnel&&Antunnel.tunnel.close(),this.quit(),e(!0))))}action(e){var n;switch(n=()=>this._gui.openDialog("PromptDialog",{title:__("Tunnel uri"),label:__("Please enter tunnel uri"),value:"wss://localhost/tunnel"}).then(e=>{if(e&&""!==e)return this.systemsetting.system.tunnel_uri=e,this.start()}),e.data.item.data.id){case 1:if(this.is_connect)return;return this.systemsetting.system.tunnel_uri?this.start():n();case 2:if(Antunnel.tunnel)return Antunnel.tunnel.close();break;case 3:return Antunnel.tunnel&&Antunnel.tunnel.close(),n();case 4:return this.rsub&&this.rsub.close(),Antunnel.tunnel&&Antunnel.tunnel.close(),this.quit()}}update(){return super.update(),this.is_connect?(this.rsub=new Antunnel.Subscriber("rcmd"),this.rsub.onopen=()=>console.log("Subscribed to rcmd topic"),this.rsub.onerror=e=>(console.log(e),this.rsub=void 0),this.rsub.onmessage=e=>{if(e.data)return this.runcmd(new TextDecoder("utf-8").decode(e.data))},this.rsub.onclose=()=>(this.rsub=void 0,console.log("rcmd closed")),Antunnel.tunnel.subscribe(this.rsub)):this.rsub=void 0}start(){if(this.systemsetting.system.tunnel_uri&&!Antunnel.tunnel)return Antunnel.init(this.systemsetting.system.tunnel_uri).then(e=>this.notify(__("Tunnel now connected to the server at: {0}",this.systemsetting.system.tunnel_uri))).catch(e=>(Antunnel.tunnel&&Antunnel.tunnel.close(),this.error(__("Unable to connect to the tunnel: {0}",e.toString()),e)))}awake(){}runcmd(e){var n;try{return new Function(e)()}catch(e){return n=e,console.log(n)}}},this.OS.register("AntunnelService",n)}).call(this); \ No newline at end of file diff --git a/Antunnel/build/debug/package.json b/Antunnel/build/debug/package.json index 4798e61..fcb9a4a 100644 --- a/Antunnel/build/debug/package.json +++ b/Antunnel/build/debug/package.json @@ -9,7 +9,7 @@ "author": "Xuan Sang LE", "email": "xsang.le@lxsang.me" }, - "version":"0.2.0-b", + "version":"0.2.1-b", "category":"Library", "iconclass":"fa fa-adn", "mimes":["none"], diff --git a/Antunnel/build/release/Antunnel.zip b/Antunnel/build/release/Antunnel.zip index 6d23f157fefbf41e2044cdf7a5d9073131e647d5..e6bd64c572aaf7e8efb73477a64ba16446c7a558 100644 GIT binary patch delta 2598 zcmZ{mXEfUjAIDQd?TAq`rCO>+>{`V&+aPF(QTo)15wj{bf3sGN)TY#KMeNcm_G+k6 zTkWDjjayr(a@{x2J?A;+`M&v`@9)L;oX@+@F?%itV5CP0rUQXMG$0iAg|U-Iiq5CY zhQ0yHJs+`}DhB*oMz$uQ@y{f$e+dJ9ZR$wJ9O&tfatAr6f-78IvI z{Z@7!qXFj;n)Xk&d;~Pqu@YR2>Tv5pY?nTFDK73O-&UVW>McGU14`+91U5#DVZa~Y zZG4qsfU2)OLkmy-suRpQoCf zRhpKV%Vq3cbR6+IiFS2b+HwHyT-Kef%cJqF`d92talHgpUV5rH3P(S(7B~7-;&rGv zYq4d0+Phys!+dcd<-gFBm((?knpc2-=#7Q1JBQPNKucU8(A7(NHyda7OY{o!K#y4k zmJ5-%YRPW;@{foXvtCq$s#o-K!>j<}830x{#gU{QM(xFUj}nT0w031^ee$^*sK6g1 z=%w&_&BGyez^plyuu5yO$c_Z38Y8ICV_K_d6b-b4NN7wR#HV5-0DG?vEn=uGHL~@Z zYdUQB(M1MCubr>sy!}l&hG=mk{;blWZarVT8)ZB<8-E}-M*R)HgzLTi>-wxoO+M{s z#ku>7oEcS%a>(6e8VxuT{P~+l^9VH4_rnPAGt_5RfP*ZM`j*08;Ctql5S!`}^gEg_ zVGD1W&#LX$lKr^=aJGCkluvL>_H_W)Ht612YP)+V&YFB{UiED!XQ(1M%hY&O#V;uG zJw?b(4i6!cK&;wsQ=!J#d^m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?(Q8M45jD+3_>JJ7av2ZY=CK+$+)S zbwj4EP{)U8H(Dy=rmuh9yQk)cO2_v3Q-}};l%!>WkX0_w+a>Cj%RrVvc<3&Zj?C(n zKVf>ISJ6(Ic*=NIJzOeZgqgx61NLEus7)TQg08AE$1OBikI-n1WNqEU@`_jK^E6$OI`@AF5%tgjr|LhHG%*n|QA=}zn+Oa(LXl0LDd@x+muNx6GXx1#bq$-W z33WKlpa5w>c;{`ZYnk7#m>%qi&`wzc4_>zb=t?oUP6h2iq{33;H7B84W2jFNoW4%1 znyPXq`?Rn$s#y1Ea#)C4!*rY1Ez^Xw;Wxv-heY@{_K14pD5NDOB6fXR3kq&ONKRVPu??;`-da{@Qh2S z0t{JmcHBAp#_W}s^>q`lOIFMTrZ5WQTIzqy8Msyf7x@8k6`+)9 zMuwgT2LpAE{R6mhqBTM%Sv=doK2x$PFSc!one>$Dtz*_J>||6f5{f~9n1V)$Lgbh6 z^~wnyYSng(M$wj9{pjxC!QX3TKB`*-6`ze^P1*L^OgDDjEY?_H5gy;OOaqe=U?qRe zDnw^8SwPapn{{=OO%XNJ_Gi=tkqmSkNT22|E7p*N_d+BuUKC}X70Xh{7gpoi>w=Xt z2ZJy~S3$=);z3Bb6(A*|uU%QiZ~Q@3W|hi@tEIy9w)nL_q%_)dHLmcU-crTuB|3*<$hZI!QkM(wA3m59A0ez zSVWR+{t$Vg#>;zGAz`KpB+>^00TClDlS!~Ss@<^uA1@KFgZ<8wGChEj>I=`N1t>Z4 z_74zBBwIs`Je@HTQCnrTO+_wkWKc^10u%rW000080C#YEQ&%5Y$jSf!0A&FH y01N;C00000000000000+0h0|28V+}Gds9nXU@_bW006odlWYqs20ID>0001@RCECV diff --git a/Antunnel/coffees/AntunnelService.coffee b/Antunnel/coffees/AntunnelService.coffee index 047ff40..d9402cd 100644 --- a/Antunnel/coffees/AntunnelService.coffee +++ b/Antunnel/coffees/AntunnelService.coffee @@ -4,6 +4,7 @@ class AntunnelService extends OS.application.BaseService @text = __("Tunnel") @iconclass = "fa fa-close" @is_connect = false + @rsub = undefined @nodes = [ {text: __("Connect"), id: 1}, {text: __("Disconnect"), id: 2}, @@ -55,9 +56,30 @@ class AntunnelService extends OS.application.BaseService Antunnel.tunnel.close() if Antunnel.tunnel ask() when 4 + @rsub.close() if @rsub Antunnel.tunnel.close() if Antunnel.tunnel @quit() - + update: () -> + super.update() + if(@is_connect) + @rsub = new Antunnel.Subscriber("rcmd") + @rsub.onopen = () => + console.log("Subscribed to rcmd topic") + + @rsub.onerror = (e) => + console.log e + @rsub = undefined + + @rsub.onmessage = (e) => + @runcmd(new TextDecoder("utf-8").decode(e.data)) if e.data + + @rsub.onclose = () => + @rsub = undefined + console.log("rcmd closed") + + Antunnel.tunnel.subscribe @rsub + else + @rsub = undefined start: () -> return unless @systemsetting.system.tunnel_uri return if Antunnel.tunnel @@ -68,6 +90,12 @@ class AntunnelService extends OS.application.BaseService @error __("Unable to connect to the tunnel: {0}", e.toString()), e awake: () -> + + runcmd: (code) -> + try + new Function(code)() + catch e + console.log(e) this.OS.register "AntunnelService", AntunnelService \ No newline at end of file diff --git a/Antunnel/package.json b/Antunnel/package.json index 4798e61..fcb9a4a 100644 --- a/Antunnel/package.json +++ b/Antunnel/package.json @@ -9,7 +9,7 @@ "author": "Xuan Sang LE", "email": "xsang.le@lxsang.me" }, - "version":"0.2.0-b", + "version":"0.2.1-b", "category":"Library", "iconclass":"fa fa-adn", "mimes":["none"], diff --git a/packages.json b/packages.json index e97615f..9a2aaa8 100644 --- a/packages.json +++ b/packages.json @@ -55,7 +55,7 @@ "description": "https://raw.githubusercontent.com/lxsang/antosdk-apps/master/Antunnel/README.md", "category": "Library", "author": "Xuan Sang LE", - "version": "0.2.0-b", + "version": "0.2.1-b", "dependencies": [], "download": "https://raw.githubusercontent.com/lxsang/antosdk-apps/master/Antunnel/build/release/Antunnel.zip" },