28300597317bd9501d49ee207622154f8aaddc2d
[citadel.git] / webcit / listsub.c
1 /*
2  * $Id$
3  *
4  * Web forms for handling mailing list subscribe/unsubscribe requests.
5  *
6  */
7
8 #include "webcit.h"
9
10
11
12 /*
13  * List subscription handling
14  */
15 void do_listsub(void)
16 {
17         char cmd[256];
18         char room[256];
19         char token[256];
20         char email[256];
21         char subtype[256];
22         char escaped_email[256];
23         char escaped_room[256];
24
25         char buf[SIZ];
26         int self;
27         char sroom[SIZ];
28
29         strcpy(WC->wc_username, "");
30         strcpy(WC->wc_password, "");
31         strcpy(WC->wc_roomname, "");
32
33         output_headers(1, 0, 0, 1, 1, 0);
34         begin_burst();
35
36         wprintf("<HTML><HEAD>\n"
37                 "<meta name=\"MSSmartTagsPreventParsing\" content=\"TRUE\" />\n"
38                 "<link href=\"static/webcit.css\" rel=\"stylesheet\" type=\"text/css\">\n"
39                 "<TITLE>\n"
40         );
41         wprintf(_("List subscription"));
42         wprintf("</TITLE></HEAD><BODY>\n");
43
44         strcpy(cmd, bstr("cmd"));
45         strcpy(room, bstr("room"));
46         strcpy(token, bstr("token"));
47         strcpy(email, bstr("email"));
48         strcpy(subtype, bstr("subtype"));
49
50         wprintf("<CENTER>"
51                 "<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#444455\"><TR><TD>"
52                 "<SPAN CLASS=\"titlebar\">");
53         wprintf(_("List subscribe/unsubscribe"));
54         wprintf("</SPAN></TD></TR></TABLE><br />\n");
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                         WC->http_host
66                 );
67                 serv_getln(buf, sizeof buf);
68                 if (buf[0] == '2') {
69                         stresc(escaped_email, email, 0, 0);
70                         stresc(escaped_room, room, 0, 0);
71
72                         wprintf("<CENTER><H1>");
73                         wprintf(_("Confirmation request sent"));
74                         wprintf("</H1>");
75                         wprintf(_("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                         wprintf("<a href=\"listsub\">%s</A></CENTER>\n", _("Go back..."));
89                 }
90                 else {
91                         wprintf("<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                         WC->http_host
107                 );
108                 serv_getln(buf, sizeof buf);
109                 if (buf[0] == '2') {
110                         wprintf("<CENTER><H1>Confirmation request sent</H1>"
111                                 "You are unsubscribing <TT>");
112                         escputs(email);
113                         wprintf("</TT> from the &quot;");
114                         escputs(room);
115                         wprintf("&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                         wprintf("<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                         wprintf("<CENTER><H1>Confirmation successful!</H1>");
147                 }
148                 else {
149                         wprintf("<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                 wprintf("%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:           wprintf("<FORM METHOD=\"POST\" action=\"listsub\">\n"
169                         "<TABLE BORDER=0>\n"
170                 );
171
172                 wprintf("<TR><TD>Name of list</TD><TD>"
173                         "<SELECT NAME=\"room\" SIZE=1>\n");
174
175                 serv_puts("LPRM");
176                 serv_getln(buf, sizeof buf);
177                 if (buf[0] == '1') {
178                         while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
179                                 extract_token(sroom, buf, 0, '|', sizeof sroom);
180                                 self = extract_int(buf, 4) & QR2_SELFLIST ;
181                                 if (self) {
182                                         wprintf("<OPTION VALUE=\"");
183                                         escputs(sroom);
184                                         wprintf("\">");
185                                         escputs(sroom);
186                                         wprintf("</OPTION>\n");
187                                 }
188                         }
189                 }
190                 wprintf("</SELECT>"
191                         "</TD></TR>\n");
192
193                 wprintf("<TR><TD>Your e-mail address</TD><TD>"
194                         "<INPUT TYPE=\"text\" NAME=\"email\" "
195                         "VALUE=\""
196                 );
197                 escputs(email);
198                 wprintf("\" MAXLENGTH=128></TD></TR>\n");
199
200                 wprintf("</TABLE>"
201                         "(If subscribing) preferred format: "
202                         "<INPUT TYPE=\"radio\" NAME=\"subtype\""
203                         "VALUE=\"list\">One message at a time&nbsp; "
204                         "<INPUT TYPE=\"radio\" NAME=\"subtype\""
205                         "VALUE=\"digest\" CHECKED>Digest format&nbsp; "
206                         "<br />\n"
207                         "<INPUT TYPE=\"submit\" NAME=\"cmd\""
208                         " VALUE=\"subscribe\">\n"
209                         "<INPUT TYPE=\"submit\" NAME=\"cmd\""
210                         " VALUE=\"unsubscribe\">\n"
211                         "</FORM>\n"
212                 );
213
214                 wprintf("<br />When you attempt to subscribe or unsubscribe to "
215                         "a mailing list, you will receive an e-mail containing"
216                         " one additional web link to click on for final "
217                         "confirmation.  This extra step is for your "
218                         "protection, as it prevents others from being able to "
219                         "subscribe or unsubscribe you to lists.<br />\n"
220                 );
221
222         }
223
224         wprintf("</BODY></HTML>\n");
225         wDumpContent(0);
226         end_webcit_session();
227 }