diff options
Diffstat (limited to '')
| -rw-r--r-- | html.c | 35 | ||||
| -rw-r--r-- | httpd.c | 39 |
2 files changed, 73 insertions, 1 deletions
| @@ -2934,6 +2934,8 @@ int html_get_handler(const xs_dict *req, const char *q_path, | |||
| 2934 | int proxy = 0; | 2934 | int proxy = 0; |
| 2935 | const char *v; | 2935 | const char *v; |
| 2936 | 2936 | ||
| 2937 | const xs_dict *q_vars = xs_dict_get(req, "q_vars"); | ||
| 2938 | |||
| 2937 | xs *l = xs_split_n(q_path, "/", 2); | 2939 | xs *l = xs_split_n(q_path, "/", 2); |
| 2938 | v = xs_list_get(l, 1); | 2940 | v = xs_list_get(l, 1); |
| 2939 | 2941 | ||
| @@ -2942,6 +2944,23 @@ int html_get_handler(const xs_dict *req, const char *q_path, | |||
| 2942 | return HTTP_STATUS_NOT_FOUND; | 2944 | return HTTP_STATUS_NOT_FOUND; |
| 2943 | } | 2945 | } |
| 2944 | 2946 | ||
| 2947 | if (strcmp(v, "share-bridge") == 0) { | ||
| 2948 | /* temporary redirect for a post */ | ||
| 2949 | const char *login = xs_dict_get(q_vars, "login"); | ||
| 2950 | const char *content = xs_dict_get(q_vars, "content"); | ||
| 2951 | |||
| 2952 | if (xs_type(login) == XSTYPE_STRING && xs_type(content) == XSTYPE_STRING) { | ||
| 2953 | xs *b64 = xs_base64_enc(content, strlen(content)); | ||
| 2954 | |||
| 2955 | srv_log(xs_fmt("share-bridge for user '%s'", login)); | ||
| 2956 | |||
| 2957 | *body = xs_fmt("%s/%s/share?content=%s", srv_baseurl, login, b64); | ||
| 2958 | return HTTP_STATUS_SEE_OTHER; | ||
| 2959 | } | ||
| 2960 | else | ||
| 2961 | return HTTP_STATUS_NOT_FOUND; | ||
| 2962 | } | ||
| 2963 | |||
| 2945 | uid = xs_dup(v); | 2964 | uid = xs_dup(v); |
| 2946 | 2965 | ||
| 2947 | /* rss extension? */ | 2966 | /* rss extension? */ |
| @@ -2976,7 +2995,6 @@ int html_get_handler(const xs_dict *req, const char *q_path, | |||
| 2976 | int def_show = xs_number_get(xs_dict_get(srv_config, "max_timeline_entries")); | 2995 | int def_show = xs_number_get(xs_dict_get(srv_config, "max_timeline_entries")); |
| 2977 | int show = def_show; | 2996 | int show = def_show; |
| 2978 | 2997 | ||
| 2979 | const xs_dict *q_vars = xs_dict_get(req, "q_vars"); | ||
| 2980 | if ((v = xs_dict_get(q_vars, "skip")) != NULL) | 2998 | if ((v = xs_dict_get(q_vars, "skip")) != NULL) |
| 2981 | skip = atoi(v), cache = 0, save = 0; | 2999 | skip = atoi(v), cache = 0, save = 0; |
| 2982 | if ((v = xs_dict_get(q_vars, "show")) != NULL) | 3000 | if ((v = xs_dict_get(q_vars, "show")) != NULL) |
| @@ -3490,6 +3508,21 @@ int html_get_handler(const xs_dict *req, const char *q_path, | |||
| 3490 | } | 3508 | } |
| 3491 | } | 3509 | } |
| 3492 | else | 3510 | else |
| 3511 | if (strcmp(p_path, "share") == 0) { /** direct post **/ | ||
| 3512 | if (!login(&snac, req)) { | ||
| 3513 | *body = xs_dup(uid); | ||
| 3514 | status = HTTP_STATUS_UNAUTHORIZED; | ||
| 3515 | } | ||
| 3516 | else { | ||
| 3517 | const char *content = xs_dict_get(q_vars, "content"); | ||
| 3518 | |||
| 3519 | // srv_log(xs_fmt("---> SHARE %s", content)); | ||
| 3520 | *body = xs_fmt("%s/admin", snac.actor); | ||
| 3521 | *b_size = strlen(*body); | ||
| 3522 | status = HTTP_STATUS_SEE_OTHER; | ||
| 3523 | } | ||
| 3524 | } | ||
| 3525 | else | ||
| 3493 | status = HTTP_STATUS_NOT_FOUND; | 3526 | status = HTTP_STATUS_NOT_FOUND; |
| 3494 | 3527 | ||
| 3495 | user_free(&snac); | 3528 | user_free(&snac); |
| @@ -164,6 +164,23 @@ static xs_str *greeting_html(void) | |||
| 164 | } | 164 | } |
| 165 | 165 | ||
| 166 | 166 | ||
| 167 | const char *share_page = "" | ||
| 168 | "<!DOCTYPE html>\n" | ||
| 169 | "<html>\n" | ||
| 170 | "<head>\n" | ||
| 171 | "<title>%s - snac</title>\n" | ||
| 172 | "<meta content=\"width=device-width, initial-scale=1, minimum-scale=1, user-scalable=no\" name=\"viewport\">" | ||
| 173 | "<style>:root {color-scheme: light dark}</style>\n" | ||
| 174 | "</head>\n" | ||
| 175 | "<body><h1>%s link share</h1>\n" | ||
| 176 | "<form method=\"get\" action=\"%s/share-bridge\">\n" | ||
| 177 | "<textarea name=\"content\" rows=\"6\" wrap=\"virtual\" required=\"required\" style=\"width: 50em\">%s</textarea>\n" | ||
| 178 | "<p>Login: <input type=\"text\" name=\"login\" autocapitalize=\"off\" required=\"required\"></p>\n" | ||
| 179 | "<input type=\"submit\" value=\"OK\">\n" | ||
| 180 | "</form><p>%s</p></body></html>\n" | ||
| 181 | ""; | ||
| 182 | |||
| 183 | |||
| 167 | int server_get_handler(xs_dict *req, const char *q_path, | 184 | int server_get_handler(xs_dict *req, const char *q_path, |
| 168 | char **body, int *b_size, char **ctype) | 185 | char **body, int *b_size, char **ctype) |
| 169 | /* basic server services */ | 186 | /* basic server services */ |
| @@ -257,6 +274,28 @@ int server_get_handler(xs_dict *req, const char *q_path, | |||
| 257 | *body = xs_str_new("User-agent: *\n" | 274 | *body = xs_str_new("User-agent: *\n" |
| 258 | "Disallow: /\n"); | 275 | "Disallow: /\n"); |
| 259 | } | 276 | } |
| 277 | else | ||
| 278 | if (strcmp(q_path, "/share") == 0) { | ||
| 279 | const xs_dict *q_vars = xs_dict_get(req, "q_vars"); | ||
| 280 | const char *url = xs_dict_get(q_vars, "url"); | ||
| 281 | const char *text = xs_dict_get(q_vars, "text"); | ||
| 282 | xs *s = NULL; | ||
| 283 | |||
| 284 | if (xs_type(text) == XSTYPE_STRING) | ||
| 285 | s = xs_fmt("%s\n\n%s\n", text, url); | ||
| 286 | else | ||
| 287 | s = xs_fmt("%s\n", url); | ||
| 288 | |||
| 289 | status = HTTP_STATUS_OK; | ||
| 290 | *ctype = "text/html"; | ||
| 291 | *body = xs_fmt(share_page, | ||
| 292 | xs_dict_get(srv_config, "host"), | ||
| 293 | xs_dict_get(srv_config, "host"), | ||
| 294 | srv_baseurl, | ||
| 295 | s, | ||
| 296 | USER_AGENT | ||
| 297 | ); | ||
| 298 | } | ||
| 260 | 299 | ||
| 261 | if (status != 0) | 300 | if (status != 0) |
| 262 | srv_debug(1, xs_fmt("server_get_handler serving '%s' %d", q_path, status)); | 301 | srv_debug(1, xs_fmt("server_get_handler serving '%s' %d", q_path, status)); |