]> code.citadel.org Git - citadel.git/blobdiff - webcit/webcit.c
* Removed the last couple of places where forms were submitted using
[citadel.git] / webcit / webcit.c
index af8b4fbd73f2d982b69561eb4bc8534851e563c8..3dc05c5fd969c8d559104c3b6060a0bd9f0dd4da 100644 (file)
@@ -87,7 +87,7 @@ void addurls(char *url)
                u = (struct urlcontent *) malloc(sizeof(struct urlcontent));
                u->next = WC->urlstrings;
                WC->urlstrings = u;
-               strcpy(u->url_key, buf);
+               safestrncpy(u->url_key, buf, sizeof u->url_key);
 
                /* now chop that part off */
                for (a = 0; a <= b; ++a)
@@ -109,7 +109,7 @@ void addurls(char *url)
                strcpy(ptr, "");
 
                u->url_data = malloc(strlen(up) + 2);
-               strcpy(u->url_data, up);
+               safestrncpy(u->url_data, up, strlen(up) + 1);
                u->url_data[b] = 0;
                unescape_input(u->url_data);
                up = ptr;
@@ -363,7 +363,7 @@ void output_headers(        int do_httpheaders,     /* 1 = output HTTP headers
        httpdate(httpnow, time(NULL));
 
        if (do_httpheaders) {
-               wprintf("Content-type: text/html\r\n"
+               wprintf("Content-type: text/html; charset=utf-8\r\n"
                        "Server: %s / %s\n"
                        "Connection: close\r\n",
                        SERVER, serv_info.serv_software
@@ -441,7 +441,7 @@ void output_headers(        int do_httpheaders,     /* 1 = output HTTP headers
                                "%s</SPAN><br />\n", WC->ImportantMessage);
                        do_template("endbox");
                        wprintf("</div>\n");
-                       strcpy(WC->ImportantMessage, "");
+                       safestrncpy(WC->ImportantMessage, "", sizeof WC->ImportantMessage);
                }
 
        }
@@ -455,7 +455,7 @@ void http_redirect(char *whichpage) {
        wprintf("HTTP/1.0 302 Moved Temporarily\n");
        wprintf("Location: %s\r\n", whichpage);
        wprintf("URI: %s\r\n", whichpage);
-       wprintf("Content-type: text/html\r\n\r\n");
+       wprintf("Content-type: text/html; charset=utf-8\r\n\r\n");
        wprintf("<html><body>\n");
        wprintf("you really want to be <A HREF=\"%s\">here</A> now\n",
                whichpage);
@@ -528,12 +528,12 @@ void http_transmit_thing(char *thing, size_t length, char *content_type,
 
 void output_static(char *what)
 {
-       char buf[4096];
+       char buf[256];
        FILE *fp;
        struct stat statbuf;
        off_t bytes;
        char *bigbuffer;
-       char content_type[SIZ];
+       char content_type[128];
 
        sprintf(buf, "static/%s", what);
        fp = fopen(buf, "rb");
@@ -544,40 +544,38 @@ void output_static(char *what)
                wprintf("Cannot open %s: %s\n", what, strerror(errno));
        } else {
                if (!strncasecmp(&what[strlen(what) - 4], ".gif", 4))
-                       strcpy(content_type, "image/gif");
+                       safestrncpy(content_type, "image/gif", sizeof content_type);
                else if (!strncasecmp(&what[strlen(what) - 4], ".txt", 4))
-                       strcpy(content_type, "text/plain");
+                       safestrncpy(content_type, "text/plain", sizeof content_type);
                else if (!strncasecmp(&what[strlen(what) - 4], ".css", 4))
-                       strcpy(content_type, "text/css");
+                       safestrncpy(content_type, "text/css", sizeof content_type);
                else if (!strncasecmp(&what[strlen(what) - 4], ".jpg", 4))
-                       strcpy(content_type, "image/jpeg");
+                       safestrncpy(content_type, "image/jpeg", sizeof content_type);
                else if (!strncasecmp(&what[strlen(what) - 4], ".png", 4))
-                       strcpy(content_type, "image/png");
+                       safestrncpy(content_type, "image/png", sizeof content_type);
                else if (!strncasecmp(&what[strlen(what) - 4], ".ico", 4))
-                       strcpy(content_type, "image/x-icon");
+                       safestrncpy(content_type, "image/x-icon", sizeof content_type);
                else if (!strncasecmp(&what[strlen(what) - 5], ".html", 5))
-                       strcpy(content_type, "text/html");
+                       safestrncpy(content_type, "text/html", sizeof content_type);
                else if (!strncasecmp(&what[strlen(what) - 4], ".htm", 4))
-                       strcpy(content_type, "text/html");
+                       safestrncpy(content_type, "text/html", sizeof content_type);
                else if (!strncasecmp(&what[strlen(what) - 4], ".wml", 4))
-                       strcpy(content_type, "text/vnd.wap.wml");
+                       safestrncpy(content_type, "text/vnd.wap.wml", sizeof content_type);
                else if (!strncasecmp(&what[strlen(what) - 5], ".wmls", 5))
-                       strcpy(content_type, "text/vnd.wap.wmlscript");
+                       safestrncpy(content_type, "text/vnd.wap.wmlscript", sizeof content_type);
                else if (!strncasecmp(&what[strlen(what) - 5], ".wmlc", 5))
-                       strcpy(content_type, "application/vnd.wap.wmlc");
+                       safestrncpy(content_type, "application/vnd.wap.wmlc", sizeof content_type);
                else if (!strncasecmp(&what[strlen(what) - 6], ".wmlsc", 6))
-                       strcpy(content_type, "application/vnd.wap.wmlscriptc");
+                       safestrncpy(content_type, "application/vnd.wap.wmlscriptc", sizeof content_type);
                else if (!strncasecmp(&what[strlen(what) - 5], ".wbmp", 5))
-                       strcpy(content_type, "image/vnd.wap.wbmp");
+                       safestrncpy(content_type, "image/vnd.wap.wbmp", sizeof content_type);
                else if (!strncasecmp(&what[strlen(what) - 3], ".js", 3))
-                       strcpy(content_type, "text/javascript");
+                       safestrncpy(content_type, "text/javascript", sizeof content_type);
                else
-                       strcpy(content_type, "application/octet-stream");
+                       safestrncpy(content_type, "application/octet-stream", sizeof content_type);
 
                fstat(fileno(fp), &statbuf);
                bytes = statbuf.st_size;
-               /* lprintf(3, "Static: %s, (%s; %ld bytes)\r\n",
-                       what, content_type, bytes); */
                bigbuffer = malloc(bytes + 2);
                fread(bigbuffer, bytes, 1, fp);
                fclose(fp);
@@ -757,13 +755,14 @@ void offer_start_page(void) {
 void change_start_page(void) {
 
        if (bstr("startpage") == NULL) {
-               strcpy(WC->ImportantMessage,
-                       "startpage set to null");
+               safestrncpy(WC->ImportantMessage,
+                       "startpage set to null",
+                       sizeof WC->ImportantMessage);
                display_main_menu();
                return;
        }
 
-       set_preference("startpage", bstr("startpage"));
+       set_preference("startpage", bstr("startpage"), 1);
 
        output_headers(1, 1, 0, 0, 0, 0, 0);
        do_template("newstartpage");
@@ -818,11 +817,14 @@ void extract_action(char *actbuf, char *cmdbuf)
 
 
 void upload_handler(char *name, char *filename, char *partnum, char *disp,
-                       void *content, char *cbtype, size_t length,
-                       char *encoding, void *userdata)
+                       void *content, char *cbtype, char *cbcharset,
+                       size_t length, char *encoding, void *userdata)
 {
        struct urlcontent *u;
 
+       lprintf(9, "upload_handler() name=%s, type=%s, len=%d\n",
+               name, cbtype, length);
+
        /* Form fields */
        if ( (length > 0) && (strlen(cbtype) == 0) ) {
                u = (struct urlcontent *) malloc(sizeof(struct urlcontent));
@@ -886,12 +888,12 @@ void session_loop(struct httprequest *req)
        char c_httpauth_pass[SIZ];
        char cookie[SIZ];
 
-       strcpy(c_username, "");
-       strcpy(c_password, "");
-       strcpy(c_roomname, "");
-       strcpy(c_httpauth_string, "");
-       strcpy(c_httpauth_user, DEFAULT_HTTPAUTH_USER);
-       strcpy(c_httpauth_pass, DEFAULT_HTTPAUTH_PASS);
+       safestrncpy(c_username, "", sizeof c_username);
+       safestrncpy(c_password, "", sizeof c_password);
+       safestrncpy(c_roomname, "", sizeof c_roomname);
+       safestrncpy(c_httpauth_string, "", sizeof c_httpauth_string);
+       safestrncpy(c_httpauth_user, DEFAULT_HTTPAUTH_USER, sizeof c_httpauth_user);
+       safestrncpy(c_httpauth_pass, DEFAULT_HTTPAUTH_PASS, sizeof c_httpauth_pass);
 
        WC->upload_length = 0;
        WC->upload = NULL;
@@ -902,13 +904,13 @@ void session_loop(struct httprequest *req)
        hptr = req;
        if (hptr == NULL) return;
 
-       strcpy(cmd, hptr->line);
+       safestrncpy(cmd, hptr->line, sizeof cmd);
        hptr = hptr->next;
        extract_token(method, cmd, 0, ' ', sizeof method);
        extract_action(action, cmd);
 
        while (hptr != NULL) {
-               strcpy(buf, hptr->line);
+               safestrncpy(buf, hptr->line, sizeof buf);
                hptr = hptr->next;
 
                if (!strncasecmp(buf, "Cookie: webcit=", 15)) {
@@ -949,7 +951,7 @@ void session_loop(struct httprequest *req)
                                ContentType, ContentLength);
                body_start = strlen(content);
 
-               /* Be daring and read it all at once. */
+               /* Read the entire input data at once. */
                client_read(WC->http_sock, &content[BytesRead+body_start],
                        ContentLength);
 
@@ -983,7 +985,7 @@ void session_loop(struct httprequest *req)
 
        /* Static content can be sent without connecting to Citadel. */
        if (!strcasecmp(action, "static")) {
-               strcpy(buf, &cmd[12]);
+               safestrncpy(buf, &cmd[12], sizeof buf);
                for (a = 0; a < strlen(buf); ++a)
                        if (isspace(buf[a]))
                                buf[a] = 0;
@@ -1061,8 +1063,8 @@ void session_loop(struct httprequest *req)
                        if (buf[0] == '2') {
                                become_logged_in(c_httpauth_user,
                                                c_httpauth_pass, buf);
-                               strcpy(WC->httpauth_user, c_httpauth_user);
-                               strcpy(WC->httpauth_pass, c_httpauth_pass);
+                               safestrncpy(WC->httpauth_user, c_httpauth_user, sizeof WC->httpauth_user);
+                               safestrncpy(WC->httpauth_pass, c_httpauth_pass, sizeof WC->httpauth_pass);
                        }
                }
        }
@@ -1082,14 +1084,15 @@ void session_loop(struct httprequest *req)
 
 
        /*
-        * If this isn't a GroupDAV session, it's an ordinary browser
-        * connecting to the user interface.  Only allow GET and POST
-        * methods.
+        * Automatically send requests with any method other than GET or
+        * POST to the GroupDAV code as well.
         */
        if ((strcasecmp(method, "GET")) && (strcasecmp(method, "POST"))) {
-               wprintf("HTTP/1.1 405 Method Not Allowed\r\n");
-               groupdav_common_headers();
-               wprintf("Content-Length: 0\r\n\r\n");
+               groupdav_main(req, ContentType, /* do GroupDAV methods */
+                       ContentLength, content+body_start);
+               if (!WC->logged_in) {
+                       WC->killthis = 1;       /* If not logged in, don't */
+               }                               /* keep the session active */
                goto SKIP_ALL_THIS_CRAP;
        }
 
@@ -1118,7 +1121,7 @@ void session_loop(struct httprequest *req)
                serv_printf("GOTO %s", c_roomname);
                serv_getln(buf, sizeof buf);
                if (buf[0] == '2') {
-                       strcpy(WC->wc_roomname, c_roomname);
+                       safestrncpy(WC->wc_roomname, c_roomname, sizeof WC->wc_roomname);
                }
        }
 
@@ -1166,7 +1169,9 @@ void session_loop(struct httprequest *req)
        } else if (!strcasecmp(action, "ungoto")) {
                ungoto();
        } else if (!strcasecmp(action, "dotgoto")) {
-               slrp_highest();
+               if (WC->wc_view != VIEW_MAILBOX) {      /* dotgoto acts like dotskip when we're in a mailbox view */
+                       slrp_highest();
+               }
                smart_goto(bstr("room"));
        } else if (!strcasecmp(action, "dotskip")) {
                smart_goto(bstr("room"));
@@ -1244,7 +1249,7 @@ void session_loop(struct httprequest *req)
        } else if (!strcasecmp(action, "editpic")) {
                do_graphics_upload("UIMG 1|_userpic_");
        } else if (!strcasecmp(action, "display_editroompic")) {
-               display_graphics_upload("the graphic for this room",
+               display_graphics_upload("the icon for this room",
                                        "UIMG 0|_roompic_",
                                        "/editroompic");
        } else if (!strcasecmp(action, "editroompic")) {
@@ -1258,7 +1263,7 @@ void session_loop(struct httprequest *req)
        } else if (!strcasecmp(action, "display_editfloorpic")) {
                sprintf(buf, "UIMG 0|_floorpic_|%s",
                        bstr("which_floor"));
-               display_graphics_upload("the graphic for this floor",
+               display_graphics_upload("the icon for this floor",
                                        buf,
                                        "/editfloorpic");
        } else if (!strcasecmp(action, "editfloorpic")) {
@@ -1358,6 +1363,10 @@ void session_loop(struct httprequest *req)
                save_inetconf();
        } else if (!strcasecmp(action, "setup_wizard")) {
                do_setup_wizard();
+       } else if (!strcasecmp(action, "display_preferences")) {
+               display_preferences();
+       } else if (!strcasecmp(action, "set_preferences")) {
+               set_preferences();
        } else if (!strcasecmp(action, "diagnostics")) {
                output_headers(1, 1, 1, 0, 0, 0, 0);