* More display fixes
[citadel.git] / webcit / graphics.c
1 /*
2  * $Id$
3  *
4  * Handles HTTP upload of graphics files into the system.
5  */
6
7 #include <ctype.h>
8 #include <stdlib.h>
9 #include <unistd.h>
10 #include <stdio.h>
11 #include <fcntl.h>
12 #include <signal.h>
13 #include <sys/types.h>
14 #include <sys/wait.h>
15 #include <sys/socket.h>
16 #include <sys/time.h>
17 #include <limits.h>
18 #include <netinet/in.h>
19 #include <netdb.h>
20 #include <string.h>
21 #include <pwd.h>
22 #include <errno.h>
23 #include <stdarg.h>
24 #include <pthread.h>
25 #include <signal.h>
26 #include "webcit.h"
27
28 void display_graphics_upload(char *description, char *check_cmd, char *uplurl)
29 {
30         char buf[SIZ];
31
32         serv_puts(check_cmd);
33         serv_gets(buf);
34         if (buf[0] != '2') {
35                 strcpy(WC->ImportantMessage, &buf[4]);
36                 display_main_menu();
37                 return;
38         }
39         output_headers(1, 1, 0, 0, 0, 0, 0);
40
41         output_headers(1, 1, 2, 0, 0, 0, 0);
42         wprintf("<div id=\"banner\">\n"
43                 "<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#444455\"><TR><TD>"
44                 "<SPAN CLASS=\"titlebar\">Set/change your photo</SPAN>"
45                 "</TD></TR></TABLE>\n"
46                 "</div>\n<div id=\"content\">\n"
47         );
48
49         wprintf("<center><table border=0 width=99%% bgcolor=\"#ffffff\"><tr><td>\n");
50
51         wprintf("<CENTER>\n");
52
53         wprintf("<FORM ENCTYPE=\"multipart/form-data\" ACTION=\"%s\" "
54                 "METHOD=\"POST\" NAME=\"graphicsupload\">\n", uplurl);
55
56         wprintf("<INPUT TYPE=\"hidden\" NAME=\"which_room\" VALUE=\"");
57         urlescputs(bstr("which_room"));
58         wprintf("\">\n");
59
60         wprintf("You can upload any image directly from your computer,\n");
61         wprintf("as long as it is in GIF format (JPEG, PNG, etc. won't\n");
62         wprintf("work).<br /><br />\n");
63
64         wprintf("Please select a file to upload:<br /><br />\n");
65         wprintf("<INPUT TYPE=\"FILE\" NAME=\"filename\" SIZE=\"35\">\n");
66         wprintf("<br /><br />");
67         wprintf("<INPUT TYPE=\"SUBMIT\" NAME=\"sc\" VALUE=\"Upload\">\n");
68         wprintf("&nbsp;");
69         wprintf("<INPUT TYPE=\"RESET\" VALUE=\"Reset Form\">\n");
70         wprintf("&nbsp;");
71         wprintf("<INPUT TYPE=\"SUBMIT\" NAME=\"sc\" VALUE=\"Cancel\">\n");
72         wprintf("</FORM>\n");
73         wprintf("</CENTER>\n");
74         wprintf("</td></tr></table></center>\n");
75         wDumpContent(1);
76 }
77
78 void do_graphics_upload(char *upl_cmd)
79 {
80         char buf[SIZ];
81         int bytes_remaining;
82         int pos = 0;
83         int thisblock;
84
85         if (!strcasecmp(bstr("sc"), "Cancel")) {
86                 strcpy(WC->ImportantMessage,
87                         "Graphics upload cancelled.");
88                 display_main_menu();
89                 return;
90         }
91
92         if (WC->upload_length == 0) {
93                 strcpy(WC->ImportantMessage,
94                         "You didn't upload a file.");
95                 display_main_menu();
96                 return;
97         }
98         serv_puts(upl_cmd);
99         serv_gets(buf);
100         if (buf[0] != '2') {
101                 strcpy(WC->ImportantMessage, &buf[4]);
102                 display_main_menu();
103                 return;
104         }
105         bytes_remaining = WC->upload_length;
106         while (bytes_remaining) {
107                 thisblock = ((bytes_remaining > 4096) ? 4096 : bytes_remaining);
108                 serv_printf("WRIT %d", thisblock);
109                 serv_gets(buf);
110                 if (buf[0] != '7') {
111                         strcpy(WC->ImportantMessage, &buf[4]);
112                         serv_puts("UCLS 0");
113                         serv_gets(buf);
114                         display_main_menu();
115                         return;
116                 }
117                 thisblock = extract_int(&buf[4], 0);
118                 serv_write(&WC->upload[pos], thisblock);
119                 pos = pos + thisblock;
120                 bytes_remaining = bytes_remaining - thisblock;
121         }
122
123         serv_puts("UCLS 1");
124         serv_gets(buf);
125         if (buf[0] != 'x') {
126                 display_success(&buf[4]);
127                 return;
128         }
129 }