Skip to content

A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.

TypeScript fluxerfluxerapp

feat(admin): split config, add notice, visits and friend toggle

Hampus0cb318e7d4d6
diff --git a/fluxer_admin/src/routes/system_actions/notices.rs b/fluxer_admin/src/routes/system_actions/notices.rs
new file mode 100644
index 000000000..868d14cb5
--- /dev/null
+++ b/fluxer_admin/src/routes/system_actions/notices.rs
@@ -0,0 +1,70 @@
+// SPDX-License-Identifier: AGPL-3.0-or-later
+
+use crate::{
+ api::types::{InstanceConfigUpdateRequest, InstanceNoticeUpdateRequest},
+ utils::forms::MultiValueForm,
+};
+
+const NOTICE_MAX_CHARS: usize = 1000;
+const LOCAL_MINUTE_TIMESTAMP_LEN: usize = 16;
+
+fn parse_notice_time(form: &MultiValueForm, key: &str) -> Result<Option<String>, &'static str> {
+ let Some(value) = form.clean(key) else {
+ return Ok(None);
+ };
+ let with_seconds = if value.len() == LOCAL_MINUTE_TIMESTAMP_LEN {
+ format!("{value}:00")
+ } else {
+ value
+ };
+ let format = time::format_description::parse_borrowed::<2>(
+ "[year]-[month]-[day]T[hour]:[minute]:[second]",
+ )
+ .map_err(|_| "Failed to read the notice time")?;
+ let parsed = time::PrimitiveDateTime::parse(&with_seconds, &format)
+ .map_err(|_| "Enter the notice times as a date and time")?;
+ parsed
+ .assume_utc()
+ .format(&time::format_description::well_known::Rfc3339)
+ .map(Some)
+ .map_err(|_| "Failed to format the notice time")
+}
+
+pub(super) fn build_notice_update(
+ form: &MultiValueForm,
+) -> Result<InstanceConfigUpdateRequest, &'static str> {
+ let message = if form.bool_value("notice_clear") {
+ None
+ } else {
+ form.clean("notice_message")
+ };
+ if message
+ .as_ref()
+ .is_some_and(|value| value.chars().count() > NOTICE_MAX_CHARS)
+ {
+ return Err("The notice must be 1000 characters or fewer");
+ }
+ let url = form.clean("notice_url");
+ if url
+ .as_deref()
+ .is_some_and(|value| !value.starts_with("https://") && !value.starts_with("http://"))
+ {
+ return Err("The notice link must start with https:// or http://");
+ }
+ let starts_at = parse_notice_time(form, "notice_starts_at")?;
+ let ends_at = parse_notice_time(form, "notice_ends_at")?;
+ if let (Some(start), Some(end)) = (&starts_at, &ends_at)
+ && end <= start
+ {
+ return Err("The notice must end after it starts");
+ }
+ Ok(InstanceConfigUpdateRequest {
+ notice: Some(InstanceNoticeUpdateRequest {
+ message,
+ url,
+ starts_at,
+ ends_at,
+ }),
+ ..Default::default()
+ })
+}
diff --git a/fluxer_admin/src/routes/system_actions/policy.rs b/fluxer_admin/src/routes/system_actions/policy.rs
new file mode 100644
index 000000000..a0a5ceade
--- /dev/null
+++ b/fluxer_admin/src/routes/system_actions/policy.rs
@@ -0,0 +1,90 @@
+// SPDX-License-Identifier: AGPL-3.0-or-later
+
+use super::parse_tristate;
+use crate::{
+ api::types::{
+ InstanceConfigUpdateRequest, InstancePolicyUpdateRequest, InstanceServicesUpdateRequest,
+ PremiumMode,
+ },
+ utils::forms::MultiValueForm,
+};
+
+pub(super) enum CommunityAction {
+ Enable,
+ Disable,
+ Update,
+}
+
+pub(super) fn build_policy_update(form: &MultiValueForm) -> InstanceConfigUpdateRequest {
+ let direct_messages_disabled = form
+ .first("policy_direct_messages_disabled")
+ .map(|value| value == "true");
+ let friends_disabled = form
+ .first("policy_friends_disabled")
+ .map(|value| value == "true");
+ let direct_messages_locked = (form.bool_value("policy_direct_messages_unlock")
+ && direct_messages_disabled == Some(true))
+ .then_some(false);
+ let guild_create_access = form
+ .first("policy_guild_create_access")
+ .map(|value| value == "true");
+ let premium_mode = match form.first("policy_premium_mode") {
+ Some("mirror") => Some(PremiumMode::Mirror),
+ Some("everyone") => Some(PremiumMode::Everyone),
+ _ => None,
+ };
+ let services = {
+ let gif_enabled = parse_tristate(form, "policy_service_gif");
+ let youtube_enabled = parse_tristate(form, "policy_service_youtube");
+ let bluesky_enabled = parse_tristate(form, "policy_service_bluesky");
+ if gif_enabled.is_none() && youtube_enabled.is_none() && bluesky_enabled.is_none() {
+ None
+ } else {
+ Some(InstanceServicesUpdateRequest {
+ gif_enabled,
+ youtube_enabled,
+ bluesky_enabled,
+ })
+ }
+ };
+ InstanceConfigUpdateRequest {
+ policy: Some(InstancePolicyUpdateRequest {
+ direct_messages_disabled,
+ direct_messages_locked,
+ friends_disabled,
+ guild_create_access,
+ premium_mode,
+ services,
+ ..Default::default()
+ }),
+ ..Default::default()
+ }
+}
+
+pub(super) fn build_single_community_update(
+ form: &MultiValueForm,
+ action: CommunityAction,
+) -> InstanceConfigUpdateRequest {
+ let enabled = match action {
+ CommunityAction::Enable => Some(true),
+ CommunityAction::Disable => Some(false),
+ CommunityAction::Update => None,
+ };
+ let keeps_mode = !matches!(action, CommunityAction::Disable);
+ InstanceConfigUpdateRequest {
+ policy: Some(InstancePolicyUpdateRequest {
+ single_community_enabled: enabled,
+ single_community_name: form
+ .clean("single_community_name")
+ .filter(|_| matches!(action, CommunityAction::Enable)),
+ single_community_guild_id: form
+ .clean("single_community_guild_id")
+ .filter(|_| keeps_mode),
+ single_community_add_members: (keeps_mode
+ && form.bool_value("single_community_add_members"))
+ .then_some(true),
+ ..Default::default()
+ }),
+ ..Default::default()
+ }
+}
diff --git a/fluxer_admin/src/templates/pages/instance_config.rs b/fluxer_admin/src/templates/pages/instance_config.rs
index 006a34b13..ae04a337b 100644
--- a/fluxer_admin/src/templates/pages/instance_config.rs
+++ b/fluxer_admin/src/templates/pages/instance_config.rs
@@ -2,16 +2,13 @@
use crate::{
api::types::{
- AccountIdentityConfigResponse, AccountIdentityMode, AppPublicConfigResponse,
- BRANDING_ASSET_ACCEPT, BRANDING_ASSET_MAX_IMAGE_CHARS, BrandingAssetKind,
- CAPTCHA_COST_RANGE, CAPTCHA_MAX_COUNTER_RANGE, CaptchaConfigResponse,
- DOMAIN_MIGRATION_DEFAULT_SALT, DomainMigrationConfigResponse,
- EXPERIMENT_MAX_ROLLOUT_COUNTRY_CODES, EXPERIMENT_MAX_TARGETED_USERS,
- ExperimentDeliveryConfigResponse, GatewayRolloutConfigResponse, InstanceConfigResponse,
- InstanceIntegrationsResponse, InstanceMediaResponse, InstancePolicyResponse,
- InstanceRegistrationResponse, LimitConfigResponse, PremiumMode, PushRelayConfigResponse,
- RegistrationUrlResponse, SsoConfigResponse, TagStyle, VOICE_P2P_DEFAULT_SALT,
- VOICE_P2P_MAX_PARTICIPANTS_RANGE, VoiceP2pConfigResponse,
+ AccountIdentitySettings, AppPublicConfigResponse, CaptchaProvider, CleanupMode,
+ DateOfBirthPolicy, EXPERIMENT_MAX_ROLLOUT_COUNTRY_CODES, EXPERIMENT_MAX_TARGETED_USERS,
+ EmailDeliveryMode, EmailDeliveryState, ExperimentDeliveryConfigResponse,
+ GUILD_VISITS_DEFAULT_SALT, GatewayRolloutConfigResponse, GuildJoinGate,
+ GuildVisitsConfigResponse, IdentifierFirstMode, InstanceConfigResponse,
+ InstanceNoticeResponse, InteractionTierMode, LastSessionCleanupMode, LimitConfigResponse,
+ PushRelayConfigResponse, VerificationBasis,
},
config::AdminConfig,
middleware::auth::AuthContext,
@@ -19,28 +16,79 @@ use crate::{
components::{
badge::{BadgeVariant, badge},
form::{
- FORM_INPUT_CLASS, checkbox, csrf_input, danger_button, form_actions,
- form_field_group, secondary_button_link, select_input, submit_button, text_input,
- textarea_input,
+ Checkbox, FORM_INPUT_CLASS, FORM_LABEL_CLASS, FORM_TEXTAREA_CLASS, NumberField,
+ csrf_input, form_actions, form_field_group, secondary_button_link, select_input,
+ submit_button, text_input, textarea_input,
},
page_container::page_header,
section_card::{section_card_simple, section_card_with_description},
},
layout::admin_layout,
- pages::instance_billing::premium_billing_section,
+ pages::{
+ instance_billing::premium_billing_section, instance_branding::branding_section,
+ instance_registration::registration_config_section,
+ },
},
utils::timestamps::format_admin_timestamp,
};
-use maud::{Markup, PreEscaped, html};
+use maud::{Markup, html};
+
+mod accounts;
+mod captcha;
+mod experiments;
+mod integrations;
+mod media;
+mod policy;
+mod sso;
+
+use self::{
+ accounts::{AccountsSectionInput, account_identity_section, accounts_section},
+ captcha::captcha_section,
+ experiments::{domain_migration_section, voice_p2p_section},
+ integrations::integrations_config_section,
+ media::{HostingMode, media_config_section},
+ policy::policy_config_section,
+ sso::sso_config_section,
+};
-fn format_percent(value: f64) -> String {
- if value.fract() == 0.0 {
- format!("{}", value as u64)
- } else {
- value.to_string()
+pub const LOADED_CONFIG_FIELD: &str = "loaded_config";
+
+#[derive(Clone, Copy)]
+pub(crate) struct ConfigForm<'a> {
+ pub(crate) csrf_token: &'a str,
+ pub(crate) loaded: &'a str,
+}
+
+impl ConfigForm<'_> {
+ pub(crate) fn fields(&self) -> Markup {
+ html! {
+ (csrf_input(self.csrf_token))
+ input type="hidden" name=(LOADED_CONFIG_FIELD) value=(self.loaded);
+ }
}
}
+pub const REGISTRATION_ALLOWED_EMAIL_DOMAINS_FIELD: &str = "registration_allowed_email_domains";
+pub const SSO_ALLOWED_DOMAINS_FIELD: &str = "sso_allowed_domains";
+
+fn inherit_select(name: &str, label: &str, override_value: Option<bool>) -> Markup {
+ let selected = match override_value {
+ None => "inherit",
+ Some(true) => "on",
+ Some(false) => "off",
+ };
+ select_input(
+ name,
+ label,
+ &[
+ ("inherit", "Inherit env default"),
+ ("on", "Force on"),
+ ("off", "Force off"),
+ ],
+ selected,
+ )
+}
+
fn format_decimal(value: f64) -> String {
if value.fract() == 0.0 {
format!("{}", value as u64)
@@ -76,29 +124,6 @@ fn experiment_rollout_country_codes_field(name: &str, country_codes: &[String])
}
}
-fn number_field(
- name: &str,
- label: &str,
- value: &str,
- min: Option<u32>,
- max: Option<u32>,
- step: &str,
- helper: Option<&str>,
-) -> Markup {
- form_field_group(
- label,
- name,
- false,
- None,
- helper,
- html! {
- input type="number" id=(name) name=(name) step=(step)
- value=(value)
- min=[min] max=[max] class=(FORM_INPUT_CLASS);
- },
- )
-}
-
pub fn instance_config_page(
config: &AdminConfig,
auth: &AuthContext,
@@ -107,6 +132,13 @@ pub fn instance_config_page(
limit_config: Option<&LimitConfigResponse>,
) -> Markup {
let base = &config.base_path;
+ let loaded = instance_config
+ .map(InstanceConfigResponse::loaded_marker)
+ .unwrap_or_default();
+ let config_form = ConfigForm {
+ csrf_token,
+ loaded: &loaded,
+ };
let content = html! {
(page_header("Instance Configuration", Some("Manage instance-wide settings")))
div class="space-y-10" {
@@ -115,16 +147,18 @@ pub fn instance_config_page(
(config_group(
"Identity & branding",
"How the instance presents itself to clients and the public discovery document.",
- html! {
- (app_public_config_section(
- base,
- csrf_token,
+ app_public_config_section(
+ config,
+ config_form,
&instance_config.app_public,
- instance_config.self_hosted,
- ))
- },
+ ),
))
}
+ (config_group(
+ "Notice",
+ "A message for everyone on the instance, shown in the app.",
+ notice_section(base, config_form, instance_config.notice.as_ref()),
+ ))
(config_group(
"Access & accounts",
"Who can sign in and create accounts on this instance.",
@@ -134,91 +168,105 @@ pub fn instance_config_page(
}
(registration_config_section(
config,
- csrf_token,
+ config_form,
&instance_config.registration,
- instance_config.app_public.registration.collect_date_of_birth,
- instance_config.self_hosted,
+ instance_config.account_identity.mode,
+ ))
+ (sso_config_section(base, config_form, &instance_config.sso))
+ (accounts_section(
+ base,
+ config_form,
+ &AccountsSectionInput {
+ auth: &instance_config.auth,
+ accounts: &instance_config.accounts,
+ identity: AccountIdentitySettings {
+ mode: instance_config.account_identity.mode,
+ tag_style: instance_config.account_identity.tag_style,
+ emails_enabled: instance_config.integrations.email.delivery_state
+ == EmailDeliveryState::On,
+ },
+ delivery_state: instance_config.integrations.email.delivery_state,
+ captcha_provider: instance_config.captcha.provider,
+ guild_visits_enabled: instance_config.guild_visits.enabled,
+ },
))
- (sso_config_section(base, csrf_token, &instance_config.sso))
+ (guild_visits_section(base, config_form, &instance_config.guild_visits))
},
))
(config_group(
"Bot protection",
"A proof-of-work check on sign-up, login, password reset and a few other abuse-prone actions.",
- html! {
- (captcha_section(base, csrf_token, &instance_config.captcha))
- },
+ captcha_section(
+ base,
+ config_form,
+ &instance_config.captcha,
+ instance_config.auth.instant_accounts.enabled,
+ ),
))
@if instance_config.self_hosted {
(config_group(
"Community & policy",
"Community shape, direct messaging, the premium model, and optional embed services.",
- html! {
- (policy_config_section(
+ policy_config_section(
base,
- csrf_token,
+ config_form,
&instance_config.policy,
&instance_config.app_public.branding.premium_product_name,
instance_config.billing.enabled == Some(true),
- ))
- },
+ ),
))
(config_group(
"Premium & billing",
"The premium tier's name, Stripe credentials and the prices members pay.",
- html! {
- (premium_billing_section(
+ premium_billing_section(
base,
- csrf_token,
+ config_form,
&instance_config.app_public.branding,
&instance_config.billing,
instance_config.policy.premium_mode,
- ))
- },
+ ),
))
}
(config_group(
"Runtime integrations",
"Credentials and provider choices that override environment variables at runtime.",
- html! {
- (integrations_config_section(
+ integrations_config_section(
base,
- csrf_token,
+ config_form,
&instance_config.integrations,
instance_config.account_identity.mode,
&instance_config.app_public.branding.product_name,
- ))
- },
+ ),
))
(config_group(
"Push notifications",
"Consent for the relay that delivers official mobile app notifications.",
- html! {
- (push_relay_section(base, csrf_token, &instance_config.push_relay))
- },
+ push_relay_section(base, config_form, &instance_config.push_relay),
))
(config_group(
"Media & retention",
"Attachment expiry rules that can be changed without editing environment variables.",
- html! {
- (media_config_section(
+ media_config_section(
base,
- csrf_token,
+ config_form,
&instance_config.media,
- instance_config.self_hosted,
- ))
- },
+ if instance_config.self_hosted {
+ HostingMode::SelfHosted
+ } else {
+ HostingMode::Hosted
+ },
+ ),
))
(config_group(
"Infrastructure & limits",
"Gateway rollout behavior and the limit rules applied to users and guilds.",
html! {
- (gateway_rollout_section(base, csrf_token, &instance_config.gateway_rollout))
+ (gateway_rollout_section(base, config_form, &instance_config.gateway_rollout))
@if !instance_config.self_hosted {
- (domain_migration_section(base, csrf_token, &instance_config.domain_migration))
+ (domain_migration_section(base, config_form, &instance_config.domain_migration))
}
- (voice_p2p_section(base, csrf_token, &instance_config.voice_p2p))
- (experiment_delivery_section(base, csrf_token, &instance_config.experiment_delivery))
+ (voice_p2p_section(base, config_form, &instance_config.voice_p2p))
+ (experiment_delivery_section(base, config_form, &instance_config.experiment_delivery))
@if let Some(limit_config) = limit_config {
(limit_config_section(base, limit_config))
} @else {
@@ -266,992 +314,207 @@ fn config_group(title: &str, description: &str, content: Markup) -> Markup {
}
}
-fn policy_config_section(
+fn notice_section(
base: &str,
- csrf_token: &str,
- policy: &InstancePolicyResponse,
- premium_name: &str,
- billing_enabled: bool,
+ config_form: ConfigForm<'_>,
+ notice: Option<&InstanceNoticeResponse>,
) -> Markup {
+ let local_value = |value: Option<&str>| {
+ value
+ .map(|iso| iso.chars().take(16).collect::<String>())
+ .unwrap_or_default()
+ };
+ let starts_at = local_value(notice.and_then(|notice| notice.starts_at.as_deref()));
+ let ends_at = local_value(notice.and_then(|notice| notice.ends_at.as_deref()));
section_card_with_description(
- "Community & Policy",
- "Control whether this instance runs as a single community, whether direct messages and \
- friends are available, which premium model applies, and which optional embed services \
- are enabled.",
+ "Instance notice",
+ "A short message shown to everyone in the app, such as planned maintenance. It appears \
+ from the start time until the end time, and people can dismiss it.",
html! {
- div class="space-y-8" {
- (single_community_form(base, csrf_token, policy))
- (direct_messages_form(base, csrf_token, policy))
- (premium_mode_form(base, csrf_token, policy, premium_name, billing_enabled))
- (community_creation_form(base, csrf_token, policy))
- (services_form(base, csrf_token, policy))
- }
- },
- )
-}
-
-fn single_community_form(base: &str, csrf_token: &str, policy: &InstancePolicyResponse) -> Markup {
- let status = if policy.single_community_enabled {
- ("Enabled", BadgeVariant::Success)
- } else {
- ("Disabled", BadgeVariant::Default)
- };
- html! {
- div class="space-y-4" {
- div class="flex flex-wrap items-center gap-2" {
- h3 class="text-sm font-semibold text-neutral-900" { "Single community" }
- (badge(status.0, status.1))
- }
- @if let Some(guild_id) = policy.single_community_guild_id.as_deref() {
- p class="break-all text-xs text-neutral-500" { "Community guild ID: " (guild_id) }
- }
- @if policy.single_community_enabled {
- p class="text-sm text-neutral-500" {
- "This instance funnels every member into a single community. You can turn this \
- off and on again from here. The community itself is kept either way."
- }
- form method="post" action={(base) "/instance-config?action=disable_single_community"} {
- (csrf_input(csrf_token))
- (form_actions(html! {
- (danger_button("Disable single-community mode"))
- }))
- }
- } @else if policy.single_community_guild_id.is_some() {
- p class="text-sm text-neutral-500" {
- "Single-community mode is off. Turning it on again reuses the community above \
- if it still exists, otherwise a new one is created."
- }
- form method="post" action={(base) "/instance-config?action=enable_single_community"} {
- (csrf_input(csrf_token))
- (form_actions(html! {
- (submit_button("Enable single-community mode"))
- }))
- }
- } @else {
- p class="text-sm text-neutral-500" {
- "Single-community mode is off. It can only be turned on for the first time \
- from the self-host setup wizard."
- }
- }
- }
- }
-}
-
-fn direct_messages_form(base: &str, csrf_token: &str, policy: &InstancePolicyResponse) -> Markup {
- html! {
- div class="space-y-4 border-t border-neutral-200 pt-6" {
- div class="flex flex-wrap items-center gap-2" {
- h3 class="text-sm font-semibold text-neutral-900" { "Direct messages & friends" }
- @if policy.direct_messages_locked {
- (badge("Locked", BadgeVariant::Warning))
- }
- }
- @if policy.direct_messages_locked {
- p class="text-sm text-neutral-500" {
- @if policy.direct_messages_disabled {
- "Direct messages and friends are disabled and locked for this instance."
- } @else {
- "Direct messages and friends are enabled and locked for this instance."
- }
- }
- } @else {
- form method="post" action={(base) "/instance-config?action=update_policy"} {
- (csrf_input(csrf_token))
- div class="space-y-4" {
- (select_input("policy_direct_messages_disabled", "Direct messages & friends", &[
- ("false", "Enabled"),
- ("true", "Disabled"),
- ], if policy.direct_messages_disabled { "true" } else { "false" }))
- p class="text-xs text-neutral-500" {
- "Re-enabling direct messages after they have been disabled locks this \
- setting permanently."
- }
- (form_actions(html! {
- (submit_button("Save direct message policy"))
- }))
- }
- }
- }
- }
- }
-}
-
-fn premium_mode_form(
- base: &str,
- csrf_token: &str,
- policy: &InstancePolicyResponse,
- premium_name: &str,
- billing_enabled: bool,
-) -> Markup {
- let mirror_label = format!("Mirror (Free and {premium_name} tiers)");
- let everyone_label = format!("Everyone (every member gets {premium_name} limits)");
- html! {
- div class="space-y-4 border-t border-neutral-200 pt-6" {
- h3 class="text-sm font-semibold text-neutral-900" { "Premium model" }
- form method="post" action={(base) "/instance-config?action=update_policy"} {
- (csrf_input(csrf_token))
- div class="space-y-4" {
- (select_input("policy_premium_mode", "Premium model", &[
- ("mirror", mirror_label.as_str()),
- ("everyone", everyone_label.as_str()),
- ], policy.premium_mode.as_str()))
- p class="text-xs text-neutral-500" {
- "Limits you have not edited follow the model. Limits you changed under Limit \
- Config keep your values in both models."
- }
- @if billing_enabled && matches!(policy.premium_mode, PremiumMode::Mirror) {
- p class="text-sm text-amber-700" {
- "Billing is enabled. Disable it under Premium & billing before switching \
- the premium model to Everyone."
- }
- }
- (form_actions(html! {
- (submit_button("Save premium model"))
- }))
- }
- }
- }
- }
-}
-
-fn community_creation_form(
- base: &str,
- csrf_token: &str,
- policy: &InstancePolicyResponse,
-) -> Markup {
- html! {
- div id="community-creation" class="space-y-4 border-t border-neutral-200 pt-6" {
- h3 class="text-sm font-semibold text-neutral-900" { "Community creation" }
- form method="post" action={(base) "/instance-config?action=update_policy"} {
- (csrf_input(csrf_token))
+ form method="post" action={(base) "/instance-config?action=update_notice"} {
+ (config_form.fields())
div class="space-y-4" {
- (select_input("policy_guild_create_access", "Who can create communities", &[
- ("true", "Everyone"),
- ("false", "Restricted"),
- ], if policy.guild_create_access { "true" } else { "false" }))
- p class="text-xs text-neutral-500" {
- "When restricted, only admins with the wildcard ACL and users matched by a "
- a href={(base) "/limit-config"} class="text-blue-600 hover:underline" {
- "limit rule"
- }
- " that grants Community Creation Access can create communities."
+ (textarea_input(
+ "notice_message",
+ "Message",
+ "We are upgrading the server on Saturday at 10:00 UTC. Expect about 15 minutes of downtime.",
+ notice.map(|notice| notice.message.as_str()).unwrap_or(""),
+ 3,
+ false,
+ ))
+ (text_input(
+ "notice_url",
+ "Link (optional)",
+ notice.and_then(|notice| notice.url.as_deref()).unwrap_or(""),
+ "https://status.example.com",
+ ))
+ div class="grid grid-cols-1 gap-4 sm:grid-cols-2" {
+ (form_field_group("Starts (UTC, optional)", "notice_starts_at", false, None, None, html! {
+ input type="datetime-local" id="notice_starts_at" name="notice_starts_at"
+ value=(starts_at) class=(FORM_INPUT_CLASS);
+ }))
+ (form_field_group("Ends (UTC, optional)", "notice_ends_at", false, None, None, html! {
+ input type="datetime-local" id="notice_ends_at" name="notice_ends_at"
+ value=(ends_at) class=(FORM_INPUT_CLASS);
+ }))
}
- (form_actions(html! {
- (submit_button("Save community creation policy"))
- }))
- }
- }
- }
- }
-}
-
-fn service_select(name: &str, label: &str, override_value: Option<bool>, resolved: bool) -> Markup {
- let selected = match override_value {
- None => "inherit",
- Some(true) => "on",
- Some(false) => "off",
- };
- let resolved_text = if resolved {
- "Effective: enabled"
- } else {
- "Effective: disabled"
- };
- html! {
- div class="space-y-2" {
- (select_input(name, label, &[
- ("inherit", "Inherit env default"),
- ("on", "Force on"),
- ("off", "Force off"),
- ], selected))
- p class="text-xs text-neutral-500" { (resolved_text) }
- }
- }
-}
-
-fn services_form(base: &str, csrf_token: &str, policy: &InstancePolicyResponse) -> Markup {
- let available = &policy.services_available;
- if !available.gif && !available.youtube && !available.bluesky {
- return html! {
- div class="space-y-4 border-t border-neutral-200 pt-6" {
- h3 class="text-sm font-semibold text-neutral-900" { "Optional services" }
- p class="text-sm text-neutral-500" {
- "No optional embed services are available in this environment."
- }
- }
- };
- }
- html! {
- div class="space-y-4 border-t border-neutral-200 pt-6" {
- h3 class="text-sm font-semibold text-neutral-900" { "Optional services" }
- p class="text-sm text-neutral-500" {
- "Override the environment default for each optional embed service. \
- \"Inherit env default\" keeps the value configured for this deployment."
- }
- form method="post" action={(base) "/instance-config?action=update_policy"} {
- (csrf_input(csrf_token))
- div class="space-y-4" {
- div class="grid grid-cols-1 gap-4 sm:grid-cols-3" {
- @if available.gif {
- (service_select(
- "policy_service_gif",
- "GIF picker",
- policy.services.gif_enabled,
- policy.services_resolved.gif_enabled,
- ))
- }
- @if available.youtube {
- (service_select(
- "policy_service_youtube",
- "YouTube embeds",
- policy.services.youtube_enabled,
- policy.services_resolved.youtube_enabled,
- ))
- }
- @if available.bluesky {
- (service_select(
- "policy_service_bluesky",
- "Bluesky embeds",
- policy.services.bluesky_enabled,
- policy.services_resolved.bluesky_enabled,
- ))
- }
+ @if notice.is_some() {
+ (Checkbox {
+ name: "notice_clear",
+ value: "true",
+ label: "Remove the notice",
+ checked: false,
+ enabled: true,
+ }.render())
}
(form_actions(html! {
- (submit_button("Save optional services"))
+ (submit_button("Save notice"))
}))
}
}
- }
- }
-}
-
-fn secret_badge(label: &str, is_set: bool) -> Markup {
- if is_set {
- badge(&format!("{label} set"), BadgeVariant::Success)
- } else {
- badge(&format!("{label} missing"), BadgeVariant::Default)
- }
-}
-
-fn password_input(name: &str, label: &str, helper: Option<&str>) -> Markup {
- form_field_group(
- label,
- name,
- false,
- None,
- helper,
- html! {
- input type="password" id=(name) name=(name) value="" class=(FORM_INPUT_CLASS)
- autocomplete="new-password";
- },
- )
-}
-
-fn smtp_tls_mode_summary(mode: &str) -> &str {
- match mode {
- "implicit" => "implicit TLS",
- "starttls" => "required STARTTLS",
- "opportunistic" => "STARTTLS when the server offers it",
- "none" => "no encryption",
- other => other,
- }
-}
-
-fn account_identity_section(account_identity: &AccountIdentityConfigResponse) -> Markup {
- let description = match account_identity.mode {
- AccountIdentityMode::Username => {
- "Members sign in with a username and password. The instance never collects an email \
- address. A member who forgets their password uses their recovery kit or a reset link \
- from an admin."
- }
- AccountIdentityMode::Email => "Members sign in with an email address and password.",
- };
- section_card_with_description(
- "Sign-in Method",
- "How members identify themselves when they sign in.",
- html! {
- div class="space-y-3" {
- div class="flex flex-wrap items-center gap-2" {
- h3 class="text-sm font-semibold text-neutral-900" {
- (account_identity.mode.label())
- }
- @match account_identity.locked {
- Some(true) => (badge("Fixed", BadgeVariant::Default)),
- Some(false) => (badge("Not fixed yet", BadgeVariant::Warning)),
- None => {}
- }
- }
- p class="text-sm text-neutral-600" { (description) }
- @if !account_identity.mode.is_username() {
- div class="flex flex-wrap items-center gap-2" {
- h3 class="text-sm font-semibold text-neutral-900" {
- (account_identity.tag_style.label())
- }
- }
- p class="text-sm text-neutral-600" {
- @match account_identity.tag_style {
- TagStyle::None => {
- "Each name belongs to one person and is shown without a tag."
- }
- TagStyle::Random => {
- "Names have a random tag, like alex#4821, so several people can share a name."
- }
- }
- }
- }
- p class="text-xs text-neutral-500" {
- @if account_identity.mode.is_username() {
- "The sign-in method is chosen during setup. It cannot be changed once setup is complete or the first account exists."
- } @else {
- "The sign-in method and the username tags are chosen during setup. They cannot be changed once setup is complete or the first account exists."
- }
- }
- }
},
)
}
-fn integrations_config_section(
- base: &str,
- csrf_token: &str,
- integrations: &InstanceIntegrationsResponse,
- account_identity: AccountIdentityMode,
- product_name: &str,
+fn app_public_config_section(
+ config: &AdminConfig,
+ config_form: ConfigForm<'_>,
+ app_public: &AppPublicConfigResponse,
) -> Markup {
- let smtp_port = integrations
- .email
- .smtp
- .port
- .map(|port| port.to_string())
- .unwrap_or_else(|| "587".to_owned());
+ let base = &config.base_path;
+ let host = web_app_host(&config.web_app_endpoint);
section_card_with_description(
- "Runtime Integrations",
- "Configure optional providers without changing environment variables. Blank secret fields keep the current value.",
+ "Public App Identity",
+ "The name, color and images people see on the sign-in page, in the apps and in the browser. The preview shows each place they are used.",
html! {
- form method="post" action={(base) "/instance-config?action=update_integrations"} {
- (csrf_input(csrf_token))
- div class="space-y-8" {
- div class="space-y-4" {
- div class="flex flex-wrap items-center gap-2" {
- h3 class="text-sm font-semibold text-neutral-900" { "GIF provider" }
- (secret_badge("KLIPY key", integrations.gif.klipy_api_key_set))
- }
- div class="grid grid-cols-1 gap-4" {
- (password_input("integration_klipy_api_key", "KLIPY API key", Some("Leave blank to keep the current key.")))
- }
- }
-
- div class="space-y-4 border-t border-neutral-200 pt-6" {
- div class="flex flex-wrap items-center gap-2" {
- h3 class="text-sm font-semibold text-neutral-900" { "YouTube Data API" }
- (secret_badge("API key", integrations.youtube.api_key_set))
- }
- (password_input("integration_youtube_api_key", "YouTube API key", Some("Leave blank to keep the current key.")))
- }
-
- @if !account_identity.is_username() {
- div class="space-y-4 border-t border-neutral-200 pt-6" {
- div class="flex flex-wrap items-center gap-2" {
- h3 class="text-sm font-semibold text-neutral-900" { "Email delivery" }
- @if integrations.email.effective_enabled {
- (badge("Effective: enabled", BadgeVariant::Success))
- } @else {
- (badge("Effective: disabled", BadgeVariant::Default))
- }
- @if integrations.email.effective_disable_new_ip_authorization {
- (badge("IP auth disabled", BadgeVariant::Warning))
- } @else {
- (badge("IP auth required", BadgeVariant::Default))
- }
- (secret_badge("SMTP password", integrations.email.smtp.password_set))
- }
- input type="hidden" name="integration_email_present" value="1";
- (checkbox("integration_email_enabled", "true", "Enable email delivery", integrations.email.effective_enabled, true))
+ div class="space-y-8" {
+ (branding_section(base, config_form, app_public, &host))
+ div class="space-y-4 border-t border-neutral-200 pt-6" {
+ h3 class="text-sm font-semibold text-neutral-900" { "Legal Documents" }
+ form method="post" action={(base) "/instance-config?action=update_app_legal"} {
+ (config_form.fields())
+ div class="space-y-4" {
div class="grid grid-cols-1 gap-4 sm:grid-cols-2" {
(text_input(
- "integration_email_from_email",
- "From email",
- integrations.email.from_email.as_deref().unwrap_or(""),
- ))
- (text_input(
- "integration_email_from_name",
- "From name",
- integrations.email.from_name.as_deref().unwrap_or(""),
- product_name,
- ))
- (text_input(
- "integration_smtp_host",
- "SMTP host",
- integrations.email.smtp.host.as_deref().unwrap_or(""),
- "smtp.example.com",
+ "app_terms_url",
+ "Terms URL",
+ app_public.legal.terms_url.as_deref().unwrap_or(""),
+ "https://example.com/terms",
))
(text_input(
- "integration_smtp_port",
- "SMTP port",
- &smtp_port,
- "587",
+ "app_privacy_url",
+ "Privacy URL",
+ app_public.legal.privacy_url.as_deref().unwrap_or(""),
+ "https://example.com/privacy",
))
(text_input(
- "integration_smtp_username",
- "SMTP username",
- integrations.email.smtp.username.as_deref().unwrap_or(""),
+ "app_guidelines_url",
+ "Community Guidelines URL",
+ app_public.legal.guidelines_url.as_deref().unwrap_or(""),
+ "https://example.com/guidelines",
))
- (password_input("integration_smtp_password", "SMTP password", Some("Leave blank to keep the current password.")))
}
- (select_input("integration_smtp_tls_mode", "SMTP encryption", &[
- ("", "Automatic"),
- ("implicit", "Implicit TLS"),
- ("starttls", "STARTTLS, required"),
- ("opportunistic", "STARTTLS, when the server offers it"),
- ("none", "None"),
- ], integrations.email.smtp.tls_mode.as_deref().unwrap_or("")))
p class="text-xs text-neutral-500" {
- "Automatic follows FLUXER_EMAIL_SMTP_TLS_MODE when it is set, then the older FLUXER_EMAIL_SMTP_SECURE, where true means implicit TLS on any port. With neither set it uses implicit TLS on port 465 and requires STARTTLS on every other port."
- }
- @if let Some(mode) = integrations.email.smtp.effective_tls_mode.as_deref() {
- p class="text-xs text-neutral-500" {
- "Outgoing email currently uses " (smtp_tls_mode_summary(mode))
- @if let Some(port) = integrations.email.smtp.port { " on port " (port) }
- "."
- }
- }
- (checkbox("integration_email_disable_new_ip_authorization", "true", "Disable new IP login authorization", integrations.email.disable_new_ip_authorization, true))
- div class="flex flex-wrap gap-2" {
- button type="submit"
- formaction={(base) "/instance-config?action=test_smtp"}
- class="inline-flex w-fit items-center justify-center gap-2 rounded-lg border border-neutral-300 bg-neutral-50 px-4 py-2 font-medium text-base text-neutral-700 transition-all duration-150 hover:border-neutral-400 hover:text-neutral-900 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-offset-white" {
- span { "Save and test SMTP" }
- }
+ "Registration asks for agreement only to the terms and privacy documents configured here. Leave both blank to hide legal consent on self-hosted registration."
}
p class="text-xs text-neutral-500" {
- "The test saves this form first, then connects with the saved settings, the same ones outgoing email uses."
- }
- }
- }
-
- div class="space-y-4 border-t border-neutral-200 pt-6" {
- div class="flex flex-wrap items-center gap-2" {
- h3 class="text-sm font-semibold text-neutral-900" { "Bluesky OAuth" }
- @if integrations.bluesky.effective_enabled {
- (badge("Effective: enabled", BadgeVariant::Success))
- } @else {
- (badge("Effective: disabled", BadgeVariant::Default))
+ "The community guidelines URL is linked from the app, the report flow and enforcement emails. Use an absolute http or https URL. Leave it blank to hide those links."
}
- (badge(&format!("{} signing key(s)", integrations.bluesky.key_count), BadgeVariant::Default))
- }
- (checkbox("integration_bluesky_enabled", "true", "Enable Bluesky OAuth", integrations.bluesky.effective_enabled, true))
- div class="grid grid-cols-1 gap-4 sm:grid-cols-2" {
- (text_input(
- "integration_bluesky_client_name",
- "Client name",
- integrations.bluesky.client_name.as_deref().unwrap_or(""),
- "Fluxer",
- ))
- (text_input(
- "integration_bluesky_client_uri",
- "Client URL",
- integrations.bluesky.client_uri.as_deref().unwrap_or(""),
- "https://example.com",
- ))
- (text_input(
- "integration_bluesky_logo_uri",
- "Logo URL",
- integrations.bluesky.logo_uri.as_deref().unwrap_or(""),
- "https://example.com/logo.png",
- ))
- (text_input(
- "integration_bluesky_tos_uri",
- "Terms URL",
- integrations.bluesky.tos_uri.as_deref().unwrap_or(""),
- "https://example.com/terms",
- ))
- (text_input(
- "integration_bluesky_policy_uri",
- "Privacy URL",
- integrations.bluesky.policy_uri.as_deref().unwrap_or(""),
- "https://example.com/privacy",
- ))
- (text_input("integration_bluesky_key_id", "New signing key ID", "", "atproto-key-1"))
- (password_input("integration_bluesky_private_key", "New private key", Some("Provide this only when adding or replacing runtime Bluesky keys.")))
+ (form_actions(html! {
+ (submit_button("Save Legal Documents"))
+ }))
}
}
-
- (form_actions(html! {
- (submit_button("Save runtime integrations"))
- }))
}
}
},
)
}
-fn media_config_section(
+fn web_app_host(endpoint: &str) -> String {
+ endpoint
+ .split_once("://")
+ .map_or(endpoint, |(_, rest)| rest)
+ .split('/')
+ .next()
+ .unwrap_or_default()
+ .to_owned()
+}
+
+fn gateway_rollout_section(
base: &str,
- csrf_token: &str,
- media: &InstanceMediaResponse,
- self_hosted: bool,
+ config_form: ConfigForm<'_>,
+ gateway_rollout: &GatewayRolloutConfigResponse,
) -> Markup {
- let decay = &media.attachment_decay;
- let effective = &decay.effective;
- let enabled = decay.enabled.unwrap_or(effective.enabled);
- let min_size_mb = format_decimal(decay.min_size_mb.unwrap_or(effective.min_size_mb));
- let max_size_mb = format_decimal(decay.max_size_mb.unwrap_or(effective.max_size_mb));
- let max_eligible_size_mb = format_decimal(
- decay
- .max_eligible_size_mb
- .unwrap_or(effective.max_eligible_size_mb),
- );
- let min_lifetime_days = decay
- .min_lifetime_days
- .unwrap_or(effective.min_lifetime_days)
- .to_string();
- let max_lifetime_days = decay
- .max_lifetime_days
- .unwrap_or(effective.max_lifetime_days)
- .to_string();
- let curve = format_decimal(decay.curve.unwrap_or(effective.curve));
- let renew_threshold_days = decay
- .renew_threshold_days
- .unwrap_or(effective.renew_threshold_days)
- .to_string();
- let renew_window_days = decay
- .renew_window_days
- .unwrap_or(effective.renew_window_days)
- .to_string();
- let description = if self_hosted {
- "Expire eligible attachments using size-based lifetimes. This is enabled by default and applies at runtime. On a self-hosted instance, changes also apply to attachments uploaded earlier, which are kept for at least the renew window before a new or shorter expiry deletes them."
- } else {
- "Expire eligible attachments using size-based lifetimes. This is enabled by default and applies at runtime. Changes apply to attachments uploaded from then on."
- };
section_card_with_description(
- "Media Expiry",
- description,
+ "Gateway Rollout Configuration",
+ "Control session and guild rollout percentages, NATS timeouts, and \
+ concurrency limits for gateway nodes. Changes propagate instantly \
+ via NATS.",
html! {
- form method="post" action={(base) "/instance-config?action=update_media"} {
- (csrf_input(csrf_token))
- div class="space-y-6" {
- div class="flex flex-wrap items-center gap-2" {
- @if effective.enabled {
- (badge("Effective: enabled", BadgeVariant::Success))
- } @else {
- (badge("Effective: disabled", BadgeVariant::Default))
- }
- }
- (checkbox("media_attachment_decay_enabled", "true", "Enable attachment expiry", enabled, true))
- div class="grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-3" {
- (number_field(
- "media_attachment_decay_min_size_mb",
- "Small file threshold (MB)",
- &min_size_mb,
- Some(1),
- Some(1_000_000),
- "0.1",
- Some("Attachments at or below this size keep the maximum lifetime."),
- ))
- (number_field(
- "media_attachment_decay_max_size_mb",
- "Large file threshold (MB)",
- &max_size_mb,
- Some(1),
- Some(1_000_000),
- "0.1",
- Some("Attachments at or above this size get the minimum lifetime."),
- ))
- (number_field(
- "media_attachment_decay_max_eligible_size_mb",
- "Maximum eligible size (MB)",
- &max_eligible_size_mb,
- Some(1),
- Some(1_000_000),
- "0.1",
- Some("Attachments above this size are not managed by expiry."),
- ))
- (number_field(
- "media_attachment_decay_min_lifetime_days",
- "Minimum lifetime (days)",
- &min_lifetime_days,
- Some(1),
- Some(36_500),
- "1",
- None,
- ))
- (number_field(
- "media_attachment_decay_max_lifetime_days",
- "Maximum lifetime (days)",
- &max_lifetime_days,
- Some(1),
- Some(36_500),
- "1",
- None,
- ))
- (number_field(
- "media_attachment_decay_curve",
- "Expiry curve",
- &curve,
- Some(0),
- Some(1),
- "0.05",
- Some("0 is linear. 1 is logarithmic."),
- ))
- (number_field(
- "media_attachment_decay_renew_threshold_days",
- "Renew threshold (days)",
- &renew_threshold_days,
- Some(1),
- Some(365),
- "1",
- Some("Viewed attachments renew when expiry is this close."),
- ))
- (number_field(
- "media_attachment_decay_renew_window_days",
- "Renew window (days)",
- &renew_window_days,
- Some(1),
- Some(365),
- "1",
- Some("Renewed attachments are extended by this many days."),
- ))
- }
- (form_actions(html! {
- (submit_button("Save media expiry"))
- }))
- }
- }
- },
- )
-}
-
-fn app_public_config_section(
- base: &str,
- csrf_token: &str,
- app_public: &AppPublicConfigResponse,
- self_hosted: bool,
-) -> Markup {
- let setup_helper = if self_hosted {
- "When this is unchecked, the web app shows the self-host setup wizard."
- } else {
- "Hosted instances are treated as already configured by clients."
- };
- section_card_with_description(
- "Public App Identity",
- "Configure the public product name, client-visible brand assets, and initial setup state returned by the instance discovery document.",
- html! {
- div class="space-y-8" {
- form method="post" action={(base) "/instance-config?action=update_app_public"} {
- (csrf_input(csrf_token))
- div class="space-y-6" {
- div class="grid grid-cols-1 gap-4 sm:grid-cols-2" {
- (text_input(
- "app_product_name",
- "Product Name",
- &app_public.branding.product_name,
- "Fluxer",
- ))
- (text_input(
- "app_theme_color",
- "Theme Color (hex)",
- app_public.branding.theme_color.as_deref().unwrap_or(""),
- "#4641d9",
- ))
- }
- div class="grid grid-cols-1 gap-4 sm:grid-cols-2" {
- @for kind in BrandingAssetKind::ALL {
- (branding_asset_field(kind, kind.url(&app_public.branding)))
- }
- (text_input(
- "app_status_page_url",
- "Status page URL",
- app_public.branding.status_page_url.as_deref().unwrap_or(""),
- "https://fluxerstatus.com",
- ))
- (text_input(
- "app_status_page_incident_history_url",
- "Status page history URL",
- app_public.branding.status_page_incident_history_url.as_deref().unwrap_or(""),
- "https://fluxerstatus.com/history",
- ))
- }
- div class="space-y-2" {
- (checkbox(
- "app_setup_configured",
- "true",
- "Setup complete",
- app_public.setup.configured,
- true,
- ))
- p class="text-xs text-neutral-500" { (setup_helper) }
- }
- (form_actions(html! {
- (submit_button("Save Public App Identity"))
- }))
- }
- }
- script { (PreEscaped(BRANDING_ASSET_SCRIPT)) }
- div class="space-y-4 border-t border-neutral-200 pt-6" {
- h3 class="text-sm font-semibold text-neutral-900" { "Legal Documents" }
- form method="post" action={(base) "/instance-config?action=update_app_legal"} {
- (csrf_input(csrf_token))
- div class="space-y-4" {
- div class="grid grid-cols-1 gap-4 sm:grid-cols-2" {
- (text_input(
- "app_terms_url",
- "Terms URL",
- app_public.legal.terms_url.as_deref().unwrap_or(""),
- "https://example.com/terms",
- ))
- (text_input(
- "app_privacy_url",
- "Privacy URL",
- app_public.legal.privacy_url.as_deref().unwrap_or(""),
- "https://example.com/privacy",
- ))
- (text_input(
- "app_guidelines_url",
- "Community Guidelines URL",
- app_public.legal.guidelines_url.as_deref().unwrap_or(""),
- "https://example.com/guidelines",
- ))
- }
- p class="text-xs text-neutral-500" {
- "Registration asks for agreement only to the terms and privacy documents configured here. Leave both blank to hide legal consent on self-hosted registration."
- }
- p class="text-xs text-neutral-500" {
- "The community guidelines URL is linked from the app, the report flow and enforcement emails. Use an absolute http or https URL. Leave it blank to hide those links."
- }
- (form_actions(html! {
- (submit_button("Save Legal Documents"))
- }))
- }
- }
- }
- }
- },
- )
-}
-
-pub fn branding_asset_field_id(kind: BrandingAssetKind) -> String {
- format!("branding-asset-{}", kind.as_str())
-}
-
-pub fn branding_asset_field(kind: BrandingAssetKind, url: Option<&str>) -> Markup {
- let name = format!("app_{}_url", kind.as_str());
- let placeholder = match kind {
- BrandingAssetKind::Favicon => "https://example.com/favicon.ico".to_owned(),
- _ => format!("https://example.com/{}.png", kind.as_str()),
- };
- html! {
- div id=(branding_asset_field_id(kind)) class="flex flex-col gap-2"
- data-branding-asset=(kind.as_str())
- data-branding-asset-max-chars=(BRANDING_ASSET_MAX_IMAGE_CHARS) {
- (text_input(&name, &format!("{} URL", kind.label()), url.unwrap_or(""), &placeholder))
- div class="flex items-center gap-2" {
- @if let Some(url) = url {
- img src=(url) alt={(kind.label()) " preview"}
- onerror="this.hidden=true"
- class="h-8 w-8 shrink-0 rounded-md border border-neutral-200 bg-neutral-50 object-contain";
- }
- input type="file" accept=(BRANDING_ASSET_ACCEPT) class="hidden"
- data-branding-asset-file
- aria-label={"Upload " (kind.as_str())};
- button type="button" data-branding-asset-upload
- class=(BRANDING_ASSET_BUTTON_CLASS) {
- "Upload"
- }
- @if url.is_some() {
- button type="button" data-branding-asset-remove
- class=(BRANDING_ASSET_BUTTON_CLASS) {
- "Remove"
- }
- }
- }
- }
- }
-}
-
-const BRANDING_ASSET_BUTTON_CLASS: &str = "inline-flex h-8 shrink-0 items-center justify-center \
- rounded-lg border border-neutral-300 bg-neutral-50 px-3 text-xs font-medium \
- text-neutral-700 transition-all hover:border-neutral-400 hover:text-neutral-900 \
- focus:outline-none focus:ring-2 focus:ring-brand-primary/20 \
- disabled:cursor-not-allowed disabled:opacity-50";
-
-const BRANDING_ASSET_SCRIPT: &str = r#"
-(function () {
- if (window.__adminBrandingAssetBound) return;
- window.__adminBrandingAssetBound = true;
- function toast(level, message) {
- document.body.dispatchEvent(new CustomEvent('showFlash', {detail: {level: level, message: message}}));
- }
- function toastFromResponse(response) {
- var raw = response.headers.get('X-Fluxer-Admin-Toast');
- if (!raw) return null;
- try {
- var parsed = JSON.parse(raw);
- return {
- level: parsed && parsed.level ? String(parsed.level) : 'info',
- message: parsed && parsed.message ? String(parsed.message) : ''
- };
- } catch (error) {
- return null;
- }
- }
- function fieldOf(element) {
- return element.closest('[data-branding-asset]');
- }
- function setBusy(field, busy) {
- field.setAttribute('aria-busy', busy ? 'true' : 'false');
- field.querySelectorAll('button').forEach(function (button) {
- button.disabled = busy;
- });
- }
- function send(field, action, image, failure) {
- var form = field.closest('form');
- var csrfInput = form ? form.querySelector('input[name="_csrf"]') : null;
- var token = csrfInput ? csrfInput.value || '' : '';
- var url = new URL(form ? form.getAttribute('action') || window.location.href : window.location.href, window.location.href);
- url.searchParams.set('action', action);
- var body = new URLSearchParams();
- body.set('_csrf', token);
- body.set('kind', field.getAttribute('data-branding-asset') || '');
- if (image !== null) body.set('image', image);
- setBusy(field, true);
- fetch(url.toString(), {
- method: 'POST',
- credentials: 'same-origin',
- headers: {
- 'Content-Type': 'application/x-www-form-urlencoded',
- 'HX-Request': 'true',
- 'HX-Target': field.id,
- 'X-CSRF-Token': token
- },
- body: body.toString()
- }).then(function (response) {
- var parsed = toastFromResponse(response);
- if (response.status !== 200) {
- setBusy(field, false);
- toast(parsed ? parsed.level : 'error', parsed ? parsed.message : failure);
- return;
- }
- return response.text().then(function (html) {
- var template = document.createElement('template');
- template.innerHTML = html.trim();
- var replacement = template.content.firstElementChild;
- if (replacement && replacement.id === field.id) {
- field.replaceWith(replacement);
- } else {
- setBusy(field, false);
- }
- if (parsed) toast(parsed.level, parsed.message);
- });
- }).catch(function () {
- setBusy(field, false);
- toast('error', failure);
- });
- }
- document.addEventListener('click', function (event) {
- var target = event.target;
- if (!(target instanceof Element)) return;
- var upload = target.closest('[data-branding-asset-upload]');
- if (upload) {
- var uploadField = fieldOf(upload);
- var file = uploadField ? uploadField.querySelector('[data-branding-asset-file]') : null;
- if (file) file.click();
- return;
- }
- var remove = target.closest('[data-branding-asset-remove]');
- if (remove) {
- var removeField = fieldOf(remove);
- if (removeField) send(removeField, 'remove_branding_asset', null, 'Failed to remove the image');
- }
- });
- document.addEventListener('change', function (event) {
- var input = event.target;
- if (!(input instanceof HTMLInputElement) || !input.hasAttribute('data-branding-asset-file')) return;
- var field = fieldOf(input);
- var selected = input.files && input.files[0];
- input.value = '';
- if (!field || !selected) return;
- var maxChars = Number(field.getAttribute('data-branding-asset-max-chars')) || 0;
- setBusy(field, true);
- var reader = new FileReader();
- reader.onload = function () {
- var dataUrl = typeof reader.result === 'string' ? reader.result : '';
- if (!dataUrl) {
- setBusy(field, false);
- toast('error', 'Failed to read the image');
- return;
- }
- if (maxChars > 0 && dataUrl.length > maxChars) {
- setBusy(field, false);
- toast('error', 'This image is too large to upload');
- return;
- }
- send(field, 'upload_branding_asset', dataUrl, 'Failed to upload the image');
- };
- reader.onerror = function () {
- setBusy(field, false);
- toast('error', 'Failed to read the image');
- };
- reader.readAsDataURL(selected);
- });
-})();
-"#;
-
-fn gateway_rollout_section(
- base: &str,
- csrf_token: &str,
- gateway_rollout: &GatewayRolloutConfigResponse,
-) -> Markup {
- section_card_with_description(
- "Gateway Rollout Configuration",
- "Control session and guild rollout percentages, NATS timeouts, and \
- concurrency limits for gateway nodes. Changes propagate instantly \
- via NATS.",
- html! {
- form method="post" action={(base) "/instance-config?action=update_gateway_rollout"} {
- (csrf_input(csrf_token))
+ form method="post" action={(base) "/instance-config?action=update_gateway_rollout"} {
+ (config_form.fields())
div class="space-y-6" {
h3 class="text-sm font-semibold text-neutral-900" { "Rollout" }
div class="grid grid-cols-1 gap-4 sm:grid-cols-2" {
- (number_field(
- "gateway_rollout_session_rollout_percentage",
- "Session Rollout (%)", &format_percent(gateway_rollout.session_rollout_percentage),
- Some(0), Some(100), "1",
- Some("Percentage of sessions allowed to start (0-100)."),
- ))
+ (NumberField {
+ name: "gateway_rollout_session_rollout_percentage",
+ label: "Session Rollout (%)",
+ value: &format_decimal(gateway_rollout.session_rollout_percentage),
+ min: Some(0),
+ max: Some(100),
+ step: "1",
+ helper: Some("Percentage of sessions allowed to start (0-100)."),
+ placeholder: None,
+ }.render())
(select_input("gateway_rollout_session_rollout_mode", "Session Rollout Mode", &[
("modulo", "Modulo"),
("random", "Random"),
], gateway_rollout.session_rollout_mode.as_str()))
}
- (number_field(
- "gateway_rollout_guild_rollout_percentage",
- "Guild Rollout (%)", &format_percent(gateway_rollout.guild_rollout_percentage),
- Some(0), Some(100), "1",
- Some("Percentage of guilds allowed to start (0-100). Uses modulo mode."),
- ))
+ (NumberField {
+ name: "gateway_rollout_guild_rollout_percentage",
+ label: "Guild Rollout (%)",
+ value: &format_decimal(gateway_rollout.guild_rollout_percentage),
+ min: Some(0),
+ max: Some(100),
+ step: "1",
+ helper: Some("Percentage of guilds allowed to start (0-100). Uses modulo mode."),
+ placeholder: None,
+ }.render())
h3 class="text-sm font-semibold text-neutral-900" { "RPC and Concurrency" }
div class="grid grid-cols-1 gap-4 sm:grid-cols-3" {
- (number_field(
- "gateway_rollout_rpc_request_timeout_ms",
- "RPC Request Timeout (ms)", &gateway_rollout.rpc_request_timeout_ms.to_string(),
- Some(1000), Some(60000), "1",
- Some("Timeout for gateway-to-API RPC calls."),
- ))
- (number_field(
- "gateway_rollout_max_concurrent_session_starts",
- "Max Concurrent Session Starts", &gateway_rollout.max_concurrent_session_starts.to_string(),
- Some(1), None, "1",
- Some("Per-node concurrency limit."),
- ))
- (number_field(
- "gateway_rollout_max_concurrent_guild_starts",
- "Max Concurrent Guild Starts", &gateway_rollout.max_concurrent_guild_starts.to_string(),
- Some(1), None, "1",
- Some("Per-node concurrency limit."),
- ))
+ (NumberField {
+ name: "gateway_rollout_rpc_request_timeout_ms",
+ label: "RPC Request Timeout (ms)",
+ value: &gateway_rollout.rpc_request_timeout_ms.to_string(),
+ min: Some(1000),
+ max: Some(60000),
+ step: "1",
+ helper: Some("Timeout for gateway-to-API RPC calls."),
+ placeholder: None,
+ }.render())
+ (NumberField {
+ name: "gateway_rollout_max_concurrent_session_starts",
+ label: "Max Concurrent Session Starts",
+ value: &gateway_rollout.max_concurrent_session_starts.to_string(),
+ min: Some(1),
+ max: None,
+ step: "1",
+ helper: Some("Per-node concurrency limit."),
+ placeholder: None,
+ }.render())
+ (NumberField {
+ name: "gateway_rollout_max_concurrent_guild_starts",
+ label: "Max Concurrent Guild Starts",
+ value: &gateway_rollout.max_concurrent_guild_starts.to_string(),
+ min: Some(1),
+ max: None,
+ step: "1",
+ helper: Some("Per-node concurrency limit."),
+ placeholder: None,
+ }.render())
}
h3 class="text-sm font-semibold text-neutral-900" { "Voice E2EE" }
@@ -1271,7 +534,7 @@ fn gateway_rollout_section(
fn push_relay_section(
base: &str,
- csrf_token: &str,
+ config_form: ConfigForm<'_>,
push_relay: &PushRelayConfigResponse,
) -> Markup {
let status = if push_relay.relay_consent_accepted {
@@ -1291,19 +554,19 @@ fn push_relay_section(
The relay delivers them only after an operator accepts its privacy notice.",
html! {
form method="post" action={(base) "/instance-config?action=update_push_relay"} {
- (csrf_input(csrf_token))
+ (config_form.fields())
div class="space-y-6" {
div class="flex flex-wrap items-center gap-2" {
h3 class="text-sm font-semibold text-neutral-900" { "Relay consent" }
(badge(status.0, status.1))
}
- (checkbox(
- "push_relay_consent_accepted",
- "true",
- "Accept the push relay supplemental privacy notice",
- push_relay.relay_consent_accepted,
- true,
- ))
+ (Checkbox {
+ name: "push_relay_consent_accepted",
+ value: "true",
+ label: "Accept the push relay supplemental privacy notice",
+ checked: push_relay.relay_consent_accepted,
+ enabled: true,
+ }.render())
p class="text-xs text-neutral-500" {
"Until this is accepted official mobile app notifications are dropped. \
Self-hosted UnifiedPush and ntfy endpoints never reach the relay and are \
@@ -1339,324 +602,178 @@ fn push_relay_section(
)
}
-fn domain_migration_section(
- base: &str,
- csrf_token: &str,
- domain_migration: &DomainMigrationConfigResponse,
+const IDENTIFIER_FIRST_CHOICES: &[(IdentifierFirstMode, &str)] = &[
+ (
+ IdentifierFirstMode::Auto,
+ "Automatic, on while the instance sends email",
+ ),
+ (IdentifierFirstMode::On, "On"),
+ (IdentifierFirstMode::Off, "Off"),
+];
+
+const DATE_OF_BIRTH_CHOICES: &[(DateOfBirthPolicy, &str)] = &[
+ (DateOfBirthPolicy::Off, "Don't ask"),
+ (DateOfBirthPolicy::Ask, "Ask, but let people skip it"),
+ (
+ DateOfBirthPolicy::RequireNewAccounts,
+ "Require it from accounts created without one",
+ ),
+ (
+ DateOfBirthPolicy::RequireAll,
+ "Require it from every account without one",
+ ),
+];
+
+const INTERACTION_TIER_CHOICES: &[(InteractionTierMode, &str)] = &[
+ (InteractionTierMode::Legacy, "Keep the older limits"),
+ (
+ InteractionTierMode::Enforced,
+ "Only allow what does not reach other people",
+ ),
+];
+
+const GUILD_JOIN_GATE_CHOICES: &[(GuildJoinGate, &str)] = &[
+ (GuildJoinGate::Off, "Never ask"),
+ (
+ GuildJoinGate::VisitsCapable,
+ "Ask only on clients that can preview communities",
+ ),
+ (GuildJoinGate::Always, "Ask on every client"),
+];
+
+const VERIFICATION_BASIS_CHOICES: &[(VerificationBasis, &str)] = &[
+ (
+ VerificationBasis::Auto,
+ "Automatic, a confirmed email while the instance sends email, otherwise a password or passkey",
+ ),
+ (VerificationBasis::ConfirmedEmail, "A confirmed email"),
+ (VerificationBasis::LocalCredential, "A password or passkey"),
+];
+
+const CLEANUP_MODE_CHOICES: &[(CleanupMode, &str)] = &[
+ (CleanupMode::Off, "Off"),
+ (
+ CleanupMode::AfterInactivity,
+ "After the days below without use",
+ ),
+];
+
+const LAST_SESSION_CLEANUP_CHOICES: &[(LastSessionCleanupMode, &str)] = &[
+ (LastSessionCleanupMode::Off, "Keep the account"),
+ (
+ LastSessionCleanupMode::AfterGrace,
+ "Delete the account after the grace period",
+ ),
+];
+
+const CAPTCHA_PROVIDER_CHOICES: &[(CaptchaProvider, &str)] = &[
+ (CaptchaProvider::Altcha, "Proof-of-work check"),
+ (CaptchaProvider::None, "Off"),
+];
+
+const EMAIL_DELIVERY_CHOICES: &[(EmailDeliveryMode, &str)] = &[
+ (EmailDeliveryMode::Smtp, "Send email through SMTP"),
+ (EmailDeliveryMode::Off, "Off"),
+];
+
+fn choice_options<T: std::fmt::Display>(
+ choices: &[(T, &'static str)],
+) -> Vec<(String, &'static str)> {
+ choices
+ .iter()
+ .map(|(value, label)| (value.to_string(), *label))
+ .collect()
+}
+
+fn choice_select<T: std::fmt::Display>(
+ name: &str,
+ label: &str,
+ choices: &[(T, &'static str)],
+ selected: &T,
) -> Markup {
- let status = if domain_migration.enabled {
- ("Live", BadgeVariant::Success)
- } else {
- ("Inert", BadgeVariant::Default)
- };
- let included_user_ids = domain_migration.included_user_ids.join("\n");
- let excluded_user_ids = domain_migration.excluded_user_ids.join("\n");
- section_card_with_description(
- "Domain Migration",
- "Moves web clients of the official instance from the legacy web app origin to the new \
- one. Selected accounts copy their local data across and continue on the new origin. \
- Clients of other instances read this configuration and ignore it.",
- html! {
- form method="post" action={(base) "/instance-config?action=update_domain_migration"} {
- (csrf_input(csrf_token))
- div class="space-y-6" {
- div class="flex flex-wrap items-center gap-2" {
- h3 class="text-sm font-semibold text-neutral-900" { "Master switch" }
- (badge(status.0, status.1))
- span class="text-xs text-neutral-500" {
- "Config version " (domain_migration.config_version)
- }
- }
- (checkbox(
- "domain_migration_enabled",
- "true",
- "Move selected web clients to the new origin",
- domain_migration.enabled,
- true,
- ))
- p class="text-xs text-neutral-500" {
- "Off is the safe state and the kill switch. With this unchecked no client \
- starts a migration and clients that already migrated stop forwarding the \
- legacy origin, so the rollout and targeting fields below have no effect at all."
- }
-
- h3 class="text-sm font-semibold text-neutral-900" { "Installed apps" }
- (checkbox(
- "domain_migration_standalone_forwarding",
- "true",
- "Forward installed desktop web apps to the new origin",
- domain_migration.standalone_forwarding,
- true,
- ))
- p class="text-xs text-neutral-500" {
- "Leave this off until the manifest scope extension and the association file \
- are live and verified. While it is off, installed Chromium desktop apps copy \
- their data across but stay on the legacy origin and offer to install the new \
- app. Installed mobile and Safari apps never forward either way."
- }
-
- h3 class="text-sm font-semibold text-neutral-900" { "Rollout" }
- (number_field(
- "domain_migration_rollout_basis_points",
- "Rollout (basis points)",
- &domain_migration.rollout_basis_points.to_string(),
- Some(0), Some(10000), "1",
- Some("Share of logged-in users bucketed into the migration, in basis points: 0 is nobody, 100 is 1%, 10000 is everybody."),
- ))
- (number_field(
- "domain_migration_anonymous_rollout_basis_points",
- "Anonymous rollout (basis points)",
- &domain_migration.anonymous_rollout_basis_points.to_string(),
- Some(0), Some(10000), "1",
- Some("Share of logged-out devices sent to the new origin, in basis points. Each device is bucketed on its own random ID."),
- ))
- (experiment_rollout_country_codes_field(
- "domain_migration_rollout_country_codes",
- &domain_migration.rollout_country_codes,
- ))
- div class="flex flex-col gap-2" {
- (text_input(
- "domain_migration_rollout_salt",
- "Rollout Salt",
- &domain_migration.rollout_salt,
- DOMAIN_MIGRATION_DEFAULT_SALT,
- ))
- p class="text-xs text-neutral-500" {
- "Seeds the bucketing hash for users and devices. Changing it reshuffles \
- which users and devices fall inside the percentages above. Leave it \
- alone to keep the current cohort stable."
- }
- }
- div class="flex flex-col gap-2" {
- (textarea_input(
- "domain_migration_included_user_ids",
- "Always-on User IDs",
- "1500000000000000001\n1500000000000000002",
- &included_user_ids,
- 4,
- false,
- ))
- (entry_count_hint(
- domain_migration.included_user_ids.len(),
- EXPERIMENT_MAX_TARGETED_USERS,
- ))
- p class="text-xs text-neutral-500" {
- "One snowflake per line, or comma separated. These users are targeted \
- regardless of the percentage above. IDs must contain 1 to 20 decimal \
- digits. Invalid entries prevent the save. Blank entries and duplicate \
- IDs are ignored."
- }
- }
- div class="flex flex-col gap-2" {
- (checkbox(
- "domain_migration_include_premium_users",
- "true",
- "Include premium users",
- domain_migration.include_premium_users,
- true,
- ))
- p class="text-xs text-neutral-500" {
- "Includes every account with active premium perks, regardless of the \
- percentage above. The never-on list still wins."
- }
- }
- div class="flex flex-col gap-2" {
- (textarea_input(
- "domain_migration_included_guild_ids",
- "Always-on Guild IDs",
- "1500000000000000005\n1500000000000000006",
- &domain_migration.included_guild_ids.join("\n"),
- 4,
- false,
- ))
- (entry_count_hint(
- domain_migration.included_guild_ids.len(),
- EXPERIMENT_MAX_TARGETED_USERS,
- ))
- p class="text-xs text-neutral-500" {
- "Same format, with guild IDs. Every member of a listed guild is \
- included regardless of the percentage above, unless the user is \
- in the never-on list."
- }
- }
- div class="flex flex-col gap-2" {
- (textarea_input(
- "domain_migration_excluded_user_ids",
- "Never-on User IDs",
- "1500000000000000003\n1500000000000000004",
- &excluded_user_ids,
- 4,
- false,
- ))
- (entry_count_hint(
- domain_migration.excluded_user_ids.len(),
- EXPERIMENT_MAX_TARGETED_USERS,
- ))
- p class="text-xs text-neutral-500" {
- "Same format. Exclusion wins over both the always-on list and the \
- percentage. It stops new migrations only. A user who already moved \
- stays on the new origin."
- }
- }
-
- (form_actions(html! {
- (submit_button("Save Domain Migration Configuration"))
- }))
- }
- }
- },
- )
+ let options = choice_options(choices);
+ let options: Vec<(&str, &str)> = options
+ .iter()
+ .map(|(value, label)| (value.as_str(), *label))
+ .collect();
+ select_input(name, label, &options, &selected.to_string())
}
-fn voice_p2p_section(base: &str, csrf_token: &str, voice_p2p: &VoiceP2pConfigResponse) -> Markup {
- let status = if voice_p2p.enabled {
- ("Live", BadgeVariant::Success)
+fn guild_visits_section(
+ base: &str,
+ config_form: ConfigForm<'_>,
+ guild_visits: &GuildVisitsConfigResponse,
+) -> Markup {
+ let status = if guild_visits.enabled {
+ ("On", BadgeVariant::Success)
} else {
- ("Inert", BadgeVariant::Default)
+ ("Off", BadgeVariant::Default)
};
- let included_user_ids = voice_p2p.included_user_ids.join("\n");
- let excluded_user_ids = voice_p2p.excluded_user_ids.join("\n");
section_card_with_description(
- "Peer-to-peer voice",
- "Lets selected users start small voice calls that connect the participants directly \
- instead of through the voice servers. A peer-to-peer call only moves to the voice \
- servers when a participant switches it or its region changes.",
+ "Community previews",
+ "Lets assigned people preview a community before joining it. For them, joining follows \
+ the \u{201c}Joining a community\u{201d} setting under Sign-in & new accounts while the \
+ stricter limits are on.",
html! {
- form method="post" action={(base) "/instance-config?action=update_voice_p2p"} {
- (csrf_input(csrf_token))
+ form method="post" action={(base) "/instance-config?action=update_guild_visits"} {
+ (config_form.fields())
div class="space-y-6" {
div class="flex flex-wrap items-center gap-2" {
- h3 class="text-sm font-semibold text-neutral-900" { "Master switch" }
(badge(status.0, status.1))
- span class="text-xs text-neutral-500" {
- "Config version " (voice_p2p.config_version)
- }
}
- (checkbox(
- "voice_p2p_enabled",
- "true",
- "Let the selected users start peer-to-peer calls",
- voice_p2p.enabled,
- true,
- ))
- p class="text-xs text-neutral-500" {
- "Off is the safe state and the kill switch. With this unchecked every new \
- call uses the voice servers and a running peer-to-peer call accepts no \
- new joins, so the rollout and targeting fields below have no effect at \
- all. While it is on, the fields below select who can start a \
- peer-to-peer call, and anyone who agrees to a direct connection can \
- join one."
- }
-
- h3 class="text-sm font-semibold text-neutral-900" { "Call size" }
- (number_field(
- "voice_p2p_max_participants",
- "Maximum participants",
- &voice_p2p.max_participants.to_string(),
- Some(*VOICE_P2P_MAX_PARTICIPANTS_RANGE.start()),
- Some(*VOICE_P2P_MAX_PARTICIPANTS_RANGE.end()),
- "1",
- Some("Most participants a peer-to-peer call can hold, 2 through 4. Clients only offer a peer-to-peer call in a direct message or group with at most this many members, and a join past it is refused as full. Lowering it never removes anyone from a running call."),
- ))
-
- h3 class="text-sm font-semibold text-neutral-900" { "Rollout" }
- (number_field(
- "voice_p2p_rollout_basis_points",
- "Rollout (basis points)",
- &voice_p2p.rollout_basis_points.to_string(),
- Some(0), Some(10000), "1",
- Some("Share of users who can start peer-to-peer calls, in basis points: 0 is nobody, 100 is 1%, 10000 is everybody."),
- ))
- (experiment_rollout_country_codes_field(
- "voice_p2p_rollout_country_codes",
- &voice_p2p.rollout_country_codes,
+ (Checkbox {
+ name: "guild_visits_enabled",
+ value: "true",
+ label: "Allow community previews",
+ checked: guild_visits.enabled,
+ enabled: true,
+ }.render())
+ (NumberField {
+ name: "guild_visits_user_basis_points",
+ label: "Rollout (basis points)",
+ value: &guild_visits.user_basis_points.to_string(),
+ min: Some(0),
+ max: Some(10000),
+ step: "1",
+ helper: Some("Share of people assigned: 0 is nobody, 100 is 1%, 10000 is everybody."),
+ placeholder: None,
+ }.render())
+ (text_input(
+ "guild_visits_user_salt",
+ "Rollout Salt",
+ &guild_visits.user_salt,
+ GUILD_VISITS_DEFAULT_SALT,
))
- div class="flex flex-col gap-2" {
- (text_input(
- "voice_p2p_rollout_salt",
- "Rollout Salt",
- &voice_p2p.rollout_salt,
- VOICE_P2P_DEFAULT_SALT,
- ))
- p class="text-xs text-neutral-500" {
- "Seeds the bucketing hash. Changing it reshuffles which users fall \
- inside the percentage above. Leave it alone to keep the current \
- cohort stable."
- }
- }
div class="flex flex-col gap-2" {
(textarea_input(
- "voice_p2p_included_user_ids",
+ "guild_visits_included_user_ids",
"Always-on User IDs",
"1500000000000000001\n1500000000000000002",
- &included_user_ids,
+ &guild_visits.included_user_ids.join("\n"),
4,
false,
))
(entry_count_hint(
- voice_p2p.included_user_ids.len(),
+ guild_visits.included_user_ids.len(),
EXPERIMENT_MAX_TARGETED_USERS,
))
- p class="text-xs text-neutral-500" {
- "One snowflake per line, or comma separated. These users are targeted \
- regardless of the percentage above. IDs must contain 1 to 20 decimal \
- digits. Invalid entries prevent the save. Blank entries and duplicate \
- IDs are ignored."
- }
- }
- div class="flex flex-col gap-2" {
- (checkbox(
- "voice_p2p_include_premium_users",
- "true",
- "Include premium users",
- voice_p2p.include_premium_users,
- true,
- ))
- p class="text-xs text-neutral-500" {
- "Includes every account with active premium perks, regardless of the \
- percentage above. The never-on list still wins."
- }
}
div class="flex flex-col gap-2" {
(textarea_input(
- "voice_p2p_included_guild_ids",
- "Always-on Guild IDs",
- "1500000000000000005\n1500000000000000006",
- &voice_p2p.included_guild_ids.join("\n"),
- 4,
- false,
- ))
- (entry_count_hint(
- voice_p2p.included_guild_ids.len(),
- EXPERIMENT_MAX_TARGETED_USERS,
- ))
- p class="text-xs text-neutral-500" {
- "Same format, with guild IDs. Every member of a listed guild is \
- included regardless of the percentage above, unless the user is \
- in the never-on list."
- }
- }
- div class="flex flex-col gap-2" {
- (textarea_input(
- "voice_p2p_excluded_user_ids",
+ "guild_visits_excluded_user_ids",
"Never-on User IDs",
- "1500000000000000003\n1500000000000000004",
- &excluded_user_ids,
+ "1500000000000000003",
+ &guild_visits.excluded_user_ids.join("\n"),
4,
false,
))
(entry_count_hint(
- voice_p2p.excluded_user_ids.len(),
+ guild_visits.excluded_user_ids.len(),
EXPERIMENT_MAX_TARGETED_USERS,
))
- p class="text-xs text-neutral-500" {
- "Same format. Exclusion wins over both the always-on list and the \
- percentage."
- }
}
-
(form_actions(html! {
- (submit_button("Save Peer-to-Peer Voice Configuration"))
+ (submit_button("Save"))
}))
}
}
@@ -1664,76 +781,9 @@ fn voice_p2p_section(base: &str, csrf_token: &str, voice_p2p: &VoiceP2pConfigRes
)
}
-fn estimate_low_end_solve_seconds(cost: u32, max_counter: u32) -> f64 {
- 0.75 * f64::from(cost) * f64::from(max_counter) / 1_050_000.0
-}
-
-fn captcha_section(base: &str, csrf_token: &str, captcha: &CaptchaConfigResponse) -> Markup {
- let status = if captcha.enabled {
- ("On", BadgeVariant::Success)
- } else {
- ("Off", BadgeVariant::Default)
- };
- let estimate = estimate_low_end_solve_seconds(captcha.cost, captcha.max_counter);
- section_card_with_description(
- "Proof-of-work check",
- "Clients solve it in the background. The API issues and verifies every challenge itself, \
- and no third party is involved.",
- html! {
- div class="space-y-6" {
- div class="flex flex-wrap items-center gap-2" {
- (badge(status.0, status.1))
- }
- form method="post" action={(base) "/instance-config?action=update_captcha"} {
- (csrf_input(csrf_token))
- div class="space-y-6" {
- (checkbox(
- "captcha_enabled",
- "true",
- "Require a proof-of-work check",
- captcha.enabled,
- true,
- ))
- p class="text-xs text-neutral-500" {
- "On by default. Turning it off removes the check from every request."
- }
- (number_field(
- "captcha_cost",
- "Cost (PBKDF2 iterations per try)",
- &captcha.cost.to_string(),
- Some(*CAPTCHA_COST_RANGE.start()),
- Some(*CAPTCHA_COST_RANGE.end()),
- "1",
- Some("Default 5000."),
- ))
- (number_field(
- "captcha_max_counter",
- "Maximum counter",
- &captcha.max_counter.to_string(),
- Some(*CAPTCHA_MAX_COUNTER_RANGE.start()),
- Some(*CAPTCHA_MAX_COUNTER_RANGE.end()),
- "1",
- Some("Default 1000. Solve time grows with cost times this value."),
- ))
- p class="text-sm text-neutral-700" {
- (format!(
- "Average solve: about {estimate:.1} s on a low-end Android device, \
- well under a second in desktop browsers."
- ))
- }
- (form_actions(html! {
- (submit_button("Save"))
- }))
- }
- }
- }
- },
- )
-}
-
fn experiment_delivery_section(
base: &str,
- csrf_token: &str,
+ config_form: ConfigForm<'_>,
experiment_delivery: &ExperimentDeliveryConfigResponse,
) -> Markup {
section_card_with_description(
@@ -1744,23 +794,29 @@ fn experiment_delivery_section(
spreads a fleet that has synchronized on one tick back out across the interval.",
html! {
form method="post" action={(base) "/instance-config?action=update_experiment_delivery"} {
- (csrf_input(csrf_token))
+ (config_form.fields())
div class="space-y-6" {
div class="grid grid-cols-1 gap-4 sm:grid-cols-2" {
- (number_field(
- "experiment_delivery_poll_interval_seconds",
- "Assignment Poll Interval (s)",
- &experiment_delivery.poll_interval_seconds.to_string(),
- Some(60), Some(86400), "1",
- Some("How often a client re-reads its assignments, 60 to 86400 seconds. Lower values pick up changes sooner at the cost of more requests."),
- ))
- (number_field(
- "experiment_delivery_poll_jitter_percent",
- "Assignment Poll Jitter (%)",
- &experiment_delivery.poll_jitter_percent.to_string(),
- Some(0), Some(50), "1",
- Some("How far each client spreads its poll around the interval, 0 to 50 percent. Raise it to break up a fleet that polls on the same tick, set it to 0 for an exact interval."),
- ))
+ (NumberField {
+ name: "experiment_delivery_poll_interval_seconds",
+ label: "Assignment Poll Interval (s)",
+ value: &experiment_delivery.poll_interval_seconds.to_string(),
+ min: Some(60),
+ max: Some(86400),
+ step: "1",
+ helper: Some("How often a client re-reads its assignments, 60 to 86400 seconds. Lower values pick up changes sooner at the cost of more requests."),
+ placeholder: None,
+ }.render())
+ (NumberField {
+ name: "experiment_delivery_poll_jitter_percent",
+ label: "Assignment Poll Jitter (%)",
+ value: &experiment_delivery.poll_jitter_percent.to_string(),
+ min: Some(0),
+ max: Some(50),
+ step: "1",
+ helper: Some("How far each client spreads its poll around the interval, 0 to 50 percent. Raise it to break up a fleet that polls on the same tick, set it to 0 for an exact interval."),
+ placeholder: None,
+ }.render())
}
(form_actions(html! {
@@ -1772,441 +828,30 @@ fn experiment_delivery_section(
)
}
-fn registration_config_section(
- config: &AdminConfig,
- csrf_token: &str,
- registration: &InstanceRegistrationResponse,
- collect_date_of_birth: bool,
- self_hosted: bool,
-) -> Markup {
- let base = &config.base_path;
- section_card_with_description(
- "Registration Controls",
- "Control public registration and admin-issued registration URLs.",
- html! {
- div class="space-y-8" {
- (registration_policy_form(base, csrf_token, registration))
- @if self_hosted {
- (registration_fields_form(base, csrf_token, collect_date_of_birth))
- }
- (create_registration_url_form(base, csrf_token))
- (registration_url_list(config, csrf_token, &registration.urls))
- }
- },
- )
-}
-
-fn registration_policy_form(
- base: &str,
- csrf_token: &str,
- registration: &InstanceRegistrationResponse,
-) -> Markup {
- html! {
- div class="space-y-4" {
- h3 class="text-sm font-semibold text-neutral-900" { "Registration Policy" }
- form method="post" action={(base) "/instance-config?action=update_registration"} {
- (csrf_input(csrf_token))
- div class="space-y-4" {
- div class="grid grid-cols-1 gap-4 sm:grid-cols-2" {
- (select_input("registration_mode", "Mode", &[
- ("open", "Open"),
- ("approval", "Approval required"),
- ("closed", "Closed"),
- ], registration.mode.as_str()))
- div class="flex items-end pb-1" {
- (checkbox(
- "admin_registration_urls_enabled",
- "true",
- "Admin registration URLs enabled",
- registration.admin_registration_urls_enabled,
- true,
- ))
- }
- }
- (form_actions(html! {
- (submit_button("Save Registration Policy"))
- }))
- }
- }
- }
- }
-}
-
-fn registration_fields_form(base: &str, csrf_token: &str, collect_date_of_birth: bool) -> Markup {
- html! {
- div class="space-y-4 border-t border-neutral-200 pt-6" {
- h3 class="text-sm font-semibold text-neutral-900" { "Registration Fields" }
- form method="post" action={(base) "/instance-config?action=update_app_registration"} {
- (csrf_input(csrf_token))
- div class="space-y-4" {
- (checkbox(
- "app_collect_date_of_birth",
- "true",
- "Collect date of birth during registration",
- collect_date_of_birth,
- true,
- ))
- p class="text-xs text-neutral-500" {
- "When disabled, new self-hosted accounts do not store a date of birth and are treated as adults."
- }
- (form_actions(html! {
- (submit_button("Save Registration Fields"))
- }))
- }
- }
- }
- }
-}
-
-fn create_registration_url_form(base: &str, csrf_token: &str) -> Markup {
- let action = format!("{base}/instance-config?action=create_registration_url");
- html! {
- div class="space-y-4 border-t border-neutral-200 pt-6" {
- h3 class="text-sm font-semibold text-neutral-900" { "Create Admin-Issued Registration URL" }
- form method="post" action=(&action)
- hx-post=(&action)
- hx-target="#registration-url-list"
- hx-swap="outerHTML"
- hx-push-url="false"
- data-admin-allow-swap="true" {
- (csrf_input(csrf_token))
- div class="space-y-4" {
- div class="grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-4" {
- (text_input(
- "registration_url_label",
- "Label",
- "",
- "Invite batch, partner, or support case",
- ))
- (number_field(
- "registration_url_expires_in_days",
- "Expires In Days",
- "",
- Some(1),
- None,
- "1",
- Some("Leave blank for no expiration."),
- ))
- (number_field(
- "registration_url_max_uses",
- "Max Uses",
- "",
- Some(1),
- Some(1_000_000),
- "1",
- Some("Leave blank for unlimited uses."),
- ))
- div class="flex items-end pb-1" {
- (checkbox(
- "registration_url_approval_required",
- "true",
- "Approval required",
- false,
- true,
- ))
- }
- }
- (form_actions(html! {
- (submit_button("Create Registration URL"))
- }))
- }
- }
- }
- }
-}
-
-pub fn registration_url_list(
- config: &AdminConfig,
- csrf_token: &str,
- urls: &[RegistrationUrlResponse],
-) -> Markup {
- let base = &config.base_path;
- html! {
- div id="registration-url-list" class="space-y-4 border-t border-neutral-200 pt-6" {
- h3 class="text-sm font-semibold text-neutral-900" { "Existing Registration URLs" }
- @if urls.is_empty() {
- p class="text-sm text-neutral-500" { "No admin-issued registration URLs." }
- } @else {
- div class="overflow-x-auto rounded-lg border border-neutral-200" {
- table class="min-w-[1100px] divide-y divide-neutral-200 text-sm" {
- thead class="bg-neutral-50" {
- tr {
- th scope="col" class="px-4 py-3 text-left font-semibold text-neutral-600" { "Label / URL" }
- th scope="col" class="px-4 py-3 text-left font-semibold text-neutral-600" { "Created" }
- th scope="col" class="px-4 py-3 text-left font-semibold text-neutral-600" { "Expires" }
- th scope="col" class="px-4 py-3 text-left font-semibold text-neutral-600" { "Uses" }
- th scope="col" class="px-4 py-3 text-left font-semibold text-neutral-600" { "Status" }
- th scope="col" class="px-4 py-3 text-left font-semibold text-neutral-600" { "Approval" }
- th scope="col" class="px-4 py-3 text-left font-semibold text-neutral-600" { "Action" }
- }
- }
- tbody class="divide-y divide-neutral-200 bg-white" {
- @for url in urls {
- (registration_url_row(config, base, csrf_token, url))
- }
- }
- }
- }
- }
- }
- }
-}
-
-fn registration_url_row(
- config: &AdminConfig,
- base: &str,
- csrf_token: &str,
- url: &RegistrationUrlResponse,
-) -> Markup {
- let label = url.label.as_deref().unwrap_or("Unlabeled");
- let full_url = admin_issued_registration_url(config, &url.id);
- let created_at = format_admin_timestamp(&url.created_at);
- let expires_at = format_optional_admin_timestamp(url.expires_at.as_deref(), "Never");
- let uses = registration_url_uses_text(url);
- let status = registration_url_status(url);
- let approval = if url.approval_required {
- "Required"
- } else {
- "Not required"
- };
- let revoke_action = format!("{base}/instance-config?action=revoke_registration_url");
- html! {
- tr {
- td class="min-w-[28rem] px-4 py-3 align-top" {
- p class="font-medium text-neutral-900" { (label) }
- (copyable_registration_url(&full_url, "Copy URL"))
- p class="mt-1 whitespace-nowrap text-xs text-neutral-500" { "ID: " (&url.id) }
- }
- td class="px-4 py-3 align-top text-neutral-700" {
- p class="whitespace-nowrap" { (created_at) }
- p class="whitespace-nowrap text-xs text-neutral-500" { "By: " (&url.created_by_user_id) }
- }
- td class="px-4 py-3 align-top text-neutral-700 whitespace-nowrap" {
- (expires_at)
- }
- td class="px-4 py-3 align-top text-neutral-700 whitespace-nowrap" {
- (uses)
- }
- td class="px-4 py-3 align-top whitespace-nowrap" {
- (registration_url_status_badge(status))
- }
- td class="px-4 py-3 align-top text-neutral-700 whitespace-nowrap" {
- (approval)
- }
- td class="px-4 py-3 align-top" {
- @if status == RegistrationUrlStatus::Active {
- form method="post" action=(&revoke_action)
- hx-post=(&revoke_action)
- hx-target="#registration-url-list"
- hx-swap="outerHTML"
- hx-push-url="false"
- data-admin-allow-swap="true" {
- (csrf_input(csrf_token))
- input type="hidden" name="registration_url_id" value=(&url.id);
- (compact_button("Revoke", true))
- }
- } @else {
- span class="text-sm text-neutral-400" { "No action" }
- }
- }
- }
- }
-}
-
-pub(super) fn admin_issued_registration_url(config: &AdminConfig, code: &str) -> String {
- format!(
- "{}/register?registration_url={}",
- config.web_app_endpoint.trim_end_matches('/'),
- urlencoding::encode(code)
- )
-}
-
-fn copyable_registration_url(value: &str, label: &str) -> Markup {
- html! {
- div class="mt-2 flex items-center gap-2" {
- input type="url" readonly value=(value)
- aria-label="Registration URL"
- class="h-8 min-w-0 flex-1 rounded-lg border border-neutral-300 bg-neutral-50 px-3 py-1.5 text-xs text-neutral-800";
- (compact_copy_button(value, label))
- }
- }
-}
-
-pub(super) fn compact_copy_button(value: &str, label: &str) -> Markup {
- html! {
- button type="button"
- class="inline-flex h-8 shrink-0 items-center justify-center rounded-lg border border-neutral-300 bg-neutral-50 px-3 text-xs font-medium text-neutral-700 transition-all hover:border-neutral-400 hover:text-neutral-900 focus:outline-none focus:ring-2 focus:ring-brand-primary/20"
- data-copy-value=(value)
- onclick="window.__adminCopyToClipboard && window.__adminCopyToClipboard(this.dataset.copyValue, this, 'Copied')" {
- (label)
- }
- }
-}
-
-pub(super) fn compact_button(label: &str, danger: bool) -> Markup {
- let variant_class = if danger {
- "bg-red-600 text-white hover:bg-red-700 focus:ring-red-500/30"
- } else {
- "bg-neutral-900 text-white hover:bg-neutral-800 focus:ring-brand-primary/20"
- };
- html! {
- button type="submit"
- class={"inline-flex h-8 shrink-0 items-center justify-center rounded-lg px-3 text-xs font-medium transition-all focus:outline-none focus:ring-2 " (variant_class)} {
- (label)
- }
- }
-}
-
-#[derive(Clone, Copy, Debug, Eq, PartialEq)]
-enum RegistrationUrlStatus {
- Active,
- Revoked,
- Expired,
- Exhausted,
-}
-
-impl RegistrationUrlStatus {
- fn label(self) -> &'static str {
- match self {
- Self::Active => "Active",
- Self::Revoked => "Revoked",
- Self::Expired => "Expired",
- Self::Exhausted => "Exhausted",
- }
- }
-
- fn variant(self) -> BadgeVariant {
- match self {
- Self::Active => BadgeVariant::Success,
- Self::Revoked => BadgeVariant::Danger,
- Self::Expired | Self::Exhausted => BadgeVariant::Warning,
- }
- }
-}
-
-fn registration_url_status(url: &RegistrationUrlResponse) -> RegistrationUrlStatus {
- if url.revoked_at.is_some() {
- return RegistrationUrlStatus::Revoked;
- }
- if url.expires_at.as_deref().is_some_and(timestamp_is_past) {
- return RegistrationUrlStatus::Expired;
- }
- if url
- .max_uses
- .is_some_and(|max_uses| url.use_count >= max_uses)
- {
- return RegistrationUrlStatus::Exhausted;
- }
- RegistrationUrlStatus::Active
-}
-
-fn registration_url_status_badge(status: RegistrationUrlStatus) -> Markup {
- badge(status.label(), status.variant())
-}
-
-fn timestamp_is_past(iso: &str) -> bool {
- time::OffsetDateTime::parse(iso, &time::format_description::well_known::Rfc3339)
- .or_else(|_| {
- time::OffsetDateTime::parse(
- iso,
- &time::format_description::well_known::Iso8601::DEFAULT,
- )
- })
- .map(|timestamp| timestamp < time::OffsetDateTime::now_utc())
- .unwrap_or(false)
-}
-
-fn format_optional_admin_timestamp(value: Option<&str>, fallback: &str) -> String {
+pub(super) fn format_optional_admin_timestamp(value: Option<&str>, fallback: &str) -> String {
value
.map(format_admin_timestamp)
.unwrap_or_else(|| fallback.to_owned())
}
-fn registration_url_uses_text(url: &RegistrationUrlResponse) -> String {
- match url.max_uses {
- Some(max_uses) => format!("{} / {}", url.use_count, max_uses),
- None => format!("{} / unlimited", url.use_count),
- }
-}
-
-fn sso_config_section(base: &str, csrf_token: &str, sso: &SsoConfigResponse) -> Markup {
- let allowed_domains = sso.allowed_domains.join("\n");
- let secret_caption = if sso.client_secret_set {
- "A secret is set. Check to clear, or enter a new value to rotate."
- } else {
- "No secret set yet."
- };
- section_card_with_description(
- "Single Sign-On (SSO)",
- "Configure OIDC-style SSO for the admin and client apps. When enabled, \
- users can sign in through your SSO provider. Require SSO to block local \
- password registration and login.",
- html! {
- form method="post" action={(base) "/instance-config?action=update_sso"} {
- (csrf_input(csrf_token))
- div class="space-y-6" {
- div class="flex flex-col gap-2" {
- (checkbox("sso_enabled", "true", "Enable SSO", sso.enabled, true))
- (checkbox("sso_enforced", "true", "Require SSO (disables local password login and registration)", sso.enforced, true))
- (checkbox("sso_auto_provision", "true", "Automatically provision users on first SSO login", sso.auto_provision, true))
- }
- div class="grid grid-cols-1 gap-4 sm:grid-cols-2" {
- (text_input("sso_display_name", "Display Name", sso.display_name.as_deref().unwrap_or(""), "Example Identity Provider"))
- (text_input("sso_issuer", "Issuer", sso.issuer.as_deref().unwrap_or(""), "https://idp.example.com"))
- }
- div class="grid grid-cols-1 gap-4 sm:grid-cols-2" {
- (text_input("sso_authorization_url", "Authorization URL", sso.authorization_url.as_deref().unwrap_or(""), "https://idp.example.com/oauth/authorize"))
- (text_input("sso_token_url", "Token URL", sso.token_url.as_deref().unwrap_or(""), "https://idp.example.com/oauth/token"))
- }
- div class="grid grid-cols-1 gap-4 sm:grid-cols-2" {
- (text_input("sso_userinfo_url", "User Info URL", sso.userinfo_url.as_deref().unwrap_or(""), "https://idp.example.com/oauth/userinfo"))
- (text_input("sso_jwks_url", "JWKS URL", sso.jwks_url.as_deref().unwrap_or(""), "https://idp.example.com/.well-known/jwks.json"))
- }
- div class="grid grid-cols-1 gap-4 sm:grid-cols-2" {
- (text_input("sso_client_id", "Client ID", sso.client_id.as_deref().unwrap_or(""), "client-id"))
- div class="space-y-2" {
- (form_field_group("Client Secret", "sso_client_secret", false, None, None, html! {
- input type="password" id="sso_client_secret" name="sso_client_secret"
- placeholder="Leave blank to keep existing"
- class=(FORM_INPUT_CLASS);
- }))
- (checkbox("sso_clear_client_secret", "true", "Clear secret", false, true))
- p class="text-xs text-neutral-500" {
- (secret_caption)
- }
- }
- }
- div class="grid grid-cols-1 gap-4 sm:grid-cols-2" {
- (text_input("sso_scope", "Scope", sso.scope.as_deref().unwrap_or(""), "openid email profile"))
- (form_field_group("Redirect URI", "sso_redirect_uri", false, None,
- Some("Configure this exact URI in your IdP. It is derived from the public gateway URL."),
- html! {
- input type="url" id="sso_redirect_uri" name="sso_redirect_uri"
- value=(sso.redirect_uri.as_deref().unwrap_or(""))
- disabled class=(FORM_INPUT_CLASS);
- },
- ))
- }
- div class="space-y-2" {
- (textarea_input(
- "sso_allowed_domains",
- "Allowed Email Domains",
- "example.com\nexample.org",
- &allowed_domains,
- 3,
- false,
- ))
- p class="text-xs text-neutral-500" {
- "Limit SSO logins to these domains (one per line). Leave empty to allow any verified email."
- }
- }
- (form_actions(html! {
- (submit_button("Save SSO Settings"))
- }))
+pub(super) fn allowed_domains_input(name: &str, value: &str, hint: &str) -> Markup {
+ let hint_id = format!("{name}-hint");
+ let error_id = format!("{name}-error");
+ html! {
+ div class="space-y-2" {
+ div class="flex flex-col gap-2" {
+ label for=(name) class=(FORM_LABEL_CLASS) { "Allowed Email Domains" }
+ textarea id=(name) name=(name) placeholder="example.com\nexample.org" rows="3"
+ aria-describedby={(error_id) " " (hint_id)}
+ class=(FORM_TEXTAREA_CLASS) {
+ (value)
}
}
- },
- )
+ p id=(error_id) class="text-xs leading-5 text-red-600"
+ data-field-error=(name) hidden {}
+ p id=(hint_id) class="text-xs text-neutral-500" { (hint) }
+ }
+ }
}
fn limit_config_section(base: &str, limit_config: &LimitConfigResponse) -> Markup {
diff --git a/fluxer_admin/src/templates/pages/instance_config/captcha.rs b/fluxer_admin/src/templates/pages/instance_config/captcha.rs
new file mode 100644
index 000000000..164ebb141
--- /dev/null
+++ b/fluxer_admin/src/templates/pages/instance_config/captcha.rs
@@ -0,0 +1,94 @@
+// SPDX-License-Identifier: AGPL-3.0-or-later
+
+use crate::templates::pages::instance_config::ConfigForm;
+use crate::{
+ api::types::{
+ CAPTCHA_COST_RANGE, CAPTCHA_MAX_COUNTER_RANGE, CaptchaConfigResponse, CaptchaProvider,
+ },
+ templates::components::{
+ badge::{BadgeVariant, badge},
+ form::{NumberField, form_actions, submit_button},
+ section_card::section_card_with_description,
+ },
+};
+use maud::{Markup, html};
+
+use super::{CAPTCHA_PROVIDER_CHOICES, choice_select};
+
+const LOW_END_SOLVE_REFERENCE_SECONDS: f64 = 0.75;
+const LOW_END_SOLVE_REFERENCE_WORK: f64 = 1_050_000.0;
+
+pub(super) fn captcha_section(
+ base: &str,
+ config_form: ConfigForm<'_>,
+ captcha: &CaptchaConfigResponse,
+ instant_accounts_enabled: bool,
+) -> Markup {
+ let status = if captcha.provider != CaptchaProvider::None {
+ ("On", BadgeVariant::Success)
+ } else {
+ ("Off", BadgeVariant::Default)
+ };
+ let estimate =
+ LOW_END_SOLVE_REFERENCE_SECONDS * f64::from(captcha.cost) * f64::from(captcha.max_counter)
+ / LOW_END_SOLVE_REFERENCE_WORK;
+ section_card_with_description(
+ "Proof-of-work check",
+ "Clients solve it in the background. The API issues and verifies every challenge itself, \
+ and no third party is involved.",
+ html! {
+ div class="space-y-6" {
+ div class="flex flex-wrap items-center gap-2" {
+ (badge(status.0, status.1))
+ }
+ form method="post" action={(base) "/instance-config?action=update_captcha"} {
+ (config_form.fields())
+ div class="space-y-6" {
+ (choice_select(
+ "captcha_provider",
+ "Check",
+ CAPTCHA_PROVIDER_CHOICES,
+ &captcha.provider,
+ ))
+ p class="text-xs text-neutral-500" {
+ "On by default. Turning it off removes the check from every request."
+ @if instant_accounts_enabled {
+ " It cannot be turned off while people can start with just a \
+ display name. Turn that off first under Sign-in & new accounts."
+ }
+ }
+ (NumberField {
+ name: "captcha_cost",
+ label: "Cost (PBKDF2 iterations per try)",
+ value: &captcha.cost.to_string(),
+ min: Some(*CAPTCHA_COST_RANGE.start()),
+ max: Some(*CAPTCHA_COST_RANGE.end()),
+ step: "1",
+ helper: Some("Default 5000."),
+ placeholder: None,
+ }.render())
+ (NumberField {
+ name: "captcha_max_counter",
+ label: "Maximum counter",
+ value: &captcha.max_counter.to_string(),
+ min: Some(*CAPTCHA_MAX_COUNTER_RANGE.start()),
+ max: Some(*CAPTCHA_MAX_COUNTER_RANGE.end()),
+ step: "1",
+ helper: Some("Default 1000. Solve time grows with cost times this value."),
+ placeholder: None,
+ }.render())
+ p class="text-sm text-neutral-700" {
+ (format!(
+ "Average solve: about {estimate:.1} s on a low-end Android device, \
+ well under a second in desktop browsers."
+ ))
+ }
+ (form_actions(html! {
+ (submit_button("Save"))
+ }))
+ }
+ }
+ }
+ },
+ )
+}
diff --git a/fluxer_admin/src/templates/pages/instance_config/experiments.rs b/fluxer_admin/src/templates/pages/instance_config/experiments.rs
new file mode 100644
index 000000000..5ccbb4aea
--- /dev/null
+++ b/fluxer_admin/src/templates/pages/instance_config/experiments.rs
@@ -0,0 +1,336 @@
+// SPDX-License-Identifier: AGPL-3.0-or-later
+
+use super::{entry_count_hint, experiment_rollout_country_codes_field};
+use crate::templates::pages::instance_config::ConfigForm;
+use crate::{
+ api::types::{
+ DOMAIN_MIGRATION_DEFAULT_SALT, DomainMigrationConfigResponse,
+ EXPERIMENT_MAX_TARGETED_USERS, VOICE_P2P_DEFAULT_SALT, VOICE_P2P_MAX_PARTICIPANTS_RANGE,
+ VoiceP2pConfigResponse,
+ },
+ templates::components::{
+ badge::{BadgeVariant, badge},
+ form::{Checkbox, NumberField, form_actions, submit_button, text_input, textarea_input},
+ section_card::section_card_with_description,
+ },
+};
+use maud::{Markup, html};
+
+fn targeted_ids_field(input: Markup, count: usize, hint: &str) -> Markup {
+ html! {
+ div class="flex flex-col gap-2" {
+ (input)
+ (entry_count_hint(count, EXPERIMENT_MAX_TARGETED_USERS))
+ p class="text-xs text-neutral-500" { (hint) }
+ }
+ }
+}
+
+pub(super) fn domain_migration_section(
+ base: &str,
+ config_form: ConfigForm<'_>,
+ domain_migration: &DomainMigrationConfigResponse,
+) -> Markup {
+ let status = if domain_migration.enabled {
+ ("Live", BadgeVariant::Success)
+ } else {
+ ("Inert", BadgeVariant::Default)
+ };
+ let included_user_ids = domain_migration.included_user_ids.join("\n");
+ let excluded_user_ids = domain_migration.excluded_user_ids.join("\n");
+ section_card_with_description(
+ "Domain Migration",
+ "Moves web clients of the official instance from the legacy web app origin to the new \
+ one. Selected accounts copy their local data across and continue on the new origin. \
+ Clients of other instances read this configuration and ignore it.",
+ html! {
+ form method="post" action={(base) "/instance-config?action=update_domain_migration"} {
+ (config_form.fields())
+ div class="space-y-6" {
+ div class="flex flex-wrap items-center gap-2" {
+ h3 class="text-sm font-semibold text-neutral-900" { "Master switch" }
+ (badge(status.0, status.1))
+ span class="text-xs text-neutral-500" {
+ "Config version " (domain_migration.config_version)
+ }
+ }
+ (Checkbox {
+ name: "domain_migration_enabled",
+ value: "true",
+ label: "Move selected web clients to the new origin",
+ checked: domain_migration.enabled,
+ enabled: true,
+ }.render())
+ p class="text-xs text-neutral-500" {
+ "Off is the safe state and the kill switch. With this unchecked no client \
+ starts a migration and clients that already migrated stop forwarding the \
+ legacy origin, so the rollout and targeting fields below have no effect at all."
+ }
+
+ h3 class="text-sm font-semibold text-neutral-900" { "Installed apps" }
+ (Checkbox {
+ name: "domain_migration_standalone_forwarding",
+ value: "true",
+ label: "Forward installed desktop web apps to the new origin",
+ checked: domain_migration.standalone_forwarding,
+ enabled: true,
+ }.render())
+ p class="text-xs text-neutral-500" {
+ "Leave this off until the manifest scope extension and the association file \
+ are live and verified. While it is off, installed Chromium desktop apps copy \
+ their data across but stay on the legacy origin and offer to install the new \
+ app. Installed mobile and Safari apps never forward either way."
+ }
+
+ h3 class="text-sm font-semibold text-neutral-900" { "Rollout" }
+ (NumberField {
+ name: "domain_migration_rollout_basis_points",
+ label: "Rollout (basis points)",
+ value: &domain_migration.rollout_basis_points.to_string(),
+ min: Some(0),
+ max: Some(10000),
+ step: "1",
+ helper: Some("Share of logged-in users bucketed into the migration, in basis points: 0 is nobody, 100 is 1%, 10000 is everybody."),
+ placeholder: None,
+ }.render())
+ (NumberField {
+ name: "domain_migration_anonymous_rollout_basis_points",
+ label: "Anonymous rollout (basis points)",
+ value: &domain_migration.anonymous_rollout_basis_points.to_string(),
+ min: Some(0),
+ max: Some(10000),
+ step: "1",
+ helper: Some("Share of logged-out devices sent to the new origin, in basis points. Each device is bucketed on its own random ID."),
+ placeholder: None,
+ }.render())
+ (experiment_rollout_country_codes_field(
+ "domain_migration_rollout_country_codes",
+ &domain_migration.rollout_country_codes,
+ ))
+ div class="flex flex-col gap-2" {
+ (text_input(
+ "domain_migration_rollout_salt",
+ "Rollout Salt",
+ &domain_migration.rollout_salt,
+ DOMAIN_MIGRATION_DEFAULT_SALT,
+ ))
+ p class="text-xs text-neutral-500" {
+ "Seeds the bucketing hash for users and devices. Changing it reshuffles \
+ which users and devices fall inside the percentages above. Leave it \
+ alone to keep the current cohort stable."
+ }
+ }
+ (targeted_ids_field(
+ textarea_input(
+ "domain_migration_included_user_ids",
+ "Always-on User IDs",
+ "1500000000000000001\n1500000000000000002",
+ &included_user_ids,
+ 4,
+ false,
+ ),
+ domain_migration.included_user_ids.len(),
+ "One snowflake per line, or comma separated. These users are targeted \
+ regardless of the percentage above. IDs must contain 1 to 20 decimal \
+ digits. Invalid entries prevent the save. Blank entries and duplicate \
+ IDs are ignored.",
+ ))
+ div class="flex flex-col gap-2" {
+ (Checkbox {
+ name: "domain_migration_include_premium_users",
+ value: "true",
+ label: "Include premium users",
+ checked: domain_migration.include_premium_users,
+ enabled: true,
+ }.render())
+ p class="text-xs text-neutral-500" {
+ "Includes every account with active premium perks, regardless of the \
+ percentage above. The never-on list still wins."
+ }
+ }
+ (targeted_ids_field(
+ textarea_input(
+ "domain_migration_included_guild_ids",
+ "Always-on Guild IDs",
+ "1500000000000000005\n1500000000000000006",
+ &domain_migration.included_guild_ids.join("\n"),
+ 4,
+ false,
+ ),
+ domain_migration.included_guild_ids.len(),
+ "Same format, with guild IDs. Every member of a listed guild is \
+ included regardless of the percentage above, unless the user is \
+ in the never-on list.",
+ ))
+ (targeted_ids_field(
+ textarea_input(
+ "domain_migration_excluded_user_ids",
+ "Never-on User IDs",
+ "1500000000000000003\n1500000000000000004",
+ &excluded_user_ids,
+ 4,
+ false,
+ ),
+ domain_migration.excluded_user_ids.len(),
+ "Same format. Exclusion wins over both the always-on list and the \
+ percentage. It stops new migrations only. A user who already moved \
+ stays on the new origin.",
+ ))
+
+ (form_actions(html! {
+ (submit_button("Save Domain Migration Configuration"))
+ }))
+ }
+ }
+ },
+ )
+}
+
+pub(super) fn voice_p2p_section(
+ base: &str,
+ config_form: ConfigForm<'_>,
+ voice_p2p: &VoiceP2pConfigResponse,
+) -> Markup {
+ let status = if voice_p2p.enabled {
+ ("Live", BadgeVariant::Success)
+ } else {
+ ("Inert", BadgeVariant::Default)
+ };
+ let included_user_ids = voice_p2p.included_user_ids.join("\n");
+ let excluded_user_ids = voice_p2p.excluded_user_ids.join("\n");
+ section_card_with_description(
+ "Peer-to-peer voice",
+ "Lets selected users start small voice calls that connect the participants directly \
+ instead of through the voice servers. A peer-to-peer call only moves to the voice \
+ servers when a participant switches it or its region changes.",
+ html! {
+ form method="post" action={(base) "/instance-config?action=update_voice_p2p"} {
+ (config_form.fields())
+ div class="space-y-6" {
+ div class="flex flex-wrap items-center gap-2" {
+ h3 class="text-sm font-semibold text-neutral-900" { "Master switch" }
+ (badge(status.0, status.1))
+ span class="text-xs text-neutral-500" {
+ "Config version " (voice_p2p.config_version)
+ }
+ }
+ (Checkbox {
+ name: "voice_p2p_enabled",
+ value: "true",
+ label: "Let the selected users start peer-to-peer calls",
+ checked: voice_p2p.enabled,
+ enabled: true,
+ }.render())
+ p class="text-xs text-neutral-500" {
+ "Off is the safe state and the kill switch. With this unchecked every new \
+ call uses the voice servers and a running peer-to-peer call accepts no \
+ new joins, so the rollout and targeting fields below have no effect at \
+ all. While it is on, the fields below select who can start a \
+ peer-to-peer call, and anyone who agrees to a direct connection can \
+ join one."
+ }
+
+ h3 class="text-sm font-semibold text-neutral-900" { "Call size" }
+ (NumberField {
+ name: "voice_p2p_max_participants",
+ label: "Maximum participants",
+ value: &voice_p2p.max_participants.to_string(),
+ min: Some(*VOICE_P2P_MAX_PARTICIPANTS_RANGE.start()),
+ max: Some(*VOICE_P2P_MAX_PARTICIPANTS_RANGE.end()),
+ step: "1",
+ helper: Some("Most participants a peer-to-peer call can hold, 2 through 4. Clients only offer a peer-to-peer call in a direct message or group with at most this many members, and a join past it is refused as full. Lowering it never removes anyone from a running call."),
+ placeholder: None,
+ }.render())
+
+ h3 class="text-sm font-semibold text-neutral-900" { "Rollout" }
+ (NumberField {
+ name: "voice_p2p_rollout_basis_points",
+ label: "Rollout (basis points)",
+ value: &voice_p2p.rollout_basis_points.to_string(),
+ min: Some(0),
+ max: Some(10000),
+ step: "1",
+ helper: Some("Share of users who can start peer-to-peer calls, in basis points: 0 is nobody, 100 is 1%, 10000 is everybody."),
+ placeholder: None,
+ }.render())
+ (experiment_rollout_country_codes_field(
+ "voice_p2p_rollout_country_codes",
+ &voice_p2p.rollout_country_codes,
+ ))
+ div class="flex flex-col gap-2" {
+ (text_input(
+ "voice_p2p_rollout_salt",
+ "Rollout Salt",
+ &voice_p2p.rollout_salt,
+ VOICE_P2P_DEFAULT_SALT,
+ ))
+ p class="text-xs text-neutral-500" {
+ "Seeds the bucketing hash. Changing it reshuffles which users fall \
+ inside the percentage above. Leave it alone to keep the current \
+ cohort stable."
+ }
+ }
+ (targeted_ids_field(
+ textarea_input(
+ "voice_p2p_included_user_ids",
+ "Always-on User IDs",
+ "1500000000000000001\n1500000000000000002",
+ &included_user_ids,
+ 4,
+ false,
+ ),
+ voice_p2p.included_user_ids.len(),
+ "One snowflake per line, or comma separated. These users are targeted \
+ regardless of the percentage above. IDs must contain 1 to 20 decimal \
+ digits. Invalid entries prevent the save. Blank entries and duplicate \
+ IDs are ignored.",
+ ))
+ div class="flex flex-col gap-2" {
+ (Checkbox {
+ name: "voice_p2p_include_premium_users",
+ value: "true",
+ label: "Include premium users",
+ checked: voice_p2p.include_premium_users,
+ enabled: true,
+ }.render())
+ p class="text-xs text-neutral-500" {
+ "Includes every account with active premium perks, regardless of the \
+ percentage above. The never-on list still wins."
+ }
+ }
+ (targeted_ids_field(
+ textarea_input(
+ "voice_p2p_included_guild_ids",
+ "Always-on Guild IDs",
+ "1500000000000000005\n1500000000000000006",
+ &voice_p2p.included_guild_ids.join("\n"),
+ 4,
+ false,
+ ),
+ voice_p2p.included_guild_ids.len(),
+ "Same format, with guild IDs. Every member of a listed guild is \
+ included regardless of the percentage above, unless the user is \
+ in the never-on list.",
+ ))
+ (targeted_ids_field(
+ textarea_input(
+ "voice_p2p_excluded_user_ids",
+ "Never-on User IDs",
+ "1500000000000000003\n1500000000000000004",
+ &excluded_user_ids,
+ 4,
+ false,
+ ),
+ voice_p2p.excluded_user_ids.len(),
+ "Same format. Exclusion wins over both the always-on list and the \
+ percentage.",
+ ))
+
+ (form_actions(html! {
+ (submit_button("Save Peer-to-Peer Voice Configuration"))
+ }))
+ }
+ }
+ },
+ )
+}
diff --git a/fluxer_admin/src/templates/pages/instance_config/integrations.rs b/fluxer_admin/src/templates/pages/instance_config/integrations.rs
new file mode 100644
index 000000000..d8902f7f2
--- /dev/null
+++ b/fluxer_admin/src/templates/pages/instance_config/integrations.rs
@@ -0,0 +1,286 @@
+// SPDX-License-Identifier: AGPL-3.0-or-later
+
+use crate::templates::pages::instance_config::ConfigForm;
+use crate::{
+ api::types::{
+ AccountIdentityMode, EmailDeliveryMode, EmailDeliveryState, InstanceIntegrationsResponse,
+ },
+ templates::components::{
+ badge::{BadgeVariant, badge},
+ form::{
+ Checkbox, FORM_INPUT_CLASS, form_actions, form_field_group, select_input,
+ submit_button, text_input,
+ },
+ section_card::section_card_with_description,
+ },
+};
+use maud::{Markup, html};
+
+use super::{EMAIL_DELIVERY_CHOICES, choice_options, inherit_select};
+
+fn secret_badge(label: &str, is_set: bool) -> Markup {
+ if is_set {
+ badge(&format!("{label} set"), BadgeVariant::Success)
+ } else {
+ badge(&format!("{label} missing"), BadgeVariant::Default)
+ }
+}
+
+fn password_input(name: &str, label: &str, helper: Option<&str>) -> Markup {
+ form_field_group(
+ label,
+ name,
+ false,
+ None,
+ helper,
+ html! {
+ input type="password" id=(name) name=(name) value="" class=(FORM_INPUT_CLASS)
+ autocomplete="new-password";
+ },
+ )
+}
+
+fn smtp_tls_mode_summary(mode: &str) -> &str {
+ match mode {
+ "implicit" => "implicit TLS",
+ "starttls" => "required STARTTLS",
+ "opportunistic" => "STARTTLS when the server offers it",
+ "none" => "no encryption",
+ other => other,
+ }
+}
+
+fn email_delivery_select(delivery: Option<EmailDeliveryMode>) -> Markup {
+ let options = choice_options(EMAIL_DELIVERY_CHOICES);
+ let options: Vec<(&str, &str)> = std::iter::once(("", "Use the environment setting"))
+ .chain(
+ options
+ .iter()
+ .map(|(value, label)| (value.as_str(), *label)),
+ )
+ .collect();
+ let selected = delivery.map(|mode| mode.to_string()).unwrap_or_default();
+ select_input(
+ "integration_email_delivery",
+ "Delivery",
+ &options,
+ &selected,
+ )
+}
+
+pub(super) fn integrations_config_section(
+ base: &str,
+ config_form: ConfigForm<'_>,
+ integrations: &InstanceIntegrationsResponse,
+ account_identity: AccountIdentityMode,
+ product_name: &str,
+) -> Markup {
+ let smtp_port = integrations
+ .email
+ .smtp
+ .port
+ .map(|port| port.to_string())
+ .unwrap_or_default();
+ section_card_with_description(
+ "Runtime Integrations",
+ "Configure optional providers without changing environment variables. Blank secret fields keep the current value.",
+ html! {
+ form method="post" action={(base) "/instance-config?action=update_integrations"} {
+ (config_form.fields())
+ div class="space-y-8" {
+ div class="space-y-4" {
+ div class="flex flex-wrap items-center gap-2" {
+ h3 class="text-sm font-semibold text-neutral-900" { "GIF provider" }
+ (secret_badge("KLIPY key", integrations.gif.klipy_api_key_set))
+ }
+ div class="grid grid-cols-1 gap-4" {
+ (password_input("integration_klipy_api_key", "KLIPY API key", Some("Leave blank to keep the current key.")))
+ }
+ }
+
+ div class="space-y-4 border-t border-neutral-200 pt-6" {
+ div class="flex flex-wrap items-center gap-2" {
+ h3 class="text-sm font-semibold text-neutral-900" { "YouTube Data API" }
+ (secret_badge("API key", integrations.youtube.api_key_set))
+ }
+ (password_input("integration_youtube_api_key", "YouTube API key", Some("Leave blank to keep the current key.")))
+ }
+
+ @if account_identity.is_username() {
+ div class="space-y-4 border-t border-neutral-200 pt-6" {
+ div class="flex flex-wrap items-center gap-2" {
+ h3 class="text-sm font-semibold text-neutral-900" { "Email delivery" }
+ (email_delivery_state_badge(integrations.email.delivery_state))
+ }
+ p class="text-xs text-neutral-500" {
+ "People sign in with a username, so the instance never sends email \
+ and email delivery cannot be turned on."
+ }
+ }
+ } @else {
+ div class="space-y-4 border-t border-neutral-200 pt-6" {
+ div class="flex flex-wrap items-center gap-2" {
+ h3 class="text-sm font-semibold text-neutral-900" { "Email delivery" }
+ (email_delivery_state_badge(integrations.email.delivery_state))
+ @if integrations.email.effective_disable_new_ip_authorization {
+ (badge("IP auth disabled", BadgeVariant::Warning))
+ } @else {
+ (badge("IP auth required", BadgeVariant::Default))
+ }
+ @if integrations.email.smtp.password_set || integrations.email.smtp.username.is_some() {
+ (secret_badge("SMTP password", integrations.email.smtp.password_set))
+ }
+ }
+ input type="hidden" name="integration_email_present" value="1";
+ (email_delivery_select(integrations.email.delivery))
+ div class="grid grid-cols-1 gap-4 sm:grid-cols-2" {
+ (text_input(
+ "integration_email_from_email",
+ "From email",
+ integrations.email.from_email.as_deref().unwrap_or(""),
+ ))
+ (text_input(
+ "integration_email_from_name",
+ "From name",
+ integrations.email.from_name.as_deref().unwrap_or(""),
+ product_name,
+ ))
+ (text_input(
+ "integration_smtp_host",
+ "SMTP host",
+ integrations.email.smtp.host.as_deref().unwrap_or(""),
+ "smtp.example.com",
+ ))
+ (text_input(
+ "integration_smtp_port",
+ "SMTP port",
+ &smtp_port,
+ "587",
+ ))
+ (text_input(
+ "integration_smtp_username",
+ "SMTP username",
+ integrations.email.smtp.username.as_deref().unwrap_or(""),
+ ))
+ (password_input("integration_smtp_password", "SMTP password", Some("Leave blank to keep the current password.")))
+ }
+ (select_input("integration_smtp_tls_mode", "SMTP encryption", &[
+ ("", "Automatic"),
+ ("implicit", "Implicit TLS"),
+ ("starttls", "STARTTLS, required"),
+ ("opportunistic", "STARTTLS, when the server offers it"),
+ ("none", "None"),
+ ], integrations.email.smtp.tls_mode.as_deref().unwrap_or("")))
+ p class="text-xs text-neutral-500" {
+ "Automatic follows FLUXER_EMAIL_SMTP_TLS_MODE when it is set, then the older FLUXER_EMAIL_SMTP_SECURE, where true means implicit TLS on port 465 and required STARTTLS on every other port. With neither set it uses implicit TLS on port 465 and requires STARTTLS on every other port."
+ }
+ p class="text-xs text-neutral-500" {
+ "Leave the username and password empty for a relay that accepts mail without signing in."
+ }
+ @if let Some(mode) = integrations.email.smtp.effective_tls_mode.as_deref() {
+ p class="text-xs text-neutral-500" {
+ "Outgoing email currently uses " (smtp_tls_mode_summary(mode))
+ @if let Some(port) = integrations.email.smtp.port { " on port " (port) }
+ "."
+ }
+ }
+ (Checkbox {
+ name: "integration_email_disable_new_ip_authorization",
+ value: "true",
+ label: "Disable new IP login authorization",
+ checked: integrations.email.disable_new_ip_authorization,
+ enabled: true,
+ }.render())
+ (text_input(
+ "smtp_test_send_to",
+ "Send a test message to (optional)",
+ "",
+ ))
+ div class="flex flex-wrap gap-2" {
+ button type="submit"
+ formaction={(base) "/instance-config?action=test_smtp"}
+ class="inline-flex w-fit items-center justify-center gap-2 rounded-lg border border-neutral-300 bg-neutral-50 px-4 py-2 font-medium text-base text-neutral-700 transition-all duration-150 hover:border-neutral-400 hover:text-neutral-900 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-offset-white" {
+ span { "Save and test SMTP" }
+ }
+ }
+ p class="text-xs text-neutral-500" {
+ "The test saves this form first, then connects with the saved settings, the same ones outgoing email uses. With an address above it also sends a short message from the from address and shows what the server answered."
+ }
+ }
+ }
+
+ div class="space-y-4 border-t border-neutral-200 pt-6" {
+ div class="flex flex-wrap items-center gap-2" {
+ h3 class="text-sm font-semibold text-neutral-900" { "Bluesky OAuth" }
+ @if integrations.bluesky.effective_enabled {
+ (badge("Effective: enabled", BadgeVariant::Success))
+ } @else {
+ (badge("Effective: disabled", BadgeVariant::Default))
+ }
+ (badge(&format!("{} signing key(s)", integrations.bluesky.key_count), BadgeVariant::Default))
+ }
+ (inherit_select(
+ "integration_bluesky_enabled",
+ "Bluesky OAuth",
+ integrations.bluesky.enabled,
+ ))
+ div class="grid grid-cols-1 gap-4 sm:grid-cols-2" {
+ (text_input(
+ "integration_bluesky_client_name",
+ "Client name",
+ integrations.bluesky.client_name.as_deref().unwrap_or(""),
+ "Fluxer",
+ ))
+ (text_input(
+ "integration_bluesky_client_uri",
+ "Client URL",
+ integrations.bluesky.client_uri.as_deref().unwrap_or(""),
+ "https://example.com",
+ ))
+ (text_input(
+ "integration_bluesky_logo_uri",
+ "Logo URL",
+ integrations.bluesky.logo_uri.as_deref().unwrap_or(""),
+ "https://example.com/logo.png",
+ ))
+ (text_input(
+ "integration_bluesky_tos_uri",
+ "Terms URL",
+ integrations.bluesky.tos_uri.as_deref().unwrap_or(""),
+ "https://example.com/terms",
+ ))
+ (text_input(
+ "integration_bluesky_policy_uri",
+ "Privacy URL",
+ integrations.bluesky.policy_uri.as_deref().unwrap_or(""),
+ "https://example.com/privacy",
+ ))
+ (text_input("integration_bluesky_key_id", "New signing key ID", "", "atproto-key-1"))
+ (password_input("integration_bluesky_private_key", "New private key", Some("Provide this only when adding or replacing runtime Bluesky keys.")))
+ }
+ }
+
+ (form_actions(html! {
+ (submit_button("Save runtime integrations"))
+ }))
+ }
+ }
+ },
+ )
+}
+
+fn email_delivery_state_badge(state: EmailDeliveryState) -> Markup {
+ match state {
+ EmailDeliveryState::On => badge("Sending email", BadgeVariant::Success),
+ EmailDeliveryState::OffDisabled => badge("Not sending: turned off", BadgeVariant::Default),
+ EmailDeliveryState::OffIncomplete => {
+ badge("Not sending: settings incomplete", BadgeVariant::Warning)
+ }
+ EmailDeliveryState::OffUsernameMode => {
+ badge("Not sending: username sign-in", BadgeVariant::Default)
+ }
+ }
+}
diff --git a/fluxer_admin/src/templates/pages/instance_config/media.rs b/fluxer_admin/src/templates/pages/instance_config/media.rs
new file mode 100644
index 000000000..7d26ebb2e
--- /dev/null
+++ b/fluxer_admin/src/templates/pages/instance_config/media.rs
@@ -0,0 +1,169 @@
+// SPDX-License-Identifier: AGPL-3.0-or-later
+
+use super::{format_decimal, inherit_select};
+use crate::templates::pages::instance_config::ConfigForm;
+use crate::{
+ api::types::InstanceMediaResponse,
+ templates::components::{
+ badge::{BadgeVariant, badge},
+ form::{NumberField, form_actions, submit_button},
+ section_card::section_card_with_description,
+ },
+};
+use maud::{Markup, html};
+
+const MAX_ATTACHMENT_SIZE_MB: u32 = 1_000_000;
+const MAX_ATTACHMENT_LIFETIME_DAYS: u32 = 36_500;
+const MAX_ATTACHMENT_RENEWAL_DAYS: u32 = 365;
+
+pub(super) enum HostingMode {
+ SelfHosted,
+ Hosted,
+}
+
+pub(super) fn media_config_section(
+ base: &str,
+ config_form: ConfigForm<'_>,
+ media: &InstanceMediaResponse,
+ hosting: HostingMode,
+) -> Markup {
+ let decay = &media.attachment_decay;
+ let effective = &decay.effective;
+ let stored_decimal = |value: Option<f64>| value.map(format_decimal).unwrap_or_default();
+ let stored_days = |value: Option<u32>| value.map(|days| days.to_string()).unwrap_or_default();
+ let min_size_mb = stored_decimal(decay.min_size_mb);
+ let max_size_mb = stored_decimal(decay.max_size_mb);
+ let max_eligible_size_mb = stored_decimal(decay.max_eligible_size_mb);
+ let min_lifetime_days = stored_days(decay.min_lifetime_days);
+ let max_lifetime_days = stored_days(decay.max_lifetime_days);
+ let curve = stored_decimal(decay.curve);
+ let renew_threshold_days = stored_days(decay.renew_threshold_days);
+ let renew_window_days = stored_days(decay.renew_window_days);
+ let default_min_size_mb = format_decimal(effective.min_size_mb);
+ let default_max_size_mb = format_decimal(effective.max_size_mb);
+ let default_max_eligible_size_mb = format_decimal(effective.max_eligible_size_mb);
+ let default_min_lifetime_days = effective.min_lifetime_days.to_string();
+ let default_max_lifetime_days = effective.max_lifetime_days.to_string();
+ let default_curve = format_decimal(effective.curve);
+ let default_renew_threshold_days = effective.renew_threshold_days.to_string();
+ let default_renew_window_days = effective.renew_window_days.to_string();
+ let description = match hosting {
+ HostingMode::SelfHosted => {
+ "Expire eligible attachments using size-based lifetimes. This is enabled by default and applies at runtime. On a self-hosted instance, changes also apply to attachments uploaded earlier, which are kept for at least the renew window before a new or shorter expiry deletes them."
+ }
+ HostingMode::Hosted => {
+ "Expire eligible attachments using size-based lifetimes. This is enabled by default and applies at runtime. Changes apply to attachments uploaded from then on."
+ }
+ };
+ section_card_with_description(
+ "Media Expiry",
+ description,
+ html! {
+ form method="post" action={(base) "/instance-config?action=update_media"} {
+ (config_form.fields())
+ div class="space-y-6" {
+ div class="flex flex-wrap items-center gap-2" {
+ @if effective.enabled {
+ (badge("Effective: enabled", BadgeVariant::Success))
+ } @else {
+ (badge("Effective: disabled", BadgeVariant::Default))
+ }
+ }
+ (inherit_select(
+ "media_attachment_decay_enabled",
+ "Attachment expiry",
+ decay.enabled,
+ ))
+ p class="text-sm text-neutral-500" {
+ "Leave a field empty to use the value in effect, which is shown in the field."
+ }
+ div class="grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-3" {
+ (NumberField {
+ name: "media_attachment_decay_min_size_mb",
+ label: "Small file threshold (MB)",
+ value: &min_size_mb,
+ min: Some(1),
+ max: Some(MAX_ATTACHMENT_SIZE_MB),
+ step: "0.1",
+ helper: Some("Attachments at or below this size keep the maximum lifetime."),
+ placeholder: Some(&default_min_size_mb),
+ }.render())
+ (NumberField {
+ name: "media_attachment_decay_max_size_mb",
+ label: "Large file threshold (MB)",
+ value: &max_size_mb,
+ min: Some(1),
+ max: Some(MAX_ATTACHMENT_SIZE_MB),
+ step: "0.1",
+ helper: Some("Attachments at or above this size get the minimum lifetime."),
+ placeholder: Some(&default_max_size_mb),
+ }.render())
+ (NumberField {
+ name: "media_attachment_decay_max_eligible_size_mb",
+ label: "Maximum eligible size (MB)",
+ value: &max_eligible_size_mb,
+ min: Some(1),
+ max: Some(MAX_ATTACHMENT_SIZE_MB),
+ step: "0.1",
+ helper: Some("Attachments above this size are not managed by expiry."),
+ placeholder: Some(&default_max_eligible_size_mb),
+ }.render())
+ (NumberField {
+ name: "media_attachment_decay_min_lifetime_days",
+ label: "Minimum lifetime (days)",
+ value: &min_lifetime_days,
+ min: Some(1),
+ max: Some(MAX_ATTACHMENT_LIFETIME_DAYS),
+ step: "1",
+ helper: None,
+ placeholder: Some(&default_min_lifetime_days),
+ }.render())
+ (NumberField {
+ name: "media_attachment_decay_max_lifetime_days",
+ label: "Maximum lifetime (days)",
+ value: &max_lifetime_days,
+ min: Some(1),
+ max: Some(MAX_ATTACHMENT_LIFETIME_DAYS),
+ step: "1",
+ helper: None,
+ placeholder: Some(&default_max_lifetime_days),
+ }.render())
+ (NumberField {
+ name: "media_attachment_decay_curve",
+ label: "Expiry curve",
+ value: &curve,
+ min: Some(0),
+ max: Some(1),
+ step: "0.05",
+ helper: Some("0 is linear. 1 is logarithmic."),
+ placeholder: Some(&default_curve),
+ }.render())
+ (NumberField {
+ name: "media_attachment_decay_renew_threshold_days",
+ label: "Renew threshold (days)",
+ value: &renew_threshold_days,
+ min: Some(1),
+ max: Some(MAX_ATTACHMENT_RENEWAL_DAYS),
+ step: "1",
+ helper: Some("Viewed attachments renew when expiry is this close."),
+ placeholder: Some(&default_renew_threshold_days),
+ }.render())
+ (NumberField {
+ name: "media_attachment_decay_renew_window_days",
+ label: "Renew window (days)",
+ value: &renew_window_days,
+ min: Some(1),
+ max: Some(MAX_ATTACHMENT_RENEWAL_DAYS),
+ step: "1",
+ helper: Some("Renewed attachments are extended by this many days."),
+ placeholder: Some(&default_renew_window_days),
+ }.render())
+ }
+ (form_actions(html! {
+ (submit_button("Save media expiry"))
+ }))
+ }
+ }
+ },
+ )
+}
diff --git a/fluxer_admin/src/templates/pages/instance_config/policy.rs b/fluxer_admin/src/templates/pages/instance_config/policy.rs
new file mode 100644
index 000000000..01b4dfdd1
--- /dev/null
+++ b/fluxer_admin/src/templates/pages/instance_config/policy.rs
@@ -0,0 +1,309 @@
+// SPDX-License-Identifier: AGPL-3.0-or-later
+
+use super::inherit_select;
+use crate::templates::pages::instance_config::ConfigForm;
+use crate::{
+ api::types::{InstancePolicyResponse, PremiumMode},
+ templates::components::{
+ badge::{BadgeVariant, badge},
+ form::{Checkbox, danger_button, form_actions, select_input, submit_button, text_input},
+ section_card::section_card_with_description,
+ },
+};
+use maud::{Markup, html};
+
+pub(super) fn policy_config_section(
+ base: &str,
+ config_form: ConfigForm<'_>,
+ policy: &InstancePolicyResponse,
+ premium_name: &str,
+ billing_enabled: bool,
+) -> Markup {
+ section_card_with_description(
+ "Community & Policy",
+ "Control whether this instance runs as a single community, whether direct messages and \
+ friends are available, which premium model applies, and which optional embed services \
+ are enabled.",
+ html! {
+ div class="space-y-8" {
+ (single_community_form(base, config_form, policy))
+ (direct_messages_form(base, config_form, policy))
+ (premium_mode_form(base, config_form, policy, premium_name, billing_enabled))
+ (community_creation_form(base, config_form, policy))
+ (services_form(base, config_form, policy))
+ }
+ },
+ )
+}
+
+fn single_community_form(
+ base: &str,
+ config_form: ConfigForm<'_>,
+ policy: &InstancePolicyResponse,
+) -> Markup {
+ let status = if policy.single_community_enabled {
+ ("Enabled", BadgeVariant::Success)
+ } else {
+ ("Disabled", BadgeVariant::Default)
+ };
+ let existing_members_checkbox = Checkbox {
+ name: "single_community_add_members",
+ value: "true",
+ label: "Also add every existing account to the community",
+ checked: false,
+ enabled: true,
+ }
+ .render();
+ html! {
+ div class="space-y-4" {
+ div class="flex flex-wrap items-center gap-2" {
+ h3 class="text-sm font-semibold text-neutral-900" { "Single community" }
+ (badge(status.0, status.1))
+ }
+ @if let Some(guild_id) = policy.single_community_guild_id.as_deref() {
+ p class="break-all text-xs text-neutral-500" { "Community guild ID: " (guild_id) }
+ }
+ @if policy.single_community_enabled {
+ p class="text-sm text-neutral-500" {
+ "This instance funnels every member into a single community. New accounts join \
+ it when they sign up. You can point the mode at another community, add the \
+ accounts that existed before, or turn it off. The community itself is kept \
+ either way."
+ }
+ form method="post" action={(base) "/instance-config?action=update_single_community"} {
+ (config_form.fields())
+ div class="space-y-4" {
+ (text_input(
+ "single_community_guild_id",
+ "Use another community (ID)",
+ "",
+ "Leave blank to keep the current community",
+ ))
+ (existing_members_checkbox)
+ (form_actions(html! {
+ (submit_button("Save single-community settings"))
+ }))
+ }
+ }
+ form method="post" action={(base) "/instance-config?action=disable_single_community"} {
+ (config_form.fields())
+ (form_actions(html! {
+ (danger_button("Disable single-community mode"))
+ }))
+ }
+ } @else {
+ p class="text-sm text-neutral-500" {
+ "Single-community mode is off. To turn it on, enter the ID of an existing community. "
+ @if policy.single_community_guild_id.is_some() {
+ "Leave the ID blank to reuse the community above."
+ } @else {
+ "Before setup is finished, a blank ID creates a new community."
+ }
+ }
+ form method="post" action={(base) "/instance-config?action=enable_single_community"} {
+ (config_form.fields())
+ div class="space-y-4" {
+ (text_input("single_community_guild_id", "Community ID", "", "123456789012345678"))
+ (existing_members_checkbox)
+ (form_actions(html! {
+ (submit_button("Enable single-community mode"))
+ }))
+ }
+ }
+ }
+ }
+ }
+}
+
+fn direct_messages_form(
+ base: &str,
+ config_form: ConfigForm<'_>,
+ policy: &InstancePolicyResponse,
+) -> Markup {
+ let enabled_options: &[(&str, &str)] = &[("false", "Enabled"), ("true", "Disabled")];
+ html! {
+ div class="space-y-4 border-t border-neutral-200 pt-6" {
+ h3 class="text-sm font-semibold text-neutral-900" { "Direct messages and friends" }
+ form method="post" action={(base) "/instance-config?action=update_policy"} {
+ (config_form.fields())
+ @if policy.direct_messages_locked && !policy.direct_messages_disabled {
+ input type="hidden" name="policy_direct_messages_unlock" value="true";
+ }
+ div class="space-y-4" {
+ div class="grid grid-cols-1 gap-4 sm:grid-cols-2" {
+ (select_input(
+ "policy_direct_messages_disabled",
+ "Direct messages",
+ enabled_options,
+ if policy.direct_messages_disabled { "true" } else { "false" },
+ ))
+ (select_input(
+ "policy_friends_disabled",
+ "Friend requests",
+ enabled_options,
+ if policy.friends_disabled { "true" } else { "false" },
+ ))
+ }
+ p class="text-xs text-neutral-500" {
+ "With direct messages off, people can still be friends and talk in communities. \
+ With friend requests off, nobody can send or accept new requests, and \
+ existing friends stay listed."
+ }
+ @if policy.direct_messages_locked {
+ p class="text-xs text-neutral-500" {
+ "Direct messages were turned off before and then back on. Turning them off \
+ again hides existing conversations until they are turned back on."
+ }
+ }
+ (form_actions(html! {
+ (submit_button("Save direct message and friend settings"))
+ }))
+ }
+ }
+ }
+ }
+}
+
+fn premium_mode_form(
+ base: &str,
+ config_form: ConfigForm<'_>,
+ policy: &InstancePolicyResponse,
+ premium_name: &str,
+ billing_enabled: bool,
+) -> Markup {
+ let mirror_label = format!("Mirror (Free and {premium_name} tiers)");
+ let everyone_label = format!("Everyone (every member gets {premium_name} limits)");
+ html! {
+ div class="space-y-4 border-t border-neutral-200 pt-6" {
+ h3 class="text-sm font-semibold text-neutral-900" { "Premium model" }
+ form method="post" action={(base) "/instance-config?action=update_policy"} {
+ (config_form.fields())
+ div class="space-y-4" {
+ (select_input("policy_premium_mode", "Premium model", &[
+ ("mirror", mirror_label.as_str()),
+ ("everyone", everyone_label.as_str()),
+ ], policy.premium_mode.as_str()))
+ p class="text-xs text-neutral-500" {
+ "Limits you have not edited follow the model. Limits you changed under Limit \
+ Config keep your values in both models."
+ }
+ @if billing_enabled && matches!(policy.premium_mode, PremiumMode::Mirror) {
+ p class="text-sm text-amber-700" {
+ "Billing is enabled. Disable it under Premium & billing before switching \
+ the premium model to Everyone."
+ }
+ }
+ (form_actions(html! {
+ (submit_button("Save premium model"))
+ }))
+ }
+ }
+ }
+ }
+}
+
+fn community_creation_form(
+ base: &str,
+ config_form: ConfigForm<'_>,
+ policy: &InstancePolicyResponse,
+) -> Markup {
+ html! {
+ div id="community-creation" class="space-y-4 border-t border-neutral-200 pt-6" {
+ h3 class="text-sm font-semibold text-neutral-900" { "Community creation" }
+ form method="post" action={(base) "/instance-config?action=update_policy"} {
+ (config_form.fields())
+ div class="space-y-4" {
+ (select_input("policy_guild_create_access", "Who can create communities", &[
+ ("true", "Everyone"),
+ ("false", "Restricted"),
+ ], if policy.guild_create_access { "true" } else { "false" }))
+ p class="text-xs text-neutral-500" {
+ "When restricted, only admins with the wildcard ACL and users matched by a "
+ a href={(base) "/limit-config"} class="text-blue-600 hover:underline" {
+ "limit rule"
+ }
+ " that grants Community Creation Access can create communities."
+ }
+ (form_actions(html! {
+ (submit_button("Save community creation policy"))
+ }))
+ }
+ }
+ }
+ }
+}
+
+fn service_select(name: &str, label: &str, override_value: Option<bool>, resolved: bool) -> Markup {
+ let resolved_text = if resolved {
+ "Effective: enabled"
+ } else {
+ "Effective: disabled"
+ };
+ html! {
+ div class="space-y-2" {
+ (inherit_select(name, label, override_value))
+ p class="text-xs text-neutral-500" { (resolved_text) }
+ }
+ }
+}
+
+fn services_form(
+ base: &str,
+ config_form: ConfigForm<'_>,
+ policy: &InstancePolicyResponse,
+) -> Markup {
+ let available = &policy.services_available;
+ if !available.gif && !available.youtube && !available.bluesky {
+ return html! {
+ div class="space-y-4 border-t border-neutral-200 pt-6" {
+ h3 class="text-sm font-semibold text-neutral-900" { "Optional services" }
+ p class="text-sm text-neutral-500" {
+ "No optional embed services are available in this environment."
+ }
+ }
+ };
+ }
+ html! {
+ div class="space-y-4 border-t border-neutral-200 pt-6" {
+ h3 class="text-sm font-semibold text-neutral-900" { "Optional services" }
+ p class="text-sm text-neutral-500" {
+ "Override the environment default for each optional embed service. \
+ \"Inherit env default\" keeps the value configured for this deployment."
+ }
+ form method="post" action={(base) "/instance-config?action=update_policy"} {
+ (config_form.fields())
+ div class="space-y-4" {
+ div class="grid grid-cols-1 gap-4 sm:grid-cols-3" {
+ @if available.gif {
+ (service_select(
+ "policy_service_gif",
+ "GIF picker",
+ policy.services.gif_enabled,
+ policy.services_resolved.gif_enabled,
+ ))
+ }
+ @if available.youtube {
+ (service_select(
+ "policy_service_youtube",
+ "YouTube embeds",
+ policy.services.youtube_enabled,
+ policy.services_resolved.youtube_enabled,
+ ))
+ }
+ @if available.bluesky {
+ (service_select(
+ "policy_service_bluesky",
+ "Bluesky embeds",
+ policy.services.bluesky_enabled,
+ policy.services_resolved.bluesky_enabled,
+ ))
+ }
+ }
+ (form_actions(html! {
+ (submit_button("Save optional services"))
+ }))
+ }
+ }
+ }
+ }
+}