* GET instead of POST for listsub. Also add a 'Back...' link.
[citadel.git] / webcit / listsub.c
1 #include <ctype.h>
2 #include <stdlib.h>
3 #include <unistd.h>
4 #include <stdio.h>
5 #include <fcntl.h>
6 #include <signal.h>
7 #include <sys/types.h>
8 #include <sys/wait.h>
9 #include <sys/socket.h>
10 #include <sys/time.h>
11 #include <limits.h>
12 #include <netinet/in.h>
13 #include <netdb.h>
14 #include <string.h>
15 #include <pwd.h>
16 #include <errno.h>
17 #include <stdarg.h>
18 #include <pthread.h>
19 #include <signal.h>
20 #include "webcit.h"
21
22
23
24 /*
25  * List subscription handling
26  */
27 void do_listsub(void)
28 {
29         char cmd[SIZ];
30         char room[SIZ];
31         char token[SIZ];
32         char email[SIZ];
33         char subtype[SIZ];
34
35         char buf[SIZ];
36         int self;
37         char sroom[SIZ];
38
39         strcpy(WC->wc_username, "");
40         strcpy(WC->wc_password, "");
41         strcpy(WC->wc_roomname, "");
42
43         wprintf("<HTML><HEAD><TITLE>List subscription</TITLE></HEAD><BODY>\n");
44
45         strcpy(cmd, bstr("cmd"));
46         strcpy(room, bstr("room"));
47         strcpy(token, bstr("token"));
48         strcpy(email, bstr("email"));
49         strcpy(subtype, bstr("subtype"));
50
51         wprintf("<CENTER>"
52                 "<TABLE WIDTH=100%% BORDER=0 BGCOLOR=000077><TR><TD>"
53                 "<FONT SIZE=+1 COLOR=\"FFFFFF\""
54                 "<B>List subscribe/unsubscribe</B>\n"
55                 "</TD></TR></TABLE><BR>\n"
56         );
57
58         /*
59          * Subscribe command
60          */
61         if (!strcasecmp(cmd, "subscribe")) {
62                 serv_printf("SUBS subscribe|%s|%s|%s|%s/listsub",
63                         room,
64                         email,
65                         subtype,
66                         WC->http_host
67                 );
68                 serv_gets(buf);
69                 if (buf[0] == '2') {
70                         wprintf("<CENTER><H1>Confirmation request sent</H1>"
71                                 "You are subscribing <TT>");
72                         escputs(email);
73                         wprintf("</TT> to the &quot;");
74                         escputs(room);
75                         wprintf("&quot; mailing list.  The listserver has "
76                                 "sent you an e-mail with one additional "
77                                 "Web link for you to click on to confirm "
78                                 "your subscription.  This extra step is for "
79                                 "your protection, as it prevents others from "
80                                 "being able to subscribe you to lists "
81                                 "without your consent.<BR><BR>"
82                                 "Please click on the link which is being "
83                                 "e-mailed to you and your subscription will "
84                                 "be confirmed.<BR>\n"
85                                 "<A HREF=\"/listsub\">Back...</A></CENTER>\n"
86                         );
87                 }
88                 else {
89                         wprintf("<FONT SIZE=+1><B>ERROR: %s</B>"
90                                 "</FONT><BR><BR>\n",
91                                 &buf[4]);
92                         goto FORM;
93                 }
94         }
95
96         /*
97          * Unsubscribe command
98          */
99         else if (!strcasecmp(cmd, "unsubscribe")) {
100                 serv_printf("SUBS unsubscribe|%s|%s|%s/listsub",
101                         room,
102                         email,
103                         WC->http_host
104                 );
105                 serv_gets(buf);
106                 if (buf[0] == '2') {
107                         wprintf("<CENTER><H1>Confirmation request sent</H1>"
108                                 "You are unsubscribing <TT>");
109                         escputs(email);
110                         wprintf("</TT> from the &quot;");
111                         escputs(room);
112                         wprintf("&quot; mailing list.  The listserver has "
113                                 "sent you an e-mail with one additional "
114                                 "Web link for you to click on to confirm "
115                                 "your unsubscription.  This extra step is for "
116                                 "your protection, as it prevents others from "
117                                 "being able to unsubscribe you from "
118                                 "lists without your consent.<BR><BR>"
119                                 "Please click on the link which is being "
120                                 "e-mailed to you and your unsubscription will "
121                                 "be confirmed.<BR>\n"
122                                 "<A HREF=\"/listsub\">Back...</A></CENTER>\n"
123                         );
124                 }
125                 else {
126                         wprintf("<FONT SIZE=+1><B>ERROR: %s</B>"
127                                 "</FONT><BR><BR>\n",
128                                 &buf[4]);
129                         goto FORM;
130                 }
131         }
132
133         /* 
134          * Confirm command
135          */
136         else if (!strcasecmp(cmd, "confirm")) {
137                 serv_printf("SUBS confirm|%s|%s",
138                         room,
139                         token
140                 );
141                 serv_gets(buf);
142                 if (buf[0] == '2') {
143                         wprintf("<CENTER><H1>Confirmation successful!</H1>");
144                 }
145                 else {
146                         wprintf("<CENTER><H1>Confirmation failed.</H1>"
147                                 "This could mean one of two things:<UL>\n"
148                                 "<LI>You waited too long to confirm your "
149                                 "subscribe/unsubscribe request (the "
150                                 "confirmation link is only valid for three "
151                                 "days)\n<LI>You have <i>already</i> "
152                                 "successfully confirmed your "
153                                 "subscribe/unsubscribe request and are "
154                                 "attempting to do it again.</UL>\n"
155                                 "The error returned by the server was: "
156                         );
157                 }
158                 wprintf("%s</CENTER><BR>\n", &buf[4]);
159         }
160
161         /*
162          * Any other (invalid) command causes the form to be displayed
163          */
164         else {
165 FORM:           wprintf("<FORM METHOD=\"GET\" ACTION=\"/listsub\">\n"
166                         "<TABLE BORDER=0>\n"
167                 );
168
169                 wprintf("<TR><TD>Name of list</TD><TD>"
170                         "<SELECT NAME=\"room\" SIZE=1>\n");
171
172                 serv_puts("LPRM");
173                 serv_gets(buf);
174                 if (buf[0] == '1') {
175                         while (serv_gets(buf), strcmp(buf, "000")) {
176                                 extract(sroom, buf, 0);
177                                 self = extract_int(buf, 4) & QR2_SELFLIST ;
178                                 if (self) {
179                                         wprintf("<OPTION VALUE=\"");
180                                         escputs(sroom);
181                                         wprintf("\">");
182                                         escputs(sroom);
183                                         wprintf("</OPTION>\n");
184                                 }
185                         }
186                 }
187                 wprintf("</SELECT>"
188                         "</TD></TR>\n");
189
190                 wprintf("<TR><TD>Your e-mail address</TD><TD>"
191                         "<INPUT TYPE=\"text\" NAME=\"email\" "
192                         "VALUE=\""
193                 );
194                 escputs(email);
195                 wprintf("\" MAXLENGTH=128></TD></TR>\n");
196
197                 wprintf("</TABLE>"
198                         "(If subscribing) preferred format: "
199                         "<INPUT TYPE=\"radio\" NAME=\"subtype\""
200                         "VALUE=\"list\">One message at a time&nbsp; "
201                         "<INPUT TYPE=\"radio\" NAME=\"subtype\""
202                         "VALUE=\"digest\" CHECKED>Digest format&nbsp; "
203                         "<BR>\n"
204                         "<INPUT TYPE=\"submit\" NAME=\"cmd\""
205                         " VALUE=\"subscribe\">\n"
206                         "<INPUT TYPE=\"submit\" NAME=\"cmd\""
207                         " VALUE=\"unsubscribe\">\n"
208                         "</FORM>\n"
209                 );
210
211                 wprintf("<BR>When you attempt to subscribe or unsubscribe to "
212                         "a mailing list, you will receive an e-mail containing"
213                         " one additional web link to click on for final "
214                         "confirmation.  This extra step is for your "
215                         "protection, as it prevents others from being able to "
216                         "subscribe or unsubscribe you to lists.<BR>\n"
217                 );
218
219         }
220
221         /*
222          * Since this isn't part of a normal Citadel session, we bail right
223          * out without maintaining any state.
224          */
225         /* wDumpContent(2); */
226         wprintf("</BODY></HTML>\n");
227         end_webcit_session();
228 }