pinokiod 3.10.5 → 3.10.7
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.
- package/kernel/index.js +0 -4
- package/kernel/procs.js +24 -16
- package/package.json +1 -1
package/kernel/index.js
CHANGED
|
@@ -263,7 +263,6 @@ class Kernel {
|
|
|
263
263
|
this.log_queue.push({ data, group, info })
|
|
264
264
|
}
|
|
265
265
|
async refresh(notify_peers) {
|
|
266
|
-
console.log("kernel.refresh", { notify_peers })
|
|
267
266
|
let env = await Environment.get(this.homedir)
|
|
268
267
|
let peer_active = false
|
|
269
268
|
// if PINOKIO_NETWORK_SHARE is 0 or false, turn it off
|
|
@@ -274,13 +273,10 @@ class Kernel {
|
|
|
274
273
|
if (env && env.PINOKIO_HTTPS_ACTIVE && (env.PINOKIO_HTTPS_ACTIVE==="1" || env.PINOKIO_HTTPS_ACTIVE.toLowerCase()==="true")) {
|
|
275
274
|
https_active = true
|
|
276
275
|
}
|
|
277
|
-
console.log({ https_active, peer_active })
|
|
278
276
|
// console.log("kernel.refresh", { active, notify_peers })
|
|
279
277
|
|
|
280
278
|
let caddy_installed = await this.bin.check_installed({ name: "caddy" })
|
|
281
279
|
|
|
282
|
-
console.log({ caddy_installed, https_active })
|
|
283
|
-
|
|
284
280
|
// 1. https
|
|
285
281
|
// 2. https + local share
|
|
286
282
|
// console.log("caddy installed?", caddy_installed)
|
package/kernel/procs.js
CHANGED
|
@@ -1,34 +1,42 @@
|
|
|
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
|
-
console.log(">>>>>>>>>>", s)
|
|
19
27
|
const lines = s.split('\n');
|
|
20
28
|
|
|
21
|
-
|
|
22
|
-
console.log({ line, isWin })
|
|
29
|
+
for(let line of lines) {
|
|
23
30
|
if (isWin) {
|
|
24
31
|
// Skip headers
|
|
25
|
-
if (!line.startsWith(' TCP'))
|
|
32
|
+
if (!line.startsWith(' TCP')) continue;
|
|
26
33
|
const parts = line.trim().split(/\s+/);
|
|
27
34
|
const [ , localAddress, , state, pid ] = parts;
|
|
28
|
-
|
|
29
|
-
if (state !== 'LISTENING') return;
|
|
35
|
+
|
|
36
|
+
//if (state !== 'LISTENING') return;
|
|
37
|
+
let isHttp = await this.isHttp(localAddress)
|
|
38
|
+
if (!isHttp) continue
|
|
30
39
|
const chunks = localAddress.split(":")
|
|
31
|
-
console.log({ chunks })
|
|
32
40
|
const port = chunks.pop()
|
|
33
41
|
let ip = chunks.pop()
|
|
34
42
|
if (!ip || ip === "*") {
|
|
@@ -36,17 +44,20 @@ class Procs {
|
|
|
36
44
|
} else {
|
|
37
45
|
ip = localAddress
|
|
38
46
|
}
|
|
39
|
-
|
|
40
|
-
if (pids.has(pid+"/"+port)) return;
|
|
47
|
+
if (pids.has(pid+"/"+port)) continue;
|
|
41
48
|
pids.add(pid+"/"+port)
|
|
42
49
|
results.push({ port, pid, ip });
|
|
43
50
|
} else {
|
|
44
|
-
if (!/LISTEN/.test(line)) return;
|
|
51
|
+
//if (!/LISTEN/.test(line)) return;
|
|
45
52
|
const parts = line.trim().split(/\s+/);
|
|
46
53
|
const pid = parts[1];
|
|
47
54
|
|
|
48
55
|
const match = line.match(/([^\s]+:\d+)\s/);
|
|
49
56
|
const localAddress = match?.[1];
|
|
57
|
+
|
|
58
|
+
let isHttp = await this.isHttp(localAddress)
|
|
59
|
+
if (!isHttp) continue;
|
|
60
|
+
|
|
50
61
|
const chunks = localAddress.split(":")
|
|
51
62
|
const port = chunks.pop()
|
|
52
63
|
let ip = chunks.pop()
|
|
@@ -57,12 +68,11 @@ class Procs {
|
|
|
57
68
|
}
|
|
58
69
|
//const portMatch = line.match(/:(\d+)\s/);
|
|
59
70
|
//const port = portMatch?.[1];
|
|
60
|
-
if (pids.has(pid+"/"+port))
|
|
71
|
+
if (pids.has(pid+"/"+port)) continue;
|
|
61
72
|
pids.add(pid+"/"+port)
|
|
62
73
|
if (pid && port) results.push({ port, pid, ip });
|
|
63
74
|
}
|
|
64
|
-
}
|
|
65
|
-
|
|
75
|
+
}
|
|
66
76
|
callback(null, results);
|
|
67
77
|
});
|
|
68
78
|
}
|
|
@@ -89,7 +99,6 @@ class Procs {
|
|
|
89
99
|
let map = {}
|
|
90
100
|
let list = await new Promise((resolve, reject) => {
|
|
91
101
|
this.getPortPidList((err, portPidList) => {
|
|
92
|
-
console.log({ portPidList })
|
|
93
102
|
if (err) {
|
|
94
103
|
console.log("getPortPidList Error", err)
|
|
95
104
|
reject(err)
|
|
@@ -114,7 +123,6 @@ class Procs {
|
|
|
114
123
|
return { port, pid , name, fullname, ip }
|
|
115
124
|
}
|
|
116
125
|
}).filter((x) => { return x })
|
|
117
|
-
console.log({ list })
|
|
118
126
|
resolve(list)
|
|
119
127
|
});
|
|
120
128
|
});
|