dsh-ops-kit 0.3.8 → 0.4.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/README.md +1 -1
- package/README.zh-CN.md +1 -1
- package/client.js +1683 -141
- package/index.js +1252 -86
- package/locale/en.json +1 -1
- package/locale/zh.json +1 -1
- package/package.json +2 -2
package/client.js
CHANGED
|
@@ -18,10 +18,10 @@ window.__ModuleLoader__.load({
|
|
|
18
18
|
const h = React.createElement
|
|
19
19
|
const PANEL = 'ops-kit'
|
|
20
20
|
|
|
21
|
-
const LABEL = { zh: '
|
|
21
|
+
const LABEL = { zh: 'OPC-运维平台', en: 'OPC Ops' }
|
|
22
22
|
const zh = (typeof navigator !== 'undefined' && String(navigator.language || '').toLowerCase().startsWith('zh'))
|
|
23
23
|
const T = zh ? {
|
|
24
|
-
title: '
|
|
24
|
+
title: 'OPC-运维平台', sub: '看状态、看图表、看配置、管应用 —— 不用敲命令。',
|
|
25
25
|
tabs: ['概览', '监控', '配置', '应用', '排查', '日志', '文件', '终端', '助手', '设置'],
|
|
26
26
|
refresh: '刷新', add: '添加服务器', save: '保存', cancel: '取消',
|
|
27
27
|
name: '名称', host: '地址', user: '用户', key: '私钥(可空)', password: '密码(可空)',
|
|
@@ -29,6 +29,51 @@ window.__ModuleLoader__.load({
|
|
|
29
29
|
cleanup: '清理日志', cleaning: '清理中…', freed: '磁盘已从',
|
|
30
30
|
cpu: 'CPU', mem: '内存', disk: '磁盘', load: '负载',
|
|
31
31
|
check: '体检', remove: '移除', noHosts: '还没有服务器,先点「添加服务器」。',
|
|
32
|
+
onboardTitle: '接入第一台服务器', onboardAdd: '添加服务器',
|
|
33
|
+
uiMode: '界面模式', modeSimple: '简单模式(给非技术同事)', modePro: '专业模式(全部功能)',
|
|
34
|
+
switchToSimple: '切到简单模式', switchToPro: '切到专业模式',
|
|
35
|
+
modeHint: '简单模式只看状态和三个自救按钮,隐藏监控图表、日志、终端、文件等技术页面。',
|
|
36
|
+
simpleSub: '这里只看状态;出问题会提示你,需要技术细节再切到专业模式。',
|
|
37
|
+
simpleReport: '把情况发给开发', reportCopied: '已复制,粘贴发给开发即可',
|
|
38
|
+
restarting: '正在重启网站服务…', checking: '已重启,正在检查…', recovered: '已恢复 ✅', stillBad: '仍然异常,建议联系开发',
|
|
39
|
+
checkingNow: '正在检查…',
|
|
40
|
+
unreachable: '暂时联系不上这台服务器(可能是网络问题),业务状态未知',
|
|
41
|
+
lastChecked: '最近检查', minutesAgo: '分钟前', justNow: '刚刚',
|
|
42
|
+
suggestion: '建议', contactDev: '联系开发', recheckOne: '重新检查这一项', cleanNow: '先清理缓存',
|
|
43
|
+
simpleOk: '运行正常', simpleWarn: '需要留意', simpleBad: '出问题了',
|
|
44
|
+
simpleStorage: '存储空间', storageFull: '已满', storageLow: '即将满', storageOk: '充足',
|
|
45
|
+
simpleService: '业务服务', serviceOkText: '正常', serviceBadText: '有异常', serviceNone: '未配置监控',
|
|
46
|
+
simpleUptime: '稳定运行', simpleChecked: '最近检查',
|
|
47
|
+
simpleActions: '我能做的', actionRecheck: '重新检查', actionClean: '清理旧日志', actionRestartWeb: '重启网站服务',
|
|
48
|
+
cleanDetail: '会做三件事:把 systemd 日志压到最近 200MB、删除 /var/log 下 7 天前的压缩和轮转日志。不会动业务数据、数据库和配置。',
|
|
49
|
+
actionRestartHint: '会短暂中断网站访问约 5 秒',
|
|
50
|
+
recentAlerts: '最近提醒', alertAck: '知道了', acked: '已知悉', noAlerts: '没有新的提醒', simpleWeb: '网站', simpleData: '数据存储',
|
|
51
|
+
fbHint: '遇到问题?', fbCopy: '复制诊断信息', fbCopied: '诊断信息已复制,粘贴发给开发者即可', fdTitle: '【dsh-ops-kit 反馈】',
|
|
52
|
+
fbIssue: '在 GitHub 提 Issue', fbProblem: '问题描述(先写一句你遇到的:点什么、看到什么)',
|
|
53
|
+
auditTitle: '操作记录', auditEmpty: '还没有操作记录',
|
|
54
|
+
onboardSteps: [
|
|
55
|
+
'① 在「设置」里填服务器 IP、SSH 用户(一般是 root)',
|
|
56
|
+
'② 用密码或密钥登录——本机已有密钥的话通常自动可用',
|
|
57
|
+
'③ 点「测试连接」,能通就会出现在概览里',
|
|
58
|
+
],
|
|
59
|
+
onboardNote: '被管理的服务器上不需要安装任何东西。',
|
|
60
|
+
hintMonitor: '看 CPU、内存、磁盘、网络随时间的变化。悬停图表能看具体数值。',
|
|
61
|
+
hintConfig: '只读查看这台机器开着哪些端口、跑着哪些服务。',
|
|
62
|
+
hintApps: '这里列出跑着的服务,可以重启、看日志、看配置文件。',
|
|
63
|
+
hintLogs: '选一个日志来源,只看错误或某个关键字。',
|
|
64
|
+
hintFiles: '像文件管理器一样浏览服务器:上传下载、编辑、改权限、压缩解压。',
|
|
65
|
+
hintTerminal: '直接连上服务器敲命令,和用 SSH 客户端一样。',
|
|
66
|
+
hintBackups: '把数据库或目录打包存在服务器上,需要时一键恢复。',
|
|
67
|
+
hintCron: '让服务器定时执行一条命令,比如每天凌晨备份。',
|
|
68
|
+
hintDeploy: '拉代码 → 构建 → 重启 → 检查,失败自动回滚上一个版本。',
|
|
69
|
+
deployExample: '示例:目录 /opt/app;构建 mvn -q -DskipTests package;重启 systemctl restart app;健康检查 https://你的域名/',
|
|
70
|
+
tipLoad: '过去 1/5/15 分钟的平均任务数,超过 CPU 核数说明在排队',
|
|
71
|
+
tipSwap: '内存不够时借用的磁盘空间,长期偏高说明内存紧张',
|
|
72
|
+
tipTcp: '当前建立的 TCP 连接数',
|
|
73
|
+
tipHealth: '综合磁盘、内存、服务、证书、备份算出的 0-100 分',
|
|
74
|
+
tipKeep: '最多保留几份备份,旧的会自动删除',
|
|
75
|
+
tipPort: '地址:端口,例如 127.0.0.1:3306',
|
|
76
|
+
tipService: '系统服务名,例如 nginx.service',
|
|
32
77
|
hours: '范围', h1: '1 小时', h6: '6 小时', h24: '24 小时', d3: '3 天',
|
|
33
78
|
noData: '还没有采样数据,等下一次巡检(每 5 分钟一次)。',
|
|
34
79
|
ports: '端口', services: '服务', containers: '容器', nginx: '网站', java: 'Java 进程', cron: '定时任务', mounts: '磁盘挂载',
|
|
@@ -45,7 +90,8 @@ window.__ModuleLoader__.load({
|
|
|
45
90
|
test: '测试连接', testing: '测试中…', installKey: '安装公钥', installing: '安装中…',
|
|
46
91
|
connected: '已连接', disconnected: '连不上', latency: '延迟', failures: '连续失败',
|
|
47
92
|
console: '命令控制台', runCmd: '执行', cmdPh: '输入命令,例如 df -h 或 systemctl status nginx',
|
|
48
|
-
terminal: '终端', openTerm: '打开终端', closeTerm: '断开',
|
|
93
|
+
terminal: '终端', openTerm: '打开终端', closeTerm: '断开', reconnect: '重新连接',
|
|
94
|
+
termClosed: '会话已断开(服务器或网络关闭了这次连接)。点「重新连接」恢复。', termHint: '步骤:① 点「打开终端」 ② 点一下黑框 ③ 敲命令,回车执行。支持 Tab 补全、Ctrl+C、方向键。', termNeedPwd: '这个主机没有保存密码,终端需要密码登录;请到设置里编辑主机并填入密码。',
|
|
49
95
|
connecting: '正在连接…', clickConnect: '点这里连接', quickCmds: '常用命令', tip: '连上后黑框里会出现服务器提示符,像用 FinalShell 一样敲命令。',
|
|
50
96
|
aiBar: '用一句话说你想做什么', aiPh: '例如:看看磁盘还剩多少 / 重启 nginx / 查最近 50 行错误日志',
|
|
51
97
|
aiMode: 'AI 模式', aiModeHint: '输入意图后回车:命令会填进终端但不会自动执行;Esc 取消',
|
|
@@ -81,11 +127,22 @@ window.__ModuleLoader__.load({
|
|
|
81
127
|
monInterval: '间隔(分钟)', monAdd: '添加并检查', monCheck: '检查', monRemove: '删除', monEmpty: '还没有监控项,可以加一个心跳检查',
|
|
82
128
|
monHttpHint: 'http:填 URL,如 https://example.com;port:填 host:port;process:填进程关键字;service:填 systemd 单元名',
|
|
83
129
|
monLast: '最近', monNever: '未检查', monEdit: '编辑', monSave: '保存修改', monCancel: '取消',
|
|
130
|
+
monWarn: '警告', monCrit: '严重', monUnknown: '未知(数据过期或未检查)', monStale: '数据过期',
|
|
131
|
+
suggest: '自动发现 → 建议监控', suggestAll: '全部加入', suggestAdd: '加入监控', suggestNone: '没有新的建议(都已经在监控里)',
|
|
132
|
+
maintenance: '维护', maintenanceOn: '维护中,不发送通知', maintenance30: '维护 30 分钟', maintenance120: '维护 2 小时', maintenanceOff: '结束维护',
|
|
133
|
+
ack: '确认', ackHint: '已确认,不再重复通知', mute1h: '静音 1 小时', mutedUntil: '静音到',
|
|
134
|
+
services: '业务服务', serviceNew: '新建业务服务', serviceName: '业务服务名称', serviceEmpty: '还没有业务服务。可以把几个监控合成一个"网站"看。',
|
|
135
|
+
serviceRemove: '删除服务', serviceMembers: '包含监控',
|
|
136
|
+
templates: '监控模板', templateApplyHere: '应用到本机', templateApplyAll: '应用到全部主机', templateSave: '保存当前为模板',
|
|
137
|
+
templateName: '模板名称', templateDelete: '删除模板', templateNone: '还没有模板', templateApplied: '已应用',
|
|
138
|
+
templateCreated: '已创建', templateSkipped: '已存在,跳过',
|
|
139
|
+
monAttempts: '连续失败次数后才告警', monStatus: '状态',
|
|
84
140
|
monOk: '服务正常', monBad: '检查失败', monHint: '排查方向', monDiag: '一键排查', monDiaging: '排查中…',
|
|
85
141
|
monResult: '这次检查结果', monClose: '关闭', monDiagTitle: '排查结果', monChecked: '检查于',
|
|
86
142
|
monPreset: '一键模板', monScript: '脚本(退出码 0 = 正常)', monLanguage: '语言',
|
|
87
143
|
monScriptHint: '脚本在服务器上用对应解释器执行,退出码 0 视为正常;python 需要 python3,js 需要 node。',
|
|
88
144
|
monTypes: [['http', '网站能不能打开'], ['port', '端口通不通'], ['process', '程序还在不在'], ['service', '系统服务在不在'], ['script', '自己写检查脚本']],
|
|
145
|
+
monTypeShort: { http: '网站', port: '端口', process: '进程', service: '服务', script: '脚本' },
|
|
89
146
|
monTypeHint: {
|
|
90
147
|
http: '填网址,例如 https://example.com 或 http://127.0.0.1:8080/health',
|
|
91
148
|
port: '填 地址:端口,例如 127.0.0.1:3306(数据库)、127.0.0.1:6379(缓存)',
|
|
@@ -98,15 +155,43 @@ window.__ModuleLoader__.load({
|
|
|
98
155
|
aiNeedTerm: '先连上终端,生成的命令才会发到服务器', aiModel: '模型',
|
|
99
156
|
process: '进程', byCpu: '按 CPU', byMem: '按内存', pid: 'PID', cpuUse: 'CPU', memUse: '内存', cmd: '命令',
|
|
100
157
|
end: '结束', ending: '结束中…', confirmKill: '结束这个进程?',
|
|
101
|
-
logs: '日志',
|
|
158
|
+
logs: '日志', logGrep: '关键字过滤', logLevel: '级别', logAll: '全部', logErrors: '只看错误', logWarnings: '只看警告',
|
|
159
|
+
logRange: '时间范围', logRangeAll: '全部', logRange5: '最近 5 分钟', logRange60: '最近 1 小时', logRangeDay: '今天',
|
|
160
|
+
logCopy: '复制', logCopied: '已复制', logFiltered: '已按条件过滤', logEmpty: '没有匹配的日志',
|
|
161
|
+
logFrames: '行堆栈', logExpand: '展开', logCollapse: '折叠', logExpandAll: '展开全部', logCollapseAll: '折叠全部',
|
|
162
|
+
logUsage: '日志占用', logJournal: 'systemd 日志', logTotal: '/var/log 合计', logTop: '最大的日志文件',
|
|
163
|
+
cleanPreviewTitle: '选择要清理的日志', cleanJournalRow: 'systemd 日志裁剪', cleanFilesRow: '轮转日志文件',
|
|
164
|
+
cleanSelectAll: '全选', cleanClear: '清空', cleanBackup: '备份选中', cleanBackupDone: '已备份到服务器', cleanDownloadBackup: '下载备份',
|
|
165
|
+
cleanDownloading: '下载中', cleanEta: '剩余约', cleanNothingSelected: '没有选中任何内容',
|
|
166
|
+
loadingPreview: '读取中…', backingUp: '备份中…', loadingList: '加载中…', saved: '已保存',
|
|
167
|
+
ovPreview: '正在读取日志占用和可清理内容…', ovBackup: '正在把选中的日志打包备份…', ovClean: '正在清理选中的日志…',
|
|
168
|
+
cleanColSource: '谁产生的', cleanColFile: '文件', cleanColSize: '大小', cleanColAge: '最后修改', cleanColOwner: '属主',
|
|
169
|
+
cleanWillFree: '预计释放', cleanConfirm: '确认清理', cleanCancel: '取消', cleanImpact: '只删除超过保留期的历史日志;正在写的日志、业务数据、数据库、配置都不动。',
|
|
170
|
+
cleanNothing: '没有需要清理的日志(都在保留期内)', cleanSource: '来源', cleanTimeRange: '时间范围',
|
|
171
|
+
cleanFrom: '最早', cleanAuto: '日志自动清理', cleanAutoOn: '启用(每天定时清理)', cleanAutoAt: '时间',
|
|
172
|
+
cleanAutoMinDisk: '磁盘超过此百分比才清理', cleanGrow: '日志暴涨告警阈值(MB/小时)',
|
|
173
|
+
logPolicy: '清理策略:删除 {0} 天前的轮转日志,systemd 日志压到 {1}MB', logCleanNow: '按策略清理', logCleanResult: '已释放 {0} MB,磁盘 {1}% → {2}%',
|
|
174
|
+
logNoUsage: '正在读取日志占用…', logNoBig: '没有超过 200KB 的普通日志文件,占用主要来自 systemd 日志。', logUsageHint: '小服务器磁盘容易被日志占满;这里能看到是谁占的,按策略清理只删旧日志。',
|
|
175
|
+
logKeepDays: '保留天数', logJournalMb: 'systemd 上限(MB)', logPolicySaved: '已保存',
|
|
176
|
+
logPick: '选择日志来源', logManual: '或手动输入',
|
|
177
|
+
logSource: '日志来源(可下拉选:服务名 / pid:12345 / file:/var/log/x.log)', lines: '行数', load: '读取', auto: '自动刷新(5s)',
|
|
102
178
|
logHint: '不知道填什么?点输入框会弹出下拉列表:systemd 服务(如 nginx.service)、java 进程(pid:12345)、或日志文件(file:/var/log/xxx.log)。选 java 进程时插件自己找日志——属于某个服务就用 journalctl,否则取它打开的最新 .log / .out 文件。',
|
|
103
179
|
logPick: '先选一个来源(点输入框有下拉列表),再点「读取」。',
|
|
104
180
|
ssl: '证书', domain: '域名', checkSsl: '检查证书', daysLeft: '剩余天数', expireAt: '到期', noExpire: '没读到证书',
|
|
181
|
+
fsRefresh: '刷新', fsDownload: '下载', fsNewFolder: '新建文件夹', fsRename: '重命名', fsDelete: '删除',
|
|
182
|
+
fsName: '文件名', fsSize: '大小', fsType: '类型', fsMtime: '修改时间', fsPerm: '权限', fsOwner: '用户/用户组',
|
|
183
|
+
fsEmpty: '这个目录是空的', fsRenamePrompt: '新名称', fsTree: '目录树',
|
|
184
|
+
fsChmod: '权限', fsCompress: '压缩', fsExtract: '解压', fsEdit: '编辑', fsSave: '保存', fsCancel: '取消',
|
|
185
|
+
fsFav: '收藏', fsFavRemove: '取消收藏', fsFavorites: '收藏', fsRecent: '最近访问', fsPreview: '预览',
|
|
186
|
+
fsUploading: '上传中', fsDownloading: '下载中', fsResume: '断点续传', fsTooBig: '文件超过 100 MB,面板不传输',
|
|
187
|
+
fsPreviewClose: '关闭预览', fsImage: '图片预览',
|
|
188
|
+
fsChmodPrompt: '权限(例如 644,或 u+x)', fsArchivePrompt: '压缩包文件名', fsExtractTo: '解压到', fsBinary: '这是二进制文件,不能在面板里编辑',
|
|
189
|
+
fsSelectedCount: '已选', fsEditTitle: '编辑文件', fsBackupNote: '保存前会自动生成 .bak 备份',
|
|
105
190
|
files: '文件', upload: '上传', newFolder: '新建文件夹', size: '大小', modified: '修改时间', open: '进入', download: '下载', del: '删除', folderName: '文件夹名', confirmDel: '删除这个路径?',
|
|
106
191
|
ask: '问一下', diagnose: '智能诊断', diagnosing: '诊断中…', askPh: '例如:网站为什么打不开?',
|
|
107
192
|
askPreset: ['网站为什么打不开?', '磁盘为什么满了?', '最近是不是有点慢?'], findings: '看到的情况', next: '建议动作', timeoutSec: '默认超时(秒)', scanSec: '扫描超时(秒)', actionSec: '操作超时(秒)'
|
|
108
193
|
} : {
|
|
109
|
-
title: 'Ops', sub: 'Status, charts, configuration and apps — no commands.',
|
|
194
|
+
title: 'OPC Ops', sub: 'Status, charts, configuration and apps — no commands.',
|
|
110
195
|
tabs: ['Overview', 'Monitor', 'Config', 'Apps', 'Triage', 'Logs', 'Files', 'Terminal', 'Assistant', 'Settings'],
|
|
111
196
|
refresh: 'Refresh', add: 'Add server', save: 'Save', cancel: 'Cancel',
|
|
112
197
|
name: 'Name', host: 'Address', user: 'User', key: 'Key (optional)', password: 'Password (optional)',
|
|
@@ -130,7 +215,8 @@ window.__ModuleLoader__.load({
|
|
|
130
215
|
test: 'Test', testing: 'Testing…', installKey: 'Install key', installing: 'Installing…',
|
|
131
216
|
connected: 'Connected', disconnected: 'Unreachable', latency: 'latency', failures: 'failures',
|
|
132
217
|
console: 'Command console', runCmd: 'Run', cmdPh: 'Type a command, e.g. df -h',
|
|
133
|
-
terminal: 'Terminal', openTerm: 'Open terminal', closeTerm: 'Disconnect',
|
|
218
|
+
terminal: 'Terminal', openTerm: 'Open terminal', closeTerm: 'Disconnect', reconnect: 'Reconnect',
|
|
219
|
+
termClosed: 'The session closed (server or network dropped it). Use Reconnect.', termHint: 'Steps: 1) Open terminal 2) click the dark box 3) type a command and press Enter. Tab, Ctrl+C and arrows work.', termNeedPwd: 'This host has no stored password; the terminal needs password auth. Edit the host and add one.',
|
|
134
220
|
connecting: 'Connecting…', clickConnect: 'Click to connect', quickCmds: 'Quick commands', tip: 'Once connected the prompt appears; type commands like in a normal SSH client.',
|
|
135
221
|
aiBar: 'Describe what you want to do', aiPh: 'e.g. how much disk is left / restart nginx / last 50 error lines',
|
|
136
222
|
aiMode: 'AI mode', aiModeHint: 'Type the intent and press Enter: the command is filled but not run; Esc cancels',
|
|
@@ -166,11 +252,22 @@ window.__ModuleLoader__.load({
|
|
|
166
252
|
monInterval: 'Interval (min)', monAdd: 'Add and check', monCheck: 'Check', monRemove: 'Remove', monEmpty: 'No monitors yet — add a heartbeat check',
|
|
167
253
|
monHttpHint: 'http: URL like https://example.com; port: host:port; process: pattern; service: systemd unit',
|
|
168
254
|
monLast: 'last', monNever: 'never', monEdit: 'Edit', monSave: 'Save', monCancel: 'Cancel',
|
|
255
|
+
monWarn: 'Warning', monCrit: 'Critical', monUnknown: 'Unknown (stale or never checked)', monStale: 'stale',
|
|
256
|
+
suggest: 'Discovered → suggested monitors', suggestAll: 'Add all', suggestAdd: 'Add', suggestNone: 'Nothing new to add',
|
|
257
|
+
maintenance: 'Maintenance', maintenanceOn: 'In maintenance — no notifications', maintenance30: 'Mute 30 min', maintenance120: 'Mute 2 h', maintenanceOff: 'End maintenance',
|
|
258
|
+
ack: 'Acknowledge', ackHint: 'Acknowledged, no repeat', mute1h: 'Mute 1 h', mutedUntil: 'muted until',
|
|
259
|
+
services: 'Business services', serviceNew: 'New service', serviceName: 'Service name', serviceEmpty: 'No business services yet. Group a few monitors into one "website" state.',
|
|
260
|
+
serviceRemove: 'Remove service', serviceMembers: 'Monitors',
|
|
261
|
+
templates: 'Templates', templateApplyHere: 'Apply here', templateApplyAll: 'Apply to all hosts', templateSave: 'Save as template',
|
|
262
|
+
templateName: 'Template name', templateDelete: 'Delete template', templateNone: 'No templates yet', templateApplied: 'applied',
|
|
263
|
+
templateCreated: 'created', templateSkipped: 'already watched',
|
|
264
|
+
monAttempts: 'Failures before alerting', monStatus: 'Status',
|
|
169
265
|
monOk: 'Healthy', monBad: 'Check failed', monHint: 'Where to look', monDiag: 'Diagnose', monDiaging: 'Diagnosing…',
|
|
170
266
|
monResult: 'Result', monClose: 'Close', monDiagTitle: 'Diagnosis', monChecked: 'checked at',
|
|
171
267
|
monPreset: 'Presets', monScript: 'Script (exit 0 = healthy)', monLanguage: 'Language',
|
|
172
268
|
monScriptHint: 'Runs on the host with the chosen interpreter; exit code 0 means healthy. python needs python3, js needs node.',
|
|
173
269
|
monTypes: [['http', 'Website reachable'], ['port', 'Port open'], ['process', 'Process alive'], ['service', 'System service active'], ['script', 'Custom script']],
|
|
270
|
+
monTypeShort: { http: 'HTTP', port: 'Port', process: 'Process', service: 'Service', script: 'Script' },
|
|
174
271
|
monTypeHint: {
|
|
175
272
|
http: 'URL, e.g. https://example.com',
|
|
176
273
|
port: 'host:port, e.g. 127.0.0.1:3306',
|
|
@@ -183,10 +280,38 @@ window.__ModuleLoader__.load({
|
|
|
183
280
|
aiNeedTerm: 'Connect the terminal first so the command can be sent', aiModel: 'model',
|
|
184
281
|
process: 'Processes', byCpu: 'By CPU', byMem: 'By memory', pid: 'PID', cpuUse: 'CPU', memUse: 'MEM', cmd: 'Command',
|
|
185
282
|
end: 'End', ending: 'Ending…', confirmKill: 'Kill this process?',
|
|
186
|
-
logs: 'Logs',
|
|
283
|
+
logs: 'Logs', logGrep: 'Keyword', logLevel: 'Level', logAll: 'All', logErrors: 'Errors only', logWarnings: 'Warnings only',
|
|
284
|
+
logRange: 'Range', logRangeAll: 'All', logRange5: 'Last 5 min', logRange60: 'Last hour', logRangeDay: 'Today',
|
|
285
|
+
logCopy: 'Copy', logCopied: 'Copied', logFiltered: 'filtered', logEmpty: 'No matching lines',
|
|
286
|
+
logFrames: 'stack lines', logExpand: 'Show', logCollapse: 'Hide', logExpandAll: 'Expand all', logCollapseAll: 'Collapse all',
|
|
287
|
+
logUsage: 'Log usage', logJournal: 'systemd journal', logTotal: '/var/log total', logTop: 'Largest log files',
|
|
288
|
+
cleanPreviewTitle: 'Pick the logs to remove', cleanJournalRow: 'systemd journal trim', cleanFilesRow: 'Rotated log files',
|
|
289
|
+
cleanSelectAll: 'Select all', cleanClear: 'Clear', cleanBackup: 'Back up selected', cleanBackupDone: 'Backed up on the server', cleanDownloadBackup: 'Download backup',
|
|
290
|
+
cleanDownloading: 'Downloading', cleanEta: 'about', cleanNothingSelected: 'Nothing selected',
|
|
291
|
+
loadingPreview: 'Loading…', backingUp: 'Backing up…', loadingList: 'Loading…', saved: 'Saved',
|
|
292
|
+
ovPreview: 'Reading log usage and what can be cleaned…', ovBackup: 'Packing the selected logs…', ovClean: 'Cleaning the selected logs…',
|
|
293
|
+
cleanColSource: 'Produced by', cleanColFile: 'File', cleanColSize: 'Size', cleanColAge: 'Modified', cleanColOwner: 'Owner',
|
|
294
|
+
cleanWillFree: 'Frees about', cleanConfirm: 'Clean now', cleanCancel: 'Cancel', cleanImpact: 'Only logs older than the retention window are removed. Live logs, business data, databases and config are untouched.',
|
|
295
|
+
cleanNothing: 'Nothing to clean — everything is inside the retention window', cleanSource: 'Source', cleanTimeRange: 'Range',
|
|
296
|
+
cleanFrom: 'oldest', cleanAuto: 'Automatic log cleanup', cleanAutoOn: 'Enabled (runs daily)', cleanAutoAt: 'At',
|
|
297
|
+
cleanAutoMinDisk: 'Only when disk is above', cleanGrow: 'Growth alert threshold (MB/hour)',
|
|
298
|
+
logPolicy: 'Cleanup: delete rotated logs older than {0} days, vacuum the journal to {1}MB', logCleanNow: 'Clean by policy', logCleanResult: 'Freed {0} MB, disk {1}% → {2}%',
|
|
299
|
+
logNoUsage: 'Reading log usage…', logNoBig: 'No single log file over 200 KB — the space is mostly the systemd journal.', logUsageHint: 'Small servers fill up with logs; this shows what takes the space, and the cleanup only removes old files.',
|
|
300
|
+
logKeepDays: 'Keep days', logJournalMb: 'Journal cap (MB)', logPolicySaved: 'Saved',
|
|
301
|
+
logPick: 'Pick a source', logManual: 'or type one',
|
|
302
|
+
logSource: 'Log source (pick from the list: unit / pid:12345 / file:/var/log/x.log)', lines: 'Lines', load: 'Load', auto: 'Auto refresh (5s)',
|
|
187
303
|
logHint: 'Not sure what to type? Click the field for a list: a systemd unit (nginx.service), a java process (pid:12345), or a log file (file:/var/log/x.log). For a java process the plugin finds the log itself — journalctl when it belongs to a unit, otherwise the newest .log / .out file it has open.',
|
|
188
304
|
logPick: 'Pick a source first (click the field for the list), then press Load.',
|
|
189
305
|
ssl: 'Certificate', domain: 'Domain', checkSsl: 'Check certificate', daysLeft: 'days left', expireAt: 'expires', noExpire: 'no certificate read',
|
|
306
|
+
fsRefresh: 'Refresh', fsDownload: 'Download', fsNewFolder: 'New folder', fsRename: 'Rename', fsDelete: 'Delete',
|
|
307
|
+
fsName: 'Name', fsSize: 'Size', fsType: 'Type', fsMtime: 'Modified', fsPerm: 'Mode', fsOwner: 'Owner',
|
|
308
|
+
fsEmpty: 'This directory is empty', fsRenamePrompt: 'New name', fsTree: 'Tree',
|
|
309
|
+
fsChmod: 'Mode', fsCompress: 'Compress', fsExtract: 'Extract', fsEdit: 'Edit', fsSave: 'Save', fsCancel: 'Cancel',
|
|
310
|
+
fsFav: 'Favourite', fsFavRemove: 'Unfavourite', fsFavorites: 'Favourites', fsRecent: 'Recent', fsPreview: 'Preview',
|
|
311
|
+
fsUploading: 'Uploading', fsDownloading: 'Downloading', fsResume: 'resumed', fsTooBig: 'File is over 100 MB',
|
|
312
|
+
fsPreviewClose: 'Close preview', fsImage: 'Image preview',
|
|
313
|
+
fsChmodPrompt: 'Mode (644, or u+x)', fsArchivePrompt: 'Archive name', fsExtractTo: 'Extract to', fsBinary: 'Binary file — not editable here',
|
|
314
|
+
fsSelectedCount: 'selected', fsEditTitle: 'Edit file', fsBackupNote: 'A .bak backup is written before saving',
|
|
190
315
|
files: 'Files', upload: 'Upload', newFolder: 'New folder', size: 'Size', modified: 'Modified', open: 'Open', download: 'Download', del: 'Delete', folderName: 'Folder name', confirmDel: 'Delete this path?',
|
|
191
316
|
ask: 'Ask', diagnose: 'Diagnose', diagnosing: 'Diagnosing…', askPh: 'e.g. why is the site down?',
|
|
192
317
|
askPreset: ['Why is the site down?', 'Why is the disk full?', 'Is it slow lately?'], findings: 'What I see', next: 'Suggested actions', timeoutSec: 'Default timeout (s)', scanSec: 'Scan timeout (s)', actionSec: 'Action timeout (s)'
|
|
@@ -211,6 +336,16 @@ window.__ModuleLoader__.load({
|
|
|
211
336
|
.ops-card-b{padding:12px 14px;display:flex;flex-direction:column;gap:10px}
|
|
212
337
|
.ops-dot{width:9px;height:9px;border-radius:50%;display:inline-block;margin-right:6px;background:var(--dsw-alias-text-secondary,#9aa0a6)}
|
|
213
338
|
.ops-dot.ok{background:var(--dsw-alias-success,#4ac97e)}
|
|
339
|
+
.ops-logbox{width:100%;box-sizing:border-box;min-height:220px;max-height:58vh;overflow-y:auto;overflow-x:hidden;background:#0b0e11;border-radius:8px;padding:10px 12px;font-family:ui-monospace,Menlo,monospace;font-size:12px;line-height:1.55;white-space:pre-wrap;overflow-wrap:anywhere;word-break:break-word}
|
|
340
|
+
.ops-busy{text-align:center;padding:26px 18px}
|
|
341
|
+
.ops-spinner{width:26px;height:26px;margin:0 auto;border-radius:50%;border:3px solid var(--dsw-alias-border,#3a3f45);border-top-color:var(--dsw-alias-accent,#4c8dff);animation:ops-spin .8s linear infinite}
|
|
342
|
+
@keyframes ops-spin{to{transform:rotate(360deg)}}
|
|
343
|
+
.ops-log-fold{margin:2px 0 4px 10px;border:0;background:transparent;color:var(--dsw-alias-text-secondary,#9aa0a6);font-size:11px;cursor:pointer;padding:0}
|
|
344
|
+
.ops-log-fold:hover{color:var(--dsw-alias-accent,#4c8dff)}
|
|
345
|
+
.ops-log-frames{border-left:2px solid var(--dsw-alias-border,#3a3f45);margin:2px 0 6px 12px;padding-left:10px;opacity:.8}
|
|
346
|
+
.ops-log-err{color:#ff6b6b}
|
|
347
|
+
.ops-log-warn{color:#e5b650}
|
|
348
|
+
.ops-chart-tip{position:absolute;top:4px;background:var(--dsw-alias-surface,#1d2126);border:1px solid var(--dsw-alias-border,#3a3f45);border-radius:8px;padding:6px 8px;pointer-events:none;z-index:5;white-space:nowrap;box-shadow:0 6px 18px rgba(0,0,0,.35)}
|
|
214
349
|
.ops-dot.warn{background:var(--dsw-alias-warning,#e5b650)}
|
|
215
350
|
.ops-dot.bad{background:var(--dsw-alias-danger,#ff6b6b)}
|
|
216
351
|
.ops-nums{display:grid;grid-template-columns:repeat(3,1fr);gap:8px}
|
|
@@ -254,6 +389,36 @@ window.__ModuleLoader__.load({
|
|
|
254
389
|
.ops-meta{display:flex;gap:8px;align-items:center;font-size:11px;color:var(--dsw-alias-text-secondary,#9aa0a6)}
|
|
255
390
|
.ops-copy{border:0;background:transparent;color:var(--dsw-alias-text-secondary,#9aa0a6);font-size:11px;cursor:pointer;padding:0}
|
|
256
391
|
.ops-copy:hover{color:var(--dsw-alias-text-primary,#e6e6e6)}
|
|
392
|
+
.ops-progress{height:6px;border-radius:3px;background:rgba(255,255,255,.08);overflow:hidden;margin-top:6px}
|
|
393
|
+
.ops-progress i{display:block;height:100%;background:var(--dsw-alias-accent,#4c8dff);transition:width .2s}
|
|
394
|
+
.ops-logbox{width:100%;box-sizing:border-box;min-height:220px;max-height:58vh;overflow-y:auto;overflow-x:hidden;background:#0b0e11;border-radius:8px;padding:10px 12px;font-family:ui-monospace,Menlo,monospace;font-size:12px;line-height:1.55;white-space:pre-wrap;overflow-wrap:anywhere;word-break:break-word}
|
|
395
|
+
.ops-busy{text-align:center;padding:26px 18px}
|
|
396
|
+
.ops-spinner{width:26px;height:26px;margin:0 auto;border-radius:50%;border:3px solid var(--dsw-alias-border,#3a3f45);border-top-color:var(--dsw-alias-accent,#4c8dff);animation:ops-spin .8s linear infinite}
|
|
397
|
+
@keyframes ops-spin{to{transform:rotate(360deg)}}
|
|
398
|
+
.ops-log-fold{margin:2px 0 4px 10px;border:0;background:transparent;color:var(--dsw-alias-text-secondary,#9aa0a6);font-size:11px;cursor:pointer;padding:0}
|
|
399
|
+
.ops-log-fold:hover{color:var(--dsw-alias-accent,#4c8dff)}
|
|
400
|
+
.ops-log-frames{border-left:2px solid var(--dsw-alias-border,#3a3f45);margin:2px 0 6px 12px;padding-left:10px;opacity:.8}
|
|
401
|
+
.ops-log-err{color:#ff6b6b}
|
|
402
|
+
.ops-log-warn{color:#e5b650}
|
|
403
|
+
.ops-chart-tip{position:absolute;top:4px;background:var(--dsw-alias-surface,#1d2126);border:1px solid var(--dsw-alias-border,#3a3f45);border-radius:8px;padding:6px 8px;pointer-events:none;z-index:5;white-space:nowrap;box-shadow:0 6px 18px rgba(0,0,0,.35)}
|
|
404
|
+
.ops-dot.warn{background:#f0b232}
|
|
405
|
+
.ops-dot.unknown{background:#6b7280}
|
|
406
|
+
.ops-fm{display:flex;gap:12px;align-items:flex-start}
|
|
407
|
+
.ops-fm-tree{width:230px;flex:0 0 230px;border:1px solid var(--dsw-alias-border,#3a3f45);border-radius:10px;max-height:64vh;overflow:auto;background:var(--dsw-alias-bg,#16191d)}
|
|
408
|
+
.ops-fm-tree-h{padding:8px 10px;border-bottom:1px solid var(--dsw-alias-border,#3a3f45);font-size:12px;color:var(--dsw-alias-text-secondary,#9aa0a6)}
|
|
409
|
+
.ops-fm-tree-body{padding:6px 0}
|
|
410
|
+
.ops-fm-node{display:flex;align-items:center;gap:4px;padding:3px 8px;font-size:12.5px;cursor:pointer;white-space:nowrap}
|
|
411
|
+
.ops-fm-node:hover{background:rgba(255,255,255,.05)}
|
|
412
|
+
.ops-fm-node.on{background:rgba(76,141,255,.14);color:var(--dsw-alias-accent,#4c8dff)}
|
|
413
|
+
.ops-fm-caret{width:12px;display:inline-block;text-align:center;color:var(--dsw-alias-text-secondary,#9aa0a6)}
|
|
414
|
+
.ops-fm-main{flex:1;min-width:0;display:flex;flex-direction:column;gap:10px}
|
|
415
|
+
.ops-fm-tablewrap{max-height:62vh;overflow:auto;border:1px solid var(--dsw-alias-border,#3a3f45);border-radius:10px}
|
|
416
|
+
.ops-fm-table{width:100%;border-collapse:collapse;font-size:12.5px}
|
|
417
|
+
.ops-fm-table th{position:sticky;top:0;background:var(--dsw-alias-surface,#1d2126);text-align:left;padding:8px 10px;border-bottom:1px solid var(--dsw-alias-border,#3a3f45);font-weight:500;color:var(--dsw-alias-text-secondary,#9aa0a6);white-space:nowrap}
|
|
418
|
+
.ops-fm-table td{padding:6px 10px;border-bottom:1px solid rgba(255,255,255,.05);white-space:nowrap;overflow:hidden;text-overflow:ellipsis;max-width:320px}
|
|
419
|
+
.ops-fm-table tbody tr{cursor:default}
|
|
420
|
+
.ops-fm-table tbody tr:hover{background:rgba(255,255,255,.04)}
|
|
421
|
+
.ops-fm-table tbody tr.on{background:rgba(76,141,255,.14)}
|
|
257
422
|
.ops-modal-mask{position:fixed;inset:0;background:rgba(0,0,0,.55);display:flex;align-items:center;justify-content:center;z-index:60;padding:20px}
|
|
258
423
|
.ops-modal{width:min(720px,100%);max-height:82vh;overflow:auto;background:var(--dsw-alias-bg,#16191d);border:1px solid var(--dsw-alias-border,#3a3f45);border-radius:12px;padding:18px 20px}
|
|
259
424
|
.ops-modal-h{display:flex;align-items:center;justify-content:space-between;gap:10px;margin-bottom:10px}
|
|
@@ -333,40 +498,129 @@ window.__ModuleLoader__.load({
|
|
|
333
498
|
.replace(/\r(?!\n)/g, '')
|
|
334
499
|
}
|
|
335
500
|
|
|
336
|
-
function
|
|
337
|
-
|
|
338
|
-
const
|
|
501
|
+
function downsample(values, limit = 180) {
|
|
502
|
+
if (values.length <= limit) return values
|
|
503
|
+
const step = Math.ceil(values.length / limit)
|
|
504
|
+
const out = []
|
|
505
|
+
for (let i = 0; i < values.length; i += step) out.push(values[i])
|
|
506
|
+
return out
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
function Chart({ rows, series, title, unit = '%', max = 100, thresholds = [], showTime = true }) {
|
|
510
|
+
const [hover, setHover] = React.useState(null)
|
|
511
|
+
const W = 560, H = 170
|
|
512
|
+
const LEFT = 34, RIGHT = 8, TOP = 8, BOTTOM = 22
|
|
513
|
+
const innerW = W - LEFT - RIGHT
|
|
514
|
+
const innerH = H - TOP - BOTTOM
|
|
515
|
+
|
|
516
|
+
const prepared = (series || []).map(item => ({
|
|
339
517
|
...item,
|
|
340
|
-
points: rows.map(row => row[item.field]).
|
|
518
|
+
points: downsample(rows.map(row => row[item.field])).map((value, index) => ({ value, index })),
|
|
341
519
|
})).filter(item => item.points.length > 0)
|
|
342
520
|
|
|
343
|
-
if (
|
|
521
|
+
if (prepared.length === 0) {
|
|
344
522
|
return h('div', { className: 'ops-chart-wrap' },
|
|
345
523
|
h('div', { className: 'ops-chart-h' }, h('span', null, title), h('span', null, '—')),
|
|
346
524
|
h('p', { className: 'ops-empty' }, T.noData))
|
|
347
525
|
}
|
|
348
526
|
|
|
349
|
-
const
|
|
350
|
-
const
|
|
351
|
-
const
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
}).join(' ')
|
|
527
|
+
const flat = prepared.flatMap(item => item.points.map(point => point.value))
|
|
528
|
+
const peak = Math.max(...flat, 1)
|
|
529
|
+
const niceCeil = (value) => {
|
|
530
|
+
if (value <= 1) return 1
|
|
531
|
+
const magnitude = Math.pow(10, Math.floor(Math.log10(value)))
|
|
532
|
+
const normalised = value / magnitude
|
|
533
|
+
const step = normalised <= 1 ? 1 : normalised <= 2 ? 2 : normalised <= 5 ? 5 : 10
|
|
534
|
+
return step * magnitude
|
|
358
535
|
}
|
|
359
|
-
const
|
|
360
|
-
|
|
361
|
-
|
|
536
|
+
const top = max ? Math.max(max, peak) : niceCeil(peak)
|
|
537
|
+
const n = Math.max(...prepared.map(item => item.points.length))
|
|
538
|
+
const xOf = (index) => LEFT + (n > 1 ? (innerW * index) / (n - 1) : innerW / 2)
|
|
539
|
+
const yOf = (value) => TOP + innerH * (1 - Math.min(1, Math.max(0, value / top)))
|
|
540
|
+
|
|
541
|
+
const legend = prepared.map(item => {
|
|
542
|
+
const last = item.points[item.points.length - 1]?.value
|
|
543
|
+
return `${item.label || item.field} ${typeof last === 'number' ? last.toFixed(1) : '—'}${unit}`
|
|
362
544
|
}).join(' · ')
|
|
363
545
|
|
|
546
|
+
const gridValues = [0, 0.25, 0.5, 0.75, 1].map(ratio => Math.round(top * ratio * 10) / 10)
|
|
547
|
+
const firstTs = rows[0]?.ts
|
|
548
|
+
const lastTs = rows[rows.length - 1]?.ts
|
|
549
|
+
const timeLabel = (ts) => {
|
|
550
|
+
if (!ts) return ''
|
|
551
|
+
const date = new Date(ts)
|
|
552
|
+
return `${String(date.getHours()).padStart(2, '0')}:${String(date.getMinutes()).padStart(2, '0')}`
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
const onMove = (event) => {
|
|
556
|
+
const rect = event.currentTarget.getBoundingClientRect()
|
|
557
|
+
const ratio = Math.min(1, Math.max(0, (event.clientX - rect.left) / rect.width))
|
|
558
|
+
const width = W - LEFT - RIGHT
|
|
559
|
+
const x = ratio * W - LEFT
|
|
560
|
+
const index = n > 1 ? Math.round((x / width) * (n - 1)) : 0
|
|
561
|
+
setHover(Math.min(n - 1, Math.max(0, index)))
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
const hoverValues = hover === null ? [] : prepared.map(item => ({
|
|
565
|
+
label: item.label || item.field,
|
|
566
|
+
color: item.color,
|
|
567
|
+
value: item.points[Math.min(hover, item.points.length - 1)]?.value,
|
|
568
|
+
}))
|
|
569
|
+
const hoverTs = rows[Math.min(rows.length - 1, hover ?? 0)]?.ts
|
|
570
|
+
|
|
364
571
|
return h('div', { className: 'ops-chart-wrap' },
|
|
365
572
|
h('div', { className: 'ops-chart-h' }, h('span', null, title), h('span', null, legend)),
|
|
366
|
-
h('
|
|
367
|
-
h('
|
|
368
|
-
|
|
369
|
-
|
|
573
|
+
h('div', { style: { position: 'relative' } },
|
|
574
|
+
h('svg', {
|
|
575
|
+
className: 'ops-chart',
|
|
576
|
+
viewBox: `0 0 ${W} ${H}`,
|
|
577
|
+
preserveAspectRatio: 'none',
|
|
578
|
+
onMouseMove: onMove,
|
|
579
|
+
onMouseLeave: () => setHover(null),
|
|
580
|
+
},
|
|
581
|
+
...gridValues.map((value) => h('g', { key: 'g' + value },
|
|
582
|
+
h('line', {
|
|
583
|
+
x1: LEFT, y1: yOf(value), x2: W - RIGHT, y2: yOf(value),
|
|
584
|
+
stroke: 'var(--dsw-alias-border,#3a3f45)', strokeWidth: 1, strokeOpacity: value === 0 ? 1 : 0.35,
|
|
585
|
+
vectorEffect: 'non-scaling-stroke',
|
|
586
|
+
}),
|
|
587
|
+
h('text', { x: 2, y: yOf(value) + 3, fill: 'var(--dsw-alias-text-secondary,#9aa0a6)', fontSize: 9 }, String(value)))),
|
|
588
|
+
...(thresholds || []).map((line, i) => h('line', {
|
|
589
|
+
key: 't' + i,
|
|
590
|
+
x1: LEFT, y1: yOf(line.value), x2: W - RIGHT, y2: yOf(line.value),
|
|
591
|
+
stroke: line.color || 'var(--dsw-alias-warning,#e5b650)',
|
|
592
|
+
strokeWidth: 1, strokeDasharray: '4 4', strokeOpacity: 0.7, vectorEffect: 'non-scaling-stroke',
|
|
593
|
+
})),
|
|
594
|
+
showTime && firstTs ? h('text', { x: LEFT, y: H - 6, fill: 'var(--dsw-alias-text-secondary,#9aa0a6)', fontSize: 9 }, timeLabel(firstTs)) : null,
|
|
595
|
+
showTime && lastTs ? h('text', { x: W - RIGHT, y: H - 6, textAnchor: 'end', fill: 'var(--dsw-alias-text-secondary,#9aa0a6)', fontSize: 9 }, timeLabel(lastTs)) : null,
|
|
596
|
+
...prepared.map(item => {
|
|
597
|
+
const line = item.points.map(point => `${xOf(point.index).toFixed(1)},${yOf(point.value).toFixed(1)}`).join(' ')
|
|
598
|
+
const area = `M ${LEFT},${TOP + innerH} L ${item.points.map(point => `${xOf(point.index).toFixed(1)},${yOf(point.value).toFixed(1)}`).join(' L ')} L ${xOf(item.points.length - 1).toFixed(1)},${TOP + innerH} Z`
|
|
599
|
+
return h('g', { key: item.field },
|
|
600
|
+
h('path', { d: area, fill: item.color, fillOpacity: 0.12, stroke: 'none' }),
|
|
601
|
+
h('polyline', { points: line, fill: 'none', stroke: item.color, strokeWidth: 1.8, strokeLinejoin: 'round', strokeLinecap: 'round' }))
|
|
602
|
+
}),
|
|
603
|
+
hover === null ? null : h('line', {
|
|
604
|
+
x1: xOf(hover), y1: TOP, x2: xOf(hover), y2: TOP + innerH,
|
|
605
|
+
stroke: 'var(--dsw-alias-text-secondary,#9aa0a6)', strokeWidth: 1, strokeDasharray: '3 3',
|
|
606
|
+
}),
|
|
607
|
+
hover === null ? null : prepared.map(item => h('circle', {
|
|
608
|
+
key: 'c' + item.field,
|
|
609
|
+
cx: xOf(Math.min(hover, item.points.length - 1)),
|
|
610
|
+
cy: yOf(item.points[Math.min(hover, item.points.length - 1)]?.value ?? 0),
|
|
611
|
+
r: 2.5, fill: item.color,
|
|
612
|
+
}))),
|
|
613
|
+
hover === null ? null : h('div', {
|
|
614
|
+
className: 'ops-chart-tip',
|
|
615
|
+
style: {
|
|
616
|
+
left: `${(xOf(hover) / W) * 100}%`,
|
|
617
|
+
transform: (xOf(hover) / W) > 0.6 ? 'translateX(-100%)' : 'none',
|
|
618
|
+
},
|
|
619
|
+
},
|
|
620
|
+
h('div', { className: 'ops-dim', style: { fontSize: '11px', marginBottom: '2px' } }, timeLabel(hoverTs)),
|
|
621
|
+
...hoverValues.map(item => h('div', { key: item.label, style: { fontSize: '12px' } },
|
|
622
|
+
h('span', { style: { color: item.color } }, '● '),
|
|
623
|
+
`${item.label} ${typeof item.value === 'number' ? item.value.toFixed(1) : '—'}${unit}`)))))
|
|
370
624
|
}
|
|
371
625
|
|
|
372
626
|
/** Byte-rate per second between consecutive samples, in KB/s. */
|
|
@@ -420,6 +674,23 @@ window.__ModuleLoader__.load({
|
|
|
420
674
|
const [logSource, setLogSource] = React.useState('nginx.service')
|
|
421
675
|
const [logLines, setLogLines] = React.useState(200)
|
|
422
676
|
const [logText, setLogText] = React.useState('')
|
|
677
|
+
const [logGrep, setLogGrep] = React.useState('')
|
|
678
|
+
const [logLevel, setLogLevel] = React.useState('')
|
|
679
|
+
const [logSince, setLogSince] = React.useState(0)
|
|
680
|
+
const [logGroups, setLogGroups] = React.useState([])
|
|
681
|
+
const [logExpanded, setLogExpanded] = React.useState({})
|
|
682
|
+
const [logAllOpen, setLogAllOpen] = React.useState(false)
|
|
683
|
+
const [logCount, setLogCount] = React.useState(0)
|
|
684
|
+
const [logUsageData, setLogUsageData] = React.useState(null)
|
|
685
|
+
const [logPolicyBusy, setLogPolicyBusy] = React.useState(false)
|
|
686
|
+
const [cleanPreview, setCleanPreview] = React.useState(null)
|
|
687
|
+
const [loadingMap, setLoadingMap] = React.useState({})
|
|
688
|
+
const markLoading = (key, value) => setLoadingMap(current => ({ ...current, [key]: value }))
|
|
689
|
+
const [cleanBusyHost, setCleanBusyHost] = React.useState('')
|
|
690
|
+
const [cleanSel, setCleanSel] = React.useState({ journal: true, paths: {} })
|
|
691
|
+
const [cleanBackupFile, setCleanBackupFile] = React.useState(null)
|
|
692
|
+
const [backupBusy, setBackupBusy] = React.useState(false)
|
|
693
|
+
const [cleanRunBusy, setCleanRunBusy] = React.useState(false)
|
|
423
694
|
const [logAuto, setLogAuto] = React.useState(false)
|
|
424
695
|
const [sslDomain, setSslDomain] = React.useState('')
|
|
425
696
|
const [sslResult, setSslResult] = React.useState(null)
|
|
@@ -443,6 +714,18 @@ window.__ModuleLoader__.load({
|
|
|
443
714
|
const [monForm, setMonForm] = React.useState({ type: 'http', target: '', label: '', intervalMinutes: 5, language: 'shell', script: '' })
|
|
444
715
|
const [monEditId, setMonEditId] = React.useState('')
|
|
445
716
|
const [monDialog, setMonDialog] = React.useState(null)
|
|
717
|
+
const [templates, setTemplates] = React.useState([])
|
|
718
|
+
const [services, setServices] = React.useState([])
|
|
719
|
+
const [uiMode, setUiMode] = React.useState('pro')
|
|
720
|
+
const [alerts, setAlerts] = React.useState([])
|
|
721
|
+
const [audit, setAudit] = React.useState([])
|
|
722
|
+
const [info, setInfo] = React.useState(null)
|
|
723
|
+
const [simpleMonitors, setSimpleMonitors] = React.useState({})
|
|
724
|
+
const [simpleCtx, setSimpleCtx] = React.useState({})
|
|
725
|
+
const [simpleNotice, setSimpleNotice] = React.useState('')
|
|
726
|
+
const [maintenanceUntil, setMaintenanceUntil] = React.useState(null)
|
|
727
|
+
const [p2Busy, setP2Busy] = React.useState('')
|
|
728
|
+
const [templateId, setTemplateId] = React.useState('')
|
|
446
729
|
const [monBusy, setMonBusy] = React.useState('')
|
|
447
730
|
const [health, setHealth] = React.useState(null)
|
|
448
731
|
const [certs, setCerts] = React.useState([])
|
|
@@ -462,6 +745,14 @@ window.__ModuleLoader__.load({
|
|
|
462
745
|
const [chBusy, setChBusy] = React.useState('')
|
|
463
746
|
const [fsPath, setFsPath] = React.useState('/')
|
|
464
747
|
const [fsEntries, setFsEntries] = React.useState(null)
|
|
748
|
+
const [fsTree, setFsTree] = React.useState({})
|
|
749
|
+
const [fsOpen, setFsOpen] = React.useState({})
|
|
750
|
+
const [fsSel, setFsSel] = React.useState(null)
|
|
751
|
+
const [fsSelSet, setFsSelSet] = React.useState({})
|
|
752
|
+
const [fsEdit, setFsEdit] = React.useState(null)
|
|
753
|
+
const [fsProgress, setFsProgress] = React.useState(null)
|
|
754
|
+
const [fsPreview, setFsPreview] = React.useState(null)
|
|
755
|
+
const [fsFavs, setFsFavs] = React.useState({ favs: [], recents: [] })
|
|
465
756
|
const [fsBusy, setFsBusy] = React.useState('')
|
|
466
757
|
const [adding, setAdding] = React.useState(false)
|
|
467
758
|
|
|
@@ -473,6 +764,7 @@ window.__ModuleLoader__.load({
|
|
|
473
764
|
const conf = await api('config')
|
|
474
765
|
if (conf.config) {
|
|
475
766
|
setConfig(conf.config)
|
|
767
|
+
setUiMode(conf.config.uiMode === 'simple' ? 'simple' : 'pro')
|
|
476
768
|
setQuickText((conf.config.quickCommands || []).join('\n'))
|
|
477
769
|
}
|
|
478
770
|
setError('')
|
|
@@ -539,7 +831,11 @@ window.__ModuleLoader__.load({
|
|
|
539
831
|
if (!source) { setLogText(T.logPick); return }
|
|
540
832
|
setBusy('logs')
|
|
541
833
|
try {
|
|
542
|
-
const
|
|
834
|
+
const params = new URLSearchParams({ host: cHost || hosts[0]?.name, source, lines: String(logLines) })
|
|
835
|
+
if (logGrep.trim()) params.set('grep', logGrep.trim())
|
|
836
|
+
if (logLevel) params.set('level', logLevel)
|
|
837
|
+
if (logSince > 0) params.set('since', String(logSince))
|
|
838
|
+
const data = await api(`tail?${params.toString()}`, {}, timeoutFor('action'))
|
|
543
839
|
if (data.missing) {
|
|
544
840
|
setLogText(data.error || '')
|
|
545
841
|
void loadInv(cHost || hosts[0]?.name, true)
|
|
@@ -565,35 +861,127 @@ window.__ModuleLoader__.load({
|
|
|
565
861
|
try {
|
|
566
862
|
const data = await api(`files?host=${encodeURIComponent(cHost || hosts[0]?.name)}&path=${encodeURIComponent(target)}`, {}, timeoutFor('action'))
|
|
567
863
|
setFsEntries(data.entries || []); setFsPath(data.path || target); setError('')
|
|
864
|
+
try { addRecent(data.path || target) } catch { /* ignore */ }
|
|
568
865
|
} catch (e) { setError(String(e.message || e)) } finally { setFsBusy('') }
|
|
569
866
|
}
|
|
570
867
|
|
|
868
|
+
const CHUNK_BYTES = 4 * 1024 * 1024
|
|
869
|
+
const IMAGE_EXT = /\.(png|jpe?g|gif|webp|bmp|svg|ico)$/i
|
|
870
|
+
|
|
871
|
+
const hostFsKey = () => `ops-kit:fs:${cHost || hosts[0]?.name || 'default'}`
|
|
872
|
+
|
|
873
|
+
const blobToBase64 = (blob) => new Promise((resolve, reject) => {
|
|
874
|
+
const reader = new FileReader()
|
|
875
|
+
reader.onload = () => resolve(String(reader.result).split(',')[1] || '')
|
|
876
|
+
reader.onerror = () => reject(new Error('read failed'))
|
|
877
|
+
reader.readAsDataURL(blob)
|
|
878
|
+
})
|
|
879
|
+
|
|
880
|
+
const loadFavs = () => {
|
|
881
|
+
try {
|
|
882
|
+
const raw = localStorage.getItem(hostFsKey())
|
|
883
|
+
setFsFavs(raw ? JSON.parse(raw) : { favs: [], recents: [] })
|
|
884
|
+
} catch { setFsFavs({ favs: [], recents: [] }) }
|
|
885
|
+
}
|
|
886
|
+
|
|
887
|
+
const saveFavs = (next) => {
|
|
888
|
+
setFsFavs(next)
|
|
889
|
+
try { localStorage.setItem(hostFsKey(), JSON.stringify(next)) } catch { /* private mode */ }
|
|
890
|
+
}
|
|
891
|
+
|
|
892
|
+
const addRecent = (path) => {
|
|
893
|
+
const next = { ...fsFavs, recents: [path, ...fsFavs.recents.filter(item => item !== path)].slice(0, 8) }
|
|
894
|
+
saveFavs(next)
|
|
895
|
+
}
|
|
896
|
+
|
|
897
|
+
const toggleFav = (path) => {
|
|
898
|
+
const has = fsFavs.favs.includes(path)
|
|
899
|
+
saveFavs({ ...fsFavs, favs: has ? fsFavs.favs.filter(item => item !== path) : [path, ...fsFavs.favs].slice(0, 12) })
|
|
900
|
+
}
|
|
901
|
+
|
|
571
902
|
const downloadFile = async (path, name) => {
|
|
572
903
|
setFsBusy('dl:' + path)
|
|
573
904
|
try {
|
|
574
|
-
const
|
|
575
|
-
const
|
|
576
|
-
|
|
905
|
+
const first = await api(`download-chunk?host=${encodeURIComponent(cHost || hosts[0]?.name)}&path=${encodeURIComponent(path)}&offset=0&length=1`, {}, 60_000)
|
|
906
|
+
const size = Number(first.size) || 0
|
|
907
|
+
if (size > 100 * 1024 * 1024) { setError(T.fsTooBig); return }
|
|
908
|
+
const parts = []
|
|
909
|
+
let offset = 0
|
|
910
|
+
const started = Date.now()
|
|
911
|
+
setFsProgress({ label: T.fsDownloading, name, done: 0, total: size, eta: null, speed: 0 })
|
|
912
|
+
while (offset < size) {
|
|
913
|
+
let chunk = null
|
|
914
|
+
for (let attempt = 0; attempt < 3 && !chunk; attempt += 1) {
|
|
915
|
+
try {
|
|
916
|
+
chunk = await api(`download-chunk?host=${encodeURIComponent(cHost || hosts[0]?.name)}&path=${encodeURIComponent(path)}&offset=${offset}&length=${CHUNK_BYTES}`, {}, 300_000)
|
|
917
|
+
} catch (error) {
|
|
918
|
+
if (attempt === 2) throw error
|
|
919
|
+
await new Promise(resolve => setTimeout(resolve, 800))
|
|
920
|
+
}
|
|
921
|
+
}
|
|
922
|
+
const bytes = Uint8Array.from(atob(chunk.base64 || ''), ch => ch.charCodeAt(0))
|
|
923
|
+
if (bytes.length === 0) break
|
|
924
|
+
parts.push(bytes)
|
|
925
|
+
offset += bytes.length
|
|
926
|
+
const seconds = Math.max(0.5, (Date.now() - started) / 1000)
|
|
927
|
+
const speed = offset / seconds
|
|
928
|
+
setFsProgress({
|
|
929
|
+
label: T.fsDownloading,
|
|
930
|
+
name,
|
|
931
|
+
done: offset,
|
|
932
|
+
total: size,
|
|
933
|
+
speed: Math.round((speed / 1048576) * 10) / 10,
|
|
934
|
+
eta: speed > 0 ? Math.max(0, Math.round((size - offset) / speed)) : null,
|
|
935
|
+
})
|
|
936
|
+
}
|
|
937
|
+
const url = URL.createObjectURL(new Blob(parts))
|
|
577
938
|
const a = document.createElement('a')
|
|
578
|
-
a.href = url
|
|
579
|
-
|
|
580
|
-
|
|
939
|
+
a.href = url
|
|
940
|
+
a.download = name || 'download'
|
|
941
|
+
a.click()
|
|
942
|
+
setTimeout(() => URL.revokeObjectURL(url), 3000)
|
|
943
|
+
} catch (e) { setError(String(e.message || e)) } finally { setFsBusy(''); setFsProgress(null) }
|
|
581
944
|
}
|
|
582
945
|
|
|
583
946
|
const uploadFile = async (file) => {
|
|
584
947
|
if (!file) return
|
|
948
|
+
if (file.size > 100 * 1024 * 1024) { setError(T.fsTooBig); return }
|
|
949
|
+
const target = (fsPath === '/' ? '' : fsPath) + '/' + file.name
|
|
585
950
|
setFsBusy('upload')
|
|
586
951
|
try {
|
|
587
|
-
const
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
952
|
+
const status = await api(`upload-status?host=${encodeURIComponent(cHost || hosts[0]?.name)}&path=${encodeURIComponent(target)}`, {}, 30_000)
|
|
953
|
+
let offset = Math.min(Number(status.bytes) || 0, file.size)
|
|
954
|
+
if (offset > 0) setNotice(`${T.fsResume} ${offset} B`)
|
|
955
|
+
setFsProgress({ label: T.fsUploading, name: file.name, done: offset, total: file.size })
|
|
956
|
+
while (offset < file.size) {
|
|
957
|
+
const slice = file.slice(offset, Math.min(offset + CHUNK_BYTES, file.size))
|
|
958
|
+
const base64 = await blobToBase64(slice)
|
|
959
|
+
const res = await api('upload-chunk', { method: 'POST', body: JSON.stringify({ host: cHost || hosts[0]?.name, path: target, offset, base64 }) }, 300_000)
|
|
960
|
+
if (!res.ok) throw new Error(res.error || 'chunk failed')
|
|
961
|
+
offset = Number(res.bytes) || offset + slice.size
|
|
962
|
+
setFsProgress({ label: T.fsUploading, name: file.name, done: offset, total: file.size })
|
|
963
|
+
}
|
|
964
|
+
const done = await api('upload-finish', { method: 'POST', body: JSON.stringify({ host: cHost || hosts[0]?.name, path: target }) }, 120_000)
|
|
965
|
+
if (!done.ok) throw new Error(done.error || 'finish failed')
|
|
966
|
+
setNotice(`${file.name} ✓`)
|
|
967
|
+
setTimeout(() => setNotice(''), 3000)
|
|
595
968
|
await loadFiles(fsPath)
|
|
596
|
-
} catch (e) { setError(String(e.message || e)) } finally { setFsBusy('') }
|
|
969
|
+
} catch (e) { setError(String(e.message || e)) } finally { setFsBusy(''); setFsProgress(null) }
|
|
970
|
+
}
|
|
971
|
+
|
|
972
|
+
const previewImage = async (entry) => {
|
|
973
|
+
setFsPreview({ name: entry.name, loading: true })
|
|
974
|
+
try {
|
|
975
|
+
const data = await api(`download?host=${encodeURIComponent(cHost || hosts[0]?.name)}&path=${encodeURIComponent(entry.path)}`, {}, 120_000)
|
|
976
|
+
const lower = entry.name.toLowerCase()
|
|
977
|
+
const mime = lower.endsWith('.svg') ? 'image/svg+xml'
|
|
978
|
+
: lower.endsWith('.png') ? 'image/png'
|
|
979
|
+
: lower.endsWith('.gif') ? 'image/gif'
|
|
980
|
+
: lower.endsWith('.webp') ? 'image/webp'
|
|
981
|
+
: lower.endsWith('.bmp') ? 'image/bmp'
|
|
982
|
+
: 'image/jpeg'
|
|
983
|
+
setFsPreview({ name: entry.name, dataUrl: `data:${mime};base64,${data.base64 || ''}`, size: data.size })
|
|
984
|
+
} catch (e) { setFsPreview(null); setError(String(e.message || e)) }
|
|
597
985
|
}
|
|
598
986
|
|
|
599
987
|
const fsDelete = async (path) => {
|
|
@@ -605,6 +993,121 @@ window.__ModuleLoader__.load({
|
|
|
605
993
|
} catch (e) { setError(String(e.message || e)) } finally { setFsBusy('') }
|
|
606
994
|
}
|
|
607
995
|
|
|
996
|
+
const loadTree = async (path) => {
|
|
997
|
+
try {
|
|
998
|
+
const data = await api(`files?host=${encodeURIComponent(cHost || hosts[0]?.name)}&dirs=1&path=${encodeURIComponent(path)}`, {}, timeoutFor('action'))
|
|
999
|
+
setFsTree(current => ({ ...current, [path]: data.entries || [] }))
|
|
1000
|
+
} catch { /* keep the tree as is */ }
|
|
1001
|
+
}
|
|
1002
|
+
|
|
1003
|
+
const toggleDir = (path) => {
|
|
1004
|
+
setFsOpen(current => ({ ...current, [path]: !current[path] }))
|
|
1005
|
+
if (!fsTree[path]) void loadTree(path)
|
|
1006
|
+
}
|
|
1007
|
+
|
|
1008
|
+
const goPath = (path) => {
|
|
1009
|
+
const parts = path.split('/').filter(Boolean)
|
|
1010
|
+
const chain = ['/']
|
|
1011
|
+
let acc = ''
|
|
1012
|
+
for (const part of parts) { acc += '/' + part; chain.push(acc) }
|
|
1013
|
+
setFsOpen(current => {
|
|
1014
|
+
const next = { ...current }
|
|
1015
|
+
for (const item of chain) next[item] = true
|
|
1016
|
+
return next
|
|
1017
|
+
})
|
|
1018
|
+
for (const item of chain) if (!fsTree[item]) void loadTree(item)
|
|
1019
|
+
void loadFiles(path)
|
|
1020
|
+
}
|
|
1021
|
+
|
|
1022
|
+
const selectedPaths = () => Object.keys(fsSelSet)
|
|
1023
|
+
|
|
1024
|
+
const toggleSelect = (entry) => {
|
|
1025
|
+
setFsSel(entry)
|
|
1026
|
+
setFsSelSet(current => {
|
|
1027
|
+
const next = { ...current }
|
|
1028
|
+
if (next[entry.path]) delete next[entry.path]
|
|
1029
|
+
else next[entry.path] = true
|
|
1030
|
+
return next
|
|
1031
|
+
})
|
|
1032
|
+
}
|
|
1033
|
+
|
|
1034
|
+
const toggleSelectAll = () => {
|
|
1035
|
+
const entries = fsEntries || []
|
|
1036
|
+
const all = entries.length > 0 && entries.every(entry => fsSelSet[entry.path])
|
|
1037
|
+
if (all) { setFsSelSet({}); return }
|
|
1038
|
+
const next = {}
|
|
1039
|
+
for (const entry of entries) next[entry.path] = true
|
|
1040
|
+
setFsSelSet(next)
|
|
1041
|
+
}
|
|
1042
|
+
|
|
1043
|
+
const fsChmod = async () => {
|
|
1044
|
+
const paths = selectedPaths()
|
|
1045
|
+
if (paths.length === 0) return
|
|
1046
|
+
const mode = window.prompt(T.fsChmodPrompt, '644')
|
|
1047
|
+
if (!mode) return
|
|
1048
|
+
setFsBusy('chmod')
|
|
1049
|
+
try {
|
|
1050
|
+
await api('fs', { method: 'POST', body: JSON.stringify({ host: cHost || hosts[0]?.name, action: 'chmod', paths, mode }) }, timeoutFor('action'))
|
|
1051
|
+
await loadFiles(fsPath)
|
|
1052
|
+
} catch (e) { setError(String(e.message || e)) } finally { setFsBusy('') }
|
|
1053
|
+
}
|
|
1054
|
+
|
|
1055
|
+
const fsCompress = async () => {
|
|
1056
|
+
const paths = selectedPaths()
|
|
1057
|
+
if (paths.length === 0) return
|
|
1058
|
+
const first = paths[0].split('/').filter(Boolean).pop() || 'archive'
|
|
1059
|
+
const archive = window.prompt(T.fsArchivePrompt, `${fsPath === '/' ? '' : fsPath}/${first}.tar.gz`)
|
|
1060
|
+
if (!archive) return
|
|
1061
|
+
setFsBusy('compress')
|
|
1062
|
+
try {
|
|
1063
|
+
await api('fs', { method: 'POST', body: JSON.stringify({ host: cHost || hosts[0]?.name, action: 'compress', paths, archive, format: /\.zip$/i.test(archive) ? 'zip' : 'tar.gz' }) }, 300_000)
|
|
1064
|
+
await loadFiles(fsPath)
|
|
1065
|
+
} catch (e) { setError(String(e.message || e)) } finally { setFsBusy('') }
|
|
1066
|
+
}
|
|
1067
|
+
|
|
1068
|
+
const fsExtract = async () => {
|
|
1069
|
+
const paths = selectedPaths()
|
|
1070
|
+
if (paths.length !== 1) { setError(T.fsExtract); return }
|
|
1071
|
+
setFsBusy('extract')
|
|
1072
|
+
try {
|
|
1073
|
+
await api('fs', { method: 'POST', body: JSON.stringify({ host: cHost || hosts[0]?.name, action: 'extract', path: paths[0], target: fsPath }) }, 300_000)
|
|
1074
|
+
await loadFiles(fsPath)
|
|
1075
|
+
} catch (e) { setError(String(e.message || e)) } finally { setFsBusy('') }
|
|
1076
|
+
}
|
|
1077
|
+
|
|
1078
|
+
const openEditor = async (entry) => {
|
|
1079
|
+
setFsEdit({ path: entry.path, loading: true, content: '', binary: false })
|
|
1080
|
+
try {
|
|
1081
|
+
const data = await api(`file-text?host=${encodeURIComponent(cHost || hosts[0]?.name)}&path=${encodeURIComponent(entry.path)}`, {}, timeoutFor('action'))
|
|
1082
|
+
setFsEdit({ path: entry.path, loading: false, content: data.content || '', binary: Boolean(data.binary), size: data.size })
|
|
1083
|
+
} catch (e) { setFsEdit(null); setError(String(e.message || e)) }
|
|
1084
|
+
}
|
|
1085
|
+
|
|
1086
|
+
const saveEditor = async () => {
|
|
1087
|
+
if (!fsEdit) return
|
|
1088
|
+
setFsBusy('save')
|
|
1089
|
+
try {
|
|
1090
|
+
await api('file-text', { method: 'POST', body: JSON.stringify({ host: cHost || hosts[0]?.name, path: fsEdit.path, content: fsEdit.content }) }, timeoutFor('action'))
|
|
1091
|
+
setNotice('已保存(原文件已备份)')
|
|
1092
|
+
setTimeout(() => setNotice(''), 3000)
|
|
1093
|
+
setFsEdit(null)
|
|
1094
|
+
await loadFiles(fsPath)
|
|
1095
|
+
} catch (e) { setError(String(e.message || e)) } finally { setFsBusy('') }
|
|
1096
|
+
}
|
|
1097
|
+
|
|
1098
|
+
const fsRename = async () => {
|
|
1099
|
+
if (!fsSel) return
|
|
1100
|
+
const name = window.prompt(T.fsRenamePrompt, fsSel.name)
|
|
1101
|
+
if (!name || name === fsSel.name) return
|
|
1102
|
+
const parent = fsPath === '/' ? '' : fsPath
|
|
1103
|
+
try {
|
|
1104
|
+
await api('fs', { method: 'POST', body: JSON.stringify({ host: cHost || hosts[0]?.name, action: 'rename', path: fsSel.path, toPath: parent + '/' + name }) }, timeoutFor('action'))
|
|
1105
|
+
setFsSel(null)
|
|
1106
|
+
await loadFiles(fsPath)
|
|
1107
|
+
if (fsTree[fsPath]) await loadTree(fsPath)
|
|
1108
|
+
} catch (e) { setError(String(e.message || e)) }
|
|
1109
|
+
}
|
|
1110
|
+
|
|
608
1111
|
const fsMkdir = async () => {
|
|
609
1112
|
const name = window.prompt(T.folderName)
|
|
610
1113
|
if (!name) return
|
|
@@ -713,26 +1216,74 @@ window.__ModuleLoader__.load({
|
|
|
713
1216
|
const host = mHost || hosts[0]?.name
|
|
714
1217
|
if (!host) return
|
|
715
1218
|
void (async () => {
|
|
1219
|
+
markLoading('samples', true)
|
|
716
1220
|
try {
|
|
717
1221
|
const data = await api(`metrics?host=${encodeURIComponent(host)}&hours=${mHours}`)
|
|
718
1222
|
setSamples(data.samples || [])
|
|
719
1223
|
} catch (e) { setError(String(e.message || e)) }
|
|
1224
|
+
finally { markLoading('samples', false) }
|
|
720
1225
|
})()
|
|
721
1226
|
}, [detailHost, detailTab, mHost, mHours, hosts])
|
|
722
1227
|
|
|
1228
|
+
React.useEffect(() => {
|
|
1229
|
+
if (tab !== 1) return
|
|
1230
|
+
void (async () => {
|
|
1231
|
+
try {
|
|
1232
|
+
const [alertData, infoData] = await Promise.all([
|
|
1233
|
+
api('alerts?limit=5', {}, 20_000).catch(() => ({ entries: [] })),
|
|
1234
|
+
api('info', {}, 15_000).catch(() => null),
|
|
1235
|
+
])
|
|
1236
|
+
setAlerts(alertData.entries || [])
|
|
1237
|
+
if (infoData) setInfo(infoData)
|
|
1238
|
+
} catch { /* keep empty */ }
|
|
1239
|
+
})()
|
|
1240
|
+
}, [tab])
|
|
1241
|
+
|
|
1242
|
+
React.useEffect(() => {
|
|
1243
|
+
if (uiMode !== 'simple' || tab !== 0) return
|
|
1244
|
+
void (async () => {
|
|
1245
|
+
try {
|
|
1246
|
+
const [alertData, auditData, infoData] = await Promise.all([
|
|
1247
|
+
api('alerts?limit=6', {}, 20_000).catch(() => ({ entries: [] })),
|
|
1248
|
+
api('audit?limit=6', {}, 20_000).catch(() => ({ entries: [] })),
|
|
1249
|
+
api('info', {}, 15_000).catch(() => null),
|
|
1250
|
+
])
|
|
1251
|
+
setAlerts(alertData.entries || [])
|
|
1252
|
+
setAudit(auditData.entries || [])
|
|
1253
|
+
if (infoData) setInfo(infoData)
|
|
1254
|
+
const pairs = await Promise.all(hosts.map(async host => {
|
|
1255
|
+
try { const data = await api(`monitors?host=${encodeURIComponent(host.name)}`, {}, 25_000); return [host.name, data.monitors || []] } catch { return [host.name, []] }
|
|
1256
|
+
}))
|
|
1257
|
+
setSimpleMonitors(Object.fromEntries(pairs))
|
|
1258
|
+
} catch { /* keep empty */ }
|
|
1259
|
+
})()
|
|
1260
|
+
}, [uiMode, tab, hosts])
|
|
1261
|
+
|
|
723
1262
|
React.useEffect(() => {
|
|
724
1263
|
if (tab !== 2 || detailHost) return
|
|
725
1264
|
void (async () => {
|
|
726
1265
|
try { setAiModels(await api('ai-models', {}, 15_000)) } catch { /* optional */ }
|
|
727
1266
|
void loadChannels()
|
|
1267
|
+
markLoading('audit', true)
|
|
1268
|
+
void api('audit?limit=20', {}, 20_000).then(data => setAudit(data.entries || [])).catch(() => {}).finally(() => markLoading('audit', false))
|
|
728
1269
|
})()
|
|
729
1270
|
}, [tab, detailHost])
|
|
730
1271
|
|
|
731
1272
|
React.useEffect(() => {
|
|
732
1273
|
if (!detailHost || detailTab !== 'files') return
|
|
1274
|
+
if (!fsTree['/']) void loadTree('/')
|
|
733
1275
|
void loadFiles(fsPath)
|
|
734
1276
|
}, [detailHost, detailTab, cHost])
|
|
735
1277
|
|
|
1278
|
+
React.useEffect(() => {
|
|
1279
|
+
if (!detailHost || detailTab !== 'logs') return
|
|
1280
|
+
void (async () => {
|
|
1281
|
+
try { const data = await api(`log-sources?host=${encodeURIComponent(cHost || hosts[0]?.name)}`, {}, 60_000); setLogGroups(data.groups || []) } catch { setLogGroups([]) }
|
|
1282
|
+
})()
|
|
1283
|
+
void loadLogUsage()
|
|
1284
|
+
void loadLogs()
|
|
1285
|
+
}, [detailHost, detailTab, cHost])
|
|
1286
|
+
|
|
736
1287
|
React.useEffect(() => {
|
|
737
1288
|
if (!detailHost || detailTab !== 'logs' || !logAuto) return
|
|
738
1289
|
void loadLogs()
|
|
@@ -772,11 +1323,12 @@ window.__ModuleLoader__.load({
|
|
|
772
1323
|
}
|
|
773
1324
|
|
|
774
1325
|
const cleanupHost = async (name) => {
|
|
775
|
-
if (!window.confirm(`${T.cleanup}
|
|
1326
|
+
if (!window.confirm(`${T.cleanup}:${name}\n${T.cleanDetail || ''}`)) return
|
|
776
1327
|
setBusy('clean:' + name)
|
|
777
1328
|
try {
|
|
778
1329
|
const data = await api('cleanup', { method: 'POST', body: JSON.stringify({ host: name, confirm: true }) }, timeoutFor('action') * 2)
|
|
779
1330
|
setNotice(data.ok ? `${T.freed} ${data.before}% → ${data.after}%` : (data.error || 'failed'))
|
|
1331
|
+
if (uiMode === 'simple') setHostCtx(name, { phase: data.ok ? 'ok' : 'fail', message: data.ok ? `磁盘已从 ${data.before}% 降到 ${data.after}%` : (data.error || T.stillBad) })
|
|
780
1332
|
setTimeout(() => setNotice(''), 4000)
|
|
781
1333
|
} catch (e) { setError(String(e.message || e)) } finally { setBusy('') }
|
|
782
1334
|
}
|
|
@@ -800,6 +1352,7 @@ window.__ModuleLoader__.load({
|
|
|
800
1352
|
}
|
|
801
1353
|
|
|
802
1354
|
const saveConfig = async () => {
|
|
1355
|
+
setOpBusy('save')
|
|
803
1356
|
try {
|
|
804
1357
|
const payload = {
|
|
805
1358
|
...config,
|
|
@@ -807,9 +1360,12 @@ window.__ModuleLoader__.load({
|
|
|
807
1360
|
aiEnabled: aiModels.aiEnabled !== false,
|
|
808
1361
|
aiProvider: aiModels.aiProvider || '',
|
|
809
1362
|
aiModel: aiModels.aiModel || '',
|
|
1363
|
+
uiMode,
|
|
810
1364
|
}
|
|
811
1365
|
const data = await api('config', { method: 'POST', body: JSON.stringify(payload) })
|
|
812
1366
|
if (data.config) setConfig(data.config)
|
|
1367
|
+
setNotice(T.saved)
|
|
1368
|
+
setTimeout(() => setNotice(''), 1500)
|
|
813
1369
|
setNotice(T.changed); setTimeout(() => setNotice(''), 2000)
|
|
814
1370
|
} catch (e) { setError(String(e.message || e)) }
|
|
815
1371
|
}
|
|
@@ -997,9 +1553,261 @@ window.__ModuleLoader__.load({
|
|
|
997
1553
|
diag.result.hint ? h('p', { className: 'ops-warn', style: { fontSize: '12px', margin: '8px 0 0' } }, diag.result.hint) : null) : null))
|
|
998
1554
|
: null
|
|
999
1555
|
|
|
1556
|
+
const onboardingView = h('div', { className: 'ops-card' },
|
|
1557
|
+
h('div', { className: 'ops-card-h' },
|
|
1558
|
+
h('span', null, T.onboardTitle),
|
|
1559
|
+
h('button', {
|
|
1560
|
+
className: 'ops-btn ops-btn-primary ops-btn-sm',
|
|
1561
|
+
onClick: () => { setTab(2); setAdding(true) },
|
|
1562
|
+
}, T.onboardAdd)),
|
|
1563
|
+
h('div', { className: 'ops-card-b' },
|
|
1564
|
+
...(T.onboardSteps || []).map((step, index) => h('div', { key: index, style: { fontSize: '13px', lineHeight: 1.9 } }, step)),
|
|
1565
|
+
h('p', { className: 'ops-sub', style: { margin: '8px 0 0' } }, T.onboardNote)))
|
|
1566
|
+
|
|
1567
|
+
const switchMode = async (next) => {
|
|
1568
|
+
setUiMode(next)
|
|
1569
|
+
if (next === 'simple') { setDetailHost(null); setTab(0) }
|
|
1570
|
+
try { await api('config', { method: 'POST', body: JSON.stringify({ uiMode: next }) }, 15_000) } catch (e) { setError(String(e.message || e)) }
|
|
1571
|
+
}
|
|
1572
|
+
|
|
1573
|
+
const diagnosticsText = () => {
|
|
1574
|
+
const failing = hosts.map(host => {
|
|
1575
|
+
const samples = overview[host.name] || []
|
|
1576
|
+
const sample = samples[samples.length - 1]
|
|
1577
|
+
return `${host.name}${sample ? `(磁盘 ${sample.disk ?? '—'}% · 内存 ${sample.mem ?? '—'}%)` : ''}`
|
|
1578
|
+
})
|
|
1579
|
+
const recent = alerts.slice(0, 3).map(alert => `- ${alert.message}(${fmt(alert.at)})`).join('\n')
|
|
1580
|
+
return [
|
|
1581
|
+
T.fdTitle,
|
|
1582
|
+
`${T.fbProblem}:`,
|
|
1583
|
+
'',
|
|
1584
|
+
`版本: v${info?.version || '?'} · 界面: ${uiMode === 'simple' ? '简单模式' : '专业模式'} · 平台: ${navigator.platform || '?'}`,
|
|
1585
|
+
`时间: ${fmt(new Date().toISOString())}`,
|
|
1586
|
+
`主机(${hosts.length}): ${failing.join(';') || '无'}`,
|
|
1587
|
+
recent ? `最近提醒:\n${recent}` : '',
|
|
1588
|
+
error ? `当前错误: ${error}` : '',
|
|
1589
|
+
'(由 dsh-ops-kit 生成,不含密码、密钥和日志内容)',
|
|
1590
|
+
].filter(Boolean).join('\n')
|
|
1591
|
+
}
|
|
1592
|
+
|
|
1593
|
+
const copyDiagnostics = async () => {
|
|
1594
|
+
try {
|
|
1595
|
+
await navigator.clipboard.writeText(diagnosticsText())
|
|
1596
|
+
setChatNotice(T.fbCopied)
|
|
1597
|
+
setTimeout(() => setChatNotice(''), 3000)
|
|
1598
|
+
} catch { setError(diagnosticsText()) }
|
|
1599
|
+
}
|
|
1600
|
+
|
|
1601
|
+
const ackAlert = async (alert) => {
|
|
1602
|
+
try {
|
|
1603
|
+
await api('alerts', { method: 'POST', body: JSON.stringify({ at: alert.at, message: alert.message }) }, 15_000)
|
|
1604
|
+
setAlerts(current => current.map(item => (item.at === alert.at && item.message === alert.message ? { ...item, acked: true } : item)))
|
|
1605
|
+
} catch (e) { setError(String(e.message || e)) }
|
|
1606
|
+
}
|
|
1607
|
+
|
|
1608
|
+
const simpleHostState = (host) => {
|
|
1609
|
+
const list = simpleMonitors[host.name] || []
|
|
1610
|
+
const failing = list.filter(item => item.lastOk === false)
|
|
1611
|
+
const samples = overview[host.name] || []
|
|
1612
|
+
const sample = samples[samples.length - 1] || null
|
|
1613
|
+
const disk = Number(sample?.disk ?? 0)
|
|
1614
|
+
const unreachable = list.some(item => item.suppressed === true || /主机不可达/.test(item.last?.detail || ''))
|
|
1615
|
+
const lastAt = list.reduce((latest, item) => {
|
|
1616
|
+
const at = new Date(item.last?.at || 0).getTime()
|
|
1617
|
+
return at > latest ? at : latest
|
|
1618
|
+
}, 0)
|
|
1619
|
+
let level = 'ok'
|
|
1620
|
+
if (unreachable) level = 'bad'
|
|
1621
|
+
if (failing.length > 0 || disk >= 95) level = 'bad'
|
|
1622
|
+
else if (disk >= 85) level = 'warn'
|
|
1623
|
+
return { list, failing, sample, disk, level, unreachable, lastAt }
|
|
1624
|
+
}
|
|
1625
|
+
|
|
1626
|
+
const setHostCtx = (name, value) => setSimpleCtx(current => ({ ...current, [name]: value }))
|
|
1627
|
+
|
|
1628
|
+
const suggestionFor = (item) => {
|
|
1629
|
+
const text = `${item.label || ''} ${item.target || ''}`
|
|
1630
|
+
if (/mysql|redis|3306|6379|数据库/i.test(text)) return { text: '数据存储异常,建议联系开发', action: 'contact' }
|
|
1631
|
+
if (item.type === 'http' || /nginx|httpd|apache/i.test(text)) return { text: '网站服务异常,可以先尝试重启网站服务', action: 'restart', monitor: item }
|
|
1632
|
+
if (item.type === 'service') return { text: '服务已停止,可以先尝试重启服务', action: 'restart', monitor: item }
|
|
1633
|
+
return { text: '可以先重新检查一次;仍然异常请联系开发', action: 'recheck', monitor: item }
|
|
1634
|
+
}
|
|
1635
|
+
|
|
1636
|
+
const recheckHost = async (host) => {
|
|
1637
|
+
setHostCtx(host.name, { phase: 'checking', message: T.checkingNow })
|
|
1638
|
+
try {
|
|
1639
|
+
await loadBase()
|
|
1640
|
+
try {
|
|
1641
|
+
const fresh = await api(`monitors?host=${encodeURIComponent(host.name)}`, {}, 30_000)
|
|
1642
|
+
setSimpleMonitors(current => ({ ...current, [host.name]: fresh.monitors || [] }))
|
|
1643
|
+
} catch { /* keep old list */ }
|
|
1644
|
+
setHostCtx(host.name, { phase: 'ok', message: T.recovered })
|
|
1645
|
+
setTimeout(() => setSimpleCtx(current => {
|
|
1646
|
+
const next = { ...current }
|
|
1647
|
+
delete next[host.name]
|
|
1648
|
+
return next
|
|
1649
|
+
}), 4000)
|
|
1650
|
+
} catch (e) {
|
|
1651
|
+
setHostCtx(host.name, { phase: 'fail', message: `${T.stillBad}(${String(e.message || e)})` })
|
|
1652
|
+
}
|
|
1653
|
+
}
|
|
1654
|
+
|
|
1655
|
+
const recheckOne = async (host, item) => {
|
|
1656
|
+
setHostCtx(host.name, { phase: 'checking', message: T.checkingNow })
|
|
1657
|
+
try {
|
|
1658
|
+
const data = await api('monitors', { method: 'POST', body: JSON.stringify({ host: host.name, action: 'test', id: item.id }) }, 60_000)
|
|
1659
|
+
const ok = data.result?.ok !== false
|
|
1660
|
+
setHostCtx(host.name, { phase: ok ? 'ok' : 'fail', message: ok ? T.recovered : T.stillBad })
|
|
1661
|
+
await (async () => {
|
|
1662
|
+
try { const fresh = await api(`monitors?host=${encodeURIComponent(host.name)}`, {}, 25_000); setSimpleMonitors(current => ({ ...current, [host.name]: fresh.monitors || [] })) } catch { /* ignore */ }
|
|
1663
|
+
})()
|
|
1664
|
+
} catch (e) { setHostCtx(host.name, { phase: 'fail', message: `${T.stillBad}(${String(e.message || e)})` }) }
|
|
1665
|
+
}
|
|
1666
|
+
|
|
1667
|
+
const restartWebFor = async (host, monitor) => {
|
|
1668
|
+
if (!monitor) {
|
|
1669
|
+
setNotice(T.contactDev)
|
|
1670
|
+
return
|
|
1671
|
+
}
|
|
1672
|
+
if (!window.confirm(`${T.actionRestartWeb}?\n${T.actionRestartHint}`)) return
|
|
1673
|
+
setHostCtx(host.name, { phase: 'restarting', message: T.restarting })
|
|
1674
|
+
try {
|
|
1675
|
+
await api('service', { method: 'POST', body: JSON.stringify({ host: host.name, service: monitor.target, action: 'restart', confirm: true }) }, timeoutFor('action'))
|
|
1676
|
+
setHostCtx(host.name, { phase: 'checking', message: T.checking })
|
|
1677
|
+
await new Promise(resolve => setTimeout(resolve, 4000))
|
|
1678
|
+
const data = await api('monitors', { method: 'POST', body: JSON.stringify({ host: host.name, action: 'test', id: monitor.id }) }, 60_000)
|
|
1679
|
+
const ok = data.result?.ok !== false
|
|
1680
|
+
setHostCtx(host.name, { phase: ok ? 'ok' : 'fail', message: ok ? T.recovered : T.stillBad })
|
|
1681
|
+
try { const fresh = await api(`monitors?host=${encodeURIComponent(host.name)}`, {}, 25_000); setSimpleMonitors(current => ({ ...current, [host.name]: fresh.monitors || [] })) } catch { /* ignore */ }
|
|
1682
|
+
} catch (e) {
|
|
1683
|
+
setHostCtx(host.name, { phase: 'fail', message: `${T.stillBad}(${String(e.message || e)})` })
|
|
1684
|
+
}
|
|
1685
|
+
}
|
|
1686
|
+
|
|
1687
|
+
const copyReport = async (host, state) => {
|
|
1688
|
+
const failing = state.failing.map(item => `- ${item.label || item.target}:${item.last?.detail || '异常'}`).join('\n')
|
|
1689
|
+
const recent = alerts.slice(0, 3).map(alert => `- ${alert.message}(${fmt(alert.at)})`).join('\n')
|
|
1690
|
+
const text = [
|
|
1691
|
+
`【运维异常】${host.alias || host.name}(${host.name})`,
|
|
1692
|
+
state.unreachable ? '现象:暂时联系不上服务器(网络或 SSH 不通),业务状态未知' : '现象:',
|
|
1693
|
+
state.unreachable ? '' : failing,
|
|
1694
|
+
`时间:${fmt(new Date().toISOString())}`,
|
|
1695
|
+
info ? `版本:v${info.version}` : '',
|
|
1696
|
+
recent ? `最近提醒:\n${recent}` : '',
|
|
1697
|
+
'(由 dsh-ops-kit 生成)',
|
|
1698
|
+
].filter(Boolean).join('\n')
|
|
1699
|
+
try {
|
|
1700
|
+
await navigator.clipboard.writeText(text)
|
|
1701
|
+
setSimpleNotice(T.reportCopied)
|
|
1702
|
+
setTimeout(() => setSimpleNotice(''), 3000)
|
|
1703
|
+
} catch { setError(text) }
|
|
1704
|
+
}
|
|
1705
|
+
|
|
1706
|
+
const simpleCards = hosts.map(host => {
|
|
1707
|
+
const state = simpleHostState(host)
|
|
1708
|
+
const ctx = simpleCtx[host.name]
|
|
1709
|
+
const storage = state.disk >= 95 ? T.storageFull : state.disk >= 85 ? T.storageLow : T.storageOk
|
|
1710
|
+
const uptime = state.sample?.uptimeSec ? `${Math.floor(state.sample.uptimeSec / 86400)} 天 ${Math.floor((state.sample.uptimeSec % 86400) / 3600)} 小时` : '—'
|
|
1711
|
+
const running = state.list.filter(item => item.type === 'service')
|
|
1712
|
+
const webMonitor = running.find(item => /nginx|httpd|apache/i.test(`${item.label} ${item.target}`)) || state.list.find(item => item.type === 'http')
|
|
1713
|
+
const webChecks = state.list.filter(item => item.type === 'http')
|
|
1714
|
+
const dataChecks = state.list.filter(item => item.type === 'port' && /mysql|redis|3306|6379|数据库/i.test(`${item.label} ${item.target}`))
|
|
1715
|
+
const otherChecks = state.list.filter(item => !webChecks.includes(item) && !dataChecks.includes(item))
|
|
1716
|
+
const otherFailing = otherChecks.filter(item => item.lastOk === false)
|
|
1717
|
+
const serviceText = otherChecks.length === 0 ? (state.list.length ? '—' : T.serviceNone)
|
|
1718
|
+
: otherFailing.length ? `${otherFailing.length} 项${T.serviceBadText}` : T.serviceOkText
|
|
1719
|
+
const webFailing = webChecks.filter(item => item.lastOk === false)
|
|
1720
|
+
const dataFailing = dataChecks.filter(item => item.lastOk === false)
|
|
1721
|
+
const checkedText = state.lastAt
|
|
1722
|
+
? `${T.lastChecked} ${(() => {
|
|
1723
|
+
const minutes = Math.round((Date.now() - state.lastAt) / 60_000)
|
|
1724
|
+
return minutes <= 1 ? T.justNow : `${minutes} ${T.minutesAgo}`
|
|
1725
|
+
})()}`
|
|
1726
|
+
: ''
|
|
1727
|
+
|
|
1728
|
+
return h('div', { key: host.name, className: 'ops-card' },
|
|
1729
|
+
h('div', { className: 'ops-card-h' },
|
|
1730
|
+
h('span', { style: { display: 'flex', alignItems: 'center', gap: '8px' } },
|
|
1731
|
+
h('i', { className: 'ops-dot ' + (state.level === 'ok' ? 'ok' : state.level === 'warn' ? 'warn' : 'bad') }),
|
|
1732
|
+
h('span', { style: { fontSize: '15px', fontWeight: 600 } }, host.alias || host.name)),
|
|
1733
|
+
h('span', {
|
|
1734
|
+
className: state.level === 'ok' ? 'ops-ok' : state.level === 'warn' ? 'ops-warn' : 'ops-bad',
|
|
1735
|
+
style: { fontSize: '13px', fontWeight: 600 },
|
|
1736
|
+
}, state.level === 'ok' ? T.simpleOk : state.level === 'warn' ? T.simpleWarn : T.simpleBad)),
|
|
1737
|
+
h('div', { className: 'ops-card-b' },
|
|
1738
|
+
state.unreachable
|
|
1739
|
+
? h('div', { className: 'ops-warn', style: { fontSize: '13px', marginBottom: '6px' } }, T.unreachable)
|
|
1740
|
+
: null,
|
|
1741
|
+
h('div', { className: 'ops-modal-row' }, h('b', null, T.simpleStorage), h('span', null, storage)),
|
|
1742
|
+
webChecks.length
|
|
1743
|
+
? h('div', { className: 'ops-modal-row' }, h('b', null, T.simpleWeb), h('span', null,
|
|
1744
|
+
webFailing.length ? `${webFailing.length} 项${T.serviceBadText}` : T.serviceOkText))
|
|
1745
|
+
: null,
|
|
1746
|
+
dataChecks.length
|
|
1747
|
+
? h('div', { className: 'ops-modal-row' }, h('b', null, T.simpleData), h('span', null,
|
|
1748
|
+
dataFailing.length ? `${dataFailing.length} 项${T.serviceBadText}` : T.serviceOkText))
|
|
1749
|
+
: null,
|
|
1750
|
+
h('div', { className: 'ops-modal-row' }, h('b', null, T.simpleService), h('span', null, serviceText)),
|
|
1751
|
+
h('div', { className: 'ops-modal-row' }, h('b', null, T.simpleUptime), h('span', null, uptime)),
|
|
1752
|
+
state.failing.length
|
|
1753
|
+
? h('div', { style: { marginTop: '6px' } }, ...state.failing.slice(0, 3).map(item => {
|
|
1754
|
+
const tip = suggestionFor(item)
|
|
1755
|
+
return h('div', { key: item.id, style: { fontSize: '12.5px', color: '#ff8a8a', lineHeight: 1.9 } },
|
|
1756
|
+
`· ${item.label || item.target}:${item.last?.detail || '异常'}`,
|
|
1757
|
+
h('div', { style: { color: 'var(--dsw-alias-text-secondary,#9aa0a6)', paddingLeft: '10px' } },
|
|
1758
|
+
`${T.suggestion}:${tip.text}`,
|
|
1759
|
+
tip.action === 'restart'
|
|
1760
|
+
? h('button', { className: 'ops-btn ops-btn-sm', style: { marginLeft: '8px' }, onClick: () => { void restartWebFor(host, tip.monitor || webMonitor) } }, T.actionRestartWeb)
|
|
1761
|
+
: tip.action === 'recheck'
|
|
1762
|
+
? h('button', { className: 'ops-btn ops-btn-sm', style: { marginLeft: '8px' }, onClick: () => { void recheckOne(host, item) } }, T.recheckOne)
|
|
1763
|
+
: h('button', { className: 'ops-btn ops-btn-sm', style: { marginLeft: '8px' }, onClick: () => { void copyReport(host, state) } }, T.simpleReport)))
|
|
1764
|
+
}))
|
|
1765
|
+
: null,
|
|
1766
|
+
ctx ? h('div', {
|
|
1767
|
+
className: ctx.phase === 'ok' ? 'ops-ok' : ctx.phase === 'fail' ? 'ops-bad' : 'ops-warn',
|
|
1768
|
+
style: { fontSize: '12.5px', marginTop: '6px' },
|
|
1769
|
+
}, ctx.message,
|
|
1770
|
+
ctx.phase === 'fail'
|
|
1771
|
+
? h('button', { className: 'ops-btn ops-btn-sm', style: { marginLeft: '8px' }, onClick: () => { void copyReport(host, state) } }, T.simpleReport)
|
|
1772
|
+
: null)
|
|
1773
|
+
: null,
|
|
1774
|
+
h('div', { className: 'ops-chips', style: { marginTop: '10px' } },
|
|
1775
|
+
h('button', { className: 'ops-btn ops-btn-primary ops-btn-sm', disabled: simpleCtx[host.name]?.phase === 'checking', onClick: () => { void recheckHost(host) } }, simpleCtx[host.name]?.phase === 'checking' ? T.checkingNow : T.actionRecheck),
|
|
1776
|
+
h('button', { className: 'ops-btn ops-btn-sm', disabled: cleanBusyHost === host.name || backupBusy || cleanRunBusy, onClick: () => { void openCleanPreview(host.name) } }, T.actionClean),
|
|
1777
|
+
webMonitor
|
|
1778
|
+
? h('button', { className: 'ops-btn ops-btn-sm', title: T.actionRestartHint, onClick: () => { void restartWebFor(host, webMonitor) } }, T.actionRestartWeb)
|
|
1779
|
+
: null,
|
|
1780
|
+
state.level !== 'ok'
|
|
1781
|
+
? h('button', { className: 'ops-btn ops-btn-sm', onClick: () => { void copyReport(host, state) } }, T.simpleReport)
|
|
1782
|
+
: null),
|
|
1783
|
+
checkedText ? h('div', { className: 'ops-dim', style: { fontSize: '11px', marginTop: '6px' } }, checkedText) : null))
|
|
1784
|
+
})
|
|
1785
|
+
|
|
1786
|
+
const simpleAlerts = h('div', { className: 'ops-card' },
|
|
1787
|
+
h('div', { className: 'ops-card-h' }, h('span', null, T.recentAlerts)),
|
|
1788
|
+
h('div', { className: 'ops-card-b' },
|
|
1789
|
+
alerts.length === 0
|
|
1790
|
+
? h('p', { className: 'ops-empty' }, T.noAlerts)
|
|
1791
|
+
: h('div', null, ...alerts.map((alert, index) => h('div', { key: index, className: 'ops-row', style: { gridTemplateColumns: '1fr auto' } },
|
|
1792
|
+
h('span', { style: { display: 'flex', alignItems: 'center', gap: '8px', opacity: alert.acked ? 0.5 : 1 } },
|
|
1793
|
+
h('i', { className: 'ops-dot ' + (alert.level === 'critical' ? 'bad' : alert.level === 'warning' ? 'warn' : '') }),
|
|
1794
|
+
h('span', null, alert.message),
|
|
1795
|
+
h('span', { className: 'ops-dim', style: { fontSize: '11px' } }, fmt(alert.at))),
|
|
1796
|
+
alert.acked
|
|
1797
|
+
? h('span', { className: 'ops-chip' }, T.acked)
|
|
1798
|
+
: h('button', { className: 'ops-btn ops-btn-sm', onClick: () => { void ackAlert(alert) } }, T.alertAck))))))
|
|
1799
|
+
|
|
1800
|
+
const simpleView = h('div', { style: { display: 'flex', flexDirection: 'column', gap: '12px' } },
|
|
1801
|
+
simpleNotice ? h('div', { className: 'ops-ok', style: { fontSize: '12.5px' } }, simpleNotice) : null,
|
|
1802
|
+
info ? h('div', { className: 'ops-chips' },
|
|
1803
|
+
h('span', { className: 'ops-chip' }, `v${info.version}`),
|
|
1804
|
+
h('span', { className: 'ops-dim' }, `${hosts.length} 台服务器`)) : null,
|
|
1805
|
+
...simpleCards,
|
|
1806
|
+
simpleAlerts)
|
|
1807
|
+
|
|
1000
1808
|
const overviewView = hosts.length === 0
|
|
1001
|
-
?
|
|
1002
|
-
: h('div', { style: { display: 'flex', flexDirection: 'column', gap: '12px' } },
|
|
1809
|
+
? onboardingView
|
|
1810
|
+
: uiMode === 'simple' ? simpleView : h('div', { style: { display: 'flex', flexDirection: 'column', gap: '12px' } },
|
|
1003
1811
|
diagView,
|
|
1004
1812
|
summaryStrip,
|
|
1005
1813
|
h('div', { className: 'ops-cards' }, ...hosts.map(hostCard)))
|
|
@@ -1017,15 +1825,43 @@ window.__ModuleLoader__.load({
|
|
|
1017
1825
|
? `${Math.floor(lastSample.uptimeSec / 86400)} 天 ${Math.floor((lastSample.uptimeSec % 86400) / 3600)} 小时`
|
|
1018
1826
|
: '—'
|
|
1019
1827
|
|
|
1020
|
-
const
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1828
|
+
const trend = (field) => {
|
|
1829
|
+
const values = enriched.map(row => row[field]).filter(value => typeof value === 'number')
|
|
1830
|
+
if (values.length < 4) return null
|
|
1831
|
+
const half = Math.floor(values.length / 2)
|
|
1832
|
+
const before = values.slice(0, half).reduce((sum, value) => sum + value, 0) / Math.max(1, half)
|
|
1833
|
+
const after = values.slice(half).reduce((sum, value) => sum + value, 0) / Math.max(1, values.length - half)
|
|
1834
|
+
const delta = after - before
|
|
1835
|
+
if (Math.abs(delta) < 1) return { text: '持平', className: 'ops-dim' }
|
|
1836
|
+
return { text: `${delta > 0 ? '↑' : '↓'}${Math.abs(delta).toFixed(1)}`, className: delta > 0 ? 'ops-warn' : 'ops-ok' }
|
|
1837
|
+
}
|
|
1838
|
+
|
|
1839
|
+
const trendValue = (field, unitText = '%') => {
|
|
1840
|
+
const info = trend(field)
|
|
1841
|
+
return info ? h('em', { className: info.className, style: { fontSize: '11px', fontStyle: 'normal', marginLeft: '6px' } }, info.text) : null
|
|
1842
|
+
}
|
|
1843
|
+
|
|
1844
|
+
const lastAt = lastSample?.ts ? fmt(new Date(lastSample.ts).toISOString()) : '—'
|
|
1845
|
+
|
|
1846
|
+
const monitorSummary = h('div', null,
|
|
1847
|
+
h('div', { className: 'ops-cards' },
|
|
1848
|
+
h('div', { className: 'ops-num' }, h('b', null, `${pct(lastSample?.cpu)}${''}`), h('span', { title: T.tipLoad }, T.cpu, trendValue('cpu'))),
|
|
1849
|
+
h('div', { className: 'ops-num' }, h('b', null, pct(lastSample?.mem)), h('span', null, T.mem, trendValue('mem'))),
|
|
1850
|
+
h('div', { className: 'ops-num' }, h('b', null, pct(lastSample?.disk)), h('span', null, T.disk, trendValue('disk'))),
|
|
1851
|
+
h('div', { className: 'ops-num' }, h('b', null, lastSample?.load1 !== null && lastSample?.load1 !== undefined ? String(lastSample.load1) : '—'), h('span', { title: T.tipLoad }, '负载(1 分钟)', trendValue('load1', '')))),
|
|
1852
|
+
h('div', { className: 'ops-chips', style: { marginTop: '8px' } },
|
|
1853
|
+
h('span', { className: 'ops-dim' }, `负载 ${lastSample?.load1 ?? '—'} / ${lastSample?.load5 ?? '—'} / ${lastSample?.load15 ?? '—'}`),
|
|
1854
|
+
h('span', { className: 'ops-dim' }, `进程 ${lastSample?.procs ?? '—'}`),
|
|
1855
|
+
h('span', { className: 'ops-dim', title: T.tipTcp }, `TCP ${lastSample?.tcp ?? '—'}`),
|
|
1856
|
+
h('span', { className: 'ops-dim', title: T.tipSwap }, `Swap ${lastSample?.swap ?? '—'}%`),
|
|
1857
|
+
h('span', { className: 'ops-dim' }, `已运行 ${uptimeText}`),
|
|
1858
|
+
h('span', { className: 'ops-chip' }, `最近采样 ${lastAt}`)))
|
|
1859
|
+
|
|
1860
|
+
const viewHint = (text) => h('p', { className: 'ops-sub', style: { margin: 0, fontSize: '12.5px' } }, text)
|
|
1027
1861
|
|
|
1028
1862
|
const monitorView = h('div', { style: { display: 'flex', flexDirection: 'column', gap: '12px' } },
|
|
1863
|
+
viewHint(T.hintMonitor),
|
|
1864
|
+
loadingMap.samples && samples.length === 0 ? h('p', { className: 'ops-empty' }, T.loadingList) : null,
|
|
1029
1865
|
h('div', { className: 'ops-chips' },
|
|
1030
1866
|
detailHost ? null : hostPicker(mHost, setMHost),
|
|
1031
1867
|
h('span', { className: 'ops-chip' }, T.hours),
|
|
@@ -1033,16 +1869,20 @@ window.__ModuleLoader__.load({
|
|
|
1033
1869
|
h('button', { key: hours, className: `ops-tab${mHours === hours ? ' on' : ''}`, onClick: () => setMHours(hours) }, label))),
|
|
1034
1870
|
monitorSummary,
|
|
1035
1871
|
h('div', { className: 'ops-grid2' },
|
|
1036
|
-
h(Chart, { rows: enriched, title: T.cpu + ' %', max: 100,
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1872
|
+
h(Chart, { rows: enriched, title: T.cpu + ' %', max: 100, thresholds: [{ value: 80 }, { value: 90, color: 'var(--dsw-alias-danger,#ff6b6b)' }],
|
|
1873
|
+
series: [{ field: 'cpu', label: T.cpu, color: 'var(--dsw-alias-accent,#4c8dff)' }] }),
|
|
1874
|
+
h(Chart, { rows: enriched, title: '内存 / Swap %', max: 100, thresholds: [{ value: 80 }, { value: 90, color: 'var(--dsw-alias-danger,#ff6b6b)' }],
|
|
1875
|
+
series: [
|
|
1876
|
+
{ field: 'mem', label: T.mem, color: 'var(--dsw-alias-accent,#4c8dff)' },
|
|
1877
|
+
{ field: 'swap', label: 'Swap', color: 'var(--dsw-alias-warning,#e5b650)' },
|
|
1878
|
+
] }),
|
|
1879
|
+
h(Chart, { rows: enriched, title: T.disk + ' %', max: 100, thresholds: [{ value: 75 }, { value: 90, color: 'var(--dsw-alias-danger,#ff6b6b)' }],
|
|
1880
|
+
series: [{ field: 'disk', label: T.disk, color: 'var(--dsw-alias-accent,#4c8dff)' }] }),
|
|
1042
1881
|
h(Chart, { rows: enriched, title: '网络 KB/s', unit: ' KB/s', series: [
|
|
1043
1882
|
{ field: 'rxRate', label: '入', color: 'var(--dsw-alias-success,#4ac97e)' },
|
|
1044
1883
|
{ field: 'txRate', label: '出', color: 'var(--dsw-alias-warning,#e5b650)' },
|
|
1045
|
-
] }),
|
|
1884
|
+
] })),
|
|
1885
|
+
h('div', { className: 'ops-grid2' },
|
|
1046
1886
|
h(Chart, { rows: enriched, title: '磁盘读写 KB/s', unit: ' KB/s', series: [
|
|
1047
1887
|
{ field: 'ioReadRate', label: '读', color: 'var(--dsw-alias-accent,#4c8dff)' },
|
|
1048
1888
|
{ field: 'ioWriteRate', label: '写', color: 'var(--dsw-alias-danger,#ff6b6b)' },
|
|
@@ -1056,6 +1896,7 @@ window.__ModuleLoader__.load({
|
|
|
1056
1896
|
h('span', { className: 'ops-mono', title: String(row) }, render ? render(row) : String(row))))))
|
|
1057
1897
|
|
|
1058
1898
|
const configView = h('div', { style: { display: 'flex', flexDirection: 'column', gap: '12px' } },
|
|
1899
|
+
viewHint(T.hintConfig),
|
|
1059
1900
|
h('div', { className: 'ops-chips' }, (detailHost ? null : hostPicker(cHost, setCHost)),
|
|
1060
1901
|
h('button', { className: 'ops-btn ops-btn-sm', disabled: busy === 'scan', onClick: () => { void loadInv(cHost || hosts[0]?.name, true) } }, busy === 'scan' ? T.rescanning : T.rescan)),
|
|
1061
1902
|
inv ? h('div', { className: 'ops-grid2' },
|
|
@@ -1083,9 +1924,61 @@ window.__ModuleLoader__.load({
|
|
|
1083
1924
|
h('button', { className: 'ops-btn ops-btn-sm', onClick: () => { void restoreVersion(backup) } }, T.fileRestore))))),
|
|
1084
1925
|
histDiff ? h('pre', { className: 'ops-pre', style: { maxHeight: '240px', marginTop: '8px' } }, histDiff.diff) : null)))
|
|
1085
1926
|
|
|
1927
|
+
const monitorSuggestions = (() => {
|
|
1928
|
+
if (!inv) return []
|
|
1929
|
+
const existing = new Set((monitors || []).map(item => `${item.type}|${item.target}`))
|
|
1930
|
+
const items = []
|
|
1931
|
+
for (const row of inv.services || []) {
|
|
1932
|
+
const unit = String(row).trim().split(/\s+/)[0]
|
|
1933
|
+
if (!unit) continue
|
|
1934
|
+
items.push({ type: 'service', target: unit, label: serviceLabel(row) || unit })
|
|
1935
|
+
}
|
|
1936
|
+
for (const port of inv.portsParsed || []) {
|
|
1937
|
+
if (!port?.port) continue
|
|
1938
|
+
items.push({ type: 'port', target: `127.0.0.1:${port.port}`, label: `${port.process || '端口'} :${port.port}` })
|
|
1939
|
+
}
|
|
1940
|
+
for (const line of inv.nginx || []) {
|
|
1941
|
+
const match = String(line).match(/server_name\s+([^;]+);/)
|
|
1942
|
+
if (!match) continue
|
|
1943
|
+
for (const domain of match[1].split(/\s+/).filter(value => value && value !== '_' && !value.includes('localhost'))) {
|
|
1944
|
+
items.push({ type: 'http', target: `https://${domain}`, label: domain })
|
|
1945
|
+
}
|
|
1946
|
+
}
|
|
1947
|
+
const seen = new Set()
|
|
1948
|
+
return items.filter(item => {
|
|
1949
|
+
const key = `${item.type}|${item.target}`
|
|
1950
|
+
if (existing.has(key) || seen.has(key)) return false
|
|
1951
|
+
seen.add(key)
|
|
1952
|
+
return true
|
|
1953
|
+
})
|
|
1954
|
+
})()
|
|
1955
|
+
|
|
1086
1956
|
const appsView = h('div', { style: { display: 'flex', flexDirection: 'column', gap: '12px' } },
|
|
1957
|
+
viewHint(T.hintApps),
|
|
1087
1958
|
h('div', { className: 'ops-chips' }, (detailHost ? null : hostPicker(cHost, setCHost)),
|
|
1088
1959
|
h('button', { className: 'ops-btn ops-btn-sm', onClick: () => { void loadInv(cHost || hosts[0]?.name, true) } }, busy === 'scan' ? T.rescanning : T.rescan)),
|
|
1960
|
+
h('div', { className: 'ops-card' },
|
|
1961
|
+
h('div', { className: 'ops-card-h' },
|
|
1962
|
+
h('span', null, T.suggest, h('span', { className: 'ops-chip', style: { marginLeft: '6px' } }, String(monitorSuggestions.length))),
|
|
1963
|
+
h('button', {
|
|
1964
|
+
className: 'ops-btn ops-btn-primary ops-btn-sm',
|
|
1965
|
+
disabled: monitorSuggestions.length === 0 || monBusy === 'suggest',
|
|
1966
|
+
onClick: () => { void addSuggestions(monitorSuggestions) },
|
|
1967
|
+
}, monBusy === 'suggest' ? T.reading : T.suggestAll)),
|
|
1968
|
+
h('div', { className: 'ops-card-b' },
|
|
1969
|
+
monitorSuggestions.length === 0
|
|
1970
|
+
? h('p', { className: 'ops-empty' }, T.suggestNone)
|
|
1971
|
+
: h('div', null, ...monitorSuggestions.slice(0, 12).map(item => h('div', {
|
|
1972
|
+
key: `${item.type}|${item.target}`,
|
|
1973
|
+
className: 'ops-row',
|
|
1974
|
+
style: { gridTemplateColumns: '1fr 1.4fr auto' },
|
|
1975
|
+
},
|
|
1976
|
+
h('span', null,
|
|
1977
|
+
h('span', { className: 'ops-chip' }, (T.monTypeShort || {})[item.type] || item.type), ' ',
|
|
1978
|
+
h('span', { className: 'ops-mono', style: { fontSize: '12px' } }, item.target)),
|
|
1979
|
+
h('span', { className: 'ops-dim' }, item.label || ''),
|
|
1980
|
+
h('span', { style: { display: 'flex', justifyContent: 'flex-end' } },
|
|
1981
|
+
h('button', { className: 'ops-btn ops-btn-sm', onClick: () => { void addSuggestions([item]) } }, T.suggestAdd))))))),
|
|
1089
1982
|
h('div', { className: 'ops-card' },
|
|
1090
1983
|
h('div', { className: 'ops-card-h' }, h('span', null, T.tabs[3]), h('span', { className: 'ops-chip' }, String((inv?.apps || []).length))),
|
|
1091
1984
|
(inv?.apps || []).length === 0 ? h('p', { className: 'ops-empty' }, T.empty)
|
|
@@ -1176,65 +2069,261 @@ window.__ModuleLoader__.load({
|
|
|
1176
2069
|
h('div', { className: sslResult.daysLeft !== null && sslResult.daysLeft < 15 ? 'ops-bad' : 'ops-sub', style: { fontSize: '12px' } },
|
|
1177
2070
|
sslResult.daysLeft === null ? T.noExpire : `${T.expireAt} ${sslResult.notAfter} · ${T.daysLeft} ${sslResult.daysLeft}`)) : null)))
|
|
1178
2071
|
|
|
1179
|
-
|
|
1180
|
-
const
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
2072
|
+
React.useEffect(() => {
|
|
2073
|
+
const el = document.getElementById('ops-logbox')
|
|
2074
|
+
if (!el) return
|
|
2075
|
+
el.scrollTop = logAuto ? el.scrollHeight : 0
|
|
2076
|
+
}, [logText, logAuto])
|
|
2077
|
+
|
|
2078
|
+
const logLineCount = logText ? logText.split('\n').length : 0
|
|
2079
|
+
|
|
2080
|
+
/** Collapse Java-style stack frames under the exception line they belong to. */
|
|
2081
|
+
const logEntries = (() => {
|
|
2082
|
+
const lines = (logText || '').split('\n').slice(0, 3000)
|
|
2083
|
+
const entries = []
|
|
2084
|
+
let current = null
|
|
2085
|
+
for (const line of lines) {
|
|
2086
|
+
const isFrame = /(^|[\s:])\s*at\s+[A-Za-z0-9_$./<>]+\(/.test(line)
|
|
2087
|
+
|| /\.\.\.\s+\d+\s+more\s*$/.test(line)
|
|
2088
|
+
|| /\bSuppressed:\s/.test(line)
|
|
2089
|
+
if (isFrame) {
|
|
2090
|
+
if (!current) {
|
|
2091
|
+
current = { type: 'event', text: '', frames: [] }
|
|
2092
|
+
entries.push(current)
|
|
2093
|
+
}
|
|
2094
|
+
current.frames.push(line)
|
|
2095
|
+
continue
|
|
2096
|
+
}
|
|
2097
|
+
if (/Exception|Error|ERROR|Caused by:|FATAL/i.test(line)) {
|
|
2098
|
+
current = { type: 'event', text: line, frames: [] }
|
|
2099
|
+
entries.push(current)
|
|
2100
|
+
continue
|
|
2101
|
+
}
|
|
2102
|
+
current = null
|
|
2103
|
+
entries.push({ type: 'line', text: line })
|
|
2104
|
+
}
|
|
2105
|
+
return entries
|
|
1186
2106
|
})()
|
|
1187
2107
|
|
|
2108
|
+
const toggleFrame = (index) => {
|
|
2109
|
+
setLogExpanded(current => ({ ...current, [index]: !current[index] }))
|
|
2110
|
+
}
|
|
2111
|
+
|
|
2112
|
+
const logLineView = logEntries.map((entry, index) => {
|
|
2113
|
+
if (entry.type === 'line') {
|
|
2114
|
+
const className = /error|critical|fatal|exception|traceback/i.test(entry.text) ? 'ops-log-err'
|
|
2115
|
+
: /warn/i.test(entry.text) ? 'ops-log-warn' : undefined
|
|
2116
|
+
return h('div', { key: index, className }, entry.text || ' ')
|
|
2117
|
+
}
|
|
2118
|
+
const open = logAllOpen || Boolean(logExpanded[index])
|
|
2119
|
+
const headClass = /error|critical|fatal|exception/i.test(entry.text) ? 'ops-log-err'
|
|
2120
|
+
: /warn/i.test(entry.text) ? 'ops-log-warn' : undefined
|
|
2121
|
+
return h('div', { key: index },
|
|
2122
|
+
h('div', { className: headClass }, entry.text),
|
|
2123
|
+
entry.frames.length
|
|
2124
|
+
? h('div', null,
|
|
2125
|
+
h('button', {
|
|
2126
|
+
className: 'ops-log-fold',
|
|
2127
|
+
onClick: () => toggleFrame(index),
|
|
2128
|
+
}, `${open ? '▾' : '▸'} ${entry.frames.length} ${T.logFrames} ${open ? T.logCollapse : T.logExpand}`),
|
|
2129
|
+
open ? h('div', { className: 'ops-log-frames' }, ...entry.frames.map((frame, i) => h('div', { key: i }, frame))) : null)
|
|
2130
|
+
: null)
|
|
2131
|
+
})
|
|
2132
|
+
|
|
2133
|
+
const loadLogUsage = async () => {
|
|
2134
|
+
try { const data = await api(`log-usage?host=${encodeURIComponent(cHost || hosts[0]?.name)}`, {}, 90_000); setLogUsageData(data) }
|
|
2135
|
+
catch { setLogUsageData(null) }
|
|
2136
|
+
}
|
|
2137
|
+
|
|
2138
|
+
const openCleanPreview = async (host) => {
|
|
2139
|
+
const target = host || cHost || hosts[0]?.name || ''
|
|
2140
|
+
setCleanBusyHost(target)
|
|
2141
|
+
try {
|
|
2142
|
+
const data = await api(`cleanup-preview?host=${encodeURIComponent(host || cHost || hosts[0]?.name)}`, {}, 90_000)
|
|
2143
|
+
const paths = {}
|
|
2144
|
+
for (const file of data.files || []) paths[file.path] = true
|
|
2145
|
+
setCleanSel({ journal: (data.journal?.freedMb ?? 0) > 0, paths })
|
|
2146
|
+
setCleanBackupFile(null)
|
|
2147
|
+
setCleanPreview(data)
|
|
2148
|
+
} catch (e) { setError(String(e.message || e)) } finally { setCleanBusyHost('') }
|
|
2149
|
+
}
|
|
2150
|
+
|
|
2151
|
+
const selectedLogPaths = () => Object.keys(cleanSel.paths).filter(path => cleanSel.paths[path])
|
|
2152
|
+
|
|
2153
|
+
const backupSelected = async () => {
|
|
2154
|
+
const paths = selectedLogPaths()
|
|
2155
|
+
if (!paths.length) { setError(T.cleanNothingSelected); return }
|
|
2156
|
+
setBackupBusy(true)
|
|
2157
|
+
try {
|
|
2158
|
+
const data = await api('log-backup', { method: 'POST', body: JSON.stringify({ host: cleanPreview.host, paths }) }, 300_000)
|
|
2159
|
+
if (!data.ok) throw new Error(data.error || 'backup failed')
|
|
2160
|
+
setCleanBackupFile(data)
|
|
2161
|
+
setNotice(`${T.cleanBackupDone}:${data.path}(${data.sizeMb} MB)`)
|
|
2162
|
+
setTimeout(() => setNotice(''), 6000)
|
|
2163
|
+
} catch (e) { setError(String(e.message || e)) } finally { setBackupBusy(false) }
|
|
2164
|
+
}
|
|
2165
|
+
|
|
2166
|
+
const downloadBackup = async () => {
|
|
2167
|
+
if (!cleanBackupFile) return
|
|
2168
|
+
await downloadFile(cleanBackupFile.path, cleanBackupFile.path.split('/').pop())
|
|
2169
|
+
}
|
|
2170
|
+
|
|
2171
|
+
const confirmClean = async () => {
|
|
2172
|
+
if (!cleanPreview) return
|
|
2173
|
+
setCleanRunBusy(true)
|
|
2174
|
+
try {
|
|
2175
|
+
const paths = selectedLogPaths()
|
|
2176
|
+
if (!paths.length && !cleanSel.journal) { setError(T.cleanNothingSelected); return }
|
|
2177
|
+
const data = await api('cleanup', { method: 'POST', body: JSON.stringify({ host: cleanPreview.host, confirm: true, paths, includeJournal: cleanSel.journal }) }, timeoutFor('action') * 3)
|
|
2178
|
+
setNotice(T.logCleanResult.replace('{0}', data.freedMb ?? 0).replace('{1}', data.before ?? '?').replace('{2}', data.after ?? '?'))
|
|
2179
|
+
setTimeout(() => setNotice(''), 5000)
|
|
2180
|
+
setCleanPreview(null)
|
|
2181
|
+
await loadLogUsage()
|
|
2182
|
+
} catch (e) { setError(String(e.message || e)) } finally { setCleanRunBusy(false) }
|
|
2183
|
+
}
|
|
2184
|
+
|
|
2185
|
+
const cleanByPolicy = async () => {
|
|
2186
|
+
const keep = Number(config.logKeepDays) || 7
|
|
2187
|
+
const journal = Number(config.logJournalMb) || 200
|
|
2188
|
+
if (!window.confirm(`${T.logCleanNow}?\n${T.logPolicy.replace('{0}', keep).replace('{1}', journal)}`)) return
|
|
2189
|
+
setLogPolicyBusy(true)
|
|
2190
|
+
try {
|
|
2191
|
+
const data = await api('cleanup', { method: 'POST', body: JSON.stringify({ host: cHost || hosts[0]?.name, confirm: true }) }, timeoutFor('action') * 3)
|
|
2192
|
+
setNotice(T.logCleanResult.replace('{0}', data.freedMb ?? 0).replace('{1}', data.before ?? '?').replace('{2}', data.after ?? '?'))
|
|
2193
|
+
setTimeout(() => setNotice(''), 5000)
|
|
2194
|
+
await loadLogUsage()
|
|
2195
|
+
} catch (e) { setError(String(e.message || e)) } finally { setLogPolicyBusy(false) }
|
|
2196
|
+
}
|
|
2197
|
+
|
|
2198
|
+
const copyLogs = async () => {
|
|
2199
|
+
try {
|
|
2200
|
+
await navigator.clipboard.writeText(logText || '')
|
|
2201
|
+
setNotice(T.logCopied)
|
|
2202
|
+
setTimeout(() => setNotice(''), 1500)
|
|
2203
|
+
} catch { /* clipboard unavailable */ }
|
|
2204
|
+
}
|
|
2205
|
+
|
|
2206
|
+
const logUsageCard = h('div', { className: 'ops-card' },
|
|
2207
|
+
h('div', { className: 'ops-card-h' },
|
|
2208
|
+
h('span', null, T.logUsage,
|
|
2209
|
+
logUsageData?.disk !== null && logUsageData?.disk !== undefined ? h('span', { className: 'ops-chip', style: { marginLeft: '6px' } }, `磁盘 ${logUsageData.disk}%`) : null),
|
|
2210
|
+
h('span', { className: 'ops-chips' },
|
|
2211
|
+
h('button', { className: 'ops-btn ops-btn-sm', disabled: logPolicyBusy, onClick: () => { void loadLogUsage() } }, T.fsRefresh),
|
|
2212
|
+
h('button', { className: 'ops-btn ops-btn-primary ops-btn-sm', disabled: Boolean(cleanBusyHost) || backupBusy || cleanRunBusy, onClick: () => { void openCleanPreview(cHost) } }, T.logCleanNow))),
|
|
2213
|
+
h('div', { className: 'ops-card-b' },
|
|
2214
|
+
logUsageData
|
|
2215
|
+
? h('div', null,
|
|
2216
|
+
h('div', { className: 'ops-modal-row' }, h('b', null, T.logJournal), h('span', null, logUsageData.journalMb !== null && logUsageData.journalMb !== undefined ? `${logUsageData.journalMb} MB` : (logUsageData.journal || '—'))),
|
|
2217
|
+
h('div', { className: 'ops-modal-row' }, h('b', null, T.logTotal), h('span', null, `${logUsageData.totalMb || 0} MB`)),
|
|
2218
|
+
h('p', { className: 'ops-sub', style: { margin: '6px 0' } }, T.logPolicy.replace('{0}', Number(config.logKeepDays) || 7).replace('{1}', Number(config.logJournalMb) || 200)),
|
|
2219
|
+
logUsageData.files.length
|
|
2220
|
+
? h('div', null,
|
|
2221
|
+
h('div', { className: 'ops-sub', style: { fontSize: '11px' } }, T.logTop),
|
|
2222
|
+
...logUsageData.files.map(file => h('div', { key: file.path, className: 'ops-row', style: { gridTemplateColumns: '1fr auto auto' } },
|
|
2223
|
+
h('span', { className: 'ops-mono', style: { fontSize: '11.5px' } }, file.path),
|
|
2224
|
+
h('span', { className: 'ops-dim' }, `${(file.bytes / 1048576).toFixed(1)} MB`),
|
|
2225
|
+
h('span', { className: 'ops-dim', style: { fontSize: '11px' } }, fmt(file.at)))))
|
|
2226
|
+
: h('p', { className: 'ops-empty' }, T.logNoBig),
|
|
2227
|
+
h('p', { className: 'ops-sub', style: { margin: '6px 0 0', fontSize: '11.5px' } }, T.logUsageHint))
|
|
2228
|
+
: h('p', { className: 'ops-empty' }, T.logNoUsage)))
|
|
2229
|
+
|
|
1188
2230
|
const logsView = h('div', { style: { display: 'flex', flexDirection: 'column', gap: '12px' } },
|
|
2231
|
+
viewHint(T.hintLogs),
|
|
2232
|
+
logUsageCard,
|
|
1189
2233
|
h('div', { className: 'ops-chips' }, (detailHost ? null : hostPicker(cHost, setCHost))),
|
|
1190
2234
|
h('div', { className: 'ops-card' },
|
|
1191
2235
|
h('div', { className: 'ops-card-h' }, h('span', null, T.logs),
|
|
1192
2236
|
h('span', { className: 'ops-chips' },
|
|
2237
|
+
notice ? h('span', { className: 'ops-ok', style: { fontSize: '12px' } }, notice) : null,
|
|
2238
|
+
h('span', { className: 'ops-dim', style: { fontSize: '12px' } }, `${logLineCount}${logCount && logCount !== logLineCount ? ` / ${logCount}` : ''}`),
|
|
1193
2239
|
h('label', { className: 'ops-sub', style: { display: 'flex', gap: '6px', alignItems: 'center' } },
|
|
1194
2240
|
h('input', { type: 'checkbox', checked: logAuto, onChange: e => setLogAuto(e.target.checked) }), T.auto),
|
|
2241
|
+
h('button', { className: 'ops-btn ops-btn-sm', onClick: () => setLogAllOpen(value => !value) }, logAllOpen ? T.logCollapseAll : T.logExpandAll),
|
|
2242
|
+
h('button', { className: 'ops-btn ops-btn-sm', onClick: () => { void copyLogs() } }, T.logCopy),
|
|
1195
2243
|
h('button', { className: 'ops-btn ops-btn-primary ops-btn-sm', disabled: busy === 'logs', onClick: () => { void loadLogs() } }, busy === 'logs' ? T.reading : T.load))),
|
|
1196
2244
|
h('div', { className: 'ops-card-b' },
|
|
1197
2245
|
h('div', { className: 'ops-chips' },
|
|
2246
|
+
h('select', {
|
|
2247
|
+
className: 'ops-input',
|
|
2248
|
+
style: { flex: '1 1 280px' },
|
|
2249
|
+
value: logGroups.some(group => group.items.some(item => item.value === logSource)) ? logSource : '',
|
|
2250
|
+
onChange: event => {
|
|
2251
|
+
const value = event.target.value
|
|
2252
|
+
if (!value) return
|
|
2253
|
+
setLogSource(value)
|
|
2254
|
+
setTimeout(() => { void loadLogs(value) }, 0)
|
|
2255
|
+
},
|
|
2256
|
+
},
|
|
2257
|
+
h('option', { value: '' }, logGroups.length ? T.logPick : '…'),
|
|
2258
|
+
...logGroups.map(group => h('optgroup', { key: group.label, label: group.label },
|
|
2259
|
+
...group.items.map(item => h('option', { key: item.value, value: item.value }, item.label)))),
|
|
1198
2260
|
h('input', {
|
|
1199
|
-
className: 'ops-input', style: { flex: '1 1
|
|
1200
|
-
placeholder: T.
|
|
2261
|
+
className: 'ops-input', style: { flex: '1 1 220px' }, value: logSource,
|
|
2262
|
+
placeholder: T.logManual, onChange: e => setLogSource(e.target.value),
|
|
1201
2263
|
onKeyDown: e => { if (e.key === 'Enter') void loadLogs() },
|
|
1202
2264
|
}),
|
|
1203
|
-
h('datalist', { id: 'ops-log-sources' }, ...logChoices.map(o => h('option', { key: o, value: o }))),
|
|
1204
2265
|
h('label', { className: 'ops-sub' }, T.lines,
|
|
1205
|
-
h('input', { className: 'ops-input', type: 'number', min: 20, max:
|
|
1206
|
-
h('
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
h('
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
h('
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
2266
|
+
h('input', { className: 'ops-input', type: 'number', min: 20, max: 2000, value: logLines, style: { width: '90px' }, onChange: e => setLogLines(Number(e.target.value)) }))),
|
|
2267
|
+
h('div', { className: 'ops-chips', style: { marginTop: '8px', flexWrap: 'wrap' } },
|
|
2268
|
+
h('input', {
|
|
2269
|
+
className: 'ops-input', style: { flex: '1 1 240px' }, value: logGrep,
|
|
2270
|
+
placeholder: T.logGrep, onChange: e => setLogGrep(e.target.value),
|
|
2271
|
+
onKeyDown: e => { if (e.key === 'Enter') void loadLogs() },
|
|
2272
|
+
}),
|
|
2273
|
+
h('span', { style: { display: 'inline-flex', alignItems: 'center', gap: '6px' } },
|
|
2274
|
+
h('span', { className: 'ops-chip' }, T.logLevel),
|
|
2275
|
+
h('select', {
|
|
2276
|
+
className: 'ops-input', style: { width: '120px' }, value: logLevel,
|
|
2277
|
+
onChange: e => { setLogLevel(e.target.value); setTimeout(() => { void loadLogs() }, 0) },
|
|
2278
|
+
},
|
|
2279
|
+
h('option', { value: '' }, T.logAll),
|
|
2280
|
+
h('option', { value: 'error' }, T.logErrors),
|
|
2281
|
+
h('option', { value: 'warn' }, T.logWarnings))),
|
|
2282
|
+
h('span', { style: { display: 'inline-flex', alignItems: 'center', gap: '6px' } },
|
|
2283
|
+
h('span', { className: 'ops-chip' }, T.logRange),
|
|
2284
|
+
h('select', {
|
|
2285
|
+
className: 'ops-input', style: { width: '130px' }, value: String(logSince),
|
|
2286
|
+
onChange: e => { setLogSince(Number(e.target.value)); setTimeout(() => { void loadLogs() }, 0) },
|
|
2287
|
+
},
|
|
2288
|
+
h('option', { value: '0' }, T.logRangeAll),
|
|
2289
|
+
h('option', { value: '5' }, T.logRange5),
|
|
2290
|
+
h('option', { value: '60' }, T.logRange60),
|
|
2291
|
+
h('option', { value: '1440' }, T.logRangeDay)))),
|
|
2292
|
+
h('p', { className: 'ops-sub', style: { margin: '6px 0 8px', fontSize: '12px' } }, T.logHint),
|
|
2293
|
+
h('div', { className: 'ops-logbox', id: 'ops-logbox' },
|
|
2294
|
+
logText
|
|
2295
|
+
? logLineView
|
|
2296
|
+
: h('p', { className: 'ops-empty' }, busy === 'logs' ? T.reading : T.logEmpty))))))
|
|
2297
|
+
|
|
2298
|
+
const sizeText = (bytes, dir) => {
|
|
2299
|
+
if (dir) return '—'
|
|
2300
|
+
const n = Number(bytes) || 0
|
|
2301
|
+
if (n < 1024) return `${n} B`
|
|
2302
|
+
if (n < 1024 * 1024) return `${(n / 1024).toFixed(1)} KB`
|
|
2303
|
+
if (n < 1024 * 1024 * 1024) return `${(n / 1048576).toFixed(1)} MB`
|
|
2304
|
+
return `${(n / 1073741824).toFixed(1)} GB`
|
|
2305
|
+
}
|
|
2306
|
+
|
|
2307
|
+
const renderTreeNode = (path, depth) => {
|
|
2308
|
+
const children = (fsTree[path] || []).filter(entry => entry.dir)
|
|
2309
|
+
const open = Boolean(fsOpen[path])
|
|
2310
|
+
return h('div', { key: path },
|
|
2311
|
+
h('div', {
|
|
2312
|
+
className: 'ops-fm-node' + (fsPath === path ? ' on' : ''),
|
|
2313
|
+
style: { paddingLeft: `${6 + depth * 12}px` },
|
|
2314
|
+
onClick: () => goPath(path),
|
|
2315
|
+
},
|
|
2316
|
+
children.length
|
|
2317
|
+
? h('span', {
|
|
2318
|
+
className: 'ops-fm-caret',
|
|
2319
|
+
onClick: event => { event.stopPropagation(); toggleDir(path) },
|
|
2320
|
+
}, open ? '▾' : '▸')
|
|
2321
|
+
: h('span', { className: 'ops-fm-caret' }, ' '),
|
|
2322
|
+
h('span', { className: 'ops-fm-name' }, path === '/' ? '/' : path.split('/').filter(Boolean).pop())),
|
|
2323
|
+
open ? children.map(child => renderTreeNode(child.path, depth + 1)) : null)
|
|
2324
|
+
}
|
|
1236
2325
|
|
|
1237
|
-
|
|
2326
|
+
const termKey = (event) => {
|
|
1238
2327
|
if (!term?.id) return
|
|
1239
2328
|
if (aiMode) {
|
|
1240
2329
|
if (event.key === 'Escape') { event.preventDefault(); setAiMode(false); setAiDraft(''); return }
|
|
@@ -1263,10 +2352,11 @@ window.__ModuleLoader__.load({
|
|
|
1263
2352
|
}
|
|
1264
2353
|
|
|
1265
2354
|
|
|
1266
|
-
const dhost = () => detailHost || cHost
|
|
1267
2355
|
|
|
1268
2356
|
const loadChannels = async () => {
|
|
2357
|
+
markLoading('channels', true)
|
|
1269
2358
|
try { const data = await api('channels', {}, 20_000); setChannels(data.channels || []) } catch { setChannels([]) }
|
|
2359
|
+
finally { markLoading('channels', false) }
|
|
1270
2360
|
}
|
|
1271
2361
|
|
|
1272
2362
|
const saveChannel = async () => {
|
|
@@ -1293,7 +2383,7 @@ window.__ModuleLoader__.load({
|
|
|
1293
2383
|
try {
|
|
1294
2384
|
const data = await api('channels', { method: 'POST', body: JSON.stringify({ action: 'remove', id }) })
|
|
1295
2385
|
setChannels(data.channels || [])
|
|
1296
|
-
} catch (e) { setError(String(e.message || e)) }
|
|
2386
|
+
} catch (e) { setError(String(e.message || e)) } finally { setOpBusy('') }
|
|
1297
2387
|
}
|
|
1298
2388
|
|
|
1299
2389
|
const loadHealth = async (host) => {
|
|
@@ -1306,8 +2396,10 @@ window.__ModuleLoader__.load({
|
|
|
1306
2396
|
|
|
1307
2397
|
const loadCerts = async (host) => {
|
|
1308
2398
|
if (!host) return
|
|
2399
|
+
markLoading('certs', true)
|
|
1309
2400
|
try { const data = await api(`certs?host=${encodeURIComponent(host)}`, {}, 60_000); setCerts(data.certs || []) }
|
|
1310
2401
|
catch { setCerts([]) }
|
|
2402
|
+
finally { markLoading('certs', false) }
|
|
1311
2403
|
}
|
|
1312
2404
|
|
|
1313
2405
|
const renewCertsNow = async (dryRun) => {
|
|
@@ -1357,8 +2449,10 @@ window.__ModuleLoader__.load({
|
|
|
1357
2449
|
|
|
1358
2450
|
const loadCron = async (host) => {
|
|
1359
2451
|
if (!host) return
|
|
2452
|
+
markLoading('cron', true)
|
|
1360
2453
|
try { const data = await api(`cron?host=${encodeURIComponent(host)}`, {}, 30_000); setCronJobs(data.jobs || []) }
|
|
1361
2454
|
catch { setCronJobs([]) }
|
|
2455
|
+
finally { markLoading('cron', false) }
|
|
1362
2456
|
}
|
|
1363
2457
|
|
|
1364
2458
|
const addCronJob = async () => {
|
|
@@ -1435,12 +2529,114 @@ window.__ModuleLoader__.load({
|
|
|
1435
2529
|
} catch (e) { setError(String(e.message || e)) }
|
|
1436
2530
|
}
|
|
1437
2531
|
|
|
2532
|
+
const loadServicesUi = async (host) => {
|
|
2533
|
+
markLoading('services', true)
|
|
2534
|
+
try { const data = await api(`services?host=${encodeURIComponent(host)}`, {}, 30_000); setServices(data.services || []) } catch { setServices([]) }
|
|
2535
|
+
finally { markLoading('services', false) }
|
|
2536
|
+
}
|
|
2537
|
+
|
|
2538
|
+
const loadMaintenance = async (host) => {
|
|
2539
|
+
try { const data = await api(`maintenance?host=${encodeURIComponent(host)}`, {}, 20_000); setMaintenanceUntil(data.until || null) } catch { setMaintenanceUntil(null) }
|
|
2540
|
+
}
|
|
2541
|
+
|
|
2542
|
+
const setMaintenanceUi = async (minutes) => {
|
|
2543
|
+
setP2Busy('maint')
|
|
2544
|
+
try {
|
|
2545
|
+
const data = await api('maintenance', { method: 'POST', body: JSON.stringify({ host: dhost(), minutes }) }, 20_000)
|
|
2546
|
+
setMaintenanceUntil(data.until || null)
|
|
2547
|
+
setNotice(minutes ? `${T.maintenanceOn}(${minutes} 分钟)` : T.maintenanceOff)
|
|
2548
|
+
setTimeout(() => setNotice(''), 3000)
|
|
2549
|
+
} catch (e) { setError(String(e.message || e)) } finally { setP2Busy('') }
|
|
2550
|
+
}
|
|
2551
|
+
|
|
2552
|
+
const createServiceUi = async () => {
|
|
2553
|
+
if (monitors.length === 0) return
|
|
2554
|
+
const name = window.prompt(T.serviceName, '网站')
|
|
2555
|
+
if (!name) return
|
|
2556
|
+
setP2Busy('svc')
|
|
2557
|
+
try {
|
|
2558
|
+
const data = await api('services', { method: 'POST', body: JSON.stringify({ host: dhost(), name, ids: monitors.map(item => item.id) }) }, 30_000)
|
|
2559
|
+
setServices(data.services || [])
|
|
2560
|
+
} catch (e) { setError(String(e.message || e)) } finally { setP2Busy('') }
|
|
2561
|
+
}
|
|
2562
|
+
|
|
2563
|
+
const removeServiceUi = async (id) => {
|
|
2564
|
+
if (!window.confirm(T.serviceRemove + '?')) return
|
|
2565
|
+
try {
|
|
2566
|
+
const data = await api('services', { method: 'POST', body: JSON.stringify({ host: dhost(), action: 'remove', id }) }, 20_000)
|
|
2567
|
+
setServices(data.services || [])
|
|
2568
|
+
} catch (e) { setError(String(e.message || e)) }
|
|
2569
|
+
}
|
|
2570
|
+
|
|
2571
|
+
const ackMonitorUi = async (id, minutes) => {
|
|
2572
|
+
setP2Busy('ack:' + id)
|
|
2573
|
+
try {
|
|
2574
|
+
await api('ack', { method: 'POST', body: JSON.stringify({ host: dhost(), id, minutes }) }, 20_000)
|
|
2575
|
+
await loadMonitors(dhost())
|
|
2576
|
+
setNotice(minutes ? T.mute1h : T.ackHint)
|
|
2577
|
+
setTimeout(() => setNotice(''), 3000)
|
|
2578
|
+
} catch (e) { setError(String(e.message || e)) } finally { setP2Busy('') }
|
|
2579
|
+
}
|
|
2580
|
+
|
|
2581
|
+
const loadTemplatesUi = async () => {
|
|
2582
|
+
try { const data = await api('templates', {}, 20_000); setTemplates(data.templates || []) } catch { setTemplates([]) }
|
|
2583
|
+
}
|
|
2584
|
+
|
|
2585
|
+
const addSuggestions = async (items) => {
|
|
2586
|
+
if (!items.length) return
|
|
2587
|
+
setMonBusy('suggest')
|
|
2588
|
+
try {
|
|
2589
|
+
const data = await api('monitors', { method: 'POST', body: JSON.stringify({ host: dhost(), action: 'bulk', items }) }, 120_000)
|
|
2590
|
+
setMonitors(data.monitors || [])
|
|
2591
|
+
const skipped = (data.skipped || []).length
|
|
2592
|
+
setNotice(`新增 ${(data.created || []).length} 项${skipped ? `,${skipped} 项已存在` : ''}`)
|
|
2593
|
+
setTimeout(() => setNotice(''), 4000)
|
|
2594
|
+
} catch (e) { setError(String(e.message || e)) } finally { setMonBusy('') }
|
|
2595
|
+
}
|
|
2596
|
+
|
|
2597
|
+
const saveAsTemplate = async () => {
|
|
2598
|
+
if (monitors.length === 0) return
|
|
2599
|
+
const name = window.prompt(T.templateName, `${dhost()} 监控`)
|
|
2600
|
+
if (!name) return
|
|
2601
|
+
setMonBusy('template')
|
|
2602
|
+
try {
|
|
2603
|
+
const items = monitors.map(item => ({ type: item.type, target: item.target, label: item.label, intervalMinutes: item.intervalMinutes, maxAttempts: item.maxAttempts, script: item.script, language: item.language }))
|
|
2604
|
+
const data = await api('templates', { method: 'POST', body: JSON.stringify({ action: 'save', name, items }) }, 30_000)
|
|
2605
|
+
setTemplates(data.templates || [])
|
|
2606
|
+
} catch (e) { setError(String(e.message || e)) } finally { setMonBusy('') }
|
|
2607
|
+
}
|
|
2608
|
+
|
|
2609
|
+
const applyTemplateUi = async (all) => {
|
|
2610
|
+
if (!templateId) return
|
|
2611
|
+
setMonBusy('template')
|
|
2612
|
+
try {
|
|
2613
|
+
const hosts = all ? hosts.map(item => item.name) : [dhost()]
|
|
2614
|
+
const data = await api('templates', { method: 'POST', body: JSON.stringify({ action: 'apply', id: templateId, hosts }) }, 300_000)
|
|
2615
|
+
const created = (data.results || []).reduce((sum, row) => sum + (row.created || []).length, 0)
|
|
2616
|
+
setNotice(`${T.templateApplied}:新增 ${created} 项`)
|
|
2617
|
+
setTimeout(() => setNotice(''), 4000)
|
|
2618
|
+
await loadMonitors(dhost())
|
|
2619
|
+
} catch (e) { setError(String(e.message || e)) } finally { setMonBusy('') }
|
|
2620
|
+
}
|
|
2621
|
+
|
|
2622
|
+
const removeTemplateUi = async () => {
|
|
2623
|
+
if (!templateId) return
|
|
2624
|
+
if (!window.confirm(T.templateDelete + '?')) return
|
|
2625
|
+
try {
|
|
2626
|
+
const data = await api('templates', { method: 'POST', body: JSON.stringify({ action: 'remove', id: templateId }) }, 20_000)
|
|
2627
|
+
setTemplates(data.templates || [])
|
|
2628
|
+
setTemplateId('')
|
|
2629
|
+
} catch (e) { setError(String(e.message || e)) }
|
|
2630
|
+
}
|
|
2631
|
+
|
|
1438
2632
|
const loadMonitors = async (host) => {
|
|
2633
|
+
markLoading('monitors', true)
|
|
1439
2634
|
if (!host) return
|
|
1440
2635
|
try {
|
|
1441
2636
|
const data = await api(`monitors?host=${encodeURIComponent(host)}`, {}, 20_000)
|
|
1442
2637
|
setMonitors(data.monitors || [])
|
|
1443
2638
|
} catch { setMonitors([]) }
|
|
2639
|
+
finally { markLoading('monitors', false) }
|
|
1444
2640
|
}
|
|
1445
2641
|
|
|
1446
2642
|
const saveMonitor = async () => {
|
|
@@ -1499,17 +2695,7 @@ window.__ModuleLoader__.load({
|
|
|
1499
2695
|
} catch (e) { setError(String(e.message || e)) }
|
|
1500
2696
|
}
|
|
1501
2697
|
|
|
1502
|
-
const openHost = (name) => {
|
|
1503
|
-
setDetailHost(name)
|
|
1504
|
-
setCHost(name)
|
|
1505
|
-
setMHost(name)
|
|
1506
|
-
setDetailTab('summary')
|
|
1507
|
-
void loadMonitors(name)
|
|
1508
|
-
void loadHealth(name)
|
|
1509
|
-
void loadCerts(name)
|
|
1510
|
-
}
|
|
1511
2698
|
|
|
1512
|
-
const focusTerm = () => { const el = document.getElementById('ops-term'); if (el) el.focus() }
|
|
1513
2699
|
|
|
1514
2700
|
const askHost = async () => {
|
|
1515
2701
|
const question = askQuestion.trim()
|
|
@@ -1579,19 +2765,128 @@ window.__ModuleLoader__.load({
|
|
|
1579
2765
|
focusTerm()
|
|
1580
2766
|
}
|
|
1581
2767
|
|
|
2768
|
+
const filesView = h('div', { style: { display: 'flex', flexDirection: 'column', gap: '10px' } },
|
|
2769
|
+
viewHint(T.hintFiles),
|
|
2770
|
+
h('div', { className: 'ops-chips' }, (detailHost ? null : hostPicker(cHost, setCHost))),
|
|
2771
|
+
h('div', { className: 'ops-fm' },
|
|
2772
|
+
h('div', { className: 'ops-fm-tree' },
|
|
2773
|
+
h('div', { className: 'ops-fm-tree-h' }, T.fsTree),
|
|
2774
|
+
h('div', { className: 'ops-fm-tree-body' }, renderTreeNode('/', 0))),
|
|
2775
|
+
h('div', { className: 'ops-fm-main' },
|
|
2776
|
+
h('div', { className: 'ops-chips', style: { flexWrap: 'wrap' } },
|
|
2777
|
+
h('input', {
|
|
2778
|
+
className: 'ops-input',
|
|
2779
|
+
style: { flex: '1 1 240px' },
|
|
2780
|
+
value: fsPath,
|
|
2781
|
+
onChange: event => setFsPath(event.target.value),
|
|
2782
|
+
onKeyDown: event => { if (event.key === 'Enter') goPath(fsPath) },
|
|
2783
|
+
}),
|
|
2784
|
+
h('button', {
|
|
2785
|
+
className: 'ops-btn ops-btn-sm',
|
|
2786
|
+
title: fsFavs.favs.includes(fsPath) ? T.fsFavRemove : T.fsFav,
|
|
2787
|
+
onClick: () => toggleFav(fsPath),
|
|
2788
|
+
}, fsFavs.favs.includes(fsPath) ? '★' : '☆'),
|
|
2789
|
+
h('button', { className: 'ops-btn ops-btn-sm', disabled: fsBusy === 'list', onClick: () => { void loadFiles(fsPath) } }, T.fsRefresh),
|
|
2790
|
+
h('label', { className: 'ops-btn ops-btn-sm', style: { cursor: 'pointer' } }, T.upload,
|
|
2791
|
+
h('input', { type: 'file', style: { display: 'none' }, onChange: event => { void uploadFile(event.target.files?.[0]); event.target.value = '' } })),
|
|
2792
|
+
h('button', { className: 'ops-btn ops-btn-sm', disabled: !fsSel || fsSel.dir, onClick: () => { if (fsSel) void downloadFile(fsSel.path, fsSel.name) } }, T.fsDownload),
|
|
2793
|
+
h('button', { className: 'ops-btn ops-btn-sm', onClick: () => { void fsMkdir() } }, T.fsNewFolder),
|
|
2794
|
+
h('button', { className: 'ops-btn ops-btn-sm', disabled: selectedPaths().length === 0, onClick: () => { void fsChmod() } }, T.fsChmod),
|
|
2795
|
+
h('button', { className: 'ops-btn ops-btn-sm', disabled: selectedPaths().length === 0 || fsBusy === 'compress', onClick: () => { void fsCompress() } }, T.fsCompress),
|
|
2796
|
+
h('button', { className: 'ops-btn ops-btn-sm', disabled: selectedPaths().length !== 1 || fsBusy === 'extract', onClick: () => { void fsExtract() } }, T.fsExtract),
|
|
2797
|
+
h('button', { className: 'ops-btn ops-btn-sm', disabled: !fsSel, onClick: () => { void fsRename() } }, T.fsRename),
|
|
2798
|
+
h('button', { className: 'ops-btn ops-btn-sm', disabled: selectedPaths().length === 0, onClick: () => { const paths = selectedPaths(); if (paths.length && window.confirm(`${T.confirmDel} ${paths.length} 项?`)) { void (async () => { setFsBusy('del'); try { await api('fs', { method: 'POST', body: JSON.stringify({ host: cHost || hosts[0]?.name, action: 'delete', paths, confirm: true }) }, timeoutFor('action')); setFsSelSet({}); setFsSel(null); await loadFiles(fsPath) } catch (e) { setError(String(e.message || e)) } finally { setFsBusy('') } })() } } }, T.fsDelete),
|
|
2799
|
+
selectedPaths().length ? h('span', { className: 'ops-dim', style: { fontSize: '12px' } }, `${T.fsSelectedCount} ${selectedPaths().length}`) : null),
|
|
2800
|
+
fsProgress
|
|
2801
|
+
? h('div', null,
|
|
2802
|
+
h('div', { className: 'ops-dim', style: { fontSize: '12px' } },
|
|
2803
|
+
`${fsProgress.label} ${fsProgress.name} · ${(fsProgress.done / 1024 / 1024).toFixed(1)} / ${(fsProgress.total / 1024 / 1024).toFixed(1)} MB`,
|
|
2804
|
+
fsProgress.speed ? ` · ${fsProgress.speed} MB/s` : '',
|
|
2805
|
+
fsProgress.eta !== null && fsProgress.eta !== undefined ? ` · ${T.cleanEta} ${fsProgress.eta}s` : ''),
|
|
2806
|
+
h('div', { className: 'ops-progress' }, h('i', { style: { width: `${fsProgress.total ? Math.round((fsProgress.done / fsProgress.total) * 100) : 0}%` } })))
|
|
2807
|
+
: null,
|
|
2808
|
+
(fsFavs.favs.length || fsFavs.recents.length)
|
|
2809
|
+
? h('div', { className: 'ops-chips', style: { flexWrap: 'wrap' } },
|
|
2810
|
+
fsFavs.favs.length ? h('span', { className: 'ops-chip' }, `★ ${T.fsFavorites}`) : null,
|
|
2811
|
+
...fsFavs.favs.map(path => h('button', {
|
|
2812
|
+
key: 'fav' + path,
|
|
2813
|
+
className: 'ops-btn ops-btn-sm',
|
|
2814
|
+
title: path,
|
|
2815
|
+
onClick: () => goPath(path),
|
|
2816
|
+
}, path.length > 28 ? '…' + path.slice(-26) : path)),
|
|
2817
|
+
fsFavs.recents.length ? h('span', { className: 'ops-chip' }, T.fsRecent) : null,
|
|
2818
|
+
...fsFavs.recents.filter(path => !fsFavs.favs.includes(path)).slice(0, 5).map(path => h('button', {
|
|
2819
|
+
key: 'rec' + path,
|
|
2820
|
+
className: 'ops-btn ops-btn-sm',
|
|
2821
|
+
title: path,
|
|
2822
|
+
onClick: () => goPath(path),
|
|
2823
|
+
}, path.length > 28 ? '…' + path.slice(-26) : path)))
|
|
2824
|
+
: null,
|
|
2825
|
+
h('div', { className: 'ops-fm-tablewrap' },
|
|
2826
|
+
!fsEntries || fsEntries.length === 0
|
|
2827
|
+
? h('p', { className: 'ops-empty' }, fsBusy === 'list' ? T.reading : T.fsEmpty)
|
|
2828
|
+
: h('table', { className: 'ops-fm-table' },
|
|
2829
|
+
h('thead', null, h('tr', null,
|
|
2830
|
+
h('th', { style: { width: '28px' } },
|
|
2831
|
+
h('input', { type: 'checkbox', checked: (fsEntries || []).length > 0 && (fsEntries || []).every(entry => fsSelSet[entry.path]), onChange: toggleSelectAll })),
|
|
2832
|
+
h('th', null, T.fsName),
|
|
2833
|
+
h('th', null, T.fsSize),
|
|
2834
|
+
h('th', null, T.fsType),
|
|
2835
|
+
h('th', null, T.fsMtime),
|
|
2836
|
+
h('th', null, T.fsPerm),
|
|
2837
|
+
h('th', null, T.fsOwner))),
|
|
2838
|
+
h('tbody', null, ...fsEntries.map(entry => h('tr', {
|
|
2839
|
+
key: entry.path,
|
|
2840
|
+
className: fsSel && fsSel.path === entry.path ? 'on' : '',
|
|
2841
|
+
onClick: () => setFsSel(entry),
|
|
2842
|
+
onDoubleClick: () => { if (entry.dir) goPath(entry.path); else if (IMAGE_EXT.test(entry.name)) void previewImage(entry); else void openEditor(entry) },
|
|
2843
|
+
},
|
|
2844
|
+
h('td', null, h('input', { type: 'checkbox', checked: Boolean(fsSelSet[entry.path]), onChange: () => toggleSelect(entry), onClick: event => event.stopPropagation() })),
|
|
2845
|
+
h('td', { className: 'ops-fm-name-cell' }, `${entry.dir ? '📁' : entry.link ? '🔗' : '📄'} ${entry.name}`),
|
|
2846
|
+
h('td', null, sizeText(entry.size, entry.dir)),
|
|
2847
|
+
h('td', null, entry.type || (entry.dir ? '文件夹' : '文件')),
|
|
2848
|
+
h('td', null, entry.mtime || '—'),
|
|
2849
|
+
h('td', { className: 'ops-mono' }, entry.perm || '—'),
|
|
2850
|
+
h('td', null, `${entry.owner || '—'}:${entry.group || '—'}`)))))))))
|
|
2851
|
+
|
|
2852
|
+
const dhost = () => detailHost || cHost
|
|
2853
|
+
|
|
2854
|
+
const openHost = (name) => {
|
|
2855
|
+
setDetailHost(name)
|
|
2856
|
+
setCHost(name)
|
|
2857
|
+
setMHost(name)
|
|
2858
|
+
setDetailTab('summary')
|
|
2859
|
+
setFsPath('/')
|
|
2860
|
+
setFsTree({})
|
|
2861
|
+
setFsOpen({ '/': true })
|
|
2862
|
+
setFsSel(null)
|
|
2863
|
+
void loadMonitors(name)
|
|
2864
|
+
void loadTemplatesUi()
|
|
2865
|
+
void loadServicesUi(name)
|
|
2866
|
+
void loadMaintenance(name)
|
|
2867
|
+
void loadHealth(name)
|
|
2868
|
+
void loadCerts(name)
|
|
2869
|
+
}
|
|
2870
|
+
|
|
2871
|
+
const focusTerm = () => { const el = document.getElementById('ops-term'); if (el) el.focus() }
|
|
2872
|
+
|
|
1582
2873
|
const quickCommands = (Array.isArray(config.quickCommands) && config.quickCommands.length > 0)
|
|
1583
2874
|
? config.quickCommands
|
|
1584
2875
|
: ['df -h', 'free -h', 'uptime', 'systemctl --failed', 'docker ps', 'tail -n 30 /var/log/messages']
|
|
1585
2876
|
|
|
1586
2877
|
const terminalView = h('div', { style: { display: 'flex', flexDirection: 'column', gap: '10px' } },
|
|
2878
|
+
viewHint(T.hintTerminal),
|
|
1587
2879
|
h('div', { className: 'ops-chips' },
|
|
1588
2880
|
(detailHost ? null : hostPicker(cHost, setCHost)),
|
|
1589
2881
|
term?.id
|
|
1590
2882
|
? h('span', { className: term.closed ? 'ops-chip' : 'ops-chip ops-ok' }, term.closed ? '已断开' : '已连接')
|
|
1591
2883
|
: (busy === 'term' ? h('span', { className: 'ops-chip' }, T.connecting) : null),
|
|
1592
|
-
term?.id
|
|
1593
|
-
? h('button', { className: 'ops-btn ops-btn-sm', onClick: () => { void
|
|
1594
|
-
:
|
|
2884
|
+
term?.id && term.closed
|
|
2885
|
+
? h('button', { className: 'ops-btn ops-btn-primary ops-btn-sm', disabled: busy === 'term', onClick: () => { setTerm(null); setTimeout(() => { void openTerm() }, 50) } }, busy === 'term' ? T.connecting : T.reconnect)
|
|
2886
|
+
: term?.id
|
|
2887
|
+
? h('button', { className: 'ops-btn ops-btn-sm', onClick: () => { void closeTerm() } }, T.closeTerm)
|
|
2888
|
+
: h('button', { className: 'ops-btn ops-btn-primary ops-btn-sm', disabled: busy === 'term', onClick: () => { void openTerm() } }, busy === 'term' ? T.connecting : T.openTerm)),
|
|
2889
|
+
term?.id && term.closed ? h('p', { className: 'ops-sub', style: { margin: 0 } }, T.termClosed) : null,
|
|
1595
2890
|
h('p', { className: 'ops-sub', style: { margin: 0 } }, T.termHint),
|
|
1596
2891
|
aiMode
|
|
1597
2892
|
? h('div', { className: 'ops-card', style: { borderColor: 'var(--dsw-alias-accent,#4c8dff)' } },
|
|
@@ -1710,7 +3005,11 @@ window.__ModuleLoader__.load({
|
|
|
1710
3005
|
askLog.length === 0
|
|
1711
3006
|
? h('div', { style: { margin: 'auto', textAlign: 'center' } },
|
|
1712
3007
|
h('p', { className: 'ops-sub', style: { margin: 0 } }, T.askPh),
|
|
1713
|
-
h('p', { className: 'ops-dim', style: { marginTop: '6px', fontSize: '12px' } }, '例如:mysql 运行了吗 / 磁盘还剩多少 / 谁在占 CPU')
|
|
3008
|
+
h('p', { className: 'ops-dim', style: { marginTop: '6px', fontSize: '12px' } }, '例如:mysql 运行了吗 / 磁盘还剩多少 / 谁在占 CPU'),
|
|
3009
|
+
h('p', { className: 'ops-dim', style: { marginTop: '18px', fontSize: '12px' } },
|
|
3010
|
+
T.fbHint,
|
|
3011
|
+
h('button', { className: 'ops-btn ops-btn-sm', style: { marginLeft: '6px' }, onClick: () => { void copyDiagnostics() } }, T.fbCopy),
|
|
3012
|
+
h('span', null, ' 发给我(开发者)')))
|
|
1714
3013
|
: askLog.map(messageView)),
|
|
1715
3014
|
h('div', { className: 'ops-composer' },
|
|
1716
3015
|
h('input', {
|
|
@@ -1725,6 +3024,14 @@ window.__ModuleLoader__.load({
|
|
|
1725
3024
|
askBusy ? T.thinking : T.send)))
|
|
1726
3025
|
|
|
1727
3026
|
const settingsView = h('div', { style: { display: 'flex', flexDirection: 'column', gap: '12px' } },
|
|
3027
|
+
h('div', { className: 'ops-card' },
|
|
3028
|
+
h('div', { className: 'ops-card-h' }, h('span', null, T.uiMode),
|
|
3029
|
+
h('button', { className: 'ops-btn ops-btn-primary ops-btn-sm', onClick: () => { void saveConfig() } }, T.save)),
|
|
3030
|
+
h('div', { className: 'ops-card-b' },
|
|
3031
|
+
h('div', { className: 'ops-chips' },
|
|
3032
|
+
h('button', { className: `ops-tab${uiMode === 'simple' ? ' on' : ''}`, onClick: () => setUiMode('simple') }, T.modeSimple),
|
|
3033
|
+
h('button', { className: `ops-tab${uiMode === 'pro' ? ' on' : ''}`, onClick: () => setUiMode('pro') }, T.modePro)),
|
|
3034
|
+
h('p', { className: 'ops-sub', style: { margin: 0 } }, T.modeHint))),
|
|
1728
3035
|
h('div', { className: 'ops-card' },
|
|
1729
3036
|
h('div', { className: 'ops-card-h' }, h('span', null, T.patrol), notice ? h('span', { className: 'ops-ok' }, notice) : null),
|
|
1730
3037
|
h('div', { className: 'ops-card-b' },
|
|
@@ -1802,6 +3109,43 @@ window.__ModuleLoader__.load({
|
|
|
1802
3109
|
}, (T.channelLevels || [])[index])),
|
|
1803
3110
|
h('button', { className: 'ops-btn ops-btn-primary ops-btn-sm', disabled: chBusy === 'add', onClick: () => { void saveChannel() } }, chBusy === 'add' ? T.reading : T.channelAdd)),
|
|
1804
3111
|
h('p', { className: 'ops-sub', style: { margin: '8px 0 0' } }, T.channelHint))),
|
|
3112
|
+
h('div', { className: 'ops-card' },
|
|
3113
|
+
h('div', { className: 'ops-card-h' }, h('span', null, T.cleanAuto),
|
|
3114
|
+
h('button', { className: 'ops-btn ops-btn-primary ops-btn-sm', onClick: () => { void saveConfig() } }, T.save)),
|
|
3115
|
+
h('div', { className: 'ops-card-b' },
|
|
3116
|
+
h('div', { className: 'ops-chips', style: { flexWrap: 'wrap' } },
|
|
3117
|
+
h('label', { className: 'ops-sub', style: { display: 'flex', gap: '6px', alignItems: 'center' } },
|
|
3118
|
+
h('input', { type: 'checkbox', checked: config.logAutoEnabled === true, onChange: e => setConfig({ ...config, logAutoEnabled: e.target.checked }) }),
|
|
3119
|
+
T.cleanAutoOn),
|
|
3120
|
+
h('label', { className: 'ops-sub' }, T.cleanAutoAt,
|
|
3121
|
+
h('input', { className: 'ops-input', type: 'number', min: 0, max: 23, value: config.logAutoHour ?? 3, style: { width: '64px' }, onChange: e => setConfig({ ...config, logAutoHour: Number(e.target.value) }) }),
|
|
3122
|
+
h('span', null, ' : '),
|
|
3123
|
+
h('input', { className: 'ops-input', type: 'number', min: 0, max: 59, value: config.logAutoMinute ?? 0, style: { width: '64px' }, onChange: e => setConfig({ ...config, logAutoMinute: Number(e.target.value) }) })),
|
|
3124
|
+
h('label', { className: 'ops-sub' }, T.cleanAutoMinDisk,
|
|
3125
|
+
h('input', { className: 'ops-input', type: 'number', min: 50, max: 99, value: config.logAutoMinDisk ?? 80, style: { width: '64px' }, onChange: e => setConfig({ ...config, logAutoMinDisk: Number(e.target.value) }) })),
|
|
3126
|
+
h('label', { className: 'ops-sub' }, T.cleanGrow,
|
|
3127
|
+
h('input', { className: 'ops-input', type: 'number', min: 50, max: 10240, value: config.logGrowAlertMb ?? 200, style: { width: '80px' }, onChange: e => setConfig({ ...config, logGrowAlertMb: Number(e.target.value) }) }))))),
|
|
3128
|
+
h('div', { className: 'ops-card' },
|
|
3129
|
+
h('div', { className: 'ops-card-h' }, h('span', null, T.logUsage),
|
|
3130
|
+
h('button', { className: 'ops-btn ops-btn-primary ops-btn-sm', onClick: () => { void saveConfig() } }, T.save)),
|
|
3131
|
+
h('div', { className: 'ops-card-b' },
|
|
3132
|
+
h('div', { className: 'ops-chips' },
|
|
3133
|
+
h('label', { className: 'ops-sub' }, T.logKeepDays,
|
|
3134
|
+
h('input', { className: 'ops-input', type: 'number', min: 1, max: 90, value: config.logKeepDays ?? 7, style: { width: '80px' }, onChange: e => setConfig({ ...config, logKeepDays: Number(e.target.value) }) })),
|
|
3135
|
+
h('label', { className: 'ops-sub' }, T.logJournalMb,
|
|
3136
|
+
h('input', { className: 'ops-input', type: 'number', min: 50, max: 4096, value: config.logJournalMb ?? 200, style: { width: '90px' }, onChange: e => setConfig({ ...config, logJournalMb: Number(e.target.value) }) }))),
|
|
3137
|
+
h('p', { className: 'ops-sub', style: { margin: 0 } }, T.logPolicy.replace('{0}', Number(config.logKeepDays) || 7).replace('{1}', Number(config.logJournalMb) || 200)))),
|
|
3138
|
+
h('div', { className: 'ops-card' },
|
|
3139
|
+
h('div', { className: 'ops-card-h' }, h('span', null, T.auditTitle)),
|
|
3140
|
+
h('div', { className: 'ops-card-b' },
|
|
3141
|
+
loadingMap.audit && audit.length === 0
|
|
3142
|
+
? h('p', { className: 'ops-empty' }, T.loadingList)
|
|
3143
|
+
: audit.length === 0
|
|
3144
|
+
? h('p', { className: 'ops-empty' }, T.auditEmpty)
|
|
3145
|
+
: h('div', null, ...audit.map((entry, index) => h('div', { key: index, className: 'ops-row', style: { gridTemplateColumns: 'auto 1fr auto' } },
|
|
3146
|
+
h('span', { className: 'ops-dim', style: { fontSize: '11px' } }, fmt(entry.at)),
|
|
3147
|
+
h('span', null, `${entry.host ? entry.host + ' · ' : ''}${entry.action}${entry.detail ? ':' + entry.detail : ''}`),
|
|
3148
|
+
h('span', { className: entry.ok ? 'ops-ok' : 'ops-bad', style: { fontSize: '11px' } }, entry.ok ? '成功' : '失败')))))),
|
|
1805
3149
|
h('div', { className: 'ops-card' },
|
|
1806
3150
|
h('div', { className: 'ops-card-h' }, h('span', null, T.quickEdit),
|
|
1807
3151
|
h('button', { className: 'ops-btn ops-btn-primary ops-btn-sm', onClick: () => { void saveConfig() } }, T.quickSave)),
|
|
@@ -1838,6 +3182,7 @@ window.__ModuleLoader__.load({
|
|
|
1838
3182
|
h('button', { className: 'ops-btn ops-btn-sm', onClick: () => { void removeHost(host.name) } }, T.remove))))))
|
|
1839
3183
|
|
|
1840
3184
|
const backupView = h('div', { style: { display: 'flex', flexDirection: 'column', gap: '12px' } },
|
|
3185
|
+
viewHint(T.hintBackups),
|
|
1841
3186
|
h('div', { className: 'ops-card' },
|
|
1842
3187
|
h('div', { className: 'ops-card-h' }, h('span', null, T.backups), h('span', { className: 'ops-dim' }, dhost())),
|
|
1843
3188
|
h('div', { className: 'ops-card-b' },
|
|
@@ -1850,7 +3195,7 @@ window.__ModuleLoader__.load({
|
|
|
1850
3195
|
? h('input', { className: 'ops-input', style: { flex: '1 1 200px' }, value: backupForm.database, placeholder: '数据库名(留空=全部)', onChange: e => setBackupForm({ ...backupForm, database: e.target.value }) })
|
|
1851
3196
|
: h('input', { className: 'ops-input', style: { flex: '1 1 260px' }, value: backupForm.path, placeholder: '/www/wwwroot 或 /etc/nginx', onChange: e => setBackupForm({ ...backupForm, path: e.target.value }) }),
|
|
1852
3197
|
h('input', { className: 'ops-input', style: { width: '160px' }, value: backupForm.dir, placeholder: '/home/backup', onChange: e => setBackupForm({ ...backupForm, dir: e.target.value }) }),
|
|
1853
|
-
h('label', { className: 'ops-sub', style: { display: 'flex', gap: '6px', alignItems: 'center' } }, T.backupKeep,
|
|
3198
|
+
h('label', { className: 'ops-sub', style: { display: 'flex', gap: '6px', alignItems: 'center' }, title: T.tipKeep }, T.backupKeep,
|
|
1854
3199
|
h('input', { className: 'ops-input', type: 'number', min: 1, max: 90, style: { width: '70px' }, value: backupForm.keep, onChange: e => setBackupForm({ ...backupForm, keep: Number(e.target.value) }) })),
|
|
1855
3200
|
h('button', { className: 'ops-btn ops-btn-primary ops-btn-sm', disabled: opBusy === 'backup', onClick: () => { void doBackup() } }, opBusy === 'backup' ? T.reading : T.backupNow)),
|
|
1856
3201
|
opOut ? h('pre', { className: 'ops-pre', style: { maxHeight: '160px', marginTop: '8px' } }, opOut) : null)),
|
|
@@ -1867,6 +3212,7 @@ window.__ModuleLoader__.load({
|
|
|
1867
3212
|
h('button', { className: 'ops-btn ops-btn-sm', onClick: () => { void removeBackupNow(item.id) } }, T.backupRemove))))))))
|
|
1868
3213
|
|
|
1869
3214
|
const cronView = h('div', { style: { display: 'flex', flexDirection: 'column', gap: '12px' } },
|
|
3215
|
+
viewHint(T.hintCron),
|
|
1870
3216
|
h('div', { className: 'ops-card' },
|
|
1871
3217
|
h('div', { className: 'ops-card-h' }, h('span', null, T.cron), h('span', { className: 'ops-dim' }, dhost())),
|
|
1872
3218
|
h('div', { className: 'ops-card-b' },
|
|
@@ -1882,7 +3228,9 @@ window.__ModuleLoader__.load({
|
|
|
1882
3228
|
h('input', { className: 'ops-input', style: { flex: '1 1 260px' }, value: cronForm.command, placeholder: T.cronCmd, onChange: e => setCronForm({ ...cronForm, command: e.target.value }) }),
|
|
1883
3229
|
h('button', { className: 'ops-btn ops-btn-primary ops-btn-sm', disabled: opBusy === 'cron', onClick: () => { void addCronJob() } }, T.cronAdd))),
|
|
1884
3230
|
h('div', { className: 'ops-card-b' },
|
|
1885
|
-
cronJobs.length === 0
|
|
3231
|
+
loadingMap.cron && cronJobs.length === 0
|
|
3232
|
+
? h('p', { className: 'ops-empty' }, T.loadingList)
|
|
3233
|
+
: cronJobs.length === 0
|
|
1886
3234
|
? h('p', { className: 'ops-empty' }, T.cronEmpty)
|
|
1887
3235
|
: h('div', null, ...cronJobs.map(job => h('div', { key: `${job.index}-${job.raw}`, className: 'ops-row', style: { gridTemplateColumns: '140px 1fr auto' } },
|
|
1888
3236
|
h('span', { className: 'ops-mono', style: { fontSize: '12px' } }, job.schedule),
|
|
@@ -1891,6 +3239,7 @@ window.__ModuleLoader__.load({
|
|
|
1891
3239
|
h('button', { className: 'ops-btn ops-btn-sm', onClick: () => { void removeCronJob(job.index) } }, T.cronRemove))))))))
|
|
1892
3240
|
|
|
1893
3241
|
const deployView = h('div', { style: { display: 'flex', flexDirection: 'column', gap: '12px' } },
|
|
3242
|
+
viewHint(T.hintDeploy),
|
|
1894
3243
|
h('div', { className: 'ops-card' },
|
|
1895
3244
|
h('div', { className: 'ops-card-h' }, h('span', null, T.deployNew)),
|
|
1896
3245
|
h('div', { className: 'ops-card-b' },
|
|
@@ -1910,7 +3259,9 @@ window.__ModuleLoader__.load({
|
|
|
1910
3259
|
h('div', { className: 'ops-card-h' }, h('span', null, T.deploy)),
|
|
1911
3260
|
h('div', { className: 'ops-card-b' },
|
|
1912
3261
|
deployJobs.length === 0
|
|
1913
|
-
? h('
|
|
3262
|
+
? h('div', null,
|
|
3263
|
+
h('p', { className: 'ops-empty' }, T.deployEmpty),
|
|
3264
|
+
h('p', { className: 'ops-sub', style: { margin: 0, fontSize: '12px' } }, T.deployExample))
|
|
1914
3265
|
: h('div', null, ...deployJobs.map(job => h('div', { key: job.id, className: 'ops-row', style: { gridTemplateColumns: '1fr 1.2fr auto' } },
|
|
1915
3266
|
h('span', { className: 'ops-name' }, job.name || job.dir),
|
|
1916
3267
|
h('span', { className: 'ops-dim' }, `${job.dir}${job.health ? ' · ' + job.health : ''}`),
|
|
@@ -1925,7 +3276,7 @@ window.__ModuleLoader__.load({
|
|
|
1925
3276
|
|
|
1926
3277
|
const healthCard = h('div', { className: 'ops-card' },
|
|
1927
3278
|
h('div', { className: 'ops-card-h' },
|
|
1928
|
-
h('span',
|
|
3279
|
+
h('span', { title: T.tipHealth }, T.health,
|
|
1929
3280
|
healthScore !== null ? h('span', { className: healthLevel === 'ok' ? 'ops-ok' : healthLevel === 'warn' ? 'ops-warn' : 'ops-bad', style: { marginLeft: '8px' } },
|
|
1930
3281
|
`${healthScore} 分 · ${healthLevel === 'ok' ? T.scoreGood : healthLevel === 'warn' ? T.scoreWarn : T.scoreBad}`) : null),
|
|
1931
3282
|
h('button', { className: 'ops-btn ops-btn-sm', disabled: opBusy === 'health', onClick: () => { void loadHealth(dhost()) } }, opBusy === 'health' ? T.reading : T.healthNow)),
|
|
@@ -1951,7 +3302,9 @@ window.__ModuleLoader__.load({
|
|
|
1951
3302
|
h('button', { className: 'ops-btn ops-btn-sm', disabled: opBusy === 'renew', onClick: () => { void renewCertsNow(true) } }, T.certRenew),
|
|
1952
3303
|
h('button', { className: 'ops-btn ops-btn-sm', disabled: opBusy === 'renew', onClick: () => { void renewCertsNow(false) } }, T.certRenewReal))),
|
|
1953
3304
|
h('div', { className: 'ops-card-b' },
|
|
1954
|
-
certs
|
|
3305
|
+
loadingMap.certs
|
|
3306
|
+
? h('p', { className: 'ops-empty' }, T.loadingList)
|
|
3307
|
+
: certs.length === 0
|
|
1955
3308
|
? h('p', { className: 'ops-empty' }, T.certNone)
|
|
1956
3309
|
: h('div', null, ...certs.map(cert => h('div', { key: cert.domain, className: 'ops-row', style: { gridTemplateColumns: '1.2fr 1fr auto' } },
|
|
1957
3310
|
h('span', { className: 'ops-mono', style: { fontSize: '12px' } }, cert.domain),
|
|
@@ -1960,22 +3313,69 @@ window.__ModuleLoader__.load({
|
|
|
1960
3313
|
h('span', null)))),
|
|
1961
3314
|
opOut ? h('pre', { className: 'ops-pre', style: { maxHeight: '200px', marginTop: '8px' } }, opOut) : null))
|
|
1962
3315
|
|
|
3316
|
+
const monitorLevel = (monitor) => {
|
|
3317
|
+
if (!monitor.last) return 'unknown'
|
|
3318
|
+
const interval = Math.max(1, Number(monitor.intervalMinutes) || 5) * 60_000
|
|
3319
|
+
const age = Date.now() - new Date(monitor.last.at || 0).getTime()
|
|
3320
|
+
if (age > interval * 3) return 'unknown'
|
|
3321
|
+
if (monitor.lastOk === true) return 'ok'
|
|
3322
|
+
return monitor.last.level || 'crit'
|
|
3323
|
+
}
|
|
3324
|
+
|
|
3325
|
+
const levelDot = (level) => `ops-dot ${level === 'ok' ? 'ok' : level === 'crit' ? 'bad' : level === 'warn' ? 'warn' : ''}`
|
|
3326
|
+
|
|
3327
|
+
const servicesCard = h('div', { className: 'ops-card' },
|
|
3328
|
+
h('div', { className: 'ops-card-h' },
|
|
3329
|
+
h('span', null, T.services, services.length ? h('span', { className: 'ops-chip', style: { marginLeft: '6px' } }, String(services.length)) : null),
|
|
3330
|
+
h('button', {
|
|
3331
|
+
className: 'ops-btn ops-btn-primary ops-btn-sm',
|
|
3332
|
+
disabled: monitors.length === 0 || p2Busy === 'svc',
|
|
3333
|
+
onClick: () => { void createServiceUi() },
|
|
3334
|
+
}, T.serviceNew)),
|
|
3335
|
+
h('div', { className: 'ops-card-b' },
|
|
3336
|
+
loadingMap.services && services.length === 0
|
|
3337
|
+
? h('p', { className: 'ops-empty' }, T.loadingList)
|
|
3338
|
+
: services.length === 0
|
|
3339
|
+
? h('p', { className: 'ops-empty' }, T.serviceEmpty)
|
|
3340
|
+
: h('div', null, ...services.map(service => h('div', { key: service.id, className: 'ops-row', style: { gridTemplateColumns: '1fr 1.6fr auto' } },
|
|
3341
|
+
h('span', { style: { display: 'flex', alignItems: 'center', gap: '6px' } },
|
|
3342
|
+
h('i', { className: levelDot(service.level) }),
|
|
3343
|
+
h('span', { className: 'ops-name' }, service.name)),
|
|
3344
|
+
h('span', { className: 'ops-dim' }, `${T.serviceMembers}: ${service.members.map(member => member.label).join('、') || '—'}`),
|
|
3345
|
+
h('span', { style: { display: 'flex', justifyContent: 'flex-end' } },
|
|
3346
|
+
h('button', { className: 'ops-btn ops-btn-sm', onClick: () => { void removeServiceUi(service.id) } }, T.serviceRemove)))))))
|
|
3347
|
+
|
|
1963
3348
|
const monitorsCard = h('div', { className: 'ops-card' },
|
|
1964
3349
|
h('div', { className: 'ops-card-h' },
|
|
1965
3350
|
h('span', null, T.monitors, monitors.length ? h('span', { className: 'ops-chip', style: { marginLeft: '6px' } }, String(monitors.length)) : null),
|
|
1966
3351
|
h('span', { className: 'ops-sub' }, T.monHttpHint)),
|
|
1967
3352
|
h('div', { className: 'ops-card-b' },
|
|
1968
|
-
monitors.length === 0
|
|
3353
|
+
loadingMap.monitors && monitors.length === 0
|
|
3354
|
+
? h('p', { className: 'ops-empty' }, T.loadingList)
|
|
3355
|
+
: monitors.length === 0
|
|
1969
3356
|
? h('p', { className: 'ops-empty' }, T.monEmpty)
|
|
1970
3357
|
: h('div', null, ...monitors.map(monitor => h('div', { key: monitor.id, className: 'ops-row', style: { gridTemplateColumns: '1fr 1.1fr auto' } },
|
|
1971
|
-
h('span', { style: { display: 'flex', alignItems: 'center', gap: '
|
|
1972
|
-
h('i', { className:
|
|
1973
|
-
h('span', { className: 'ops-name' }, monitor.label ||
|
|
1974
|
-
h('span', { className: 'ops-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
h('span', { className: 'ops-dim' },
|
|
1978
|
-
|
|
3358
|
+
h('span', { style: { display: 'flex', alignItems: 'center', gap: '8px', minWidth: 0 } },
|
|
3359
|
+
h('i', { className: levelDot(monitorLevel(monitor)) }),
|
|
3360
|
+
h('span', { className: 'ops-name' }, monitor.label || monitor.target || monitor.type),
|
|
3361
|
+
monitor.target && monitor.label ? h('span', { className: 'ops-mono ops-dim', style: { fontSize: '11.5px' } }, monitor.target) : null,
|
|
3362
|
+
h('span', { className: 'ops-chip' }, (T.monTypeShort || {})[monitor.type] || monitor.type)
|
|
3363
|
+
, monitor.type === 'script' ? h('span', { className: 'ops-chip' }, monitor.language || 'shell') : null),
|
|
3364
|
+
h('span', { className: 'ops-dim' },
|
|
3365
|
+
monitor.last
|
|
3366
|
+
? `${monitor.last.detail} · ${fmt(monitor.last.at)}${monitorLevel(monitor) === 'unknown' ? ' · ' + T.monStale : ''}`
|
|
3367
|
+
: T.monNever),
|
|
3368
|
+
h('span', { style: { display: 'flex', gap: '6px', justifyContent: 'flex-end', alignItems: 'center' } },
|
|
3369
|
+
monitor.acked ? h('span', { className: 'ops-chip' }, T.ack) : null,
|
|
3370
|
+
monitor.mutedUntil && new Date(monitor.mutedUntil).getTime() > Date.now()
|
|
3371
|
+
? h('span', { className: 'ops-chip' }, `${T.mutedUntil} ${fmt(monitor.mutedUntil)}`)
|
|
3372
|
+
: null,
|
|
3373
|
+
monitorLevel(monitor) !== 'ok' && !monitor.acked
|
|
3374
|
+
? h('button', { className: 'ops-btn ops-btn-sm', disabled: p2Busy === 'ack:' + monitor.id, onClick: () => { void ackMonitorUi(monitor.id) } }, T.ack)
|
|
3375
|
+
: null,
|
|
3376
|
+
monitorLevel(monitor) !== 'ok' && !(monitor.mutedUntil && new Date(monitor.mutedUntil).getTime() > Date.now())
|
|
3377
|
+
? h('button', { className: 'ops-btn ops-btn-sm', disabled: p2Busy === 'ack:' + monitor.id, onClick: () => { void ackMonitorUi(monitor.id, 60) } }, T.mute1h)
|
|
3378
|
+
: null,
|
|
1979
3379
|
h('button', { className: 'ops-btn ops-btn-sm', disabled: monBusy === 'test:' + monitor.id, onClick: () => { void testMonitor(monitor.id) } }, T.monCheck),
|
|
1980
3380
|
h('button', { className: 'ops-btn ops-btn-sm', onClick: () => editMonitor(monitor) }, T.monEdit),
|
|
1981
3381
|
h('button', { className: 'ops-btn ops-btn-sm', onClick: () => { void removeMonitor(monitor.id) } }, T.monRemove))))),
|
|
@@ -2012,6 +3412,16 @@ window.__ModuleLoader__.load({
|
|
|
2012
3412
|
monBusy === 'add' ? T.reading : (monEditId ? T.monSave : T.monAdd)),
|
|
2013
3413
|
monEditId ? h('button', { className: 'ops-btn ops-btn-sm', onClick: () => { setMonEditId(''); setMonForm({ type: 'http', target: '', label: '', intervalMinutes: 5, language: 'shell', script: '' }) } }, T.monCancel) : null),
|
|
2014
3414
|
|
|
3415
|
+
h('div', { className: 'ops-chips', style: { marginTop: '8px', flexWrap: 'wrap' } },
|
|
3416
|
+
h('span', { className: 'ops-chip' }, T.templates),
|
|
3417
|
+
h('select', { className: 'ops-input', style: { width: '180px' }, value: templateId, onChange: event => setTemplateId(event.target.value) },
|
|
3418
|
+
h('option', { value: '' }, T.templateNone),
|
|
3419
|
+
...templates.map(template => h('option', { key: template.id, value: template.id }, `${template.name} (${template.items.length})`))),
|
|
3420
|
+
h('button', { className: 'ops-btn ops-btn-sm', disabled: !templateId || monBusy === 'template', onClick: () => { void applyTemplateUi(false) } }, T.templateApplyHere),
|
|
3421
|
+
h('button', { className: 'ops-btn ops-btn-sm', disabled: !templateId || monBusy === 'template', onClick: () => { void applyTemplateUi(true) } }, T.templateApplyAll),
|
|
3422
|
+
h('button', { className: 'ops-btn ops-btn-sm', disabled: !templateId, onClick: () => { void removeTemplateUi() } }, T.templateDelete),
|
|
3423
|
+
h('button', { className: 'ops-btn ops-btn-sm', disabled: monitors.length === 0 || monBusy === 'template', onClick: () => { void saveAsTemplate() } }, T.templateSave)),
|
|
3424
|
+
|
|
2015
3425
|
monForm.type === 'script'
|
|
2016
3426
|
? h('div', { style: { marginTop: '8px' } },
|
|
2017
3427
|
h('textarea', {
|
|
@@ -2063,6 +3473,15 @@ window.__ModuleLoader__.load({
|
|
|
2063
3473
|
h('button', { className: 'ops-btn ops-btn-primary ops-btn-sm', onClick: () => { void askAi(host.name, '') } }, T.diagnose),
|
|
2064
3474
|
h('button', { className: 'ops-btn ops-btn-sm', onClick: () => setDetailTab('logs') }, T.tabs[5]),
|
|
2065
3475
|
h('button', { className: 'ops-btn ops-btn-sm', onClick: () => setDetailTab('terminal') }, T.tabs[7]),
|
|
3476
|
+
maintenanceUntil && new Date(maintenanceUntil).getTime() > Date.now()
|
|
3477
|
+
? h('span', { className: 'ops-chip ops-warn' }, `${T.maintenanceOn} · ${fmt(maintenanceUntil)}`)
|
|
3478
|
+
: null,
|
|
3479
|
+
maintenanceUntil && new Date(maintenanceUntil).getTime() > Date.now()
|
|
3480
|
+
? h('button', { className: 'ops-btn ops-btn-sm', disabled: p2Busy === 'maint', onClick: () => { void setMaintenanceUi(0) } }, T.maintenanceOff)
|
|
3481
|
+
: h('button', { className: 'ops-btn ops-btn-sm', disabled: p2Busy === 'maint', onClick: () => { void setMaintenanceUi(30) } }, T.maintenance30),
|
|
3482
|
+
maintenanceUntil && new Date(maintenanceUntil).getTime() > Date.now()
|
|
3483
|
+
? null
|
|
3484
|
+
: h('button', { className: 'ops-btn ops-btn-sm', disabled: p2Busy === 'maint', onClick: () => { void setMaintenanceUi(120) } }, T.maintenance120),
|
|
2066
3485
|
h('button', { className: 'ops-btn ops-btn-sm', onClick: () => { void loadBase(); void testHost(host.name) } }, T.test),
|
|
2067
3486
|
(sample?.disk ?? 0) >= 85
|
|
2068
3487
|
? h('button', { className: 'ops-btn ops-btn-sm', onClick: () => { void cleanupHost(host.name) } }, T.cleanup)
|
|
@@ -2074,6 +3493,7 @@ window.__ModuleLoader__.load({
|
|
|
2074
3493
|
healthCard,
|
|
2075
3494
|
certsCard,
|
|
2076
3495
|
monitorsCard,
|
|
3496
|
+
servicesCard,
|
|
2077
3497
|
diag && diag.host === host.name ? diagView : null)
|
|
2078
3498
|
})()
|
|
2079
3499
|
|
|
@@ -2101,9 +3521,14 @@ window.__ModuleLoader__.load({
|
|
|
2101
3521
|
const header = h('div', { className: 'ops-top' },
|
|
2102
3522
|
h('div', null,
|
|
2103
3523
|
h('h1', { className: 'ops-title' }, detailHost ? (hosts.find(item => item.name === detailHost)?.alias || detailHost) : T.title),
|
|
2104
|
-
h('p', { className: 'ops-sub' }, detailHost ? '这台服务器的全部信息' : T.sub)),
|
|
3524
|
+
h('p', { className: 'ops-sub' }, detailHost ? '这台服务器的全部信息' : (uiMode === 'simple' ? T.simpleSub : T.sub))),
|
|
2105
3525
|
h('div', { style: { display: 'flex', gap: '10px', alignItems: 'center' } },
|
|
2106
|
-
busy ? h('span', { className: 'ops-dim' }, '⏳ ' + (busy === 'scan' ? T.rescanning : T.loading)) : null,
|
|
3526
|
+
busy || opBusy ? h('span', { className: 'ops-dim' }, '⏳ ' + (busy === 'scan' ? T.rescanning : busy === 'logs' ? T.reading : T.loading)) : null,
|
|
3527
|
+
h('button', {
|
|
3528
|
+
className: 'ops-btn ops-btn-sm',
|
|
3529
|
+
title: T.modeHint,
|
|
3530
|
+
onClick: () => { void switchMode(uiMode === 'simple' ? 'pro' : 'simple') },
|
|
3531
|
+
}, uiMode === 'simple' ? T.switchToPro : T.switchToSimple),
|
|
2107
3532
|
detailHost
|
|
2108
3533
|
? h('button', { className: 'ops-btn ops-btn-sm', onClick: () => { setDetailHost(null); void loadBase() } }, '← 返回所有服务器')
|
|
2109
3534
|
: h('button', { className: 'ops-btn ops-btn-sm', onClick: () => { void loadBase(); if (detailHost) void loadInv(cHost || detailHost, true) } }, T.refresh)))
|
|
@@ -2120,13 +3545,18 @@ window.__ModuleLoader__.load({
|
|
|
2120
3545
|
},
|
|
2121
3546
|
h('div', { className: 'ops-modal', onClick: event => event.stopPropagation() },
|
|
2122
3547
|
h('div', { className: 'ops-modal-h' },
|
|
2123
|
-
h('span', { className: 'ops-modal-title' }, monDialog.monitor.label ||
|
|
3548
|
+
h('span', { className: 'ops-modal-title' }, `${monDialog.monitor.label || monDialog.monitor.target || monDialog.monitor.type}`),
|
|
2124
3549
|
h('button', { className: 'ops-modal-x', onClick: () => setMonDialog(null) }, '✕')),
|
|
2125
3550
|
h('div', {
|
|
2126
|
-
className: monDialog.result?.ok ? 'ops-result-ok' : 'ops-result-bad',
|
|
3551
|
+
className: monDialog.result?.ok ? 'ops-result-ok' : monDialog.result?.level === 'warn' ? 'ops-warn' : 'ops-result-bad',
|
|
2127
3552
|
style: { fontSize: '15px', marginBottom: '10px' },
|
|
2128
|
-
}, monDialog.result?.ok ? `✓ ${T.monOk}`
|
|
2129
|
-
|
|
3553
|
+
}, monDialog.result?.ok ? `✓ ${T.monOk}`
|
|
3554
|
+
: monDialog.result?.level === 'warn' ? `△ ${T.monWarn}`
|
|
3555
|
+
: monDialog.result?.level === 'unknown' ? `? ${T.monUnknown}`
|
|
3556
|
+
: `✕ ${T.monCrit}`),
|
|
3557
|
+
h('div', { className: 'ops-modal-row' }, h('b', null, '类型'), h('span', null,
|
|
3558
|
+
`${(T.monTypeShort || {})[monDialog.monitor.type] || monDialog.monitor.type}${monDialog.monitor.language ? ' · ' + monDialog.monitor.language : ''}`)),
|
|
3559
|
+
h('div', { className: 'ops-modal-row' }, h('b', null, '目标'), h('span', { className: 'ops-mono' }, monDialog.monitor.target || (monDialog.monitor.script ? '(脚本)' : '—'))),
|
|
2130
3560
|
h('div', { className: 'ops-modal-row' }, h('b', null, '详情'), h('span', null, monDialog.result?.detail || '—')),
|
|
2131
3561
|
h('div', { className: 'ops-modal-row' }, h('b', null, T.monResult), h('span', null,
|
|
2132
3562
|
`${monDialog.result?.ms ?? '—'}ms · ${T.monChecked} ${monDialog.result?.at ? fmt(monDialog.result.at) : '—'}`)),
|
|
@@ -2153,13 +3583,125 @@ window.__ModuleLoader__.load({
|
|
|
2153
3583
|
h('div', { className: 'ops-chips', style: { marginTop: '14px', justifyContent: 'flex-end' } },
|
|
2154
3584
|
h('button', { className: 'ops-btn ops-btn-sm', onClick: () => setMonDialog(null) }, T.monClose)))) : null
|
|
2155
3585
|
|
|
3586
|
+
const fsEditView = fsEdit ? h('div', { className: 'ops-modal-mask', onClick: () => setFsEdit(null) },
|
|
3587
|
+
h('div', { className: 'ops-modal', style: { width: 'min(900px, 100%)' }, onClick: event => event.stopPropagation() },
|
|
3588
|
+
h('div', { className: 'ops-modal-h' },
|
|
3589
|
+
h('span', { className: 'ops-modal-title' }, `${T.fsEditTitle} · ${fsEdit.path.split('/').pop()}`),
|
|
3590
|
+
h('button', { className: 'ops-modal-x', onClick: () => setFsEdit(null) }, '✕')),
|
|
3591
|
+
h('div', { className: 'ops-dim', style: { fontSize: '12px', marginBottom: '8px' } }, `${fsEdit.path}${fsEdit.size ? ` · ${(fsEdit.size / 1024).toFixed(1)} KB` : ''} · ${T.fsBackupNote}`),
|
|
3592
|
+
fsEdit.binary
|
|
3593
|
+
? h('p', { className: 'ops-warn' }, T.fsBinary)
|
|
3594
|
+
: h('textarea', {
|
|
3595
|
+
className: 'ops-input',
|
|
3596
|
+
style: { minHeight: '55vh', width: '100%', fontFamily: 'ui-monospace,Menlo,monospace', fontSize: '12.5px', lineHeight: 1.5 },
|
|
3597
|
+
value: fsEdit.loading ? T.loading : fsEdit.content,
|
|
3598
|
+
onChange: event => setFsEdit(current => (current ? { ...current, content: event.target.value } : current)),
|
|
3599
|
+
spellCheck: false,
|
|
3600
|
+
}),
|
|
3601
|
+
h('div', { className: 'ops-chips', style: { marginTop: '12px', justifyContent: 'flex-end' } },
|
|
3602
|
+
h('button', { className: 'ops-btn ops-btn-sm', onClick: () => setFsEdit(null) }, T.fsCancel),
|
|
3603
|
+
h('button', { className: 'ops-btn ops-btn-primary ops-btn-sm', disabled: fsEdit.binary || fsEdit.loading || fsBusy === 'save', onClick: () => { void saveEditor() } }, fsBusy === 'save' ? T.reading : T.fsSave)))) : null
|
|
3604
|
+
|
|
3605
|
+
const fsPreviewView = fsPreview ? h('div', { className: 'ops-modal-mask', onClick: () => setFsPreview(null) },
|
|
3606
|
+
h('div', { className: 'ops-modal', style: { width: 'min(1000px, 100%)' }, onClick: event => event.stopPropagation() },
|
|
3607
|
+
h('div', { className: 'ops-modal-h' },
|
|
3608
|
+
h('span', { className: 'ops-modal-title' }, `${T.fsImage} · ${fsPreview.name}`),
|
|
3609
|
+
h('button', { className: 'ops-modal-x', onClick: () => setFsPreview(null) }, '✕')),
|
|
3610
|
+
fsPreview.loading
|
|
3611
|
+
? h('p', { className: 'ops-sub' }, T.loading)
|
|
3612
|
+
: h('img', {
|
|
3613
|
+
src: fsPreview.dataUrl,
|
|
3614
|
+
alt: fsPreview.name,
|
|
3615
|
+
style: { maxWidth: '100%', maxHeight: '70vh', minHeight: '120px', display: 'block', margin: '0 auto', background: '#0b0e11', borderRadius: '8px', objectFit: 'contain' },
|
|
3616
|
+
}),
|
|
3617
|
+
h('div', { className: 'ops-chips', style: { marginTop: '12px', justifyContent: 'flex-end' } },
|
|
3618
|
+
h('button', { className: 'ops-btn ops-btn-sm', onClick: () => setFsPreview(null) }, T.fsPreviewClose)))) : null
|
|
3619
|
+
|
|
3620
|
+
const cleanSelectedFreed = cleanPreview
|
|
3621
|
+
? (cleanSel.journal ? (cleanPreview.journal?.freedMb || 0) : 0)
|
|
3622
|
+
+ (cleanPreview.files || []).filter(file => cleanSel.paths[file.path]).reduce((sum, file) => sum + (file.sizeMb || 0), 0)
|
|
3623
|
+
: 0
|
|
3624
|
+
|
|
3625
|
+
const busyMessage = cleanBusyHost ? T.ovPreview : backupBusy ? T.ovBackup : cleanRunBusy ? T.ovClean : ''
|
|
3626
|
+
const busyOverlay = busyMessage
|
|
3627
|
+
? h('div', { className: 'ops-modal-mask' },
|
|
3628
|
+
h('div', { className: 'ops-modal ops-busy', style: { width: 'min(340px, 100%)' } },
|
|
3629
|
+
h('div', { className: 'ops-spinner' }),
|
|
3630
|
+
h('div', { style: { marginTop: '12px', fontSize: '13px' } }, busyMessage)))
|
|
3631
|
+
: null
|
|
3632
|
+
|
|
3633
|
+
const cleanPreviewView = cleanPreview ? h('div', { className: 'ops-modal-mask', onClick: () => setCleanPreview(null) },
|
|
3634
|
+
h('div', { className: 'ops-modal', style: { width: 'min(900px, 100%)' }, onClick: event => event.stopPropagation() },
|
|
3635
|
+
h('div', { className: 'ops-modal-h' },
|
|
3636
|
+
h('span', { className: 'ops-modal-title' }, `${T.cleanPreviewTitle} · ${cleanPreview.host}`),
|
|
3637
|
+
h('button', { className: 'ops-modal-x', onClick: () => setCleanPreview(null) }, '✕')),
|
|
3638
|
+
h('div', { className: 'ops-modal-row' }, h('b', null, T.cleanWillFree), h('span', { className: 'ops-ok' }, `${cleanSelectedFreed} MB`)),
|
|
3639
|
+
h('div', { className: 'ops-chips', style: { margin: '4px 0 8px' } },
|
|
3640
|
+
h('button', {
|
|
3641
|
+
className: 'ops-btn ops-btn-sm',
|
|
3642
|
+
onClick: () => {
|
|
3643
|
+
const paths = {}
|
|
3644
|
+
for (const file of cleanPreview.files || []) paths[file.path] = true
|
|
3645
|
+
setCleanSel({ journal: (cleanPreview.journal?.freedMb ?? 0) > 0, paths })
|
|
3646
|
+
},
|
|
3647
|
+
}, T.cleanSelectAll),
|
|
3648
|
+
h('button', { className: 'ops-btn ops-btn-sm', onClick: () => setCleanSel({ journal: false, paths: {} }) }, T.cleanClear)),
|
|
3649
|
+
cleanPreview.journal?.freedMb
|
|
3650
|
+
? h('label', { className: 'ops-modal-row', style: { cursor: 'pointer' } },
|
|
3651
|
+
h('input', {
|
|
3652
|
+
type: 'checkbox', checked: cleanSel.journal,
|
|
3653
|
+
onChange: e => setCleanSel(current => ({ ...current, journal: e.target.checked })),
|
|
3654
|
+
}),
|
|
3655
|
+
h('b', { style: { marginLeft: '6px' } }, T.cleanJournalRow),
|
|
3656
|
+
h('span', null, `${cleanPreview.journal.currentMb} MB → ${cleanPreview.journal.capMb} MB(释放 ${cleanPreview.journal.freedMb} MB)`))
|
|
3657
|
+
: null,
|
|
3658
|
+
cleanPreview.files?.length
|
|
3659
|
+
? h('div', { style: { marginTop: '8px' } },
|
|
3660
|
+
h('div', { className: 'ops-sub', style: { marginBottom: '4px' } }, `${T.cleanFilesRow}(${cleanPreview.files.length} 个,共 ${cleanPreview.filesMb} MB)`),
|
|
3661
|
+
h('div', { className: 'ops-fm-tablewrap', style: { maxHeight: '38vh' } },
|
|
3662
|
+
h('table', { className: 'ops-fm-table' },
|
|
3663
|
+
h('thead', null, h('tr', null,
|
|
3664
|
+
h('th', { style: { width: '28px' } }), h('th', null, T.cleanColFile), h('th', null, T.cleanColSource),
|
|
3665
|
+
h('th', null, T.cleanColSize), h('th', null, T.cleanColAge), h('th', null, T.cleanColOwner))),
|
|
3666
|
+
h('tbody', null, ...cleanPreview.files.map(file => h('tr', { key: file.path },
|
|
3667
|
+
h('td', null, h('input', {
|
|
3668
|
+
type: 'checkbox', checked: Boolean(cleanSel.paths[file.path]),
|
|
3669
|
+
onChange: () => setCleanSel(current => {
|
|
3670
|
+
const next = { ...current.paths }
|
|
3671
|
+
if (next[file.path]) delete next[file.path]
|
|
3672
|
+
else next[file.path] = true
|
|
3673
|
+
return { ...current, paths: next }
|
|
3674
|
+
}),
|
|
3675
|
+
})),
|
|
3676
|
+
h('td', { className: 'ops-mono', style: { fontSize: '11.5px' } }, file.path),
|
|
3677
|
+
h('td', null, file.source),
|
|
3678
|
+
h('td', null, `${file.sizeMb} MB`),
|
|
3679
|
+
h('td', null, fmt(file.at)),
|
|
3680
|
+
h('td', null, file.owner)))))))
|
|
3681
|
+
: h('p', { className: 'ops-empty' }, T.cleanNothing),
|
|
3682
|
+
h('p', { className: 'ops-sub', style: { margin: '10px 0 0', fontSize: '12px' } }, T.cleanImpact),
|
|
3683
|
+
cleanBackupFile
|
|
3684
|
+
? h('p', { className: 'ops-ok', style: { margin: '8px 0 0', fontSize: '12px' } }, `${T.cleanBackupDone}:${cleanBackupFile.path}(${cleanBackupFile.sizeMb} MB)`)
|
|
3685
|
+
: null,
|
|
3686
|
+
h('div', { className: 'ops-chips', style: { marginTop: '14px', justifyContent: 'flex-end' } },
|
|
3687
|
+
h('button', { className: 'ops-btn ops-btn-sm', disabled: backupBusy || cleanRunBusy, onClick: () => { void backupSelected() } }, backupBusy ? T.backingUp : T.cleanBackup),
|
|
3688
|
+
cleanBackupFile
|
|
3689
|
+
? h('button', { className: 'ops-btn ops-btn-sm', onClick: () => { void downloadBackup() } }, T.cleanDownloadBackup)
|
|
3690
|
+
: null,
|
|
3691
|
+
h('button', { className: 'ops-btn ops-btn-sm', onClick: () => setCleanPreview(null) }, T.cleanCancel),
|
|
3692
|
+
h('button', { className: 'ops-btn ops-btn-primary ops-btn-sm', disabled: backupBusy || cleanRunBusy, onClick: () => { void confirmClean() } }, cleanRunBusy ? T.cleaning : T.cleanConfirm)))) : null
|
|
3693
|
+
|
|
2156
3694
|
return h('div', { className: 'ops-page' },
|
|
2157
3695
|
h('style', null, CSS),
|
|
2158
3696
|
header,
|
|
2159
3697
|
nav,
|
|
2160
3698
|
error ? h('p', { className: 'ops-err' }, error) : null,
|
|
2161
3699
|
body,
|
|
2162
|
-
monitorDialogView
|
|
3700
|
+
monitorDialogView,
|
|
3701
|
+
fsEditView,
|
|
3702
|
+
fsPreviewView,
|
|
3703
|
+
cleanPreviewView,
|
|
3704
|
+
busyOverlay)
|
|
2163
3705
|
}
|
|
2164
3706
|
|
|
2165
3707
|
/** Keeps a render error visible instead of leaving an empty page. */
|
|
@@ -2174,7 +3716,7 @@ window.__ModuleLoader__.load({
|
|
|
2174
3716
|
render() {
|
|
2175
3717
|
if (this.state.error) {
|
|
2176
3718
|
return h('div', { style: { padding: '20px', color: 'var(--dsw-alias-danger,#ff6b6b)', fontSize: '13px', lineHeight: 1.7 } },
|
|
2177
|
-
h('div', { style: { fontWeight: 600, marginBottom: '6px' } }, '
|
|
3719
|
+
h('div', { style: { fontWeight: 600, marginBottom: '6px' } }, 'OPC-运维平台 渲染失败'),
|
|
2178
3720
|
h('pre', { style: { whiteSpace: 'pre-wrap', fontFamily: 'ui-monospace,Menlo,monospace', fontSize: '12px' } },
|
|
2179
3721
|
String(this.state.error?.stack || this.state.error?.message || this.state.error)))
|
|
2180
3722
|
}
|