фикс карточки устройства 2

This commit is contained in:
dv 2026-04-14 13:49:56 +03:00
parent 1e9592f013
commit a322b612f8
2 changed files with 81 additions and 48 deletions

View file

@ -111,8 +111,8 @@ def _parse(output: str) -> dict:
disk_lines = sections.get("DISK", []) disk_lines = sections.get("DISK", [])
disks = [] disks = []
for line in disk_lines: for line in disk_lines:
# Skip header lines # Skip header lines ("Filesystem ...", "target ...", "Mounted on ...")
if line.startswith("Filesystem") or line.startswith("target"): if line.startswith(("Filesystem", "target", "Mounted")):
continue continue
parts = line.split() parts = line.split()
if len(parts) >= 5: if len(parts) >= 5:

View file

@ -38,7 +38,7 @@ import dayjs from 'dayjs'
import { useState } from 'react' import { useState } from 'react'
import { useNavigate, useParams } from 'react-router-dom' import { useNavigate, useParams } from 'react-router-dom'
import { useAlerts, useAcknowledgeAlert, useResolveAlert, type AlertItem } from '../api/alerts' 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 { getDeviceWebUrl } from '../utils/deviceUrl'
import { elapsedAgo } from '../utils/time' import { elapsedAgo } from '../utils/time'
import { useSnapshots, useSnapshotDiff } from '../api/snapshots' import { useSnapshots, useSnapshotDiff } from '../api/snapshots'
@ -101,13 +101,29 @@ function getSnapshotConfig(device: DeviceItem) {
// ─── SSH / Credentials block ────────────────────────────────────────────────── // ─── 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 [showPassword, setShowPassword] = useState(false)
const { data: creds, isFetching: credsFetching } = useDeviceCredentials(objId, device.id, showPassword) 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 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 ( return (
<Descriptions <Descriptions
bordered bordered
@ -117,23 +133,46 @@ function SshBlock({ device, objId }: { device: DeviceItem; objId: number }) {
style={{ marginTop: 16 }} style={{ marginTop: 16 }}
title={<Typography.Text strong style={{ fontSize: 13 }}>SSH / Авторизация</Typography.Text>} title={<Typography.Text strong style={{ fontSize: 13 }}>SSH / Авторизация</Typography.Text>}
> >
{/* Effective login */}
<Descriptions.Item label="Логин"> <Descriptions.Item label="Логин">
<Space size={6}>
{effectiveUser
? <Typography.Text code>{effectiveUser}</Typography.Text>
: <Typography.Text type="secondary">Не задан</Typography.Text>}
{device.ssh_user_override {device.ssh_user_override
? <><Typography.Text code>{device.ssh_user_override}</Typography.Text> <Tag color="blue" style={{ fontSize: 10 }}>override</Tag></> ? <Tag color="blue" style={{ fontSize: 10 }}>device</Tag>
: <Typography.Text type="secondary">С объекта</Typography.Text>} : obj?.ssh_user
? <Tag style={{ fontSize: 10 }}>объект</Tag>
: null}
</Space>
</Descriptions.Item> </Descriptions.Item>
<Descriptions.Item label="Пароль"> {/* Effective auth method + password */}
{device.ssh_key_id_override != null ? ( <Descriptions.Item label="Авторизация">
<Typography.Text type="secondary"> (используется ключ)</Typography.Text> {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}> <Space size={8}>
<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>
) : (
<>
{showPassword ? ( {showPassword ? (
credsFetching credsFetching
? <Spin size="small" /> ? <Spin size="small" />
: creds?.ssh_password : creds?.ssh_password
? <Typography.Text code>{creds.ssh_password}</Typography.Text> ? <Typography.Text code copyable>{creds.ssh_password}</Typography.Text>
: <Typography.Text type="secondary">Не задан (используется с объекта)</Typography.Text> : <Typography.Text type="secondary">Не задан</Typography.Text>
) : ( ) : (
<Typography.Text type="secondary"></Typography.Text> <Typography.Text type="secondary"></Typography.Text>
)} )}
@ -145,35 +184,29 @@ function SshBlock({ device, objId }: { device: DeviceItem; objId: number }) {
> >
{showPassword ? 'Скрыть' : 'Показать'} {showPassword ? 'Скрыть' : 'Показать'}
</Button> </Button>
</>
)}
</Space> </Space>
)} )}
</Descriptions.Item> </Descriptions.Item>
{/* Port */}
<Descriptions.Item label="Порт"> <Descriptions.Item label="Порт">
{device.ssh_port_override <Space size={6}>
? <><Typography.Text code>{device.ssh_port_override}</Typography.Text> <Tag color="blue" style={{ fontSize: 10 }}>override</Tag></> <Typography.Text code>{effectivePort}</Typography.Text>
: <Typography.Text type="secondary">22 (по умолчанию)</Typography.Text>} {device.ssh_port_override && <Tag color="blue" style={{ fontSize: 10 }}>device</Tag>}
</Space>
</Descriptions.Item> </Descriptions.Item>
{device.ssh_key_id_override != null && ( {/* Last successful connection */}
<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>
)}
{lastAuth && ( {lastAuth && (
<Descriptions.Item label="Последний успешный SSH"> <Descriptions.Item label="Последнее подключение">
<Space size={4} wrap> <Space size={4} wrap>
<Tag color="green">{String(lastAuth.type ?? '—')}</Tag> <Tag color="green">успешно</Tag>
{lastAuth.username && <Typography.Text code>{String(lastAuth.username)}</Typography.Text>} {authType && <Tag>{authType === 'key' ? 'ключ' : 'пароль'}</Tag>}
{lastAuth.key_id != null && <Typography.Text type="secondary">key_id={String(lastAuth.key_id)}</Typography.Text>} {lastAuth.username && (
{lastAuth.cred_id != null && <Typography.Text type="secondary">cred_id={String(lastAuth.cred_id)}</Typography.Text>} <Typography.Text code style={{ fontSize: 12 }}>{String(lastAuth.username)}</Typography.Text>
)}
</Space> </Space>
</Descriptions.Item> </Descriptions.Item>
)} )}
@ -372,7 +405,7 @@ function SystemInfoRender({ data }: { data: Record<string, unknown> }) {
{disks && disks.length > 0 && ( {disks && disks.length > 0 && (
<div> <div>
<Typography.Text type="secondary" style={{ fontSize: 12, display: 'block', marginBottom: 4 }}>Диски:</Typography.Text> <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) const pctNum = parseInt(d.pct)
return ( return (
<div key={d.mount} style={{ marginBottom: 6 }}> <div key={d.mount} style={{ marginBottom: 6 }}>
@ -1021,7 +1054,7 @@ export function DeviceDetailPage() {
</Descriptions> </Descriptions>
{/* SSH block — always shown */} {/* SSH block — always shown */}
<SshBlock device={device} objId={objId} /> <SshBlock device={device} objId={objId} obj={obj} />
{/* System info (Linux-like devices) */} {/* System info (Linux-like devices) */}
{isLinuxLike && <SystemInfoBlock device={device} tasks={tasks} />} {isLinuxLike && <SystemInfoBlock device={device} tasks={tasks} />}