diff options
Diffstat (limited to 'httpd.c')
| -rw-r--r-- | httpd.c | 54 |
1 files changed, 48 insertions, 6 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* snac - A simple, minimalistic ActivityPub instance */ | 1 | /* snac - A simple, minimalistic ActivityPub instance */ |
| 2 | /* copyright (c) 2022 - 2024 grunfink et al. / MIT license */ | 2 | /* copyright (c) 2022 - 2025 grunfink et al. / MIT license */ |
| 3 | 3 | ||
| 4 | #include "xs.h" | 4 | #include "xs.h" |
| 5 | #include "xs_io.h" | 5 | #include "xs_io.h" |
| @@ -138,7 +138,7 @@ static xs_str *greeting_html(void) | |||
| 138 | while (xs_list_iter(&p, &uid)) { | 138 | while (xs_list_iter(&p, &uid)) { |
| 139 | snac user; | 139 | snac user; |
| 140 | 140 | ||
| 141 | if (user_open(&user, uid)) { | 141 | if (strcmp(uid, "relay") && user_open(&user, uid)) { |
| 142 | xs_html_add(ul, | 142 | xs_html_add(ul, |
| 143 | xs_html_tag("li", | 143 | xs_html_tag("li", |
| 144 | xs_html_tag("a", | 144 | xs_html_tag("a", |
| @@ -182,6 +182,29 @@ const char *share_page = "" | |||
| 182 | ""; | 182 | ""; |
| 183 | 183 | ||
| 184 | 184 | ||
| 185 | const char *authorize_interaction_page = "" | ||
| 186 | "<!DOCTYPE html>\n" | ||
| 187 | "<html>\n" | ||
| 188 | "<head>\n" | ||
| 189 | "<title>%s - snac</title>\n" | ||
| 190 | "<meta content=\"width=device-width, initial-scale=1, minimum-scale=1, user-scalable=no\" name=\"viewport\">\n" | ||
| 191 | "<link rel=\"stylesheet\" type=\"text/css\" href=\"%s/style.css\"/>\n" | ||
| 192 | "<style>:root {color-scheme: light dark}</style>\n" | ||
| 193 | "</head>\n" | ||
| 194 | "<body><h1>%s authorize interaction</h1>\n" | ||
| 195 | "<form method=\"get\" action=\"%s/auth-int-bridge\">\n" | ||
| 196 | "<select name=\"action\">\n" | ||
| 197 | "<option value=\"Follow\">Follow</option>\n" | ||
| 198 | "<option value=\"Boost\">Boost</option>\n" | ||
| 199 | "<option value=\"Like\">Like</option>\n" | ||
| 200 | "</select> %s\n" | ||
| 201 | "<input type=\"hidden\" name=\"id\" value=\"%s\">\n" | ||
| 202 | "<p>Login: <input type=\"text\" name=\"login\" autocapitalize=\"off\" required=\"required\"></p>\n" | ||
| 203 | "<input type=\"submit\" value=\"OK\">\n" | ||
| 204 | "</form><p>%s</p></body></html>\n" | ||
| 205 | ""; | ||
| 206 | |||
| 207 | |||
| 185 | int server_get_handler(xs_dict *req, const char *q_path, | 208 | int server_get_handler(xs_dict *req, const char *q_path, |
| 186 | char **body, int *b_size, char **ctype) | 209 | char **body, int *b_size, char **ctype) |
| 187 | /* basic server services */ | 210 | /* basic server services */ |
| @@ -189,7 +212,7 @@ int server_get_handler(xs_dict *req, const char *q_path, | |||
| 189 | int status = 0; | 212 | int status = 0; |
| 190 | 213 | ||
| 191 | /* is it the server root? */ | 214 | /* is it the server root? */ |
| 192 | if (*q_path == '\0') { | 215 | if (*q_path == '\0' || strcmp(q_path, "/") == 0) { |
| 193 | const xs_dict *q_vars = xs_dict_get(req, "q_vars"); | 216 | const xs_dict *q_vars = xs_dict_get(req, "q_vars"); |
| 194 | const char *t = NULL; | 217 | const char *t = NULL; |
| 195 | 218 | ||
| @@ -318,6 +341,25 @@ int server_get_handler(xs_dict *req, const char *q_path, | |||
| 318 | USER_AGENT | 341 | USER_AGENT |
| 319 | ); | 342 | ); |
| 320 | } | 343 | } |
| 344 | else | ||
| 345 | if (strcmp(q_path, "/authorize_interaction") == 0) { | ||
| 346 | const xs_dict *q_vars = xs_dict_get(req, "q_vars"); | ||
| 347 | const char *uri = xs_dict_get(q_vars, "uri"); | ||
| 348 | |||
| 349 | if (xs_is_string(uri)) { | ||
| 350 | status = HTTP_STATUS_OK; | ||
| 351 | *ctype = "text/html; charset=utf-8"; | ||
| 352 | *body = xs_fmt(authorize_interaction_page, | ||
| 353 | xs_dict_get(srv_config, "host"), | ||
| 354 | srv_baseurl, | ||
| 355 | xs_dict_get(srv_config, "host"), | ||
| 356 | srv_baseurl, | ||
| 357 | uri, | ||
| 358 | uri, | ||
| 359 | USER_AGENT | ||
| 360 | ); | ||
| 361 | } | ||
| 362 | } | ||
| 321 | 363 | ||
| 322 | if (status != 0) | 364 | if (status != 0) |
| 323 | srv_debug(1, xs_fmt("server_get_handler serving '%s' %d", q_path, status)); | 365 | srv_debug(1, xs_fmt("server_get_handler serving '%s' %d", q_path, status)); |
| @@ -459,13 +501,13 @@ void httpd_connection(FILE *f) | |||
| 459 | } | 501 | } |
| 460 | 502 | ||
| 461 | if (status == HTTP_STATUS_FORBIDDEN) | 503 | if (status == HTTP_STATUS_FORBIDDEN) |
| 462 | body = xs_str_new("<h1>403 Forbidden</h1>"); | 504 | body = xs_str_new("<h1>403 Forbidden (" USER_AGENT ")</h1>"); |
| 463 | 505 | ||
| 464 | if (status == HTTP_STATUS_NOT_FOUND) | 506 | if (status == HTTP_STATUS_NOT_FOUND) |
| 465 | body = xs_str_new("<h1>404 Not Found</h1>"); | 507 | body = xs_str_new("<h1>404 Not Found (" USER_AGENT ")</h1>"); |
| 466 | 508 | ||
| 467 | if (status == HTTP_STATUS_BAD_REQUEST && body != NULL) | 509 | if (status == HTTP_STATUS_BAD_REQUEST && body != NULL) |
| 468 | body = xs_str_new("<h1>400 Bad Request</h1>"); | 510 | body = xs_str_new("<h1>400 Bad Request (" USER_AGENT ")</h1>"); |
| 469 | 511 | ||
| 470 | if (status == HTTP_STATUS_SEE_OTHER) | 512 | if (status == HTTP_STATUS_SEE_OTHER) |
| 471 | headers = xs_dict_append(headers, "location", body); | 513 | headers = xs_dict_append(headers, "location", body); |