Project

General

Profile

Download (8.51 KB) Statistics
| Branch: | Tag: | Revision:
1 5b237745 Scott Ullrich
#!/usr/local/bin/php
2
<?php
3
/*
4
	firewall_shaper_queues.php
5 b49448ac Scott Ullrich
	Copyright (C) 2004, 2005 Scott Ullrich
6
	All rights reserved.
7 5b237745 Scott Ullrich
8 b49448ac Scott Ullrich
	Originally part of m0n0wall (http://m0n0.ch/wall)
9 5b237745 Scott Ullrich
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
10
	All rights reserved.
11
12
	Redistribution and use in source and binary forms, with or without
13
	modification, are permitted provided that the following conditions are met:
14
15
	1. Redistributions of source code must retain the above copyright notice,
16
	   this list of conditions and the following disclaimer.
17
18
	2. Redistributions in binary form must reproduce the above copyright
19
	   notice, this list of conditions and the following disclaimer in the
20
	   documentation and/or other materials provided with the distribution.
21
22
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
23
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
24
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
26
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31
	POSSIBILITY OF SUCH DAMAGE.
32
*/
33
34
require("guiconfig.inc");
35
36 12bcdc89 Scott Ullrich
if (!is_array($config['shaper']['pipe'])) {
37
	$config['shaper']['pipe'] = array();
38 5b237745 Scott Ullrich
}
39 12bcdc89 Scott Ullrich
if (!is_array($config['shaper']['queue'])) {
40
	$config['shaper']['queue'] = array();
41 5b237745 Scott Ullrich
}
42 12bcdc89 Scott Ullrich
$a_queues = &$config['shaper']['queue'];
43
$a_pipe = &$config['shaper']['pipe'];
44 5b237745 Scott Ullrich
45 845dc7ed Scott Ullrich
$iflist = array("lan" => "LAN", "wan" => "WAN");
46
47
for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) {
48
	$iflist['opt' . $i] = $config['interfaces']['opt' . $i]['descr'];
49
}
50
51 e8731417 Scott Ullrich
if ($_POST['apply'] || $_POST['submit']) {
52
	$config['shaper']['enable'] = true;
53
	write_config();
54
55
	$retval = 0;
56
	$savemsg = get_std_save_message($retval);
57
	/* Setup pf rules since the user may have changed the optimization value */
58
	//config_lock();
59
	$retval = filter_configure();
60
	//config_unlock();
61
	if(stristr($retval, "error") <> true)
62
	    $savemsg = get_std_save_message($retval);
63
	else
64
	    $savemsg = $retval;
65
66
	if(file_exists($d_shaperconfdirty_path))
67
	  unlink($d_shaperconfdirty_path);
68
}
69
70 5b237745 Scott Ullrich
if ($_GET['act'] == "del") {
71
	if ($a_queues[$_GET['id']]) {
72
		/* check that no rule references this queue */
73 12bcdc89 Scott Ullrich
		if (is_array($config['shaper']['rule'])) {
74
			foreach ($config['shaper']['rule'] as $rule) {
75 5b237745 Scott Ullrich
				if (isset($rule['targetqueue']) && ($rule['targetqueue'] == $_GET['id'])) {
76
					$input_errors[] = "This queue cannot be deleted because it is still referenced by a rule.";
77
					break;
78
				}
79
			}
80
		}
81
82
		if (!$input_errors) {
83
			unset($a_queues[$_GET['id']]);
84
85
			/* renumber all rules */
86 12bcdc89 Scott Ullrich
			if (is_array($config['shaper']['rule'])) {
87
				for ($i = 0; isset($config['shaper']['rule'][$i]); $i++) {
88
					$currule = &$config['shaper']['rule'][$i];
89 5b237745 Scott Ullrich
					if (isset($currule['targetqueue']) && ($currule['targetqueue'] > $_GET['id']))
90
						$currule['targetqueue']--;
91
				}
92
			}
93
94
			write_config();
95
			touch($d_shaperconfdirty_path);
96
			header("Location: firewall_shaper_queues.php");
97
			exit;
98
		}
99
	}
100
}
101
?>
102
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
103
<html>
104
<head>
105 cad11f37 Bill Marquette
<title><?=gentitle("Firewall: Traffic shaper: Queues");?></title>
106 5b237745 Scott Ullrich
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
107
<link href="gui.css" rel="stylesheet" type="text/css">
108
</head>
109
110
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
111
<?php include("fbegin.inc"); ?>
112 cad11f37 Bill Marquette
<p class="pgtitle">Firewall: Traffic shaper: Queues</p>
113 54eaa3c1 Scott Ullrich
<form action="firewall_shaper_queues.php" method="post">
114 5b237745 Scott Ullrich
<?php if ($input_errors) print_input_errors($input_errors); ?>
115
<?php if ($savemsg) print_info_box($savemsg); ?>
116
<?php if (file_exists($d_shaperconfdirty_path)): ?><p>
117
<?php print_info_box_np("The traffic shaper configuration has been changed.<br>You must apply the changes in order for them to take effect.");?><br>
118
<input name="apply" type="submit" class="formbtn" id="apply" value="Apply changes"></p>
119
<?php endif; ?>
120
<table width="100%" border="0" cellpadding="0" cellspacing="0">
121
  <tr><td>
