Project

General

Profile

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

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

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

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

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

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

    
162
?>
163

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