Project

General

Profile

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