Project

General

Profile

Download (10.9 KB) Statistics
| Branch: | Tag: | Revision:
1 5b237745 Scott Ullrich
#!/usr/local/bin/php
2
<?php
3 b46bfcf5 Bill Marquette
/* $Id$ */
4 5b237745 Scott Ullrich
/*
5
	firewall_shaper_queues.php
6 b49448ac Scott Ullrich
	Copyright (C) 2004, 2005 Scott Ullrich
7
	All rights reserved.
8 5b237745 Scott Ullrich
9 b49448ac Scott Ullrich
	Originally part of m0n0wall (http://m0n0.ch/wall)
10 5b237745 Scott Ullrich
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
11
	All rights reserved.
12
13
	Redistribution and use in source and binary forms, with or without
14
	modification, are permitted provided that the following conditions are met:
15
16
	1. Redistributions of source code must retain the above copyright notice,
17
	   this list of conditions and the following disclaimer.
18
19
	2. Redistributions in binary form must reproduce the above copyright
20
	   notice, this list of conditions and the following disclaimer in the
21
	   documentation and/or other materials provided with the distribution.
22
23
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
24
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
25
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
27
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32
	POSSIBILITY OF SUCH DAMAGE.
33
*/
34
35
require("guiconfig.inc");
36
37 4f335a1b Scott Ullrich
if($_GET['reset'] <> "") {
38
	mwexec("killall -9 pfctl php");
39
	exit;
40
}
41
42 12bcdc89 Scott Ullrich
if (!is_array($config['shaper']['queue'])) {
43
	$config['shaper']['queue'] = array();
44 5b237745 Scott Ullrich
}
45 12bcdc89 Scott Ullrich
$a_queues = &$config['shaper']['queue'];
46 5b237745 Scott Ullrich
47 b3e7dc67 Scott Ullrich
/* redirect to wizard if shaper isn't already configured */
48
if(isset($config['shaper']['enable'])) {
49 75d5cf4f Scott Ullrich
	$pconfig['enable'] = TRUE;
50 b3e7dc67 Scott Ullrich
} else {
51 75d5cf4f Scott Ullrich
	if(!is_array($config['shaper']['queue']))
52
		Header("Location: wizard.php?xml=traffic_shaper_wizard.xml");
53 b3e7dc67 Scott Ullrich
}
54
55 845dc7ed Scott Ullrich
$iflist = array("lan" => "LAN", "wan" => "WAN");
56
57
for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) {
58
	$iflist['opt' . $i] = $config['interfaces']['opt' . $i]['descr'];
59
}
60
61 e8731417 Scott Ullrich
if ($_POST['apply'] || $_POST['submit']) {
62
	$config['shaper']['enable'] = true;
63
	write_config();
64
65
	$retval = 0;
66
	$savemsg = get_std_save_message($retval);
67
	/* Setup pf rules since the user may have changed the optimization value */
68 527be97b Bill Marquette
	config_lock();
69 e8731417 Scott Ullrich
	$retval = filter_configure();
70 527be97b Bill Marquette
	config_unlock();
71 e8731417 Scott Ullrich
	if(stristr($retval, "error") <> true)
72
	    $savemsg = get_std_save_message($retval);
73
	else
74
	    $savemsg = $retval;
75
76
	if(file_exists($d_shaperconfdirty_path))
77
	  unlink($d_shaperconfdirty_path);
78
}
79
80 5b237745 Scott Ullrich
if ($_GET['act'] == "del") {
81
	if ($a_queues[$_GET['id']]) {
82
		/* check that no rule references this queue */
83 12bcdc89 Scott Ullrich
		if (is_array($config['shaper']['rule'])) {
84
			foreach ($config['shaper']['rule'] as $rule) {
85 5b237745 Scott Ullrich
				if (isset($rule['targetqueue']) && ($rule['targetqueue'] == $_GET['id'])) {
86
					$input_errors[] = "This queue cannot be deleted because it is still referenced by a rule.";
87
					break;
88
				}
89
			}
90
		}
91
92
		if (!$input_errors) {
93
			unset($a_queues[$_GET['id']]);
94
95
			/* renumber all rules */
96 12bcdc89 Scott Ullrich
			if (is_array($config['shaper']['rule'])) {
97
				for ($i = 0; isset($config['shaper']['rule'][$i]); $i++) {
98
					$currule = &$config['shaper']['rule'][$i];
99 5b237745 Scott Ullrich
					if (isset($currule['targetqueue']) && ($currule['targetqueue'] > $_GET['id']))
100
						$currule['targetqueue']--;
101
				}
102
			}
103
104
			write_config();
105
			touch($d_shaperconfdirty_path);
106
			header("Location: firewall_shaper_queues.php");
107
			exit;
108
		}
109
	}
110
}
111 52380979 Scott Ullrich
112 b7ff5e40 Scott Ullrich
if ($_POST) {
113
        /* yuck - IE won't send value attributes for image buttons, while Mozilla does -
114
           so we use .x/.y to fine move button clicks instead... */
115
        unset($movebtn);
116
        foreach ($_POST as $pn => $pd) {
117
                if (preg_match("/move_(\d+)_x/", $pn, $matches)) {
118
                        $movebtn = $matches[1];
119
                        break;
120
                }
121
        }
122
        /* move selected rules before this rule */
123
        if (isset($movebtn) && is_array($_POST['queue']) && count($_POST['queue'])) {
124
                $a_queue_new = array();
125
126
                /* copy all rules < $movebtn and not selected */
127
                for ($i = 0; $i < $movebtn; $i++) {
128
                        if (!in_array($i, $_POST['queue']))
129
                                $a_queue_new[] = $a_queues[$i];
130
                }
131
132
                /* copy all selected rules */
133
                for ($i = 0; $i < count($a_queues); $i++) {
134
                        if ($i == $movebtn)
135
                                continue;
136
                        if (in_array($i, $_POST['queue']))
137
                                $a_queue_new[] = $a_queues[$i];
138
                }
139
140
                /* copy $movebtn rule */
141
                if ($movebtn < count($a_queues))
142
                        $a_queue_new[] = $a_queues[$movebtn];
143
144
                /* copy all rules > $movebtn and not selected */
145
                for ($i = $movebtn+1; $i < count($a_queues); $i++) {
146
                        if (!in_array($i, $_POST['queue']))
147
                                $a_queue_new[] = $a_queues[$i];
148
                }
149
150
                $a_queues = $a_queue_new;
151
                write_config();
152
                touch($d_shaperconfdirty_path);
153
                header("Location: firewall_shaper_queues.php");
154
                exit;
155
        }
156
}
157
158
159 52380979 Scott Ullrich
$pgtitle = "Firewall: Shaper: Queues";
160
include("head.inc");
161
162 5b237745 Scott Ullrich
?>
163
164
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
165
<?php include("fbegin.inc"); ?>
166 da7ae7ef Bill Marquette
<p class="pgtitle"><?=$pgtitle?></p>
167 54eaa3c1 Scott Ullrich
<form action="firewall_shaper_queues.php" method="post">
168 b7ff5e40 Scott Ullrich
<script type="text/javascript" language="javascript" src="row_toggle.js"></script>
169 5b237745 Scott Ullrich
<?php if ($input_errors) print_input_errors($input_errors); ?>
170
<?php if ($savemsg) print_info_box($savemsg); ?>
171
<?php if (file_exists($d_shaperconfdirty_path)): ?><p>
172
<?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>
173
<?php endif; ?>
174
<table width="100%" border="0" cellpadding="0" cellspacing="0">
175
  <tr><td>
