From a2a37a07959d2f4db67bac3e2e466265491b0564 Mon Sep 17 00:00:00 2001 From: Ylian Saint-Hilaire Date: Tue, 9 Apr 2019 15:51:05 -0700 Subject: [PATCH] Fixed MeshCMD AMT Script Exception --- agents/MeshCmd-signed.exe | Bin 3466320 -> 3466336 bytes agents/MeshCmd64-signed.exe | Bin 3442768 -> 3442784 bytes agents/MeshService-signed.exe | Bin 2572168 -> 2566656 bytes agents/MeshService64-signed.exe | Bin 2548616 -> 2548616 bytes agents/modules_meshcmd/amt-script.js | 8 +- agents/modules_meshcmd_min/amt-script.min.js | 2 +- meshagent.js | 181 +++++++++++++------ meshuser.js | 4 + public/styles/style.css | 2 +- views/default-min.handlebars | 2 +- views/default.handlebars | 1 - views/login-min.handlebars | 2 +- views/login.handlebars | 2 +- views/messenger-min.handlebars | 2 +- 14 files changed, 137 insertions(+), 69 deletions(-) diff --git a/agents/MeshCmd-signed.exe b/agents/MeshCmd-signed.exe index cad927b78dff4e9102f864b92446fdffb22b01fe..9400b575844f1e8b9583c1ba7a03945e2d8d6543 100644 GIT binary patch delta 909 zcmX}idr;B`8~|{CKj25CEXZFvLz+SgzCaN5sB{_XS!cV7>|JJdVTdx_O0tKKPH9nj zWo8fWy2@$VEaoHp-H~vVml;BaH*LAV)`n?rJG7ZStZ)DH$LGJ#qaFw10(uRC{&c>& z7)eA%j}nNMKt4kO36KE=V1Nqd02-JJynzp(gRj6mzyM4zANT?sEC7DMAAAi0z(T+R zfq)Gbfp0(%2nHO$1&cul2sIE0FP(2d!+G0#efI9*tAZ2q_o-B22WvB@c>A>jQ#`;2 zVIUktfJhJp1V9L)fe45V15+`RPY`Quk4^!-rmEA|h+I-VyZiJT3SH5E%?kc=FFl;>5dCF@-sfcJ~7YXuDmn;ek z%p`7SB{~hU<7$PhoBOcwudF$weAmd*;v0%Y^)CNxopP*eL)05L)oBuHRAo&V?cVc* zm22#(x%i>2$5%~OrH&onIhm2G=rixwWp2hNY=1Y6JhAL6uwD0g8Ejth5mi?R8cfEP zf2_j#0KJxOEedwg;%CkPSX(@S>#8? zrFW&7O{3kn7Pm2#%DnQPI$8HG(ey6~K`372a>T3iv6pML{r(`1AGvV$yI5mDF2h7H z+7Iw6gt`>{mHq0F4e|1eBhLTlNtYVd`)RK=Rx5sZq%O;m%(MlUP>A9NqLUODCy@1P zdlBP$Q=#16amuVHZC@7|*74$yihi&K|6cLi;pM~Wb#b%0Ql{n4>}%+gatg6MW^2QEle_u~RE3kZP-%myC76Ntea-~}WA)%WAx!!MC$%+w*x zU?LYrgele&aqZK2a^Lug>g#t#-s|H!rOpgyqFR2pwHveNa{`JtM^v%+qN+gbuvway zW5*5U9{5#M_N;^=T}ksx4j(N{dYocen@Z|BJ407HLdk^924&^p#=;c6c{=3{4m?G`e5y_sjEtnIEs%jb9aSB z2IyX}Hv~&qLPGBWyOZ}+`_WXQQ%=iUwa*D1@B6PP_KL#uZh3XTWpmdQ7f{$&62tXm zT(D`0;G2j<`?DuwsoiHW_tTKU|83)`-Ah+Y85^tj=Hj|o=ChMzgNXQ*hwq5k1|4#@) zvLfz7tQ^h+T5K?Pl{hM*s-?7_`stqE4br;o=zb7{fT$S z2eS8`8=rR!bxsiawVlqfX&sbp48lWVdvPo4nsj;B_!gOq;X<~~aX9UW`|?b!jpHFx zF)jC0d`uFLeQoGTkT2C-sbCs%`Hu0fjKx_RV)9iHL3n#}cu4t{vZ$~-mDr_oyt+q< zP|7Vb*5`eU%yH2~J{&Np5;U0^+H!4&JfES|l&6_W=?e!#u%amY>g~eLzQ|x~zV2mv z)AKled5=UKGo1CERcEwJ@-(J%IvKJ4AD7KzaUVSOuece(@i9zWcxmT`Z9SxkO+_5@ EUv9mPtpET3 diff --git a/agents/MeshCmd64-signed.exe b/agents/MeshCmd64-signed.exe index 0e7392b6a5a747fa2c8c814aec923ac1c85686ee..aa0818a493deaa433d0a3bfb9e79a6411a4a29eb 100644 GIT binary patch delta 910 zcmX}qZBPqv9KiAYS6k9r4{GyJO{}rfV zMN*wCVj88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Y?*VPZnHpqT}Im$;28^q6#%(4i%Fz}v>#b@6DPEJ-Algr`!1Tsro0 zO?J@nlM>}|+O$#A_&Wcp9FsEX>Y6#q58u#_#Y)lMcG|NBS3RUBa_xA8mf1A-zYD}8 z$jyW0y9@h?U3%JayUyE`1hh}AP6({aT~Kmsv?6@=p&d2!3Q9_q&*>xk1F!pfbq4tC z=*@A_Zk}sL$TgFm|8xlLtLhqjZU=Q4=x?q4*z=bR^+iGHK-;92UGuGoM~rv%X7stQ zWVI5MhVFehSM4u8M=gqujXu)7t=zB9!_m@K?$bK=>&Nz*D@PBK->Al@ZC;b>z3J1| zr`;oe%yt~1xgoHEu9kT45~ea`jm%D3n$<@qdZ^`}PKV-T6ZECGO37?Dywuh9!6t;B J1x{z7{{c4q-t7PY diff --git a/agents/MeshService64-signed.exe b/agents/MeshService64-signed.exe index f499154d71a4206ff2726d83393907f7942382ba..6a24af090ddc5b47ca9666f16bd80465fb801320 100644 GIT binary patch delta 449 zcmeA;KAW)vh&OaFGWA?(?qY23Vgz9(AZ7+)79eH?Vm2UV2VxE&<^*CcAm#>Q9w6og zVm=_|2Vwyr76f7;AQlE<5g--?Vlf~V2Vw~zmIPucAeIJV86cJgVmTm|2Vw;vRs>=t zAXWxq6(CmK-o>c4;{m6Mfu)g=vALn)bni!Mmh}>DM>CWjanC(dv%`reKkdDMxz`kj zH>}${7o;AW^i|^Ok75_6z^8xz&OUC-c_s3x*tNE@pBkQxFF4n`9|&c;bt*~pnWFIb zfccFJg!iRyJn=dIx8LH2N}C^bm0wcWAeflTDb&91chbbf2UmBzee$II!@hWK|JLk@ zm-y}mY&okhU;lNgQsUa%Kioh5oY}3&vPnhvxQ6KI&F8LN+Pg?g=<>%?mV4#g^wT$f zWt|%5eO_^8=sjPjptPm8L!#N<9eiA(mitCJGez2{s6%PvqB4nv$E0@p^n5lu!0aU5 xf85Tv;d8FbV%N0ybJ!(21T(8v&YQKU>V}!o-gL?Rg->^-nka8%E3IJw0sy|hx)}ff delta 449 zcmeA;KAW)vh&OaFGR;5J+{M`5#R$SoK+FupEI`Z(#B4y!4#XTl%n8I?K+FxqJV49~ z#C$-^55xjMEC|FxKr9TzB0ww(#9}}!4#W~bED6L?Kr9W!GC(W~#Bx9^55x*UtO&$P zK&%YJDnP8dy^B$8#{*7dBMT!VLknYz>E4gjEbFh_xwc{6-LSq#Sp|xUFQ*=G)$ds; zDtV*JaGhSK%b4AR*hO(C??{(O27t+)Rav@AP+KAXOZbRNg=gUJDjGTLjbZ~5PCW93OGR$s7Ufr-4gM(oQ4OO&OH zO|(8*tYtr4|M^M(dA9k@&$l~uKdUdSJiGeC^Y96^<$U#(bAJ_9r0<`7?ReGnJK|C) z8(+3^yBzHo@blc88YHkfyKO?UKZno8T2TQ9-gfEtb1J1nEQJo52+UM@pZ7y`QSaeL wo6GMx{yP1|L&KR{xGz*~iq=j(i`%!(q{yaDYSyUu&JcFkaUz@gOa>qT0B=CDHvj+t diff --git a/agents/modules_meshcmd/amt-script.js b/agents/modules_meshcmd/amt-script.js index d00ed101..b52285be 100644 --- a/agents/modules_meshcmd/amt-script.js +++ b/agents/modules_meshcmd/amt-script.js @@ -109,10 +109,10 @@ module.exports.setup = function(binary, startvars) { var argcount = ReadShort(obj.script, obj.ip + 4); var argptr = obj.ip + 6; var args = []; - + // Clear all temp variables (This is optional) for (var i in obj.variables) { if (i.startsWith('__')) { delete obj.variables[i]; } } - + // Loop on each argument, moving forward by the argument length each time for (var i = 0; i < argcount; i++) { var arglen = ReadShort(obj.script, argptr); @@ -122,7 +122,7 @@ module.exports.setup = function(binary, startvars) { if (argtyp < 2) { // Get the value and replace all {var} with variable values argval = argval.toString(); - while (argval.split("{").length > 1) { var t = argval.split("{").pop().split("}").shift(); argval = argval.replace('{' + t + '}', obj.getVar(t)); } + if (argval != null) { while (argval.split("{").length > 1) { var t = argval.split("{").pop().split("}").shift(); argval = argval.replace('{' + t + '}', obj.getVar(t)); } } if (argtyp == 1) { obj.variables['__' + i] = decodeURI(argval); argval = '__' + i; } // If argtyp is 1, this is a literal. Store in temp variable. args.push(argval); } @@ -132,7 +132,7 @@ module.exports.setup = function(binary, startvars) { } argptr += (2 + arglen); } - + // Move instruction pointer forward by command size obj.ip += cmdlen; diff --git a/agents/modules_meshcmd_min/amt-script.min.js b/agents/modules_meshcmd_min/amt-script.min.js index 244ee297..62a1a11e 100644 --- a/agents/modules_meshcmd_min/amt-script.min.js +++ b/agents/modules_meshcmd_min/amt-script.min.js @@ -1 +1 @@ -script_functionTable1=["nop","jump","set","print","dialog","getitem","substr","indexof","split","join","length","jsonparse","jsonstr","add","substract","parseint","wsbatchenum","wsput","wscreate","wsdelete","wsexec","scriptspeed","wssubscribe","wsunsubscribe","readchar","signwithdummyca"];script_functionTable2=["encodeuri","decodeuri","passwordcheck","atob","btoa","hex2str","str2hex","random","md5","maketoarray","readshort","readshortx","readint","readsint","readintx","shorttostr","shorttostrx","inttostr","inttostrx"];script_functionTableX2=[encodeURI,decodeURI,passwordcheck,atob,btoa,hex2rstr,rstr2hex,random,rstr_md5,MakeToArray,ReadShort,ReadShortX,ReadInt,ReadSInt,ReadIntX,ShortToStr,ShortToStrX,IntToStr,IntToStrX];function MakeToArray(a){if(!a||a==null||typeof a=="object"){return a}return[a]}function ReadShort(b,a){return(b[a]<<8)+b[a+1]}function ReadShortX(b,a){return(b[a+1]<<8)+b[a]}function ReadInt(b,a){return(b[a]*16777216)+(b[a+1]<<16)+(b[a+2]<<8)+b[a+3]}function ReadSInt(b,a){return(b[a]<<24)+(b[a+1]<<16)+(b[a+2]<<8)+b[a+3]}function ReadIntX(b,a){return(b[a+3]*16777216)+(b[a+2]<<16)+(b[a+1]<<8)+b[a]}function ShortToStr(a){return String.fromCharCode((a>>8)&255,a&255)}function ShortToStrX(a){return String.fromCharCode(a&255,(a>>8)&255)}function IntToStr(a){return String.fromCharCode((a>>24)&255,(a>>16)&255,(a>>8)&255,a&255)}function IntToStrX(a){return String.fromCharCode(a&255,(a>>8)&255,(a>>16)&255,(a>>24)&255)}function btoa(a){return Buffer.from(a).toString("base64")}function atob(b){var c=null;try{c=Buffer.from(b,"base64").toString()}catch(a){console.log(a)}return c}function passwordcheck(g){if(g.length<8){return false}var h=0,d=0,f=0,e=0;for(var b in g){var a=g.charCodeAt(b);if((a>64)&&(a<91)){h=1}else{if((a>96)&&(a<123)){d=1}else{if((a>47)&&(a<58)){f=1}else{e=1}}}}return((h+d+f+e)==4)}function hex2rstr(a){Buffer.from(a,"hex").toString()}function rstr2hex(a){Buffer.from(a).toString("hex")}function random(){return Math.floor(Math.random()*max)}function rstr_md5(a){return hex2rstr(hex_md5(a))}function getItem(b,c,d){for(var a in b){if(b[a][c]==d){return b[a]}}return null}var httpErrorTable={200:"OK",401:"Authentication Error",408:"Timeout Error",601:"WSMAN Parsing Error",602:"Unable to parse HTTP response header",603:"Unexpected HTTP enum response",604:"Unexpected HTTP pull response",998:"Invalid TLS certificate"};module.exports.setup=function(a,c){var b={startvars:c,onCompleted:null};if(a.length<6){console.error("Invalid script length");return null}if(ReadInt(a,0)!=612182341){console.error("Invalid binary script");return null}if(ReadShort(a,4)>1){console.error("Unsupported script version");return null}b.script=a.slice(6);b.reset=function(d){b.stop();b.ip=0;b.variables=c;b.state=1};b.start=function(d){b.stop();if(d==null){b.stepspeed=10}else{b.stepspeed=d}if(b.stepspeed>0){b.timer=setInterval(function(){b.step()},b.stepspeed)}};b.stop=function(){if(b.timer!=null){clearInterval(b.timer)}b.timer=null;b.stepspeed=0};b.getVar=function(d){if(d==undefined){return undefined}return b.getVarEx(d.split("."),b.variables)};b.getVarEx=function(f,g){try{if(f==undefined){return undefined}if(f.length==0){return g}return b.getVarEx(f.slice(1),g[f[0]])}catch(d){return null}};b.setVar=function(d,e){b.setVarEx(d.split("."),b.variables,e)};b.setVarEx=function(d,f,e){if(d.length==1){f[d[0]]=e}else{b.setVarEx(d.slice(1),f[d[0]],e)}};b.step=function(){if(b.state!=1){return}if(b.ip1){var r=l.split("{").pop().split("}").shift();l=l.replace("{"+r+"}",b.getVar(r))}if(k==1){b.variables["__"+p]=decodeURI(l);l="__"+p}h.push(l)}if(k==2||k==3){b.variables["__"+p]=ReadSInt(l,0);h.push("__"+p)}g+=(2+f)}b.ip+=n;var j=[];for(var p=0;p<10;p++){j.push(b.getVar(h[p]))}var q;try{if(m<10000){switch(m){case 0:break;case 1:if(j[2]){if((j[2]=="<"&&j[1]="&&j[1]>=j[3])||(j[2]==">"&&j[1]>j[3])){b.ip=j[0]}}else{b.ip=j[0]}break;case 2:if(h[1]==undefined){delete b.variables[h[0]]}else{b.setVar(h[0],j[1])}break;case 3:var s=b.toString(j[0]);if(s.indexOf("INFO: ")==0){s=s.substring(6)}if(s.indexOf("SUCCESS: ")==0){s=s.substring(9)}if(b.onConsole){b.onConsole(s,b)}else{console.log(s)}break;case 4:b.state=2;b.dialog=true;setDialogMode(11,j[0],j[2],b.xxStepDialogOk,j[1],b);break;case 5:for(var p in j[1]){if(j[1][p][j[2]]==j[3]){q=p}}break;case 6:q=j[1].substr(j[2],j[3]);break;case 7:q=j[1].indexOf(j[2]);break;case 8:q=j[1].split(j[2]);break;case 9:q=j[1].join(j[2]);break;case 10:if(j[1]==null){q=0}else{q=j[1].length}break;case 11:q=JSON.parse(j[1]);break;case 12:q=JSON.stringify(j[1]);break;case 13:q=(j[1]+j[2]);break;case 14:q=(j[1]-j[2]);break;case 15:q=parseInt(j[1]);break;case 16:b.state=2;b.amtstack.BatchEnum(j[0],j[1],b.xxWsmanReturn,b);break;case 17:b.state=2;b.amtstack.Put(j[0],j[1],b.xxWsmanReturn,b);break;case 18:b.state=2;b.amtstack.Create(j[0],j[1],b.xxWsmanReturn,b);break;case 19:b.state=2;b.amtstack.Delete(j[0],j[1],b.xxWsmanReturn,b);break;case 20:b.state=2;b.amtstack.Exec(j[0],j[1],j[2],b.xxWsmanReturn,b,0,j[3]);break;case 21:b.stepspeed=j[0];if(b.timer!=null){clearInterval(b.timer);b.timer=setInterval(function(){b.step()},b.stepspeed)}break;case 22:b.state=2;b.amtstack.Subscribe(j[0],j[1],j[2],b.xxWsmanReturn,b,0,j[3],j[4],j[5],j[6]);break;case 23:b.state=2;b.amtstack.UnSubscribe(j[0],b.xxWsmanReturn,b,0,j[1]);break;case 24:console.log(j[1],j[2],j[1].charCodeAt(j[2]));q=j[1].charCodeAt(j[2]);break;case 25:break;default:b.state=9;console.error("Script Error, unknown command: "+m)}}else{if(m<20000){q=script_functionTableX2[m-10000](j[1],j[2],j[3],j[4],j[5],j[6])}else{}}if(q!=undefined){b.setVar(h[0],q)}}catch(o){if(typeof o=="object"){o=o.message}b.setVar("_exception",o)}}if(b.state==1&&b.ip>=b.script.length){b.state=0;b.stop();if(b.onCompleted){b.onCompleted()}}if(b.onStep){b.onStep(b)}return b};b.xxStepDialogOk=function(d){b.variables.DialogSelect=d;b.state=1;b.dialog=false;if(b.onStep){b.onStep(b)}};b.xxWsmanReturn=function(f,d,e,g){b.setVar(d,e);b.setVar("wsman_result",g);b.setVar("wsman_result_str",((httpErrorTable[g])?(httpErrorTable[g]):("Error #"+g)));b.state=1;if(b.onStep){b.onStep(b)}};b.toString=function(d){if(typeof d=="object"){return JSON.stringify(d)}return d};b.reset();return b};module.exports.compile=function(o,l){var n="",q=o.split("\n"),h={},k=[],s=[];for(var d in q){var p=q[d];if(p.startsWith("##SWAP ")){var u=p.split(" ");if(u.length==3){s[u[1]]=u[2]}}if(p[0]=="#"||p.length==0){continue}for(var u in s){p=p.split(u).join(s[u])}var f=p.match(/"[^"]*"|[^\s"]+/g);if(f.length==0){continue}if(p[0]==":"){h[f[0].toUpperCase()]=n.length;continue}var c=script_functionTable1.indexOf(f[0].toLowerCase());if(c==-1){c=script_functionTable2.indexOf(f[0].toLowerCase());if(c>=0){c+=10000}}if(c==-1){if(l){l("Unabled to compile, unknown command: "+f[0])}return""}var b=ShortToStr(f.length-1);for(var e in f){if(e==0){continue}if(f[e][0]==":"){k.push([f[e],n.length+b.length+7]);b+=ShortToStr(5)+String.fromCharCode(3)+IntToStr(4294967295)}else{var a=parseInt(f[e]);if(a==f[e]){b+=ShortToStr(5)+String.fromCharCode(2)+IntToStr(a)}else{if(f[e][0]=='"'&&f[e][f[e].length-1]=='"'){b+=ShortToStr(f[e].length-1)+String.fromCharCode(1)+f[e].substring(1,f[e].length-1)}else{b+=ShortToStr(f[e].length+1)+String.fromCharCode(0)+f[e]}}}}b=ShortToStr(c)+ShortToStr(b.length+4)+b;n+=b}for(d in k){var g=k[d][0].toUpperCase(),m=k[d][1],t=h[g];if(t==undefined){if(l){l("Unabled to compile, unknown label: "+g)}return""}n=n.substr(0,m)+IntToStr(t)+n.substr(m+4)}return IntToStr(612182341)+ShortToStr(1)+n};module.exports.decompile=function(g,q){var t="",s=6,m=0,n={};if(q>=0){s=q}else{if(g.length<6){return"# Invalid script length"}var p=ReadInt(g,0);var w=ReadShort(g,4);if(p!=612182341){return"# Invalid binary script: "+p}if(w!=1){return"# Invalid script version"}}while(s=0)){t+=":label"+(s-6)+"\n"}for(var k=0;k=10000)&&(h<10000)){t+=script_functionTable2[h-10000]+d+"\n"}}s+=j;if(q>=0){return t}}var u=t.split("\n");t="";for(var k in u){var o=u[k];if(o[0]!=":"){t+=o+"\n"}else{if(n[o]){t+=o+"\n"}}}return t}; \ No newline at end of file +script_functionTable1=["nop","jump","set","print","dialog","getitem","substr","indexof","split","join","length","jsonparse","jsonstr","add","substract","parseint","wsbatchenum","wsput","wscreate","wsdelete","wsexec","scriptspeed","wssubscribe","wsunsubscribe","readchar","signwithdummyca"];script_functionTable2=["encodeuri","decodeuri","passwordcheck","atob","btoa","hex2str","str2hex","random","md5","maketoarray","readshort","readshortx","readint","readsint","readintx","shorttostr","shorttostrx","inttostr","inttostrx"];script_functionTableX2=[encodeURI,decodeURI,passwordcheck,atob,btoa,hex2rstr,rstr2hex,random,rstr_md5,MakeToArray,ReadShort,ReadShortX,ReadInt,ReadSInt,ReadIntX,ShortToStr,ShortToStrX,IntToStr,IntToStrX];function MakeToArray(a){if(!a||a==null||typeof a=="object"){return a}return[a]}function ReadShort(b,a){return(b[a]<<8)+b[a+1]}function ReadShortX(b,a){return(b[a+1]<<8)+b[a]}function ReadInt(b,a){return(b[a]*16777216)+(b[a+1]<<16)+(b[a+2]<<8)+b[a+3]}function ReadSInt(b,a){return(b[a]<<24)+(b[a+1]<<16)+(b[a+2]<<8)+b[a+3]}function ReadIntX(b,a){return(b[a+3]*16777216)+(b[a+2]<<16)+(b[a+1]<<8)+b[a]}function ShortToStr(a){return String.fromCharCode((a>>8)&255,a&255)}function ShortToStrX(a){return String.fromCharCode(a&255,(a>>8)&255)}function IntToStr(a){return String.fromCharCode((a>>24)&255,(a>>16)&255,(a>>8)&255,a&255)}function IntToStrX(a){return String.fromCharCode(a&255,(a>>8)&255,(a>>16)&255,(a>>24)&255)}function btoa(a){return Buffer.from(a).toString("base64")}function atob(b){var c=null;try{c=Buffer.from(b,"base64").toString()}catch(a){console.log(a)}return c}function passwordcheck(g){if(g.length<8){return false}var h=0,d=0,f=0,e=0;for(var b in g){var a=g.charCodeAt(b);if((a>64)&&(a<91)){h=1}else{if((a>96)&&(a<123)){d=1}else{if((a>47)&&(a<58)){f=1}else{e=1}}}}return((h+d+f+e)==4)}function hex2rstr(a){Buffer.from(a,"hex").toString()}function rstr2hex(a){Buffer.from(a).toString("hex")}function random(){return Math.floor(Math.random()*max)}function rstr_md5(a){return hex2rstr(hex_md5(a))}function getItem(b,c,d){for(var a in b){if(b[a][c]==d){return b[a]}}return null}var httpErrorTable={200:"OK",401:"Authentication Error",408:"Timeout Error",601:"WSMAN Parsing Error",602:"Unable to parse HTTP response header",603:"Unexpected HTTP enum response",604:"Unexpected HTTP pull response",998:"Invalid TLS certificate"};module.exports.setup=function(a,c){var b={startvars:c,onCompleted:null};if(a.length<6){console.error("Invalid script length");return null}if(ReadInt(a,0)!=612182341){console.error("Invalid binary script");return null}if(ReadShort(a,4)>1){console.error("Unsupported script version");return null}b.script=a.slice(6);b.reset=function(d){b.stop();b.ip=0;b.variables=c;b.state=1};b.start=function(d){b.stop();if(d==null){b.stepspeed=10}else{b.stepspeed=d}if(b.stepspeed>0){b.timer=setInterval(function(){b.step()},b.stepspeed)}};b.stop=function(){if(b.timer!=null){clearInterval(b.timer)}b.timer=null;b.stepspeed=0};b.getVar=function(d){if(d==undefined){return undefined}return b.getVarEx(d.split("."),b.variables)};b.getVarEx=function(f,g){try{if(f==undefined){return undefined}if(f.length==0){return g}return b.getVarEx(f.slice(1),g[f[0]])}catch(d){return null}};b.setVar=function(d,e){b.setVarEx(d.split("."),b.variables,e)};b.setVarEx=function(d,f,e){if(d.length==1){f[d[0]]=e}else{b.setVarEx(d.slice(1),f[d[0]],e)}};b.step=function(){if(b.state!=1){return}if(b.ip1){var r=l.split("{").pop().split("}").shift();l=l.replace("{"+r+"}",b.getVar(r))}}if(k==1){b.variables["__"+p]=decodeURI(l);l="__"+p}h.push(l)}if(k==2||k==3){b.variables["__"+p]=ReadSInt(l,0);h.push("__"+p)}g+=(2+f)}b.ip+=n;var j=[];for(var p=0;p<10;p++){j.push(b.getVar(h[p]))}var q;try{if(m<10000){switch(m){case 0:break;case 1:if(j[2]){if((j[2]=="<"&&j[1]="&&j[1]>=j[3])||(j[2]==">"&&j[1]>j[3])){b.ip=j[0]}}else{b.ip=j[0]}break;case 2:if(h[1]==undefined){delete b.variables[h[0]]}else{b.setVar(h[0],j[1])}break;case 3:var s=b.toString(j[0]);if(s.indexOf("INFO: ")==0){s=s.substring(6)}if(s.indexOf("SUCCESS: ")==0){s=s.substring(9)}if(b.onConsole){b.onConsole(s,b)}else{console.log(s)}break;case 4:b.state=2;b.dialog=true;setDialogMode(11,j[0],j[2],b.xxStepDialogOk,j[1],b);break;case 5:for(var p in j[1]){if(j[1][p][j[2]]==j[3]){q=p}}break;case 6:q=j[1].substr(j[2],j[3]);break;case 7:q=j[1].indexOf(j[2]);break;case 8:q=j[1].split(j[2]);break;case 9:q=j[1].join(j[2]);break;case 10:if(j[1]==null){q=0}else{q=j[1].length}break;case 11:q=JSON.parse(j[1]);break;case 12:q=JSON.stringify(j[1]);break;case 13:q=(j[1]+j[2]);break;case 14:q=(j[1]-j[2]);break;case 15:q=parseInt(j[1]);break;case 16:b.state=2;b.amtstack.BatchEnum(j[0],j[1],b.xxWsmanReturn,b);break;case 17:b.state=2;b.amtstack.Put(j[0],j[1],b.xxWsmanReturn,b);break;case 18:b.state=2;b.amtstack.Create(j[0],j[1],b.xxWsmanReturn,b);break;case 19:b.state=2;b.amtstack.Delete(j[0],j[1],b.xxWsmanReturn,b);break;case 20:b.state=2;b.amtstack.Exec(j[0],j[1],j[2],b.xxWsmanReturn,b,0,j[3]);break;case 21:b.stepspeed=j[0];if(b.timer!=null){clearInterval(b.timer);b.timer=setInterval(function(){b.step()},b.stepspeed)}break;case 22:b.state=2;b.amtstack.Subscribe(j[0],j[1],j[2],b.xxWsmanReturn,b,0,j[3],j[4],j[5],j[6]);break;case 23:b.state=2;b.amtstack.UnSubscribe(j[0],b.xxWsmanReturn,b,0,j[1]);break;case 24:console.log(j[1],j[2],j[1].charCodeAt(j[2]));q=j[1].charCodeAt(j[2]);break;case 25:break;default:b.state=9;console.error("Script Error, unknown command: "+m)}}else{if(m<20000){q=script_functionTableX2[m-10000](j[1],j[2],j[3],j[4],j[5],j[6])}else{}}if(q!=undefined){b.setVar(h[0],q)}}catch(o){if(typeof o=="object"){o=o.message}b.setVar("_exception",o)}}if(b.state==1&&b.ip>=b.script.length){b.state=0;b.stop();if(b.onCompleted){b.onCompleted()}}if(b.onStep){b.onStep(b)}return b};b.xxStepDialogOk=function(d){b.variables.DialogSelect=d;b.state=1;b.dialog=false;if(b.onStep){b.onStep(b)}};b.xxWsmanReturn=function(f,d,e,g){b.setVar(d,e);b.setVar("wsman_result",g);b.setVar("wsman_result_str",((httpErrorTable[g])?(httpErrorTable[g]):("Error #"+g)));b.state=1;if(b.onStep){b.onStep(b)}};b.toString=function(d){if(typeof d=="object"){return JSON.stringify(d)}return d};b.reset();return b};module.exports.compile=function(o,l){var n="",q=o.split("\n"),h={},k=[],s=[];for(var d in q){var p=q[d];if(p.startsWith("##SWAP ")){var u=p.split(" ");if(u.length==3){s[u[1]]=u[2]}}if(p[0]=="#"||p.length==0){continue}for(var u in s){p=p.split(u).join(s[u])}var f=p.match(/"[^"]*"|[^\s"]+/g);if(f.length==0){continue}if(p[0]==":"){h[f[0].toUpperCase()]=n.length;continue}var c=script_functionTable1.indexOf(f[0].toLowerCase());if(c==-1){c=script_functionTable2.indexOf(f[0].toLowerCase());if(c>=0){c+=10000}}if(c==-1){if(l){l("Unabled to compile, unknown command: "+f[0])}return""}var b=ShortToStr(f.length-1);for(var e in f){if(e==0){continue}if(f[e][0]==":"){k.push([f[e],n.length+b.length+7]);b+=ShortToStr(5)+String.fromCharCode(3)+IntToStr(4294967295)}else{var a=parseInt(f[e]);if(a==f[e]){b+=ShortToStr(5)+String.fromCharCode(2)+IntToStr(a)}else{if(f[e][0]=='"'&&f[e][f[e].length-1]=='"'){b+=ShortToStr(f[e].length-1)+String.fromCharCode(1)+f[e].substring(1,f[e].length-1)}else{b+=ShortToStr(f[e].length+1)+String.fromCharCode(0)+f[e]}}}}b=ShortToStr(c)+ShortToStr(b.length+4)+b;n+=b}for(d in k){var g=k[d][0].toUpperCase(),m=k[d][1],t=h[g];if(t==undefined){if(l){l("Unabled to compile, unknown label: "+g)}return""}n=n.substr(0,m)+IntToStr(t)+n.substr(m+4)}return IntToStr(612182341)+ShortToStr(1)+n};module.exports.decompile=function(g,q){var t="",s=6,m=0,n={};if(q>=0){s=q}else{if(g.length<6){return"# Invalid script length"}var p=ReadInt(g,0);var w=ReadShort(g,4);if(p!=612182341){return"# Invalid binary script: "+p}if(w!=1){return"# Invalid script version"}}while(s=0)){t+=":label"+(s-6)+"\n"}for(var k=0;k=10000)&&(h<10000)){t+=script_functionTable2[h-10000]+d+"\n"}}s+=j;if(q>=0){return t}}var u=t.split("\n");t="";for(var k in u){var o=u[k];if(o[0]!=":"){t+=o+"\n"}else{if(n[o]){t+=o+"\n"}}}return t}; \ No newline at end of file diff --git a/meshagent.js b/meshagent.js index 2a2646d1..5033284d 100644 --- a/meshagent.js +++ b/meshagent.js @@ -46,38 +46,41 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) { if (arg == 2) { try { ws._socket._parent.end(); if (obj.nodeid != null) { parent.parent.debug(1, 'Hard disconnect ' + obj.nodeid + ' (' + obj.remoteaddrport + ')'); } } catch (e) { console.log(e); } } // Hard close, close the TCP socket // If arg == 3, don't communicate with this agent anymore, but don't disconnect (Duplicate agent). - // Remove this agent from the webserver list - if (parent.wsagents[obj.dbNodeKey] == obj) { - delete parent.wsagents[obj.dbNodeKey]; - parent.parent.ClearConnectivityState(obj.dbMeshKey, obj.dbNodeKey, 1); - } - - // Get the current mesh - const mesh = parent.meshes[obj.dbMeshKey]; - - // If this is a temporary or recovery agent, or all devices in this group are temporary, remove the agent (0x20 = Temporary, 0x40 = Recovery) - if (((obj.agentInfo) && (obj.agentInfo.capabilities) && ((obj.agentInfo.capabilities & 0x20) || (obj.agentInfo.capabilities & 0x40))) || ((mesh) && (mesh.flags) && (mesh.flags & 1))) { - // Delete this node including network interface information and events - db.Remove(obj.dbNodeKey); // Remove node with that id - db.Remove('if' + obj.dbNodeKey); // Remove interface information - db.Remove('nt' + obj.dbNodeKey); // Remove notes - db.Remove('lc' + obj.dbNodeKey); // Remove last connect time - db.RemoveSMBIOS(obj.dbNodeKey); // Remove SMBios data - db.RemoveAllNodeEvents(obj.dbNodeKey); // Remove all events for this node - db.removeAllPowerEventsForNode(obj.dbNodeKey); // Remove all power events for this node - - // Event node deletion - parent.parent.DispatchEvent(['*', obj.dbMeshKey], obj, { etype: 'node', action: 'removenode', nodeid: obj.dbNodeKey, domain: domain.id, nolog: 1 }); - - // Disconnect all connections if needed - const state = parent.parent.GetConnectivityState(obj.dbNodeKey); - if ((state != null) && (state.connectivity != null)) { - if ((state.connectivity & 1) != 0) { parent.wsagents[obj.dbNodeKey].close(); } // Disconnect mesh agent - if ((state.connectivity & 2) != 0) { parent.parent.mpsserver.close(parent.parent.mpsserver.ciraConnections[obj.dbNodeKey]); } // Disconnect CIRA connection + // If this is a recovery agent, don't bother with all this clean up. + if ((obj.agentInfo.capabilities & 0x40) == 0) { + // Remove this agent from the webserver list + if (parent.wsagents[obj.dbNodeKey] == obj) { + delete parent.wsagents[obj.dbNodeKey]; + parent.parent.ClearConnectivityState(obj.dbMeshKey, obj.dbNodeKey, 1); + } + + // Get the current mesh + const mesh = parent.meshes[obj.dbMeshKey]; + + // If this is a temporary or recovery agent, or all devices in this group are temporary, remove the agent (0x20 = Temporary, 0x40 = Recovery) + if (((obj.agentInfo) && (obj.agentInfo.capabilities) && (obj.agentInfo.capabilities & 0x20)) || ((mesh) && (mesh.flags) && (mesh.flags & 1))) { + // Delete this node including network interface information and events + db.Remove(obj.dbNodeKey); // Remove node with that id + db.Remove('if' + obj.dbNodeKey); // Remove interface information + db.Remove('nt' + obj.dbNodeKey); // Remove notes + db.Remove('lc' + obj.dbNodeKey); // Remove last connect time + db.RemoveSMBIOS(obj.dbNodeKey); // Remove SMBios data + db.RemoveAllNodeEvents(obj.dbNodeKey); // Remove all events for this node + db.removeAllPowerEventsForNode(obj.dbNodeKey); // Remove all power events for this node + + // Event node deletion + parent.parent.DispatchEvent(['*', obj.dbMeshKey], obj, { etype: 'node', action: 'removenode', nodeid: obj.dbNodeKey, domain: domain.id, nolog: 1 }); + + // Disconnect all connections if needed + const state = parent.parent.GetConnectivityState(obj.dbNodeKey); + if ((state != null) && (state.connectivity != null)) { + if ((state.connectivity & 1) != 0) { parent.wsagents[obj.dbNodeKey].close(); } // Disconnect mesh agent + if ((state.connectivity & 2) != 0) { parent.parent.mpsserver.close(parent.parent.mpsserver.ciraConnections[obj.dbNodeKey]); } // Disconnect CIRA connection + } + } else { + // Update the last connect time + if (obj.authenticated == 2) { db.Set({ _id: 'lc' + obj.dbNodeKey, type: 'lastconnect', domain: domain.id, time: obj.connectTime, addr: obj.remoteaddrport }); } } - } else { - // Update the last connect time - if (obj.authenticated == 2) { db.Set({ _id: 'lc' + obj.dbNodeKey, type: 'lastconnect', domain: domain.id, time: obj.connectTime, addr: obj.remoteaddrport }); } } // If we where updating the agent, clean that up. @@ -522,6 +525,12 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) { if ((obj.authenticated != 1) || (obj.meshid == null) || obj.pendingCompleteAgentConnection || (obj.agentInfo == null)) { return; } obj.pendingCompleteAgentConnection = true; + if (obj.agentInfo.capabilities & 0x40) { + // This is a recovery agent + obj.send(common.ShortToStr(11) + common.ShortToStr(0)); // Command 11, ask for mesh core hash. + return; + } + // Check if we have too many agent sessions if (typeof domain.limits.maxagentsessions == 'number') { // Count the number of agent sessions for this domain @@ -700,40 +709,25 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) { // Not sure why, but in rare cases, obj.agentInfo is undefined here. if ((obj.agentInfo == null) || (typeof obj.agentInfo.capabilities != 'number')) { return; } // This is an odd case. - if ((obj.agentInfo.capabilities & 64) != 0) { - // This is a recovery agent - obj.send(common.ShortToStr(11) + common.ShortToStr(0)); // Command 11, ask for mesh core hash. - } else { - // Check if we need to make an native update check - obj.agentExeInfo = parent.parent.meshAgentBinaries[obj.agentInfo.agentId]; - const corename = parent.parent.meshAgentsArchitectureNumbers[obj.agentInfo.agentId].core; - if (corename == null) { obj.send(common.ShortToStr(10) + common.ShortToStr(0)); } // MeshCommand_CoreModule, ask mesh agent to clear the core + // Check if we need to make an native update check + obj.agentExeInfo = parent.parent.meshAgentBinaries[obj.agentInfo.agentId]; + const corename = parent.parent.meshAgentsArchitectureNumbers[obj.agentInfo.agentId].core; + if (corename == null) { obj.send(common.ShortToStr(10) + common.ShortToStr(0)); } // MeshCommand_CoreModule, ask mesh agent to clear the core - if ((obj.agentExeInfo != null) && (obj.agentExeInfo.update == true)) { - // Ask the agent for it's executable binary hash - obj.send(common.ShortToStr(12) + common.ShortToStr(0)); + if ((obj.agentExeInfo != null) && (obj.agentExeInfo.update == true)) { + // Ask the agent for it's executable binary hash + obj.send(common.ShortToStr(12) + common.ShortToStr(0)); + } else { + // Check the mesh core, if the agent is capable of running one + if (((obj.agentInfo.capabilities & 16) != 0) && (corename != null)) { + obj.send(common.ShortToStr(11) + common.ShortToStr(0)); // Command 11, ask for mesh core hash. } else { - // Check the mesh core, if the agent is capable of running one - if (((obj.agentInfo.capabilities & 16) != 0) && (corename != null)) { - obj.send(common.ShortToStr(11) + common.ShortToStr(0)); // Command 11, ask for mesh core hash. - } else { - agentCoreIsStable(); // No updates needed, agent is ready to go. - } + agentCoreIsStable(); // No updates needed, agent is ready to go. } } }); } - function recoveryAgentCoreIsStable() { - // Recovery agent is doing ok, lets perform main agent checking. - - // TODO - console.log('recoveryAgentCoreIsStable()'); - - // Close the recovery agent connection when done. - //obj.close(1); - } - // Take a basic Intel AMT policy and add all server information to it, making it ready to send to this agent. function completeIntelAmtPolicy(amtPolicy) { if (amtPolicy == null) return null; @@ -764,6 +758,21 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) { } } + function recoveryAgentCoreIsStable(mesh) { + // Recovery agent is doing ok, lets perform main agent checking. + //console.log('recoveryAgentCoreIsStable()'); + + // Fetch the the real agent nodeid + db.Get('da' + obj.dbNodeKey, function (err, nodes) { + if (nodes.length == 1) { + obj.realNodeKey = nodes[0].raid; + obj.send(JSON.stringify({ action: 'diagnostic', value: { command: 'query', value: obj.realNodeKey } })); + } else { + obj.send(JSON.stringify({ action: 'diagnostic', value: { command: 'query', value: null } })); + } + }); + } + function agentCoreIsStable() { // Check that the mesh exists const mesh = parent.meshes[obj.dbMeshKey]; @@ -772,6 +781,17 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) { return; // Probably not worth doing anything else. Hold this agent. } + // Fetch the the real agent nodeid + db.Get('ra' + obj.dbNodeKey, function (err, nodes) { + if (nodes.length == 1) { + obj.diagnosticNodeKey = nodes[0].daid; + obj.send(JSON.stringify({ action: 'diagnostic', value: { command: 'query', value: obj.diagnosticNodeKey } })); + } + }); + + // Check if this is a recovery agent + if (obj.agentInfo.capabilities & 0x40) { recoveryAgentCoreIsStable(mesh); return; } + // Send Intel AMT policy if (obj.agentExeInfo && (obj.agentExeInfo.amt == true) && (mesh.amt != null)) { // Only send Intel AMT policy to agents what could have AMT. try { obj.send(JSON.stringify({ action: 'amtPolicy', amtPolicy: completeIntelAmtPolicy(common.Clone(mesh.amt)) })); } catch (ex) { } @@ -1066,6 +1086,48 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) { } break; } + case 'diagnostic': + { + if (typeof command.value == 'object') { + switch (command.value.command) { + case 'register': { + // Only main agent can do this + if (((obj.agentInfo.capabilities & 0x40) == 0) && (typeof command.value.command.value == 'string') && (command.value.command.value.length == 64)) { + // Store links to diagnostic agent id + var daNodeKey = 'node/' + domain.id + '/' + command.value.command.value; + db.Set({ _id: 'da' + daNodeKey, domain: domain.id, time: obj.connectTime, raid: obj.dbNodeKey }); // DiagnosticAgent --> Agent + db.Set({ _id: 'ra' + obj.dbNodeKey, domain: domain.id, time: obj.connectTime, daid: daNodeKey }); // Agent --> DiagnosticAgent + } + break; + } + case 'query': { + // Only the diagnostic agent can do + if ((obj.agentInfo.capabilities & 0x40) != 0) { + // Return nodeid of main agent + connection status + db.Get('da' + obj.dbNodeKey, function (err, nodes) { + if (nodes.length == 1) { + obj.realNodeKey = nodes[0].raid; + obj.send(JSON.stringify({ action: 'diagnostic', value: { command: 'query', value: obj.realNodeKey } })); + } else { + obj.send(JSON.stringify({ action: 'diagnostic', value: { command: 'query', value: null } })); + } + }); + } + break; + } + case 'log': { + // Only the diagnostic agent can do + if (((obj.agentInfo.capabilities & 0x40) != 0) && (typeof command.value.command.value == 'string') && (command.value.command.value.length < 256)) { + // Log a value in the event log of the main again + var event = { etype: 'node', action: 'diagnostic', nodeid: obj.dbNodeKey, domain: domain.id, msg: command.value.command.value }; + parent.parent.DispatchEvent(['*', obj.dbMeshKey], obj, event); + } + break; + } + } + } + break; + } default: { console.log('Unknown agent action (' + obj.remoteaddrport + '): ' + command.action + '.'); break; @@ -1076,6 +1138,7 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) { // Change the current core information string and event it function ChangeAgentCoreInfo(command) { + if (obj.agentInfo.capabilities & 0x40) return; if ((command == null) || (command == null)) return; // Safety, should never happen. // Check that the mesh exists @@ -1137,6 +1200,7 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) { // Change the current core information string and event it function ChangeAgentLocationInfo(command) { + if (obj.agentInfo.capabilities & 0x40) return; if ((command == null) || (command == null)) { return; } // Safety, should never happen. // Check that the mesh exists @@ -1172,6 +1236,7 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) { // Update the mesh agent tab in the database function ChangeAgentTag(tag) { + if (obj.agentInfo.capabilities & 0x40) return; if (tag.length == 0) { tag = null; } // Get the node and change it if needed db.Get(obj.dbNodeKey, function (err, nodes) { diff --git a/meshuser.js b/meshuser.js index df7baea0..1ab27ada 100644 --- a/meshuser.js +++ b/meshuser.js @@ -1396,6 +1396,10 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use db.RemoveSMBIOS(node._id); // Remove SMBios data db.RemoveAllNodeEvents(node._id); // Remove all events for this node db.removeAllPowerEventsForNode(node._id); // Remove all power events for this node + db.Get('ra' + obj.dbNodeKey, function (err, nodes) { + if (nodes.length == 1) { db.Remove('da' + nodes[0].daid); } // Remove diagnostic agent to real agent link + db.Remove('ra' + node._id); // Remove real agent to diagnostic agent link + }); // Event node deletion parent.parent.DispatchEvent(['*', node.meshid], obj, { etype: 'node', username: user.name, action: 'removenode', nodeid: node._id, msg: 'Removed device ' + node.name + ' from group ' + mesh.name, domain: domain.id }); diff --git a/public/styles/style.css b/public/styles/style.css index b0c0183f..2ff27514 100644 --- a/public/styles/style.css +++ b/public/styles/style.css @@ -92,7 +92,7 @@ } #page_content { - max-height: calc(100vh - 108px); + /*max-height: calc(100vh - 108px);*/ } .fullscreen #page_content { position: absolute; diff --git a/views/default-min.handlebars b/views/default-min.handlebars index 6fa56557..e9510371 100644 --- a/views/default-min.handlebars +++ b/views/default-min.handlebars @@ -1 +1 @@ - {{{title}}}
{{{title}}}
{{{title2}}}

