фикс карточки устройства 2
This commit is contained in:
parent
1e9592f013
commit
a322b612f8
2 changed files with 81 additions and 48 deletions
|
|
@ -111,8 +111,8 @@ def _parse(output: str) -> dict:
|
|||
disk_lines = sections.get("DISK", [])
|
||||
disks = []
|
||||
for line in disk_lines:
|
||||
# Skip header lines
|
||||
if line.startswith("Filesystem") or line.startswith("target"):
|
||||
# Skip header lines ("Filesystem ...", "target ...", "Mounted on ...")
|
||||
if line.startswith(("Filesystem", "target", "Mounted")):
|
||||
continue
|
||||
parts = line.split()
|
||||
if len(parts) >= 5:
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ import dayjs from 'dayjs'
|
|||
import { useState } from 'react'
|
||||
import { useNavigate, useParams } from 'react-router-dom'
|
||||
import { useAlerts, useAcknowledgeAlert, useResolveAlert, type AlertItem } from '../api/alerts'
|
||||
import { useDevice, useDeleteDevice, useObject, useDeviceCredentials, type DeviceItem } from '../api/objects'
|
||||
import { useDevice, useDeleteDevice, useObject, useDeviceCredentials, type DeviceItem, type ObjectItem } from '../api/objects'
|
||||
import { getDeviceWebUrl } from '../utils/deviceUrl'
|
||||
import { elapsedAgo } from '../utils/time'
|
||||
import { useSnapshots, useSnapshotDiff } from '../api/snapshots'
|
||||
|
|
@ -101,13 +101,29 @@ function getSnapshotConfig(device: DeviceItem) {
|
|||
|
||||
// ─── SSH / Credentials block ──────────────────────────────────────────────────
|
||||
|
||||
function SshBlock({ device, objId }: { device: DeviceItem; objId: number }) {
|
||||
function SshBlock({ device, objId, obj }: { device: DeviceItem; objId: number; obj: ObjectItem | undefined }) {
|
||||
const [showPassword, setShowPassword] = useState(false)
|
||||
const { data: creds, isFetching: credsFetching } = useDeviceCredentials(objId, device.id, showPassword)
|
||||
|
||||
const hasOverride = !!(device.ssh_user_override || device.ssh_port_override || device.ssh_key_id_override)
|
||||
const lastAuth = device.ssh_last_auth
|
||||
|
||||
// Resolve effective values: device override → object default → fallback
|
||||
const effectiveUser =
|
||||
lastAuth?.username
|
||||
? String(lastAuth.username)
|
||||
: device.ssh_user_override ?? obj?.ssh_user ?? null
|
||||
|
||||
const effectivePort = device.ssh_port_override ?? 22
|
||||
|
||||
// Determine auth method from last_auth
|
||||
const authType = lastAuth?.type ? String(lastAuth.type) : null
|
||||
const usesKey = authType === 'key' || device.ssh_key_id_override != null
|
||||
const credSource: 'device' | 'object' | 'unknown' =
|
||||
lastAuth?.cred_id != null ? 'object'
|
||||
: lastAuth?.key_id != null || device.ssh_key_id_override != null ? 'device'
|
||||
: device.ssh_user_override ? 'device'
|
||||
: 'object'
|
||||
|
||||
return (
|
||||
<Descriptions
|
||||
bordered
|
||||
|
|
@ -117,63 +133,80 @@ function SshBlock({ device, objId }: { device: DeviceItem; objId: number }) {
|
|||
style={{ marginTop: 16 }}
|
||||
title={<Typography.Text strong style={{ fontSize: 13 }}>SSH / Авторизация</Typography.Text>}
|
||||
>
|
||||
{/* Effective login */}
|
||||
<Descriptions.Item label="Логин">
|
||||
{device.ssh_user_override
|
||||
? <><Typography.Text code>{device.ssh_user_override}</Typography.Text> <Tag color="blue" style={{ fontSize: 10 }}>override</Tag></>
|
||||
: <Typography.Text type="secondary">С объекта</Typography.Text>}
|
||||
<Space size={6}>
|
||||
{effectiveUser
|
||||
? <Typography.Text code>{effectiveUser}</Typography.Text>
|
||||
: <Typography.Text type="secondary">Не задан</Typography.Text>}
|
||||
{device.ssh_user_override
|
||||
? <Tag color="blue" style={{ fontSize: 10 }}>device</Tag>
|
||||
: obj?.ssh_user
|
||||
? <Tag style={{ fontSize: 10 }}>объект</Tag>
|
||||
: null}
|
||||
</Space>
|
||||
</Descriptions.Item>
|
||||
|
||||
<Descriptions.Item label="Пароль">
|
||||
{device.ssh_key_id_override != null ? (
|
||||
<Typography.Text type="secondary">— (используется ключ)</Typography.Text>
|
||||
{/* Effective auth method + password */}
|
||||
<Descriptions.Item label="Авторизация">
|
||||
{usesKey ? (
|
||||
<Space size={6}>
|
||||
<Tag color="purple">SSH ключ</Tag>
|
||||
{(lastAuth?.key_id != null || device.ssh_key_id_override != null) && (
|
||||
<Typography.Text type="secondary" style={{ fontSize: 12 }}>
|
||||
key_id={String(lastAuth?.key_id ?? device.ssh_key_id_override)}
|
||||
</Typography.Text>
|
||||
)}
|
||||
</Space>
|
||||
) : (
|
||||
<Space size={8}>
|
||||
{showPassword ? (
|
||||
credsFetching
|
||||
? <Spin size="small" />
|
||||
: creds?.ssh_password
|
||||
? <Typography.Text code>{creds.ssh_password}</Typography.Text>
|
||||
: <Typography.Text type="secondary">Не задан (используется с объекта)</Typography.Text>
|
||||
<Tag color="orange">Пароль</Tag>
|
||||
{credSource === 'object' ? (
|
||||
<Typography.Text type="secondary" style={{ fontSize: 12 }}>
|
||||
с объекта{lastAuth?.cred_id != null ? ` (cred_id=${String(lastAuth.cred_id)})` : ''}
|
||||
</Typography.Text>
|
||||
) : (
|
||||
<Typography.Text type="secondary">••••••••</Typography.Text>
|
||||
<>
|
||||
{showPassword ? (
|
||||
credsFetching
|
||||
? <Spin size="small" />
|
||||
: creds?.ssh_password
|
||||
? <Typography.Text code copyable>{creds.ssh_password}</Typography.Text>
|
||||
: <Typography.Text type="secondary">Не задан</Typography.Text>
|
||||
) : (
|
||||
<Typography.Text type="secondary">••••••••</Typography.Text>
|
||||
)}
|
||||
<Button
|
||||
size="small"
|
||||
type="text"
|
||||
icon={showPassword ? <EyeInvisibleOutlined /> : <EyeOutlined />}
|
||||
onClick={() => setShowPassword((v) => !v)}
|
||||
>
|
||||
{showPassword ? 'Скрыть' : 'Показать'}
|
||||
</Button>
|
||||
</>
|
||||
)}
|
||||
<Button
|
||||
size="small"
|
||||
type="text"
|
||||
icon={showPassword ? <EyeInvisibleOutlined /> : <EyeOutlined />}
|
||||
onClick={() => setShowPassword((v) => !v)}
|
||||
>
|
||||
{showPassword ? 'Скрыть' : 'Показать'}
|
||||
</Button>
|
||||
</Space>
|
||||
)}
|
||||
</Descriptions.Item>
|
||||
|
||||
{/* Port */}
|
||||
<Descriptions.Item label="Порт">
|
||||
{device.ssh_port_override
|
||||
? <><Typography.Text code>{device.ssh_port_override}</Typography.Text> <Tag color="blue" style={{ fontSize: 10 }}>override</Tag></>
|
||||
: <Typography.Text type="secondary">22 (по умолчанию)</Typography.Text>}
|
||||
<Space size={6}>
|
||||
<Typography.Text code>{effectivePort}</Typography.Text>
|
||||
{device.ssh_port_override && <Tag color="blue" style={{ fontSize: 10 }}>device</Tag>}
|
||||
</Space>
|
||||
</Descriptions.Item>
|
||||
|
||||
{device.ssh_key_id_override != null && (
|
||||
<Descriptions.Item label="SSH ключ (override)">
|
||||
<Typography.Text code>key_id={device.ssh_key_id_override}</Typography.Text>
|
||||
</Descriptions.Item>
|
||||
)}
|
||||
|
||||
{!hasOverride && (
|
||||
<Descriptions.Item label="Кредиалы">
|
||||
<Typography.Text type="secondary">Используются настройки объекта</Typography.Text>
|
||||
</Descriptions.Item>
|
||||
)}
|
||||
|
||||
{/* Last successful connection */}
|
||||
{lastAuth && (
|
||||
<Descriptions.Item label="Последний успешный SSH">
|
||||
<Descriptions.Item label="Последнее подключение">
|
||||
<Space size={4} wrap>
|
||||
<Tag color="green">{String(lastAuth.type ?? '—')}</Tag>
|
||||
{lastAuth.username && <Typography.Text code>{String(lastAuth.username)}</Typography.Text>}
|
||||
{lastAuth.key_id != null && <Typography.Text type="secondary">key_id={String(lastAuth.key_id)}</Typography.Text>}
|
||||
{lastAuth.cred_id != null && <Typography.Text type="secondary">cred_id={String(lastAuth.cred_id)}</Typography.Text>}
|
||||
<Tag color="green">успешно</Tag>
|
||||
{authType && <Tag>{authType === 'key' ? 'ключ' : 'пароль'}</Tag>}
|
||||
{lastAuth.username && (
|
||||
<Typography.Text code style={{ fontSize: 12 }}>{String(lastAuth.username)}</Typography.Text>
|
||||
)}
|
||||
</Space>
|
||||
</Descriptions.Item>
|
||||
)}
|
||||
|
|
@ -372,7 +405,7 @@ function SystemInfoRender({ data }: { data: Record<string, unknown> }) {
|
|||
{disks && disks.length > 0 && (
|
||||
<div>
|
||||
<Typography.Text type="secondary" style={{ fontSize: 12, display: 'block', marginBottom: 4 }}>Диски:</Typography.Text>
|
||||
{disks.map((d) => {
|
||||
{disks.filter((d) => !isNaN(parseInt(d.pct))).map((d) => {
|
||||
const pctNum = parseInt(d.pct)
|
||||
return (
|
||||
<div key={d.mount} style={{ marginBottom: 6 }}>
|
||||
|
|
@ -1021,7 +1054,7 @@ export function DeviceDetailPage() {
|
|||
</Descriptions>
|
||||
|
||||
{/* SSH block — always shown */}
|
||||
<SshBlock device={device} objId={objId} />
|
||||
<SshBlock device={device} objId={objId} obj={obj} />
|
||||
|
||||
{/* System info (Linux-like devices) */}
|
||||
{isLinuxLike && <SystemInfoBlock device={device} tasks={tasks} />}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue