* Fleshed out the list subscription page a bit
[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
37         strcpy(WC->wc_username, "");
38         strcpy(WC->wc_password, "");
39         strcpy(WC->wc_roomname, "");
40
41         output_headers(2);      /* note "2" causes cookies to be unset */
42
43         strcpy(cmd, bstr("cmd"));
44         strcpy(room, bstr("room"));
45         strcpy(token, bstr("token"));
46         strcpy(email, bstr("email"));
47         strcpy(subtype, bstr("subtype"));
48
49         wprintf("<CENTER>"
50                 "<TABLE WIDTH=100%% BORDER=0 BGCOLOR=000077><TR><TD>"
51                 "<FONT SIZE=+1 COLOR=\"FFFFFF\""
52                 "<B>List subscribe/unsubscribe</B>\n"
53                 "</TD></TR></TABLE><BR>\n"
54         );
55
56         /*
57          * Subscribe command
58          */
59         if (!strcasecmp(cmd, "subscribe")) {
60                 serv_printf("SUBS subscribe|%s|%s|digest|%s/listsub",
61                         room,
62                         email,
63                         WC->http_host
64                 );
65                 serv_gets(buf);
66                 if (buf[0] == '2') {
67                         wprintf("<CENTER><H1>Confirmation request sent</H1>"
68                                 "You are subscribing <TT>");
69                         escputs(email);
70                         wprintf("</TT> to the &quot;");
71                         escputs(room);
72                         wprintf("&quot; mailing list.  The listserver has "
73                                 "sent you an e-mail with one additional "
74                                 "Web link for you to click on to confirm "
75                                 "your subscription.  This extra step is for "
76                                 "your protection, as it prevents others from "
77                                 "being able to subscribe you to lists.<BR><BR>"
78                                 "Please click on the link which is being "
79                                 "e-mailed to you and your subscription will "
80                                 "be confirmed.<BR></CENTER>\n"
81                         );
82                 }
83                 else {
84                         wprintf("<FONT SIZE=+1>ERROR: </FONT>%s<BR><BR>\n",
85                                 &buf[4]);
86                         goto FORM;
87                 }
88         }
89         
90         /*
91          * Any other (invalid) command causes the form to be displayed
92          */
93         else {
94 FORM:           wprintf("<FORM METHOD=\"POST\" ACTION=\"/listsub\">\n"
95                         "<TABLE BORDER=0>\n"
96                 );
97
98                 wprintf("<TR><TD>Name of list</TD><TD>"
99                         "<INPUT TYPE=\"text\" NAME=\"room\" "
100                         "VALUE=\""
101                 );
102                 escputs(room);
103                 wprintf("\" MAXLENGTH=128></TD></TR>\n");
104
105                 wprintf("<TR><TD>Your e-mail address</TD><TD>"
106                         "<INPUT TYPE=\"text\" NAME=\"email\" "
107                         "VALUE=\""
108                 );
109                 escputs(email);
110                 wprintf("\" MAXLENGTH=128></TD></TR>\n");
111
112                 wprintf("</TABLE>"
113                         "<INPUT TYPE=\"submit\" NAME=\"cmd\""
114                         " VALUE=\"subscribe\">\n"
115                         "<INPUT TYPE=\"submit\" NAME=\"cmd\""
116                         " VALUE=\"unsubscribe\">\n"
117                         "</FORM>\n"
118                 );
119
120                 wprintf("<BR>When you attempt to subscribe or unsubscribe to "
121                         "a mailing list, you will receive an e-mail containing"
122                         " one additional web link to click on for final "
123                         "confirmation.  This extra step is for your "
124                         "protection, as it prevents others from being able to "
125                         "subscribe or unsubscribe you to lists.<BR>\n"
126                 );
127
128         }
129
130         /*
131          * Since this isn't part of a normal Citadel session, we bail right
132          * out without maintaining any state.
133          */
134         wDumpContent(2);
135         end_webcit_session();
136 }