{{{logoutControl}}}

 

\ No newline at end of file + {{{title}}}
{{{title}}}
{{{title2}}}

{{{logoutControl}}}

 

\ No newline at end of file diff --git a/views/default.handlebars b/views/default.handlebars index 7c726279..8d34183c 100644 --- a/views/default.handlebars +++ b/views/default.handlebars @@ -1043,7 +1043,6 @@ if (toggle === 1) { webPageFullScreen = !webPageFullScreen; putstore('webPageFullScreen', webPageFullScreen); } var hide = 0; if (args.hide) { hide = parseInt(args.hide); } - console.log("-----------hide:", hide) if (webPageFullScreen == false) { QC('body').remove("fullscreen"); QC('body').remove("arg_hide"); diff --git a/views/login-min.handlebars b/views/login-min.handlebars index 549e7c18..f19afd6a 100644 --- a/views/login-min.handlebars +++ b/views/login-min.handlebars @@ -1 +1 @@ - {{{title}}} - Login
{{{title}}}
{{{title2}}}

Welcome


\ No newline at end of file + {{{title}}} - Login
{{{title}}}
{{{title2}}}

Welcome


\ No newline at end of file diff --git a/views/login.handlebars b/views/login.handlebars index 1bbee21f..38ad2ddc 100644 --- a/views/login.handlebars +++ b/views/login.handlebars @@ -22,7 +22,7 @@
-
+

Welcome

diff --git a/views/messenger-min.handlebars b/views/messenger-min.handlebars index 5a0a5372..867b086c 100644 --- a/views/messenger-min.handlebars +++ b/views/messenger-min.handlebars @@ -1 +1 @@ -MeshMessenger
MeshMessenger
\ No newline at end of file +MeshMessenger
MeshMessenger
\ No newline at end of file