1#	makeanalyse.pl
2#
3# Generate an HTML page containing a list of networks and a list of traffic
4# sources. This page invokes the CGI script analyse.pl. The page is written to
5# STDOUT.
6#
7# Modification History
8######################
9# 23 Dec 98	Tony Farr	Original coding
10##############################################################################
11
12use strict;
13
14my(@sources, @dests);					# Globals
15my $LOGPATH= "D:\\logs\\whodo\\";		# Directory where csv/logs are stored.
16
17get_sources_and_dests();
18write_html();
19exit(0);
20
21
22
23sub get_sources_and_dests {
24# Initialises @sources & @dests with yesterday's traffic sources and destinations
25	my(%srchash, %dsthash, $src, $dst);
26	my $fname= get_input_file();
27	open(LOG,"<$fname") || die "$0: unable to open input file $fname; $!";
28
29	# First 2 lines are headers
30	<LOG> || die "$0: $fname is empty\n";
31	<LOG> || die "$0: $fname lacks second header line\n";
32	# The rest of the file has traffic for particular sources & destinations
33	while (<LOG>) {
34		($src, $dst)= split/,/;
35		$srchash{$src}= 1;
36		$dsthash{$dst}= 1;
37	}
38	close(LOG);
39	# Transfer them from the hashes to the arrays
40	@sources= sort( keys(%srchash) );
41	@dests= sort( keys(%dsthash) );
42}
43
44
45
46sub get_input_file {
47# Returns the file name of yesterday's whodo log
48	my $t = time() - 24*60*60;
49	my ($mday,$mon,$year) = ( localtime($t) )[3..5];
50	$LOGPATH . sprintf("%d%02d%02d.csv",$year+1900,$mon+1,$mday);
51}
52
53
54
55sub write_html {
56
57	print <<HEAD;
58<HTML><head><title>Analyse traffic sources or destinations</title></head>
59<BODY><H1>Analyse traffic sources or destinations</H1><HR>
60<FORM METHOD="POST" ACTION="../scripts/analyse.pl">
61<P>Show sources sending traffic to:
62<SELECT NAME="dest"><OPTION></OPTION>
63HEAD
64
65	foreach my $dst (@dests) {
66		print "<OPTION>$dst</OPTION>\n";
67	}
68
69	print <<MIDDLE;
70</SELECT>(Leave blank to include all destinations.)</P>
71<P>During last:
72<INPUT TYPE="radio" NAME="src_duration" VALUE="30 minutes" checked>30 minutes
73<INPUT TYPE="radio" NAME="src_duration" VALUE="day">day
74<INPUT TYPE="radio" NAME="src_duration" VALUE="week">week
75<INPUT TYPE="radio" NAME="src_duration" VALUE="month">month</P>
76<P>Summarise minor sources: <INPUT TYPE="checkbox" NAME="summarise" checked></P>
77<INPUT TYPE="Submit" NAME="submit" VALUE="Get sources">
78</FORM><H3>OR</H3><FORM METHOD="POST" ACTION="../scripts/analyse.pl">
79<P>Show destinations receiving traffic from:
80<SELECT NAME="src"><OPTION></OPTION>
81MIDDLE
82
83	foreach my $src (@sources) {
84		print "<OPTION>$src</OPTION>\n";
85	}
86
87	print <<TAIL;
88</SELECT>(Leave blank to include all sources.)</P>
89<P>During last:
90<INPUT TYPE="radio" NAME="dest_duration" VALUE="30 minutes" checked>30 minutes
91<INPUT TYPE="radio" NAME="dest_duration" VALUE="day">day
92<INPUT TYPE="radio" NAME="dest_duration" VALUE="week">week
93<INPUT TYPE="radio" NAME="dest_duration" VALUE="month">month</P>
94<P>Summarise minor destinations: <INPUT TYPE="checkbox" NAME="summarise" checked></P>
95<INPUT TYPE="Submit" NAME="submit" VALUE="Get destinations">
96</FORM><HR>
97</BODY></HTML>
98TAIL
99
100}