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
								$search = array("-", ".rrd", $optionc);
165
								$replace = array(" :: ", "", $friendly);
166
								echo "<option value=\"$optionc\"";
167
								$prettyprint = ucwords(str_replace($search, $replace, $friendly));
168
						}
169
						if($curoption == $optionc) {
170
							echo " selected ";
171
						}
172
						echo ">" . htmlspecialchars($prettyprint) . "</option>\n";
173
					}
174

    
175
					?>
176
					</select>
177

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

    
188
					</select>
189

    
190
					<?php
191

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

    
295
<?php include("fend.inc"); ?>
296
</body>
297
</html>
(153-153/215)