Updated meshcmd.js with --uuidoutput feature.

Ylian Saint-Hilaire committed Oct 22, 2019 at 16:29 UTC 52609a0082f26f88c2d04bf04a29751ea3ad222f
3 files changed +162 -30
agents/meshcmd.js
+80 -14
@@ -153,6 +153,7 @@ function run(argv) {
153 if ((typeof args.tag) == 'string') { settings.tag = args.tag; }
154 if ((typeof args.scan) == 'string') { settings.scan = args.scan; }
155 if ((typeof args.timeout) == 'string') { settings.timeout = parseInt(args.timeout); }
156 + if ((typeof args.uuidoutput) == 'string' || args.uuidoutput) { settings.uuidoutput = args.uuidoutput; }
157 if (args.debug === true) { settings.debuglevel = 1; }
158 if (args.debug) { try { waitForDebugger(); } catch (e) { } }
159 if (args.noconsole) { settings.noconsole = true; }
@@ -355,6 +356,7 @@ function run(argv) {
356 console.log(' --user [username] The Intel AMT login username, admin is default.');
357 console.log(' --pass [password] The Intel AMT login password.');
358 console.log(' --tls Specifies that TLS must be used.');
359 + console.log(' --uuidoutput Output with unique identifier as the filename.');
360 console.log(' --json Output as a JSON format.');
361 } else if (action == 'amtauditlog') {
362 console.log('AmtAuditLog action will fetch the local or remote audit log. If used localy, no username/password is required. Example usage:\r\n\r\n meshcmd amtauditlog --host 1.2.3.4 --user admin --pass mypassword --tls --output audit.json');
@@ -364,6 +366,7 @@ function run(argv) {
366 console.log(' --user [username] The Intel AMT login username, admin is default.');
367 console.log(' --pass [password] The Intel AMT login password.');
368 console.log(' --tls Specifies that TLS must be used.');
369 + console.log(' --uuidoutput Output with unique identifier as the filename.');
370 console.log(' --json Output as a JSON format.');
371 } else if (action == 'amtider') {
372 console.log('AmtIDER will mount a local disk images to a remote Intel AMT computer. Example usage:\r\n\r\n meshcmd amtider --host 1.2.3.4 --user admin --pass mypassword --tls --floppy disk.img --cdrom disk.iso');
@@ -665,9 +668,10 @@ function run(argv) {
668 } else { settings.hostname = '127.0.0.1'; }
669 readAmtAuditLog();
670 } else if (settings.action == 'amteventlog') { // Read the Intel AMT audit log
668 - if (settings.hostname == null) { settings.hostname = '127.0.0.1'; }
669 - if ((settings.password == null) || (typeof settings.password != 'string') || (settings.password == '')) { console.log('No or invalid \"password\" specified, use --password [password].'); exit(1); return; }
670 - if ((settings.username == null) || (typeof settings.username != 'string') || (settings.username == '')) { settings.username = 'admin'; }
671 + if (settings.hostname != null) {
672 + if ((settings.password == null) || (typeof settings.password != 'string') || (settings.password == '')) { console.log('No or invalid \"password\" specified, use --password [password].'); exit(1); return; }
673 + if ((settings.username == null) || (typeof settings.username != 'string') || (settings.username == '')) { settings.username = 'admin'; }
674 + } else { settings.hostname = '127.0.0.1'; }
675 readAmtEventLog();
676 } else if (settings.action == 'amtider') { // Remote mount IDER image
677 if ((settings.hostname == null) || (typeof settings.hostname != 'string') || (settings.hostname == '')) { console.log('No or invalid \"hostname\" specified, use --hostname [password].'); exit(1); return; }
@@ -838,15 +842,46 @@ function readAmtEventLogEx2(stack, messages) {
842 if (settings.json) {
843 out = JSON.stringify(messages, 4, ' ');
844 } else {
841 - for (var i in messages) { out += messages[i].Time + ', ' + messages[i].EntityStr + ', ' + messages[i].Desc + '\r\n'; }
845 + for (var i in messages) { out += messages[i].Time + ', ' + messages[i].EntityStr + ', ' + messages[i].Desc + ', ' + messages[i].EventSeverity + '\r\n'; }
846 }
843 - if (settings.output == null) { console.log(out); } else {
844 - var file = fs.openSync(settings.output, 'w');
845 - fs.writeSync(file, Buffer.from(out));
846 - fs.closeSync(file);
847 + if ((settings.output == null || settings.output == "") && !settings.uuidoutput) { console.log(out); exit(1); }
848 + else {
849 + try {
850 + if (settings.output) {
851 + var file = fs.openSync(settings.output, 'w');
852 + fs.writeSync(file, Buffer.from(out));
853 + fs.closeSync(file);
854 + exit(1);
855 + }
856 + else if (settings.uuidoutput) {
857 + var destpath = null; //Dest path where messagelog file will be saved
858 + if ((typeof settings.uuidoutput) == 'string') {
859 + fs.statSync(settings.uuidoutput).isDirectory();//Validate directory path
860 + destpath = settings.uuidoutput;
861 + }
862 + //Generate uuid and append it to dest path
863 + stack.Get('CIM_ComputerSystemPackage', function (obj, name, response, xstatus, tag) {
864 + if (xstatus == 200) {
865 + var eventlogsfile = path.join(destpath, guidToStr(response.Body.PlatformGUID.toLowerCase() + '_Event' + (settings.json ? '.json' : '.csv')));
866 + var file = fs.openSync(eventlogsfile, 'w');
867 + fs.writeSync(file, Buffer.from(out));
868 + fs.closeSync(file);
869 + } else {
870 + console.log('Intel AMT is not available or not activated, status = ' + status + '.');
871 + } exit(1);
872 + });
873 + }
874 + else{
875 + console.log('Invalid action, usage:\r\n\r\n meshcmd help amtauditlog');
876 + exit(1);
877 + }
878 + }
879 + catch (e) {
880 + console.log(e);
881 + exit(1);
882 + }
883 }
884 }
849 - exit(1);
885 }
886
887 //
@@ -888,13 +923,44 @@ function readAmtAuditLogEx2(stack, response, status) {
923 out += (response[i].Time + ' - ' + name + response[i].Event + '\r\n');
924 }
925 }
891 - if (settings.output == null) { console.log(out); } else {
892 - var file = fs.openSync(settings.output, 'w');
893 - fs.writeSync(file, Buffer.from(out));
894 - fs.closeSync(file);
926 + if ((settings.output == null || settings.output == "") && !settings.uuidoutput) { console.log(out); exit(1); }
927 + else {
928 + try {
929 + if (settings.output) {
930 + var file = fs.openSync(settings.output, 'w');
931 + fs.writeSync(file, Buffer.from(out));
932 + fs.closeSync(file);
933 + exit(1);
934 + }
935 + else if (settings.uuidoutput) {
936 + var destpath = null; //Dest path where auditlog file will be saved
937 + if ((typeof settings.uuidoutput) == 'string') {
938 + fs.statSync(settings.uuidoutput).isDirectory();//Validate directory path
939 + destpath = settings.uuidoutput;
940 + }
941 + //Generate uuid and append it to dest path
942 + stack.Get('CIM_ComputerSystemPackage', function (obj, name, response, xstatus, tag) {
943 + if (xstatus == 200) {
944 + var auditlogsfile = path.join(destpath, guidToStr(response.Body.PlatformGUID.toLowerCase() + '_Audit' + (settings.json ? '.json' : '.csv')));
945 + var file = fs.openSync(auditlogsfile, 'w');
946 + fs.writeSync(file, Buffer.from(out));
947 + fs.closeSync(file);
948 + } else {
949 + console.log('Intel AMT is not available or not activated, status = ' + status + '.');
950 + } exit(1);
951 + });
952 + }
953 + else{
954 + console.log('Invalid action, usage:\r\n\r\n meshcmd help amtauditlog');
955 + exit(1);
956 + }
957 + }
958 + catch (e) {
959 + console.log(e);
960 + exit(1);
961 + }
962 }
963 }
897 - exit(1);
964 }
965
966 //
agents/meshcmd.min.js
+80 -14
@@ -153,6 +153,7 @@ function run(argv) {
153 if ((typeof args.tag) == 'string') { settings.tag = args.tag; }
154 if ((typeof args.scan) == 'string') { settings.scan = args.scan; }
155 if ((typeof args.timeout) == 'string') { settings.timeout = parseInt(args.timeout); }
156 + if ((typeof args.uuidoutput) == 'string' || args.uuidoutput) { settings.uuidoutput = args.uuidoutput; }
157 if (args.debug === true) { settings.debuglevel = 1; }
158 if (args.debug) { try { waitForDebugger(); } catch (e) { } }
159 if (args.noconsole) { settings.noconsole = true; }
@@ -355,6 +356,7 @@ function run(argv) {
356 console.log(' --user [username] The Intel AMT login username, admin is default.');
357 console.log(' --pass [password] The Intel AMT login password.');
358 console.log(' --tls Specifies that TLS must be used.');
359 + console.log(' --uuidoutput Output with unique identifier as the filename.');
360 console.log(' --json Output as a JSON format.');
361 } else if (action == 'amtauditlog') {
362 console.log('AmtAuditLog action will fetch the local or remote audit log. If used localy, no username/password is required. Example usage:\r\n\r\n meshcmd amtauditlog --host 1.2.3.4 --user admin --pass mypassword --tls --output audit.json');
@@ -364,6 +366,7 @@ function run(argv) {
366 console.log(' --user [username] The Intel AMT login username, admin is default.');
367 console.log(' --pass [password] The Intel AMT login password.');
368 console.log(' --tls Specifies that TLS must be used.');
369 + console.log(' --uuidoutput Output with unique identifier as the filename.');
370 console.log(' --json Output as a JSON format.');
371 } else if (action == 'amtider') {
372 console.log('AmtIDER will mount a local disk images to a remote Intel AMT computer. Example usage:\r\n\r\n meshcmd amtider --host 1.2.3.4 --user admin --pass mypassword --tls --floppy disk.img --cdrom disk.iso');
@@ -665,9 +668,10 @@ function run(argv) {
668 } else { settings.hostname = '127.0.0.1'; }
669 readAmtAuditLog();
670 } else if (settings.action == 'amteventlog') { // Read the Intel AMT audit log
668 - if (settings.hostname == null) { settings.hostname = '127.0.0.1'; }
669 - if ((settings.password == null) || (typeof settings.password != 'string') || (settings.password == '')) { console.log('No or invalid \"password\" specified, use --password [password].'); exit(1); return; }
670 - if ((settings.username == null) || (typeof settings.username != 'string') || (settings.username == '')) { settings.username = 'admin'; }
671 + if (settings.hostname != null) {
672 + if ((settings.password == null) || (typeof settings.password != 'string') || (settings.password == '')) { console.log('No or invalid \"password\" specified, use --password [password].'); exit(1); return; }
673 + if ((settings.username == null) || (typeof settings.username != 'string') || (settings.username == '')) { settings.username = 'admin'; }
674 + } else { settings.hostname = '127.0.0.1'; }
675 readAmtEventLog();
676 } else if (settings.action == 'amtider') { // Remote mount IDER image
677 if ((settings.hostname == null) || (typeof settings.hostname != 'string') || (settings.hostname == '')) { console.log('No or invalid \"hostname\" specified, use --hostname [password].'); exit(1); return; }
@@ -838,15 +842,46 @@ function readAmtEventLogEx2(stack, messages) {
842 if (settings.json) {
843 out = JSON.stringify(messages, 4, ' ');
844 } else {
841 - for (var i in messages) { out += messages[i].Time + ', ' + messages[i].EntityStr + ', ' + messages[i].Desc + '\r\n'; }
845 + for (var i in messages) { out += messages[i].Time + ', ' + messages[i].EntityStr + ', ' + messages[i].Desc + ', ' + messages[i].EventSeverity + '\r\n'; }
846 }
843 - if (settings.output == null) { console.log(out); } else {
844 - var file = fs.openSync(settings.output, 'w');
845 - fs.writeSync(file, Buffer.from(out));
846 - fs.closeSync(file);
847 + if ((settings.output == null || settings.output == "") && !settings.uuidoutput) { console.log(out); exit(1); }
848 + else {
849 + try {
850 + if (settings.output) {
851 + var file = fs.openSync(settings.output, 'w');
852 + fs.writeSync(file, Buffer.from(out));
853 + fs.closeSync(file);
854 + exit(1);
855 + }
856 + else if (settings.uuidoutput) {
857 + var destpath = null; //Dest path where messagelog file will be saved
858 + if ((typeof settings.uuidoutput) == 'string') {
859 + fs.statSync(settings.uuidoutput).isDirectory();//Validate directory path
860 + destpath = settings.uuidoutput;
861 + }
862 + //Generate uuid and append it to dest path
863 + stack.Get('CIM_ComputerSystemPackage', function (obj, name, response, xstatus, tag) {
864 + if (xstatus == 200) {
865 + var eventlogsfile = path.join(destpath, guidToStr(response.Body.PlatformGUID.toLowerCase() + '_Event' + (settings.json ? '.json' : '.csv')));
866 + var file = fs.openSync(eventlogsfile, 'w');
867 + fs.writeSync(file, Buffer.from(out));
868 + fs.closeSync(file);
869 + } else {
870 + console.log('Intel AMT is not available or not activated, status = ' + status + '.');
871 + } exit(1);
872 + });
873 + }
874 + else{
875 + console.log('Invalid action, usage:\r\n\r\n meshcmd help amtauditlog');
876 + exit(1);
877 + }
878 + }
879 + catch (e) {
880 + console.log(e);
881 + exit(1);
882 + }
883 }
884 }
849 - exit(1);
885 }
886
887 //
@@ -888,13 +923,44 @@ function readAmtAuditLogEx2(stack, response, status) {
923 out += (response[i].Time + ' - ' + name + response[i].Event + '\r\n');
924 }
925 }
891 - if (settings.output == null) { console.log(out); } else {
892 - var file = fs.openSync(settings.output, 'w');
893 - fs.writeSync(file, Buffer.from(out));
894 - fs.closeSync(file);
926 + if ((settings.output == null || settings.output == "") && !settings.uuidoutput) { console.log(out); exit(1); }
927 + else {
928 + try {
929 + if (settings.output) {
930 + var file = fs.openSync(settings.output, 'w');
931 + fs.writeSync(file, Buffer.from(out));
932 + fs.closeSync(file);
933 + exit(1);
934 + }
935 + else if (settings.uuidoutput) {
936 + var destpath = null; //Dest path where auditlog file will be saved
937 + if ((typeof settings.uuidoutput) == 'string') {
938 + fs.statSync(settings.uuidoutput).isDirectory();//Validate directory path
939 + destpath = settings.uuidoutput;
940 + }
941 + //Generate uuid and append it to dest path
942 + stack.Get('CIM_ComputerSystemPackage', function (obj, name, response, xstatus, tag) {
943 + if (xstatus == 200) {
944 + var auditlogsfile = path.join(destpath, guidToStr(response.Body.PlatformGUID.toLowerCase() + '_Audit' + (settings.json ? '.json' : '.csv')));
945 + var file = fs.openSync(auditlogsfile, 'w');
946 + fs.writeSync(file, Buffer.from(out));
947 + fs.closeSync(file);
948 + } else {
949 + console.log('Intel AMT is not available or not activated, status = ' + status + '.');
950 + } exit(1);
951 + });
952 + }
953 + else{
954 + console.log('Invalid action, usage:\r\n\r\n meshcmd help amtauditlog');
955 + exit(1);
956 + }
957 + }
958 + catch (e) {
959 + console.log(e);
960 + exit(1);
961 + }
962 }
963 }
897 - exit(1);
964 }
965
966 //
package.json
+2 -2
@@ -1,6 +1,6 @@
1 {
2 "name": "meshcentral",
3 - "version": "0.4.2-u",
3 + "version": "0.4.2-x",
4 "keywords": [
5 "Remote Management",
6 "Intel AMT",
@@ -22,6 +22,7 @@
22 "views",
23 "agents",
24 "public",
25 + "translate",
26 "readme.txt",
27 "license.txt",
28 "sample-config.json"
@@ -37,7 +38,6 @@
38 "express-handlebars": "^3.1.0",
39 "express-ws": "^4.0.0",
40 "ipcheck": "^0.1.0",
40 - "jsdom": "^15.2.0",
41 "meshcentral": "*",
42 "minimist": "^1.2.0",
43 "multiparty": "^4.2.1",