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()
456 if (buf[3] == '*') WC->HaveInstantMessages = 1;
463 * Output a piece of content to the web browser
465 void http_transmit_thing(char *thing, size_t length, char *content_type,
468 output_headers(0, 0, 0, 0, 0, 0, 1);
471 output_headers(0, 0, 0, 0, 0, 0, 0);
473 wprintf("Content-type: %s\n"
474 "Content-length: %ld\n"
476 "Connection: close\n"
482 client_write(thing, (size_t)length);
488 void output_static(char *what)
495 char content_type[SIZ];
497 sprintf(buf, "static/%s", what);
498 fp = fopen(buf, "rb");
500 wprintf("HTTP/1.0 404 %s\n", strerror(errno));
501 wprintf("Content-Type: text/plain\n");
503 wprintf("Cannot open %s: %s\n", what, strerror(errno));
505 if (!strncasecmp(&what[strlen(what) - 4], ".gif", 4))
506 strcpy(content_type, "image/gif");
507 else if (!strncasecmp(&what[strlen(what) - 4], ".txt", 4))
508 strcpy(content_type, "text/plain");
509 else if (!strncasecmp(&what[strlen(what) - 4], ".css", 4))
510 strcpy(content_type, "text/css");
511 else if (!strncasecmp(&what[strlen(what) - 4], ".jpg", 4))
512 strcpy(content_type, "image/jpeg");
513 else if (!strncasecmp(&what[strlen(what) - 4], ".png", 4))
514 strcpy(content_type, "image/png");
515 else if (!strncasecmp(&what[strlen(what) - 4], ".ico", 4))
516 strcpy(content_type, "image/x-icon");
517 else if (!strncasecmp(&what[strlen(what) - 5], ".html", 5))
518 strcpy(content_type, "text/html");
519 else if (!strncasecmp(&what[strlen(what) - 4], ".htm", 4))
520 strcpy(content_type, "text/html");
521 else if (!strncasecmp(&what[strlen(what) - 4], ".wml", 4))
522 strcpy(content_type, "text/vnd.wap.wml");
523 else if (!strncasecmp(&what[strlen(what) - 5], ".wmls", 5))
524 strcpy(content_type, "text/vnd.wap.wmlscript");
525 else if (!strncasecmp(&what[strlen(what) - 5], ".wmlc", 5))
526 strcpy(content_type, "application/vnd.wap.wmlc");
527 else if (!strncasecmp(&what[strlen(what) - 6], ".wmlsc", 6))
528 strcpy(content_type, "application/vnd.wap.wmlscriptc");
529 else if (!strncasecmp(&what[strlen(what) - 5], ".wbmp", 5))
530 strcpy(content_type, "image/vnd.wap.wbmp");
531 else if (!strncasecmp(&what[strlen(what) - 3], ".js", 3))
532 strcpy(content_type, "text/javascript");
534 strcpy(content_type, "application/octet-stream");
536 fstat(fileno(fp), &statbuf);
537 bytes = statbuf.st_size;
538 /* lprintf(3, "Static: %s, (%s; %ld bytes)\n",
539 what, content_type, bytes); */
540 bigbuffer = malloc(bytes + 2);
541 fread(bigbuffer, bytes, 1, fp);
544 http_transmit_thing(bigbuffer, (size_t)bytes, content_type, 1);
547 if (!strcasecmp(bstr("force_close_session"), "yes")) {
548 end_webcit_session();
554 * When the browser requests an image file from the Citadel server,
555 * this function is called to transmit it.
560 char *xferbuf = NULL;
563 serv_printf("OIMG %s|%s", bstr("name"), bstr("parm"));
566 bytes = extract_long(&buf[4], 0);
567 xferbuf = malloc(bytes + 2);
569 /* Read it from the server */
570 read_server_binary(xferbuf, bytes);
574 /* Write it to the browser */
575 http_transmit_thing(xferbuf, (size_t)bytes, "image/gif", 0);
580 /* Instead of an ugly 404, send a 1x1 transparent GIF
581 * when there's no such image on the server.
583 output_static("blank.gif");
586 wprintf("HTTP/1.0 404 %s\n", &buf[4]);
587 output_headers(0, 0, 0, 0, 0, 0, 0);
588 wprintf("Content-Type: text/plain\n"
590 "Error retrieving image: %s\n",
603 void output_mimepart()
607 char content_type[SIZ];
608 char *content = NULL;
610 serv_printf("OPNA %s|%s", bstr("msgnum"), bstr("partnum"));
613 bytes = extract_long(&buf[4], 0);
614 content = malloc(bytes + 2);
615 extract(content_type, &buf[4], 3);
616 output_headers(0, 0, 0, 0, 0, 0, 0);
617 read_server_binary(content, bytes);
620 http_transmit_thing(content, bytes, content_type, 0);
623 wprintf("HTTP/1.0 404 %s\n", &buf[4]);
624 output_headers(0, 0, 0, 0, 0, 0, 0);
625 wprintf("Content-Type: text/plain\n");
627 wprintf("Error retrieving part: %s\n", &buf[4]);
635 char *load_mimepart(long msgnum, char *partnum)
639 char content_type[SIZ];
642 serv_printf("OPNA %ld|%s", msgnum, partnum);
645 bytes = extract_long(&buf[4], 0);
646 extract(content_type, &buf[4], 3);
648 content = malloc(bytes + 2);
649 read_server_binary(content, bytes);
653 content[bytes] = 0; /* null terminate for good measure */
664 * Convenience functions to display a page containing only a string
666 void convenience_page(char *titlebarcolor, char *titlebarmsg, char *messagetext)
668 wprintf("HTTP/1.0 200 OK\n");
669 output_headers(1, 1, 2, 0, 0, 0, 0);
670 wprintf("<div id=\"banner\">\n");
671 wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#%s\"><TR><TD>", titlebarcolor);
672 wprintf("<SPAN CLASS=\"titlebar\">%s</SPAN>\n", titlebarmsg);
673 wprintf("</TD></TR></TABLE>\n");
674 wprintf("</div>\n<div id=\"content\">\n");
675 escputs(messagetext);
683 * Display a blank page.
685 void blank_page(void) {
686 output_headers(1, 1, 0, 0, 1, 0, 0);
692 * A template has been requested
694 void url_do_template(void) {
695 do_template(bstr("template"));
701 * Offer to make any page the user's "start page."
703 void offer_start_page(void) {
704 wprintf("<A HREF=\"/change_start_page?startpage=");
705 urlescputs(WC->this_page);
707 "<FONT SIZE=-2 COLOR=\"#AAAAAA\">Make this my start page</FONT>"
714 * Change the user's start page
716 void change_start_page(void) {
718 if (bstr("startpage") == NULL) {
719 strcpy(WC->ImportantMessage,
720 "startpage set to null");
725 set_preference("startpage", bstr("startpage"));
727 output_headers(1, 1, 0, 0, 0, 0, 0);
728 do_template("newstartpage");
735 void display_success(char *successmessage)
737 convenience_page("007700", "OK", successmessage);
742 void extract_action(char *actbuf, char *cmdbuf)
746 strcpy(actbuf, cmdbuf);
749 * First strip out the http method
751 remove_token(actbuf, 0, ' ');
752 if (actbuf[0] == ' ') strcpy(actbuf, &actbuf[1]);
753 if (actbuf[0] == '/') strcpy(actbuf, &actbuf[1]);
756 * Now kill invalid (for webcit) characters
758 for (i = 0; i < strlen(actbuf); ++i) {
759 if (actbuf[i] == ' ') {
763 if (actbuf[i] == '/') {
767 if (actbuf[i] == '?') {
771 if (actbuf[i] == '&') {
779 void upload_handler(char *name, char *filename, char *partnum, char *disp,
780 void *content, char *cbtype, size_t length,
781 char *encoding, void *userdata)
783 struct urlcontent *u;
786 if ( (length > 0) && (strlen(cbtype) == 0) ) {
787 u = (struct urlcontent *) malloc(sizeof(struct urlcontent));
788 u->next = WC->urlstrings;
790 safestrncpy(u->url_key, name, sizeof(u->url_key));
791 u->url_data = malloc(length + 1);
792 memcpy(u->url_data, content, length);
793 u->url_data[length] = 0;
797 if ( (length > 0) && (strlen(cbtype) > 0) ) {
798 WC->upload = malloc(length);
799 if (WC->upload != NULL) {
800 WC->upload_length = length;
801 safestrncpy(WC->upload_filename, filename,
802 sizeof(WC->upload_filename));
803 safestrncpy(WC->upload_content_type, cbtype,
804 sizeof(WC->upload_content_type));
805 memcpy(WC->upload, content, length);
808 lprintf(3, "malloc() failed: %s\n", strerror(errno));
818 * Entry point for WebCit transaction
820 void session_loop(struct httprequest *req)
827 int ContentLength = 0;
829 char ContentType[512];
830 char *content = NULL;
831 char *content_end = NULL;
832 struct httprequest *hptr;
833 char browser_host[SIZ];
834 char user_agent[SIZ];
837 /* We stuff these with the values coming from the client cookies,
838 * so we can use them to reconnect a timed out session if we have to.
840 char c_username[SIZ];
841 char c_password[SIZ];
842 char c_roomname[SIZ];
843 char c_httpauth_string[SIZ];
844 char c_httpauth_user[SIZ];
845 char c_httpauth_pass[SIZ];
848 strcpy(c_username, "");
849 strcpy(c_password, "");
850 strcpy(c_roomname, "");
851 strcpy(c_httpauth_string, "");
852 strcpy(c_httpauth_user, DEFAULT_HTTPAUTH_USER);
853 strcpy(c_httpauth_pass, DEFAULT_HTTPAUTH_PASS);
855 WC->upload_length = 0;
862 if (hptr == NULL) return;
864 strcpy(cmd, hptr->line);
866 extract_token(method, cmd, 0, ' ');
867 extract_action(action, cmd);
869 while (hptr != NULL) {
870 strcpy(buf, hptr->line);
873 if (!strncasecmp(buf, "Cookie: webcit=", 15)) {
874 safestrncpy(cookie, &buf[15], sizeof cookie);
875 cookie_to_stuff(cookie, NULL,
876 c_username, c_password, c_roomname);
878 else if (!strncasecmp(buf, "Authorization: Basic ", 21)) {
879 CtdlDecodeBase64(c_httpauth_string, &buf[21], strlen(&buf[21]));
880 extract_token(c_httpauth_user, c_httpauth_string, 0, ':');
881 extract_token(c_httpauth_pass, c_httpauth_string, 1, ':');
883 else if (!strncasecmp(buf, "Content-length: ", 16)) {
884 ContentLength = atoi(&buf[16]);
886 else if (!strncasecmp(buf, "Content-type: ", 14)) {
887 safestrncpy(ContentType, &buf[14], sizeof ContentType);
889 else if (!strncasecmp(buf, "User-agent: ", 12)) {
890 safestrncpy(user_agent, &buf[12], sizeof user_agent);
892 else if (!strncasecmp(buf, "Host: ", 6)) {
893 safestrncpy(WC->http_host, &buf[6], sizeof WC->http_host);
895 /* Only WAP gateways explicitly name this content-type */
896 else if (strstr(buf, "text/vnd.wap.wml")) {
901 if (ContentLength > 0) {
902 content = malloc(ContentLength + SIZ);
903 memset(content, 0, ContentLength + SIZ);
904 sprintf(content, "Content-type: %s\n"
905 "Content-length: %d\n\n",
906 ContentType, ContentLength);
907 body_start = strlen(content);
909 /* Be daring and read it all at once. */
910 client_read(WC->http_sock, &content[BytesRead+body_start],
913 if (!strncasecmp(ContentType,
914 "application/x-www-form-urlencoded", 33)) {
915 addurls(&content[body_start]);
916 } else if (!strncasecmp(ContentType, "multipart", 9)) {
917 content_end = content + ContentLength + body_start;
918 mime_parser(content, content_end, *upload_handler,
919 NULL, NULL, NULL, 0);
925 /* make a note of where we are in case the user wants to save it */
926 safestrncpy(WC->this_page, cmd, sizeof(WC->this_page));
927 remove_token(WC->this_page, 2, ' ');
928 remove_token(WC->this_page, 0, ' ');
930 /* If there are variables in the URL, we must grab them now */
931 for (a = 0; a < strlen(cmd); ++a) {
932 if ((cmd[a] == '?') || (cmd[a] == '&')) {
933 for (b = a; b < strlen(cmd); ++b)
936 addurls(&cmd[a + 1]);
941 /* Static content can be sent without connecting to Citadel. */
942 if (!strcasecmp(action, "static")) {
943 strcpy(buf, &cmd[12]);
944 for (a = 0; a < strlen(buf); ++a)
948 goto SKIP_ALL_THIS_CRAP; /* Don't try to connect */
952 * If we're not connected to a Citadel server, try to hook up the
955 if (!WC->connected) {
956 if (!strcasecmp(ctdlhost, "uds")) {
957 /* unix domain socket */
958 sprintf(buf, "%s/citadel.socket", ctdlport);
959 WC->serv_sock = uds_connectsock(buf);
963 WC->serv_sock = tcp_connectsock(ctdlhost, ctdlport);
966 if (WC->serv_sock < 0) {
968 goto SKIP_ALL_THIS_CRAP;
972 serv_gets(buf); /* get the server welcome message */
973 locate_host(browser_host, WC->http_sock);
974 get_serv_info(browser_host, user_agent);
975 if (serv_info.serv_rev_level < MINIMUM_CIT_VERSION) {
976 wprintf("You are connected to a Citadel "
977 "server running Citadel %d.%02d;\nin "
978 "order to run this version of WebCit "
979 "you must also have Citadel %d.%02d or"
981 serv_info.serv_rev_level / 100,
982 serv_info.serv_rev_level % 100,
983 MINIMUM_CIT_VERSION / 100,
984 MINIMUM_CIT_VERSION % 100
986 end_webcit_session();
987 goto SKIP_ALL_THIS_CRAP;
993 * Functions which can be performed without logging in
995 if (!strcasecmp(action, "listsub")) {
997 goto SKIP_ALL_THIS_CRAP;
999 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
1000 if (!strcasecmp(action, "freebusy")) {
1002 goto SKIP_ALL_THIS_CRAP;
1007 * If we're not logged in, but we have HTTP Authentication data,
1008 * try logging in to Citadel using that.
1010 if ((!WC->logged_in)
1011 && (strlen(c_httpauth_user) > 0)
1012 && (strlen(c_httpauth_pass) > 0)) {
1013 serv_printf("USER %s", c_httpauth_user);
1015 if (buf[0] == '3') {
1016 serv_printf("PASS %s", c_httpauth_pass);
1018 if (buf[0] == '2') {
1019 become_logged_in(c_httpauth_user,
1020 c_httpauth_pass, buf);
1021 strcpy(WC->httpauth_user, c_httpauth_user);
1022 strcpy(WC->httpauth_pass, c_httpauth_pass);
1028 * The GroupDAV stuff relies on HTTP authentication instead of
1029 * our session's authentication.
1031 if (!strncasecmp(action, "groupdav", 8)) {
1032 groupdav_main(req, ContentType, /* do GroupDAV methods */
1033 ContentLength, content+body_start);
1034 if (!WC->logged_in) {
1035 WC->killthis = 1; /* If not logged in, don't */
1036 } /* keep the session active */
1037 goto SKIP_ALL_THIS_CRAP;
1042 * If this isn't a GroupDAV session, it's an ordinary browser
1043 * connecting to the user interface. Only allow GET and POST
1046 if ((strcasecmp(method, "GET")) && (strcasecmp(method, "POST"))) {
1047 wprintf("HTTP/1.1 405 Method Not Allowed\r\n");
1048 groupdav_common_headers();
1049 wprintf("Content-Length: 0\r\n\r\n");
1050 goto SKIP_ALL_THIS_CRAP;
1053 check_for_instant_messages();
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);
1084 if (!strcasecmp(action, "image")) {
1088 * All functions handled below this point ... make sure we log in
1089 * before doing anything else!
1091 } else if ((!WC->logged_in) && (!strcasecmp(action, "login"))) {
1093 } else if (!WC->logged_in) {
1094 display_login(NULL);
1098 * Various commands...
1101 else if (!strcasecmp(action, "do_welcome")) {
1103 } else if (!strcasecmp(action, "blank")) {
1105 } else if (!strcasecmp(action, "do_template")) {
1107 } else if (!strcasecmp(action, "display_main_menu")) {
1108 display_main_menu();
1109 } else if (!strcasecmp(action, "whobbs")) {
1111 } else if (!strcasecmp(action, "knrooms")) {
1113 } else if (!strcasecmp(action, "gotonext")) {
1116 } else if (!strcasecmp(action, "skip")) {
1118 } else if (!strcasecmp(action, "ungoto")) {
1120 } else if (!strcasecmp(action, "dotgoto")) {
1122 smart_goto(bstr("room"));
1123 } else if (!strcasecmp(action, "dotskip")) {
1124 smart_goto(bstr("room"));
1125 } else if (!strcasecmp(action, "termquit")) {
1127 } else if (!strcasecmp(action, "readnew")) {
1128 readloop("readnew");
1129 } else if (!strcasecmp(action, "readold")) {
1130 readloop("readold");
1131 } else if (!strcasecmp(action, "readfwd")) {
1132 readloop("readfwd");
1133 } else if (!strcasecmp(action, "headers")) {
1134 readloop("headers");
1135 } else if (!strcasecmp(action, "display_enter")) {
1137 } else if (!strcasecmp(action, "post")) {
1139 } else if (!strcasecmp(action, "do_stuff_to_one_msg")) {
1140 do_stuff_to_one_msg();
1141 } else if (!strcasecmp(action, "move_msg")) {
1143 } else if (!strcasecmp(action, "userlist")) {
1145 } else if (!strcasecmp(action, "showuser")) {
1147 } else if (!strcasecmp(action, "display_page")) {
1149 } else if (!strcasecmp(action, "page_user")) {
1151 } else if (!strcasecmp(action, "chat")) {
1153 } else if (!strcasecmp(action, "display_private")) {
1154 display_private("", 0);
1155 } else if (!strcasecmp(action, "goto_private")) {
1157 } else if (!strcasecmp(action, "zapped_list")) {
1159 } else if (!strcasecmp(action, "display_zap")) {
1161 } else if (!strcasecmp(action, "zap")) {
1163 } else if (!strcasecmp(action, "display_entroom")) {
1165 } else if (!strcasecmp(action, "entroom")) {
1167 } else if (!strcasecmp(action, "display_editroom")) {
1169 } else if (!strcasecmp(action, "netedit")) {
1171 } else if (!strcasecmp(action, "editroom")) {
1173 } else if (!strcasecmp(action, "display_whok")) {
1175 } else if (!strcasecmp(action, "display_editinfo")) {
1176 display_edit("Room info", "EINF 0", "RINF", "/editinfo", 1);
1177 } else if (!strcasecmp(action, "editinfo")) {
1178 save_edit("Room info", "EINF 1", 1);
1179 } else if (!strcasecmp(action, "display_editbio")) {
1180 sprintf(buf, "RBIO %s", WC->wc_username);
1181 display_edit("Your bio", "NOOP", buf, "editbio", 3);
1182 } else if (!strcasecmp(action, "editbio")) {
1183 save_edit("Your bio", "EBIO", 0);
1184 } else if (!strcasecmp(action, "confirm_delete_room")) {
1185 confirm_delete_room();
1186 } else if (!strcasecmp(action, "delete_room")) {
1188 } else if (!strcasecmp(action, "validate")) {
1190 } else if (!strcasecmp(action, "display_editpic")) {
1191 display_graphics_upload("your photo",
1194 } else if (!strcasecmp(action, "editpic")) {
1195 do_graphics_upload("UIMG 1|_userpic_");
1196 } else if (!strcasecmp(action, "display_editroompic")) {
1197 display_graphics_upload("the graphic for this room",
1200 } else if (!strcasecmp(action, "editroompic")) {
1201 do_graphics_upload("UIMG 1|_roompic_");
1202 } else if (!strcasecmp(action, "delete_floor")) {
1204 } else if (!strcasecmp(action, "rename_floor")) {
1206 } else if (!strcasecmp(action, "create_floor")) {
1208 } else if (!strcasecmp(action, "display_editfloorpic")) {
1209 sprintf(buf, "UIMG 0|_floorpic_|%s",
1210 bstr("which_floor"));
1211 display_graphics_upload("the graphic for this floor",
1214 } else if (!strcasecmp(action, "editfloorpic")) {
1215 sprintf(buf, "UIMG 1|_floorpic_|%s",
1216 bstr("which_floor"));
1217 do_graphics_upload(buf);
1218 } else if (!strcasecmp(action, "display_reg")) {
1220 } else if (!strcasecmp(action, "display_changepw")) {
1222 } else if (!strcasecmp(action, "changepw")) {
1224 } else if (!strcasecmp(action, "display_edit_node")) {
1225 display_edit_node();
1226 } else if (!strcasecmp(action, "edit_node")) {
1228 } else if (!strcasecmp(action, "display_netconf")) {
1230 } else if (!strcasecmp(action, "display_confirm_delete_node")) {
1231 display_confirm_delete_node();
1232 } else if (!strcasecmp(action, "delete_node")) {
1234 } else if (!strcasecmp(action, "display_add_node")) {
1236 } else if (!strcasecmp(action, "add_node")) {
1238 } else if (!strcasecmp(action, "terminate_session")) {
1240 terminate_session();
1241 } else if (!strcasecmp(action, "edit_me")) {
1243 } else if (!strcasecmp(action, "display_siteconfig")) {
1244 display_siteconfig();
1245 } else if (!strcasecmp(action, "chat_recv")) {
1247 } else if (!strcasecmp(action, "chat_send")) {
1249 } else if (!strcasecmp(action, "siteconfig")) {
1251 } else if (!strcasecmp(action, "display_generic")) {
1253 } else if (!strcasecmp(action, "do_generic")) {
1255 } else if (!strcasecmp(action, "display_menubar")) {
1257 } else if (!strcasecmp(action, "output_mimepart")) {
1259 } else if (!strcasecmp(action, "edit_vcard")) {
1261 } else if (!strcasecmp(action, "submit_vcard")) {
1263 } else if (!strcasecmp(action, "select_user_to_edit")) {
1264 select_user_to_edit(NULL, NULL);
1265 } else if (!strcasecmp(action, "display_edituser")) {
1266 display_edituser(NULL, 0);
1267 } else if (!strcasecmp(action, "edituser")) {
1269 } else if (!strcasecmp(action, "create_user")) {
1271 } else if (!strcasecmp(action, "changeview")) {
1273 } else if (!strcasecmp(action, "do_stuff_to_msgs")) {
1275 } else if (!strcasecmp(action, "change_start_page")) {
1276 change_start_page();
1277 } else if (!strcasecmp(action, "display_floorconfig")) {
1278 display_floorconfig(NULL);
1279 } else if (!strcasecmp(action, "toggle_self_service")) {
1280 toggle_self_service();
1281 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
1282 } else if (!strcasecmp(action, "display_edit_task")) {
1283 display_edit_task();
1284 } else if (!strcasecmp(action, "save_task")) {
1286 } else if (!strcasecmp(action, "display_edit_event")) {
1287 display_edit_event();
1288 } else if (!strcasecmp(action, "save_event")) {
1290 } else if (!strcasecmp(action, "respond_to_request")) {
1291 respond_to_request();
1292 } else if (!strcasecmp(action, "handle_rsvp")) {
1295 } else if (!strcasecmp(action, "summary")) {
1297 } else if (!strcasecmp(action, "iconbar")) {
1299 } else if (!strcasecmp(action, "display_customize_iconbar")) {
1300 display_customize_iconbar();
1301 } else if (!strcasecmp(action, "commit_iconbar")) {
1303 } else if (!strcasecmp(action, "set_room_policy")) {
1305 } else if (!strcasecmp(action, "display_inetconf")) {
1307 } else if (!strcasecmp(action, "save_inetconf")) {
1309 } else if (!strcasecmp(action, "diagnostics")) {
1310 output_headers(1, 1, 1, 0, 0, 0, 0);
1312 wprintf("You're in session %d<hr />\n", WC->wc_session);
1313 wprintf("Command: <br /><PRE>\n");
1315 wprintf("</PRE><hr />\n");
1316 wprintf("Variables: <br /><PRE>\n");
1318 wprintf("</PRE><hr />\n");
1321 /* When all else fais, display the main menu. */
1323 display_main_menu();
1328 if (content != NULL) {
1333 if (WC->upload_length > 0) {
1335 WC->upload_length = 0;