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