pinokiod 3.8.148 → 3.8.149
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/bin/caddy.js +6 -5
- package/kernel/bin/conda.js +5 -1
- package/kernel/bin/index.js +244 -66
- package/kernel/bin/setup.js +130 -0
- package/kernel/environment.js +36 -1
- package/kernel/index.js +15 -4
- package/kernel/loader.js +6 -4
- package/kernel/procs.js +1 -0
- package/kernel/prototype.js +12 -9
- package/kernel/router/common.js +50 -41
- package/kernel/router/connector.js +38 -30
- package/kernel/router/index.js +51 -7
- package/kernel/router/peer_port_router.js +2 -3
- package/package.json +1 -1
- package/server/index.js +145 -317
- package/server/public/fscreator.js +1 -1
- package/server/views/network.ejs +3 -1
- package/server/views/prototypes.ejs +1 -1
- package/server/views/setup.ejs +254 -0
- package/server/views/setup_home.ejs +181 -0
package/kernel/loader.js
CHANGED
|
@@ -40,30 +40,32 @@ class Loader {
|
|
|
40
40
|
resolved = null
|
|
41
41
|
}
|
|
42
42
|
} catch (e) {
|
|
43
|
-
console.log(`[did not load] ${_path}`)
|
|
44
43
|
resolved = null
|
|
45
44
|
}
|
|
46
45
|
}
|
|
46
|
+
if (!resolved) {
|
|
47
|
+
console.log(`[did not load] ${_path}`)
|
|
48
|
+
}
|
|
47
49
|
return { resolved, extension, dirname }
|
|
48
50
|
}
|
|
49
51
|
async requireJSON(filepath) {
|
|
50
52
|
let config
|
|
51
53
|
try { config = require(filepath) } catch (e) {
|
|
52
|
-
console.log(`[did not load] ${filepath}`)
|
|
54
|
+
// console.log(`[did not load] ${filepath}`)
|
|
53
55
|
}
|
|
54
56
|
return config
|
|
55
57
|
}
|
|
56
58
|
async requireJS(filepath) {
|
|
57
59
|
let config
|
|
58
60
|
try { config = require(filepath) } catch (e) {
|
|
59
|
-
console.log(`[did not load] ${filepath}`)
|
|
61
|
+
// console.log(`[did not load] ${filepath}`)
|
|
60
62
|
}
|
|
61
63
|
try {
|
|
62
64
|
// if the required module is a class, return the instantiated object
|
|
63
65
|
return new config();
|
|
64
66
|
} catch (e) {
|
|
65
67
|
// otherwise return normally
|
|
66
|
-
console.log(`[did not load] ${filepath}`)
|
|
68
|
+
// console.log(`[did not load] ${filepath}`)
|
|
67
69
|
return config
|
|
68
70
|
}
|
|
69
71
|
}
|
package/kernel/procs.js
CHANGED
package/kernel/prototype.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const fs = require('fs')
|
|
2
2
|
const path = require('path')
|
|
3
|
+
const { glob, sync, hasMagic } = require('glob-gitignore')
|
|
3
4
|
class Proto {
|
|
4
5
|
constructor(kernel) {
|
|
5
6
|
this.kernel = kernel
|
|
@@ -10,24 +11,26 @@ class Proto {
|
|
|
10
11
|
let exists = await this.kernel.exists("prototype")
|
|
11
12
|
if (!exists) {
|
|
12
13
|
console.log("prototype doesn't exist. cloning...")
|
|
14
|
+
await fs.promises.mkdir(this.kernel.path("prototype"), { recursive: true }).catch((e) => { })
|
|
13
15
|
await this.kernel.exec({
|
|
14
|
-
message: "git clone https://github.com/peanutcocktail/prototype",
|
|
15
|
-
path: this.kernel.
|
|
16
|
+
message: "git clone https://github.com/peanutcocktail/prototype system",
|
|
17
|
+
path: this.kernel.path("prototype")
|
|
16
18
|
}, (e) => {
|
|
17
19
|
process.stdout.write(e.raw)
|
|
18
20
|
})
|
|
19
21
|
}
|
|
20
|
-
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
let cwd = path.resolve(this.kernel.homedir, "prototype")
|
|
25
|
+
let prototype_paths = (await glob('**/pinokio.js', { cwd }))
|
|
21
26
|
let prototype_dir = path.resolve(this.kernel.homedir, "prototype")
|
|
22
|
-
let prototypes = await fs.promises.readdir(prototype_dir, { withFileTypes: true })
|
|
23
|
-
prototypes = prototypes.filter(d => d.isDirectory()).map(d => d.name);
|
|
24
|
-
console.log({ prototypes })
|
|
25
27
|
this.items = []
|
|
26
28
|
this.kv = {}
|
|
27
|
-
for(let
|
|
28
|
-
let
|
|
29
|
+
for(let prototype_path of prototype_paths) {
|
|
30
|
+
let proto = path.dirname(prototype_path)
|
|
31
|
+
let pinokiojs = path.resolve(prototype_dir, prototype_path)
|
|
29
32
|
let config = await this.kernel.require(pinokiojs)
|
|
30
|
-
if (config && config.
|
|
33
|
+
if (config && config.create && typeof config.create === "function") {
|
|
31
34
|
if (config.icon) {
|
|
32
35
|
config.icon = "/prototype/" + proto + "/" + config.icon
|
|
33
36
|
} else {
|
package/kernel/router/common.js
CHANGED
|
@@ -1,50 +1,59 @@
|
|
|
1
|
-
|
|
1
|
+
const Processor = require('./processor')
|
|
2
|
+
class Common extends Processor {
|
|
2
3
|
constructor (router) {
|
|
4
|
+
super()
|
|
3
5
|
this.router = router
|
|
4
6
|
}
|
|
5
7
|
handle({ match, dial, host }) {
|
|
6
|
-
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
"
|
|
12
|
-
|
|
13
|
-
"
|
|
14
|
-
|
|
15
|
-
"Origin": ["http://127.0.0.1:11434"],
|
|
16
|
-
"X-Forwarded-Proto": ["https"],
|
|
17
|
-
"X-Forwarded-Host": ["{http.request.host}"]
|
|
18
|
-
}
|
|
19
|
-
},
|
|
20
|
-
"response": {
|
|
21
|
-
"set": {
|
|
22
|
-
"Access-Control-Allow-Origin": ["*"],
|
|
23
|
-
"Access-Control-Allow-Methods": ["GET, POST, OPTIONS, PUT, DELETE"],
|
|
24
|
-
"Access-Control-Allow-Headers": ["*"],
|
|
25
|
-
"Vary": ["Origin"]
|
|
26
|
-
}
|
|
27
|
-
}
|
|
8
|
+
let handler = [{
|
|
9
|
+
"handler": "reverse_proxy",
|
|
10
|
+
"upstreams": [{ "dial": dial }],
|
|
11
|
+
"headers": {
|
|
12
|
+
"request": {
|
|
13
|
+
"set": {
|
|
14
|
+
// "Origin": ["http://127.0.0.1:11434"],
|
|
15
|
+
"X-Forwarded-Proto": ["https"],
|
|
16
|
+
"X-Forwarded-Host": ["{http.request.host}"]
|
|
28
17
|
}
|
|
29
18
|
},
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
19
|
+
"response": {
|
|
20
|
+
"set": {
|
|
21
|
+
"Access-Control-Allow-Origin": ["*"],
|
|
22
|
+
"Access-Control-Allow-Methods": ["GET, POST, OPTIONS, PUT, DELETE"],
|
|
23
|
+
"Access-Control-Allow-Headers": ["*"],
|
|
24
|
+
"Vary": ["Origin"]
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
//{
|
|
30
|
+
// "handler": "headers",
|
|
31
|
+
// "request": {
|
|
32
|
+
// "set": {
|
|
33
|
+
// "X-Forwarded-Proto": ["https"],
|
|
34
|
+
// "X-Forwarded-Host": ["{http.request.host}"]
|
|
35
|
+
// }
|
|
36
|
+
// },
|
|
37
|
+
// "response": {
|
|
38
|
+
// "set": {
|
|
39
|
+
// "Access-Control-Allow-Origin": ["*"],
|
|
40
|
+
// "Access-Control-Allow-Methods": ["GET, POST, OPTIONS, PUT, DELETE"],
|
|
41
|
+
// "Access-Control-Allow-Headers": ["*"],
|
|
42
|
+
// "Vary": ["Origin"]
|
|
43
|
+
// }
|
|
44
|
+
// }
|
|
45
|
+
//}
|
|
46
|
+
]
|
|
47
|
+
|
|
48
|
+
// if the dial port has been overridden by router.custom_routers, use that instead
|
|
49
|
+
let parsed_dial = this.parse_ip(dial)
|
|
50
|
+
let override_handler = this.router.custom_routers[String(parsed_dial.port)]
|
|
51
|
+
if (override_handler) {
|
|
52
|
+
handler = override_handler
|
|
53
|
+
}
|
|
54
|
+
this.router.config.apps.http.servers.main.routes.push({
|
|
55
|
+
"match": [{ "host": [match] }],
|
|
56
|
+
"handle": handler
|
|
48
57
|
})
|
|
49
58
|
this.router.add({ host, dial, match })
|
|
50
59
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
const Processor = require('./processor')
|
|
2
|
+
class Connector extends Processor {
|
|
2
3
|
constructor(router) {
|
|
4
|
+
super()
|
|
3
5
|
this.router = router
|
|
4
6
|
}
|
|
5
7
|
handle ({ match, connector, dial, }) {
|
|
@@ -9,34 +11,29 @@ class Connector {
|
|
|
9
11
|
let listener_pointer = connector.host + ":PORT_PLACEHOLDER_" + connector_name
|
|
10
12
|
let port_placeholder = "PORT_PLACEHOLDER_" + connector_name
|
|
11
13
|
// console.log("CONNECTING", { listener, dial, listener_pointer, match })
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
"Vary": ["Origin"]
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
},
|
|
14
|
+
|
|
15
|
+
let handler = [{
|
|
16
|
+
"handler": "reverse_proxy",
|
|
17
|
+
"upstreams": [{ "dial": dial }],
|
|
18
|
+
"headers": {
|
|
19
|
+
"request": {
|
|
20
|
+
"set": {
|
|
21
|
+
// "Origin": ["http://127.0.0.1:11434"],
|
|
22
|
+
"X-Forwarded-Proto": ["{http.request.header.X-Forwarded-Proto}"],
|
|
23
|
+
//"X-Forwarded-Proto": ["{http.request.scheme}"],
|
|
24
|
+
//"X-Forwarded-Proto": ["https"],
|
|
25
|
+
//"X-Forwarded-Host": ["{http.request.host}"]
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"response": {
|
|
29
|
+
"set": {
|
|
30
|
+
"Access-Control-Allow-Origin": ["*"],
|
|
31
|
+
"Access-Control-Allow-Methods": ["GET, POST, OPTIONS, PUT, DELETE"],
|
|
32
|
+
"Access-Control-Allow-Headers": ["*"],
|
|
33
|
+
"Vary": ["Origin"]
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
40
37
|
// {
|
|
41
38
|
// "handler": "headers",
|
|
42
39
|
// "request": {
|
|
@@ -54,7 +51,18 @@ class Connector {
|
|
|
54
51
|
// }
|
|
55
52
|
// }
|
|
56
53
|
// }
|
|
57
|
-
|
|
54
|
+
}]
|
|
55
|
+
// if the dial port has been overridden by router.custom_routers, use that instead
|
|
56
|
+
let parsed_dial = this.parse_ip(dial)
|
|
57
|
+
let override_handler = this.router.custom_routers[String(parsed_dial.port)]
|
|
58
|
+
if (override_handler) {
|
|
59
|
+
handler = override_handler
|
|
60
|
+
}
|
|
61
|
+
if(!this.router.config.apps.http.servers[connector_name]) {
|
|
62
|
+
this.router.config.apps.http.servers[connector_name] = {
|
|
63
|
+
"listen": [listener],
|
|
64
|
+
"routes": [{
|
|
65
|
+
"handle": handler
|
|
58
66
|
}]
|
|
59
67
|
}
|
|
60
68
|
}
|
package/kernel/router/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const axios = require('axios')
|
|
2
2
|
const path = require('path')
|
|
3
|
+
const { glob, sync, hasMagic } = require('glob-gitignore')
|
|
3
4
|
const Util = require('../util')
|
|
4
5
|
const LocalhostHomeRouter = require('./localhost_home_router')
|
|
5
6
|
const LocalhostVariableRouter = require('./localhost_variable_router')
|
|
@@ -28,6 +29,47 @@ class Router {
|
|
|
28
29
|
this.mapping = {}
|
|
29
30
|
this.port_mapping = {} // 127.0.0.1 => 192.168,..
|
|
30
31
|
this.local_network_mapping = {}
|
|
32
|
+
this.custom_routers = {}
|
|
33
|
+
}
|
|
34
|
+
async init() {
|
|
35
|
+
console.log("router.init")
|
|
36
|
+
// if ~/pinokio/network doesn't exist, clone
|
|
37
|
+
let exists = await this.kernel.exists("network/system")
|
|
38
|
+
if (!exists) {
|
|
39
|
+
console.log("network doesn't exist. cloning...")
|
|
40
|
+
await fs.promises.mkdir(this.kernel.path("network"), { recursive: true }).catch((e) => { })
|
|
41
|
+
await this.kernel.exec({
|
|
42
|
+
message: "git clone https://github.com/peanutcocktail/network system",
|
|
43
|
+
path: this.kernel.path("network")
|
|
44
|
+
}, (e) => {
|
|
45
|
+
process.stdout.write(e.raw)
|
|
46
|
+
})
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
let cwd = path.resolve(this.kernel.homedir, "network")
|
|
51
|
+
let router_paths = (await glob('**/*.json', { cwd }))
|
|
52
|
+
let router_dir = path.resolve(this.kernel.homedir, "network")
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
// create a custom_map that maps port to custom router declarations
|
|
56
|
+
/*
|
|
57
|
+
custom_routers = {
|
|
58
|
+
PORT1: <caddy handler>,
|
|
59
|
+
PORT2: <caddy handler>,
|
|
60
|
+
...
|
|
61
|
+
}
|
|
62
|
+
*/
|
|
63
|
+
this.custom_routers = {}
|
|
64
|
+
console.log({ router_paths })
|
|
65
|
+
for(let router_path of router_paths) {
|
|
66
|
+
let router_abs_path = this.kernel.path("network", router_path)
|
|
67
|
+
let config = await this.kernel.require(router_abs_path)
|
|
68
|
+
console.log({ config })
|
|
69
|
+
for(let port in config) {
|
|
70
|
+
this.custom_routers[port] = config[port]
|
|
71
|
+
}
|
|
72
|
+
}
|
|
31
73
|
}
|
|
32
74
|
async add({ host, match, dial }) {
|
|
33
75
|
if (!this._mapping[host]) {
|
|
@@ -219,14 +261,16 @@ class Router {
|
|
|
219
261
|
if (JSON.stringify(this.config) === JSON.stringify(this.old_config)) {
|
|
220
262
|
// console.log("config hasn't updated")
|
|
221
263
|
} else {
|
|
222
|
-
console.log("caddy config has updated")
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
264
|
+
console.log("caddy config has updated", this.config)
|
|
265
|
+
try {
|
|
266
|
+
let response = await axios.post('http://127.0.0.1:2019/load', this.config, {
|
|
267
|
+
headers: { 'Content-Type': 'application/json' }
|
|
268
|
+
})
|
|
269
|
+
console.log("Caddy Response", { response })
|
|
270
|
+
this.old_config = this.config
|
|
271
|
+
} catch (e) {
|
|
226
272
|
console.log("EEEEEEEEEEEEE", e.message)
|
|
227
|
-
}
|
|
228
|
-
// console.log("Caddy Response", { response })
|
|
229
|
-
this.old_config = this.config
|
|
273
|
+
}
|
|
230
274
|
}
|
|
231
275
|
}
|
|
232
276
|
|
|
@@ -9,9 +9,10 @@ class PeerPortRouter extends Processor {
|
|
|
9
9
|
}
|
|
10
10
|
handle(peer) {
|
|
11
11
|
let https_domains_mapping = this.router.info[peer.host]
|
|
12
|
+
console.log({ https_domains_mapping })
|
|
12
13
|
for(let dial in https_domains_mapping) {
|
|
14
|
+
console.log({ dial })
|
|
13
15
|
let parsed_dial = this.parse_ip(dial)
|
|
14
|
-
|
|
15
16
|
if (parsed_dial.host !== peer.host) {
|
|
16
17
|
// ONLY connect for 127.0.0.1 or localhost
|
|
17
18
|
// DO NOT connect if it's the actual host => because it will keep creating proxies forever recursively. only need to create proxies for localhost
|
|
@@ -40,8 +41,6 @@ class PeerPortRouter extends Processor {
|
|
|
40
41
|
})
|
|
41
42
|
}
|
|
42
43
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
44
|
}
|
|
46
45
|
}
|
|
47
46
|
}
|