1
0
mirror of https://github.com/Ylianst/MeshAgent synced 2026-01-12 05:23:17 +00:00

GC reference update

This commit is contained in:
Bryan Roe
2021-03-18 11:43:49 -07:00
parent 4f4085d542
commit 577a59ea8e
6 changed files with 82 additions and 52 deletions

File diff suppressed because one or more lines are too long

View File

@@ -22,6 +22,12 @@ function trimIdentifiers(val)
}
}
function stdparser(c)
{
if (this.str == null) { this.str = ''; }
this.str += c.toString();
}
function linux_identifiers()
{
var identifiers = {};
@@ -48,7 +54,7 @@ function linux_identifiers()
identifiers['product_uuid'] = ret['product_uuid'];
var child = require('child_process').execFile('/bin/sh', ['sh']);
child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
child.stdout.str = ''; child.stdout.on('data', stdparser);
child.stdin.write('cat /proc/cpuinfo | grep "model name" | ' + "tr '\\n' ':' | awk -F: '{ print $2 }'\nexit\n");
child.waitExit();
identifiers['cpu_name'] = child.stdout.str.trim();
@@ -56,14 +62,14 @@ function linux_identifiers()
// Fetch GPU info
var child = require('child_process').execFile('/bin/sh', ['sh']);
child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
child.stdout.str = ''; child.stdout.on('data', stdparser);
child.stdin.write("lspci | grep ' VGA ' | tr '\\n' '`' | awk '{ a=split($0,lines" + ',"`"); printf "["; for(i=1;i<a;++i) { split(lines[i],gpu,"r: "); printf "%s\\"%s\\"", (i==1?"":","),gpu[2]; } printf "]"; }\'\nexit\n');
child.waitExit();
try { identifiers['gpu_name'] = JSON.parse(child.stdout.str.trim()); } catch (xx) { }
// Fetch Storage Info
var child = require('child_process').execFile('/bin/sh', ['sh']);
child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
child.stdout.str = ''; child.stdout.on('data', stdparser);
child.stdin.write("lshw -class disk | tr '\\n' '`' | awk '" + '{ len=split($0,lines,"*"); printf "["; for(i=2;i<=len;++i) { model=""; caption=""; size=""; clen=split(lines[i],item,"`"); for(j=2;j<clen;++j) { split(item[j],tokens,":"); split(tokens[1],key," "); if(key[1]=="description") { caption=substr(tokens[2],2); } if(key[1]=="product") { model=substr(tokens[2],2); } if(key[1]=="size") { size=substr(tokens[2],2); } } if(model=="") { model=caption; } if(caption!="" || model!="") { printf "%s{\\"Caption\\":\\"%s\\",\\"Model\\":\\"%s\\",\\"Size\\":\\"%s\\"}",(i==2?"":","),caption,model,size; } } printf "]"; }\'\nexit\n');
child.waitExit();
try { identifiers['storage_devices'] = JSON.parse(child.stdout.str.trim()); } catch (xx) { }
@@ -171,7 +177,7 @@ function windows_identifiers()
{
var ret = { windows: {}}; values = {}; var items; var i; var item;
var child = require('child_process').execFile(process.env['windir'] + '\\System32\\wbem\\wmic.exe', ['wmic', 'bios', 'get', '/VALUE']);
child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
child.stdout.str = ''; child.stdout.on('data', stdparser);
child.waitExit();
var items = child.stdout.str.split('\r\r\n');
@@ -187,7 +193,7 @@ function windows_identifiers()
ret['identifiers']['bios_version'] = values['SMBIOSBIOSVersion'];
child = require('child_process').execFile(process.env['windir'] + '\\System32\\wbem\\wmic.exe', ['wmic', 'BASEBOARD', 'get', '/VALUE']);
child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
child.stdout.str = ''; child.stdout.on('data', stdparser);
child.waitExit();
var items = child.stdout.str.split('\r\r\n');
@@ -202,7 +208,7 @@ function windows_identifiers()
ret['identifiers']['board_version'] = values['Version'];
child = require('child_process').execFile(process.env['windir'] + '\\System32\\wbem\\wmic.exe', ['wmic', 'CSProduct', 'get', '/VALUE']);
child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
child.stdout.str = ''; child.stdout.on('data', stdparser);
child.waitExit();
var items = child.stdout.str.split('\r\r\n');
@@ -217,32 +223,32 @@ function windows_identifiers()
var CSV = '/FORMAT:"' + require('util-language').wmicXslPath + 'csv"';
child = require('child_process').execFile(process.env['windir'] + '\\System32\\wbem\\wmic.exe', ['wmic', 'MEMORYCHIP', 'LIST', CSV]);
child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
child.stdout.str = ''; child.stdout.on('data', stdparser);
child.waitExit();
ret.windows.memory = windows_wmic_results(child.stdout.str);
child = require('child_process').execFile(process.env['windir'] + '\\System32\\wbem\\wmic.exe', ['wmic', 'OS', 'GET', CSV]);
child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
child.stdout.str = ''; child.stdout.on('data', stdparser);
child.waitExit();
ret.windows.osinfo = windows_wmic_results(child.stdout.str)[0];
child = require('child_process').execFile(process.env['windir'] + '\\System32\\wbem\\wmic.exe', ['wmic', 'PARTITION', 'LIST', CSV]);
child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
child.stdout.str = ''; child.stdout.on('data', stdparser);
child.waitExit();
ret.windows.partitions = windows_wmic_results(child.stdout.str);
child = require('child_process').execFile(process.env['windir'] + '\\System32\\wbem\\wmic.exe', ['wmic', 'CPU', 'LIST', 'BRIEF', CSV]);
child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
child.stdout.str = ''; child.stdout.on('data', stdparser);
child.waitExit();
ret.windows.cpu = windows_wmic_results(child.stdout.str);
child = require('child_process').execFile(process.env['windir'] + '\\System32\\wbem\\wmic.exe', ['wmic', 'PATH', 'Win32_VideoController', 'GET', 'Name,CurrentHorizontalResolution,CurrentVerticalResolution', CSV]);
child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
child.stdout.str = ''; child.stdout.on('data', stdparser);
child.waitExit();
ret.windows.gpu = windows_wmic_results(child.stdout.str);
child = require('child_process').execFile(process.env['windir'] + '\\System32\\wbem\\wmic.exe', ['wmic', 'diskdrive', 'LIST', 'BRIEF', CSV]);
child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
child.stdout.str = ''; child.stdout.on('data', stdparser);
child.waitExit();
ret.windows.drives = windows_wmic_results(child.stdout.str);
@@ -261,6 +267,7 @@ function windows_identifiers()
}
try { ret.identifiers.cpu_name = ret.windows.cpu[0].Name; } catch (x) { }
child = null;
return (ret);
}
function macos_identifiers()
@@ -386,7 +393,7 @@ module.exports.isDocker = function isDocker()
if (process.platform != 'linux') { return (false); }
var child = require('child_process').execFile('/bin/sh', ['sh']);
child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
child.stdout.str = ''; child.stdout.on('data', stdparser);
child.stdin.write("cat /proc/self/cgroup | tr '\n' '`' | awk -F'`' '{ split($1, res, " + '"/"); if(res[2]=="docker"){print "1";} }\'\nexit\n');
child.waitExit();
return (child.stdout.str != '');

