* Completed self-service list subscription via web.
[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|digest|%s/listsub",
63                         room,
64                         email,
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.<BR><BR>"
80                                 "Please click on the link which is being "
81                                 "e-mailed to you and your subscription will "
82                                 "be confirmed.<BR></CENTER>\n"
83                         );
84                 }
85                 else {
86                         wprintf("<FONT SIZE=+1><B>ERROR: %s</B>"
87                                 "</FONT><BR><BR>\n",
88                                 &buf[4]);
89                         goto FORM;
90                 }
91         }
92
93         /* 
94          * Confirm command
95          */
96         else if (!strcasecmp(cmd, "confirm")) {
97                 serv_printf("SUBS confirm|%s|%s",
98                         room,
99                         token
100                 );
101                 serv_gets(buf);
102                 if (buf[0] == '2') {
103                         wprintf("<CENTER><H1>Confirmation successful!</H1>");
104                 }
105                 else {
106                         wprintf("<CENTER><H1>Confirmation failed.</H1>");
107                 }
108                 wprintf("%s</CENTER><BR>\n", &buf[4]);
109         }
110
111         /*
112          * Any other (invalid) command causes the form to be displayed
113          */
114         else {
115 FORM:           wprintf("<FORM METHOD=\"POST\" ACTION=\"/listsub\">\n"
116                         "<TABLE BORDER=0>\n"
117                 );
118
119                 wprintf("<TR><TD>Name of list</TD><TD>"
120                         "<SELECT NAME=\"room\" SIZE=1>\n");
121
122                 serv_puts("LPRM");
123                 serv_gets(buf);
124                 if (buf[0] == '1') {
125                         while (serv_gets(buf), strcmp(buf, "000")) {
126                                 extract(sroom, buf, 0);
127                                 self = extract_int(buf, 4) & QR2_SELFLIST ;
128                                 if (self) {
129                                         wprintf("<OPTION VALUE=\"");
130                                         escputs(sroom);
131                                         wprintf("\">");
132                                         escputs(sroom);
133                                         wprintf("</OPTION>\n");
134                                 }
135                         }
136                 }
137                 wprintf("</SELECT>"
138                         "</TD></TR>\n");
139
140                 wprintf("<TR><TD>Your e-mail address</TD><TD>"
141                         "<INPUT TYPE=\"text\" NAME=\"email\" "
142                         "VALUE=\""
143                 );
144                 escputs(email);
145                 wprintf("\" MAXLENGTH=128></TD></TR>\n");
146
147                 wprintf("</TABLE>"
148                         "<INPUT TYPE=\"submit\" NAME=\"cmd\""
149                         " VALUE=\"subscribe\">\n"
150                         "<INPUT TYPE=\"submit\" NAME=\"cmd\""
151                         " VALUE=\"unsubscribe\">\n"
152                         "</FORM>\n"
153                 );
154
155                 wprintf("<BR>When you attempt to subscribe or unsubscribe to "
156                         "a mailing list, you will receive an e-mail containing"
157                         " one additional web link to click on for final "
158                         "confirmation.  This extra step is for your "
159                         "protection, as it prevents others from being able to "
160                         "subscribe or unsubscribe you to lists.<BR>\n"
161                 );
162
163         }
164
165         /*
166          * Since this isn't part of a normal Citadel session, we bail right
167          * out without maintaining any state.
168          */
169         /* wDumpContent(2); */
170         wprintf("</BODY></HTML>\n");
171         end_webcit_session();
172 }