176 52380979 Scott Ullrich
<?php
177
	$tab_array = array();
178 4958090d Bill Marquette
	$tab_array[0] = array("Rules", false, "firewall_shaper.php");
179
	$tab_array[1] = array("Queues", true, "firewall_shaper_queues.php");
180
	$tab_array[2] = array("EZ Shaper wizard", false, "wizard.php?xml=traffic_shaper_wizard.xml");
181 52380979 Scott Ullrich
	display_top_tabs($tab_array);
182
?>
183 5b237745 Scott Ullrich
  </td></tr>
184
  <tr>
185 d732f186 Bill Marquette
    <td>
186
	<div id="mainarea">
187
              <table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
188 b7ff5e40 Scott Ullrich
		<tr id="frheader">
189
                        <td width="3%" class="list">&nbsp;</td>
190
                        <td width="0%" class="list">&nbsp;</td>
191 8217e5e0 Scott Ullrich
			<td width="5%" class="listhdrr">Flags</td>
192
                        <td width="5%" class="listhdrr">Priority</td>
193
			<td width="5%" class="listhdr">Default</td>
194 dbab498d Scott Ullrich
			<td width="5%" class="listhdr">Bandwidth</td>
195 b7ff5e40 Scott Ullrich
                        <td width="65%" class="listhdr">Name</td>
196
                        <td width="10%" class="list">&nbsp;</td>
197 5b237745 Scott Ullrich
                      </tr>
198
                      <?php $i = 0; foreach ($a_queues as $queue): ?>
199 b7ff5e40 Scott Ullrich
                      <tr valign="top" id="fr<?=$i;?>">
