* *** HUGE CHANGES *** *** WARNING: NOT FULLY FUNCTIONAL ***
[citadel.git] / webcit / graphics.c
1
2 #include <ctype.h>
3 #include <stdlib.h>
4 #include <unistd.h>
5 #include <stdio.h>
6 #include <fcntl.h>
7 #include <signal.h>
8 #include <sys/types.h>
9 #include <sys/wait.h>
10 #include <sys/socket.h>
11 #include <sys/time.h>
12 #include <limits.h>
13 #include <netinet/in.h>
14 #include <netdb.h>
15 #include <string.h>
16 #include <pwd.h>
17 #include <errno.h>
18 #include <stdarg.h>
19 #include <pthread.h>
20 #include <signal.h>
21 #include "webcit.h"
22
23 void display_graphics_upload(char *description, char *check_cmd, char *uplurl)
24 {
25         char buf[SIZ];
26
27         serv_puts(check_cmd);
28         serv_gets(buf);
29         if (buf[0] != '2') {
30                 strcpy(WC->ImportantMessage, &buf[4]);
31                 display_main_menu();
32                 return;
33         }
34         output_headers(1, 1, 0, 0, 0, 0, 0);
35
36         svprintf("BOXTITLE", WCS_STRING, "Set/change your photo");
37         do_template("beginbox");
38
39         wprintf("<CENTER>\n");
40
41         wprintf("<FORM ENCTYPE=\"multipart/form-data\" ACTION=\"%s\" "
42                 "METHOD=\"POST\" NAME=\"graphicsupload\">\n", uplurl);
43
44         wprintf("<INPUT TYPE=\"hidden\" NAME=\"which_room\" VALUE=\"");
45         urlescputs(bstr("which_room"));
46         wprintf("\">\n");
47
48         wprintf("You can upload any image directly from your computer,\n");
49         wprintf("as long as it is in GIF format (JPEG, PNG, etc. won't\n");
50         wprintf("work).<br /><br />\n");
51
52         wprintf("Please select a file to upload:<br /><br />\n");
53         wprintf("<INPUT TYPE=\"FILE\" NAME=\"filename\" SIZE=\"35\">\n");
54         wprintf("<br /><br />");
55         wprintf("<INPUT TYPE=\"SUBMIT\" NAME=\"sc\" VALUE=\"Upload\">\n");
56         wprintf("&nbsp;");
57         wprintf("<INPUT TYPE=\"RESET\" VALUE=\"Reset Form\">\n");
58         wprintf("&nbsp;");
59         wprintf("<INPUT TYPE=\"SUBMIT\" NAME=\"sc\" VALUE=\"Cancel\">\n");
60         wprintf("</FORM>\n");
61         wprintf("</CENTER>\n");
62         do_template("endbox");
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 (!strcasecmp(bstr("sc"), "Cancel")) {
74                 strcpy(WC->ImportantMessage,
75                         "Graphics upload 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_gets(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_gets(buf);
98                 if (buf[0] != '7') {
99                         strcpy(WC->ImportantMessage, &buf[4]);
100                         serv_puts("UCLS 0");
101                         serv_gets(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_gets(buf);
113         if (buf[0] != 'x') {
114                 display_success(&buf[4]);
115                 return;
116         }
117 }