4 * This module will eventually replace netproc and some of its utilities.
5 * Copyright (C) 2000 by Art Cancro and others.
6 * This code is released under the terms of the GNU General Public License.
13 there's stuff in here that makes the assumption that /tmp is on the same
14 filesystem as Citadel, and makes calls to link() on that basis. fix this.
26 #include <sys/types.h>
34 #include "sysdep_decls.h"
35 #include "citserver.h"
38 #include "dynloader.h"
45 #include "internet_addressing.h"
46 #include "serv_network.h"
49 void cmd_gnet(char *argbuf) {
54 if (CtdlAccessCheck(ac_room_aide)) return;
55 assoc_file_name(filename, &CC->quickroom, "netconfigs");
56 cprintf("%d Network settings for room #%ld <%s>\n",
58 CC->quickroom.QRnumber, CC->quickroom.QRname);
60 fp = fopen(filename, "r");
62 while (fgets(buf, sizeof buf, fp) != NULL) {
63 buf[strlen(buf)-1] = 0;
73 void cmd_snet(char *argbuf) {
74 char tempfilename[256];
79 if (CtdlAccessCheck(ac_room_aide)) return;
80 safestrncpy(tempfilename, tmpnam(NULL), sizeof tempfilename);
81 assoc_file_name(filename, &CC->quickroom, "netconfigs");
83 fp = fopen(tempfilename, "w");
85 cprintf("%d Cannot open %s: %s\n",
91 cprintf("%d %s\n", SEND_LISTING, tempfilename);
92 while (client_gets(buf), strcmp(buf, "000")) {
93 fprintf(fp, "%s\n", buf);
97 /* Now that we've got the whole file, put it in place */
99 link(tempfilename, filename);
100 unlink(tempfilename);
106 * Spools out one message from the list.
108 void network_spool_msg(long msgnum, void *userdata) {
109 struct SpoolControl *sc;
110 struct namelist *nptr;
114 struct CtdlMessage *imsg;
116 sc = (struct SpoolControl *)userdata;
118 /* If no recipients, bail out now.
119 * (May need to tweak this when we add other types of targets)
121 if (sc->listrecps == NULL) return;
123 /* First, copy it to the spoolout room */
124 err = CtdlSaveMsgPointerInRoom(SMTP_SPOOLOUT_ROOM, msgnum, 0);
125 if (err != 0) return;
127 lprintf(9, "Generating delivery instructions\n");
129 instr = mallok(instr_len);
131 "Content-type: %s\n\nmsgid|%ld\nsubmitted|%ld\n"
132 "bounceto|postmaster@%s\n" ,
133 SPOOLMIME, msgnum, time(NULL), config.c_fqdn );
135 imsg = mallok(sizeof(struct CtdlMessage));
136 memset(imsg, 0, sizeof(struct CtdlMessage));
137 imsg->cm_magic = CTDLMESSAGE_MAGIC;
138 imsg->cm_anon_type = MES_NORMAL;
139 imsg->cm_format_type = FMT_RFC822;
140 imsg->cm_fields['A'] = strdoop("Citadel");
141 imsg->cm_fields['M'] = instr;
143 /* Generate delivery instructions for each recipient */
144 for (nptr = sc->listrecps; nptr != NULL; nptr = nptr->next) {
145 if (instr_len - strlen(instr) < 256) {
146 instr_len = instr_len * 2;
147 instr = reallok(instr, instr_len);
149 sprintf(&instr[strlen(instr)], "remote|%s|0||\n",
153 /* Save delivery instructions in spoolout room */
154 CtdlSaveMsg(imsg, "", SMTP_SPOOLOUT_ROOM, MES_LOCAL);
155 CtdlFreeMessage(imsg);
157 /* update lastsent */
158 sc->lastsent = msgnum;
165 * Batch up and send all outbound traffic from the current room
167 void network_spoolout_current_room(void) {
172 struct SpoolControl sc;
173 /* struct namelist *digestrecps = NULL; */
174 struct namelist *nptr;
176 memset(&sc, 0, sizeof(struct SpoolControl));
177 assoc_file_name(filename, &CC->quickroom, "netconfigs");
179 fp = fopen(filename, "r");
181 lprintf(7, "Outbound batch processing skipped for <%s>\n",
182 CC->quickroom.QRname);
186 lprintf(5, "Outbound batch processing started for <%s>\n",
187 CC->quickroom.QRname);
189 while (fgets(buf, sizeof buf, fp) != NULL) {
190 buf[strlen(buf)-1] = 0;
192 extract(instr, buf, 0);
193 if (!strcasecmp(instr, "lastsent")) {
194 sc.lastsent = extract_long(buf, 1);
196 else if (!strcasecmp(instr, "listrecp")) {
197 nptr = (struct namelist *)
198 mallok(sizeof(struct namelist));
199 nptr->next = sc.listrecps;
200 extract(nptr->name, buf, 1);
209 /* Do something useful */
210 CtdlForEachMessage(MSGS_ALL, 0L, (-63), NULL, NULL,
211 network_spool_msg, &sc);
214 /* Now rewrite the config file */
215 fp = fopen(filename, "w");
217 lprintf(1, "ERROR: cannot open %s: %s\n",
218 filename, strerror(errno));
221 fprintf(fp, "lastsent|%ld\n", sc.lastsent);
223 /* Write out the listrecps while freeing from memory at the
224 * same time. Am I clever or what? :)
226 while (sc.listrecps != NULL) {
227 fprintf(fp, "listrecp|%s\n", sc.listrecps->name);
228 nptr = sc.listrecps->next;
236 lprintf(5, "Outbound batch processing finished for <%s>\n",
237 CC->quickroom.QRname);
242 /* FIXME temporary server command for batch send */
243 void cmd_batc(char *argbuf) {
244 if (CtdlAccessCheck(ac_aide)) return;
246 network_spoolout_current_room();
248 cprintf("%d FIXME cmd_batc() ok\n", OK);
253 char *Dynamic_Module_Init(void)
255 CtdlRegisterProtoHook(cmd_gnet, "GNET", "Get network config");
256 CtdlRegisterProtoHook(cmd_snet, "SNET", "Get network config");
259 temporary server command for batch send
261 CtdlRegisterProtoHook(cmd_batc, "BATC", "send out batch (temp)");