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

    
44
/* if the rrd graphs are not enabled redirect to settings page */
45
if(! isset($config['rrd']['enable'])) {
46
	header("Location: status_rrd_graph_settings.php");
47
}
48

    
49
$rrddbpath = "/var/db/rrd/";
50
/* XXX: (billm) do we have an exec() type function that does this type of thing? */
51
exec("cd $rrddbpath;/usr/bin/find -name *.rrd", $databases);
52

    
53
if ($_GET['cat']) {
54
	$curcat = $_GET['cat'];
55
} else {
56
	if(! empty($config['rrd']['category'])) {
57
		$curcat = $config['rrd']['category'];
58
	} else {
59
		$curcat = "system";
60
	}
61
}
62

    
63
if ($_GET['option']) {
64
	$curoption = $_GET['option'];
65
} else {
66
	switch($curcat) {
67
		case "system":
68
			$curoption = "processor";
69
			break;
70
		case "queues":
71
			$curoption = "queues";
72
			break;
73
		case "queuedrops":
74
			$curoption = "queuedrops";
75
			case "quality":
76
		foreach($databases as $database) {
77
			if(preg_match("/[-]quality\.rrd/i", $database)) {
78
				/* pick off the 1st database we find that matches the quality graph */
79
				$name = explode("-", $database);
80
				$curoption = "$name[0]";
81
				continue 2;
82
			}
83
		}
84
		default:
85
			$curoption = "wan";
86
			break;
87
	}
88
}
89

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

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

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

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

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

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

    
124
?>
125
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
126
<?php include("fbegin.inc"); ?>
127
<table width="100%" border="0" cellpadding="0" cellspacing="0">
128
        <tr>
129
                <td>
130
			<form name="form1" action="status_rrd_graph.php" method="get">
131
			<input type="hidden" name="cat" value="<?php echo "$curcat"; ?>">
132
			<?php
133
			        $tab_array = array();
134
				if($curcat == "system") { $tabactive = True; } else { $tabactive = False; }
135
			        $tab_array[] = array("System", $tabactive, "status_rrd_graph.php?cat=system");
136
				if($curcat == "traffic") { $tabactive = True; } else { $tabactive = False; }
137
			        $tab_array[] = array("Traffic", $tabactive, "status_rrd_graph.php?cat=traffic");
138
				if($curcat == "packets") { $tabactive = True; } else { $tabactive = False; }
139
			        $tab_array[] = array("Packets", $tabactive, "status_rrd_graph.php?cat=packets");
140
				if($curcat == "quality") { $tabactive = True; } else { $tabactive = False; }
141
			        $tab_array[] = array("Quality", $tabactive, "status_rrd_graph.php?cat=quality");
142
				if($curcat == "queues") { $tabactive = True; } else { $tabactive = False; }
143
			        $tab_array[] = array("Queues", $tabactive, "status_rrd_graph.php?cat=queues");
144
				if($curcat == "queuedrops") { $tabactive = True; } else { $tabactive = False; }
145
                                $tab_array[] = array("QueueDrops", $tabactive, "status_rrd_graph.php?cat=queuedrops");
146
				if($curcat == "wireless") { $tabactive = True; } else { $tabactive = False; }
147
			        $tab_array[] = array("Wireless", $tabactive, "status_rrd_graph.php?cat=wireless");
148
				if($curcat == "settings") { $tabactive = True; } else { $tabactive = False; }
149
			        $tab_array[] = array("Settings", $tabactive, "status_rrd_graph_settings.php");
150
			        display_top_tabs($tab_array);
151
			?>
152
                </td>
153
        </tr>
154
        <tr>
155
                <td>
156
                        <div id="mainarea">
157
                        <table class="tabcont" width="100%" border="0" cellspacing="0" cellpadding="0">
158
                                <tr>
159
                                        <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>
160
				</tr>
161
				<tr>
162
                                        <td colspan="2" class="list">
163
					<?=gettext("Graphs:");?>
164
					<select name="option" class="formselect" style="z-index: -10;" onchange="document.form1.submit()">
165
					<?php
166

    
167
					foreach ($ui_databases as $db => $database) {
168
						if(! preg_match("/($curcat)/i", $database)) {
169
							continue;
170
						}
171
						$optionc = split("-", $database);
172
						$search = array("-", ".rrd", $optionc);
173
						$replace = array(" :: ", "", $friendly);
174
						switch($curcat) {
175
							case "system":
176
								$optionc = str_replace($search, $replace, $optionc[1]);
177
								echo "<option value=\"$optionc\"";
178
								$prettyprint = ucwords(str_replace($search, $replace, $optionc));
179
								break;
180
							default:
181
								/* Deduce a interface if possible and use the description */
182
								$optionc = "$optionc[0]";
183
								$friendly = convert_friendly_interface_to_friendly_descr(strtolower($optionc));
184
								if(empty($friendly)) {
185
									$friendly = $optionc;
186
								}
187
								$search = array("-", ".rrd", $optionc);
188
								$replace = array(" :: ", "", $friendly);
189
								echo "<option value=\"$optionc\"";
190
								$prettyprint = ucwords(str_replace($search, $replace, $friendly));
191
						}
192
						if($curoption == $optionc) {
193
							echo " selected ";
194
						}
195
						echo ">" . htmlspecialchars($prettyprint) . "</option>\n";
196
					}
