Project

General

Profile

Download (10.8 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
require("guiconfig.inc");
32

    
33
if ($_GET['cat']) {
34
	$curcat = $_GET['cat'];
35
} else {
36
	if(! empty($config['rrd']['category'])) {
37
		$curcat = $config['rrd']['category'];
38
	} else {
39
		$curcat = "system";
40
	}
41
}
42

    
43
if ($_GET['option']) {
44
	$curoption = $_GET['option'];
45
} else {
46
	if($curcat == "system") {
47
		$curoption = "processor";
48
	} else if($curcat == "queues") {
49
		$curoption = "queues";
50
	} else {
51
		$curoption = "wan";
52
	}
53
}
54

    
55
if ($_GET['style']) {
56
	$curstyle = $_GET['style'];
57
} else {
58
	if(! empty($config['rrd']['style'])) {
59
		$curstyle = $config['rrd']['style'];
60
	} else {
61
		$curstyle = "inverse";
62
	}
63
}
64

    
65
$rrddbpath = "/var/db/rrd/";
66

    
67
/* 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

    
71
/* these boilerplate databases are required for the other menu choices */
72
$dbheader = array("allgraphs-traffic.rrd",
73
		"allgraphs-quality.rrd",
74
		"allgraphs-wireless.rrd",
75
		"allgraphs-packets.rrd",
76
		"system-allgraphs.rrd",
77
		"system-throughput.rrd",
78
		"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
$styles = array('inverse' => 'Inverse',
86
		'absolute' => 'Absolute');
87
$periods = array("4h", "16h", "48h", "32d", "6m", "1y", "4y");
88

    
89
$pgtitle = array("Status","RRD Graphs");
90
include("head.inc");
91

    
92
?>
93
<script src="/javascript/scriptaculous/prototype.js" type="text/javascript"></script>
94
<script src="/javascript/scriptaculous/scriptaculous.js" type="text/javascript"></script>
95
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
96
<?php include("fbegin.inc"); ?>
97
<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
				if($curcat == "queues") { $tabactive = True; } else { $tabactive = False; }
113
			        $tab_array[] = array("Queues", $tabactive, "status_rrd_graph.php?cat=queues");
114
				if($curcat == "wireless") { $tabactive = True; } else { $tabactive = False; }
115
			        $tab_array[] = array("Wireless", $tabactive, "status_rrd_graph.php?cat=wireless");
116
				if($curcat == "settings") { $tabactive = True; } else { $tabactive = False; }
117
			        $tab_array[] = array("Settings", $tabactive, "status_rrd_graph_settings.php");
118
			        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
						if(! preg_match("/($curcat)/i", $database)) {
137
							continue;
138
						}
139
						$optionc = split("-", $database);
140
						$search = array("-", ".rrd", $optionc);
141
						$replace = array(" :: ", "", $friendly);
142
						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
								echo "<option value=\"$optionc\"";
151
								$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
						}
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
							if(! preg_match("/($curcat)/i", $curdatabase)) {
189
								continue;
190
							}
191
							$optionc = split("-", $curdatabase);
192
							$search = array("-", ".rrd", $optionc);
193
							$replace = array(" :: ", "", $friendly);
194
							switch($curoption) {
195
								case "outbound":
196
									/* only show interfaces with a gateway */
197
									$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
									if(! preg_match("/($optionc)[-.]/i", $curdatabase)) {
205
										continue 2;
206
									}
207
									break;
208
								case "allgraphs":
209
									/* 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
								default:
215
									/* just use the name here */
216
									if(! preg_match("/($curoption)[-.]/i", $curdatabase)) {
217
										continue 2;
218
									}
219
							}
220
							if(in_array($curdatabase, $databases)) {
221
								echo "<tr><td colspan=2 class=\"list\">\n";
222
								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
								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
							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
											break;
265
										case "allgraphs":
266
											/* 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
										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
							?>
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

    
296
<?php include("fend.inc"); ?>
297
</body>
298
</html>
(134-134/187)