feat: Linux SSH admin and remote ssh-monitor update (0.11.0)

This commit is contained in:
PTah
2026-06-20 00:25:35 +10:00
parent 279ea925a8
commit cc8f50de89
17 changed files with 805 additions and 5 deletions
+98
View File
@@ -82,6 +82,44 @@
</form>
</section>
<section class="card settings-card settings-policy">
<h2>Linux (SSH / обновление ssh-monitor)</h2>
<p class="settings-hint settings-hint-top">
SSH-учётка для удалённого запуска <code>/opt/scripts/update_ssh_monitor.sh</code> с карточки Linux-хоста.
Рекомендуется <code>root</code> или пользователь с <code>sudo NOPASSWD</code>.
Пока запись не создана в UI используются <code>SAC_LINUX_ADMIN_*</code> из <code>sac-api.env</code>.
</p>
<form class="settings-form" @submit.prevent="saveLinuxAdminSettings">
<label class="settings-field">
SSH login
<input
v-model="linuxAdminForm.user"
type="text"
autocomplete="off"
placeholder="root"
/>
</label>
<label class="settings-field">
SSH password
<input
v-model="linuxAdminForm.password"
type="password"
autocomplete="new-password"
:placeholder="linuxAdminPasswordPlaceholder"
/>
</label>
<p v-if="linuxAdminLoaded" class="settings-meta">
Настроен: {{ linuxAdminLoaded.configured ? "да" : "нет" }}
· источник: <code>{{ linuxAdminLoaded.source }}</code>
</p>
<div class="settings-actions">
<button type="submit" :disabled="savingLinuxAdmin">
{{ savingLinuxAdmin ? "Сохранение…" : "Сохранить Linux admin" }}
</button>
</div>
</form>
</section>
<section class="card settings-card settings-policy">
<h2>Правило оповещений</h2>
<p class="settings-hint settings-hint-top">
@@ -475,12 +513,14 @@ import {
fetchMobileSettings,
fetchUsers,
fetchWinAdminSettings,
fetchLinuxAdminSettings,
revokeMobileDevice,
deleteMobileDevice,
revokeMobileEnrollmentCode,
testMobileDevicePush,
updateMobileSettings,
updateWinAdminSettings,
updateLinuxAdminSettings,
type MobileDevice,
type MobileEnrollmentCode,
type MobileSettings,
@@ -542,6 +582,13 @@ interface WinAdminSettings {
source: string;
}
interface LinuxAdminSettings {
configured: boolean;
user: string | null;
password_hint: string | null;
source: string;
}
interface SeverityOverrideRowApi {
event_type: string;
default_severity: string;
@@ -556,6 +603,7 @@ const loading = ref(true);
const savingPolicy = ref(false);
const savingUi = ref(false);
const savingWinAdmin = ref(false);
const savingLinuxAdmin = ref(false);
const savingTelegram = ref(false);
const savingWebhook = ref(false);
const savingEmail = ref(false);
@@ -574,6 +622,7 @@ const emailLoaded = ref<EmailSettings | null>(null);
const policyLoaded = ref<NotificationPolicy | null>(null);
const uiLoaded = ref<UiSettings | null>(null);
const winAdminLoaded = ref<WinAdminSettings | null>(null);
const linuxAdminLoaded = ref<LinuxAdminSettings | null>(null);
const severityRows = ref<SeverityOverrideRowUi[]>([]);
const severityFilter = ref("");
const mobileLoaded = ref<MobileSettings | null>(null);
@@ -641,6 +690,11 @@ const winAdminForm = reactive({
password: "",
});
const linuxAdminForm = reactive({
user: "",
password: "",
});
const telegramForm = reactive({
enabled: false,
bot_token: "",
@@ -696,6 +750,11 @@ const winAdminPasswordPlaceholder = computed(() =>
? `оставить ${winAdminLoaded.value.password_hint}`
: "обязателен при первой настройке",
);
const linuxAdminPasswordPlaceholder = computed(() =>
linuxAdminLoaded.value?.password_hint
? `оставить ${linuxAdminLoaded.value.password_hint}`
: "обязателен при первой настройке",
);
const filteredSeverityRows = computed(() => {
const q = severityFilter.value.trim().toLowerCase();
@@ -812,6 +871,44 @@ async function saveWinAdminSettings() {
}
}
async function loadLinuxAdminSettings() {
const data = await fetchLinuxAdminSettings();
linuxAdminLoaded.value = data;
linuxAdminForm.user = data.user ?? "";
linuxAdminForm.password = "";
}
async function saveLinuxAdminSettings() {
savingLinuxAdmin.value = true;
error.value = "";
success.value = "";
try {
const payload: { user?: string; password?: string } = {};
if (linuxAdminForm.user.trim()) {
payload.user = linuxAdminForm.user.trim();
}
if (linuxAdminForm.password.trim()) {
payload.password = linuxAdminForm.password;
}
if (!payload.user && !payload.password) {
error.value = "Укажите логин и/или новый пароль Linux admin";
return;
}
if (!linuxAdminLoaded.value?.configured && (!payload.user || !payload.password)) {
error.value = "Для первой настройки укажите логин и пароль";
return;
}
linuxAdminLoaded.value = await updateLinuxAdminSettings(payload);
linuxAdminForm.user = linuxAdminLoaded.value.user ?? linuxAdminForm.user;
linuxAdminForm.password = "";
success.value = "Учётные данные Linux admin сохранены.";
} catch (e) {
error.value = e instanceof Error ? e.message : "Ошибка сохранения Linux admin";
} finally {
savingLinuxAdmin.value = false;
}
}
async function loadMobileSection() {
mobileLoaded.value = await fetchMobileSettings();
mobileForm.devices_allowed = mobileLoaded.value.devices_allowed;
@@ -958,6 +1055,7 @@ async function load() {
emailForm.smtp_ssl = data.email.smtp_ssl;
await loadUiSettings();
await loadWinAdminSettings();
await loadLinuxAdminSettings();
await loadSeverityOverrides();
await loadMobileSection();
} catch (e) {