/[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 62 - (show annotations) (download)
Thu Jan 10 23:59:16 2002 UTC (11 years, 4 months ago) by rabbi
File MIME type: text/plain
File size: 9019 byte(s)
Patches to support the Encrypt-To directive (by Disastry).
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.2 2002/01/10 23:59:16 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
63 now = (time(NULL) / (60 * 60) + 1) * 60 * 60;
64 today = (now / SECONDSPERDAY) * SECONDSPERDAY;
65
66 for (i = 0; i < 24; i++)
67 msgd[0][i] = msgd[1][i] = msgd[2][i] = poold[0][i] = poold[1][i] = 0;
68 for (i = 0; i < 80; i++)
69 msg[0][i] = msg[1][i] = msg[2][i] = pool[0][i] = pool[1][i] = 0;
70
71 s = mix_openfile(STATS, "r");
72 if (s != NULL) {
73 lock(s);
74 fscanf(s, "%ld", &updated);
75 while (fgets(line, sizeof(line), s) != NULL) {
76 switch (line[0]) {
77 case '0':
78 case '1':
79 case '2':
80 sscanf(line, "%d %d %ld", &type, &num, &then);
81 if (now - then < 0)
82 break; /* keep memory consistent even if the time
83 suddenly goes backwards :) */
84 if (now - then < SECONDSPERDAY)
85 msgd[type][(now - then) / (60 * 60)] += num;
86 else if (today - then < 80 * SECONDSPERDAY)
87 msg[type][(today - then) / SECONDSPERDAY] += num;
88 if (havestats == 0 || then < havestats)
89 havestats = then;
90 break;
91 case 'p':
92 sscanf(line, "p %d %d %ld", &num, &i, &then);
93 if (now - then < 0)
94 break;
95 if (now - then < SECONDSPERDAY) {
96 poold[0][(now - then) / (60 * 60)] += num;
97 poold[1][(now - then) / (60 * 60)] += i;
98 } else if (today - then < 80 * SECONDSPERDAY) {
99 poold[0][(today - then) / (24 * 60 * 60)] += num;
100 poold[1][(today - then) / (24 * 60 * 60)] += i;
101 }
102 if (havestats == 0 || then < havestats)
103 havestats = then;
104 break;
105 }
106 }
107 unlock(s);
108 fclose(s);
109 }
110 f = mix_openfile(IDLOG, "r");
111 if (f != NULL) {
112 while (fscanf(f, "%*s %ld", &then) != EOF) {
113 if (then < updated || now - then < 0)
114 continue;
115 if (now - then < SECONDSPERDAY)
116 msgd[2][(now - then) / (60 * 60)]++;
117 else if (today - then < 80 * SECONDSPERDAY)
118 msg[2][(today - then) / SECONDSPERDAY]++;
119 if (havestats == 0 || then < havestats)
120 havestats = then;
121 }
122 fclose(f);
123 }
124 if (havestats == 0) {
125 if (b != NULL)
126 errlog(NOTICE, "No statistics available.\n");
127 return (-1);
128 }
129 s = mix_openfile(STATS, "w");
130 if (s == NULL) {
131 errlog(ERRORMSG, "Can't create %s!\n", STATS);
132 return (-1);
133 }
134 lock(s);
135 fprintf(s, "%ld\n", (long) time(NULL)); /* time of stats.log update */
136 for (i = 0; i < 24; i++) {
137 for (type = 0; type < 3; type++)
138 if (msgd[type][i] > 0)
139 fprintf(s, "%d %d %ld\n", type, msgd[type][i], now - i * 60 * 60);
140 if (poold[0][i] > 0)
141 fprintf(s, "p %d %d %ld\n", poold[0][i], poold[1][i], now - i * 60 * 60);
142 }
143 for (i = 0; i < 80; i++) {
144 for (type = 0; type < 3; type++)
145 if (msg[type][i] > 0)
146 fprintf(s, "%d %d %ld\n", type, msg[type][i],
147 today - i * 24 * 60 * 60);
148 if (pool[0][i] > 0)
149 fprintf(s, "p %d %d %ld\n", pool[0][i], pool[1][i],
150 today - i * 24 * 60 * 60);
151 }
152 unlock(s);
153 fclose(s);
154 if (b != NULL) {
155 struct tm *gt;
156
157 buf_sets(b, "Subject: Statistics for the ");
158 buf_appends(b, SHORTNAME);
159 buf_appends(b, " remailer\n\n");
160
161 buf_appends(b, "Number of messages in the past 24 hours:\n");
162 t = now;
163 gt = gmtime(&t);
164 for (i = 23; i >= 0; i--) {
165 buf_appendf(b, " %2dh: ", (24 + gt->tm_hour - i) % 24);
166 if (MIX) {
167 if (PGP || UNENCRYPTED)
168 buf_appends(b, " Mix:");
169 buf_appendf(b, "%4d", msgd[2][i]);
170 }
171 if (PGP)
172 buf_appendf(b, " PGP: %4d", msgd[1][i]);
173 if (UNENCRYPTED)
174 buf_appendf(b, " Unencrypted:%4d", msgd[0][i]);
175 if (poold[0][i] > 0)
176 buf_appendf(b, " [Pool size:%4d]", poold[1][i] / poold[0][i]);
177 #if 0
178 else
179 buf_appends(b, " [ no remailing ]");
180 #endif
181 buf_nl(b);
182 }
183 if ((today - havestats) / SECONDSPERDAY >= 1)
184 buf_appends(b, "\nNumber of messages per day:\n");
185 for ((i = (today - havestats) / SECONDSPERDAY) > 79 ? 79 : i;
186 i >= 1; i--) {
187 t = now - i * SECONDSPERDAY;
188 gt = localtime(&t);
189 strftime(line, LINELEN, "%d %b: ", gt);
190 buf_appends(b, line);
191
192 if (MIX) {
193 if (PGP || UNENCRYPTED)
194 buf_appends(b, " Mix:");
195 buf_appendf(b, "%4d", msg[2][i]);
196 }
197 if (PGP)
198 buf_appendf(b, " PGP: %4d", msg[1][i]);
199 if (UNENCRYPTED)
200 buf_appendf(b, " Unencrypted:%4d", msg[0][i]);
201 if (pool[0][i] > 0)
202 buf_appendf(b, " [Pool size:%4d]", pool[1][i] / pool[0][i]);
203 #if 0
204 else
205 buf_appends(b, " [ no remailing ]");
206 #endif
207 buf_nl(b);
208 }
209 }
210 return (0);
211 }
212
213 int conf(BUFFER *out)
214 {
215 FILE *f;
216 BUFFER *b, *line;
217 int flag = 0;
218 b = buf_new();
219 line = buf_new();
220
221 buf_sets(out, "Subject: Capabilities of the ");
222 buf_appends(out, SHORTNAME);
223 buf_appends(out, " remailer\n\n");
224 buf_appends(out, remailer_type);
225 buf_appends(out, VERSION);
226 buf_nl(out);
227
228 if (MIX + PGP + UNENCRYPTED == 1)
229 buf_appends(out, "Supported format:");
230 else
231 buf_appends(out, "Supported formats:\n");
232 if (MIX)
233 buf_appends(out, " Mixmaster\n");
234 if (PGP)
235 buf_appends(out, " Cypherpunk with PGP encryption\n");
236 if (UNENCRYPTED)
237 buf_appends(out, " Cypherpunk (unencrypted)\n");
238
239 buf_appendf(out, "Pool size: %d\n", POOLSIZE);
240 if (SIZELIMIT)
241 buf_appendf(out, "Maximum message size: %d kB\n", SIZELIMIT);
242
243 f = mix_openfile(HDRFILTER, "r");
244 if (f != NULL) {
245 buf_read(b, f);
246 fclose(f);
247 while(buf_getline(b, line) != -1)
248 if (line->length > 0 && line->data[0] != '#') {
249 if (flag == 0) {
250 buf_appends(out, "The following header lines will be filtered:\n");
251 flag = 1;
252 }
253 buf_appends(out, " ");
254 if (line->length > 3 && streq(line->data + line->length - 2, "/q")) {
255 buf_append(out, line->data, line->length - 1);
256 buf_appends(out, " => delete message");
257 }
258 else
259 buf_cat(out, line);
260 buf_nl(out);
261 }
262 buf_free(b);
263 }
264 flag = 0;
265 b = readdestblk( );
266 if ( b != NULL ) {
267 while(buf_getline(b, line) != -1)
268 if (line->length > 0 && !bufleft(line, "#") && !buffind(line, "@")) {
269 /* mail addresses are not listed */
270 if (flag == 0) {
271 if (NEWS[0])
272 buf_appends(out,
273 "The following newsgroups/domains are blocked:\n");
274 else
275 buf_appends(out, "The following domains are blocked:\n");
276 flag = 1;
277 }
278 buf_appendf(out, " %b\n", line);
279 }
280 if (flag == 0 && NEWS[0])
281 buf_appends(out, "Note that other newsgroups may be unavailable at the remailer's news server.\n");
282 }
283
284 buf_nl(out);
285 conf_premail(out);
286 if ( b ) buf_free(b);
287 buf_free(line);
288 return (0);
289 }
290
291 void conf_premail(BUFFER *out)
292 {
293 buf_appends(out, "$remailer{\"");
294 buf_appends(out, SHORTNAME);
295 buf_appends(out, "\"} = \"<");
296 buf_appends(out, REMAILERADDR);
297 buf_appendc(out, '>');
298 if (PGP || UNENCRYPTED)
299 buf_appends(out, " cpunk");
300 if (MIX)
301 buf_appends(out, " mix");
302 if (MIDDLEMAN)
303 buf_appends(out, " middle");
304 if (PGP)
305 buf_appends(out, " pgp");
306 if (PGP && !UNENCRYPTED)
307 buf_appends(out, " pgponly");
308 if (REPGP) {
309 if (REMIX == 1)
310 buf_appends(out, " repgp");
311 else
312 buf_appends(out, " repgp2");
313 }
314 if (REMIX == 1)
315 buf_appends(out, " remix");
316 else if (REMIX)
317 buf_appends(out, " remix2");
318 if (PGP || UNENCRYPTED)
319 buf_appends(out, " latent hash cut test");
320 if (PGP) {
321 #ifdef USE_IDEA
322 buf_appends(out, " ek");
323 #endif
324 buf_appends(out, " ekx");
325 }
326 #ifdef USE_IDEA
327 buf_appends(out, " esub");
328 #endif
329 #if 0 /* obsolete */
330 #ifdef USE_NSUB
331 buf_appends(out, " nsub");
332 #else
333 buf_appends(out, " ksub");
334 #endif
335 #endif
336 if (INFLATEMAX)
337 buf_appendf(out, " inflt%d", INFLATEMAX);
338 if (MAXRANDHOPS)
339 buf_appendf(out, " rhop%d", MAXRANDHOPS);
340 if (POOLSIZE >= 5)
341 buf_appends(out, " reord");
342 if (NEWS[0])
343 buf_appends(out, " post");
344 if (SIZELIMIT)
345 buf_appendf(out, " klen%d", SIZELIMIT);
346 buf_appends(out, "\";\n");
347 }

  ViewVC Help
Powered by ViewVC 1.1.5