Nearly all <FORM> blocks now contain a hidden input
[citadel.git] / webcit / graphics.c
1 /*
2  * $Id$
3  *
4  * Handles HTTP upload of graphics files into the system.
5  * \ingroup WebcitHttpServer
6  */
7
8 #include "webcit.h"
9
10 void display_graphics_upload(char *description, char *check_cmd, char *uplurl)
11 {
12         char buf[SIZ];
13
14         serv_puts(check_cmd);
15         serv_getln(buf, sizeof buf);
16         if (buf[0] != '2') {
17                 strcpy(WC->ImportantMessage, &buf[4]);
18                 display_main_menu();
19                 return;
20         }
21         output_headers(1, 1, 0, 0, 0, 0);
22
23         output_headers(1, 1, 2, 0, 0, 0);
24         wprintf("<div id=\"banner\">\n"
25                 "<TABLE class=\"graphics_banner\"><TR><TD>"
26                 "<SPAN CLASS=\"titlebar\">");
27         wprintf(_("Image upload"));
28         wprintf("</SPAN>"
29                 "</TD></TR></TABLE>\n"
30                 "</div>\n<div id=\"content\">\n"
31         );
32
33         wprintf("<div class=\"fix_scrollbar_bug\">"
34                 "<table class=\"graphics_background\"><tr><td>\n");
35
36         wprintf("<CENTER>\n");
37
38         wprintf("<FORM ENCTYPE=\"multipart/form-data\" action=\"%s\" "
39                 "METHOD=\"POST\" NAME=\"graphicsupload\">\n", uplurl);
40
41         wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%ld\">\n", WC->nonce);
42         wprintf("<INPUT TYPE=\"hidden\" NAME=\"which_room\" VALUE=\"");
43         urlescputs(bstr("which_room"));
44         wprintf("\">\n");
45
46         wprintf(_("You can upload any image directly from your computer, "
47                 "as long as it is in GIF format (JPEG, PNG, etc. won't "
48                 "work)."));
49         wprintf("<br /><br />\n");
50
51         wprintf(_("Please select a file to upload:"));
52         wprintf("<br /><br />\n");
53         wprintf("<INPUT TYPE=\"FILE\" NAME=\"filename\" SIZE=\"35\">\n");
54         wprintf("<br /><br />");
55         wprintf("<INPUT TYPE=\"SUBMIT\" NAME=\"upload_button\" VALUE=\"%s\">\n", _("Upload"));
56         wprintf("&nbsp;");
57         wprintf("<INPUT TYPE=\"RESET\" VALUE=\"%s\">\n", _("Reset form"));
58         wprintf("&nbsp;");
59         wprintf("<INPUT TYPE=\"SUBMIT\" NAME=\"cancel_button\" VALUE=\"%s\">\n", _("Cancel"));
60         wprintf("</FORM>\n");
61         wprintf("</CENTER>\n");
62         wprintf("</td></tr></table></div>\n");
63         wDumpContent(1);
64 }
65
66 void do_graphics_upload(char *upl_cmd)
67 {
68         char buf[SIZ];
69         int bytes_remaining;
70         int pos = 0;
71         int thisblock;
72
73         if (strlen(bstr("cancel_button")) > 0) {
74                 strcpy(WC->ImportantMessage,
75                         _("Graphics upload has been cancelled."));
76                 display_main_menu();
77                 return;
78         }
79
80         if (WC->upload_length == 0) {
81                 strcpy(WC->ImportantMessage,
82                         _("You didn't upload a file."));
83                 display_main_menu();
84                 return;
85         }
86         serv_puts(upl_cmd);
87         serv_getln(buf, sizeof buf);
88         if (buf[0] != '2') {
89                 strcpy(WC->ImportantMessage, &buf[4]);
90                 display_main_menu();
91                 return;
92         }
93         bytes_remaining = WC->upload_length;
94         while (bytes_remaining) {
95                 thisblock = ((bytes_remaining > 4096) ? 4096 : bytes_remaining);
96                 serv_printf("WRIT %d", thisblock);
97                 serv_getln(buf, sizeof buf);
98                 if (buf[0] != '7') {
99                         strcpy(WC->ImportantMessage, &buf[4]);
100                         serv_puts("UCLS 0");
101                         serv_getln(buf, sizeof buf);
102                         display_main_menu();
103                         return;
104                 }
105                 thisblock = extract_int(&buf[4], 0);
106                 serv_write(&WC->upload[pos], thisblock);
107                 pos = pos + thisblock;
108                 bytes_remaining = bytes_remaining - thisblock;
109         }
110
111         serv_puts("UCLS 1");
112         serv_getln(buf, sizeof buf);
113         if (buf[0] != 'x') {
114                 display_success(&buf[4]);
115                 return;
116         }
117 }