Server partially supports hardware login keys.

This commit is contained in:
Ylian Saint-Hilaire 2019-02-07 20:06:01 -08:00
parent 28d13d6995
commit d8e866c5ca
47 changed files with 307 additions and 109 deletions

File diff suppressed because one or more lines are too long

View File

@ -512,6 +512,11 @@ function createMeshCore(agent) {
if (data.amtPolicy != null) { db.Put('amtPolicy', JSON.stringify(data.amtPolicy)); } else { db.Put('amtPolicy', null); }
break;
}
case 'getScript': {
// Received a configuration script from the server
sendConsoleText('getScript: ' + JSON.stringify(data));
break;
}
default:
// Unknown action, ignore it.
break;
@ -1103,7 +1108,7 @@ function createMeshCore(agent) {
var response = null;
switch (cmd) {
case 'help': { // Displays available commands
response = 'Available commands: help, info, osinfo,args, print, type, dbget, dbset, dbcompact, eval, parseuri, httpget,\r\nwslist, wsconnect, wssend, wsclose, notify, ls, ps, kill, amt, netinfo, location, power, wakeonlan, scanwifi,\r\nscanamt, setdebug, smbios, rawsmbios, toast, lock, users, sendcaps, openurl, amtreset, amtccm, amtdeactivate, amtpolicy.';
response = 'Available commands: help, info, osinfo,args, print, type, dbget, dbset, dbcompact, eval, parseuri, httpget,\r\nwslist, wsconnect, wssend, wsclose, notify, ls, ps, kill, amt, netinfo, location, power, wakeonlan, scanwifi,\r\nscanamt, setdebug, smbios, rawsmbios, toast, lock, users, sendcaps, openurl, amtreset, amtccm, amtdeactivate,\r\namtpolicy, getscript.';
break;
}
/*
@ -1543,6 +1548,14 @@ function createMeshCore(agent) {
response = JSON.stringify(addedModules);
break;
}
case 'getscript': {
if (args['_'].length != 1) {
response = 'Proper usage: getscript [scriptNumber].';
} else {
mesh.SendCommand({ "action": "getScript", "type": args['_'][0] });
}
break;
}
default: { // This is an unknown command, return an error message
response = 'Unknown command \"' + cmd + '\", type \"help\" for list of avaialble commands.';
break;

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1 +0,0 @@
function AMTScanner(){var a=require("events").inherits(this);a.createEvent("found");this.dgram=require("dgram");this.buildRmcpPing=function(c){var b=Buffer.from("06000006000011BE80000000","hex");b[9]=c;return b};this.parseRmcpPacket=function(h,b,g,d){if(b==null||b.length<20){return}var f={};if(((b[12]==0)||(b[13]!=0)||(b[14]!=1)||(b[15]!=87))&&(b[21]&32)){f.servertag=b[9];f.minorVersion=b[18]&15;f.majorVersion=(b[18]>>4)&15;f.provisioningState=b[19]&3;var e=(b[16]*256)+b[17];var c=((b[19]&4)!=0)?true:false;f.openPorts=[e];f.address=g.address;if(c==true){f.openPorts=[16992,16993]}if(d!==undefined){d(h,f)}}};this.parseIPv4Range=function(f){if(f==undefined||f==null){return null}var g=f.split("-");if(g.length==2){return{min:this.parseIpv4Addr(g[0]),max:this.parseIpv4Addr(g[1])}}g=f.split("/");if(g.length==2){var c=this.parseIpv4Addr(g[0]),e=parseInt(g[1]),d=0;if(e<=16||e>32){return null}e=32-e;for(var b=0;b<e;b++){d=(d<<1);d++}return{min:c&(4294967295-d),max:(c&(4294967295-d))+d}}g=this.parseIpv4Addr(f);if(g==null){return null}return{min:g,max:g}};this.parseIpv4Addr=function(b){var c=b.split(".");if(c.length==4){return(parseInt(c[0])<<24)+(parseInt(c[1])<<16)+(parseInt(c[2])<<8)+(parseInt(c[3])<<0)}return null};this.IPv4NumToStr=function(b){return((b>>24)&255)+"."+((b>>16)&255)+"."+((b>>8)&255)+"."+(b&255)};this.scan=function(d,g){var c=this.parseIPv4Range(d);var e=this.buildRmcpPing(0);var f=this.dgram.createSocket({type:"udp4"});f.parent=this;f.scanResults=[];f.on("error",function(i){console.log("Error:"+i)});f.on("message",function(i,j){if(j.size>4){this.parent.parseRmcpPacket(this,i,j,function(l,k){l.scanResults.push(k)})}});f.on("listening",function(){for(var j=c.min;j<=c.max;j++){f.send(e,623,f.parent.IPv4NumToStr(j))}});f.bind({address:"0.0.0.0",port:0,exclusive:true});var h=setTimeout(function b(){f.close();f.parent.emit("found",f.scanResults);delete f},g)}}module.exports=AMTScanner;

File diff suppressed because one or more lines are too long

View File

@ -1 +0,0 @@
function CreateWsmanComm(){var a={};a.PendingAjax=[];a.ActiveAjaxCount=0;a.MaxActiveAjaxCount=1;a.FailAllError=0;a.digest=null;a.RequestCount=0;if(arguments.length==1&&typeof(arguments[0]=="object")){a.host=arguments[0].host;a.port=arguments[0].port;a.authToken=arguments[0].authToken;a.tls=arguments[0].tls}else{a.host=arguments[0];a.port=arguments[1];a.user=arguments[2];a.pass=arguments[3];a.tls=arguments[4]}a.PerformAjax=function(d,c,f,e,g,b){if((a.ActiveAjaxCount==0||((a.ActiveAjaxCount<a.MaxActiveAjaxCount)&&(a.challengeParams!=null)))&&a.PendingAjax.length==0){a.PerformAjaxEx(d,c,f,g,b)}else{if(e==1){a.PendingAjax.unshift([d,c,f,g,b])}else{a.PendingAjax.push([d,c,f,g,b])}}};a.PerformNextAjax=function(){if(a.ActiveAjaxCount>=a.MaxActiveAjaxCount||a.PendingAjax.length==0){return}var b=a.PendingAjax.shift();a.PerformAjaxEx(b[0],b[1],b[2],b[3],b[4]);a.PerformNextAjax()};a.PerformAjaxEx=function(d,c,g,h,b){if(a.FailAllError!=0){if(a.FailAllError!=999){a.gotNextMessagesError({status:a.FailAllError},"error",null,[d,c,g])}return}if(!d){d=""}if(a.digest==null){if(a.authToken){a.digest=require("http-digest").create({authToken:a.authToken})}else{a.digest=require("http-digest").create(a.user,a.pass)}a.digest.http=require("http")}var f={protocol:(a.tls==1?"https:":"http:"),method:"POST",host:a.host,path:"/wsman",port:a.port,rejectUnauthorized:false,checkServerIdentity:function(i){console.log("checkServerIdentity",JSON.stringify(i))}};var e=a.digest.request(f);e.on("error",function(i){a.gotNextMessagesError({status:600},"error",null,[d,c,g])});e.on("response",function(i){if(i.statusCode!=200){a.gotNextMessagesError({status:i.statusCode},"error",null,[d,c,g])}else{i.acc="";i.on("data",function(j){this.acc+=j});i.on("end",function(){a.gotNextMessages(i.acc,"success",{status:i.statusCode},[d,c,g])})}});e.end(d);a.ActiveAjaxCount++;return e};a.pendingAjaxCall=[];a.gotNextMessages=function(c,e,d,b){a.ActiveAjaxCount--;if(a.FailAllError==999){return}if(a.FailAllError!=0){b[1](null,a.FailAllError,b[2]);return}if(d.status!=200){b[1](null,d.status,b[2]);return}b[1](c,200,b[2]);a.PerformNextAjax()};a.gotNextMessagesError=function(d,e,c,b){a.ActiveAjaxCount--;if(a.FailAllError==999){return}if(a.FailAllError!=0){b[1](null,a.FailAllError,b[2]);return}if(a.FailAllError!=999){b[1]({Header:{HttpError:d.status}},d.status,b[2])}a.PerformNextAjax()};a.CancelAllQueries=function(b){while(a.PendingAjax.length>0){var c=a.PendingAjax.shift();c[1](null,b,c[2])}};return a}module.exports=CreateWsmanComm;

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1 +0,0 @@
var GM=require("_GenericMarshal");function processManager(){this._ObjectID="process-manager";switch(process.platform){case"win32":this._kernel32=GM.CreateNativeProxy("kernel32.dll");this._kernel32.CreateMethod("GetLastError");this._kernel32.CreateMethod("CreateToolhelp32Snapshot");this._kernel32.CreateMethod("Process32First");this._kernel32.CreateMethod("Process32Next");break;case"linux":case"darwin":this._childProcess=require("child_process");break;default:throw (process.platform+" not supported");break}this.enumerateProcesses=function a(){var d=require("promise");var e=new d(function(g,f){this._res=g;this._rej=f});this.getProcesses(function(g,f){f._res(g)},e);return(e)};this.getProcesses=function b(d){switch(process.platform){default:throw ("Enumerating processes on "+process.platform+" not supported");break;case"win32":var n={};var e=this._kernel32.CreateToolhelp32Snapshot(2,0);var g=GM.CreateVariable(304);g.toBuffer().writeUInt32LE(304,0);var j=this._kernel32.Process32First(e,g);while(j.Val){n[g.Deref(8,4).toBuffer().readUInt32LE(0)]={pid:g.Deref(8,4).toBuffer().readUInt32LE(0),cmd:g.Deref(GM.PointerSize==4?36:44,260).String};j=this._kernel32.Process32Next(e,g)}if(d){d.apply(this,[n])}break;case"linux":if(!this._psp){this._psp={}}var l=this._childProcess.execFile("/bin/ps",["ps","-uxa"],{type:this._childProcess.SpawnTypes.TERM});this._psp[l.pid]=l;l.Parent=this;l.ps="";l.callback=d;l.args=[];for(var f=1;f<arguments.length;++f){l.args.push(arguments[f])}l.on("exit",function k(){delete this.Parent._psp[this.pid];var r={},q=this.ps.split("\x0D\x0A"),o={},p=0;for(var h in q){var t=q[h].split(" ");var s=[];for(var u in t){if(h==0&&t[u]){o[t[u]]=p++}if(h>0&&t[u]){s.push(t[u])}}if(h>0){if(s[o.PID]){r[s[o.PID]]={pid:o.PID,user:s[o.USER],cmd:s[o.COMMAND]}}}}if(this.callback){this.args.unshift(r);this.callback.apply(this.parent,this.args)}});l.stdout.on("data",function(h){this.parent.ps+=h.toString()});break;case"darwin":var m=require("promise");var l=new m(function(i,h){this._res=i;this._rej=h});l.pm=this;l.callback=d;l.args=[];for(var f=1;f<arguments.length;++f){l.args.push(arguments[f])}l.child=this._childProcess.execFile("/bin/ps",["ps","-xa"]);l.child.promise=l;l.child.stdout.ps="";l.child.stdout.on("data",function(h){this.ps+=h.toString()});l.child.on("exit",function(){var p=this.stdout.ps.split("\n");var q=p[0].split("PID")[0].length+3;var h=p[0].split("CMD")[0].length;var r={};for(var o=1;o<p.length;++o){if(p[o].length>0){r[p[o].substring(0,q).trim()]={pid:p[o].substring(0,q).trim(),cmd:p[o].substring(h)}}}this.promise._res(r)});l.then(function(h){this.args.unshift(h);this.callback.apply(this.pm,this.args)});break}};this.getProcessInfo=function c(g){switch(process.platform){default:throw ("getProcessInfo() not supported for "+process.platform);break;case"linux":var h=require("fs").readFileSync("/proc/"+g+"/status");var e={};var f=h.toString().split("\n");for(var d in f){var j=f[d].split(":");if(j.length>1){j[1]=j[1].trim()}e[j[0]]=j[1]}return(e);break}}}module.exports=new processManager();

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1 +0,0 @@
function AMTScanner(){var a=require("events").inherits(this);a.createEvent("found");this.dgram=require("dgram");this.buildRmcpPing=function(c){var b=Buffer.from("06000006000011BE80000000","hex");b[9]=c;return b};this.parseRmcpPacket=function(h,b,g,d){if(b==null||b.length<20){return}var f={};if(((b[12]==0)||(b[13]!=0)||(b[14]!=1)||(b[15]!=87))&&(b[21]&32)){f.servertag=b[9];f.minorVersion=b[18]&15;f.majorVersion=(b[18]>>4)&15;f.provisioningState=b[19]&3;var e=(b[16]*256)+b[17];var c=((b[19]&4)!=0)?true:false;f.openPorts=[e];f.address=g.address;if(c==true){f.openPorts=[16992,16993]}if(d!==undefined){d(h,f)}}};this.parseIPv4Range=function(f){if(f==undefined||f==null){return null}var g=f.split("-");if(g.length==2){return{min:this.parseIpv4Addr(g[0]),max:this.parseIpv4Addr(g[1])}}g=f.split("/");if(g.length==2){var c=this.parseIpv4Addr(g[0]),e=parseInt(g[1]),d=0;if(e<=16||e>32){return null}e=32-e;for(var b=0;b<e;b++){d=(d<<1);d++}return{min:c&(4294967295-d),max:(c&(4294967295-d))+d}}g=this.parseIpv4Addr(f);if(g==null){return null}return{min:g,max:g}};this.parseIpv4Addr=function(b){var c=b.split(".");if(c.length==4){return(parseInt(c[0])<<24)+(parseInt(c[1])<<16)+(parseInt(c[2])<<8)+(parseInt(c[3])<<0)}return null};this.IPv4NumToStr=function(b){return((b>>24)&255)+"."+((b>>16)&255)+"."+((b>>8)&255)+"."+(b&255)};this.scan=function(d,g){var c=this.parseIPv4Range(d);var e=this.buildRmcpPing(0);var f=this.dgram.createSocket({type:"udp4"});f.parent=this;f.scanResults=[];f.on("error",function(i){console.log("Error:"+i)});f.on("message",function(i,j){if(j.size>4){this.parent.parseRmcpPacket(this,i,j,function(l,k){l.scanResults.push(k)})}});f.on("listening",function(){for(var j=c.min;j<=c.max;j++){f.send(e,623,f.parent.IPv4NumToStr(j))}});f.bind({address:"0.0.0.0",port:0,exclusive:true});var h=setTimeout(function b(){f.close();f.parent.emit("found",f.scanResults);delete f},g)}}module.exports=AMTScanner;

View File

@ -1 +0,0 @@
function CreateWsmanComm(){var a={};a.PendingAjax=[];a.ActiveAjaxCount=0;a.MaxActiveAjaxCount=1;a.FailAllError=0;a.digest=null;a.RequestCount=0;if(arguments.length==1&&typeof(arguments[0]=="object")){a.host=arguments[0].host;a.port=arguments[0].port;a.authToken=arguments[0].authToken;a.tls=arguments[0].tls}else{a.host=arguments[0];a.port=arguments[1];a.user=arguments[2];a.pass=arguments[3];a.tls=arguments[4]}a.PerformAjax=function(d,c,f,e,g,b){if((a.ActiveAjaxCount==0||((a.ActiveAjaxCount<a.MaxActiveAjaxCount)&&(a.challengeParams!=null)))&&a.PendingAjax.length==0){a.PerformAjaxEx(d,c,f,g,b)}else{if(e==1){a.PendingAjax.unshift([d,c,f,g,b])}else{a.PendingAjax.push([d,c,f,g,b])}}};a.PerformNextAjax=function(){if(a.ActiveAjaxCount>=a.MaxActiveAjaxCount||a.PendingAjax.length==0){return}var b=a.PendingAjax.shift();a.PerformAjaxEx(b[0],b[1],b[2],b[3],b[4]);a.PerformNextAjax()};a.PerformAjaxEx=function(d,c,g,h,b){if(a.FailAllError!=0){if(a.FailAllError!=999){a.gotNextMessagesError({status:a.FailAllError},"error",null,[d,c,g])}return}if(!d){d=""}if(a.digest==null){if(a.authToken){a.digest=require("http-digest").create({authToken:a.authToken})}else{a.digest=require("http-digest").create(a.user,a.pass)}a.digest.http=require("http")}var f={protocol:(a.tls==1?"https:":"http:"),method:"POST",host:a.host,path:"/wsman",port:a.port,rejectUnauthorized:false,checkServerIdentity:function(i){console.log("checkServerIdentity",JSON.stringify(i))}};var e=a.digest.request(f);e.on("error",function(i){a.gotNextMessagesError({status:600},"error",null,[d,c,g])});e.on("response",function(i){if(i.statusCode!=200){a.gotNextMessagesError({status:i.statusCode},"error",null,[d,c,g])}else{i.acc="";i.on("data",function(j){this.acc+=j});i.on("end",function(){a.gotNextMessages(i.acc,"success",{status:i.statusCode},[d,c,g])})}});e.end(d);a.ActiveAjaxCount++;return e};a.pendingAjaxCall=[];a.gotNextMessages=function(c,e,d,b){a.ActiveAjaxCount--;if(a.FailAllError==999){return}if(a.FailAllError!=0){b[1](null,a.FailAllError,b[2]);return}if(d.status!=200){b[1](null,d.status,b[2]);return}b[1](c,200,b[2]);a.PerformNextAjax()};a.gotNextMessagesError=function(d,e,c,b){a.ActiveAjaxCount--;if(a.FailAllError==999){return}if(a.FailAllError!=0){b[1](null,a.FailAllError,b[2]);return}if(a.FailAllError!=999){b[1]({Header:{HttpError:d.status}},d.status,b[2])}a.PerformNextAjax()};a.CancelAllQueries=function(b){while(a.PendingAjax.length>0){var c=a.PendingAjax.shift();c[1](null,b,c[2])}};return a}module.exports=CreateWsmanComm;

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1 +0,0 @@
try{Object.defineProperty(Array.prototype,"peek",{value:function(){return(this.length>0?this[this.length-1]:undefined)}})}catch(e){}function dbus(a,b){this._ObjectID="linux-dbus";require("events").EventEmitter.call(this,true).createEvent("signal");Object.defineProperty(this,"uid",{value:b});this._child=require("child_process").execFile("/bin/sh",["sh"],{type:require("child_process").SpawnTypes.TERM,uid:b==null?-1:b});this._child.stdin.write("dbus-monitor --session \"type='signal', interface='"+a+'\'" | ( while read X; do echo "$X"; done )\n');this._child.stdout.dbus=this;this._child.stdout.on("data",function(c){if(!this.ready){this.ready=true;return}var f=[];var g=c.toString().split("\r\n");for(var d in g){if(g[d]==""){this.dbus.preParseRecords(f);f=[]}else{f.push(g[d])}}});this.preParseRecords=function(d){var f=[];for(var c in d){if(d[c].startsWith("signal ")){if(f.length>0){this.parseRecords(f)}f=[]}f.push(d[c])}if(f.length>0){this.parseRecords(f)}};this.parseRecords=function(d){if(d[0].startsWith("signal ")){var g={};var h=d[0].split(" ");h.shift();for(var c in h){var f=h[c].split("=");if(f.length==2){g[f[0]]=f[1]}}d.shift();g.data=d;this.parseSignal(g)}};this.parseSignal=function(f){var c=f.data;f.data=[];for(var d=0;d<c.length;++d){if(c[d].startsWith("array ")){f.data.push([]);for(d=d+1;d<c.length;++d){this.parseSignal2(c[d],f.data.peek())}}else{this.parseSignal2(c[d],f.data)}}this.emit("signal",f)};this.parseSignal2=function(c,d){if(c.startsWith("string ")){d.push(JSON.parse(c.slice(7)))}else{if(c.startsWith("boolean ")){d.push(JSON.parse(c.slice(8)))}}}}module.exports=dbus;

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1 +0,0 @@
function powerMonitor(){this._ObjectID="power-monitor";require("events").EventEmitter.call(this,true).createEvent("changed").createEvent("sx").createEvent("batteryLevel").createEvent("acdc").createEvent("display");this._i=setImmediate(function(a){require("user-sessions");delete a._i},this)}module.exports=new powerMonitor();

View File

@ -1 +0,0 @@
var GM=require("_GenericMarshal");function processManager(){this._ObjectID="process-manager";switch(process.platform){case"win32":this._kernel32=GM.CreateNativeProxy("kernel32.dll");this._kernel32.CreateMethod("GetLastError");this._kernel32.CreateMethod("CreateToolhelp32Snapshot");this._kernel32.CreateMethod("Process32First");this._kernel32.CreateMethod("Process32Next");break;case"linux":case"darwin":this._childProcess=require("child_process");break;default:throw (process.platform+" not supported");break}this.enumerateProcesses=function a(){var d=require("promise");var e=new d(function(g,f){this._res=g;this._rej=f});this.getProcesses(function(g,f){f._res(g)},e);return(e)};this.getProcesses=function b(d){switch(process.platform){default:throw ("Enumerating processes on "+process.platform+" not supported");break;case"win32":var n={};var e=this._kernel32.CreateToolhelp32Snapshot(2,0);var g=GM.CreateVariable(304);g.toBuffer().writeUInt32LE(304,0);var j=this._kernel32.Process32First(e,g);while(j.Val){n[g.Deref(8,4).toBuffer().readUInt32LE(0)]={pid:g.Deref(8,4).toBuffer().readUInt32LE(0),cmd:g.Deref(GM.PointerSize==4?36:44,260).String};j=this._kernel32.Process32Next(e,g)}if(d){d.apply(this,[n])}break;case"linux":if(!this._psp){this._psp={}}var l=this._childProcess.execFile("/bin/ps",["ps","-uxa"],{type:this._childProcess.SpawnTypes.TERM});this._psp[l.pid]=l;l.Parent=this;l.ps="";l.callback=d;l.args=[];for(var f=1;f<arguments.length;++f){l.args.push(arguments[f])}l.on("exit",function k(){delete this.Parent._psp[this.pid];var r={},q=this.ps.split("\x0D\x0A"),o={},p=0;for(var h in q){var t=q[h].split(" ");var s=[];for(var u in t){if(h==0&&t[u]){o[t[u]]=p++}if(h>0&&t[u]){s.push(t[u])}}if(h>0){if(s[o.PID]){r[s[o.PID]]={pid:o.PID,user:s[o.USER],cmd:s[o.COMMAND]}}}}if(this.callback){this.args.unshift(r);this.callback.apply(this.parent,this.args)}});l.stdout.on("data",function(h){this.parent.ps+=h.toString()});break;case"darwin":var m=require("promise");var l=new m(function(i,h){this._res=i;this._rej=h});l.pm=this;l.callback=d;l.args=[];for(var f=1;f<arguments.length;++f){l.args.push(arguments[f])}l.child=this._childProcess.execFile("/bin/ps",["ps","-xa"]);l.child.promise=l;l.child.stdout.ps="";l.child.stdout.on("data",function(h){this.ps+=h.toString()});l.child.on("exit",function(){var p=this.stdout.ps.split("\n");var q=p[0].split("PID")[0].length+3;var h=p[0].split("CMD")[0].length;var r={};for(var o=1;o<p.length;++o){if(p[o].length>0){r[p[o].substring(0,q).trim()]={pid:p[o].substring(0,q).trim(),cmd:p[o].substring(h)}}}this.promise._res(r)});l.then(function(h){this.args.unshift(h);this.callback.apply(this.pm,this.args)});break}};this.getProcessInfo=function c(g){switch(process.platform){default:throw ("getProcessInfo() not supported for "+process.platform);break;case"linux":var h=require("fs").readFileSync("/proc/"+g+"/status");var e={};var f=h.toString().split("\n");for(var d in f){var j=f[d].split(":");if(j.length>1){j[1]=j[1].trim()}e[j[0]]=j[1]}return(e);break}}}module.exports=new processManager();

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1 +0,0 @@
var toasters={};function Toaster(){this._ObjectID="toaster";this.Toast=function a(l,b){var h={};var d=require("events").inherits(h);d.createEvent("Dismissed");h.title=l;h.caption=b;if(process.platform=="win32"){d.createEvent("Clicked");var j=require("user-sessions").Current();for(var f in j){console.log(j[f])}try{console.log("Attempting Toast Mechanism 1");h._child=require("ScriptContainer").Create({processIsolation:true,sessionId:j.Active[0].SessionId})}catch(c){console.log(c);console.log("Attempting Toast Mechanism 2");h._child=require("ScriptContainer").Create({processIsolation:true})}h._child.parent=h;h._child.on("exit",function(e){this.parent.emit("Dismissed");delete this.parent._child});h._child.addModule("win-console",getJSModule("win-console"));h._child.addModule("win-message-pump",getJSModule("win-message-pump"));var k=" try{ var toast = require('win-console'); var balloon = toast.SetTrayIcon({ szInfo: '"+b+"', szInfoTitle: '"+l+"', balloonOnly: true }); balloon.on('ToastDismissed', function(){process.exit();}); } catch(e) { require('ScriptContainer').send(e); } require('ScriptContainer').send('done'); ";h._child.ExecuteString(k);toasters[h._hashCode()]=h;h.on("Dismissed",function(){delete toasters[this._hashCode()]});console.log("Returning");return(h)}else{if(!require("fs").existsSync("/usr/bin/notify-send")){throw ("Toast not supported on this platform")}Object.defineProperty(h,"_sessions",{value:require("user-sessions").Current(function g(e){this._cchild=require("child_process").execFile("/usr/bin/whoami",["whoami"],{type:require("child_process").SpawnTypes.TERM});this._cchild.stdout.on("data",function(i){if(i.toString().split("\r\n")[0]=="root"){if(e[":0"].State!="Connected"&&e[":0"].State!="Active"){this.parent.parent.Parent.emit("Dismissed");return}this.parent.parent._notify=require("child_process").execFile("/bin/sh",["sh"],{type:require("child_process").SpawnTypes.TERM});this.parent.parent._notify.stdin.write("su - "+e[":0"].Username+" -c \"DISPLAY=:0 notify-send '"+this.parent.parent.Parent.title+"' '"+this.parent.parent.Parent.caption+"'\"\n");this.parent.parent._notify.stdin.write("exit\n");this.parent.parent._notify.stdout.on("data",function(n){})}else{this.parent.parent._notify=require("child_process").execFile("/usr/bin/notify-send",["notify-send",this.parent.parent.Parent.title,this.parent.parent.Parent.caption],{type:require("child_process").SpawnTypes.TERM});this.parent.parent._notify.stdout.on("data",function(n){})}this.parent.parent.Parent._timeout=setTimeout(function m(n){n.emit("Dismissed")},10000,this.parent.parent.Parent)});this._cchild.parent=this})});h._sessions.Parent=h;toasters[h._hashCode()]=h;h.on("Dismissed",function(){delete toasters[this._hashCode()]});return(h)}}}module.exports=new Toaster();

File diff suppressed because one or more lines are too long

View File

@ -1 +0,0 @@
function _Scan(){var f=this.Marshal.CreatePointer();this.Native.WlanEnumInterfaces(this.Handle,0,f);var a=f.Deref().Deref(0,4).toBuffer().readUInt32LE(0);var d=f.Deref().Deref(8,532);var c=d.Deref(16,512).AnsiString;var e;switch(d.Deref(528,4).toBuffer().readUInt32LE(0)){case 0:e="NOT READY";break;case 1:e="CONNECTED";break;case 2:e="AD-HOC";break;case 3:e="DISCONNECTING";break;case 4:e="DISCONNECTED";break;case 5:e="ASSOCIATING";break;case 6:e="DISCOVERING";break;case 7:e="AUTHENTICATING";break;default:e="UNKNOWN";break}var b=d.Deref(0,16);if(this.Native.WlanScan(this.Handle,b,0,0,0).Val==0){return(true)}else{return(false)}}function AccessPoint(d,a,c,b){this.ssid=d;this.bssid=a;this.rssi=c;this.lq=b}AccessPoint.prototype.toString=function(){return(this.ssid+" ["+this.bssid+"]: "+this.lq)};function OnNotify(g){var h=g.Deref(0,4).toBuffer().readUInt32LE(0);var f=g.Deref(4,4).toBuffer().readUInt32LE(0);var c=g.Deref(8,16);if((h&8)&&(f==7)){var a=this.Parent.Marshal.CreatePointer();var k=this.Parent.Native.GetBSSList(this.Parent.Handle,c,0,3,0,0,a).Val;if(k==0){var n=a.Deref().Deref(0,4).toBuffer().readUInt32LE(0);var j=a.Deref().Deref(4,4).toBuffer().readUInt32LE(0);for(i=0;i<j;++i){var d=a.Deref().Deref(8+(360*i),360);var m=d.Deref(4,32).String.trim();var b=d.Deref(40,6).HexString2;var l=d.Deref(56,4).toBuffer().readUInt32LE(0);var e=d.Deref(60,4).toBuffer().readUInt32LE(0);this.Parent.emit("Scan",new AccessPoint(m,b,l,e))}}}}function Wireless(){var a=require("events").inherits(this);this.Marshal=require("_GenericMarshal");this.Native=this.Marshal.CreateNativeProxy("wlanapi.dll");this.Native.CreateMethod("WlanOpenHandle");this.Native.CreateMethod("WlanGetNetworkBssList","GetBSSList");this.Native.CreateMethod("WlanRegisterNotification");this.Native.CreateMethod("WlanEnumInterfaces");this.Native.CreateMethod("WlanScan");this.Native.CreateMethod("WlanQueryInterface");var c=this.Marshal.CreatePointer();var b=this.Marshal.CreatePointer();this.Native.WlanOpenHandle(2,0,c,b);this.Handle=b.Deref();this._NOTIFY_PROXY_OBJECT=this.Marshal.CreateCallbackProxy(OnNotify,2);this._NOTIFY_PROXY_OBJECT.Parent=this;var d=this.Marshal.CreatePointer();var e=this.Native.WlanRegisterNotification(this.Handle,65535,0,this._NOTIFY_PROXY_OBJECT.Callback,this._NOTIFY_PROXY_OBJECT.State,0,d);a.createEvent("Scan");a.addMethod("Scan",_Scan);this.GetConnectedNetwork=function(){var n=this.Marshal.CreatePointer();console.log("Success = "+this.Native.WlanEnumInterfaces(this.Handle,0,n).Val);var h=n.Deref().Deref(0,4).toBuffer().readUInt32LE(0);var m=n.Deref().Deref(8,532);var l=m.Deref(16,512).AnsiString;var o=m.Deref(528,4).toBuffer().readUInt32LE(0);if(m.Deref(528,4).toBuffer().readUInt32LE(0)==1){var j=this.Marshal.CreatePointer();var q=this.Marshal.CreatePointer();var s=this.Marshal.CreatePointer();var k=m.Deref(0,16);var r=this.Native.WlanQueryInterface(this.Handle,k,7,0,j,q,s).Val;if(r==0){var f=q.Deref().Deref(524,32).String;var g=q.Deref().Deref(560,6).HexString;var p=q.Deref().Deref(576,4).toBuffer().readUInt32LE(0);return(new AccessPoint(f,g,0,p))}}throw ("GetConnectedNetworks: FAILED (not associated to a network)")};return(this)}module.exports=new Wireless();

View File

@ -1 +0,0 @@
var MemoryStream=require("MemoryStream");var WindowsChildScript='var parent = require("ScriptContainer");var Wireless = require("wifi-scanner-windows");Wireless.on("Scan", function (ap) { parent.send(ap); });Wireless.Scan();';function AccessPoint(c,a,b){this.ssid=c;this.bssid=a;this.lq=b}AccessPoint.prototype.toString=function(){return("["+this.bssid+"]: "+this.ssid+" ("+this.lq+")")};function WiFiScanner(){var a=require("events").inherits(this);a.createEvent("accessPoint");this.hasWireless=function(){var d=false;var b=require("os").networkInterfaces();for(var c in b){if(b[c][0].type=="wireless"){d=true;break}}return(d)};this.Scan=function(){if(process.platform=="win32"){this.master=require("ScriptContainer").Create(15,ContainerPermissions.DEFAULT);this.master.parent=this;this.master.on("data",function(e){this.parent.emit("accessPoint",new AccessPoint(e.ssid,e.bssid,e.lq))});this.master.addModule("wifi-scanner-windows",getJSModule("wifi-scanner-windows"));this.master.ExecuteString(WindowsChildScript)}else{if(process.platform=="linux"){var c=require("os").networkInterfaces();var d=null;for(var b in c){if(c[b][0].type=="wireless"){d=b;break}}if(d!=null){this.child=require("child_process").execFile("/sbin/iwlist",["iwlist",d,"scan"]);this.child.parent=this;this.child.ms=new MemoryStream();this.child.ms.parent=this.child;this.child.stdout.on("data",function(e){this.parent.ms.write(e)});this.child.on("exit",function(){this.ms.end()});this.child.ms.on("end",function(){var l=this.buffer.toString();tokens=l.split(" - Address: ");for(var h in tokens){if(h==0){continue}var i=tokens[h].split("\n");var e=i[0];var f;var g;for(var j in i){j=i[j].trim();j=j.trim();if(j.startsWith("ESSID:")){g=j.slice(7,j.length-1);if(g=="<hidden>"){g=""}}if(j.startsWith("Signal level=")){f=j.slice(13,j.length-4)}else{if(j.startsWith("Quality=")){f=j.slice(8,10);var k=j.slice(11,13)}}}this.parent.parent.emit("accessPoint",new AccessPoint(g,e,f))}})}}}}}module.exports=WiFiScanner;

View File

@ -1 +0,0 @@
var TrayIconFlags={NIF_MESSAGE:1,NIF_ICON:2,NIF_TIP:4,NIF_STATE:8,NIF_INFO:16,NIF_GUID:32,NIF_REALTIME:64,NIF_SHOWTIP:128,NIM_ADD:0,NIM_MODIFY:1,NIM_DELETE:2,NIM_SETFOCUS:3,NIM_SETVERSION:4};var NOTIFYICON_VERSION_4=4;var MessageTypes={WM_APP:32768,WM_USER:1024};function WindowsConsole(){if(process.platform=="win32"){this._ObjectID="win-console";this._Marshal=require("_GenericMarshal");this._kernel32=this._Marshal.CreateNativeProxy("kernel32.dll");this._user32=this._Marshal.CreateNativeProxy("user32.dll");this._kernel32.CreateMethod("GetConsoleWindow");this._kernel32.CreateMethod("GetCurrentThread");this._user32.CreateMethod("ShowWindow");this._user32.CreateMethod("LoadImageA");this._user32.CreateMethod({method:"GetMessageA",threadDispatch:1});this._shell32=this._Marshal.CreateNativeProxy("Shell32.dll");this._shell32.CreateMethod("Shell_NotifyIconA");this._handle=this._kernel32.GetConsoleWindow();this.minimize=function(){this._user32.ShowWindow(this._handle,6)};this.restore=function(){this._user32.ShowWindow(this._handle,9)};this.hide=function(){this._user32.ShowWindow(this._handle,0)};this.show=function(){this._user32.ShowWindow(this._handle,5)};this._loadicon=function(c){var b=this._user32.LoadImageA(0,this._Marshal.CreateVariable(c),1,0,0,16|32768|64);return(b)};this.SetTrayIcon=function a(h){var b=this._Marshal.CreateVariable(this._Marshal.PointerSize==4?508:528);b.toBuffer().writeUInt32LE(b._size,0);var n=TrayIconFlags.NIF_TIP|TrayIconFlags.NIF_MESSAGE;h.filter=MessageTypes.WM_APP+1;b.Deref(this._Marshal.PointerSize==4?16:24,4).toBuffer().writeUInt32LE(h.filter);if(!h.noBalloon){n|=TrayIconFlags.NIF_INFO}if(h.icon){n|=TrayIconFlags.NIF_ICON;var c=b.Deref(this._Marshal.PointerSize==4?20:32,this._Marshal.PointerSize);h.icon.pointerBuffer().copy(c.toBuffer())}b.Deref(this._Marshal.PointerSize*2,4).toBuffer().writeUInt32LE(1);b.Deref(this._Marshal.PointerSize==4?12:20,4).toBuffer().writeUInt32LE(n);b.Deref(this._Marshal.PointerSize==4?416:432,4).toBuffer().writeUInt32LE(NOTIFYICON_VERSION_4);var m=b.Deref(this._Marshal.PointerSize==4?24:40,128);var k=b.Deref(this._Marshal.PointerSize==4?160:176,256);var l=b.Deref(this._Marshal.PointerSize==4?420:436,64);if(h.szTip){Buffer.from(h.szTip).copy(m.toBuffer())}if(h.szInfo){Buffer.from(h.szInfo).copy(k.toBuffer())}if(h.szInfoTitle){Buffer.from(h.szInfoTitle).copy(l.toBuffer())}var d=require("win-message-pump");retVal={_ObjectID:"WindowsConsole.TrayIcon",MessagePump:new d(h)};var j=require("events").inherits(retVal);j.createEvent("ToastClicked");j.createEvent("IconHover");j.createEvent("ToastDismissed");retVal.Options=h;retVal.MessagePump.TrayIcon=retVal;retVal.MessagePump.NotifyData=b;retVal.MessagePump.WindowsConsole=this;retVal.MessagePump.on("exit",function e(o){console.log("Pump Exited");if(this.TrayIcon){this.TrayIcon.remove()}});retVal.MessagePump.on("hwnd",function f(o){h.hwnd=o;o.pointerBuffer().copy(this.NotifyData.Deref(this.WindowsConsole._Marshal.PointerSize,this.WindowsConsole._Marshal.PointerSize).toBuffer());if(this.WindowsConsole._shell32.Shell_NotifyIconA(TrayIconFlags.NIM_ADD,this.NotifyData).Val==0){}});retVal.MessagePump.on("message",function g(p){if(p.message==this.TrayIcon.Options.filter){var o=false;if(p.wparam==1&&p.lparam==1029){this.TrayIcon.emit("ToastClicked");o=true}if(p.wparam==1&&p.lparam==512){this.TrayIcon.emit("IconHover");o=true}if(this.TrayIcon.Options.balloonOnly&&p.wparam==1&&(p.lparam==1028||p.lparam==1029)){this.TrayIcon.emit("ToastDismissed");this.TrayIcon.remove();o=true}if(!o){console.log(p)}}});retVal.remove=function i(){this.MessagePump.WindowsConsole._shell32.Shell_NotifyIconA(TrayIconFlags.NIM_DELETE,this.MessagePump.NotifyData);this.MessagePump.stop();delete this.MessagePump.TrayIcon;delete this.MessagePump};return(retVal)}}}module.exports=new WindowsConsole();

View File

@ -1 +0,0 @@
var WH_CALLWNDPROC=4;var WM_QUIT=18;var GM=require("_GenericMarshal");function WindowsMessagePump(d){this._ObjectID="win-message-pump";this._options=d;var b=require("events").inherits(this);b.createEvent("hwnd");b.createEvent("error");b.createEvent("message");b.createEvent("exit");this._msg=GM.CreateVariable(GM.PointerSize==4?28:48);this._kernel32=GM.CreateNativeProxy("Kernel32.dll");this._kernel32.mp=this;this._kernel32.CreateMethod("GetLastError");this._kernel32.CreateMethod("GetModuleHandleA");this._user32=GM.CreateNativeProxy("User32.dll");this._user32.mp=this;this._user32.CreateMethod("GetMessageA");this._user32.CreateMethod("CreateWindowExA");this._user32.CreateMethod("TranslateMessage");this._user32.CreateMethod("DispatchMessageA");this._user32.CreateMethod("RegisterClassExA");this._user32.CreateMethod("DefWindowProcA");this._user32.CreateMethod("PostMessageA");this.wndclass=GM.CreateVariable(GM.PointerSize==4?48:80);this.wndclass.mp=this;this.wndclass.hinstance=this._kernel32.GetModuleHandleA(0);this.wndclass.cname=GM.CreateVariable("MainWWWClass");this.wndclass.wndproc=GM.GetGenericGlobalCallback(4);this.wndclass.wndproc.mp=this;this.wndclass.toBuffer().writeUInt32LE(this.wndclass._size);this.wndclass.cname.pointerBuffer().copy(this.wndclass.Deref(GM.PointerSize==4?40:64,GM.PointerSize).toBuffer());this.wndclass.wndproc.pointerBuffer().copy(this.wndclass.Deref(8,GM.PointerSize).toBuffer());this.wndclass.hinstance.pointerBuffer().copy(this.wndclass.Deref(GM.PointerSize==4?20:24,GM.PointerSize).toBuffer());this.wndclass.wndproc.on("GlobalCallback",function c(h,i,g,f){if(this.mp._hwnd!=null&&this.mp._hwnd.Val==h.Val){this.mp.emit("message",{message:i.Val,wparam:g.Val,lparam:f.Val,lparam_hex:f.pointerBuffer().toString("hex")});return(this.mp._user32.DefWindowProcA(h,i,g,f))}else{if(this.mp._hwnd==null&&this.CallingThread()==this.mp._user32.RegisterClassExA.async.threadId()){return(this.mp._user32.DefWindowProcA(h,i,g,f))}}});this._user32.RegisterClassExA.async(this.wndclass).then(function(){this.nativeProxy.CreateWindowExA.async(this.nativeProxy.RegisterClassExA.async,136,this.nativeProxy.mp.wndclass.cname,0,8388608,0,0,100,100,0,0,0,0).then(function(f){if(f.Val==0){this.nativeProxy.mp.emit("error","Error creating hidden window")}else{this.nativeProxy.mp._hwnd=f;this.nativeProxy.mp.emit("hwnd",f);this.nativeProxy.mp._startPump()}})});this._startPump=function a(){this._user32.GetMessageA.async(this._user32.RegisterClassExA.async,this._msg,this._hwnd,0,0).then(function(f){if(f.Val>0){this.nativeProxy.TranslateMessage.async(this.nativeProxy.RegisterClassExA.async,this.nativeProxy.mp._msg).then(function(){this.nativeProxy.DispatchMessageA.async(this.nativeProxy.RegisterClassExA.async,this.nativeProxy.mp._msg).then(function(){this.nativeProxy.mp._startPump()})})}else{delete this.nativeProxy.mp._hwnd;this.nativeProxy.mp.emit("exit",0)}},function(f){this.nativeProxy.mp.stop()})};this.stop=function e(){if(this._hwnd){this._user32.PostMessageA(this._hwnd,WM_QUIT,0,0)}}}module.exports=WindowsMessagePump;

View File

@ -1 +0,0 @@
var KEY_QUERY_VALUE=1;var KEY_ENUMERATE_SUB_KEYS=8;var KEY_WRITE=131078;var KEY_DATA_TYPES={REG_NONE:0,REG_SZ:1,REG_EXPAND_SZ:2,REG_BINARY:3,REG_DWORD:4,REG_DWORD_BIG_ENDIAN:5,REG_LINK:6,REG_MULTI_SZ:7,REG_RESOURCE_LIST:8,REG_FULL_RESOURCE_DESCRIPTOR:9,REG_RESOURCE_REQUIREMENTS_LIST:10,REG_QWORD:11};function windows_registry(){this._ObjectId="win-registry";this._marshal=require("_GenericMarshal");this._AdvApi=this._marshal.CreateNativeProxy("Advapi32.dll");this._AdvApi.CreateMethod("RegCreateKeyExA");this._AdvApi.CreateMethod("RegEnumKeyExA");this._AdvApi.CreateMethod("RegEnumValueA");this._AdvApi.CreateMethod("RegOpenKeyExA");this._AdvApi.CreateMethod("RegQueryInfoKeyA");this._AdvApi.CreateMethod("RegQueryValueExA");this._AdvApi.CreateMethod("RegCloseKey");this._AdvApi.CreateMethod("RegDeleteKeyA");this._AdvApi.CreateMethod("RegDeleteValueA");this._AdvApi.CreateMethod("RegSetValueExA");this.HKEY={Root:Buffer.from("80000000","hex").swap32(),CurrentUser:Buffer.from("80000001","hex").swap32(),LocalMachine:Buffer.from("80000002","hex").swap32(),Users:Buffer.from("80000003","hex").swap32()};this.QueryKey=function b(o,A,q){var l;var m=this._marshal.CreatePointer();var s=this._marshal.CreateVariable(4);var E=this._marshal.CreateVariable(4);var n=this._marshal.CreatePointer(o);var C=null;if(q){q=this._marshal.CreateVariable(q)}if(!A){A=""}if((l=this._AdvApi.RegOpenKeyExA(n,this._marshal.CreateVariable(A),0,KEY_QUERY_VALUE|KEY_ENUMERATE_SUB_KEYS,m).Val)!=0){throw ("Opening Registry Key: "+A+" => Returned Error: "+l)}if((A==""&&!q)||!q){var B={subkeys:[],values:[]};var d=this._marshal.CreateVariable(1024);var f=this._marshal.CreateVariable(1024);var g=this._marshal.CreateVariable(32768);var j=this._marshal.CreateVariable(4);var x=this._marshal.CreateVariable(4);var e=this._marshal.CreateVariable(4);e.toBuffer().writeUInt32LE(1024);var y=this._marshal.CreateVariable(4);var z=this._marshal.CreateVariable(4);var u=this._marshal.CreateVariable(4);var t=this._marshal.CreateVariable(4);var w=this._marshal.CreateVariable(4);var v=this._marshal.CreateVariable(4);var D=this._marshal.CreateVariable(4);var r=this._marshal.CreateVariable(8);C=this._AdvApi.RegQueryInfoKeyA(m.Deref(),d,e,0,y,u,t,z,w,v,D,r);if(C.Val!=0){throw ("RegQueryInfoKeyA() returned error: "+C.Val)}for(var p=0;p<y.toBuffer().readUInt32LE();++p){x.toBuffer().writeUInt32LE(1024);C=this._AdvApi.RegEnumKeyExA(m.Deref(),p,f,x,0,0,0,r);if(C.Val==0){B.subkeys.push(f.String)}}for(var p=0;p<z.toBuffer().readUInt32LE();++p){j.toBuffer().writeUInt32LE(32768);if(this._AdvApi.RegEnumValueA(m.Deref(),p,g,j,0,0,0,0).Val==0){B.values.push(g.String)}}return(B)}if(this._AdvApi.RegQueryValueExA(m.Deref(),q,0,0,0,s).Val==0){var k=this._marshal.CreateVariable(s.toBuffer().readUInt32LE());if(this._AdvApi.RegQueryValueExA(m.Deref(),q,0,E,k,s).Val==0){switch(E.toBuffer().readUInt32LE()){case KEY_DATA_TYPES.REG_DWORD:C=k.toBuffer().readUInt32LE();break;case KEY_DATA_TYPES.REG_DWORD_BIG_ENDIAN:C=k.toBuffer().readUInt32BE();break;case KEY_DATA_TYPES.REG_SZ:C=k.String;break;case KEY_DATA_TYPES.REG_BINARY:default:C=k.toBuffer();C._data=k;break}}}else{this._AdvApi.RegCloseKey(m.Deref());throw ("Not Found")}this._AdvApi.RegCloseKey(m.Deref());return(C)};this.WriteKey=function c(g,j,i,l){var k;var f=this._marshal.CreatePointer();if(this._AdvApi.RegCreateKeyExA(this._marshal.CreatePointer(g),this._marshal.CreateVariable(j),0,0,0,KEY_WRITE,0,f,0).Val!=0){throw ("Error Opening Registry Key: "+j)}var d;var e;switch(typeof(l)){case"boolean":e=KEY_DATA_TYPES.REG_DWORD;d=this._marshal.CreateVariable(4);d.toBuffer().writeUInt32LE(l?1:0);break;case"number":e=KEY_DATA_TYPES.REG_DWORD;d=this._marshal.CreateVariable(4);d.toBuffer().writeUInt32LE(l);break;case"string":e=KEY_DATA_TYPES.REG_SZ;d=this._marshal.CreateVariable(l);break;default:e=KEY_DATA_TYPES.REG_BINARY;d=this._marshal.CreateVariable(l.length);l.copy(d.toBuffer());break}if(this._AdvApi.RegSetValueExA(f.Deref(),this._marshal.CreateVariable(i),0,e,d,d._size).Val!=0){this._AdvApi.RegCloseKey(f.Deref());throw ("Error writing reg key: "+i)}this._AdvApi.RegCloseKey(f.Deref())};this.DeleteKey=function a(e,g,f){if(!f){if(this._AdvApi.RegDeleteKeyA(this._marshal.CreatePointer(e),this._marshal.CreateVariable(g)).Val!=0){throw ("Error Deleting Key: "+g)}}else{var d=this._marshal.CreatePointer();var i;if(this._AdvApi.RegOpenKeyExA(this._marshal.CreatePointer(e),this._marshal.CreateVariable(g),0,KEY_QUERY_VALUE|KEY_WRITE,d).Val!=0){throw ("Error Opening Registry Key: "+g)}if((i=this._AdvApi.RegDeleteValueA(d.Deref(),this._marshal.CreateVariable(f)).Val)!=0){this._AdvApi.RegCloseKey(d.Deref());throw ("Error["+i+"] Deleting Key: "+g+"."+f)}this._AdvApi.RegCloseKey(d.Deref())}}}module.exports=new windows_registry();

File diff suppressed because one or more lines are too long

View File

@ -757,6 +757,20 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
// Nothing is done right now.
break;
}
case 'getScript':
{
// Used by the agent to get configuration scripts.
if (command.type == 1) {
obj.parent.getCiraConfigurationScript(obj.dbMeshKey, function (script) {
obj.send(JSON.stringify({ action: 'getScript', type: 1, script: script.toString() }));
});
} else if (command.type == 2) {
obj.parent.getCiraCleanupScript(function (script) {
obj.send(JSON.stringify({ action: 'getScript', type: 2, script: script.toString() }));
});
}
break;
}
default: {
console.log('Unknown agent action (' + obj.remoteaddrport + '): ' + command.action + '.');
break;

View File

@ -1471,6 +1471,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
{
// Check is 2-step login is supported
const twoStepLoginSupported = ((domain.auth != 'sspi') && (obj.parent.parent.certificates.CommonName != 'un-configured') && (obj.args.lanonly !== true) && (obj.args.nousers !== true));
if (twoStepLoginSupported == false) break;
// Perform a sub-action
var actionTaken = false;
@ -1489,7 +1490,103 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
if (actionTaken) { obj.parent.db.SetUser(user); }
// Return one time passwords for this user
if (twoStepLoginSupported && user.otpsecret) { ws.send(JSON.stringify({ action: 'otpauth-getpasswords', passwords: user.otpkeys?user.otpkeys.keys:null })); }
if (user.otpsecret) { ws.send(JSON.stringify({ action: 'otpauth-getpasswords', passwords: user.otpkeys?user.otpkeys.keys:null })); }
break;
}
case 'otp-hkey-get':
{
// Check is 2-step login is supported
const twoStepLoginSupported = ((domain.auth != 'sspi') && (obj.parent.parent.certificates.CommonName != 'un-configured') && (obj.args.lanonly !== true) && (obj.args.nousers !== true));
if (twoStepLoginSupported == false) break;
// Send back the list of keys we have, just send the list of names and index
var hkeys = [];
if (user.otphkeys != null) { for (var i = 0; i < user.otphkeys.length; i++) { hkeys.push({ i: user.otphkeys[i].keyIndex, name: user.otphkeys[i].name }); } }
//hkeys = [{ i: 1234, name: 'My Normal Key' }, { i: 5678, name: 'Backup Key' }, { i: 90122, name: 'Blue Extra Key' }];
ws.send(JSON.stringify({ action: 'otp-hkey-get', keys: hkeys }));
break;
}
case 'otp-hkey-remove':
{
// Check is 2-step login is supported
const twoStepLoginSupported = ((domain.auth != 'sspi') && (obj.parent.parent.certificates.CommonName != 'un-configured') && (obj.args.lanonly !== true) && (obj.args.nousers !== true));
if (twoStepLoginSupported == false || command.index == null) break;
// Remove a key
var foundAtIndex = -1;
if (user.otphkeys != null) { for (var i = 0; i < user.otphkeys.length; i++) { if (user.otphkeys[i].keyIndex == command.index) { foundAtIndex = i; } } }
if (foundAtIndex != -1) {
user.otphkeys.splice(foundAtIndex, 1);
obj.parent.db.SetUser(user);
}
break;
}
case 'otp-hkey-yubikey-add':
{
// Yubico API id and signature key can be requested from https://upgrade.yubico.com/getapikey/
// Check is 2-step login is supported
const twoStepLoginSupported = ((domain.auth != 'sspi') && (obj.parent.parent.certificates.CommonName != 'un-configured') && (obj.args.lanonly !== true) && (obj.args.nousers !== true));
if ((twoStepLoginSupported == false) || (typeof command.otp != 'string')) break;
// Check if Yubikey support is present
if ((typeof domain.yubikey != 'object') || (typeof domain.yubikey.id != 'string') || (typeof domain.yubikey.secret != 'string')) break;
/*
var yub = require('yubikey-client');
yub.init(domain.yubikey.id, domain.yubikey.secret);
yub.verify(command.otp, function (err, data) {
console.log(err, data);
});
*/
var yubikeyotp = require('yubikeyotp');
//var request = { otp: command.otp, id: domain.yubikey.id, key: domain.yubikey.secret, sl: '100', timestamp: true }
var request = { otp: command.otp, id: domain.yubikey.id, key: domain.yubikey.secret, timestamp: true }
if (domain.yubikey.proxy) { request.requestParams = { proxy: domain.yubikey.proxy }; }
console.log('YubiKey Request: ' + JSON.stringify(request));
yubikeyotp.verifyOTP(request, function (err, results) {
console.log(err, results);
});
break;
}
case 'otp-hkey-setup-request':
{
// Check is 2-step login is supported
const twoStepLoginSupported = ((domain.auth != 'sspi') && (obj.parent.parent.certificates.CommonName != 'un-configured') && (obj.args.lanonly !== true) && (obj.args.nousers !== true));
if (twoStepLoginSupported == false) break;
// Build list of known keys
//var knownKeys = [];
//if (user.otphkeys != null) { for (var i = 0; i < user.otphkeys.length; i++) { knownKeys.push(user.otphkeys[i].keyHandle); } }
// Build a key registration request and send it over
const registrationRequest = require('u2f').request('https://' + obj.parent.parent.certificates.CommonName);
if (registrationRequest) { ws.send(JSON.stringify({ action: 'otp-hkey-setup-request', request: registrationRequest, name: command.name })); }
break;
}
case 'otp-hkey-setup-response':
{
// Check is 2-step login is supported
const twoStepLoginSupported = ((domain.auth != 'sspi') && (obj.parent.parent.certificates.CommonName != 'un-configured') && (obj.args.lanonly !== true) && (obj.args.nousers !== true));
if ((twoStepLoginSupported == false) || (command.request == null) || (command.response == null) || (command.name == null)) break;
// Check the key registration request
const result = require('u2f').checkRegistration(command.request, command.response);
if (result) {
var keyIndex = obj.parent.crypto.randomBytes(4).readUInt32BE(0);
ws.send(JSON.stringify({ action: 'otp-hkey-setup-response', result: result.successful, name: command.name, index: keyIndex }));
if (result.successful) {
if (user.otphkeys == null) { user.otphkeys = []; }
user.otphkeys.push({ name: command.name, publicKey: result.publicKey, keyHandle: result.keyHandle, keyIndex: keyIndex });
obj.parent.db.SetUser(user);
//console.log('KEYS', JSON.stringify(user.otphkeys));
}
}
break;
}
case 'getNotes':

Binary file not shown.

After

Width:  |  Height:  |  Size: 362 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 578 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -252,6 +252,7 @@
<span id="otpAuth" style="display:none"><a onclick="account_addOtp()" style="cursor:pointer">Add 2-step login</a><br /></span>
<span id="otpAuthRemove" style="display:none"><a onclick="account_removeOtp()" style="cursor:pointer">Remove 2-step login</a><br /></span>
<span id="manageOtp" style="display:none"><a onclick="account_manageOtp(0)" style="cursor:pointer">Manage one time passwords</a><br /></span>
<span id="manageHardwareOtp" style="display:none"><a onclick="account_manageHardwareOtp(0)" style="cursor:pointer">Manage hardware login keys</a><br /></span>
<a onclick="account_showChangeEmail()" style="cursor:pointer">Change email address</a><br />
<a onclick="account_showChangePassword()" style="cursor:pointer">Change password</a><br />
<a onclick="account_showDeleteAccount()" style="cursor:pointer">Delete account</a><br />
@ -1172,6 +1173,7 @@
QV('otpAuth', ((features & 4096) != 0) && (userinfo.otpsecret != 1));
QV('otpAuthRemove', ((features & 4096) != 0) && (userinfo.otpsecret == 1));
QV('manageOtp', ((features & 4096) != 0) && (userinfo.otpsecret == 1));
QV('manageHardwareOtp', ((features & 0x5000) != 0)); // Requires 2-step login + YubiKey support
}
function onMessage(server, message) {
@ -1438,6 +1440,55 @@
setDialogMode(2, "Manage One Time Passwords", 8, null, x, 'otpauth-manage');
break;
}
case 'otp-hkey-get': {
if (xxdialogMode && (xxdialogTag != 'otpauth-hardware-manage')) return;
var start = "<div style='border-radius:6px;border: 2px solid #CCC;background-color:#BBB;width:100%;margin-top:8px'><div style='padding:8px;font-family:Arial, Helvetica, sans-serif;font-size:16px;font-weight:bold'><table style=width:100%;text-align:left>";
var end = "</table></div></div>";
var x = "<a href='https://www.yubico.com/' rel='noreferrer noopener' target='_blank'>Hardware keys</a> are used as secondary login authentication.";
x += "";
if (message.keys && message.keys.length > 0) {
for (var i in message.keys) {
var key = message.keys[i];
x += start + '<tr style=margin:5px><td style=width:30px><img src="images/hardware-key-24.png"><td style=width:250px>' + key.name + "<td><input type=button value='Remove' onclick=account_removehkey(" + key.i + ")></input>" + end;
}
} else {
x += start + '<tr style=text-align:center><td>No Hardware Keys Configured' + end;
}
x += "<br />";
x += "<div><input type=button value='Close' onclick=setDialogMode(0) style=float:right></input>";
//x += "<input type=button value='Add YubiKey' onclick='account_addYubiKey();'></input>";
if (window.u2f) {
x += "<input type=button value='Add Key' onclick='account_addhkey();'></input>";
} else {
x += "No hardware key support on this browser.";
}
x += "</div><br />";
setDialogMode(2, "Manage Hardware Login Keys", 8, null, x, 'otpauth-hardware-manage');
break;
}
case 'otp-hkey-setup-request': {
if (xxdialogMode && (xxdialogTag != 'otpauth-hardware-manage')) return;
var x = "Press the key button now.<br /><br /><div style=width:100%;text-align:center><img src='images/hardware-keypress-120.png' /></div><input id=dp1keyname style=display:none value=" + message.name + " />";
setDialogMode(2, "Add Hardware Login Key", 2, null, x);
window.u2f.register(message.request.appId, [message.request], [], function (registrationResponse) {
if (registrationResponse.errorCode == 0) {
meshserver.send({ action: 'otp-hkey-setup-response', request: message.request, response: registrationResponse, name: Q('dp1keyname').value });
setDialogMode(2, "Add Hardware Login Key", 0, null, '<br />Checking...<br /><br /><br />', 'otpauth-hardware-manage');
} else {
setDialogMode(0);
}
});
break;
}
case 'otp-hkey-setup-response': {
if (xxdialogMode && (xxdialogTag != 'otpauth-hardware-manage')) return;
if (message.result == true) {
meshserver.send({ action: 'otp-hkey-get' }); // Success, ask for the full list of keys.
} else {
setDialogMode(2, "Add Hardware Login Key", 1, null, '<br />ERROR: Unable to add key.<br /><br />', 'otpauth-hardware-manage');
}
break;
}
case 'event': {
if (!message.event.nolog) {
events.unshift(message.event);
@ -5174,8 +5225,8 @@
// Called then user presses the "Change Core" button
function p15uploadCore(e) {
if (xxdialogMode) return;
if (e.shiftKey == true) { meshserver.send({ action: 'uploadagentcore', nodeid: consoleNode._id, path:'*' }); } // Upload default core
else if (e.altKey == true) { meshserver.send({ action: 'uploadagentcore', nodeid: consoleNode._id }); } // Clear the core
if (e.shiftKey == true) { meshserver.send({ action: 'uploadagentcore', nodeid: consoleNode._id, type: 'default' }); } // Upload default core
else if (e.altKey == true) { meshserver.send({ action: 'uploadagentcore', nodeid: consoleNode._id, type: 'clear' }); } // Clear the core
else if (e.ctrlKey == true) { p15uploadCore2(); } // Upload the core from a file
else { setDialogMode(2, "Change Mesh Agent Core", 3, p15uploadCoreEx, '<select id=d3coreMode style=float:right;width:260px><option value=1>Upload default server core</option><option value=2>Clear the core</option><option value=6>Upload recovery core</option><option value=3>Upload a core file</option><option value=4>Soft disconnect agent</option><option value=5>Hard disconnect agent</option></select><div>Change Core</div>'); }
}
@ -5250,6 +5301,49 @@
meshserver.send({ action: 'otpauth-getpasswords', subaction: action });
}
function account_manageHardwareOtp() {
if ((xxdialogMode == 2) && (xxdialogTag == 'otpauth-hardware-manage')) { dialogclose(0); }
if (xxdialogMode || ((features & 4096) == 0)) return;
meshserver.send({ action: 'otp-hkey-get' });
}
function account_addhkey() {
var x = "Type in the name of the key to add.<br /><br />";
x += addHtmlValue('Key Name', '<input id=dp1keyname style=width:230px maxlength=20 autocomplete=off onchange=account_addhkeyValidate() onkeyup=account_addhkeyValidate() />');
setDialogMode(2, "Add Hardware Login Key", 3, account_addhkeyEx, x);
account_addhkeyValidate();
}
function account_addhkeyValidate() {
QE('idx_dlgOkButton', (Q('dp1keyname').value.length > 0));
}
function account_addhkeyEx() {
meshserver.send({ action: 'otp-hkey-setup-request', name: Q('dp1keyname').value });
}
function account_addYubiKey() {
if (xxdialogMode && (xxdialogTag != 'otpauth-hardware-manage')) return;
var x = "Type in a name for the key and press button on the key to register the new hardware key.<br /><br />";
x += addHtmlValue('Key Name', '<input id=dp1keyname style=width:230px maxlength=20 autocomplete=off onchange=account_addYubiKeyValidate() onkeyup=account_addYubiKeyValidate() />');
x += addHtmlValue('Key Token', '<input id=dp1keytoken style=width:230px maxlength=2048 autocomplete=off onchange=account_addYubiKeyValidate() onkeyup=account_addYubiKeyValidate() />');
setDialogMode(2, "Add Yubikey", 3, account_addYubiKeyEx, x);
account_addYubiKeyValidate();
}
function account_addYubiKeyValidate() {
QE('idx_dlgOkButton', (Q('dp1keyname').value.length > 0) && (Q('dp1keytoken').value.length > 0));
}
function account_addYubiKeyEx() {
meshserver.send({ action: 'otp-hkey-yubikey-add', name: Q('dp1keyname').value, otp: Q('dp1keytoken').value });
}
function account_removehkey(index) {
meshserver.send({ action: 'otp-hkey-remove', index: index });
meshserver.send({ action: 'otp-hkey-get' });
}
function account_showVerifyEmail() {
if (xxdialogMode || (userinfo.emailVerified == true) || (serverinfo.emailcheck != true)) return;
var x = "Click ok to send a verification mail to:<br /><div style=padding:8px><b>" + EscapeHtml(userinfo.email) + "</b></div>Please wait a few minute to receive the verification.";

View File

@ -807,6 +807,7 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
if ((obj.parent.serverSelfWriteAllowed == true) && (user != null) && (user.siteadmin == 0xFFFFFFFF)) { features += 0x0800; } // Server can self-write (Allows self-update)
if ((domain.auth != 'sspi') && (obj.parent.certificates.CommonName != 'un-configured') && (obj.args.lanonly !== true) && (obj.args.nousers !== true)) { features += 0x1000; } // 2-step login supported
if (domain.agentnoproxy === true) { features += 0x2000; } // Indicates that agents should be installed without using a HTTP proxy
if (domain.yubikey && domain.yubikey.id && domain.yubikey.secret) { features += 0x4000; } // Indicates Yubikey support
// Create a authentication cookie
const authCookie = obj.parent.encodeCookie({ userid: user._id, domainid: domain.id }, obj.parent.loginCookieEncryptionKey);
@ -938,76 +939,91 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
res.send(Buffer.from(getRootCertBase64(), 'base64'));
}
// Return the CIRA configuration script
obj.getCiraCleanupScript = function(func) {
obj.fs.readFile(obj.parent.path.join(obj.parent.webPublicPath, 'scripts/cira_cleanup.mescript'), 'utf8', function (err, data) {
if (err != null) { func(null); return; }
func(Buffer.from(data));
});
}
// Return the CIRA configuration script
obj.getCiraConfigurationScript = function(meshid, func) {
var serverNameSplit = obj.certificates.AmtMpsName.split('.');
// Figure out the MPS port, use the alias if set
var mpsport = ((obj.args.mpsaliasport != null) ? obj.args.mpsaliasport : obj.args.mpsport);
if ((serverNameSplit.length == 4) && (parseInt(serverNameSplit[0]) == serverNameSplit[0]) && (parseInt(serverNameSplit[1]) == serverNameSplit[1]) && (parseInt(serverNameSplit[2]) == serverNameSplit[2]) && (parseInt(serverNameSplit[3]) == serverNameSplit[3])) {
// Server name is an IPv4 address
obj.fs.readFile(obj.parent.path.join(obj.parent.webPublicPath, 'scripts/cira_setup_script_ip.mescript'), 'utf8', function (err, data) {
if (err != null) { func(null); return; }
var scriptFile = JSON.parse(data);
// Change a few things in the script
scriptFile.scriptBlocks[2].vars.CertBin.value = getRootCertBase64(); // Set the root certificate
scriptFile.scriptBlocks[3].vars.IP.value = obj.certificates.AmtMpsName; // Set the server IPv4 address name
scriptFile.scriptBlocks[3].vars.ServerName.value = obj.certificates.AmtMpsName; // Set the server certificate name
scriptFile.scriptBlocks[3].vars.Port.value = mpsport; // Set the server MPS port
scriptFile.scriptBlocks[3].vars.username.value = meshid; // Set the username
scriptFile.scriptBlocks[3].vars.password.value = obj.args.mpspass ? obj.args.mpspass : 'A@xew9rt'; // Set the password
scriptFile.scriptBlocks[4].vars.AccessInfo1.value = obj.certificates.AmtMpsName + ':' + mpsport; // Set the primary server name:port to set periodic timer
//scriptFile.scriptBlocks[4].vars.AccessInfo2.value = obj.certificates.AmtMpsName + ':' + mpsport; // Set the secondary server name:port to set periodic timer
if (obj.args.ciralocalfqdn != null) { scriptFile.scriptBlocks[6].vars.DetectionStrings.value = obj.args.ciralocalfqdn; } // Set the environment detection local FQDN's
// Compile the script
var scriptEngine = require('./amtscript.js').CreateAmtScriptEngine();
var runscript = scriptEngine.script_blocksToScript(scriptFile.blocks, scriptFile.scriptBlocks);
scriptFile.mescript = Buffer.from(scriptEngine.script_compile(runscript), 'binary').toString('base64');
scriptFile.scriptText = runscript;
// Send the script
func(Buffer.from(JSON.stringify(scriptFile, null, ' ')));
});
} else {
// Server name is a hostname
obj.fs.readFile(obj.parent.path.join(obj.parent.webPublicPath, 'scripts/cira_setup_script_dns.mescript'), 'utf8', function (err, data) {
if (err != null) { res.sendStatus(404); return; }
var scriptFile = JSON.parse(data);
// Change a few things in the script
scriptFile.scriptBlocks[2].vars.CertBin.value = getRootCertBase64(); // Set the root certificate
scriptFile.scriptBlocks[3].vars.FQDN.value = obj.certificates.AmtMpsName; // Set the server DNS name
scriptFile.scriptBlocks[3].vars.Port.value = mpsport; // Set the server MPS port
scriptFile.scriptBlocks[3].vars.username.value = meshid; // Set the username
scriptFile.scriptBlocks[3].vars.password.value = obj.args.mpspass ? obj.args.mpspass : 'A@xew9rt'; // Set the password
scriptFile.scriptBlocks[4].vars.AccessInfo1.value = obj.certificates.AmtMpsName + ':' + mpsport; // Set the primary server name:port to set periodic timer
//scriptFile.scriptBlocks[4].vars.AccessInfo2.value = obj.certificates.AmtMpsName + ':' + mpsport; // Set the secondary server name:port to set periodic timer
if (obj.args.ciralocalfqdn != null) { scriptFile.scriptBlocks[6].vars.DetectionStrings.value = obj.args.ciralocalfqdn; } // Set the environment detection local FQDN's
// Compile the script
var scriptEngine = require('./amtscript.js').CreateAmtScriptEngine();
var runscript = scriptEngine.script_blocksToScript(scriptFile.blocks, scriptFile.scriptBlocks);
scriptFile.mescript = Buffer.from(scriptEngine.script_compile(runscript), 'binary').toString('base64');
scriptFile.scriptText = runscript;
// Send the script
func(Buffer.from(JSON.stringify(scriptFile, null, ' ')));
});
}
}
// Returns an mescript for Intel AMT configuration
function handleMeScriptRequest(req, res) {
if ((obj.userAllowedIp != null) && (checkIpAddressEx(req, res, obj.userAllowedIp, false) === false)) { return; } // Check server-wide IP filter only.
if (req.query.type == 1) {
var filename = 'cira_setup.mescript';
res.set({ 'Cache-Control': 'no-cache, no-store, must-revalidate', 'Pragma': 'no-cache', 'Expires': '0', 'Content-Type': 'application/octet-stream', 'Content-Disposition': 'attachment; filename=' + filename });
var serverNameSplit = obj.certificates.AmtMpsName.split('.');
// Figure out the MPS port, use the alias if set
var mpsport = ((obj.args.mpsaliasport != null) ? obj.args.mpsaliasport : obj.args.mpsport);
if ((serverNameSplit.length == 4) && (parseInt(serverNameSplit[0]) == serverNameSplit[0]) && (parseInt(serverNameSplit[1]) == serverNameSplit[1]) && (parseInt(serverNameSplit[2]) == serverNameSplit[2]) && (parseInt(serverNameSplit[3]) == serverNameSplit[3])) {
// Server name is an IPv4 address
obj.fs.readFile(obj.parent.path.join(obj.parent.webPublicPath, 'scripts/cira_setup_script_ip.mescript'), 'utf8', function (err, data) {
if (err != null) { res.sendStatus(404); return; }
var scriptFile = JSON.parse(data);
// Change a few things in the script
scriptFile.scriptBlocks[2].vars.CertBin.value = getRootCertBase64(); // Set the root certificate
scriptFile.scriptBlocks[3].vars.IP.value = obj.certificates.AmtMpsName; // Set the server IPv4 address name
scriptFile.scriptBlocks[3].vars.ServerName.value = obj.certificates.AmtMpsName; // Set the server certificate name
scriptFile.scriptBlocks[3].vars.Port.value = mpsport; // Set the server MPS port
scriptFile.scriptBlocks[3].vars.username.value = req.query.meshid; // Set the username
scriptFile.scriptBlocks[3].vars.password.value = obj.args.mpspass ? obj.args.mpspass : 'A@xew9rt'; // Set the password
scriptFile.scriptBlocks[4].vars.AccessInfo1.value = obj.certificates.AmtMpsName + ':' + mpsport; // Set the primary server name:port to set periodic timer
//scriptFile.scriptBlocks[4].vars.AccessInfo2.value = obj.certificates.AmtMpsName + ':' + mpsport; // Set the secondary server name:port to set periodic timer
if (obj.args.ciralocalfqdn != null) { scriptFile.scriptBlocks[6].vars.DetectionStrings.value = obj.args.ciralocalfqdn; } // Set the environment detection local FQDN's
// Compile the script
var scriptEngine = require('./amtscript.js').CreateAmtScriptEngine();
var runscript = scriptEngine.script_blocksToScript(scriptFile.blocks, scriptFile.scriptBlocks);
scriptFile.mescript = Buffer.from(scriptEngine.script_compile(runscript), 'binary').toString('base64');
scriptFile.scriptText = runscript;
// Send the script
res.send(Buffer.from(JSON.stringify(scriptFile, null, ' ')));
});
} else {
// Server name is a hostname
obj.fs.readFile(obj.parent.path.join(obj.parent.webPublicPath, 'scripts/cira_setup_script_dns.mescript'), 'utf8', function (err, data) {
if (err != null) { res.sendStatus(404); return; }
var scriptFile = JSON.parse(data);
// Change a few things in the script
scriptFile.scriptBlocks[2].vars.CertBin.value = getRootCertBase64(); // Set the root certificate
scriptFile.scriptBlocks[3].vars.FQDN.value = obj.certificates.AmtMpsName; // Set the server DNS name
scriptFile.scriptBlocks[3].vars.Port.value = mpsport; // Set the server MPS port
scriptFile.scriptBlocks[3].vars.username.value = req.query.meshid; // Set the username
scriptFile.scriptBlocks[3].vars.password.value = obj.args.mpspass ? obj.args.mpspass : 'A@xew9rt'; // Set the password
scriptFile.scriptBlocks[4].vars.AccessInfo1.value = obj.certificates.AmtMpsName + ':' + mpsport; // Set the primary server name:port to set periodic timer
//scriptFile.scriptBlocks[4].vars.AccessInfo2.value = obj.certificates.AmtMpsName + ':' + mpsport; // Set the secondary server name:port to set periodic timer
if (obj.args.ciralocalfqdn != null) { scriptFile.scriptBlocks[6].vars.DetectionStrings.value = obj.args.ciralocalfqdn; } // Set the environment detection local FQDN's
// Compile the script
var scriptEngine = require('./amtscript.js').CreateAmtScriptEngine();
var runscript = scriptEngine.script_blocksToScript(scriptFile.blocks, scriptFile.scriptBlocks);
scriptFile.mescript = Buffer.from(scriptEngine.script_compile(runscript), 'binary').toString('base64');
scriptFile.scriptText = runscript;
// Send the script
res.send(Buffer.from(JSON.stringify(scriptFile, null, ' ')));
});
}
}
else if (req.query.type == 2) {
var filename = 'cira_cleanup.mescript';
res.set({ 'Cache-Control': 'no-cache, no-store, must-revalidate', 'Pragma': 'no-cache', 'Expires': '0', 'Content-Type': 'application/octet-stream', 'Content-Disposition': 'attachment; filename=' + filename });
obj.fs.readFile(obj.parent.path.join(obj.parent.webPublicPath, 'scripts/cira_cleanup.mescript'), 'utf8', function (err, data) {
if (err != null) { res.sendStatus(404); return; }
res.send(Buffer.from(data));
getCiraConfigurationScript(req.query.meshid, function (script) {
if (script == null) { res.sendStatus(404); } else {
res.set({ 'Cache-Control': 'no-cache, no-store, must-revalidate', 'Pragma': 'no-cache', 'Expires': '0', 'Content-Type': 'application/octet-stream', 'Content-Disposition': 'attachment; filename=cira_setup.mescript' });
res.send(script);
}
});
} else if (req.query.type == 2) {
getCiraCleanupScript(function (script) {
if (script == null) { res.sendStatus(404); } else {
res.set({ 'Cache-Control': 'no-cache, no-store, must-revalidate', 'Pragma': 'no-cache', 'Expires': '0', 'Content-Type': 'application/octet-stream', 'Content-Disposition': 'attachment; filename=cira_cleanup.mescript' });
res.send(script);
}
});
}
}
@ -2300,6 +2316,7 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
delete user2.passtype;
if (user2.otpsecret) { user2.otpsecret = 1; } // Indicates a time secret is present.
if (user2.otpkeys) { user2.otpkeys = 1; } // Indicates a set of one time passwords are present.
if (user2.otphkeys) { user2.otphkeys = user2.otphkeys.length; } // Indicates the number of hardware keys setup
return user2;
}