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]>
This commit is contained in:
@@ -1,41 +1,22 @@
|
||||
<script setup>
|
||||
/**
|
||||
* Admin panel: configuration checklist, the job capture token, and log tail.
|
||||
* Admin panel: tail of the backend log.
|
||||
*
|
||||
* All of it comes from the backend as JSON (GET /api/admin/config,
|
||||
* /api/admin/capture-token, /api/admin/logs). Nothing here is GraphQL — the
|
||||
* data is process environment and filesystem, not the site's data model.
|
||||
* 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.
|
||||
*
|
||||
* The capture token is the credential the job capture userscript
|
||||
* (public/job-capture.user.js) sends. The server keeps only a hash, so the
|
||||
* token can be shown exactly once, in the response to generating it.
|
||||
*
|
||||
* The log tail loads lazily (only when the Logs tab is selected first)
|
||||
* because reading the file on every /admin visit would be waste; an admin
|
||||
* who remounts the component via tab switches re-triggers onMounted, which
|
||||
* is the desired "refresh on tab change" behaviour.
|
||||
* 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 vars = ref([]);
|
||||
const configError = ref("");
|
||||
|
||||
const lines = ref([]);
|
||||
const logsError = ref("");
|
||||
const loadingLogs = ref(false);
|
||||
|
||||
async function fetchConfig() {
|
||||
try {
|
||||
const res = await axios.get("/api/admin/config");
|
||||
vars.value = res.data.vars;
|
||||
configError.value = "";
|
||||
} catch (err) {
|
||||
configError.value = err.response?.data?.error || "Failed to load config";
|
||||
}
|
||||
}
|
||||
|
||||
async function fetchLogs() {
|
||||
loadingLogs.value = true;
|
||||
try {
|
||||
@@ -49,79 +30,6 @@ async function fetchLogs() {
|
||||
}
|
||||
}
|
||||
|
||||
// Job capture token. `newToken` holds a just-generated token and lives only in
|
||||
// this component's memory: leaving the tab is the end of it.
|
||||
const capture = ref(null);
|
||||
const captureError = ref("");
|
||||
const captureBusy = ref(false);
|
||||
const newToken = ref("");
|
||||
const copied = ref(false);
|
||||
|
||||
async function fetchCaptureToken() {
|
||||
try {
|
||||
capture.value = (await axios.get("/api/admin/capture-token")).data;
|
||||
captureError.value = "";
|
||||
} catch (err) {
|
||||
captureError.value =
|
||||
err.response?.data?.error || "Failed to load the capture token state";
|
||||
}
|
||||
}
|
||||
|
||||
async function generateCaptureToken() {
|
||||
// Generating replaces: an installed script stops working until it is
|
||||
// given the new token, which is worth a pause when one already exists.
|
||||
if (
|
||||
capture.value?.set &&
|
||||
!confirm(
|
||||
"Replace the existing capture token? The installed userscript will stop working until you paste the new one into it.",
|
||||
)
|
||||
)
|
||||
return;
|
||||
captureBusy.value = true;
|
||||
try {
|
||||
const res = await axios.post("/api/admin/capture-token");
|
||||
newToken.value = res.data.token;
|
||||
capture.value = { set: true, createdAt: res.data.createdAt };
|
||||
copied.value = false;
|
||||
captureError.value = "";
|
||||
} catch (err) {
|
||||
captureError.value =
|
||||
err.response?.data?.error || "Failed to generate a token";
|
||||
} finally {
|
||||
captureBusy.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function revokeCaptureToken() {
|
||||
if (!confirm("Revoke the capture token? The userscript will stop working."))
|
||||
return;
|
||||
captureBusy.value = true;
|
||||
try {
|
||||
capture.value = (await axios.delete("/api/admin/capture-token")).data;
|
||||
newToken.value = "";
|
||||
captureError.value = "";
|
||||
} catch (err) {
|
||||
captureError.value =
|
||||
err.response?.data?.error || "Failed to revoke the token";
|
||||
} finally {
|
||||
captureBusy.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function copyToken() {
|
||||
try {
|
||||
await navigator.clipboard.writeText(newToken.value);
|
||||
copied.value = true;
|
||||
} catch {
|
||||
// Clipboard access can be refused; the token is on screen to select.
|
||||
captureError.value = "Could not copy — select the token and copy it by hand.";
|
||||
}
|
||||
}
|
||||
|
||||
const blank = computed(() =>
|
||||
vars.value.filter((v) => !v.set),
|
||||
);
|
||||
|
||||
// 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.
|
||||
@@ -131,82 +39,11 @@ const shownLines = computed(() => {
|
||||
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(() => {
|
||||
fetchConfig();
|
||||
fetchCaptureToken();
|
||||
fetchLogs();
|
||||
});
|
||||
onMounted(fetchLogs);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="diagnostics">
|
||||
<h1>Configuration</h1>
|
||||
<p v-if="blank.length === 0" class="ok">All known configuration set.</p>
|
||||
<p v-else class="warn">
|
||||
{{ blank.length }} unset. Blank vars with <em>required</em> break their
|
||||
feature; optional ones degrade it.
|
||||
</p>
|
||||
<p v-if="configError" class="error">{{ configError }}</p>
|
||||
|
||||
<table v-if="vars.length">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Variable</th>
|
||||
<th>For</th>
|
||||
<th>State</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="v in vars" :key="v.name">
|
||||
<td><code>{{ v.name }}</code></td>
|
||||
<td>{{ v.purpose }}</td>
|
||||
<td>
|
||||
<span v-if="!v.set" class="warn">unset</span>
|
||||
<span v-else-if="v.secret">set (secret)</span>
|
||||
<span v-else>{{ v.value }}</span>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<h1>Job capture token</h1>
|
||||
<p class="hint">
|
||||
The credential for the
|
||||
<a href="/job-capture.user.js" target="_blank" rel="noopener"
|
||||
>job capture userscript</a
|
||||
>. Generate one, then paste it into the script's
|
||||
<em>Configure job capture</em> menu command. Only a hash is stored, so a
|
||||
token is shown once and cannot be recovered — generate again to replace
|
||||
it.
|
||||
</p>
|
||||
<p v-if="captureError" class="error">{{ captureError }}</p>
|
||||
<template v-if="capture">
|
||||
<p v-if="capture.set">
|
||||
A token is active, generated
|
||||
{{ new Date(capture.createdAt).toLocaleString() }}.
|
||||
</p>
|
||||
<p v-else class="warn">
|
||||
No token — the capture script cannot reach the tracker.
|
||||
</p>
|
||||
<div v-if="newToken" class="token-box">
|
||||
<p class="hint">Copy this now. It will not be shown again.</p>
|
||||
<code class="token">{{ newToken }}</code>
|
||||
<Button @click="copyToken">{{ copied ? "Copied" : "Copy" }}</Button>
|
||||
</div>
|
||||
<div class="token-controls">
|
||||
<Button :disabled="captureBusy" @click="generateCaptureToken">
|
||||
{{ capture.set ? "Regenerate" : "Generate token" }}
|
||||
</Button>
|
||||
<Button
|
||||
v-if="capture.set"
|
||||
:disabled="captureBusy"
|
||||
@click="revokeCaptureToken"
|
||||
>
|
||||
Revoke
|
||||
</Button>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<h1>Logs</h1>
|
||||
<p class="hint">
|
||||
Tail of the backend log (up to 500 lines): HTTP traffic and application
|
||||
@@ -235,24 +72,6 @@ onMounted(() => {
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
font-size: 0.85rem;
|
||||
}
|
||||
th,
|
||||
td {
|
||||
text-align: left;
|
||||
padding: 4px 8px;
|
||||
border-bottom: 1px solid var(--color-quaternary);
|
||||
}
|
||||
|
||||
.ok {
|
||||
color: var(--color-tertiary);
|
||||
}
|
||||
.warn {
|
||||
color: var(--color-error, #b91c1c);
|
||||
}
|
||||
.error {
|
||||
color: var(--color-error, #b91c1c);
|
||||
}
|
||||
@@ -261,30 +80,6 @@ td {
|
||||
opacity: 0.75;
|
||||
}
|
||||
|
||||
.token-box {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
padding: 8px;
|
||||
border: 1px solid var(--color-quaternary);
|
||||
}
|
||||
.token-box .hint {
|
||||
flex-basis: 100%;
|
||||
margin: 0;
|
||||
}
|
||||
.token {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
font-size: 0.8rem;
|
||||
word-break: break-all;
|
||||
user-select: all;
|
||||
}
|
||||
.token-controls {
|
||||
display: flex;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.log-controls {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
|
||||
Reference in New Issue
Block a user