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

    
39
require("guiconfig.inc");
40

    
41
if ($_GET['cat']) {
42
	$curcat = $_GET['cat'];
43
} else {
44
	if(! empty($config['rrd']['category'])) {
45
		$curcat = $config['rrd']['category'];
46
	} else {
47
		$curcat = "system";
48
	}
49
}
50

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

    
65
if ($_GET['style']) {
66
	$curstyle = $_GET['style'];
67
} else {
68
	if(! empty($config['rrd']['style'])) {
69
		$curstyle = $config['rrd']['style'];
70
	} else {
71
		$curstyle = "inverse";
72
	}
73
}
74

    
75
$rrddbpath = "/var/db/rrd/";
76

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

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

    
92
/* append the existing array to the header */
93
$databases = array_merge($dbheader, $databases);
94

    
95
$styles = array('inverse' => 'Inverse',
96
		'absolute' => 'Absolute');
97
$periods = array("4h", "16h", "48h", "32d", "6m", "1y", "4y");
98

    
99
$pgtitle = array("Status","RRD Graphs");
100
include("head.inc");
101

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

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

    
178
					?>
179
					</select>
180

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

    
191
					</select>
192

    
193
					<?php
194

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

    
298
<?php include("fend.inc"); ?>
299
</body>
300
</html>
(156-156/211)