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