122
  <ul id="tabnav">
123 1b8f6d97 Scott Ullrich
    <li class="tabinact"><a href="firewall_shaper.php">Rules</a></li>
124
    <li class="tabact">Queues</a></li>
125
    <li class="tabinact"><a href="firewall_shaper_magic.php">Magic shaper wizard</a></li>
126 5b237745 Scott Ullrich
  </ul>
127
  </td></tr>
128
  <tr>
129
    <td class="tabcont">
130
              <table width="100%" border="0" cellpadding="0" cellspacing="0">
131
                      <tr>
132
                        <td width="10%" class="listhdrr">No.</td>
133 b45ea709 Scott Ullrich
                        <td width="20%" class="listhdrr">Priority</td>
134 fccb044c Scott Ullrich
			<td width="10%" class="listhdr">Default</td>
135
                        <td width="50%" class="listhdr">Name</td>
136 5b237745 Scott Ullrich
                        <td width="10%" class="list"></td>
137
                      </tr>
138
                      <?php $i = 0; foreach ($a_queues as $queue): ?>
139
                      <tr valign="top">
140
                        <td class="listlr">
141 12bcdc89 Scott Ullrich
                          <?=($i+1);?>
142
			</td>
143 5b237745 Scott Ullrich
                        <td class="listr">
144 740dac81 Scott Ullrich
                          <?=$queue['priority'];?>&nbsp;
145 12bcdc89 Scott Ullrich
			</td>
146
			<td class="listr">
147
			  <?php
148 7fc9b85f Scott Ullrich
				if($queue['defaultqueue'] <> "") {
149 12bcdc89 Scott Ullrich
					echo "Yes";
150
				} else {
151
					echo "No";
152
				}
153
			  ?>
154
			</td>
155 5b237745 Scott Ullrich
                        <td class="listbg">
156 2dc6b3ad Scott Ullrich
                          <font color="#FFFFFF"><?=htmlspecialchars($queue['name']);?>
157 b45ea709 Scott Ullrich
                          &nbsp;<br>
158
<?php
159
			$cpuUsage = 0;
160
			echo "<img src='bar_left.gif' height='15' width='4' border='0' align='absmiddle'>";
161
			echo "<img src='bar_blue.gif' height='15' name='queue{$i}widtha' id='queue{$i}widtha' width='" . $cpuUsage . "' border='0' align='absmiddle'>";
162
			echo "<img src='bar_gray.gif' height='15' name='queue{$i}widthb' id='queue{$i}widthb' width='" . (100 - $cpuUsage) . "' border='0' align='absmiddle'>";
163
			echo "<img src='bar_right.gif' height='15' width='5' border='0' align='absmiddle'> ";
