4 * This is the actual program called by the webserver. It maintains a
5 * persistent session to the Citadel server, handling HTTP WebCit requests as
6 * they arrive and presenting a user interface.
17 #include <sys/types.h>
19 #include <sys/socket.h>
23 #include <netinet/in.h>
33 #include "webserver.h"
34 #include "mime_parser.h"
37 * String to unset the cookie.
38 * Any date "in the past" will work, so I chose my birthday, right down to
39 * the exact minute. :)
41 static char *unset = "; expires=28-May-1971 18:10:00 GMT";
43 void unescape_input(char *buf)
48 while ((isspace(buf[strlen(buf) - 1])) && (strlen(buf) > 0))
49 buf[strlen(buf) - 1] = 0;
51 for (a = 0; a < strlen(buf); ++a) {
59 sscanf(hex, "%02x", &b);
61 strcpy(&buf[a + 1], &buf[a + 3]);
68 void addurls(char *url)
76 while (strlen(up) > 0) {
78 /* locate the = sign */
79 safestrncpy(buf, up, sizeof buf);
81 for (a = 255; a >= 0; --a)
88 u = (struct urlcontent *) malloc(sizeof(struct urlcontent));
89 u->next = WC->urlstrings;
91 strcpy(u->url_key, buf);
93 /* now chop that part off */
94 for (a = 0; a <= b; ++a)
97 /* locate "&" and "?" delimiters */
100 for (a = 0; a < strlen(up); ++a) {
101 if ( (ptr[0] == '&') || (ptr[0] == '?') ) {
108 for (a = 0; a < b; ++a)
112 u->url_data = malloc(strlen(up) + 2);
113 strcpy(u->url_data, up);
115 unescape_input(u->url_data);
123 struct urlcontent *u;
125 while (WC->urlstrings != NULL) {
126 free(WC->urlstrings->url_data);
127 u = WC->urlstrings->next;
128 free(WC->urlstrings);
134 * Diagnostic function to display the contents of all variables
138 struct urlcontent *u;
140 for (u = WC->urlstrings; u != NULL; u = u->next) {
141 wprintf("%38s = %s\n", u->url_key, u->url_data);
145 char *bstr(char *key)
147 struct urlcontent *u;
149 for (u = WC->urlstrings; u != NULL; u = u->next) {
150 if (!strcasecmp(u->url_key, key))
151 return (u->url_data);
157 void wprintf(const char *format,...)
162 va_start(arg_ptr, format);
163 vsnprintf(wbuf, sizeof wbuf, format, arg_ptr);
166 client_write(wbuf, strlen(wbuf));
171 * wDumpContent() wraps up an HTTP session, closes tags, etc.
173 * print_standard_html_footer should be set to 0 to transmit only, 1 to
174 * append the main menu and closing tags, or 2 to
175 * append the closing tags only.
177 void wDumpContent(int print_standard_html_footer)
179 if (print_standard_html_footer) {
180 wprintf("</DIV>\n"); /* end of "text" div */
181 do_template("trailing");
188 * Copy a string, escaping characters which have meaning in HTML. If
189 * nbsp is nonzero, spaces are converted to non-breaking spaces.
191 void stresc(char *target, char *strbuf, int nbsp, int nolinebreaks)
196 for (a = 0; a < strlen(strbuf); ++a) {
197 if (strbuf[a] == '<')
198 strcat(target, "<");
199 else if (strbuf[a] == '>')
200 strcat(target, ">");
201 else if (strbuf[a] == '&')
202 strcat(target, "&");
203 else if (strbuf[a] == '\"')
204 strcat(target, """);
205 else if (strbuf[a] == '\'')
206 strcat(target, "'");
207 else if (strbuf[a] == LB)
209 else if (strbuf[a] == RB)
211 else if (strbuf[a] == QU)
212 strcat(target, "\"");
213 else if ((strbuf[a] == 32) && (nbsp == 1))
214 strcat(target, " ");
215 else if ((strbuf[a] == '\n') && (nolinebreaks))
216 strcat(target, ""); /* nothing */
217 else if ((strbuf[a] == '\r') && (nolinebreaks))
218 strcat(target, ""); /* nothing */
220 strncat(target, &strbuf[a], 1);
224 void escputs1(char *strbuf, int nbsp, int nolinebreaks)
228 if (strbuf == NULL) return;
229 buf = malloc( (3 * strlen(strbuf)) + SIZ );
230 stresc(buf, strbuf, nbsp, nolinebreaks);
235 void escputs(char *strbuf)
237 escputs1(strbuf, 0, 0);
241 * Escape a string for feeding out as a URL.
242 * Returns a pointer to a buffer that must be freed by the caller!
244 void urlesc(char *outbuf, char *strbuf)
247 char *ec = " #&;`'|*?-~<>^()[]{}$\\";
251 for (a = 0; a < strlen(strbuf); ++a) {
253 for (b = 0; b < strlen(ec); ++b) {
254 if (strbuf[a] == ec[b])
259 sprintf(&outbuf[b], "%%%02x", strbuf[a]);
261 sprintf(&outbuf[b], "%c", strbuf[a]);
265 void urlescputs(char *strbuf)
269 urlesc(outbuf, strbuf);
270 wprintf("%s", outbuf);
275 * Copy a string, escaping characters for JavaScript strings.
277 void jsesc(char *target, char *strbuf)
282 for (a = 0; a < strlen(strbuf); ++a) {
283 if (strbuf[a] == '<')
285 else if (strbuf[a] == '>')
287 else if (strbuf[a] == '\"')
288 strcat(target, """);
289 else if (strbuf[a] == '&')
290 strcat(target, "&;");
291 else if (strbuf[a] == '\'')
292 strcat(target, "\\'");
294 strncat(target, &strbuf[a], 1);
299 void jsescputs(char *strbuf)
303 jsesc(outbuf, strbuf);
304 wprintf("%s", outbuf);
308 * Copy a string, escaping characters for message text hold
310 void msgesc(char *target, char *strbuf)
315 for (a = 0; a < strlen(strbuf); ++a) {
316 if (strbuf[a] == '\'')
317 strcat(target, "\\'");
318 else if (strbuf[a] == '\n')
320 else if (strbuf[a] == '\r')
323 strncat(target, &strbuf[a], 1);
328 void msgescputs(char *strbuf) {
331 if (strbuf == NULL) return;
332 outbuf = malloc( (3 * strlen(strbuf)) + SIZ);
333 msgesc(outbuf, strbuf);
334 wprintf("%s", outbuf);
342 * Output all that important stuff that the browser will want to see
344 void output_headers( int do_httpheaders, /* 1 = output HTTP headers */
345 int do_htmlhead, /* 1 = output HTML <head> section and <body> opener */
347 int do_room_banner, /* 0=no, 1=yes, */
348 /* 2 = I'm going to embed my own, so don't open the */
349 /* <div id="text"> either. */
351 int unset_cookies, /* 1 = session is terminating, so unset the cookies */
352 int refresh30, /* 1 = automatically refresh page every 30 seconds */
353 int suppress_check, /* 1 = suppress check for instant messages */
354 int cache /* 1 = allow browser to cache this page */
359 wprintf("HTTP/1.0 200 OK\n");
360 httpdate(httpnow, time(NULL));
362 if (do_httpheaders) {
363 wprintf("Content-type: text/html\n"
364 "Server: %s / %s\n", SERVER, serv_info.serv_software
367 wprintf("Connection: close\n"
369 "Cache-Control: no-store\n"
373 stuff_to_cookie(cookie, WC->wc_session, WC->wc_username,
374 WC->wc_password, WC->wc_roomname);
377 wprintf("Set-cookie: webcit=%s; path=/\n", unset);
379 wprintf("Set-cookie: webcit=%s; path=/\n", cookie);
380 if (server_cookie != NULL) {
381 wprintf("%s\n", server_cookie);
389 svprintf("REFRESHTAG", WCS_STRING, "%s",
390 "<meta http-equiv=\"refresh\" content=\"30\" />\n");
393 svprintf("REFRESHTAG", WCS_STRING, "%s",
394 "<meta http-equiv=\"refresh\" content=\"500363689;\" />\n");
403 if (WC->HaveInstantMessages) {
404 wprintf("<div id=\"page_popup\">\n");
408 if ( (WC->logged_in) && (!unset_cookies) ) {
409 wprintf("<div id=\"iconbar\">");
413 if (do_room_banner == 1) {
414 wprintf("<div id=\"banner\">\n");
415 embed_room_banner(NULL, navbar_default);
420 if (do_room_banner != 2) {
421 wprintf("<div id=\"content\">\n");
424 if (strlen(WC->ImportantMessage) > 0) {
425 do_template("beginbox_nt");
426 wprintf("<SPAN CLASS=\"errormsg\">"
427 "%s</SPAN><br />\n", WC->ImportantMessage);
428 do_template("endbox");
429 strcpy(WC->ImportantMessage, "");
437 * Generic function to do an HTTP redirect. Easy and fun.
439 void http_redirect(char *whichpage) {
440 wprintf("HTTP/1.0 302 Moved Temporarily\n");
441 wprintf("Location: %s\n", whichpage);
442 wprintf("URI: %s\n", whichpage);
443 wprintf("Content-type: text/html\n\n");
444 wprintf("<html><body>\n");
445 wprintf("you really want to be <A HREF=\"%s\">here</A> now\n",
447 wprintf("</body></html>\n");
452 void check_for_instant_messages()
458 if (buf[3] == '*') WC->HaveInstantMessages = 1;
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", 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;