4 * This module handles self-service subscription/unsubscription to mail lists.
6 * Copyright (C) 2002 by Art Cancro and others.
7 * This code is released under the terms of the GNU General Public License.
20 #include <sys/types.h>
22 #if TIME_WITH_SYS_TIME
23 # include <sys/time.h>
27 # include <sys/time.h>
38 #include "sysdep_decls.h"
39 #include "citserver.h"
42 #include "dynloader.h"
49 #include "internet_addressing.h"
50 #include "serv_network.h"
51 #include "clientsocket.h"
60 * Generate a randomizationalisticized token to use for authentication of
61 * a subscribe or unsubscribe request.
63 void listsub_generate_token(char *buf) {
67 /* Theo, please sit down and shut up. This key doesn't have to be
68 * tinfoil-hat secure, it just needs to be reasonably unguessable
71 sprintf(sourcebuf, "%d%d%ld",
77 /* Convert it to base64 so it looks cool */
78 encode_base64(buf, sourcebuf);
83 * Enter a subscription request
85 void do_subscribe(char *room, char *email, char *subtype, char *webpage) {
86 struct quickroom qrbuf;
90 char confirmation_request[SIZ];
92 if (getroom(&qrbuf, room) != 0) {
93 cprintf("%d There is no list called '%s'\n", ERROR, room);
97 listsub_generate_token(token);
99 begin_critical_section(S_NETCONFIGS);
100 assoc_file_name(filename, sizeof filename, &qrbuf, "netconfigs");
101 ncfp = fopen(filename, "a");
103 fprintf(ncfp, "subpending|%s|%s|%s|%ld|%s\n",
112 end_critical_section(S_NETCONFIGS);
114 /* Generate and send the confirmation request */
116 snprintf(confirmation_request, sizeof confirmation_request,
117 "Someone (probably you) has submitted a request to subscribe\n"
118 "<%s> to the '%s' mailing list.\n\n"
119 "In order to confirm this subscription request, please\n"
120 "point your web browser at the following location:\n\n"
121 "http://%s?room=%s&token=%s\n\n"
122 "If this request has been submitted in error and you do not\n"
123 "wish to receive the '%s' mailing list, simply do nothing,\n"
124 "and you will not receive any further mailings.\n",
126 email, qrbuf.QRname, webpage, qrbuf.QRname, token, qrbuf.QRname
136 cprintf("%d Subscription entered; confirmation request sent\n", CIT_OK);
142 * Confirm a subscribe/unsubscribe request.
144 void do_confirm(char *room, char *token) {
145 struct quickroom qrbuf;
148 char line_token[SIZ];
157 if (getroom(&qrbuf, room) != 0) {
158 cprintf("%d There is no list called '%s'\n", ERROR, room);
162 begin_critical_section(S_NETCONFIGS);
163 assoc_file_name(filename, sizeof filename, &qrbuf, "netconfigs");
164 ncfp = fopen(filename, "r+");
166 while (line_offset = ftell(ncfp),
167 (fgets(buf, sizeof buf, ncfp) != NULL) ) {
168 buf[strlen(buf)-1] = 0;
169 line_length = strlen(buf);
170 extract(cmd, buf, 0);
171 if (!strcasecmp(cmd, "subpending")) {
172 extract(email, buf, 1);
173 extract(subtype, buf, 2);
174 extract(line_token, buf, 3);
175 if (!strcasecmp(token, line_token)) {
176 if (!strcasecmp(subtype, "digest")) {
177 strcpy(buf, "digestrecp|");
180 strcpy(buf, "listrecp|");
184 /* SLEAZY HACK: pad the line out so
185 * it's the same length as the line
188 while (strlen(buf) < line_length) {
191 fseek(ncfp, line_offset, SEEK_SET);
192 fprintf(ncfp, "%s\n", buf);
199 end_critical_section(S_NETCONFIGS);
202 cprintf("%d %d operation(s) confirmed.\n", CIT_OK, success);
205 cprintf("%d Invalid token.\n", ERROR);
213 * process subscribe/unsubscribe requests and confirmations
215 void cmd_subs(char *cmdbuf) {
224 extract(opr, cmdbuf, 0);
225 if (!strcasecmp(opr, "subscribe")) {
226 extract(subtype, cmdbuf, 3);
227 if ( (strcasecmp(subtype, "list"))
228 && (strcasecmp(subtype, "digest")) ) {
229 cprintf("%d Invalid subscription type.\n", ERROR);
232 extract(room, cmdbuf, 1);
233 extract(email, cmdbuf, 2);
234 extract(webpage, cmdbuf, 3);
235 do_subscribe(room, email, subtype, webpage);
238 else if (!strcasecmp(opr, "unsubscribe")) {
239 cprintf("%d not yet implemented\n", ERROR);
241 else if (!strcasecmp(opr, "confirm")) {
242 extract(room, cmdbuf, 1);
243 extract(token, cmdbuf, 2);
244 do_confirm(room, token);
247 cprintf("%d Invalid command\n", ERROR);
255 char *Dynamic_Module_Init(void)
257 CtdlRegisterProtoHook(cmd_subs, "SUBS", "List subscribe/unsubscribe");