Project

General

Profile

Download (10.9 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	firewall_shaper_queues.php
5
	Copyright (C) 2004, 2005 Scott Ullrich
6
	All rights reserved.
7

    
8
	Originally part of m0n0wall (http://m0n0.ch/wall)
9
	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
if($_GET['reset'] <> "") {
37
	mwexec("killall -9 pfctl php");
38
	exit;
39
}
40

    
41
if (!is_array($config['shaper']['queue'])) {
42
	$config['shaper']['queue'] = array();
43
}
44
$a_queues = &$config['shaper']['queue'];
45

    
46
/* redirect to wizard if shaper isn't already configured */
47
if(isset($config['shaper']['enable'])) {
48
	$pconfig['enable'] = TRUE;
49
} else {
50
	if(!is_array($config['shaper']['queue']))
51
		Header("Location: wizard.php?xml=traffic_shaper_wizard.xml");
52
}
53

    
54
$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
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
	config_lock();
68
	$retval = filter_configure();
69
	config_unlock();
70
	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
if ($_GET['act'] == "del") {
80
	if ($a_queues[$_GET['id']]) {
81
		/* check that no rule references this queue */
82
		if (is_array($config['shaper']['rule'])) {
83
			foreach ($config['shaper']['rule'] as $rule) {
84
				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
			if (is_array($config['shaper']['rule'])) {
96
				for ($i = 0; isset($config['shaper']['rule'][$i]); $i++) {
97
					$currule = &$config['shaper']['rule'][$i];
98
					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

    
111
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
$pgtitle = "Firewall: Shaper: Queues";
159
include("head.inc");
160

    
161
?>
162

    
163
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
164
<?php include("fbegin.inc"); ?>
165
<p class="pgtitle"><?=$pgtitle?></p>
166
<form action="firewall_shaper_queues.php" method="post">
167
<script type="text/javascript" language="javascript" src="row_toggle.js"></script>
168
<?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
<?php
176
	$tab_array = array();
177
	$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
	display_top_tabs($tab_array);
181
?>
182
  </td></tr>
183
  <tr>
184
    <td>
185
	<div id="mainarea">
186
              <table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
187
		<tr id="frheader">
188
                        <td width="3%" class="list">&nbsp;</td>
189
                        <td width="0%" class="list">&nbsp;</td>
190
			<td width="5%" class="listhdrr">Flags</td>
191
                        <td width="5%" class="listhdrr">Priority</td>
192
			<td width="5%" class="listhdr">Default</td>
193
			<td width="5%" class="listhdr">Bandwidth</td>
194
                        <td width="65%" class="listhdr">Name</td>
195
                        <td width="10%" class="list">&nbsp;</td>
196
                      </tr>
197
                      <?php $i = 0; foreach ($a_queues as $queue): ?>
198
                      <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
			</td>
211
                        <td class="listr" onClick="fr_toggle(<?=$i;?>)" id="frd<?=$i;?>" ondblclick="document.location='firewall_shaper_queues_edit.php?id=<?=$i;?>';">
212
                          <?=$queue['priority'];?>&nbsp;
213
			</td>
214
			<td class="listr" onClick="fr_toggle(<?=$i;?>)" id="frd<?=$i;?>" ondblclick="document.location='firewall_shaper_queues_edit.php?id=<?=$i;?>';">
215
			  <?php
216
				if($queue['defaultqueue'] <> "") {
217
					echo "Yes";
218
				} else {
219
					echo "No";
220
				}
221
			  ?>
222
			</td>
223
                        <td class="listr" onClick="fr_toggle(<?=$i;?>)" id="frd<?=$i;?>" ondblclick="document.location='firewall_shaper_queues_edit.php?id=<?=$i;?>';">
224
                          <?=htmlspecialchars($queue['bandwidth']);?> <?=htmlspecialchars($queue['bandwidthtype']);?>
225
                          &nbsp;
226
			</td>
227
                        <td class="listbg" onClick="fr_toggle(<?=$i;?>)" ondblclick="document.location='firewall_shaper_queues_edit.php?id=<?=$i;?>';">
228
                          <font color="#FFFFFF"><?=htmlspecialchars($queue['name']);?>
229
                          &nbsp;
230
			</td>
231
                        <td valign="middle" nowrap class="list">
232
                          <table border="0" cellspacing="0" cellpadding="1">
233
                            <tr>
234
			      <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
                              <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
                            </tr>
238
                         </table>
239
                        </td>
240
                      </tr>
241
                      <?php $i++; endforeach; $total_queues = $i; ?>
242
                      <tr>
243
                        <td class="list" colspan="7"></td>
244
                        <td class="list">
245
                          <table border="0" cellspacing="0" cellpadding="1">
246
                            <tr>
247
                              <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
                            </tr>
249
                          </table>
250
                        </td>
251
                      </tr>
252
		      <tr><td colspan="7">
253
		    <p>
254
                    <strong><span class="red">Note:</span></strong><strong><br></strong>
255
                      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
		    </p>
258
		      </td></tr>
259
                    </table>
260
		</div>
261
	  </td>
262
	</tr>
263
</table>
264
            </form>
265
<?php include("fend.inc"); ?>
266
</body>
267
</html>
(59-59/176)