Add console command to manually start apf tunnel

jsastriawan committed Sep 17, 2019 at 13:11 UTC d73f437374416fc90ea2b9ab242dbd388ac4055c
1 file changed +45 -1
agents/meshcore.js
+45 -1
@@ -306,6 +306,7 @@ function createMeshCore(agent)
306 var amtscanner = null;
307 var nextTunnelIndex = 1;
308 var amtPolicy = null;
309 + var apftunnel = null;
310
311 // Add to the server event log
312 function MeshServerLog(msg, state) {
@@ -1667,7 +1668,7 @@ function createMeshCore(agent)
1668 var response = null;
1669 switch (cmd) {
1670 case 'help': { // Displays available commands
1670 - 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, amtacm,\r\namtdeactivate, amtpolicy, getscript, getclip, setclip, log, av, cpuinfo, sysinfo.';
1671 + 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, amtacm,\r\namtdeactivate, amtpolicy, getscript, getclip, setclip, log, av, cpuinfo, sysinfo, apf.';
1672 break;
1673 }
1674 /*
@@ -2281,6 +2282,49 @@ function createMeshCore(agent)
2282 if (diag) { diag.close(); diag = null; }
2283 break;
2284 }
2285 + case 'apf': {
2286 + if (meshCoreObj.intelamt!==null) {
2287 + if (args['_'].length == 1) {
2288 + if (args['_'][0] == 'on') {
2289 + response = 'Starting APF tunnel'
2290 + var apfarg = {
2291 + mpsurl: mesh.ServerUrl.replace('agent.ashx','apf.ashx'),
2292 + mpsuser: Buffer.from(mesh.ServerInfo.MeshID,'hex').toString('base64').substring(0,16),
2293 + mpspass: Buffer.from(mesh.ServerInfo.MeshID,'hex').toString('base64').substring(0,16),
2294 + mpskeepalive: 60000,
2295 + clientname: require('os').hostname(),
2296 + clientaddress: '127.0.0.1',
2297 + clientuuid: meshCoreObj.intelamt.uuid
2298 + };
2299 + var tobj = { debug: false }; //
2300 + apftunnel= require('apfclient')(tobj,apfarg);
2301 + try {
2302 + apftunnel.connect();
2303 + response += "..success";
2304 + } catch (e) {
2305 + response += JSON.stringify(e);
2306 + }
2307 + } else if (args['_'][0] == 'off') {
2308 + response = 'Stopping APF tunnel';
2309 + try {
2310 + apftunnel.disconnect();
2311 + response += "..success";
2312 + } catch (e) {
2313 + response += JSON.stringify(e);
2314 + }
2315 + apftunnel=null;
2316 + } else {
2317 + response = 'Invalid command.\r\nCmd syntax: apf on|off';
2318 + }
2319 + } else {
2320 + response = 'APF tunnel is '+ (apftunnel == null ? 'off': 'on' );
2321 + }
2322 +
2323 + } else {
2324 + response = 'APF tunnel requires Intel AMT';
2325 + }
2326 + break;
2327 + }
2328 default: { // This is an unknown command, return an error message
2329 response = 'Unknown command \"' + cmd + '\", type \"help\" for list of avaialble commands.';
2330 break;