ad2425b0ff
Co-authored-by: Cursor <cursoragent@cursor.com>
119 lines
3.4 KiB
Vue
119 lines
3.4 KiB
Vue
<template>
|
|
<section class="card host-sessions">
|
|
<h2>Залогиненные пользователи</h2>
|
|
<p class="muted">
|
|
Текущие сессии на хосте (Linux: loginctl, Windows: qwinsta). Требуются учётные данные admin в настройках SAC.
|
|
</p>
|
|
<p v-if="error" class="error">{{ error }}</p>
|
|
<template v-if="loaded">
|
|
<p v-if="!sessions.length" class="muted">Активных сессий не найдено.</p>
|
|
<table v-else>
|
|
<thead>
|
|
<tr>
|
|
<th>Пользователь</th>
|
|
<th>Session</th>
|
|
<th>TTY / имя</th>
|
|
<th>Состояние</th>
|
|
<th>Действия</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr v-for="s in sessions" :key="s.session_id + s.user">
|
|
<td>{{ s.user }}</td>
|
|
<td><code>{{ s.session_id }}</code></td>
|
|
<td>{{ s.tty || s.session_name || "—" }}</td>
|
|
<td>{{ s.state || "—" }}</td>
|
|
<td>
|
|
<button
|
|
type="button"
|
|
class="secondary"
|
|
:disabled="terminatingId === s.session_id"
|
|
@click="terminate(s.session_id)"
|
|
>
|
|
{{ terminatingId === s.session_id ? "…" : "Завершить" }}
|
|
</button>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
<p v-if="message" :class="messageOk ? 'success' : 'error'">{{ message }}</p>
|
|
</template>
|
|
<button type="button" class="secondary" :disabled="loading" @click="load">
|
|
{{ loading ? "Загрузка…" : loaded ? "Обновить" : "Показать пользователей" }}
|
|
</button>
|
|
</section>
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
|
import { ref } from "vue";
|
|
import {
|
|
fetchHostSessions,
|
|
terminateHostSession,
|
|
type HostSessionItem,
|
|
} from "../api";
|
|
|
|
const props = defineProps<{ hostId: number }>();
|
|
|
|
const loading = ref(false);
|
|
const loaded = ref(false);
|
|
const sessions = ref<HostSessionItem[]>([]);
|
|
const error = ref("");
|
|
const message = ref("");
|
|
const messageOk = ref(true);
|
|
const terminatingId = ref<string | null>(null);
|
|
|
|
async function load() {
|
|
loading.value = true;
|
|
error.value = "";
|
|
message.value = "";
|
|
try {
|
|
const res = await fetchHostSessions(props.hostId);
|
|
if (!res.ok) {
|
|
error.value = res.message;
|
|
sessions.value = [];
|
|
} else {
|
|
sessions.value = res.sessions;
|
|
loaded.value = true;
|
|
}
|
|
} catch (e) {
|
|
error.value = e instanceof Error ? e.message : "Ошибка загрузки сессий";
|
|
} finally {
|
|
loading.value = false;
|
|
}
|
|
}
|
|
|
|
async function terminate(sessionId: string) {
|
|
if (!window.confirm(`Завершить сессию ${sessionId}?`)) return;
|
|
terminatingId.value = sessionId;
|
|
message.value = "";
|
|
try {
|
|
const res = await terminateHostSession(props.hostId, sessionId);
|
|
messageOk.value = res.ok;
|
|
message.value = res.message;
|
|
if (res.ok) {
|
|
sessions.value = sessions.value.filter((s) => s.session_id !== sessionId);
|
|
}
|
|
} catch (e) {
|
|
messageOk.value = false;
|
|
message.value = e instanceof Error ? e.message : "Ошибка завершения сессии";
|
|
} finally {
|
|
terminatingId.value = null;
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<style scoped>
|
|
.host-sessions table {
|
|
width: 100%;
|
|
margin: 0.75rem 0;
|
|
}
|
|
|
|
.host-sessions {
|
|
margin-top: 0;
|
|
}
|
|
|
|
.host-sessions button.secondary {
|
|
margin-top: 0.5rem;
|
|
}
|
|
</style>
|