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
require("guiconfig.inc");
32

    
33
if ($_GET['cat']) {
34
	$curcat = $_GET['cat'];
35
} else {
36
	if(! empty($config['rrd']['category'])) {
37
		$curcat = $config['rrd']['category'];
38
	} else {
39
		$curcat = "system";
40
	}
41
}
42

    
43
if ($_GET['option']) {
44
	$curoption = $_GET['option'];
45
} else {
46
	if($curcat == "system") {
47
		$curoption = "processor";
48
	} else if($curcat == "queues") {
49
		$curoption = "queues";
50
	} else if($curcat == "queuedrops") {
51
		$curoption = "queuedrops";
52
	} else {
53
		$curoption = "wan";
54
	}
55
}
56

    
57
if ($_GET['style']) {
58
	$curstyle = $_GET['style'];
59
} else {
60
	if(! empty($config['rrd']['style'])) {
61
		$curstyle = $config['rrd']['style'];
62
	} else {
63
		$curstyle = "inverse";
64
	}
65
}
66

    
67
$rrddbpath = "/var/db/rrd/";
68

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

    
73
/* these boilerplate databases are required for the other menu choices */
74
$dbheader = array("allgraphs-traffic.rrd",
75
		"allgraphs-quality.rrd",
76
		"allgraphs-wireless.rrd",
77
		"allgraphs-packets.rrd",
78
		"system-allgraphs.rrd",
79
		"system-throughput.rrd",
80
		"outbound-quality.rrd",
81
		"outbound-packets.rrd",
82
		"outbound-traffic.rrd");
83

    
84
/* append the existing array to the header */
85
$databases = array_merge($dbheader, $databases);
86

    
87
$styles = array('inverse' => 'Inverse',
88
		'absolute' => 'Absolute');
89
$periods = array("4h", "16h", "48h", "32d", "6m", "1y", "4y");
90

    
91
$pgtitle = array("Status","RRD Graphs");
92
include("head.inc");
93

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

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

    
167
					?>
168
					</select>
169

    
170
					<?=gettext("Style:");?>
171
					<select name="style" class="formselect" style="z-index: -10;" onchange="document.form1.submit()">
172
					<?php
173
					foreach ($styles as $style => $styled) {
174
						echo "<option value=\"$style\"";
175
						if ($style == $curstyle) echo " selected";
176
						echo ">" . htmlspecialchars($styled) . "</option>\n";
177
					}
178
					?>
179

    
180
					</select>
181

    
182
					<?php
183

    
184
					foreach($periods as $period => $interval) {
185
						/* check which databases are valid for our category */
186
						foreach($databases as $curdatabase) {
187
							if(! preg_match("/($curcat)/i", $curdatabase)) {
188
								continue;
189
							}
190
							$optionc = split("-", $curdatabase);
191
							$search = array("-", ".rrd", $optionc);
192
							$replace = array(" :: ", "", $friendly);
193
							switch($curoption) {
194
								case "outbound":
195
									/* only show interfaces with a gateway */
196
									$optionc = "$optionc[0]";
197
									$friendly = convert_friendly_interface_to_friendly_descr(strtolower($optionc));
198
									$realif = convert_friendly_interface_to_real_interface_name(strtolower($optionc));
199
									$monitorip = get_interface_gateway(strtolower($optionc));
200
									if($monitorip == "") {
201
										continue 2; 
202
									}
203
									if(! preg_match("/($optionc)[-.]/i", $curdatabase)) {
204
										continue 2;
205
									}
206
									break;
207
								case "allgraphs":
208
									/* make sure we do not show the placeholder databases in the all view */
209
									if((stristr($curdatabase, "outbound")) || (stristr($curdatabase, "allgraphs"))) {
210
										continue 2;
211
									}
212
									break;
213
								default:
214
									/* just use the name here */
215
									if(! preg_match("/($curoption)[-.]/i", $curdatabase)) {
216
										continue 2;
217
									}
218
							}
219
							if(in_array($curdatabase, $databases)) {
220
								echo "<tr><td colspan=2 class=\"list\">\n";
221
								echo "<IMG BORDER='0' name='{$interval}-{$curoption}-{$curdatabase}' ";
222
								echo "id='{$interval}-{$curoption}-{$curdatabase}' ALT=\"$prettydb Graph\" ";
223
								echo "SRC=\"status_rrd_graph_img.php?interval=$interval&amp;database={$curdatabase}&amp;style={$curstyle}\" />\n";
224
								echo "<br /><hr><br />\n";								
225
								echo "</td></tr>\n";
226
							} else {
227
								echo "<b>There is no database available to generate $prettydb from.</b>";
228
							}
229
						}
230
					}
231
					?>
232
					</td>
233
				</tr>
234
				<tr>
235
					<td colspan=2 class="list">
236
					<script language="javascript">
237
						function update_graph_images() {
238
							//alert('updating');
239
							var randomid = Math.floor(Math.random()*11);
240
							<?php
241
							foreach($periods as $period => $interval) {
242
								/* check which databases are valid for our category */
243
								foreach($databases as $curdatabase) {
244
									if(! stristr($curdatabase, $curcat)) {
245
										continue;
246
									}
247
									$optionc = split("-", $curdatabase);
248
									$search = array("-", ".rrd", $optionc);
249
									$replace = array(" :: ", "", $friendly);
250
									switch($curoption) {
251
										case "outbound":
252
											/* only show interfaces with a gateway */
253
												$optionc = "$optionc[0]";
254
												$friendly = convert_friendly_interface_to_friendly_descr(strtolower($optionc));
255
												$realif = convert_friendly_interface_to_real_interface_name(strtolower($optionc));
256
												$monitorip = get_interface_gateway(strtolower($optionc));
257
												if($monitorip == "") {
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>
(136-136/189)