Project

General

Profile

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