View File

@@ -16,6 +16,12 @@ limitations under the License.
var cpu_feature = {};
function stdparser(c)
{
if (this.str == null) { this.str = ''; }
this.str += c.toString();
}
/* Intel-defined CPU features, CPUID level 0x00000001 (EDX), word 0 */
cpu_feature.X86_FEATURE_FPU = ( 0*32+ 0); /* Onboard FPU */
cpu_feature.X86_FEATURE_VME = ( 0*32+ 1); /* Virtual Mode Extensions */
@@ -66,10 +72,10 @@ cpu_feature.X86_FEATURE_LONGRUN = ( 2*32+ 1); /* Longrun power control */
cpu_feature.X86_FEATURE_LRTI = (2 * 32 + 3); /* LongRun table interface */
/* Other features, Linux-defined mapping, word 3 */
cpu_Feature.X86_FEATURE_CXMMX = ( 3*32+ 0); /* Cyrix MMX extensions */
cpu_Feature.X86_FEATURE_K6_MTRR = ( 3*32+ 1); /* AMD K6 nonstandard MTRRs */
cpu_Feature.X86_FEATURE_CYRIX_ARR = ( 3*32+ 2); /* Cyrix ARRs (= MTRRs) */
cpu_Feature.X86_FEATURE_CENTAUR_MCR = (3 * 32 + 3); /* Centaur MCRs (= MTRRs) */
cpu_feature.X86_FEATURE_CXMMX = (3 * 32 + 0); /* Cyrix MMX extensions */
cpu_feature.X86_FEATURE_K6_MTRR = (3 * 32 + 1); /* AMD K6 nonstandard MTRRs */
cpu_feature.X86_FEATURE_CYRIX_ARR = (3 * 32 + 2); /* Cyrix ARRs (= MTRRs) */
cpu_feature.X86_FEATURE_CENTAUR_MCR = (3 * 32 + 3); /* Centaur MCRs (= MTRRs) */
cpu_feature.X86_FEATURE_K8 = ( 3*32+ 4); /* "" Opteron, Athlon64 */
cpu_feature.X86_FEATURE_K7 = ( 3*32+ 5); /* "" Athlon */
cpu_feature.X86_FEATURE_P3 = ( 3*32+ 6); /* "" P3 */
@@ -248,9 +254,9 @@ cpu_feature.X86_FEATURE_AVX512BW = ( 9*32+30); /* AVX-512 BW (Byte/Word granula
cpu_feature.X86_FEATURE_AVX512VL = (9 * 32 + 31); /* AVX-512 VL (128/256 Vector Length) Extensions */
var child = require('child_process').execFile('/bin/sh', ['sh']);
child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
child.stdout.str = ''; child.stdout.on('data', stdparser);
child.stdin.write("cat /proc/cpuinfo | grep flags | tr '\\n' '~' | awk -F~ '{ printf " + '"["; for(i=1;i<=NF-1;++i) { split($i, line, ":"); x=split(line[2], vals, " "); printf "%s{", (i!=1?",":""); for(j=1;j<=x;++j) { printf "%s\\"%s\\": 1", (j!=1?",":""), vals[j]; } printf "}"; } printf "]"; }\'\nexit\n');
child.stderr.on('data', function (c) { });
child.stderr.on('data', stdparser);
child.waitExit();
if (process.platform == 'linux')
@@ -273,3 +279,4 @@ else
module.exports = null;
}
child = null;

