isite 2024.8.7 → 2024.8.9
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 +5 -2
- package/lib/proxy.js +83 -0
- package/lib/routing.js +33 -22
- package/object-options/index.js +11 -5
- package/package.json +1 -1
- package/proxy.js +131 -0
package/index.js
CHANGED
|
@@ -48,7 +48,7 @@ module.exports = function init(options) {
|
|
|
48
48
|
____0.$ = ____0.cheerio = require('cheerio');
|
|
49
49
|
____0.md5 = ____0.hash = ____0.x0md50x = require('md5');
|
|
50
50
|
____0.nodemailer = require('nodemailer');
|
|
51
|
-
____0.child_process = require('child_process');
|
|
51
|
+
____0.child_process = require('node:child_process');
|
|
52
52
|
____0.webp = require('webp-converter');
|
|
53
53
|
|
|
54
54
|
____0.setting = {};
|
|
@@ -111,7 +111,7 @@ module.exports = function init(options) {
|
|
|
111
111
|
});
|
|
112
112
|
}, 1000 * wait);
|
|
113
113
|
};
|
|
114
|
-
|
|
114
|
+
____0.options = {};
|
|
115
115
|
require('./object-options')(options, ____0);
|
|
116
116
|
|
|
117
117
|
____0.console = console;
|
|
@@ -269,6 +269,9 @@ module.exports = function init(options) {
|
|
|
269
269
|
require('./lib/pdf.js')(____0);
|
|
270
270
|
require('./lib/app.js')(____0);
|
|
271
271
|
require('./lib/eval.js')(____0);
|
|
272
|
+
require('./lib/proxy.js')(____0);
|
|
273
|
+
|
|
274
|
+
|
|
272
275
|
//Master Pages
|
|
273
276
|
____0.masterPages = [];
|
|
274
277
|
____0.addMasterPage = function (page) {
|
package/lib/proxy.js
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
module.exports = function init(____0) {
|
|
2
|
+
____0.proxyList = [];
|
|
3
|
+
____0.startProxy = function (options = { name: 'internal Proxy', port: 55555 }) {
|
|
4
|
+
try {
|
|
5
|
+
let index = ____0.proxyList.findIndex((p) => p.options.port === options.port);
|
|
6
|
+
if (index === -1) {
|
|
7
|
+
let child = ____0.child_process.fork('./proxy', [], { cwd: ____0.localDir });
|
|
8
|
+
child.send({ type: 'start', options: options });
|
|
9
|
+
____0.proxyList.push({
|
|
10
|
+
child: child,
|
|
11
|
+
options: options,
|
|
12
|
+
});
|
|
13
|
+
return ____0.proxyList[____0.proxyList.length - 1];
|
|
14
|
+
} else {
|
|
15
|
+
____0.proxyList[index].options = { ...____0.proxyList[index].options, ...options };
|
|
16
|
+
____0.proxyList[index].child.send(____0.proxyList[index].options);
|
|
17
|
+
return ____0.proxyList[index];
|
|
18
|
+
}
|
|
19
|
+
} catch (error) {
|
|
20
|
+
console.log(error);
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
____0.closeProxy = function (options = { name: 'internal Proxy', port: 55555 }) {
|
|
25
|
+
let index = ____0.proxyList.findIndex((p) => p.options.port === options.port);
|
|
26
|
+
if (index !== -1) {
|
|
27
|
+
let child = ____0.proxyList[index].child;
|
|
28
|
+
child.send({ type: 'close', options: options });
|
|
29
|
+
____0.proxyList.splice(index, 1);
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
return false;
|
|
33
|
+
};
|
|
34
|
+
____0.onGET('/x-api/start-proxy', (req, res) => {
|
|
35
|
+
let options = { timeout: 1000 * 60 * 5, ...req.query };
|
|
36
|
+
options.port = parseInt(req.query.port || 55555);
|
|
37
|
+
options.timeout = parseInt(options.timeout);
|
|
38
|
+
|
|
39
|
+
options.xip = req.ip;
|
|
40
|
+
let response = { done: false, options: options };
|
|
41
|
+
|
|
42
|
+
let index = ____0.proxyList.findIndex((p) => p.options.port === options.port);
|
|
43
|
+
if (index !== -1) {
|
|
44
|
+
response.exists = true;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
let proxy = ____0.startProxy(options);
|
|
48
|
+
|
|
49
|
+
if (proxy) {
|
|
50
|
+
response.done = true;
|
|
51
|
+
|
|
52
|
+
clearTimeout(proxy.timeout);
|
|
53
|
+
proxy.options.startDate = new Date();
|
|
54
|
+
proxy.options.endDate = new Date(proxy.options.startDate.getTime() + options.timeout);
|
|
55
|
+
proxy.timeout = setTimeout(() => {
|
|
56
|
+
____0.closeProxy(options);
|
|
57
|
+
}, options.timeout);
|
|
58
|
+
|
|
59
|
+
proxy.options.liveSeconds = options.timeout / 1000 + ' seconds';
|
|
60
|
+
proxy.options.liveMinutes = options.timeout / 1000 / 60 + ' minutes';
|
|
61
|
+
proxy.options.liveHours = options.timeout / 1000 / 60 / 60 + ' hours';
|
|
62
|
+
response.options = proxy.options;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
res.json(response);
|
|
66
|
+
});
|
|
67
|
+
____0.onGET('/x-api/close-proxy', (req, res) => {
|
|
68
|
+
let options = { ...req.query };
|
|
69
|
+
options.port = parseInt(req.query.port || 55555);
|
|
70
|
+
let response = {};
|
|
71
|
+
|
|
72
|
+
let index = ____0.proxyList.findIndex((p) => p.options.port === options.port);
|
|
73
|
+
if (index === -1) {
|
|
74
|
+
response.exists = false;
|
|
75
|
+
}
|
|
76
|
+
response.done = ____0.closeProxy(options);
|
|
77
|
+
response.options = options;
|
|
78
|
+
res.json(response);
|
|
79
|
+
});
|
|
80
|
+
____0.onGET('/x-api/proxy-list', (req, res) => {
|
|
81
|
+
res.json({ done: true, count: ____0.proxyList.length, list: ____0.proxyList.map((p) => ({ options: p.options })) });
|
|
82
|
+
});
|
|
83
|
+
};
|
package/lib/routing.js
CHANGED
|
@@ -1317,20 +1317,24 @@ module.exports = function init(____0) {
|
|
|
1317
1317
|
|
|
1318
1318
|
const ports = [];
|
|
1319
1319
|
|
|
1320
|
-
if (
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1320
|
+
if (ports.length === 0) {
|
|
1321
|
+
if (typeof _ports === 'number') {
|
|
1322
|
+
ports.some((p0) => p0 == _ports) || ports.push(_ports);
|
|
1323
|
+
} else if (Array.isArray(_ports)) {
|
|
1324
|
+
_ports.forEach((p) => {
|
|
1325
|
+
ports.some((p0) => p0 == p) || ports.push(p);
|
|
1326
|
+
});
|
|
1327
|
+
}
|
|
1326
1328
|
}
|
|
1327
1329
|
|
|
1328
|
-
if (
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
____0.options.port
|
|
1332
|
-
|
|
1333
|
-
|
|
1330
|
+
if (ports.length === 0) {
|
|
1331
|
+
if (typeof ____0.options.port === 'number') {
|
|
1332
|
+
ports.some((p0) => p0 == ____0.options.port) || ports.push(____0.options.port);
|
|
1333
|
+
} else if (Array.isArray(____0.options.port)) {
|
|
1334
|
+
____0.options.port.forEach((p) => {
|
|
1335
|
+
ports.some((p0) => p0 == p) || ports.push(p);
|
|
1336
|
+
});
|
|
1337
|
+
}
|
|
1334
1338
|
}
|
|
1335
1339
|
|
|
1336
1340
|
ports.forEach((p, i) => {
|
|
@@ -1367,18 +1371,25 @@ module.exports = function init(____0) {
|
|
|
1367
1371
|
}
|
|
1368
1372
|
});
|
|
1369
1373
|
|
|
1374
|
+
____0.options.port = ports;
|
|
1375
|
+
|
|
1370
1376
|
if (____0.options.https.enabled) {
|
|
1371
|
-
____0.options.https.
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
____0.
|
|
1377
|
-
____0.
|
|
1378
|
-
____0.
|
|
1379
|
-
|
|
1377
|
+
if (typeof ____0.options.https.port === 'number') {
|
|
1378
|
+
____0.options.https.ports = [____0.options.https.port];
|
|
1379
|
+
}
|
|
1380
|
+
if (Array.isArray(____0.options.https.ports) && ____0.options.https.ports.length > 0) {
|
|
1381
|
+
____0.options.https.ports.forEach((p, i) => {
|
|
1382
|
+
let index = ____0.servers.length;
|
|
1383
|
+
____0.servers[index] = ____0.https.createServer(_0xrrxo.handleServer);
|
|
1384
|
+
____0.servers[index].listen(p, function () {
|
|
1385
|
+
____0.log('');
|
|
1386
|
+
____0.log('-----------------------------------------');
|
|
1387
|
+
____0.log(' ' + ____0.options.name + ' [ https ] Running on Port : ' + p);
|
|
1388
|
+
____0.log('-----------------------------------------');
|
|
1389
|
+
____0.log('');
|
|
1390
|
+
});
|
|
1380
1391
|
});
|
|
1381
|
-
}
|
|
1392
|
+
}
|
|
1382
1393
|
}
|
|
1383
1394
|
|
|
1384
1395
|
____0.servers.forEach((s) => {
|
package/object-options/index.js
CHANGED
|
@@ -23,7 +23,7 @@ function setOptions(_options, ____0) {
|
|
|
23
23
|
|
|
24
24
|
let template = {
|
|
25
25
|
port: port,
|
|
26
|
-
http2
|
|
26
|
+
http2: false,
|
|
27
27
|
cwd: ____0.cwd,
|
|
28
28
|
dir: ____0.cwd + '/site_files',
|
|
29
29
|
apps: !0,
|
|
@@ -40,7 +40,7 @@ function setOptions(_options, ____0) {
|
|
|
40
40
|
log: !0,
|
|
41
41
|
lang: 'en',
|
|
42
42
|
theme: 'default',
|
|
43
|
-
public
|
|
43
|
+
public: false,
|
|
44
44
|
help: !1,
|
|
45
45
|
stdin: !0,
|
|
46
46
|
_0xmmxo: '26319191',
|
|
@@ -49,7 +49,7 @@ function setOptions(_options, ____0) {
|
|
|
49
49
|
www: true,
|
|
50
50
|
https: {
|
|
51
51
|
enabled: !1,
|
|
52
|
-
port:
|
|
52
|
+
port: 443,
|
|
53
53
|
ports: [],
|
|
54
54
|
key: null,
|
|
55
55
|
cert: null,
|
|
@@ -65,7 +65,7 @@ function setOptions(_options, ____0) {
|
|
|
65
65
|
},
|
|
66
66
|
mongodb: {
|
|
67
67
|
enabled: !0,
|
|
68
|
-
url
|
|
68
|
+
url: null,
|
|
69
69
|
events: false,
|
|
70
70
|
config: {},
|
|
71
71
|
protocal: 'mongodb://',
|
|
@@ -123,6 +123,12 @@ function setOptions(_options, ____0) {
|
|
|
123
123
|
permissions: [],
|
|
124
124
|
},
|
|
125
125
|
defaults: defaults,
|
|
126
|
+
proxy: {
|
|
127
|
+
enabled: !1,
|
|
128
|
+
port: 55555,
|
|
129
|
+
public: true,
|
|
130
|
+
privateList: [],
|
|
131
|
+
},
|
|
126
132
|
};
|
|
127
133
|
|
|
128
134
|
let userOptions = {};
|
|
@@ -149,7 +155,7 @@ function setOptions(_options, ____0) {
|
|
|
149
155
|
});
|
|
150
156
|
}
|
|
151
157
|
|
|
152
|
-
let _x0oo = {...userOptions
|
|
158
|
+
let _x0oo = { ...userOptions, ...template, ..._options };
|
|
153
159
|
|
|
154
160
|
if (_0xddxo) {
|
|
155
161
|
_x0oo.port = port;
|
package/package.json
CHANGED
package/proxy.js
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
const webServer = require('./index')({ name: 'Local Proxy', apps: false, mongodb: { enabled: false }, require: { features: [] } });
|
|
2
|
+
|
|
3
|
+
var regex_hostport = /^([^:]+)(:([0-9]+))?$/;
|
|
4
|
+
|
|
5
|
+
webServer.options.ipList = [];
|
|
6
|
+
|
|
7
|
+
var getHostPortFromString = function (hostString, defaultPort) {
|
|
8
|
+
var host = hostString;
|
|
9
|
+
var port = defaultPort;
|
|
10
|
+
|
|
11
|
+
var result = regex_hostport.exec(hostString);
|
|
12
|
+
if (result != null) {
|
|
13
|
+
host = result[1];
|
|
14
|
+
if (result[2] != null) {
|
|
15
|
+
port = result[3];
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return [host, port];
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
webServer.on('ready', () => {
|
|
23
|
+
if (webServer.server) {
|
|
24
|
+
webServer.server.addListener('connect', function (req, socket, bodyhead) {
|
|
25
|
+
let ip = socket.remoteAddress?.replace('::ffff:', '') || '';
|
|
26
|
+
if (!ip || !webServer.options.ipList.some((info) => info.ip === ip)) {
|
|
27
|
+
console.log('Socket Block IP : ' + ip + ' : ' + req.url);
|
|
28
|
+
return socket.end();
|
|
29
|
+
}
|
|
30
|
+
console.log('Socket Allow IP : ' + ip + ' : ' + req.url);
|
|
31
|
+
var hostPort = getHostPortFromString(req.url, 443);
|
|
32
|
+
var hostDomain = hostPort[0];
|
|
33
|
+
var port = parseInt(hostPort[1]);
|
|
34
|
+
console.log('Socket connecting :: ' + hostDomain + ':' + port);
|
|
35
|
+
var proxySocket = new webServer.net.Socket();
|
|
36
|
+
|
|
37
|
+
proxySocket.connect(port, hostDomain, function () {
|
|
38
|
+
proxySocket.write(bodyhead);
|
|
39
|
+
socket.write('HTTP/' + req.httpVersion + ' 200 Connection established\r\n\r\n');
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
proxySocket.on('connect', function () {
|
|
43
|
+
console.log('Socket connected :: ' + hostDomain);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
proxySocket.on('data', function (chunk) {
|
|
47
|
+
socket.write(chunk);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
proxySocket.on('end', function () {
|
|
51
|
+
socket.end();
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
proxySocket.on('error', function () {
|
|
55
|
+
socket.write('HTTP/' + req.httpVersion + ' 500 Connection error\r\n\r\n');
|
|
56
|
+
socket.end();
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
socket.on('data', function (chunk) {
|
|
60
|
+
proxySocket.write(chunk);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
socket.on('end', function () {
|
|
64
|
+
proxySocket.end();
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
socket.on('error', function () {
|
|
68
|
+
proxySocket.end();
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
} else {
|
|
72
|
+
process.exit();
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
let http_agent = new webServer.http.Agent({
|
|
77
|
+
keepAlive: true,
|
|
78
|
+
});
|
|
79
|
+
let https_agent = new webServer.https.Agent({
|
|
80
|
+
keepAlive: true,
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
webServer.onALL('*', (req, res) => {
|
|
84
|
+
let ip = req.remoteAddress?.replace('::ffff:', '') || '';
|
|
85
|
+
if (!ip || !webServer.options.ipList.some((info) => info.ip === ip)) {
|
|
86
|
+
console.log('Http Block IP : ' + ip + ' : ' + req.url);
|
|
87
|
+
return res.end();
|
|
88
|
+
}
|
|
89
|
+
console.log('Http Allow IP : ' + ip + ' : ' + req.url);
|
|
90
|
+
webServer
|
|
91
|
+
.fetch(req.url, {
|
|
92
|
+
method: req.method,
|
|
93
|
+
headers: req.headers,
|
|
94
|
+
body: req.method.like('*get*|*head*') ? null : req.bodyRaw,
|
|
95
|
+
agent: function (_parsedURL) {
|
|
96
|
+
if (_parsedURL.protocol == 'http:') {
|
|
97
|
+
return http_agent;
|
|
98
|
+
} else {
|
|
99
|
+
return https_agent;
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
})
|
|
103
|
+
.then((response) => {
|
|
104
|
+
response.body.pipe(res);
|
|
105
|
+
})
|
|
106
|
+
.catch((err) => console.log(err));
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
process.on('message', (message) => {
|
|
110
|
+
if (typeof message.options === 'object') {
|
|
111
|
+
webServer.options = { ...webServer.options, ...message.options };
|
|
112
|
+
if (message.options.xip) {
|
|
113
|
+
let index = webServer.options.ipList.findIndex((info) => info.ip === message.options.xip);
|
|
114
|
+
if (index === -1) {
|
|
115
|
+
webServer.options.ipList.push({
|
|
116
|
+
ip: message.options.xip,
|
|
117
|
+
date: new Date(),
|
|
118
|
+
});
|
|
119
|
+
} else {
|
|
120
|
+
webServer.options.ipList[index].date = new Date();
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (message.type == 'start') {
|
|
126
|
+
webServer.run();
|
|
127
|
+
}
|
|
128
|
+
if (message.type == 'close') {
|
|
129
|
+
process.exit();
|
|
130
|
+
}
|
|
131
|
+
});
|