Files
stpweb/vue/src/views/admin/Diagnostics.vue
T
adamfandClaude Opus 5.5 2786bce022 Manage .env from the admin panel
Add an Environment tab to /admin that lists every variable in .env.example
and lets keys, OAuth settings, email settings and generated secrets be
changed without SSH. Secrets are write-only; infrastructure variables are
shown read-only.

The backend never writes .env or touches Docker. It validates an edit and
queues it in env-apply/run/request.json; env-apply/apply.py, run on the host
by a systemd path unit (env-apply/install.sh), rewrites .env atomically,
keeps .env.bak, and recreates only the services that read the change.

backend/services/env_registry.json is the single list of variables, shared
by the backend and the host script; a test keeps it in step with
.env.example. It replaces the drifted checklist in handle_admin.go. The job
capture token card moves to the new tab.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-12 14:02:28 +01:00

110 lines
2.9 KiB
Vue

<script setup>
/**
* Admin panel: tail of the backend log.
*
* GET /api/admin/logs returns JSON read from the filesystem, not GraphQL —
* it is not part of the site's data model. Configuration and the job capture
* token, which used to share this tab, are on the Environment tab.
*
* An admin who remounts the component via tab switches re-triggers
* onMounted, which is the desired "refresh on tab change" behaviour.
*/
import { ref, onMounted, computed } from "vue";
import axios from "axios";
import Button from "@/components/input/Button.vue";
const lines = ref([]);
const logsError = ref("");
const loadingLogs = ref(false);
async function fetchLogs() {
loadingLogs.value = true;
try {
const res = await axios.get("/api/admin/logs");
lines.value = res.data.lines;
logsError.value = "";
} catch (err) {
logsError.value = err.response?.data?.error || "Failed to load logs";
} finally {
loadingLogs.value = false;
}
}
// Traffic view: a filter over the log tail for "who is using my site" —
// lines with a client IP (the formatter appends it only for real visitors
// and error statuses). Skips the standard line numbers of JSON-array output.
const trafficOnly = ref(true);
const shownLines = computed(() => {
if (!trafficOnly.value) return lines.value;
return lines.value.filter((l) => /\b(?:[0-9]{1,3}\.){3}[0-9]{1,3}$/.test(l.trim()) || l.includes("!!! SERVER ERROR") || l.includes(" !!"));
});
onMounted(fetchLogs);
</script>
<template>
<div class="diagnostics">
<h1>Logs</h1>
<p class="hint">
Tail of the backend log (up to 500 lines): HTTP traffic and application
messages, newest last.
</p>
<div class="log-controls">
<label class="hint toggle">
<input type="checkbox" v-model="trafficOnly" /> visitors only
</label>
<Button :disabled="loadingLogs" @click="fetchLogs">
{{ loadingLogs ? "Loading…" : "Refresh" }}
</Button>
</div>
<p v-if="logsError" class="error">{{ logsError }}</p>
<p v-else-if="shownLines.length === 0" class="hint">
No {{ trafficOnly ? "visitor" : "" }} lines in the current tail.
</p>
<pre v-else class="log-output">{{ shownLines.join("\n") }}</pre>
</div>
</template>
<style scoped>
.diagnostics {
display: flex;
flex-direction: column;
gap: 8px;
}
.error {
color: var(--color-error, #b91c1c);
}
.hint {
font-size: 0.85rem;
opacity: 0.75;
}
.log-controls {
display: flex;
justify-content: flex-end;
gap: 12px;
align-items: center;
}
.toggle {
display: flex;
gap: 4px;
align-items: center;
cursor: pointer;
}
.log-output {
max-height: 400px;
overflow-y: auto;
padding: 8px;
background: var(--color-surface-tint, #111);
color: var(--color-primary);
font-size: 0.75rem;
line-height: 1.4;
white-space: pre-wrap;
word-break: break-all;
border: 1px solid var(--color-quaternary);
}
</style>