dsh-ops-kit 0.3.9 → 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/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: '运维', en: 'Ops' }
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: '运维', sub: '看状态、看图表、看配置、管应用 —— 不用敲命令。',
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: '磁盘挂载',
@@ -82,6 +127,16 @@ window.__ModuleLoader__.load({
82
127
  monInterval: '间隔(分钟)', monAdd: '添加并检查', monCheck: '检查', monRemove: '删除', monEmpty: '还没有监控项,可以加一个心跳检查',
83
128
  monHttpHint: 'http:填 URL,如 https://example.com;port:填 host:port;process:填进程关键字;service:填 systemd 单元名',
84
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: '状态',
85
140
  monOk: '服务正常', monBad: '检查失败', monHint: '排查方向', monDiag: '一键排查', monDiaging: '排查中…',
86
141
  monResult: '这次检查结果', monClose: '关闭', monDiagTitle: '排查结果', monChecked: '检查于',
87
142
  monPreset: '一键模板', monScript: '脚本(退出码 0 = 正常)', monLanguage: '语言',
@@ -100,15 +155,43 @@ window.__ModuleLoader__.load({
100
155
  aiNeedTerm: '先连上终端,生成的命令才会发到服务器', aiModel: '模型',
101
156
  process: '进程', byCpu: '按 CPU', byMem: '按内存', pid: 'PID', cpuUse: 'CPU', memUse: '内存', cmd: '命令',
102
157
  end: '结束', ending: '结束中…', confirmKill: '结束这个进程?',
103
- logs: '日志', logSource: '日志来源(可下拉选:服务名 / pid:12345 / file:/var/log/x.log)', lines: '行数', load: '读取', auto: '自动刷新(5s)',
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)',
104
178
  logHint: '不知道填什么?点输入框会弹出下拉列表:systemd 服务(如 nginx.service)、java 进程(pid:12345)、或日志文件(file:/var/log/xxx.log)。选 java 进程时插件自己找日志——属于某个服务就用 journalctl,否则取它打开的最新 .log / .out 文件。',
105
179
  logPick: '先选一个来源(点输入框有下拉列表),再点「读取」。',
106
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 备份',
107
190
  files: '文件', upload: '上传', newFolder: '新建文件夹', size: '大小', modified: '修改时间', open: '进入', download: '下载', del: '删除', folderName: '文件夹名', confirmDel: '删除这个路径?',
108
191
  ask: '问一下', diagnose: '智能诊断', diagnosing: '诊断中…', askPh: '例如:网站为什么打不开?',
109
192
  askPreset: ['网站为什么打不开?', '磁盘为什么满了?', '最近是不是有点慢?'], findings: '看到的情况', next: '建议动作', timeoutSec: '默认超时(秒)', scanSec: '扫描超时(秒)', actionSec: '操作超时(秒)'
110
193
  } : {
111
- title: 'Ops', sub: 'Status, charts, configuration and apps — no commands.',
194
+ title: 'OPC Ops', sub: 'Status, charts, configuration and apps — no commands.',
112
195
  tabs: ['Overview', 'Monitor', 'Config', 'Apps', 'Triage', 'Logs', 'Files', 'Terminal', 'Assistant', 'Settings'],
113
196
  refresh: 'Refresh', add: 'Add server', save: 'Save', cancel: 'Cancel',
114
197
  name: 'Name', host: 'Address', user: 'User', key: 'Key (optional)', password: 'Password (optional)',
@@ -169,6 +252,16 @@ window.__ModuleLoader__.load({
169
252
  monInterval: 'Interval (min)', monAdd: 'Add and check', monCheck: 'Check', monRemove: 'Remove', monEmpty: 'No monitors yet — add a heartbeat check',
170
253
  monHttpHint: 'http: URL like https://example.com; port: host:port; process: pattern; service: systemd unit',
171
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',
172
265
  monOk: 'Healthy', monBad: 'Check failed', monHint: 'Where to look', monDiag: 'Diagnose', monDiaging: 'Diagnosing…',
173
266
  monResult: 'Result', monClose: 'Close', monDiagTitle: 'Diagnosis', monChecked: 'checked at',
174
267
  monPreset: 'Presets', monScript: 'Script (exit 0 = healthy)', monLanguage: 'Language',
@@ -187,10 +280,38 @@ window.__ModuleLoader__.load({
187
280
  aiNeedTerm: 'Connect the terminal first so the command can be sent', aiModel: 'model',
188
281
  process: 'Processes', byCpu: 'By CPU', byMem: 'By memory', pid: 'PID', cpuUse: 'CPU', memUse: 'MEM', cmd: 'Command',
189
282
  end: 'End', ending: 'Ending…', confirmKill: 'Kill this process?',
190
- logs: 'Logs', logSource: 'Log source (pick from the list: unit / pid:12345 / file:/var/log/x.log)', lines: 'Lines', load: 'Load', auto: 'Auto refresh (5s)',
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)',
191
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.',
192
304
  logPick: 'Pick a source first (click the field for the list), then press Load.',
193
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',
194
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?',
195
316
  ask: 'Ask', diagnose: 'Diagnose', diagnosing: 'Diagnosing…', askPh: 'e.g. why is the site down?',
196
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)'
@@ -215,6 +336,16 @@ window.__ModuleLoader__.load({
215
336
  .ops-card-b{padding:12px 14px;display:flex;flex-direction:column;gap:10px}
216
337
  .ops-dot{width:9px;height:9px;border-radius:50%;display:inline-block;margin-right:6px;background:var(--dsw-alias-text-secondary,#9aa0a6)}
217
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)}
218
349
  .ops-dot.warn{background:var(--dsw-alias-warning,#e5b650)}
219
350
  .ops-dot.bad{background:var(--dsw-alias-danger,#ff6b6b)}
220
351
  .ops-nums{display:grid;grid-template-columns:repeat(3,1fr);gap:8px}
@@ -258,6 +389,36 @@ window.__ModuleLoader__.load({
258
389
  .ops-meta{display:flex;gap:8px;align-items:center;font-size:11px;color:var(--dsw-alias-text-secondary,#9aa0a6)}
259
390
  .ops-copy{border:0;background:transparent;color:var(--dsw-alias-text-secondary,#9aa0a6);font-size:11px;cursor:pointer;padding:0}
260
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)}
261
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}
262
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}
263
424
  .ops-modal-h{display:flex;align-items:center;justify-content:space-between;gap:10px;margin-bottom:10px}
@@ -337,40 +498,129 @@ window.__ModuleLoader__.load({
337
498
  .replace(/\r(?!\n)/g, '')
338
499
  }
339
500
 
340
- function Chart({ rows, series, title, unit = '%', max = 100 }) {
341
- const W = 520, H = 110, P = 6
342
- const drawn = (series || []).map(item => ({
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 => ({
343
517
  ...item,
344
- points: rows.map(row => row[item.field]).filter(v => typeof v === 'number'),
518
+ points: downsample(rows.map(row => row[item.field])).map((value, index) => ({ value, index })),
345
519
  })).filter(item => item.points.length > 0)
346
520
 
347
- if (drawn.length === 0) {
521
+ if (prepared.length === 0) {
348
522
  return h('div', { className: 'ops-chart-wrap' },
349
523
  h('div', { className: 'ops-chart-h' }, h('span', null, title), h('span', null, '—')),
350
524
  h('p', { className: 'ops-empty' }, T.noData))
351
525
  }
352
526
 
353
- const peak = Math.max(max || 0, ...drawn.flatMap(item => item.points))
354
- const top = peak > 0 ? peak : 1
355
- const poly = (points) => {
356
- const step = points.length > 1 ? (W - P * 2) / (points.length - 1) : 0
357
- return points.map((value, index) => {
358
- const x = P + index * step
359
- const y = P + (H - P * 2) * (1 - Math.min(1, value / top))
360
- return `${x.toFixed(1)},${y.toFixed(1)}`
361
- }).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
362
535
  }
363
- const legend = drawn.map(item => {
364
- const last = item.points[item.points.length - 1]
365
- return `${item.label || item.field} ${last.toFixed(1)}${unit}`
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}`
366
544
  }).join(' · ')
367
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
+
368
571
  return h('div', { className: 'ops-chart-wrap' },
369
572
  h('div', { className: 'ops-chart-h' }, h('span', null, title), h('span', null, legend)),
370
- h('svg', { className: 'ops-chart', viewBox: `0 0 ${W} ${H}`, preserveAspectRatio: 'none' },
371
- h('line', { x1: P, y1: H - P, x2: W - P, y2: H - P, stroke: 'var(--dsw-alias-border,#3a3f45)', strokeWidth: 1 }),
372
- h('line', { x1: P, y1: P, x2: W - P, y2: P, stroke: 'var(--dsw-alias-border,#3a3f45)', strokeWidth: 1, strokeDasharray: '3 4' }),
373
- ...drawn.map(item => h('polyline', { key: item.field, points: poly(item.points), fill: 'none', stroke: item.color, strokeWidth: 2, strokeLinejoin: 'round', strokeLinecap: 'round' }))))
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}`)))))
374
624
  }
375
625
 
376
626
  /** Byte-rate per second between consecutive samples, in KB/s. */
@@ -424,6 +674,23 @@ window.__ModuleLoader__.load({
424
674
  const [logSource, setLogSource] = React.useState('nginx.service')
425
675
  const [logLines, setLogLines] = React.useState(200)
426
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)
427
694
  const [logAuto, setLogAuto] = React.useState(false)
428
695
  const [sslDomain, setSslDomain] = React.useState('')
429
696
  const [sslResult, setSslResult] = React.useState(null)
@@ -447,6 +714,18 @@ window.__ModuleLoader__.load({
447
714
  const [monForm, setMonForm] = React.useState({ type: 'http', target: '', label: '', intervalMinutes: 5, language: 'shell', script: '' })
448
715
  const [monEditId, setMonEditId] = React.useState('')
449
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('')
450
729
  const [monBusy, setMonBusy] = React.useState('')
451
730
  const [health, setHealth] = React.useState(null)
452
731
  const [certs, setCerts] = React.useState([])
@@ -466,6 +745,14 @@ window.__ModuleLoader__.load({
466
745
  const [chBusy, setChBusy] = React.useState('')
467
746
  const [fsPath, setFsPath] = React.useState('/')
468
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: [] })
469
756
  const [fsBusy, setFsBusy] = React.useState('')
470
757
  const [adding, setAdding] = React.useState(false)
471
758
 
@@ -477,6 +764,7 @@ window.__ModuleLoader__.load({
477
764
  const conf = await api('config')
478
765
  if (conf.config) {
479
766
  setConfig(conf.config)
767
+ setUiMode(conf.config.uiMode === 'simple' ? 'simple' : 'pro')
480
768
  setQuickText((conf.config.quickCommands || []).join('\n'))
481
769
  }
482
770
  setError('')
@@ -543,7 +831,11 @@ window.__ModuleLoader__.load({
543
831
  if (!source) { setLogText(T.logPick); return }
544
832
  setBusy('logs')
545
833
  try {
546
- const data = await api(`tail?host=${encodeURIComponent(cHost || hosts[0]?.name)}&source=${encodeURIComponent(source)}&lines=${logLines}`, {}, timeoutFor('action'))
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'))
547
839
  if (data.missing) {
548
840
  setLogText(data.error || '')
549
841
  void loadInv(cHost || hosts[0]?.name, true)
@@ -569,35 +861,127 @@ window.__ModuleLoader__.load({
569
861
  try {
570
862
  const data = await api(`files?host=${encodeURIComponent(cHost || hosts[0]?.name)}&path=${encodeURIComponent(target)}`, {}, timeoutFor('action'))
571
863
  setFsEntries(data.entries || []); setFsPath(data.path || target); setError('')
864
+ try { addRecent(data.path || target) } catch { /* ignore */ }
572
865
  } catch (e) { setError(String(e.message || e)) } finally { setFsBusy('') }
573
866
  }
574
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
+
575
902
  const downloadFile = async (path, name) => {
576
903
  setFsBusy('dl:' + path)
577
904
  try {
578
- const data = await api(`download?host=${encodeURIComponent(cHost || hosts[0]?.name)}&path=${encodeURIComponent(path)}`, {}, 120_000)
579
- const bytes = Uint8Array.from(atob(data.base64 || ''), ch => ch.charCodeAt(0))
580
- const url = URL.createObjectURL(new Blob([bytes]))
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))
581
938
  const a = document.createElement('a')
582
- a.href = url; a.download = name || 'download'; a.click()
583
- setTimeout(() => URL.revokeObjectURL(url), 2000)
584
- } catch (e) { setError(String(e.message || e)) } finally { setFsBusy('') }
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) }
585
944
  }
586
945
 
587
946
  const uploadFile = async (file) => {
588
947
  if (!file) return
948
+ if (file.size > 100 * 1024 * 1024) { setError(T.fsTooBig); return }
949
+ const target = (fsPath === '/' ? '' : fsPath) + '/' + file.name
589
950
  setFsBusy('upload')
590
951
  try {
591
- const base64 = await new Promise((resolve, reject) => {
592
- const reader = new FileReader()
593
- reader.onload = () => resolve(String(reader.result).split(',')[1] || '')
594
- reader.onerror = () => reject(new Error('read failed'))
595
- reader.readAsDataURL(file)
596
- })
597
- const target = (fsPath === '/' ? '' : fsPath) + '/' + file.name
598
- await api('upload', { method: 'POST', body: JSON.stringify({ host: cHost || hosts[0]?.name, path: target, base64 }) }, 180_000)
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)
599
968
  await loadFiles(fsPath)
600
- } 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)) }
601
985
  }
602
986
 
603
987
  const fsDelete = async (path) => {
@@ -609,6 +993,121 @@ window.__ModuleLoader__.load({
609
993
  } catch (e) { setError(String(e.message || e)) } finally { setFsBusy('') }
610
994
  }
611
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
+
612
1111
  const fsMkdir = async () => {
613
1112
  const name = window.prompt(T.folderName)
614
1113
  if (!name) return
@@ -717,26 +1216,74 @@ window.__ModuleLoader__.load({
717
1216
  const host = mHost || hosts[0]?.name
718
1217
  if (!host) return
719
1218
  void (async () => {
1219
+ markLoading('samples', true)
720
1220
  try {
721
1221
  const data = await api(`metrics?host=${encodeURIComponent(host)}&hours=${mHours}`)
722
1222
  setSamples(data.samples || [])
723
1223
  } catch (e) { setError(String(e.message || e)) }
1224
+ finally { markLoading('samples', false) }
724
1225
  })()
725
1226
  }, [detailHost, detailTab, mHost, mHours, hosts])
726
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
+
727
1262
  React.useEffect(() => {
728
1263
  if (tab !== 2 || detailHost) return
729
1264
  void (async () => {
730
1265
  try { setAiModels(await api('ai-models', {}, 15_000)) } catch { /* optional */ }
731
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))
732
1269
  })()
733
1270
  }, [tab, detailHost])
734
1271
 
735
1272
  React.useEffect(() => {
736
1273
  if (!detailHost || detailTab !== 'files') return
1274
+ if (!fsTree['/']) void loadTree('/')
737
1275
  void loadFiles(fsPath)
738
1276
  }, [detailHost, detailTab, cHost])
739
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
+
740
1287
  React.useEffect(() => {
741
1288
  if (!detailHost || detailTab !== 'logs' || !logAuto) return
742
1289
  void loadLogs()
@@ -776,11 +1323,12 @@ window.__ModuleLoader__.load({
776
1323
  }
777
1324
 
778
1325
  const cleanupHost = async (name) => {
779
- if (!window.confirm(`${T.cleanup}: ${name}?`)) return
1326
+ if (!window.confirm(`${T.cleanup}:${name}\n${T.cleanDetail || ''}`)) return
780
1327
  setBusy('clean:' + name)
781
1328
  try {
782
1329
  const data = await api('cleanup', { method: 'POST', body: JSON.stringify({ host: name, confirm: true }) }, timeoutFor('action') * 2)
783
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) })
784
1332
  setTimeout(() => setNotice(''), 4000)
785
1333
  } catch (e) { setError(String(e.message || e)) } finally { setBusy('') }
786
1334
  }
@@ -804,6 +1352,7 @@ window.__ModuleLoader__.load({
804
1352
  }
805
1353
 
806
1354
  const saveConfig = async () => {
1355
+ setOpBusy('save')
807
1356
  try {
808
1357
  const payload = {
809
1358
  ...config,
@@ -811,9 +1360,12 @@ window.__ModuleLoader__.load({
811
1360
  aiEnabled: aiModels.aiEnabled !== false,
812
1361
  aiProvider: aiModels.aiProvider || '',
813
1362
  aiModel: aiModels.aiModel || '',
1363
+ uiMode,
814
1364
  }
815
1365
  const data = await api('config', { method: 'POST', body: JSON.stringify(payload) })
816
1366
  if (data.config) setConfig(data.config)
1367
+ setNotice(T.saved)
1368
+ setTimeout(() => setNotice(''), 1500)
817
1369
  setNotice(T.changed); setTimeout(() => setNotice(''), 2000)
818
1370
  } catch (e) { setError(String(e.message || e)) }
819
1371
  }
@@ -1001,9 +1553,261 @@ window.__ModuleLoader__.load({
1001
1553
  diag.result.hint ? h('p', { className: 'ops-warn', style: { fontSize: '12px', margin: '8px 0 0' } }, diag.result.hint) : null) : null))
1002
1554
  : null
1003
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
+
1004
1808
  const overviewView = hosts.length === 0
1005
- ? h('p', { className: 'ops-empty' }, T.noHosts)
1006
- : h('div', { style: { display: 'flex', flexDirection: 'column', gap: '12px' } },
1809
+ ? onboardingView
1810
+ : uiMode === 'simple' ? simpleView : h('div', { style: { display: 'flex', flexDirection: 'column', gap: '12px' } },
1007
1811
  diagView,
1008
1812
  summaryStrip,
1009
1813
  h('div', { className: 'ops-cards' }, ...hosts.map(hostCard)))
@@ -1021,15 +1825,43 @@ window.__ModuleLoader__.load({
1021
1825
  ? `${Math.floor(lastSample.uptimeSec / 86400)} 天 ${Math.floor((lastSample.uptimeSec % 86400) / 3600)} 小时`
1022
1826
  : '—'
1023
1827
 
1024
- const monitorSummary = h('div', { className: 'ops-cards' },
1025
- h('div', { className: 'ops-num' }, h('b', null, lastSample?.load1 !== null && lastSample?.load1 !== undefined ? String(lastSample.load1) : '—'), h('span', null, '负载(1 分钟)')),
1026
- h('div', { className: 'ops-num' }, h('b', null, [lastSample?.load5, lastSample?.load15].every(v => v === null || v === undefined) ? '—' : `${lastSample?.load5 ?? '—'} / ${lastSample?.load15 ?? '—'}`), h('span', null, '负载 5 / 15 分钟')),
1027
- h('div', { className: 'ops-num' }, h('b', null, lastSample?.procs !== null && lastSample?.procs !== undefined ? String(lastSample.procs) : '—'), h('span', null, '进程数')),
1028
- h('div', { className: 'ops-num' }, h('b', null, lastSample?.tcp !== null && lastSample?.tcp !== undefined ? String(lastSample.tcp) : '—'), h('span', null, 'TCP 连接')),
1029
- h('div', { className: 'ops-num' }, h('b', null, lastSample?.swap !== null && lastSample?.swap !== undefined ? lastSample.swap + '%' : '—'), h('span', null, 'Swap 使用')),
1030
- h('div', { className: 'ops-num' }, h('b', null, uptimeText), h('span', null, '已运行')))
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)
1031
1861
 
1032
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,
1033
1865
  h('div', { className: 'ops-chips' },
1034
1866
  detailHost ? null : hostPicker(mHost, setMHost),
1035
1867
  h('span', { className: 'ops-chip' }, T.hours),
@@ -1037,16 +1869,20 @@ window.__ModuleLoader__.load({
1037
1869
  h('button', { key: hours, className: `ops-tab${mHours === hours ? ' on' : ''}`, onClick: () => setMHours(hours) }, label))),
1038
1870
  monitorSummary,
1039
1871
  h('div', { className: 'ops-grid2' },
1040
- h(Chart, { rows: enriched, title: T.cpu + ' %', max: 100, series: [{ field: 'cpu', label: T.cpu, color: 'var(--dsw-alias-accent,#4c8dff)' }] }),
1041
- h(Chart, { rows: enriched, title: '内存 / Swap %', max: 100, series: [
1042
- { field: 'mem', label: T.mem, color: 'var(--dsw-alias-accent,#4c8dff)' },
1043
- { field: 'swap', label: 'Swap', color: 'var(--dsw-alias-warning,#e5b650)' },
1044
- ] }),
1045
- h(Chart, { rows: enriched, title: T.disk + ' %', max: 100, series: [{ field: 'disk', label: T.disk, color: 'var(--dsw-alias-accent,#4c8dff)' }] }),
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)' }] }),
1046
1881
  h(Chart, { rows: enriched, title: '网络 KB/s', unit: ' KB/s', series: [
1047
1882
  { field: 'rxRate', label: '入', color: 'var(--dsw-alias-success,#4ac97e)' },
1048
1883
  { field: 'txRate', label: '出', color: 'var(--dsw-alias-warning,#e5b650)' },
1049
- ] }),
1884
+ ] })),
1885
+ h('div', { className: 'ops-grid2' },
1050
1886
  h(Chart, { rows: enriched, title: '磁盘读写 KB/s', unit: ' KB/s', series: [
1051
1887
  { field: 'ioReadRate', label: '读', color: 'var(--dsw-alias-accent,#4c8dff)' },
1052
1888
  { field: 'ioWriteRate', label: '写', color: 'var(--dsw-alias-danger,#ff6b6b)' },
@@ -1060,6 +1896,7 @@ window.__ModuleLoader__.load({
1060
1896
  h('span', { className: 'ops-mono', title: String(row) }, render ? render(row) : String(row))))))
1061
1897
 
1062
1898
  const configView = h('div', { style: { display: 'flex', flexDirection: 'column', gap: '12px' } },
1899
+ viewHint(T.hintConfig),
1063
1900
  h('div', { className: 'ops-chips' }, (detailHost ? null : hostPicker(cHost, setCHost)),
1064
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)),
1065
1902
  inv ? h('div', { className: 'ops-grid2' },
@@ -1087,9 +1924,61 @@ window.__ModuleLoader__.load({
1087
1924
  h('button', { className: 'ops-btn ops-btn-sm', onClick: () => { void restoreVersion(backup) } }, T.fileRestore))))),
1088
1925
  histDiff ? h('pre', { className: 'ops-pre', style: { maxHeight: '240px', marginTop: '8px' } }, histDiff.diff) : null)))
1089
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
+
1090
1956
  const appsView = h('div', { style: { display: 'flex', flexDirection: 'column', gap: '12px' } },
1957
+ viewHint(T.hintApps),
1091
1958
  h('div', { className: 'ops-chips' }, (detailHost ? null : hostPicker(cHost, setCHost)),
1092
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))))))),
1093
1982
  h('div', { className: 'ops-card' },
1094
1983
  h('div', { className: 'ops-card-h' }, h('span', null, T.tabs[3]), h('span', { className: 'ops-chip' }, String((inv?.apps || []).length))),
1095
1984
  (inv?.apps || []).length === 0 ? h('p', { className: 'ops-empty' }, T.empty)
@@ -1180,65 +2069,261 @@ window.__ModuleLoader__.load({
1180
2069
  h('div', { className: sslResult.daysLeft !== null && sslResult.daysLeft < 15 ? 'ops-bad' : 'ops-sub', style: { fontSize: '12px' } },
1181
2070
  sslResult.daysLeft === null ? T.noExpire : `${T.expireAt} ${sslResult.notAfter} · ${T.daysLeft} ${sslResult.daysLeft}`)) : null)))
1182
2071
 
1183
- const logChoices = (() => {
1184
- const apps = inv?.apps || []
1185
- const services = apps.filter(a => a.kind === 'service').map(a => a.name)
1186
- const pids = apps.filter(a => a.kind === 'java').map(a => `pid:${String(a.name).replace(/[^0-9]/g, '')}`)
1187
- const files = ['file:/var/log/syslog', 'file:/var/log/messages', 'file:/var/log/nginx/error.log',
1188
- 'file:/var/log/nginx/access.log', 'file:/var/log/auth.log']
1189
- return [...services, ...pids, ...files]
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
1190
2106
  })()
1191
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
+
1192
2230
  const logsView = h('div', { style: { display: 'flex', flexDirection: 'column', gap: '12px' } },
2231
+ viewHint(T.hintLogs),
2232
+ logUsageCard,
1193
2233
  h('div', { className: 'ops-chips' }, (detailHost ? null : hostPicker(cHost, setCHost))),
1194
2234
  h('div', { className: 'ops-card' },
1195
2235
  h('div', { className: 'ops-card-h' }, h('span', null, T.logs),
1196
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}` : ''}`),
1197
2239
  h('label', { className: 'ops-sub', style: { display: 'flex', gap: '6px', alignItems: 'center' } },
1198
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),
1199
2243
  h('button', { className: 'ops-btn ops-btn-primary ops-btn-sm', disabled: busy === 'logs', onClick: () => { void loadLogs() } }, busy === 'logs' ? T.reading : T.load))),
1200
2244
  h('div', { className: 'ops-card-b' },
1201
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)))),
1202
2260
  h('input', {
1203
- className: 'ops-input', style: { flex: '1 1 320px' }, value: logSource, list: 'ops-log-sources',
1204
- placeholder: T.logSource, onChange: e => setLogSource(e.target.value),
2261
+ className: 'ops-input', style: { flex: '1 1 220px' }, value: logSource,
2262
+ placeholder: T.logManual, onChange: e => setLogSource(e.target.value),
1205
2263
  onKeyDown: e => { if (e.key === 'Enter') void loadLogs() },
1206
2264
  }),
1207
- h('datalist', { id: 'ops-log-sources' }, ...logChoices.map(o => h('option', { key: o, value: o }))),
1208
2265
  h('label', { className: 'ops-sub' }, T.lines,
1209
- h('input', { className: 'ops-input', type: 'number', min: 20, max: 1000, value: logLines, style: { width: '90px' }, onChange: e => setLogLines(Number(e.target.value)) }))),
1210
- h('p', { className: 'ops-sub', style: { margin: '0 0 8px', fontSize: '12px' } }, T.logHint),
1211
- h('pre', { className: 'ops-pre', style: { maxHeight: '55vh' } }, logText || (busy === 'logs' ? T.reading : '')))))
1212
-
1213
- const filesView = h('div', { style: { display: 'flex', flexDirection: 'column', gap: '12px' } },
1214
- h('div', { className: 'ops-chips' }, (detailHost ? null : hostPicker(cHost, setCHost))),
1215
- h('div', { className: 'ops-card' },
1216
- h('div', { className: 'ops-card-h' }, h('span', null, T.files + ' ' + fsPath),
1217
- h('span', { className: 'ops-chips' },
1218
- h('label', { className: 'ops-btn ops-btn-sm', style: { display: 'inline-flex', alignItems: 'center' } },
1219
- T.upload,
1220
- h('input', { type: 'file', style: { display: 'none' }, onChange: e => { void uploadFile(e.target.files?.[0]); e.target.value = '' } })),
1221
- h('button', { className: 'ops-btn ops-btn-sm', onClick: () => { void fsMkdir() } }, T.newFolder))),
1222
- h('div', { className: 'ops-card-b' },
1223
- h('div', { className: 'ops-chips' },
1224
- h('button', { className: 'ops-btn ops-btn-sm', onClick: () => { const up = fsPath.split('/').slice(0, -1).join('/') || '/'; void loadFiles(up) } }, T.up),
1225
- h('input', { className: 'ops-input', style: { flex: '1 1 320px' }, value: fsPath, onChange: e => setFsPath(e.target.value), onKeyDown: e => { if (e.key === 'Enter') void loadFiles() } }),
1226
- h('button', { className: 'ops-btn ops-btn-sm', disabled: fsBusy === 'list', onClick: () => { void loadFiles() } }, fsBusy === 'list' ? T.reading : T.refresh))),
1227
- (fsEntries || []).length === 0 ? h('p', { className: 'ops-empty' }, fsBusy ? T.reading : T.empty)
1228
- : h('div', { className: 'ops-list' }, ...(fsEntries || []).map(entry => h('div', { key: entry.path, className: 'ops-row', style: { gridTemplateColumns: '1fr 90px 140px auto' } },
1229
- h('span', { style: { display: 'flex', alignItems: 'center', gap: '6px', minWidth: 0 } },
1230
- h('span', { className: 'ops-chip' }, entry.dir ? 'DIR' : (entry.link ? 'LNK' : 'FILE')),
1231
- h('span', { className: 'ops-mono', title: entry.path, style: { cursor: entry.dir ? 'pointer' : 'default', color: entry.dir ? 'var(--dsw-alias-accent,#4c8dff)' : 'inherit' }, onClick: () => { if (entry.dir) void loadFiles(entry.path) } }, entry.name)),
1232
- h('span', { className: 'ops-dim' }, entry.dir ? '—' : `${(entry.size / 1024).toFixed(entry.size > 1048576 ? 0 : 1)} KB`),
1233
- h('span', { className: 'ops-dim' }, String(entry.mtime || '').replace('T', ' ')),
1234
- h('span', { style: { display: 'flex', gap: '6px', justifyContent: 'flex-end' } },
1235
- entry.dir
1236
- ? h('button', { className: 'ops-btn ops-btn-sm', onClick: () => { void loadFiles(entry.path) } }, T.open)
1237
- : h('button', { className: 'ops-btn ops-btn-sm', disabled: fsBusy === 'dl:' + entry.path, onClick: () => { void downloadFile(entry.path, entry.name) } }, fsBusy === 'dl:' + entry.path ? '…' : T.download),
1238
- h('button', { className: 'ops-btn ops-btn-sm', disabled: fsBusy === 'del:' + entry.path, onClick: () => { void fsDelete(entry.path) } }, T.del)))))),
1239
- output ? h('pre', { className: 'ops-pre' }, output) : null)
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
+ }
1240
2325
 
