Project

General

Profile

Download (10.9 KB) Statistics
| Branch: | Tag: | Revision:
1 5b237745 Scott Ullrich
<?php
2 b46bfcf5 Bill Marquette
/* $Id$ */
3 5b237745 Scott Ullrich
/*
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 4f335a1b Scott Ullrich
if($_GET['reset'] <> "") {
37
	mwexec("killall -9 pfctl php");
38
	exit;
39
}
40
41 12bcdc89 Scott Ullrich
if (!is_array($config['shaper']['queue'])) {
42
	$config['shaper']['queue'] = array();
43 5b237745 Scott Ullrich
}
44 12bcdc89 Scott Ullrich
$a_queues = &$config['shaper']['queue'];
45 5b237745 Scott Ullrich
46 b3e7dc67 Scott Ullrich
/* redirect to wizard if shaper isn't already configured */
47
if(isset($config['shaper']['enable'])) {
48 75d5cf4f Scott Ullrich
	$pconfig['enable'] = TRUE;
49 b3e7dc67 Scott Ullrich
} else {
50 75d5cf4f Scott Ullrich
	if(!is_array($config['shaper']['queue']))
51
		Header("Location: wizard.php?xml=traffic_shaper_wizard.xml");
52 b3e7dc67 Scott Ullrich
}
53
54 845dc7ed Scott Ullrich
$iflist = array("lan" => "LAN", "wan" => "WAN");
55
56
for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) {
57
	$iflist['opt' . $i] = $config['interfaces']['opt' . $i]['descr'];
58
}
59
60 e8731417 Scott Ullrich
if ($_POST['apply'] || $_POST['submit']) {
61
	$config['shaper']['enable'] = true;
62
	write_config();
63
64
	$retval = 0;
65
	$savemsg = get_std_save_message($retval);
66
	/* Setup pf rules since the user may have changed the optimization value */
67 527be97b Bill Marquette
	config_lock();
68 e8731417 Scott Ullrich
	$retval = filter_configure();
69 527be97b Bill Marquette
	config_unlock();
70 e8731417 Scott Ullrich
	if(stristr($retval, "error") <> true)
71
	    $savemsg = get_std_save_message($retval);
72
	else
73
	    $savemsg = $retval;
74
75
	if(file_exists($d_shaperconfdirty_path))
76
	  unlink($d_shaperconfdirty_path);
77
}
78
79 5b237745 Scott Ullrich
if ($_GET['act'] == "del") {
80
	if ($a_queues[$_GET['id']]) {
81
		/* check that no rule references this queue */
82 12bcdc89 Scott Ullrich
		if (is_array($config['shaper']['rule'])) {
83
			foreach ($config['shaper']['rule'] as $rule) {
84 5b237745 Scott Ullrich
				if (isset($rule['targetqueue']) && ($rule['targetqueue'] == $_GET['id'])) {
85
					$input_errors[] = "This queue cannot be deleted because it is still referenced by a rule.";
86
					break;
87
				}
88
			}
89
		}
90
91
		if (!$input_errors) {
92
			unset($a_queues[$_GET['id']]);
93
94
			/* renumber all rules */
95 12bcdc89 Scott Ullrich
			if (is_array($config['shaper']['rule'])) {
96
				for ($i = 0; isset($config['shaper']['rule'][$i]); $i++) {
97
					$currule = &$config['shaper']['rule'][$i];
98 5b237745 Scott Ullrich
					if (isset($currule['targetqueue']) && ($currule['targetqueue'] > $_GET['id']))
99
						$currule['targetqueue']--;
100
				}
101
			}
102
103
			write_config();
104
			touch($d_shaperconfdirty_path);
105
			header("Location: firewall_shaper_queues.php");
106
			exit;
107
		}
108
	}
109
}
110 52380979 Scott Ullrich
111 b7ff5e40 Scott Ullrich
if ($_POST) {
112
        /* yuck - IE won't send value attributes for image buttons, while Mozilla does -
113
           so we use .x/.y to fine move button clicks instead... */
114
        unset($movebtn);
115
        foreach ($_POST as $pn => $pd) {
116
                if (preg_match("/move_(\d+)_x/", $pn, $matches)) {
117
                        $movebtn = $matches[1];
118
                        break;
119
                }
120
        }
121
        /* move selected rules before this rule */
122
        if (isset($movebtn) && is_array($_POST['queue']) && count($_POST['queue'])) {
123
                $a_queue_new = array();
124
125
                /* copy all rules < $movebtn and not selected */
126
                for ($i = 0; $i < $movebtn; $i++) {
127
                        if (!in_array($i, $_POST['queue']))
128
                                $a_queue_new[] = $a_queues[$i];
129
                }
130
131
                /* copy all selected rules */
132
                for ($i = 0; $i < count($a_queues); $i++) {
133
                        if ($i == $movebtn)
134
                                continue;
135
                        if (in_array($i, $_POST['queue']))
136
                                $a_queue_new[] = $a_queues[$i];
137
                }
138
139
                /* copy $movebtn rule */
140
                if ($movebtn < count($a_queues))
141
                        $a_queue_new[] = $a_queues[$movebtn];
142
143
                /* copy all rules > $movebtn and not selected */
144
                for ($i = $movebtn+1; $i < count($a_queues); $i++) {
145
                        if (!in_array($i, $_POST['queue']))
146
                                $a_queue_new[] = $a_queues[$i];
147
                }
148
149
                $a_queues = $a_queue_new;
150
                write_config();
151
                touch($d_shaperconfdirty_path);
152
                header("Location: firewall_shaper_queues.php");
153
                exit;
154
        }
155
}
156
157
158 52380979 Scott Ullrich
$pgtitle = "Firewall: Shaper: Queues";
159
include("head.inc");
160
161 5b237745 Scott Ullrich
?>
162
163
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
164
<?php include("fbegin.inc"); ?>
165 da7ae7ef Bill Marquette
<p class="pgtitle"><?=$pgtitle?></p>
166 54eaa3c1 Scott Ullrich
<form action="firewall_shaper_queues.php" method="post">
167 b7ff5e40 Scott Ullrich
<script type="text/javascript" language="javascript" src="row_toggle.js"></script>
168 5b237745 Scott Ullrich
<?php if ($input_errors) print_input_errors($input_errors); ?>
169
<?php if ($savemsg) print_info_box($savemsg); ?>
170
<?php if (file_exists($d_shaperconfdirty_path)): ?><p>
171
<?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>
172
<?php endif; ?>
173
<table width="100%" border="0" cellpadding="0" cellspacing="0">
174
  <tr><td>
