feat: reimplements the captcha and related options

This commit is contained in:
Lewis Wynne 2026-04-09 19:11:45 +01:00
parent 726fe55eb8
commit 75f1644cc1
5 changed files with 242 additions and 30 deletions

View file

@ -60,7 +60,7 @@ in
enableHtmlInjection = mkOption {
type = types.bool;
default = true;
default = false;
description = "Allow raw HTML/JS in entry names and message bodies. When false, HTML is escaped. Website URLs are always escaped.";
};
@ -75,6 +75,34 @@ in
default = true;
description = "Enable honeypot field for spam prevention.";
};
captcha = {
enable = mkEnableOption "captcha on submission form";
question = mkOption {
type = types.str;
default = "";
description = "Captcha question displayed as a label.";
};
answer = mkOption {
type = types.str;
default = "";
description = "Captcha answer to validate against.";
};
exact = mkOption {
type = types.bool;
default = false;
description = "Require exact match. When false, the answer just needs to be contained in the response.";
};
caseSensitive = mkOption {
type = types.bool;
default = false;
description = "Require case-sensitive match.";
};
};
};
telegram = {
@ -92,19 +120,19 @@ in
limits = {
name = mkOption {
type = types.int;
default = 50;
default = 0;
description = "Maximum length for names. 0 for unlimited.";
};
message = mkOption {
type = types.int;
default = 1000;
default = 0;
description = "Maximum length for messages. 0 for unlimited.";
};
website = mkOption {
type = types.int;
default = 100;
default = 0;
description = "Maximum length for website URLs. 0 for unlimited.";
};
};
@ -136,7 +164,7 @@ in
greeting = mkOption {
type = types.str;
default = "If you visited my site, please sign my guestbook!";
default = "Thanks for visiting. Sign the guestbook!";
description = "Text shown above the form.";
};
@ -199,6 +227,11 @@ in
BOOK_ENABLE_SUBMISSIONS = if cfg.security.enableSubmissions then "true" else "false";
BOOK_ENABLE_HTML_INJECTION = if cfg.security.enableHtmlInjection then "true" else "false";
BOOK_ENABLE_WEBSITE_LINKS = if cfg.security.enableWebsiteLinks then "true" else "false";
BOOK_ENABLE_CAPTCHA = if cfg.security.captcha.enable then "true" else "false";
BOOK_CAPTCHA_QUESTION = cfg.security.captcha.question;
BOOK_CAPTCHA_ANSWER = cfg.security.captcha.answer;
BOOK_CAPTCHA_EXACT = if cfg.security.captcha.exact then "true" else "false";
BOOK_CAPTCHA_CASESENSITIVE = if cfg.security.captcha.caseSensitive then "true" else "false";
BOOK_MAX_NAME_LENGTH = toString cfg.limits.name;
BOOK_MAX_MESSAGE_LENGTH = toString cfg.limits.message;
BOOK_MAX_WEBSITE_LENGTH = toString cfg.limits.website;