Project

General

Profile

Download (10.9 KB) Statistics
| Branch: | Tag: | Revision:
1 37285f69 Scott Ullrich
<?php
2
/* $Id$ */
3
/*
4
	status_rrd_graph.php
5
	Part of pfSense
6 69487053 Seth Mos
	Copyright (C) 2007 Seth Mos <seth.mos@xs4all.nl>
7 37285f69 Scott Ullrich
	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 1d333258 Scott Ullrich
/*	
31
	pfSense_BUILDER_BINARIES:	/usr/bin/find
32
	pfSense_MODULE:	system
33
*/
34 37285f69 Scott Ullrich
35 6b07c15a Matthew Grooms
##|+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 37285f69 Scott Ullrich
require("guiconfig.inc");
43 483e6de8 Scott Ullrich
require_once("rrd.inc");
44 37285f69 Scott Ullrich
45 70281b3a Seth Mos
/* if the rrd graphs are not enabled redirect to settings page */
46
if(! isset($config['rrd']['enable'])) {
47
	header("Location: status_rrd_graph_settings.php");
48
}
49
50 329bb764 Seth Mos
$rrddbpath = "/var/db/rrd/";
51
/* XXX: (billm) do we have an exec() type function that does this type of thing? */
52
exec("cd $rrddbpath;/usr/bin/find -name *.rrd", $databases);
53
54 89d25faf Seth Mos
if ($_GET['cat']) {
55
	$curcat = $_GET['cat'];
56 37285f69 Scott Ullrich
} else {
57 69487053 Seth Mos
	if(! empty($config['rrd']['category'])) {
58
		$curcat = $config['rrd']['category'];
59
	} else {
60
		$curcat = "system";
61
	}
62 89d25faf Seth Mos
}
63
64
if ($_GET['option']) {
65
	$curoption = $_GET['option'];
66
} else {
67 329bb764 Seth Mos
	switch($curcat) {
68
		case "system":
69
			$curoption = "processor";
70
			break;
71
		case "queues":
72
			$curoption = "queues";
73
			break;
74
		case "queuedrops":
75
			$curoption = "queuedrops";
76
			case "quality":
77
		foreach($databases as $database) {
78
			if(preg_match("/[-]quality\.rrd/i", $database)) {
79
				/* pick off the 1st database we find that matches the quality graph */
80
				$name = explode("-", $database);
81
				$curoption = "$name[0]";
82
				continue 2;
83
			}
84
		}
85
		default:
86
			$curoption = "wan";
87
			break;
88 89d25faf Seth Mos
	}
89 37285f69 Scott Ullrich
}
90
91 6ab7ae50 Seth Mos
if ($_GET['style']) {
92
	$curstyle = $_GET['style'];
93 37285f69 Scott Ullrich
} else {
94 69487053 Seth Mos
	if(! empty($config['rrd']['style'])) {
95
		$curstyle = $config['rrd']['style'];
96
	} else {
97
		$curstyle = "inverse";
98
	}
99 37285f69 Scott Ullrich
}
100
101 329bb764 Seth Mos
/* sort names reverse so WAN comes first */
102 6ab7ae50 Seth Mos
rsort($databases);
103 37285f69 Scott Ullrich
104 9850b625 Seth Mos
/* these boilerplate databases are required for the other menu choices */
105
$dbheader = array("allgraphs-traffic.rrd",
106
		"allgraphs-quality.rrd",
107 2f80d451 Seth Mos
		"allgraphs-wireless.rrd",
108 9850b625 Seth Mos
		"allgraphs-packets.rrd",
109
		"system-allgraphs.rrd",
110 e3d7c123 Seth Mos
		"system-throughput.rrd",
111 9850b625 Seth Mos
		"outbound-quality.rrd",
112
		"outbound-packets.rrd",
113
		"outbound-traffic.rrd");
114
115
/* append the existing array to the header */
116 a927edff Seth Mos
$ui_databases = array_merge($dbheader, $databases);
117 9850b625 Seth Mos
118 89d25faf Seth Mos
$styles = array('inverse' => 'Inverse',
119
		'absolute' => 'Absolute');
120 7828fd5b Seth Mos
$periods = array("4h", "16h", "48h", "32d", "6m", "1y", "4y");
121 6ab7ae50 Seth Mos
122 d88c6a9f Scott Ullrich
$pgtitle = array("Status","RRD Graphs");
123 89d25faf Seth Mos
include("head.inc");
124 6ab7ae50 Seth Mos
125
?>
126 37285f69 Scott Ullrich
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
127
<?php include("fbegin.inc"); ?>
128 89d25faf Seth Mos
<table width="100%" border="0" cellpadding="0" cellspacing="0">
129
        <tr>
130
                <td>
