From 7b8f766feb35629c7db6e9392dbe9de2dd6f7239 Mon Sep 17 00:00:00 2001 From: default Date: Thu, 19 Dec 2024 05:00:23 +0100 Subject: Searching for URLs brings a post to the user timeline. --- html.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'html.c') diff --git a/html.c b/html.c index 2c353d2..f2b1252 100644 --- a/html.c +++ b/html.c @@ -2996,6 +2996,51 @@ int html_get_handler(const xs_dict *req, const char *q_path, } else { const char *q = xs_dict_get(q_vars, "q"); + xs *url_acct = NULL; + + /* searching for an URL? */ + if (q && xs_match(q, "https://*|http://*")) { + /* may by an actor; try a webfinger */ + xs *actor_obj = NULL; + + if (valid_status(webfinger_request(q, &actor_obj, &url_acct))) { + /* it's an actor; do the dirty trick of changing q to the account name */ + q = url_acct; + } + else { + /* if it's not already here, try to bring it to the user's timeline */ + xs *md5 = xs_md5_hex(q, strlen(q)); + + if (!timeline_here(&snac, md5)) { + xs *object = NULL; + int status; + + status = activitypub_request(&snac, q, &object); + snac_debug(&snac, 1, xs_fmt("Request searched URL %s %d", q, status)); + + if (valid_status(status)) { + /* got it; also request the actor */ + const char *attr_to = get_atto(object); + + if (!xs_is_null(attr_to)) { + status = actor_request(&snac, attr_to, &actor_obj); + + snac_debug(&snac, 1, xs_fmt("Request author %s of %s %d", attr_to, q, status)); + + if (valid_status(status)) { + /* add the actor */ + actor_add(attr_to, actor_obj); + + /* add the post to the timeline */ + timeline_add(&snac, q, object); + } + } + } + } + } + + /* fall through */ + } if (q && *q) { if (xs_regex_match(q, "^@?[a-zA-Z0-9_]+@[a-zA-Z0-9-]+\\.")) { -- cgit v1.2.3 From 57a8716f72dd5c75c98ead085fbd8d7f12660da6 Mon Sep 17 00:00:00 2001 From: default Date: Thu, 19 Dec 2024 18:54:15 +0100 Subject: Added bad login throttling. --- html.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'html.c') diff --git a/html.c b/html.c index f2b1252..8c00961 100644 --- a/html.c +++ b/html.c @@ -29,9 +29,18 @@ int login(snac *snac, const xs_dict *headers) xs *l1 = xs_split_n(s2, ":", 1); if (xs_list_len(l1) == 2) { - logged_in = check_password( - xs_list_get(l1, 0), xs_list_get(l1, 1), - xs_dict_get(snac->config, "passwd")); + const char *user = xs_list_get(l1, 0); + const char *pwd = xs_list_get(l1, 1); + const char *addr = xs_or(xs_dict_get(headers, "remote-addr"), + xs_dict_get(headers, "x-forwarded-for")); + + if (badlogin_check(user, addr)) { + logged_in = check_password(user, pwd, + xs_dict_get(snac->config, "passwd")); + + if (!logged_in) + badlogin_inc(user, addr); + } } } -- cgit v1.2.3 From 156d5280196c948369b186999a74c7062272b5b2 Mon Sep 17 00:00:00 2001 From: default Date: Fri, 20 Dec 2024 09:04:17 +0100 Subject: Add contact metrics to og:description. --- html.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'html.c') diff --git a/html.c b/html.c index 8c00961..d85c673 100644 --- a/html.c +++ b/html.c @@ -642,6 +642,17 @@ xs_html *html_user_head(snac *user, const char *desc, const char *url) else s_desc = xs_dup(desc); + /* show metrics in og:description? */ + if (xs_is_true(xs_dict_get(user->config, "show_contact_metrics"))) { + xs *fwers = follower_list(user); + xs *fwing = following_list(user); + + xs *s1 = xs_fmt(L("%d following, %d followers ยท "), + xs_list_len(fwing), xs_list_len(fwers)); + + s_desc = xs_str_prepend_i(s_desc, s1); + } + /* shorten desc to a reasonable size */ for (n = 0; s_desc[n]; n++) { if (n > 512 && (s_desc[n] == ' ' || s_desc[n] == '\n')) -- cgit v1.2.3 From 05d6e41710ed46526f42048dbf24cc3185ba3aa6 Mon Sep 17 00:00:00 2001 From: default Date: Sat, 21 Dec 2024 17:06:01 +0100 Subject: If an attachment includes an icon, show it. --- html.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'html.c') diff --git a/html.c b/html.c index d85c673..4060262 100644 --- a/html.c +++ b/html.c @@ -2061,6 +2061,23 @@ xs_html *html_entry(snac *user, xs_dict *msg, int read_only, if (content && xs_str_in(content, o_href) != -1) continue; + /* do this attachment include an icon? */ + const xs_dict *icon = xs_dict_get(a, "icon"); + if (xs_type(icon) == XSTYPE_DICT) { + const char *icon_mtype = xs_dict_get(icon, "mediaType"); + const char *icon_url = xs_dict_get(icon, "url"); + + if (icon_mtype && icon_url && xs_startswith(icon_mtype, "image/")) { + xs_html_add(content_attachments, + xs_html_tag("a", + xs_html_attr("href", icon_url), + xs_html_attr("target", "_blank"), + xs_html_sctag("img", + xs_html_attr("loading", "lazy"), + xs_html_attr("src", icon_url)))); + } + } + xs *href = make_url(o_href, proxy, 0); if (xs_startswith(type, "image/") || strcmp(type, "Image") == 0) { -- cgit v1.2.3 From 240f212252f9cc2a16d2accda7c619a90702da9c Mon Sep 17 00:00:00 2001 From: default Date: Sat, 21 Dec 2024 18:40:09 +0100 Subject: Account names can also contain periods (in account search). --- html.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'html.c') diff --git a/html.c b/html.c index 4060262..2c0a823 100644 --- a/html.c +++ b/html.c @@ -3080,7 +3080,7 @@ int html_get_handler(const xs_dict *req, const char *q_path, } if (q && *q) { - if (xs_regex_match(q, "^@?[a-zA-Z0-9_]+@[a-zA-Z0-9-]+\\.")) { + if (xs_regex_match(q, "^@?[a-zA-Z0-9._]+@[a-zA-Z0-9-]+\\.")) { /** search account **/ xs *actor = NULL; xs *acct = NULL; -- cgit v1.2.3