summaryrefslogtreecommitdiff
path: root/other/tor/bin/rrd-graph
blob: 2940f7ce7b606710cb7420012283592bacb6e85d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
#!/usr/bin/perl -w

use strict;
use RRDs;

my $HOSTNAME = `hostname`;

#my $IMG_URL = 'http://images.noreply.org/tor-running-routers/';
#my $IMG_URL = 'http://new.noreply.org/tor-running-routers/';
my $IMG_URL = '';
my $NOW = time;
my $GMTIME = gmtime($NOW);
my $START_AT = $NOW-4*30*24*3600;
my $END_AT = $NOW-4*3600;
my $OLD_AT = $NOW-7*24*3600;
my $RRD = '/home/weasel/www/www.noreply.org/Build/other/tor/rrd/running_Routers.rrd';
my $RRD_DIR = '/home/weasel/www/www.noreply.org/Build/other/tor/rrd/nodes';
my $INDEX_DIR = '/home/weasel/www/www.noreply.org/Build/other/tor/index';
my $RESULT_DIR = 'result.new';
my $LONG_TIME_MONTHS = 15;

# Get list of RRD files
opendir(D,$RRD_DIR) or die ("Cannot opendir $RRD_DIR: $!\n");
my @SOURCES = grep { /\.rrd$/ } readdir(D);
@SOURCES = grep {
			my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
			    $atime,$mtime,$ctime,$blksize,$blocks) = stat($RRD_DIR.'/'.$_);
			$mtime >= $START_AT;
		} @SOURCES;
closedir(D);

# Read hash <-> name mapping
my %hashes_router;
opendir(D,$INDEX_DIR) or die ("Cannot opendir $INDEX_DIR: $!\n");
my @NAME = grep { /\.name$/ } readdir(D);
closedir(D);
for my $hash (@NAME) {
	my $f = $INDEX_DIR.'/'.$hash;
	open (F, $f) or warn("Cannot open $f: $!\n"), next;
	my $name = <F>;
	my $platform = <F>;
	my $published = <F>;
	chomp $name;
	chomp $platform;
	chomp $published;
	close F;
	$hash =~ s/\.name$//;
	$hashes_router{$hash} = {name => $name, platform => $platform, published => $published };
};

@SOURCES = grep { !/^TRAF-/ } @SOURCES;
@SOURCES = sort {
		my $aa = $a;
		my $bb = $b;
		$aa =~ s/\.rrd//;
		$bb =~ s/\.rrd//;
		lc($hashes_router{$aa}->{'name'}) cmp lc($hashes_router{$bb}->{'name'}) ||
		$a cmp $b
	} @SOURCES;


my @nodesTraffic = ();

my %body;
my %index;
my $traf_item_counter = 0;

