pinokiod 3.24.0 → 3.25.0
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/api/exec/index.js +67 -0
- package/kernel/api/index.js +1 -0
- package/kernel/plugin.js +24 -41
- package/kernel/prototype.js +23 -0
- package/kernel/router/index.js +13 -0
- package/kernel/router/localhost_home_router.js +11 -0
- package/kernel/shell.js +13 -10
- package/kernel/shells.js +52 -47
- package/package.json +2 -1
- package/server/index.js +191 -169
- package/server/public/style.css +1 -1
- package/server/socket.js +0 -19
- package/server/views/app.ejs +45 -11
- package/server/views/d.ejs +71 -12
- package/server/views/index.ejs +69 -1
- package/server/views/init/index.ejs +248 -87
- package/server/views/net.ejs +0 -1
- package/server/views/network.ejs +3 -2
- package/server/views/partials/dynamic.ejs +1 -1
- package/server/views/start.ejs +233 -0
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
const child_process = require('child_process')
|
|
2
|
+
module.exports = async (req, ondata, kernel) => {
|
|
3
|
+
/*
|
|
4
|
+
req := {
|
|
5
|
+
method: "exec",
|
|
6
|
+
params: {
|
|
7
|
+
|
|
8
|
+
// pinokio params
|
|
9
|
+
message: <message>,
|
|
10
|
+
path: <path>,
|
|
11
|
+
|
|
12
|
+
// node.js child_process.exec params
|
|
13
|
+
|
|
14
|
+
// Working directory
|
|
15
|
+
cwd: '/path/to/working/directory',
|
|
16
|
+
|
|
17
|
+
// Environment variables
|
|
18
|
+
env: { ...process.env, CUSTOM_VAR: 'value' },
|
|
19
|
+
|
|
20
|
+
// Encoding for stdout/stderr (default: 'utf8')
|
|
21
|
+
encoding: 'utf8', // or 'buffer', 'ascii', etc.
|
|
22
|
+
|
|
23
|
+
// Shell to execute the command
|
|
24
|
+
shell: '/bin/bash', // default varies by platform
|
|
25
|
+
|
|
26
|
+
// Timeout in milliseconds
|
|
27
|
+
timeout: 10000, // Kill process after 10 seconds
|
|
28
|
+
|
|
29
|
+
// Maximum buffer size for stdout/stderr
|
|
30
|
+
maxBuffer: 1024 * 1024, // 1MB (default: 1024 * 1024)
|
|
31
|
+
|
|
32
|
+
// Signal to send when killing due to timeout
|
|
33
|
+
killSignal: 'SIGTERM', // default: 'SIGTERM'
|
|
34
|
+
|
|
35
|
+
// User identity (Unix only)
|
|
36
|
+
uid: 1000,
|
|
37
|
+
gid: 1000,
|
|
38
|
+
|
|
39
|
+
// Windows-specific options
|
|
40
|
+
windowsHide: true, // Hide subprocess console window on Windows
|
|
41
|
+
windowsVerbatimArguments: false // Quote handling on Windows
|
|
42
|
+
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
*/
|
|
46
|
+
if (req.params && req.params.message) {
|
|
47
|
+
// if cwd exists, use cwd
|
|
48
|
+
// if cwd doesn't exist, set pat
|
|
49
|
+
if (!req.params.cwd && req.params.path) {
|
|
50
|
+
req.params.cwd = req.params.path
|
|
51
|
+
}
|
|
52
|
+
req.params.env = Object.assign({}, kernel.envs, req.params.env)
|
|
53
|
+
console.log("env", JSON.stringify(req.params.env, null, 2))
|
|
54
|
+
ondata({ raw: `██ Exec: ${req.params.message}\r\n` })
|
|
55
|
+
let response = await new Promise((resolve, reject) => {
|
|
56
|
+
child_process.exec(req.params.message, req.params, (error, stdout, stderr) => {
|
|
57
|
+
resolve({
|
|
58
|
+
stdout,
|
|
59
|
+
error,
|
|
60
|
+
stderr
|
|
61
|
+
})
|
|
62
|
+
})
|
|
63
|
+
})
|
|
64
|
+
console.log({ response })
|
|
65
|
+
return response
|
|
66
|
+
}
|
|
67
|
+
}
|
package/kernel/api/index.js
CHANGED
package/kernel/plugin.js
CHANGED
|
@@ -5,33 +5,13 @@ class Plugin {
|
|
|
5
5
|
constructor(kernel) {
|
|
6
6
|
this.kernel = kernel
|
|
7
7
|
}
|
|
8
|
-
async
|
|
9
|
-
let exists = await this.kernel.exists("plugin")
|
|
10
|
-
if (!exists) {
|
|
11
|
-
await fs.promises.mkdir(this.kernel.path("plugin"), { recursive: true }).catch((e) => {})
|
|
12
|
-
if (this.kernel.bin.installed && this.kernel.bin.installed.conda && this.kernel.bin.installed.conda.has("git")) {
|
|
13
|
-
await this.kernel.exec({
|
|
14
|
-
//message: "git clone https://github.com/peanutcocktail/plugin",
|
|
15
|
-
//message: "git clone https://github.com/pinokiocomputer/plugin",
|
|
16
|
-
message: "git clone https://github.com/pinokiocomputer/code",
|
|
17
|
-
path: this.kernel.path("plugin")
|
|
18
|
-
}, (e) => {
|
|
19
|
-
process.stdout.write(e.raw)
|
|
20
|
-
})
|
|
21
|
-
}
|
|
22
|
-
}
|
|
8
|
+
async setConfig() {
|
|
23
9
|
let plugin_dir = path.resolve(this.kernel.homedir, "plugin")
|
|
24
|
-
// this.config = await this.kernel.require(pinokiojs)
|
|
25
10
|
this.cache = {}
|
|
26
11
|
|
|
27
12
|
let plugin_paths = await glob('**/pinokio.js', { cwd: plugin_dir })
|
|
28
|
-
console.log({ plugin_paths })
|
|
29
13
|
|
|
30
14
|
let plugins = []
|
|
31
|
-
// let info = new Info(this.kernel)
|
|
32
|
-
// info.cwd = () => {
|
|
33
|
-
// return plugin_dir
|
|
34
|
-
// }
|
|
35
15
|
for(let plugin_path of plugin_paths) {
|
|
36
16
|
let config = await this.kernel.require(path.resolve(plugin_dir, plugin_path))
|
|
37
17
|
let cwd = plugin_path.split("/").slice(0, -1).join("/")
|
|
@@ -48,26 +28,29 @@ class Plugin {
|
|
|
48
28
|
return plugin
|
|
49
29
|
})
|
|
50
30
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
//
|
|
62
|
-
//
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
31
|
+
}
|
|
32
|
+
async init() {
|
|
33
|
+
let exists = await this.kernel.exists("plugin")
|
|
34
|
+
if (!exists) {
|
|
35
|
+
await fs.promises.mkdir(this.kernel.path("plugin"), { recursive: true }).catch((e) => {})
|
|
36
|
+
}
|
|
37
|
+
let code_exists = await this.kernel.exists("plugin/code")
|
|
38
|
+
if (!code_exists) {
|
|
39
|
+
if (this.kernel.bin.installed && this.kernel.bin.installed.conda && this.kernel.bin.installed.conda.has("git")) {
|
|
40
|
+
await this.kernel.exec({
|
|
41
|
+
//message: "git clone https://github.com/peanutcocktail/plugin",
|
|
42
|
+
//message: "git clone https://github.com/pinokiocomputer/plugin",
|
|
43
|
+
message: "git clone https://github.com/pinokiocomputer/code",
|
|
44
|
+
path: this.kernel.path("plugin")
|
|
45
|
+
}, (e) => {
|
|
46
|
+
process.stdout.write(e.raw)
|
|
47
|
+
})
|
|
48
|
+
await this.setConfig()
|
|
49
|
+
return
|
|
50
|
+
}
|
|
51
|
+
} else {
|
|
52
|
+
await this.setConfig()
|
|
53
|
+
}
|
|
71
54
|
}
|
|
72
55
|
async update() {
|
|
73
56
|
if (this.kernel.bin.installed && this.kernel.bin.installed.conda && this.kernel.bin.installed.conda.has("git")) {
|
package/kernel/prototype.js
CHANGED
|
@@ -2,6 +2,7 @@ const fs = require('fs')
|
|
|
2
2
|
const path = require('path')
|
|
3
3
|
const { glob, sync, hasMagic } = require('glob-gitignore')
|
|
4
4
|
const marked = require('marked')
|
|
5
|
+
const matter = require('gray-matter');
|
|
5
6
|
class Proto {
|
|
6
7
|
constructor(kernel) {
|
|
7
8
|
this.kernel = kernel
|
|
@@ -49,6 +50,28 @@ class Proto {
|
|
|
49
50
|
}
|
|
50
51
|
console.log("Proto init done")
|
|
51
52
|
}
|
|
53
|
+
async ai() {
|
|
54
|
+
let ai_path = this.kernel.path("prototype/system/ai/new/static")
|
|
55
|
+
let mds = await fs.promises.readdir(ai_path)
|
|
56
|
+
mds = mds.filter((md) => {
|
|
57
|
+
return md.endsWith(".md")
|
|
58
|
+
})
|
|
59
|
+
const results = []
|
|
60
|
+
for(let md of mds) {
|
|
61
|
+
let mdpath = path.resolve(ai_path, md)
|
|
62
|
+
let mdstr = await fs.promises.readFile(mdpath, "utf8")
|
|
63
|
+
const { data, content } = matter(mdstr)
|
|
64
|
+
// const html = marked.parse(content)
|
|
65
|
+
let { title, description, ...meta } = data
|
|
66
|
+
results.push({
|
|
67
|
+
title,
|
|
68
|
+
description,
|
|
69
|
+
meta,
|
|
70
|
+
content
|
|
71
|
+
})
|
|
72
|
+
}
|
|
73
|
+
return results
|
|
74
|
+
}
|
|
52
75
|
async reset() {
|
|
53
76
|
await fs.promises.rm(this.kernel.path("prototype"), { recursive: true })
|
|
54
77
|
}
|
package/kernel/router/index.js
CHANGED
|
@@ -216,6 +216,19 @@ class Router {
|
|
|
216
216
|
await this.fill()
|
|
217
217
|
}
|
|
218
218
|
}
|
|
219
|
+
this.config.apps.http.servers.main.routes.push({
|
|
220
|
+
"handle": [
|
|
221
|
+
{
|
|
222
|
+
"handler": "static_response",
|
|
223
|
+
"status_code": 302,
|
|
224
|
+
"headers": {
|
|
225
|
+
"Location": [
|
|
226
|
+
`https://${this.default_match}/launch?url={http.request.scheme}://{http.request.host}{http.request.uri}`
|
|
227
|
+
]
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
]
|
|
231
|
+
})
|
|
219
232
|
this.mapping = this._mapping
|
|
220
233
|
}
|
|
221
234
|
|
|
@@ -6,6 +6,17 @@ class LocalhostHomeRouter {
|
|
|
6
6
|
this.router.add({ host: this.router.kernel.peer.host, dial: this.router.default_host + ":" + this.router.default_port, match: this.router.default_match })
|
|
7
7
|
this.router.config = {
|
|
8
8
|
"apps": {
|
|
9
|
+
"tls": {
|
|
10
|
+
"automation": {
|
|
11
|
+
"policies": [
|
|
12
|
+
{
|
|
13
|
+
"issuers": [{ "module": "internal" }],
|
|
14
|
+
"on_demand": true
|
|
15
|
+
}
|
|
16
|
+
]
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
|
|
9
20
|
"http": {
|
|
10
21
|
"servers": {
|
|
11
22
|
"main": {
|
package/kernel/shell.js
CHANGED
|
@@ -209,7 +209,6 @@ class Shell {
|
|
|
209
209
|
}
|
|
210
210
|
}
|
|
211
211
|
async start(params, ondata) {
|
|
212
|
-
console.log("SHELL START", params)
|
|
213
212
|
this.ondata = ondata
|
|
214
213
|
|
|
215
214
|
/*
|
|
@@ -1056,10 +1055,8 @@ class Shell {
|
|
|
1056
1055
|
for(let notif of notifications) {
|
|
1057
1056
|
if (notif.type !== "bell") {
|
|
1058
1057
|
Util.push({
|
|
1059
|
-
// title: notif.type,
|
|
1060
|
-
// subtitle: notif.title,
|
|
1061
1058
|
image: path.resolve(__dirname, "../server/public/pinokio-black.png"),
|
|
1062
|
-
message: notif.title
|
|
1059
|
+
message: notif.title,
|
|
1063
1060
|
sound: true,
|
|
1064
1061
|
timeout: 30,
|
|
1065
1062
|
})
|
|
@@ -1135,8 +1132,10 @@ class Shell {
|
|
|
1135
1132
|
this.ptyProcess = undefined
|
|
1136
1133
|
// automatically remove the shell from this.kernel.shells
|
|
1137
1134
|
this.kernel.shell.rm(this.id)
|
|
1138
|
-
this.
|
|
1139
|
-
|
|
1135
|
+
if (!this.mute) {
|
|
1136
|
+
this.ondata({ raw: `\r\n\r\n██ Terminated Shell ${this.id}\r\n████\r\n` })
|
|
1137
|
+
this.ondata({ raw: "", type: "shell.kill" })
|
|
1138
|
+
}
|
|
1140
1139
|
cb()
|
|
1141
1140
|
} else {
|
|
1142
1141
|
kill(this.ptyProcess.pid, "SIGKILL", true)
|
|
@@ -1144,13 +1143,17 @@ class Shell {
|
|
|
1144
1143
|
this.ptyProcess = undefined
|
|
1145
1144
|
// automatically remove the shell from this.kernel.shells
|
|
1146
1145
|
this.kernel.shell.rm(this.id)
|
|
1147
|
-
this.
|
|
1148
|
-
|
|
1146
|
+
if (!this.mute) {
|
|
1147
|
+
this.ondata({ raw: `\r\n\r\n██ Terminated Shell ${this.id}\r\n████\r\n` })
|
|
1148
|
+
this.ondata({ raw: "", type: "shell.kill" })
|
|
1149
|
+
}
|
|
1149
1150
|
}
|
|
1150
1151
|
} else {
|
|
1151
1152
|
this.kernel.shell.rm(this.id)
|
|
1152
|
-
this.
|
|
1153
|
-
|
|
1153
|
+
if (!this.mute) {
|
|
1154
|
+
this.ondata({ raw: `\r\n\r\n██ Terminated Shell ${this.id}\r\n████\r\n` })
|
|
1155
|
+
this.ondata({ raw: "", type: "shell.kill" })
|
|
1156
|
+
}
|
|
1154
1157
|
}
|
|
1155
1158
|
|
|
1156
1159
|
|
package/kernel/shells.js
CHANGED
|
@@ -142,59 +142,66 @@ class Shells {
|
|
|
142
142
|
}
|
|
143
143
|
}
|
|
144
144
|
*/
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
let
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
if (handler.
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
matches[2]
|
|
156
|
-
|
|
157
|
-
let re = new RegExp(matches[1], matches[2])
|
|
158
|
-
let test = re.exec(sh.monitor)
|
|
159
|
-
if (test && test.length > 0) {
|
|
160
|
-
// reset monitor
|
|
161
|
-
sh.monitor = ""
|
|
162
|
-
let params = this.kernel.template.render(handler.notify, { event: test })
|
|
163
|
-
if (params.image) {
|
|
164
|
-
params.contentImage = path.resolve(req.cwd, params.image)
|
|
145
|
+
try {
|
|
146
|
+
if (params.on && Array.isArray(params.on)) {
|
|
147
|
+
for(let i=0; i<params.on.length; i++) {
|
|
148
|
+
let handler = params.on[i]
|
|
149
|
+
// regexify
|
|
150
|
+
//let matches = /^\/([^\/]+)\/([dgimsuy]*)$/.exec(handler.event)
|
|
151
|
+
if (handler.event) {
|
|
152
|
+
if (handler.notify) {
|
|
153
|
+
// notify is a special case. check by line
|
|
154
|
+
let matches = /^\/(.+)\/([dgimsuy]*)$/gs.exec(handler.event)
|
|
155
|
+
if (!/g/.test(matches[2])) {
|
|
156
|
+
matches[2] += "g" // if g option is not included, include it (need it for matchAll)
|
|
165
157
|
}
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
if (stream.cleaned) {
|
|
175
|
-
let line = stream.cleaned.replaceAll(/[\r\n]/g, "")
|
|
176
|
-
let rendered_event = [...line.matchAll(re)]
|
|
177
|
-
// 3. if the rendered expression is truthy, run the "run" script
|
|
178
|
-
if (rendered_event.length > 0) {
|
|
179
|
-
stream.matches = rendered_event
|
|
180
|
-
if (handler.kill) {
|
|
181
|
-
m = rendered_event[0]
|
|
182
|
-
matched_index = i
|
|
183
|
-
sh.kill()
|
|
158
|
+
let re = new RegExp(matches[1], matches[2])
|
|
159
|
+
let test = re.exec(sh.monitor)
|
|
160
|
+
if (test && test.length > 0) {
|
|
161
|
+
// reset monitor
|
|
162
|
+
sh.monitor = ""
|
|
163
|
+
let params = this.kernel.template.render(handler.notify, { event: test })
|
|
164
|
+
if (params.image) {
|
|
165
|
+
params.contentImage = path.resolve(req.cwd, params.image)
|
|
184
166
|
}
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
167
|
+
Util.push(params)
|
|
168
|
+
}
|
|
169
|
+
} else {
|
|
170
|
+
let matches = /^\/(.+)\/([dgimsuy]*)$/gs.exec(handler.event)
|
|
171
|
+
if (!/g/.test(matches[2])) {
|
|
172
|
+
matches[2] += "g" // if g option is not included, include it (need it for matchAll)
|
|
173
|
+
}
|
|
174
|
+
let re = new RegExp(matches[1], matches[2])
|
|
175
|
+
if (stream.cleaned) {
|
|
176
|
+
let line = stream.cleaned.replaceAll(/[\r\n]/g, "")
|
|
177
|
+
let rendered_event = [...line.matchAll(re)]
|
|
178
|
+
// 3. if the rendered expression is truthy, run the "run" script
|
|
179
|
+
if (rendered_event.length > 0) {
|
|
180
|
+
stream.matches = rendered_event
|
|
181
|
+
if (handler.kill) {
|
|
182
|
+
m = rendered_event[0]
|
|
183
|
+
matched_index = i
|
|
184
|
+
sh.kill()
|
|
185
|
+
}
|
|
186
|
+
if (handler.done) {
|
|
187
|
+
m = rendered_event[0]
|
|
188
|
+
matched_index = i
|
|
189
|
+
sh.continue()
|
|
190
|
+
}
|
|
189
191
|
}
|
|
190
192
|
}
|
|
191
193
|
}
|
|
192
194
|
}
|
|
193
195
|
}
|
|
194
196
|
}
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
197
|
+
if (ondata) {
|
|
198
|
+
ondata(stream)
|
|
199
|
+
}
|
|
200
|
+
} catch (e) {
|
|
201
|
+
console.log("Capture error", e)
|
|
202
|
+
ondata({ raw: e.stack })
|
|
203
|
+
sh.mute = true
|
|
204
|
+
sh.kill()
|
|
198
205
|
}
|
|
199
206
|
})
|
|
200
207
|
/*
|
|
@@ -490,8 +497,6 @@ class Shells {
|
|
|
490
497
|
|
|
491
498
|
if (request.id) {
|
|
492
499
|
|
|
493
|
-
console.log("this.shells", this.shells.map((x) => { return x.id }))
|
|
494
|
-
|
|
495
500
|
let shells = []
|
|
496
501
|
for(let i=0; i<this.shells.length; i++) {
|
|
497
502
|
shells.push(this.shells[i])
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pinokiod",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.25.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -36,6 +36,7 @@
|
|
|
36
36
|
"glob": "^10.3.3",
|
|
37
37
|
"glob-gitignore": "^1.0.14",
|
|
38
38
|
"go-get-folder-size": "^0.5.5",
|
|
39
|
+
"gray-matter": "^4.0.3",
|
|
39
40
|
"http-proxy": "^1.18.1",
|
|
40
41
|
"http-proxy-middleware": "^3.0.0",
|
|
41
42
|
"http-terminator": "^3.2.0",
|