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"
367 "Server: %s / %s\n", SERVER, serv_info.serv_software
370 wprintf("Connection: close\r\n"
371 "Pragma: no-cache\r\n"
372 "Cache-Control: no-store\r\n"
376 stuff_to_cookie(cookie, WC->wc_session, WC->wc_username,
377 WC->wc_password, WC->wc_roomname);
380 wprintf("Set-cookie: webcit=%s; path=/\r\n", unset);
382 wprintf("Set-cookie: webcit=%s; path=/\r\n", cookie);
383 if (server_cookie != NULL) {
384 wprintf("%s\n", server_cookie);
393 svprintf("REFRESHTAG", WCS_STRING, "%s",
394 "<meta http-equiv=\"refresh\" content=\"30\" />\n");
397 svprintf("REFRESHTAG", WCS_STRING, "%s",
398 "<meta http-equiv=\"refresh\" content=\"500363689;\" />\n");
407 if (WC->HaveInstantMessages) {
408 wprintf("<div id=\"page_popup\">\n");
412 if ( (WC->logged_in) && (!unset_cookies) ) {
413 wprintf("<div id=\"iconbar\">");
417 if (do_room_banner == 1) {
418 wprintf("<div id=\"banner\">\n");
419 embed_room_banner(NULL, navbar_default);
424 if (do_room_banner == 1) {
425 wprintf("<div id=\"content\">\n");
427 if (strlen(WC->ImportantMessage) > 0) {
428 do_template("beginbox_nt");
429 wprintf("<SPAN CLASS=\"errormsg\">"
430 "%s</SPAN><br />\n", WC->ImportantMessage);
431 do_template("endbox");
432 strcpy(WC->ImportantMessage, "");
440 * Generic function to do an HTTP redirect. Easy and fun.
442 void http_redirect(char *whichpage) {
443 wprintf("HTTP/1.0 302 Moved Temporarily\n");
444 wprintf("Location: %s\r\n", whichpage);
445 wprintf("URI: %s\r\n", whichpage);
446 wprintf("Content-type: text/html\r\n\r\n");
447 wprintf("<html><body>\n");
448 wprintf("you really want to be <A HREF=\"%s\">here</A> now\n",
450 wprintf("</body></html>\n");
455 void check_for_instant_messages()
461 if (buf[3] == '*') WC->HaveInstantMessages = 1;
468 * Output a piece of content to the web browser
470 void http_transmit_thing(char *thing, size_t length, char *content_type,
473 output_headers(0, 0, 0, 0, 0, 0, 1);
476 output_headers(0, 0, 0, 0, 0, 0, 0);
478 wprintf("Content-type: %s\r\n"
479 "Content-length: %ld\r\n"
481 "Connection: close\r\n"
487 client_write(thing, (size_t)length);
493 void output_static(char *what)
500 char content_type[SIZ];
502 sprintf(buf, "static/%s", what);
503 fp = fopen(buf, "rb");
505 wprintf("HTTP/1.0 404 %s\n", strerror(errno));
506 wprintf("Content-Type: text/plain\r\n");
508 wprintf("Cannot open %s: %s\n", what, strerror(errno));
510 if (!strncasecmp(&what[strlen(what) - 4], ".gif", 4))
511 strcpy(content_type, "image/gif");
512 else if (!strncasecmp(&what[strlen(what) - 4], ".txt", 4))
513 strcpy(content_type, "text/plain");
514 else if (!strncasecmp(&what[strlen(what) - 4], ".css", 4))
515 strcpy(content_type, "text/css");
516 else if (!strncasecmp(&what[strlen(what) - 4], ".jpg", 4))
517 strcpy(content_type, "image/jpeg");
518 else if (!strncasecmp(&what[strlen(what) - 4], ".png", 4))
519 strcpy(content_type, "image/png");
520 else if (!strncasecmp(&what[strlen(what) - 4], ".ico", 4))
521 strcpy(content_type, "image/x-icon");
522 else if (!strncasecmp(&what[strlen(what) - 5], ".html", 5))
523 strcpy(content_type, "text/html");
524 else if (!strncasecmp(&what[strlen(what) - 4], ".htm", 4))
525 strcpy(content_type, "text/html");
526 else if (!strncasecmp(&what[strlen(what) - 4], ".wml", 4))
527 strcpy(content_type, "text/vnd.wap.wml");
528 else if (!strncasecmp(&what[strlen(what) - 5], ".wmls", 5))
529 strcpy(content_type, "text/vnd.wap.wmlscript");
530 else if (!strncasecmp(&what[strlen(what) - 5], ".wmlc", 5))
531 strcpy(content_type, "application/vnd.wap.wmlc");
532 else if (!strncasecmp(&what[strlen(what) - 6], ".wmlsc", 6))
533 strcpy(content_type, "application/vnd.wap.wmlscriptc");
534 else if (!strncasecmp(&what[strlen(what) - 5], ".wbmp", 5))
535 strcpy(content_type, "image/vnd.wap.wbmp");
536 else if (!strncasecmp(&what[strlen(what) - 3], ".js", 3))
537 strcpy(content_type, "text/javascript");
539 strcpy(content_type, "application/octet-stream");
541 fstat(fileno(fp), &statbuf);
542 bytes = statbuf.st_size;
543 /* lprintf(3, "Static: %s, (%s; %ld bytes)\r\n",
544 what, content_type, bytes); */
545 bigbuffer = malloc(bytes + 2);
546 fread(bigbuffer, bytes, 1, fp);
549 http_transmit_thing(bigbuffer, (size_t)bytes, content_type, 1);
552 if (!strcasecmp(bstr("force_close_session"), "yes")) {
553 end_webcit_session();
559 * When the browser requests an image file from the Citadel server,
560 * this function is called to transmit it.
565 char *xferbuf = NULL;
568 serv_printf("OIMG %s|%s", bstr("name"), bstr("parm"));
571 bytes = extract_long(&buf[4], 0);
572 xferbuf = malloc(bytes + 2);
574 /* Read it from the server */
575 read_server_binary(xferbuf, bytes);
579 /* Write it to the browser */
580 http_transmit_thing(xferbuf, (size_t)bytes, "image/gif", 0);
585 /* Instead of an ugly 404, send a 1x1 transparent GIF
586 * when there's no such image on the server.
588 output_static("blank.gif");
591 wprintf("HTTP/1.0 404 %s\n", &buf[4]);
592 output_headers(0, 0, 0, 0, 0, 0, 0);
593 wprintf("Content-Type: text/plain\r\n"
595 "Error retrieving image: %s\n",
608 void output_mimepart()
612 char content_type[SIZ];
613 char *content = NULL;
615 serv_printf("OPNA %s|%s", bstr("msgnum"), bstr("partnum"));
618 bytes = extract_long(&buf[4], 0);
619 content = malloc(bytes + 2);
620 extract(content_type, &buf[4], 3);
621 output_headers(0, 0, 0, 0, 0, 0, 0);
622 read_server_binary(content, bytes);
625 http_transmit_thing(content, bytes, content_type, 0);
628 wprintf("HTTP/1.0 404 %s\n", &buf[4]);
629 output_headers(0, 0, 0, 0, 0, 0, 0);
630 wprintf("Content-Type: text/plain\r\n");
632 wprintf("Error retrieving part: %s\n", &buf[4]);
640 char *load_mimepart(long msgnum, char *partnum)
644 char content_type[SIZ];
647 serv_printf("OPNA %ld|%s", msgnum, partnum);
650 bytes = extract_long(&buf[4], 0);
651 extract(content_type, &buf[4], 3);
653 content = malloc(bytes + 2);
654 read_server_binary(content, bytes);
658 content[bytes] = 0; /* null terminate for good measure */
669 * Convenience functions to display a page containing only a string
671 void convenience_page(char *titlebarcolor, char *titlebarmsg, char *messagetext)
673 wprintf("HTTP/1.0 200 OK\n");
674 output_headers(1, 1, 2, 0, 0, 0, 0);
675 wprintf("<div id=\"banner\">\n");
676 wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#%s\"><TR><TD>", titlebarcolor);
677 wprintf("<SPAN CLASS=\"titlebar\">%s</SPAN>\n", titlebarmsg);
678 wprintf("</TD></TR></TABLE>\n");
679 wprintf("</div>\n<div id=\"content\">\n");
680 escputs(messagetext);
688 * Display a blank page.
690 void blank_page(void) {
691 output_headers(1, 1, 0, 0, 1, 0, 0);
697 * A template has been requested
699 void url_do_template(void) {
700 do_template(bstr("template"));
706 * Offer to make any page the user's "start page."
708 void offer_start_page(void) {
709 wprintf("<A HREF=\"/change_start_page?startpage=");
710 urlescputs(WC->this_page);
712 "<FONT SIZE=-2 COLOR=\"#AAAAAA\">Make this my start page</FONT>"
719 * Change the user's start page
721 void change_start_page(void) {
723 if (bstr("startpage") == NULL) {
724 strcpy(WC->ImportantMessage,
725 "startpage set to null");
730 set_preference("startpage", bstr("startpage"));
732 output_headers(1, 1, 0, 0, 0, 0, 0);
733 do_template("newstartpage");
740 void display_success(char *successmessage)
742 convenience_page("007700", "OK", successmessage);
747 void extract_action(char *actbuf, char *cmdbuf)
751 strcpy(actbuf, cmdbuf);
754 * First strip out the http method
756 remove_token(actbuf, 0, ' ');
757 if (actbuf[0] == ' ') strcpy(actbuf, &actbuf[1]);
758 if (actbuf[0] == '/') strcpy(actbuf, &actbuf[1]);
761 * Now kill invalid (for webcit) characters
763 for (i = 0; i < strlen(actbuf); ++i) {
764 if (actbuf[i] == ' ') {
768 if (actbuf[i] == '/') {
772 if (actbuf[i] == '?') {
776 if (actbuf[i] == '&') {
784 void upload_handler(char *name, char *filename, char *partnum, char *disp,
785 void *content, char *cbtype, size_t length,
786 char *encoding, void *userdata)
788 struct urlcontent *u;
791 if ( (length > 0) && (strlen(cbtype) == 0) ) {
792 u = (struct urlcontent *) malloc(sizeof(struct urlcontent));
793 u->next = WC->urlstrings;
795 safestrncpy(u->url_key, name, sizeof(u->url_key));
796 u->url_data = malloc(length + 1);
797 memcpy(u->url_data, content, length);
798 u->url_data[length] = 0;
802 if ( (length > 0) && (strlen(cbtype) > 0) ) {
803 WC->upload = malloc(length);
804 if (WC->upload != NULL) {
805 WC->upload_length = length;
806 safestrncpy(WC->upload_filename, filename,
807 sizeof(WC->upload_filename));
808 safestrncpy(WC->upload_content_type, cbtype,
809 sizeof(WC->upload_content_type));
810 memcpy(WC->upload, content, length);
813 lprintf(3, "malloc() failed: %s\n", strerror(errno));
823 * Entry point for WebCit transaction
825 void session_loop(struct httprequest *req)
832 int ContentLength = 0;
834 char ContentType[512];
835 char *content = NULL;
836 char *content_end = NULL;
837 struct httprequest *hptr;
838 char browser_host[SIZ];
839 char user_agent[SIZ];
842 /* We stuff these with the values coming from the client cookies,
843 * so we can use them to reconnect a timed out session if we have to.
845 char c_username[SIZ];
846 char c_password[SIZ];
847 char c_roomname[SIZ];
848 char c_httpauth_string[SIZ];
849 char c_httpauth_user[SIZ];
850 char c_httpauth_pass[SIZ];
853 strcpy(c_username, "");
854 strcpy(c_password, "");
855 strcpy(c_roomname, "");
856 strcpy(c_httpauth_string, "");
857 strcpy(c_httpauth_user, DEFAULT_HTTPAUTH_USER);
858 strcpy(c_httpauth_pass, DEFAULT_HTTPAUTH_PASS);
860 WC->upload_length = 0;
867 if (hptr == NULL) return;
869 strcpy(cmd, hptr->line);
871 extract_token(method, cmd, 0, ' ');
872 extract_action(action, cmd);
874 while (hptr != NULL) {
875 strcpy(buf, hptr->line);
878 if (!strncasecmp(buf, "Cookie: webcit=", 15)) {
879 safestrncpy(cookie, &buf[15], sizeof cookie);
880 cookie_to_stuff(cookie, NULL,
881 c_username, c_password, c_roomname);
883 else if (!strncasecmp(buf, "Authorization: Basic ", 21)) {
884 CtdlDecodeBase64(c_httpauth_string, &buf[21], strlen(&buf[21]));
885 extract_token(c_httpauth_user, c_httpauth_string, 0, ':');
886 extract_token(c_httpauth_pass, c_httpauth_string, 1, ':');
888 else if (!strncasecmp(buf, "Content-length: ", 16)) {
889 ContentLength = atoi(&buf[16]);
891 else if (!strncasecmp(buf, "Content-type: ", 14)) {
892 safestrncpy(ContentType, &buf[14], sizeof ContentType);
894 else if (!strncasecmp(buf, "User-agent: ", 12)) {
895 safestrncpy(user_agent, &buf[12], sizeof user_agent);
897 else if (!strncasecmp(buf, "Host: ", 6)) {
898 safestrncpy(WC->http_host, &buf[6], sizeof WC->http_host);
900 /* Only WAP gateways explicitly name this content-type */
901 else if (strstr(buf, "text/vnd.wap.wml")) {
906 if (ContentLength > 0) {
907 content = malloc(ContentLength + SIZ);
908 memset(content, 0, ContentLength + SIZ);
909 sprintf(content, "Content-type: %s\n"
910 "Content-length: %d\n\n",
911 ContentType, ContentLength);
912 body_start = strlen(content);
914 /* Be daring and read it all at once. */
915 client_read(WC->http_sock, &content[BytesRead+body_start],
918 if (!strncasecmp(ContentType,
919 "application/x-www-form-urlencoded", 33)) {
920 addurls(&content[body_start]);
921 } else if (!strncasecmp(ContentType, "multipart", 9)) {
922 content_end = content + ContentLength + body_start;
923 mime_parser(content, content_end, *upload_handler,
924 NULL, NULL, NULL, 0);
930 /* make a note of where we are in case the user wants to save it */
931 safestrncpy(WC->this_page, cmd, sizeof(WC->this_page));
932 remove_token(WC->this_page, 2, ' ');
933 remove_token(WC->this_page, 0, ' ');
935 /* If there are variables in the URL, we must grab them now */
936 for (a = 0; a < strlen(cmd); ++a) {
937 if ((cmd[a] == '?') || (cmd[a] == '&')) {
938 for (b = a; b < strlen(cmd); ++b)
941 addurls(&cmd[a + 1]);
946 /* Static content can be sent without connecting to Citadel. */
947 if (!strcasecmp(action, "static")) {
948 strcpy(buf, &cmd[12]);
949 for (a = 0; a < strlen(buf); ++a)
953 goto SKIP_ALL_THIS_CRAP; /* Don't try to connect */
957 * If we're not connected to a Citadel server, try to hook up the
960 if (!WC->connected) {
961 if (!strcasecmp(ctdlhost, "uds")) {
962 /* unix domain socket */
963 sprintf(buf, "%s/citadel.socket", ctdlport);
964 WC->serv_sock = uds_connectsock(buf);
968 WC->serv_sock = tcp_connectsock(ctdlhost, ctdlport);
971 if (WC->serv_sock < 0) {
973 goto SKIP_ALL_THIS_CRAP;
977 serv_gets(buf); /* get the server welcome message */
978 locate_host(browser_host, WC->http_sock);
979 get_serv_info(browser_host, user_agent);
980 if (serv_info.serv_rev_level < MINIMUM_CIT_VERSION) {
981 wprintf("You are connected to a Citadel "
982 "server running Citadel %d.%02d;\nin "
983 "order to run this version of WebCit "
984 "you must also have Citadel %d.%02d or"
986 serv_info.serv_rev_level / 100,
987 serv_info.serv_rev_level % 100,
988 MINIMUM_CIT_VERSION / 100,
989 MINIMUM_CIT_VERSION % 100
991 end_webcit_session();
992 goto SKIP_ALL_THIS_CRAP;
998 * Functions which can be performed without logging in
1000 if (!strcasecmp(action, "listsub")) {
1002 goto SKIP_ALL_THIS_CRAP;
1004 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
1005 if (!strcasecmp(action, "freebusy")) {
1007 goto SKIP_ALL_THIS_CRAP;
1012 * If we're not logged in, but we have HTTP Authentication data,
1013 * try logging in to Citadel using that.
1015 if ((!WC->logged_in)
1016 && (strlen(c_httpauth_user) > 0)
1017 && (strlen(c_httpauth_pass) > 0)) {
1018 serv_printf("USER %s", c_httpauth_user);
1020 if (buf[0] == '3') {
1021 serv_printf("PASS %s", c_httpauth_pass);
1023 if (buf[0] == '2') {
1024 become_logged_in(c_httpauth_user,
1025 c_httpauth_pass, buf);
1026 strcpy(WC->httpauth_user, c_httpauth_user);
1027 strcpy(WC->httpauth_pass, c_httpauth_pass);
1033 * The GroupDAV stuff relies on HTTP authentication instead of
1034 * our session's authentication.
1036 if (!strncasecmp(action, "groupdav", 8)) {
1037 groupdav_main(req, ContentType, /* do GroupDAV methods */
1038 ContentLength, content+body_start);
1039 if (!WC->logged_in) {
1040 WC->killthis = 1; /* If not logged in, don't */
1041 } /* keep the session active */
1042 goto SKIP_ALL_THIS_CRAP;
1047 * If this isn't a GroupDAV session, it's an ordinary browser
1048 * connecting to the user interface. Only allow GET and POST
1051 if ((strcasecmp(method, "GET")) && (strcasecmp(method, "POST"))) {
1052 wprintf("HTTP/1.1 405 Method Not Allowed\r\n");
1053 groupdav_common_headers();
1054 wprintf("Content-Length: 0\r\n\r\n");
1055 goto SKIP_ALL_THIS_CRAP;
1059 * If we're not logged in, but we have username and password cookies
1060 * supplied by the browser, try using them to log in.
1062 if ((!WC->logged_in)
1063 && (strlen(c_username) > 0)
1064 && (strlen(c_password) > 0)) {
1065 serv_printf("USER %s", c_username);
1067 if (buf[0] == '3') {
1068 serv_printf("PASS %s", c_password);
1070 if (buf[0] == '2') {
1071 become_logged_in(c_username, c_password, buf);
1076 * If we don't have a current room, but a cookie specifying the
1077 * current room is supplied, make an effort to go there.
1079 if ((strlen(WC->wc_roomname) == 0) && (strlen(c_roomname) > 0)) {
1080 serv_printf("GOTO %s", c_roomname);
1082 if (buf[0] == '2') {
1083 strcpy(WC->wc_roomname, c_roomname);
1088 * If there are instant messages waiting, retrieve them for display.
1090 check_for_instant_messages();
1092 if (!strcasecmp(action, "image")) {
1096 * All functions handled below this point ... make sure we log in
1097 * before doing anything else!
1099 } else if ((!WC->logged_in) && (!strcasecmp(action, "login"))) {
1101 } else if (!WC->logged_in) {
1102 display_login(NULL);
1106 * Various commands...
1109 else if (!strcasecmp(action, "do_welcome")) {
1111 } else if (!strcasecmp(action, "blank")) {
1113 } else if (!strcasecmp(action, "do_template")) {
1115 } else if (!strcasecmp(action, "display_aide_menu")) {
1116 display_aide_menu();
1117 } else if (!strcasecmp(action, "display_main_menu")) {
1118 display_main_menu();
1119 } else if (!strcasecmp(action, "whobbs")) {
1121 } else if (!strcasecmp(action, "knrooms")) {
1123 } else if (!strcasecmp(action, "gotonext")) {
1126 } else if (!strcasecmp(action, "skip")) {
1128 } else if (!strcasecmp(action, "ungoto")) {
1130 } else if (!strcasecmp(action, "dotgoto")) {
1132 smart_goto(bstr("room"));
1133 } else if (!strcasecmp(action, "dotskip")) {
1134 smart_goto(bstr("room"));
1135 } else if (!strcasecmp(action, "termquit")) {
1137 } else if (!strcasecmp(action, "readnew")) {
1138 readloop("readnew");
1139 } else if (!strcasecmp(action, "readold")) {
1140 readloop("readold");
1141 } else if (!strcasecmp(action, "readfwd")) {
1142 readloop("readfwd");
1143 } else if (!strcasecmp(action, "headers")) {
1144 readloop("headers");
1145 } else if (!strcasecmp(action, "display_enter")) {
1147 } else if (!strcasecmp(action, "post")) {
1149 } else if (!strcasecmp(action, "move_msg")) {
1151 } else if (!strcasecmp(action, "delete_msg")) {
1153 } else if (!strcasecmp(action, "userlist")) {
1155 } else if (!strcasecmp(action, "showuser")) {
1157 } else if (!strcasecmp(action, "display_page")) {
1159 } else if (!strcasecmp(action, "page_user")) {
1161 } else if (!strcasecmp(action, "chat")) {
1163 } else if (!strcasecmp(action, "display_private")) {
1164 display_private("", 0);
1165 } else if (!strcasecmp(action, "goto_private")) {
1167 } else if (!strcasecmp(action, "zapped_list")) {
1169 } else if (!strcasecmp(action, "display_zap")) {
1171 } else if (!strcasecmp(action, "zap")) {
1173 } else if (!strcasecmp(action, "display_entroom")) {
1175 } else if (!strcasecmp(action, "entroom")) {
1177 } else if (!strcasecmp(action, "display_whok")) {
1179 } else if (!strcasecmp(action, "do_invt_kick")) {
1181 } else if (!strcasecmp(action, "display_editroom")) {
1183 } else if (!strcasecmp(action, "netedit")) {
1185 } else if (!strcasecmp(action, "editroom")) {
1187 } else if (!strcasecmp(action, "display_editinfo")) {
1188 display_edit("Room info", "EINF 0", "RINF", "/editinfo", 1);
1189 } else if (!strcasecmp(action, "editinfo")) {
1190 save_edit("Room info", "EINF 1", 1);
1191 } else if (!strcasecmp(action, "display_editbio")) {
1192 sprintf(buf, "RBIO %s", WC->wc_username);
1193 display_edit("Your bio", "NOOP", buf, "editbio", 3);
1194 } else if (!strcasecmp(action, "editbio")) {
1195 save_edit("Your bio", "EBIO", 0);
1196 } else if (!strcasecmp(action, "confirm_move_msg")) {
1198 } else if (!strcasecmp(action, "confirm_delete_room")) {
1199 confirm_delete_room();
1200 } else if (!strcasecmp(action, "delete_room")) {
1202 } else if (!strcasecmp(action, "validate")) {
1204 } else if (!strcasecmp(action, "display_editpic")) {
1205 display_graphics_upload("your photo",
1208 } else if (!strcasecmp(action, "editpic")) {
1209 do_graphics_upload("UIMG 1|_userpic_");
1210 } else if (!strcasecmp(action, "display_editroompic")) {
1211 display_graphics_upload("the graphic for this room",
1214 } else if (!strcasecmp(action, "editroompic")) {
1215 do_graphics_upload("UIMG 1|_roompic_");
1216 } else if (!strcasecmp(action, "delete_floor")) {
1218 } else if (!strcasecmp(action, "rename_floor")) {
1220 } else if (!strcasecmp(action, "create_floor")) {
1222 } else if (!strcasecmp(action, "display_editfloorpic")) {
1223 sprintf(buf, "UIMG 0|_floorpic_|%s",
1224 bstr("which_floor"));
1225 display_graphics_upload("the graphic for this floor",
1228 } else if (!strcasecmp(action, "editfloorpic")) {
1229 sprintf(buf, "UIMG 1|_floorpic_|%s",
1230 bstr("which_floor"));
1231 do_graphics_upload(buf);
1232 } else if (!strcasecmp(action, "display_reg")) {
1234 } else if (!strcasecmp(action, "display_changepw")) {
1236 } else if (!strcasecmp(action, "changepw")) {
1238 } else if (!strcasecmp(action, "display_edit_node")) {
1239 display_edit_node();
1240 } else if (!strcasecmp(action, "edit_node")) {
1242 } else if (!strcasecmp(action, "display_netconf")) {
1244 } else if (!strcasecmp(action, "display_confirm_delete_node")) {
1245 display_confirm_delete_node();
1246 } else if (!strcasecmp(action, "delete_node")) {
1248 } else if (!strcasecmp(action, "display_add_node")) {
1250 } else if (!strcasecmp(action, "add_node")) {
1252 } else if (!strcasecmp(action, "terminate_session")) {
1254 terminate_session();
1255 } else if (!strcasecmp(action, "edit_me")) {
1257 } else if (!strcasecmp(action, "display_siteconfig")) {
1258 display_siteconfig();
1259 } else if (!strcasecmp(action, "chat_recv")) {
1261 } else if (!strcasecmp(action, "chat_send")) {
1263 } else if (!strcasecmp(action, "siteconfig")) {
1265 } else if (!strcasecmp(action, "display_generic")) {
1267 } else if (!strcasecmp(action, "do_generic")) {
1269 } else if (!strcasecmp(action, "display_menubar")) {
1271 } else if (!strcasecmp(action, "output_mimepart")) {
1273 } else if (!strcasecmp(action, "edit_vcard")) {
1275 } else if (!strcasecmp(action, "submit_vcard")) {
1277 } else if (!strcasecmp(action, "select_user_to_edit")) {
1278 select_user_to_edit(NULL, NULL);
1279 } else if (!strcasecmp(action, "display_edituser")) {
1280 display_edituser(NULL, 0);
1281 } else if (!strcasecmp(action, "edituser")) {
1283 } else if (!strcasecmp(action, "create_user")) {
1285 } else if (!strcasecmp(action, "changeview")) {
1287 } else if (!strcasecmp(action, "do_stuff_to_msgs")) {
1289 } else if (!strcasecmp(action, "change_start_page")) {
1290 change_start_page();
1291 } else if (!strcasecmp(action, "display_floorconfig")) {
1292 display_floorconfig(NULL);
1293 } else if (!strcasecmp(action, "toggle_self_service")) {
1294 toggle_self_service();
1295 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
1296 } else if (!strcasecmp(action, "display_edit_task")) {
1297 display_edit_task();
1298 } else if (!strcasecmp(action, "save_task")) {
1300 } else if (!strcasecmp(action, "display_edit_event")) {
1301 display_edit_event();
1302 } else if (!strcasecmp(action, "save_event")) {
1304 } else if (!strcasecmp(action, "respond_to_request")) {
1305 respond_to_request();
1306 } else if (!strcasecmp(action, "handle_rsvp")) {
1309 } else if (!strcasecmp(action, "summary")) {
1311 } else if (!strcasecmp(action, "iconbar")) {
1313 } else if (!strcasecmp(action, "display_customize_iconbar")) {
1314 display_customize_iconbar();
1315 } else if (!strcasecmp(action, "commit_iconbar")) {
1317 } else if (!strcasecmp(action, "set_room_policy")) {
1319 } else if (!strcasecmp(action, "display_inetconf")) {
1321 } else if (!strcasecmp(action, "save_inetconf")) {
1323 } else if (!strcasecmp(action, "diagnostics")) {
1324 output_headers(1, 1, 1, 0, 0, 0, 0);
1326 wprintf("You're in session %d<hr />\n", WC->wc_session);
1327 wprintf("Command: <br /><PRE>\n");
1329 wprintf("</PRE><hr />\n");
1330 wprintf("Variables: <br /><PRE>\n");
1332 wprintf("</PRE><hr />\n");
1335 /* When all else fais, display the main menu. */
1337 display_main_menu();
1342 if (content != NULL) {
1347 if (WC->upload_length > 0) {
1349 WC->upload_length = 0;