@maiyunnet/kebab 2.0.3 → 2.0.4
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/index.js +1 -1
- package/package.json +1 -1
- package/tsconfig.json +1 -1
- package/index.ts +0 -33
- package/lib/buffer.ts +0 -152
- package/lib/captcha.ts +0 -63
- package/lib/consistent.ts +0 -219
- package/lib/core.ts +0 -880
- package/lib/crypto.ts +0 -384
- package/lib/db.ts +0 -719
- package/lib/dns.ts +0 -405
- package/lib/fs.ts +0 -527
- package/lib/jwt.ts +0 -276
- package/lib/kv.ts +0 -1489
- package/lib/lan.ts +0 -87
- package/lib/net/formdata.ts +0 -166
- package/lib/net/request.ts +0 -150
- package/lib/net/response.ts +0 -59
- package/lib/net.ts +0 -662
- package/lib/s3.ts +0 -235
- package/lib/scan.ts +0 -364
- package/lib/session.ts +0 -230
- package/lib/sql.ts +0 -1149
- package/lib/ssh/sftp.ts +0 -508
- package/lib/ssh/shell.ts +0 -123
- package/lib/ssh.ts +0 -191
- package/lib/text.ts +0 -626
- package/lib/time.ts +0 -254
- package/lib/ws.ts +0 -523
- package/lib/zip.ts +0 -447
- package/lib/zlib.ts +0 -350
- package/main.ts +0 -27
- package/sys/child.ts +0 -678
- package/sys/cmd.ts +0 -225
- package/sys/ctr.ts +0 -904
- package/sys/master.ts +0 -355
- package/sys/mod.ts +0 -1871
- package/sys/route.ts +0 -1113
- package/types/index.d.ts +0 -283
- package/www/example/ctr/main.ts +0 -9
- package/www/example/ctr/middle.ts +0 -26
- package/www/example/ctr/test.ts +0 -3218
- package/www/example/mod/test.ts +0 -47
- package/www/example/mod/testdata.ts +0 -30
- package/www/example/ws/mproxy.ts +0 -16
- package/www/example/ws/rproxy.ts +0 -14
- package/www/example/ws/test.ts +0 -36
package/sys/cmd.ts
DELETED
|
@@ -1,225 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Project: Kebab, User: JianSuoQiYue
|
|
3
|
-
* Date: 2020-3-7 23:51:15
|
|
4
|
-
* Last: 2020-3-7 23:51:18, 2022-07-22 14:14:09, 2022-9-27 14:52:19, 2023-5-23 21:42:46, 2024-7-2 15:12:28
|
|
5
|
-
*/
|
|
6
|
-
import * as http from 'http';
|
|
7
|
-
import * as lFs from '~/lib/fs';
|
|
8
|
-
import * as lText from '~/lib/text';
|
|
9
|
-
import * as lTime from '~/lib/time';
|
|
10
|
-
import * as lCore from '~/lib/core';
|
|
11
|
-
import * as lCrypto from '~/lib/crypto';
|
|
12
|
-
import * as kebab from '~/index';
|
|
13
|
-
|
|
14
|
-
/** --- 解析命令 --- */
|
|
15
|
-
const cmds = process.argv.slice(2);
|
|
16
|
-
|
|
17
|
-
/** --- 批量创建目录 --- */
|
|
18
|
-
async function initDir(paths: string[]): Promise<boolean> {
|
|
19
|
-
for (const path of paths) {
|
|
20
|
-
if (await lFs.isDir(path)) {
|
|
21
|
-
continue;
|
|
22
|
-
}
|
|
23
|
-
lCore.display('KEBAB', 'CREATE', 'DIR', path);
|
|
24
|
-
if (!await lFs.mkdir(path)) {
|
|
25
|
-
lCore.display('KEBAB', 'CREATE', 'DIR', path, '[FAILED]');
|
|
26
|
-
return false;
|
|
27
|
-
}
|
|
28
|
-
lCore.display('KEBAB', 'CREATE', 'FILE', path + 'lock.txt');
|
|
29
|
-
if (!await lFs.putContent(path + 'lock.txt', 'Kebab')) {
|
|
30
|
-
lCore.display('KEBAB', 'CREATE', 'FILE', path + 'lock.txt', '[FAILED]');
|
|
31
|
-
return false;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
return true;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/** --- cmd 解析 --- */
|
|
38
|
-
async function run(): Promise<void> {
|
|
39
|
-
if (cmds[0] === 'init' || cmds[0] === 'update') {
|
|
40
|
-
// --- 初始化、更新 ---
|
|
41
|
-
if (!await initDir([
|
|
42
|
-
kebab.CERT_CWD + 'default/',
|
|
43
|
-
kebab.VHOST_CWD,
|
|
44
|
-
kebab.FTMP_CWD,
|
|
45
|
-
kebab.IND_CWD,
|
|
46
|
-
kebab.LIB_CWD,
|
|
47
|
-
kebab.LOG_CWD,
|
|
48
|
-
kebab.WWW_CWD,
|
|
49
|
-
kebab.MOD_CWD,
|
|
50
|
-
])) {
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
// --- /conf/cert.json ---
|
|
54
|
-
if (!await lFs.isFile(kebab.CONF_CWD + 'cert.json')) {
|
|
55
|
-
lCore.display('KEBAB', 'CREATE', 'FILE', kebab.CONF_CWD + 'cert.json');
|
|
56
|
-
if (!await lFs.putContent(kebab.CONF_CWD + 'cert.json', lText.stringifyJson([
|
|
57
|
-
{
|
|
58
|
-
'cert': 'default/xxx.cer',
|
|
59
|
-
'key': 'default/xxx.key'
|
|
60
|
-
}
|
|
61
|
-
], 4))) {
|
|
62
|
-
lCore.display('KEBAB', 'CREATE', 'FILE', kebab.CONF_CWD + 'cert.json', '[FAILED]');
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
// --- /conf/config.json ---
|
|
67
|
-
let config: any = {};
|
|
68
|
-
if (await lFs.isFile(kebab.CONF_CWD + 'config.json')) {
|
|
69
|
-
config = lText.parseJson((await lFs.getContent(kebab.CONF_CWD + 'config.json'))?.toString() ?? '{}');
|
|
70
|
-
}
|
|
71
|
-
else {
|
|
72
|
-
lCore.display('KEBAB', 'CREATE', 'FILE', kebab.CONF_CWD + 'config.json');
|
|
73
|
-
}
|
|
74
|
-
// --- 修复 config ---
|
|
75
|
-
config.httpPort ??= 8080;
|
|
76
|
-
config.httpsPort ??= 4333;
|
|
77
|
-
config.rpcPort ??= 10630;
|
|
78
|
-
config.rpcSecret ??= 'MUSTCHANGE';
|
|
79
|
-
config.debug ??= true;
|
|
80
|
-
config.max ??= 64;
|
|
81
|
-
// --- config - set ---
|
|
82
|
-
config.set ??= {};
|
|
83
|
-
config.set.timezone ??= 8;
|
|
84
|
-
config.set.mustHttps ??= false;
|
|
85
|
-
config.set.cacheTtl ??= 0;
|
|
86
|
-
config.set.staticVer ??= '20200314174905';
|
|
87
|
-
config.set.staticPath ??= '';
|
|
88
|
-
// --- config - db ---
|
|
89
|
-
config.db ??= {};
|
|
90
|
-
config.db.host ??= '127.0.0.1';
|
|
91
|
-
config.db.port ??= 3306;
|
|
92
|
-
config.db.charset ??= 'utf8mb4';
|
|
93
|
-
config.db.name ??= 'maiyun';
|
|
94
|
-
config.db.user ??= 'root';
|
|
95
|
-
config.db.pwd ??= 'DashAdmin';
|
|
96
|
-
// --- config - jwt ---
|
|
97
|
-
config.jwt ??= {};
|
|
98
|
-
config.jwt.name ??= 'KE_JWT';
|
|
99
|
-
config.jwt.ttl ??= 172800;
|
|
100
|
-
config.jwt.ssl ??= false;
|
|
101
|
-
config.jwt.secret ??= 'MUSTCHANGE';
|
|
102
|
-
config.jwt.auth ??= false;
|
|
103
|
-
// --- config - dns ---
|
|
104
|
-
config.dns ??= {};
|
|
105
|
-
config.dns['DNSPOD'] ??= {};
|
|
106
|
-
config.dns['DNSPOD'].sid ??= '';
|
|
107
|
-
config.dns['DNSPOD'].skey ??= '';
|
|
108
|
-
config.dns['CF'] ??= {};
|
|
109
|
-
config.dns['CF'].sid ??= '';
|
|
110
|
-
config.dns['CF'].skey ??= '';
|
|
111
|
-
// --- config - kv ---
|
|
112
|
-
config.kv ??= {};
|
|
113
|
-
config.kv.host ??= '127.0.0.1';
|
|
114
|
-
config.kv.port ??= 6379;
|
|
115
|
-
config.kv.index ??= 0;
|
|
116
|
-
config.kv.pre ??= 'm_';
|
|
117
|
-
config.kv.user ??= '';
|
|
118
|
-
config.kv.pwd ??= '';
|
|
119
|
-
// --- config - session ---
|
|
120
|
-
config.session ??= {};
|
|
121
|
-
config.session.name ??= 'KE_SESSION';
|
|
122
|
-
config.session.ttl ??= 172800;
|
|
123
|
-
config.session.ssl ??= false;
|
|
124
|
-
// --- config - sql ---
|
|
125
|
-
config.sql ??= {};
|
|
126
|
-
config.sql.pre ??= 'm_';
|
|
127
|
-
// --- config - s3 ---
|
|
128
|
-
config.s3 ??= {};
|
|
129
|
-
config.s3['CF'] ??= {};
|
|
130
|
-
config.s3['CF'].account = '';
|
|
131
|
-
config.s3['CF'].sid = '';
|
|
132
|
-
config.s3['CF'].skey = '';
|
|
133
|
-
config.s3['CF'].region = 'auto';
|
|
134
|
-
config.s3['CF'].bucket = '';
|
|
135
|
-
config.s3['TENCENT'] ??= {};
|
|
136
|
-
config.s3['TENCENT'].sid = '';
|
|
137
|
-
config.s3['TENCENT'].skey = '';
|
|
138
|
-
config.s3['TENCENT'].region = '';
|
|
139
|
-
config.s3['TENCENT'].bucket = '';
|
|
140
|
-
// --- 保存 config.json ---
|
|
141
|
-
if (!await lFs.putContent(kebab.CONF_CWD + 'config.json', lText.stringifyJson(config, 4))) {
|
|
142
|
-
lCore.display('KEBAB', 'CREATE', 'FILE', kebab.CONF_CWD + 'config.json', '[FAILED]');
|
|
143
|
-
return;
|
|
144
|
-
}
|
|
145
|
-
// --- 只在初始化时 ---
|
|
146
|
-
if (cmds[0] === 'init') {
|
|
147
|
-
// --- /conf/vhost/default.json ---
|
|
148
|
-
if (!await lFs.isFile(kebab.VHOST_CWD + 'default.json')) {
|
|
149
|
-
lCore.display('KEBAB', 'CREATE', 'FILE', kebab.VHOST_CWD + 'default.json');
|
|
150
|
-
if (!await lFs.putContent(kebab.VHOST_CWD + 'default.json', lText.stringifyJson([
|
|
151
|
-
{
|
|
152
|
-
'name': 'example',
|
|
153
|
-
'domains': ['*'],
|
|
154
|
-
'root': '${example}',
|
|
155
|
-
'remark': '',
|
|
156
|
-
},
|
|
157
|
-
{
|
|
158
|
-
'name': 'default',
|
|
159
|
-
'domains': ['www.maiyun.net'],
|
|
160
|
-
'root': 'default/',
|
|
161
|
-
'remark': '',
|
|
162
|
-
},
|
|
163
|
-
], 4))) {
|
|
164
|
-
lCore.display('KEBAB', 'CREATE', 'FILE', kebab.VHOST_CWD + 'default.json', '[FAILED]');
|
|
165
|
-
return;
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
lCore.display('DONE');
|
|
170
|
-
process.exit();
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
// --- 读取配置文件 ---
|
|
174
|
-
const configContent = await lFs.getContent(kebab.CONF_CWD + 'config.json', 'utf8');
|
|
175
|
-
if (!configContent) {
|
|
176
|
-
throw `File '${kebab.CONF_CWD}config.json' not found.`;
|
|
177
|
-
}
|
|
178
|
-
/** --- 系统 config.json --- */
|
|
179
|
-
const config = lText.parseJson(configContent);
|
|
180
|
-
for (const key in config) {
|
|
181
|
-
lCore.globalConfig[key] = config[key];
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
if (cmds[0] === '--ind' || cmds[0] === '-i') {
|
|
185
|
-
// --- 运行独立文件,如 node ./index --ind gps ---
|
|
186
|
-
if (!await lFs.isFile(kebab.IND_CWD + cmds[1] + '/index.js')) {
|
|
187
|
-
lCore.display('CMD ERROR', 'IND FILE "' + cmds[1] + '" NOT FOUND.');
|
|
188
|
-
return;
|
|
189
|
-
}
|
|
190
|
-
// --- 载入独立文件入口 ---
|
|
191
|
-
import('../ind/' + cmds[1] + '/index').catch((e) => {
|
|
192
|
-
lCore.display('CMD ERROR', 'E', e);
|
|
193
|
-
});
|
|
194
|
-
}
|
|
195
|
-
else {
|
|
196
|
-
// --- 其他,如 node ./index reload 或 restart ---
|
|
197
|
-
const time = lTime.stamp();
|
|
198
|
-
http.request({
|
|
199
|
-
'hostname': '127.0.0.1',
|
|
200
|
-
'port': config.rpcPort,
|
|
201
|
-
'path': '/' + lCrypto.aesEncrypt(lText.stringifyJson({
|
|
202
|
-
'action': cmds[0],
|
|
203
|
-
'time': time
|
|
204
|
-
}), lCore.globalConfig.rpcSecret)
|
|
205
|
-
}, function(res: http.IncomingMessage) {
|
|
206
|
-
res.on('data', function(chunk: Buffer) {
|
|
207
|
-
const str = chunk.toString();
|
|
208
|
-
if (str === 'Done') {
|
|
209
|
-
lCore.display(`Command ${cmds[0]} has been sent.`);
|
|
210
|
-
}
|
|
211
|
-
else {
|
|
212
|
-
lCore.display('Returns an information exception: ' + str);
|
|
213
|
-
}
|
|
214
|
-
process.exit();
|
|
215
|
-
});
|
|
216
|
-
}).on('error', function() {
|
|
217
|
-
lCore.display('RPC Server Error.');
|
|
218
|
-
}).end();
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
run().catch(function(e): void {
|
|
223
|
-
lCore.display('[cmd] ------ [Process fatal Error] ------');
|
|
224
|
-
lCore.display(e);
|
|
225
|
-
});
|