pinokiod 3.10.4 → 3.10.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/kernel/procs.js +33 -9
  2. package/package.json +1 -1
package/kernel/procs.js CHANGED
@@ -1,32 +1,46 @@
1
1
  const os = require('os')
2
2
  const path = require('path')
3
+ const axios = require('axios')
3
4
  const { fork, exec } = require('child_process');
4
5
  const platform = os.platform();
5
6
  class Procs {
6
7
  constructor () {
7
8
  console.log("Initializing procs")
8
9
  }
10
+ async isHttp(localAddress) {
11
+ try {
12
+ await axios.head(`http://${localAddress}`, { timeout: 1000 });
13
+ return true;
14
+ } catch (err) {
15
+ return false;
16
+ }
17
+ }
9
18
  getPortPidList(callback) {
10
19
  const isWin = platform === 'win32';
11
20
  const cmd = isWin ? 'netstat -ano -p tcp' : 'lsof -nP -iTCP -sTCP:LISTEN';
12
- exec(cmd, (err, stdout) => {
21
+ exec(cmd, async (err, stdout) => {
13
22
  if (err) return callback(err);
14
23
 
15
24
  const results = [];
16
25
  let pids = new Set()
17
26
  let s = stdout.trim()
18
- cosnole.log(">>>>>>>>>>", s)
27
+ console.log(">>>>>>>>>>", s)
19
28
  const lines = s.split('\n');
20
29
 
21
- lines.forEach(line => {
30
+ console.log("LINES", lines)
31
+ for(let line of lines) {
22
32
  console.log({ line, isWin })
23
33
  if (isWin) {
24
34
  // Skip headers
25
- if (!line.startsWith(' TCP')) return;
35
+ if (!line.startsWith(' TCP')) continue;
26
36
  const parts = line.trim().split(/\s+/);
27
37
  const [ , localAddress, , state, pid ] = parts;
28
38
  console.log({ parts, localAddress, state, pid })
29
- if (state !== 'LISTENING') return;
39
+
40
+ //if (state !== 'LISTENING') return;
41
+ let isHttp = await this.isHttp(localAddress)
42
+ console.log({ localAddress, isHttp })
43
+ if (!isHttp) continue
30
44
  const chunks = localAddress.split(":")
31
45
  console.log({ chunks })
32
46
  const port = chunks.pop()
@@ -37,16 +51,23 @@ class Procs {
37
51
  ip = localAddress
38
52
  }
39
53
  console.log({ port, ip })
40
- if (pids.has(pid+"/"+port)) return;
54
+ if (pids.has(pid+"/"+port)) continue;
41
55
  pids.add(pid+"/"+port)
42
56
  results.push({ port, pid, ip });
43
57
  } else {
44
- if (!/LISTEN/.test(line)) return;
58
+ //if (!/LISTEN/.test(line)) return;
45
59
  const parts = line.trim().split(/\s+/);
46
60
  const pid = parts[1];
61
+ console.log({ parts, pid })
47
62
 
48
63
  const match = line.match(/([^\s]+:\d+)\s/);
64
+ console.log({ line, match })
49
65
  const localAddress = match?.[1];
66
+
67
+ let isHttp = await this.isHttp(localAddress)
68
+ console.log({ localAddress, isHttp })
69
+ if (!isHttp) continue;
70
+
50
71
  const chunks = localAddress.split(":")
51
72
  const port = chunks.pop()
52
73
  let ip = chunks.pop()
@@ -57,11 +78,12 @@ class Procs {
57
78
  }
58
79
  //const portMatch = line.match(/:(\d+)\s/);
59
80
  //const port = portMatch?.[1];
60
- if (pids.has(pid+"/"+port)) return;
81
+ if (pids.has(pid+"/"+port)) continue;
61
82
  pids.add(pid+"/"+port)
62
83
  if (pid && port) results.push({ port, pid, ip });
63
84
  }
64
- });
85
+ }
86
+ console.log("CALL")
65
87
 
66
88
  callback(null, results);
67
89
  });
@@ -88,8 +110,10 @@ class Procs {
88
110
  async refresh() {
89
111
  let map = {}
90
112
  let list = await new Promise((resolve, reject) => {
113
+ console.time("getPortPidList")
91
114
  this.getPortPidList((err, portPidList) => {
92
115
  console.log({ portPidList })
116
+ console.timeEnd("getPortPidList")
93
117
  if (err) {
94
118
  console.log("getPortPidList Error", err)
95
119
  reject(err)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pinokiod",
3
- "version": "3.10.4",
3
+ "version": "3.10.6",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {