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
##|+PRIV
32
##|*IDENT=page-status-rrdgraphs
33
##|*NAME=Status: RRD Graphs page
34
##|*DESCR=Allow access to the 'Status: RRD Graphs' page.
35
##|*MATCH=status_rrd_graph.php*
36
##|-PRIV
37

    
38
require("guiconfig.inc");
39

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

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

    
49
if ($_GET['cat']) {
50
	$curcat = $_GET['cat'];
51
} else {
52
	if(! empty($config['rrd']['category'])) {
53
		$curcat = $config['rrd']['category'];
54
	} else {
55
		$curcat = "system";
56
	}
57
}
58

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

    
86
if ($_GET['style']) {
87
	$curstyle = $_GET['style'];
88
} else {
89
	if(! empty($config['rrd']['style'])) {
90
		$curstyle = $config['rrd']['style'];
91
	} else {
92
		$curstyle = "inverse";
93
	}
94
}
95

    
96
/* sort names reverse so WAN comes first */
97
rsort($databases);
98

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

    
110
/* append the existing array to the header */
111
$ui_databases = array_merge($dbheader, $databases);
112

    
113
$styles = array('inverse' => 'Inverse',
114
		'absolute' => 'Absolute');
115
$periods = array("4h", "16h", "48h", "32d", "6m", "1y", "4y");
116

    
117
$pgtitle = array("Status","RRD Graphs");
118
include("head.inc");
119

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

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

    
194
					?>
195
					</select>
196

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

    
207
					</select>
208

    
209
					<?php
210

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

    
314
<?php include("fend.inc"); ?>
315
</body>
316
</html>
(161-161/217)