root/trunk/flowmon-web/index.php

Revision 1, 7.6 kB (checked in by ixs, 16 years ago)

initial checkin of RH revision

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 # Copyright 2004, 2005 Red Hat, Inc.
21 #
22 # AUTHOR: Andreas Thienemann <athienem@redhat.com>
23 #
24
25 require_once('config.inc.php');
26 require_once('common.inc.php');
27 require_once('db_handler.inc.php');
28
29 // Initiate the databaseconnection
30 $dbh = '';
31 init_db();
32
33 // The main interface/welcome screen
34 if (!array_key_exists('action', $_REQUEST) OR (array_key_exists('action', $_REQUEST) && $_REQUEST['action'] == 'probe_select' && empty($_REQUEST['probe']))) {
35     print(html_header($title = 'FlowMon '.$prog_vers.' - running on '.$_SERVER['HTTP_HOST']));
36     print(page_header($title = 'FlowMon overview'));
37
38     print('<div style="margin-left: 30px; margin-right: 30px;"><h1>Network Flow Monitor</h1></div>');
39     $num_flows = get_num_flows();
40     $num_systems = get_num_systems();
41     print('<div style="margin: 30px; height: 175px; width: 40%; text-align: left; float: left;">
42         <h2>Database Statistics</h2>
43         <p><table>
44             <tr><td>Number of reporting FlowProbes:</td><td>'.get_num_probes().'<td></tr>
45             <tr><td>Number of archived Flows:</td><td>'.$num_flows.'<td></tr>
46             <tr><td>Number of tracked Systems:</td><td>'.$num_systems.'<td></tr>
47             <tr><td>First Flow occurence:</td><td>'.strftime($date_fmt_str, get_oldest_flow_ts()).'<td></tr>
48             <tr><td>Most recent Flow occurence:</td><td>'.strftime($date_fmt_str, get_newest_flow_ts()).'<td></tr>
49             <tr><td>Database Size:</td><td>'.round((get_db_size() / 1024 / 1024), 2).' MB<td></tr>
50         </table></p>
51         </div>');
52     $bytes = get_bytes();
53     $pkts = get_pkts();
54     print('<div style="margin: 30px; height: 175px; width: 40%; text-align: left; float: right;">
55         <h2>Network Statistics</h2>
56         <p><table>
57             <tr><td>Total Bytes tracked</td><td>'.round((get_bytes() / 1024 / 1024), 2).' MB<td></tr>
58             <tr><td>Total Pakets tracked</td><td>'.get_pkts().'<td></tr>
59             <tr><td>Average Paketsize</td><td>'.@round(($bytes / $pkts), 0).' Bytes<td></tr>
60             <tr><td>Average Traffic per system</td><td>'.@round(($bytes / $num_systems / 1024 / 1024), 2).' MB<td></tr>
61             <tr><td>Average Traffic per flow</td><td>'.@round(($bytes / $num_flows / 1024 / 1024), 2).' MB<td></tr>
62         </table></p>
63         </div>');
64 //    print('<div style="clear: left;"></div>');
65     print('<div style="margin-left: 30px; margin-right: 30px; clear: right; text-align: center;"><h2>Detailed traffic graphs</h2></div>');
66     print('<div style="margin-left: auto; margin-right: auto; width: 400px; height: 100px;">');
67     print('<form action="'.$_SERVER['SCRIPT_NAME'].'" method="GET"><select name="probe" size=1>');
68         print('<option value="" selected="selected">Please select a FlowProbe to chart</option>');
69     foreach(get_probes() as $probe => $hostname) {
70         print('<option value="'.$probe.'">'.$hostname.' ('.$probe.')</option>');
71     }
72     print('</select><input type="hidden" name="action" value="probe_select"><input type="submit" value="Graph!"></form>');
73     print('</div>');
74     print(html_footer());
75
76
77 // We have selected a probe, present with detailes form to get the chart parameters
78 } else if (array_key_exists('action', $_REQUEST) && $_REQUEST['action'] == 'probe_select') {
79     print(html_header($title = 'FlowMon '.$prog_vers.' - running on '.$_SERVER['HTTP_HOST'], $calendar = True));
80     print(page_header($title = 'FlowMon Chart Parameters'));
81     print('<div style="margin: 30px auto 30px auto; height: 350px; width: 40%; text-align: left;">
82         <h1> Statistics</h1>
83                 <form action="'.$_SERVER['SCRIPT_NAME'].'" method="GET">
84         <table>
85         <tr><td>Probe</td><td><input type="hidden" name="probe" value="'.$_REQUEST['probe'].'" />'.gethostbyaddr(htmlspecialchars($_REQUEST['probe'])).' ('.htmlspecialchars($_REQUEST['probe']).')</td></tr>
86         <tr><td>Start Date</td><td><input type="text" name="startdate" value="'.strftime('%Y-%m-%d').'" /></td></tr>
87         <tr><td>Start Time</td><td><input type="text" name="starttime" value="'.strftime('%H:%M', (time() - 3600)).'" /></td></tr>
88         <tr><td>End Date</td><td><input type="text" name="enddate" value="'.strftime('%Y-%m-%d').'" /></td></tr>
89         <tr><td>End Time</td><td><input type="text" name="endtime" value="'.strftime('%H:%M').'" /></td></tr>
90         <tr><td>Chart Style</td><td><select name="style" size=1>');
91         foreach ($chart_styles as $style=>$file) {
92             print('<option>'.$style.'</option>');
93         }
94     print('</select></td></tr>
95         <tr><td colspan="2" style="text-align: right;"><input type="hidden" name="action" value="chart" /><input type="submit" value="Chart" /></form></td></tr>
96         <tr><td colspan="2"><hr></td></tr>
97         <tr><td><form action="'.$_SERVER['SCRIPT_NAME'].'" method="GET">Chart Style</td><td><select name="style" size=1>');
98         foreach ($chart_styles as $style=>$file) {
99             print('<option>'.$style.'</option>');
100         }
101         print('</select></td></tr>
102         <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>
103         </table>
104         </div>');
105
106     print(html_footer());
107
108
109 // We got everything needed to chart the requested data.
110 // Do it!
111 } else if (array_key_exists('action', $_REQUEST) && $_REQUEST['action'] == 'chart') {
112     print(html_header($title = 'FlowMon '.$prog_vers.' - running on '.$_SERVER['HTTP_HOST'], $calendar = True));
113     print(page_header($title = 'FlowMon Traffic Chart'));
114     print('<div style="margin: 30px auto 30px auto; width: 850px; text-align: left;">
115         <h1> Statistics</h1>');
116
117     // Import the Chart-Plugin
118     if (array_key_exists($_REQUEST['style'], $chart_styles)) {
119         require_once('charts/'.$chart_styles[$_REQUEST['style']]);
120     }
121
122     // Sanitize user input
123     $starttime = strtotime($_REQUEST['startdate'].' '.$_REQUEST['starttime']);
124     $endtime = strtotime($_REQUEST['enddate'].' '.$_REQUEST['endtime']);
125     if (!isvalid_probe($_REQUEST['probe'])) {
126         die("Invalid Probe");
127     }
128
129     $file = chart_prepare($_REQUEST['probe'], $starttime, $endtime);
130
131     print('<img src="'.$file.'" />');
132
133     print('    </div>');
134
135     print(html_footer());
136
137 // Rolling chart requested
138 } else if (array_key_exists('action', $_REQUEST) && $_REQUEST['action'] == 'rollingchart') {
139     print(html_header($title = 'FlowMon '.$prog_vers.' - running on '.$_SERVER['HTTP_HOST'], $calendar = False, $refresh = 300));
140     print(page_header($title = 'FlowMon Rolling Traffic Chart'));
141     print('<div style="margin: 30px auto 30px auto; width: 850px; text-align: left;">
142         <h1>Rolling Statistics (updated every 5min)</h1>');
143
144     // Import the Chart-Plugin
145     if (array_key_exists($_REQUEST['style'], $chart_styles)) {
146         require_once('charts/'.$chart_styles[$_REQUEST['style']]);
147     }
148
149     // Sanitize user input
150     if (!isvalid_probe($_REQUEST['probe'])) {
151         die("Invalid Probe");
152     }
153
154     $file = chart_prepare($_REQUEST['probe'], False, False, $_REQUEST['timeframe']);
155
156     print('<img src="'.$file.'" />');
157
158     print('    </div>');
159
160     print(html_footer());
161
162
163 }
164
Note: See TracBrowser for help on using the browser.