for my $source (@SOURCES) {
	my $hash = $source;
	   $hash =~ s/\.rrd$//;
	my $name = $hashes_router{$hash}->{'name'};
	my $platform = $hashes_router{$hash}->{'platform'};
	my $published = $hashes_router{$hash}->{'published'};
	my $def = $name;
	my $cdef = 'c_'.$def;
	my $label = $def;

	my $source_traffic = $RRD_DIR .'/TRAF-'. $source;
	$source = $RRD_DIR .'/'. $source;

	my (undef,undef,undef,undef,undef,undef,undef,undef, undef,$mtime,undef,undef,undef) = stat($source);
	my $section = $mtime < $OLD_AT ? 'old' : 'current';


	my @this;
	push @this, sprintf($RESULT_DIR.'/node-%s.png', $hash);
	push @this, sprintf('-s %s', $START_AT);
	push @this, sprintf('-e %s', $END_AT);
	push @this, sprintf('-t %s', "$name");
	push @this, sprintf('-aPNG');
	push @this, sprintf('-v %s', "running");
	push @this, sprintf('-w %d', 150);
	push @this, sprintf('-h %d', 50);

	push @this, sprintf('DEF:%s=%s:%s:%s', 'd_runningVerified' , $source, 'runningVerified', 'AVERAGE');
	push @this, sprintf('CDEF:%s=%s'     , 'c_runningVerified' , 'd_runningVerified');

	push @this, sprintf('DEF:%s=%s:%s:%s', 'd_runningUnverified' , $source, 'runningUnverified', 'AVERAGE');
	push @this, sprintf('CDEF:%s=%s'     , 'c_runningUnverified' , 'd_runningUnverified');

	push @this, sprintf('DEF:%s=%s:%s:%s', 'd_exit80Verified' , $source, 'exit80Verified', 'AVERAGE');
	push @this, sprintf('CDEF:c_exit80Verified=d_exit80Verified,0.5,*,c_runningVerified,*');

	push @this, sprintf('%s:%s#%s'    , 'AREA'  , 'c_runningVerified'   , '7777FF' );
	push @this, sprintf('%s:%s#%s'    , 'STACK' , 'c_runningUnverified' , 'FF7700' );
	push @this, sprintf('%s:%s#%s'    , 'AREA' , 'c_exit80Verified' , '00FF00' );

	push @this, sprintf('CDEF:%s=d_runningVerified,0,*,%s,+'     , 'zeroline'         , '0');
	push @this, sprintf('%s:%s' , 'LINE1' , 'zeroline' );

	my ($averages,$xsize,$ysize) = RRDs::graph @this;
	warn RRDs::error if RRDs::error;

	$body{$section} .= "<h2><a name=\"$hash\">$name</a></h2>".
		"<p>".
		"Last descriptor data:".
		"<blockquote>".
		"platform $platform<br>".
		"published $published".
		"</blockquote>".
		"<p><img width=\"$xsize\" height=\"$ysize\" alt=\"$name running\" src=\"$IMG_URL"."node-$hash.png\">\n";
	$index{$section} .= "<li><a href=\"$section.html#$hash\">$name</a></li>\n";

	if (-e $source_traffic) {
		$traf_item_counter++;
		push @nodesTraffic, sprintf('DEF:read%d=%s:read:AVERAGE', $traf_item_counter, $source_traffic);
		push @nodesTraffic, sprintf('DEF:write%d=%s:write:AVERAGE', $traf_item_counter, $source_traffic);
		push @nodesTraffic, sprintf('DEF:max_read%d=%s:read:MAX', $traf_item_counter, $source_traffic);
		push @nodesTraffic, sprintf('DEF:max_write%d=%s:write:MAX', $traf_item_counter, $source_traffic);
		#push @nodesTraffic, sprintf('DEF:min_read%d=%s:read:MIN', $traf_item_counter, $source_traffic);
		#push @nodesTraffic, sprintf('DEF:min_write%d=%s:write:MIN', $traf_item_counter, $source_traffic);
		push @nodesTraffic, sprintf('DEF:max_capacity%d=%s:capacity:MAX', $traf_item_counter, $source);

		push @nodesTraffic, sprintf('CDEF:cleanread%d=read%d,UN,0,read%d,IF', $traf_item_counter, $traf_item_counter, $traf_item_counter);
		push @nodesTraffic, sprintf('CDEF:cleanwrite%d=write%d,UN,0,write%d,IF', $traf_item_counter, $traf_item_counter, $traf_item_counter);
		push @nodesTraffic, sprintf('CDEF:max_cleanread%d=max_read%d,UN,0,max_read%d,IF', $traf_item_counter, $traf_item_counter, $traf_item_counter);
		push @nodesTraffic, sprintf('CDEF:max_cleanwrite%d=max_write%d,UN,0,max_write%d,IF', $traf_item_counter, $traf_item_counter, $traf_item_counter);
		#push @nodesTraffic, sprintf('CDEF:min_cleanread%d=min_read%d,UN,0,min_read%d,IF', $traf_item_counter, $traf_item_counter, $traf_item_counter);
		#push @nodesTraffic, sprintf('CDEF:min_cleanwrite%d=min_write%d,UN,0,min_write%d,IF', $traf_item_counter, $traf_item_counter, $traf_item_counter);
		push @nodesTraffic, sprintf('CDEF:max_cleancapacity%d=max_capacity%d,UN,0,max_capacity%d,IF', $traf_item_counter, $traf_item_counter, $traf_item_counter);

		if ($traf_item_counter == 1) {
			push @nodesTraffic, sprintf('CDEF:aggread%d=cleanread%d', $traf_item_counter, $traf_item_counter);
			push @nodesTraffic, sprintf('CDEF:aggwrite%d=cleanwrite%d', $traf_item_counter, $traf_item_counter);
			push @nodesTraffic, sprintf('CDEF:max_aggread%d=max_cleanread%d', $traf_item_counter, $traf_item_counter);
			push @nodesTraffic, sprintf('CDEF:max_aggwrite%d=max_cleanwrite%d', $traf_item_counter, $traf_item_counter);
			#push @nodesTraffic, sprintf('CDEF:min_aggread%d=min_cleanread%d', $traf_item_counter, $traf_item_counter);
			#push @nodesTraffic, sprintf('CDEF:min_aggwrite%d=min_cleanwrite%d', $traf_item_counter, $traf_item_counter);
			push @nodesTraffic, sprintf('CDEF:max_aggcapacity%d=max_cleancapacity%d', $traf_item_counter, $traf_item_counter);
		} else {
			push @nodesTraffic, sprintf('CDEF:aggread%d=cleanread%d,aggread%d,+', $traf_item_counter, $traf_item_counter, $traf_item_counter-1);
			push @nodesTraffic, sprintf('CDEF:aggwrite%d=cleanwrite%d,aggwrite%d,+', $traf_item_counter, $traf_item_counter, $traf_item_counter-1);
			push @nodesTraffic, sprintf('CDEF:max_aggread%d=max_cleanread%d,max_aggread%d,+', $traf_item_counter, $traf_item_counter, $traf_item_counter-1);
			push @nodesTraffic, sprintf('CDEF:max_aggwrite%d=max_cleanwrite%d,max_aggwrite%d,+', $traf_item_counter, $traf_item_counter, $traf_item_counter-1);
			#push @nodesTraffic, sprintf('CDEF:min_aggread%d=min_cleanread%d,min_aggread%d,+', $traf_item_counter, $traf_item_counter, $traf_item_counter-1);
			#push @nodesTraffic, sprintf('CDEF:min_aggwrite%d=min_cleanwrite%d,min_aggwrite%d,+', $traf_item_counter, $traf_item_counter, $traf_item_counter-1);
			push @nodesTraffic, sprintf('CDEF:max_aggcapacity%d=max_cleancapacity%d,max_aggcapacity%d,+', $traf_item_counter, $traf_item_counter, $traf_item_counter-1);
		};

		for my $thumb (0, 1) {
			@this = ();
			push @this, sprintf($RESULT_DIR.'/node-'.($thumb ? 'small-' : '').'traf-%s.png', $hash);
			#push @this, sprintf('-s %s', '-604800');
			push @this, sprintf('-s %s', $START_AT);
			push @this, sprintf('-e %s', $END_AT);
			push @this, sprintf('-t %s', "$name traffic");
			push @this, sprintf('-v %s', "bytes/sec");
			if ($thumb) {
				push @this, sprintf('-w %d', 150);
				push @this, sprintf('-h %d', 50);
			};
			push @this, sprintf('-aPNG');
			push @this, sprintf('DEF:read=%s:read:AVERAGE', $source_traffic);
			push @this, sprintf('DEF:maxread=%s:read:MAX', $source_traffic);
			#push @this, sprintf('DEF:minread=%s:read:MIN', $source_traffic);
			push @this, sprintf('DEF:write=%s:write:AVERAGE', $source_traffic);
			push @this, sprintf('DEF:maxwrite=%s:write:MAX', $source_traffic);
			#push @this, sprintf('DEF:minwrite=%s:write:MIN', $source_traffic);
			push @this, sprintf('DEF:maxcapacity=%s:capacity:MAX', $source);
			push @this, sprintf('AREA:read#00FF00:Read');
			push @this, sprintf('LINE2:write#0000FF:Write');
			unless ($thumb) {
				push @this, sprintf('LINE1:maxread#009A2C:Read [max 15min]');
				push @this, sprintf('LINE1:maxwrite#5555FF:Write [max 15min]');
				#push @this, sprintf('LINE1:minread#FF76D4:Read [min]');
				#push @this, sprintf('LINE1:minwrite#222255:Write [min]');
				push @this, sprintf('LINE1:maxcapacity#FF5555:Capacity');
			}
			#push @this, sprintf('COMMENT:\\n');
			#push @this, sprintf('COMMENT:%s\\r', $GMTIME);
			#push @this, sprintf('COMMENT:\\n');
			#push @this, sprintf('COMMENT:             Min           Max           Average       Last\\n');
			#push @this, sprintf('COMMENT:Read:     ');
			#push @this, sprintf('GPRINT:minread:MIN:%6.2lf %sb/s ');
			#push @this, sprintf('GPRINT:maxread:MAX:%6.2lf %sb/s ');
			#push @this, sprintf('GPRINT:read:AVERAGE:%6.2lf %sb/s ');
			#push @this, sprintf('GPRINT:read:LAST:%6.2lf %sb/s\\n');
			#push @this, sprintf('COMMENT:Write:    ');
			#push @this, sprintf('GPRINT:minwrite:MIN:%6.2lf %sb/s ');
			#push @this, sprintf('GPRINT:maxwrite:MAX:%6.2lf %sb/s ');
			#push @this, sprintf('GPRINT:write:AVERAGE:%6.2lf %sb/s ');
			#push @this, sprintf('GPRINT:write:LAST:%6.2lf %sb/s\\n');

			#push @this, sprintf('CDEF:%s=read,0,*,%s,+'     , 'zeroline'         , '0');
			#push @this, sprintf('%s:%s' , 'LINE1' , 'zeroline' );

			($averages,$xsize,$ysize) = RRDs::graph @this;
			warn RRDs::error if RRDs::error;

		};
		$body{$section} .= " <a href=\"$IMG_URL"."node-traf-$hash.png\">";
		$body{$section} .= "<img width=\"$xsize\" height=\"$ysize\" alt=\"$name traffic\" src=\"$IMG_URL"."node-small-traf-$hash.png\">";
		$body{$section} .= "</a>";
	};
	#$body{$section} .= "<br><a href=\"#_top\">top</a>";
	$body{$section} .= "<br><a href=\"./\">back</a>";
	$body{$section} .= '</p>';
};



