Project

General

Profile

Download (10.9 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("rrd.inc");
44

    
45
/* 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
$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
if ($_GET['cat']) {
55
	$curcat = $_GET['cat'];
56
} else {
57
	if(! empty($config['rrd']['category'])) {
58
		$curcat = $config['rrd']['category'];
59
	} else {
60
		$curcat = "system";
61
	}
62
}
63

    
64
if ($_GET['option']) {
65
	$curoption = $_GET['option'];
66
} else {
67
	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
	}
89
}
90

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

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

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

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

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

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

    
125
?>
126
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
127
<?php include("fbegin.inc"); ?>
128
<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
				if($curcat == "queues") { $tabactive = True; } else { $tabactive = False; }
144
			        $tab_array[] = array("Queues", $tabactive, "status_rrd_graph.php?cat=queues");
145
				if($curcat == "queuedrops") { $tabactive = True; } else { $tabactive = False; }
146
                                $tab_array[] = array("QueueDrops", $tabactive, "status_rrd_graph.php?cat=queuedrops");
147
				if($curcat == "wireless") { $tabactive = True; } else { $tabactive = False; }
148
			        $tab_array[] = array("Wireless", $tabactive, "status_rrd_graph.php?cat=wireless");
149
				if($curcat == "settings") { $tabactive = True; } else { $tabactive = False; }
150
			        $tab_array[] = array("Settings", $tabactive, "status_rrd_graph_settings.php");
151
			        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
					foreach ($ui_databases as $db => $database) {
169
						if(! preg_match("/($curcat)/i", $database)) {
170
							continue;
171
						}
172
						$optionc = split("-", $database);
173
						$search = array("-", ".rrd", $optionc);
174
						$replace = array(" :: ", "", $friendly);
175
						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
								if(empty($friendly)) {
186
									$friendly = $optionc;
187
								}
188
								$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
						}
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
						foreach($ui_databases as $curdatabase) {
219
							if(! preg_match("/($curcat)/i", $curdatabase)) {
220
								continue;
221
							}
222
							$optionc = split("-", $curdatabase);
223
							$search = array("-", ".rrd", $optionc);
224
							$replace = array(" :: ", "", $friendly);
225
							switch($curoption) {
226
								case "outbound":
227
									/* only show interfaces with a gateway */
228
									$optionc = "$optionc[0]";
229
									if(!interface_has_gateway($optionc)) {
230
										if(!preg_match("/($optionc)-(quality)/", $curdatabase)) {
231
											continue 2;
232
										}
233
									}
234
									if(! preg_match("/($optionc)[-.]/i", $curdatabase)) {
235
										continue 2;
236
									}
237
									break;
238
								case "allgraphs":
239
									/* 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
								default:
245
									/* just use the name here */
246
									if(! preg_match("/($curoption)[-.]/i", $curdatabase)) {
247
										continue 2;
248
									}
249
							}
250
							if(in_array($curdatabase, $databases)) {
251
								echo "<tr><td colspan=2 class=\"list\">\n";
252
								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
								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
							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
											if(!interface_has_gateway($optionc)) {
282
												continue 2; 
283
											}
284
											if(! stristr($curdatabase, $optionc)) {
285
													continue 2;
286
											}
287
											break;
288
										case "allgraphs":
289
											/* 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
										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
							?>
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

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