diff options
| -rw-r--r-- | html.c | 31 | ||||
| -rw-r--r-- | httpd.c | 3 | ||||
| -rw-r--r-- | mastoapi.c | 19 |
3 files changed, 53 insertions, 0 deletions
| @@ -1567,6 +1567,25 @@ xs_str *html_timeline(snac *user, const xs_list *list, int local, int skip, int | |||
| 1567 | if (!valid_status(status)) | 1567 | if (!valid_status(status)) |
| 1568 | continue; | 1568 | continue; |
| 1569 | 1569 | ||
| 1570 | /* if it's an instance page, discard private users */ | ||
| 1571 | if (user == NULL) { | ||
| 1572 | const char *atto = xs_dict_get(msg, "attributedTo"); | ||
| 1573 | xs *l = xs_split(atto, "/"); | ||
| 1574 | const char *uid = xs_list_get(l, -1); | ||
| 1575 | snac user; | ||
| 1576 | int skip = 1; | ||
| 1577 | |||
| 1578 | if (uid && user_open(&user, uid)) { | ||
| 1579 | if (xs_type(xs_dict_get(user.config, "private")) != XSTYPE_TRUE) | ||
| 1580 | skip = 0; | ||
| 1581 | |||
| 1582 | user_free(&user); | ||
| 1583 | } | ||
| 1584 | |||
| 1585 | if (skip) | ||
| 1586 | continue; | ||
| 1587 | } | ||
| 1588 | |||
| 1570 | s = html_entry(user, s, msg, local, 0, v, user ? 0 : 1); | 1589 | s = html_entry(user, s, msg, local, 0, v, user ? 0 : 1); |
| 1571 | } | 1590 | } |
| 1572 | 1591 | ||
| @@ -1940,6 +1959,9 @@ int html_get_handler(const xs_dict *req, const char *q_path, | |||
| 1940 | show = atoi(v), cache = 0, save = 0; | 1959 | show = atoi(v), cache = 0, save = 0; |
| 1941 | 1960 | ||
| 1942 | if (p_path == NULL) { /** public timeline **/ | 1961 | if (p_path == NULL) { /** public timeline **/ |
| 1962 | if (xs_type(xs_dict_get(snac.config, "private")) == XSTYPE_TRUE) | ||
| 1963 | return 403; | ||
| 1964 | |||
| 1943 | xs *h = xs_str_localtime(0, "%Y-%m.html"); | 1965 | xs *h = xs_str_localtime(0, "%Y-%m.html"); |
| 1944 | 1966 | ||
| 1945 | if (cache && history_mtime(&snac, h) > timeline_mtime(&snac)) { | 1967 | if (cache && history_mtime(&snac, h) > timeline_mtime(&snac)) { |
| @@ -2022,6 +2044,9 @@ int html_get_handler(const xs_dict *req, const char *q_path, | |||
| 2022 | } | 2044 | } |
| 2023 | else | 2045 | else |
| 2024 | if (xs_startswith(p_path, "p/")) { /** a timeline with just one entry **/ | 2046 | if (xs_startswith(p_path, "p/")) { /** a timeline with just one entry **/ |
| 2047 | if (xs_type(xs_dict_get(snac.config, "private")) == XSTYPE_TRUE) | ||
| 2048 | return 403; | ||
| 2049 | |||
| 2025 | xs *id = xs_fmt("%s/%s", snac.actor, p_path); | 2050 | xs *id = xs_fmt("%s/%s", snac.actor, p_path); |
| 2026 | xs *msg = NULL; | 2051 | xs *msg = NULL; |
| 2027 | 2052 | ||
| @@ -2054,6 +2079,9 @@ int html_get_handler(const xs_dict *req, const char *q_path, | |||
| 2054 | } | 2079 | } |
| 2055 | else | 2080 | else |
| 2056 | if (xs_startswith(p_path, "h/")) { /** an entry from the history **/ | 2081 | if (xs_startswith(p_path, "h/")) { /** an entry from the history **/ |
| 2082 | if (xs_type(xs_dict_get(snac.config, "private")) == XSTYPE_TRUE) | ||
| 2083 | return 403; | ||
| 2084 | |||
| 2057 | xs *l = xs_split(p_path, "/"); | 2085 | xs *l = xs_split(p_path, "/"); |
| 2058 | char *id = xs_list_get(l, 1); | 2086 | char *id = xs_list_get(l, 1); |
| 2059 | 2087 | ||
| @@ -2070,6 +2098,9 @@ int html_get_handler(const xs_dict *req, const char *q_path, | |||
| 2070 | } | 2098 | } |
| 2071 | else | 2099 | else |
| 2072 | if (strcmp(p_path, ".rss") == 0) { /** public timeline in RSS format **/ | 2100 | if (strcmp(p_path, ".rss") == 0) { /** public timeline in RSS format **/ |
| 2101 | if (xs_type(xs_dict_get(snac.config, "private")) == XSTYPE_TRUE) | ||
| 2102 | return 403; | ||
| 2103 | |||
| 2073 | xs_str *rss; | 2104 | xs_str *rss; |
| 2074 | xs *elems = timeline_simple_list(&snac, "public", 0, 20); | 2105 | xs *elems = timeline_simple_list(&snac, "public", 0, 20); |
| 2075 | xs *bio = not_really_markdown(xs_dict_get(snac.config, "bio"), NULL); | 2106 | xs *bio = not_really_markdown(xs_dict_get(snac.config, "bio"), NULL); |
| @@ -284,6 +284,9 @@ void httpd_connection(FILE *f) | |||
| 284 | status = 404; | 284 | status = 404; |
| 285 | } | 285 | } |
| 286 | 286 | ||
| 287 | if (status == 403) | ||
| 288 | body = xs_str_new("<h1>403 Forbidden</h1>"); | ||
| 289 | |||
| 287 | if (status == 404) | 290 | if (status == 404) |
| 288 | body = xs_str_new("<h1>404 Not Found</h1>"); | 291 | body = xs_str_new("<h1>404 Not Found</h1>"); |
| 289 | 292 | ||
| @@ -1377,6 +1377,25 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, | |||
| 1377 | if (strcmp(type, "Note") != 0 && strcmp(type, "Question") != 0) | 1377 | if (strcmp(type, "Note") != 0 && strcmp(type, "Question") != 0) |
| 1378 | continue; | 1378 | continue; |
| 1379 | 1379 | ||
| 1380 | /* discard private users */ | ||
| 1381 | { | ||
| 1382 | const char *atto = xs_dict_get(msg, "attributedTo"); | ||
| 1383 | xs *l = xs_split(atto, "/"); | ||
| 1384 | const char *uid = xs_list_get(l, -1); | ||
| 1385 | snac p_user; | ||
| 1386 | int skip = 1; | ||
| 1387 | |||
| 1388 | if (uid && user_open(&p_user, uid)) { | ||
| 1389 | if (xs_type(xs_dict_get(p_user.config, "private")) != XSTYPE_TRUE) | ||
| 1390 | skip = 0; | ||
| 1391 | |||
| 1392 | user_free(&p_user); | ||
| 1393 | } | ||
| 1394 | |||
| 1395 | if (skip) | ||
| 1396 | continue; | ||
| 1397 | } | ||
| 1398 | |||
| 1380 | /* convert the Note into a Mastodon status */ | 1399 | /* convert the Note into a Mastodon status */ |
| 1381 | xs *st = mastoapi_status(user, msg); | 1400 | xs *st = mastoapi_status(user, msg); |
| 1382 | 1401 | ||