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

Contents of /branches/mixmaster_2_9_STABLE/Mix/Src/stats.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 327 - (hide annotations) (download)
Wed Oct 9 20:29:44 2002 UTC (10 years, 8 months ago) by weaselp
File MIME type: text/plain
File size: 11259 byte(s)
Added closing comments for all #ifdef statements.
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 327 $Id: stats.c,v 1.8.2.4 2002/10/09 20:29:44 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 rabbi 316 if (REMAIL == 0)
41     return (0); /* don't keep statistics for the client */
42    
43 rabbi 1 f = mix_openfile(STATS, "a");
44     if (f == NULL) {
45     errlog(ERRORMSG, "Can't open %s!\n", STATS);
46     return (-1);
47     }
48     lock(f);
49     fprintf(f, "p 1 %d %ld\n", pool, (long) time(NULL));
50     unlock(f);
51     fclose(f);
52     return (0);
53     }
54    
55     int stats(BUFFER *b)
56     {
57     FILE *s, *f;
58     char line[LINELEN];
59     long now, today, then;
60     time_t t;
61     long updated = 0, havestats = 0;
62     int msgd[3][24], msg[3][80];
63     int poold[2][24], pool[2][80];
64 rabbi 244 int i, num, type, assigned, daysum;
65     char c;
66 rabbi 82 idlog_t idbuf;
67 rabbi 1
68     now = (time(NULL) / (60 * 60) + 1) * 60 * 60;
69     today = (now / SECONDSPERDAY) * SECONDSPERDAY;
70    
71     for (i = 0; i < 24; i++)
72     msgd[0][i] = msgd[1][i] = msgd[2][i] = poold[0][i] = poold[1][i] = 0;
73     for (i = 0; i < 80; i++)
74     msg[0][i] = msg[1][i] = msg[2][i] = pool[0][i] = pool[1][i] = 0;
75    
76     s = mix_openfile(STATS, "r");
77     if (s != NULL) {
78     lock(s);
79     fscanf(s, "%ld", &updated);
80     while (fgets(line, sizeof(line), s) != NULL) {
81     switch (line[0]) {
82     case '0':
83     case '1':
84     case '2':
85 rabbi 244 c = '\0';
86     assigned = sscanf(line, "%d %d %ld %c", &type, &num, &then, &c);
87     daysum = (assigned == 4 && c == 'd');
88    
89     if (now - then < 0 || (daysum && today - then < 0))
90 rabbi 1 break; /* keep memory consistent even if the time
91     suddenly goes backwards :) */
92 rabbi 244 if (now - then < SECONDSPERDAY && !daysum)
93 rabbi 1 msgd[type][(now - then) / (60 * 60)] += num;
94     else if (today - then < 80 * SECONDSPERDAY)
95     msg[type][(today - then) / SECONDSPERDAY] += num;
96     if (havestats == 0 || then < havestats)
97     havestats = then;
98     break;
99     case 'p':
100 rabbi 244 c = '\0';
101     assigned = sscanf(line, "p %d %d %ld %c", &num, &i, &then, &c);
102     daysum = (assigned == 4 && c == 'd');
103    
104     if (now - then < 0 || (daysum && today - then < 0))
105 rabbi 1 break;
106 rabbi 244 if (now - then < SECONDSPERDAY && !daysum) {
107 rabbi 1 poold[0][(now - then) / (60 * 60)] += num;
108     poold[1][(now - then) / (60 * 60)] += i;
109     } else if (today - then < 80 * SECONDSPERDAY) {
110     poold[0][(today - then) / (24 * 60 * 60)] += num;
111     poold[1][(today - then) / (24 * 60 * 60)] += i;
112     }
113     if (havestats == 0 || then < havestats)
114     havestats = then;
115     break;
116     }
117     }
118     unlock(s);
119     fclose(s);
120     }
121 rabbi 82 f = mix_openfile(IDLOG, "rb");
122 rabbi 1 if (f != NULL) {
123 rabbi 82 while (fread(&idbuf, 1, sizeof(idlog_t), f) == sizeof(idlog_t)) {
124     then = idbuf.time;
125 rabbi 1 if (then < updated || now - then < 0)
126     continue;
127     if (now - then < SECONDSPERDAY)
128     msgd[2][(now - then) / (60 * 60)]++;
129     else if (today - then < 80 * SECONDSPERDAY)
130     msg[2][(today - then) / SECONDSPERDAY]++;
131     if (havestats == 0 || then < havestats)
132     havestats = then;
133     }
134     fclose(f);
135     }
136     if (havestats == 0) {
137     if (b != NULL)
138     errlog(NOTICE, "No statistics available.\n");
139     return (-1);
140     }
141     s = mix_openfile(STATS, "w");
142     if (s == NULL) {
143     errlog(ERRORMSG, "Can't create %s!\n", STATS);
144     return (-1);
145     }
146     lock(s);
147     fprintf(s, "%ld\n", (long) time(NULL)); /* time of stats.log update */
148     for (i = 0; i < 24; i++) {
149     for (type = 0; type < 3; type++)
150     if (msgd[type][i] > 0)
151     fprintf(s, "%d %d %ld\n", type, msgd[type][i], now - i * 60 * 60);
152     if (poold[0][i] > 0)
153     fprintf(s, "p %d %d %ld\n", poold[0][i], poold[1][i], now - i * 60 * 60);
154     }
155     for (i = 0; i < 80; i++) {
156     for (type = 0; type < 3; type++)
157     if (msg[type][i] > 0)
158 rabbi 244 fprintf(s, "%d %d %ld d\n", type, msg[type][i],
159 rabbi 1 today - i * 24 * 60 * 60);
160     if (pool[0][i] > 0)
161 rabbi 244 fprintf(s, "p %d %d %ld d\n", pool[0][i], pool[1][i],
162 rabbi 1 today - i * 24 * 60 * 60);
163     }
164     unlock(s);
165     fclose(s);
166     if (b != NULL) {
167     struct tm *gt;
168    
169     buf_sets(b, "Subject: Statistics for the ");
170     buf_appends(b, SHORTNAME);
171     buf_appends(b, " remailer\n\n");
172    
173     buf_appends(b, "Number of messages in the past 24 hours:\n");
174     t = now;
175     gt = gmtime(&t);
176     for (i = 23; i >= 0; i--) {
177     buf_appendf(b, " %2dh: ", (24 + gt->tm_hour - i) % 24);
178     if (MIX) {
179     if (PGP || UNENCRYPTED)
180     buf_appends(b, " Mix:");
181     buf_appendf(b, "%4d", msgd[2][i]);
182     }
183     if (PGP)
184     buf_appendf(b, " PGP: %4d", msgd[1][i]);
185     if (UNENCRYPTED)
186     buf_appendf(b, " Unencrypted:%4d", msgd[0][i]);
187     if (poold[0][i] > 0)
188     buf_appendf(b, " [Pool size:%4d]", poold[1][i] / poold[0][i]);
189     #if 0
190     else
191     buf_appends(b, " [ no remailing ]");
192 weaselp 327 #endif /* 0 */
193 rabbi 1 buf_nl(b);
194     }
195     if ((today - havestats) / SECONDSPERDAY >= 1)
196     buf_appends(b, "\nNumber of messages per day:\n");
197     for ((i = (today - havestats) / SECONDSPERDAY) > 79 ? 79 : i;
198     i >= 1; i--) {
199     t = now - i * SECONDSPERDAY;
200     gt = localtime(&t);
201     strftime(line, LINELEN, "%d %b: ", gt);
202     buf_appends(b, line);
203    
204     if (MIX) {
205     if (PGP || UNENCRYPTED)
206     buf_appends(b, " Mix:");
207     buf_appendf(b, "%4d", msg[2][i]);
208     }
209     if (PGP)
210     buf_appendf(b, " PGP: %4d", msg[1][i]);
211     if (UNENCRYPTED)
212     buf_appendf(b, " Unencrypted:%4d", msg[0][i]);
213     if (pool[0][i] > 0)
214     buf_appendf(b, " [Pool size:%4d]", pool[1][i] / pool[0][i]);
215     #if 0
216     else
217     buf_appends(b, " [ no remailing ]");
218 weaselp 327 #endif /* 0 */
219 rabbi 1 buf_nl(b);
220     }
221     }
222     return (0);
223     }
224    
225     int conf(BUFFER *out)
226     {
227     FILE *f;
228     BUFFER *b, *line;
229     int flag = 0;
230 rabbi 306 REMAILER remailer[MAXREM];
231     int pgpkeyid[MAXREM];
232     int i, num;
233     char tmpline[LINELEN];
234    
235 rabbi 1 b = buf_new();
236     line = buf_new();
237    
238     buf_sets(out, "Subject: Capabilities of the ");
239     buf_appends(out, SHORTNAME);
240     buf_appends(out, " remailer\n\n");
241     buf_appends(out, remailer_type);
242     buf_appends(out, VERSION);
243     buf_nl(out);
244    
245     if (MIX + PGP + UNENCRYPTED == 1)
246     buf_appends(out, "Supported format:");
247     else
248     buf_appends(out, "Supported formats:\n");
249     if (MIX)
250     buf_appends(out, " Mixmaster\n");
251     if (PGP)
252     buf_appends(out, " Cypherpunk with PGP encryption\n");
253     if (UNENCRYPTED)
254     buf_appends(out, " Cypherpunk (unencrypted)\n");
255    
256     buf_appendf(out, "Pool size: %d\n", POOLSIZE);
257     if (SIZELIMIT)
258     buf_appendf(out, "Maximum message size: %d kB\n", SIZELIMIT);
259    
260 rabbi 143 /* display destinations to which delivery is explicitly permitted
261 rabbi 306 when in middleman mode (contents of DESTALLOW file.) */
262 rabbi 143
263 weaselp 90 if (MIDDLEMAN) {
264     f = mix_openfile(DESTALLOW, "r");
265     if (f != NULL) {
266     buf_read(b, f);
267     fclose(f);
268     while(buf_getline(b, line) != -1) {
269     if (line->length > 0 && line->data[0] != '#') {
270     if (flag == 0) {
271 rabbi 143 buf_appends(out, "In addition to other remailers, this remailer also sends mail to these\n addresses directly:\n");
272 weaselp 90 flag = 1;
273     }
274     buf_appendf(out, " %b\n", line);
275     }
276     }
277     }
278     }
279    
280 weaselp 107 flag = 0;
281 rabbi 1 f = mix_openfile(HDRFILTER, "r");
282     if (f != NULL) {
283     buf_read(b, f);
284     fclose(f);
285     while(buf_getline(b, line) != -1)
286     if (line->length > 0 && line->data[0] != '#') {
287     if (flag == 0) {
288     buf_appends(out, "The following header lines will be filtered:\n");
289     flag = 1;
290     }
291     buf_appends(out, " ");
292     if (line->length > 3 && streq(line->data + line->length - 2, "/q")) {
293     buf_append(out, line->data, line->length - 1);
294     buf_appends(out, " => delete message");
295     }
296     else
297     buf_cat(out, line);
298     buf_nl(out);
299     }
300     buf_free(b);
301     }
302     flag = 0;
303     b = readdestblk( );
304     if ( b != NULL ) {
305     while(buf_getline(b, line) != -1)
306     if (line->length > 0 && !bufleft(line, "#") && !buffind(line, "@")) {
307     /* mail addresses are not listed */
308     if (flag == 0) {
309     if (NEWS[0])
310     buf_appends(out,
311     "The following newsgroups/domains are blocked:\n");
312     else
313     buf_appends(out, "The following domains are blocked:\n");
314     flag = 1;
315     }
316     buf_appendf(out, " %b\n", line);
317     }
318     if (flag == 0 && NEWS[0])
319     buf_appends(out, "Note that other newsgroups may be unavailable at the remailer's news server.\n");
320     }
321    
322     buf_nl(out);
323     conf_premail(out);
324 rabbi 306
325     if (LISTSUPPORTED) {
326     /* SUPPORTED CPUNK (TYPE I) REMAILERS
327     * 0xDC7532F9 "Heex Remailer <remailer@xmailer.ods.org>"
328     * 0x759ED311 "znar <ka5tkn@cox-internet.com>"
329     *
330     * SUPPORTED MIXMASTER (TYPE II) REMAILERS
331     * aarg remailer@aarg.net 475f3f9fe8da22896c10082695a92c2d 2.9b33 C
332     * anon mixmaster@anon.978.org 7384ba1eec585bfd7d2b0e9b307f0b1d 2.9b36 MCNm
333     */
334    
335     buf_nl(out);
336     if (PGP) {
337     buf_appends(out, "SUPPORTED CPUNK (TYPE I) REMAILERS\n");
338     num = t1_rlist(remailer);
339     pgp_rkeylist(remailer, pgpkeyid, num);
340     for (i=1; i<=num; i++) {
341     if (remailer[i].flags.pgp) {
342     snprintf(tmpline, LINELEN, "0x%08X \"%s <%s>\"\n", pgpkeyid[i], remailer[i].name, remailer[i].addr);
343     tmpline[LINELEN-1] = '\0';
344     buf_appends(out, tmpline);
345     }
346     }
347     buf_nl(out);
348     }
349     if (MIX) {
350     buf_appends(out, "SUPPORTED MIXMASTER (TYPE II) REMAILERS\n");
351     prepare_type2list(out);
352     buf_nl(out);
353     }
354     }
355    
356    
357 rabbi 1 if ( b ) buf_free(b);
358     buf_free(line);
359     return (0);
360     }
361    
362     void conf_premail(BUFFER *out)
363     {
364     buf_appends(out, "$remailer{\"");
365     buf_appends(out, SHORTNAME);
366     buf_appends(out, "\"} = \"<");
367     buf_appends(out, REMAILERADDR);
368     buf_appendc(out, '>');
369     if (PGP || UNENCRYPTED)
370     buf_appends(out, " cpunk");
371     if (MIX)
372     buf_appends(out, " mix");
373     if (MIDDLEMAN)
374     buf_appends(out, " middle");
375     if (PGP)
376     buf_appends(out, " pgp");
377     if (PGP && !UNENCRYPTED)
378     buf_appends(out, " pgponly");
379 rabbi 64 if (PGP && REPGP) {
380 rabbi 62 if (REMIX == 1)
381     buf_appends(out, " repgp");
382     else
383     buf_appends(out, " repgp2");
384     }
385 rabbi 1 if (REMIX == 1)
386     buf_appends(out, " remix");
387     else if (REMIX)
388     buf_appends(out, " remix2");
389     if (PGP || UNENCRYPTED)
390     buf_appends(out, " latent hash cut test");
391     if (PGP) {
392     #ifdef USE_IDEA
393     buf_appends(out, " ek");
394 weaselp 327 #endif /* USE_IDEA */
395 rabbi 1 buf_appends(out, " ekx");
396     }
397     #ifdef USE_IDEA
398     buf_appends(out, " esub");
399 weaselp 327 #endif /* USE_IDEA */
400 rabbi 1 #if 0 /* obsolete */
401     #ifdef USE_NSUB
402     buf_appends(out, " nsub");
403 weaselp 327 #else /* end of USE_NSUB */
404 rabbi 1 buf_appends(out, " ksub");
405 weaselp 327 #endif /* else if not USE_NSUB */
406     #endif /* 0 */
407 rabbi 1 if (INFLATEMAX)
408     buf_appendf(out, " inflt%d", INFLATEMAX);
409     if (MAXRANDHOPS)
410     buf_appendf(out, " rhop%d", MAXRANDHOPS);
411     if (POOLSIZE >= 5)
412     buf_appends(out, " reord");
413     if (NEWS[0])
414     buf_appends(out, " post");
415     if (SIZELIMIT)
416     buf_appendf(out, " klen%d", SIZELIMIT);
417     buf_appends(out, "\";\n");
418     }

  ViewVC Help
Powered by ViewVC 1.1.5