configurable honeypot toggle
This commit is contained in:
parent
5bfba1b6ff
commit
c3ceb39b71
3 changed files with 12 additions and 1 deletions
|
|
@ -45,6 +45,12 @@ in
|
||||||
description = "Path to a file containing the Telegram bot token.";
|
description = "Path to a file containing the Telegram bot token.";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
honeypot = mkOption {
|
||||||
|
type = types.bool;
|
||||||
|
default = true;
|
||||||
|
description = "Enable honeypot field for spam prevention.";
|
||||||
|
};
|
||||||
|
|
||||||
user = mkOption {
|
user = mkOption {
|
||||||
type = types.str;
|
type = types.str;
|
||||||
default = "guestbook";
|
default = "guestbook";
|
||||||
|
|
@ -80,6 +86,7 @@ in
|
||||||
BOOK_SITE_TITLE = cfg.siteTitle;
|
BOOK_SITE_TITLE = cfg.siteTitle;
|
||||||
BOOK_SITE_URL = cfg.siteUrl;
|
BOOK_SITE_URL = cfg.siteUrl;
|
||||||
BOOK_TELEGRAM_CHAT_ID = toString cfg.telegramChatId;
|
BOOK_TELEGRAM_CHAT_ID = toString cfg.telegramChatId;
|
||||||
|
BOOK_HONEYPOT = if cfg.honeypot then "true" else "false";
|
||||||
};
|
};
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
Type = "simple";
|
Type = "simple";
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ pub struct Config {
|
||||||
pub site_url: String,
|
pub site_url: String,
|
||||||
pub telegram_bot_token: String,
|
pub telegram_bot_token: String,
|
||||||
pub telegram_chat_id: i64,
|
pub telegram_chat_id: i64,
|
||||||
|
pub honeypot: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Config {
|
impl Config {
|
||||||
|
|
@ -33,6 +34,9 @@ impl Config {
|
||||||
.map_err(|_| "BOOK_TELEGRAM_CHAT_ID is required")?
|
.map_err(|_| "BOOK_TELEGRAM_CHAT_ID is required")?
|
||||||
.parse()
|
.parse()
|
||||||
.map_err(|_| "BOOK_TELEGRAM_CHAT_ID must be an integer")?,
|
.map_err(|_| "BOOK_TELEGRAM_CHAT_ID must be an integer")?,
|
||||||
|
honeypot: env::var("BOOK_HONEYPOT")
|
||||||
|
.map(|v| v != "false")
|
||||||
|
.unwrap_or(true),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,7 @@ async fn submit(
|
||||||
Form(form): Form<SubmitForm>,
|
Form(form): Form<SubmitForm>,
|
||||||
) -> Html<String> {
|
) -> Html<String> {
|
||||||
// Honeypot check — silently discard
|
// Honeypot check — silently discard
|
||||||
if !form.url.is_empty() {
|
if state.config.honeypot && !form.url.is_empty() {
|
||||||
return Html("Thanks! Your message is pending approval.".to_string());
|
return Html("Thanks! Your message is pending approval.".to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue