diff options
Diffstat (limited to 'data.c')
| -rw-r--r-- | data.c | 22 |
1 files changed, 20 insertions, 2 deletions
| @@ -12,6 +12,7 @@ | |||
| 12 | #include "xs_regex.h" | 12 | #include "xs_regex.h" |
| 13 | #include "xs_match.h" | 13 | #include "xs_match.h" |
| 14 | #include "xs_unicode.h" | 14 | #include "xs_unicode.h" |
| 15 | #include "xs_random.h" | ||
| 15 | 16 | ||
| 16 | #include "snac.h" | 17 | #include "snac.h" |
| 17 | 18 | ||
| @@ -164,6 +165,23 @@ int srv_open(const char *basedir, int auto_upgrade) | |||
| 164 | write_default_css(); | 165 | write_default_css(); |
| 165 | } | 166 | } |
| 166 | 167 | ||
| 168 | /* if proxy_media is set but there is no token seed, create one */ | ||
| 169 | if (xs_is_true(xs_dict_get(srv_config, "proxy_media")) && | ||
| 170 | xs_is_null(xs_dict_get(srv_config, "proxy_token_seed"))) { | ||
| 171 | char rnd[16]; | ||
| 172 | xs_rnd_buf(rnd, sizeof(rnd)); | ||
| 173 | xs *pts = xs_hex_enc(rnd, sizeof(rnd)); | ||
| 174 | |||
| 175 | xs_dict_set(srv_config, "proxy_token_seed", pts); | ||
| 176 | |||
| 177 | if ((f = fopen(cfg_file, "w")) != NULL) { | ||
| 178 | xs_json_dump(srv_config, 4, f); | ||
| 179 | fclose(f); | ||
| 180 | |||
| 181 | srv_log(xs_fmt("Created proxy_token_seed")); | ||
| 182 | } | ||
| 183 | } | ||
| 184 | |||
| 167 | return ret; | 185 | return ret; |
| 168 | } | 186 | } |
| 169 | 187 | ||
| @@ -3652,13 +3670,13 @@ t_announcement *announcement(const double after) | |||
| 3652 | } | 3670 | } |
| 3653 | 3671 | ||
| 3654 | 3672 | ||
| 3655 | xs_str *make_url(const char *href, const char *proxy) | 3673 | xs_str *make_url(const char *href, const char *proxy, int by_token) |
| 3656 | /* makes an URL, possibly including proxying */ | 3674 | /* makes an URL, possibly including proxying */ |
| 3657 | { | 3675 | { |
| 3658 | xs_str *url = NULL; | 3676 | xs_str *url = NULL; |
| 3659 | 3677 | ||
| 3660 | if (proxy && !xs_startswith(href, srv_baseurl)) { | 3678 | if (proxy && !xs_startswith(href, srv_baseurl)) { |
| 3661 | xs *p = xs_str_cat(xs_dup(proxy), "/proxy/"); | 3679 | xs *p = xs_str_cat(xs_dup(proxy), "/x/"); |
| 3662 | url = xs_replace(href, "https:/" "/", p); | 3680 | url = xs_replace(href, "https:/" "/", p); |
| 3663 | } | 3681 | } |
| 3664 | else | 3682 | else |