sub makeTotalTrafficPic($$$) {
	my ($file, $age, $include15min) = @_;

	my @totalTraffic = ();
	push @totalTraffic, $file;
	push @totalTraffic, sprintf('-s %s', $NOW-$age);

	#push @totalTraffic, sprintf('-s %s', $START_AT);
	push @totalTraffic, sprintf('-e %s', $END_AT);
	#push @totalTraffic, sprintf('-e %s', $NOW-   2*24*3600);
	push @totalTraffic, sprintf('-t %s', "Total Traffic");
	push @totalTraffic, sprintf('-aPNG');
	push @totalTraffic, sprintf('-v %s', "Bandwidth Used");
	#push @totalTraffic, sprintf('-w %d', 600);
	#push @totalTraffic, sprintf('-h %d', 400);
	push @totalTraffic, sprintf('-w %d', 497);
	push @totalTraffic, sprintf('-h %d', 201);
	#push @totalTraffic, sprintf('-h %d', 301);
	#push @totalTraffic, sprintf('-h %d', 271);

	push @totalTraffic, @nodesTraffic;


	push @totalTraffic, sprintf('AREA:aggread%d#00FF00:Read bytes/s', $traf_item_counter);
	push @totalTraffic, sprintf('LINE2:aggwrite%d#0000FF:Write bytes/s', $traf_item_counter);
	push @totalTraffic, sprintf('LINE1:max_aggread%d#009A2C:Read [max 15min]', $traf_item_counter)    if $include15min;
	push @totalTraffic, sprintf('LINE1:max_aggwrite%d#5555FF:Write [max 15min]', $traf_item_counter)  if $include15min;
	#push @totalTraffic, sprintf('LINE1:min_aggread%d#FF76D4:Read [min]', $traf_item_counter);
	#push @totalTraffic, sprintf('LINE1:min_aggwrite%d#222255:Write [min]', $traf_item_counter);
	push @totalTraffic, sprintf('LINE1:max_aggcapacity%d#FF5555:Capacity', $traf_item_counter);

	push @totalTraffic, sprintf('CDEF:zeroline=aggread%d,0,*', $traf_item_counter);
	push @totalTraffic, sprintf('%s:%s' , 'LINE1' , 'zeroline' );

	my ($averages,$xsize,$ysize) = RRDs::graph @totalTraffic;
	warn RRDs::error if RRDs::error;

	return ($averages,$xsize,$ysize);
};

