Skip to content

Commit

Permalink
fix: package is signed as high severity vulnerability from npm
Browse files Browse the repository at this point in the history
  • Loading branch information
SunilWang committed Oct 25, 2019
1 parent 6035043 commit e0b6090
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 32 deletions.
2 changes: 2 additions & 0 deletions index.js
Expand Up @@ -15,3 +15,5 @@ require('./lib/proc')
require('./lib/users')

module.exports = require('./lib/bucket')

console.dir(module.exports)
17 changes: 0 additions & 17 deletions lib/bucket.js
Expand Up @@ -3,26 +3,9 @@
* createTime : 2017/7/9 19:24
* description :
*/
var cp = require('child_process')

module.exports = {
options: {
NOT_SUPPORTED_VALUE: 'not supported',
INTERVAL: 1000
},
exec: function (command) {
var self = this

return function () {
return new Promise(function (resolve) {
cp.exec(command, { shell: true }, function (err, stdout, stderr) {
if (err || !stdout) {
return resolve(self.options.NOT_SUPPORTED_VALUE)
}

return resolve(stdout)
})
})
}
}
}
4 changes: 2 additions & 2 deletions lib/drive.js
Expand Up @@ -4,6 +4,7 @@
* description :
*/
var bucket = require('./bucket')
var exec = require('./exec')
var DISK_PATTERN = /^(\S+)\n?\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(.+?)\n/mg

function createDiskInfo (headlineArgs, args) {
Expand Down Expand Up @@ -39,7 +40,7 @@ bucket.drive = {
diskName = '/'
}

return bucket.exec('df -kP')().then(function (out) {
return exec('df -kP')().then(function (out) {
var diskInfo = null
var main = null
var lines = parseDfStdout(out)
Expand Down Expand Up @@ -110,4 +111,3 @@ bucket.drive = {
})
}
}

21 changes: 21 additions & 0 deletions lib/exec.js
@@ -0,0 +1,21 @@
/**
* author : Sunil Wang
* createTime : 2019/10/25 10:36
* description :
*/
var cp = require('child_process')
var bucket = require('./bucket')

module.exports = function (command) {
return function () {
return new Promise(function (resolve) {
cp.exec(command, { shell: true }, function (err, stdout, stderr) {
if (err || !stdout) {
return resolve(bucket.options.NOT_SUPPORTED_VALUE)
}

return resolve(stdout)
})
})
}
}
5 changes: 3 additions & 2 deletions lib/mem.js
Expand Up @@ -4,14 +4,15 @@
* description :
*/
var bucket = require('./bucket')
var exec = require('./exec')
var cp = require('child_process')
var os = require('os')
var co = require('../util/co')

var darwinMem = {
PAGE_SIZE: 4096,
physicalMemory: co.wrap(function * () {
var res = yield (bucket.exec('sysctl hw.memsize')())
var res = yield (exec('sysctl hw.memsize')())
res = res.trim().split(' ')[1]
return parseInt(res)
}),
Expand All @@ -25,7 +26,7 @@ var darwinMem = {
}

var ret = {}
var res = yield (bucket.exec('vm_stat')())
var res = yield (exec('vm_stat')())
var lines = res.split('\n')

lines = lines.filter(x => x !== '')
Expand Down
19 changes: 10 additions & 9 deletions lib/osCmd.js
Expand Up @@ -4,15 +4,16 @@
* description :
*/
var bucket = require('./bucket')
var exec = require('./exec')

bucket.osCmd = {
topCpu: bucket.exec('ps -eo pcpu,user,args --no-headers | sort -k 1 -n | tail -n 10 | sort -k 1 -nr | cut -c 1-70'),
topMem: bucket.exec('ps -eo pmem,pid,cmd | sort -k 1 -n | tail -n 10 | sort -k 1 -nr | cut -c 1-70'),
vmstats: bucket.exec('vmstat -S m'),
processesUsers: bucket.exec('ps hax -o user | sort | uniq -c'),
diskUsage: bucket.exec('df -h'),
who: bucket.exec('who'),
whoami: bucket.exec('whoami'),
openPorts: bucket.exec('lsof -Pni4 | grep ESTABLISHED'),
ifconfig: bucket.exec('ifconfig')
topCpu: exec('ps -eo pcpu,user,args --no-headers | sort -k 1 -n | tail -n 10 | sort -k 1 -nr | cut -c 1-70'),
topMem: exec('ps -eo pmem,pid,cmd | sort -k 1 -n | tail -n 10 | sort -k 1 -nr | cut -c 1-70'),
vmstats: exec('vmstat -S m'),
processesUsers: exec('ps hax -o user | sort | uniq -c'),
diskUsage: exec('df -h'),
who: exec('who'),
whoami: exec('whoami'),
openPorts: exec('lsof -Pni4 | grep ESTABLISHED'),
ifconfig: exec('ifconfig')
}
3 changes: 2 additions & 1 deletion lib/proc.js
Expand Up @@ -4,6 +4,7 @@
* description :
*/
var bucket = require('./bucket')
var exec = require('./exec')
var cp = require('child_process')
var os = require('os')
var co = require('../util/co')
Expand All @@ -16,7 +17,7 @@ bucket.proc = {
co.wrap(function * (err, out, stderr) {
if (err || !out) {
if (os.platform() === 'darwin') {
var nb = yield (bucket.exec('ps -A')())
var nb = yield (exec('ps -A')())

nb = nb.toString().split('\n')

Expand Down
3 changes: 2 additions & 1 deletion lib/users.js
Expand Up @@ -4,10 +4,11 @@
* description :
*/
var bucket = require('./bucket')
var exec = require('./exec')

bucket.users = {
openedCount: function () {
return bucket.exec('who | grep -v localhost | wc -l')()
return exec('who | grep -v localhost | wc -l')()
.then(function (count) {
return Promise.resolve(parseInt(count, 10))
})
Expand Down

0 comments on commit e0b6090

Please sign in to comment.