4 * This is the main transaction loop of the web service. It maintains a
5 * persistent session to the Citadel server, handling HTTP WebCit requests as
6 * they arrive and presenting a user interface.
16 #include <sys/types.h>
18 #include <sys/socket.h>
22 #include <netinet/in.h>
32 #include "webserver.h"
33 #include "mime_parser.h"
36 * String to unset the cookie.
37 * Any date "in the past" will work, so I chose my birthday, right down to
38 * the exact minute. :)
40 static char *unset = "; expires=28-May-1971 18:10:00 GMT";
42 void unescape_input(char *buf)
47 while ((isspace(buf[strlen(buf) - 1])) && (strlen(buf) > 0))
48 buf[strlen(buf) - 1] = 0;
50 for (a = 0; a < strlen(buf); ++a) {
58 sscanf(hex, "%02x", &b);
60 strcpy(&buf[a + 1], &buf[a + 3]);
67 void addurls(char *url)
75 while (strlen(up) > 0) {
77 /* locate the = sign */
78 safestrncpy(buf, up, sizeof buf);
80 for (a = 255; a >= 0; --a)
87 u = (struct urlcontent *) malloc(sizeof(struct urlcontent));
88 u->next = WC->urlstrings;
90 strcpy(u->url_key, buf);
92 /* now chop that part off */
93 for (a = 0; a <= b; ++a)
96 /* locate "&" and "?" delimiters */
99 for (a = 0; a < strlen(up); ++a) {
100 if ( (ptr[0] == '&') || (ptr[0] == '?') ) {
107 for (a = 0; a < b; ++a)
111 u->url_data = malloc(strlen(up) + 2);
112 strcpy(u->url_data, up);
114 unescape_input(u->url_data);
122 struct urlcontent *u;
124 while (WC->urlstrings != NULL) {
125 free(WC->urlstrings->url_data);
126 u = WC->urlstrings->next;
127 free(WC->urlstrings);
133 * Diagnostic function to display the contents of all variables
137 struct urlcontent *u;
139 for (u = WC->urlstrings; u != NULL; u = u->next) {
140 wprintf("%38s = %s\n", u->url_key, u->url_data);
144 char *bstr(char *key)
146 struct urlcontent *u;
148 for (u = WC->urlstrings; u != NULL; u = u->next) {
149 if (!strcasecmp(u->url_key, key))
150 return (u->url_data);
156 void wprintf(const char *format,...)
161 va_start(arg_ptr, format);
162 vsnprintf(wbuf, sizeof wbuf, format, arg_ptr);
165 client_write(wbuf, strlen(wbuf));
170 * wDumpContent() wraps up an HTTP session, closes tags, etc.
172 * print_standard_html_footer should be set to 0 to transmit only, 1 to
173 * append the main menu and closing tags, or 2 to
174 * append the closing tags only.
176 void wDumpContent(int print_standard_html_footer)
178 if (print_standard_html_footer) {
179 wprintf("</DIV>\n"); /* end of "text" div */
180 do_template("trailing");
183 /* If we've been saving it all up for one big output burst,
184 * go ahead and do that now.
191 * Copy a string, escaping characters which have meaning in HTML. If
192 * nbsp is nonzero, spaces are converted to non-breaking spaces.
194 void stresc(char *target, char *strbuf, int nbsp, int nolinebreaks)
199 for (a = 0; a < strlen(strbuf); ++a) {
200 if (strbuf[a] == '<')
201 strcat(target, "<");
202 else if (strbuf[a] == '>')
203 strcat(target, ">");
204 else if (strbuf[a] == '&')
205 strcat(target, "&");
206 else if (strbuf[a] == '\"')
207 strcat(target, """);
208 else if (strbuf[a] == '\'')
209 strcat(target, "'");
210 else if (strbuf[a] == LB)
212 else if (strbuf[a] == RB)
214 else if (strbuf[a] == QU)
215 strcat(target, "\"");
216 else if ((strbuf[a] == 32) && (nbsp == 1))
217 strcat(target, " ");
218 else if ((strbuf[a] == '\n') && (nolinebreaks))
219 strcat(target, ""); /* nothing */
220 else if ((strbuf[a] == '\r') && (nolinebreaks))
221 strcat(target, ""); /* nothing */
223 strncat(target, &strbuf[a], 1);
227 void escputs1(char *strbuf, int nbsp, int nolinebreaks)
231 if (strbuf == NULL) return;
232 buf = malloc( (3 * strlen(strbuf)) + SIZ );
233 stresc(buf, strbuf, nbsp, nolinebreaks);
238 void escputs(char *strbuf)
240 escputs1(strbuf, 0, 0);
244 * Escape a string for feeding out as a URL.
245 * Returns a pointer to a buffer that must be freed by the caller!
247 void urlesc(char *outbuf, char *strbuf)
250 char *ec = " #&;`'|*?-~<>^()[]{}$\\";
254 for (a = 0; a < strlen(strbuf); ++a) {
256 for (b = 0; b < strlen(ec); ++b) {
257 if (strbuf[a] == ec[b])
262 sprintf(&outbuf[b], "%%%02x", strbuf[a]);
264 sprintf(&outbuf[b], "%c", strbuf[a]);
268 void urlescputs(char *strbuf)
272 urlesc(outbuf, strbuf);
273 wprintf("%s", outbuf);
278 * Copy a string, escaping characters for JavaScript strings.
280 void jsesc(char *target, char *strbuf)
285 for (a = 0; a < strlen(strbuf); ++a) {
286 if (strbuf[a] == '<')
288 else if (strbuf[a] == '>')
290 else if (strbuf[a] == '\"')
291 strcat(target, """);
292 else if (strbuf[a] == '&')
293 strcat(target, "&;");
294 else if (strbuf[a] == '\'')
295 strcat(target, "\\'");
297 strncat(target, &strbuf[a], 1);
302 void jsescputs(char *strbuf)
306 jsesc(outbuf, strbuf);
307 wprintf("%s", outbuf);
311 * Copy a string, escaping characters for message text hold
313 void msgesc(char *target, char *strbuf)
318 for (a = 0; a < strlen(strbuf); ++a) {
319 if (strbuf[a] == '\'')
320 strcat(target, "\\'");
321 else if (strbuf[a] == '\n')
323 else if (strbuf[a] == '\r')
326 strncat(target, &strbuf[a], 1);
331 void msgescputs(char *strbuf) {
334 if (strbuf == NULL) return;
335 outbuf = malloc( (3 * strlen(strbuf)) + SIZ);
336 msgesc(outbuf, strbuf);
337 wprintf("%s", outbuf);
345 * Output all that important stuff that the browser will want to see
347 void output_headers( int do_httpheaders, /* 1 = output HTTP headers */
348 int do_htmlhead, /* 1 = output HTML <head> section and <body> opener */
350 int do_room_banner, /* 0=no, 1=yes, */
351 /* 2 = I'm going to embed my own, so don't open the */
352 /* <div id="content"> either. */
354 int unset_cookies, /* 1 = session is terminating, so unset the cookies */
355 int refresh30, /* 1 = automatically refresh page every 30 seconds */
356 int suppress_check, /* 1 = suppress check for instant messages */
357 int cache /* 1 = allow browser to cache this page */
362 wprintf("HTTP/1.0 200 OK\n");
363 httpdate(httpnow, time(NULL));
365 if (do_httpheaders) {
366 wprintf("Content-type: text/html\r\n"
368 "Connection: close\r\n",
369 SERVER, serv_info.serv_software
374 wprintf("Pragma: public\r\n"
375 "Cache-Control: max-age=3600, must-revalidate\r\n"
376 "Last-modified: %s\r\n",
381 wprintf("Pragma: no-cache\r\n"
382 "Cache-Control: no-store\r\n"
386 stuff_to_cookie(cookie, WC->wc_session, WC->wc_username,
387 WC->wc_password, WC->wc_roomname);
390 wprintf("Set-cookie: webcit=%s; path=/\r\n", unset);
392 wprintf("Set-cookie: webcit=%s; path=/\r\n", cookie);
393 if (server_cookie != NULL) {
394 wprintf("%s\n", server_cookie);
403 svprintf("REFRESHTAG", WCS_STRING, "%s",
404 "<meta http-equiv=\"refresh\" content=\"30\" />\n");
407 svprintf("REFRESHTAG", WCS_STRING, "%s",
408 "<meta http-equiv=\"refresh\" content=\"500363689;\" />\n");
417 if (WC->HaveInstantMessages) {
418 wprintf("<div id=\"page_popup\">\n");
422 if ( (WC->logged_in) && (!unset_cookies) ) {
423 wprintf("<div id=\"iconbar\">");
427 if (do_room_banner == 1) {
428 wprintf("<div id=\"banner\">\n");
429 embed_room_banner(NULL, navbar_default);
434 if (do_room_banner == 1) {
435 wprintf("<div id=\"content\">\n");
437 if (strlen(WC->ImportantMessage) > 0) {
438 wprintf("<div id=\"fix_scrollbar_bug\">\n");
439 do_template("beginbox_nt");
440 wprintf("<SPAN CLASS=\"errormsg\">"
441 "%s</SPAN><br />\n", WC->ImportantMessage);
442 do_template("endbox");
444 strcpy(WC->ImportantMessage, "");
452 * Generic function to do an HTTP redirect. Easy and fun.
454 void http_redirect(char *whichpage) {
455 wprintf("HTTP/1.0 302 Moved Temporarily\n");
456 wprintf("Location: %s\r\n", whichpage);
457 wprintf("URI: %s\r\n", whichpage);
458 wprintf("Content-type: text/html\r\n\r\n");
459 wprintf("<html><body>\n");
460 wprintf("you really want to be <A HREF=\"%s\">here</A> now\n",
462 wprintf("</body></html>\n");
467 void check_for_instant_messages()
473 if (buf[3] == '*') WC->HaveInstantMessages = 1;
480 * Output a piece of content to the web browser
482 void http_transmit_thing(char *thing, size_t length, char *content_type,
485 output_headers(0, 0, 0, 0, 0, 0, is_static);
487 wprintf("Content-type: %s\r\n"
489 "Connection: close\r\n",
494 /* If we can send the data out compressed, please do so. */
496 char *compressed_data = NULL;
497 uLongf compressed_len;
499 compressed_len = (uLongf) ((length * 101) / 100) + 100;
500 compressed_data = malloc(compressed_len);
502 if (compress_gzip((Bytef *) compressed_data,
505 (uLongf) length, Z_BEST_SPEED) == Z_OK) {
506 wprintf("Content-encoding: gzip\r\n"
507 "Content-length: %ld\r\n"
509 (long) compressed_len
511 client_write(compressed_data, (size_t)compressed_len);
512 free(compressed_data);
518 /* No compression ... just send it out as-is */
519 wprintf("Content-length: %ld\r\n"
523 client_write(thing, (size_t)length);
529 void output_static(char *what)
536 char content_type[SIZ];
538 sprintf(buf, "static/%s", what);
539 fp = fopen(buf, "rb");
541 wprintf("HTTP/1.0 404 %s\n", strerror(errno));
542 wprintf("Content-Type: text/plain\r\n");
544 wprintf("Cannot open %s: %s\n", what, strerror(errno));
546 if (!strncasecmp(&what[strlen(what) - 4], ".gif", 4))
547 strcpy(content_type, "image/gif");
548 else if (!strncasecmp(&what[strlen(what) - 4], ".txt", 4))
549 strcpy(content_type, "text/plain");
550 else if (!strncasecmp(&what[strlen(what) - 4], ".css", 4))
551 strcpy(content_type, "text/css");
552 else if (!strncasecmp(&what[strlen(what) - 4], ".jpg", 4))
553 strcpy(content_type, "image/jpeg");
554 else if (!strncasecmp(&what[strlen(what) - 4], ".png", 4))
555 strcpy(content_type, "image/png");
556 else if (!strncasecmp(&what[strlen(what) - 4], ".ico", 4))
557 strcpy(content_type, "image/x-icon");
558 else if (!strncasecmp(&what[strlen(what) - 5], ".html", 5))
559 strcpy(content_type, "text/html");
560 else if (!strncasecmp(&what[strlen(what) - 4], ".htm", 4))
561 strcpy(content_type, "text/html");
562 else if (!strncasecmp(&what[strlen(what) - 4], ".wml", 4))
563 strcpy(content_type, "text/vnd.wap.wml");
564 else if (!strncasecmp(&what[strlen(what) - 5], ".wmls", 5))
565 strcpy(content_type, "text/vnd.wap.wmlscript");
566 else if (!strncasecmp(&what[strlen(what) - 5], ".wmlc", 5))
567 strcpy(content_type, "application/vnd.wap.wmlc");
568 else if (!strncasecmp(&what[strlen(what) - 6], ".wmlsc", 6))
569 strcpy(content_type, "application/vnd.wap.wmlscriptc");
570 else if (!strncasecmp(&what[strlen(what) - 5], ".wbmp", 5))
571 strcpy(content_type, "image/vnd.wap.wbmp");
572 else if (!strncasecmp(&what[strlen(what) - 3], ".js", 3))
573 strcpy(content_type, "text/javascript");
575 strcpy(content_type, "application/octet-stream");
577 fstat(fileno(fp), &statbuf);
578 bytes = statbuf.st_size;
579 /* lprintf(3, "Static: %s, (%s; %ld bytes)\r\n",
580 what, content_type, bytes); */
581 bigbuffer = malloc(bytes + 2);
582 fread(bigbuffer, bytes, 1, fp);
585 http_transmit_thing(bigbuffer, (size_t)bytes, content_type, 1);
588 if (!strcasecmp(bstr("force_close_session"), "yes")) {
589 end_webcit_session();
595 * When the browser requests an image file from the Citadel server,
596 * this function is called to transmit it.
601 char *xferbuf = NULL;
604 serv_printf("OIMG %s|%s", bstr("name"), bstr("parm"));
607 bytes = extract_long(&buf[4], 0);
608 xferbuf = malloc(bytes + 2);
610 /* Read it from the server */
611 read_server_binary(xferbuf, bytes);
615 /* Write it to the browser */
616 http_transmit_thing(xferbuf, (size_t)bytes, "image/gif", 0);
621 /* Instead of an ugly 404, send a 1x1 transparent GIF
622 * when there's no such image on the server.
624 output_static("blank.gif");
627 wprintf("HTTP/1.0 404 %s\n", &buf[4]);
628 output_headers(0, 0, 0, 0, 0, 0, 0);
629 wprintf("Content-Type: text/plain\r\n"
631 "Error retrieving image: %s\n",
644 void output_mimepart()
648 char content_type[SIZ];
649 char *content = NULL;
651 serv_printf("OPNA %s|%s", bstr("msgnum"), bstr("partnum"));
654 bytes = extract_long(&buf[4], 0);
655 content = malloc(bytes + 2);
656 extract(content_type, &buf[4], 3);
657 output_headers(0, 0, 0, 0, 0, 0, 0);
658 read_server_binary(content, bytes);
661 http_transmit_thing(content, bytes, content_type, 0);
664 wprintf("HTTP/1.0 404 %s\n", &buf[4]);
665 output_headers(0, 0, 0, 0, 0, 0, 0);
666 wprintf("Content-Type: text/plain\r\n");
668 wprintf("Error retrieving part: %s\n", &buf[4]);
676 char *load_mimepart(long msgnum, char *partnum)
680 char content_type[SIZ];
683 serv_printf("OPNA %ld|%s", msgnum, partnum);
686 bytes = extract_long(&buf[4], 0);
687 extract(content_type, &buf[4], 3);
689 content = malloc(bytes + 2);
690 read_server_binary(content, bytes);
694 content[bytes] = 0; /* null terminate for good measure */
705 * Convenience functions to display a page containing only a string
707 void convenience_page(char *titlebarcolor, char *titlebarmsg, char *messagetext)
709 wprintf("HTTP/1.0 200 OK\n");
710 output_headers(1, 1, 2, 0, 0, 0, 0);
711 wprintf("<div id=\"banner\">\n");
712 wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#%s\"><TR><TD>", titlebarcolor);
713 wprintf("<SPAN CLASS=\"titlebar\">%s</SPAN>\n", titlebarmsg);
714 wprintf("</TD></TR></TABLE>\n");
715 wprintf("</div>\n<div id=\"content\">\n");
716 escputs(messagetext);
724 * Display a blank page.
726 void blank_page(void) {
727 output_headers(1, 1, 0, 0, 1, 0, 0);
733 * A template has been requested
735 void url_do_template(void) {
736 do_template(bstr("template"));
742 * Offer to make any page the user's "start page."
744 void offer_start_page(void) {
745 wprintf("<A HREF=\"/change_start_page?startpage=");
746 urlescputs(WC->this_page);
748 "<FONT SIZE=-2 COLOR=\"#AAAAAA\">Make this my start page</FONT>"
755 * Change the user's start page
757 void change_start_page(void) {
759 if (bstr("startpage") == NULL) {
760 strcpy(WC->ImportantMessage,
761 "startpage set to null");
766 set_preference("startpage", bstr("startpage"));
768 output_headers(1, 1, 0, 0, 0, 0, 0);
769 do_template("newstartpage");
776 void display_success(char *successmessage)
778 convenience_page("007700", "OK", successmessage);
783 void extract_action(char *actbuf, char *cmdbuf)
787 strcpy(actbuf, cmdbuf);
790 * First strip out the http method
792 remove_token(actbuf, 0, ' ');
793 if (actbuf[0] == ' ') strcpy(actbuf, &actbuf[1]);
794 if (actbuf[0] == '/') strcpy(actbuf, &actbuf[1]);
797 * Now kill invalid (for webcit) characters
799 for (i = 0; i < strlen(actbuf); ++i) {
800 if (actbuf[i] == ' ') {
804 if (actbuf[i] == '/') {
808 if (actbuf[i] == '?') {
812 if (actbuf[i] == '&') {
820 void upload_handler(char *name, char *filename, char *partnum, char *disp,
821 void *content, char *cbtype, size_t length,
822 char *encoding, void *userdata)
824 struct urlcontent *u;
827 if ( (length > 0) && (strlen(cbtype) == 0) ) {
828 u = (struct urlcontent *) malloc(sizeof(struct urlcontent));
829 u->next = WC->urlstrings;
831 safestrncpy(u->url_key, name, sizeof(u->url_key));
832 u->url_data = malloc(length + 1);
833 memcpy(u->url_data, content, length);
834 u->url_data[length] = 0;
838 if ( (length > 0) && (strlen(cbtype) > 0) ) {
839 WC->upload = malloc(length);
840 if (WC->upload != NULL) {
841 WC->upload_length = length;
842 safestrncpy(WC->upload_filename, filename,
843 sizeof(WC->upload_filename));
844 safestrncpy(WC->upload_content_type, cbtype,
845 sizeof(WC->upload_content_type));
846 memcpy(WC->upload, content, length);
849 lprintf(3, "malloc() failed: %s\n", strerror(errno));
859 * Entry point for WebCit transaction
861 void session_loop(struct httprequest *req)
868 int ContentLength = 0;
870 char ContentType[512];
871 char *content = NULL;
872 char *content_end = NULL;
873 struct httprequest *hptr;
874 char browser_host[SIZ];
875 char user_agent[SIZ];
878 /* We stuff these with the values coming from the client cookies,
879 * so we can use them to reconnect a timed out session if we have to.
881 char c_username[SIZ];
882 char c_password[SIZ];
883 char c_roomname[SIZ];
884 char c_httpauth_string[SIZ];
885 char c_httpauth_user[SIZ];
886 char c_httpauth_pass[SIZ];
889 strcpy(c_username, "");
890 strcpy(c_password, "");
891 strcpy(c_roomname, "");
892 strcpy(c_httpauth_string, "");
893 strcpy(c_httpauth_user, DEFAULT_HTTPAUTH_USER);
894 strcpy(c_httpauth_pass, DEFAULT_HTTPAUTH_PASS);
896 WC->upload_length = 0;
903 if (hptr == NULL) return;
905 strcpy(cmd, hptr->line);
907 extract_token(method, cmd, 0, ' ');
908 extract_action(action, cmd);
910 while (hptr != NULL) {
911 strcpy(buf, hptr->line);
914 if (!strncasecmp(buf, "Cookie: webcit=", 15)) {
915 safestrncpy(cookie, &buf[15], sizeof cookie);
916 cookie_to_stuff(cookie, NULL,
917 c_username, c_password, c_roomname);
919 else if (!strncasecmp(buf, "Authorization: Basic ", 21)) {
920 CtdlDecodeBase64(c_httpauth_string, &buf[21], strlen(&buf[21]));
921 extract_token(c_httpauth_user, c_httpauth_string, 0, ':');
922 extract_token(c_httpauth_pass, c_httpauth_string, 1, ':');
924 else if (!strncasecmp(buf, "Content-length: ", 16)) {
925 ContentLength = atoi(&buf[16]);
927 else if (!strncasecmp(buf, "Content-type: ", 14)) {
928 safestrncpy(ContentType, &buf[14], sizeof ContentType);
930 else if (!strncasecmp(buf, "User-agent: ", 12)) {
931 safestrncpy(user_agent, &buf[12], sizeof user_agent);
933 else if (!strncasecmp(buf, "Host: ", 6)) {
934 safestrncpy(WC->http_host, &buf[6], sizeof WC->http_host);
936 /* Only WAP gateways explicitly name this content-type */
937 else if (strstr(buf, "text/vnd.wap.wml")) {
942 if (ContentLength > 0) {
943 content = malloc(ContentLength + SIZ);
944 memset(content, 0, ContentLength + SIZ);
945 sprintf(content, "Content-type: %s\n"
946 "Content-length: %d\n\n",
947 ContentType, ContentLength);
948 body_start = strlen(content);
950 /* Be daring and read it all at once. */
951 client_read(WC->http_sock, &content[BytesRead+body_start],
954 if (!strncasecmp(ContentType,
955 "application/x-www-form-urlencoded", 33)) {
956 addurls(&content[body_start]);
957 } else if (!strncasecmp(ContentType, "multipart", 9)) {
958 content_end = content + ContentLength + body_start;
959 mime_parser(content, content_end, *upload_handler,
960 NULL, NULL, NULL, 0);
966 /* make a note of where we are in case the user wants to save it */
967 safestrncpy(WC->this_page, cmd, sizeof(WC->this_page));
968 remove_token(WC->this_page, 2, ' ');
969 remove_token(WC->this_page, 0, ' ');
971 /* If there are variables in the URL, we must grab them now */
972 for (a = 0; a < strlen(cmd); ++a) {
973 if ((cmd[a] == '?') || (cmd[a] == '&')) {
974 for (b = a; b < strlen(cmd); ++b)
977 addurls(&cmd[a + 1]);
982 /* Static content can be sent without connecting to Citadel. */
983 if (!strcasecmp(action, "static")) {
984 strcpy(buf, &cmd[12]);
985 for (a = 0; a < strlen(buf); ++a)
989 goto SKIP_ALL_THIS_CRAP; /* Don't try to connect */
993 * If we're not connected to a Citadel server, try to hook up the
996 if (!WC->connected) {
997 if (!strcasecmp(ctdlhost, "uds")) {
998 /* unix domain socket */
999 sprintf(buf, "%s/citadel.socket", ctdlport);
1000 WC->serv_sock = uds_connectsock(buf);
1004 WC->serv_sock = tcp_connectsock(ctdlhost, ctdlport);
1007 if (WC->serv_sock < 0) {
1009 goto SKIP_ALL_THIS_CRAP;
1013 serv_gets(buf); /* get the server welcome message */
1014 locate_host(browser_host, WC->http_sock);
1015 get_serv_info(browser_host, user_agent);
1016 if (serv_info.serv_rev_level < MINIMUM_CIT_VERSION) {
1017 wprintf("You are connected to a Citadel "
1018 "server running Citadel %d.%02d;\nin "
1019 "order to run this version of WebCit "
1020 "you must also have Citadel %d.%02d or"
1022 serv_info.serv_rev_level / 100,
1023 serv_info.serv_rev_level % 100,
1024 MINIMUM_CIT_VERSION / 100,
1025 MINIMUM_CIT_VERSION % 100
1027 end_webcit_session();
1028 goto SKIP_ALL_THIS_CRAP;
1034 * Functions which can be performed without logging in
1036 if (!strcasecmp(action, "listsub")) {
1038 goto SKIP_ALL_THIS_CRAP;
1040 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
1041 if (!strcasecmp(action, "freebusy")) {
1043 goto SKIP_ALL_THIS_CRAP;
1048 * If we're not logged in, but we have HTTP Authentication data,
1049 * try logging in to Citadel using that.
1051 if ((!WC->logged_in)
1052 && (strlen(c_httpauth_user) > 0)
1053 && (strlen(c_httpauth_pass) > 0)) {
1054 serv_printf("USER %s", c_httpauth_user);
1056 if (buf[0] == '3') {
1057 serv_printf("PASS %s", c_httpauth_pass);
1059 if (buf[0] == '2') {
1060 become_logged_in(c_httpauth_user,
1061 c_httpauth_pass, buf);
1062 strcpy(WC->httpauth_user, c_httpauth_user);
1063 strcpy(WC->httpauth_pass, c_httpauth_pass);
1069 * The GroupDAV stuff relies on HTTP authentication instead of
1070 * our session's authentication.
1072 if (!strncasecmp(action, "groupdav", 8)) {
1073 groupdav_main(req, ContentType, /* do GroupDAV methods */
1074 ContentLength, content+body_start);
1075 if (!WC->logged_in) {
1076 WC->killthis = 1; /* If not logged in, don't */
1077 } /* keep the session active */
1078 goto SKIP_ALL_THIS_CRAP;
1083 * If this isn't a GroupDAV session, it's an ordinary browser
1084 * connecting to the user interface. Only allow GET and POST
1087 if ((strcasecmp(method, "GET")) && (strcasecmp(method, "POST"))) {
1088 wprintf("HTTP/1.1 405 Method Not Allowed\r\n");
1089 groupdav_common_headers();
1090 wprintf("Content-Length: 0\r\n\r\n");
1091 goto SKIP_ALL_THIS_CRAP;
1095 * If we're not logged in, but we have username and password cookies
1096 * supplied by the browser, try using them to log in.
1098 if ((!WC->logged_in)
1099 && (strlen(c_username) > 0)
1100 && (strlen(c_password) > 0)) {
1101 serv_printf("USER %s", c_username);
1103 if (buf[0] == '3') {
1104 serv_printf("PASS %s", c_password);
1106 if (buf[0] == '2') {
1107 become_logged_in(c_username, c_password, buf);
1112 * If we don't have a current room, but a cookie specifying the
1113 * current room is supplied, make an effort to go there.
1115 if ((strlen(WC->wc_roomname) == 0) && (strlen(c_roomname) > 0)) {
1116 serv_printf("GOTO %s", c_roomname);
1118 if (buf[0] == '2') {
1119 strcpy(WC->wc_roomname, c_roomname);
1124 * If there are instant messages waiting, retrieve them for display.
1126 check_for_instant_messages();
1128 if (!strcasecmp(action, "image")) {
1132 * All functions handled below this point ... make sure we log in
1133 * before doing anything else!
1135 } else if ((!WC->logged_in) && (!strcasecmp(action, "login"))) {
1137 } else if (!WC->logged_in) {
1138 display_login(NULL);
1142 * Various commands...
1145 else if (!strcasecmp(action, "do_welcome")) {
1147 } else if (!strcasecmp(action, "blank")) {
1149 } else if (!strcasecmp(action, "do_template")) {
1151 } else if (!strcasecmp(action, "display_aide_menu")) {
1152 display_aide_menu();
1153 } else if (!strcasecmp(action, "display_main_menu")) {
1154 display_main_menu();
1155 } else if (!strcasecmp(action, "whobbs")) {
1157 } else if (!strcasecmp(action, "knrooms")) {
1159 } else if (!strcasecmp(action, "gotonext")) {
1162 } else if (!strcasecmp(action, "skip")) {
1164 } else if (!strcasecmp(action, "ungoto")) {
1166 } else if (!strcasecmp(action, "dotgoto")) {
1168 smart_goto(bstr("room"));
1169 } else if (!strcasecmp(action, "dotskip")) {
1170 smart_goto(bstr("room"));
1171 } else if (!strcasecmp(action, "termquit")) {
1173 } else if (!strcasecmp(action, "readnew")) {
1174 readloop("readnew");
1175 } else if (!strcasecmp(action, "readold")) {
1176 readloop("readold");
1177 } else if (!strcasecmp(action, "readfwd")) {
1178 readloop("readfwd");
1179 } else if (!strcasecmp(action, "headers")) {
1180 readloop("headers");
1181 } else if (!strcasecmp(action, "display_enter")) {
1183 } else if (!strcasecmp(action, "post")) {
1185 } else if (!strcasecmp(action, "move_msg")) {
1187 } else if (!strcasecmp(action, "delete_msg")) {
1189 } else if (!strcasecmp(action, "userlist")) {
1191 } else if (!strcasecmp(action, "showuser")) {
1193 } else if (!strcasecmp(action, "display_page")) {
1195 } else if (!strcasecmp(action, "page_user")) {
1197 } else if (!strcasecmp(action, "chat")) {
1199 } else if (!strcasecmp(action, "display_private")) {
1200 display_private("", 0);
1201 } else if (!strcasecmp(action, "goto_private")) {
1203 } else if (!strcasecmp(action, "zapped_list")) {
1205 } else if (!strcasecmp(action, "display_zap")) {
1207 } else if (!strcasecmp(action, "zap")) {
1209 } else if (!strcasecmp(action, "display_entroom")) {
1211 } else if (!strcasecmp(action, "entroom")) {
1213 } else if (!strcasecmp(action, "display_whok")) {
1215 } else if (!strcasecmp(action, "do_invt_kick")) {
1217 } else if (!strcasecmp(action, "display_editroom")) {
1219 } else if (!strcasecmp(action, "netedit")) {
1221 } else if (!strcasecmp(action, "editroom")) {
1223 } else if (!strcasecmp(action, "display_editinfo")) {
1224 display_edit("Room info", "EINF 0", "RINF", "/editinfo", 1);
1225 } else if (!strcasecmp(action, "editinfo")) {
1226 save_edit("Room info", "EINF 1", 1);
1227 } else if (!strcasecmp(action, "display_editbio")) {
1228 sprintf(buf, "RBIO %s", WC->wc_username);
1229 display_edit("Your bio", "NOOP", buf, "editbio", 3);
1230 } else if (!strcasecmp(action, "editbio")) {
1231 save_edit("Your bio", "EBIO", 0);
1232 } else if (!strcasecmp(action, "confirm_move_msg")) {
1234 } else if (!strcasecmp(action, "delete_room")) {
1236 } else if (!strcasecmp(action, "validate")) {
1238 } else if (!strcasecmp(action, "display_editpic")) {
1239 display_graphics_upload("your photo",
1242 } else if (!strcasecmp(action, "editpic")) {
1243 do_graphics_upload("UIMG 1|_userpic_");
1244 } else if (!strcasecmp(action, "display_editroompic")) {
1245 display_graphics_upload("the graphic for this room",
1248 } else if (!strcasecmp(action, "editroompic")) {
1249 do_graphics_upload("UIMG 1|_roompic_");
1250 } else if (!strcasecmp(action, "delete_floor")) {
1252 } else if (!strcasecmp(action, "rename_floor")) {
1254 } else if (!strcasecmp(action, "create_floor")) {
1256 } else if (!strcasecmp(action, "display_editfloorpic")) {
1257 sprintf(buf, "UIMG 0|_floorpic_|%s",
1258 bstr("which_floor"));
1259 display_graphics_upload("the graphic for this floor",
1262 } else if (!strcasecmp(action, "editfloorpic")) {
1263 sprintf(buf, "UIMG 1|_floorpic_|%s",
1264 bstr("which_floor"));
1265 do_graphics_upload(buf);
1266 } else if (!strcasecmp(action, "display_reg")) {
1268 } else if (!strcasecmp(action, "display_changepw")) {
1270 } else if (!strcasecmp(action, "changepw")) {
1272 } else if (!strcasecmp(action, "display_edit_node")) {
1273 display_edit_node();
1274 } else if (!strcasecmp(action, "edit_node")) {
1276 } else if (!strcasecmp(action, "display_netconf")) {
1278 } else if (!strcasecmp(action, "display_confirm_delete_node")) {
1279 display_confirm_delete_node();
1280 } else if (!strcasecmp(action, "delete_node")) {
1282 } else if (!strcasecmp(action, "display_add_node")) {
1284 } else if (!strcasecmp(action, "add_node")) {
1286 } else if (!strcasecmp(action, "terminate_session")) {
1288 terminate_session();
1289 } else if (!strcasecmp(action, "edit_me")) {
1291 } else if (!strcasecmp(action, "display_siteconfig")) {
1292 display_siteconfig();
1293 } else if (!strcasecmp(action, "chat_recv")) {
1295 } else if (!strcasecmp(action, "chat_send")) {
1297 } else if (!strcasecmp(action, "siteconfig")) {
1299 } else if (!strcasecmp(action, "display_generic")) {
1301 } else if (!strcasecmp(action, "do_generic")) {
1303 } else if (!strcasecmp(action, "display_menubar")) {
1305 } else if (!strcasecmp(action, "output_mimepart")) {
1307 } else if (!strcasecmp(action, "edit_vcard")) {
1309 } else if (!strcasecmp(action, "submit_vcard")) {
1311 } else if (!strcasecmp(action, "select_user_to_edit")) {
1312 select_user_to_edit(NULL, NULL);
1313 } else if (!strcasecmp(action, "display_edituser")) {
1314 display_edituser(NULL, 0);
1315 } else if (!strcasecmp(action, "edituser")) {
1317 } else if (!strcasecmp(action, "create_user")) {
1319 } else if (!strcasecmp(action, "changeview")) {
1321 } else if (!strcasecmp(action, "do_stuff_to_msgs")) {
1323 } else if (!strcasecmp(action, "change_start_page")) {
1324 change_start_page();
1325 } else if (!strcasecmp(action, "display_floorconfig")) {
1326 display_floorconfig(NULL);
1327 } else if (!strcasecmp(action, "toggle_self_service")) {
1328 toggle_self_service();
1329 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
1330 } else if (!strcasecmp(action, "display_edit_task")) {
1331 display_edit_task();
1332 } else if (!strcasecmp(action, "save_task")) {
1334 } else if (!strcasecmp(action, "display_edit_event")) {
1335 display_edit_event();
1336 } else if (!strcasecmp(action, "save_event")) {
1338 } else if (!strcasecmp(action, "respond_to_request")) {
1339 respond_to_request();
1340 } else if (!strcasecmp(action, "handle_rsvp")) {
1343 } else if (!strcasecmp(action, "summary")) {
1345 } else if (!strcasecmp(action, "iconbar")) {
1347 } else if (!strcasecmp(action, "display_customize_iconbar")) {
1348 display_customize_iconbar();
1349 } else if (!strcasecmp(action, "commit_iconbar")) {
1351 } else if (!strcasecmp(action, "set_room_policy")) {
1353 } else if (!strcasecmp(action, "display_inetconf")) {
1355 } else if (!strcasecmp(action, "save_inetconf")) {
1357 } else if (!strcasecmp(action, "setup_wizard")) {
1359 } else if (!strcasecmp(action, "diagnostics")) {
1360 output_headers(1, 1, 1, 0, 0, 0, 0);
1362 wprintf("You're in session %d<hr />\n", WC->wc_session);
1363 wprintf("Command: <br /><PRE>\n");
1365 wprintf("</PRE><hr />\n");
1366 wprintf("Variables: <br /><PRE>\n");
1368 wprintf("</PRE><hr />\n");
1371 /* When all else fais, display the main menu. */
1373 display_main_menu();
1378 if (content != NULL) {
1383 if (WC->upload_length > 0) {
1385 WC->upload_length = 0;