200
<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>
201
			<td class="listt" onClick="fr_toggle(<?=$i;?>)" id="frc<?=$i;?>" ondblclick="document.location='firewall_shaper_queues_edit.php?id=<?=$i;?>';">&nbsp;</td>
202
			<td class="listr" onClick="fr_toggle(<?=$i;?>)" id="frd<?=$i;?>" ondblclick="document.location='firewall_shaper_queues_edit.php?id=<?=$i;?>';">
203
<?php
204
     if($queue['red'] <> "") echo " RED";
205
     if($queue['rio'] <> "") echo " RIO";
206
     if($queue['ecn'] <> "") echo " ECN";
207
     if($queue['borrow'] <> "") echo " Borrow";
208
     if(isset($queue['ack'])) echo "ACK"
209
?>
210
			&nbsp;
211 b9000512 Scott Ullrich
			</td>
212 b7ff5e40 Scott Ullrich
                        <td class="listr" onClick="fr_toggle(<?=$i;?>)" id="frd<?=$i;?>" ondblclick="document.location='firewall_shaper_queues_edit.php?id=<?=$i;?>';">
213 740dac81 Scott Ullrich
                          <?=$queue['priority'];?>&nbsp;
214 12bcdc89 Scott Ullrich
			</td>
215 b7ff5e40 Scott Ullrich
			<td class="listr" onClick="fr_toggle(<?=$i;?>)" id="frd<?=$i;?>" ondblclick="document.location='firewall_shaper_queues_edit.php?id=<?=$i;?>';">
216 12bcdc89 Scott Ullrich
			  <?php
217 7fc9b85f Scott Ullrich
				if($queue['defaultqueue'] <> "") {
218 12bcdc89 Scott Ullrich
					echo "Yes";
219
				} else {
220
					echo "No";
221
				}
222
			  ?>
223
			</td>
224 b7ff5e40 Scott Ullrich
                        <td class="listr" onClick="fr_toggle(<?=$i;?>)" id="frd<?=$i;?>" ondblclick="document.location='firewall_shaper_queues_edit.php?id=<?=$i;?>';">
225 dbab498d Scott Ullrich
                          <?=htmlspecialchars($queue['bandwidth']);?> <?=htmlspecialchars($queue['bandwidthtype']);?>
226
                          &nbsp;
227
			</td>
228 b7ff5e40 Scott Ullrich
                        <td class="listbg" onClick="fr_toggle(<?=$i;?>)" ondblclick="document.location='firewall_shaper_queues_edit.php?id=<?=$i;?>';">
229 2dc6b3ad Scott Ullrich
                          <font color="#FFFFFF"><?=htmlspecialchars($queue['name']);?>
230 a11c626c Scott Ullrich
                          &nbsp;
231 12bcdc89 Scott Ullrich
			</td>
232 c39b8aa6 Bill Marquette
                        <td valign="middle" nowrap class="list">
233
                          <table border="0" cellspacing="0" cellpadding="1">
234
                            <tr>
235 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>
236 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>
237
                              <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>
238 c39b8aa6 Bill Marquette
                            </tr>
239
                         </table>
240
                        </td>
241 5b237745 Scott Ullrich
                      </tr>
242 b45ea709 Scott Ullrich
                      <?php $i++; endforeach; $total_queues = $i; ?>
243 5b237745 Scott Ullrich
                      <tr>
244 b7ff5e40 Scott Ullrich
                        <td class="list" colspan="7"></td>
245 c39b8aa6 Bill Marquette
                        <td class="list">
246
                          <table border="0" cellspacing="0" cellpadding="1">
247
                            <tr>
248 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>
249 c39b8aa6 Bill Marquette
                            </tr>
250
                          </table>
251
                        </td>
252 5b237745 Scott Ullrich
                      </tr>
253 b7ff5e40 Scott Ullrich
		      <tr><td colspan="7">
254 b45ea709 Scott Ullrich
		    <p>
255 cad11f37 Bill Marquette
                    <strong><span class="red">Note:</span></strong><strong><br></strong>
256 c55a8ab9 Holger Bauer
                      A queue can only be deleted if it is not referenced by any rules.<br>
257
                      You can check the results of your queues at <a href="status_queues.php">Status:Queues</a>.
258 b45ea709 Scott Ullrich
		    </p>
259 d732f186 Bill Marquette
		      </td></tr>
260
                    </table>
261
		</div>
262
	  </td>
263 5b237745 Scott Ullrich
	</tr>
264
</table>
265
            </form>
266
<?php include("fend.inc"); ?>
267
</body>
268
</html>