/[pkg-mixmaster]/trunk/Mix/Src/stats.c
ViewVC logotype

Contents of /trunk/Mix/Src/stats.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 143 - (show annotations) (download)
Tue Aug 20 18:46:33 2002 UTC (10 years, 9 months ago) by rabbi
File MIME type: text/plain
File size: 9712 byte(s)
Fixed wording.
1 /* Mixmaster version 3 -- (C) 1999 Anonymizer Inc.
2
3 Mixmaster may be redistributed and modified under certain conditions.
4 This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
5 ANY KIND, either express or implied. See the file COPYRIGHT for
6 details.
7
8 Remailer statistics
9 $Id: stats.c,v 1.8 2002/08/20 18:46:33 rabbi Exp $ */
10
11
12 #include "mix3.h"
13 #include <stdio.h>
14 #include <string.h>
15 #include <time.h>
16
17 /* log that a message of type t has been received. Statistics for type 2
18 messages are taken from the IDLOG instead of calling this function */
19 int stats_log(int t)
20 {
21 FILE *f;
22
23 f = mix_openfile(STATS, "a");
24 if (f == NULL) {
25 errlog(ERRORMSG, "Can't open %s!\n", STATS);
26 return (-1);
27 }
28 lock(f);
29 fprintf(f, "%d 1 %ld\n", t, (long) time(NULL));
30 unlock(f);
31 fclose(f);
32 return (0);
33 }
34
35 /* log the current pool size after sending messages */
36 int stats_out(int pool)
37 {
38 FILE *f;
39
40 f = mix_openfile(STATS, "a");
41 if (f == NULL) {
42 errlog(ERRORMSG, "Can't open %s!\n", STATS);
43 return (-1);
44 }
45 lock(f);
46 fprintf(f, "p 1 %d %ld\n", pool, (long) time(NULL));
47 unlock(f);
48 fclose(f);
49 return (0);
50 }
51
52 int stats(BUFFER *b)
53 {
54 FILE *s, *f;
55 char line[LINELEN];
56 long now, today, then;
57 time_t t;
58 long updated = 0, havestats = 0;
59 int msgd[3][24], msg[3][80];
60 int poold[2][24], pool[2][80];
61 int i, num, type;
62 idlog_t idbuf;
63
64 now = (time(NULL) / (60 * 60) + 1) * 60 * 60;
65 today = (now / SECONDSPERDAY) * SECONDSPERDAY;
66
67 for (i = 0; i < 24; i++)
68 msgd[0][i] = msgd[1][i] = msgd[2][i] = poold[0][i] = poold[1][i] = 0;
69 for (i = 0; i < 80; i++)
70 msg[0][i] = msg[1][i] = msg[2][i] = pool[0][i] = pool[1][i] = 0;
71
72 s = mix_openfile(STATS, "r");
73 if (s != NULL) {
74 lock(s);
75 fscanf(s, "%ld", &updated);
76 while (fgets(line, sizeof(line), s) != NULL) {
77 switch (line[0]) {
78 case '0':
79 case '1':
80 case '2':
81 sscanf(line, "%d %d %ld", &type, &num, &then);
82 if (now - then < 0)
83 break; /* keep memory consistent even if the time
84 suddenly goes backwards :) */
85 if (now - then < SECONDSPERDAY)
86 msgd[type][(now - then) / (60 * 60)] += num;
87 else if (today - then < 80 * SECONDSPERDAY)
88 msg[type][(today - then) / SECONDSPERDAY] += num;
89 if (havestats == 0 || then < havestats)
90 havestats = then;
91 break;
92 case 'p':
93 sscanf(line, "p %d %d %ld", &num, &i, &then);
94 if (now - then < 0)
95 break;
96 if (now - then < SECONDSPERDAY) {
97 poold[0][(now - then) / (60 * 60)] += num;
98 poold[1][(now - then) / (60 * 60)] += i;
99 } else if (today - then < 80 * SECONDSPERDAY) {
100 poold[0][(today - then) / (24 * 60 * 60)] += num;
101 poold[1][(today - then) / (24 * 60 * 60)] += i;
102 }
103 if (havestats == 0 || then < havestats)
104 havestats = then;
105 break;
106 }
107 }
108 unlock(s);
109 fclose(s);
110 }
111 f = mix_openfile(IDLOG, "rb");
112 if (f != NULL) {
113 while (fread(&idbuf, 1, sizeof(idlog_t), f) == sizeof(idlog_t)) {
114 then = idbuf.time;
115 if (then < updated || now - then < 0)
116 continue;
117 if (now - then < SECONDSPERDAY)
118 msgd[2][(now - then) / (60 * 60)]++;
119 else if (today - then < 80 * SECONDSPERDAY)
120 msg[2][(today - then) / SECONDSPERDAY]++;
121 if (havestats == 0 || then < havestats)
122 havestats = then;
123 }
124 fclose(f);
125 }
126 if (havestats == 0) {
127 if (b != NULL)
128 errlog(NOTICE, "No statistics available.\n");
129 return (-1);
130 }
131 s = mix_openfile(STATS, "w");
132 if (s == NULL) {
133 errlog(ERRORMSG, "Can't create %s!\n", STATS);
134 return (-1);
135 }
136 lock(s);
137 fprintf(s, "%ld\n", (long) time(NULL)); /* time of stats.log update */
138 for (i = 0; i < 24; i++) {
139 for (type = 0; type < 3; type++)
140 if (msgd[type][i] > 0)
141 fprintf(s, "%d %d %ld\n", type, msgd[type][i], now - i * 60 * 60);
142 if (poold[0][i] > 0)
143 fprintf(s, "p %d %d %ld\n", poold[0][i], poold[1][i], now - i * 60 * 60);
144 }
145 for (i = 0; i < 80; i++) {
146 for (type = 0; type < 3; type++)
147 if (msg[type][i] > 0)
148 fprintf(s, "%d %d %ld\n", type, msg[type][i],
149 today - i * 24 * 60 * 60);
150 if (pool[0][i] > 0)
151 fprintf(s, "p %d %d %ld\n", pool[0][i], pool[1][i],
152 today - i * 24 * 60 * 60);
153 }
154 unlock(s);
155 fclose(s);
156 if (b != NULL) {
157 struct tm *gt;
158
159 buf_sets(b, "Subject: Statistics for the ");
160 buf_appends(b, SHORTNAME);
161 buf_appends(b, " remailer\n\n");
162
163 buf_appends(b, "Number of messages in the past 24 hours:\n");
164 t = now;
165 gt = gmtime(&t);
166 for (i = 23; i >= 0; i--) {
167 buf_appendf(b, " %2dh: ", (24 + gt->tm_hour - i) % 24);
168 if (MIX) {
169 if (PGP || UNENCRYPTED)
170 buf_appends(b, " Mix:");
171 buf_appendf(b, "%4d", msgd[2][i]);
172 }
173 if (PGP)
174 buf_appendf(b, " PGP: %4d", msgd[1][i]);
175 if (UNENCRYPTED)
176 buf_appendf(b, " Unencrypted:%4d", msgd[0][i]);
177 if (poold[0][i] > 0)
178 buf_appendf(b, " [Pool size:%4d]", poold[1][i] / poold[0][i]);
179 #if 0
180 else
181 buf_appends(b, " [ no remailing ]");
182 #endif
183 buf_nl(b);
184 }
185 if ((today - havestats) / SECONDSPERDAY >= 1)
186 buf_appends(b, "\nNumber of messages per day:\n");
187 for ((i = (today - havestats) / SECONDSPERDAY) > 79 ? 79 : i;
188 i >= 1; i--) {
189 t = now - i * SECONDSPERDAY;
190 gt = localtime(&t);
191 strftime(line, LINELEN, "%d %b: ", gt);
192 buf_appends(b, line);
193
194 if (MIX) {
195 if (PGP || UNENCRYPTED)
196 buf_appends(b, " Mix:");
197 buf_appendf(b, "%4d", msg[2][i]);
198 }
199 if (PGP)
200 buf_appendf(b, " PGP: %4d", msg[1][i]);
201 if (UNENCRYPTED)
202 buf_appendf(b, " Unencrypted:%4d", msg[0][i]);
203 if (pool[0][i] > 0)
204 buf_appendf(b, " [Pool size:%4d]", pool[1][i] / pool[0][i]);
205 #if 0
206 else
207 buf_appends(b, " [ no remailing ]");
208 #endif
209 buf_nl(b);
210 }
211 }
212 return (0);
213 }
214
215 int conf(BUFFER *out)
216 {
217 FILE *f;
218 BUFFER *b, *line;
219 int flag = 0;
220 b = buf_new();
221 line = buf_new();
222
223 buf_sets(out, "Subject: Capabilities of the ");
224 buf_appends(out, SHORTNAME);
225 buf_appends(out, " remailer\n\n");
226 buf_appends(out, remailer_type);
227 buf_appends(out, VERSION);
228 buf_nl(out);
229
230 if (MIX + PGP + UNENCRYPTED == 1)
231 buf_appends(out, "Supported format:");
232 else
233 buf_appends(out, "Supported formats:\n");
234 if (MIX)
235 buf_appends(out, " Mixmaster\n");
236 if (PGP)
237 buf_appends(out, " Cypherpunk with PGP encryption\n");
238 if (UNENCRYPTED)
239 buf_appends(out, " Cypherpunk (unencrypted)\n");
240
241 buf_appendf(out, "Pool size: %d\n", POOLSIZE);
242 if (SIZELIMIT)
243 buf_appendf(out, "Maximum message size: %d kB\n", SIZELIMIT);
244
245 /* display destinations to which delivery is explicitly permitted
246 when in middleman mode (contents of DESTALLOWf file.) */
247
248 if (MIDDLEMAN) {
249 f = mix_openfile(DESTALLOW, "r");
250 if (f != NULL) {
251 buf_read(b, f);
252 fclose(f);
253 while(buf_getline(b, line) != -1) {
254 if (line->length > 0 && line->data[0] != '#') {
255 if (flag == 0) {
256 buf_appends(out, "In addition to other remailers, this remailer also sends mail to these\n addresses directly:\n");
257 flag = 1;
258 }
259 buf_appendf(out, " %b\n", line);
260 }
261 }
262 }
263 }
264
265 flag = 0;
266 f = mix_openfile(HDRFILTER, "r");
267 if (f != NULL) {
268 buf_read(b, f);
269 fclose(f);
270 while(buf_getline(b, line) != -1)
271 if (line->length > 0 && line->data[0] != '#') {
272 if (flag == 0) {
273 buf_appends(out, "The following header lines will be filtered:\n");
274 flag = 1;
275 }
276 buf_appends(out, " ");
277 if (line->length > 3 && streq(line->data + line->length - 2, "/q")) {
278 buf_append(out, line->data, line->length - 1);
279 buf_appends(out, " => delete message");
280 }
281 else
282 buf_cat(out, line);
283 buf_nl(out);
284 }
285 buf_free(b);
286 }
287 flag = 0;
288 b = readdestblk( );
289 if ( b != NULL ) {
290 while(buf_getline(b, line) != -1)
291 if (line->length > 0 && !bufleft(line, "#") && !buffind(line, "@")) {
292 /* mail addresses are not listed */
293 if (flag == 0) {
294 if (NEWS[0])
295 buf_appends(out,
296 "The following newsgroups/domains are blocked:\n");
297 else
298 buf_appends(out, "The following domains are blocked:\n");
299 flag = 1;
300 }
301 buf_appendf(out, " %b\n", line);
302 }
303 if (flag == 0 && NEWS[0])
304 buf_appends(out, "Note that other newsgroups may be unavailable at the remailer's news server.\n");
305 }
306
307 buf_nl(out);
308 conf_premail(out);
309 if ( b ) buf_free(b);
310 buf_free(line);
311 return (0);
312 }
313
314 void conf_premail(BUFFER *out)
315 {
316 buf_appends(out, "$remailer{\"");
317 buf_appends(out, SHORTNAME);
318 buf_appends(out, "\"} = \"<");
319 buf_appends(out, REMAILERADDR);
320 buf_appendc(out, '>');
321 if (PGP || UNENCRYPTED)
322 buf_appends(out, " cpunk");
323 if (MIX)
324 buf_appends(out, " mix");
325 if (MIDDLEMAN)
326 buf_appends(out, " middle");
327 if (PGP)
328 buf_appends(out, " pgp");
329 if (PGP && !UNENCRYPTED)
330 buf_appends(out, " pgponly");
331 if (PGP && REPGP) {
332 if (REMIX == 1)
333 buf_appends(out, " repgp");
334 else
335 buf_appends(out, " repgp2");
336 }
337 if (REMIX == 1)
338 buf_appends(out, " remix");
339 else if (REMIX)
340 buf_appends(out, " remix2");
341 if (PGP || UNENCRYPTED)
342 buf_appends(out, " latent hash cut test");
343 if (PGP) {
344 #ifdef USE_IDEA
345 buf_appends(out, " ek");
346 #endif
347 buf_appends(out, " ekx");
348 }
349 #ifdef USE_IDEA
350 buf_appends(out, " esub");
351 #endif
352 #if 0 /* obsolete */
353 #ifdef USE_NSUB
354 buf_appends(out, " nsub");
355 #else
356 buf_appends(out, " ksub");
357 #endif
358 #endif
359 if (INFLATEMAX)
360 buf_appendf(out, " inflt%d", INFLATEMAX);
361 if (MAXRANDHOPS)
362 buf_appendf(out, " rhop%d", MAXRANDHOPS);
363 if (POOLSIZE >= 5)
364 buf_appends(out, " reord");
365 if (NEWS[0])
366 buf_appends(out, " post");
367 if (SIZELIMIT)
368 buf_appendf(out, " klen%d", SIZELIMIT);
369 buf_appends(out, "\";\n");
370 }

  ViewVC Help
Powered by ViewVC 1.1.5