sub makeNumbersGraph($$) {
	my ($file, $age) = @_;

	my @params;
	push @params, $file;
	push @params, sprintf('-s %s', $NOW-$age);

	push @params, sprintf('-e %s', $END_AT);
	#push @params, sprintf('-e %s', $NOW-   2*24*3600);
	push @params, sprintf('-t %s', "Running routers");
	push @params, sprintf('-aPNG');
	push @params, sprintf('-v %s', "# Routers");
	#push @params, sprintf('-w %d', 600);
	#push @params, sprintf('-h %d', 400);
	push @params, sprintf('-w %d', 497);
	push @params, sprintf('-h %d', 301);
	#push @params, sprintf('-h %d', 271);

	push @params, sprintf('DEF:%s=%s:%s:%s', 'd_runningVerified' , $RRD, 'runningVerified', 'AVERAGE');
	push @params, sprintf('CDEF:%s=%s'     , 'c_runningVerified' , 'd_runningVerified');
	push @params, sprintf('DEF:%s=%s:%s:%s', 'd_runningUnverified' , $RRD, 'runningUnverified', 'AVERAGE');
	push @params, sprintf('CDEF:%s=%s'     , 'c_runningUnverified' , 'd_runningUnverified');
	push @params, sprintf('DEF:%s=%s:%s:%s', 'd_exit80Verified' , $RRD, 'exit80Verified', 'AVERAGE');
	push @params, sprintf('CDEF:%s=%s'     , 'c_exit80Verified' , 'd_exit80Verified');

	push @params, sprintf('DEF:%s=%s:%s:%s', 'd_f_runningVerified' , $RRD, 'fastRunningVerified', 'AVERAGE');
	push @params, sprintf('CDEF:%s=%s'     , 'c_f_runningVerified' , 'd_f_runningVerified');
	push @params, sprintf('DEF:%s=%s:%s:%s', 'd_f_runningUnverified' , $RRD, 'fastRunningUnverifi', 'AVERAGE');
	push @params, sprintf('CDEF:%s=%s'     , 'c_f_runningUnverified' , 'd_f_runningUnverified');
	push @params, sprintf('DEF:%s=%s:%s:%s', 'd_f_exit80Verified' , $RRD, 'fastExit80Verified', 'AVERAGE');
	push @params, sprintf('CDEF:%s=%s'     , 'c_f_exit80Verified' , 'd_f_exit80Verified');

	#push @params, sprintf('%s:%s#%s:%s'    , 'AREA'  , 'c_runningVerified'   , '7777FF', 'verified Nodes' );
	#push @params, sprintf('%s:%s#%s:%s'    , 'STACK' , 'c_runningUnverified' , 'FF7700', 'unverified Nodes' );
	#push @params, sprintf('%s:%s#%s:%s'    , 'LINE3'  , 'c_exit80Verified'   , '00FF00', 'verified Nodes exiting to port 80' );
	push @params, sprintf('%s:%s#%s:%s'    , 'AREA'   , 'c_runningVerified'     , 'AAAAFF', 'verified Nodes' );
	push @params, sprintf('%s:%s#%s:%s'    , 'STACK'  , 'c_runningUnverified'   , 'FF7700', '+unverified Nodes' );
	push @params, sprintf('%s:%s#%s:%s'    , 'LINE2'  , 'c_exit80Verified'      , 'BBFFBB', 'verified Nodes exiting to port 80' );

	push @params, sprintf('%s:%s#%s:%s'    , 'LINE3'  , 'c_f_runningVerified'   , '0000FF', 'fast verified Nodes' );
	push @params, sprintf('%s:%s#%s:%s'    , 'STACK'  , 'c_f_runningUnverified' , 'FF0000', '+fast unverified Nodes' );
	push @params, sprintf('%s:%s#%s:%s'    , 'LINE3'  , 'c_f_exit80Verified'    , '00FF00', 'fast verified Nodes exiting to port 80' );

	push @params, sprintf('CDEF:%s=d_runningVerified,0,*,%s,+'     , 'zeroline'         , '0');
	push @params, sprintf('%s:%s' , 'LINE1' , 'zeroline' );



	my ($averages,$xsize,$ysize) = RRDs::graph @params;
	warn RRDs::error if RRDs::error;

	return ($averages,$xsize,$ysize);
};