1241
- const termKey = (event) => {
2326
+ const termKey = (event) => {
1242
2327
  if (!term?.id) return
1243
2328
  if (aiMode) {
1244
2329
  if (event.key === 'Escape') { event.preventDefault(); setAiMode(false); setAiDraft(''); return }
@@ -1267,10 +2352,11 @@ window.__ModuleLoader__.load({
1267
2352
  }
1268
2353
 
1269
2354
 
1270
- const dhost = () => detailHost || cHost
1271
2355
 
1272
2356
  const loadChannels = async () => {
2357
+ markLoading('channels', true)
1273
2358
  try { const data = await api('channels', {}, 20_000); setChannels(data.channels || []) } catch { setChannels([]) }
2359
+ finally { markLoading('channels', false) }
1274
2360
  }
1275
2361
 
1276
2362
  const saveChannel = async () => {
@@ -1297,7 +2383,7 @@ window.__ModuleLoader__.load({
1297
2383
  try {
1298
2384
  const data = await api('channels', { method: 'POST', body: JSON.stringify({ action: 'remove', id }) })
1299
2385
  setChannels(data.channels || [])
1300
- } catch (e) { setError(String(e.message || e)) }
2386
+ } catch (e) { setError(String(e.message || e)) } finally { setOpBusy('') }
1301
2387
  }
1302
2388
 
1303
2389
  const loadHealth = async (host) => {
@@ -1310,8 +2396,10 @@ window.__ModuleLoader__.load({
1310
2396
 
1311
2397
  const loadCerts = async (host) => {
1312
2398
  if (!host) return
2399
+ markLoading('certs', true)
1313
2400
  try { const data = await api(`certs?host=${encodeURIComponent(host)}`, {}, 60_000); setCerts(data.certs || []) }
1314
2401
  catch { setCerts([]) }
2402
+ finally { markLoading('certs', false) }
1315
2403
  }
1316
2404
 
1317
2405
  const renewCertsNow = async (dryRun) => {
@@ -1361,8 +2449,10 @@ window.__ModuleLoader__.load({
1361
2449
 
1362
2450
  const loadCron = async (host) => {
1363
2451
  if (!host) return
2452
+ markLoading('cron', true)
1364
2453
  try { const data = await api(`cron?host=${encodeURIComponent(host)}`, {}, 30_000); setCronJobs(data.jobs || []) }
1365
2454
  catch { setCronJobs([]) }
2455
+ finally { markLoading('cron', false) }
1366
2456
  }
1367
2457
 
1368
2458
  const addCronJob = async () => {
@@ -1439,12 +2529,114 @@ window.__ModuleLoader__.load({
1439
2529
  } catch (e) { setError(String(e.message || e)) }
1440
2530
  }
1441
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
+
1442
2632
  const loadMonitors = async (host) => {
2633
+ markLoading('monitors', true)
1443
2634
  if (!host) return
1444
2635
  try {
1445
2636
  const data = await api(`monitors?host=${encodeURIComponent(host)}`, {}, 20_000)
1446
2637
  setMonitors(data.monitors || [])
1447
2638
  } catch { setMonitors([]) }
2639
+ finally { markLoading('monitors', false) }
1448
2640
  }
1449
2641
 
1450
2642
  const saveMonitor = async () => {
@@ -1503,17 +2695,7 @@ window.__ModuleLoader__.load({
1503
2695
  } catch (e) { setError(String(e.message || e)) }
1504
2696
  }
1505
2697
 
1506
- const openHost = (name) => {
1507
- setDetailHost(name)
1508
- setCHost(name)
1509
- setMHost(name)
1510
- setDetailTab('summary')
1511
- void loadMonitors(name)
1512
- void loadHealth(name)
1513
- void loadCerts(name)
1514
- }
1515
2698
 
1516
- const focusTerm = () => { const el = document.getElementById('ops-term'); if (el) el.focus() }
1517
2699
 
1518
2700
  const askHost = async () => {
1519
2701
  const question = askQuestion.trim()
@@ -1583,11 +2765,117 @@ window.__ModuleLoader__.load({
1583
2765
  focusTerm()
1584
2766
  }
1585
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
+
1586
2873
  const quickCommands = (Array.isArray(config.quickCommands) && config.quickCommands.length > 0)
1587
2874
  ? config.quickCommands
1588
2875
  : ['df -h', 'free -h', 'uptime', 'systemctl --failed', 'docker ps', 'tail -n 30 /var/log/messages']
1589
2876
 
1590
2877
  const terminalView = h('div', { style: { display: 'flex', flexDirection: 'column', gap: '10px' } },
2878
+ viewHint(T.hintTerminal),
1591
2879
  h('div', { className: 'ops-chips' },
1592
2880
  (detailHost ? null : hostPicker(cHost, setCHost)),
1593
2881
  term?.id
@@ -1717,7 +3005,11 @@ window.__ModuleLoader__.load({
1717
3005
  askLog.length === 0
1718
3006
  ? h('div', { style: { margin: 'auto', textAlign: 'center' } },
1719
3007
  h('p', { className: 'ops-sub', style: { margin: 0 } }, T.askPh),
1720
- 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, ' 发给我(开发者)')))
1721
3013
  : askLog.map(messageView)),
1722
3014
  h('div', { className: 'ops-composer' },
1723
3015
  h('input', {
@@ -1732,6 +3024,14 @@ window.__ModuleLoader__.load({
1732
3024
  askBusy ? T.thinking : T.send)))
1733
3025
 
1734
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))),
1735
3035
  h('div', { className: 'ops-card' },
1736
3036
  h('div', { className: 'ops-card-h' }, h('span', null, T.patrol), notice ? h('span', { className: 'ops-ok' }, notice) : null),
1737
3037
  h('div', { className: 'ops-card-b' },
@@ -1809,6 +3109,43 @@ window.__ModuleLoader__.load({
1809
3109
  }, (T.channelLevels || [])[index])),
1810
3110
  h('button', { className: 'ops-btn ops-btn-primary ops-btn-sm', disabled: chBusy === 'add', onClick: () => { void saveChannel() } }, chBusy === 'add' ? T.reading : T.channelAdd)),
1811
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 ? '成功' : '失败')))))),
1812
3149
  h('div', { className: 'ops-card' },
1813
3150
  h('div', { className: 'ops-card-h' }, h('span', null, T.quickEdit),
1814
3151
  h('button', { className: 'ops-btn ops-btn-primary ops-btn-sm', onClick: () => { void saveConfig() } }, T.quickSave)),
@@ -1845,6 +3182,7 @@ window.__ModuleLoader__.load({
1845
3182
  h('button', { className: 'ops-btn ops-btn-sm', onClick: () => { void removeHost(host.name) } }, T.remove))))))
1846
3183
 
1847
3184
  const backupView = h('div', { style: { display: 'flex', flexDirection: 'column', gap: '12px' } },
3185
+ viewHint(T.hintBackups),
1848
3186
  h('div', { className: 'ops-card' },
1849
3187
  h('div', { className: 'ops-card-h' }, h('span', null, T.backups), h('span', { className: 'ops-dim' }, dhost())),
1850
3188
  h('div', { className: 'ops-card-b' },
@@ -1857,7 +3195,7 @@ window.__ModuleLoader__.load({
1857
3195
  ? h('input', { className: 'ops-input', style: { flex: '1 1 200px' }, value: backupForm.database, placeholder: '数据库名(留空=全部)', onChange: e => setBackupForm({ ...backupForm, database: e.target.value }) })
1858
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 }) }),
1859
3197
  h('input', { className: 'ops-input', style: { width: '160px' }, value: backupForm.dir, placeholder: '/home/backup', onChange: e => setBackupForm({ ...backupForm, dir: e.target.value }) }),
1860
- 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,
1861
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) }) })),
1862
3200
  h('button', { className: 'ops-btn ops-btn-primary ops-btn-sm', disabled: opBusy === 'backup', onClick: () => { void doBackup() } }, opBusy === 'backup' ? T.reading : T.backupNow)),
1863
3201
  opOut ? h('pre', { className: 'ops-pre', style: { maxHeight: '160px', marginTop: '8px' } }, opOut) : null)),