View File

@@ -14,11 +14,16 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
function stdparser(c)
{
if (this.str = null) { this.str = ''; }
this.str += c.toString();
}
function linux_getMountPoints()
{
var child = require('child_process').execFile('/bin/sh', ['sh']);
child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
child.stdout.str = ''; child.stdout.on('data', stdparser);
child.stdin.write("mount | tr '\\n' '`' | awk '");
child.stdin.write('{');
child.stdin.write(' printf "{";');
@@ -49,8 +54,8 @@ function linux_getMountPoints()
function gnome_getProxySettings(uid)
{
var child = require('child_process').execFile('/bin/sh', ['sh'], { env: { HOME: require('user-sessions').getHomeFolder(uid) }});
child.stderr.str = ''; child.stderr.on('data', function (c) { });
child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
child.stderr.str = ''; child.stderr.on('data', stdparser);
child.stdout.str = ''; child.stdout.on('data', stdparser);
child.stdin.write('gsettings list-recursively org.gnome.system.proxy | tr "\\n" "\\|" | awk \'');
child.stdin.write('{');
@@ -94,8 +99,8 @@ function gnome_getProxySettings(uid)
function gnome_getDesktopWallpaper(uid)
{
var child = require('child_process').execFile('/bin/sh', ['sh'], { env: { HOME: require('user-sessions').getHomeFolder(uid) } });
child.stderr.str = ''; child.stderr.on('data', function (c) { });
child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
child.stderr.str = ''; child.stderr.on('data', stdparser);
child.stdout.str = ''; child.stdout.on('data', stdparser);
child.stdin.write('gsettings get org.gnome.desktop.background picture-uri\nexit\n');
child.waitExit();
child.stdout.str = child.stdout.str.trim().split('file://').pop();
@@ -127,8 +132,8 @@ function gnome_setDesktopWallpaper(uid, filePath)
}
var child = require('child_process').execFile('/bin/sh', ['sh'], { uid: uid, env: v });
child.stderr.str = ''; child.stderr.on('data', function (c) { this.str += c.toString(); });
child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
child.stderr.str = ''; child.stderr.on('data', stdparser);
child.stdout.str = ''; child.stdout.on('data', stdparser);
child.stdin.write('gsettings set org.gnome.desktop.background picture-uri file://' + filePath + '\nexit\n');
child.waitExit();
}
@@ -148,7 +153,7 @@ switch(process.platform)
{
var child = require('child_process').execFile('/bin/sh', ['sh']);
child.stdout.str = '';
child.stdout.on('data', function (chunk) { this.str += chunk.toString(); });
child.stdout.on('data', stdparser);
child.stdin.write("whereis gsettings | awk '{ print $2 }'\nexit\n");
child.waitExit();
return (child.stdout.str.trim());
@@ -163,8 +168,8 @@ switch(process.platform)
if(require('fs').existsSync('/usr/bin/script'))
{
var child = require('child_process').execFile('/bin/sh', ['sh']);
child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
child.stderr.on('data', function () { });
child.stdout.str = ''; child.stdout.on('data', stdparser);
child.stderr.on('data', stdparser);
child.stdin.write('script -V | awk \'{ split($NF, T, "."); printf "{\\"major\\":%s, \\"minor\\":%s}",T[1],T[2]; }\'\nexit\n');
child.waitExit();
try

View File

@@ -22,6 +22,12 @@ var TH32CS_SNAPMODULE = 0x08;
var PROCESS_QUERY_LIMITED_INFORMATION = 0x1000;
function stdparser(c)
{
if (this.str == null) { this.str = ''; }
this.str += c.toString();
}
// Used on Windows and Linux to get information about running processes
function processManager() {
this._ObjectID = 'process-manager'; // Used for debugging, allows you to get the object type at runtime.
@@ -113,8 +119,8 @@ function processManager() {
var fallback = false;
var users = require('fs').existsSync('/etc/login.defs') ? 'user:99' : 'user';
var p = require('child_process').execFile('/bin/sh', ['sh']);
p.stdout.str = ''; p.stdout.on('data', function (c) { this.str += c.toString(); });
p.stderr.str = ''; p.stderr.on('data', function (c) { this.str += c.toString(); });
p.stdout.str = ''; p.stdout.on('data', stdparser);
p.stderr.str = ''; p.stderr.on('data', stdparser);
p.stdin.write('ps -e -o pid -o ' + users + ' -o args | tr ' + "'\\n' '\\t' | awk -F" + '"\\t" \'');
p.stdin.write('{');
p.stdin.write(' printf "{"; ');
@@ -136,8 +142,8 @@ function processManager() {
{
fallback = true;
var p = require('child_process').execFile('/bin/sh', ['sh']);
p.stdout.str = ''; p.stdout.on('data', function (c) { this.str += c.toString(); });
p.stderr.str = ''; p.stderr.on('data', function (c) { this.str += c.toString(); });
p.stdout.str = ''; p.stdout.on('data', stdparser);
p.stderr.str = ''; p.stderr.on('data', stdparser);
p.stdin.write("ps | tr '\\n' '`' | awk -F'`' '");
p.stdin.write('{');
p.stdin.write(' len=split($1,A," "); X=index($1,A[len]);');
@@ -192,8 +198,8 @@ function processManager() {
case 'darwin':
case 'freebsd':
var p = require('child_process').execFile('/bin/sh', ['sh']);
p.stdout.str = ''; p.stdout.on('data', function (c) { this.str += c.toString(); });
p.stderr.str = ''; p.stderr.on('data', function (c) { this.str += c.toString(); });
p.stdout.str = ''; p.stdout.on('data', stdparser);
p.stderr.str = ''; p.stderr.on('data', stdparser);
p.stdin.write('ps -axo pid -o user -o command | tr ' + "'\\n' '\\t' | awk -F" + '"\\t" \'{ printf "{"; for(i=2;i<NF;++i) { gsub(/^[ ]+/,"",$i); split($i,tok," "); pid=tok[1]; user=tok[2]; cmd=substr($i,length(tok[1])+length(tok[2])+2); gsub(/\\\\/,"\\\\\\\\&",cmd); gsub(/"/,"\\\\\\\\&",cmd); gsub(/^[ ]+/,"",cmd); printf "%s\\"%s\\":{\\"pid\\":\\"%s\\",\\"user\\":\\"%s\\",\\"cmd\\":\\"%s\\"}",(i!=2?",":""),pid,pid,user,cmd; } printf "}"; }\'\nexit\n');
p.waitExit();
@@ -258,7 +264,7 @@ function processManager() {
{
var child = require('child_process').execFile('/bin/sh', ['sh']);
child.stdout.str = '';
child.stdout.on('data', function (chunk) { this.str += chunk.toString(); });
child.stdout.on('data', stdparser);
child.stdin.write("whereis pgrep | awk '{ print $2 }'\nexit\n");
child.waitExit();
return (child.stdout.str.trim());
@@ -270,8 +276,8 @@ function processManager() {
this.getProcess = function getProcess(cmd)
{
var child = require('child_process').execFile('/bin/sh', ['sh']);
child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
child.stderr.str = ''; child.stderr.on('data', function (c) { this.str += c.toString(); });
child.stdout.str = ''; child.stdout.on('data', stdparser);
child.stderr.str = ''; child.stderr.on('data', stdparser);
child.stdin.write("pgrep gnome-session | tr '\\n' '\\t' |" + ' awk -F"\\t" \'{ printf "["; for(i=1;i<NF;++i) { if(i>1) { printf ","; } printf "%d", $i; } printf "]"; }\'');
child.stdin.write('\nexit\n');
child.waitExit();
@@ -285,8 +291,8 @@ function processManager() {
this.getProcessEx = function getProcessEx(cmd)
{
var child = require('child_process').execFile('/bin/sh', ['sh']);
child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
child.stderr.str = ''; child.stderr.on('data', function (c) { this.str += c.toString(); });
child.stdout.str = ''; child.stdout.on('data', stdparser);
child.stderr.str = ''; child.stderr.on('data', stdparser);
child.stdin.write('ps -ax -o pid -o command | grep ' + cmd + " | tr '\\n' '\\t' | awk -F" + '"\\t" \'{ printf "["; for(i=1;i<NF;++i) { split($i,r," "); if(r[2]!="grep") { if(i>1) { printf ","; } printf "%s", r[1]; } } printf "]"; }\'');
child.stdin.write('\nexit\n');
child.waitExit();

View File

@@ -14,6 +14,11 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
function stdparser(c)
{
if (this.str == null) { this.str = ''; }
this.str += c.toString();
}
function toLang(val)
{
@@ -964,8 +969,8 @@ function getCurrent()
if(process.platform == 'win32')
{
var child = require('child_process').execFile(process.env['windir'] + '\\system32\\wbem\\wmic.exe', ['wmic', 'os', 'get', 'oslanguage','/FORMAT:LIST']);
child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
child.stderr.str = ''; child.stderr.on('data', function (c) { this.str += c.toString(); });
child.stdout.str = ''; child.stdout.on('data', stdparser);
child.stderr.str = ''; child.stderr.on('data', stdparser);
child.waitExit();
var lines = child.stdout.str.trim().split('\r\n');
@@ -990,8 +995,8 @@ function getCurrent()
if (process.platform == 'darwin')
{
var child = require('child_process').execFile('/bin/sh', ['sh']);
child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
child.stderr.str = ''; child.stderr.on('data', function (c) { this.str += c.toString(); });
child.stdout.str = ''; child.stdout.on('data', stdparser);
child.stderr.str = ''; child.stderr.on('data', stdparser);
child.stdin.write("osascript -e 'user locale of (get system info)'\nexit\n");
child.waitExit();
return (child.stdout.str.trim());
@@ -1002,8 +1007,8 @@ function getCurrent()
{
var uid = require('user-sessions').gdmUid;
var child = require('child_process').execFile('/bin/sh', ['sh']);
child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
child.stderr.str = ''; child.stderr.on('data', function (c) { this.str += c.toString(); });
child.stdout.str = ''; child.stdout.on('data', stdparser);
child.stderr.str = ''; child.stderr.on('data', stdparser);
child.stdin.write('ps -e -o pid -o uid | grep ' + uid + ' | awk ' + "'{ print $1; }'\nexit\n");
child.waitExit();
var pid = parseInt(child.stdout.str.trim());