tanyu_admin 1.0.1
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/.dockerignore +16 -0
- package/.github/workflows/docker-build.yml +52 -0
- package/CLAUDE.md +85 -0
- package/DEPLOY.md +367 -0
- package/Dockerfile +27 -0
- package/archive/dataCrypto.js +124 -0
- package/archive/delte.js +29 -0
- package/archive/edit.js +29 -0
- package/axios-interceptor-example.js +57 -0
- package/axios-interceptor.js +191 -0
- package/cli.js +313 -0
- package/design-output.txt +5 -0
- package/design-system/virtual-host-management/MASTER.md +202 -0
- package/design-system-output.md +5 -0
- package/design-system-result.md +50 -0
- package/design-system.md +0 -0
- package/docker-compose.yml +18 -0
- package/index.js +404 -0
- package/jsencrypt.min.js +2 -0
- package/modem-api.js +419 -0
- package/package.json +42 -0
- package/parser.js +146 -0
- package/public/index.html +656 -0
- package/readme.md +1 -0
- package/server.js +268 -0
- package/test.js +7 -0
package/server.js
ADDED
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
const express = require('express');
|
|
2
|
+
const cors = require('cors');
|
|
3
|
+
const path = require('path');
|
|
4
|
+
const { saveConfigToJson, loadConfigFromFile } = require('./parser');
|
|
5
|
+
const { addHost, updateHost, deleteHost, refreshFromModem } = require('./modem-api');
|
|
6
|
+
|
|
7
|
+
const app = express();
|
|
8
|
+
const PORT = 3000;
|
|
9
|
+
|
|
10
|
+
// 中间件
|
|
11
|
+
app.use(cors());
|
|
12
|
+
app.use(express.json());
|
|
13
|
+
app.use(express.static('public'));
|
|
14
|
+
|
|
15
|
+
// 数据文件路径
|
|
16
|
+
const DATA_FILE = './virtual_hosts.json';
|
|
17
|
+
const CACHE_DIR = './.cache';
|
|
18
|
+
const CACHE_HTML = path.join(CACHE_DIR, 'page.html');
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* 获取所有虚拟主机配置(从光猫实时获取)
|
|
22
|
+
*/
|
|
23
|
+
app.get('/api/hosts', async (req, res) => {
|
|
24
|
+
try {
|
|
25
|
+
const refreshResult = await refreshFromModem();
|
|
26
|
+
|
|
27
|
+
if (refreshResult.success) {
|
|
28
|
+
const fs = require('fs');
|
|
29
|
+
// 确保 .cache 目录存在
|
|
30
|
+
if (!fs.existsSync(CACHE_DIR)) {
|
|
31
|
+
fs.mkdirSync(CACHE_DIR, { recursive: true });
|
|
32
|
+
}
|
|
33
|
+
fs.writeFileSync(CACHE_HTML, refreshResult.html);
|
|
34
|
+
const configs = loadConfigFromFile(CACHE_HTML);
|
|
35
|
+
// 同步保存到本地
|
|
36
|
+
saveConfigToJson(configs, DATA_FILE);
|
|
37
|
+
|
|
38
|
+
res.json({
|
|
39
|
+
success: true,
|
|
40
|
+
data: configs,
|
|
41
|
+
total: configs.length
|
|
42
|
+
});
|
|
43
|
+
} else {
|
|
44
|
+
res.status(500).json({
|
|
45
|
+
success: false,
|
|
46
|
+
message: '获取配置失败',
|
|
47
|
+
error: refreshResult.error
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
} catch (error) {
|
|
51
|
+
res.status(500).json({
|
|
52
|
+
success: false,
|
|
53
|
+
message: '获取配置失败',
|
|
54
|
+
error: error.message
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* 获取单个虚拟主机配置(从光猫实时获取)
|
|
61
|
+
*/
|
|
62
|
+
app.get('/api/hosts/:id', async (req, res) => {
|
|
63
|
+
try {
|
|
64
|
+
const refreshResult = await refreshFromModem();
|
|
65
|
+
|
|
66
|
+
if (refreshResult.success) {
|
|
67
|
+
const fs = require('fs');
|
|
68
|
+
fs.writeFileSync('./page.html', refreshResult.html);
|
|
69
|
+
const configs = loadConfigFromFile('./page.html');
|
|
70
|
+
const host = configs.find(h => h.index === parseInt(req.params.id));
|
|
71
|
+
|
|
72
|
+
if (host) {
|
|
73
|
+
res.json({
|
|
74
|
+
success: true,
|
|
75
|
+
data: host
|
|
76
|
+
});
|
|
77
|
+
} else {
|
|
78
|
+
res.status(404).json({
|
|
79
|
+
success: false,
|
|
80
|
+
message: '配置不存在'
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
} else {
|
|
84
|
+
res.status(500).json({
|
|
85
|
+
success: false,
|
|
86
|
+
message: '获取配置失败',
|
|
87
|
+
error: refreshResult.error
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
} catch (error) {
|
|
91
|
+
res.status(500).json({
|
|
92
|
+
success: false,
|
|
93
|
+
message: '获取配置失败',
|
|
94
|
+
error: error.message
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* 新增虚拟主机配置
|
|
101
|
+
*/
|
|
102
|
+
app.post('/api/hosts', async (req, res) => {
|
|
103
|
+
try {
|
|
104
|
+
const newHost = req.body;
|
|
105
|
+
|
|
106
|
+
// 设置默认值
|
|
107
|
+
newHost.Enable = newHost.Enable || '1';
|
|
108
|
+
newHost.Protocol = newHost.Protocol || '2';
|
|
109
|
+
|
|
110
|
+
// 提交到光猫
|
|
111
|
+
console.log('正在向光猫添加配置:', newHost.Name);
|
|
112
|
+
const result = await addHost(newHost);
|
|
113
|
+
|
|
114
|
+
if (result.success) {
|
|
115
|
+
// 使用返回的 HTML 数据,避免重复请求
|
|
116
|
+
if (result.html) {
|
|
117
|
+
const fs = require('fs');
|
|
118
|
+
fs.writeFileSync('./page.html', result.html);
|
|
119
|
+
const configs = loadConfigFromFile('./page.html');
|
|
120
|
+
saveConfigToJson(configs, DATA_FILE);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
res.json({
|
|
124
|
+
success: true,
|
|
125
|
+
message: '添加成功',
|
|
126
|
+
data: newHost
|
|
127
|
+
});
|
|
128
|
+
} else {
|
|
129
|
+
res.status(500).json({
|
|
130
|
+
success: false,
|
|
131
|
+
message: '添加失败: ' + result.error
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
} catch (error) {
|
|
135
|
+
res.status(500).json({
|
|
136
|
+
success: false,
|
|
137
|
+
message: '添加失败',
|
|
138
|
+
error: error.message
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* 更新虚拟主机配置
|
|
145
|
+
*/
|
|
146
|
+
app.put('/api/hosts/:id', async (req, res) => {
|
|
147
|
+
try {
|
|
148
|
+
const hostId = parseInt(req.params.id);
|
|
149
|
+
const updatedHost = req.body;
|
|
150
|
+
|
|
151
|
+
// 提交到光猫
|
|
152
|
+
console.log('正在向光猫更新配置:', updatedHost.Name);
|
|
153
|
+
const result = await updateHost(updatedHost, hostId);
|
|
154
|
+
|
|
155
|
+
if (result.success) {
|
|
156
|
+
// 使用返回的 HTML 数据,避免重复请求
|
|
157
|
+
if (result.html) {
|
|
158
|
+
const fs = require('fs');
|
|
159
|
+
fs.writeFileSync('./page.html', result.html);
|
|
160
|
+
const configs = loadConfigFromFile('./page.html');
|
|
161
|
+
saveConfigToJson(configs, DATA_FILE);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
res.json({
|
|
165
|
+
success: true,
|
|
166
|
+
message: '更新成功',
|
|
167
|
+
data: updatedHost
|
|
168
|
+
});
|
|
169
|
+
} else {
|
|
170
|
+
res.status(500).json({
|
|
171
|
+
success: false,
|
|
172
|
+
message: '更新失败: ' + result.error
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
} catch (error) {
|
|
176
|
+
res.status(500).json({
|
|
177
|
+
success: false,
|
|
178
|
+
message: '更新失败',
|
|
179
|
+
error: error.message
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* 删除虚拟主机配置
|
|
186
|
+
*/
|
|
187
|
+
app.delete('/api/hosts/:id', async (req, res) => {
|
|
188
|
+
try {
|
|
189
|
+
const hostId = parseInt(req.params.id);
|
|
190
|
+
|
|
191
|
+
// 提交到光猫
|
|
192
|
+
console.log('正在从光猫删除配置,索引:', hostId);
|
|
193
|
+
const result = await deleteHost(hostId);
|
|
194
|
+
|
|
195
|
+
if (result.success) {
|
|
196
|
+
// 使用返回的 HTML 数据,避免重复请求
|
|
197
|
+
if (result.html) {
|
|
198
|
+
const fs = require('fs');
|
|
199
|
+
fs.writeFileSync('./page.html', result.html);
|
|
200
|
+
const configs = loadConfigFromFile('./page.html');
|
|
201
|
+
saveConfigToJson(configs, DATA_FILE);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
res.json({
|
|
205
|
+
success: true,
|
|
206
|
+
message: '删除成功'
|
|
207
|
+
});
|
|
208
|
+
} else {
|
|
209
|
+
res.status(500).json({
|
|
210
|
+
success: false,
|
|
211
|
+
message: '删除失败: ' + result.error
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
} catch (error) {
|
|
215
|
+
res.status(500).json({
|
|
216
|
+
success: false,
|
|
217
|
+
message: '删除失败',
|
|
218
|
+
error: error.message
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* 从光猫刷新配置
|
|
225
|
+
*/
|
|
226
|
+
app.post('/api/hosts/refresh', async (req, res) => {
|
|
227
|
+
try {
|
|
228
|
+
console.log('正在从光猫刷新配置...');
|
|
229
|
+
const refreshResult = await refreshFromModem();
|
|
230
|
+
|
|
231
|
+
if (refreshResult.success) {
|
|
232
|
+
const fs = require('fs');
|
|
233
|
+
fs.writeFileSync('./page.html', refreshResult.html);
|
|
234
|
+
const configs = loadConfigFromFile('./page.html');
|
|
235
|
+
saveConfigToJson(configs, DATA_FILE);
|
|
236
|
+
|
|
237
|
+
res.json({
|
|
238
|
+
success: true,
|
|
239
|
+
message: '刷新成功',
|
|
240
|
+
data: configs,
|
|
241
|
+
total: configs.length
|
|
242
|
+
});
|
|
243
|
+
} else {
|
|
244
|
+
res.status(500).json({
|
|
245
|
+
success: false,
|
|
246
|
+
message: '刷新失败: ' + refreshResult.error
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
} catch (error) {
|
|
250
|
+
res.status(500).json({
|
|
251
|
+
success: false,
|
|
252
|
+
message: '刷新失败',
|
|
253
|
+
error: error.message
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
// 启动服务器
|
|
259
|
+
app.listen(PORT, () => {
|
|
260
|
+
console.log(`=== 虚拟主机管理系统 ===`);
|
|
261
|
+
console.log(`服务器运行在: http://localhost:${PORT}`);
|
|
262
|
+
console.log(`API接口:`);
|
|
263
|
+
console.log(` GET /api/hosts - 获取所有配置`);
|
|
264
|
+
console.log(` GET /api/hosts/:id - 获取单个配置`);
|
|
265
|
+
console.log(` POST /api/hosts - 新增配置`);
|
|
266
|
+
console.log(` PUT /api/hosts/:id - 更新配置`);
|
|
267
|
+
console.log(` DELETE /api/hosts/:id - 删除配置`);
|
|
268
|
+
});
|
package/test.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
const { encodeKey,pubKey,encodePara } = require('./modem-api');
|
|
2
|
+
|
|
3
|
+
let data='ViewName=NULL&WANCViewName=IGD.WD1.WCD2.WCPPP1&WANCName=NULL&Enable=1&Protocol=2&Name=%E8%BF%9C%E7%A8%8B12&MinExtPort=6565&MaxExtPort=6565&InternalHost=192.168.1.17&MinIntPort=6565&MaxIntPort=6565&Description=NULL&LeaseDuration=NULL&PortMappCreator=NULL&MinRemoteHost=0.0.0.0&MaxRemoteHost=0.0.0.0&InternalMacHost=NULL&MacEnable=0&IF_ACTION=apply&IF_ERRORSTR=SUCC&IF_ERRORPARAM=SUCC&IF_ERRORTYPE=-1&IF_INDEX=2&IF_INSTNUM=10&ViewName0=IGD.WD1.WCD2.WCPPP1.FWPM1&WANCViewName0=IGD.WD1.WCD2.WCPPP1&WANCName0=2_INTERNET_R_VID_637&Enable0=1&Protocol0=2&Name0=%E8%B7%AF%E7%94%B1%E5%99%A8&MinExtPort0=5700&MaxExtPort0=5700&InternalHost0=192.168.1.125&MinIntPort0=5700&MaxIntPort0=5700&Description0=&LeaseDuration0=0&PortMappCreator0=&MinRemoteHost0=0.0.0.0&MaxRemoteHost0=0.0.0.0&InternalMacHost0=e0%3Ab6%3A68%3A2e%3A2d%3A5b&MacEnable0=0&WANCName0=&ViewName1=IGD.WD1.WCD2.WCPPP1.FWPM2&WANCViewName1=IGD.WD1.WCD2.WCPPP1&WANCName1=2_INTERNET_R_VID_637&Enable1=1&Protocol1=2&Name1=route&MinExtPort1=23831&MaxExtPort1=23831&InternalHost1=192.168.1.125&MinIntPort1=23831&MaxIntPort1=23831&Description1=&LeaseDuration1=0&PortMappCreator1=&MinRemoteHost1=0.0.0.0&MaxRemoteHost1=0.0.0.0&InternalMacHost1=d8%3Ac8%3Ae9%3A1b%3A0a%3A79&MacEnable1=0&WANCName1=&ViewName2=IGD.WD1.WCD2.WCPPP1.FWPM3&WANCViewName2=IGD.WD1.WCD2.WCPPP1&WANCName2=2_INTERNET_R_VID_637&Enable2=1&Protocol2=2&Name2=%E8%BF%9C%E7%A8%8B1&MinExtPort2=6565&MaxExtPort2=6565&InternalHost2=192.168.1.17&MinIntPort2=6565&MaxIntPort2=6565&Description2=&LeaseDuration2=0&PortMappCreator2=&MinRemoteHost2=0.0.0.0&MaxRemoteHost2=0.0.0.0&InternalMacHost2=c8%3A7f%3A54%3A70%3Aee%3Abc&MacEnable2=0&WANCName2=&ViewName3=IGD.WD1.WCD2.WCPPP1.FWPM4&WANCViewName3=IGD.WD1.WCD2.WCPPP1&WANCName3=2_INTERNET_R_VID_637&Enable3=1&Protocol3=0&Name3=tv&MinExtPort3=4567&MaxExtPort3=4567&InternalHost3=192.168.1.125&MinIntPort3=4567&MaxIntPort3=4567&Description3=&LeaseDuration3=0&PortMappCreator3=&MinRemoteHost3=0.0.0.0&MaxRemoteHost3=0.0.0.0&InternalMacHost3=00%3A00%3A00%3A00%3A00%3A00&MacEnable3=0&WANCName3=&ViewName4=IGD.WD1.WCD2.WCPPP1.FWPM6&WANCViewName4=IGD.WD1.WCD2.WCPPP1&WANCName4=2_INTERNET_R_VID_637&Enable4=1&Protocol4=0&Name4=panso&MinExtPort4=7123&MaxExtPort4=7123&InternalHost4=192.168.1.125&MinIntPort4=7123&MaxIntPort4=7123&Description4=&LeaseDuration4=0&PortMappCreator4=&MinRemoteHost4=0.0.0.0&MaxRemoteHost4=0.0.0.0&InternalMacHost4=00%3A00%3A00%3A00%3A00%3A00&MacEnable4=0&WANCName4=&ViewName5=IGD.WD1.WCD2.WCPPP1.FWPM7&WANCViewName5=IGD.WD1.WCD2.WCPPP1&WANCName5=2_INTERNET_R_VID_637&Enable5=1&Protocol5=0&Name5=frp&MinExtPort5=7001&MaxExtPort5=7001&InternalHost5=192.168.1.125&MinIntPort5=7001&MaxIntPort5=7001&Description5=&LeaseDuration5=0&PortMappCreator5=&MinRemoteHost5=0.0.0.0&MaxRemoteHost5=0.0.0.0&InternalMacHost5=00%3A00%3A00%3A00%3A00%3A00&MacEnable5=0&WANCName5=&ViewName6=IGD.WD1.WCD2.WCPPP1.FWPM8&WANCViewName6=IGD.WD1.WCD2.WCPPP1&WANCName6=2_INTERNET_R_VID_637&Enable6=1&Protocol6=0&Name6=frp_25000&MinExtPort6=25000&MaxExtPort6=25000&InternalHost6=192.168.1.125&MinIntPort6=25000&MaxIntPort6=25000&Description6=&LeaseDuration6=0&PortMappCreator6=&MinRemoteHost6=0.0.0.0&MaxRemoteHost6=0.0.0.0&InternalMacHost6=00%3A00%3A00%3A00%3A00%3A00&MacEnable6=0&WANCName6=&ViewName7=IGD.WD1.WCD2.WCPPP1.FWPM9&WANCViewName7=IGD.WD1.WCD2.WCPPP1&WANCName7=2_INTERNET_R_VID_637&Enable7=1&Protocol7=0&Name7=v2_33786&MinExtPort7=33786&MaxExtPort7=33786&InternalHost7=192.168.1.125&MinIntPort7=33786&MaxIntPort7=33786&Description7=&LeaseDuration7=0&PortMappCreator7=&MinRemoteHost7=0.0.0.0&MaxRemoteHost7=0.0.0.0&InternalMacHost7=00%3A00%3A00%3A00%3A00%3A00&MacEnable7=0&WANCName7=&ViewName8=IGD.WD1.WCD2.WCPPP1.FWPM10&WANCViewName8=IGD.WD1.WCD2.WCPPP1&WANCName8=2_INTERNET_R_VID_637&Enable8=1&Protocol8=2&Name8=ai&MinExtPort8=7138&MaxExtPort8=7138&InternalHost8=192.168.1.125&MinIntPort8=8317&MaxIntPort8=8317&Description8=&LeaseDuration8=0&PortMappCreator8=&MinRemoteHost8=0.0.0.0&MaxRemoteHost8=0.0.0.0&InternalMacHost8=00%3A00%3A00%3A00%3A00%3A00&MacEnable8=0&WANCName8=&ViewName9=IGD.WD1.WCD2.WCPPP1.FWPM11&WANCViewName9=IGD.WD1.WCD2.WCPPP1&WANCName9=2_INTERNET_R_VID_637&Enable9=1&Protocol9=2&Name9=clash&MinExtPort9=16412&MaxExtPort9=16412&InternalHost9=192.168.1.125&MinIntPort9=16412&MaxIntPort9=16412&Description9=&LeaseDuration9=0&PortMappCreator9=&MinRemoteHost9=0.0.0.0&MaxRemoteHost9=0.0.0.0&InternalMacHost9=00%3A00%3A00%3A00%3A00%3A00&MacEnable9=0&WANCName9=&_SESSION_TOKEN=tEjLD5eD0nozYdZr97Xe177Y'
|
|
4
|
+
// const key = encodeKey(key, iv, pubKey);
|
|
5
|
+
|
|
6
|
+
// console.log(encodePara(data,'9679113177374574','3736537739258096'));
|
|
7
|
+
console.log(encodeKey('5996615615335631','8319705880240059',pubKey))
|