root/trunk/flowmon-web/index.php

Revision 4, 7.7 kB (checked in by ixs, 16 years ago)

Additional changes, nslookup support, added time selection to the chart itself...

Line 
1 <?php
2 ini_set("display_errors", "on");
3 ini_set("display_startup_errors", "on");
4 #
5 # Copyright (C) 2008 Red Hat, Inc.
6 # Author: Andreas Thienemann <athienem@redhat.com>
7 #
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU Library General Public License as published by
10 # the Free Software Foundation; version 2 only
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU Library General Public License for more details.
16 #
17 # You should have received a copy of the GNU Library General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 #
21
22 require_once('config.inc.php');
23 require_once('common.inc.php');
24 require_once('db_handler.inc.php');
25
26 // Initiate the databaseconnection
27 $dbh = '';
28 init_db();
29
30 // The main interface/welcome screen
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 //    print('<div style="clear: left;"></div>');
62     print('<div style="margin-left: 30px; margin-right: 30px; clear: right; text-align: center;"><h2>Detailed traffic graphs</h2></div>');
63     print('<div style="margin-left: auto; margin-right: auto; width: 400px; height: 100px;">');
64     print('<form action="'.$_SERVER['SCRIPT_NAME'].'" method="GET"><select name="probe" size=1>');
65         print('<option value="" selected="selected">Please select a FlowProbe to chart</option>');
66     foreach(get_probes() as $probe => $hostname) {
67         print('<option value="'.$probe.'">'.$hostname.' ('.$probe.')</option>');
68     }
69     print('</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     print('</div>');
71     print(html_footer());
72
73
74 // We have selected a probe, present with detailes form to get the chart parameters
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 // We got everything needed to chart the requested data.
108 // Do it!
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     // Initialize defaults which might not exist
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         // Sanitize user input
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     // Import the Chart-Plugin
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     // Do we want namelookups?
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
Note: See TracBrowser for help on using the browser.