diff options
| -rw-r--r-- | html.c | 73 | ||||
| -rw-r--r-- | httpd.c | 9 | ||||
| -rw-r--r-- | main.c | 2 | ||||
| -rw-r--r-- | snac.h | 2 | ||||
| -rw-r--r-- | utils.c | 4 |
5 files changed, 86 insertions, 4 deletions
| @@ -244,8 +244,81 @@ xs_str *html_instance_header(xs_str *s) | |||
| 244 | { | 244 | { |
| 245 | s = html_base_header(s); | 245 | s = html_base_header(s); |
| 246 | 246 | ||
| 247 | { | ||
| 248 | FILE *f; | ||
| 249 | xs *g_css_fn = xs_fmt("%s/style.css", srv_basedir); | ||
| 250 | |||
| 251 | if ((f = fopen(g_css_fn, "r")) != NULL) { | ||
| 252 | xs *css = xs_readall(f); | ||
| 253 | fclose(f); | ||
| 254 | |||
| 255 | xs *s1 = xs_fmt("<style>%s</style>\n", css); | ||
| 256 | s = xs_str_cat(s, s1); | ||
| 257 | } | ||
| 258 | } | ||
| 259 | |||
| 260 | const char *host = xs_dict_get(srv_config, "host"); | ||
| 261 | const char *title = xs_dict_get(srv_config, "title"); | ||
| 262 | const char *sdesc = xs_dict_get(srv_config, "short_description"); | ||
| 263 | const char *email = xs_dict_get(srv_config, "admin_email"); | ||
| 264 | const char *acct = xs_dict_get(srv_config, "admin_account"); | ||
| 265 | |||
| 266 | { | ||
| 267 | xs *s1 = xs_fmt("<title>%s</title>\n", title && *title ? title : host); | ||
| 268 | s = xs_str_cat(s, s1); | ||
| 269 | } | ||
| 270 | |||
| 247 | s = xs_str_cat(s, "</head>\n<body>\n"); | 271 | s = xs_str_cat(s, "</head>\n<body>\n"); |
| 248 | 272 | ||
| 273 | s = xs_str_cat(s, "<div class=\"snac-instance-blurb\">\n"); | ||
| 274 | |||
| 275 | { | ||
| 276 | xs *s1 = xs_fmt( | ||
| 277 | "<p><b>%s</b> is a " | ||
| 278 | "<a href=\"https:/" "/en.wikipedia.org/wiki/Fediverse\">Fediverse</a> " | ||
| 279 | "instance that uses the " | ||
| 280 | "<a href=\"https:/" "/en.wikipedia.org/wiki/ActivityPub\">ActivityPub</a> " | ||
| 281 | "protocol. In other words, users at this host can communicate with people " | ||
| 282 | "that use software like Mastodon, Pleroma, Friendica, etc. " | ||
| 283 | "all around the world.</p>\n" | ||
| 284 | "<p>This server runs the " | ||
| 285 | "<a href=\"" WHAT_IS_SNAC_URL "\">snac</a> software and there is no " | ||
| 286 | "automatic sign-up process.</p>\n", | ||
| 287 | host); | ||
| 288 | s = xs_str_cat(s, s1); | ||
| 289 | } | ||
| 290 | |||
| 291 | s = xs_str_cat(s, "<dl>\n"); | ||
| 292 | |||
| 293 | if (sdesc && *sdesc) { | ||
| 294 | xs *s1 = xs_fmt("<di><dt>%s</dt><dd>%s</dd></di>\n", L("Site description"), sdesc); | ||
| 295 | s = xs_str_cat(s, s1); | ||
| 296 | } | ||
| 297 | if (email && *email) { | ||
| 298 | xs *s1 = xs_fmt("<di><dt>%s</dt><dd>" | ||
| 299 | "<a href=\"mailto:%s\">%s</a></dd></di>\n", | ||
| 300 | L("Admin email"), email, email); | ||
| 301 | |||
| 302 | s = xs_str_cat(s, s1); | ||
| 303 | } | ||
| 304 | if (acct && *acct) { | ||
| 305 | xs *s1 = xs_fmt("<di><dt>%s</dt><dd>" | ||
| 306 | "<a href=\"%s/%s\">@%s@%s</a></dd></di>\n", | ||
| 307 | L("Admin account"), srv_baseurl, acct, acct, host); | ||
| 308 | |||
| 309 | s = xs_str_cat(s, s1); | ||
| 310 | } | ||
| 311 | |||
| 312 | s = xs_str_cat(s, "</dl>\n"); | ||
| 313 | |||
| 314 | s = xs_str_cat(s, "</div>\n"); | ||
| 315 | |||
| 316 | { | ||
| 317 | xs *s1 = xs_fmt("<h2 class=\"snac-header\">%s</h2>\n", | ||
| 318 | L("Recent posts by users in this instance")); | ||
| 319 | s = xs_str_cat(s, s1); | ||
| 320 | } | ||
| 321 | |||
| 249 | return s; | 322 | return s; |
| 250 | } | 323 | } |
| 251 | 324 | ||
| @@ -114,7 +114,14 @@ int server_get_handler(xs_dict *req, const char *q_path, | |||
| 114 | 114 | ||
| 115 | /* is it the server root? */ | 115 | /* is it the server root? */ |
| 116 | if (*q_path == '\0') { | 116 | if (*q_path == '\0') { |
| 117 | if ((*body = greeting_html()) != NULL) | 117 | if (xs_type(xs_dict_get(srv_config, "show_instance_timeline")) == XSTYPE_TRUE) { |
| 118 | xs *tl = timeline_instance_list(0, 30); | ||
| 119 | *body = html_timeline(NULL, tl, 0, 0, 0, 0); | ||
| 120 | } | ||
| 121 | else | ||
| 122 | *body = greeting_html(); | ||
| 123 | |||
| 124 | if (*body) | ||
| 118 | status = 200; | 125 | status = 200; |
| 119 | } | 126 | } |
| 120 | else | 127 | else |
| @@ -55,8 +55,6 @@ char *get_argv(int *argi, int argc, char *argv[]) | |||
| 55 | 55 | ||
| 56 | #define GET_ARGV() get_argv(&argi, argc, argv) | 56 | #define GET_ARGV() get_argv(&argi, argc, argv) |
| 57 | 57 | ||
| 58 | d_char *html_timeline(snac *snac, char *list, int local); | ||
| 59 | |||
| 60 | int main(int argc, char *argv[]) | 58 | int main(int argc, char *argv[]) |
| 61 | { | 59 | { |
| 62 | char *cmd; | 60 | char *cmd; |
| @@ -259,6 +259,8 @@ xs_str *not_really_markdown(const char *content, xs_list **attach); | |||
| 259 | xs_str *sanitize(const char *content); | 259 | xs_str *sanitize(const char *content); |
| 260 | xs_str *encode_html(const char *str); | 260 | xs_str *encode_html(const char *str); |
| 261 | 261 | ||
| 262 | xs_str *html_timeline(snac *user, const xs_list *list, int local, int skip, int show, int show_more); | ||
| 263 | |||
| 262 | int html_get_handler(const xs_dict *req, const char *q_path, | 264 | int html_get_handler(const xs_dict *req, const char *q_path, |
| 263 | char **body, int *b_size, char **ctype, xs_str **etag); | 265 | char **body, int *b_size, char **ctype, xs_str **etag); |
| 264 | int html_post_handler(const xs_dict *req, const char *q_path, | 266 | int html_post_handler(const xs_dict *req, const char *q_path, |
| @@ -27,7 +27,9 @@ static const char *default_srv_config = "{" | |||
| 27 | "\"timeline_purge_days\": 120," | 27 | "\"timeline_purge_days\": 120," |
| 28 | "\"local_purge_days\": 0," | 28 | "\"local_purge_days\": 0," |
| 29 | "\"admin_email\": \"\"," | 29 | "\"admin_email\": \"\"," |
| 30 | "\"admin_account\": \"\"" | 30 | "\"admin_account\": \"\"," |
| 31 | "\"title\": \"\"," | ||
| 32 | "\"short_description\": \"\"" | ||
| 31 | "}"; | 33 | "}"; |
| 32 | 34 | ||
| 33 | static const char *default_css = | 35 | static const char *default_css = |