131
			<form name="form1" action="status_rrd_graph.php" method="get">
132
			<input type="hidden" name="cat" value="<?php echo "$curcat"; ?>">
133
			<?php
134
			        $tab_array = array();
135
				if($curcat == "system") { $tabactive = True; } else { $tabactive = False; }
136
			        $tab_array[] = array("System", $tabactive, "status_rrd_graph.php?cat=system");
137
				if($curcat == "traffic") { $tabactive = True; } else { $tabactive = False; }
138
			        $tab_array[] = array("Traffic", $tabactive, "status_rrd_graph.php?cat=traffic");
139
				if($curcat == "packets") { $tabactive = True; } else { $tabactive = False; }
140
			        $tab_array[] = array("Packets", $tabactive, "status_rrd_graph.php?cat=packets");
141
				if($curcat == "quality") { $tabactive = True; } else { $tabactive = False; }
142
			        $tab_array[] = array("Quality", $tabactive, "status_rrd_graph.php?cat=quality");
143 c01d99da Seth Mos
				if($curcat == "queues") { $tabactive = True; } else { $tabactive = False; }
144
			        $tab_array[] = array("Queues", $tabactive, "status_rrd_graph.php?cat=queues");
145 34aa4cce Ermal Luçi
				if($curcat == "queuedrops") { $tabactive = True; } else { $tabactive = False; }
146 21a0464c Ermal Luçi
                                $tab_array[] = array("QueueDrops", $tabactive, "status_rrd_graph.php?cat=queuedrops");
147 2f80d451 Seth Mos
				if($curcat == "wireless") { $tabactive = True; } else { $tabactive = False; }
148
			        $tab_array[] = array("Wireless", $tabactive, "status_rrd_graph.php?cat=wireless");
149 69487053 Seth Mos
				if($curcat == "settings") { $tabactive = True; } else { $tabactive = False; }
150
			        $tab_array[] = array("Settings", $tabactive, "status_rrd_graph_settings.php");
151 89d25faf Seth Mos
			        display_top_tabs($tab_array);
152
			?>
153
                </td>
154
        </tr>
155
        <tr>
156
                <td>
157
                        <div id="mainarea">
158
                        <table class="tabcont" width="100%" border="0" cellspacing="0" cellpadding="0">
159
                                <tr>
160
                                        <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>
161
				</tr>
162
				<tr>
163
                                        <td colspan="2" class="list">
164
					<?=gettext("Graphs:");?>
165
					<select name="option" class="formselect" style="z-index: -10;" onchange="document.form1.submit()">
166
					<?php
167
168 a927edff Seth Mos
					foreach ($ui_databases as $db => $database) {
169 2ab73e04 Seth Mos
						if(! preg_match("/($curcat)/i", $database)) {
170 89d25faf Seth Mos
							continue;
171
						}
172
						$optionc = split("-", $database);
173
						$search = array("-", ".rrd", $optionc);
174 35551994 Seth Mos
						$replace = array(" :: ", "", $friendly);
175 9850b625 Seth Mos
						switch($curcat) {
176
							case "system":
177
								$optionc = str_replace($search, $replace, $optionc[1]);
178
								echo "<option value=\"$optionc\"";
179
								$prettyprint = ucwords(str_replace($search, $replace, $optionc));
180
								break;
181
							default:
182
								/* Deduce a interface if possible and use the description */
183
								$optionc = "$optionc[0]";
184
								$friendly = convert_friendly_interface_to_friendly_descr(strtolower($optionc));
185 d9699f96 Seth Mos
								if(empty($friendly)) {
186
									$friendly = $optionc;
187
								}
188 9850b625 Seth Mos
								$search = array("-", ".rrd", $optionc);
189
								$replace = array(" :: ", "", $friendly);
190
								echo "<option value=\"$optionc\"";
191
								$prettyprint = ucwords(str_replace($search, $replace, $friendly));
192
						}
193
						if($curoption == $optionc) {
194
							echo " selected ";
195 89d25faf Seth Mos
						}
196
						echo ">" . htmlspecialchars($prettyprint) . "</option>\n";
197
					}
198
199
					?>
200
					</select>
201
202
					<?=gettext("Style:");?>
203
					<select name="style" class="formselect" style="z-index: -10;" onchange="document.form1.submit()">
204
					<?php
205
					foreach ($styles as $style => $styled) {
206
						echo "<option value=\"$style\"";
207
						if ($style == $curstyle) echo " selected";
208
						echo ">" . htmlspecialchars($styled) . "</option>\n";
209
					}
210
					?>
211
212
					</select>
213
214
					<?php
