Project

General

Profile

Download (10.5 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
if ($_GET['cat']) {
46
	$curcat = $_GET['cat'];
47
} else {
48
	if(! empty($config['rrd']['category'])) {
49
		$curcat = $config['rrd']['category'];
50
	} else {
51
		$curcat = "system";
52
	}
53
}
54

    
55
if ($_GET['option']) {
56
	$curoption = $_GET['option'];
57
} else {
58
	if($curcat == "system") {
59
		$curoption = "processor";
60
	} else if($curcat == "queues") {
61
		$curoption = "queues";
62
	} else if($curcat == "queuedrops") {
63
		$curoption = "queuedrops";
64
	} else {
65
		$curoption = "wan";
66
	}
67
}
68

    
69
if ($_GET['style']) {
70
	$curstyle = $_GET['style'];
71
} else {
72
	if(! empty($config['rrd']['style'])) {
73
		$curstyle = $config['rrd']['style'];
74
	} else {
75
		$curstyle = "inverse";
76
	}
77
}
78

    
79
$rrddbpath = "/var/db/rrd/";
80

    
81
/* XXX: (billm) do we have an exec() type function that does this type of thing? */
82
exec("cd $rrddbpath;/usr/bin/find -name *.rrd", $databases);
83
rsort($databases);
84

    
85
/* these boilerplate databases are required for the other menu choices */
86
$dbheader = array("allgraphs-traffic.rrd",
87
		"allgraphs-quality.rrd",
88
		"allgraphs-wireless.rrd",
89
		"allgraphs-packets.rrd",
90
		"system-allgraphs.rrd",
91
		"system-throughput.rrd",
92
		"outbound-quality.rrd",
93
		"outbound-packets.rrd",
94
		"outbound-traffic.rrd");
95

    
96
/* append the existing array to the header */
97
$ui_databases = array_merge($dbheader, $databases);
98

    
99
$styles = array('inverse' => 'Inverse',
100
		'absolute' => 'Absolute');
101
$periods = array("4h", "16h", "48h", "32d", "6m", "1y", "4y");
102

    
103
$pgtitle = array("Status","RRD Graphs");
104
include("head.inc");
105

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

    
149
					foreach ($ui_databases as $db => $database) {
150
						if(! preg_match("/($curcat)/i", $database)) {
151
							continue;
152
						}
153
						$optionc = split("-", $database);
154
						$search = array("-", ".rrd", $optionc);
155
						$replace = array(" :: ", "", $friendly);
156
						switch($curcat) {
157
							case "system":
158
								$optionc = str_replace($search, $replace, $optionc[1]);
159
								echo "<option value=\"$optionc\"";
160
								$prettyprint = ucwords(str_replace($search, $replace, $optionc));
161
								break;
162
							default:
163
								/* Deduce a interface if possible and use the description */
164
								$optionc = "$optionc[0]";
165
								$friendly = convert_friendly_interface_to_friendly_descr(strtolower($optionc));
166
								if(empty($friendly)) {
167
									$friendly = $optionc;
168
								}
169
								$search = array("-", ".rrd", $optionc);
170
								$replace = array(" :: ", "", $friendly);
171
								echo "<option value=\"$optionc\"";
172
								$prettyprint = ucwords(str_replace($search, $replace, $friendly));
173
						}
174
						if($curoption == $optionc) {
175
							echo " selected ";
176
						}
177
						echo ">" . htmlspecialchars($prettyprint) . "</option>\n";
178
					}
179

    
180
					?>
181
					</select>
182

    
183
					<?=gettext("Style:");?>
184
					<select name="style" class="formselect" style="z-index: -10;" onchange="document.form1.submit()">
185
					<?php
186
					foreach ($styles as $style => $styled) {
187
						echo "<option value=\"$style\"";
188
						if ($style == $curstyle) echo " selected";
189
						echo ">" . htmlspecialchars($styled) . "</option>\n";
190
					}
191
					?>
192

    
193
					</select>
194

    
195
					<?php
196

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

    
300
<?php include("fend.inc"); ?>
301
</body>
302
</html>
(151-151/207)