* Better alignment of system messages
[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(3);
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("<INPUT TYPE=\"RESET\" VALUE=\"Reset Form\">\n");
57         wprintf("<INPUT TYPE=\"SUBMIT\" NAME=\"sc\" VALUE=\"Cancel\">\n");
58         wprintf("</FORM>\n");
59         wprintf("</CENTER>\n");
60         do_template("endbox");
61         wDumpContent(1);
62 }
63
64 void do_graphics_upload(char *upl_cmd)
65 {
66         char buf[SIZ];
67         int bytes_remaining;
68         int pos = 0;
69         int thisblock;
70
71         if (!strcasecmp(bstr("sc"), "Cancel")) {
72                 strcpy(WC->ImportantMessage,
73                         "Graphics upload cancelled.");
74                 display_main_menu();
75                 return;
76         }
77
78         if (WC->upload_length == 0) {
79                 strcpy(WC->ImportantMessage,
80                         "You didn't upload a file.");
81                 display_main_menu();
82                 return;
83         }
84         serv_puts(upl_cmd);
85         serv_gets(buf);
86         if (buf[0] != '2') {
87                 strcpy(WC->ImportantMessage, &buf[4]);
88                 display_main_menu();
89                 return;
90         }
91         bytes_remaining = WC->upload_length;
92         while (bytes_remaining) {
93                 thisblock = ((bytes_remaining > 4096) ? 4096 : bytes_remaining);
94                 serv_printf("WRIT %d", thisblock);
95                 serv_gets(buf);
96                 if (buf[0] != '7') {
97                         strcpy(WC->ImportantMessage, &buf[4]);
98                         serv_puts("UCLS 0");
99                         serv_gets(buf);
100                         display_main_menu();
101                         return;
102                 }
103                 thisblock = extract_int(&buf[4], 0);
104                 serv_write(&WC->upload[pos], thisblock);
105                 pos = pos + thisblock;
106                 bytes_remaining = bytes_remaining - thisblock;
107         }
108
109         serv_puts("UCLS 1");
110         serv_gets(buf);
111         if (buf[0] != 'x') {
112                 display_success(&buf[4]);
113                 return;
114         }
115 }