my $html = "<html><head><title>Number of Running Tor routers</title></head><body>";
$html .= "<h1><a name=\"_top\">Number of Running Tor routers</a></h1>";
$html .= "<a href=\"../\">..</a><br>\n";

my ($averages,$xsize,$ysize);

makeNumbersGraph($RESULT_DIR.'/totalWeekly.png', 7*24*3600);
makeNumbersGraph($RESULT_DIR.'/totalBiWeekly.png', 14*24*3600);
makeNumbersGraph($RESULT_DIR.'/totalMonthly.png', 35*24*3600);
makeNumbersGraph($RESULT_DIR.'/totalLong.png', $LONG_TIME_MONTHS*30*24*3600);
($averages,$xsize,$ysize) = makeNumbersGraph($RESULT_DIR.'/total.png', $NOW - $START_AT);

$html .= "<p><img width=\"$xsize\" height=\"$ysize\" src=\"$IMG_URL"."total.png\"></p>";
$html .= "<p>\"Fast\" means a capacity of over 20,000 bytes/second</p>\n";
$html .= "<p>Number of routers over the <a href=\"$IMG_URL"."totalLong.html\">last $LONG_TIME_MONTHS months</a> | ";
$html .= "   <a href=\"$IMG_URL"."totalMonthly.html\">last month</a> |";
$html .= "   <a href=\"$IMG_URL"."totalBiWeekly.html\">last 2 weeks</a> |";
$html .= "   <a href=\"$IMG_URL"."totalWeekly.html\">last week</a></p>";