175 52380979 Scott Ullrich
<?php
176
	$tab_array = array();
177 4958090d Bill Marquette
	$tab_array[0] = array("Rules", false, "firewall_shaper.php");
178
	$tab_array[1] = array("Queues", true, "firewall_shaper_queues.php");
179
	$tab_array[2] = array("EZ Shaper wizard", false, "wizard.php?xml=traffic_shaper_wizard.xml");
180 52380979 Scott Ullrich
	display_top_tabs($tab_array);
181
?>
182 5b237745 Scott Ullrich
  </td></tr>
183
  <tr>
184 d732f186 Bill Marquette
    <td>
185
	<div id="mainarea">
186
              <table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
187 b7ff5e40 Scott Ullrich
		<tr id="frheader">
188
                        <td width="3%" class="list">&nbsp;</td>
189
                        <td width="0%" class="list">&nbsp;</td>
190 8217e5e0 Scott Ullrich
			<td width="5%" class="listhdrr">Flags</td>
191
                        <td width="5%" class="listhdrr">Priority</td>
192
			<td width="5%" class="listhdr">Default</td>
193 dbab498d Scott Ullrich
			<td width="5%" class="listhdr">Bandwidth</td>
194 b7ff5e40 Scott Ullrich
                        <td width="65%" class="listhdr">Name</td>
195
                        <td width="10%" class="list">&nbsp;</td>
196 5b237745 Scott Ullrich
                      </tr>
197
                      <?php $i = 0; foreach ($a_queues as $queue): ?>
198 b7ff5e40 Scott Ullrich
                      <tr valign="top" id="fr<?=$i;?>">
199
<td class="listt"><input type="checkbox" id="frc<?=$i;?>" name="queue[]" value="<?=$i;?>" onClick="fr_bgcolor('<?=$i;?>')" style="margin: 0; padding: 0; width: 15px; height: 15px;"></td>
200
			<td class="listt" onClick="fr_toggle(<?=$i;?>)" id="frc<?=$i;?>" ondblclick="document.location='firewall_shaper_queues_edit.php?id=<?=$i;?>';">&nbsp;</td>
201
			<td class="listr" onClick="fr_toggle(<?=$i;?>)" id="frd<?=$i;?>" ondblclick="document.location='firewall_shaper_queues_edit.php?id=<?=$i;?>';">
202
<?php
203
     if($queue['red'] <> "") echo " RED";
204
     if($queue['rio'] <> "") echo " RIO";
205
     if($queue['ecn'] <> "") echo " ECN";
206
     if($queue['borrow'] <> "") echo " Borrow";
207
     if(isset($queue['ack'])) echo "ACK"
208
?>
209
			&nbsp;
