Project

General

Profile

Download (10.2 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	status_rrd_graph.php
5
	Part of pfSense
6
	Copyright (C) 2006 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
	$curcat = "system";
37
}
38

    
39
if ($_GET['option']) {
40
	$curoption = $_GET['option'];
41
} else {
42
	if($curcat == "system") {
43
		$curoption = "processor";
44
	} else if($curcat == "queues") {
45
		$curoption = "queues.";
46
	} else {
47
		$curoption = "wan";
48
	}
49
}
50

    
51
if ($_GET['style']) {
52
	$curstyle = $_GET['style'];
53
} else {
54
	$curstyle = "inverse";
55
}
56

    
57
$rrddbpath = "/var/db/rrd/";
58

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

    
63
/* these boilerplate databases are required for the other menu choices */
64
$dbheader = array("allgraphs-traffic.rrd",
65
		"allgraphs-quality.rrd",
66
		"allgraphs-packets.rrd",
67
		"system-allgraphs.rrd",
68
		"system-throughput.rrd",
69
		"outbound-quality.rrd",
70
		"outbound-packets.rrd",
71
		"outbound-traffic.rrd");
72

    
73
/* append the existing array to the header */
74
$databases = array_merge($dbheader, $databases);
75

    
76
$styles = array('inverse' => 'Inverse',
77
		'absolute' => 'Absolute');
78

    
79
$pgtitle = gettext("Status: RRD Graphs");
80
include("head.inc");
81

    
82
?>
83
<script src="/javascript/scriptaculous/prototype.js" type="text/javascript"></script>
84
<script src="/javascript/scriptaculous/scriptaculous.js" type="text/javascript"></script>
85
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
86
<?php include("fbegin.inc"); ?>
87
<p class="pgtitle"><?=$pgtitle?></p>
88
<table width="100%" border="0" cellpadding="0" cellspacing="0">
89
        <tr>
90
                <td>
91
			<form name="form1" action="status_rrd_graph.php" method="get">
92
			<input type="hidden" name="cat" value="<?php echo "$curcat"; ?>">
93
			<?php
94
			        $tab_array = array();
95
				if($curcat == "system") { $tabactive = True; } else { $tabactive = False; }
96
			        $tab_array[] = array("System", $tabactive, "status_rrd_graph.php?cat=system");
97
				if($curcat == "traffic") { $tabactive = True; } else { $tabactive = False; }
98
			        $tab_array[] = array("Traffic", $tabactive, "status_rrd_graph.php?cat=traffic");
99
				if($curcat == "packets") { $tabactive = True; } else { $tabactive = False; }
100
			        $tab_array[] = array("Packets", $tabactive, "status_rrd_graph.php?cat=packets");
101
				if($curcat == "quality") { $tabactive = True; } else { $tabactive = False; }
102
			        $tab_array[] = array("Quality", $tabactive, "status_rrd_graph.php?cat=quality");
103
				if($curcat == "queues") { $tabactive = True; } else { $tabactive = False; }
104
			        $tab_array[] = array("Queues", $tabactive, "status_rrd_graph.php?cat=queues");
105
			        display_top_tabs($tab_array);
106
			?>
107
                </td>
108
        </tr>
109
        <tr>
110
                <td>
111
                        <div id="mainarea">
112
                        <table class="tabcont" width="100%" border="0" cellspacing="0" cellpadding="0">
113
                                <tr>
114
                                        <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>
115
				</tr>
116
				<tr>
117
                                        <td colspan="2" class="list">
118
					<?=gettext("Graphs:");?>
119
					<select name="option" class="formselect" style="z-index: -10;" onchange="document.form1.submit()">
120
					<?php
121

    
122
					foreach ($databases as $db => $database) {
123
						if(! stristr($database, $curcat)) {
124
							continue;
125
						}
126
						$optionc = split("-", $database);
127
						$search = array("-", ".rrd", $optionc);
128
						$replace = array(" :: ", "", $friendly);
129
						switch($curcat) {
130
							case "system":
131
								$optionc = str_replace($search, $replace, $optionc[1]);
132
								echo "<option value=\"$optionc\"";
133
								$prettyprint = ucwords(str_replace($search, $replace, $optionc));
134
								break;
135
							case "queues":
136
								$optionc = str_replace($search, $replace, $optionc[1]);
137
								echo "<option value=\"$optionc.\"";
138
								$prettyprint = ucwords(str_replace($search, $replace, $optionc));
139
								break;
140
							default:
141
								/* Deduce a interface if possible and use the description */
142
								$optionc = "$optionc[0]";
143
								$friendly = convert_friendly_interface_to_friendly_descr(strtolower($optionc));
144
								$search = array("-", ".rrd", $optionc);
145
								$replace = array(" :: ", "", $friendly);
146
								echo "<option value=\"$optionc\"";
147
								$prettyprint = ucwords(str_replace($search, $replace, $friendly));
148
						}
149
						if($curoption == $optionc) {
150
							echo " selected ";
151
						}
152
						echo ">" . htmlspecialchars($prettyprint) . "</option>\n";
153
					}
154

    
155
					?>
156
					</select>
157

    
158
					<?=gettext("Style:");?>
159
					<select name="style" class="formselect" style="z-index: -10;" onchange="document.form1.submit()">
160
					<?php
161
					foreach ($styles as $style => $styled) {
162
						echo "<option value=\"$style\"";
163
						if ($style == $curstyle) echo " selected";
164
						echo ">" . htmlspecialchars($styled) . "</option>\n";
165
					}
166
					?>
167

    
168
					</select>
169

    
170
					<?php
171

    
172
					$periods = array("4h", "16h", "48h", "32d", "6m", "16m");
173

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

    
285
<?php include("fend.inc"); ?>
286
</body>
287
</html>
(128-128/175)