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

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

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

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

    
165
					?>
166
					</select>
167

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

    
178
					</select>
179

    
180
					<?php
181

    
182
					$periods = array("4h", "16h", "48h", "32d", "6m", "16m");
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>
(128-128/173)