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>
20 #if TIME_WITH_SYS_TIME
21 # include <sys/time.h>
25 # include <sys/time.h>
36 #include "sysdep_decls.h"
37 #include "citserver.h"
40 #include "dynloader.h"
47 #include "internet_addressing.h"
48 #include "serv_network.h"
51 void cmd_gnet(char *argbuf) {
56 if (CtdlAccessCheck(ac_room_aide)) return;
57 assoc_file_name(filename, &CC->quickroom, "netconfigs");
58 cprintf("%d Network settings for room #%ld <%s>\n",
60 CC->quickroom.QRnumber, CC->quickroom.QRname);
62 fp = fopen(filename, "r");
64 while (fgets(buf, sizeof buf, fp) != NULL) {
65 buf[strlen(buf)-1] = 0;
75 void cmd_snet(char *argbuf) {
76 char tempfilename[SIZ];
81 if (CtdlAccessCheck(ac_room_aide)) return;
82 safestrncpy(tempfilename, tmpnam(NULL), sizeof tempfilename);
83 assoc_file_name(filename, &CC->quickroom, "netconfigs");
85 fp = fopen(tempfilename, "w");
87 cprintf("%d Cannot open %s: %s\n",
93 cprintf("%d %s\n", SEND_LISTING, tempfilename);
94 while (client_gets(buf), strcmp(buf, "000")) {
95 fprintf(fp, "%s\n", buf);
99 /* Now copy the temp file to its permanent location
100 * (We use /bin/mv instead of link() because they may be on
101 * different filesystems)
104 snprintf(buf, sizeof buf, "/bin/mv %s %s", tempfilename, filename);
111 * Spools out one message from the list.
113 void network_spool_msg(long msgnum, void *userdata) {
114 struct SpoolControl *sc;
115 struct namelist *nptr;
119 struct CtdlMessage *imsg;
121 sc = (struct SpoolControl *)userdata;
123 /* If no recipients, bail out now.
124 * (May need to tweak this when we add other types of targets)
126 if (sc->listrecps == NULL) return;
128 /* First, copy it to the spoolout room */
129 err = CtdlSaveMsgPointerInRoom(SMTP_SPOOLOUT_ROOM, msgnum, 0);
130 if (err != 0) return;
132 lprintf(9, "Generating delivery instructions\n");
134 instr = mallok(instr_len);
136 "Content-type: %s\n\nmsgid|%ld\nsubmitted|%ld\n"
137 "bounceto|postmaster@%s\n" ,
138 SPOOLMIME, msgnum, time(NULL), config.c_fqdn );
140 imsg = mallok(sizeof(struct CtdlMessage));
141 memset(imsg, 0, sizeof(struct CtdlMessage));
142 imsg->cm_magic = CTDLMESSAGE_MAGIC;
143 imsg->cm_anon_type = MES_NORMAL;
144 imsg->cm_format_type = FMT_RFC822;
145 imsg->cm_fields['A'] = strdoop("Citadel");
146 imsg->cm_fields['M'] = instr;
148 /* Generate delivery instructions for each recipient */
149 for (nptr = sc->listrecps; nptr != NULL; nptr = nptr->next) {
150 if (instr_len - strlen(instr) < SIZ) {
151 instr_len = instr_len * 2;
152 instr = reallok(instr, instr_len);
154 sprintf(&instr[strlen(instr)], "remote|%s|0||\n",
158 /* Save delivery instructions in spoolout room */
159 CtdlSaveMsg(imsg, "", SMTP_SPOOLOUT_ROOM, MES_LOCAL);
160 CtdlFreeMessage(imsg);
162 /* update lastsent */
163 sc->lastsent = msgnum;
170 * Batch up and send all outbound traffic from the current room
172 void network_spoolout_current_room(void) {
177 struct SpoolControl sc;
178 /* struct namelist *digestrecps = NULL; */
179 struct namelist *nptr;
181 memset(&sc, 0, sizeof(struct SpoolControl));
182 assoc_file_name(filename, &CC->quickroom, "netconfigs");
184 fp = fopen(filename, "r");
186 lprintf(7, "Outbound batch processing skipped for <%s>\n",
187 CC->quickroom.QRname);
191 lprintf(5, "Outbound batch processing started for <%s>\n",
192 CC->quickroom.QRname);
194 while (fgets(buf, sizeof buf, fp) != NULL) {
195 buf[strlen(buf)-1] = 0;
197 extract(instr, buf, 0);
198 if (!strcasecmp(instr, "lastsent")) {
199 sc.lastsent = extract_long(buf, 1);
201 else if (!strcasecmp(instr, "listrecp")) {
202 nptr = (struct namelist *)
203 mallok(sizeof(struct namelist));
204 nptr->next = sc.listrecps;
205 extract(nptr->name, buf, 1);
214 /* Do something useful */
215 CtdlForEachMessage(MSGS_GT, sc.lastsent, (-63), NULL, NULL,
216 network_spool_msg, &sc);
219 /* Now rewrite the config file */
220 fp = fopen(filename, "w");
222 lprintf(1, "ERROR: cannot open %s: %s\n",
223 filename, strerror(errno));
226 fprintf(fp, "lastsent|%ld\n", sc.lastsent);
228 /* Write out the listrecps while freeing from memory at the
229 * same time. Am I clever or what? :)
231 while (sc.listrecps != NULL) {
232 fprintf(fp, "listrecp|%s\n", sc.listrecps->name);
233 nptr = sc.listrecps->next;
241 lprintf(5, "Outbound batch processing finished for <%s>\n",
242 CC->quickroom.QRname);
247 /* FIXME temporary server command for batch send */
248 void cmd_batc(char *argbuf) {
249 if (CtdlAccessCheck(ac_aide)) return;
251 network_spoolout_current_room();
253 cprintf("%d FIXME cmd_batc() ok\n", OK);
258 char *Dynamic_Module_Init(void)
260 CtdlRegisterProtoHook(cmd_gnet, "GNET", "Get network config");
261 CtdlRegisterProtoHook(cmd_snet, "SNET", "Get network config");
264 temporary server command for batch send
266 CtdlRegisterProtoHook(cmd_batc, "BATC", "send out batch (temp)");