move beginbox & endbox to box_* so we can tidy up our static/t/ directory a little...
[citadel.git] / webcit / listsub.c
1 /*
2  * Web forms for handling mailing list subscribe/unsubscribe requests.
3  *
4  * Copyright (c) 1996-2011 by the citadel.org team
5  *
6  * This program is open source software.  You can redistribute it and/or
7  * modify it under the terms of the GNU General Public License as
8  * published by the Free Software Foundation; either version 3 of the
9  * License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  */
20
21 #include "webcit.h"
22
23 /*
24  * List subscription handling
25  */
26 void do_listsub(void)
27 {
28         char cmd[256];
29         char room[256];
30         char token[256];
31         char email[256];
32         char subtype[256];
33         char escaped_email[256];
34         char escaped_room[256];
35
36         char buf[SIZ];
37         int self;
38         char sroom[SIZ];
39
40         FlushStrBuf(WC->wc_fullname);
41         FlushStrBuf(WC->wc_username);
42         FlushStrBuf(WC->wc_password);
43         FlushStrBuf(WC->CurRoom.name);
44
45         output_headers(1, 0, 0, 1, 1, 0);
46         begin_burst();
47
48         wc_printf("<HTML><HEAD>\n"
49                 "<meta name=\"MSSmartTagsPreventParsing\" content=\"TRUE\" />\n"
50                 "<link href=\"static/styles/webcit.css\" rel=\"stylesheet\" type=\"text/css\">\n"
51                 "<TITLE>\n"
52         );
53         wc_printf(_("List subscription"));
54         wc_printf("</TITLE></HEAD><BODY>\n");
55
56         strcpy(cmd, bstr("cmd"));
57         strcpy(room, bstr("room"));
58         strcpy(token, bstr("token"));
59         strcpy(email, bstr("email"));
60         strcpy(subtype, bstr("subtype"));
61
62         wc_printf("<div align=center>");
63         wc_printf("<table border=0 width=75%%><tr><td>");
64
65         do_template("box_begin_1");
66         StrBufAppendBufPlain(WC->WBuf, _("List subscribe/unsubscribe"), -1, 0);
67         do_template("box_begin_2");
68         wc_printf("<div align=center><br>");
69
70         /*
71          * Subscribe command
72          */
73         if (!strcasecmp(cmd, "subscribe")) {
74                 serv_printf("SUBS subscribe|%s|%s|%s|%s/listsub",
75                         room,
76                         email,
77                         subtype,
78                         ChrPtr(site_prefix)
79                 );
80                 serv_getln(buf, sizeof buf);
81                 if (buf[0] == '2') {
82                         stresc(escaped_email, 256, email, 0, 0);
83                         stresc(escaped_room, 256, room, 0, 0);
84
85                         wc_printf("<CENTER><H1>");
86                         wc_printf(_("Confirmation request sent"));
87                         wc_printf("</H1>");
88                         wc_printf(_("You are subscribing <TT>%s"
89                                 "</TT> to the <b>%s</b> mailing list.  "
90                                 "The listserver has "
91                                 "sent you an e-mail with one additional "
92                                 "Web link for you to click on to confirm "
93                                 "your subscription.  This extra step is for "
94                                 "your protection, as it prevents others from "
95                                 "being able to subscribe you to lists "
96                                 "without your consent.<br><br>"
97                                 "Please click on the link which is being "
98                                 "e-mailed to you and your subscription will "
99                                 "be confirmed.<br>\n"),
100                                 escaped_email, escaped_room);
101                         wc_printf("<a href=\"listsub\">%s</A></CENTER>\n", _("Go back..."));
102                 }
103                 else {
104                         wc_printf("<FONT SIZE=+1><B>ERROR: %s</B>"
105                                 "</FONT><br><br>\n",
106                                 &buf[4]);
107                         goto FORM;
108                 }
109         }
110
111         /*
112          * Unsubscribe command
113          */
114         else if (!strcasecmp(cmd, "unsubscribe")) {
115                 serv_printf("SUBS unsubscribe|%s|%s|%s/listsub",
116                         room,
117                         email,
118                         ChrPtr(site_prefix)
119                 );
120                 serv_getln(buf, sizeof buf);
121                 if (buf[0] == '2') {
122                         wc_printf("<CENTER><H1>Confirmation request sent</H1>"
123                                 "You are unsubscribing <TT>");
124                         escputs(email);
125                         wc_printf("</TT> from the &quot;");
126                         escputs(room);
127                         wc_printf("&quot; mailing list.  The listserver has "
128                                 "sent you an e-mail with one additional "
129                                 "Web link for you to click on to confirm "
130                                 "your unsubscription.  This extra step is for "
131                                 "your protection, as it prevents others from "
132                                 "being able to unsubscribe you from "
133                                 "lists without your consent.<br><br>"
134                                 "Please click on the link which is being "
135                                 "e-mailed to you and your unsubscription will "
136                                 "be confirmed.<br>\n"
137                                 "<a href=\"listsub\">Back...</A></CENTER>\n"
138                         );
139                 }
140                 else {
141                         wc_printf("<FONT SIZE=+1><B>ERROR: %s</B>"
142                                 "</FONT><br><br>\n",
143                                 &buf[4]);
144                         goto FORM;
145                 }
146         }
147
148         /*
149          * Confirm command
150          */
151         else if (!strcasecmp(cmd, "confirm")) {
152                 serv_printf("SUBS confirm|%s|%s",
153                         room,
154                         token
155                 );
156                 serv_getln(buf, sizeof buf);
157                 if (buf[0] == '2') {
158                         wc_printf("<CENTER><H1>Confirmation successful!</H1>");
159                 }
160                 else {
161                         wc_printf("<CENTER><H1>Confirmation failed.</H1>"
162                                 "This could mean one of two things:<UL>\n"
163                                 "<LI>You waited too long to confirm your "
164                                 "subscribe/unsubscribe request (the "
165                                 "confirmation link is only valid for three "
166                                 "days)\n<LI>You have <i>already</i> "
167                                 "successfully confirmed your "
168                                 "subscribe/unsubscribe request and are "
169                                 "attempting to do it again.</UL>\n"
170                                 "The error returned by the server was: "
171                         );
172                 }
173                 wc_printf("%s</CENTER><br>\n", &buf[4]);
174         }
175
176         /*
177          * Any other (invalid) command causes the form to be displayed
178          */
179         else {
180 FORM:           wc_printf("<form method=\"POST\" action=\"listsub\">\n");
181
182                 wc_printf("Name of list: "
183                         "<select name=\"room\" size=1>\n");
184
185                 serv_puts("LPRM");
186                 serv_getln(buf, sizeof buf);
187                 if (buf[0] == '1') {
188                         while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
189                                 extract_token(sroom, buf, 0, '|', sizeof sroom);
190                                 self = extract_int(buf, 4) & QR2_SELFLIST ;
191                                 if (self) {
192                                         wc_printf("<option value=\"");
193                                         escputs(sroom);
194                                         wc_printf("\">");
195                                         escputs(sroom);
196                                         wc_printf("</option>\n");
197                                 }
198                         }
199                 }
200                 wc_printf("</select><br><br>\n");
201
202                 wc_printf("Your e-mail address: "
203                         "<INPUT TYPE=\"text\" NAME=\"email\" "
204                         "VALUE=\""
205                 );
206                 escputs(email);
207                 wc_printf("\" maxlength=128 size=60><br><br>\n");
208
209                 wc_printf("(If subscribing) preferred format: "
210                         "<INPUT TYPE=\"radio\" NAME=\"subtype\" "
211                         "VALUE=\"list\" CHECKED>One message at a time&nbsp; "
212                         "<INPUT TYPE=\"radio\" NAME=\"subtype\" "
213                         "VALUE=\"digest\">Digest format&nbsp; "
214                         "<br><br>\n"
215                         "<INPUT TYPE=\"submit\" NAME=\"cmd\""
216                         " VALUE=\"subscribe\">\n"
217                         "<INPUT TYPE=\"submit\" NAME=\"cmd\""
218                         " VALUE=\"unsubscribe\"><br><br>\n"
219                         "</FORM>\n"
220                 );
221
222                 wc_printf("<hr>When you attempt to subscribe or unsubscribe to "
223                         "a mailing list, you will receive an e-mail containing"
224                         " one additional web link to click on for final "
225                         "confirmation.  This extra step is for your "
226                         "protection, as it prevents others from being able to "
227                         "subscribe or unsubscribe you to lists.<br>\n"
228                 );
229
230         }
231
232         wc_printf("</div>");
233         do_template("box_end");
234         wc_printf("</td></tr></table></div>");
235
236         wc_printf("</BODY></HTML>\n");
237         wDumpContent(0);
238         end_webcit_session();
239 }
240
241
242
243 void 
244 InitModule_LISTSUB
245 (void)
246 {
247         WebcitAddUrlHandler(HKEY("listsub"), "", 0, do_listsub, ANONYMOUS|COOKIEUNNEEDED|FORCE_SESSIONCLOSE);
248
249
250 }