* Removed all of the absolute URL's.
[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         wprintf("<HTML><HEAD><TITLE>");
34         wprintf(_("List subscription"));
35         wprintf("</TITLE></HEAD><BODY>\n");
36
37         strcpy(cmd, bstr("cmd"));
38         strcpy(room, bstr("room"));
39         strcpy(token, bstr("token"));
40         strcpy(email, bstr("email"));
41         strcpy(subtype, bstr("subtype"));
42
43         wprintf("<CENTER>"
44                 "<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#444455\"><TR><TD>"
45                 "<SPAN CLASS=\"titlebar\">");
46         wprintf(_("List subscribe/unsubscribe"));
47         wprintf("</SPAN></TD></TR></TABLE><br />\n");
48
49         /*
50          * Subscribe command
51          */
52         if (!strcasecmp(cmd, "subscribe")) {
53                 serv_printf("SUBS subscribe|%s|%s|%s|%s://%s/listsub",
54                         room,
55                         email,
56                         subtype,
57                         (is_https ? "https" : "http"),
58                         WC->http_host
59                 );
60                 serv_getln(buf, sizeof buf);
61                 if (buf[0] == '2') {
62                         stresc(escaped_email, email, 0, 0);
63                         stresc(escaped_room, room, 0, 0);
64
65                         wprintf("<CENTER><H1>");
66                         wprintf(_("Confirmation request sent"));
67                         wprintf("</H1>");
68                         wprintf(_("You are subscribing <TT>%s"
69                                 "</TT> to the <b>%s</b> mailing list.  "
70                                 "The listserver has "
71                                 "sent you an e-mail with one additional "
72                                 "Web link for you to click on to confirm "
73                                 "your subscription.  This extra step is for "
74                                 "your protection, as it prevents others from "
75                                 "being able to subscribe you to lists "
76                                 "without your consent.<br /><br />"
77                                 "Please click on the link which is being "
78                                 "e-mailed to you and your subscription will "
79                                 "be confirmed.<br />\n"),
80                                 escaped_email, escaped_room);
81                         wprintf("<a href=\"listsub\">%s</A></CENTER>\n", _("Go back..."));
82                 }
83                 else {
84                         wprintf("<FONT SIZE=+1><B>ERROR: %s</B>"
85                                 "</FONT><br /><br />\n",
86                                 &buf[4]);
87                         goto FORM;
88                 }
89         }
90
91         /*
92          * Unsubscribe command
93          */
94         else if (!strcasecmp(cmd, "unsubscribe")) {
95                 serv_printf("SUBS unsubscribe|%s|%s|%s://%s/listsub",
96                         room,
97                         email,
98                         (is_https ? "https" : "http"),
99                         WC->http_host
100                 );
101                 serv_getln(buf, sizeof buf);
102                 if (buf[0] == '2') {
103                         wprintf("<CENTER><H1>Confirmation request sent</H1>"
104                                 "You are unsubscribing <TT>");
105                         escputs(email);
106                         wprintf("</TT> from the &quot;");
107                         escputs(room);
108                         wprintf("&quot; mailing list.  The listserver has "
109                                 "sent you an e-mail with one additional "
110                                 "Web link for you to click on to confirm "
111                                 "your unsubscription.  This extra step is for "
112                                 "your protection, as it prevents others from "
113                                 "being able to unsubscribe you from "
114                                 "lists without your consent.<br /><br />"
115                                 "Please click on the link which is being "
116                                 "e-mailed to you and your unsubscription will "
117                                 "be confirmed.<br />\n"
118                                 "<a href=\"listsub\">Back...</A></CENTER>\n"
119                         );
120                 }
121                 else {
122                         wprintf("<FONT SIZE=+1><B>ERROR: %s</B>"
123                                 "</FONT><br /><br />\n",
124                                 &buf[4]);
125                         goto FORM;
126                 }
127         }
128
129         /* 
130          * Confirm command
131          */
132         else if (!strcasecmp(cmd, "confirm")) {
133                 serv_printf("SUBS confirm|%s|%s",
134                         room,
135                         token
136                 );
137                 serv_getln(buf, sizeof buf);
138                 if (buf[0] == '2') {
139                         wprintf("<CENTER><H1>Confirmation successful!</H1>");
140                 }
141                 else {
142                         wprintf("<CENTER><H1>Confirmation failed.</H1>"
143                                 "This could mean one of two things:<UL>\n"
144                                 "<LI>You waited too long to confirm your "
145                                 "subscribe/unsubscribe request (the "
146                                 "confirmation link is only valid for three "
147                                 "days)\n<LI>You have <i>already</i> "
148                                 "successfully confirmed your "
149                                 "subscribe/unsubscribe request and are "
150                                 "attempting to do it again.</UL>\n"
151                                 "The error returned by the server was: "
152                         );
153                 }
154                 wprintf("%s</CENTER><br />\n", &buf[4]);
155         }
156
157         /*
158          * Any other (invalid) command causes the form to be displayed
159          */
160         else {
161 FORM:           wprintf("<FORM METHOD=\"POST\" action=\"listsub\">\n"
162                         "<TABLE BORDER=0>\n"
163                 );
164
165                 wprintf("<TR><TD>Name of list</TD><TD>"
166                         "<SELECT NAME=\"room\" SIZE=1>\n");
167
168                 serv_puts("LPRM");
169                 serv_getln(buf, sizeof buf);
170                 if (buf[0] == '1') {
171                         while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
172                                 extract_token(sroom, buf, 0, '|', sizeof sroom);
173                                 self = extract_int(buf, 4) & QR2_SELFLIST ;
174                                 if (self) {
175                                         wprintf("<OPTION VALUE=\"");
176                                         escputs(sroom);
177                                         wprintf("\">");
178                                         escputs(sroom);
179                                         wprintf("</OPTION>\n");
180                                 }
181                         }
182                 }
183                 wprintf("</SELECT>"
184                         "</TD></TR>\n");
185
186                 wprintf("<TR><TD>Your e-mail address</TD><TD>"
187                         "<INPUT TYPE=\"text\" NAME=\"email\" "
188                         "VALUE=\""
189                 );
190                 escputs(email);
191                 wprintf("\" MAXLENGTH=128></TD></TR>\n");
192
193                 wprintf("</TABLE>"
194                         "(If subscribing) preferred format: "
195                         "<INPUT TYPE=\"radio\" NAME=\"subtype\""
196                         "VALUE=\"list\">One message at a time&nbsp; "
197                         "<INPUT TYPE=\"radio\" NAME=\"subtype\""
198                         "VALUE=\"digest\" CHECKED>Digest format&nbsp; "
199                         "<br />\n"
200                         "<INPUT TYPE=\"submit\" NAME=\"cmd\""
201                         " VALUE=\"subscribe\">\n"
202                         "<INPUT TYPE=\"submit\" NAME=\"cmd\""
203                         " VALUE=\"unsubscribe\">\n"
204                         "</FORM>\n"
205                 );
206
207                 wprintf("<br />When you attempt to subscribe or unsubscribe to "
208                         "a mailing list, you will receive an e-mail containing"
209                         " one additional web link to click on for final "
210                         "confirmation.  This extra step is for your "
211                         "protection, as it prevents others from being able to "
212                         "subscribe or unsubscribe you to lists.<br />\n"
213                 );
214
215         }
216
217         /*
218          * Since this isn't part of a normal Citadel session, we bail right
219          * out without maintaining any state.
220          */
221         /* wDumpContent(2); */
222         wprintf("</BODY></HTML>\n");
223         end_webcit_session();
224 }