210 b9000512 Scott Ullrich
			</td>
211 b7ff5e40 Scott Ullrich
                        <td class="listr" onClick="fr_toggle(<?=$i;?>)" id="frd<?=$i;?>" ondblclick="document.location='firewall_shaper_queues_edit.php?id=<?=$i;?>';">
212 740dac81 Scott Ullrich
                          <?=$queue['priority'];?>&nbsp;
213 12bcdc89 Scott Ullrich
			</td>
214 b7ff5e40 Scott Ullrich
			<td class="listr" onClick="fr_toggle(<?=$i;?>)" id="frd<?=$i;?>" ondblclick="document.location='firewall_shaper_queues_edit.php?id=<?=$i;?>';">
215 12bcdc89 Scott Ullrich
			  <?php
216 7fc9b85f Scott Ullrich
				if($queue['defaultqueue'] <> "") {
217 12bcdc89 Scott Ullrich
					echo "Yes";
218
				} else {
219
					echo "No";
220
				}
221
			  ?>
222
			</td>
223 b7ff5e40 Scott Ullrich
                        <td class="listr" onClick="fr_toggle(<?=$i;?>)" id="frd<?=$i;?>" ondblclick="document.location='firewall_shaper_queues_edit.php?id=<?=$i;?>';">
224 dbab498d Scott Ullrich
                          <?=htmlspecialchars($queue['bandwidth']);?> <?=htmlspecialchars($queue['bandwidthtype']);?>
225
                          &nbsp;
226
			</td>
227 b7ff5e40 Scott Ullrich
                        <td class="listbg" onClick="fr_toggle(<?=$i;?>)" ondblclick="document.location='firewall_shaper_queues_edit.php?id=<?=$i;?>';">
228 2dc6b3ad Scott Ullrich
                          <font color="#FFFFFF"><?=htmlspecialchars($queue['name']);?>
229 a11c626c Scott Ullrich
                          &nbsp;
230 12bcdc89 Scott Ullrich
			</td>
231 c39b8aa6 Bill Marquette
                        <td valign="middle" nowrap class="list">
232
                          <table border="0" cellspacing="0" cellpadding="1">
233
                            <tr>
234 b7ff5e40 Scott Ullrich
			      <td><input name="move_<?=$i;?>" type="image" src="./themes/<?= $g['theme']; ?>/images/icons/icon_left.gif" width="17" height="17" title="move selected queue before this rule" onMouseOver="fr_insline(<?=$i;?>, true)" onMouseOut="fr_insline(<?=$i;?>, false)"></td>
235 677c0869 Erik Kristensen
                              <td valign="middle"><a href="firewall_shaper_queues_edit.php?id=<?=$i;?>"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_e.gif" width="17" height="17" border="0"></a></td>
236
                              <td valign="middle"><a href="firewall_shaper_queues.php?act=del&id=<?=$i;?>" onclick="return confirm('Do you really want to delete this queue?')"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" width="17" height="17" border="0"></a></td>
237 c39b8aa6 Bill Marquette
                            </tr>
238
                         </table>
239
                        </td>
240 5b237745 Scott Ullrich
                      </tr>
241 b45ea709 Scott Ullrich
                      <?php $i++; endforeach; $total_queues = $i; ?>
242 5b237745 Scott Ullrich
                      <tr>
243 b7ff5e40 Scott Ullrich
                        <td class="list" colspan="7"></td>
244 c39b8aa6 Bill Marquette
                        <td class="list">
245
                          <table border="0" cellspacing="0" cellpadding="1">
246
                            <tr>
247 677c0869 Erik Kristensen
                              <td valign="middle"><a href="firewall_shaper_queues_edit.php"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0"></a></td>
248 c39b8aa6 Bill Marquette
                            </tr>
249
                          </table>
250
                        </td>
251 5b237745 Scott Ullrich
                      </tr>
252 b7ff5e40 Scott Ullrich
		      <tr><td colspan="7">
253 b45ea709 Scott Ullrich
		    <p>
254 cad11f37 Bill Marquette
                    <strong><span class="red">Note:</span></strong><strong><br></strong>
255 c55a8ab9 Holger Bauer
                      A queue can only be deleted if it is not referenced by any rules.<br>
256
                      You can check the results of your queues at <a href="status_queues.php">Status:Queues</a>.
257 b45ea709 Scott Ullrich
		    </p>
258 d732f186 Bill Marquette
		      </td></tr>
259
                    </table>
260
		</div>
261
	  </td>
262 5b237745 Scott Ullrich
	</tr>
263
</table>
264
            </form>
265
<?php include("fend.inc"); ?>
266
</body>
267
</html>