@@ -1874,6 +3212,7 @@ window.__ModuleLoader__.load({
1874
3212
  h('button', { className: 'ops-btn ops-btn-sm', onClick: () => { void removeBackupNow(item.id) } }, T.backupRemove))))))))
1875
3213
 
1876
3214
  const cronView = h('div', { style: { display: 'flex', flexDirection: 'column', gap: '12px' } },
3215
+ viewHint(T.hintCron),
1877
3216
  h('div', { className: 'ops-card' },
1878
3217
  h('div', { className: 'ops-card-h' }, h('span', null, T.cron), h('span', { className: 'ops-dim' }, dhost())),
1879
3218
  h('div', { className: 'ops-card-b' },
@@ -1889,7 +3228,9 @@ window.__ModuleLoader__.load({
1889
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 }) }),
1890
3229
  h('button', { className: 'ops-btn ops-btn-primary ops-btn-sm', disabled: opBusy === 'cron', onClick: () => { void addCronJob() } }, T.cronAdd))),
1891
3230
  h('div', { className: 'ops-card-b' },
1892
- cronJobs.length === 0
3231
+ loadingMap.cron && cronJobs.length === 0
3232
+ ? h('p', { className: 'ops-empty' }, T.loadingList)
3233
+ : cronJobs.length === 0
1893
3234
  ? h('p', { className: 'ops-empty' }, T.cronEmpty)
1894
3235
  : h('div', null, ...cronJobs.map(job => h('div', { key: `${job.index}-${job.raw}`, className: 'ops-row', style: { gridTemplateColumns: '140px 1fr auto' } },
1895
3236
  h('span', { className: 'ops-mono', style: { fontSize: '12px' } }, job.schedule),
@@ -1898,6 +3239,7 @@ window.__ModuleLoader__.load({
1898
3239
  h('button', { className: 'ops-btn ops-btn-sm', onClick: () => { void removeCronJob(job.index) } }, T.cronRemove))))))))
