More server fixes.

Ylian Saint-Hilaire committed Mar 10, 2019 at 11:47 UTC 6edc50161eec9e6f053c01ad7bbca0c8b37f2a66
5 files changed +24 -14
agents/modules_meshcore/amt-manage.js
+15 -5
@@ -88,7 +88,7 @@ function AmtManager(agent, db, isdebug) {
88 amtMei.getProvisioningMode(function (result) { if (result) { amtMeiTmpState.ProvisioningMode = result.mode; } });
89 amtMei.getProvisioningState(function (result) { if (result) { amtMeiTmpState.ProvisioningState = result.state; } });
90 amtMei.getEHBCState(function (result) { if ((result != null) && (result.EHBC == true)) { amtMeiTmpState.Flags += 1; } });
91 - amtMei.getControlMode(function (result) { if (result != null) { if (result.controlMode == 1) { amtMeiTmpState.Flags += 2; } if (result.controlMode == 2) { amtMeiTmpState.Flags += 4; } } });
91 + amtMei.getControlMode(function (result) { if (result != null) { if (result.controlMode == 1) { amtMeiTmpState.Flags += 2; } if (result.controlMode == 2) { amtMeiTmpState.Flags += 4; } } }); // Flag 2 = CCM, 4 = ACM
92 //amtMei.getMACAddresses(function (result) { if (result) { amtMeiTmpState.mac = result; } });
93 amtMei.getLanInterfaceSettings(0, function (result) { if (result) { amtMeiTmpState.net0 = result; } });
94 amtMei.getLanInterfaceSettings(1, function (result) { if (result) { amtMeiTmpState.net1 = result; } });
@@ -496,7 +496,7 @@ function AmtManager(agent, db, isdebug) {
496 if ((amtMeiState != 3) || (typeof amtpolicy != 'object') || (typeof amtpolicy.type != 'number') || (amtpolicy.type == 0)) return;
497 if ((amtpolicy.password != null) && (amtpolicy.password != '')) { intelAmtAdminPass = amtpolicy.password; }
498 obj.getAmtInfo(function (meinfo) {
499 - if ((amtpolicy.type == 1) && (meinfo.ProvisioningState == 2)) {
499 + if ((amtpolicy.type == 1) && (meinfo.ProvisioningState == 2) && ((meinfo.Flags & 2) != 0)) {
500 // CCM Deactivation Policy.
501 wsstack = null;
502 amtstack = null;
@@ -507,14 +507,14 @@ function AmtManager(agent, db, isdebug) {
507 amtstack = null;
508 if ((amtpolicy.password == null) || (amtpolicy.password == '')) { intelAmtAdminPass = null; }
509 obj.activeToCCM(intelAmtAdminPass);
510 - } else if ((amtpolicy.type == 2) && (meinfo.ProvisioningState == 2) && (intelAmtAdminPass != null)) {
510 + } else if ((amtpolicy.type == 2) && (meinfo.ProvisioningState == 2) && (intelAmtAdminPass != null) && ((meinfo.Flags & 2) != 0)) {
511 // Perform password test
512 var transport = require('amt-wsman-duk');
513 var wsman = require('amt-wsman');
514 var amt = require('amt');
515 wsstack = new wsman(transport, '127.0.0.1', 16992, 'admin', intelAmtAdminPass, false);
516 amtstack = new amt(wsstack);
517 - try { amtstack.BatchEnum(null, ['*AMT_GeneralSettings', '*IPS_HostBasedSetupService'], wsmanPassTestResponse); } catch (ex) { debug(ex); }
517 + try { amtstack.BatchEnum(null, ['*AMT_GeneralSettings', '*IPS_HostBasedSetupService', '*AMT_RedirectionService', '*CIM_KVMRedirectionSAP'], wsmanPassTestResponse); } catch (ex) { debug(ex); }
518 } else {
519 // Other possible cases...
520 }
@@ -525,8 +525,18 @@ function AmtManager(agent, db, isdebug) {
525 if (status != 200) {
526 if (amtpolicy.badpass == 1) { obj.deactivateCCM(); } // Something went wrong, reactivate.
527 } else {
528 + /*
529 + var redir = (amtsysstate['AMT_RedirectionService'].response["ListenerEnabled"] == true);
530 + var sol = ((amtsysstate['AMT_RedirectionService'].response["EnabledState"] & 2) != 0);
531 + var ider = ((amtsysstate['AMT_RedirectionService'].response["EnabledState"] & 1) != 0);
532 + var kvm = false;
533 + if (amtsysstate['CIM_KVMRedirectionSAP'] != null) {
534 + kvm = ((amtsysstate['CIM_KVMRedirectionSAP'].response["EnabledState"] == 6 && amtsysstate['CIM_KVMRedirectionSAP'].response["RequestedState"] == 2) || amtsysstate['CIM_KVMRedirectionSAP'].response["EnabledState"] == 2 || amtsysstate['CIM_KVMRedirectionSAP'].response["EnabledState"] == 6);
535 + }
536 + */
537 +
538 // Success, make sure
529 - debug('SUCCESS!');
539 + debug('SUCCESS!' + JSON.stringify(responses));
540 // TODO: Check Intel AMT Features need to be enabled & if Intel AMT CIRA needs to be setup
541 }
542 }
agents/modules_meshcore_min/amt-manage.min.js
+1 -1
@@ -1 +1 @@
1 -function AmtManager(c,m,r){var E=function(K){c.SendCommand({action:"msg",type:"console",value:K})};var n=function(K){if(r){E("amt-manager: "+K)}};var g=null,h=0;var e=null,f=0;var d=null;var B=null;var A=null;var j=null;var z=this;z.state=0;z.lmsstate=0;z.onStateChange=null;z.setDebug=function(K){r=K};z.setPolicy=function(K){if(JSON.stringify(j)!=JSON.stringify(K)){j=K;z.applyPolicy()}};var D=0;z.reset=function(){++D;g=null,h=0,e=null,f=0,z.state=0,z.lmsstate=0;try{var K=require("amt-mei");g=new K();g.on("error",function(M){n("MEI error");g=null;h=-1;z.state=-1;z.onStateChange(h)});g.getVersion(function(M){if(M==null){h=-1;z.state=-1;if(z.onStateChange!=null){z.onStateChange(h)}if(D<10){setTimeout(z.reset,10000)}}else{d=M;h=2;z.state=2;D=0;if(z.onStateChange!=null){z.onStateChange(h)}z.lmsreset()}})}catch(L){n("MEI exception: "+L);g=null;h=-1;z.state=-1}};var i=null;z.getAmtInfo=function(L){if((g==null)||(h<2)){if(L!=null){L(null)}return}try{i={Flags:0};g.getProtocolVersion(function(M){if(M!=null){i.MeiVersion=M}});g.getVersion(function(M){if(M){i.Versions={};for(var N in M.Versions){i.Versions[M.Versions[N].Description]=M.Versions[N].Version}}});g.getProvisioningMode(function(M){if(M){i.ProvisioningMode=M.mode}});g.getProvisioningState(function(M){if(M){i.ProvisioningState=M.state}});g.getEHBCState(function(M){if((M!=null)&&(M.EHBC==true)){i.Flags+=1}});g.getControlMode(function(M){if(M!=null){if(M.controlMode==1){i.Flags+=2}if(M.controlMode==2){i.Flags+=4}}});g.getLanInterfaceSettings(0,function(M){if(M){i.net0=M}});g.getLanInterfaceSettings(1,function(M){if(M){i.net1=M}});g.getUuid(function(M){if((M!=null)&&(M.uuid!=null)){i.UUID=M.uuid}});g.getDnsSuffix(function(M){if(M!=null){i.dns=M}if(L!=null){L(i)}})}catch(K){if(L!=null){L(null)}return}};var p=function(N){if((N==null)||(N.Body==null)||(N.Body.MessageID==null)||(N.Body.MessageArguments==null)){return null}var K=N.Body.MessageID,L=N.Body.MessageArguments[0],M=null;switch(K){case"iAMT0050":if(L=="48"){M="Intel&reg; AMT Serial-over-LAN connected"}else{if(L=="49"){M="Intel&reg; AMT Serial-over-LAN disconnected"}}break;case"iAMT0052":if(L=="1"){M="Intel&reg; AMT KVM connected"}else{if(L=="2"){M="Intel&reg; AMT KVM disconnected"}}break;default:break}if(M!=null){c.SendCommand({action:"msg",type:"notify",value:M,tag:"general"})}};z.lmsreset=function(){var K=null,L=0;z.lmsstate=0;try{var N=require("amt-lme");L=1;z.lmsstate=1;K=new N();K.on("error",function(O){L=0;z.lmsstate=0;K=null;n("LMS error");F(1)});K.on("connect",function(){L=2;z.lmsstate=2;n("LMS connected");F(2)});K.on("notify",function(P,Q,R,O){if(O=="iAMT0052-3"){u()}else{p(P)}})}catch(M){L=-1;z.lmsstate=-1;K=null}};var F=function(K){if((g==null)||(h<2)||(d==null)){return}g.getLocalSystemAccount(function(R){if(R==null){return}var P=require("amt-wsman-duk");var Q=require("amt-wsman");var L=require("amt");B=new Q(P,"127.0.0.1",16992,R.user,R.pass,false);A=new L(B);h=3;z.state=3;if(z.onStateChange!=null){z.onStateChange(h)}z.applyPolicy();var M=null;try{for(var O in d.Versions){if(d.Versions[O].Description=="AMT"){M=parseInt(d.Versions[O].Version.split(".")[0])}}}catch(N){}if((M!=null)&&(M>=12)){n("KVM data channel setup");u("skip");z.kvmTempTimer=setInterval(function(){u()},2000);w(JSON.stringify({action:"restart",ver:1}))}})};var u=function(K){A.IPS_KVMRedirectionSettingData_DataChannelRead(z.kvmDataGetResponse,K)};var t=function(N,L,M,O,P){if((P!="skip")&&(O==200)&&(M.Body.ReturnValue==0)){var Q=null;try{Q=Buffer.from(M.Body.DataMessage,"base64").toString()}catch(K){return}if(Q!=null){z.kvmProcessData(M.Body.RealmsBitmap,M.Body.MessageId,Q)}}};var H=null;var v=function(N,M,P){var K=null;try{K=JSON.parse(P)}catch(L){}if((K!=null)&&(K.action)){if(K.action=="present"){w(JSON.stringify({action:"present",ver:1,platform:process.platform}))}if(K.action=="offer"){H={};var O=require("ILibWebRTC");H.webrtc=O.createConnection();H.webrtc.on("connected",function(){});H.webrtc.on("disconnected",function(){z.webRtcCleanUp()});H.webrtc.on("dataChannel",function(Q){H.rtcchannel=Q;H.kvm=mesh.getRemoteDesktopStream();H.kvm.pipe(H.rtcchannel,{dataTypeSkip:1,end:false});H.rtcchannel.on("end",function(){z.webRtcCleanUp()});H.rtcchannel.on("data",function(R){z.kvmCtrlData(this,R)});H.rtcchannel.pipe(H.kvm,{dataTypeSkip:1,end:false})});w(JSON.stringify({action:"answer",ver:1,sdp:H.webrtc.setOffer(K.sdp)}))}}};var s=function(L,N){if(N.length>0&&N.charCodeAt(0)!=123){if(z.fileupload!=null){N=Buffer.from(N,"base64");var T=N.readUInt32BE(0);if((T==16777216)||(T==16777217)){fs.writeSync(z.fileupload.fp,N.slice(4));L.write({action:"upload",sub:"ack",reqid:z.fileupload.reqid});if(T==16777217){fs.closeSync(z.fileupload.fp);z.fileupload=null}}}return}n("KVM Ctrl Data: "+N);try{N=JSON.parse(N)}catch(Q){n("Invalid JSON: "+N);return}if((N.path!=null)&&(process.platform!="win32")&&(N.path[0]!="/")){N.path="/"+N.path}switch(N.action){case"ping":L.write({action:"pong"});break;case"lock":if(process.platform=="win32"){var M=require("child_process");M.execFile(process.env.windir+"\\system32\\cmd.exe",["/c","RunDll32.exe user32.dll,LockWorkStation"],{type:1})}break;case"ls":var W=getDirectoryInfo(N.path);if(N.reqid!=undefined){W.reqid=N.reqid}L.write(W);break;case"mkdir":fs.mkdirSync(N.path);break;case"rm":for(var U in N.delfiles){var S=C.join(N.path,N.delfiles[U]);try{fs.unlinkSync(S)}catch(P){n(P)}}break;case"rename":try{fs.renameSync(C.join(N.path,N.oldname),C.join(N.path,N.newname))}catch(P){n(P)}break;case"download":var Y=0;if(N.sub=="start"){if(z.filedownload!=null){L.write({action:"download",sub:"cancel",id:z.filedownload.id});delete z.filedownload}z.filedownload={id:N.id,path:N.path,ptr:0};try{z.filedownload.f=fs.openSync(z.filedownload.path,"rbN")}catch(P){L.write({action:"download",sub:"cancel",id:z.filedownload.id});delete z.filedownload}if(z.filedownload){L.write({action:"download",sub:"start",id:N.id})}}else{if((z.filedownload!=null)&&(N.id==z.filedownload.id)){if(N.sub=="startack"){Y=8}else{if(N.sub=="stop"){delete z.filedownload}else{if(N.sub=="ack"){Y=1}}}}}while(Y>0){Y--;var K=Buffer.alloc(4096);var V=fs.readSync(z.filedownload.f,K,4,4092,null);z.filedownload.ptr+=V;if(V<4092){K.writeInt32BE(16777217,0);fs.closeSync(z.filedownload.f);delete z.filedownload;Y=0}else{K.writeInt32BE(16777216,0)}L.write(K.slice(0,V+4).toString("base64"))}break;case"upload":if(N.sub=="start"){if(z.fileupload!=null){fs.closeSync(z.fileupload.fp)}if(!N.path||!N.name){break}z.fileupload={reqid:N.reqid};var R=C.join(N.path,N.name);try{z.fileupload.fp=fs.openSync(R,"wbN")}catch(P){}if(z.fileupload.fp){L.write({action:"upload",sub:"start",reqid:z.fileupload.reqid})}else{z.fileupload=null;L.write({action:"upload",sub:"error",reqid:z.fileupload.reqid})}}else{if(N.sub=="cancel"){if(z.fileupload!=null){fs.closeSync(z.fileupload.fp);z.fileupload=null}}}break;case"copy":for(var U in N.names){var X=C.join(N.scpath,N.names[U]),O=C.join(N.dspath,N.names[U]);if(X!=O){try{fs.copyFileSync(X,O)}catch(P){}}}break;case"move":for(var U in N.names){var X=C.join(N.scpath,N.names[U]),O=C.join(N.dspath,N.names[U]);if(X!=O){try{fs.copyFileSync(X,O);fs.unlinkSync(X)}catch(P){}}}break;default:n("Invalid KVM command: "+N);break}};var G=function(){n("webRtcCleanUp");if(H==null){return}if(H.rtcchannel){try{H.rtcchannel.close()}catch(K){}try{H.rtcchannel.removeAllListeners("data")}catch(K){}try{H.rtcchannel.removeAllListeners("end")}catch(K){}delete H.rtcchannel}if(H.webrtc){try{H.webrtc.close()}catch(K){}try{H.webrtc.removeAllListeners("connected")}catch(K){}try{H.webrtc.removeAllListeners("disconnected")}catch(K){}try{H.webrtc.removeAllListeners("dataChannel")}catch(K){}delete H.webrtc}if(H.kvm){try{H.kvm.end()}catch(K){}delete H.kvm}H=null};var w=function(K){A.IPS_KVMRedirectionSettingData_DataChannelWrite(Buffer.from(K).toString("base64"),function(){})};var o=function(K,L){if(fs.existsSync(K)){if(L==true){fs.readdirSync(z.path.join(K,"*")).forEach(function(N,O){var M=z.path.join(K,N);if(fs.statSync(M).isDirectory()){o(M,true)}else{fs.unlinkSync(M)}})}fs.unlinkSync(K)}};var C={join:function(){var M=[];for(var K in arguments){var L=arguments[K];if(L!=null){while(L.endsWith("/")||L.endsWith("\\")){L=L.substring(0,L.length-1)}if(K!=0){while(L.startsWith("/")||L.startsWith("\\")){L=L.substring(1)}}M.push(L)}}if(M.length==0){return"/"}return M.join("/")}};function y(K){return require("MD5Stream").create().syncHash(K).toString("hex")}z.deactivateCCM=function(){g.unprovision(1,function(K){if(K==0){n("Success deactivating Intel AMT CCM.");c.SendCommand({action:"coreinfo",intelamt:{state:0,flags:0}});l=setTimeout(z.applyPolicy,8000)}else{n("Intel AMT CCM deactivation error: "+K)}})};function x(L){var N="",M="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";for(var K=0;K<L;K++){N+=M.charAt(Math.floor(Math.random()*M.length))}return N}z.activeToCCM=function(K){if((K==null)||(K=="")){K="P@0s"+x(23)}q=K;g.getLocalSystemAccount(function(O){if((O!=null)&&O.user&&O.pass){var M=require("amt-wsman-duk");var N=require("amt-wsman");var L=require("amt");B=new N(M,"127.0.0.1",16992,O.user,O.pass,false);A=new L(B);A.BatchEnum(null,["*AMT_GeneralSettings","*IPS_HostBasedSetupService"],a,K)}else{n("Unable to get $$OsAdmin password.")}})};var a=function(N,L,M,O,K){if(O!=200){n("Failed to fetch activation information, status "+O)}else{if(M.IPS_HostBasedSetupService.response.AllowedControlModes.length!=2){n("Client control mode activation not allowed")}else{N.IPS_HostBasedSetupService_Setup(2,y("admin:"+M.AMT_GeneralSettings.response.DigestRealm+":"+K).substring(0,32),null,null,null,null,b)}}};var b=function(M,K,L,N){if(N!=200){n("Failed to activate, status "+N)}else{if(L.Body.ReturnValue!=0){n("Client control mode activation failed: "+L.Body.ReturnValueStr)}else{n("Intel AMT CCM activation success.");m.Put("amtCCMPass",q);c.SendCommand({action:"coreinfo",intelamt:{state:2,flags:2,user:"admin",pass:q}})}}l=setTimeout(z.applyPolicy,8000)};z.start=function(){var K=null;try{K=JSON.parse(m.Get("amtPolicy"))}catch(L){n("Exception loading amtPolicy")}try{q=m.Get("amtCCMPass")}catch(L){}if(typeof q!="string"){q=null}z.reset()};var q,J,k,l;z.applyPolicy=function(){l=null;if((h!=3)||(typeof j!="object")||(typeof j.type!="number")||(j.type==0)){return}if((j.password!=null)&&(j.password!="")){q=j.password}z.getAmtInfo(function(M){if((j.type==1)&&(M.ProvisioningState==2)){J=null;k=null;z.deactivateCCM()}else{if((j.type==2)&&(M.ProvisioningState==0)){J=null;k=null;if((j.password==null)||(j.password=="")){q=null}z.activeToCCM(q)}else{if((j.type==2)&&(M.ProvisioningState==2)&&(q!=null)){var N=require("amt-wsman-duk");var O=require("amt-wsman");var K=require("amt");J=new O(N,"127.0.0.1",16992,"admin",q,false);k=new K(J);try{k.BatchEnum(null,["*AMT_GeneralSettings","*IPS_HostBasedSetupService"],I)}catch(L){n(L)}}else{}}}})};var I=function(M,K,L,N){if(N!=200){if(j.badpass==1){z.deactivateCCM()}}else{n("SUCCESS!")}}}module.exports=AmtManager;
\ No newline at end of file
1 +function AmtManager(c,m,r){var E=function(K){c.SendCommand({action:"msg",type:"console",value:K})};var n=function(K){if(r){E("amt-manager: "+K)}};var g=null,h=0;var e=null,f=0;var d=null;var B=null;var A=null;var j=null;var z=this;z.state=0;z.lmsstate=0;z.onStateChange=null;z.setDebug=function(K){r=K};z.setPolicy=function(K){if(JSON.stringify(j)!=JSON.stringify(K)){j=K;z.applyPolicy()}};var D=0;z.reset=function(){++D;g=null,h=0,e=null,f=0,z.state=0,z.lmsstate=0;try{var K=require("amt-mei");g=new K();g.on("error",function(M){n("MEI error");g=null;h=-1;z.state=-1;z.onStateChange(h)});g.getVersion(function(M){if(M==null){h=-1;z.state=-1;if(z.onStateChange!=null){z.onStateChange(h)}if(D<10){setTimeout(z.reset,10000)}}else{d=M;h=2;z.state=2;D=0;if(z.onStateChange!=null){z.onStateChange(h)}z.lmsreset()}})}catch(L){n("MEI exception: "+L);g=null;h=-1;z.state=-1}};var i=null;z.getAmtInfo=function(L){if((g==null)||(h<2)){if(L!=null){L(null)}return}try{i={Flags:0};g.getProtocolVersion(function(M){if(M!=null){i.MeiVersion=M}});g.getVersion(function(M){if(M){i.Versions={};for(var N in M.Versions){i.Versions[M.Versions[N].Description]=M.Versions[N].Version}}});g.getProvisioningMode(function(M){if(M){i.ProvisioningMode=M.mode}});g.getProvisioningState(function(M){if(M){i.ProvisioningState=M.state}});g.getEHBCState(function(M){if((M!=null)&&(M.EHBC==true)){i.Flags+=1}});g.getControlMode(function(M){if(M!=null){if(M.controlMode==1){i.Flags+=2}if(M.controlMode==2){i.Flags+=4}}});g.getLanInterfaceSettings(0,function(M){if(M){i.net0=M}});g.getLanInterfaceSettings(1,function(M){if(M){i.net1=M}});g.getUuid(function(M){if((M!=null)&&(M.uuid!=null)){i.UUID=M.uuid}});g.getDnsSuffix(function(M){if(M!=null){i.dns=M}if(L!=null){L(i)}})}catch(K){if(L!=null){L(null)}return}};var p=function(N){if((N==null)||(N.Body==null)||(N.Body.MessageID==null)||(N.Body.MessageArguments==null)){return null}var K=N.Body.MessageID,L=N.Body.MessageArguments[0],M=null;switch(K){case"iAMT0050":if(L=="48"){M="Intel&reg; AMT Serial-over-LAN connected"}else{if(L=="49"){M="Intel&reg; AMT Serial-over-LAN disconnected"}}break;case"iAMT0052":if(L=="1"){M="Intel&reg; AMT KVM connected"}else{if(L=="2"){M="Intel&reg; AMT KVM disconnected"}}break;default:break}if(M!=null){c.SendCommand({action:"msg",type:"notify",value:M,tag:"general"})}};z.lmsreset=function(){var K=null,L=0;z.lmsstate=0;try{var N=require("amt-lme");L=1;z.lmsstate=1;K=new N();K.on("error",function(O){L=0;z.lmsstate=0;K=null;n("LMS error");F(1)});K.on("connect",function(){L=2;z.lmsstate=2;n("LMS connected");F(2)});K.on("notify",function(P,Q,R,O){if(O=="iAMT0052-3"){u()}else{p(P)}})}catch(M){L=-1;z.lmsstate=-1;K=null}};var F=function(K){if((g==null)||(h<2)||(d==null)){return}g.getLocalSystemAccount(function(R){if(R==null){return}var P=require("amt-wsman-duk");var Q=require("amt-wsman");var L=require("amt");B=new Q(P,"127.0.0.1",16992,R.user,R.pass,false);A=new L(B);h=3;z.state=3;if(z.onStateChange!=null){z.onStateChange(h)}z.applyPolicy();var M=null;try{for(var O in d.Versions){if(d.Versions[O].Description=="AMT"){M=parseInt(d.Versions[O].Version.split(".")[0])}}}catch(N){}if((M!=null)&&(M>=12)){n("KVM data channel setup");u("skip");z.kvmTempTimer=setInterval(function(){u()},2000);w(JSON.stringify({action:"restart",ver:1}))}})};var u=function(K){A.IPS_KVMRedirectionSettingData_DataChannelRead(z.kvmDataGetResponse,K)};var t=function(N,L,M,O,P){if((P!="skip")&&(O==200)&&(M.Body.ReturnValue==0)){var Q=null;try{Q=Buffer.from(M.Body.DataMessage,"base64").toString()}catch(K){return}if(Q!=null){z.kvmProcessData(M.Body.RealmsBitmap,M.Body.MessageId,Q)}}};var H=null;var v=function(N,M,P){var K=null;try{K=JSON.parse(P)}catch(L){}if((K!=null)&&(K.action)){if(K.action=="present"){w(JSON.stringify({action:"present",ver:1,platform:process.platform}))}if(K.action=="offer"){H={};var O=require("ILibWebRTC");H.webrtc=O.createConnection();H.webrtc.on("connected",function(){});H.webrtc.on("disconnected",function(){z.webRtcCleanUp()});H.webrtc.on("dataChannel",function(Q){H.rtcchannel=Q;H.kvm=mesh.getRemoteDesktopStream();H.kvm.pipe(H.rtcchannel,{dataTypeSkip:1,end:false});H.rtcchannel.on("end",function(){z.webRtcCleanUp()});H.rtcchannel.on("data",function(R){z.kvmCtrlData(this,R)});H.rtcchannel.pipe(H.kvm,{dataTypeSkip:1,end:false})});w(JSON.stringify({action:"answer",ver:1,sdp:H.webrtc.setOffer(K.sdp)}))}}};var s=function(L,N){if(N.length>0&&N.charCodeAt(0)!=123){if(z.fileupload!=null){N=Buffer.from(N,"base64");var T=N.readUInt32BE(0);if((T==16777216)||(T==16777217)){fs.writeSync(z.fileupload.fp,N.slice(4));L.write({action:"upload",sub:"ack",reqid:z.fileupload.reqid});if(T==16777217){fs.closeSync(z.fileupload.fp);z.fileupload=null}}}return}n("KVM Ctrl Data: "+N);try{N=JSON.parse(N)}catch(Q){n("Invalid JSON: "+N);return}if((N.path!=null)&&(process.platform!="win32")&&(N.path[0]!="/")){N.path="/"+N.path}switch(N.action){case"ping":L.write({action:"pong"});break;case"lock":if(process.platform=="win32"){var M=require("child_process");M.execFile(process.env.windir+"\\system32\\cmd.exe",["/c","RunDll32.exe user32.dll,LockWorkStation"],{type:1})}break;case"ls":var W=getDirectoryInfo(N.path);if(N.reqid!=undefined){W.reqid=N.reqid}L.write(W);break;case"mkdir":fs.mkdirSync(N.path);break;case"rm":for(var U in N.delfiles){var S=C.join(N.path,N.delfiles[U]);try{fs.unlinkSync(S)}catch(P){n(P)}}break;case"rename":try{fs.renameSync(C.join(N.path,N.oldname),C.join(N.path,N.newname))}catch(P){n(P)}break;case"download":var Y=0;if(N.sub=="start"){if(z.filedownload!=null){L.write({action:"download",sub:"cancel",id:z.filedownload.id});delete z.filedownload}z.filedownload={id:N.id,path:N.path,ptr:0};try{z.filedownload.f=fs.openSync(z.filedownload.path,"rbN")}catch(P){L.write({action:"download",sub:"cancel",id:z.filedownload.id});delete z.filedownload}if(z.filedownload){L.write({action:"download",sub:"start",id:N.id})}}else{if((z.filedownload!=null)&&(N.id==z.filedownload.id)){if(N.sub=="startack"){Y=8}else{if(N.sub=="stop"){delete z.filedownload}else{if(N.sub=="ack"){Y=1}}}}}while(Y>0){Y--;var K=Buffer.alloc(4096);var V=fs.readSync(z.filedownload.f,K,4,4092,null);z.filedownload.ptr+=V;if(V<4092){K.writeInt32BE(16777217,0);fs.closeSync(z.filedownload.f);delete z.filedownload;Y=0}else{K.writeInt32BE(16777216,0)}L.write(K.slice(0,V+4).toString("base64"))}break;case"upload":if(N.sub=="start"){if(z.fileupload!=null){fs.closeSync(z.fileupload.fp)}if(!N.path||!N.name){break}z.fileupload={reqid:N.reqid};var R=C.join(N.path,N.name);try{z.fileupload.fp=fs.openSync(R,"wbN")}catch(P){}if(z.fileupload.fp){L.write({action:"upload",sub:"start",reqid:z.fileupload.reqid})}else{z.fileupload=null;L.write({action:"upload",sub:"error",reqid:z.fileupload.reqid})}}else{if(N.sub=="cancel"){if(z.fileupload!=null){fs.closeSync(z.fileupload.fp);z.fileupload=null}}}break;case"copy":for(var U in N.names){var X=C.join(N.scpath,N.names[U]),O=C.join(N.dspath,N.names[U]);if(X!=O){try{fs.copyFileSync(X,O)}catch(P){}}}break;case"move":for(var U in N.names){var X=C.join(N.scpath,N.names[U]),O=C.join(N.dspath,N.names[U]);if(X!=O){try{fs.copyFileSync(X,O);fs.unlinkSync(X)}catch(P){}}}break;default:n("Invalid KVM command: "+N);break}};var G=function(){n("webRtcCleanUp");if(H==null){return}if(H.rtcchannel){try{H.rtcchannel.close()}catch(K){}try{H.rtcchannel.removeAllListeners("data")}catch(K){}try{H.rtcchannel.removeAllListeners("end")}catch(K){}delete H.rtcchannel}if(H.webrtc){try{H.webrtc.close()}catch(K){}try{H.webrtc.removeAllListeners("connected")}catch(K){}try{H.webrtc.removeAllListeners("disconnected")}catch(K){}try{H.webrtc.removeAllListeners("dataChannel")}catch(K){}delete H.webrtc}if(H.kvm){try{H.kvm.end()}catch(K){}delete H.kvm}H=null};var w=function(K){A.IPS_KVMRedirectionSettingData_DataChannelWrite(Buffer.from(K).toString("base64"),function(){})};var o=function(K,L){if(fs.existsSync(K)){if(L==true){fs.readdirSync(z.path.join(K,"*")).forEach(function(N,O){var M=z.path.join(K,N);if(fs.statSync(M).isDirectory()){o(M,true)}else{fs.unlinkSync(M)}})}fs.unlinkSync(K)}};var C={join:function(){var M=[];for(var K in arguments){var L=arguments[K];if(L!=null){while(L.endsWith("/")||L.endsWith("\\")){L=L.substring(0,L.length-1)}if(K!=0){while(L.startsWith("/")||L.startsWith("\\")){L=L.substring(1)}}M.push(L)}}if(M.length==0){return"/"}return M.join("/")}};function y(K){return require("MD5Stream").create().syncHash(K).toString("hex")}z.deactivateCCM=function(){g.unprovision(1,function(K){if(K==0){n("Success deactivating Intel AMT CCM.");c.SendCommand({action:"coreinfo",intelamt:{state:0,flags:0}});l=setTimeout(z.applyPolicy,8000)}else{n("Intel AMT CCM deactivation error: "+K)}})};function x(L){var N="",M="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";for(var K=0;K<L;K++){N+=M.charAt(Math.floor(Math.random()*M.length))}return N}z.activeToCCM=function(K){if((K==null)||(K=="")){K="P@0s"+x(23)}q=K;g.getLocalSystemAccount(function(O){if((O!=null)&&O.user&&O.pass){var M=require("amt-wsman-duk");var N=require("amt-wsman");var L=require("amt");B=new N(M,"127.0.0.1",16992,O.user,O.pass,false);A=new L(B);A.BatchEnum(null,["*AMT_GeneralSettings","*IPS_HostBasedSetupService"],a,K)}else{n("Unable to get $$OsAdmin password.")}})};var a=function(N,L,M,O,K){if(O!=200){n("Failed to fetch activation information, status "+O)}else{if(M.IPS_HostBasedSetupService.response.AllowedControlModes.length!=2){n("Client control mode activation not allowed")}else{N.IPS_HostBasedSetupService_Setup(2,y("admin:"+M.AMT_GeneralSettings.response.DigestRealm+":"+K).substring(0,32),null,null,null,null,b)}}};var b=function(M,K,L,N){if(N!=200){n("Failed to activate, status "+N)}else{if(L.Body.ReturnValue!=0){n("Client control mode activation failed: "+L.Body.ReturnValueStr)}else{n("Intel AMT CCM activation success.");m.Put("amtCCMPass",q);c.SendCommand({action:"coreinfo",intelamt:{state:2,flags:2,user:"admin",pass:q}})}}l=setTimeout(z.applyPolicy,8000)};z.start=function(){var K=null;try{K=JSON.parse(m.Get("amtPolicy"))}catch(L){n("Exception loading amtPolicy")}try{q=m.Get("amtCCMPass")}catch(L){}if(typeof q!="string"){q=null}z.reset()};var q,J,k,l;z.applyPolicy=function(){l=null;if((h!=3)||(typeof j!="object")||(typeof j.type!="number")||(j.type==0)){return}if((j.password!=null)&&(j.password!="")){q=j.password}z.getAmtInfo(function(M){if((j.type==1)&&(M.ProvisioningState==2)&&((M.Flags&2)!=0)){J=null;k=null;z.deactivateCCM()}else{if((j.type==2)&&(M.ProvisioningState==0)){J=null;k=null;if((j.password==null)||(j.password=="")){q=null}z.activeToCCM(q)}else{if((j.type==2)&&(M.ProvisioningState==2)&&(q!=null)&&((M.Flags&2)!=0)){var N=require("amt-wsman-duk");var O=require("amt-wsman");var K=require("amt");J=new O(N,"127.0.0.1",16992,"admin",q,false);k=new K(J);try{k.BatchEnum(null,["*AMT_GeneralSettings","*IPS_HostBasedSetupService","*AMT_RedirectionService","*CIM_KVMRedirectionSAP"],I)}catch(L){n(L)}}else{}}}})};var I=function(M,K,L,N){if(N!=200){if(j.badpass==1){z.deactivateCCM()}}else{n("SUCCESS!"+JSON.stringify(L))}}}module.exports=AmtManager;
\ No newline at end of file
meshagent.js
+2 -2
@@ -519,7 +519,7 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
519
520 // Once we get all the information about an agent, run this to hook everything up to the server
521 function completeAgentConnection() {
522 - if ((obj.authenticated != 1) || (obj.meshid == null) || obj.pendingCompleteAgentConnection || (obj.agentExeInfo == null)) return;
522 + if ((obj.authenticated != 1) || (obj.meshid == null) || obj.pendingCompleteAgentConnection || (obj.agentInfo == null)) { return; }
523 obj.pendingCompleteAgentConnection = true;
524
525 // Check if we have too many agent sessions
@@ -568,7 +568,7 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
568
569 // Check that the node exists
570 db.Get(obj.dbNodeKey, function (err, nodes) {
571 - if (obj.agentExeInfo == null) { return; } // Agent has disconnected
571 + if (obj.agentInfo == null) { return; }
572 var device;
573
574 // See if this node exists in the database
meshcentral.js
+5 -5
@@ -278,17 +278,17 @@ function CreateMeshCentralServer(config, args) {
278 // Push all relevent files from meshcentral-data into the database
279 if (obj.args.dbpushconfigfiles) {
280 if (typeof obj.args.configkey != 'string') { console.log('Error, --configkey is required.'); process.exit(); return; }
281 - if (typeof obj.args.dbpushconfigfiles != 'string') {
281 + if ((obj.args.dbpushconfigfiles !== true) && (typeof obj.args.dbpushconfigfiles != 'string')) {
282 console.log('Usage: --dbpulldatafiles (path) This will import files from folder into the database');
283 - console.log(' --dbpulldatafiles * This will import files from meshcentral-data into the db.');
283 + console.log(' --dbpulldatafiles This will import files from meshcentral-data into the db.');
284 process.exit();
285 } else {
286 - if (obj.args.dbpushconfigfiles == '*') { obj.args.dbpushconfigfiles = obj.datapath; }
286 + if ((obj.args.dbpushconfigfiles == '*') || (obj.args.dbpushconfigfiles === true)) { obj.args.dbpushconfigfiles = obj.datapath; }
287 obj.fs.readdir(obj.args.dbpushconfigfiles, function (err, files) {
288 - if (err != null) { console.log('Unable to read from folder ' + obj.args.dbpushconfigfiles); process.exit(); return; }
288 + if (err != null) { console.log('ERROR: Unable to read from folder ' + obj.args.dbpushconfigfiles); process.exit(); return; }
289 var configFound = false;
290 for (var i in files) { if (files[i] == 'config.json') { configFound = true; } }
291 - if (configFound == false) { console.log('No config.json in folder ' + obj.args.dbpushconfigfiles); process.exit(); return; }
291 + if (configFound == false) { console.log('ERROR: No config.json in folder ' + obj.args.dbpushconfigfiles); process.exit(); return; }
292 obj.db.RemoveAllOfType('cfile', function () {
293 obj.fs.readdir(obj.args.dbpushconfigfiles, function (err, files) {
294 var lockCount = 1
package.json
+1 -1
@@ -1,6 +1,6 @@
1 {
2 "name": "meshcentral",
3 - "version": "0.3.0-c",
3 + "version": "0.3.0-d",
4 "keywords": [
5 "Remote Management",
6 "Intel AMT",