1
|
#!/usr/local/bin/php
|
2
|
<?php
|
3
|
/* $Id$ */
|
4
|
/*
|
5
|
firewall_shaper.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 (!is_array($config['shaper']['rule'])) {
|
38
|
$config['shaper']['rule'] = array();
|
39
|
}
|
40
|
if (!is_array($config['shaper']['queue'])) {
|
41
|
$config['shaper']['queue'] = array();
|
42
|
}
|
43
|
$a_shaper = &$config['shaper']['rule'];
|
44
|
$a_queue = &$config['shaper']['queue'];
|
45
|
|
46
|
$pconfig['enable'] = isset($config['shaper']['enable']);
|
47
|
|
48
|
if ($_POST) {
|
49
|
|
50
|
if ($_POST['submit']) {
|
51
|
$pconfig = $_POST;
|
52
|
$config['shaper']['enable'] = $_POST['enable'] ? true : false;
|
53
|
write_config();
|
54
|
}
|
55
|
|
56
|
if ($_POST['apply'] || $_POST['submit']) {
|
57
|
$config['shaper']['enable'] = $_POST['enable'] ? true : false;
|
58
|
write_config();
|
59
|
$retval = 0;
|
60
|
$savemsg = get_std_save_message($retval);
|
61
|
/* Setup pf rules since the user may have changed the optimization value */
|
62
|
config_lock();
|
63
|
$retval = filter_configure();
|
64
|
config_unlock();
|
65
|
if(stristr($retval, "error") <> true)
|
66
|
$savemsg = get_std_save_message($retval);
|
67
|
else
|
68
|
$savemsg = $retval;
|
69
|
|
70
|
if(file_exists($d_shaperconfdirty_path))
|
71
|
unlink($d_shaperconfdirty_path);
|
72
|
}
|
73
|
}
|
74
|
|
75
|
if ($_GET['act'] == "del") {
|
76
|
if ($a_shaper[$_GET['id']]) {
|
77
|
unset($a_shaper[$_GET['id']]);
|
78
|
write_config();
|
79
|
touch($d_shaperconfdirty_path);
|
80
|
header("Location: firewall_shaper.php");
|
81
|
exit;
|
82
|
}
|
83
|
} else if ($_GET['act'] == "down") {
|
84
|
if ($a_shaper[$_GET['id']] && $a_shaper[$_GET['id']+1]) {
|
85
|
$tmp = $a_shaper[$_GET['id']+1];
|
86
|
$a_shaper[$_GET['id']+1] = $a_shaper[$_GET['id']];
|
87
|
$a_shaper[$_GET['id']] = $tmp;
|
88
|
write_config();
|
89
|
touch($d_shaperconfdirty_path);
|
90
|
header("Location: firewall_shaper.php");
|
91
|
exit;
|
92
|
}
|
93
|
} else if ($_GET['act'] == "up") {
|
94
|
if (($_GET['id'] > 0) && $a_shaper[$_GET['id']]) {
|
95
|
$tmp = $a_shaper[$_GET['id']-1];
|
96
|
$a_shaper[$_GET['id']-1] = $a_shaper[$_GET['id']];
|
97
|
$a_shaper[$_GET['id']] = $tmp;
|
98
|
write_config();
|
99
|
touch($d_shaperconfdirty_path);
|
100
|
header("Location: firewall_shaper.php");
|
101
|
exit;
|
102
|
}
|
103
|
} else if ($_GET['act'] == "toggle") {
|
104
|
if ($a_shaper[$_GET['id']]) {
|
105
|
$a_shaper[$_GET['id']]['disabled'] = !isset($a_shaper[$_GET['id']]['disabled']);
|
106
|
write_config();
|
107
|
touch($d_shaperconfdirty_path);
|
108
|
header("Location: firewall_shaper.php");
|
109
|
exit;
|
110
|
}
|
111
|
} else {
|
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['rule']) && count($_POST['rule'])) {
|
123
|
$a_shaper_new = array();
|
124
|
|
125
|
/* copy all rules < $movebtn and not selected */
|
126
|
for ($i = 0; $i < $movebtn; $i++) {
|
127
|
if (!in_array($i, $_POST['rule']))
|
128
|
$a_shaper_new[] = $a_shaper[$i];
|
129
|
}
|
130
|
|
131
|
/* copy all selected rules */
|
132
|
for ($i = 0; $i < count($a_shaper); $i++) {
|
133
|
if ($i == $movebtn)
|
134
|
continue;
|
135
|
if (in_array($i, $_POST['rule']))
|
136
|
$a_shaper_new[] = $a_shaper[$i];
|
137
|
}
|
138
|
|
139
|
/* copy $movebtn rule */
|
140
|
if ($movebtn < count($a_shaper))
|
141
|
$a_shaper_new[] = $a_shaper[$movebtn];
|
142
|
|
143
|
/* copy all rules > $movebtn and not selected */
|
144
|
for ($i = $movebtn+1; $i < count($a_shaper); $i++) {
|
145
|
if (!in_array($i, $_POST['rule']))
|
146
|
$a_shaper_new[] = $a_shaper[$i];
|
147
|
}
|
148
|
|
149
|
$a_shaper = $a_shaper_new;
|
150
|
write_config();
|
151
|
touch($d_shaperconfdirty_path);
|
152
|
header("Location: firewall_shaper.php");
|
153
|
exit;
|
154
|
}
|
155
|
}
|
156
|
?>
|
157
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
158
|
<html>
|
159
|
<head>
|
160
|
<title><?=gentitle("Firewall: Traffic shaper: Rules");?></title>
|
161
|
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
162
|
<link href="gui.css" rel="stylesheet" type="text/css">
|
163
|
</head>
|
164
|
|
165
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
|
166
|
<?php include("fbegin.inc"); ?>
|
167
|
<p class="pgtitle">Firewall: Traffic shaper: Rules</p>
|
168
|
<form action="firewall_shaper.php" method="post" name="iform">
|
169
|
<script type="text/javascript" language="javascript" src="row_toggle.js">
|
170
|
</script>
|
171
|
<?php if ($savemsg) print_info_box($savemsg); ?>
|
172
|
<?php if (file_exists($d_shaperconfdirty_path)): ?><p>
|
173
|
<?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>
|
174
|
<input name="apply" type="submit" class="formbtn" id="apply" value="Apply changes"></p>
|
175
|
<?php endif; ?>
|
176
|
<table width="100%" border="0" cellpadding="0" cellspacing="0">
|
177
|
<tr><td>
|
178
|
<ul id="tabnav">
|
179
|
<li class="tabact">Rules</li>
|
180
|
<li class="tabinact"><a href="firewall_shaper_queues.php">Queues</a></li>
|
181
|
<li class="tabinact"><a href="firewall_shaper_magic.php">Magic shaper wizard</a></li>
|
182
|
</ul>
|
183
|
</td></tr>
|
184
|
<tr>
|
185
|
<td class="tabcont">
|
186
|
<table width="100%" border="0" cellpadding="6" cellspacing="0">
|
187
|
<tr>
|
188
|
<td class="vtable"><p>
|
189
|
<input name="enable" type="checkbox" id="enable" value="yes" <?php if ($pconfig['enable'] == "yes") echo "checked";?>>
|
190
|
<strong>Enable traffic shaper<br>
|
191
|
</strong></p></td>
|
192
|
</tr>
|
193
|
<tr>
|
194
|
<td> <input name="submit" type="submit" class="formbtn" value="Save">
|
195
|
</td>
|
196
|
</tr>
|
197
|
</table>
|
198
|
<br>
|
199
|
<table width="100%" border="0" cellpadding="0" cellspacing="0">
|
200
|
<tr id="frheader">
|
201
|
<td width="3%" class="list"> </td>
|
202
|
<td width="3%" class="list"> </td>
|
203
|
<td width="5%" class="listhdrrns">If</td>
|
204
|
<td width="5%" class="listhdrrns">Proto</td>
|
205
|
<td width="20%" class="listhdrr">Source</td>
|
206
|
<td width="20%" class="listhdrr">Destination</td>
|
207
|
<td width="15%" class="listhdrrns">Target</td>
|
208
|
<td width="25%" class="listhdr">Description</td>
|
209
|
<td width="10%" class="list"></td>
|
210
|
</tr>
|
211
|
<?php $nrules = $i = 0; foreach ($a_shaper as $shaperent): ?>
|
212
|
<tr valign="top" id="fr<?=$nrules;?>">
|
213
|
<td class="listt"><input type="checkbox" id="frc<?=$nrules;?>" name="rule[]" value="<?=$i;?>" onClick="fr_bgcolor('<?=$nrules;?>')" style="margin: 0; padding: 0; width: 15px; height: 15px;"></td>
|
214
|
<td class="listt" align="center"></td>
|
215
|
<td class="listlr" onClick="fr_toggle(<?=$nrules;?>)" id="frd<?=$nrules;?>">
|
216
|
<?php
|
217
|
$dis = "";
|
218
|
if (isset($shaperent['disabled'])) {
|
219
|
$dis = "_d";
|
220
|
$textss = "<span class=\"gray\">";
|
221
|
$textse = "</span>";
|
222
|
} else {
|
223
|
$textss = $textse = "";
|
224
|
}
|
225
|
$iflabels = array('lan' => 'LAN', 'wan' => 'WAN', 'pptp' => 'PPTP');
|
226
|
for ($j = 1; isset($config['interfaces']['opt' . $j]); $j++)
|
227
|
$iflabels['opt' . $j] = $config['interfaces']['opt' . $j]['descr'];
|
228
|
echo $textss . htmlspecialchars($iflabels[$shaperent['interface']]);
|
229
|
echo "<br>";
|
230
|
echo "<a href=\"?act=toggle&id={$i}\">";
|
231
|
if ($shaperent['direction'] != "in")
|
232
|
echo "<img src=\"out{$dis}.gif\" width=\"11\" height=\"11\" border=\"0\" style=\"margin-top: 5px\" title=\"click to toggle enabled/disabled status\">";
|
233
|
if ($shaperent['direction'] != "out")
|
234
|
echo "<img src=\"in{$dis}.gif\" width=\"11\" height=\"11\" border=\"0\" style=\"margin-top: 5px\" title=\"click to toggle enabled/disabled status\">";
|
235
|
echo "</a>" . $textse;;
|
236
|
?>
|
237
|
</td>
|
238
|
<td class="listr" onClick="fr_toggle(<?=$nrules;?>)" id="frd<?=$nrules;?>">
|
239
|
<?=$textss;?><?php if (isset($shaperent['protocol'])) echo strtoupper($shaperent['protocol']); else echo "*"; ?><?=$textse;?>
|
240
|
</td>
|
241
|
<td class="listr" onClick="fr_toggle(<?=$nrules;?>)" id="frd<?=$nrules;?>"><?=$textss;?><?php echo htmlspecialchars(pprint_address($shaperent['source'])); ?>
|
242
|
<?php if ($shaperent['source']['port']): ?><br>
|
243
|
Port: <?=htmlspecialchars(pprint_port($shaperent['source']['port'])); ?>
|
244
|
<?php endif; ?><?=$textse;?>
|
245
|
</td>
|
246
|
<td class="listr" onClick="fr_toggle(<?=$nrules;?>)" id="frd<?=$nrules;?>"><?=$textss;?><?php echo htmlspecialchars(pprint_address($shaperent['destination'])); ?>
|
247
|
<?php if ($shaperent['destination']['port']): ?><br>
|
248
|
Port: <?=htmlspecialchars(pprint_port($shaperent['destination']['port'])); ?>
|
249
|
<?php endif; ?><?=$textse;?>
|
250
|
</td>
|
251
|
<td class="listr" onClick="fr_toggle(<?=$nrules;?>)" id="frd<?=$nrules;?>"><?=$textss;?>
|
252
|
<?php
|
253
|
if (isset($shaperent['targetqueue'])) {
|
254
|
$desc = htmlspecialchars($shaperent['targetqueue']);
|
255
|
echo "<a href=\"firewall_shaper_queues_edit.php?id={$shaperent['targetqueue']}\">{$desc}</a>";
|
256
|
}
|
257
|
?><?=$textse;?>
|
258
|
</td>
|
259
|
<td class="listbg"><font color="white">
|
260
|
<?=$textss;?><?=htmlspecialchars($shaperent['descr']);?><?=$textse;?>
|
261
|
</td>
|
262
|
<td valign="middle" nowrap class="list"> <a href="firewall_shaper_edit.php?id=<?=$i;?>"><img src="e.gif" title="edit rule" width="17" height="17" border="0"></a>
|
263
|
<?php if ($i > 0): ?>
|
264
|
<a href="firewall_shaper.php?act=up&id=<?=$i;?>"><img src="up.gif" title="move up" width="17" height="17" border="0"></a>
|
265
|
<?php else: ?>
|
266
|
<img src="up_d.gif" width="17" height="17" border="0">
|
267
|
<?php endif; ?>
|
268
|
<input name="move_<?=$i;?>" type="image" src="left.gif" width="17" height="17" title="move selected rules before this rule" onMouseOver="fr_insline(<?=$nrules;?>, true)" onMouseOut="fr_insline(<?=$nrules;?>, false)"><br>
|
269
|
<a href="firewall_shaper.php?act=del&id=<?=$i;?>" onclick="return confirm('Do you really want to delete this rule?')"><img src="x.gif" title="delete rule" width="17" height="17" border="0"></a>
|
270
|
<?php if (isset($a_shaper[$i+1])): ?>
|
271
|
<a href="firewall_shaper.php?act=down&id=<?=$i;?>"><img src="down.gif" title="move down" width="17" height="17" border="0"></a>
|
272
|
<?php else: ?>
|
273
|
<img src="down_d.gif" width="17" height="17" border="0">
|
274
|
<?php endif; ?>
|
275
|
<a href="firewall_shaper_edit.php?dup=<?=$i;?>"><img src="plus.gif" title="add a new rule based on this one" width="17" height="17" border="0"></a>
|
276
|
</td>
|
277
|
</tr>
|
278
|
<?php $nrules++; $i++; endforeach; ?>
|
279
|
<tr>
|
280
|
<td class="list" colspan="8"></td>
|
281
|
<td class="list"> <a href="firewall_shaper_edit.php"><img src="plus.gif" width="17" height="17" border="0"></a></td>
|
282
|
</tr>
|
283
|
</table>
|
284
|
|
285
|
<table border="0" cellspacing="0" cellpadding="0">
|
286
|
<tr>
|
287
|
<td width="16"><img src="in.gif" width="11" height="11"></td>
|
288
|
<td>incoming (as seen by firewall)</td>
|
289
|
<td width="14"></td>
|
290
|
<td width="16"><img src="out.gif" width="11" height="11"></td>
|
291
|
<td>outgoing (as seen by firewall)</td>
|
292
|
</tr>
|
293
|
<tr>
|
294
|
<td colspan="5" height="4"></td>
|
295
|
</tr>
|
296
|
<tr>
|
297
|
<td><img src="in_d.gif" width="11" height="11"></td>
|
298
|
<td>incoming (disabled)</td>
|
299
|
<td width="14"></td>
|
300
|
<td><img src="out_d.gif" width="11" height="11"></td>
|
301
|
<td>outgoing (disabled)</td>
|
302
|
</tr>
|
303
|
</table>
|
304
|
<p><span class="red"><strong>Note:</strong></span><strong><br>
|
305
|
</strong>the first rule that matches a packet will be executed.<br>
|
306
|
The following match patterns are not shown in the list above:
|
307
|
IP packet length, TCP flags.</td>
|
308
|
</tr>
|
309
|
</table>
|
310
|
</form>
|
311
|
<?php include("fend.inc"); ?>
|
312
|
</body>
|
313
|
</html>
|