197

    
198
					?>
199
					</select>
200

    
201
					<?=gettext("Style:");?>
202
					<select name="style" class="formselect" style="z-index: -10;" onchange="document.form1.submit()">
203
					<?php
204
					foreach ($styles as $style => $styled) {
205
						echo "<option value=\"$style\"";
206
						if ($style == $curstyle) echo " selected";
207
						echo ">" . htmlspecialchars($styled) . "</option>\n";
208
					}
209
					?>
210

    
211
					</select>
212

    
213
					<?php
214

    
215
					foreach($periods as $period => $interval) {
216
						/* check which databases are valid for our category */
217
						foreach($ui_databases as $curdatabase) {
218
							if(! preg_match("/($curcat)/i", $curdatabase)) {
219
								continue;
220
							}
221
							$optionc = split("-", $curdatabase);
222
							$search = array("-", ".rrd", $optionc);
223
							$replace = array(" :: ", "", $friendly);
224
							switch($curoption) {
225
								case "outbound":
226
									/* only show interfaces with a gateway */
227
									$optionc = "$optionc[0]";
228
									if(!interface_has_gateway($optionc)) {
229
										if(!preg_match("/($optionc)-(quality)/", $curdatabase)) {
230
											continue 2;
231
										}
232
									}
233
									if(! preg_match("/($optionc)[-.]/i", $curdatabase)) {
234
										continue 2;
235
									}
236
									break;
237
								case "allgraphs":
238
									/* make sure we do not show the placeholder databases in the all view */
239
									if((stristr($curdatabase, "outbound")) || (stristr($curdatabase, "allgraphs"))) {
240
										continue 2;
241
									}
242
									break;
243
								default:
244
									/* just use the name here */
245
									if(! preg_match("/($curoption)[-.]/i", $curdatabase)) {
246
										continue 2;
247
									}
248
							}
249
							if(in_array($curdatabase, $databases)) {
250
								echo "<tr><td colspan=2 class=\"list\">\n";
251
								echo "<IMG BORDER='0' name='{$interval}-{$curoption}-{$curdatabase}' ";
252
								echo "id='{$interval}-{$curoption}-{$curdatabase}' ALT=\"$prettydb Graph\" ";
253
								echo "SRC=\"status_rrd_graph_img.php?interval=$interval&amp;database={$curdatabase}&amp;style={$curstyle}\" />\n";
254
								echo "<br /><hr><br />\n";								
255
								echo "</td></tr>\n";
256
							}
257
						}
258
					}
259
					?>
260
					</td>
261
				</tr>
262
				<tr>
263
					<td colspan=2 class="list">
264
					<script language="javascript">
265
						function update_graph_images() {
266
							//alert('updating');
267
							var randomid = Math.floor(Math.random()*11);
268
							<?php
269
							foreach($periods as $period => $interval) {
270
								/* check which databases are valid for our category */
271
								foreach($databases as $curdatabase) {
272
									if(! stristr($curdatabase, $curcat)) {
273
										continue;
274
									}
275
									$optionc = split("-", $curdatabase);
276
									$search = array("-", ".rrd", $optionc);
277
									$replace = array(" :: ", "", $friendly);
278
									switch($curoption) {
279
										case "outbound":
280
											if(!interface_has_gateway($optionc)) {
281
												continue 2; 
282
											}
283
											if(! stristr($curdatabase, $optionc)) {
284
													continue 2;
285
											}
286
											break;
287
										case "allgraphs":
288
											/* make sure we do not show the placeholder databases in the all view */
289
											if((stristr($curdatabase, "outbound")) || (stristr($curdatabase, "allgraphs"))) {
290
												continue 2;
291
											}
292
											break;
293
										default:
294
											/* just use the name here */
295
											if(! stristr($curdatabase, $curoption)) {
296
												continue 2;
297
											}
298
									}
299
									/* generate update events utilizing prototype $('') feature */
300
									echo "\n";
301
									echo "\t\t\$('{$interval}-{$curoption}-{$curdatabase}').src='status_rrd_graph_img.php?interval={$interval}&database={$curdatabase}&style={$curstyle}&tmp=' + randomid;\n";
302
									}
303
								}
304
							?>
305
							window.setTimeout('update_graph_images()', 355000);
306
						}
307
						window.setTimeout('update_graph_images()', 355000);
308
					</script>
309
					</form>
310
					</td>
311
				</tr>
312
			</table>
313
		</div>
314
		</td>
315
	</tr>
316
</table>
317

    
318
<?php include("fend.inc"); ?>
319
</body>
320
</html>
(160-160/217)