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");
187 * Copy a string, escaping characters which have meaning in HTML. If
188 * nbsp is nonzero, spaces are converted to non-breaking spaces.
190 void stresc(char *target, char *strbuf, int nbsp, int nolinebreaks)
195 for (a = 0; a < strlen(strbuf); ++a) {
196 if (strbuf[a] == '<')
197 strcat(target, "<");
198 else if (strbuf[a] == '>')
199 strcat(target, ">");
200 else 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] == LB)
208 else if (strbuf[a] == RB)
210 else if (strbuf[a] == QU)
211 strcat(target, "\"");
212 else if ((strbuf[a] == 32) && (nbsp == 1))
213 strcat(target, " ");
214 else if ((strbuf[a] == '\n') && (nolinebreaks))
215 strcat(target, ""); /* nothing */
216 else if ((strbuf[a] == '\r') && (nolinebreaks))
217 strcat(target, ""); /* nothing */
219 strncat(target, &strbuf[a], 1);
223 void escputs1(char *strbuf, int nbsp, int nolinebreaks)
227 if (strbuf == NULL) return;
228 buf = malloc( (3 * strlen(strbuf)) + SIZ );
229 stresc(buf, strbuf, nbsp, nolinebreaks);
234 void escputs(char *strbuf)
236 escputs1(strbuf, 0, 0);
240 * Escape a string for feeding out as a URL.
241 * Returns a pointer to a buffer that must be freed by the caller!
243 void urlesc(char *outbuf, char *strbuf)
246 char *ec = " #&;`'|*?-~<>^()[]{}$\\";
250 for (a = 0; a < strlen(strbuf); ++a) {
252 for (b = 0; b < strlen(ec); ++b) {
253 if (strbuf[a] == ec[b])
258 sprintf(&outbuf[b], "%%%02x", strbuf[a]);
260 sprintf(&outbuf[b], "%c", strbuf[a]);
264 void urlescputs(char *strbuf)
268 urlesc(outbuf, strbuf);
269 wprintf("%s", outbuf);
274 * Copy a string, escaping characters for JavaScript strings.
276 void jsesc(char *target, char *strbuf)
281 for (a = 0; a < strlen(strbuf); ++a) {
282 if (strbuf[a] == '<')
284 else if (strbuf[a] == '>')
286 else if (strbuf[a] == '\"')
287 strcat(target, """);
288 else if (strbuf[a] == '&')
289 strcat(target, "&;");
290 else if (strbuf[a] == '\'')
291 strcat(target, "\\'");
293 strncat(target, &strbuf[a], 1);
298 void jsescputs(char *strbuf)
302 jsesc(outbuf, strbuf);
303 wprintf("%s", outbuf);
307 * Copy a string, escaping characters for message text hold
309 void msgesc(char *target, char *strbuf)
314 for (a = 0; a < strlen(strbuf); ++a) {
315 if (strbuf[a] == '\'')
316 strcat(target, "\\'");
317 else if (strbuf[a] == '\n')
319 else if (strbuf[a] == '\r')
322 strncat(target, &strbuf[a], 1);
327 void msgescputs(char *strbuf) {
330 if (strbuf == NULL) return;
331 outbuf = malloc( (3 * strlen(strbuf)) + SIZ);
332 msgesc(outbuf, strbuf);
333 wprintf("%s", outbuf);
341 * Output all that important stuff that the browser will want to see
343 void output_headers( int do_httpheaders, /* 1 = output HTTP headers */
344 int do_htmlhead, /* 1 = output HTML <head> section and <body> opener */
346 int do_room_banner, /* 0=no, 1=yes, */
347 /* 2 = I'm going to embed my own, so don't open the */
348 /* <div id="content"> either. */
350 int unset_cookies, /* 1 = session is terminating, so unset the cookies */
351 int refresh30, /* 1 = automatically refresh page every 30 seconds */
352 int suppress_check, /* 1 = suppress check for instant messages */
353 int cache /* 1 = allow browser to cache this page */
358 wprintf("HTTP/1.0 200 OK\n");
359 httpdate(httpnow, time(NULL));
361 if (do_httpheaders) {
362 wprintf("Content-type: text/html\n"
363 "Server: %s / %s\n", SERVER, serv_info.serv_software
366 wprintf("Connection: close\n"
368 "Cache-Control: no-store\n"
372 stuff_to_cookie(cookie, WC->wc_session, WC->wc_username,
373 WC->wc_password, WC->wc_roomname);
376 wprintf("Set-cookie: webcit=%s; path=/\n", unset);
378 wprintf("Set-cookie: webcit=%s; path=/\n", cookie);
379 if (server_cookie != NULL) {
380 wprintf("%s\n", server_cookie);
388 svprintf("REFRESHTAG", WCS_STRING, "%s",
389 "<meta http-equiv=\"refresh\" content=\"30\" />\n");
392 svprintf("REFRESHTAG", WCS_STRING, "%s",
393 "<meta http-equiv=\"refresh\" content=\"500363689;\" />\n");
402 if (WC->HaveInstantMessages) {
403 wprintf("<div id=\"page_popup\">\n");
407 if ( (WC->logged_in) && (!unset_cookies) ) {
408 wprintf("<div id=\"iconbar\">");
412 if (do_room_banner == 1) {
413 wprintf("<div id=\"banner\">\n");
414 embed_room_banner(NULL, navbar_default);
419 if (do_room_banner == 1) {
420 wprintf("<div id=\"content\">\n");
422 if (strlen(WC->ImportantMessage) > 0) {
423 do_template("beginbox_nt");
424 wprintf("<SPAN CLASS=\"errormsg\">"
425 "%s</SPAN><br />\n", WC->ImportantMessage);
426 do_template("endbox");
427 strcpy(WC->ImportantMessage, "");
435 * Generic function to do an HTTP redirect. Easy and fun.
437 void http_redirect(char *whichpage) {
438 wprintf("HTTP/1.0 302 Moved Temporarily\n");
439 wprintf("Location: %s\n", whichpage);
440 wprintf("URI: %s\n", whichpage);
441 wprintf("Content-type: text/html\n\n");
442 wprintf("<html><body>\n");
443 wprintf("you really want to be <A HREF=\"%s\">here</A> now\n",
445 wprintf("</body></html>\n");
450 void check_for_instant_messages()
454 lprintf(9, "Checking for instant messages...\n");
457 if (buf[3] == '*') WC->HaveInstantMessages = 1;
458 lprintf(9, "...done\n");
465 * Output a piece of content to the web browser
467 void http_transmit_thing(char *thing, size_t length, char *content_type,
470 output_headers(0, 0, 0, 0, 0, 0, 1);
473 output_headers(0, 0, 0, 0, 0, 0, 0);
475 wprintf("Content-type: %s\n"
476 "Content-length: %ld\n"
478 "Connection: close\n"
484 client_write(thing, (size_t)length);
490 void output_static(char *what)
497 char content_type[SIZ];
499 sprintf(buf, "static/%s", what);
500 fp = fopen(buf, "rb");
502 wprintf("HTTP/1.0 404 %s\n", strerror(errno));
503 wprintf("Content-Type: text/plain\n");
505 wprintf("Cannot open %s: %s\n", what, strerror(errno));
507 if (!strncasecmp(&what[strlen(what) - 4], ".gif", 4))
508 strcpy(content_type, "image/gif");
509 else if (!strncasecmp(&what[strlen(what) - 4], ".txt", 4))
510 strcpy(content_type, "text/plain");
511 else if (!strncasecmp(&what[strlen(what) - 4], ".css", 4))
512 strcpy(content_type, "text/css");
513 else if (!strncasecmp(&what[strlen(what) - 4], ".jpg", 4))
514 strcpy(content_type, "image/jpeg");
515 else if (!strncasecmp(&what[strlen(what) - 4], ".png", 4))
516 strcpy(content_type, "image/png");
517 else if (!strncasecmp(&what[strlen(what) - 4], ".ico", 4))
518 strcpy(content_type, "image/x-icon");
519 else if (!strncasecmp(&what[strlen(what) - 5], ".html", 5))
520 strcpy(content_type, "text/html");
521 else if (!strncasecmp(&what[strlen(what) - 4], ".htm", 4))
522 strcpy(content_type, "text/html");
523 else if (!strncasecmp(&what[strlen(what) - 4], ".wml", 4))
524 strcpy(content_type, "text/vnd.wap.wml");
525 else if (!strncasecmp(&what[strlen(what) - 5], ".wmls", 5))
526 strcpy(content_type, "text/vnd.wap.wmlscript");
527 else if (!strncasecmp(&what[strlen(what) - 5], ".wmlc", 5))
528 strcpy(content_type, "application/vnd.wap.wmlc");
529 else if (!strncasecmp(&what[strlen(what) - 6], ".wmlsc", 6))
530 strcpy(content_type, "application/vnd.wap.wmlscriptc");
531 else if (!strncasecmp(&what[strlen(what) - 5], ".wbmp", 5))
532 strcpy(content_type, "image/vnd.wap.wbmp");
533 else if (!strncasecmp(&what[strlen(what) - 3], ".js", 3))
534 strcpy(content_type, "text/javascript");
536 strcpy(content_type, "application/octet-stream");
538 fstat(fileno(fp), &statbuf);
539 bytes = statbuf.st_size;
540 /* lprintf(3, "Static: %s, (%s; %ld bytes)\n",
541 what, content_type, bytes); */
542 bigbuffer = malloc(bytes + 2);
543 fread(bigbuffer, bytes, 1, fp);
546 http_transmit_thing(bigbuffer, (size_t)bytes, content_type, 1);
549 if (!strcasecmp(bstr("force_close_session"), "yes")) {
550 end_webcit_session();
556 * When the browser requests an image file from the Citadel server,
557 * this function is called to transmit it.
562 char *xferbuf = NULL;
565 serv_printf("OIMG %s|%s", bstr("name"), bstr("parm"));
568 bytes = extract_long(&buf[4], 0);
569 xferbuf = malloc(bytes + 2);
571 /* Read it from the server */
572 read_server_binary(xferbuf, bytes);
576 /* Write it to the browser */
577 http_transmit_thing(xferbuf, (size_t)bytes, "image/gif", 0);
582 /* Instead of an ugly 404, send a 1x1 transparent GIF
583 * when there's no such image on the server.
585 output_static("blank.gif");
588 wprintf("HTTP/1.0 404 %s\n", &buf[4]);
589 output_headers(0, 0, 0, 0, 0, 0, 0);
590 wprintf("Content-Type: text/plain\n"
592 "Error retrieving image: %s\n",
605 void output_mimepart()
609 char content_type[SIZ];
610 char *content = NULL;
612 serv_printf("OPNA %s|%s", bstr("msgnum"), bstr("partnum"));
615 bytes = extract_long(&buf[4], 0);
616 content = malloc(bytes + 2);
617 extract(content_type, &buf[4], 3);
618 output_headers(0, 0, 0, 0, 0, 0, 0);
619 read_server_binary(content, bytes);
622 http_transmit_thing(content, bytes, content_type, 0);
625 wprintf("HTTP/1.0 404 %s\n", &buf[4]);
626 output_headers(0, 0, 0, 0, 0, 0, 0);
627 wprintf("Content-Type: text/plain\n");
629 wprintf("Error retrieving part: %s\n", &buf[4]);
637 char *load_mimepart(long msgnum, char *partnum)
641 char content_type[SIZ];
644 serv_printf("OPNA %ld|%s", msgnum, partnum);
647 bytes = extract_long(&buf[4], 0);
648 extract(content_type, &buf[4], 3);
650 content = malloc(bytes + 2);
651 read_server_binary(content, bytes);
655 content[bytes] = 0; /* null terminate for good measure */
666 * Convenience functions to display a page containing only a string
668 void convenience_page(char *titlebarcolor, char *titlebarmsg, char *messagetext)
670 wprintf("HTTP/1.0 200 OK\n");
671 output_headers(1, 1, 2, 0, 0, 0, 0);
672 wprintf("<div id=\"banner\">\n");
673 wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#%s\"><TR><TD>", titlebarcolor);
674 wprintf("<SPAN CLASS=\"titlebar\">%s</SPAN>\n", titlebarmsg);
675 wprintf("</TD></TR></TABLE>\n");
676 wprintf("</div>\n<div id=\"content\">\n");
677 escputs(messagetext);
685 * Display a blank page.
687 void blank_page(void) {
688 output_headers(1, 1, 0, 0, 1, 0, 0);
694 * A template has been requested
696 void url_do_template(void) {
697 do_template(bstr("template"));
703 * Offer to make any page the user's "start page."
705 void offer_start_page(void) {
706 wprintf("<A HREF=\"/change_start_page?startpage=");
707 urlescputs(WC->this_page);
709 "<FONT SIZE=-2 COLOR=\"#AAAAAA\">Make this my start page</FONT>"
716 * Change the user's start page
718 void change_start_page(void) {
720 if (bstr("startpage") == NULL) {
721 strcpy(WC->ImportantMessage,
722 "startpage set to null");
727 set_preference("startpage", bstr("startpage"));
729 output_headers(1, 1, 0, 0, 0, 0, 0);
730 do_template("newstartpage");
737 void display_success(char *successmessage)
739 convenience_page("007700", "OK", successmessage);
744 void extract_action(char *actbuf, char *cmdbuf)
748 strcpy(actbuf, cmdbuf);
751 * First strip out the http method
753 remove_token(actbuf, 0, ' ');
754 if (actbuf[0] == ' ') strcpy(actbuf, &actbuf[1]);
755 if (actbuf[0] == '/') strcpy(actbuf, &actbuf[1]);
758 * Now kill invalid (for webcit) characters
760 for (i = 0; i < strlen(actbuf); ++i) {
761 if (actbuf[i] == ' ') {
765 if (actbuf[i] == '/') {
769 if (actbuf[i] == '?') {
773 if (actbuf[i] == '&') {
781 void upload_handler(char *name, char *filename, char *partnum, char *disp,
782 void *content, char *cbtype, size_t length,
783 char *encoding, void *userdata)
785 struct urlcontent *u;
788 if ( (length > 0) && (strlen(cbtype) == 0) ) {
789 u = (struct urlcontent *) malloc(sizeof(struct urlcontent));
790 u->next = WC->urlstrings;
792 safestrncpy(u->url_key, name, sizeof(u->url_key));
793 u->url_data = malloc(length + 1);
794 memcpy(u->url_data, content, length);
795 u->url_data[length] = 0;
799 if ( (length > 0) && (strlen(cbtype) > 0) ) {
800 WC->upload = malloc(length);
801 if (WC->upload != NULL) {
802 WC->upload_length = length;
803 safestrncpy(WC->upload_filename, filename,
804 sizeof(WC->upload_filename));
805 safestrncpy(WC->upload_content_type, cbtype,
806 sizeof(WC->upload_content_type));
807 memcpy(WC->upload, content, length);
810 lprintf(3, "malloc() failed: %s\n", strerror(errno));
820 * Entry point for WebCit transaction
822 void session_loop(struct httprequest *req)
829 int ContentLength = 0;
831 char ContentType[512];
832 char *content = NULL;
833 char *content_end = NULL;
834 struct httprequest *hptr;
835 char browser_host[SIZ];
836 char user_agent[SIZ];
839 /* We stuff these with the values coming from the client cookies,
840 * so we can use them to reconnect a timed out session if we have to.
842 char c_username[SIZ];
843 char c_password[SIZ];
844 char c_roomname[SIZ];
845 char c_httpauth_string[SIZ];
846 char c_httpauth_user[SIZ];
847 char c_httpauth_pass[SIZ];
850 strcpy(c_username, "");
851 strcpy(c_password, "");
852 strcpy(c_roomname, "");
853 strcpy(c_httpauth_string, "");
854 strcpy(c_httpauth_user, DEFAULT_HTTPAUTH_USER);
855 strcpy(c_httpauth_pass, DEFAULT_HTTPAUTH_PASS);
857 WC->upload_length = 0;
864 if (hptr == NULL) return;
866 strcpy(cmd, hptr->line);
868 extract_token(method, cmd, 0, ' ');
869 extract_action(action, cmd);
871 while (hptr != NULL) {
872 strcpy(buf, hptr->line);
875 if (!strncasecmp(buf, "Cookie: webcit=", 15)) {
876 safestrncpy(cookie, &buf[15], sizeof cookie);
877 cookie_to_stuff(cookie, NULL,
878 c_username, c_password, c_roomname);
880 else if (!strncasecmp(buf, "Authorization: Basic ", 21)) {
881 CtdlDecodeBase64(c_httpauth_string, &buf[21], strlen(&buf[21]));
882 extract_token(c_httpauth_user, c_httpauth_string, 0, ':');
883 extract_token(c_httpauth_pass, c_httpauth_string, 1, ':');
885 else if (!strncasecmp(buf, "Content-length: ", 16)) {
886 ContentLength = atoi(&buf[16]);
888 else if (!strncasecmp(buf, "Content-type: ", 14)) {
889 safestrncpy(ContentType, &buf[14], sizeof ContentType);
891 else if (!strncasecmp(buf, "User-agent: ", 12)) {
892 safestrncpy(user_agent, &buf[12], sizeof user_agent);
894 else if (!strncasecmp(buf, "Host: ", 6)) {
895 safestrncpy(WC->http_host, &buf[6], sizeof WC->http_host);
897 /* Only WAP gateways explicitly name this content-type */
898 else if (strstr(buf, "text/vnd.wap.wml")) {
903 if (ContentLength > 0) {
904 content = malloc(ContentLength + SIZ);
905 memset(content, 0, ContentLength + SIZ);
906 sprintf(content, "Content-type: %s\n"
907 "Content-length: %d\n\n",
908 ContentType, ContentLength);
909 body_start = strlen(content);
911 /* Be daring and read it all at once. */
912 client_read(WC->http_sock, &content[BytesRead+body_start],
915 if (!strncasecmp(ContentType,
916 "application/x-www-form-urlencoded", 33)) {
917 addurls(&content[body_start]);
918 } else if (!strncasecmp(ContentType, "multipart", 9)) {
919 content_end = content + ContentLength + body_start;
920 mime_parser(content, content_end, *upload_handler,
921 NULL, NULL, NULL, 0);
927 /* make a note of where we are in case the user wants to save it */
928 safestrncpy(WC->this_page, cmd, sizeof(WC->this_page));
929 remove_token(WC->this_page, 2, ' ');
930 remove_token(WC->this_page, 0, ' ');
932 /* If there are variables in the URL, we must grab them now */
933 for (a = 0; a < strlen(cmd); ++a) {
934 if ((cmd[a] == '?') || (cmd[a] == '&')) {
935 for (b = a; b < strlen(cmd); ++b)
938 addurls(&cmd[a + 1]);
943 /* Static content can be sent without connecting to Citadel. */
944 if (!strcasecmp(action, "static")) {
945 strcpy(buf, &cmd[12]);
946 for (a = 0; a < strlen(buf); ++a)
950 goto SKIP_ALL_THIS_CRAP; /* Don't try to connect */
954 * If we're not connected to a Citadel server, try to hook up the
957 if (!WC->connected) {
958 if (!strcasecmp(ctdlhost, "uds")) {
959 /* unix domain socket */
960 sprintf(buf, "%s/citadel.socket", ctdlport);
961 WC->serv_sock = uds_connectsock(buf);
965 WC->serv_sock = tcp_connectsock(ctdlhost, ctdlport);
968 if (WC->serv_sock < 0) {
970 goto SKIP_ALL_THIS_CRAP;
974 serv_gets(buf); /* get the server welcome message */
975 locate_host(browser_host, WC->http_sock);
976 get_serv_info(browser_host, user_agent);
977 if (serv_info.serv_rev_level < MINIMUM_CIT_VERSION) {
978 wprintf("You are connected to a Citadel "
979 "server running Citadel %d.%02d;\nin "
980 "order to run this version of WebCit "
981 "you must also have Citadel %d.%02d or"
983 serv_info.serv_rev_level / 100,
984 serv_info.serv_rev_level % 100,
985 MINIMUM_CIT_VERSION / 100,
986 MINIMUM_CIT_VERSION % 100
988 end_webcit_session();
989 goto SKIP_ALL_THIS_CRAP;
995 * Functions which can be performed without logging in
997 if (!strcasecmp(action, "listsub")) {
999 goto SKIP_ALL_THIS_CRAP;
1001 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
1002 if (!strcasecmp(action, "freebusy")) {
1004 goto SKIP_ALL_THIS_CRAP;
1009 * If we're not logged in, but we have HTTP Authentication data,
1010 * try logging in to Citadel using that.
1012 if ((!WC->logged_in)
1013 && (strlen(c_httpauth_user) > 0)
1014 && (strlen(c_httpauth_pass) > 0)) {
1015 serv_printf("USER %s", c_httpauth_user);
1017 if (buf[0] == '3') {
1018 serv_printf("PASS %s", c_httpauth_pass);
1020 if (buf[0] == '2') {
1021 become_logged_in(c_httpauth_user,
1022 c_httpauth_pass, buf);
1023 strcpy(WC->httpauth_user, c_httpauth_user);
1024 strcpy(WC->httpauth_pass, c_httpauth_pass);
1030 * The GroupDAV stuff relies on HTTP authentication instead of
1031 * our session's authentication.
1033 if (!strncasecmp(action, "groupdav", 8)) {
1034 groupdav_main(req, ContentType, /* do GroupDAV methods */
1035 ContentLength, content+body_start);
1036 if (!WC->logged_in) {
1037 WC->killthis = 1; /* If not logged in, don't */
1038 } /* keep the session active */
1039 goto SKIP_ALL_THIS_CRAP;
1044 * If this isn't a GroupDAV session, it's an ordinary browser
1045 * connecting to the user interface. Only allow GET and POST
1048 if ((strcasecmp(method, "GET")) && (strcasecmp(method, "POST"))) {
1049 wprintf("HTTP/1.1 405 Method Not Allowed\r\n");
1050 groupdav_common_headers();
1051 wprintf("Content-Length: 0\r\n\r\n");
1052 goto SKIP_ALL_THIS_CRAP;
1056 * If we're not logged in, but we have username and password cookies
1057 * supplied by the browser, try using them to log in.
1059 if ((!WC->logged_in)
1060 && (strlen(c_username) > 0)
1061 && (strlen(c_password) > 0)) {
1062 serv_printf("USER %s", c_username);
1064 if (buf[0] == '3') {
1065 serv_printf("PASS %s", c_password);
1067 if (buf[0] == '2') {
1068 become_logged_in(c_username, c_password, buf);
1073 * If we don't have a current room, but a cookie specifying the
1074 * current room is supplied, make an effort to go there.
1076 if ((strlen(WC->wc_roomname) == 0) && (strlen(c_roomname) > 0)) {
1077 serv_printf("GOTO %s", c_roomname);
1079 if (buf[0] == '2') {
1080 strcpy(WC->wc_roomname, c_roomname);
1085 * If there are instant messages waiting, retrieve them for display.
1087 check_for_instant_messages();
1089 if (!strcasecmp(action, "image")) {
1093 * All functions handled below this point ... make sure we log in
1094 * before doing anything else!
1096 } else if ((!WC->logged_in) && (!strcasecmp(action, "login"))) {
1098 } else if (!WC->logged_in) {
1099 display_login(NULL);
1103 * Various commands...
1106 else if (!strcasecmp(action, "do_welcome")) {
1108 } else if (!strcasecmp(action, "blank")) {
1110 } else if (!strcasecmp(action, "do_template")) {
1112 } else if (!strcasecmp(action, "display_aide_menu")) {
1113 display_aide_menu();
1114 } else if (!strcasecmp(action, "display_main_menu")) {
1115 display_main_menu();
1116 } else if (!strcasecmp(action, "whobbs")) {
1118 } else if (!strcasecmp(action, "knrooms")) {
1120 } else if (!strcasecmp(action, "gotonext")) {
1123 } else if (!strcasecmp(action, "skip")) {
1125 } else if (!strcasecmp(action, "ungoto")) {
1127 } else if (!strcasecmp(action, "dotgoto")) {
1129 smart_goto(bstr("room"));
1130 } else if (!strcasecmp(action, "dotskip")) {
1131 smart_goto(bstr("room"));
1132 } else if (!strcasecmp(action, "termquit")) {
1134 } else if (!strcasecmp(action, "readnew")) {
1135 readloop("readnew");
1136 } else if (!strcasecmp(action, "readold")) {
1137 readloop("readold");
1138 } else if (!strcasecmp(action, "readfwd")) {
1139 readloop("readfwd");
1140 } else if (!strcasecmp(action, "headers")) {
1141 readloop("headers");
1142 } else if (!strcasecmp(action, "display_enter")) {
1144 } else if (!strcasecmp(action, "post")) {
1146 } else if (!strcasecmp(action, "move_msg")) {
1148 } else if (!strcasecmp(action, "delete_msg")) {
1150 } else if (!strcasecmp(action, "userlist")) {
1152 } else if (!strcasecmp(action, "showuser")) {
1154 } else if (!strcasecmp(action, "display_page")) {
1156 } else if (!strcasecmp(action, "page_user")) {
1158 } else if (!strcasecmp(action, "chat")) {
1160 } else if (!strcasecmp(action, "display_private")) {
1161 display_private("", 0);
1162 } else if (!strcasecmp(action, "goto_private")) {
1164 } else if (!strcasecmp(action, "zapped_list")) {
1166 } else if (!strcasecmp(action, "display_zap")) {
1168 } else if (!strcasecmp(action, "zap")) {
1170 } else if (!strcasecmp(action, "display_entroom")) {
1172 } else if (!strcasecmp(action, "entroom")) {
1174 } else if (!strcasecmp(action, "display_whok")) {
1176 } else if (!strcasecmp(action, "do_invt_kick")) {
1178 } else if (!strcasecmp(action, "display_editroom")) {
1180 } else if (!strcasecmp(action, "netedit")) {
1182 } else if (!strcasecmp(action, "editroom")) {
1184 } else if (!strcasecmp(action, "display_editinfo")) {
1185 display_edit("Room info", "EINF 0", "RINF", "/editinfo", 1);
1186 } else if (!strcasecmp(action, "editinfo")) {
1187 save_edit("Room info", "EINF 1", 1);
1188 } else if (!strcasecmp(action, "display_editbio")) {
1189 sprintf(buf, "RBIO %s", WC->wc_username);
1190 display_edit("Your bio", "NOOP", buf, "editbio", 3);
1191 } else if (!strcasecmp(action, "editbio")) {
1192 save_edit("Your bio", "EBIO", 0);
1193 } else if (!strcasecmp(action, "confirm_move_msg")) {
1195 } else if (!strcasecmp(action, "confirm_delete_room")) {
1196 confirm_delete_room();
1197 } else if (!strcasecmp(action, "delete_room")) {
1199 } else if (!strcasecmp(action, "validate")) {
1201 } else if (!strcasecmp(action, "display_editpic")) {
1202 display_graphics_upload("your photo",
1205 } else if (!strcasecmp(action, "editpic")) {
1206 do_graphics_upload("UIMG 1|_userpic_");
1207 } else if (!strcasecmp(action, "display_editroompic")) {
1208 display_graphics_upload("the graphic for this room",
1211 } else if (!strcasecmp(action, "editroompic")) {
1212 do_graphics_upload("UIMG 1|_roompic_");
1213 } else if (!strcasecmp(action, "delete_floor")) {
1215 } else if (!strcasecmp(action, "rename_floor")) {
1217 } else if (!strcasecmp(action, "create_floor")) {
1219 } else if (!strcasecmp(action, "display_editfloorpic")) {
1220 sprintf(buf, "UIMG 0|_floorpic_|%s",
1221 bstr("which_floor"));
1222 display_graphics_upload("the graphic for this floor",
1225 } else if (!strcasecmp(action, "editfloorpic")) {
1226 sprintf(buf, "UIMG 1|_floorpic_|%s",
1227 bstr("which_floor"));
1228 do_graphics_upload(buf);
1229 } else if (!strcasecmp(action, "display_reg")) {
1231 } else if (!strcasecmp(action, "display_changepw")) {
1233 } else if (!strcasecmp(action, "changepw")) {
1235 } else if (!strcasecmp(action, "display_edit_node")) {
1236 display_edit_node();
1237 } else if (!strcasecmp(action, "edit_node")) {
1239 } else if (!strcasecmp(action, "display_netconf")) {
1241 } else if (!strcasecmp(action, "display_confirm_delete_node")) {
1242 display_confirm_delete_node();
1243 } else if (!strcasecmp(action, "delete_node")) {
1245 } else if (!strcasecmp(action, "display_add_node")) {
1247 } else if (!strcasecmp(action, "add_node")) {
1249 } else if (!strcasecmp(action, "terminate_session")) {
1251 terminate_session();
1252 } else if (!strcasecmp(action, "edit_me")) {
1254 } else if (!strcasecmp(action, "display_siteconfig")) {
1255 display_siteconfig();
1256 } else if (!strcasecmp(action, "chat_recv")) {
1258 } else if (!strcasecmp(action, "chat_send")) {
1260 } else if (!strcasecmp(action, "siteconfig")) {
1262 } else if (!strcasecmp(action, "display_generic")) {
1264 } else if (!strcasecmp(action, "do_generic")) {
1266 } else if (!strcasecmp(action, "display_menubar")) {
1268 } else if (!strcasecmp(action, "output_mimepart")) {
1270 } else if (!strcasecmp(action, "edit_vcard")) {
1272 } else if (!strcasecmp(action, "submit_vcard")) {
1274 } else if (!strcasecmp(action, "select_user_to_edit")) {
1275 select_user_to_edit(NULL, NULL);
1276 } else if (!strcasecmp(action, "display_edituser")) {
1277 display_edituser(NULL, 0);
1278 } else if (!strcasecmp(action, "edituser")) {
1280 } else if (!strcasecmp(action, "create_user")) {
1282 } else if (!strcasecmp(action, "changeview")) {
1284 } else if (!strcasecmp(action, "do_stuff_to_msgs")) {
1286 } else if (!strcasecmp(action, "change_start_page")) {
1287 change_start_page();
1288 } else if (!strcasecmp(action, "display_floorconfig")) {
1289 display_floorconfig(NULL);
1290 } else if (!strcasecmp(action, "toggle_self_service")) {
1291 toggle_self_service();
1292 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
1293 } else if (!strcasecmp(action, "display_edit_task")) {
1294 display_edit_task();
1295 } else if (!strcasecmp(action, "save_task")) {
1297 } else if (!strcasecmp(action, "display_edit_event")) {
1298 display_edit_event();
1299 } else if (!strcasecmp(action, "save_event")) {
1301 } else if (!strcasecmp(action, "respond_to_request")) {
1302 respond_to_request();
1303 } else if (!strcasecmp(action, "handle_rsvp")) {
1306 } else if (!strcasecmp(action, "summary")) {
1308 } else if (!strcasecmp(action, "iconbar")) {
1310 } else if (!strcasecmp(action, "display_customize_iconbar")) {
1311 display_customize_iconbar();
1312 } else if (!strcasecmp(action, "commit_iconbar")) {
1314 } else if (!strcasecmp(action, "set_room_policy")) {
1316 } else if (!strcasecmp(action, "display_inetconf")) {
1318 } else if (!strcasecmp(action, "save_inetconf")) {
1320 } else if (!strcasecmp(action, "diagnostics")) {
1321 output_headers(1, 1, 1, 0, 0, 0, 0);
1323 wprintf("You're in session %d<hr />\n", WC->wc_session);
1324 wprintf("Command: <br /><PRE>\n");
1326 wprintf("</PRE><hr />\n");
1327 wprintf("Variables: <br /><PRE>\n");
1329 wprintf("</PRE><hr />\n");
1332 /* When all else fais, display the main menu. */
1334 display_main_menu();
1339 if (content != NULL) {
1344 if (WC->upload_length > 0) {
1346 WC->upload_length = 0;