Project

General

Profile

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

    
287
<?php include("fend.inc"); ?>
288
</body>
289
</html>
(143-143/200)