1 |
<?php |
---|
2 |
ini_set("display_errors", "on"); |
---|
3 |
ini_set("display_startup_errors", "on"); |
---|
4 |
|
---|
5 |
|
---|
6 |
|
---|
7 |
|
---|
8 |
|
---|
9 |
|
---|
10 |
|
---|
11 |
|
---|
12 |
|
---|
13 |
|
---|
14 |
|
---|
15 |
|
---|
16 |
|
---|
17 |
|
---|
18 |
|
---|
19 |
|
---|
20 |
|
---|
21 |
|
---|
22 |
require_once('config.inc.php'); |
---|
23 |
require_once('common.inc.php'); |
---|
24 |
require_once('db_handler.inc.php'); |
---|
25 |
|
---|
26 |
|
---|
27 |
$dbh = ''; |
---|
28 |
init_db(); |
---|
29 |
|
---|
30 |
|
---|
31 |
if (!array_key_exists('action', $_REQUEST) OR (array_key_exists('action', $_REQUEST) && $_REQUEST['action'] == 'probe_select' && empty($_REQUEST['probe']))) { |
---|
32 |
print(html_header($title = 'FlowMon '.$prog_vers.' - running on '.$_SERVER['HTTP_HOST'])); |
---|
33 |
print(page_header($title = 'FlowMon overview')); |
---|
34 |
|
---|
35 |
print('<div style="margin-left: 30px; margin-right: 30px;"><h1>Network Flow Monitor</h1></div>'); |
---|
36 |
$num_flows = get_num_flows(); |
---|
37 |
$num_systems = get_num_systems(); |
---|
38 |
print('<div style="margin: 30px; height: 175px; width: 40%; text-align: left; float: left;"> |
---|
39 |
<h2>Database Statistics</h2> |
---|
40 |
<p><table> |
---|
41 |
<tr><td>Number of reporting FlowProbes:</td><td>'.get_num_probes().'<td></tr> |
---|
42 |
<tr><td>Number of archived Flows:</td><td>'.$num_flows.'<td></tr> |
---|
43 |
<tr><td>Number of tracked Systems:</td><td>'.$num_systems.'<td></tr> |
---|
44 |
<tr><td>First Flow occurence:</td><td>'.strftime($date_fmt_str, get_oldest_flow_ts()).'<td></tr> |
---|
45 |
<tr><td>Most recent Flow occurence:</td><td>'.strftime($date_fmt_str, get_newest_flow_ts()).'<td></tr> |
---|
46 |
<tr><td>Database Size:</td><td>'.round((get_db_size() / 1024 / 1024), 2).' MB<td></tr> |
---|
47 |
</table></p> |
---|
48 |
</div>'); |
---|
49 |
$bytes = get_bytes(); |
---|
50 |
$pkts = get_pkts(); |
---|
51 |
print('<div style="margin: 30px; height: 175px; width: 40%; text-align: left; float: right;"> |
---|
52 |
<h2>Network Statistics</h2> |
---|
53 |
<p><table> |
---|
54 |
<tr><td>Total Bytes tracked</td><td>'.round((get_bytes() / 1024 / 1024), 2).' MB<td></tr> |
---|
55 |
<tr><td>Total Pakets tracked</td><td>'.get_pkts().'<td></tr> |
---|
56 |
<tr><td>Average Paketsize</td><td>'.@round(($bytes / $pkts), 0).' Bytes<td></tr> |
---|
57 |
<tr><td>Average Traffic per system</td><td>'.@round(($bytes / $num_systems / 1024 / 1024), 2).' MB<td></tr> |
---|
58 |
<tr><td>Average Traffic per flow</td><td>'.@round(($bytes / $num_flows / 1024 / 1024), 2).' MB<td></tr> |
---|
59 |
</table></p> |
---|
60 |
</div>'); |
---|
61 |
|
---|
62 |
print('<div style="margin-left: 30px; margin-right: 30px; clear: right; text-align: center;"><h2>Detailed traffic graphs</h2></div>'); |
---|
63 |
'<div style="margin-left: auto; margin-right: auto; width: 400px; height: 100px;">'); |
---|
64 |
'<form action="'.$_SERVER['SCRIPT_NAME'].'" method="GET"><select name="probe" size=1>'); |
---|
65 |
'<option value="" selected="selected">Please select a FlowProbe to chart</option>'); |
---|
66 |
get_probes() as $probe => $hostname) { |
---|
67 |
'<option value="'.$probe.'">'.$hostname.' ('.$probe.')</option>'); |
---|
68 |
|
---|
69 |
'</select><input type="hidden" name="action" value="chart"><input type="hidden" name="nslookup" value="on"><input type="hidden" name="rolling" value="on"><input type="submit" value="Graph!"></form>'); |
---|
70 |
'</div>'); |
---|
71 |
html_footer()); |
---|
72 |
|
---|
73 |
|
---|
74 |
|
---|
75 |
} else if (array_key_exists('action', $_REQUEST) && $_REQUEST['action'] == 'probe_select') { |
---|
76 |
|
---|
77 |
print(html_header($title = 'FlowMon '.$prog_vers.' - running on '.$_SERVER['HTTP_HOST'], $calendar = True)); |
---|
78 |
print(page_header($title = 'FlowMon Chart Parameters')); |
---|
79 |
print('<div style="margin: 30px auto 30px auto; height: 350px; width: 40%; text-align: left;"> |
---|
80 |
<h1> Statistics</h1> |
---|
81 |
<form action="'.$_SERVER['SCRIPT_NAME'].'" method="GET"> |
---|
82 |
<table> |
---|
83 |
<tr><td>Probe</td><td><input type="hidden" name="probe" value="'.$_REQUEST['probe'].'" />'.gethostbyaddr(htmlspecialchars($_REQUEST['probe'])).' ('.htmlspecialchars($_REQUEST['probe']).')</td></tr> |
---|
84 |
<tr><td>Start Date</td><td><input type="text" name="startdate" value="'.strftime('%Y-%m-%d').'" /></td></tr> |
---|
85 |
<tr><td>Start Time</td><td><input type="text" name="starttime" value="'.strftime('%H:%M', (time() - 3600)).'" /></td></tr> |
---|
86 |
<tr><td>End Date</td><td><input type="text" name="enddate" value="'.strftime('%Y-%m-%d').'" /></td></tr> |
---|
87 |
<tr><td>End Time</td><td><input type="text" name="endtime" value="'.strftime('%H:%M').'" /></td></tr> |
---|
88 |
<tr><td>Chart Style</td><td><select name="style" size=1>'); |
---|
89 |
foreach ($chart_styles as $style=>$file) { |
---|
90 |
print('<option>'.$style.'</option>'); |
---|
91 |
} |
---|
92 |
print('</select></td></tr> |
---|
93 |
<tr><td colspan="2" style="text-align: right;"><input type="hidden" name="action" value="chart" /><input type="submit" value="Chart" /></form></td></tr> |
---|
94 |
<tr><td colspan="2"><hr></td></tr> |
---|
95 |
<tr><td><form action="'.$_SERVER['SCRIPT_NAME'].'" method="GET">Chart Style</td><td><select name="style" size=1>'); |
---|
96 |
foreach ($chart_styles as $style=>$file) { |
---|
97 |
print('<option>'.$style.'</option>'); |
---|
98 |
} |
---|
99 |
print('</select></td></tr> |
---|
100 |
<tr><td><input type="hidden" name="probe" value="'.$_REQUEST['probe'].'" /><select name="timeframe"><option value="1800">Past 30 minutes</option><option value="3600">Past hour</option><option value="7200">Past 2 hours</option></select></td><td style="text-align: right;"><input type="hidden" name="action" value="rollingchart" /><input type="submit" value="Rolling Chart" /></td></tr> |
---|
101 |
</table> |
---|
102 |
</div>'); |
---|
103 |
|
---|
104 |
print(html_footer()); |
---|
105 |
|
---|
106 |
|
---|
107 |
|
---|
108 |
|
---|
109 |
} else if (array_key_exists('action', $_REQUEST) && $_REQUEST['action'] == 'chart') { |
---|
110 |
print(html_header($title = 'FlowMon '.$prog_vers.' - running on '.$_SERVER['HTTP_HOST'], $calendar = True)); |
---|
111 |
print(page_header($title = 'FlowMon Traffic Chart')); |
---|
112 |
|
---|
113 |
|
---|
114 |
if (!@array_key_exists('style', $_REQUEST)) { |
---|
115 |
$_REQUEST['style'] = 'Top Sources'; |
---|
116 |
} |
---|
117 |
if (!@array_key_exists('timeframe', $_REQUEST)) { |
---|
118 |
$_REQUEST['timeframe'] = '3600'; |
---|
119 |
} |
---|
120 |
if (@$_REQUEST['rolling'] == 'on') { |
---|
121 |
$_REQUEST['startdate'] = strftime('%Y-%m-%d', (time() - $_REQUEST['timeframe'])); |
---|
122 |
$_REQUEST['starttime'] = strftime('%H:%M', (time() - $_REQUEST['timeframe'])); |
---|
123 |
$_REQUEST['enddate'] = strftime('%Y-%m-%d'); |
---|
124 |
$_REQUEST['endtime'] = strftime('%H:%M'); |
---|
125 |
|
---|
126 |
$starttime = strtotime($_REQUEST['startdate'].' '.$_REQUEST['starttime']); |
---|
127 |
$endtime = strtotime($_REQUEST['enddate'].' '.$_REQUEST['endtime']); |
---|
128 |
} else { |
---|
129 |
|
---|
130 |
$starttime = strtotime($_REQUEST['startdate'].' '.$_REQUEST['starttime']); |
---|
131 |
$endtime = strtotime($_REQUEST['enddate'].' '.$_REQUEST['endtime']); |
---|
132 |
} |
---|
133 |
print(chartstyle_header($_REQUEST['startdate'], $_REQUEST['starttime'], $_REQUEST['enddate'], $_REQUEST['endtime'])); |
---|
134 |
print('<div style="margin: 30px auto 30px auto; width: 850px; text-align: left;"> |
---|
135 |
<h1> Statistics</h1>'); |
---|
136 |
|
---|
137 |
|
---|
138 |
if (array_key_exists($_REQUEST['style'], $chart_styles)) { |
---|
139 |
require_once('charts/'.$chart_styles[$_REQUEST['style']]); |
---|
140 |
} |
---|
141 |
|
---|
142 |
if (!isvalid_probe($_REQUEST['probe'])) { |
---|
143 |
die("Invalid Probe"); |
---|
144 |
} |
---|
145 |
|
---|
146 |
|
---|
147 |
if (@$_REQUEST['nslookup'] == 'on') { |
---|
148 |
$nslookup = True; |
---|
149 |
} else { |
---|
150 |
$nslookup = False; |
---|
151 |
} |
---|
152 |
|
---|
153 |
$file = chart_prepare($_REQUEST['probe'], $starttime, $endtime, $nslookup=$nslookup); |
---|
154 |
|
---|
155 |
print('<img src="'.$file.'" />'); |
---|
156 |
|
---|
157 |
print(' </div>'); |
---|
158 |
|
---|
159 |
print(html_footer()); |
---|
160 |
|
---|
161 |
} |
---|
162 |
|
---|