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) {
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\n",
111 end_critical_section(S_NETCONFIGS);
113 /* Generate and send the confirmation request */
115 snprintf(confirmation_request, sizeof confirmation_request,
116 "Someone (probably you) has submitted a request to subscribe\n"
117 "<%s> to the '%s' mailing list.\n\n"
118 "In order to confirm this subscription request, please\n"
119 "point your web browser at the following location:\n\n"
120 "http://FIXME.com:FIXME/blah?room=%s&token=%s\n\n"
121 "If this request has been submitted in error and you do not\n"
122 "wish to receive the '%s' mailing list, simply do nothing,\n"
123 "and you will not receive any further mailings.\n",
125 email, qrbuf.QRname, qrbuf.QRname, token, qrbuf.QRname
135 cprintf("%d Subscription entered; confirmation request sent\n", CIT_OK);
141 * Confirm a subscribe/unsubscribe request.
143 void do_confirm(char *room, char *token) {
144 struct quickroom qrbuf;
147 char line_token[SIZ];
156 if (getroom(&qrbuf, room) != 0) {
157 cprintf("%d There is no list called '%s'\n", ERROR, room);
161 begin_critical_section(S_NETCONFIGS);
162 assoc_file_name(filename, sizeof filename, &qrbuf, "netconfigs");
163 ncfp = fopen(filename, "r+");
165 while (line_offset = ftell(ncfp),
166 (fgets(buf, sizeof buf, ncfp) != NULL) ) {
167 buf[strlen(buf)-1] = 0;
168 line_length = strlen(buf);
169 extract(cmd, buf, 0);
170 if (!strcasecmp(cmd, "subpending")) {
171 extract(email, buf, 1);
172 extract(subtype, buf, 2);
173 extract(line_token, buf, 3);
174 if (!strcasecmp(token, line_token)) {
175 if (!strcasecmp(subtype, "digest")) {
176 strcpy(buf, "digestrecp|");
179 strcpy(buf, "listrecp|");
183 /* SLEAZY HACK: pad the line out so
184 * it's the same length as the line
187 while (strlen(buf) < line_length) {
190 fseek(ncfp, line_offset, SEEK_SET);
191 fprintf(ncfp, "%s\n", buf);
198 end_critical_section(S_NETCONFIGS);
201 cprintf("%d %d operation(s) confirmed.\n", CIT_OK, success);
204 cprintf("%d Invalid token.\n", ERROR);
212 * process subscribe/unsubscribe requests and confirmations
214 void cmd_subs(char *cmdbuf) {
222 extract(opr, cmdbuf, 0);
223 if (!strcasecmp(opr, "subscribe")) {
224 extract(subtype, cmdbuf, 3);
225 if ( (strcasecmp(subtype, "list"))
226 && (strcasecmp(subtype, "digest")) ) {
227 cprintf("%d Invalid subscription type.\n", ERROR);
230 extract(room, cmdbuf, 1);
231 extract(email, cmdbuf, 2);
232 do_subscribe(room, email, subtype);
235 else if (!strcasecmp(opr, "unsubscribe")) {
236 cprintf("%d not yet implemented\n", ERROR);
238 else if (!strcasecmp(opr, "confirm")) {
239 extract(room, cmdbuf, 1);
240 extract(token, cmdbuf, 2);
241 do_confirm(room, token);
244 cprintf("%d Invalid command\n", ERROR);
252 char *Dynamic_Module_Init(void)
254 CtdlRegisterProtoHook(cmd_subs, "SUBS", "List subscribe/unsubscribe");