* Finished all of the subscribe/unsubscribe/confirm stuff! (I think)
[citadel.git] / webcit / listsub.c
1 #include <ctype.h>
2 #include <stdlib.h>
3 #include <unistd.h>
4 #include <stdio.h>
5 #include <fcntl.h>
6 #include <signal.h>
7 #include <sys/types.h>
8 #include <sys/wait.h>
9 #include <sys/socket.h>
10 #include <sys/time.h>
11 #include <limits.h>
12 #include <netinet/in.h>
13 #include <netdb.h>
14 #include <string.h>
15 #include <pwd.h>
16 #include <errno.h>
17 #include <stdarg.h>
18 #include <pthread.h>
19 #include <signal.h>
20 #include "webcit.h"
21
22
23
24 /*
25  * List subscription handling
26  */
27 void do_listsub(void)
28 {
29         char cmd[SIZ];
30         char room[SIZ];
31         char token[SIZ];
32         char email[SIZ];
33         char subtype[SIZ];
34
35         char buf[SIZ];
36         int self;
37         char sroom[SIZ];
38
39         strcpy(WC->wc_username, "");
40         strcpy(WC->wc_password, "");
41         strcpy(WC->wc_roomname, "");
42
43         wprintf("<HTML><HEAD><TITLE>List subscription</TITLE></HEAD><BODY>\n");
44
45         strcpy(cmd, bstr("cmd"));
46         strcpy(room, bstr("room"));
47         strcpy(token, bstr("token"));
48         strcpy(email, bstr("email"));
49         strcpy(subtype, bstr("subtype"));
50
51         wprintf("<CENTER>"
52                 "<TABLE WIDTH=100%% BORDER=0 BGCOLOR=000077><TR><TD>"
53                 "<FONT SIZE=+1 COLOR=\"FFFFFF\""
54                 "<B>List subscribe/unsubscribe</B>\n"
55                 "</TD></TR></TABLE><BR>\n"
56         );
57
58         /*
59          * Subscribe command
60          */
61         if (!strcasecmp(cmd, "subscribe")) {
62                 serv_printf("SUBS subscribe|%s|%s|%s|%s/listsub",
63                         room,
64                         email,
65                         subtype,
66                         WC->http_host
67                 );
68                 serv_gets(buf);
69                 if (buf[0] == '2') {
70                         wprintf("<CENTER><H1>Confirmation request sent</H1>"
71                                 "You are subscribing <TT>");
72                         escputs(email);
73                         wprintf("</TT> to the &quot;");
74                         escputs(room);
75                         wprintf("&quot; mailing list.  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></CENTER>\n"
85                         );
86                 }
87                 else {
88                         wprintf("<FONT SIZE=+1><B>ERROR: %s</B>"
89                                 "</FONT><BR><BR>\n",
90                                 &buf[4]);
91                         goto FORM;
92                 }
93         }
94
95         /*
96          * Unsubscribe command
97          */
98         else if (!strcasecmp(cmd, "unsubscribe")) {
99                 serv_printf("SUBS unsubscribe|%s|%s|%s/listsub",
100                         room,
101                         email,
102                         WC->http_host
103                 );
104                 serv_gets(buf);
105                 if (buf[0] == '2') {
106                         wprintf("<CENTER><H1>Confirmation request sent</H1>"
107                                 "You are unsubscribing <TT>");
108                         escputs(email);
109                         wprintf("</TT> from the &quot;");
110                         escputs(room);
111                         wprintf("&quot; mailing list.  The listserver has "
112                                 "sent you an e-mail with one additional "
113                                 "Web link for you to click on to confirm "
114                                 "your unsubscription.  This extra step is for "
115                                 "your protection, as it prevents others from "
116                                 "being able to unsubscribe you from "
117                                 "lists without your consent.<BR><BR>"
118                                 "Please click on the link which is being "
119                                 "e-mailed to you and your unsubscription will "
120                                 "be confirmed.<BR></CENTER>\n"
121                         );
122                 }
123                 else {
124                         wprintf("<FONT SIZE=+1><B>ERROR: %s</B>"
125                                 "</FONT><BR><BR>\n",
126                                 &buf[4]);
127                         goto FORM;
128                 }
129         }
130
131         /* 
132          * Confirm command
133          */
134         else if (!strcasecmp(cmd, "confirm")) {
135                 serv_printf("SUBS confirm|%s|%s",
136                         room,
137                         token
138                 );
139                 serv_gets(buf);
140                 if (buf[0] == '2') {
141                         wprintf("<CENTER><H1>Confirmation successful!</H1>");
142                 }
143                 else {
144                         wprintf("<CENTER><H1>Confirmation failed.</H1>");
145                 }
146                 wprintf("%s</CENTER><BR>\n", &buf[4]);
147         }
148
149         /*
150          * Any other (invalid) command causes the form to be displayed
151          */
152         else {
153 FORM:           wprintf("<FORM METHOD=\"POST\" ACTION=\"/listsub\">\n"
154                         "<TABLE BORDER=0>\n"
155                 );
156
157                 wprintf("<TR><TD>Name of list</TD><TD>"
158                         "<SELECT NAME=\"room\" SIZE=1>\n");
159
160                 serv_puts("LPRM");
161                 serv_gets(buf);
162                 if (buf[0] == '1') {
163                         while (serv_gets(buf), strcmp(buf, "000")) {
164                                 extract(sroom, buf, 0);
165                                 self = extract_int(buf, 4) & QR2_SELFLIST ;
166                                 if (self) {
167                                         wprintf("<OPTION VALUE=\"");
168                                         escputs(sroom);
169                                         wprintf("\">");
170                                         escputs(sroom);
171                                         wprintf("</OPTION>\n");
172                                 }
173                         }
174                 }
175                 wprintf("</SELECT>"
176                         "</TD></TR>\n");
177
178                 wprintf("<TR><TD>Your e-mail address</TD><TD>"
179                         "<INPUT TYPE=\"text\" NAME=\"email\" "
180                         "VALUE=\""
181                 );
182                 escputs(email);
183                 wprintf("\" MAXLENGTH=128></TD></TR>\n");
184
185                 wprintf("</TABLE>"
186                         "(If subscribing) preferred format: "
187                         "<INPUT TYPE=\"radio\" NAME=\"subtype\""
188                         "VALUE=\"list\">One message at a time&nbsp; "
189                         "<INPUT TYPE=\"radio\" NAME=\"subtype\""
190                         "VALUE=\"digest\" CHECKED>Digest format&nbsp; "
191                         "<BR>\n"
192                         "<INPUT TYPE=\"submit\" NAME=\"cmd\""
193                         " VALUE=\"subscribe\">\n"
194                         "<INPUT TYPE=\"submit\" NAME=\"cmd\""
195                         " VALUE=\"unsubscribe\">\n"
196                         "</FORM>\n"
197                 );
198
199                 wprintf("<BR>When you attempt to subscribe or unsubscribe to "
200                         "a mailing list, you will receive an e-mail containing"
201                         " one additional web link to click on for final "
202                         "confirmation.  This extra step is for your "
203                         "protection, as it prevents others from being able to "
204                         "subscribe or unsubscribe you to lists.<BR>\n"
205                 );
206
207         }
208
209         /*
210          * Since this isn't part of a normal Citadel session, we bail right
211          * out without maintaining any state.
212          */
213         /* wDumpContent(2); */
214         wprintf("</BODY></HTML>\n");
215         end_webcit_session();
216 }