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="text"> 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 != 2) {
420 wprintf("<div id=\"content\">\n");
423 if (strlen(WC->ImportantMessage) > 0) {
424 do_template("beginbox_nt");
425 wprintf("<SPAN CLASS=\"errormsg\">"
426 "%s</SPAN><br />\n", WC->ImportantMessage);
427 do_template("endbox");
428 strcpy(WC->ImportantMessage, "");
436 * Generic function to do an HTTP redirect. Easy and fun.
438 void http_redirect(char *whichpage) {
439 wprintf("HTTP/1.0 302 Moved Temporarily\n");
440 wprintf("Location: %s\n", whichpage);
441 wprintf("URI: %s\n", whichpage);
442 wprintf("Content-type: text/html\n\n");
443 wprintf("<html><body>\n");
444 wprintf("you really want to be <A HREF=\"%s\">here</A> now\n",
446 wprintf("</body></html>\n");
451 void check_for_instant_messages()
457 if (buf[3] == '*') WC->HaveInstantMessages = 1;
464 * Output a piece of content to the web browser
466 void http_transmit_thing(char *thing, size_t length, char *content_type,
469 output_headers(0, 0, 0, 0, 0, 0, 1);
472 output_headers(0, 0, 0, 0, 0, 0, 0);
474 wprintf("Content-type: %s\n"
475 "Content-length: %ld\n"
477 "Connection: close\n"
483 client_write(thing, (size_t)length);
489 void output_static(char *what)
496 char content_type[SIZ];
498 sprintf(buf, "static/%s", what);
499 fp = fopen(buf, "rb");
501 wprintf("HTTP/1.0 404 %s\n", strerror(errno));
502 wprintf("Content-Type: text/plain\n");
504 wprintf("Cannot open %s: %s\n", what, strerror(errno));
506 if (!strncasecmp(&what[strlen(what) - 4], ".gif", 4))
507 strcpy(content_type, "image/gif");
508 else if (!strncasecmp(&what[strlen(what) - 4], ".txt", 4))
509 strcpy(content_type, "text/plain");
510 else if (!strncasecmp(&what[strlen(what) - 4], ".css", 4))
511 strcpy(content_type, "text/css");
512 else if (!strncasecmp(&what[strlen(what) - 4], ".jpg", 4))
513 strcpy(content_type, "image/jpeg");
514 else if (!strncasecmp(&what[strlen(what) - 4], ".png", 4))
515 strcpy(content_type, "image/png");
516 else if (!strncasecmp(&what[strlen(what) - 4], ".ico", 4))
517 strcpy(content_type, "image/x-icon");
518 else if (!strncasecmp(&what[strlen(what) - 5], ".html", 5))
519 strcpy(content_type, "text/html");
520 else if (!strncasecmp(&what[strlen(what) - 4], ".htm", 4))
521 strcpy(content_type, "text/html");
522 else if (!strncasecmp(&what[strlen(what) - 4], ".wml", 4))
523 strcpy(content_type, "text/vnd.wap.wml");
524 else if (!strncasecmp(&what[strlen(what) - 5], ".wmls", 5))
525 strcpy(content_type, "text/vnd.wap.wmlscript");
526 else if (!strncasecmp(&what[strlen(what) - 5], ".wmlc", 5))
527 strcpy(content_type, "application/vnd.wap.wmlc");
528 else if (!strncasecmp(&what[strlen(what) - 6], ".wmlsc", 6))
529 strcpy(content_type, "application/vnd.wap.wmlscriptc");
530 else if (!strncasecmp(&what[strlen(what) - 5], ".wbmp", 5))
531 strcpy(content_type, "image/vnd.wap.wbmp");
532 else if (!strncasecmp(&what[strlen(what) - 3], ".js", 3))
533 strcpy(content_type, "text/javascript");
535 strcpy(content_type, "application/octet-stream");
537 fstat(fileno(fp), &statbuf);
538 bytes = statbuf.st_size;
539 /* lprintf(3, "Static: %s, (%s; %ld bytes)\n",
540 what, content_type, bytes); */
541 bigbuffer = malloc(bytes + 2);
542 fread(bigbuffer, bytes, 1, fp);
545 http_transmit_thing(bigbuffer, (size_t)bytes, content_type, 1);
548 if (!strcasecmp(bstr("force_close_session"), "yes")) {
549 end_webcit_session();
555 * When the browser requests an image file from the Citadel server,
556 * this function is called to transmit it.
561 char *xferbuf = NULL;
564 serv_printf("OIMG %s|%s", bstr("name"), bstr("parm"));
567 bytes = extract_long(&buf[4], 0);
568 xferbuf = malloc(bytes + 2);
570 /* Read it from the server */
571 read_server_binary(xferbuf, bytes);
575 /* Write it to the browser */
576 http_transmit_thing(xferbuf, (size_t)bytes, "image/gif", 0);
581 /* Instead of an ugly 404, send a 1x1 transparent GIF
582 * when there's no such image on the server.
584 output_static("blank.gif");
587 wprintf("HTTP/1.0 404 %s\n", &buf[4]);
588 output_headers(0, 0, 0, 0, 0, 0, 0);
589 wprintf("Content-Type: text/plain\n"
591 "Error retrieving image: %s\n",
604 void output_mimepart()
608 char content_type[SIZ];
609 char *content = NULL;
611 serv_printf("OPNA %s|%s", bstr("msgnum"), bstr("partnum"));
614 bytes = extract_long(&buf[4], 0);
615 content = malloc(bytes + 2);
616 extract(content_type, &buf[4], 3);
617 output_headers(0, 0, 0, 0, 0, 0, 0);
618 read_server_binary(content, bytes);
621 http_transmit_thing(content, bytes, content_type, 0);
624 wprintf("HTTP/1.0 404 %s\n", &buf[4]);
625 output_headers(0, 0, 0, 0, 0, 0, 0);
626 wprintf("Content-Type: text/plain\n");
628 wprintf("Error retrieving part: %s\n", &buf[4]);
636 char *load_mimepart(long msgnum, char *partnum)
640 char content_type[SIZ];
643 serv_printf("OPNA %ld|%s", msgnum, partnum);
646 bytes = extract_long(&buf[4], 0);
647 extract(content_type, &buf[4], 3);
649 content = malloc(bytes + 2);
650 read_server_binary(content, bytes);
654 content[bytes] = 0; /* null terminate for good measure */
665 * Convenience functions to display a page containing only a string
667 void convenience_page(char *titlebarcolor, char *titlebarmsg, char *messagetext)
669 wprintf("HTTP/1.0 200 OK\n");
670 output_headers(1, 1, 2, 0, 0, 0, 0);
671 wprintf("<div id=\"banner\">\n");
672 wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#%s\"><TR><TD>", titlebarcolor);
673 wprintf("<SPAN CLASS=\"titlebar\">%s</SPAN>\n", titlebarmsg);
674 wprintf("</TD></TR></TABLE>\n");
675 wprintf("</div>\n<div id=\"content\">\n");
676 escputs(messagetext);
684 * Display a blank page.
686 void blank_page(void) {
687 output_headers(1, 1, 0, 0, 1, 0, 0);
693 * A template has been requested
695 void url_do_template(void) {
696 do_template(bstr("template"));
702 * Offer to make any page the user's "start page."
704 void offer_start_page(void) {
705 wprintf("<A HREF=\"/change_start_page?startpage=");
706 urlescputs(WC->this_page);
708 "<FONT SIZE=-2 COLOR=\"#AAAAAA\">Make this my start page</FONT>"
715 * Change the user's start page
717 void change_start_page(void) {
719 if (bstr("startpage") == NULL) {
720 strcpy(WC->ImportantMessage,
721 "startpage set to null");
726 set_preference("startpage", bstr("startpage"));
728 output_headers(1, 1, 0, 0, 0, 0, 0);
729 do_template("newstartpage");
736 void display_success(char *successmessage)
738 convenience_page("007700", "OK", successmessage);
743 void extract_action(char *actbuf, char *cmdbuf)
747 strcpy(actbuf, cmdbuf);
750 * First strip out the http method
752 remove_token(actbuf, 0, ' ');
753 if (actbuf[0] == ' ') strcpy(actbuf, &actbuf[1]);
754 if (actbuf[0] == '/') strcpy(actbuf, &actbuf[1]);
757 * Now kill invalid (for webcit) characters
759 for (i = 0; i < strlen(actbuf); ++i) {
760 if (actbuf[i] == ' ') {
764 if (actbuf[i] == '/') {
768 if (actbuf[i] == '?') {
772 if (actbuf[i] == '&') {
780 void upload_handler(char *name, char *filename, char *partnum, char *disp,
781 void *content, char *cbtype, size_t length,
782 char *encoding, void *userdata)
784 struct urlcontent *u;
787 if ( (length > 0) && (strlen(cbtype) == 0) ) {
788 u = (struct urlcontent *) malloc(sizeof(struct urlcontent));
789 u->next = WC->urlstrings;
791 safestrncpy(u->url_key, name, sizeof(u->url_key));
792 u->url_data = malloc(length + 1);
793 memcpy(u->url_data, content, length);
794 u->url_data[length] = 0;
798 if ( (length > 0) && (strlen(cbtype) > 0) ) {
799 WC->upload = malloc(length);
800 if (WC->upload != NULL) {
801 WC->upload_length = length;
802 safestrncpy(WC->upload_filename, filename,
803 sizeof(WC->upload_filename));
804 safestrncpy(WC->upload_content_type, cbtype,
805 sizeof(WC->upload_content_type));
806 memcpy(WC->upload, content, length);
809 lprintf(3, "malloc() failed: %s\n", strerror(errno));
819 * Entry point for WebCit transaction
821 void session_loop(struct httprequest *req)
828 int ContentLength = 0;
830 char ContentType[512];
831 char *content = NULL;
832 char *content_end = NULL;
833 struct httprequest *hptr;
834 char browser_host[SIZ];
835 char user_agent[SIZ];
838 /* We stuff these with the values coming from the client cookies,
839 * so we can use them to reconnect a timed out session if we have to.
841 char c_username[SIZ];
842 char c_password[SIZ];
843 char c_roomname[SIZ];
844 char c_httpauth_string[SIZ];
845 char c_httpauth_user[SIZ];
846 char c_httpauth_pass[SIZ];
849 strcpy(c_username, "");
850 strcpy(c_password, "");
851 strcpy(c_roomname, "");
852 strcpy(c_httpauth_string, "");
853 strcpy(c_httpauth_user, "");
854 strcpy(c_httpauth_pass, "");
856 WC->upload_length = 0;
863 if (hptr == NULL) return;
865 strcpy(cmd, hptr->line);
867 extract_token(method, cmd, 0, ' ');
868 extract_action(action, cmd);
870 while (hptr != NULL) {
871 strcpy(buf, hptr->line);
874 if (!strncasecmp(buf, "Cookie: webcit=", 15)) {
875 safestrncpy(cookie, &buf[15], sizeof cookie);
876 cookie_to_stuff(cookie, NULL,
877 c_username, c_password, c_roomname);
879 else if (!strncasecmp(buf, "Authorization: Basic ", 21)) {
880 CtdlDecodeBase64(c_httpauth_string, &buf[21], strlen(&buf[21]));
881 extract_token(c_httpauth_user, c_httpauth_string, 0, ':');
882 extract_token(c_httpauth_pass, c_httpauth_string, 1, ':');
884 else if (!strncasecmp(buf, "Content-length: ", 16)) {
885 ContentLength = atoi(&buf[16]);
887 else if (!strncasecmp(buf, "Content-type: ", 14)) {
888 safestrncpy(ContentType, &buf[14], sizeof ContentType);
890 else if (!strncasecmp(buf, "User-agent: ", 12)) {
891 safestrncpy(user_agent, &buf[12], sizeof user_agent);
893 else if (!strncasecmp(buf, "Host: ", 6)) {
894 safestrncpy(WC->http_host, &buf[6], sizeof WC->http_host);
896 /* Only WAP gateways explicitly name this content-type */
897 else if (strstr(buf, "text/vnd.wap.wml")) {
902 if (ContentLength > 0) {
903 content = malloc(ContentLength + SIZ);
904 memset(content, 0, ContentLength + SIZ);
905 sprintf(content, "Content-type: %s\n"
906 "Content-length: %d\n\n",
907 ContentType, ContentLength);
908 body_start = strlen(content);
910 /* Be daring and read it all at once. */
911 client_read(WC->http_sock, &content[BytesRead+body_start],
914 if (!strncasecmp(ContentType,
915 "application/x-www-form-urlencoded", 33)) {
916 addurls(&content[body_start]);
917 } else if (!strncasecmp(ContentType, "multipart", 9)) {
918 content_end = content + ContentLength + body_start;
919 mime_parser(content, content_end, *upload_handler,
920 NULL, NULL, NULL, 0);
926 /* make a note of where we are in case the user wants to save it */
927 safestrncpy(WC->this_page, cmd, sizeof(WC->this_page));
928 remove_token(WC->this_page, 2, ' ');
929 remove_token(WC->this_page, 0, ' ');
931 /* If there are variables in the URL, we must grab them now */
932 for (a = 0; a < strlen(cmd); ++a) {
933 if ((cmd[a] == '?') || (cmd[a] == '&')) {
934 for (b = a; b < strlen(cmd); ++b)
937 addurls(&cmd[a + 1]);
942 /* Static content can be sent without connecting to Citadel. */
943 if (!strcasecmp(action, "static")) {
944 strcpy(buf, &cmd[12]);
945 for (a = 0; a < strlen(buf); ++a)
949 goto SKIP_ALL_THIS_CRAP; /* Don't try to connect */
953 * If we're not connected to a Citadel server, try to hook up the
956 if (!WC->connected) {
957 if (!strcasecmp(ctdlhost, "uds")) {
958 /* unix domain socket */
959 sprintf(buf, "%s/citadel.socket", ctdlport);
960 WC->serv_sock = uds_connectsock(buf);
964 WC->serv_sock = tcp_connectsock(ctdlhost, ctdlport);
967 if (WC->serv_sock < 0) {
969 goto SKIP_ALL_THIS_CRAP;
973 serv_gets(buf); /* get the server welcome message */
974 locate_host(browser_host, WC->http_sock);
975 get_serv_info(browser_host, user_agent);
976 if (serv_info.serv_rev_level < MINIMUM_CIT_VERSION) {
977 wprintf("You are connected to a Citadel "
978 "server running Citadel %d.%02d;\nin "
979 "order to run this version of WebCit "
980 "you must also have Citadel %d.%02d or"
982 serv_info.serv_rev_level / 100,
983 serv_info.serv_rev_level % 100,
984 MINIMUM_CIT_VERSION / 100,
985 MINIMUM_CIT_VERSION % 100
987 end_webcit_session();
988 goto SKIP_ALL_THIS_CRAP;
994 * Functions which can be performed without logging in
996 if (!strcasecmp(action, "listsub")) {
998 goto SKIP_ALL_THIS_CRAP;
1000 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
1001 if (!strcasecmp(action, "freebusy")) {
1003 goto SKIP_ALL_THIS_CRAP;
1008 * If we're not logged in, but we have HTTP Authentication data,
1009 * try logging in to Citadel using that.
1011 if ((!WC->logged_in)
1012 && (strlen(c_httpauth_user) > 0)
1013 && (strlen(c_httpauth_pass) > 0)) {
1014 serv_printf("USER %s", c_httpauth_user);
1016 if (buf[0] == '3') {
1017 serv_printf("PASS %s", c_httpauth_pass);
1019 if (buf[0] == '2') {
1020 become_logged_in(c_httpauth_user,
1021 c_httpauth_pass, buf);
1022 strcpy(WC->httpauth_user, c_httpauth_user);
1023 strcpy(WC->httpauth_pass, c_httpauth_pass);
1029 * The GroupDAV stuff relies on HTTP authentication instead of
1030 * our session's authentication.
1032 if (!strncasecmp(action, "groupdav", 8)) {
1033 groupdav_main(req, ContentType, /* do GroupDAV methods */
1034 ContentLength, content+body_start);
1035 if (!WC->logged_in) {
1036 WC->killthis = 1; /* If not logged in, don't */
1037 } /* keep the session active */
1038 goto SKIP_ALL_THIS_CRAP;
1041 check_for_instant_messages();
1044 * If we're not logged in, but we have username and password cookies
1045 * supplied by the browser, try using them to log in.
1047 if ((!WC->logged_in)
1048 && (strlen(c_username) > 0)
1049 && (strlen(c_password) > 0)) {
1050 serv_printf("USER %s", c_username);
1052 if (buf[0] == '3') {
1053 serv_printf("PASS %s", c_password);
1055 if (buf[0] == '2') {
1056 become_logged_in(c_username, c_password, buf);
1061 * If we don't have a current room, but a cookie specifying the
1062 * current room is supplied, make an effort to go there.
1064 if ((strlen(WC->wc_roomname) == 0) && (strlen(c_roomname) > 0)) {
1065 serv_printf("GOTO %s", c_roomname);
1067 if (buf[0] == '2') {
1068 strcpy(WC->wc_roomname, c_roomname);
1072 if (!strcasecmp(action, "image")) {
1076 * All functions handled below this point ... make sure we log in
1077 * before doing anything else!
1079 } else if ((!WC->logged_in) && (!strcasecmp(action, "login"))) {
1081 } else if (!WC->logged_in) {
1082 display_login(NULL);
1086 * Various commands...
1089 else if (!strcasecmp(action, "do_welcome")) {
1091 } else if (!strcasecmp(action, "blank")) {
1093 } else if (!strcasecmp(action, "do_template")) {
1095 } else if (!strcasecmp(action, "display_main_menu")) {
1096 display_main_menu();
1097 } else if (!strcasecmp(action, "whobbs")) {
1099 } else if (!strcasecmp(action, "knrooms")) {
1101 } else if (!strcasecmp(action, "gotonext")) {
1104 } else if (!strcasecmp(action, "skip")) {
1106 } else if (!strcasecmp(action, "ungoto")) {
1108 } else if (!strcasecmp(action, "dotgoto")) {
1110 smart_goto(bstr("room"));
1111 } else if (!strcasecmp(action, "dotskip")) {
1112 smart_goto(bstr("room"));
1113 } else if (!strcasecmp(action, "termquit")) {
1115 } else if (!strcasecmp(action, "readnew")) {
1116 readloop("readnew");
1117 } else if (!strcasecmp(action, "readold")) {
1118 readloop("readold");
1119 } else if (!strcasecmp(action, "readfwd")) {
1120 readloop("readfwd");
1121 } else if (!strcasecmp(action, "headers")) {
1122 readloop("headers");
1123 } else if (!strcasecmp(action, "display_enter")) {
1125 } else if (!strcasecmp(action, "post")) {
1127 } else if (!strcasecmp(action, "do_stuff_to_one_msg")) {
1128 do_stuff_to_one_msg();
1129 } else if (!strcasecmp(action, "move_msg")) {
1131 } else if (!strcasecmp(action, "userlist")) {
1133 } else if (!strcasecmp(action, "showuser")) {
1135 } else if (!strcasecmp(action, "display_page")) {
1137 } else if (!strcasecmp(action, "page_user")) {
1139 } else if (!strcasecmp(action, "chat")) {
1141 } else if (!strcasecmp(action, "display_private")) {
1142 display_private("", 0);
1143 } else if (!strcasecmp(action, "goto_private")) {
1145 } else if (!strcasecmp(action, "zapped_list")) {
1147 } else if (!strcasecmp(action, "display_zap")) {
1149 } else if (!strcasecmp(action, "zap")) {
1151 } else if (!strcasecmp(action, "display_entroom")) {
1153 } else if (!strcasecmp(action, "entroom")) {
1155 } else if (!strcasecmp(action, "display_editroom")) {
1157 } else if (!strcasecmp(action, "netedit")) {
1159 } else if (!strcasecmp(action, "editroom")) {
1161 } else if (!strcasecmp(action, "display_whok")) {
1163 } else if (!strcasecmp(action, "display_editinfo")) {
1164 display_edit("Room info", "EINF 0", "RINF", "/editinfo", 1);
1165 } else if (!strcasecmp(action, "editinfo")) {
1166 save_edit("Room info", "EINF 1", 1);
1167 } else if (!strcasecmp(action, "display_editbio")) {
1168 sprintf(buf, "RBIO %s", WC->wc_username);
1169 display_edit("Your bio", "NOOP", buf, "editbio", 3);
1170 } else if (!strcasecmp(action, "editbio")) {
1171 save_edit("Your bio", "EBIO", 0);
1172 } else if (!strcasecmp(action, "confirm_delete_room")) {
1173 confirm_delete_room();
1174 } else if (!strcasecmp(action, "delete_room")) {
1176 } else if (!strcasecmp(action, "validate")) {
1178 } else if (!strcasecmp(action, "display_editpic")) {
1179 display_graphics_upload("your photo",
1182 } else if (!strcasecmp(action, "editpic")) {
1183 do_graphics_upload("UIMG 1|_userpic_");
1184 } else if (!strcasecmp(action, "display_editroompic")) {
1185 display_graphics_upload("the graphic for this room",
1188 } else if (!strcasecmp(action, "editroompic")) {
1189 do_graphics_upload("UIMG 1|_roompic_");
1190 } else if (!strcasecmp(action, "delete_floor")) {
1192 } else if (!strcasecmp(action, "rename_floor")) {
1194 } else if (!strcasecmp(action, "create_floor")) {
1196 } else if (!strcasecmp(action, "display_editfloorpic")) {
1197 sprintf(buf, "UIMG 0|_floorpic_|%s",
1198 bstr("which_floor"));
1199 display_graphics_upload("the graphic for this floor",
1202 } else if (!strcasecmp(action, "editfloorpic")) {
1203 sprintf(buf, "UIMG 1|_floorpic_|%s",
1204 bstr("which_floor"));
1205 do_graphics_upload(buf);
1206 } else if (!strcasecmp(action, "display_reg")) {
1208 } else if (!strcasecmp(action, "display_changepw")) {
1210 } else if (!strcasecmp(action, "changepw")) {
1212 } else if (!strcasecmp(action, "display_edit_node")) {
1213 display_edit_node();
1214 } else if (!strcasecmp(action, "edit_node")) {
1216 } else if (!strcasecmp(action, "display_netconf")) {
1218 } else if (!strcasecmp(action, "display_confirm_delete_node")) {
1219 display_confirm_delete_node();
1220 } else if (!strcasecmp(action, "delete_node")) {
1222 } else if (!strcasecmp(action, "display_add_node")) {
1224 } else if (!strcasecmp(action, "add_node")) {
1226 } else if (!strcasecmp(action, "terminate_session")) {
1228 terminate_session();
1229 } else if (!strcasecmp(action, "edit_me")) {
1231 } else if (!strcasecmp(action, "display_siteconfig")) {
1232 display_siteconfig();
1233 } else if (!strcasecmp(action, "chat_recv")) {
1235 } else if (!strcasecmp(action, "chat_send")) {
1237 } else if (!strcasecmp(action, "siteconfig")) {
1239 } else if (!strcasecmp(action, "display_generic")) {
1241 } else if (!strcasecmp(action, "do_generic")) {
1243 } else if (!strcasecmp(action, "display_menubar")) {
1245 } else if (!strcasecmp(action, "output_mimepart")) {
1247 } else if (!strcasecmp(action, "edit_vcard")) {
1249 } else if (!strcasecmp(action, "submit_vcard")) {
1251 } else if (!strcasecmp(action, "select_user_to_edit")) {
1252 select_user_to_edit(NULL, NULL);
1253 } else if (!strcasecmp(action, "display_edituser")) {
1254 display_edituser(NULL, 0);
1255 } else if (!strcasecmp(action, "edituser")) {
1257 } else if (!strcasecmp(action, "create_user")) {
1259 } else if (!strcasecmp(action, "changeview")) {
1261 } else if (!strcasecmp(action, "do_stuff_to_msgs")) {
1263 } else if (!strcasecmp(action, "change_start_page")) {
1264 change_start_page();
1265 } else if (!strcasecmp(action, "display_floorconfig")) {
1266 display_floorconfig(NULL);
1267 } else if (!strcasecmp(action, "toggle_self_service")) {
1268 toggle_self_service();
1269 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
1270 } else if (!strcasecmp(action, "display_edit_task")) {
1271 display_edit_task();
1272 } else if (!strcasecmp(action, "save_task")) {
1274 } else if (!strcasecmp(action, "display_edit_event")) {
1275 display_edit_event();
1276 } else if (!strcasecmp(action, "save_event")) {
1278 } else if (!strcasecmp(action, "respond_to_request")) {
1279 respond_to_request();
1280 } else if (!strcasecmp(action, "handle_rsvp")) {
1283 } else if (!strcasecmp(action, "summary")) {
1285 } else if (!strcasecmp(action, "iconbar")) {
1287 } else if (!strcasecmp(action, "display_customize_iconbar")) {
1288 display_customize_iconbar();
1289 } else if (!strcasecmp(action, "commit_iconbar")) {
1291 } else if (!strcasecmp(action, "set_room_policy")) {
1293 } else if (!strcasecmp(action, "display_inetconf")) {
1295 } else if (!strcasecmp(action, "save_inetconf")) {
1297 } else if (!strcasecmp(action, "diagnostics")) {
1298 output_headers(1, 1, 1, 0, 0, 0, 0);
1300 wprintf("You're in session %d<hr />\n", WC->wc_session);
1301 wprintf("Command: <br /><PRE>\n");
1303 wprintf("</PRE><hr />\n");
1304 wprintf("Variables: <br /><PRE>\n");
1306 wprintf("</PRE><hr />\n");
1309 /* When all else fais, display the main menu. */
1311 display_main_menu();
1316 if (content != NULL) {
1321 if (WC->upload_length > 0) {
1323 WC->upload_length = 0;