164 1866bb19 Scott Ullrich
			echo "<input style='border: 0px solid white; background-color:#990000; color:#FFFFFF;' size='18' name='queue{$i}meter' id='queue{$i}meter' value='{$cpuUsage}'>";
165 b45ea709 Scott Ullrich
?>
166
167 12bcdc89 Scott Ullrich
			</td>
168 5b237745 Scott Ullrich
                        <td valign="middle" nowrap class="list"> <a href="firewall_shaper_queues_edit.php?id=<?=$i;?>"><img src="e.gif" width="17" height="17" border="0"></a>
169
                          &nbsp;<a href="firewall_shaper_queues.php?act=del&id=<?=$i;?>" onclick="return confirm('Do you really want to delete this queue?')"><img src="x.gif" width="17" height="17" border="0"></a></td>
170
                      </tr>
171 b45ea709 Scott Ullrich
                      <?php $i++; endforeach; $total_queues = $i; ?>
172 5b237745 Scott Ullrich
                      <tr>
173
                        <td class="list" colspan="5"></td>
174
                        <td class="list"> <a href="firewall_shaper_queues_edit.php"><img src="plus.gif" width="17" height="17" border="0"></a></td>
175
                      </tr>
176
                    </table>
177 b45ea709 Scott Ullrich
		    <p>
178 cad11f37 Bill Marquette
                    <strong><span class="red">Note:</span></strong><strong><br></strong>
179 b45ea709 Scott Ullrich
                      1)  A queue can only be deleted if it is not referenced by any rules.<br>
180
		      2)  Queue graphs take 5 seconds to sample data.
181
		      </td>
182
		    </p>
183 5b237745 Scott Ullrich
	</tr>
184
</table>
185
            </form>
186
<?php include("fend.inc"); ?>
187
</body>
188
</html>
189 b45ea709 Scott Ullrich
190
191
<?php
192
193 fccb044c Scott Ullrich
$counter = 0;
194 b45ea709 Scott Ullrich
While(!Connection_Aborted()) {
195
196 6a153733 Scott Ullrich
	$stats_array = gather_altq_queue_stats(true);
197 b45ea709 Scott Ullrich
198
	/* calculate total packets being moved through all queues. */
199
	$total_packets_s = 0;
200
	foreach($stats_array as $stats_line) {
201
		$stat_line_split = split("\|", $stats_line);
202
		$total_packets_s = $total_packets_s + intval($stat_line_split[2]);
203
	}
204
205
	$i = 0;
206
	foreach($stats_array as $stats_line) {
207
		$stat_line_split = split("\|", $stats_line);
208 fccb044c Scott Ullrich
		$packet_sampled = intval($stat_line_split[2]);
209
		$speed = $stat_line_split[1];
210 b45ea709 Scott Ullrich
		echo "<script language='javascript'>\n";
211 fccb044c Scott Ullrich
212
		$packet_s = round(100 * (1 - $packet_sampled / $total_packets_s), 0);
213
214
		echo "document.queue{$i}widthb.style.width='{$packet_s}';\n";
215
		echo "document.queue{$i}widtha.style.width='" . (100 - $packet_s) . "';\n";
216 c4ced4c1 Scott Ullrich
		echo "document.forms[0].queue{$i}meter.value = '" . $packet_sampled . "/pps - " . $speed . "';\n";
217 b45ea709 Scott Ullrich
		echo "</script>\n";
218
		$i++;
219
	}
220
221 fccb044c Scott Ullrich
	/*
222
	 *   prevent user from running out of ram.
223
	 *   firefox and ie can be a bear on ram usage!
224
         */
225
	$counter++;
226
	if($counter > 10000) {
227
		echo "Redirecting to <a href=\"firewall_shaper_queues.php\">Firewall Shaper Queues</a>.<p>";
228
		echo "<meta http-equiv=\"refresh\" content=\"1;url=firewall_shaper_queues.php\">";
229
		exit;
230
	}
231
232 b45ea709 Scott Ullrich
}
233
234
?>