* *** HUGE CHANGES *** *** WARNING: NOT FULLY FUNCTIONAL ***
[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=\"#444455\"><TR><TD>"
53                 "<SPAN CLASS=\"titlebar\">List subscribe/unsubscribe</SPAN>\n"
54                 "</TD></TR></TABLE><br />\n"
55         );
56
57         /*
58          * Subscribe command
59          */
60         if (!strcasecmp(cmd, "subscribe")) {
61                 serv_printf("SUBS subscribe|%s|%s|%s|%s/listsub",
62                         room,
63                         email,
64                         subtype,
65                         WC->http_host
66                 );
67                 serv_gets(buf);
68                 if (buf[0] == '2') {
69                         wprintf("<CENTER><H1>Confirmation request sent</H1>"
70                                 "You are subscribing <TT>");
71                         escputs(email);
72                         wprintf("</TT> to the &quot;");
73                         escputs(room);
74                         wprintf("&quot; mailing list.  The listserver has "
75                                 "sent you an e-mail with one additional "
76                                 "Web link for you to click on to confirm "
77                                 "your subscription.  This extra step is for "
78                                 "your protection, as it prevents others from "
79                                 "being able to subscribe you to lists "
80                                 "without your consent.<br /><br />"
81                                 "Please click on the link which is being "
82                                 "e-mailed to you and your subscription will "
83                                 "be confirmed.<br />\n"
84                                 "<A HREF=\"/listsub\">Back...</A></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 />\n"
121                                 "<A HREF=\"/listsub\">Back...</A></CENTER>\n"
122                         );
123                 }
124                 else {
125                         wprintf("<FONT SIZE=+1><B>ERROR: %s</B>"
126                                 "</FONT><br /><br />\n",
127                                 &buf[4]);
128                         goto FORM;
129                 }
130         }
131
132         /* 
133          * Confirm command
134          */
135         else if (!strcasecmp(cmd, "confirm")) {
136                 serv_printf("SUBS confirm|%s|%s",
137                         room,
138                         token
139                 );
140                 serv_gets(buf);
141                 if (buf[0] == '2') {
142                         wprintf("<CENTER><H1>Confirmation successful!</H1>");
143                 }
144                 else {
145                         wprintf("<CENTER><H1>Confirmation failed.</H1>"
146                                 "This could mean one of two things:<UL>\n"
147                                 "<LI>You waited too long to confirm your "
148                                 "subscribe/unsubscribe request (the "
149                                 "confirmation link is only valid for three "
150                                 "days)\n<LI>You have <i>already</i> "
151                                 "successfully confirmed your "
152                                 "subscribe/unsubscribe request and are "
153                                 "attempting to do it again.</UL>\n"
154                                 "The error returned by the server was: "
155                         );
156                 }
157                 wprintf("%s</CENTER><br />\n", &buf[4]);
158         }
159
160         /*
161          * Any other (invalid) command causes the form to be displayed
162          */
163         else {
164 FORM:           wprintf("<FORM METHOD=\"GET\" ACTION=\"/listsub\">\n"
165                         "<TABLE BORDER=0>\n"
166                 );
167
168                 wprintf("<TR><TD>Name of list</TD><TD>"
169                         "<SELECT NAME=\"room\" SIZE=1>\n");
170
171                 serv_puts("LPRM");
172                 serv_gets(buf);
173                 if (buf[0] == '1') {
174                         while (serv_gets(buf), strcmp(buf, "000")) {
175                                 extract(sroom, buf, 0);
176                                 self = extract_int(buf, 4) & QR2_SELFLIST ;
177                                 if (self) {
178                                         wprintf("<OPTION VALUE=\"");
179                                         escputs(sroom);
180                                         wprintf("\">");
181                                         escputs(sroom);
182                                         wprintf("</OPTION>\n");
183                                 }
184                         }
185                 }
186                 wprintf("</SELECT>"
187                         "</TD></TR>\n");
188
189                 wprintf("<TR><TD>Your e-mail address</TD><TD>"
190                         "<INPUT TYPE=\"text\" NAME=\"email\" "
191                         "VALUE=\""
192                 );
193                 escputs(email);
194                 wprintf("\" MAXLENGTH=128></TD></TR>\n");
195
196                 wprintf("</TABLE>"
197                         "(If subscribing) preferred format: "
198                         "<INPUT TYPE=\"radio\" NAME=\"subtype\""
199                         "VALUE=\"list\">One message at a time&nbsp; "
200                         "<INPUT TYPE=\"radio\" NAME=\"subtype\""
201                         "VALUE=\"digest\" CHECKED>Digest format&nbsp; "
202                         "<br />\n"
203                         "<INPUT TYPE=\"submit\" NAME=\"cmd\""
204                         " VALUE=\"subscribe\">\n"
205                         "<INPUT TYPE=\"submit\" NAME=\"cmd\""
206                         " VALUE=\"unsubscribe\">\n"
207                         "</FORM>\n"
208                 );
209
210                 wprintf("<br />When you attempt to subscribe or unsubscribe to "
211                         "a mailing list, you will receive an e-mail containing"
212                         " one additional web link to click on for final "
213                         "confirmation.  This extra step is for your "
214                         "protection, as it prevents others from being able to "
215                         "subscribe or unsubscribe you to lists.<br />\n"
216                 );
217
218         }
219
220         /*
221          * Since this isn't part of a normal Citadel session, we bail right
222          * out without maintaining any state.
223          */
224         /* wDumpContent(2); */
225         wprintf("</BODY></HTML>\n");
226         end_webcit_session();
227 }