From 50129db64b70604d347c2f21be5e5182080c6e07 Mon Sep 17 00:00:00 2001 From: green Date: Sat, 12 Apr 2025 21:56:23 +0200 Subject: small: configurable poll limit --- activitypub.c | 4 ++++ html.c | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/activitypub.c b/activitypub.c index c34e510..2890a94 100644 --- a/activitypub.c +++ b/activitypub.c @@ -2322,8 +2322,12 @@ xs_dict *msg_question(snac *user, const char *content, xs_list *attach, { xs_dict *msg = msg_note(user, content, NULL, NULL, attach, 0, NULL, NULL); int max = 8; + const xs_number *max_options = xs_dict_get(srv_config, "max_poll_options"); xs_set seen; + if (xs_type(max_options) == XSTYPE_NUMBER) + max = xs_number_get(max_options); + msg = xs_dict_set(msg, "type", "Question"); /* make it non-editable */ diff --git a/html.c b/html.c index 3f5435c..1a7162f 100644 --- a/html.c +++ b/html.c @@ -778,13 +778,17 @@ xs_html *html_note(snac *user, const char *summary, /* add poll controls */ if (poll) { + const xs_number *max_options = xs_dict_get(srv_config, "max_poll_options"); + xs *poll_limit_str = xs_dup(L("Poll options (one per line, up to 8):")); + poll_limit_str = xs_replace_i(poll_limit_str, "8", xs_number_str(max_options)); + xs_html_add(form, xs_html_tag("p", NULL), xs_html_tag("details", xs_html_tag("summary", xs_html_text(L("Poll..."))), xs_html_tag("p", - xs_html_text(L("Poll options (one per line, up to 8):")), + xs_html_text(poll_limit_str), xs_html_sctag("br", NULL), xs_html_tag("textarea", xs_html_attr("class", "snac-textarea"), -- cgit v1.2.3 From 207d9e0f01b1703ed55b00825ef65be49576254b Mon Sep 17 00:00:00 2001 From: green Date: Sun, 13 Apr 2025 21:23:01 +0200 Subject: small: fix segfault for poll options --- html.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/html.c b/html.c index 1a7162f..9de51d1 100644 --- a/html.c +++ b/html.c @@ -780,7 +780,8 @@ xs_html *html_note(snac *user, const char *summary, if (poll) { const xs_number *max_options = xs_dict_get(srv_config, "max_poll_options"); xs *poll_limit_str = xs_dup(L("Poll options (one per line, up to 8):")); - poll_limit_str = xs_replace_i(poll_limit_str, "8", xs_number_str(max_options)); + if (max_options != NULL) + poll_limit_str = xs_replace_i(poll_limit_str, "8", xs_number_str(max_options)); xs_html_add(form, xs_html_tag("p", NULL), -- cgit v1.2.3 From ce8e11adc74015931d9adac6f3b108e7ec31fbf5 Mon Sep 17 00:00:00 2001 From: green Date: Mon, 5 May 2025 22:52:50 +0200 Subject: personal: bigger limit for polls --- activitypub.c | 5 +++-- html.c | 11 ++++++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/activitypub.c b/activitypub.c index 2890a94..8964030 100644 --- a/activitypub.c +++ b/activitypub.c @@ -2321,6 +2321,7 @@ xs_dict *msg_question(snac *user, const char *content, xs_list *attach, /* creates a Question message */ { xs_dict *msg = msg_note(user, content, NULL, NULL, attach, 0, NULL, NULL); + int max_line = 200; int max = 8; const xs_number *max_options = xs_dict_get(srv_config, "max_poll_options"); xs_set seen; @@ -2345,8 +2346,8 @@ xs_dict *msg_question(snac *user, const char *content, xs_list *attach, xs *v2 = xs_dup(v); xs *d = xs_dict_new(); - if (strlen(v2) > 60) { - v2[60] = '\0'; + if (strlen(v2) > max_line) { + v2[max_line] = '\0'; v2 = xs_str_cat(v2, "..."); } diff --git a/html.c b/html.c index 9de51d1..77ffda9 100644 --- a/html.c +++ b/html.c @@ -817,7 +817,13 @@ xs_html *html_note(snac *user, const char *summary, xs_html_text(L("End in 1 hour"))), xs_html_tag("option", xs_html_attr("value", "86400"), - xs_html_text(L("End in 1 day")))))); + xs_html_text(L("End in 1 day"))), + xs_html_tag("option", + xs_html_attr("value", "259200"), + xs_html_text(L("End in 3 days"))), + xs_html_tag("option", + xs_html_attr("value", "31536000"), + xs_html_text(L("End in 1 year")))))); } xs_html_add(form, @@ -3207,6 +3213,7 @@ xs_html *html_entry(snac *user, xs_dict *msg, int read_only, xs_html *add_hashtags = xs_html_tag("ul", xs_html_attr("class", "snac-more-hashtags")); + // todo: wafrn hashtags xs_list_foreach(tags, tag) { const char *type = xs_dict_get(tag, "type"); @@ -3857,6 +3864,8 @@ xs_html *html_people_list(snac *user, xs_list *list, const char *header, const c xs_free(xs_html_render(snac_metadata)); } + // todo: add metadata from "attachemnt"->"PropertyValue" + /* buttons */ xs *btn_form_action = xs_fmt("%s/admin/action", user->actor); -- cgit v1.2.3 From cc013a5af8a661a954a15bf46a2feb17d8574855 Mon Sep 17 00:00:00 2001 From: green Date: Sat, 24 Jan 2026 02:14:18 +0100 Subject: poll-limit: fix warning --- activitypub.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/activitypub.c b/activitypub.c index 8964030..e9e28be 100644 --- a/activitypub.c +++ b/activitypub.c @@ -17,6 +17,7 @@ #include "snac.h" +#include #include const char * const public_address = "https:/" "/www.w3.org/ns/activitystreams#Public"; @@ -2321,8 +2322,8 @@ xs_dict *msg_question(snac *user, const char *content, xs_list *attach, /* creates a Question message */ { xs_dict *msg = msg_note(user, content, NULL, NULL, attach, 0, NULL, NULL); - int max_line = 200; - int max = 8; + size_t max_line = 200; + int max = 8; const xs_number *max_options = xs_dict_get(srv_config, "max_poll_options"); xs_set seen; -- cgit v1.2.3 From cd96b83828a852bdf4f4311900501eba8c3972ca Mon Sep 17 00:00:00 2001 From: green Date: Sat, 24 Jan 2026 23:37:55 +0100 Subject: poll-limits: added "max_poll_option_length" option --- activitypub.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/activitypub.c b/activitypub.c index e9e28be..8eb7844 100644 --- a/activitypub.c +++ b/activitypub.c @@ -2322,13 +2322,16 @@ xs_dict *msg_question(snac *user, const char *content, xs_list *attach, /* creates a Question message */ { xs_dict *msg = msg_note(user, content, NULL, NULL, attach, 0, NULL, NULL); - size_t max_line = 200; - int max = 8; const xs_number *max_options = xs_dict_get(srv_config, "max_poll_options"); + const xs_number *max_length = xs_dict_get(srv_config, "max_poll_option_length"); xs_set seen; + size_t max_line = 60; + int max = 8; if (xs_type(max_options) == XSTYPE_NUMBER) max = xs_number_get(max_options); + if (xs_type(max_length) == XSTYPE_NUMBER) + max_line = xs_number_get(max_length); msg = xs_dict_set(msg, "type", "Question"); -- cgit v1.2.3 From 2216ac4662eed9235eadcafcfbf83928750abb67 Mon Sep 17 00:00:00 2001 From: green Date: Sun, 25 Jan 2026 00:05:03 +0100 Subject: poll-limits: added documentation to the man page --- doc/snac.8 | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/doc/snac.8 b/doc/snac.8 index d961ed2..760d54c 100644 --- a/doc/snac.8 +++ b/doc/snac.8 @@ -269,6 +269,10 @@ The maximum number of entries (posts) to be returned in user RSS feeds and outbo (default: 20). .It Ic max_attachments The maximum number of attachments per post (default: 4). +.It Ic max_poll_options +The maximum number of poll options in a poll (default: 8). +.It Ic max_poll_option_length +The maximum length of a single poll option (default: 60). .It Ic enable_svg Since version 2.73, SVG image attachments are hidden by default; you can enable them by setting this value to true. @@ -360,7 +364,7 @@ account creation, it will only get worse. includes some (not very strong) tools for trying to survive the SPAM flood that will eventually happen. .Pp -The +The .Ic min_account_age field in the main configuration file allows setting a minimum age (in seconds) to consider too recently created accounts suspicious of being @@ -375,7 +379,7 @@ These weapons of mass destruction can be written into the file in the server base directory, one per line; if this file exists, all posts' content will be matched (after being stripped of HTML tags) against these regexes, one by one, and any match will make the post to -be rejected. Use lower case, the regex will be case insensitive by default. +be rejected. Use lower case, the regex will be case insensitive by default. If you don't know about regular expressions, don't use this option (or learn about them inw some tutorial, there are gazillions of them out there), as you and your users may start missing posts. Also, @@ -455,7 +459,7 @@ The rest of activities and objects are dropped on input. There is partial support for .Vt OrderedCollection objects in the -.Pa /outbox +.Pa /outbox (with the last 20 entries of the local timeline shown). No pagination is supported. Intentionally, the .Pa /followers @@ -538,7 +542,7 @@ snac migrate $SNAC_BASEDIR origin .Pp This process can be very long and unreliable; any destination server may be down, too busy, disconnected or gone. I recommend you to read the document I linked -above to know about all the sorrows awaiting. +above to know about all the sorrows awaiting. .Pp Also, please take note that the .Nm @@ -627,7 +631,7 @@ the command-line tool. See Since version 2.67, a simple logic to avoid brute force attacks against user passwords has been implemented: if, from a given IP address, the number of failed logins reaches a given threshold, further tries from that IP address are never successful until a timer -expires. The maximum number of retries can be configured in the +expires. The maximum number of retries can be configured in the .Pa server.json file by setting the .Ic badlogin_retries -- cgit v1.2.3 From a14cf4a7dbbf6ee90ef8ff4974e7fe9a023d6e48 Mon Sep 17 00:00:00 2001 From: green Date: Sun, 25 Jan 2026 00:30:38 +0100 Subject: poll-limits: revert accidentally commited changes --- doc/snac.8 | 10 +++++----- html.c | 3 --- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/doc/snac.8 b/doc/snac.8 index 760d54c..b5ec33c 100644 --- a/doc/snac.8 +++ b/doc/snac.8 @@ -364,7 +364,7 @@ account creation, it will only get worse. includes some (not very strong) tools for trying to survive the SPAM flood that will eventually happen. .Pp -The +The .Ic min_account_age field in the main configuration file allows setting a minimum age (in seconds) to consider too recently created accounts suspicious of being @@ -379,7 +379,7 @@ These weapons of mass destruction can be written into the file in the server base directory, one per line; if this file exists, all posts' content will be matched (after being stripped of HTML tags) against these regexes, one by one, and any match will make the post to -be rejected. Use lower case, the regex will be case insensitive by default. +be rejected. Use lower case, the regex will be case insensitive by default. If you don't know about regular expressions, don't use this option (or learn about them inw some tutorial, there are gazillions of them out there), as you and your users may start missing posts. Also, @@ -459,7 +459,7 @@ The rest of activities and objects are dropped on input. There is partial support for .Vt OrderedCollection objects in the -.Pa /outbox +.Pa /outbox (with the last 20 entries of the local timeline shown). No pagination is supported. Intentionally, the .Pa /followers @@ -542,7 +542,7 @@ snac migrate $SNAC_BASEDIR origin .Pp This process can be very long and unreliable; any destination server may be down, too busy, disconnected or gone. I recommend you to read the document I linked -above to know about all the sorrows awaiting. +above to know about all the sorrows awaiting. .Pp Also, please take note that the .Nm @@ -631,7 +631,7 @@ the command-line tool. See Since version 2.67, a simple logic to avoid brute force attacks against user passwords has been implemented: if, from a given IP address, the number of failed logins reaches a given threshold, further tries from that IP address are never successful until a timer -expires. The maximum number of retries can be configured in the +expires. The maximum number of retries can be configured in the .Pa server.json file by setting the .Ic badlogin_retries diff --git a/html.c b/html.c index 77ffda9..0ee4d71 100644 --- a/html.c +++ b/html.c @@ -3213,7 +3213,6 @@ xs_html *html_entry(snac *user, xs_dict *msg, int read_only, xs_html *add_hashtags = xs_html_tag("ul", xs_html_attr("class", "snac-more-hashtags")); - // todo: wafrn hashtags xs_list_foreach(tags, tag) { const char *type = xs_dict_get(tag, "type"); @@ -3864,8 +3863,6 @@ xs_html *html_people_list(snac *user, xs_list *list, const char *header, const c xs_free(xs_html_render(snac_metadata)); } - // todo: add metadata from "attachemnt"->"PropertyValue" - /* buttons */ xs *btn_form_action = xs_fmt("%s/admin/action", user->actor); -- cgit v1.2.3