makeTotalTrafficPic($RESULT_DIR.'/totalTrafficWeekly.png', 7*24*3600, 1);
makeTotalTrafficPic($RESULT_DIR.'/totalTrafficBiWeekly.png', 14*24*3600, 1);
makeTotalTrafficPic($RESULT_DIR.'/totalTrafficMonthly.png', 35*24*3600, 0);
makeTotalTrafficPic($RESULT_DIR.'/totalTrafficLong.png', $LONG_TIME_MONTHS*30*24*3600, 0);
($averages,$xsize,$ysize) = makeTotalTrafficPic($RESULT_DIR.'/totalTraffic.png', $NOW - $START_AT, 0);

$html .= "<p><img width=\"$xsize\" height=\"$ysize\" src=\"$IMG_URL"."totalTraffic.png\"></p>";
$html .= "<p>Bandwidth usage for <a href=\"$IMG_URL"."totalTrafficLong.html\">last $LONG_TIME_MONTHS months</a> | ";
$html .= "   <a href=\"$IMG_URL"."totalTrafficMonthly.html\">last month</a> |";
$html .= "   <a href=\"$IMG_URL"."totalTrafficBiWeekly.html\">last 2 weeks</a> |";
$html .= "   <a href=\"$IMG_URL"."totalTrafficWeekly.html\">last week</a></p>";



$html .= "<p>The directory is downloaded from ";
  $html .= "<a href=\"http://tor.noreply.org/tor/\">http://tor.noreply.org/tor/</a>";

