Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/OPERATIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ into the server's config, and the CLI does the same:
| A server without mail (port 25 blocked, no relay) | Settings → Mail → No mail: deletions are confirmed in the panel with the 2FA code (the password without 2FA), no invites, no new mail domains, reports only in the panel and webhooks |
| genco sends mail but hosts none | Settings → Mail → uncheck Mail hosting: no new mail domains, mailboxes, forwards or send-only addresses (panel, CLI and agent refuse them); genco's own mails (confirmations, invites, proposal links) keep going. Existing mail domains stay and keep running until deleted; without any, Dovecot, Rspamd and the submission ports stay off as always. No mail implies hosting off |
| A PostgreSQL database | `genco database add <name> --group <g> --postgres`, then `genco apply` (installs PostgreSQL the first time) |
| Environment variables of an app | `genco domain env <name> --set NAME=value --secret NAME=value --unset NAME`, then `genco apply` |
| Environment variables of an app | The domain's page (saving applies and restarts the app), or `genco domain env <name> --set NAME=value --secret NAME=value --unset NAME`, then `genco apply` |
| A stored password (Start → Passwords) | `genco secret list`, `genco secret show <name>` |
| Block an address or range from the sites and mail (never ssh) | `genco firewall block 203.0.113.7 [--for 24h] [--note "..."]`, `genco firewall unblock <ip|cidr>`, `genco firewall list`; Settings → Firewall (see below) |
| Reset an admin's password | `genco user password <email>` (reads the password from stdin) |
Expand Down
2 changes: 1 addition & 1 deletion server/src/activity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ fn describe(method: &Method, path: &str) -> Option<String> {
("POST", "/settings/notify", "Change notifications"),
("POST", "/settings/model", "Change the agent's model"),
("POST", "/settings/memory", "Change the memory reserve"),
("POST", "/domains/*/env", "Change environment variables"),
("POST", "/domains/*/env", "Change and apply app env"),
("POST", "/groups/*/workers", "Add worker"),
("POST", "/workers/*", "Change worker"),
("DELETE", "/workers/*", "Delete worker"),
Expand Down
27 changes: 21 additions & 6 deletions server/src/appenv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
//! domain, written to a file only root reads, which the app's unit loads
//! (`EnvironmentFile`, systemd reads it before it drops to the group's
//! user). Secret values never go back to the browser or the terminal.
//! Saving in the panel applies at once: the file is written and the app
//! restarts with the new variables.

use std::sync::Arc;

use axum::extract::{Path, State};
use axum::routing::get;
Expand All @@ -10,6 +14,8 @@ use rusqlite::{Connection, params};
use serde::{Deserialize, Serialize};

use crate::AppState;
use crate::apply;
use crate::config::Config;
use crate::db::Db;
use crate::error::{Error, Result};
use crate::events::{Event, Events};
Expand Down Expand Up @@ -177,15 +183,26 @@ struct EnvRow {
from: Option<String>,
}

/// Stores the variables and applies: the app restarts with them.
async fn set_env(
_authed: Authed,
State(cfg): State<Arc<Config>>,
State(db): State<Db>,
State(events): State<Events>,
Path(id): Path<i64>,
Json(rows): Json<Vec<EnvRow>>,
) -> Result<Json<()>> {
let conn = db.conn();
let old = load(&conn, id)?;
) -> Result<Json<apply::Report>> {
// the connection mustn't be held over the apply
store(&db.conn(), id, rows)?;
let report = apply::apply(&cfg, &db).await;
events.send(Event::Tree);
Ok(Json(report))
}

/// The panel's rows as the domain's variables; an empty value keeps a
/// secret's.
fn store(conn: &Connection, id: i64, rows: Vec<EnvRow>) -> Result<()> {
let old = load(conn, id)?;
let mut vars = vec![];
for r in rows {
let was = r
Expand Down Expand Up @@ -216,9 +233,7 @@ async fn set_env(
"UPDATE domains SET env = ?1 WHERE id = ?2",
params![serde_json::to_string(&vars).unwrap(), id],
)?;
drop(conn);
events.send(Event::Tree);
Ok(Json(()))
Ok(())
}

pub fn routes() -> Router<AppState> {
Expand Down
14 changes: 10 additions & 4 deletions webui/src/components/AppEnv.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts">
import { get, post } from '@/lib/api';
import { applyErrors, get, saveEnv } from '@/lib/api';
import Button from '@/components/win/Button.svelte';

// environment variables of a Node or Rust app; a secret's value never
Expand Down Expand Up @@ -43,8 +43,14 @@
secret,
from,
}));
await post(`/domains/${domainId}/env`, list);
const report = await saveEnv(domainId, list);
// reload first: they are saved even when apply failed, a
// renamed secret's `from` must be its new name
vars = loaded(await get(`/domains/${domainId}/env`));
if (!report.ok)
throw new Error(
`Saved, but apply failed: ${applyErrors(report)}`,
);
saved = true;
setTimeout(() => (saved = false), 1500);
} catch (e: any) {
Expand Down Expand Up @@ -117,8 +123,8 @@
</Button>
</div>
<p class="hint">
The app gets them with <code>HOST</code> and <code>PORT</code> after Server →
Apply Changes, which restarts it.
The app gets them with <code>HOST</code> and <code>PORT</code>: saving
applies right away and restarts it.
</p>

<style lang="scss">
Expand Down
11 changes: 11 additions & 0 deletions webui/src/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,17 @@ export async function setMemoryReserve(reserveMb: number | null) {
if (!report.ok) throw new Error(applyErrors(report));
}

/**
* Saves an app's environment variables, apply runs right away and the app
* restarts with them.
*/
export function saveEnv(
domainId: number,
vars: { name: string; value: string; secret: boolean; from?: string }[],
): Promise<ApplyReport> {
return post(`/domains/${domainId}/env`, vars);
}

/** Puts a group in quarantine with the reason, apply runs right away. */
export function quarantineGroup(
group: Group,
Expand Down