Project

General

Profile

Download (10.6 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 {
51
		$curoption = "wan";
52
	}
53
}
54

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

    
65
$rrddbpath = "/var/db/rrd/";
66

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

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

    
81
/* append the existing array to the header */
82
$databases = array_merge($dbheader, $databases);
83

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

    
88
$pgtitle = gettext("Status: RRD Graphs");
89
include("head.inc");
90

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

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

    
166
					?>
167
					</select>
168

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

    
179
					</select>
180

    
181
					<?php
182

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

    
294
<?php include("fend.inc"); ?>
295
</body>
296
</html>
(134-134/183)