/[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 169 - (hide annotations) (download)
Thu Aug 22 05:25:22 2002 UTC (10 years, 9 months ago) by weaselp
File MIME type: text/plain
File size: 10394 byte(s)
Only list supported if we support that type
1 rabbi 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 weaselp 169 $Id: stats.c,v 1.11 2002/08/22 05:25:22 weaselp Exp $ */
10 rabbi 1
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 rabbi 82 idlog_t idbuf;
63 rabbi 1
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 rabbi 82 f = mix_openfile(IDLOG, "rb");
112 rabbi 1 if (f != NULL) {
113 rabbi 82 while (fread(&idbuf, 1, sizeof(idlog_t), f) == sizeof(idlog_t)) {
114     then = idbuf.time;
115 rabbi 1 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 rabbi 143 /* display destinations to which delivery is explicitly permitted
246 weaselp 149 when in middleman mode (contents of DESTALLOW file.) */
247 rabbi 143
248 weaselp 90 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 rabbi 143 buf_appends(out, "In addition to other remailers, this remailer also sends mail to these\n addresses directly:\n");
257 weaselp 90 flag = 1;
258     }
259     buf_appendf(out, " %b\n", line);
260     }
261     }
262     }
263     }
264    
265 weaselp 107 flag = 0;
266 rabbi 1 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 weaselp 168
310     if (LISTSUPPORTED) {
311     /* SUPPORTED CPUNK (TYPE I) REMAILERS
312     * 0xDC7532F9 "Heex Remailer <remailer@xmailer.ods.org>"
313     * 0x759ED311 "znar <ka5tkn@cox-internet.com>"
314     *
315     * SUPPORTED MIXMASTER (TYPE II) REMAILERS
316     * aarg remailer@aarg.net 475f3f9fe8da22896c10082695a92c2d 2.9b33 C
317     * anon mixmaster@anon.978.org 7384ba1eec585bfd7d2b0e9b307f0b1d 2.9b36 MCNm
318     */
319    
320 weaselp 169 buf_nl(out);
321     /* FIXME
322     if (PGP) {
323     buf_appends(out, "SUPPORTED CPUNK (TYPE I) REMAILERS\n");
324     buf_nl(out);
325     }
326 weaselp 168 */
327 weaselp 169 if (MIX) {
328     buf_appends(out, "SUPPORTED MIXMASTER (TYPE II) REMAILERS\n");
329     prepare_type2list(out);
330     buf_nl(out);
331     }
332 weaselp 168 }
333    
334    
335 rabbi 1 if ( b ) buf_free(b);
336     buf_free(line);
337     return (0);
338     }
339    
340     void conf_premail(BUFFER *out)
341     {
342     buf_appends(out, "$remailer{\"");
343     buf_appends(out, SHORTNAME);
344     buf_appends(out, "\"} = \"<");
345     buf_appends(out, REMAILERADDR);
346     buf_appendc(out, '>');
347     if (PGP || UNENCRYPTED)
348     buf_appends(out, " cpunk");
349     if (MIX)
350     buf_appends(out, " mix");
351     if (MIDDLEMAN)
352     buf_appends(out, " middle");
353     if (PGP)
354     buf_appends(out, " pgp");
355     if (PGP && !UNENCRYPTED)
356     buf_appends(out, " pgponly");
357 rabbi 64 if (PGP && REPGP) {
358 rabbi 62 if (REMIX == 1)
359     buf_appends(out, " repgp");
360     else
361     buf_appends(out, " repgp2");
362     }
363 rabbi 1 if (REMIX == 1)
364     buf_appends(out, " remix");
365     else if (REMIX)
366     buf_appends(out, " remix2");
367     if (PGP || UNENCRYPTED)
368     buf_appends(out, " latent hash cut test");
369     if (PGP) {
370     #ifdef USE_IDEA
371     buf_appends(out, " ek");
372     #endif
373     buf_appends(out, " ekx");
374     }
375     #ifdef USE_IDEA
376     buf_appends(out, " esub");
377     #endif
378     #if 0 /* obsolete */
379     #ifdef USE_NSUB
380     buf_appends(out, " nsub");
381     #else
382     buf_appends(out, " ksub");
383     #endif
384     #endif
385     if (INFLATEMAX)
386     buf_appendf(out, " inflt%d", INFLATEMAX);
387     if (MAXRANDHOPS)
388     buf_appendf(out, " rhop%d", MAXRANDHOPS);
389     if (POOLSIZE >= 5)
390     buf_appends(out, " reord");
391     if (NEWS[0])
392     buf_appends(out, " post");
393     if (SIZELIMIT)
394     buf_appendf(out, " klen%d", SIZELIMIT);
395     buf_appends(out, "\";\n");
396     }

  ViewVC Help
Powered by ViewVC 1.1.5