* add a Display name to our handlers; this will be used by DAV handlers.
[citadel.git] / webcit / listsub.c
1 /*
2  * $Id$
3  *
4  * Web forms for handling mailing list subscribe/unsubscribe requests.
5  */
6
7 #include "webcit.h"
8
9 /*
10  * List subscription handling
11  */
12 void do_listsub(void)
13 {
14         char cmd[256];
15         char room[256];
16         char token[256];
17         char email[256];
18         char subtype[256];
19         char escaped_email[256];
20         char escaped_room[256];
21
22         char buf[SIZ];
23         int self;
24         char sroom[SIZ];
25
26         FlushStrBuf(WC->wc_fullname);
27         FlushStrBuf(WC->wc_username);
28         FlushStrBuf(WC->wc_password);
29         FlushStrBuf(WC->wc_roomname);
30
31         output_headers(1, 0, 0, 1, 1, 0);
32         begin_burst();
33
34         wprintf("<HTML><HEAD>\n"
35                 "<meta name=\"MSSmartTagsPreventParsing\" content=\"TRUE\" />\n"
36                 "<link href=\"static/webcit.css\" rel=\"stylesheet\" type=\"text/css\">\n"
37                 "<TITLE>\n"
38         );
39         wprintf(_("List subscription"));
40         wprintf("</TITLE></HEAD><BODY>\n");
41
42         strcpy(cmd, bstr("cmd"));
43         strcpy(room, bstr("room"));
44         strcpy(token, bstr("token"));
45         strcpy(email, bstr("email"));
46         strcpy(subtype, bstr("subtype"));
47
48         wprintf("<div align=center>");
49         wprintf("<table border=0 width=75%%><tr><td>");
50
51         svput("BOXTITLE", WCS_STRING, _("List subscribe/unsubscribe"));
52         do_template("beginboxx", NULL);
53         wprintf("<div align=center><br>");
54
55         /*
56          * Subscribe command
57          */
58         if (!strcasecmp(cmd, "subscribe")) {
59                 serv_printf("SUBS subscribe|%s|%s|%s|%s://%s/listsub",
60                         room,
61                         email,
62                         subtype,
63                         (is_https ? "https" : "http"),
64                             ChrPtr(WC->Hdr->HR.http_host)
65                 );
66                 serv_getln(buf, sizeof buf);
67                 if (buf[0] == '2') {
68                         stresc(escaped_email, 256, email, 0, 0);
69                         stresc(escaped_room, 256, room, 0, 0);
70
71                         wprintf("<CENTER><H1>");
72                         wprintf(_("Confirmation request sent"));
73                         wprintf("</H1>");
74                         wprintf(_("You are subscribing <TT>%s"
75                                 "</TT> to the <b>%s</b> mailing list.  "
76                                 "The listserver has "
77                                 "sent you an e-mail with one additional "
78                                 "Web link for you to click on to confirm "
79                                 "your subscription.  This extra step is for "
80                                 "your protection, as it prevents others from "
81                                 "being able to subscribe you to lists "
82                                 "without your consent.<br /><br />"
83                                 "Please click on the link which is being "
84                                 "e-mailed to you and your subscription will "
85                                 "be confirmed.<br />\n"),
86                                 escaped_email, escaped_room);
87                         wprintf("<a href=\"listsub\">%s</A></CENTER>\n", _("Go back..."));
88                 }
89                 else {
90                         wprintf("<FONT SIZE=+1><B>ERROR: %s</B>"
91                                 "</FONT><br /><br />\n",
92                                 &buf[4]);
93                         goto FORM;
94                 }
95         }
96
97         /*
98          * Unsubscribe command
99          */
100         else if (!strcasecmp(cmd, "unsubscribe")) {
101                 serv_printf("SUBS unsubscribe|%s|%s|%s://%s/listsub",
102                             room,
103                             email,
104                             (is_https ? "https" : "http"),
105                             ChrPtr(WC->Hdr->HR.http_host)
106                 );
107                 serv_getln(buf, sizeof buf);
108                 if (buf[0] == '2') {
109                         wprintf("<CENTER><H1>Confirmation request sent</H1>"
110                                 "You are unsubscribing <TT>");
111                         escputs(email);
112                         wprintf("</TT> from the &quot;");
113                         escputs(room);
114                         wprintf("&quot; mailing list.  The listserver has "
115                                 "sent you an e-mail with one additional "
116                                 "Web link for you to click on to confirm "
117                                 "your unsubscription.  This extra step is for "
118                                 "your protection, as it prevents others from "
119                                 "being able to unsubscribe you from "
120                                 "lists without your consent.<br /><br />"
121                                 "Please click on the link which is being "
122                                 "e-mailed to you and your unsubscription will "
123                                 "be confirmed.<br />\n"
124                                 "<a href=\"listsub\">Back...</A></CENTER>\n"
125                         );
126                 }
127                 else {
128                         wprintf("<FONT SIZE=+1><B>ERROR: %s</B>"
129                                 "</FONT><br /><br />\n",
130                                 &buf[4]);
131                         goto FORM;
132                 }
133         }
134
135         /*
136          * Confirm command
137          */
138         else if (!strcasecmp(cmd, "confirm")) {
139                 serv_printf("SUBS confirm|%s|%s",
140                         room,
141                         token
142                 );
143                 serv_getln(buf, sizeof buf);
144                 if (buf[0] == '2') {
145                         wprintf("<CENTER><H1>Confirmation successful!</H1>");
146                 }
147                 else {
148                         wprintf("<CENTER><H1>Confirmation failed.</H1>"
149                                 "This could mean one of two things:<UL>\n"
150                                 "<LI>You waited too long to confirm your "
151                                 "subscribe/unsubscribe request (the "
152                                 "confirmation link is only valid for three "
153                                 "days)\n<LI>You have <i>already</i> "
154                                 "successfully confirmed your "
155                                 "subscribe/unsubscribe request and are "
156                                 "attempting to do it again.</UL>\n"
157                                 "The error returned by the server was: "
158                         );
159                 }
160                 wprintf("%s</CENTER><br />\n", &buf[4]);
161         }
162
163         /*
164          * Any other (invalid) command causes the form to be displayed
165          */
166         else {
167 FORM:           wprintf("<form method=\"POST\" action=\"listsub\">\n");
168
169                 wprintf("Name of list: "
170                         "<select name=\"room\" size=1>\n");
171
172                 serv_puts("LPRM");
173                 serv_getln(buf, sizeof buf);
174                 if (buf[0] == '1') {
175                         while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
176                                 extract_token(sroom, buf, 0, '|', sizeof sroom);
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><br><br>\n");
188
189                 wprintf("Your e-mail address: "
190                         "<INPUT TYPE=\"text\" NAME=\"email\" "
191                         "VALUE=\""
192                 );
193                 escputs(email);
194                 wprintf("\" maxlength=128 size=60><br><br>\n");
195
196                 wprintf("(If subscribing) preferred format: "
197                         "<INPUT TYPE=\"radio\" NAME=\"subtype\" "
198                         "VALUE=\"list\" CHECKED>One message at a time&nbsp; "
199                         "<INPUT TYPE=\"radio\" NAME=\"subtype\" "
200                         "VALUE=\"digest\">Digest format&nbsp; "
201                         "<br><br>\n"
202                         "<INPUT TYPE=\"submit\" NAME=\"cmd\""
203                         " VALUE=\"subscribe\">\n"
204                         "<INPUT TYPE=\"submit\" NAME=\"cmd\""
205                         " VALUE=\"unsubscribe\"><br><br>\n"
206                         "</FORM>\n"
207                 );
208
209                 wprintf("<hr>When you attempt to subscribe or unsubscribe to "
210                         "a mailing list, you will receive an e-mail containing"
211                         " one additional web link to click on for final "
212                         "confirmation.  This extra step is for your "
213                         "protection, as it prevents others from being able to "
214                         "subscribe or unsubscribe you to lists.<br />\n"
215                 );
216
217         }
218
219         wprintf("</div>");
220         do_template("endbox", NULL);
221         wprintf("</td></tr></table></div>");
222
223         wprintf("</BODY></HTML>\n");
224         wDumpContent(0);
225         end_webcit_session();
226 }
227
228
229
230 void 
231 InitModule_LISTSUB
232 (void)
233 {
234         WebcitAddUrlHandler(HKEY("listsub"), "", 0, do_listsub, ANONYMOUS|COOKIEUNNEEDED|FORCE_SESSIONCLOSE);
235
236
237 }