pinokiod 3.8.35 → 3.8.36
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/caddy.js +20 -6
- package/kernel/peer.js +15 -3
- package/package.json +1 -1
- package/server/index.js +17 -1
- package/server/views/proxy.ejs +6 -3
package/kernel/caddy.js
CHANGED
|
@@ -136,7 +136,7 @@ class Caddy {
|
|
|
136
136
|
// create a proxy proxy
|
|
137
137
|
// - get next available port and expose
|
|
138
138
|
payload.apps.http.servers[":" + INTERNAL_PORT] = {
|
|
139
|
-
"listen": [":PORT_PLACEHOLDER_" + INTERNAL_PORT],
|
|
139
|
+
"listen": [":PORT_PLACEHOLDER_" + ip + ":" + INTERNAL_PORT],
|
|
140
140
|
"routes": [{
|
|
141
141
|
"handle": [
|
|
142
142
|
{
|
|
@@ -172,7 +172,7 @@ class Caddy {
|
|
|
172
172
|
"handle": [
|
|
173
173
|
{
|
|
174
174
|
"handler": "reverse_proxy",
|
|
175
|
-
"upstreams": [{ "dial": ip + ":PORT_PLACEHOLDER_" + INTERNAL_PORT }]
|
|
175
|
+
"upstreams": [{ "dial": ip + ":PORT_PLACEHOLDER_" + ip + ":" + INTERNAL_PORT }]
|
|
176
176
|
},
|
|
177
177
|
{
|
|
178
178
|
"handler": "headers",
|
|
@@ -200,7 +200,7 @@ class Caddy {
|
|
|
200
200
|
"handle": [
|
|
201
201
|
{
|
|
202
202
|
"handler": "reverse_proxy",
|
|
203
|
-
"upstreams": [{ "dial": ip + ":PORT_PLACEHOLDER_" + INTERNAL_PORT }]
|
|
203
|
+
"upstreams": [{ "dial": ip + ":PORT_PLACEHOLDER_" + ip + ":" + INTERNAL_PORT }]
|
|
204
204
|
},
|
|
205
205
|
{
|
|
206
206
|
"handler": "headers",
|
|
@@ -327,7 +327,7 @@ class Caddy {
|
|
|
327
327
|
this.ip_mapping[INTERNAL_PORT] = ip
|
|
328
328
|
|
|
329
329
|
payload.apps.http.servers[":" + INTERNAL_PORT] = {
|
|
330
|
-
"listen": [":PORT_PLACEHOLDER_" + INTERNAL_PORT],
|
|
330
|
+
"listen": [":PORT_PLACEHOLDER_" + ip + ":" + INTERNAL_PORT],
|
|
331
331
|
"routes": [{
|
|
332
332
|
"handle": [
|
|
333
333
|
{
|
|
@@ -381,7 +381,7 @@ class Caddy {
|
|
|
381
381
|
"handle": [
|
|
382
382
|
{
|
|
383
383
|
"handler": "reverse_proxy",
|
|
384
|
-
"upstreams": [{ "dial": ip + ":PORT_PLACEHOLDER_" + INTERNAL_PORT }]
|
|
384
|
+
"upstreams": [{ "dial": ip + ":PORT_PLACEHOLDER_" + ip + ":" + INTERNAL_PORT }]
|
|
385
385
|
},
|
|
386
386
|
{
|
|
387
387
|
"handler": "headers",
|
|
@@ -458,6 +458,7 @@ class Caddy {
|
|
|
458
458
|
this._mapping = {}
|
|
459
459
|
this.ip_mapping = {}
|
|
460
460
|
this.port_mapping = {} // 127.0.0.1 => 192.168,..
|
|
461
|
+
this.local_network_mapping = {}
|
|
461
462
|
|
|
462
463
|
// localhost home
|
|
463
464
|
let payload = this.home()
|
|
@@ -487,7 +488,20 @@ class Caddy {
|
|
|
487
488
|
payload = response.result
|
|
488
489
|
let replaced_map = response.replaced_map
|
|
489
490
|
for(let key in replaced_map) {
|
|
490
|
-
|
|
491
|
+
// local_share_ip :- 192.168....
|
|
492
|
+
let local_share_key = key.replace("PORT_PLACEHOLDER_", "")
|
|
493
|
+
let chunks = local_share_key.split(":")
|
|
494
|
+
let local_share_ip = chunks[0]
|
|
495
|
+
let original_port = chunks[1]
|
|
496
|
+
let local_share_port = replaced_map[key]
|
|
497
|
+
console.log({ local_share_ip, local_share_port })
|
|
498
|
+
if (!this.local_network_mapping[local_share_ip]) {
|
|
499
|
+
this.local_network_mapping[local_share_ip] = {}
|
|
500
|
+
}
|
|
501
|
+
this.local_network_mapping[local_share_ip][original_port] = local_share_port
|
|
502
|
+
|
|
503
|
+
|
|
504
|
+
//let original_port = key.replace("PORT_PLACEHOLDER_", "")
|
|
491
505
|
this.port_mapping[original_port] = replaced_map[key]
|
|
492
506
|
}
|
|
493
507
|
}
|
package/kernel/peer.js
CHANGED
|
@@ -9,6 +9,7 @@ class PeerDiscovery {
|
|
|
9
9
|
this.socket = dgram.createSocket('udp4');
|
|
10
10
|
this.peers = new Set();
|
|
11
11
|
this.current_account = os.userInfo()
|
|
12
|
+
this.current_ip = this._getLocalIPAddress()
|
|
12
13
|
// this.start();
|
|
13
14
|
}
|
|
14
15
|
account(ip) {
|
|
@@ -18,7 +19,7 @@ class PeerDiscovery {
|
|
|
18
19
|
return this.data[ip].homedir
|
|
19
20
|
}
|
|
20
21
|
caddy(ip) {
|
|
21
|
-
return this.data[ip].
|
|
22
|
+
return this.data[ip].proxy
|
|
22
23
|
}
|
|
23
24
|
local(ip) {
|
|
24
25
|
return this.data[ip].memory.local
|
|
@@ -33,12 +34,12 @@ class PeerDiscovery {
|
|
|
33
34
|
const ip = rinfo.address;
|
|
34
35
|
if (msg.toString() === this.message.toString() && this._isLocalLAN(ip)) {
|
|
35
36
|
if (!this.peers.has(ip)) {
|
|
37
|
+
console.log(`Discovered peer: ${ip}`);
|
|
36
38
|
this.peers.add(ip);
|
|
37
39
|
let interval = setInterval(() => {
|
|
38
40
|
axios.get(`http://${ip}:42000/pinokio/mem`).then((res) => {
|
|
39
41
|
this.data[ip] = res.data
|
|
40
|
-
if (res.data.
|
|
41
|
-
console.log(`Discovered peer: ${ip}`);
|
|
42
|
+
if (res.data.proxy) {
|
|
42
43
|
// clearInterval(interval)
|
|
43
44
|
}
|
|
44
45
|
})
|
|
@@ -65,6 +66,17 @@ class PeerDiscovery {
|
|
|
65
66
|
_isLocalLAN(ip) {
|
|
66
67
|
return ip.startsWith('192.168.');
|
|
67
68
|
}
|
|
69
|
+
_getLocalIPAddress() {
|
|
70
|
+
const interfaces = os.networkInterfaces();
|
|
71
|
+
for (const ifaceList of Object.values(interfaces)) {
|
|
72
|
+
for (const iface of ifaceList) {
|
|
73
|
+
if (iface.family === 'IPv4' && !iface.internal && iface.address.startsWith('192.168.')) {
|
|
74
|
+
return iface.address;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
68
80
|
}
|
|
69
81
|
|
|
70
82
|
module.exports = PeerDiscovery;
|
package/package.json
CHANGED
package/server/index.js
CHANGED
|
@@ -2670,6 +2670,17 @@ class Server {
|
|
|
2670
2670
|
console.log("list", list)
|
|
2671
2671
|
|
|
2672
2672
|
let peers = this.kernel.peer.get()
|
|
2673
|
+
peers = peers.map((x) => {
|
|
2674
|
+
let account = this.kernel.peer.account(x)
|
|
2675
|
+
let domain = `https://pinokio.${account}.localhost`
|
|
2676
|
+
let proxy_page = `https://pinokio.${account}.localhost/proxy`
|
|
2677
|
+
return {
|
|
2678
|
+
ip: x,
|
|
2679
|
+
account,
|
|
2680
|
+
domain,
|
|
2681
|
+
proxy_page
|
|
2682
|
+
}
|
|
2683
|
+
})
|
|
2673
2684
|
|
|
2674
2685
|
let live_proxies = this.kernel.api.proxies["/proxy"]
|
|
2675
2686
|
if (!live_proxies) live_proxies = []
|
|
@@ -2742,10 +2753,12 @@ class Server {
|
|
|
2742
2753
|
|
|
2743
2754
|
console.log({ port_mapping: this.kernel.caddy.port_mapping, ip_mapping: this.kernel.caddy.ip_mapping })
|
|
2744
2755
|
res.render("proxy", {
|
|
2756
|
+
ip: this.kernel.peer.current_ip,
|
|
2745
2757
|
peers,
|
|
2746
2758
|
list,
|
|
2747
2759
|
port_mapping: this.kernel.caddy.port_mapping,
|
|
2748
2760
|
ip_mapping: this.kernel.caddy.ip_mapping,
|
|
2761
|
+
lan: this.kernel.caddy.local_network_mapping,
|
|
2749
2762
|
agent: this.agent,
|
|
2750
2763
|
theme: this.theme,
|
|
2751
2764
|
items: proxies,
|
|
@@ -3278,7 +3291,10 @@ class Server {
|
|
|
3278
3291
|
res.json({
|
|
3279
3292
|
homedir: this.kernel.homedir,
|
|
3280
3293
|
account: this.kernel.peer.current_account,
|
|
3281
|
-
|
|
3294
|
+
proxy: this.kernel.caddy.mapping, // mapping: { IP => https_domain }
|
|
3295
|
+
ports: this.kernel.caddy.port_mapping,
|
|
3296
|
+
lan: this.kernel.caddy.local_network_mapping,
|
|
3297
|
+
ips: this.kernel.caddy.ip_mapping,
|
|
3282
3298
|
memory: this.kernel.memory
|
|
3283
3299
|
})
|
|
3284
3300
|
}))
|
package/server/views/proxy.ejs
CHANGED
|
@@ -195,6 +195,9 @@ table a {
|
|
|
195
195
|
text-decoration: none;
|
|
196
196
|
color: royalblue;
|
|
197
197
|
}
|
|
198
|
+
td:first-child, th:first-child {
|
|
199
|
+
max-width: 100px;
|
|
200
|
+
}
|
|
198
201
|
.container-row th {
|
|
199
202
|
text-align: left;
|
|
200
203
|
font-size: 18px;
|
|
@@ -243,8 +246,8 @@ table a {
|
|
|
243
246
|
<div class='header-container'>
|
|
244
247
|
<div class='header-label-sub'><i class="fa-solid fa-podcast"></i> Local Network</div>
|
|
245
248
|
<% peers.forEach((item) => { %>
|
|
246
|
-
<a target="_blank" href="
|
|
247
|
-
<h3 class='table-grid'><%=item%></h3>
|
|
249
|
+
<a target="_blank" href="<%=item.proxy_page%>" class='line align-top'>
|
|
250
|
+
<h3 class='table-grid'><%=item.account%></h3>
|
|
248
251
|
</a>
|
|
249
252
|
<% }) %>
|
|
250
253
|
</div>
|
|
@@ -272,7 +275,7 @@ table a {
|
|
|
272
275
|
<a target="_blank" href="http://localhost:<%=item.port%>">http://localhost:<%=item.port%></a>
|
|
273
276
|
</div>
|
|
274
277
|
<div>
|
|
275
|
-
<a target="_blank" href="http://<%=
|
|
278
|
+
<a target="_blank" href="http://<%=ip%>:<%=lan[ip][item.port]%>">http://<%=ip%>:<%=lan[ip][item.port]%></a>
|
|
276
279
|
</div>
|
|
277
280
|
</td>
|
|
278
281
|
</tr>
|