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