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:
2026-10-12 14:02:28 +01:00
co-authored by Claude Opus 5.5
parent 26f312e307
commit 2786bce022
24 changed files with 2293 additions and 306 deletions
+122
View File
@@ -0,0 +1,122 @@
<script setup>
/**
* The job capture token card on the admin Environment tab.
*
* The token is the credential the job capture userscript
* (public/job-capture.user.js) sends. It is not a .env variable: the server
* keeps only a hash in backend/token/, so it can be shown exactly once, in
* the response to generating it, and replacing it needs no restart.
*/
import { ref, onMounted } from "vue";
import axios from "axios";
import Button from "@/components/input/Button.vue";
import SecretReveal from "@/components/admin/SecretReveal.vue";
import "./env.css";
// `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 error = ref("");
const busy = ref(false);
const newToken = ref("");
async function fetchCaptureToken() {
try {
capture.value = (await axios.get("/api/admin/capture-token")).data;
error.value = "";
} catch (err) {
error.value =
err.response?.data?.error || "Failed to load the capture token state";
}
}
async function generate() {
// 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;
busy.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 };
error.value = "";
} catch (err) {
error.value = err.response?.data?.error || "Failed to generate a token";
} finally {
busy.value = false;
}
}
async function revoke() {
if (!confirm("Revoke the capture token? The userscript will stop working."))
return;
busy.value = true;
try {
capture.value = (await axios.delete("/api/admin/capture-token")).data;
newToken.value = "";
error.value = "";
} catch (err) {
error.value = err.response?.data?.error || "Failed to revoke the token";
} finally {
busy.value = false;
}
}
onMounted(fetchCaptureToken);
</script>
<template>
<section class="env-card">
<header class="env-card-head">
<h2>Job capture</h2>
<span v-if="capture" class="env-pill" :class="capture.set ? 'is-set' : 'is-unset'">
{{ capture.set ? "active" : "no token" }}
</span>
</header>
<div class="capture-body">
<p class="env-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
it takes effect at once and cannot be recovered — generate again to
replace it.
</p>
<p v-if="error" class="env-error">{{ error }}</p>
<template v-if="capture">
<p v-if="capture.set" class="env-hint">
Generated {{ new Date(capture.createdAt).toLocaleString() }}.
</p>
<SecretReveal v-if="newToken" :value="newToken" />
<div class="capture-controls">
<Button class="px-2" :disabled="busy" @click="generate">
{{ capture.set ? "Regenerate" : "Generate token" }}
</Button>
<Button v-if="capture.set" class="px-2" :disabled="busy" @click="revoke">
Revoke
</Button>
</div>
</template>
</div>
</section>
</template>
<style scoped>
.capture-body {
display: flex;
flex-direction: column;
gap: 8px;
padding: 8px 10px;
}
.capture-controls {
display: flex;
gap: 12px;
}
</style>