Merge pull request 'Web Client: Do not hard link on <a> element' (#75) from yonle/snac2:nohardlink into master

Reviewed-on: https://codeberg.org/grunfink/snac2/pulls/75
This commit is contained in:
grunfink 2023-07-24 14:00:35 +00:00
commit 34963e0abc
2 changed files with 40 additions and 68 deletions

106
html.c
View file

@ -1,4 +1,4 @@
/* snac - A simple, minimalistic ActivityPub instance */ /* snac - A simple, minimalistic ActivityPub instance */
/* copyright (c) 2022 - 2023 grunfink / MIT license */ /* copyright (c) 2022 - 2023 grunfink / MIT license */
#include "xs.h" #include "xs.h"
@ -325,8 +325,8 @@ d_char *html_user_header(snac *snac, d_char *s, int local)
s1 = xs_fmt( s1 = xs_fmt(
"<a href=\"%s.rss\">%s</a> - " "<a href=\"%s.rss\">%s</a> - "
"<a href=\"%s/admin\" rel=\"nofollow\">%s</a></nav>\n", "<a href=\"%s/admin\" rel=\"nofollow\">%s</a></nav>\n",
snac->actor, L("RSS"), snac->uid, L("RSS"),
snac->actor, L("private")); snac->uid, L("private"));
else { else {
xs *n_list = notify_list(snac, 1); xs *n_list = notify_list(snac, 1);
int n_len = xs_list_len(n_list); int n_len = xs_list_len(n_list);
@ -340,18 +340,14 @@ d_char *html_user_header(snac *snac, d_char *s, int local)
n_str = xs_str_new(""); n_str = xs_str_new("");
s1 = xs_fmt( s1 = xs_fmt(
"<a href=\"%s\">%s</a> - " "<a href=\"../%s\">%s</a> - "
"<a href=\"%s/admin\">%s</a> - " "<a href=\"admin\">%s</a> - "
"<a href=\"%s/notifications\">%s</a>%s - " "<a href=\"notifications\">%s</a>%s - "
"<a href=\"%s/people\">%s</a> - " "<a href=\"people\">%s</a></nav>\n",
"<a href=\"%s/settings\">%s</a>" snac->uid, L("public"),
"</nav>\n", L("private"),
snac->actor, L("public"), L("notifications"), n_str,
snac->actor, L("private"), L("people"));
snac->actor, L("notifications"), n_str,
snac->actor, L("people"),
snac->actor, L("settings")
);
} }
s = xs_str_cat(s, s1); s = xs_str_cat(s, s1);
@ -389,16 +385,16 @@ d_char *html_user_header(snac *snac, d_char *s, int local)
} }
xs_str *html_top_controls(snac *snac, xs_str *s, int settings) d_char *html_top_controls(snac *snac, d_char *s)
/* generates the top controls */ /* generates the top controls */
{ {
char *_tmpl = char *_tmpl =
"<div class=\"snac-top-controls\">\n" "<div class=\"snac-top-controls\">\n"
"<div class=\"snac-note\" %s>\n" "<div class=\"snac-note\">\n"
"<details><summary>%s</summary>\n" "<details><summary>%s</summary>\n"
"<form autocomplete=\"off\" method=\"post\" " "<form autocomplete=\"off\" method=\"post\" "
"action=\"%s/admin/note\" enctype=\"multipart/form-data\">\n" "action=\"admin/note\" enctype=\"multipart/form-data\">\n"
"<textarea class=\"snac-textarea\" name=\"content\" " "<textarea class=\"snac-textarea\" name=\"content\" "
"rows=\"8\" wrap=\"virtual\" required=\"required\" placeholder=\"What's on your mind?\"></textarea>\n" "rows=\"8\" wrap=\"virtual\" required=\"required\" placeholder=\"What's on your mind?\"></textarea>\n"
"<input type=\"hidden\" name=\"in_reply_to\" value=\"\">\n" "<input type=\"hidden\" name=\"in_reply_to\" value=\"\">\n"
@ -432,28 +428,25 @@ xs_str *html_top_controls(snac *snac, xs_str *s, int settings)
"</div>\n" "</div>\n"
"</details>\n" "</details>\n"
"<div class=\"snac-top-controls-more\" %s>\n" "<div class=\"snac-top-controls-more\">\n"
"<p><details><summary>%s</summary>\n" "<details><summary>%s</summary>\n"
"<form autocomplete=\"off\" method=\"post\" action=\"%s/admin/action\">\n" /** follow **/ "<form autocomplete=\"off\" method=\"post\" action=\"admin/action\">\n" /** follow **/
"<input type=\"text\" name=\"actor\" required=\"required\" placeholder=\"bob@example.com\">\n" "<input type=\"text\" name=\"actor\" required=\"required\" placeholder=\"bob@example.com\">\n"
"<input type=\"submit\" name=\"action\" value=\"%s\"> %s\n" "<input type=\"submit\" name=\"action\" value=\"%s\"> %s\n"
"</form><p>\n" "</form><p>\n"
"<form autocomplete=\"off\" method=\"post\" action=\"%s/admin/action\">\n" /** boost **/ "<form autocomplete=\"off\" method=\"post\" action=\"admin/action\">\n" /** boost **/
"<input type=\"text\" name=\"id\" required=\"required\" placeholder=\"https://fedi.example.com/bob/....\">\n" "<input type=\"text\" name=\"id\" required=\"required\" placeholder=\"https://fedi.example.com/bob/....\">\n"
"<input type=\"submit\" name=\"action\" value=\"%s\"> %s\n" "<input type=\"submit\" name=\"action\" value=\"%s\"> %s\n"
"</form><p>\n" "</form><p>\n"
"</details>\n" "</details>\n"
"</div>\n"
"<div class=\"snac-user-settings\" %s>\n" "<details><summary>%s</summary>\n"
"<h2 class=\"snac-header\">%s</h2>\n"
"<div class=\"snac-user-setup\">\n" /** user setup **/ "<div class=\"snac-user-setup\">\n" /** user setup **/
"<form autocomplete=\"off\" method=\"post\" " "<form autocomplete=\"off\" method=\"post\" "
"action=\"%s/admin/user-setup\" enctype=\"multipart/form-data\">\n" "action=\"admin/user-setup\" enctype=\"multipart/form-data\">\n"
"<p>%s:<br>\n" "<p>%s:<br>\n"
"<input type=\"text\" name=\"name\" value=\"%s\" placeholder=\"Your name.\"></p>\n" "<input type=\"text\" name=\"name\" value=\"%s\" placeholder=\"Your name.\"></p>\n"
@ -491,6 +484,7 @@ xs_str *html_top_controls(snac *snac, xs_str *s, int settings)
"</form>\n" "</form>\n"
"</div>\n" "</div>\n"
"</details>\n"
"</div>\n" "</div>\n"
"</div>\n"; "</div>\n";
@ -536,9 +530,7 @@ xs_str *html_top_controls(snac *snac, xs_str *s, int settings)
xs *es6 = encode_html(purge_days); xs *es6 = encode_html(purge_days);
xs *s1 = xs_fmt(_tmpl, xs *s1 = xs_fmt(_tmpl,
settings ? "style=\"display: none\"" : "",
L("New Post..."), L("New Post..."),
snac->actor,
L("Sensitive content"), L("Sensitive content"),
L("Sensitive content description"), L("Sensitive content description"),
L("Only for mentioned people"), L("Only for mentioned people"),
@ -557,19 +549,11 @@ xs_str *html_top_controls(snac *snac, xs_str *s, int settings)
L("Post"), L("Post"),
settings ? "style=\"display: none\"" : "",
L("Operations..."), L("Operations..."),
snac->actor,
L("Follow"), L("(by URL or user@host)"), L("Follow"), L("(by URL or user@host)"),
snac->actor,
L("Boost"), L("(by URL)"), L("Boost"), L("(by URL)"),
!settings ? "style=\"display: none\"" : "", L("User Settings..."),
L("User Settings"),
snac->actor,
L("Display name"), L("Display name"),
es1, es1,
L("Avatar"), L("Avatar"),
@ -673,13 +657,13 @@ xs_str *html_entry_controls(snac *snac, xs_str *os, const xs_dict *msg, const ch
{ {
xs *s1 = xs_fmt( xs *s1 = xs_fmt(
"<form autocomplete=\"off\" method=\"post\" action=\"%s/admin/action\">\n" "<form autocomplete=\"off\" method=\"post\" action=\"admin/action\">\n"
"<input type=\"hidden\" name=\"id\" value=\"%s\">\n" "<input type=\"hidden\" name=\"id\" value=\"%s\">\n"
"<input type=\"hidden\" name=\"actor\" value=\"%s\">\n" "<input type=\"hidden\" name=\"actor\" value=\"%s\">\n"
"<input type=\"hidden\" name=\"redir\" value=\"%s_entry\">\n" "<input type=\"hidden\" name=\"redir\" value=\"%s_entry\">\n"
"\n", "\n",
snac->actor, id, actor, md5 id, actor, md5
); );
s = xs_str_cat(s, s1); s = xs_str_cat(s, s1);
@ -733,7 +717,7 @@ xs_str *html_entry_controls(snac *snac, xs_str *os, const xs_dict *msg, const ch
xs *s1 = xs_fmt( xs *s1 = xs_fmt(
"<p><details><summary>%s</summary>\n" "<p><details><summary>%s</summary>\n"
"<p><div class=\"snac-note\" id=\"%s_edit\">\n" "<p><div class=\"snac-note\" id=\"%s_edit\">\n"
"<form autocomplete=\"off\" method=\"post\" action=\"%s/admin/note\" " "<form autocomplete=\"off\" method=\"post\" action=\"admin/note\" "
"enctype=\"multipart/form-data\" id=\"%s_edit_form\">\n" "enctype=\"multipart/form-data\" id=\"%s_edit_form\">\n"
"<textarea class=\"snac-textarea\" name=\"content\" " "<textarea class=\"snac-textarea\" name=\"content\" "
"rows=\"4\" wrap=\"virtual\" required=\"required\">%s</textarea>\n" "rows=\"4\" wrap=\"virtual\" required=\"required\">%s</textarea>\n"
@ -756,7 +740,7 @@ xs_str *html_entry_controls(snac *snac, xs_str *os, const xs_dict *msg, const ch
L("Edit..."), L("Edit..."),
md5, md5,
snac->actor, md5, md5,
prev_src, prev_src,
id, id,
L("Sensitive content"), L("Sensitive content"),
@ -784,7 +768,7 @@ xs_str *html_entry_controls(snac *snac, xs_str *os, const xs_dict *msg, const ch
xs *s1 = xs_fmt( xs *s1 = xs_fmt(
"<p><details><summary>%s</summary>\n" "<p><details><summary>%s</summary>\n"
"<p><div class=\"snac-note\" id=\"%s_reply\">\n" "<p><div class=\"snac-note\" id=\"%s_reply\">\n"
"<form autocomplete=\"off\" method=\"post\" action=\"%s/admin/note\" " "<form autocomplete=\"off\" method=\"post\" action=\"admin/note\" "
"enctype=\"multipart/form-data\" id=\"%s_reply_form\">\n" "enctype=\"multipart/form-data\" id=\"%s_reply_form\">\n"
"<textarea class=\"snac-textarea\" name=\"content\" " "<textarea class=\"snac-textarea\" name=\"content\" "
"rows=\"4\" wrap=\"virtual\" required=\"required\">%s</textarea>\n" "rows=\"4\" wrap=\"virtual\" required=\"required\">%s</textarea>\n"
@ -807,7 +791,7 @@ xs_str *html_entry_controls(snac *snac, xs_str *os, const xs_dict *msg, const ch
L("Reply..."), L("Reply..."),
md5, md5,
snac->actor, md5, md5,
ct, ct,
id, id,
L("Sensitive content"), L("Sensitive content"),
@ -1102,10 +1086,10 @@ xs_str *html_entry(snac *snac, xs_str *os, const xs_dict *msg, int local,
/* poll still active */ /* poll still active */
xs *s1 = xs_fmt("<div class=\"snac-poll-form\">\n" xs *s1 = xs_fmt("<div class=\"snac-poll-form\">\n"
"<form autocomplete=\"off\" " "<form autocomplete=\"off\" "
"method=\"post\" action=\"%s/admin/vote\">\n" "method=\"post\" action=\"admin/vote\">\n"
"<input type=\"hidden\" name=\"actor\" value= \"%s\">\n" "<input type=\"hidden\" name=\"actor\" value= \"%s\">\n"
"<input type=\"hidden\" name=\"irt\" value=\"%s\">\n", "<input type=\"hidden\" name=\"irt\" value=\"%s\">\n",
snac->actor, actor, id); actor, id);
while (xs_list_iter(&p, &v)) { while (xs_list_iter(&p, &v)) {
const char *name = xs_dict_get(v, "name"); const char *name = xs_dict_get(v, "name");
@ -1386,7 +1370,7 @@ xs_str *html_timeline(snac *snac, const xs_list *list, int local, int skip, int
s = html_user_header(snac, s, local); s = html_user_header(snac, s, local);
if (!local) if (!local)
s = html_top_controls(snac, s, list == NULL ? 1 : 0); s = html_top_controls(snac, s);
s = xs_str_cat(s, "<a name=\"snac-posts\"></a>\n"); s = xs_str_cat(s, "<a name=\"snac-posts\"></a>\n");
s = xs_str_cat(s, "<div class=\"snac-posts\">\n"); s = xs_str_cat(s, "<div class=\"snac-posts\">\n");
@ -1495,11 +1479,11 @@ d_char *html_people_list(snac *snac, d_char *os, d_char *list, const char *heade
s = xs_str_cat(s, "<div class=\"snac-controls\">\n"); s = xs_str_cat(s, "<div class=\"snac-controls\">\n");
xs *s1 = xs_fmt( xs *s1 = xs_fmt(
"<p><form autocomplete=\"off\" method=\"post\" action=\"%s/admin/action\">\n" "<p><form autocomplete=\"off\" method=\"post\" action=\"admin/action\">\n"
"<input type=\"hidden\" name=\"actor\" value=\"%s\">\n" "<input type=\"hidden\" name=\"actor\" value=\"%s\">\n"
"<input type=\"hidden\" name=\"actor-form\" value=\"yes\">\n", "<input type=\"hidden\" name=\"actor-form\" value=\"yes\">\n",
snac->actor, actor_id actor_id
); );
s = xs_str_cat(s, s1); s = xs_str_cat(s, s1);
@ -1523,7 +1507,7 @@ d_char *html_people_list(snac *snac, d_char *os, d_char *list, const char *heade
xs *s2 = xs_fmt( xs *s2 = xs_fmt(
"<p><details><summary>%s</summary>\n" "<p><details><summary>%s</summary>\n"
"<p><div class=\"snac-note\" id=\"%s_%s_dm\">\n" "<p><div class=\"snac-note\" id=\"%s_%s_dm\">\n"
"<form autocomplete=\"off\" method=\"post\" action=\"%s/admin/note\" " "<form autocomplete=\"off\" method=\"post\" action=\"admin/note\" "
"enctype=\"multipart/form-data\" id=\"%s_reply_form\">\n" "enctype=\"multipart/form-data\" id=\"%s_reply_form\">\n"
"<textarea class=\"snac-textarea\" name=\"content\" " "<textarea class=\"snac-textarea\" name=\"content\" "
"rows=\"4\" wrap=\"virtual\" required=\"required\"></textarea>\n" "rows=\"4\" wrap=\"virtual\" required=\"required\"></textarea>\n"
@ -1535,7 +1519,7 @@ d_char *html_people_list(snac *snac, d_char *os, d_char *list, const char *heade
L("Direct Message..."), L("Direct Message..."),
md5, t, md5, t,
snac->actor, md5, md5,
actor_id, actor_id,
L("Post") L("Post")
); );
@ -1586,9 +1570,9 @@ xs_str *html_notifications(snac *snac)
xs *s1 = xs_fmt( xs *s1 = xs_fmt(
"<form autocomplete=\"off\" " "<form autocomplete=\"off\" "
"method=\"post\" action=\"%s/admin/clear-notifications\" id=\"clear\">\n" "method=\"post\" action=\"admin/clear-notifications\" id=\"clear\">\n"
"<input type=\"submit\" class=\"snac-btn-like\" value=\"%s\">\n" "<input type=\"submit\" class=\"snac-btn-like\" value=\"%s\">\n"
"</form><p>\n", snac->actor, L("Clear all")); "</form><p>\n", L("Clear all"));
s = xs_str_cat(s, s1); s = xs_str_cat(s, s1);
while (xs_list_iter(&p, &v)) { while (xs_list_iter(&p, &v)) {
@ -1823,18 +1807,6 @@ int html_get_handler(const xs_dict *req, const char *q_path,
} }
} }
else else
if (strcmp(p_path, "settings") == 0) { /** user settings **/
if (!login(&snac, req)) {
*body = xs_dup(uid);
status = 401;
}
else {
*body = html_timeline(&snac, NULL, 0, 0, 0, 0);
*b_size = strlen(*body);
status = 200;
}
}
else
if (strcmp(p_path, "notifications") == 0) { /** the list of notifications **/ if (strcmp(p_path, "notifications") == 0) { /** the list of notifications **/
if (!login(&snac, req)) { if (!login(&snac, req)) {
*body = xs_dup(uid); *body = xs_dup(uid);
@ -2400,9 +2372,9 @@ int html_post_handler(const xs_dict *req, const char *q_path,
char *redir = xs_dict_get(p_vars, "redir"); char *redir = xs_dict_get(p_vars, "redir");
if (xs_is_null(redir)) if (xs_is_null(redir))
redir = "snac-posts"; redir = "";
*body = xs_fmt("%s/admin#%s", snac.actor, redir); *body = xs_fmt("../admin#%s", redir);
*b_size = strlen(*body); *b_size = strlen(*body);
} }

View file

@ -91,7 +91,7 @@ int server_get_handler(xs_dict *req, char *q_path,
if (user_open(&snac, uid)) { if (user_open(&snac, uid)) {
xs *u = xs_fmt( xs *u = xs_fmt(
"<li><a href=\"%s\">@%s@%s (%s)</a></li>\n", "<li><a href=\"%s\">@%s@%s (%s)</a></li>\n",
snac.actor, uid, host, uid, uid, host,
xs_dict_get(snac.config, "name")); xs_dict_get(snac.config, "name"));
ul = xs_str_cat(ul, u); ul = xs_str_cat(ul, u);