$html .= " at regular intervals.<br>\n";
$html .= "Other directory sources are ";
  $html .= "<a href=\"http://moria.mit.edu:9031/tor/\">http://moria.mit.edu:9031/tor/</a>";

$html .= " and\n";
  $html .= "<a href=\"http://belegost.mit.edu/tor/\">http://belegost.mit.edu/tor/</a>";

$html .= ".";
$html .= "<h1>Recent Nodes</h1>";
$html .= "<ul>".$index{'current'}."</ul>";
#$html .= $body{'current'};
$html .= "<h1>Older Nodes</h1>";
$html .= "<ul>".$index{'old'}."</ul>";
#$html .= $body{'current'};
$html .= "<br><br><br>\n";
$html .= 'Images created with Tobi Oetiker\'s <a href="http://people.ee.ethz.ch/~oetiker/webtools/rrdtool/">rrdtool</a>'."\n";
$html .= "<hr>\nBuilt at $GMTIME on $HOSTNAME<br>\n";
$html .= "<a href=\"mailto:web\@palfrader.org\">Peter Palfrader &lt;web\@palfrader.org&gt;</a>\n";
$html .= "</body></html>\n";

open (F, ">$RESULT_DIR/index.html") or die ("Cannot open index.html: $!\n");
print F $html;
close F;

open (F, ">$RESULT_DIR/current.html") or die ("Cannot open current.html: $!\n");
print F "<html><head><title>Current Tor Routers</title></head><body>",
	"<h1><a name=\"_top\">Current Tor routers</a></h1>",
	"<a href=\"./\">./</a><br>\n",
	$body{'current'},
	"<br><br><br>\n",
	'Images created with Tobi Oetiker\'s <a href="http://people.ee.ethz.ch/~oetiker/webtools/rrdtool/">rrdtool</a>'."\n",
	"<hr>\nBuilt at $GMTIME on $HOSTNAME<br>\n",
	"<a href=\"mailto:web\@palfrader.org\">Peter Palfrader &lt;web\@palfrader.org&gt;</a>\n",
	"</body></html>\n";
close F;

open (F, ">$RESULT_DIR/old.html") or die ("Cannot open old.html: $!\n");
print F "<html><head><title>Older Tor Routers</title></head><body>",
	"<h1><a name=\"_top\">Older Tor routers</a></h1>",
	"<a href=\"./\">./</a><br>\n",
	$body{'old'},
	"<br><br><br>\n",
	'Images created with Tobi Oetiker\'s <a href="http://people.ee.ethz.ch/~oetiker/webtools/rrdtool/">rrdtool</a>'."\n",
	"<hr>\nBuilt at $GMTIME on $HOSTNAME<br>\n",
	"<a href=\"mailto:web\@palfrader.org\">Peter Palfrader &lt;web\@palfrader.org&gt;</a>\n",
	"</body></html>\n";
close F;


my %imgs = (
	totalLong => 'Number of routers over the last '.$LONG_TIME_MONTHS.' months',
	totalMonthly => 'Number of routers over the last month',
	totalBiWeekly => 'Number of routers over the last 2 weeks',
	totalWeekly => 'Number of routers over the last week',
	totalTrafficLong => 'Traffic over the last '.$LONG_TIME_MONTHS.' months',
	totalTrafficMonthly => 'Traffic over the last month',
	totalTrafficBiWeekly => 'Traffic over the last 2 weeks',
	totalTrafficWeekly => 'Traffic over the last week' );

for my $key (keys %imgs) {
	open (F, ">$RESULT_DIR/$key.html") or die ("Cannot open $key.html: $!\n");
	print F "<html><head><title>$imgs{$key}</title></head><body>",
		"<h1>$imgs{$key}</h1>",
		"<a href=\".\">back</a>",
		"<p>",
		"<img src=\"$key.png\">",
		"<br><br><br>\n",
		"<hr>\nBuilt at $GMTIME on $HOSTNAME<br>\n",
		"<a href=\"mailto:web\@palfrader.org\">Peter Palfrader &lt;web\@palfrader.org&gt;</a>\n",
		"</body></html>\n";
	close F;
};