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.
18 #include <sys/types.h>
26 #include "sysdep_decls.h"
27 #include "citserver.h"
30 #include "dynloader.h"
37 #include "internet_addressing.h"
38 #include "serv_network.h"
41 void cmd_gnet(char *argbuf) {
46 if (CtdlAccessCheck(ac_room_aide)) return;
47 assoc_file_name(filename, &CC->quickroom, "netconfigs");
48 cprintf("%d Network settings for room #%ld <%s>\n",
50 CC->quickroom.QRnumber, CC->quickroom.QRname);
52 fp = fopen(filename, "r");
54 while (fgets(buf, sizeof buf, fp) != NULL) {
55 buf[strlen(buf)-1] = 0;
65 void cmd_snet(char *argbuf) {
66 char tempfilename[SIZ];
72 if (CtdlAccessCheck(ac_room_aide)) return;
73 safestrncpy(tempfilename, tmpnam(NULL), sizeof tempfilename);
74 assoc_file_name(filename, &CC->quickroom, "netconfigs");
76 fp = fopen(tempfilename, "w");
78 cprintf("%d Cannot open %s: %s\n",
84 cprintf("%d %s\n", SEND_LISTING, tempfilename);
85 while (client_gets(&ibuf), strcmp(ibuf, "000")) {
86 fprintf(fp, "%s\n", ibuf);
90 /* Now copy the temp file to its permanent location
91 * (We use /bin/mv instead of link() because they may be on
92 * different filesystems)
95 snprintf(cbuf, sizeof cbuf, "/bin/mv %s %s", tempfilename, filename);
102 * Spools out one message from the list.
104 void network_spool_msg(long msgnum, void *userdata) {
105 struct SpoolControl *sc;
106 struct namelist *nptr;
110 struct CtdlMessage *imsg;
112 sc = (struct SpoolControl *)userdata;
114 /* If no recipients, bail out now.
115 * (May need to tweak this when we add other types of targets)
117 if (sc->listrecps == NULL) return;
119 /* First, copy it to the spoolout room */
120 err = CtdlSaveMsgPointerInRoom(SMTP_SPOOLOUT_ROOM, msgnum, 0);
121 if (err != 0) return;
123 lprintf(9, "Generating delivery instructions\n");
125 instr = mallok(instr_len);
127 "Content-type: %s\n\nmsgid|%ld\nsubmitted|%ld\n"
128 "bounceto|postmaster@%s\n" ,
129 SPOOLMIME, msgnum, time(NULL), config.c_fqdn );
131 imsg = mallok(sizeof(struct CtdlMessage));
132 memset(imsg, 0, sizeof(struct CtdlMessage));
133 imsg->cm_magic = CTDLMESSAGE_MAGIC;
134 imsg->cm_anon_type = MES_NORMAL;
135 imsg->cm_format_type = FMT_RFC822;
136 imsg->cm_fields['A'] = strdoop("Citadel");
137 imsg->cm_fields['M'] = instr;
139 /* Generate delivery instructions for each recipient */
140 for (nptr = sc->listrecps; nptr != NULL; nptr = nptr->next) {
141 if (instr_len - strlen(instr) < SIZ) {
142 instr_len = instr_len * 2;
143 instr = reallok(instr, instr_len);
145 sprintf(&instr[strlen(instr)], "remote|%s|0||\n",
149 /* Save delivery instructions in spoolout room */
150 CtdlSaveMsg(imsg, "", SMTP_SPOOLOUT_ROOM, MES_LOCAL);
151 CtdlFreeMessage(imsg);
153 /* update lastsent */
154 sc->lastsent = msgnum;
161 * Batch up and send all outbound traffic from the current room
163 void network_spoolout_current_room(void) {
168 struct SpoolControl sc;
169 /* struct namelist *digestrecps = NULL; */
170 struct namelist *nptr;
172 memset(&sc, 0, sizeof(struct SpoolControl));
173 assoc_file_name(filename, &CC->quickroom, "netconfigs");
175 fp = fopen(filename, "r");
177 lprintf(7, "Outbound batch processing skipped for <%s>\n",
178 CC->quickroom.QRname);
182 lprintf(5, "Outbound batch processing started for <%s>\n",
183 CC->quickroom.QRname);
185 while (fgets(buf, sizeof buf, fp) != NULL) {
186 buf[strlen(buf)-1] = 0;
188 extract(instr, buf, 0);
189 if (!strcasecmp(instr, "lastsent")) {
190 sc.lastsent = extract_long(buf, 1);
192 else if (!strcasecmp(instr, "listrecp")) {
193 nptr = (struct namelist *)
194 mallok(sizeof(struct namelist));
195 nptr->next = sc.listrecps;
196 extract(nptr->name, buf, 1);
205 /* Do something useful */
206 CtdlForEachMessage(MSGS_GT, sc.lastsent, (-63), NULL, NULL,
207 network_spool_msg, &sc);
210 /* Now rewrite the config file */
211 fp = fopen(filename, "w");
213 lprintf(1, "ERROR: cannot open %s: %s\n",
214 filename, strerror(errno));
217 fprintf(fp, "lastsent|%ld\n", sc.lastsent);
219 /* Write out the listrecps while freeing from memory at the
220 * same time. Am I clever or what? :)
222 while (sc.listrecps != NULL) {
223 fprintf(fp, "listrecp|%s\n", sc.listrecps->name);
224 nptr = sc.listrecps->next;
232 lprintf(5, "Outbound batch processing finished for <%s>\n",
233 CC->quickroom.QRname);
238 /* FIXME temporary server command for batch send */
239 void cmd_batc(char *argbuf) {
240 if (CtdlAccessCheck(ac_aide)) return;
242 network_spoolout_current_room();
244 cprintf("%d FIXME cmd_batc() ok\n", OK);
249 char *Dynamic_Module_Init(void)
251 CtdlRegisterProtoHook(cmd_gnet, "GNET", "Get network config");
252 CtdlRegisterProtoHook(cmd_snet, "SNET", "Get network config");
255 temporary server command for batch send
257 CtdlRegisterProtoHook(cmd_batc, "BATC", "send out batch (temp)");