dsh-ops-kit 0.0.0-stage → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +168 -2
- package/README.zh-CN.md +154 -0
- package/client.js +2094 -0
- package/cordis.patch.yml +4 -0
- package/docs/DETAIL.md +71 -0
- package/docs/USAGE.zh-CN.md +192 -0
- package/icon.svg +9 -0
- package/index.js +3524 -0
- package/locale/en.json +7 -0
- package/locale/zh.json +7 -0
- package/package.json +63 -4
package/client.js
ADDED
|
@@ -0,0 +1,2094 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* dsh-ops-kit — client half (v3: cards, charts, config browser, app manager).
|
|
3
|
+
*
|
|
4
|
+
* One page, five tabs:
|
|
5
|
+
* 概览 Overview — one card per server, status dot and the three key numbers
|
|
6
|
+
* 监控 Monitor — CPU / memory / disk line charts from the local sample history
|
|
7
|
+
* 配置 Config — read-only inventory: ports, services, containers, nginx, java, cron, mounts
|
|
8
|
+
* 应用 Apps — containers and services with Logs / Restart, confirmation first
|
|
9
|
+
* 设置 Settings — scheduled checks, host inventory
|
|
10
|
+
*
|
|
11
|
+
* Everything is plain React from the browser module table; styles are one
|
|
12
|
+
* <style> element using DSH theme tokens only.
|
|
13
|
+
*/
|
|
14
|
+
window.__ModuleLoader__.load({
|
|
15
|
+
id: 'dsh-ops-kit',
|
|
16
|
+
factory(require) {
|
|
17
|
+
const React = require('react')
|
|
18
|
+
const h = React.createElement
|
|
19
|
+
const PANEL = 'ops-kit'
|
|
20
|
+
|
|
21
|
+
const LABEL = { zh: '运维', en: 'Ops' }
|
|
22
|
+
const zh = (typeof navigator !== 'undefined' && String(navigator.language || '').toLowerCase().startsWith('zh'))
|
|
23
|
+
const T = zh ? {
|
|
24
|
+
title: '运维', sub: '看状态、看图表、看配置、管应用 —— 不用敲命令。',
|
|
25
|
+
tabs: ['概览', '监控', '配置', '应用', '排查', '日志', '文件', '终端', '助手', '设置'],
|
|
26
|
+
refresh: '刷新', add: '添加服务器', save: '保存', cancel: '取消',
|
|
27
|
+
name: '名称', host: '地址', user: '用户', key: '私钥(可空)', password: '密码(可空)',
|
|
28
|
+
normal: '正常', warn: '注意', down: '连不上', unknown: '还没数据',
|
|
29
|
+
cleanup: '清理日志', cleaning: '清理中…', freed: '磁盘已从',
|
|
30
|
+
cpu: 'CPU', mem: '内存', disk: '磁盘', load: '负载',
|
|
31
|
+
check: '体检', remove: '移除', noHosts: '还没有服务器,先点「添加服务器」。',
|
|
32
|
+
hours: '范围', h1: '1 小时', h6: '6 小时', h24: '24 小时', d3: '3 天',
|
|
33
|
+
noData: '还没有采样数据,等下一次巡检(每 5 分钟一次)。',
|
|
34
|
+
ports: '端口', services: '服务', containers: '容器', nginx: '网站', java: 'Java 进程', cron: '定时任务', mounts: '磁盘挂载',
|
|
35
|
+
rescan: '重新扫描', rescanning: '扫描中…', empty: '暂无',
|
|
36
|
+
logs: '日志', restart: '重启', stop: '停止', close: '关闭', changed: '已保存',
|
|
37
|
+
patrol: '定时巡检', enabled: '启用', interval: '体检间隔(分)', metricsEvery: '采样间隔(分)', diskWarn: '磁盘告警(%)',
|
|
38
|
+
lastCheck: '最近检查', lastSample: '最近采样', loading: '加载中…',
|
|
39
|
+
summary: '台服务器', allOk: '全部正常', needLook: '需要看一眼', offline: '连不上',
|
|
40
|
+
alias: '显示名(好记的名字)', edit: '编辑', saveHost: '保存修改', configFile: '配置文件',
|
|
41
|
+
saveFile: '保存到服务器', saved2: '已保存,原文件已备份', close2: '关闭', raw: '原始信息',
|
|
42
|
+
purpose: '用途', noConfig: '这个应用没有可编辑的配置文件', editHint: '修改会先备份原文件,再写入。',
|
|
43
|
+
diskFull: '磁盘快满', suggestClean: '建议清理日志', reading: '读取中…', loadingFile: '正在读取配置文件…', savingFile: '正在保存…',
|
|
44
|
+
diskScan: '磁盘分析', path: '路径', scan: '分析', up: '上一级',
|
|
45
|
+
test: '测试连接', testing: '测试中…', installKey: '安装公钥', installing: '安装中…',
|
|
46
|
+
connected: '已连接', disconnected: '连不上', latency: '延迟', failures: '连续失败',
|
|
47
|
+
console: '命令控制台', runCmd: '执行', cmdPh: '输入命令,例如 df -h 或 systemctl status nginx',
|
|
48
|
+
terminal: '终端', openTerm: '打开终端', closeTerm: '断开', termHint: '步骤:① 点「打开终端」 ② 点一下黑框 ③ 敲命令,回车执行。支持 Tab 补全、Ctrl+C、方向键。', termNeedPwd: '这个主机没有保存密码,终端需要密码登录;请到设置里编辑主机并填入密码。',
|
|
49
|
+
connecting: '正在连接…', clickConnect: '点这里连接', quickCmds: '常用命令', tip: '连上后黑框里会出现服务器提示符,像用 FinalShell 一样敲命令。',
|
|
50
|
+
aiBar: '用一句话说你想做什么', aiPh: '例如:看看磁盘还剩多少 / 重启 nginx / 查最近 50 行错误日志',
|
|
51
|
+
aiMode: 'AI 模式', aiModeHint: '输入意图后回车:命令会填进终端但不会自动执行;Esc 取消',
|
|
52
|
+
assistant: '助手', askPh: '直接问,例如:mysql 运行了吗?磁盘还剩多少?谁在占 CPU?',
|
|
53
|
+
copy: '复制', copied: '已复制', you: '你', aiName: 'AI 运维助手',
|
|
54
|
+
send: '发送', thinking: '正在查…', askedCmds: '它执行过的命令', noCmds: '没有执行命令,直接回答',
|
|
55
|
+
needConfirm: '这一步会改动服务器,需要你确认后执行', runIt: '执行这条命令', answerOnly: '只回答,不改动',
|
|
56
|
+
aiFilled: '已填入命令,确认后按回车执行', quickEdit: '自定义常用命令(一行一条)', quickSave: '保存命令列表',
|
|
57
|
+
quickHint: '在终端里输入 ? 开头即可用 AI 生成命令',
|
|
58
|
+
aiSettings: 'AI 模型', aiOn: '启用 AI(助手 / 诊断 / 生成命令)',
|
|
59
|
+
channels: '告警外发', channelAdd: '添加通道', channelTest: '发送测试', channelRemove: '删除',
|
|
60
|
+
channelEmpty: '还没有配置通知通道。配上之后,监控失败、证书到期、磁盘告急会主动发给你。',
|
|
61
|
+
channelName: '名称', channelUrl: 'Webhook 地址', channelEvents: '推送级别',
|
|
62
|
+
channelHint: '飞书/钉钉/企业微信:群机器人 Webhook;自定义:任意接收 JSON 的地址。地址保存在本机 channels.json(0600)。',
|
|
63
|
+
channelLevels: ['严重', '警告', '提示'], channelSent: '已发送,请查看群消息', aiFollow: '跟随 DSH 默认模型',
|
|
64
|
+
aiPrivacy: '选择本机 Ollama 模型时,服务器信息不会离开这台电脑;选云端模型会把服务器摘要发给对应服务商。',
|
|
65
|
+
aiCurrent: '当前使用', aiSave: '保存 AI 设置',
|
|
66
|
+
health: '健康分', healthNow: '重新体检', scoreGood: '状态良好', scoreWarn: '需要留意', scoreBad: '有风险',
|
|
67
|
+
noIssues: '没有发现问题', fixFirst: '先做这件事', todos: '待办',
|
|
68
|
+
certs: '证书', certDays: '天后过期', certRenew: '续期(预演)', certRenewReal: '正式续期', certNone: '没有发现证书',
|
|
69
|
+
backups: '备份', backupNow: '立即备份', backupType: '备份内容', backupDb: '数据库', backupDirKind: '目录',
|
|
70
|
+
backupKeep: '保留份数', backupList: '已有备份', backupRestore: '恢复', backupRemove: '删除',
|
|
71
|
+
backupEmpty: '还没有备份。建议先备份数据库或网站目录。', backupSize: '大小', backupAt: '时间',
|
|
72
|
+
restoreWarn: '恢复会覆盖当前数据,确认继续?',
|
|
73
|
+
cron: '计划任务', cronAdd: '添加任务', cronEmpty: '服务器上还没有定时任务', cronRemove: '删除',
|
|
74
|
+
cronEvery: '频率', cronDaily: '每天', cronHourly: '每小时', cronWeekly: '每周', cronAt: '时间', cronCmd: '要执行的命令',
|
|
75
|
+
deploy: '一键发布', deployNew: '新建发布', deployRun: '发布', deployRemove: '删除', deployEmpty: '还没有发布任务',
|
|
76
|
+
deployDir: '项目目录', deployRepo: 'Git 仓库(可空)', deployBranch: '分支', deployBuild: '构建命令',
|
|
77
|
+
deployRestart: '重启命令', deployHealth: '健康检查地址', deploySave: '保存', deployRolledBack: '已回滚',
|
|
78
|
+
fileHistory: '历史版本', fileDiff: '差异', fileRestore: '回滚到此版本', fileNoHistory: '这个文件还没有历史版本',
|
|
79
|
+
pathPh: '文件路径,例如 /etc/nginx/nginx.conf',
|
|
80
|
+
monitors: '服务监控', addMonitor: '添加监控', monType: '类型', monTarget: '目标', monLabel: '名称(可空)',
|
|
81
|
+
monInterval: '间隔(分钟)', monAdd: '添加并检查', monCheck: '检查', monRemove: '删除', monEmpty: '还没有监控项,可以加一个心跳检查',
|
|
82
|
+
monHttpHint: 'http:填 URL,如 https://example.com;port:填 host:port;process:填进程关键字;service:填 systemd 单元名',
|
|
83
|
+
monLast: '最近', monNever: '未检查', monEdit: '编辑', monSave: '保存修改', monCancel: '取消',
|
|
84
|
+
monPreset: '一键模板', monScript: '脚本(退出码 0 = 正常)', monLanguage: '语言',
|
|
85
|
+
monScriptHint: '脚本在服务器上用对应解释器执行,退出码 0 视为正常;python 需要 python3,js 需要 node。',
|
|
86
|
+
monTypes: [['http', '网站能不能打开'], ['port', '端口通不通'], ['process', '程序还在不在'], ['service', '系统服务在不在'], ['script', '自己写检查脚本']],
|
|
87
|
+
monTypeHint: {
|
|
88
|
+
http: '填网址,例如 https://example.com 或 http://127.0.0.1:8080/health',
|
|
89
|
+
port: '填 地址:端口,例如 127.0.0.1:3306(数据库)、127.0.0.1:6379(缓存)',
|
|
90
|
+
process: '填进程关键字,例如 mysqld 或 java',
|
|
91
|
+
service: '填系统服务名,例如 nginx.service、mysqld.service',
|
|
92
|
+
script: '用 shell / python / js 写一段检查,退出码 0 表示正常',
|
|
93
|
+
},
|
|
94
|
+
monPresets: [['网站首页', { type: 'http', target: 'https://', label: '网站首页' }], ['MySQL 端口', { type: 'port', target: '127.0.0.1:3306', label: 'MySQL' }], ['Redis 端口', { type: 'port', target: '127.0.0.1:6379', label: 'Redis' }], ['SSH 端口', { type: 'port', target: '127.0.0.1:22', label: 'SSH' }], ['nginx 服务', { type: 'service', target: 'nginx.service', label: 'nginx' }]],
|
|
95
|
+
gen: '生成命令', regenerating: '生成中…', exec: '执行到终端', discard: '不要', risk: '这条命令会改动系统,确认再执行',
|
|
96
|
+
aiNeedTerm: '先连上终端,生成的命令才会发到服务器', aiModel: '模型',
|
|
97
|
+
process: '进程', byCpu: '按 CPU', byMem: '按内存', pid: 'PID', cpuUse: 'CPU', memUse: '内存', cmd: '命令',
|
|
98
|
+
end: '结束', ending: '结束中…', confirmKill: '结束这个进程?',
|
|
99
|
+
logs: '日志', logSource: '来源(nginx.service 或 file:/var/log/x.log)', lines: '行数', load: '读取', auto: '自动刷新(5s)',
|
|
100
|
+
ssl: '证书', domain: '域名', checkSsl: '检查证书', daysLeft: '剩余天数', expireAt: '到期', noExpire: '没读到证书',
|
|
101
|
+
files: '文件', upload: '上传', newFolder: '新建文件夹', size: '大小', modified: '修改时间', open: '进入', download: '下载', del: '删除', folderName: '文件夹名', confirmDel: '删除这个路径?',
|
|
102
|
+
ask: '问一下', diagnose: '智能诊断', diagnosing: '诊断中…', askPh: '例如:网站为什么打不开?',
|
|
103
|
+
askPreset: ['网站为什么打不开?', '磁盘为什么满了?', '最近是不是有点慢?'], findings: '看到的情况', next: '建议动作', timeoutSec: '默认超时(秒)', scanSec: '扫描超时(秒)', actionSec: '操作超时(秒)'
|
|
104
|
+
} : {
|
|
105
|
+
title: 'Ops', sub: 'Status, charts, configuration and apps — no commands.',
|
|
106
|
+
tabs: ['Overview', 'Monitor', 'Config', 'Apps', 'Triage', 'Logs', 'Files', 'Terminal', 'Assistant', 'Settings'],
|
|
107
|
+
refresh: 'Refresh', add: 'Add server', save: 'Save', cancel: 'Cancel',
|
|
108
|
+
name: 'Name', host: 'Address', user: 'User', key: 'Key (optional)', password: 'Password (optional)',
|
|
109
|
+
normal: 'Healthy', warn: 'Attention', down: 'Unreachable', unknown: 'No data',
|
|
110
|
+
cleanup: 'Clean logs', cleaning: 'Cleaning…', freed: 'Disk',
|
|
111
|
+
cpu: 'CPU', mem: 'Memory', disk: 'Disk', load: 'Load',
|
|
112
|
+
check: 'Check', remove: 'Remove', noHosts: 'No servers yet. Use "Add server".',
|
|
113
|
+
hours: 'Range', h1: '1 h', h6: '6 h', h24: '24 h', d3: '3 d',
|
|
114
|
+
noData: 'No samples yet; the scheduler samples every 5 minutes.',
|
|
115
|
+
ports: 'Ports', services: 'Services', containers: 'Containers', nginx: 'Sites', java: 'Java', cron: 'Cron', mounts: 'Mounts',
|
|
116
|
+
rescan: 'Rescan', rescanning: 'Scanning…', empty: 'none',
|
|
117
|
+
logs: 'Logs', restart: 'Restart', stop: 'Stop', close: 'Close', changed: 'Saved',
|
|
118
|
+
patrol: 'Scheduled checks', enabled: 'Enabled', interval: 'Check every (min)', metricsEvery: 'Sample every (min)', diskWarn: 'Disk warn (%)',
|
|
119
|
+
lastCheck: 'Last check', lastSample: 'Last sample', loading: 'Loading…',
|
|
120
|
+
summary: 'servers', allOk: 'all healthy', needLook: 'needs attention', offline: 'unreachable',
|
|
121
|
+
alias: 'Display name (easy to remember)', edit: 'Edit', saveHost: 'Save changes', configFile: 'Config file',
|
|
122
|
+
saveFile: 'Save to server', saved2: 'Saved; the original was backed up', close2: 'Close', raw: 'Raw',
|
|
123
|
+
purpose: 'Purpose', noConfig: 'No editable config file for this app', editHint: 'Saving backs up the original first.',
|
|
124
|
+
diskFull: 'Disk almost full', suggestClean: 'Clean logs', reading: 'Reading…', loadingFile: 'Reading the config file…', savingFile: 'Saving…',
|
|
125
|
+
diskScan: 'Disk usage', path: 'Path', scan: 'Scan', up: 'Up',
|
|
126
|
+
test: 'Test', testing: 'Testing…', installKey: 'Install key', installing: 'Installing…',
|
|
127
|
+
connected: 'Connected', disconnected: 'Unreachable', latency: 'latency', failures: 'failures',
|
|
128
|
+
console: 'Command console', runCmd: 'Run', cmdPh: 'Type a command, e.g. df -h',
|
|
129
|
+
terminal: 'Terminal', openTerm: 'Open terminal', closeTerm: 'Disconnect', termHint: 'Steps: 1) Open terminal 2) click the dark box 3) type a command and press Enter. Tab, Ctrl+C and arrows work.', termNeedPwd: 'This host has no stored password; the terminal needs password auth. Edit the host and add one.',
|
|
130
|
+
connecting: 'Connecting…', clickConnect: 'Click to connect', quickCmds: 'Quick commands', tip: 'Once connected the prompt appears; type commands like in a normal SSH client.',
|
|
131
|
+
aiBar: 'Describe what you want to do', aiPh: 'e.g. how much disk is left / restart nginx / last 50 error lines',
|
|
132
|
+
aiMode: 'AI mode', aiModeHint: 'Type the intent and press Enter: the command is filled but not run; Esc cancels',
|
|
133
|
+
assistant: 'Assistant', askPh: 'Just ask, e.g. is mysql running? how much disk is left?',
|
|
134
|
+
copy: 'Copy', copied: 'Copied', you: 'You', aiName: 'Ops assistant',
|
|
135
|
+
send: 'Send', thinking: 'Looking…', askedCmds: 'Commands it ran', noCmds: 'Answered without running commands',
|
|
136
|
+
needConfirm: 'This step changes the server; confirm to run it', runIt: 'Run this command', answerOnly: 'Answer only',
|
|
137
|
+
aiFilled: 'Command filled in; press Enter to run', quickEdit: 'Custom quick commands (one per line)', quickSave: 'Save quick commands',
|
|
138
|
+
quickHint: 'Type ? in the terminal to generate a command with AI',
|
|
139
|
+
aiSettings: 'AI model', aiOn: 'Enable AI (assistant / diagnosis / command generation)',
|
|
140
|
+
channels: 'Alert delivery', channelAdd: 'Add channel', channelTest: 'Send test', channelRemove: 'Remove',
|
|
141
|
+
channelEmpty: 'No delivery channels yet. Once configured, monitor failures, expiring certificates and disk pressure reach you.',
|
|
142
|
+
channelName: 'Name', channelUrl: 'Webhook URL', channelEvents: 'Levels',
|
|
143
|
+
channelHint: 'Feishu / DingTalk / WeCom group bots, or any endpoint that accepts JSON. Stored locally in channels.json (0600).',
|
|
144
|
+
channelLevels: ['critical', 'warning', 'info'], channelSent: 'Sent — check the chat', aiFollow: 'Follow the DSH default model',
|
|
145
|
+
aiPrivacy: 'A local Ollama model keeps server data on this machine; a cloud model sends a server summary to that provider.',
|
|
146
|
+
aiCurrent: 'Currently using', aiSave: 'Save AI settings',
|
|
147
|
+
health: 'Health', healthNow: 'Re-check', scoreGood: 'Healthy', scoreWarn: 'Needs attention', scoreBad: 'At risk',
|
|
148
|
+
noIssues: 'No issues found', fixFirst: 'Do this first', todos: 'To do',
|
|
149
|
+
certs: 'Certificates', certDays: 'days left', certRenew: 'Renew (dry run)', certRenewReal: 'Renew now', certNone: 'No certificates found',
|
|
150
|
+
backups: 'Backups', backupNow: 'Back up now', backupType: 'What', backupDb: 'Database', backupDirKind: 'Directory',
|
|
151
|
+
backupKeep: 'Keep', backupList: 'Backups', backupRestore: 'Restore', backupRemove: 'Delete',
|
|
152
|
+
backupEmpty: 'No backups yet. Start with the database or the site directory.', backupSize: 'size', backupAt: 'time',
|
|
153
|
+
restoreWarn: 'Restoring overwrites current data. Continue?',
|
|
154
|
+
cron: 'Scheduled tasks', cronAdd: 'Add task', cronEmpty: 'No crontab entries yet', cronRemove: 'Delete',
|
|
155
|
+
cronEvery: 'Frequency', cronDaily: 'Daily', cronHourly: 'Hourly', cronWeekly: 'Weekly', cronAt: 'Time', cronCmd: 'Command',
|
|
156
|
+
deploy: 'Deploy', deployNew: 'New job', deployRun: 'Deploy', deployRemove: 'Delete', deployEmpty: 'No deploy jobs yet',
|
|
157
|
+
deployDir: 'Project dir', deployRepo: 'Git remote (optional)', deployBranch: 'Branch', deployBuild: 'Build command',
|
|
158
|
+
deployRestart: 'Restart command', deployHealth: 'Health URL', deploySave: 'Save', deployRolledBack: 'rolled back',
|
|
159
|
+
fileHistory: 'History', fileDiff: 'Diff', fileRestore: 'Restore this version', fileNoHistory: 'No history for this file yet',
|
|
160
|
+
pathPh: 'File path, e.g. /etc/nginx/nginx.conf',
|
|
161
|
+
monitors: 'Service monitors', addMonitor: 'Add monitor', monType: 'Type', monTarget: 'Target', monLabel: 'Label (optional)',
|
|
162
|
+
monInterval: 'Interval (min)', monAdd: 'Add and check', monCheck: 'Check', monRemove: 'Remove', monEmpty: 'No monitors yet — add a heartbeat check',
|
|
163
|
+
monHttpHint: 'http: URL like https://example.com; port: host:port; process: pattern; service: systemd unit',
|
|
164
|
+
monLast: 'last', monNever: 'never', monEdit: 'Edit', monSave: 'Save', monCancel: 'Cancel',
|
|
165
|
+
monPreset: 'Presets', monScript: 'Script (exit 0 = healthy)', monLanguage: 'Language',
|
|
166
|
+
monScriptHint: 'Runs on the host with the chosen interpreter; exit code 0 means healthy. python needs python3, js needs node.',
|
|
167
|
+
monTypes: [['http', 'Website reachable'], ['port', 'Port open'], ['process', 'Process alive'], ['service', 'System service active'], ['script', 'Custom script']],
|
|
168
|
+
monTypeHint: {
|
|
169
|
+
http: 'URL, e.g. https://example.com',
|
|
170
|
+
port: 'host:port, e.g. 127.0.0.1:3306',
|
|
171
|
+
process: 'process keyword, e.g. mysqld',
|
|
172
|
+
service: 'unit name, e.g. nginx.service',
|
|
173
|
+
script: 'shell / python / js; exit 0 means healthy',
|
|
174
|
+
},
|
|
175
|
+
monPresets: [['Homepage', { type: 'http', target: 'https://', label: 'Homepage' }], ['MySQL port', { type: 'port', target: '127.0.0.1:3306', label: 'MySQL' }], ['Redis port', { type: 'port', target: '127.0.0.1:6379', label: 'Redis' }], ['SSH port', { type: 'port', target: '127.0.0.1:22', label: 'SSH' }], ['nginx unit', { type: 'service', target: 'nginx.service', label: 'nginx' }]],
|
|
176
|
+
gen: 'Generate command', regenerating: 'Generating…', exec: 'Run in terminal', discard: 'Discard', risk: 'This command changes the system; confirm before running',
|
|
177
|
+
aiNeedTerm: 'Connect the terminal first so the command can be sent', aiModel: 'model',
|
|
178
|
+
process: 'Processes', byCpu: 'By CPU', byMem: 'By memory', pid: 'PID', cpuUse: 'CPU', memUse: 'MEM', cmd: 'Command',
|
|
179
|
+
end: 'End', ending: 'Ending…', confirmKill: 'Kill this process?',
|
|
180
|
+
logs: 'Logs', logSource: 'Source (nginx.service or file:/var/log/x.log)', lines: 'Lines', load: 'Load', auto: 'Auto refresh (5s)',
|
|
181
|
+
ssl: 'Certificate', domain: 'Domain', checkSsl: 'Check certificate', daysLeft: 'days left', expireAt: 'expires', noExpire: 'no certificate read',
|
|
182
|
+
files: 'Files', upload: 'Upload', newFolder: 'New folder', size: 'Size', modified: 'Modified', open: 'Open', download: 'Download', del: 'Delete', folderName: 'Folder name', confirmDel: 'Delete this path?',
|
|
183
|
+
ask: 'Ask', diagnose: 'Diagnose', diagnosing: 'Diagnosing…', askPh: 'e.g. why is the site down?',
|
|
184
|
+
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)'
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
const CSS = `
|
|
188
|
+
.ops-page{height:100%;overflow:auto;padding:18px 22px 40px;display:flex;flex-direction:column;gap:14px;color:var(--dsw-alias-text-primary,#e6e6e6)}
|
|
189
|
+
.ops-top{display:flex;align-items:center;justify-content:space-between;gap:12px;flex-wrap:wrap}
|
|
190
|
+
.ops-title{margin:0;font-size:18px;font-weight:600}
|
|
191
|
+
.ops-sub{margin:3px 0 0;font-size:12px;color:var(--dsw-alias-text-secondary,#9aa0a6)}
|
|
192
|
+
.ops-tabs{display:flex;gap:6px;flex-wrap:wrap}
|
|
193
|
+
.ops-tab{appearance:none;border:1px solid transparent;background:transparent;color:var(--dsw-alias-text-secondary,#9aa0a6);border-radius:8px;padding:6px 12px;font-size:13px;cursor:pointer}
|
|
194
|
+
.ops-tab.on{background:var(--dsw-alias-surface,#22262b);border-color:var(--dsw-alias-border,#3a3f45);color:var(--dsw-alias-text-primary,#e6e6e6);font-weight:600}
|
|
195
|
+
.ops-btn{appearance:none;border:1px solid var(--dsw-alias-border,#3a3f45);background:var(--dsw-alias-surface,#22262b);color:inherit;border-radius:8px;padding:6px 12px;font-size:13px;cursor:pointer;white-space:nowrap}
|
|
196
|
+
.ops-btn:hover{border-color:var(--dsw-alias-text-secondary,#9aa0a6)}
|
|
197
|
+
.ops-btn[disabled]{opacity:.55;cursor:default}
|
|
198
|
+
.ops-btn-primary{background:var(--dsw-alias-accent,#4c8dff);border-color:var(--dsw-alias-accent,#4c8dff);color:#fff}
|
|
199
|
+
.ops-btn-sm{padding:3px 9px;font-size:12px}
|
|
200
|
+
.ops-cards{display:grid;grid-template-columns:repeat(auto-fill,minmax(300px,1fr));gap:12px}
|
|
201
|
+
.ops-card{border:1px solid var(--dsw-alias-border,#3a3f45);border-radius:12px;background:var(--dsw-alias-surface,#1d2126);overflow:hidden}
|
|
202
|
+
.ops-card-h{display:flex;align-items:center;justify-content:space-between;gap:10px;padding:10px 14px;border-bottom:1px solid var(--dsw-alias-border,#3a3f45);font-size:13px;font-weight:600}
|
|
203
|
+
.ops-card-b{padding:12px 14px;display:flex;flex-direction:column;gap:10px}
|
|
204
|
+
.ops-dot{width:9px;height:9px;border-radius:50%;display:inline-block;margin-right:6px;background:var(--dsw-alias-text-secondary,#9aa0a6)}
|
|
205
|
+
.ops-dot.ok{background:var(--dsw-alias-success,#4ac97e)}
|
|
206
|
+
.ops-dot.warn{background:var(--dsw-alias-warning,#e5b650)}
|
|
207
|
+
.ops-dot.bad{background:var(--dsw-alias-danger,#ff6b6b)}
|
|
208
|
+
.ops-nums{display:grid;grid-template-columns:repeat(3,1fr);gap:8px}
|
|
209
|
+
.ops-num{background:var(--dsw-alias-bg,#15181c);border:1px solid var(--dsw-alias-border,#3a3f45);border-radius:8px;padding:8px 10px}
|
|
210
|
+
.ops-num b{display:block;font-size:16px;font-weight:600}
|
|
211
|
+
.ops-num span{font-size:11px;color:var(--dsw-alias-text-secondary,#9aa0a6)}
|
|
212
|
+
.ops-bar{height:4px;border-radius:2px;background:var(--dsw-alias-border,#3a3f45);overflow:hidden;margin-top:6px}
|
|
213
|
+
.ops-bar i{display:block;height:100%;background:var(--dsw-alias-accent,#4c8dff)}
|
|
214
|
+
.ops-bar i.warn{background:var(--dsw-alias-warning,#e5b650)}
|
|
215
|
+
.ops-bar i.bad{background:var(--dsw-alias-danger,#ff6b6b)}
|
|
216
|
+
.ops-row{display:grid;grid-template-columns:1.1fr 1.4fr .8fr auto;gap:10px;align-items:center;padding:8px 14px;border-top:1px solid var(--dsw-alias-border,#3a3f45);min-width:0}
|
|
217
|
+
.ops-row:first-child{border-top:0}
|
|
218
|
+
.ops-row-h{font-size:11px;text-transform:uppercase;letter-spacing:.04em;color:var(--dsw-alias-text-secondary,#9aa0a6)}
|
|
219
|
+
.ops-name{font-size:13px;font-weight:600;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
|
|
220
|
+
.ops-mono{font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:12px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
221
|
+
.ops-dim{font-size:12px;color:var(--dsw-alias-text-secondary,#9aa0a6);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
222
|
+
.ops-ok{color:var(--dsw-alias-success,#4ac97e)}
|
|
223
|
+
.ops-bad{color:var(--dsw-alias-danger,#ff6b6b)}
|
|
224
|
+
.ops-warn{color:var(--dsw-alias-warning,#e5b650)}
|
|
225
|
+
.ops-pre{margin:0;padding:12px 14px;white-space:pre-wrap;word-break:break-word;font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:12px;line-height:1.55;background:var(--dsw-alias-bg,#15181c);border:1px solid var(--dsw-alias-border,#3a3f45);border-radius:8px;max-height:40vh;overflow:auto}
|
|
226
|
+
.ops-input{appearance:none;width:100%;box-sizing:border-box;border:1px solid var(--dsw-alias-border,#3a3f45);background:var(--dsw-alias-bg,#15181c);color:inherit;border-radius:8px;padding:7px 10px;font-size:13px}
|
|
227
|
+
.ops-form{display:grid;grid-template-columns:1fr 1fr;gap:10px;padding:14px}
|
|
228
|
+
.ops-wide{grid-column:1/-1}
|
|
229
|
+
.ops-err{color:var(--dsw-alias-danger,#ff6b6b);font-size:12px;margin:0}
|
|
230
|
+
.ops-chips{display:flex;gap:8px;flex-wrap:wrap;align-items:center}
|
|
231
|
+
.ops-chip{font-size:11px;padding:1px 8px;border-radius:999px;border:1px solid var(--dsw-alias-border,#3a3f45);color:var(--dsw-alias-text-secondary,#9aa0a6)}
|
|
232
|
+
.ops-chart{width:100%;height:120px;display:block}
|
|
233
|
+
.ops-chart-wrap{border:1px solid var(--dsw-alias-border,#3a3f45);border-radius:10px;background:var(--dsw-alias-bg,#15181c);padding:10px 12px}
|
|
234
|
+
.ops-chart-h{display:flex;justify-content:space-between;font-size:12px;color:var(--dsw-alias-text-secondary,#9aa0a6);margin-bottom:4px}
|
|
235
|
+
.ops-empty{padding:14px;margin:0;font-size:12px;color:var(--dsw-alias-text-secondary,#9aa0a6)}
|
|
236
|
+
.ops-grid2{display:grid;grid-template-columns:minmax(0,1fr) minmax(0,1fr);gap:12px}
|
|
237
|
+
@media(max-width:1000px){.ops-grid2{grid-template-columns:1fr}}
|
|
238
|
+
.ops-list{max-height:320px;overflow:auto}
|
|
239
|
+
.ops-chat{display:flex;flex-direction:column;gap:10px;height:56vh;overflow:auto;padding:14px;border:1px solid var(--dsw-alias-border,#3a3f45);border-radius:10px;background:var(--dsw-alias-bg,#15181c)}
|
|
240
|
+
.ops-msg{display:flex;flex-direction:column;gap:4px;max-width:82%}
|
|
241
|
+
.ops-msg.user{align-self:flex-end;align-items:flex-end}
|
|
242
|
+
.ops-msg.ai{align-self:flex-start;align-items:flex-start}
|
|
243
|
+
.ops-bubble{padding:9px 12px;border-radius:10px;font-size:13px;line-height:1.7;white-space:pre-wrap;word-break:break-word}
|
|
244
|
+
.ops-msg.user .ops-bubble{background:var(--dsw-alias-accent,#4c8dff);color:#fff}
|
|
245
|
+
.ops-msg.ai .ops-bubble{background:var(--dsw-alias-surface,#1d2126);border:1px solid var(--dsw-alias-border,#3a3f45)}
|
|
246
|
+
.ops-meta{display:flex;gap:8px;align-items:center;font-size:11px;color:var(--dsw-alias-text-secondary,#9aa0a6)}
|
|
247
|
+
.ops-copy{border:0;background:transparent;color:var(--dsw-alias-text-secondary,#9aa0a6);font-size:11px;cursor:pointer;padding:0}
|
|
248
|
+
.ops-copy:hover{color:var(--dsw-alias-text-primary,#e6e6e6)}
|
|
249
|
+
.ops-composer{display:flex;gap:8px;align-items:flex-end;padding:10px 14px;border-top:1px solid var(--dsw-alias-border,#3a3f45)}
|
|
250
|
+
`
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* One API call with a hard client-side timeout, so a slow remote command
|
|
254
|
+
* shows "timed out" instead of leaving the button spinning forever.
|
|
255
|
+
*/
|
|
256
|
+
async function api(path, init = {}, timeoutMs = 25_000) {
|
|
257
|
+
const controller = new AbortController()
|
|
258
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs)
|
|
259
|
+
try {
|
|
260
|
+
const response = await fetch(`/ops-kit/api/${path}`, {
|
|
261
|
+
credentials: 'same-origin',
|
|
262
|
+
headers: { 'content-type': 'application/json' },
|
|
263
|
+
...init,
|
|
264
|
+
signal: controller.signal,
|
|
265
|
+
})
|
|
266
|
+
const text = await response.text()
|
|
267
|
+
let body
|
|
268
|
+
try { body = JSON.parse(text) } catch { body = { error: text.slice(0, 300) } }
|
|
269
|
+
if (!response.ok) throw new Error(body?.error || `HTTP ${response.status}`)
|
|
270
|
+
return body
|
|
271
|
+
} catch (e) {
|
|
272
|
+
if (e && e.name === 'AbortError') throw new Error(`请求超时(${Math.round(timeoutMs / 1000)}s):服务器响应太慢,稍后重试`)
|
|
273
|
+
throw e
|
|
274
|
+
} finally {
|
|
275
|
+
clearTimeout(timer)
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
const fmt = (iso) => { try { return new Date(iso).toLocaleString() } catch { return iso || '' } }
|
|
280
|
+
const pct = (v) => (v === null || v === undefined ? '—' : `${v}%`)
|
|
281
|
+
const level = (v) => (v === null || v === undefined ? 'unknown' : v >= 90 ? 'bad' : v >= 75 ? 'warn' : 'ok')
|
|
282
|
+
|
|
283
|
+
function Icon() {
|
|
284
|
+
return h('svg', { viewBox: '0 0 24 24', width: 18, height: 18, 'aria-hidden': true, style: { display: 'block' } },
|
|
285
|
+
h('rect', { x: 3, y: 4, width: 18, height: 6, rx: 1.5, fill: 'none', stroke: 'currentColor', strokeWidth: 1.6 }),
|
|
286
|
+
h('rect', { x: 3, y: 14, width: 18, height: 6, rx: 1.5, fill: 'none', stroke: 'currentColor', strokeWidth: 1.6 }),
|
|
287
|
+
h('circle', { cx: 6.5, cy: 7, r: 0.9, fill: 'currentColor' }),
|
|
288
|
+
h('circle', { cx: 6.5, cy: 17, r: 0.9, fill: 'currentColor' }))
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
const PORT_PURPOSE = {
|
|
292
|
+
22: '远程管理', 80: '网站', 443: '网站(加密)', 3306: '数据库 MySQL', 33060: '数据库 MySQL',
|
|
293
|
+
6379: '缓存 Redis', 8888: '宝塔面板', 8080: 'Java 服务', 25: '邮件', 111: '系统服务',
|
|
294
|
+
27017: '数据库 MongoDB', 5432: '数据库 PostgreSQL', 9200: '搜索 Elasticsearch',
|
|
295
|
+
}
|
|
296
|
+
const SERVICE_NAME = {
|
|
297
|
+
'nginx.service': '网站服务(Nginx)',
|
|
298
|
+
'mysqld.service': '数据库(MySQL)',
|
|
299
|
+
'redis.service': '缓存(Redis)',
|
|
300
|
+
'sshd.service': '远程登录',
|
|
301
|
+
'crond.service': '定时任务',
|
|
302
|
+
'firewalld.service': '防火墙',
|
|
303
|
+
'docker.service': '容器引擎',
|
|
304
|
+
'scorepocket.service': '业务应用',
|
|
305
|
+
'site_total.service': '业务应用',
|
|
306
|
+
}
|
|
307
|
+
const purposeOf = (row) => PORT_PURPOSE[row.port] || (row.process ? row.process : '未知')
|
|
308
|
+
const serviceLabel = (name) => SERVICE_NAME[name] || String(name).replace(/\.service$/, '')
|
|
309
|
+
|
|
310
|
+
/** Strip ANSI escapes so a PTY stream reads as plain text in a <pre>. */
|
|
311
|
+
function stripAnsi(text) {
|
|
312
|
+
return String(text ?? '')
|
|
313
|
+
.replace(/\x1b\][^\x07]*\x07/g, '')
|
|
314
|
+
.replace(/\x1b\[[0-9;?]*[A-Za-z]/g, '')
|
|
315
|
+
.replace(/\x1b[()][A-Za-z0-9]/g, '')
|
|
316
|
+
.replace(/\r(?!\n)/g, '')
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
function Chart({ rows, series, title, unit = '%', max = 100 }) {
|
|
320
|
+
const W = 520, H = 110, P = 6
|
|
321
|
+
const drawn = (series || []).map(item => ({
|
|
322
|
+
...item,
|
|
323
|
+
points: rows.map(row => row[item.field]).filter(v => typeof v === 'number'),
|
|
324
|
+
})).filter(item => item.points.length > 0)
|
|
325
|
+
|
|
326
|
+
if (drawn.length === 0) {
|
|
327
|
+
return h('div', { className: 'ops-chart-wrap' },
|
|
328
|
+
h('div', { className: 'ops-chart-h' }, h('span', null, title), h('span', null, '—')),
|
|
329
|
+
h('p', { className: 'ops-empty' }, T.noData))
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
const peak = Math.max(max || 0, ...drawn.flatMap(item => item.points))
|
|
333
|
+
const top = peak > 0 ? peak : 1
|
|
334
|
+
const poly = (points) => {
|
|
335
|
+
const step = points.length > 1 ? (W - P * 2) / (points.length - 1) : 0
|
|
336
|
+
return points.map((value, index) => {
|
|
337
|
+
const x = P + index * step
|
|
338
|
+
const y = P + (H - P * 2) * (1 - Math.min(1, value / top))
|
|
339
|
+
return `${x.toFixed(1)},${y.toFixed(1)}`
|
|
340
|
+
}).join(' ')
|
|
341
|
+
}
|
|
342
|
+
const legend = drawn.map(item => {
|
|
343
|
+
const last = item.points[item.points.length - 1]
|
|
344
|
+
return `${item.label || item.field} ${last.toFixed(1)}${unit}`
|
|
345
|
+
}).join(' · ')
|
|
346
|
+
|
|
347
|
+
return h('div', { className: 'ops-chart-wrap' },
|
|
348
|
+
h('div', { className: 'ops-chart-h' }, h('span', null, title), h('span', null, legend)),
|
|
349
|
+
h('svg', { className: 'ops-chart', viewBox: `0 0 ${W} ${H}`, preserveAspectRatio: 'none' },
|
|
350
|
+
h('line', { x1: P, y1: H - P, x2: W - P, y2: H - P, stroke: 'var(--dsw-alias-border,#3a3f45)', strokeWidth: 1 }),
|
|
351
|
+
h('line', { x1: P, y1: P, x2: W - P, y2: P, stroke: 'var(--dsw-alias-border,#3a3f45)', strokeWidth: 1, strokeDasharray: '3 4' }),
|
|
352
|
+
...drawn.map(item => h('polyline', { key: item.field, points: poly(item.points), fill: 'none', stroke: item.color, strokeWidth: 2, strokeLinejoin: 'round', strokeLinecap: 'round' }))))
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
/** Byte-rate per second between consecutive samples, in KB/s. */
|
|
356
|
+
function rates(rows, field) {
|
|
357
|
+
return rows.map((row, index) => {
|
|
358
|
+
if (index === 0) return null
|
|
359
|
+
const prev = rows[index - 1]
|
|
360
|
+
if (typeof row[field] !== 'number' || typeof prev[field] !== 'number') return null
|
|
361
|
+
const dt = (row.ts - prev.ts) / 1000
|
|
362
|
+
if (!(dt > 0)) return null
|
|
363
|
+
return Math.max(0, Math.round(((row[field] - prev[field]) / dt / 1024) * 10) / 10)
|
|
364
|
+
}).map((value, index) => ({ ts: rows[index].ts, value })).map(item => item.value)
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
function Spark({ rows, field }) {
|
|
368
|
+
const pts = rows.map(r => r[field]).filter(v => typeof v === 'number')
|
|
369
|
+
if (pts.length < 2) return h('span', { className: 'ops-dim' }, '—')
|
|
370
|
+
const W = 120, H = 26, P = 2
|
|
371
|
+
const step = (W - P * 2) / (pts.length - 1)
|
|
372
|
+
const d = pts.map((v, i) => `${(P + i * step).toFixed(1)},${(H - P - (H - P * 2) * (v / 100)).toFixed(1)}`).join(' ')
|
|
373
|
+
const last = pts[pts.length - 1]
|
|
374
|
+
const color = last >= 90 ? 'var(--dsw-alias-danger,#ff6b6b)' : last >= 75 ? 'var(--dsw-alias-warning,#e5b650)' : 'var(--dsw-alias-accent,#4c8dff)'
|
|
375
|
+
return h('svg', { viewBox: `0 0 ${W} ${H}`, width: W, height: H, 'aria-hidden': true },
|
|
376
|
+
h('polyline', { points: d, fill: 'none', stroke: color, strokeWidth: 1.6 }))
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
function Panel() {
|
|
380
|
+
const [tab, setTab] = React.useState(0)
|
|
381
|
+
const [detailHost, setDetailHost] = React.useState(null)
|
|
382
|
+
const [detailTab, setDetailTab] = React.useState('summary')
|
|
383
|
+
const [hosts, setHosts] = React.useState([])
|
|
384
|
+
const [config, setConfig] = React.useState({ enabled: true, intervalMinutes: 10, diskWarnPercent: 90, metricsMinutes: 5 })
|
|
385
|
+
const [overview, setOverview] = React.useState({})
|
|
386
|
+
const [mHost, setMHost] = React.useState('')
|
|
387
|
+
const [mHours, setMHours] = React.useState(6)
|
|
388
|
+
const [samples, setSamples] = React.useState([])
|
|
389
|
+
const [cHost, setCHost] = React.useState('')
|
|
390
|
+
const [inv, setInv] = React.useState(null)
|
|
391
|
+
const [busy, setBusy] = React.useState('')
|
|
392
|
+
const [output, setOutput] = React.useState('')
|
|
393
|
+
const [error, setError] = React.useState('')
|
|
394
|
+
const [notice, setNotice] = React.useState('')
|
|
395
|
+
const [form, setForm] = React.useState({ name: '', host: '', user: '', key: '', password: '', alias: '' })
|
|
396
|
+
const [editName, setEditName] = React.useState('')
|
|
397
|
+
const [fileState, setFileState] = React.useState(null)
|
|
398
|
+
const [diag, setDiag] = React.useState(null)
|
|
399
|
+
const [duPath, setDuPath] = React.useState('/')
|
|
400
|
+
const [duRows, setDuRows] = React.useState(null)
|
|
401
|
+
const [psSort, setPsSort] = React.useState('cpu')
|
|
402
|
+
const [psRows, setPsRows] = React.useState(null)
|
|
403
|
+
const [logSource, setLogSource] = React.useState('nginx.service')
|
|
404
|
+
const [logLines, setLogLines] = React.useState(200)
|
|
405
|
+
const [logText, setLogText] = React.useState('')
|
|
406
|
+
const [logAuto, setLogAuto] = React.useState(false)
|
|
407
|
+
const [sslDomain, setSslDomain] = React.useState('')
|
|
408
|
+
const [sslResult, setSslResult] = React.useState(null)
|
|
409
|
+
const [conns, setConns] = React.useState({})
|
|
410
|
+
const [consoleCmd, setConsoleCmd] = React.useState('')
|
|
411
|
+
const [consoleOut, setConsoleOut] = React.useState('')
|
|
412
|
+
const [consoleHistory, setConsoleHistory] = React.useState([])
|
|
413
|
+
const [term, setTerm] = React.useState(null)
|
|
414
|
+
const [aiIntent, setAiIntent] = React.useState('')
|
|
415
|
+
const [aiResult, setAiResult] = React.useState(null)
|
|
416
|
+
const [aiBusy, setAiBusy] = React.useState(false)
|
|
417
|
+
const [aiMode, setAiMode] = React.useState(false)
|
|
418
|
+
const [aiDraft, setAiDraft] = React.useState('')
|
|
419
|
+
const [quickText, setQuickText] = React.useState('')
|
|
420
|
+
const [askQuestion, setAskQuestion] = React.useState('')
|
|
421
|
+
const [askBusy, setAskBusy] = React.useState(false)
|
|
422
|
+
const [askLog, setAskLog] = React.useState([])
|
|
423
|
+
const [chatNotice, setChatNotice] = React.useState('')
|
|
424
|
+
const [aiModels, setAiModels] = React.useState({ providers: [], defaultSelection: null, aiEnabled: true, aiProvider: '', aiModel: '' })
|
|
425
|
+
const [monitors, setMonitors] = React.useState([])
|
|
426
|
+
const [monForm, setMonForm] = React.useState({ type: 'http', target: '', label: '', intervalMinutes: 5, language: 'shell', script: '' })
|
|
427
|
+
const [monEditId, setMonEditId] = React.useState('')
|
|
428
|
+
const [monBusy, setMonBusy] = React.useState('')
|
|
429
|
+
const [health, setHealth] = React.useState(null)
|
|
430
|
+
const [certs, setCerts] = React.useState([])
|
|
431
|
+
const [backups, setBackups] = React.useState([])
|
|
432
|
+
const [backupForm, setBackupForm] = React.useState({ type: 'mysql', database: '', path: '/etc/nginx', dir: '/home/backup', keep: 7 })
|
|
433
|
+
const [cronJobs, setCronJobs] = React.useState([])
|
|
434
|
+
const [cronForm, setCronForm] = React.useState({ frequency: 'daily', hour: '3', minute: '0', command: '' })
|
|
435
|
+
const [deployJobs, setDeployJobs] = React.useState([])
|
|
436
|
+
const [deployForm, setDeployForm] = React.useState({ name: '发布', dir: '', repo: '', branch: 'origin/main', build: '', restart: '', health: '' })
|
|
437
|
+
const [opBusy, setOpBusy] = React.useState('')
|
|
438
|
+
const [opOut, setOpOut] = React.useState('')
|
|
439
|
+
const [histPath, setHistPath] = React.useState('/etc/nginx/nginx.conf')
|
|
440
|
+
const [histList, setHistList] = React.useState([])
|
|
441
|
+
const [histDiff, setHistDiff] = React.useState(null)
|
|
442
|
+
const [channels, setChannels] = React.useState([])
|
|
443
|
+
const [channelForm, setChannelForm] = React.useState({ type: 'feishu', name: '飞书群', url: '', events: ['critical', 'warning'] })
|
|
444
|
+
const [chBusy, setChBusy] = React.useState('')
|
|
445
|
+
const [fsPath, setFsPath] = React.useState('/')
|
|
446
|
+
const [fsEntries, setFsEntries] = React.useState(null)
|
|
447
|
+
const [fsBusy, setFsBusy] = React.useState('')
|
|
448
|
+
const [adding, setAdding] = React.useState(false)
|
|
449
|
+
|
|
450
|
+
const loadBase = React.useCallback(async () => {
|
|
451
|
+
try {
|
|
452
|
+
const data = await api('hosts')
|
|
453
|
+
setHosts(data.hosts || [])
|
|
454
|
+
try { const c = await api('conn'); setConns(c.connections || {}) } catch { /* optional */ }
|
|
455
|
+
const conf = await api('config')
|
|
456
|
+
if (conf.config) {
|
|
457
|
+
setConfig(conf.config)
|
|
458
|
+
setQuickText((conf.config.quickCommands || []).join('\n'))
|
|
459
|
+
}
|
|
460
|
+
setError('')
|
|
461
|
+
return data.hosts || []
|
|
462
|
+
} catch (e) { setError(String(e.message || e)); return [] }
|
|
463
|
+
}, [])
|
|
464
|
+
|
|
465
|
+
React.useEffect(() => { void loadBase() }, [loadBase])
|
|
466
|
+
|
|
467
|
+
const timeoutFor = (kind) => {
|
|
468
|
+
const sec = kind === 'scan'
|
|
469
|
+
? (config.scanSec ?? 90)
|
|
470
|
+
: kind === 'action'
|
|
471
|
+
? (config.actionSec ?? 45)
|
|
472
|
+
: (config.timeoutSec ?? 25)
|
|
473
|
+
return Math.max(5, Number(sec) || 25) * 1000
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
const askAi = async (host, question) => {
|
|
477
|
+
setDiag({ host, loading: true, question: question ?? diag?.question ?? '', result: null })
|
|
478
|
+
setBusy('diag')
|
|
479
|
+
try {
|
|
480
|
+
const data = await api('diagnose', {
|
|
481
|
+
method: 'POST',
|
|
482
|
+
body: JSON.stringify({ host, question: question ?? diag?.question ?? '' }),
|
|
483
|
+
}, timeoutFor('action'))
|
|
484
|
+
setDiag({ host, loading: false, question: question ?? diag?.question ?? '', result: data })
|
|
485
|
+
} catch (e) {
|
|
486
|
+
setDiag({ host, loading: false, question: '', result: { level: 'bad', headline: String(e.message || e), reasons: [], actions: [] } })
|
|
487
|
+
} finally { setBusy('') }
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
const loadDu = async (path) => {
|
|
491
|
+
const target = path ?? duPath
|
|
492
|
+
setBusy('du')
|
|
493
|
+
try {
|
|
494
|
+
const data = await api('du', { method: 'POST', body: JSON.stringify({ host: cHost || hosts[0]?.name, path: target }) }, timeoutFor('action'))
|
|
495
|
+
setDuRows(data.rows || []); setDuPath(data.path || target); setError('')
|
|
496
|
+
} catch (e) { setError(String(e.message || e)) } finally { setBusy('') }
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
const loadPs = async (sort) => {
|
|
500
|
+
const key = sort ?? psSort
|
|
501
|
+
setBusy('ps')
|
|
502
|
+
try {
|
|
503
|
+
const data = await api(`ps?host=${encodeURIComponent(cHost || hosts[0]?.name)}&sort=${key}`, {}, timeoutFor('action'))
|
|
504
|
+
setPsRows(data.rows || []); setPsSort(key); setError('')
|
|
505
|
+
} catch (e) { setError(String(e.message || e)) } finally { setBusy('') }
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
const killPid = async (pid) => {
|
|
509
|
+
if (!window.confirm(`${T.confirmKill} PID ${pid}`)) return
|
|
510
|
+
setBusy('kill:' + pid)
|
|
511
|
+
try {
|
|
512
|
+
const data = await api('kill', { method: 'POST', body: JSON.stringify({ host: cHost || hosts[0]?.name, pid, signal: 'TERM', confirm: true }) }, timeoutFor('action'))
|
|
513
|
+
setNotice(data.ok ? `PID ${pid} 已发送 TERM` : (data.stderr || 'failed'))
|
|
514
|
+
setTimeout(() => setNotice(''), 3000)
|
|
515
|
+
await loadPs()
|
|
516
|
+
} catch (e) { setError(String(e.message || e)) } finally { setBusy('') }
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
const loadLogs = async () => {
|
|
520
|
+
setBusy('logs')
|
|
521
|
+
try {
|
|
522
|
+
const data = await api(`tail?host=${encodeURIComponent(cHost || hosts[0]?.name)}&source=${encodeURIComponent(logSource)}&lines=${logLines}`, {}, timeoutFor('action'))
|
|
523
|
+
setLogText(data.lines || data.error || '')
|
|
524
|
+
} catch (e) { setLogText(String(e.message || e)) } finally { setBusy('') }
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
const checkSsl = async () => {
|
|
528
|
+
if (!sslDomain.trim()) { setError(T.domain); return }
|
|
529
|
+
setBusy('ssl')
|
|
530
|
+
try {
|
|
531
|
+
const data = await api('ssl', { method: 'POST', body: JSON.stringify({ host: cHost || hosts[0]?.name, domain: sslDomain.trim() }) }, timeoutFor('action'))
|
|
532
|
+
setSslResult(data)
|
|
533
|
+
} catch (e) { setError(String(e.message || e)) } finally { setBusy('') }
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
const loadFiles = async (path) => {
|
|
537
|
+
const target = path ?? fsPath
|
|
538
|
+
setFsBusy('list')
|
|
539
|
+
try {
|
|
540
|
+
const data = await api(`files?host=${encodeURIComponent(cHost || hosts[0]?.name)}&path=${encodeURIComponent(target)}`, {}, timeoutFor('action'))
|
|
541
|
+
setFsEntries(data.entries || []); setFsPath(data.path || target); setError('')
|
|
542
|
+
} catch (e) { setError(String(e.message || e)) } finally { setFsBusy('') }
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
const downloadFile = async (path, name) => {
|
|
546
|
+
setFsBusy('dl:' + path)
|
|
547
|
+
try {
|
|
548
|
+
const data = await api(`download?host=${encodeURIComponent(cHost || hosts[0]?.name)}&path=${encodeURIComponent(path)}`, {}, 120_000)
|
|
549
|
+
const bytes = Uint8Array.from(atob(data.base64 || ''), ch => ch.charCodeAt(0))
|
|
550
|
+
const url = URL.createObjectURL(new Blob([bytes]))
|
|
551
|
+
const a = document.createElement('a')
|
|
552
|
+
a.href = url; a.download = name || 'download'; a.click()
|
|
553
|
+
setTimeout(() => URL.revokeObjectURL(url), 2000)
|
|
554
|
+
} catch (e) { setError(String(e.message || e)) } finally { setFsBusy('') }
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
const uploadFile = async (file) => {
|
|
558
|
+
if (!file) return
|
|
559
|
+
setFsBusy('upload')
|
|
560
|
+
try {
|
|
561
|
+
const base64 = await new Promise((resolve, reject) => {
|
|
562
|
+
const reader = new FileReader()
|
|
563
|
+
reader.onload = () => resolve(String(reader.result).split(',')[1] || '')
|
|
564
|
+
reader.onerror = () => reject(new Error('read failed'))
|
|
565
|
+
reader.readAsDataURL(file)
|
|
566
|
+
})
|
|
567
|
+
const target = (fsPath === '/' ? '' : fsPath) + '/' + file.name
|
|
568
|
+
await api('upload', { method: 'POST', body: JSON.stringify({ host: cHost || hosts[0]?.name, path: target, base64 }) }, 180_000)
|
|
569
|
+
await loadFiles(fsPath)
|
|
570
|
+
} catch (e) { setError(String(e.message || e)) } finally { setFsBusy('') }
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
const fsDelete = async (path) => {
|
|
574
|
+
if (!window.confirm(`${T.confirmDel} ${path}`)) return
|
|
575
|
+
setFsBusy('del:' + path)
|
|
576
|
+
try {
|
|
577
|
+
await api('fs', { method: 'POST', body: JSON.stringify({ host: cHost || hosts[0]?.name, action: 'delete', path, confirm: true }) }, timeoutFor('action'))
|
|
578
|
+
await loadFiles(fsPath)
|
|
579
|
+
} catch (e) { setError(String(e.message || e)) } finally { setFsBusy('') }
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
const fsMkdir = async () => {
|
|
583
|
+
const name = window.prompt(T.folderName)
|
|
584
|
+
if (!name) return
|
|
585
|
+
try {
|
|
586
|
+
await api('fs', { method: 'POST', body: JSON.stringify({ host: cHost || hosts[0]?.name, action: 'mkdir', path: (fsPath === '/' ? '' : fsPath) + '/' + name }) }, timeoutFor('action'))
|
|
587
|
+
await loadFiles(fsPath)
|
|
588
|
+
} catch (e) { setError(String(e.message || e)) }
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
const testHost = async (name) => {
|
|
592
|
+
setBusy('test:' + name)
|
|
593
|
+
try {
|
|
594
|
+
const data = await api('test', { method: 'POST', body: JSON.stringify({ host: name }) }, timeoutFor('action'))
|
|
595
|
+
setConns({ ...conns, [name]: { ok: data.ok, ms: data.ms, at: new Date().toISOString(), error: data.error } })
|
|
596
|
+
if (!data.ok) setError(`${name}: ${data.error || 'connection failed'}`)
|
|
597
|
+
} catch (e) { setError(String(e.message || e)) } finally { setBusy('') }
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
const installKeyOn = async (name) => {
|
|
601
|
+
setBusy('key:' + name)
|
|
602
|
+
try {
|
|
603
|
+
const data = await api('install-key', { method: 'POST', body: JSON.stringify({ host: name }) }, timeoutFor('action'))
|
|
604
|
+
setNotice(data.ok ? `公钥已安装(authorized_keys 共 ${data.keys ?? '?'} 条)` : (data.error || 'failed'))
|
|
605
|
+
setTimeout(() => setNotice(''), 4000)
|
|
606
|
+
} catch (e) { setError(String(e.message || e)) } finally { setBusy('') }
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
const runConsole = async () => {
|
|
610
|
+
const command = consoleCmd.trim()
|
|
611
|
+
if (!command) return
|
|
612
|
+
setBusy('console')
|
|
613
|
+
try {
|
|
614
|
+
const data = await api('exec', { method: 'POST', body: JSON.stringify({ command, hosts: [cHost || hosts[0]?.name] }) }, timeoutFor('action'))
|
|
615
|
+
const row = (data.results || [])[0]
|
|
616
|
+
setConsoleOut(row ? (row.ok ? row.stdout || '(no output)' : `exit ${row.code}\n${row.stderr || ''}`) : 'no result')
|
|
617
|
+
setConsoleHistory([command, ...consoleHistory.filter(item => item !== command)].slice(0, 20))
|
|
618
|
+
} catch (e) { setConsoleOut(String(e.message || e)) } finally { setBusy('') }
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
const openTerm = async () => {
|
|
622
|
+
if (busy === 'term' || term?.id) return
|
|
623
|
+
setBusy('term')
|
|
624
|
+
try {
|
|
625
|
+
const data = await api('term/open', { method: 'POST', body: JSON.stringify({ host: cHost || hosts[0]?.name, cols: 120, rows: 30 }) }, 30_000)
|
|
626
|
+
setTerm({ id: data.id, output: '', offset: 0, closed: false })
|
|
627
|
+
setTimeout(() => { const el = document.getElementById('ops-term'); if (el) el.focus() }, 400)
|
|
628
|
+
setError('')
|
|
629
|
+
} catch (e) { setError(String(e.message || e)) } finally { setBusy('') }
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
const closeTerm = async () => {
|
|
633
|
+
if (term?.id) { try { await api('term/close', { method: 'POST', body: JSON.stringify({ id: term.id }) }) } catch {} }
|
|
634
|
+
setTerm(null)
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
const sendKey = async (data) => {
|
|
638
|
+
if (!term?.id) return
|
|
639
|
+
try { await api('term/input', { method: 'POST', body: JSON.stringify({ id: term.id, data }) }, 15_000) } catch (e) { setError(String(e.message || e)) }
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
React.useEffect(() => {
|
|
643
|
+
if (!term?.id) return
|
|
644
|
+
let offset = 0
|
|
645
|
+
let alive = true
|
|
646
|
+
let closed = false
|
|
647
|
+
const timer = setInterval(async () => {
|
|
648
|
+
if (!alive || closed) return
|
|
649
|
+
try {
|
|
650
|
+
const data = await api(`term/poll?id=${encodeURIComponent(term.id)}&since=${offset}`, {}, 15_000)
|
|
651
|
+
if (!alive) return
|
|
652
|
+
if (data.error) { closed = true; setTerm(current => (current ? { ...current, closed: true } : null)); return }
|
|
653
|
+
if (typeof data.offset === 'number') offset = data.offset
|
|
654
|
+
if (data.data) {
|
|
655
|
+
setTerm(current => (current
|
|
656
|
+
? { ...current, output: (current.output + data.data).slice(-60_000), closed: Boolean(data.closed) }
|
|
657
|
+
: null))
|
|
658
|
+
}
|
|
659
|
+
if (data.closed) closed = true
|
|
660
|
+
} catch { /* retry next tick */ }
|
|
661
|
+
}, 400)
|
|
662
|
+
return () => { alive = false; clearInterval(timer) }
|
|
663
|
+
}, [term?.id])
|
|
664
|
+
|
|
665
|
+
// Overview: latest sample per host.
|
|
666
|
+
React.useEffect(() => {
|
|
667
|
+
if (hosts.length === 0) return
|
|
668
|
+
if (!detailHost && tab !== 0) return
|
|
669
|
+
let alive = true
|
|
670
|
+
void (async () => {
|
|
671
|
+
const next = {}
|
|
672
|
+
await Promise.all(hosts.map(async (host) => {
|
|
673
|
+
try {
|
|
674
|
+
const data = await api(`metrics?host=${encodeURIComponent(host.name)}&hours=2`)
|
|
675
|
+
const list = data.samples || []
|
|
676
|
+
next[host.name] = list.slice(-40)
|
|
677
|
+
} catch { next[host.name] = null }
|
|
678
|
+
}))
|
|
679
|
+
if (alive) setOverview(next)
|
|
680
|
+
})()
|
|
681
|
+
return () => { alive = false }
|
|
682
|
+
}, [tab, hosts, detailHost])
|
|
683
|
+
|
|
684
|
+
// Monitor samples.
|
|
685
|
+
React.useEffect(() => {
|
|
686
|
+
if (!detailHost || detailTab !== 'monitor') return
|
|
687
|
+
const host = mHost || hosts[0]?.name
|
|
688
|
+
if (!host) return
|
|
689
|
+
void (async () => {
|
|
690
|
+
try {
|
|
691
|
+
const data = await api(`metrics?host=${encodeURIComponent(host)}&hours=${mHours}`)
|
|
692
|
+
setSamples(data.samples || [])
|
|
693
|
+
} catch (e) { setError(String(e.message || e)) }
|
|
694
|
+
})()
|
|
695
|
+
}, [detailHost, detailTab, mHost, mHours, hosts])
|
|
696
|
+
|
|
697
|
+
React.useEffect(() => {
|
|
698
|
+
if (tab !== 2 || detailHost) return
|
|
699
|
+
void (async () => {
|
|
700
|
+
try { setAiModels(await api('ai-models', {}, 15_000)) } catch { /* optional */ }
|
|
701
|
+
void loadChannels()
|
|
702
|
+
})()
|
|
703
|
+
}, [tab, detailHost])
|
|
704
|
+
|
|
705
|
+
React.useEffect(() => {
|
|
706
|
+
if (!detailHost || detailTab !== 'files') return
|
|
707
|
+
void loadFiles(fsPath)
|
|
708
|
+
}, [detailHost, detailTab, cHost])
|
|
709
|
+
|
|
710
|
+
React.useEffect(() => {
|
|
711
|
+
if (!detailHost || detailTab !== 'logs' || !logAuto) return
|
|
712
|
+
void loadLogs()
|
|
713
|
+
const timer = setInterval(() => { void loadLogs() }, 5000)
|
|
714
|
+
return () => clearInterval(timer)
|
|
715
|
+
}, [detailHost, detailTab, logAuto, logSource, logLines, cHost])
|
|
716
|
+
|
|
717
|
+
// Inventory (config + apps tabs).
|
|
718
|
+
const loadInv = React.useCallback(async (host, refresh) => {
|
|
719
|
+
if (!host) return
|
|
720
|
+
setBusy(refresh ? 'scan' : '')
|
|
721
|
+
try {
|
|
722
|
+
const data = refresh
|
|
723
|
+
? await api('discover', { method: 'POST', body: JSON.stringify({ host }) }, timeoutFor('scan'))
|
|
724
|
+
: await api(`inventory?host=${encodeURIComponent(host)}`, {}, 30_000)
|
|
725
|
+
setInv(data)
|
|
726
|
+
setError('')
|
|
727
|
+
} catch (e) { setError(String(e.message || e)) } finally { setBusy('') }
|
|
728
|
+
}, [])
|
|
729
|
+
|
|
730
|
+
React.useEffect(() => {
|
|
731
|
+
if (!detailHost || (detailTab !== 'config' && detailTab !== 'apps')) return
|
|
732
|
+
const host = cHost || hosts[0]?.name
|
|
733
|
+
if (!host) return
|
|
734
|
+
void loadInv(host, false)
|
|
735
|
+
}, [detailHost, detailTab, cHost, hosts, loadInv])
|
|
736
|
+
|
|
737
|
+
const doAction = async (kind, name, action, hostOverride) => {
|
|
738
|
+
if (action !== 'logs' && !window.confirm(`${action} ${name}?`)) return
|
|
739
|
+
const key = `act:${kind}:${name}:${action}`
|
|
740
|
+
setBusy(key)
|
|
741
|
+
setOutput(action === 'logs' ? T.reading : '…')
|
|
742
|
+
try {
|
|
743
|
+
const data = await api('app', { method: 'POST', body: JSON.stringify({ host: hostOverride || cHost || hosts[0]?.name, kind, name, action, confirm: true }) }, timeoutFor('action'))
|
|
744
|
+
setOutput(data.ok ? (data.stdout || data.stderr || 'ok') : (data.stderr || 'failed'))
|
|
745
|
+
} catch (e) { setOutput(String(e.message || e)) } finally { setBusy('') }
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
const cleanupHost = async (name) => {
|
|
749
|
+
if (!window.confirm(`${T.cleanup}: ${name}?`)) return
|
|
750
|
+
setBusy('clean:' + name)
|
|
751
|
+
try {
|
|
752
|
+
const data = await api('cleanup', { method: 'POST', body: JSON.stringify({ host: name, confirm: true }) }, timeoutFor('action') * 2)
|
|
753
|
+
setNotice(data.ok ? `${T.freed} ${data.before}% → ${data.after}%` : (data.error || 'failed'))
|
|
754
|
+
setTimeout(() => setNotice(''), 4000)
|
|
755
|
+
} catch (e) { setError(String(e.message || e)) } finally { setBusy('') }
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
const openFile = async (path, appName) => {
|
|
759
|
+
setFileState({ path, appName, content: '', busy: false, loading: true, msg: '' })
|
|
760
|
+
try {
|
|
761
|
+
const data = await api(`file?host=${encodeURIComponent(cHost || hosts[0]?.name)}&path=${encodeURIComponent(path)}`, {}, timeoutFor('action'))
|
|
762
|
+
setFileState({ path, appName, content: data.content || '', busy: false, loading: false, msg: '' })
|
|
763
|
+
} catch (e) { setFileState(null); setError(String(e.message || e)) }
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
const saveFile = async () => {
|
|
767
|
+
if (!fileState) return
|
|
768
|
+
if (!window.confirm(`${T.saveFile}: ${fileState.path}?`)) return
|
|
769
|
+
setFileState({ ...fileState, busy: true })
|
|
770
|
+
try {
|
|
771
|
+
const data = await api('file', { method: 'POST', body: JSON.stringify({ host: cHost || hosts[0]?.name, path: fileState.path, content: fileState.content, confirm: true }) }, timeoutFor('action') * 2)
|
|
772
|
+
setFileState({ ...fileState, busy: false, msg: data.ok ? `${T.saved2}(${data.backup})` : (data.error || 'failed') })
|
|
773
|
+
} catch (e) { setFileState({ ...fileState, busy: false, msg: String(e.message || e) }) }
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
const saveConfig = async () => {
|
|
777
|
+
try {
|
|
778
|
+
const payload = {
|
|
779
|
+
...config,
|
|
780
|
+
quickCommands: quickText.split('\n').map(line => line.trim()).filter(Boolean),
|
|
781
|
+
aiEnabled: aiModels.aiEnabled !== false,
|
|
782
|
+
aiProvider: aiModels.aiProvider || '',
|
|
783
|
+
aiModel: aiModels.aiModel || '',
|
|
784
|
+
}
|
|
785
|
+
const data = await api('config', { method: 'POST', body: JSON.stringify(payload) })
|
|
786
|
+
if (data.config) setConfig(data.config)
|
|
787
|
+
setNotice(T.changed); setTimeout(() => setNotice(''), 2000)
|
|
788
|
+
} catch (e) { setError(String(e.message || e)) }
|
|
789
|
+
}
|
|
790
|
+
|
|
791
|
+
const addHost = async () => {
|
|
792
|
+
if (!form.name || !form.host) { setError(`${T.name} / ${T.host}`); return }
|
|
793
|
+
try {
|
|
794
|
+
const payload = editName
|
|
795
|
+
? { action: 'update', name: editName, host: form.host, user: form.user, port: form.port, alias: form.alias, key: form.key, password: form.password || undefined }
|
|
796
|
+
: { ...form, defaultHost: hosts.length === 0 }
|
|
797
|
+
const data = await api('hosts', { method: 'POST', body: JSON.stringify(payload) })
|
|
798
|
+
if (data.tested && !data.tested.ok) setError(`${T.check}: ${data.tested.error || data.tested.code}`)
|
|
799
|
+
setForm({ name: '', host: '', user: '', key: '', password: '', alias: '' })
|
|
800
|
+
setEditName('')
|
|
801
|
+
setAdding(false)
|
|
802
|
+
await loadBase()
|
|
803
|
+
} catch (e) { setError(String(e.message || e)) }
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
const startEdit = (host) => {
|
|
807
|
+
setEditName(host.name)
|
|
808
|
+
setForm({ name: host.name, host: host.host, user: host.user || '', key: host.key || '', password: '', alias: host.alias || '', port: host.port || 22 })
|
|
809
|
+
setAdding(true)
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
const removeHost = async (name) => {
|
|
813
|
+
if (!window.confirm(`remove ${name}?`)) return
|
|
814
|
+
try { await api('hosts', { method: 'POST', body: JSON.stringify({ action: 'remove', name }) }); await loadBase() }
|
|
815
|
+
catch (e) { setError(String(e.message || e)) }
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
const hostPicker = (value, onChange) => h('div', { className: 'ops-chips' },
|
|
819
|
+
hosts.map(host => h('button', {
|
|
820
|
+
key: host.name,
|
|
821
|
+
className: `ops-tab${(value || hosts[0]?.name) === host.name ? ' on' : ''}`,
|
|
822
|
+
onClick: () => onChange(host.name),
|
|
823
|
+
}, host.name)))
|
|
824
|
+
|
|
825
|
+
const statusOf = (sample) => {
|
|
826
|
+
if (!sample) return { cls: 'unknown', text: T.unknown }
|
|
827
|
+
if (sample.ok === false) return { cls: 'bad', text: T.down }
|
|
828
|
+
if ((sample.disk ?? 0) >= 90 || (sample.mem ?? 0) >= 90) return { cls: 'bad', text: T.disk + ' ' + pct(sample.disk) }
|
|
829
|
+
if ((sample.disk ?? 0) >= 75 || (sample.mem ?? 0) >= 80) return { cls: 'warn', text: T.warn }
|
|
830
|
+
return { cls: 'ok', text: T.normal }
|
|
831
|
+
}
|
|
832
|
+
|
|
833
|
+
|
|
834
|
+
const countOf = (cls) => hosts.filter(host => {
|
|
835
|
+
const list = overview[host.name] || []
|
|
836
|
+
return statusOf(list[list.length - 1] || null).cls === cls
|
|
837
|
+
}).length
|
|
838
|
+
|
|
839
|
+
const metricBox = (label, value, tone) => h('div', { className: 'ops-num' },
|
|
840
|
+
h('b', null, pct(value)),
|
|
841
|
+
h('span', null, label),
|
|
842
|
+
h('div', { className: 'ops-bar' },
|
|
843
|
+
h('i', { className: tone, style: { width: Math.min(100, value ?? 0) + '%' } })))
|
|
844
|
+
|
|
845
|
+
const hostCard = (host) => {
|
|
846
|
+
const list = overview[host.name] || []
|
|
847
|
+
const sample = list[list.length - 1] || null
|
|
848
|
+
const st = statusOf(sample)
|
|
849
|
+
const diskTone = (sample?.disk ?? 0) >= 90 ? 'bad' : (sample?.disk ?? 0) >= 75 ? 'warn' : ''
|
|
850
|
+
const memTone = (sample?.mem ?? 0) >= 85 ? 'warn' : ''
|
|
851
|
+
const title = host.alias || host.name
|
|
852
|
+
const toneClass = st.cls === 'ok' ? 'ops-ok' : st.cls === 'warn' ? 'ops-warn' : st.cls === 'bad' ? 'ops-bad' : 'ops-dim'
|
|
853
|
+
|
|
854
|
+
const head = h('div', { className: 'ops-card-h' },
|
|
855
|
+
h('span', null,
|
|
856
|
+
h('i', { className: 'ops-dot ' + st.cls }),
|
|
857
|
+
title,
|
|
858
|
+
host.alias ? h('span', { className: 'ops-dim', style: { marginLeft: '8px', fontWeight: 400 } }, host.name) : null),
|
|
859
|
+
h('span', { className: toneClass, style: { fontSize: '12px' } }, st.text))
|
|
860
|
+
|
|
861
|
+
const nums = h('div', { className: 'ops-nums' },
|
|
862
|
+
metricBox(T.cpu, sample?.cpu, ''),
|
|
863
|
+
metricBox(T.mem, sample?.mem, memTone),
|
|
864
|
+
metricBox(T.disk, sample?.disk, diskTone))
|
|
865
|
+
|
|
866
|
+
const trends = h('div', { style: { display: 'flex', gap: '12px', alignItems: 'center', flexWrap: 'wrap' } },
|
|
867
|
+
h('span', { className: 'ops-dim' }, T.cpu), h(Spark, { rows: list, field: 'cpu' }),
|
|
868
|
+
h('span', { className: 'ops-dim' }, T.mem), h(Spark, { rows: list, field: 'mem' }),
|
|
869
|
+
h('span', { className: 'ops-dim' }, T.disk), h(Spark, { rows: list, field: 'disk' }))
|
|
870
|
+
|
|
871
|
+
const conn = conns[host.name]
|
|
872
|
+
const meta = h('div', { className: 'ops-dim' },
|
|
873
|
+
(host.user ? host.user + '@' : '') + host.host + ':' + (host.port || 22),
|
|
874
|
+
conn
|
|
875
|
+
? ' · ' + (conn.ok ? `${T.connected} ${conn.ms}ms` : `${T.disconnected}(${T.failures} ${conn.failures ?? 1})`)
|
|
876
|
+
: '',
|
|
877
|
+
sample?.ts ? ' · ' + T.lastSample + ' ' + fmt(new Date(sample.ts).toISOString()) : '')
|
|
878
|
+
|
|
879
|
+
const buttons = [
|
|
880
|
+
h('button', { key: 'open', className: 'ops-btn ops-btn-primary ops-btn-sm', onClick: () => openHost(host.name) }, '进入详情'),
|
|
881
|
+
h('button', { key: 'ask', className: 'ops-btn ops-btn-sm', disabled: busy === 'diag', onClick: () => { void askAi(host.name, '') } }, busy === 'diag' ? T.diagnosing : T.ask),
|
|
882
|
+
]
|
|
883
|
+
if ((sample?.disk ?? 0) >= 85) {
|
|
884
|
+
buttons.push(h('button', {
|
|
885
|
+
key: 'clean',
|
|
886
|
+
className: 'ops-btn ops-btn-sm',
|
|
887
|
+
disabled: busy === 'clean:' + host.name,
|
|
888
|
+
onClick: () => { void cleanupHost(host.name) },
|
|
889
|
+
}, busy === 'clean:' + host.name ? T.cleaning : T.cleanup))
|
|
890
|
+
}
|
|
891
|
+
|
|
892
|
+
return h('div', { key: host.name, className: 'ops-card' },
|
|
893
|
+
head,
|
|
894
|
+
h('div', { className: 'ops-card-b' }, nums, trends, meta, h('div', { className: 'ops-chips' }, buttons)))
|
|
895
|
+
}
|
|
896
|
+
|
|
897
|
+
const summaryStrip = h('div', { className: 'ops-cards' },
|
|
898
|
+
h('div', { className: 'ops-num' }, h('b', null, String(hosts.length)), h('span', null, T.summary)),
|
|
899
|
+
h('div', { className: 'ops-num' }, h('b', { className: 'ops-ok' }, String(countOf('ok'))), h('span', null, T.allOk)),
|
|
900
|
+
h('div', { className: 'ops-num' }, h('b', { className: 'ops-warn' }, String(countOf('warn'))), h('span', null, T.needLook)),
|
|
901
|
+
h('div', { className: 'ops-num' }, h('b', { className: 'ops-bad' }, String(countOf('bad'))), h('span', null, T.offline)))
|
|
902
|
+
|
|
903
|
+
const diagView = diag ? h('div', { className: 'ops-card' },
|
|
904
|
+
h('div', { className: 'ops-card-h' },
|
|
905
|
+
h('span', null, `${T.diagnose}: ${diag.host}`),
|
|
906
|
+
h('span', { className: diag.result?.level === 'ok' ? 'ops-ok' : diag.result?.level === 'warn' ? 'ops-warn' : 'ops-bad', style: { fontSize: '12px' } },
|
|
907
|
+
diag.loading ? T.diagnosing : (diag.result?.headline || ''))),
|
|
908
|
+
h('div', { className: 'ops-card-b' },
|
|
909
|
+
h('div', { className: 'ops-chips' },
|
|
910
|
+
h('input', {
|
|
911
|
+
className: 'ops-input',
|
|
912
|
+
style: { flex: '1 1 260px' },
|
|
913
|
+
placeholder: T.askPh,
|
|
914
|
+
value: diag.question,
|
|
915
|
+
onChange: e => setDiag({ ...diag, question: e.target.value }),
|
|
916
|
+
onKeyDown: e => { if (e.key === 'Enter') void askAi(diag.host, diag.question) },
|
|
917
|
+
}),
|
|
918
|
+
h('button', { className: 'ops-btn ops-btn-primary ops-btn-sm', disabled: diag.loading, onClick: () => { void askAi(diag.host, diag.question) } }, diag.loading ? T.diagnosing : T.ask),
|
|
919
|
+
h('button', {
|
|
920
|
+
className: 'ops-btn ops-btn-sm',
|
|
921
|
+
onClick: () => {
|
|
922
|
+
const text = `用运维工具排查一下 ${diag.host}:${diag.question || '有什么问题?'}`
|
|
923
|
+
void navigator.clipboard?.writeText(text).then(() => {
|
|
924
|
+
setNotice('已复制,粘贴到对话框让 AI 深入分析')
|
|
925
|
+
setTimeout(() => setNotice(''), 3000)
|
|
926
|
+
}).catch(() => {})
|
|
927
|
+
},
|
|
928
|
+
}, '复制到对话'),
|
|
929
|
+
h('button', { className: 'ops-btn ops-btn-sm', onClick: () => setDiag(null) }, T.close2)),
|
|
930
|
+
h('div', { className: 'ops-chips' },
|
|
931
|
+
...T.askPreset.map(text => h('button', { key: text, className: 'ops-btn ops-btn-sm', onClick: () => { void askAi(diag.host, text) } }, text))),
|
|
932
|
+
diag.loading ? h('p', { className: 'ops-empty' }, T.loading) : null,
|
|
933
|
+
!diag.loading && diag.result ? h('div', null,
|
|
934
|
+
diag.result.ai
|
|
935
|
+
? h('div', {
|
|
936
|
+
style: {
|
|
937
|
+
padding: '12px 14px',
|
|
938
|
+
margin: '0 0 10px',
|
|
939
|
+
borderRadius: '10px',
|
|
940
|
+
background: 'var(--dsw-alias-bg,#15181c)',
|
|
941
|
+
border: '1px solid var(--dsw-alias-border,#3a3f45)',
|
|
942
|
+
fontSize: '13px',
|
|
943
|
+
lineHeight: 1.75,
|
|
944
|
+
whiteSpace: 'pre-wrap',
|
|
945
|
+
},
|
|
946
|
+
}, diag.result.ai)
|
|
947
|
+
: (diag.result.summary ? h('p', { className: 'ops-sub', style: { margin: '0 0 10px', lineHeight: 1.7 } }, diag.result.summary) : null),
|
|
948
|
+
...((diag.result.sections || []).map((item, index) => h('div', {
|
|
949
|
+
key: index,
|
|
950
|
+
style: { display: 'flex', gap: '10px', alignItems: 'flex-start', padding: '8px 0', borderTop: index === 0 ? 'none' : '1px solid var(--dsw-alias-border,#3a3f45)' },
|
|
951
|
+
},
|
|
952
|
+
h('i', { className: 'ops-dot ' + (item.status === 'ok' ? 'ok' : item.status === 'warn' ? 'warn' : item.status === 'bad' ? 'bad' : 'unknown'), style: { marginTop: '5px' } }),
|
|
953
|
+
h('div', { style: { minWidth: 0 } },
|
|
954
|
+
h('div', { style: { fontSize: '13px', fontWeight: 600 } }, item.title),
|
|
955
|
+
h('div', { className: 'ops-sub', style: { lineHeight: 1.6 } }, item.detail),
|
|
956
|
+
item.advice ? h('div', { className: 'ops-dim', style: { lineHeight: 1.6 } }, item.advice) : null)))),
|
|
957
|
+
(diag.result.reasons || []).length && !(diag.result.sections || []).length
|
|
958
|
+
? h('div', null, ...diag.result.reasons.map((reason, index) => h('div', { key: 'r' + index, className: 'ops-sub' }, '· ' + reason)))
|
|
959
|
+
: null,
|
|
960
|
+
(diag.result.actions || []).length ? h('div', { className: 'ops-chips', style: { marginTop: '8px' } },
|
|
961
|
+
h('span', { className: 'ops-sub' }, T.next),
|
|
962
|
+
...(diag.result.actions || []).map(action => h('button', {
|
|
963
|
+
key: action.id,
|
|
964
|
+
className: 'ops-btn ops-btn-sm',
|
|
965
|
+
onClick: () => {
|
|
966
|
+
if (action.id === 'cleanup') void cleanupHost(diag.host)
|
|
967
|
+
else if (action.id === 'goto-service') { setTab(3); setCHost(diag.host) }
|
|
968
|
+
else if (action.id.startsWith('restart:')) void doAction('service', action.id.slice(8), 'restart', diag.host)
|
|
969
|
+
},
|
|
970
|
+
}, action.label))) : null,
|
|
971
|
+
diag.result.hint ? h('p', { className: 'ops-warn', style: { fontSize: '12px', margin: '8px 0 0' } }, diag.result.hint) : null) : null))
|
|
972
|
+
: null
|
|
973
|
+
|
|
974
|
+
const overviewView = hosts.length === 0
|
|
975
|
+
? h('p', { className: 'ops-empty' }, T.noHosts)
|
|
976
|
+
: h('div', { style: { display: 'flex', flexDirection: 'column', gap: '12px' } },
|
|
977
|
+
diagView,
|
|
978
|
+
summaryStrip,
|
|
979
|
+
h('div', { className: 'ops-cards' }, ...hosts.map(hostCard)))
|
|
980
|
+
|
|
981
|
+
const lastSample = samples[samples.length - 1] || null
|
|
982
|
+
const rx = rates(samples, 'rx')
|
|
983
|
+
const tx = rates(samples, 'tx')
|
|
984
|
+
const ioR = rates(samples, 'ioRead')
|
|
985
|
+
const ioW = rates(samples, 'ioWrite')
|
|
986
|
+
const enriched = samples.map((row, index) => ({
|
|
987
|
+
...row,
|
|
988
|
+
rxRate: rx[index], txRate: tx[index], ioReadRate: ioR[index], ioWriteRate: ioW[index],
|
|
989
|
+
}))
|
|
990
|
+
const uptimeText = lastSample?.uptimeSec
|
|
991
|
+
? `${Math.floor(lastSample.uptimeSec / 86400)} 天 ${Math.floor((lastSample.uptimeSec % 86400) / 3600)} 小时`
|
|
992
|
+
: '—'
|
|
993
|
+
|
|
994
|
+
const monitorSummary = h('div', { className: 'ops-cards' },
|
|
995
|
+
h('div', { className: 'ops-num' }, h('b', null, lastSample?.load1 !== null && lastSample?.load1 !== undefined ? String(lastSample.load1) : '—'), h('span', null, '负载(1 分钟)')),
|
|
996
|
+
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 分钟')),
|
|
997
|
+
h('div', { className: 'ops-num' }, h('b', null, lastSample?.procs !== null && lastSample?.procs !== undefined ? String(lastSample.procs) : '—'), h('span', null, '进程数')),
|
|
998
|
+
h('div', { className: 'ops-num' }, h('b', null, lastSample?.tcp !== null && lastSample?.tcp !== undefined ? String(lastSample.tcp) : '—'), h('span', null, 'TCP 连接')),
|
|
999
|
+
h('div', { className: 'ops-num' }, h('b', null, lastSample?.swap !== null && lastSample?.swap !== undefined ? lastSample.swap + '%' : '—'), h('span', null, 'Swap 使用')),
|
|
1000
|
+
h('div', { className: 'ops-num' }, h('b', null, uptimeText), h('span', null, '已运行')))
|
|
1001
|
+
|
|
1002
|
+
const monitorView = h('div', { style: { display: 'flex', flexDirection: 'column', gap: '12px' } },
|
|
1003
|
+
h('div', { className: 'ops-chips' },
|
|
1004
|
+
detailHost ? null : hostPicker(mHost, setMHost),
|
|
1005
|
+
h('span', { className: 'ops-chip' }, T.hours),
|
|
1006
|
+
[[1, T.h1], [6, T.h6], [24, T.h24], [72, T.d3]].map(([hours, label]) =>
|
|
1007
|
+
h('button', { key: hours, className: `ops-tab${mHours === hours ? ' on' : ''}`, onClick: () => setMHours(hours) }, label))),
|
|
1008
|
+
monitorSummary,
|
|
1009
|
+
h('div', { className: 'ops-grid2' },
|
|
1010
|
+
h(Chart, { rows: enriched, title: T.cpu + ' %', max: 100, series: [{ field: 'cpu', label: T.cpu, color: 'var(--dsw-alias-accent,#4c8dff)' }] }),
|
|
1011
|
+
h(Chart, { rows: enriched, title: '内存 / Swap %', max: 100, series: [
|
|
1012
|
+
{ field: 'mem', label: T.mem, color: 'var(--dsw-alias-accent,#4c8dff)' },
|
|
1013
|
+
{ field: 'swap', label: 'Swap', color: 'var(--dsw-alias-warning,#e5b650)' },
|
|
1014
|
+
] }),
|
|
1015
|
+
h(Chart, { rows: enriched, title: T.disk + ' %', max: 100, series: [{ field: 'disk', label: T.disk, color: 'var(--dsw-alias-accent,#4c8dff)' }] }),
|
|
1016
|
+
h(Chart, { rows: enriched, title: '网络 KB/s', unit: ' KB/s', series: [
|
|
1017
|
+
{ field: 'rxRate', label: '入', color: 'var(--dsw-alias-success,#4ac97e)' },
|
|
1018
|
+
{ field: 'txRate', label: '出', color: 'var(--dsw-alias-warning,#e5b650)' },
|
|
1019
|
+
] }),
|
|
1020
|
+
h(Chart, { rows: enriched, title: '磁盘读写 KB/s', unit: ' KB/s', series: [
|
|
1021
|
+
{ field: 'ioReadRate', label: '读', color: 'var(--dsw-alias-accent,#4c8dff)' },
|
|
1022
|
+
{ field: 'ioWriteRate', label: '写', color: 'var(--dsw-alias-danger,#ff6b6b)' },
|
|
1023
|
+
] }),
|
|
1024
|
+
h(Chart, { rows: enriched, title: '进程数', unit: '', series: [{ field: 'procs', label: '进程', color: 'var(--dsw-alias-accent,#4c8dff)' }] })))
|
|
1025
|
+
|
|
1026
|
+
const sectionList = (title, rows, render) => h('div', { className: 'ops-card' },
|
|
1027
|
+
h('div', { className: 'ops-card-h' }, h('span', null, title), h('span', { className: 'ops-chip' }, String(rows.length))),
|
|
1028
|
+
rows.length === 0 ? h('p', { className: 'ops-empty' }, T.empty)
|
|
1029
|
+
: h('div', { className: 'ops-list' }, ...rows.map((row, i) => h('div', { key: i, className: 'ops-row', style: { gridTemplateColumns: '1fr' } },
|
|
1030
|
+
h('span', { className: 'ops-mono', title: String(row) }, render ? render(row) : String(row))))))
|
|
1031
|
+
|
|
1032
|
+
const configView = h('div', { style: { display: 'flex', flexDirection: 'column', gap: '12px' } },
|
|
1033
|
+
h('div', { className: 'ops-chips' }, (detailHost ? null : hostPicker(cHost, setCHost)),
|
|
1034
|
+
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)),
|
|
1035
|
+
inv ? h('div', { className: 'ops-grid2' },
|
|
1036
|
+
sectionList(T.ports, (inv.portsParsed && inv.portsParsed.length ? inv.portsParsed : inv.ports || []),
|
|
1037
|
+
row => (typeof row === 'object' && row.port) ? `${row.port} · ${purposeOf(row)}${row.process ? '(' + row.process + ')' : ''}` : String(row).replace(/\s+/g, ' ')),
|
|
1038
|
+
sectionList(T.services, inv.services || [], row => `${serviceLabel(row)} ${row}`),
|
|
1039
|
+
sectionList(T.containers, (inv.docker || []).map(d => `${d.name} — ${d.status}`)),
|
|
1040
|
+
sectionList(T.nginx, inv.nginx || [], row => String(row).trim()),
|
|
1041
|
+
sectionList(T.java, (inv.java || []).map(j => `进程 ${j.pid} · 已运行 ${j.uptime} · ${String(j.cmd).slice(0, 90)}`)),
|
|
1042
|
+
sectionList(T.cron, inv.crontab || []),
|
|
1043
|
+
sectionList(T.mounts, inv.mounts || [], row => String(row).replace(/\s+/g, ' ')))
|
|
1044
|
+
: h('p', { className: 'ops-empty' }, busy ? T.loading : T.noData),
|
|
1045
|
+
h('div', { className: 'ops-card' },
|
|
1046
|
+
h('div', { className: 'ops-card-h' }, h('span', null, T.fileHistory),
|
|
1047
|
+
h('button', { className: 'ops-btn ops-btn-sm', disabled: opBusy === 'history', onClick: () => { void loadHistory() } }, opBusy === 'history' ? T.reading : T.fileHistory)),
|
|
1048
|
+
h('div', { className: 'ops-card-b' },
|
|
1049
|
+
h('div', { className: 'ops-chips' },
|
|
1050
|
+
h('input', { className: 'ops-input', style: { flex: '1 1 320px' }, value: histPath, placeholder: T.pathPh, onChange: e => setHistPath(e.target.value) })),
|
|
1051
|
+
histList.length === 0
|
|
1052
|
+
? h('p', { className: 'ops-empty' }, T.fileNoHistory)
|
|
1053
|
+
: h('div', null, ...histList.map(backup => h('div', { key: backup, className: 'ops-row', style: { gridTemplateColumns: '1fr auto' } },
|
|
1054
|
+
h('span', { className: 'ops-mono', style: { fontSize: '12px' } }, backup.split('/').pop()),
|
|
1055
|
+
h('span', { style: { display: 'flex', gap: '6px', justifyContent: 'flex-end' } },
|
|
1056
|
+
h('button', { className: 'ops-btn ops-btn-sm', onClick: () => { void showDiff(backup) } }, T.fileDiff),
|
|
1057
|
+
h('button', { className: 'ops-btn ops-btn-sm', onClick: () => { void restoreVersion(backup) } }, T.fileRestore))))),
|
|
1058
|
+
histDiff ? h('pre', { className: 'ops-pre', style: { maxHeight: '240px', marginTop: '8px' } }, histDiff.diff) : null)))
|
|
1059
|
+
|
|
1060
|
+
const appsView = h('div', { style: { display: 'flex', flexDirection: 'column', gap: '12px' } },
|
|
1061
|
+
h('div', { className: 'ops-chips' }, (detailHost ? null : hostPicker(cHost, setCHost)),
|
|
1062
|
+
h('button', { className: 'ops-btn ops-btn-sm', onClick: () => { void loadInv(cHost || hosts[0]?.name, true) } }, busy === 'scan' ? T.rescanning : T.rescan)),
|
|
1063
|
+
h('div', { className: 'ops-card' },
|
|
1064
|
+
h('div', { className: 'ops-card-h' }, h('span', null, T.tabs[3]), h('span', { className: 'ops-chip' }, String((inv?.apps || []).length))),
|
|
1065
|
+
(inv?.apps || []).length === 0 ? h('p', { className: 'ops-empty' }, T.empty)
|
|
1066
|
+
: h('div', { className: 'ops-list' }, ...(inv.apps || []).map(app => h('div', { key: app.kind + app.name, className: 'ops-row' },
|
|
1067
|
+
h('span', null, h('span', { className: 'ops-chip', style: { marginRight: '6px' } }, app.kind), h('span', { className: 'ops-name' }, app.name)),
|
|
1068
|
+
h('span', { className: 'ops-dim' }, app.ports || app.status || ''),
|
|
1069
|
+
h('span', { className: app.status ? 'ops-ok' : 'ops-dim', style: { fontSize: '12px' } }, app.status || ''),
|
|
1070
|
+
h('span', { style: { display: 'flex', gap: '6px', justifyContent: 'flex-end' } },
|
|
1071
|
+
app.config ? h('button', { className: 'ops-btn ops-btn-sm', onClick: () => { void openFile(app.config, app.name) } }, T.configFile) : null,
|
|
1072
|
+
h('button', { className: 'ops-btn ops-btn-sm', disabled: busy === `act:${app.kind}:${app.name}:logs`, onClick: () => { void doAction(app.kind, app.name, 'logs') } }, busy === `act:${app.kind}:${app.name}:logs` ? T.reading : T.logs),
|
|
1073
|
+
app.kind === 'service' ? h('button', { className: 'ops-btn ops-btn-sm', disabled: busy === `act:${app.kind}:${app.name}:stop`, onClick: () => { void doAction(app.kind, app.name, 'stop') } }, T.stop) : null,
|
|
1074
|
+
app.kind !== 'java' ? h('button', { className: 'ops-btn ops-btn-sm', disabled: busy === `act:${app.kind}:${app.name}:restart`, onClick: () => { void doAction(app.kind, app.name, 'restart') } }, busy === `act:${app.kind}:${app.name}:restart` ? '…' : T.restart) : null))))),
|
|
1075
|
+
output ? h('pre', { className: 'ops-pre' }, output) : null,
|
|
1076
|
+
fileState ? h('div', { className: 'ops-card' },
|
|
1077
|
+
h('div', { className: 'ops-card-h' },
|
|
1078
|
+
h('span', null, `${T.configFile}: ${fileState.path}`),
|
|
1079
|
+
h('span', { style: { display: 'flex', gap: '6px' } },
|
|
1080
|
+
h('button', { className: 'ops-btn ops-btn-sm', onClick: () => setFileState(null) }, T.close2),
|
|
1081
|
+
h('button', { className: 'ops-btn ops-btn-primary ops-btn-sm', disabled: fileState.busy, onClick: () => { void saveFile() } }, fileState.busy ? '…' : T.saveFile))),
|
|
1082
|
+
fileState.loading ? h('p', { className: 'ops-empty' }, T.loadingFile) : null,
|
|
1083
|
+
h('div', { style: { padding: '10px 14px 0' } }, h('p', { className: 'ops-sub' }, T.editHint)),
|
|
1084
|
+
h('textarea', {
|
|
1085
|
+
className: 'ops-input',
|
|
1086
|
+
style: { minHeight: '260px', margin: '0 14px 12px', width: 'calc(100% - 28px)', fontFamily: 'ui-monospace,SFMono-Regular,Menlo,monospace', fontSize: '12px', lineHeight: 1.5 },
|
|
1087
|
+
value: fileState.content,
|
|
1088
|
+
onChange: e => setFileState({ ...fileState, content: e.target.value }),
|
|
1089
|
+
spellCheck: false,
|
|
1090
|
+
}),
|
|
1091
|
+
fileState.msg ? h('p', { className: 'ops-ok', style: { padding: '0 14px 12px', margin: 0, fontSize: '12px' } }, fileState.msg) : null) : null)
|
|
1092
|
+
|
|
1093
|
+
const checkView = h('div', { style: { display: 'flex', flexDirection: 'column', gap: '12px' } },
|
|
1094
|
+
h('div', { className: 'ops-chips' }, (detailHost ? null : hostPicker(cHost, setCHost))),
|
|
1095
|
+
h('div', { className: 'ops-grid2' },
|
|
1096
|
+
h('div', { className: 'ops-card' },
|
|
1097
|
+
h('div', { className: 'ops-card-h' }, h('span', null, T.diskScan),
|
|
1098
|
+
h('span', { className: 'ops-chips' },
|
|
1099
|
+
h('button', { className: 'ops-btn ops-btn-sm', onClick: () => { void loadDu(duPath.split('/').slice(0, -1).join('/') || '/') } }, T.up),
|
|
1100
|
+
h('button', { className: 'ops-btn ops-btn-primary ops-btn-sm', disabled: busy === 'du', onClick: () => { void loadDu() } }, busy === 'du' ? T.reading : T.scan))),
|
|
1101
|
+
h('div', { style: { padding: '10px 14px' } },
|
|
1102
|
+
h('input', { className: 'ops-input', value: duPath, onChange: e => setDuPath(e.target.value), onKeyDown: e => { if (e.key === 'Enter') void loadDu() } })),
|
|
1103
|
+
(duRows || []).length === 0 ? h('p', { className: 'ops-empty' }, busy === 'du' ? T.reading : T.empty)
|
|
1104
|
+
: h('div', { className: 'ops-list' }, ...duRows.map(row => h('div', { key: row.path, className: 'ops-row', style: { gridTemplateColumns: '90px 1fr auto' } },
|
|
1105
|
+
h('span', { className: 'ops-mono' }, row.size),
|
|
1106
|
+
h('span', { className: 'ops-mono', title: row.path }, row.path),
|
|
1107
|
+
h('button', { className: 'ops-btn ops-btn-sm', onClick: () => { setDuPath(row.path); void loadDu(row.path) } }, '→'))))),
|
|
1108
|
+
h('div', { className: 'ops-card' },
|
|
1109
|
+
h('div', { className: 'ops-card-h' }, h('span', null, T.process),
|
|
1110
|
+
h('span', { className: 'ops-chips' },
|
|
1111
|
+
h('button', { className: `ops-tab${psSort === 'cpu' ? ' on' : ''}`, onClick: () => { void loadPs('cpu') } }, T.byCpu),
|
|
1112
|
+
h('button', { className: `ops-tab${psSort === 'mem' ? ' on' : ''}`, onClick: () => { void loadPs('mem') } }, T.byMem),
|
|
1113
|
+
h('button', { className: 'ops-btn ops-btn-sm', disabled: busy === 'ps', onClick: () => { void loadPs() } }, busy === 'ps' ? T.reading : T.scan))),
|
|
1114
|
+
(psRows || []).length === 0 ? h('p', { className: 'ops-empty' }, busy === 'ps' ? T.reading : T.empty)
|
|
1115
|
+
: h('div', { className: 'ops-list' }, ...(psRows || []).map(row => h('div', { key: row.pid, className: 'ops-row', style: { gridTemplateColumns: '70px 60px 60px 1fr auto' } },
|
|
1116
|
+
h('span', { className: 'ops-mono' }, row.pid),
|
|
1117
|
+
h('span', { className: 'ops-mono' }, row.cpu + '%'),
|
|
1118
|
+
h('span', { className: 'ops-mono' }, row.mem + '%'),
|
|
1119
|
+
h('span', { className: 'ops-mono', title: row.cmd }, row.cmd),
|
|
1120
|
+
h('button', { className: 'ops-btn ops-btn-sm', disabled: busy === 'kill:' + row.pid, onClick: () => { void killPid(row.pid) } }, T.end)))))),
|
|
1121
|
+
h('div', { className: 'ops-card' },
|
|
1122
|
+
h('div', { className: 'ops-card-h' }, h('span', null, T.console),
|
|
1123
|
+
h('button', { className: 'ops-btn ops-btn-primary ops-btn-sm', disabled: busy === 'console', onClick: () => { void runConsole() } }, busy === 'console' ? T.reading : T.runCmd)),
|
|
1124
|
+
h('div', { className: 'ops-card-b' },
|
|
1125
|
+
h('div', { className: 'ops-chips' },
|
|
1126
|
+
h('input', { className: 'ops-input', style: { flex: '1 1 320px' }, value: consoleCmd, placeholder: T.cmdPh, onChange: e => setConsoleCmd(e.target.value), onKeyDown: e => { if (e.key === 'Enter') void runConsole() } })),
|
|
1127
|
+
consoleHistory.length ? h('div', { className: 'ops-chips' }, ...consoleHistory.slice(0, 6).map(cmd => h('button', { key: cmd, className: 'ops-btn ops-btn-sm', onClick: () => setConsoleCmd(cmd) }, cmd.length > 28 ? cmd.slice(0, 28) + '…' : cmd))) : null,
|
|
1128
|
+
h('pre', { className: 'ops-pre', style: { maxHeight: '30vh' } }, consoleOut || ''))),
|
|
1129
|
+
h('div', { className: 'ops-card' },
|
|
1130
|
+
h('div', { className: 'ops-card-h' }, T.ssl),
|
|
1131
|
+
h('div', { className: 'ops-card-b' },
|
|
1132
|
+
h('div', { className: 'ops-chips' },
|
|
1133
|
+
h('input', { className: 'ops-input', style: { flex: '1 1 220px' }, value: sslDomain, placeholder: 'example.com', onChange: e => setSslDomain(e.target.value), onKeyDown: e => { if (e.key === 'Enter') void checkSsl() } }),
|
|
1134
|
+
h('button', { className: 'ops-btn ops-btn-primary ops-btn-sm', disabled: busy === 'ssl', onClick: () => { void checkSsl() } }, busy === 'ssl' ? T.reading : T.checkSsl)),
|
|
1135
|
+
sslResult ? h('div', null,
|
|
1136
|
+
h('div', { className: 'ops-sub' }, `${sslResult.domain}: ${sslResult.subject || ''}`),
|
|
1137
|
+
h('div', { className: sslResult.daysLeft !== null && sslResult.daysLeft < 15 ? 'ops-bad' : 'ops-sub', style: { fontSize: '12px' } },
|
|
1138
|
+
sslResult.daysLeft === null ? T.noExpire : `${T.expireAt} ${sslResult.notAfter} · ${T.daysLeft} ${sslResult.daysLeft}`)) : null)))
|
|
1139
|
+
|
|
1140
|
+
const logsView = h('div', { style: { display: 'flex', flexDirection: 'column', gap: '12px' } },
|
|
1141
|
+
h('div', { className: 'ops-chips' }, (detailHost ? null : hostPicker(cHost, setCHost))),
|
|
1142
|
+
h('div', { className: 'ops-card' },
|
|
1143
|
+
h('div', { className: 'ops-card-h' }, h('span', null, T.logs),
|
|
1144
|
+
h('span', { className: 'ops-chips' },
|
|
1145
|
+
h('label', { className: 'ops-sub', style: { display: 'flex', gap: '6px', alignItems: 'center' } },
|
|
1146
|
+
h('input', { type: 'checkbox', checked: logAuto, onChange: e => setLogAuto(e.target.checked) }), T.auto),
|
|
1147
|
+
h('button', { className: 'ops-btn ops-btn-primary ops-btn-sm', disabled: busy === 'logs', onClick: () => { void loadLogs() } }, busy === 'logs' ? T.reading : T.load))),
|
|
1148
|
+
h('div', { className: 'ops-card-b' },
|
|
1149
|
+
h('div', { className: 'ops-chips' },
|
|
1150
|
+
h('input', { className: 'ops-input', style: { flex: '1 1 320px' }, value: logSource, placeholder: T.logSource, onChange: e => setLogSource(e.target.value), onKeyDown: e => { if (e.key === 'Enter') void loadLogs() } }),
|
|
1151
|
+
h('label', { className: 'ops-sub' }, T.lines,
|
|
1152
|
+
h('input', { className: 'ops-input', type: 'number', min: 20, max: 1000, value: logLines, style: { width: '90px' }, onChange: e => setLogLines(Number(e.target.value)) }))),
|
|
1153
|
+
h('pre', { className: 'ops-pre', style: { maxHeight: '55vh' } }, logText || (busy === 'logs' ? T.reading : '')))))
|
|
1154
|
+
|
|
1155
|
+
const filesView = h('div', { style: { display: 'flex', flexDirection: 'column', gap: '12px' } },
|
|
1156
|
+
h('div', { className: 'ops-chips' }, (detailHost ? null : hostPicker(cHost, setCHost))),
|
|
1157
|
+
h('div', { className: 'ops-card' },
|
|
1158
|
+
h('div', { className: 'ops-card-h' }, h('span', null, T.files + ' ' + fsPath),
|
|
1159
|
+
h('span', { className: 'ops-chips' },
|
|
1160
|
+
h('label', { className: 'ops-btn ops-btn-sm', style: { display: 'inline-flex', alignItems: 'center' } },
|
|
1161
|
+
T.upload,
|
|
1162
|
+
h('input', { type: 'file', style: { display: 'none' }, onChange: e => { void uploadFile(e.target.files?.[0]); e.target.value = '' } })),
|
|
1163
|
+
h('button', { className: 'ops-btn ops-btn-sm', onClick: () => { void fsMkdir() } }, T.newFolder))),
|
|
1164
|
+
h('div', { className: 'ops-card-b' },
|
|
1165
|
+
h('div', { className: 'ops-chips' },
|
|
1166
|
+
h('button', { className: 'ops-btn ops-btn-sm', onClick: () => { const up = fsPath.split('/').slice(0, -1).join('/') || '/'; void loadFiles(up) } }, T.up),
|
|
1167
|
+
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() } }),
|
|
1168
|
+
h('button', { className: 'ops-btn ops-btn-sm', disabled: fsBusy === 'list', onClick: () => { void loadFiles() } }, fsBusy === 'list' ? T.reading : T.refresh))),
|
|
1169
|
+
(fsEntries || []).length === 0 ? h('p', { className: 'ops-empty' }, fsBusy ? T.reading : T.empty)
|
|
1170
|
+
: h('div', { className: 'ops-list' }, ...(fsEntries || []).map(entry => h('div', { key: entry.path, className: 'ops-row', style: { gridTemplateColumns: '1fr 90px 140px auto' } },
|
|
1171
|
+
h('span', { style: { display: 'flex', alignItems: 'center', gap: '6px', minWidth: 0 } },
|
|
1172
|
+
h('span', { className: 'ops-chip' }, entry.dir ? 'DIR' : (entry.link ? 'LNK' : 'FILE')),
|
|
1173
|
+
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)),
|
|
1174
|
+
h('span', { className: 'ops-dim' }, entry.dir ? '—' : `${(entry.size / 1024).toFixed(entry.size > 1048576 ? 0 : 1)} KB`),
|
|
1175
|
+
h('span', { className: 'ops-dim' }, String(entry.mtime || '').replace('T', ' ')),
|
|
1176
|
+
h('span', { style: { display: 'flex', gap: '6px', justifyContent: 'flex-end' } },
|
|
1177
|
+
entry.dir
|
|
1178
|
+
? h('button', { className: 'ops-btn ops-btn-sm', onClick: () => { void loadFiles(entry.path) } }, T.open)
|
|
1179
|
+
: 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),
|
|
1180
|
+
h('button', { className: 'ops-btn ops-btn-sm', disabled: fsBusy === 'del:' + entry.path, onClick: () => { void fsDelete(entry.path) } }, T.del)))))),
|
|
1181
|
+
output ? h('pre', { className: 'ops-pre' }, output) : null)
|
|
1182
|
+
|
|
1183
|
+
const termKey = (event) => {
|
|
1184
|
+
if (!term?.id) return
|
|
1185
|
+
if (aiMode) {
|
|
1186
|
+
if (event.key === 'Escape') { event.preventDefault(); setAiMode(false); setAiDraft(''); return }
|
|
1187
|
+
if (event.key === 'Enter') { event.preventDefault(); void aiFill(aiDraft); return }
|
|
1188
|
+
if (event.key === 'Backspace') { event.preventDefault(); setAiDraft(current => current.slice(0, -1)); return }
|
|
1189
|
+
if (!event.ctrlKey && !event.metaKey && !event.altKey && event.key.length === 1) {
|
|
1190
|
+
event.preventDefault(); setAiDraft(current => current + event.key); return
|
|
1191
|
+
}
|
|
1192
|
+
return
|
|
1193
|
+
}
|
|
1194
|
+
if (event.key === '?' && !event.ctrlKey && !event.metaKey && !event.altKey) {
|
|
1195
|
+
event.preventDefault(); setAiMode(true); setAiDraft(''); return
|
|
1196
|
+
}
|
|
1197
|
+
const map = {
|
|
1198
|
+
Enter: '\r', Backspace: '\x7f', Tab: '\t', Escape: '\x1b',
|
|
1199
|
+
ArrowUp: '\x1b[A', ArrowDown: '\x1b[B', ArrowRight: '\x1b[C', ArrowLeft: '\x1b[D',
|
|
1200
|
+
Home: '\x1b[H', End: '\x1b[F', Delete: '\x1b[3~', PageUp: '\x1b[5~', PageDown: '\x1b[6~',
|
|
1201
|
+
}
|
|
1202
|
+
let data
|
|
1203
|
+
if (map[event.key]) data = map[event.key]
|
|
1204
|
+
else if (event.ctrlKey && event.key.length === 1) data = String.fromCharCode(event.key.toUpperCase().charCodeAt(0) - 64)
|
|
1205
|
+
else if (!event.metaKey && !event.altKey && event.key.length === 1) data = event.key
|
|
1206
|
+
if (data === undefined) return
|
|
1207
|
+
event.preventDefault()
|
|
1208
|
+
void sendKey(data)
|
|
1209
|
+
}
|
|
1210
|
+
|
|
1211
|
+
|
|
1212
|
+
const dhost = () => detailHost || cHost
|
|
1213
|
+
|
|
1214
|
+
const loadChannels = async () => {
|
|
1215
|
+
try { const data = await api('channels', {}, 20_000); setChannels(data.channels || []) } catch { setChannels([]) }
|
|
1216
|
+
}
|
|
1217
|
+
|
|
1218
|
+
const saveChannel = async () => {
|
|
1219
|
+
if (!/^https?:\/\//.test(channelForm.url.trim())) { setError(T.channelUrl); return }
|
|
1220
|
+
setChBusy('add')
|
|
1221
|
+
try {
|
|
1222
|
+
const data = await api('channels', { method: 'POST', body: JSON.stringify(channelForm) }, 20_000)
|
|
1223
|
+
setChannels(data.channels || [])
|
|
1224
|
+
setChannelForm({ type: 'feishu', name: '飞书群', url: '', events: ['critical', 'warning'] })
|
|
1225
|
+
} catch (e) { setError(String(e.message || e)) } finally { setChBusy('') }
|
|
1226
|
+
}
|
|
1227
|
+
|
|
1228
|
+
const testChannelUi = async (id) => {
|
|
1229
|
+
setChBusy('test:' + id)
|
|
1230
|
+
try {
|
|
1231
|
+
const result = await api('channels', { method: 'POST', body: JSON.stringify({ action: 'test', id }) }, 20_000)
|
|
1232
|
+
setNotice(result.ok ? T.channelSent : `发送失败:HTTP ${result.status || '?'}`)
|
|
1233
|
+
setTimeout(() => setNotice(''), 4000)
|
|
1234
|
+
} catch (e) { setError(String(e.message || e)) } finally { setChBusy('') }
|
|
1235
|
+
}
|
|
1236
|
+
|
|
1237
|
+
const removeChannelUi = async (id) => {
|
|
1238
|
+
if (!window.confirm(T.channelRemove + '?')) return
|
|
1239
|
+
try {
|
|
1240
|
+
const data = await api('channels', { method: 'POST', body: JSON.stringify({ action: 'remove', id }) })
|
|
1241
|
+
setChannels(data.channels || [])
|
|
1242
|
+
} catch (e) { setError(String(e.message || e)) }
|
|
1243
|
+
}
|
|
1244
|
+
|
|
1245
|
+
const loadHealth = async (host) => {
|
|
1246
|
+
if (!host) return
|
|
1247
|
+
setOpBusy('health')
|
|
1248
|
+
try { setHealth(await api(`health?host=${encodeURIComponent(host)}`, {}, 60_000)) }
|
|
1249
|
+
catch (e) { setError(String(e.message || e)) }
|
|
1250
|
+
finally { setOpBusy('') }
|
|
1251
|
+
}
|
|
1252
|
+
|
|
1253
|
+
const loadCerts = async (host) => {
|
|
1254
|
+
if (!host) return
|
|
1255
|
+
try { const data = await api(`certs?host=${encodeURIComponent(host)}`, {}, 60_000); setCerts(data.certs || []) }
|
|
1256
|
+
catch { setCerts([]) }
|
|
1257
|
+
}
|
|
1258
|
+
|
|
1259
|
+
const renewCertsNow = async (dryRun) => {
|
|
1260
|
+
setOpBusy('renew')
|
|
1261
|
+
try {
|
|
1262
|
+
const data = await api('certs', { method: 'POST', body: JSON.stringify({ host: dhost(), dryRun }) }, 10 * 60_000)
|
|
1263
|
+
setOpOut(data.output || '')
|
|
1264
|
+
setNotice(dryRun ? '预演完成' : '续期命令已执行')
|
|
1265
|
+
setTimeout(() => setNotice(''), 4000)
|
|
1266
|
+
} catch (e) { setError(String(e.message || e)) } finally { setOpBusy('') }
|
|
1267
|
+
}
|
|
1268
|
+
|
|
1269
|
+
const loadBackups = async (host) => {
|
|
1270
|
+
if (!host) return
|
|
1271
|
+
try { const data = await api(`backups?host=${encodeURIComponent(host)}`, {}, 30_000); setBackups(data.backups || []) }
|
|
1272
|
+
catch { setBackups([]) }
|
|
1273
|
+
}
|
|
1274
|
+
|
|
1275
|
+
const doBackup = async () => {
|
|
1276
|
+
setOpBusy('backup')
|
|
1277
|
+
setOpOut('')
|
|
1278
|
+
try {
|
|
1279
|
+
const payload = { host: dhost(), ...backupForm, keep: Number(backupForm.keep) || 7 }
|
|
1280
|
+
const record = await api('backups', { method: 'POST', body: JSON.stringify(payload) }, 25 * 60_000)
|
|
1281
|
+
setOpOut(record.ok ? `备份完成:${record.file}(${(record.size / 1024).toFixed(0)} KB,${(record.ms / 1000).toFixed(1)}s)` : `备份失败:${record.error}`)
|
|
1282
|
+
await loadBackups(dhost())
|
|
1283
|
+
} catch (e) { setError(String(e.message || e)) } finally { setOpBusy('') }
|
|
1284
|
+
}
|
|
1285
|
+
|
|
1286
|
+
const restoreBackupNow = async (id) => {
|
|
1287
|
+
if (!window.confirm(T.restoreWarn)) return
|
|
1288
|
+
setOpBusy('restore:' + id)
|
|
1289
|
+
try {
|
|
1290
|
+
const data = await api('backups', { method: 'POST', body: JSON.stringify({ host: dhost(), action: 'restore', id }) }, 25 * 60_000)
|
|
1291
|
+
setOpOut(data.ok ? '恢复完成' : `恢复失败:${data.output}`)
|
|
1292
|
+
await loadBackups(dhost())
|
|
1293
|
+
} catch (e) { setError(String(e.message || e)) } finally { setOpBusy('') }
|
|
1294
|
+
}
|
|
1295
|
+
|
|
1296
|
+
const removeBackupNow = async (id) => {
|
|
1297
|
+
if (!window.confirm('删除这条备份?')) return
|
|
1298
|
+
try {
|
|
1299
|
+
const data = await api('backups', { method: 'POST', body: JSON.stringify({ host: dhost(), action: 'remove', id }) }, 60_000)
|
|
1300
|
+
setBackups(data.backups || [])
|
|
1301
|
+
} catch (e) { setError(String(e.message || e)) }
|
|
1302
|
+
}
|
|
1303
|
+
|
|
1304
|
+
const loadCron = async (host) => {
|
|
1305
|
+
if (!host) return
|
|
1306
|
+
try { const data = await api(`cron?host=${encodeURIComponent(host)}`, {}, 30_000); setCronJobs(data.jobs || []) }
|
|
1307
|
+
catch { setCronJobs([]) }
|
|
1308
|
+
}
|
|
1309
|
+
|
|
1310
|
+
const addCronJob = async () => {
|
|
1311
|
+
if (!cronForm.command.trim()) return
|
|
1312
|
+
setOpBusy('cron')
|
|
1313
|
+
try {
|
|
1314
|
+
const schedule = cronForm.frequency === 'hourly'
|
|
1315
|
+
? { minute: cronForm.minute, hour: '*' }
|
|
1316
|
+
: cronForm.frequency === 'weekly'
|
|
1317
|
+
? { minute: cronForm.minute, hour: cronForm.hour, weekday: '1' }
|
|
1318
|
+
: { minute: cronForm.minute, hour: cronForm.hour }
|
|
1319
|
+
await api('cron', { method: 'POST', body: JSON.stringify({ host: dhost(), command: cronForm.command, ...schedule }) }, 60_000)
|
|
1320
|
+
setCronForm({ ...cronForm, command: '' })
|
|
1321
|
+
await loadCron(dhost())
|
|
1322
|
+
} catch (e) { setError(String(e.message || e)) } finally { setOpBusy('') }
|
|
1323
|
+
}
|
|
1324
|
+
|
|
1325
|
+
const removeCronJob = async (index) => {
|
|
1326
|
+
setOpBusy('cron')
|
|
1327
|
+
try {
|
|
1328
|
+
await api('cron', { method: 'POST', body: JSON.stringify({ host: dhost(), action: 'remove', index }) }, 60_000)
|
|
1329
|
+
await loadCron(dhost())
|
|
1330
|
+
} catch (e) { setError(String(e.message || e)) } finally { setOpBusy('') }
|
|
1331
|
+
}
|
|
1332
|
+
|
|
1333
|
+
const loadDeploys = async (host) => {
|
|
1334
|
+
if (!host) return
|
|
1335
|
+
try { const data = await api(`deploy?host=${encodeURIComponent(host)}`, {}, 30_000); setDeployJobs(data.jobs || []) }
|
|
1336
|
+
catch { setDeployJobs([]) }
|
|
1337
|
+
}
|
|
1338
|
+
|
|
1339
|
+
const saveDeployJob = async () => {
|
|
1340
|
+
setOpBusy('deploy-save')
|
|
1341
|
+
try {
|
|
1342
|
+
const data = await api('deploy', { method: 'POST', body: JSON.stringify({ host: dhost(), action: 'save', ...deployForm }) }, 60_000)
|
|
1343
|
+
setDeployJobs(data.jobs || [])
|
|
1344
|
+
} catch (e) { setError(String(e.message || e)) } finally { setOpBusy('') }
|
|
1345
|
+
}
|
|
1346
|
+
|
|
1347
|
+
const runDeployJob = async (id) => {
|
|
1348
|
+
setOpBusy('deploy:' + id)
|
|
1349
|
+
setOpOut('')
|
|
1350
|
+
try {
|
|
1351
|
+
const data = await api('deploy', { method: 'POST', body: JSON.stringify({ host: dhost(), action: 'run', id }) }, 30 * 60_000)
|
|
1352
|
+
setOpOut((data.ok ? '发布成功' : `发布失败:${data.error || ''}${data.rolledBack ? '(已回滚)' : ''}`)
|
|
1353
|
+
+ '\n' + (data.steps || []).map(step => `[${step.ok ? '✓' : '✗'}] ${step.label}\n${step.output}`).join('\n\n'))
|
|
1354
|
+
} catch (e) { setError(String(e.message || e)) } finally { setOpBusy('') }
|
|
1355
|
+
}
|
|
1356
|
+
|
|
1357
|
+
const loadHistory = async () => {
|
|
1358
|
+
if (!histPath.trim()) return
|
|
1359
|
+
setOpBusy('history')
|
|
1360
|
+
try {
|
|
1361
|
+
const data = await api(`file-history?path=${encodeURIComponent(histPath.trim())}&host=${encodeURIComponent(dhost())}`, {}, 30_000)
|
|
1362
|
+
setHistList(data.backups || [])
|
|
1363
|
+
setHistDiff(null)
|
|
1364
|
+
} catch (e) { setError(String(e.message || e)) } finally { setOpBusy('') }
|
|
1365
|
+
}
|
|
1366
|
+
|
|
1367
|
+
const showDiff = async (backup) => {
|
|
1368
|
+
try {
|
|
1369
|
+
const data = await api('file-history', { method: 'POST', body: JSON.stringify({ host: dhost(), path: histPath.trim(), backup }) }, 30_000)
|
|
1370
|
+
setHistDiff({ backup, diff: data.diff || '(无差异)' })
|
|
1371
|
+
} catch (e) { setError(String(e.message || e)) }
|
|
1372
|
+
}
|
|
1373
|
+
|
|
1374
|
+
const restoreVersion = async (backup) => {
|
|
1375
|
+
if (!window.confirm(`${T.fileRestore}?`)) return
|
|
1376
|
+
try {
|
|
1377
|
+
const data = await api('file-history', { method: 'POST', body: JSON.stringify({ host: dhost(), path: histPath.trim(), action: 'restore', backup }) }, 60_000)
|
|
1378
|
+
setNotice(data.ok ? '已回滚' : '回滚失败')
|
|
1379
|
+
setTimeout(() => setNotice(''), 3000)
|
|
1380
|
+
await loadHistory()
|
|
1381
|
+
} catch (e) { setError(String(e.message || e)) }
|
|
1382
|
+
}
|
|
1383
|
+
|
|
1384
|
+
const loadMonitors = async (host) => {
|
|
1385
|
+
if (!host) return
|
|
1386
|
+
try {
|
|
1387
|
+
const data = await api(`monitors?host=${encodeURIComponent(host)}`, {}, 20_000)
|
|
1388
|
+
setMonitors(data.monitors || [])
|
|
1389
|
+
} catch { setMonitors([]) }
|
|
1390
|
+
}
|
|
1391
|
+
|
|
1392
|
+
const saveMonitor = async () => {
|
|
1393
|
+
const needsScript = monForm.type === 'script'
|
|
1394
|
+
if (needsScript ? !monForm.script.trim() : !monForm.target.trim()) {
|
|
1395
|
+
setError(needsScript ? T.monScript : T.monTarget)
|
|
1396
|
+
return
|
|
1397
|
+
}
|
|
1398
|
+
setMonBusy('add')
|
|
1399
|
+
try {
|
|
1400
|
+
const payload = monEditId
|
|
1401
|
+
? { host: detailHost || cHost, action: 'update', id: monEditId, ...monForm }
|
|
1402
|
+
: { host: detailHost || cHost, ...monForm }
|
|
1403
|
+
const data = await api('monitors', { method: 'POST', body: JSON.stringify(payload) }, 45_000)
|
|
1404
|
+
setMonitors(data.monitors || [])
|
|
1405
|
+
setMonForm({ type: 'http', target: '', label: '', intervalMinutes: 5, language: 'shell', script: '' })
|
|
1406
|
+
setMonEditId('')
|
|
1407
|
+
} catch (e) { setError(String(e.message || e)) } finally { setMonBusy('') }
|
|
1408
|
+
}
|
|
1409
|
+
|
|
1410
|
+
const editMonitor = (monitor) => {
|
|
1411
|
+
setMonEditId(monitor.id)
|
|
1412
|
+
setMonForm({
|
|
1413
|
+
type: monitor.type,
|
|
1414
|
+
target: monitor.target || '',
|
|
1415
|
+
label: monitor.label || '',
|
|
1416
|
+
intervalMinutes: monitor.intervalMinutes || 5,
|
|
1417
|
+
language: monitor.language || 'shell',
|
|
1418
|
+
script: monitor.script || '',
|
|
1419
|
+
})
|
|
1420
|
+
}
|
|
1421
|
+
|
|
1422
|
+
const testMonitor = async (id) => {
|
|
1423
|
+
setMonBusy('test:' + id)
|
|
1424
|
+
try {
|
|
1425
|
+
await api('monitors', { method: 'POST', body: JSON.stringify({ host: detailHost || cHost, action: 'test', id }) }, 30_000)
|
|
1426
|
+
await loadMonitors(detailHost || cHost)
|
|
1427
|
+
} catch (e) { setError(String(e.message || e)) } finally { setMonBusy('') }
|
|
1428
|
+
}
|
|
1429
|
+
|
|
1430
|
+
const removeMonitor = async (id) => {
|
|
1431
|
+
if (!window.confirm(T.monRemove + '?')) return
|
|
1432
|
+
try {
|
|
1433
|
+
const data = await api('monitors', { method: 'POST', body: JSON.stringify({ host: detailHost || cHost, action: 'remove', id }) })
|
|
1434
|
+
setMonitors(data.monitors || [])
|
|
1435
|
+
} catch (e) { setError(String(e.message || e)) }
|
|
1436
|
+
}
|
|
1437
|
+
|
|
1438
|
+
const openHost = (name) => {
|
|
1439
|
+
setDetailHost(name)
|
|
1440
|
+
setCHost(name)
|
|
1441
|
+
setMHost(name)
|
|
1442
|
+
setDetailTab('summary')
|
|
1443
|
+
void loadMonitors(name)
|
|
1444
|
+
void loadHealth(name)
|
|
1445
|
+
void loadCerts(name)
|
|
1446
|
+
}
|
|
1447
|
+
|
|
1448
|
+
const focusTerm = () => { const el = document.getElementById('ops-term'); if (el) el.focus() }
|
|
1449
|
+
|
|
1450
|
+
const askHost = async () => {
|
|
1451
|
+
const question = askQuestion.trim()
|
|
1452
|
+
if (!question || askBusy) return
|
|
1453
|
+
const stamp = Date.now()
|
|
1454
|
+
const replyId = 'a' + stamp
|
|
1455
|
+
setAskLog(current => [...current, { id: 'u' + stamp, role: 'user', text: question, at: stamp },
|
|
1456
|
+
{ id: replyId, role: 'assistant', text: '', at: stamp, thinking: true }])
|
|
1457
|
+
setAskQuestion('')
|
|
1458
|
+
setAskBusy(true)
|
|
1459
|
+
try {
|
|
1460
|
+
const data = await api('ask', { method: 'POST', body: JSON.stringify({ host: cHost || hosts[0]?.name, question }) }, timeoutFor('action') * 3)
|
|
1461
|
+
setAskLog(current => current.map(message => message.id === replyId
|
|
1462
|
+
? { id: replyId, role: 'assistant', text: data.answer || '(没有回答)', at: Date.now(), transcript: data.transcript || [], needsConfirm: data.needsConfirm }
|
|
1463
|
+
: message))
|
|
1464
|
+
} catch (e) {
|
|
1465
|
+
setAskLog(current => current.map(message => message.id === replyId
|
|
1466
|
+
? { id: replyId, role: 'assistant', text: String(e.message || e), at: Date.now(), transcript: [] }
|
|
1467
|
+
: message))
|
|
1468
|
+
} finally { setAskBusy(false) }
|
|
1469
|
+
}
|
|
1470
|
+
|
|
1471
|
+
const copyText = async (text) => {
|
|
1472
|
+
try {
|
|
1473
|
+
await navigator.clipboard.writeText(text)
|
|
1474
|
+
setChatNotice(T.copied)
|
|
1475
|
+
setTimeout(() => setChatNotice(''), 1500)
|
|
1476
|
+
} catch { /* clipboard unavailable */ }
|
|
1477
|
+
}
|
|
1478
|
+
|
|
1479
|
+
const runNeedsConfirm = async (command) => {
|
|
1480
|
+
if (!term?.id || term.closed) { setError(T.aiNeedTerm); return }
|
|
1481
|
+
await sendKey(command + '\r')
|
|
1482
|
+
focusTerm()
|
|
1483
|
+
}
|
|
1484
|
+
|
|
1485
|
+
const generateCommand = async () => {
|
|
1486
|
+
const intent = aiIntent.trim()
|
|
1487
|
+
if (!intent) return
|
|
1488
|
+
setAiBusy(true)
|
|
1489
|
+
try {
|
|
1490
|
+
const data = await api('ai-command', { method: 'POST', body: JSON.stringify({ host: cHost || hosts[0]?.name, intent }) }, 60_000)
|
|
1491
|
+
setAiResult(data)
|
|
1492
|
+
setError('')
|
|
1493
|
+
} catch (e) { setAiResult({ error: String(e.message || e) }) } finally { setAiBusy(false) }
|
|
1494
|
+
}
|
|
1495
|
+
|
|
1496
|
+
const aiFill = async (intent) => {
|
|
1497
|
+
const text = String(intent || '').trim()
|
|
1498
|
+
if (!text) { setAiMode(false); return }
|
|
1499
|
+
setBusy('aiFill')
|
|
1500
|
+
try {
|
|
1501
|
+
const data = await api('ai-command', { method: 'POST', body: JSON.stringify({ host: cHost || hosts[0]?.name, intent: text }) }, 60_000)
|
|
1502
|
+
await sendKey(data.command)
|
|
1503
|
+
setNotice(`${T.aiFilled}:${data.command}`)
|
|
1504
|
+
setTimeout(() => setNotice(''), 5000)
|
|
1505
|
+
} catch (e) { setError(String(e.message || e)) } finally { setBusy(''); setAiMode(false); setAiDraft(''); focusTerm() }
|
|
1506
|
+
}
|
|
1507
|
+
|
|
1508
|
+
const runGenerated = async () => {
|
|
1509
|
+
if (!aiResult?.command) return
|
|
1510
|
+
if (!term?.id || term.closed) { setError(T.aiNeedTerm); return }
|
|
1511
|
+
if (aiResult.dangerous && !window.confirm(T.risk + '\n\n' + aiResult.command)) return
|
|
1512
|
+
await sendKey(aiResult.command + '\r')
|
|
1513
|
+
setAiResult(null)
|
|
1514
|
+
setAiIntent('')
|
|
1515
|
+
focusTerm()
|
|
1516
|
+
}
|
|
1517
|
+
|
|
1518
|
+
const quickCommands = (Array.isArray(config.quickCommands) && config.quickCommands.length > 0)
|
|
1519
|
+
? config.quickCommands
|
|
1520
|
+
: ['df -h', 'free -h', 'uptime', 'systemctl --failed', 'docker ps', 'tail -n 30 /var/log/messages']
|
|
1521
|
+
|
|
1522
|
+
const terminalView = h('div', { style: { display: 'flex', flexDirection: 'column', gap: '10px' } },
|
|
1523
|
+
h('div', { className: 'ops-chips' },
|
|
1524
|
+
(detailHost ? null : hostPicker(cHost, setCHost)),
|
|
1525
|
+
term?.id
|
|
1526
|
+
? h('span', { className: term.closed ? 'ops-chip' : 'ops-chip ops-ok' }, term.closed ? '已断开' : '已连接')
|
|
1527
|
+
: (busy === 'term' ? h('span', { className: 'ops-chip' }, T.connecting) : null),
|
|
1528
|
+
term?.id
|
|
1529
|
+
? h('button', { className: 'ops-btn ops-btn-sm', onClick: () => { void closeTerm() } }, T.closeTerm)
|
|
1530
|
+
: h('button', { className: 'ops-btn ops-btn-primary ops-btn-sm', disabled: busy === 'term', onClick: () => { void openTerm() } }, busy === 'term' ? T.connecting : T.openTerm)),
|
|
1531
|
+
h('p', { className: 'ops-sub', style: { margin: 0 } }, T.termHint),
|
|
1532
|
+
aiMode
|
|
1533
|
+
? h('div', { className: 'ops-card', style: { borderColor: 'var(--dsw-alias-accent,#4c8dff)' } },
|
|
1534
|
+
h('div', { className: 'ops-card-b' },
|
|
1535
|
+
h('div', { className: 'ops-chips' },
|
|
1536
|
+
h('span', { className: 'ops-chip ops-ok' }, T.aiMode),
|
|
1537
|
+
h('span', { className: 'ops-mono' }, aiDraft || '…'),
|
|
1538
|
+
h('span', { className: 'ops-dim' }, T.aiModeHint))))
|
|
1539
|
+
: null,
|
|
1540
|
+
h('div', {
|
|
1541
|
+
style: {
|
|
1542
|
+
height: '58vh',
|
|
1543
|
+
background: '#0b0e11',
|
|
1544
|
+
border: '1px solid var(--dsw-alias-border,#3a3f45)',
|
|
1545
|
+
borderRadius: '10px',
|
|
1546
|
+
overflow: 'auto',
|
|
1547
|
+
cursor: 'text',
|
|
1548
|
+
position: 'relative',
|
|
1549
|
+
},
|
|
1550
|
+
onClick: focusTerm,
|
|
1551
|
+
},
|
|
1552
|
+
term?.id
|
|
1553
|
+
? h('pre', {
|
|
1554
|
+
id: 'ops-term',
|
|
1555
|
+
tabIndex: 0,
|
|
1556
|
+
onKeyDown: termKey,
|
|
1557
|
+
style: {
|
|
1558
|
+
margin: 0,
|
|
1559
|
+
padding: '12px 14px',
|
|
1560
|
+
color: '#d7e2ea',
|
|
1561
|
+
outline: 'none',
|
|
1562
|
+
whiteSpace: 'pre-wrap',
|
|
1563
|
+
wordBreak: 'break-all',
|
|
1564
|
+
fontFamily: 'ui-monospace,SFMono-Regular,Menlo,monospace',
|
|
1565
|
+
fontSize: '12.5px',
|
|
1566
|
+
lineHeight: 1.5,
|
|
1567
|
+
minHeight: '100%',
|
|
1568
|
+
boxSizing: 'border-box',
|
|
1569
|
+
},
|
|
1570
|
+
}, stripAnsi(term.output || '') + (term.closed ? '' : '█'))
|
|
1571
|
+
: h('div', { style: { height: '100%', display: 'flex', flexDirection: 'column', alignItems: 'center', justifyContent: 'center', gap: '12px' } },
|
|
1572
|
+
h('button', { className: 'ops-btn ops-btn-primary', disabled: busy === 'term', onClick: () => { void openTerm() } },
|
|
1573
|
+
busy === 'term' ? T.connecting : `${T.clickConnect} ${cHost || hosts[0]?.name || ''}`),
|
|
1574
|
+
h('p', { className: 'ops-sub', style: { margin: 0, maxWidth: '420px', textAlign: 'center' } }, T.tip))),
|
|
1575
|
+
h('div', { className: 'ops-card' },
|
|
1576
|
+
h('div', { className: 'ops-card-h' }, h('span', null, T.aiBar),
|
|
1577
|
+
aiResult?.model ? h('span', { className: 'ops-chip' }, `${T.aiModel} ${aiResult.model}`) : null),
|
|
1578
|
+
h('div', { className: 'ops-card-b' },
|
|
1579
|
+
h('div', { className: 'ops-chips' },
|
|
1580
|
+
h('input', {
|
|
1581
|
+
className: 'ops-input',
|
|
1582
|
+
style: { flex: '1 1 320px' },
|
|
1583
|
+
value: aiIntent,
|
|
1584
|
+
placeholder: T.aiPh,
|
|
1585
|
+
onChange: e => setAiIntent(e.target.value),
|
|
1586
|
+
onKeyDown: e => { if (e.key === 'Enter') void generateCommand() },
|
|
1587
|
+
}),
|
|
1588
|
+
h('button', { className: 'ops-btn ops-btn-primary ops-btn-sm', disabled: aiBusy, onClick: () => { void generateCommand() } },
|
|
1589
|
+
aiBusy ? T.regenerating : T.gen)),
|
|
1590
|
+
aiResult?.error ? h('p', { className: 'ops-err', style: { margin: 0 } }, aiResult.error) : null,
|
|
1591
|
+
aiResult?.command ? h('div', null,
|
|
1592
|
+
aiResult.explanation ? h('p', { className: 'ops-sub', style: { margin: '0 0 6px' } }, aiResult.explanation) : null,
|
|
1593
|
+
h('pre', { className: 'ops-pre', style: { margin: '0 0 8px' } }, aiResult.command),
|
|
1594
|
+
aiResult.dangerous ? h('p', { className: 'ops-warn', style: { margin: '0 0 8px', fontSize: '12px' } }, T.risk) : null,
|
|
1595
|
+
h('div', { className: 'ops-chips' },
|
|
1596
|
+
h('button', { className: 'ops-btn ops-btn-primary ops-btn-sm', onClick: () => { void runGenerated() } }, T.exec),
|
|
1597
|
+
h('button', { className: 'ops-btn ops-btn-sm', disabled: aiBusy, onClick: () => { void generateCommand() } }, T.gen),
|
|
1598
|
+
h('button', { className: 'ops-btn ops-btn-sm', onClick: () => setAiResult(null) }, T.discard))) : null)),
|
|
1599
|
+
|
|
1600
|
+
term?.id && !term.closed
|
|
1601
|
+
? h('div', { className: 'ops-chips' },
|
|
1602
|
+
h('span', { className: 'ops-chip' }, T.quickCmds),
|
|
1603
|
+
...quickCommands.map(cmd => h('button', { key: cmd, className: 'ops-btn ops-btn-sm', onClick: () => { void sendKey(cmd + '\r'); focusTerm() } }, cmd)))
|
|
1604
|
+
: null)
|
|
1605
|
+
|
|
1606
|
+
React.useEffect(() => {
|
|
1607
|
+
const el = document.getElementById('ops-chat')
|
|
1608
|
+
if (el) el.scrollTop = el.scrollHeight
|
|
1609
|
+
}, [askLog])
|
|
1610
|
+
|
|
1611
|
+
const messageView = (message) => {
|
|
1612
|
+
const time = new Date(message.at).toLocaleTimeString('zh-CN', { hour: '2-digit', minute: '2-digit' })
|
|
1613
|
+
const bubble = h('div', { className: 'ops-bubble' },
|
|
1614
|
+
message.thinking ? (message.text || T.thinking) : message.text,
|
|
1615
|
+
message.needsConfirm
|
|
1616
|
+
? h('div', { style: { marginTop: '8px' } },
|
|
1617
|
+
h('div', { className: 'ops-warn', style: { fontSize: '12px', marginBottom: '4px' } }, T.needConfirm),
|
|
1618
|
+
h('code', { className: 'ops-mono' }, message.needsConfirm),
|
|
1619
|
+
h('button', { className: 'ops-btn ops-btn-sm', style: { marginLeft: '8px' }, onClick: () => { void runNeedsConfirm(message.needsConfirm) } }, T.runIt))
|
|
1620
|
+
: null,
|
|
1621
|
+
(message.transcript || []).length > 0
|
|
1622
|
+
? h('details', { style: { marginTop: '8px' } },
|
|
1623
|
+
h('summary', { className: 'ops-dim', style: { cursor: 'pointer', fontSize: '12px' } }, `${T.askedCmds} (${message.transcript.length})`),
|
|
1624
|
+
...message.transcript.map((row, index) => h('div', { key: index, style: { marginTop: '6px' } },
|
|
1625
|
+
h('div', { className: 'ops-mono', style: { fontSize: '12px' } }, `$ ${row.command}`),
|
|
1626
|
+
h('pre', { className: 'ops-pre', style: { maxHeight: '160px', marginTop: '4px' } }, row.output || ''))))
|
|
1627
|
+
: null)
|
|
1628
|
+
|
|
1629
|
+
const meta = h('div', { className: 'ops-meta' },
|
|
1630
|
+
h('span', null, time),
|
|
1631
|
+
message.role === 'assistant' && !message.thinking
|
|
1632
|
+
? h('button', { className: 'ops-copy', onClick: () => { void copyText(message.text) } }, T.copy)
|
|
1633
|
+
: null)
|
|
1634
|
+
|
|
1635
|
+
return h('div', { key: message.id, className: `ops-msg ${message.role === 'user' ? 'user' : 'ai'}` },
|
|
1636
|
+
bubble,
|
|
1637
|
+
meta)
|
|
1638
|
+
}
|
|
1639
|
+
|
|
1640
|
+
const assistantView = h('div', { style: { display: 'flex', flexDirection: 'column', gap: '10px' } },
|
|
1641
|
+
h('div', { className: 'ops-chips' },
|
|
1642
|
+
hostPicker(cHost, setCHost),
|
|
1643
|
+
h('span', { className: 'ops-chip' }, T.aiName),
|
|
1644
|
+
chatNotice ? h('span', { className: 'ops-ok', style: { fontSize: '12px' } }, chatNotice) : null),
|
|
1645
|
+
h('div', { className: 'ops-chat', id: 'ops-chat' },
|
|
1646
|
+
askLog.length === 0
|
|
1647
|
+
? h('div', { style: { margin: 'auto', textAlign: 'center' } },
|
|
1648
|
+
h('p', { className: 'ops-sub', style: { margin: 0 } }, T.askPh),
|
|
1649
|
+
h('p', { className: 'ops-dim', style: { marginTop: '6px', fontSize: '12px' } }, '例如:mysql 运行了吗 / 磁盘还剩多少 / 谁在占 CPU'))
|
|
1650
|
+
: askLog.map(messageView)),
|
|
1651
|
+
h('div', { className: 'ops-composer' },
|
|
1652
|
+
h('input', {
|
|
1653
|
+
className: 'ops-input',
|
|
1654
|
+
style: { flex: '1 1 320px' },
|
|
1655
|
+
value: askQuestion,
|
|
1656
|
+
placeholder: T.askPh,
|
|
1657
|
+
onChange: e => setAskQuestion(e.target.value),
|
|
1658
|
+
onKeyDown: e => { if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); void askHost() } },
|
|
1659
|
+
}),
|
|
1660
|
+
h('button', { className: 'ops-btn ops-btn-primary', disabled: askBusy, onClick: () => { void askHost() } },
|
|
1661
|
+
askBusy ? T.thinking : T.send)))
|
|
1662
|
+
|
|
1663
|
+
const settingsView = h('div', { style: { display: 'flex', flexDirection: 'column', gap: '12px' } },
|
|
1664
|
+
h('div', { className: 'ops-card' },
|
|
1665
|
+
h('div', { className: 'ops-card-h' }, h('span', null, T.patrol), notice ? h('span', { className: 'ops-ok' }, notice) : null),
|
|
1666
|
+
h('div', { className: 'ops-card-b' },
|
|
1667
|
+
h('div', { className: 'ops-chips' },
|
|
1668
|
+
h('label', { className: 'ops-sub', style: { display: 'flex', gap: '6px', alignItems: 'center' } },
|
|
1669
|
+
h('input', { type: 'checkbox', checked: config.enabled !== false, onChange: e => setConfig({ ...config, enabled: e.target.checked }) }), T.enabled),
|
|
1670
|
+
h('label', { className: 'ops-sub' }, T.interval,
|
|
1671
|
+
h('input', { className: 'ops-input', type: 'number', min: 1, max: 1440, value: config.intervalMinutes ?? 10, style: { width: '80px' }, onChange: e => setConfig({ ...config, intervalMinutes: Number(e.target.value) }) })),
|
|
1672
|
+
h('label', { className: 'ops-sub' }, T.metricsEvery,
|
|
1673
|
+
h('input', { className: 'ops-input', type: 'number', min: 1, max: 60, value: config.metricsMinutes ?? 5, style: { width: '80px' }, onChange: e => setConfig({ ...config, metricsMinutes: Number(e.target.value) }) })),
|
|
1674
|
+
h('label', { className: 'ops-sub' }, T.diskWarn,
|
|
1675
|
+
h('input', { className: 'ops-input', type: 'number', min: 50, max: 99, value: config.diskWarnPercent ?? 90, style: { width: '80px' }, onChange: e => setConfig({ ...config, diskWarnPercent: Number(e.target.value) }) })),
|
|
1676
|
+
h('label', { className: 'ops-sub' }, T.timeoutSec,
|
|
1677
|
+
h('input', { className: 'ops-input', type: 'number', min: 5, max: 300, value: config.timeoutSec ?? 25, style: { width: '80px' }, onChange: e => setConfig({ ...config, timeoutSec: Number(e.target.value) }) })),
|
|
1678
|
+
h('label', { className: 'ops-sub' }, T.scanSec,
|
|
1679
|
+
h('input', { className: 'ops-input', type: 'number', min: 10, max: 600, value: config.scanSec ?? 90, style: { width: '80px' }, onChange: e => setConfig({ ...config, scanSec: Number(e.target.value) }) })),
|
|
1680
|
+
h('label', { className: 'ops-sub' }, T.actionSec,
|
|
1681
|
+
h('input', { className: 'ops-input', type: 'number', min: 10, max: 600, value: config.actionSec ?? 45, style: { width: '80px' }, onChange: e => setConfig({ ...config, actionSec: Number(e.target.value) }) })),
|
|
1682
|
+
h('button', { className: 'ops-btn ops-btn-primary ops-btn-sm', onClick: () => { void saveConfig() } }, T.save)))),
|
|
1683
|
+
h('div', { className: 'ops-card' },
|
|
1684
|
+
h('div', { className: 'ops-card-h' }, h('span', null, T.aiSettings),
|
|
1685
|
+
h('button', { className: 'ops-btn ops-btn-primary ops-btn-sm', onClick: () => { void saveConfig() } }, T.aiSave)),
|
|
1686
|
+
h('div', { className: 'ops-card-b' },
|
|
1687
|
+
h('div', { className: 'ops-chips' },
|
|
1688
|
+
h('label', { className: 'ops-sub', style: { display: 'flex', gap: '6px', alignItems: 'center' } },
|
|
1689
|
+
h('input', { type: 'checkbox', checked: aiModels.aiEnabled !== false, onChange: e => setAiModels({ ...aiModels, aiEnabled: e.target.checked }) }),
|
|
1690
|
+
T.aiOn)),
|
|
1691
|
+
h('select', {
|
|
1692
|
+
className: 'ops-input',
|
|
1693
|
+
value: aiModels.aiProvider && aiModels.aiModel ? `${aiModels.aiProvider}|${aiModels.aiModel}` : '',
|
|
1694
|
+
onChange: e => {
|
|
1695
|
+
const value = e.target.value
|
|
1696
|
+
const [provider, model] = value.split('|')
|
|
1697
|
+
setAiModels({ ...aiModels, aiProvider: provider || '', aiModel: model || '' })
|
|
1698
|
+
},
|
|
1699
|
+
},
|
|
1700
|
+
h('option', { value: '' }, `${T.aiFollow}${aiModels.defaultSelection ? ` (${aiModels.defaultSelection.provider}/${aiModels.defaultSelection.model})` : ''}`),
|
|
1701
|
+
...(aiModels.providers || []).map(provider => h('optgroup', { key: provider.id, label: provider.name || provider.id },
|
|
1702
|
+
...(provider.models || []).map(model => h('option', { key: `${provider.id}|${model.id}`, value: `${provider.id}|${model.id}` }, model.name || model.id))))),
|
|
1703
|
+
h('p', { className: 'ops-sub', style: { margin: 0 } }, T.aiPrivacy),
|
|
1704
|
+
aiModels.defaultSelection
|
|
1705
|
+
? h('p', { className: 'ops-dim', style: { margin: 0, fontSize: '12px' } }, `${T.aiCurrent}: ${(aiModels.aiProvider && aiModels.aiModel) ? `${aiModels.aiProvider}/${aiModels.aiModel}` : `${aiModels.defaultSelection.provider}/${aiModels.defaultSelection.model}`}`)
|
|
1706
|
+
: null)),
|
|
1707
|
+
h('div', { className: 'ops-card' },
|
|
1708
|
+
h('div', { className: 'ops-card-h' }, h('span', null, T.channels)),
|
|
1709
|
+
h('div', { className: 'ops-card-b' },
|
|
1710
|
+
channels.length === 0
|
|
1711
|
+
? h('p', { className: 'ops-empty' }, T.channelEmpty)
|
|
1712
|
+
: h('div', null, ...channels.map(channel => h('div', { key: channel.id, className: 'ops-row', style: { gridTemplateColumns: '1fr 1.4fr auto' } },
|
|
1713
|
+
h('span', { className: 'ops-name' }, channel.name || channel.type),
|
|
1714
|
+
h('span', { className: 'ops-mono', style: { fontSize: '12px', overflow: 'hidden', textOverflow: 'ellipsis' } },
|
|
1715
|
+
`${channel.type} · ${String(channel.url).replace(/^(https?:\/\/[^/]+).*/, '$1')}/… · ${(channel.events || []).join('/')}`),
|
|
1716
|
+
h('span', { style: { display: 'flex', gap: '6px', justifyContent: 'flex-end' } },
|
|
1717
|
+
h('button', { className: 'ops-btn ops-btn-sm', disabled: chBusy === 'test:' + channel.id, onClick: () => { void testChannelUi(channel.id) } }, chBusy === 'test:' + channel.id ? T.reading : T.channelTest),
|
|
1718
|
+
h('button', { className: 'ops-btn ops-btn-sm', onClick: () => { void removeChannelUi(channel.id) } }, T.channelRemove))))),
|
|
1719
|
+
h('div', { className: 'ops-chips', style: { marginTop: '10px' } },
|
|
1720
|
+
h('select', { className: 'ops-input', style: { width: '110px' }, value: channelForm.type, onChange: e => setChannelForm({ ...channelForm, type: e.target.value }) },
|
|
1721
|
+
h('option', { value: 'feishu' }, '飞书'),
|
|
1722
|
+
h('option', { value: 'dingtalk' }, '钉钉'),
|
|
1723
|
+
h('option', { value: 'wecom' }, '企业微信'),
|
|
1724
|
+
h('option', { value: 'webhook' }, '自定义')),
|
|
1725
|
+
h('input', { className: 'ops-input', style: { width: '120px' }, value: channelForm.name, placeholder: T.channelName, onChange: e => setChannelForm({ ...channelForm, name: e.target.value }) }),
|
|
1726
|
+
h('input', { className: 'ops-input', style: { flex: '1 1 280px' }, value: channelForm.url, placeholder: 'https://open.feishu.cn/open-apis/bot/v2/hook/…', onChange: e => setChannelForm({ ...channelForm, url: e.target.value }) })),
|
|
1727
|
+
h('div', { className: 'ops-chips', style: { marginTop: '8px' } },
|
|
1728
|
+
h('span', { className: 'ops-chip' }, T.channelEvents),
|
|
1729
|
+
...['critical', 'warning', 'info'].map((level, index) => h('button', {
|
|
1730
|
+
key: level,
|
|
1731
|
+
className: `ops-tab${channelForm.events.includes(level) ? ' on' : ''}`,
|
|
1732
|
+
onClick: () => setChannelForm({
|
|
1733
|
+
...channelForm,
|
|
1734
|
+
events: channelForm.events.includes(level)
|
|
1735
|
+
? channelForm.events.filter(item => item !== level)
|
|
1736
|
+
: [...channelForm.events, level],
|
|
1737
|
+
}),
|
|
1738
|
+
}, (T.channelLevels || [])[index])),
|
|
1739
|
+
h('button', { className: 'ops-btn ops-btn-primary ops-btn-sm', disabled: chBusy === 'add', onClick: () => { void saveChannel() } }, chBusy === 'add' ? T.reading : T.channelAdd)),
|
|
1740
|
+
h('p', { className: 'ops-sub', style: { margin: '8px 0 0' } }, T.channelHint))),
|
|
1741
|
+
h('div', { className: 'ops-card' },
|
|
1742
|
+
h('div', { className: 'ops-card-h' }, h('span', null, T.quickEdit),
|
|
1743
|
+
h('button', { className: 'ops-btn ops-btn-primary ops-btn-sm', onClick: () => { void saveConfig() } }, T.quickSave)),
|
|
1744
|
+
h('div', { className: 'ops-card-b' },
|
|
1745
|
+
h('textarea', {
|
|
1746
|
+
className: 'ops-input',
|
|
1747
|
+
style: { minHeight: '110px', fontFamily: 'ui-monospace,Menlo,monospace', fontSize: '12px' },
|
|
1748
|
+
value: quickText,
|
|
1749
|
+
placeholder: 'df -h\nfree -h',
|
|
1750
|
+
onChange: e => setQuickText(e.target.value),
|
|
1751
|
+
spellCheck: false,
|
|
1752
|
+
}),
|
|
1753
|
+
h('p', { className: 'ops-sub', style: { margin: 0 } }, T.quickHint))),
|
|
1754
|
+
h('div', { className: 'ops-card' },
|
|
1755
|
+
h('div', { className: 'ops-card-h' }, h('span', null, T.tabs[0]), h('button', { className: 'ops-btn ops-btn-sm', onClick: () => setAdding(v => !v) }, T.add)),
|
|
1756
|
+
adding ? h('div', { className: 'ops-form' },
|
|
1757
|
+
h('label', { className: 'ops-sub' }, T.name, h('input', { className: 'ops-input', value: form.name, disabled: Boolean(editName), onChange: e => setForm({ ...form, name: e.target.value }) })),
|
|
1758
|
+
h('label', { className: 'ops-sub' }, T.alias, h('input', { className: 'ops-input', value: form.alias || '', onChange: e => setForm({ ...form, alias: e.target.value }), placeholder: '公司网站' })),
|
|
1759
|
+
h('label', { className: 'ops-sub' }, T.host, h('input', { className: 'ops-input', value: form.host, onChange: e => setForm({ ...form, host: e.target.value }), placeholder: '203.0.113.10' })),
|
|
1760
|
+
h('label', { className: 'ops-sub' }, T.user, h('input', { className: 'ops-input', value: form.user, onChange: e => setForm({ ...form, user: e.target.value }), placeholder: 'root' })),
|
|
1761
|
+
h('label', { className: 'ops-sub' }, T.key, h('input', { className: 'ops-input', value: form.key, onChange: e => setForm({ ...form, key: e.target.value }), placeholder: '~/.ssh/id_ed25519' })),
|
|
1762
|
+
h('label', { className: 'ops-sub' }, T.password, h('input', { className: 'ops-input', type: 'password', value: form.password, onChange: e => setForm({ ...form, password: e.target.value }), placeholder: '••••••', autoComplete: 'new-password' })),
|
|
1763
|
+
h('div', { className: 'ops-wide', style: { display: 'flex', gap: '8px', justifyContent: 'flex-end' } },
|
|
1764
|
+
h('button', { className: 'ops-btn', onClick: () => { setAdding(false); setEditName(''); setForm({ name: '', host: '', user: '', key: '', password: '', alias: '' }) } }, T.cancel),
|
|
1765
|
+
h('button', { className: 'ops-btn ops-btn-primary', onClick: () => { void addHost() } }, T.save))) : null,
|
|
1766
|
+
...hosts.map(host => h('div', { key: host.name, className: 'ops-row' },
|
|
1767
|
+
h('span', { className: 'ops-name' }, host.alias || host.name),
|
|
1768
|
+
h('span', { className: 'ops-mono' }, `${host.user ? host.user + '@' : ''}${host.host}:${host.port || 22}`),
|
|
1769
|
+
h('span', { className: 'ops-dim' }, `${host.name} · ${host.key || 'ssh agent'}`),
|
|
1770
|
+
h('span', { style: { display: 'flex', gap: '6px', justifyContent: 'flex-end' } },
|
|
1771
|
+
h('button', { className: 'ops-btn ops-btn-sm', disabled: busy === 'test:' + host.name, onClick: () => { void testHost(host.name) } }, busy === 'test:' + host.name ? T.testing : T.test),
|
|
1772
|
+
h('button', { className: 'ops-btn ops-btn-sm', disabled: busy === 'key:' + host.name, onClick: () => { void installKeyOn(host.name) } }, busy === 'key:' + host.name ? T.installing : T.installKey),
|
|
1773
|
+
h('button', { className: 'ops-btn ops-btn-sm', onClick: () => startEdit(host) }, T.edit),
|
|
1774
|
+
h('button', { className: 'ops-btn ops-btn-sm', onClick: () => { void removeHost(host.name) } }, T.remove))))))
|
|
1775
|
+
|
|
1776
|
+
const backupView = h('div', { style: { display: 'flex', flexDirection: 'column', gap: '12px' } },
|
|
1777
|
+
h('div', { className: 'ops-card' },
|
|
1778
|
+
h('div', { className: 'ops-card-h' }, h('span', null, T.backups), h('span', { className: 'ops-dim' }, dhost())),
|
|
1779
|
+
h('div', { className: 'ops-card-b' },
|
|
1780
|
+
h('div', { className: 'ops-chips' },
|
|
1781
|
+
...(T.monTypes ? [] : []),
|
|
1782
|
+
h('button', { className: `ops-tab${backupForm.type === 'mysql' ? ' on' : ''}`, onClick: () => setBackupForm({ ...backupForm, type: 'mysql' }) }, T.backupDb),
|
|
1783
|
+
h('button', { className: `ops-tab${backupForm.type === 'dir' ? ' on' : ''}`, onClick: () => setBackupForm({ ...backupForm, type: 'dir' }) }, T.backupDirKind)),
|
|
1784
|
+
h('div', { className: 'ops-chips', style: { marginTop: '8px' } },
|
|
1785
|
+
backupForm.type === 'mysql'
|
|
1786
|
+
? h('input', { className: 'ops-input', style: { flex: '1 1 200px' }, value: backupForm.database, placeholder: '数据库名(留空=全部)', onChange: e => setBackupForm({ ...backupForm, database: e.target.value }) })
|
|
1787
|
+
: 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 }) }),
|
|
1788
|
+
h('input', { className: 'ops-input', style: { width: '160px' }, value: backupForm.dir, placeholder: '/home/backup', onChange: e => setBackupForm({ ...backupForm, dir: e.target.value }) }),
|
|
1789
|
+
h('label', { className: 'ops-sub', style: { display: 'flex', gap: '6px', alignItems: 'center' } }, T.backupKeep,
|
|
1790
|
+
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) }) })),
|
|
1791
|
+
h('button', { className: 'ops-btn ops-btn-primary ops-btn-sm', disabled: opBusy === 'backup', onClick: () => { void doBackup() } }, opBusy === 'backup' ? T.reading : T.backupNow)),
|
|
1792
|
+
opOut ? h('pre', { className: 'ops-pre', style: { maxHeight: '160px', marginTop: '8px' } }, opOut) : null)),
|
|
1793
|
+
h('div', { className: 'ops-card' },
|
|
1794
|
+
h('div', { className: 'ops-card-h' }, h('span', null, T.backupList)),
|
|
1795
|
+
h('div', { className: 'ops-card-b' },
|
|
1796
|
+
backups.length === 0
|
|
1797
|
+
? h('p', { className: 'ops-empty' }, T.backupEmpty)
|
|
1798
|
+
: h('div', null, ...backups.map(item => h('div', { key: item.id, className: 'ops-row', style: { gridTemplateColumns: '1fr 1fr auto' } },
|
|
1799
|
+
h('span', { className: 'ops-mono', style: { fontSize: '12px' } }, item.file),
|
|
1800
|
+
h('span', { className: 'ops-dim' }, `${(item.size / 1024).toFixed(0)} KB · ${fmt(item.at)}${item.ok ? '' : ' · 失败'}${item.removed ? ' · 已清理' : ''}`),
|
|
1801
|
+
h('span', { style: { display: 'flex', gap: '6px', justifyContent: 'flex-end' } },
|
|
1802
|
+
h('button', { className: 'ops-btn ops-btn-sm', disabled: !item.ok || opBusy === 'restore:' + item.id, onClick: () => { void restoreBackupNow(item.id) } }, T.backupRestore),
|
|
1803
|
+
h('button', { className: 'ops-btn ops-btn-sm', onClick: () => { void removeBackupNow(item.id) } }, T.backupRemove))))))))
|
|
1804
|
+
|
|
1805
|
+
const cronView = h('div', { style: { display: 'flex', flexDirection: 'column', gap: '12px' } },
|
|
1806
|
+
h('div', { className: 'ops-card' },
|
|
1807
|
+
h('div', { className: 'ops-card-h' }, h('span', null, T.cron), h('span', { className: 'ops-dim' }, dhost())),
|
|
1808
|
+
h('div', { className: 'ops-card-b' },
|
|
1809
|
+
h('div', { className: 'ops-chips' },
|
|
1810
|
+
h('select', { className: 'ops-input', style: { width: '110px' }, value: cronForm.frequency, onChange: e => setCronForm({ ...cronForm, frequency: e.target.value }) },
|
|
1811
|
+
h('option', { value: 'daily' }, T.cronDaily),
|
|
1812
|
+
h('option', { value: 'hourly' }, T.cronHourly),
|
|
1813
|
+
h('option', { value: 'weekly' }, T.cronWeekly)),
|
|
1814
|
+
cronForm.frequency === 'hourly' ? null : h('label', { className: 'ops-sub', style: { display: 'flex', gap: '4px', alignItems: 'center' } }, T.cronAt,
|
|
1815
|
+
h('input', { className: 'ops-input', style: { width: '60px' }, value: cronForm.hour, onChange: e => setCronForm({ ...cronForm, hour: e.target.value }) })),
|
|
1816
|
+
h('label', { className: 'ops-sub', style: { display: 'flex', gap: '4px', alignItems: 'center' } }, ':',
|
|
1817
|
+
h('input', { className: 'ops-input', style: { width: '60px' }, value: cronForm.minute, onChange: e => setCronForm({ ...cronForm, minute: e.target.value }) })),
|
|
1818
|
+
h('input', { className: 'ops-input', style: { flex: '1 1 260px' }, value: cronForm.command, placeholder: T.cronCmd, onChange: e => setCronForm({ ...cronForm, command: e.target.value }) }),
|
|
1819
|
+
h('button', { className: 'ops-btn ops-btn-primary ops-btn-sm', disabled: opBusy === 'cron', onClick: () => { void addCronJob() } }, T.cronAdd))),
|
|
1820
|
+
h('div', { className: 'ops-card-b' },
|
|
1821
|
+
cronJobs.length === 0
|
|
1822
|
+
? h('p', { className: 'ops-empty' }, T.cronEmpty)
|
|
1823
|
+
: h('div', null, ...cronJobs.map(job => h('div', { key: `${job.index}-${job.raw}`, className: 'ops-row', style: { gridTemplateColumns: '140px 1fr auto' } },
|
|
1824
|
+
h('span', { className: 'ops-mono', style: { fontSize: '12px' } }, job.schedule),
|
|
1825
|
+
h('span', { className: 'ops-mono', style: { fontSize: '12px', overflow: 'hidden', textOverflow: 'ellipsis' } }, job.command),
|
|
1826
|
+
h('span', { style: { display: 'flex', justifyContent: 'flex-end' } },
|
|
1827
|
+
h('button', { className: 'ops-btn ops-btn-sm', onClick: () => { void removeCronJob(job.index) } }, T.cronRemove))))))))
|
|
1828
|
+
|
|
1829
|
+
const deployView = h('div', { style: { display: 'flex', flexDirection: 'column', gap: '12px' } },
|
|
1830
|
+
h('div', { className: 'ops-card' },
|
|
1831
|
+
h('div', { className: 'ops-card-h' }, h('span', null, T.deployNew)),
|
|
1832
|
+
h('div', { className: 'ops-card-b' },
|
|
1833
|
+
h('div', { className: 'ops-chips' },
|
|
1834
|
+
h('input', { className: 'ops-input', style: { width: '140px' }, value: deployForm.name, placeholder: '名称', onChange: e => setDeployForm({ ...deployForm, name: e.target.value }) }),
|
|
1835
|
+
h('input', { className: 'ops-input', style: { flex: '1 1 220px' }, value: deployForm.dir, placeholder: T.deployDir, onChange: e => setDeployForm({ ...deployForm, dir: e.target.value }) })),
|
|
1836
|
+
h('div', { className: 'ops-chips', style: { marginTop: '8px' } },
|
|
1837
|
+
h('input', { className: 'ops-input', style: { flex: '1 1 220px' }, value: deployForm.repo, placeholder: T.deployRepo, onChange: e => setDeployForm({ ...deployForm, repo: e.target.value }) }),
|
|
1838
|
+
h('input', { className: 'ops-input', style: { width: '140px' }, value: deployForm.branch, placeholder: T.deployBranch, onChange: e => setDeployForm({ ...deployForm, branch: e.target.value }) })),
|
|
1839
|
+
h('div', { className: 'ops-chips', style: { marginTop: '8px' } },
|
|
1840
|
+
h('input', { className: 'ops-input', style: { flex: '1 1 200px' }, value: deployForm.build, placeholder: T.deployBuild, onChange: e => setDeployForm({ ...deployForm, build: e.target.value }) }),
|
|
1841
|
+
h('input', { className: 'ops-input', style: { flex: '1 1 200px' }, value: deployForm.restart, placeholder: T.deployRestart, onChange: e => setDeployForm({ ...deployForm, restart: e.target.value }) })),
|
|
1842
|
+
h('div', { className: 'ops-chips', style: { marginTop: '8px' } },
|
|
1843
|
+
h('input', { className: 'ops-input', style: { flex: '1 1 260px' }, value: deployForm.health, placeholder: T.deployHealth, onChange: e => setDeployForm({ ...deployForm, health: e.target.value }) }),
|
|
1844
|
+
h('button', { className: 'ops-btn ops-btn-primary ops-btn-sm', disabled: opBusy === 'deploy-save', onClick: () => { void saveDeployJob() } }, T.deploySave)))),
|
|
1845
|
+
h('div', { className: 'ops-card' },
|
|
1846
|
+
h('div', { className: 'ops-card-h' }, h('span', null, T.deploy)),
|
|
1847
|
+
h('div', { className: 'ops-card-b' },
|
|
1848
|
+
deployJobs.length === 0
|
|
1849
|
+
? h('p', { className: 'ops-empty' }, T.deployEmpty)
|
|
1850
|
+
: h('div', null, ...deployJobs.map(job => h('div', { key: job.id, className: 'ops-row', style: { gridTemplateColumns: '1fr 1.2fr auto' } },
|
|
1851
|
+
h('span', { className: 'ops-name' }, job.name || job.dir),
|
|
1852
|
+
h('span', { className: 'ops-dim' }, `${job.dir}${job.health ? ' · ' + job.health : ''}`),
|
|
1853
|
+
h('span', { style: { display: 'flex', gap: '6px', justifyContent: 'flex-end' } },
|
|
1854
|
+
h('button', { className: 'ops-btn ops-btn-primary ops-btn-sm', disabled: opBusy === 'deploy:' + job.id, onClick: () => { void runDeployJob(job.id) } }, opBusy === 'deploy:' + job.id ? T.reading : T.deployRun),
|
|
1855
|
+
h('button', { className: 'ops-btn ops-btn-sm', onClick: () => { void api('deploy', { method: 'POST', body: JSON.stringify({ host: dhost(), action: 'remove', id: job.id }) }).then(d => setDeployJobs(d.jobs || [])) } }, T.deployRemove))))),
|
|
1856
|
+
opOut ? h('pre', { className: 'ops-pre', style: { maxHeight: '260px', marginTop: '8px' } }, opOut) : null)))
|
|
1857
|
+
|
|
1858
|
+
const healthIssues = Array.isArray(health?.issues) ? health.issues : []
|
|
1859
|
+
const healthScore = typeof health?.score === 'number' ? health.score : null
|
|
1860
|
+
const healthLevel = health?.level || (healthScore === null ? '' : healthScore >= 90 ? 'ok' : healthScore >= 70 ? 'warn' : 'bad')
|
|
1861
|
+
|
|
1862
|
+
const healthCard = h('div', { className: 'ops-card' },
|
|
1863
|
+
h('div', { className: 'ops-card-h' },
|
|
1864
|
+
h('span', null, T.health,
|
|
1865
|
+
healthScore !== null ? h('span', { className: healthLevel === 'ok' ? 'ops-ok' : healthLevel === 'warn' ? 'ops-warn' : 'ops-bad', style: { marginLeft: '8px' } },
|
|
1866
|
+
`${healthScore} 分 · ${healthLevel === 'ok' ? T.scoreGood : healthLevel === 'warn' ? T.scoreWarn : T.scoreBad}`) : null),
|
|
1867
|
+
h('button', { className: 'ops-btn ops-btn-sm', disabled: opBusy === 'health', onClick: () => { void loadHealth(dhost()) } }, opBusy === 'health' ? T.reading : T.healthNow)),
|
|
1868
|
+
h('div', { className: 'ops-card-b' },
|
|
1869
|
+
healthScore !== null && healthIssues.length === 0 ? h('p', { className: 'ops-ok', style: { margin: 0 } }, '✓ ' + T.noIssues) : null,
|
|
1870
|
+
healthIssues.length > 0
|
|
1871
|
+
? h('div', null, ...healthIssues.slice(0, 4).map((issue, index) => h('div', { key: issue.id + index, className: 'ops-chips', style: { marginTop: index ? '6px' : 0 } },
|
|
1872
|
+
h('span', { className: issue.level === 'critical' ? 'ops-bad' : issue.level === 'warning' ? 'ops-warn' : 'ops-dim', style: { fontSize: '13px' } },
|
|
1873
|
+
`${index === 0 ? '▸ ' : ''}${issue.text}`),
|
|
1874
|
+
index === 0 ? h('span', { className: 'ops-chip' }, T.fixFirst) : null,
|
|
1875
|
+
issue.action === 'cleanup' ? h('button', { className: 'ops-btn ops-btn-sm', onClick: () => { void cleanupHost(dhost()) } }, T.cleanup) : null,
|
|
1876
|
+
issue.action === 'ps' ? h('button', { className: 'ops-btn ops-btn-sm', onClick: () => setDetailTab('monitor') }, T.tabs[1]) : null,
|
|
1877
|
+
issue.action === 'units' ? h('button', { className: 'ops-btn ops-btn-sm', onClick: () => setDetailTab('apps') }, T.tabs[3]) : null,
|
|
1878
|
+
issue.action === 'backup' ? h('button', { className: 'ops-btn ops-btn-sm', onClick: () => setDetailTab('backups') }, T.backups) : null,
|
|
1879
|
+
issue.action === 'monitor' ? h('button', { className: 'ops-btn ops-btn-sm', onClick: () => setDetailTab('backups') }, T.monitors) : null,
|
|
1880
|
+
issue.action === 'cert' ? h('button', { className: 'ops-btn ops-btn-sm', onClick: () => { void renewCertsNow(true) } }, T.certRenew) : null)))
|
|
1881
|
+
: (healthScore !== null ? null : h('p', { className: 'ops-sub', style: { margin: 0 } }, T.loading))))
|
|
1882
|
+
|
|
1883
|
+
const certsCard = h('div', { className: 'ops-card' },
|
|
1884
|
+
h('div', { className: 'ops-card-h' },
|
|
1885
|
+
h('span', null, T.certs),
|
|
1886
|
+
h('span', { className: 'ops-chips' },
|
|
1887
|
+
h('button', { className: 'ops-btn ops-btn-sm', disabled: opBusy === 'renew', onClick: () => { void renewCertsNow(true) } }, T.certRenew),
|
|
1888
|
+
h('button', { className: 'ops-btn ops-btn-sm', disabled: opBusy === 'renew', onClick: () => { void renewCertsNow(false) } }, T.certRenewReal))),
|
|
1889
|
+
h('div', { className: 'ops-card-b' },
|
|
1890
|
+
certs.length === 0
|
|
1891
|
+
? h('p', { className: 'ops-empty' }, T.certNone)
|
|
1892
|
+
: h('div', null, ...certs.map(cert => h('div', { key: cert.domain, className: 'ops-row', style: { gridTemplateColumns: '1.2fr 1fr auto' } },
|
|
1893
|
+
h('span', { className: 'ops-mono', style: { fontSize: '12px' } }, cert.domain),
|
|
1894
|
+
h('span', { className: cert.days === null ? 'ops-dim' : cert.days <= 14 ? 'ops-warn' : 'ops-dim' },
|
|
1895
|
+
cert.days === null ? (cert.error || '无法读取') : `${cert.days} ${T.certDays} · ${fmt(cert.expiresAt)}`),
|
|
1896
|
+
h('span', null)))),
|
|
1897
|
+
opOut ? h('pre', { className: 'ops-pre', style: { maxHeight: '200px', marginTop: '8px' } }, opOut) : null))
|
|
1898
|
+
|
|
1899
|
+
const monitorsCard = h('div', { className: 'ops-card' },
|
|
1900
|
+
h('div', { className: 'ops-card-h' },
|
|
1901
|
+
h('span', null, T.monitors, monitors.length ? h('span', { className: 'ops-chip', style: { marginLeft: '6px' } }, String(monitors.length)) : null),
|
|
1902
|
+
h('span', { className: 'ops-sub' }, T.monHttpHint)),
|
|
1903
|
+
h('div', { className: 'ops-card-b' },
|
|
1904
|
+
monitors.length === 0
|
|
1905
|
+
? h('p', { className: 'ops-empty' }, T.monEmpty)
|
|
1906
|
+
: h('div', null, ...monitors.map(monitor => h('div', { key: monitor.id, className: 'ops-row', style: { gridTemplateColumns: '1fr 1.1fr auto' } },
|
|
1907
|
+
h('span', { style: { display: 'flex', alignItems: 'center', gap: '6px', minWidth: 0 } },
|
|
1908
|
+
h('i', { className: 'ops-dot ' + (monitor.lastOk === true ? 'ok' : monitor.lastOk === false ? 'bad' : '') }),
|
|
1909
|
+
h('span', { className: 'ops-name' }, monitor.label || `${monitor.type} ${monitor.target || ''}`),
|
|
1910
|
+
h('span', { className: 'ops-chip' }, monitor.type === 'script'
|
|
1911
|
+
? `${(T.monTypes || []).find(([value]) => value === 'script')?.[1] || 'script'} · ${monitor.language || 'shell'}`
|
|
1912
|
+
: ((T.monTypes || []).find(([value]) => value === monitor.type)?.[1] || monitor.type))),
|
|
1913
|
+
h('span', { className: 'ops-dim' }, monitor.last ? `${monitor.last.detail} · ${fmt(monitor.last.at)}` : T.monNever),
|
|
1914
|
+
h('span', { style: { display: 'flex', gap: '6px', justifyContent: 'flex-end' } },
|
|
1915
|
+
h('button', { className: 'ops-btn ops-btn-sm', disabled: monBusy === 'test:' + monitor.id, onClick: () => { void testMonitor(monitor.id) } }, T.monCheck),
|
|
1916
|
+
h('button', { className: 'ops-btn ops-btn-sm', onClick: () => editMonitor(monitor) }, T.monEdit),
|
|
1917
|
+
h('button', { className: 'ops-btn ops-btn-sm', onClick: () => { void removeMonitor(monitor.id) } }, T.monRemove))))),
|
|
1918
|
+
|
|
1919
|
+
h('div', { className: 'ops-chips', style: { marginTop: '10px' } },
|
|
1920
|
+
h('span', { className: 'ops-chip' }, T.monPreset),
|
|
1921
|
+
...(T.monPresets || []).map(([name, preset]) => h('button', {
|
|
1922
|
+
key: name,
|
|
1923
|
+
className: 'ops-btn ops-btn-sm',
|
|
1924
|
+
onClick: () => { setMonEditId(''); setMonForm({ ...monForm, ...preset }) },
|
|
1925
|
+
}, name))),
|
|
1926
|
+
|
|
1927
|
+
h('div', { className: 'ops-chips', style: { marginTop: '8px' } },
|
|
1928
|
+
...(T.monTypes || []).map(([value, label]) => h('button', {
|
|
1929
|
+
key: value,
|
|
1930
|
+
className: `ops-tab${monForm.type === value ? ' on' : ''}`,
|
|
1931
|
+
onClick: () => setMonForm({ ...monForm, type: value }),
|
|
1932
|
+
}, label))),
|
|
1933
|
+
h('p', { className: 'ops-sub', style: { margin: '6px 0 0' } }, (T.monTypeHint || {})[monForm.type] || ''),
|
|
1934
|
+
h('div', { className: 'ops-chips', style: { marginTop: '8px' } },
|
|
1935
|
+
monForm.type === 'script'
|
|
1936
|
+
? h('select', { className: 'ops-input', style: { width: '110px' }, value: monForm.language || 'shell', onChange: e => setMonForm({ ...monForm, language: e.target.value }) },
|
|
1937
|
+
h('option', { value: 'shell' }, 'shell'),
|
|
1938
|
+
h('option', { value: 'python' }, 'python'),
|
|
1939
|
+
h('option', { value: 'js' }, 'js'))
|
|
1940
|
+
: null,
|
|
1941
|
+
monForm.type === 'script'
|
|
1942
|
+
? null
|
|
1943
|
+
: h('input', { className: 'ops-input', style: { flex: '1 1 220px' }, value: monForm.target, placeholder: 'https://example.com 或 127.0.0.1:3306', onChange: e => setMonForm({ ...monForm, target: e.target.value }) }),
|
|
1944
|
+
h('input', { className: 'ops-input', style: { width: '130px' }, value: monForm.label, placeholder: T.monLabel, onChange: e => setMonForm({ ...monForm, label: e.target.value }) }),
|
|
1945
|
+
h('label', { className: 'ops-sub', style: { display: 'flex', gap: '6px', alignItems: 'center' } }, T.monInterval,
|
|
1946
|
+
h('input', { className: 'ops-input', type: 'number', min: 1, max: 1440, style: { width: '70px' }, value: monForm.intervalMinutes, onChange: e => setMonForm({ ...monForm, intervalMinutes: Number(e.target.value) }) })),
|
|
1947
|
+
h('button', { className: 'ops-btn ops-btn-primary ops-btn-sm', disabled: monBusy === 'add', onClick: () => { void saveMonitor() } },
|
|
1948
|
+
monBusy === 'add' ? T.reading : (monEditId ? T.monSave : T.monAdd)),
|
|
1949
|
+
monEditId ? h('button', { className: 'ops-btn ops-btn-sm', onClick: () => { setMonEditId(''); setMonForm({ type: 'http', target: '', label: '', intervalMinutes: 5, language: 'shell', script: '' }) } }, T.monCancel) : null),
|
|
1950
|
+
|
|
1951
|
+
monForm.type === 'script'
|
|
1952
|
+
? h('div', { style: { marginTop: '8px' } },
|
|
1953
|
+
h('textarea', {
|
|
1954
|
+
className: 'ops-input',
|
|
1955
|
+
style: { minHeight: '120px', fontFamily: 'ui-monospace,Menlo,monospace', fontSize: '12px' },
|
|
1956
|
+
value: monForm.script,
|
|
1957
|
+
placeholder: '#!/bin/bash\ncurl -sf http://127.0.0.1/ >/dev/null || exit 1',
|
|
1958
|
+
onChange: e => setMonForm({ ...monForm, script: e.target.value }),
|
|
1959
|
+
spellCheck: false,
|
|
1960
|
+
}),
|
|
1961
|
+
h('p', { className: 'ops-sub', style: { margin: '4px 0 0' } }, T.monScriptHint))
|
|
1962
|
+
: null))
|
|
1963
|
+
|
|
1964
|
+
const hostDetailView = (() => {
|
|
1965
|
+
const host = hosts.find(item => item.name === detailHost)
|
|
1966
|
+
if (!host) return h('p', { className: 'ops-empty' }, T.noHosts)
|
|
1967
|
+
const list = overview[host.name] || []
|
|
1968
|
+
const sample = list[list.length - 1] || null
|
|
1969
|
+
const st = statusOf(sample)
|
|
1970
|
+
const conn = conns[host.name]
|
|
1971
|
+
const uptimeText = sample?.uptimeSec
|
|
1972
|
+
? `${Math.floor(sample.uptimeSec / 86400)} 天 ${Math.floor((sample.uptimeSec % 86400) / 3600)} 小时`
|
|
1973
|
+
: '—'
|
|
1974
|
+
return h('div', { style: { display: 'flex', flexDirection: 'column', gap: '12px' } },
|
|
1975
|
+
h('div', { className: 'ops-card' },
|
|
1976
|
+
h('div', { className: 'ops-card-h' },
|
|
1977
|
+
h('span', null, h('i', { className: 'ops-dot ' + st.cls }), host.alias || host.name,
|
|
1978
|
+
host.alias ? h('span', { className: 'ops-dim', style: { marginLeft: '8px', fontWeight: 400 } }, host.name) : null),
|
|
1979
|
+
h('span', { className: st.cls === 'ok' ? 'ops-ok' : st.cls === 'warn' ? 'ops-warn' : 'ops-bad', style: { fontSize: '12px' } }, st.text)),
|
|
1980
|
+
h('div', { className: 'ops-card-b' },
|
|
1981
|
+
h('div', { className: 'ops-dim' },
|
|
1982
|
+
`${host.user ? host.user + '@' : ''}${host.host}:${host.port || 22}`,
|
|
1983
|
+
conn ? ` · ${conn.ok ? `${T.connected} ${conn.ms}ms` : T.disconnected}` : '',
|
|
1984
|
+
sample?.ts ? ` · ${T.lastSample} ${fmt(new Date(sample.ts).toISOString())}` : ''),
|
|
1985
|
+
h('div', { className: 'ops-nums' },
|
|
1986
|
+
h('div', { className: 'ops-num' }, h('b', null, pct(sample?.cpu)), h('span', null, T.cpu),
|
|
1987
|
+
h('div', { className: 'ops-bar' }, h('i', { style: { width: Math.min(100, sample?.cpu ?? 0) + '%' } }))),
|
|
1988
|
+
h('div', { className: 'ops-num' }, h('b', null, pct(sample?.mem)), h('span', null, T.mem),
|
|
1989
|
+
h('div', { className: 'ops-bar' }, h('i', { className: (sample?.mem ?? 0) >= 80 ? 'warn' : '', style: { width: Math.min(100, sample?.mem ?? 0) + '%' } }))),
|
|
1990
|
+
h('div', { className: 'ops-num' }, h('b', null, pct(sample?.disk)), h('span', null, T.disk),
|
|
1991
|
+
h('div', { className: 'ops-bar' }, h('i', { className: (sample?.disk ?? 0) >= 90 ? 'bad' : (sample?.disk ?? 0) >= 75 ? 'warn' : '', style: { width: Math.min(100, sample?.disk ?? 0) + '%' } })))),
|
|
1992
|
+
h('div', { className: 'ops-chips' },
|
|
1993
|
+
h('span', { className: 'ops-dim' }, '负载 ' + (sample?.load1 ?? '—') + ' / ' + (sample?.load5 ?? '—') + ' / ' + (sample?.load15 ?? '—')),
|
|
1994
|
+
h('span', { className: 'ops-dim' }, '进程 ' + (sample?.procs ?? '—')),
|
|
1995
|
+
h('span', { className: 'ops-dim' }, 'TCP ' + (sample?.tcp ?? '—')),
|
|
1996
|
+
h('span', { className: 'ops-dim' }, 'Swap ' + (sample?.swap ?? '—') + '%'),
|
|
1997
|
+
h('span', { className: 'ops-dim' }, '已运行 ' + uptimeText)),
|
|
1998
|
+
h('div', { className: 'ops-chips' },
|
|
1999
|
+
h('button', { className: 'ops-btn ops-btn-primary ops-btn-sm', onClick: () => { void askAi(host.name, '') } }, T.diagnose),
|
|
2000
|
+
h('button', { className: 'ops-btn ops-btn-sm', onClick: () => setDetailTab('logs') }, T.tabs[5]),
|
|
2001
|
+
h('button', { className: 'ops-btn ops-btn-sm', onClick: () => setDetailTab('terminal') }, T.tabs[7]),
|
|
2002
|
+
h('button', { className: 'ops-btn ops-btn-sm', onClick: () => { void loadBase(); void testHost(host.name) } }, T.test),
|
|
2003
|
+
(sample?.disk ?? 0) >= 85
|
|
2004
|
+
? h('button', { className: 'ops-btn ops-btn-sm', onClick: () => { void cleanupHost(host.name) } }, T.cleanup)
|
|
2005
|
+
: null))),
|
|
2006
|
+
h('div', { style: { display: 'flex', gap: '14px', alignItems: 'center', flexWrap: 'wrap' } },
|
|
2007
|
+
h('span', { className: 'ops-dim' }, T.cpu), h(Spark, { rows: list, field: 'cpu' }),
|
|
2008
|
+
h('span', { className: 'ops-dim' }, T.mem), h(Spark, { rows: list, field: 'mem' }),
|
|
2009
|
+
h('span', { className: 'ops-dim' }, T.disk), h(Spark, { rows: list, field: 'disk' })),
|
|
2010
|
+
healthCard,
|
|
2011
|
+
certsCard,
|
|
2012
|
+
monitorsCard,
|
|
2013
|
+
diag && diag.host === host.name ? diagView : null)
|
|
2014
|
+
})()
|
|
2015
|
+
|
|
2016
|
+
const subTabs = [
|
|
2017
|
+
['summary', T.tabs[0]],
|
|
2018
|
+
['monitor', T.tabs[1]],
|
|
2019
|
+
['config', T.tabs[2]],
|
|
2020
|
+
['apps', T.tabs[3]],
|
|
2021
|
+
['logs', T.tabs[5]],
|
|
2022
|
+
['files', T.tabs[6]],
|
|
2023
|
+
['terminal', T.tabs[7]],
|
|
2024
|
+
['backups', T.backups],
|
|
2025
|
+
['cron', T.cron],
|
|
2026
|
+
['deploy', T.deploy],
|
|
2027
|
+
]
|
|
2028
|
+
|
|
2029
|
+
const subBody = detailHost
|
|
2030
|
+
? ({ summary: hostDetailView, monitor: monitorView, config: configView, apps: appsView, logs: logsView, files: filesView, terminal: terminalView, backups: backupView, cron: cronView, deploy: deployView }[detailTab] || hostDetailView)
|
|
2031
|
+
: null
|
|
2032
|
+
|
|
2033
|
+
const topTabs = [[0, T.tabs[0]], [1, T.tabs[8]], [2, T.tabs[9]]]
|
|
2034
|
+
|
|
2035
|
+
const body = detailHost ? subBody : [overviewView, assistantView, settingsView][tab]
|
|
2036
|
+
|
|
2037
|
+
const header = h('div', { className: 'ops-top' },
|
|
2038
|
+
h('div', null,
|
|
2039
|
+
h('h1', { className: 'ops-title' }, detailHost ? (hosts.find(item => item.name === detailHost)?.alias || detailHost) : T.title),
|
|
2040
|
+
h('p', { className: 'ops-sub' }, detailHost ? '这台服务器的全部信息' : T.sub)),
|
|
2041
|
+
h('div', { style: { display: 'flex', gap: '10px', alignItems: 'center' } },
|
|
2042
|
+
busy ? h('span', { className: 'ops-dim' }, '⏳ ' + (busy === 'scan' ? T.rescanning : T.loading)) : null,
|
|
2043
|
+
detailHost
|
|
2044
|
+
? h('button', { className: 'ops-btn ops-btn-sm', onClick: () => { setDetailHost(null); void loadBase() } }, '← 返回所有服务器')
|
|
2045
|
+
: h('button', { className: 'ops-btn ops-btn-sm', onClick: () => { void loadBase(); if (detailHost) void loadInv(cHost || detailHost, true) } }, T.refresh)))
|
|
2046
|
+
|
|
2047
|
+
const nav = detailHost
|
|
2048
|
+
? h('div', { className: 'ops-tabs' }, ...subTabs.map(([key, label]) =>
|
|
2049
|
+
h('button', { key, className: `ops-tab${detailTab === key ? ' on' : ''}`, onClick: () => setDetailTab(key) }, label)))
|
|
2050
|
+
: h('div', { className: 'ops-tabs' }, ...topTabs.map(([index, label]) =>
|
|
2051
|
+
h('button', { key: label, className: `ops-tab${tab === index ? ' on' : ''}`, onClick: () => setTab(index) }, label)))
|
|
2052
|
+
|
|
2053
|
+
return h('div', { className: 'ops-page' },
|
|
2054
|
+
h('style', null, CSS),
|
|
2055
|
+
header,
|
|
2056
|
+
nav,
|
|
2057
|
+
error ? h('p', { className: 'ops-err' }, error) : null,
|
|
2058
|
+
body)
|
|
2059
|
+
}
|
|
2060
|
+
|
|
2061
|
+
/** Keeps a render error visible instead of leaving an empty page. */
|
|
2062
|
+
class Boundary extends React.Component {
|
|
2063
|
+
constructor(props) {
|
|
2064
|
+
super(props)
|
|
2065
|
+
this.state = { error: null }
|
|
2066
|
+
}
|
|
2067
|
+
static getDerivedStateFromError(error) {
|
|
2068
|
+
return { error }
|
|
2069
|
+
}
|
|
2070
|
+
render() {
|
|
2071
|
+
if (this.state.error) {
|
|
2072
|
+
return h('div', { style: { padding: '20px', color: 'var(--dsw-alias-danger,#ff6b6b)', fontSize: '13px', lineHeight: 1.7 } },
|
|
2073
|
+
h('div', { style: { fontWeight: 600, marginBottom: '6px' } }, '运维面板渲染失败'),
|
|
2074
|
+
h('pre', { style: { whiteSpace: 'pre-wrap', fontFamily: 'ui-monospace,Menlo,monospace', fontSize: '12px' } },
|
|
2075
|
+
String(this.state.error?.stack || this.state.error?.message || this.state.error)))
|
|
2076
|
+
}
|
|
2077
|
+
return this.props.children
|
|
2078
|
+
}
|
|
2079
|
+
}
|
|
2080
|
+
|
|
2081
|
+
function PanelRoot() {
|
|
2082
|
+
return h(Boundary, null, h(Panel))
|
|
2083
|
+
}
|
|
2084
|
+
|
|
2085
|
+
function apply(ctx) {
|
|
2086
|
+
ctx.slots.inject('sidebar.panellist', () => ctx.slots.register({
|
|
2087
|
+
name: 'sidebar.panellist', id: PANEL, order: 7, label: () => LABEL[zh ? 'zh' : 'en'],
|
|
2088
|
+
}, Icon))
|
|
2089
|
+
ctx.slots.inject('main', () => ctx.slots.register({ name: 'main', key: PANEL }, PanelRoot))
|
|
2090
|
+
}
|
|
2091
|
+
|
|
2092
|
+
return { isPlugin: true, inject: ['slots'], apply }
|
|
2093
|
+
},
|
|
2094
|
+
})
|