]> code.citadel.org Git - citadel.git/blob - citadel/serv_network.c
* Changed all the "200 ok" responses to more descriptive strings
[citadel.git] / citadel / serv_network.c
1 /*
2  * $Id$ 
3  *
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.
7  *
8  */
9
10
11 /* FIXME
12
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.
15
16 */
17
18 #include "sysdep.h"
19 #include <stdlib.h>
20 #include <unistd.h>
21 #include <stdio.h>
22 #include <fcntl.h>
23 #include <signal.h>
24 #include <pwd.h>
25 #include <errno.h>
26 #include <sys/types.h>
27 #include <sys/time.h>
28 #include <sys/wait.h>
29 #include <string.h>
30 #include <limits.h>
31 #include "citadel.h"
32 #include "server.h"
33 #include <time.h>
34 #include "sysdep_decls.h"
35 #include "citserver.h"
36 #include "support.h"
37 #include "config.h"
38 #include "dynloader.h"
39 #include "room_ops.h"
40 #include "user_ops.h"
41 #include "policy.h"
42 #include "database.h"
43 #include "msgbase.h"
44 #include "tools.h"
45 #include "internet_addressing.h"
46 #include "serv_network.h"
47
48
49 void cmd_gnet(char *argbuf) {
50         char filename[256];
51         char buf[256];
52         FILE *fp;
53
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",
57                 LISTING_FOLLOWS,
58                 CC->quickroom.QRnumber, CC->quickroom.QRname);
59
60         fp = fopen(filename, "r");
61         if (fp != NULL) {
62                 while (fgets(buf, sizeof buf, fp) != NULL) {
63                         buf[strlen(buf)-1] = 0;
64                         cprintf("%s\n", buf);
65                 }
66                 fclose(fp);
67         }
68
69         cprintf("000\n");
70 }
71
72
73 void cmd_snet(char *argbuf) {
74         char tempfilename[256];
75         char filename[256];
76         char buf[256];
77         FILE *fp;
78
79         if (CtdlAccessCheck(ac_room_aide)) return;
80         safestrncpy(tempfilename, tmpnam(NULL), sizeof tempfilename);
81         assoc_file_name(filename, &CC->quickroom, "netconfigs");
82
83         fp = fopen(tempfilename, "w");
84         if (fp == NULL) {
85                 cprintf("%d Cannot open %s: %s\n",
86                         ERROR+INTERNAL_ERROR,
87                         tempfilename,
88                         strerror(errno));
89         }
90
91         cprintf("%d %s\n", SEND_LISTING, tempfilename);
92         while (client_gets(buf), strcmp(buf, "000")) {
93                 fprintf(fp, "%s\n", buf);
94         }
95         fclose(fp);
96
97         /* Now that we've got the whole file, put it in place */
98         unlink(filename);
99         link(tempfilename, filename);
100         unlink(tempfilename);
101 }
102
103
104
105
106 /*
107  * Batch up and send all outbound traffic from the current room
108  */
109 void network_spoolout_current_room(void) {
110         char filename[256];
111         char buf[256];
112         char instr[256];
113         FILE *fp;
114         long lastsent = 0L;
115         struct namelist *listrecps = NULL;
116         /* struct namelist *digestrecps = NULL; */
117         struct namelist *nptr;
118
119         assoc_file_name(filename, &CC->quickroom, "netconfigs");
120
121         fp = fopen(filename, "r");
122         if (fp == NULL) {
123                 lprintf(7, "Outbound batch processing skipped for <%s>\n",
124                         CC->quickroom.QRname);
125                 return;
126         }
127
128         lprintf(5, "Outbound batch processing started for <%s>\n",
129                 CC->quickroom.QRname);
130
131         while (fgets(buf, sizeof buf, fp) != NULL) {
132                 buf[strlen(buf)-1] = 0;
133
134                 extract(instr, buf, 0);
135                 if (!strcasecmp(instr, "lastsent")) {
136                         lastsent = extract_long(buf, 1);
137                 }
138                 else if (!strcasecmp(instr, "listrecp")) {
139                         nptr = (struct namelist *)
140                                 mallok(sizeof(struct namelist));
141                         nptr->next = listrecps;
142                         extract(nptr->name, buf, 1);
143                         listrecps = nptr;
144                 }
145
146
147         }
148         fclose(fp);
149
150
151         /* Do something useful */
152
153
154
155
156
157
158
159         /* Now rewrite the config file */
160         fp = fopen(filename, "w");
161         if (fp == NULL) {
162                 lprintf(1, "ERROR: cannot open %s: %s\n",
163                         filename, strerror(errno));
164         }
165         else {
166                 fprintf(fp, "lastsent|%ld\n", lastsent);
167
168                 /* Write out the listrecps while freeing from memory at the
169                  * same time.  Am I clever or what?  :)
170                  */
171                 while (listrecps != NULL) {
172                         fprintf(fp, "listrecp|%s\n", listrecps->name);
173                         nptr = listrecps->next;
174                         phree(listrecps);
175                         listrecps = nptr;
176                 }
177
178                 fclose(fp);
179         }
180
181         lprintf(5, "Outbound batch processing finished for <%s>\n",
182                 CC->quickroom.QRname);
183 }
184
185
186
187 /* FIXME temporary server command for batch send */
188 void cmd_batc(char *argbuf) {
189         if (CtdlAccessCheck(ac_aide)) return;
190
191         network_spoolout_current_room();
192
193         cprintf("%d FIXME cmd_batc() ok\n", OK);
194 }
195
196
197
198 char *Dynamic_Module_Init(void)
199 {
200         CtdlRegisterProtoHook(cmd_gnet, "GNET", "Get network config");
201         CtdlRegisterProtoHook(cmd_snet, "SNET", "Get network config");
202
203         /* FIXME
204            temporary server command for batch send
205          */
206         CtdlRegisterProtoHook(cmd_batc, "BATC", "send out batch (temp)");
207
208         return "$Id$";
209 }