Project

General

Profile

Download (11 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	status_rrd_graph.php
5
	Part of pfSense
6
	Copyright (C) 2007 Seth Mos <seth.mos@xs4all.nl>
7
	All rights reserved.
8

    
9
	Redistribution and use in source and binary forms, with or without
10
	modification, are permitted provided that the following conditions are met:
11

    
12
	1. Redistributions of source code must retain the above copyright notice,
13
	   this list of conditions and the following disclaimer.
14

    
15
	2. Redistributions in binary form must reproduce the above copyright
16
	   notice, this list of conditions and the following disclaimer in the
17
	   documentation and/or other materials provided with the distribution.
18

    
19
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
20
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
21
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
23
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28
	POSSIBILITY OF SUCH DAMAGE.
29
*/
30
/*	
31
	pfSense_BUILDER_BINARIES:	/usr/bin/find
32
	pfSense_MODULE:	system
33
*/
34

    
35
##|+PRIV
36
##|*IDENT=page-status-rrdgraphs
37
##|*NAME=Status: RRD Graphs page
38
##|*DESCR=Allow access to the 'Status: RRD Graphs' page.
39
##|*MATCH=status_rrd_graph.php*
40
##|-PRIV
41

    
42
require("guiconfig.inc");
43
require_once("filter.inc");
44
require("shaper.inc");
45
require_once("rrd.inc");
46

    
47
/* if the rrd graphs are not enabled redirect to settings page */
48
if(! isset($config['rrd']['enable'])) {
49
	header("Location: status_rrd_graph_settings.php");
50
}
51

    
52
$rrddbpath = "/var/db/rrd/";
53
/* XXX: (billm) do we have an exec() type function that does this type of thing? */
54
exec("cd $rrddbpath;/usr/bin/find -name *.rrd", $databases);
55

    
56
if ($_GET['cat']) {
57
	$curcat = $_GET['cat'];
58
} else {
59
	if(! empty($config['rrd']['category'])) {
60
		$curcat = $config['rrd']['category'];
61
	} else {
62
		$curcat = "system";
63
	}
64
}
65

    
66
if ($_GET['option']) {
67
	$curoption = $_GET['option'];
68
} else {
69
	switch($curcat) {
70
		case "system":
71
			$curoption = "processor";
72
			break;
73
		case "queues":
74
			$curoption = "queues";
75
			break;
76
		case "queuedrops":
77
			$curoption = "queuedrops";
78
			case "quality":
79
		foreach($databases as $database) {
80
			if(preg_match("/[-]quality\.rrd/i", $database)) {
81
				/* pick off the 1st database we find that matches the quality graph */
82
				$name = explode("-", $database);
83
				$curoption = "$name[0]";
84
				continue 2;
85
			}
86
		}
87
		default:
88
			$curoption = "wan";
89
			break;
90
	}
91
}
92

    
93
if ($_GET['style']) {
94
	$curstyle = $_GET['style'];
95
} else {
96
	if(! empty($config['rrd']['style'])) {
97
		$curstyle = $config['rrd']['style'];
98
	} else {
99
		$curstyle = "inverse";
100
	}
101
}
102

    
103
/* sort names reverse so WAN comes first */
104
rsort($databases);
105

    
106
/* these boilerplate databases are required for the other menu choices */
107
$dbheader = array("allgraphs-traffic.rrd",
108
		"allgraphs-quality.rrd",
109
		"allgraphs-wireless.rrd",
110
		"allgraphs-packets.rrd",
111
		"system-allgraphs.rrd",
112
		"system-throughput.rrd",
113
		"outbound-quality.rrd",
114
		"outbound-packets.rrd",
115
		"outbound-traffic.rrd");
116

    
117
/* append the existing array to the header */
118
$ui_databases = array_merge($dbheader, $databases);
119

    
120
$styles = array('inverse' => 'Inverse',
121
		'absolute' => 'Absolute');
122
$periods = array("4h", "16h", "48h", "32d", "6m", "1y", "4y");
123

    
124
$pgtitle = array("Status","RRD Graphs");
125
include("head.inc");
126

    
127
?>
128
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
129
<?php include("fbegin.inc"); ?>
130
<table width="100%" border="0" cellpadding="0" cellspacing="0">
131
        <tr>
132
                <td>
133
			<form name="form1" action="status_rrd_graph.php" method="get">
134
			<input type="hidden" name="cat" value="<?php echo "$curcat"; ?>">
135
			<?php
136
			        $tab_array = array();
137
				if($curcat == "system") { $tabactive = True; } else { $tabactive = False; }
138
			        $tab_array[] = array("System", $tabactive, "status_rrd_graph.php?cat=system");
139
				if($curcat == "traffic") { $tabactive = True; } else { $tabactive = False; }
140
			        $tab_array[] = array("Traffic", $tabactive, "status_rrd_graph.php?cat=traffic");
141
				if($curcat == "packets") { $tabactive = True; } else { $tabactive = False; }
142
			        $tab_array[] = array("Packets", $tabactive, "status_rrd_graph.php?cat=packets");
143
				if($curcat == "quality") { $tabactive = True; } else { $tabactive = False; }
144
			        $tab_array[] = array("Quality", $tabactive, "status_rrd_graph.php?cat=quality");
145
				if($curcat == "queues") { $tabactive = True; } else { $tabactive = False; }
146
			        $tab_array[] = array("Queues", $tabactive, "status_rrd_graph.php?cat=queues");
147
				if($curcat == "queuedrops") { $tabactive = True; } else { $tabactive = False; }
148
                                $tab_array[] = array("QueueDrops", $tabactive, "status_rrd_graph.php?cat=queuedrops");
149
				if($curcat == "wireless") { $tabactive = True; } else { $tabactive = False; }
150
			        $tab_array[] = array("Wireless", $tabactive, "status_rrd_graph.php?cat=wireless");
151
				if($curcat == "settings") { $tabactive = True; } else { $tabactive = False; }
152
			        $tab_array[] = array("Settings", $tabactive, "status_rrd_graph_settings.php");
153
			        display_top_tabs($tab_array);
154
			?>
155
                </td>
156
        </tr>
157
        <tr>
158
                <td>
159
                        <div id="mainarea">
160
                        <table class="tabcont" width="100%" border="0" cellspacing="0" cellpadding="0">
161
                                <tr>
162
                                        <td colspan="2" class="list"><p><b><?=gettext("Note: Change of color and/or style may not take effect until the next refresh");?></b></p></td>
163
				</tr>
164
				<tr>
165
                                        <td colspan="2" class="list">
166
					<?=gettext("Graphs:");?>
167
					<select name="option" class="formselect" style="z-index: -10;" onchange="document.form1.submit()">
168
					<?php
169

    
170
					foreach ($ui_databases as $db => $database) {
171
						if(! preg_match("/($curcat)/i", $database)) {
172
							continue;
173
						}
174
						$optionc = split("-", $database);
175
						$search = array("-", ".rrd", $optionc);
176
						$replace = array(" :: ", "", $friendly);
177
						switch($curcat) {
178
							case "system":
179
								$optionc = str_replace($search, $replace, $optionc[1]);
180
								echo "<option value=\"$optionc\"";
181
								$prettyprint = ucwords(str_replace($search, $replace, $optionc));
182
								break;
183
							default:
184
								/* Deduce a interface if possible and use the description */
185
								$optionc = "$optionc[0]";
186
								$friendly = convert_friendly_interface_to_friendly_descr(strtolower($optionc));
187
								if(empty($friendly)) {
188
									$friendly = $optionc;
189
								}
190
								$search = array("-", ".rrd", $optionc);
191
								$replace = array(" :: ", "", $friendly);
192
								echo "<option value=\"$optionc\"";
193
								$prettyprint = ucwords(str_replace($search, $replace, $friendly));
194
						}
195
						if($curoption == $optionc) {
196
							echo " selected ";
197
						}
198
						echo ">" . htmlspecialchars($prettyprint) . "</option>\n";
199
					}
200

    
201
					?>
202
					</select>
203

    
204
					<?=gettext("Style:");?>
205
					<select name="style" class="formselect" style="z-index: -10;" onchange="document.form1.submit()">
206
					<?php
207
					foreach ($styles as $style => $styled) {
208
						echo "<option value=\"$style\"";
209
						if ($style == $curstyle) echo " selected";
210
						echo ">" . htmlspecialchars($styled) . "</option>\n";
211
					}
212
					?>
213

    
214
					</select>
215

    
216
					<?php
217

    
218
					foreach($periods as $period => $interval) {
219
						/* check which databases are valid for our category */
220
						foreach($ui_databases as $curdatabase) {
221
							if(! preg_match("/($curcat)/i", $curdatabase)) {
222
								continue;
223
							}
224
							$optionc = split("-", $curdatabase);
225
							$search = array("-", ".rrd", $optionc);
226
							$replace = array(" :: ", "", $friendly);
227
							switch($curoption) {
228
								case "outbound":
229
									/* only show interfaces with a gateway */
230
									$optionc = "$optionc[0]";
231
									if(!interface_has_gateway($optionc)) {
232
										if(!preg_match("/($optionc)-(quality)/", $curdatabase)) {
233
											continue 2;
234
										}
235
									}
236
									if(! preg_match("/($optionc)[-.]/i", $curdatabase)) {
237
										continue 2;
238
									}
239
									break;
240
								case "allgraphs":
241
									/* make sure we do not show the placeholder databases in the all view */
242
									if((stristr($curdatabase, "outbound")) || (stristr($curdatabase, "allgraphs"))) {
243
										continue 2;
244
									}
245
									break;
246
								default:
247
									/* just use the name here */
248
									if(! preg_match("/($curoption)[-.]/i", $curdatabase)) {
249
										continue 2;
250
									}
251
							}
252
							if(in_array($curdatabase, $databases)) {
253
								echo "<tr><td colspan=2 class=\"list\">\n";
254
								echo "<IMG BORDER='0' name='{$interval}-{$curoption}-{$curdatabase}' ";
255
								echo "id='{$interval}-{$curoption}-{$curdatabase}' ALT=\"$prettydb Graph\" ";
256
								echo "SRC=\"status_rrd_graph_img.php?interval=$interval&amp;database={$curdatabase}&amp;style={$curstyle}\" />\n";
257
								echo "<br /><hr><br />\n";								
258
								echo "</td></tr>\n";
259
							}
260
						}
261
					}
262
					?>
263
					</td>
264
				</tr>
265
				<tr>
266
					<td colspan=2 class="list">
267
					<script language="javascript">
268
						function update_graph_images() {
269
							//alert('updating');
270
							var randomid = Math.floor(Math.random()*11);
271
							<?php
272
							foreach($periods as $period => $interval) {
273
								/* check which databases are valid for our category */
274
								foreach($databases as $curdatabase) {
275
									if(! stristr($curdatabase, $curcat)) {
276
										continue;
277
									}
278
									$optionc = split("-", $curdatabase);
279
									$search = array("-", ".rrd", $optionc);
280
									$replace = array(" :: ", "", $friendly);
281
									switch($curoption) {
282
										case "outbound":
283
											if(!interface_has_gateway($optionc)) {
284
												continue 2; 
285
											}
286
											if(! stristr($curdatabase, $optionc)) {
287
													continue 2;
288
											}
289
											break;
290
										case "allgraphs":
291
											/* make sure we do not show the placeholder databases in the all view */
292
											if((stristr($curdatabase, "outbound")) || (stristr($curdatabase, "allgraphs"))) {
293
												continue 2;
294
											}
295
											break;
296
										default:
297
											/* just use the name here */
298
											if(! stristr($curdatabase, $curoption)) {
299
												continue 2;
300
											}
301
									}
302
									/* generate update events utilizing prototype $('') feature */
303
									echo "\n";
304
									echo "\t\t\$('{$interval}-{$curoption}-{$curdatabase}').src='status_rrd_graph_img.php?interval={$interval}&database={$curdatabase}&style={$curstyle}&tmp=' + randomid;\n";
305
									}
306
								}
307
							?>
308
							window.setTimeout('update_graph_images()', 355000);
309
						}
310
						window.setTimeout('update_graph_images()', 355000);
311
					</script>
312
					</form>
313
					</td>
314
				</tr>
315
			</table>
316
		</div>
317
		</td>
318
	</tr>
319
</table>
320

    
321
<?php include("fend.inc"); ?>
322
</body>
323
</html>
(157-157/214)