1899
3240
 
1900
3241
  const deployView = h('div', { style: { display: 'flex', flexDirection: 'column', gap: '12px' } },
3242
+ viewHint(T.hintDeploy),
1901
3243
  h('div', { className: 'ops-card' },
1902
3244
  h('div', { className: 'ops-card-h' }, h('span', null, T.deployNew)),
1903
3245
  h('div', { className: 'ops-card-b' },
@@ -1917,7 +3259,9 @@ window.__ModuleLoader__.load({
1917
3259
  h('div', { className: 'ops-card-h' }, h('span', null, T.deploy)),
1918
3260
  h('div', { className: 'ops-card-b' },
1919
3261
  deployJobs.length === 0
1920
- ? h('p', { className: 'ops-empty' }, T.deployEmpty)
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))
1921
3265
  : h('div', null, ...deployJobs.map(job => h('div', { key: job.id, className: 'ops-row', style: { gridTemplateColumns: '1fr 1.2fr auto' } },
1922
3266
  h('span', { className: 'ops-name' }, job.name || job.dir),
1923
3267
  h('span', { className: 'ops-dim' }, `${job.dir}${job.health ? ' · ' + job.health : ''}`),
@@ -1932,7 +3276,7 @@ window.__ModuleLoader__.load({
1932
3276
 
1933
3277
  const healthCard = h('div', { className: 'ops-card' },
1934
3278
  h('div', { className: 'ops-card-h' },
1935
- h('span', null, T.health,
3279
+ h('span', { title: T.tipHealth }, T.health,
1936
3280
  healthScore !== null ? h('span', { className: healthLevel === 'ok' ? 'ops-ok' : healthLevel === 'warn' ? 'ops-warn' : 'ops-bad', style: { marginLeft: '8px' } },
1937
3281
  `${healthScore} 分 · ${healthLevel === 'ok' ? T.scoreGood : healthLevel === 'warn' ? T.scoreWarn : T.scoreBad}`) : null),
1938
3282
  h('button', { className: 'ops-btn ops-btn-sm', disabled: opBusy === 'health', onClick: () => { void loadHealth(dhost()) } }, opBusy === 'health' ? T.reading : T.healthNow)),
@@ -1958,7 +3302,9 @@ window.__ModuleLoader__.load({
1958
3302
  h('button', { className: 'ops-btn ops-btn-sm', disabled: opBusy === 'renew', onClick: () => { void renewCertsNow(true) } }, T.certRenew),
1959
3303
  h('button', { className: 'ops-btn ops-btn-sm', disabled: opBusy === 'renew', onClick: () => { void renewCertsNow(false) } }, T.certRenewReal))),
1960
3304
  h('div', { className: 'ops-card-b' },
1961
- certs.length === 0
3305
+ loadingMap.certs
3306
+ ? h('p', { className: 'ops-empty' }, T.loadingList)
3307
+ : certs.length === 0
1962
3308
  ? h('p', { className: 'ops-empty' }, T.certNone)
1963
3309
  : h('div', null, ...certs.map(cert => h('div', { key: cert.domain, className: 'ops-row', style: { gridTemplateColumns: '1.2fr 1fr auto' } },
1964
3310
  h('span', { className: 'ops-mono', style: { fontSize: '12px' } }, cert.domain),
@@ -1967,22 +3313,69 @@ window.__ModuleLoader__.load({
1967
3313
  h('span', null)))),
1968
3314
  opOut ? h('pre', { className: 'ops-pre', style: { maxHeight: '200px', marginTop: '8px' } }, opOut) : null))
1969
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
+
1970
3348
  const monitorsCard = h('div', { className: 'ops-card' },
1971
3349
  h('div', { className: 'ops-card-h' },
1972
3350
  h('span', null, T.monitors, monitors.length ? h('span', { className: 'ops-chip', style: { marginLeft: '6px' } }, String(monitors.length)) : null),
1973
3351
  h('span', { className: 'ops-sub' }, T.monHttpHint)),
1974
3352
  h('div', { className: 'ops-card-b' },
1975
- monitors.length === 0
3353
+ loadingMap.monitors && monitors.length === 0
3354
+ ? h('p', { className: 'ops-empty' }, T.loadingList)
3355
+ : monitors.length === 0
1976
3356
  ? h('p', { className: 'ops-empty' }, T.monEmpty)
1977
3357
  : h('div', null, ...monitors.map(monitor => h('div', { key: monitor.id, className: 'ops-row', style: { gridTemplateColumns: '1fr 1.1fr auto' } },
1978
3358
  h('span', { style: { display: 'flex', alignItems: 'center', gap: '8px', minWidth: 0 } },
1979
- h('i', { className: 'ops-dot ' + (monitor.lastOk === true ? 'ok' : monitor.lastOk === false ? 'bad' : '') }),
3359
+ h('i', { className: levelDot(monitorLevel(monitor)) }),
1980
3360
  h('span', { className: 'ops-name' }, monitor.label || monitor.target || monitor.type),
1981
3361
  monitor.target && monitor.label ? h('span', { className: 'ops-mono ops-dim', style: { fontSize: '11.5px' } }, monitor.target) : null,
1982
3362
  h('span', { className: 'ops-chip' }, (T.monTypeShort || {})[monitor.type] || monitor.type)
1983
3363
  , monitor.type === 'script' ? h('span', { className: 'ops-chip' }, monitor.language || 'shell') : null),
1984
- h('span', { className: 'ops-dim' }, monitor.last ? `${monitor.last.detail} · ${fmt(monitor.last.at)}` : T.monNever),
1985
- h('span', { style: { display: 'flex', gap: '6px', justifyContent: 'flex-end' } },
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,
1986
3379
  h('button', { className: 'ops-btn ops-btn-sm', disabled: monBusy === 'test:' + monitor.id, onClick: () => { void testMonitor(monitor.id) } }, T.monCheck),
1987
3380
  h('button', { className: 'ops-btn ops-btn-sm', onClick: () => editMonitor(monitor) }, T.monEdit),
1988
3381
  h('button', { className: 'ops-btn ops-btn-sm', onClick: () => { void removeMonitor(monitor.id) } }, T.monRemove))))),
@@ -2019,6 +3412,16 @@ window.__ModuleLoader__.load({
2019
3412
  monBusy === 'add' ? T.reading : (monEditId ? T.monSave : T.monAdd)),
2020
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),
2021
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
+
2022
3425
  monForm.type === 'script'
2023
3426
  ? h('div', { style: { marginTop: '8px' } },
2024
3427
  h('textarea', {
@@ -2070,6 +3473,15 @@ window.__ModuleLoader__.load({
2070
3473
  h('button', { className: 'ops-btn ops-btn-primary ops-btn-sm', onClick: () => { void askAi(host.name, '') } }, T.diagnose),
2071
3474
  h('button', { className: 'ops-btn ops-btn-sm', onClick: () => setDetailTab('logs') }, T.tabs[5]),
2072
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),
2073
3485
  h('button', { className: 'ops-btn ops-btn-sm', onClick: () => { void loadBase(); void testHost(host.name) } }, T.test),
2074
3486
  (sample?.disk ?? 0) >= 85
2075
3487
  ? h('button', { className: 'ops-btn ops-btn-sm', onClick: () => { void cleanupHost(host.name) } }, T.cleanup)
@@ -2081,6 +3493,7 @@ window.__ModuleLoader__.load({
2081
3493
  healthCard,
2082
3494
  certsCard,
2083
3495
  monitorsCard,
3496
+ servicesCard,
2084
3497
  diag && diag.host === host.name ? diagView : null)
2085
3498
  })()
2086
3499
 
@@ -2108,9 +3521,14 @@ window.__ModuleLoader__.load({
2108
3521
  const header = h('div', { className: 'ops-top' },
2109
3522
  h('div', null,
2110
3523
  h('h1', { className: 'ops-title' }, detailHost ? (hosts.find(item => item.name === detailHost)?.alias || detailHost) : T.title),
2111
- h('p', { className: 'ops-sub' }, detailHost ? '这台服务器的全部信息' : T.sub)),
3524
+ h('p', { className: 'ops-sub' }, detailHost ? '这台服务器的全部信息' : (uiMode === 'simple' ? T.simpleSub : T.sub))),
2112
3525
  h('div', { style: { display: 'flex', gap: '10px', alignItems: 'center' } },
2113
- 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),
2114
3532
  detailHost
2115
3533
  ? h('button', { className: 'ops-btn ops-btn-sm', onClick: () => { setDetailHost(null); void loadBase() } }, '← 返回所有服务器')
2116
3534
  : h('button', { className: 'ops-btn ops-btn-sm', onClick: () => { void loadBase(); if (detailHost) void loadInv(cHost || detailHost, true) } }, T.refresh)))
@@ -2130,9 +3548,12 @@ window.__ModuleLoader__.load({
2130
3548
  h('span', { className: 'ops-modal-title' }, `${monDialog.monitor.label || monDialog.monitor.target || monDialog.monitor.type}`),
2131
3549
  h('button', { className: 'ops-modal-x', onClick: () => setMonDialog(null) }, '✕')),
2132
3550
  h('div', {
2133
- 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',
2134
3552
  style: { fontSize: '15px', marginBottom: '10px' },
2135
- }, monDialog.result?.ok ? `✓ ${T.monOk}` : `✕ ${T.monBad}`),
3553
+ }, monDialog.result?.ok ? `✓ ${T.monOk}`
3554
+ : monDialog.result?.level === 'warn' ? `△ ${T.monWarn}`
3555
+ : monDialog.result?.level === 'unknown' ? `? ${T.monUnknown}`
3556
+ : `✕ ${T.monCrit}`),
2136
3557
  h('div', { className: 'ops-modal-row' }, h('b', null, '类型'), h('span', null,
2137
3558
  `${(T.monTypeShort || {})[monDialog.monitor.type] || monDialog.monitor.type}${monDialog.monitor.language ? ' · ' + monDialog.monitor.language : ''}`)),
2138
3559
  h('div', { className: 'ops-modal-row' }, h('b', null, '目标'), h('span', { className: 'ops-mono' }, monDialog.monitor.target || (monDialog.monitor.script ? '(脚本)' : '—'))),
@@ -2162,13 +3583,125 @@ window.__ModuleLoader__.load({
2162
3583
  h('div', { className: 'ops-chips', style: { marginTop: '14px', justifyContent: 'flex-end' } },
2163
3584
  h('button', { className: 'ops-btn ops-btn-sm', onClick: () => setMonDialog(null) }, T.monClose)))) : null
2164
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
+
2165
3694
  return h('div', { className: 'ops-page' },
2166
3695
  h('style', null, CSS),
2167
3696
  header,
2168
3697
  nav,
2169
3698
  error ? h('p', { className: 'ops-err' }, error) : null,
2170
3699
  body,
2171
- monitorDialogView)
3700
+ monitorDialogView,
3701
+ fsEditView,
3702
+ fsPreviewView,
3703
+ cleanPreviewView,
3704
+ busyOverlay)
2172
3705
  }
2173
3706
 
2174
3707
  /** Keeps a render error visible instead of leaving an empty page. */
@@ -2183,7 +3716,7 @@ window.__ModuleLoader__.load({
2183
3716
  render() {
2184
3717
  if (this.state.error) {
2185
3718
  return h('div', { style: { padding: '20px', color: 'var(--dsw-alias-danger,#ff6b6b)', fontSize: '13px', lineHeight: 1.7 } },
2186
- h('div', { style: { fontWeight: 600, marginBottom: '6px' } }, '运维面板渲染失败'),
3719
+ h('div', { style: { fontWeight: 600, marginBottom: '6px' } }, 'OPC-运维平台 渲染失败'),
2187
3720
  h('pre', { style: { whiteSpace: 'pre-wrap', fontFamily: 'ui-monospace,Menlo,monospace', fontSize: '12px' } },
2188
3721
  String(this.state.error?.stack || this.state.error?.message || this.state.error)))
2189
3722
  }