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;
91 if (getroom(&qrbuf, room) != 0) {
92 cprintf("%d There is no list called '%s'\n", ERROR, room);
96 listsub_generate_token(token);
98 begin_critical_section(S_NETCONFIGS);
99 assoc_file_name(filename, sizeof filename, &qrbuf, "netconfigs");
100 ncfp = fopen(filename, "a");
102 fprintf(ncfp, "subpending|%s|%s|%s|%ld\n",
110 end_critical_section(S_NETCONFIGS);
112 /* FIXME -- generate and send the confirmation request */
114 cprintf("%d Subscription entered; confirmation request sent\n", CIT_OK);
120 * Confirm a subscribe/unsubscribe request.
122 void do_confirm(char *room, char *token) {
123 struct quickroom qrbuf;
126 char line_token[SIZ];
135 if (getroom(&qrbuf, room) != 0) {
136 cprintf("%d There is no list called '%s'\n", ERROR, room);
140 begin_critical_section(S_NETCONFIGS);
141 assoc_file_name(filename, sizeof filename, &qrbuf, "netconfigs");
142 ncfp = fopen(filename, "r+");
144 while (line_offset = ftell(ncfp),
145 (fgets(buf, sizeof buf, ncfp) != NULL) ) {
146 buf[strlen(buf)-1] = 0;
147 line_length = strlen(buf);
148 extract(cmd, buf, 0);
149 if (!strcasecmp(cmd, "subpending")) {
150 extract(email, buf, 1);
151 extract(subtype, buf, 2);
152 extract(line_token, buf, 3);
153 if (!strcasecmp(token, line_token)) {
154 if (!strcasecmp(subtype, "digest")) {
155 strcpy(buf, "digestrecp|");
158 strcpy(buf, "listrecp|");
162 /* SLEAZY HACK: pad the line out so
163 * it's the same length as the line
166 while (strlen(buf) < line_length) {
169 fseek(ncfp, line_offset, SEEK_SET);
170 fprintf(ncfp, "%s\n", buf);
177 end_critical_section(S_NETCONFIGS);
180 cprintf("%d %d operation(s) confirmed.\n", CIT_OK, success);
183 cprintf("%d Invalid token.\n", ERROR);
191 * process subscribe/unsubscribe requests and confirmations
193 void cmd_subs(char *cmdbuf) {
201 extract(opr, cmdbuf, 0);
202 if (!strcasecmp(opr, "subscribe")) {
203 extract(subtype, cmdbuf, 3);
204 if ( (strcasecmp(subtype, "list"))
205 && (strcasecmp(subtype, "digest")) ) {
206 cprintf("%d Invalid subscription type.\n", ERROR);
209 extract(room, cmdbuf, 1);
210 extract(email, cmdbuf, 2);
211 do_subscribe(room, email, subtype);
214 else if (!strcasecmp(opr, "unsubscribe")) {
215 cprintf("%d not yet implemented\n", ERROR);
217 else if (!strcasecmp(opr, "confirm")) {
218 extract(room, cmdbuf, 1);
219 extract(token, cmdbuf, 2);
220 do_confirm(room, token);
223 cprintf("%d Invalid command\n", ERROR);
231 char *Dynamic_Module_Init(void)
233 CtdlRegisterProtoHook(cmd_subs, "SUBS", "List subscribe/unsubscribe");