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];
71 if (CtdlAccessCheck(ac_room_aide)) return;
72 safestrncpy(tempfilename, tmpnam(NULL), sizeof tempfilename);
73 assoc_file_name(filename, &CC->quickroom, "netconfigs");
75 fp = fopen(tempfilename, "w");
77 cprintf("%d Cannot open %s: %s\n",
83 cprintf("%d %s\n", SEND_LISTING, tempfilename);
84 while (client_gets(buf), strcmp(buf, "000")) {
85 fprintf(fp, "%s\n", buf);
89 /* Now copy the temp file to its permanent location
90 * (We use /bin/mv instead of link() because they may be on
91 * different filesystems)
94 snprintf(buf, sizeof buf, "/bin/mv %s %s", tempfilename, filename);
101 * Spools out one message from the list.
103 void network_spool_msg(long msgnum, void *userdata) {
104 struct SpoolControl *sc;
105 struct namelist *nptr;
109 struct CtdlMessage *imsg;
111 sc = (struct SpoolControl *)userdata;
113 /* If no recipients, bail out now.
114 * (May need to tweak this when we add other types of targets)
116 if (sc->listrecps == NULL) return;
118 /* First, copy it to the spoolout room */
119 err = CtdlSaveMsgPointerInRoom(SMTP_SPOOLOUT_ROOM, msgnum, 0);
120 if (err != 0) return;
122 lprintf(9, "Generating delivery instructions\n");
124 instr = mallok(instr_len);
126 "Content-type: %s\n\nmsgid|%ld\nsubmitted|%ld\n"
127 "bounceto|postmaster@%s\n" ,
128 SPOOLMIME, msgnum, time(NULL), config.c_fqdn );
130 imsg = mallok(sizeof(struct CtdlMessage));
131 memset(imsg, 0, sizeof(struct CtdlMessage));
132 imsg->cm_magic = CTDLMESSAGE_MAGIC;
133 imsg->cm_anon_type = MES_NORMAL;
134 imsg->cm_format_type = FMT_RFC822;
135 imsg->cm_fields['A'] = strdoop("Citadel");
136 imsg->cm_fields['M'] = instr;
138 /* Generate delivery instructions for each recipient */
139 for (nptr = sc->listrecps; nptr != NULL; nptr = nptr->next) {
140 if (instr_len - strlen(instr) < SIZ) {
141 instr_len = instr_len * 2;
142 instr = reallok(instr, instr_len);
144 sprintf(&instr[strlen(instr)], "remote|%s|0||\n",
148 /* Save delivery instructions in spoolout room */
149 CtdlSaveMsg(imsg, "", SMTP_SPOOLOUT_ROOM, MES_LOCAL);
150 CtdlFreeMessage(imsg);
152 /* update lastsent */
153 sc->lastsent = msgnum;
160 * Batch up and send all outbound traffic from the current room
162 void network_spoolout_current_room(void) {
167 struct SpoolControl sc;
168 /* struct namelist *digestrecps = NULL; */
169 struct namelist *nptr;
171 memset(&sc, 0, sizeof(struct SpoolControl));
172 assoc_file_name(filename, &CC->quickroom, "netconfigs");
174 fp = fopen(filename, "r");
176 lprintf(7, "Outbound batch processing skipped for <%s>\n",
177 CC->quickroom.QRname);
181 lprintf(5, "Outbound batch processing started for <%s>\n",
182 CC->quickroom.QRname);
184 while (fgets(buf, sizeof buf, fp) != NULL) {
185 buf[strlen(buf)-1] = 0;
187 extract(instr, buf, 0);
188 if (!strcasecmp(instr, "lastsent")) {
189 sc.lastsent = extract_long(buf, 1);
191 else if (!strcasecmp(instr, "listrecp")) {
192 nptr = (struct namelist *)
193 mallok(sizeof(struct namelist));
194 nptr->next = sc.listrecps;
195 extract(nptr->name, buf, 1);
204 /* Do something useful */
205 CtdlForEachMessage(MSGS_GT, sc.lastsent, (-63), NULL, NULL,
206 network_spool_msg, &sc);
209 /* Now rewrite the config file */
210 fp = fopen(filename, "w");
212 lprintf(1, "ERROR: cannot open %s: %s\n",
213 filename, strerror(errno));
216 fprintf(fp, "lastsent|%ld\n", sc.lastsent);
218 /* Write out the listrecps while freeing from memory at the
219 * same time. Am I clever or what? :)
221 while (sc.listrecps != NULL) {
222 fprintf(fp, "listrecp|%s\n", sc.listrecps->name);
223 nptr = sc.listrecps->next;
231 lprintf(5, "Outbound batch processing finished for <%s>\n",
232 CC->quickroom.QRname);
237 /* FIXME temporary server command for batch send */
238 void cmd_batc(char *argbuf) {
239 if (CtdlAccessCheck(ac_aide)) return;
241 network_spoolout_current_room();
243 cprintf("%d FIXME cmd_batc() ok\n", OK);
248 char *Dynamic_Module_Init(void)
250 CtdlRegisterProtoHook(cmd_gnet, "GNET", "Get network config");
251 CtdlRegisterProtoHook(cmd_snet, "SNET", "Get network config");
254 temporary server command for batch send
256 CtdlRegisterProtoHook(cmd_batc, "BATC", "send out batch (temp)");