215
216
					foreach($periods as $period => $interval) {
217
						/* check which databases are valid for our category */
218 a927edff Seth Mos
						foreach($ui_databases as $curdatabase) {
219 2ab73e04 Seth Mos
							if(! preg_match("/($curcat)/i", $curdatabase)) {
220 89d25faf Seth Mos
								continue;
221
							}
222 35551994 Seth Mos
							$optionc = split("-", $curdatabase);
223
							$search = array("-", ".rrd", $optionc);
224
							$replace = array(" :: ", "", $friendly);
225 89d25faf Seth Mos
							switch($curoption) {
226
								case "outbound":
227
									/* only show interfaces with a gateway */
228 35551994 Seth Mos
									$optionc = "$optionc[0]";
229 2e76e612 Seth Mos
									if(!interface_has_gateway($optionc)) {
230 a927edff Seth Mos
										if(!preg_match("/($optionc)-(quality)/", $curdatabase)) {
231
											continue 2;
232
										}
233 35551994 Seth Mos
									}
234 2ab73e04 Seth Mos
									if(! preg_match("/($optionc)[-.]/i", $curdatabase)) {
235 89d25faf Seth Mos
										continue 2;
236
									}
237 9850b625 Seth Mos
									break;
238 89d25faf Seth Mos
								case "allgraphs":
239 9850b625 Seth Mos
									/* make sure we do not show the placeholder databases in the all view */
240
									if((stristr($curdatabase, "outbound")) || (stristr($curdatabase, "allgraphs"))) {
241
										continue 2;
242
									}
243
									break;
244 89d25faf Seth Mos
								default:
245
									/* just use the name here */
246 2ab73e04 Seth Mos
									if(! preg_match("/($curoption)[-.]/i", $curdatabase)) {
247 89d25faf Seth Mos
										continue 2;
248
									}
249
							}
250 e3d7c123 Seth Mos
							if(in_array($curdatabase, $databases)) {
251 89d25faf Seth Mos
								echo "<tr><td colspan=2 class=\"list\">\n";
252 683bf031 Seth Mos
								echo "<IMG BORDER='0' name='{$interval}-{$curoption}-{$curdatabase}' ";
253
								echo "id='{$interval}-{$curoption}-{$curdatabase}' ALT=\"$prettydb Graph\" ";
254
								echo "SRC=\"status_rrd_graph_img.php?interval=$interval&amp;database={$curdatabase}&amp;style={$curstyle}\" />\n";
255 89d25faf Seth Mos
								echo "<br /><hr><br />\n";								
256
								echo "</td></tr>\n";
257
							}
258
						}
259
					}
260
					?>
261
					</td>
262
				</tr>
263
				<tr>
264
					<td colspan=2 class="list">
265
					<script language="javascript">
266
						function update_graph_images() {
267
							//alert('updating');
268
							var randomid = Math.floor(Math.random()*11);
269
							<?php
270 683bf031 Seth Mos
							foreach($periods as $period => $interval) {
271
								/* check which databases are valid for our category */
272
								foreach($databases as $curdatabase) {
273
									if(! stristr($curdatabase, $curcat)) {
274
										continue;
275
									}
276
									$optionc = split("-", $curdatabase);
277
									$search = array("-", ".rrd", $optionc);
278
									$replace = array(" :: ", "", $friendly);
279
									switch($curoption) {
280
										case "outbound":
281 2e76e612 Seth Mos
											if(!interface_has_gateway($optionc)) {
282 683bf031 Seth Mos
												continue 2; 
283
											}
284
											if(! stristr($curdatabase, $optionc)) {
285
													continue 2;
286
											}
287 9850b625 Seth Mos
											break;
288 683bf031 Seth Mos
										case "allgraphs":
289 9850b625 Seth Mos
											/* make sure we do not show the placeholder databases in the all view */
290
											if((stristr($curdatabase, "outbound")) || (stristr($curdatabase, "allgraphs"))) {
291
												continue 2;
292
											}
293
											break;
294 683bf031 Seth Mos
										default:
295
											/* just use the name here */
296
											if(! stristr($curdatabase, $curoption)) {
297
												continue 2;
298
											}
299
									}
300
									/* generate update events utilizing prototype $('') feature */
301
									echo "\n";
302
									echo "\t\t\$('{$interval}-{$curoption}-{$curdatabase}').src='status_rrd_graph_img.php?interval={$interval}&database={$curdatabase}&style={$curstyle}&tmp=' + randomid;\n";
303
									}
304
								}
305 89d25faf Seth Mos
							?>
306
							window.setTimeout('update_graph_images()', 355000);
307
						}
308
						window.setTimeout('update_graph_images()', 355000);
309
					</script>
310
					</form>
311
					</td>
312
				</tr>
313
			</table>
314
		</div>
315
		</td>
316
	</tr>
317
</table>
318 37285f69 Scott Ullrich
319
<?php include("fend.inc"); ?>
320
</body>
321
</html>