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