1
|
#!/usr/local/bin/php
|
2
|
<?php
|
3
|
/* $Id$ */
|
4
|
/*
|
5
|
firewall_rules.php
|
6
|
part of pfSense (http://www.pfsense.com)
|
7
|
Copyright (C) 2005 Scott Ullrich (sullrich@gmail.com)
|
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
|
$pgtitle = array("Firewall", "Rules");
|
36
|
require("guiconfig.inc");
|
37
|
|
38
|
if (!is_array($config['filter']['rule'])) {
|
39
|
$config['filter']['rule'] = array();
|
40
|
}
|
41
|
filter_rules_sort();
|
42
|
$a_filter = &$config['filter']['rule'];
|
43
|
|
44
|
$if = $_GET['if'];
|
45
|
if ($_POST['if'])
|
46
|
$if = $_POST['if'];
|
47
|
|
48
|
$iflist = array("lan" => "LAN", "wan" => "WAN");
|
49
|
|
50
|
if ($config['pptpd']['mode'] == "server")
|
51
|
$iflist['pptp'] = "PPTP VPN";
|
52
|
|
53
|
if ($config['pppoe']['mode'] == "server")
|
54
|
$iflist['pppoe'] = "PPPoE VPN";
|
55
|
|
56
|
for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) {
|
57
|
$iflist['opt' . $i] = $config['interfaces']['opt' . $i]['descr'];
|
58
|
}
|
59
|
|
60
|
if (!$if || !isset($iflist[$if]))
|
61
|
$if = "wan";
|
62
|
|
63
|
if ($_POST) {
|
64
|
|
65
|
$pconfig = $_POST;
|
66
|
|
67
|
if ($_POST['apply']) {
|
68
|
$retval = 0;
|
69
|
config_lock();
|
70
|
$retval = filter_configure();
|
71
|
config_unlock();
|
72
|
|
73
|
if (file_exists($d_filterconfdirty_path))
|
74
|
unlink($d_filterconfdirty_path);
|
75
|
|
76
|
$savemsg = "The settings have been applied";
|
77
|
}
|
78
|
}
|
79
|
|
80
|
if (isset($_POST['del_x'])) {
|
81
|
/* delete selected rules */
|
82
|
if (is_array($_POST['rule']) && count($_POST['rule'])) {
|
83
|
foreach ($_POST['rule'] as $rulei) {
|
84
|
unset($a_filter[$rulei]);
|
85
|
}
|
86
|
write_config();
|
87
|
touch($d_filterconfdirty_path);
|
88
|
header("Location: firewall_rules.php?if={$if}");
|
89
|
exit;
|
90
|
}
|
91
|
} else if ($_GET['act'] == "toggle") {
|
92
|
if ($a_filter[$_GET['id']]) {
|
93
|
if(isset($a_filter[$_GET['id']]['disabled']))
|
94
|
unset($a_filter[$_GET['id']]['disabled']);
|
95
|
else
|
96
|
$a_filter[$_GET['id']]['disabled'] = true;
|
97
|
write_config();
|
98
|
touch($d_filterconfdirty_path);
|
99
|
header("Location: firewall_rules.php?if={$if}");
|
100
|
exit;
|
101
|
}
|
102
|
} else {
|
103
|
/* yuck - IE won't send value attributes for image buttons, while Mozilla does -
|
104
|
so we use .x/.y to fine move button clicks instead... */
|
105
|
unset($movebtn);
|
106
|
foreach ($_POST as $pn => $pd) {
|
107
|
if (preg_match("/move_(\d+)_x/", $pn, $matches)) {
|
108
|
$movebtn = $matches[1];
|
109
|
break;
|
110
|
}
|
111
|
}
|
112
|
/* move selected rules before this rule */
|
113
|
if (isset($movebtn) && is_array($_POST['rule']) && count($_POST['rule'])) {
|
114
|
$a_filter_new = array();
|
115
|
|
116
|
/* copy all rules < $movebtn and not selected */
|
117
|
for ($i = 0; $i < $movebtn; $i++) {
|
118
|
if (!in_array($i, $_POST['rule']))
|
119
|
$a_filter_new[] = $a_filter[$i];
|
120
|
}
|
121
|
|
122
|
/* copy all selected rules */
|
123
|
for ($i = 0; $i < count($a_filter); $i++) {
|
124
|
if ($i == $movebtn)
|
125
|
continue;
|
126
|
if (in_array($i, $_POST['rule']))
|
127
|
$a_filter_new[] = $a_filter[$i];
|
128
|
}
|
129
|
|
130
|
/* copy $movebtn rule */
|
131
|
if ($movebtn < count($a_filter))
|
132
|
$a_filter_new[] = $a_filter[$movebtn];
|
133
|
|
134
|
/* copy all rules > $movebtn and not selected */
|
135
|
for ($i = $movebtn+1; $i < count($a_filter); $i++) {
|
136
|
if (!in_array($i, $_POST['rule']))
|
137
|
$a_filter_new[] = $a_filter[$i];
|
138
|
}
|
139
|
|
140
|
$a_filter = $a_filter_new;
|
141
|
write_config();
|
142
|
touch($d_filterconfdirty_path);
|
143
|
header("Location: firewall_rules.php?if={$if}");
|
144
|
exit;
|
145
|
}
|
146
|
}
|
147
|
|
148
|
$pgtitle = "Firewall: Rules";
|
149
|
include("head.inc");
|
150
|
|
151
|
?>
|
152
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
|
153
|
<?php include("fbegin.inc"); ?>
|
154
|
<p class="pgtitle"><?=$pgtitle?></p>
|
155
|
<form action="firewall_rules.php" method="post">
|
156
|
<script type="text/javascript" language="javascript" src="row_toggle.js">
|
157
|
</script>
|
158
|
<?php if ($savemsg) print_info_box($savemsg); ?>
|
159
|
<?php if (file_exists($d_filterconfdirty_path)): ?><p>
|
160
|
<?php print_info_box_np("The firewall rule configuration has been changed.<br>You must apply the changes in order for them to take effect.");?><br>
|
161
|
<?php endif; ?>
|
162
|
<table width="100%" border="0" cellpadding="0" cellspacing="0">
|
163
|
<tr><td class="tabnavtbl">
|
164
|
<?php
|
165
|
/* active tabs */
|
166
|
$tab_array = array();
|
167
|
$tabscounter = 0; $i = 0; foreach ($iflist as $ifent => $ifname) {
|
168
|
if ($ifent == $if)
|
169
|
$active = true;
|
170
|
else
|
171
|
$active = false;
|
172
|
$tab_array[] = array($ifname, $active, "firewall_rules.php?if={$ifent}");
|
173
|
}
|
174
|
display_top_tabs($tab_array);
|
175
|
?>
|
176
|
</td></tr>
|
177
|
<tr>
|
178
|
<td>
|
179
|
<div id="mainarea">
|
180
|
<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
|
181
|
<tr id="frheader">
|
182
|
<td width="3%" class="list"> </td>
|
183
|
<td width="5%" class="list"> </td>
|
184
|
<td width="10%" class="listhdrr">Proto</td>
|
185
|
<td width="15%" class="listhdrr">Source</td>
|
186
|
<td width="10%" class="listhdrr">Port</td>
|
187
|
<td width="15%" class="listhdrr">Destination</td>
|
188
|
<td width="10%" class="listhdrr">Port</td>
|
189
|
<td width="22%" class="listhdr">Description</td>
|
190
|
<td width="10%" class="list"></td>
|
191
|
</tr>
|
192
|
<?php $nrules = 0; for ($i = 0; isset($a_filter[$i]); $i++):
|
193
|
$filterent = $a_filter[$i];
|
194
|
if ($filterent['interface'] != $if)
|
195
|
continue;
|
196
|
?>
|
197
|
<tr valign="top" id="fr<?=$nrules;?>">
|
198
|
<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>
|
199
|
<td class="listt" align="center">
|
200
|
<?php if ($filterent['type'] == "block")
|
201
|
$iconfn = "block";
|
202
|
else if ($filterent['type'] == "reject") {
|
203
|
if ($filterent['protocol'] == "tcp" || $filterent['protocol'] == "udp")
|
204
|
$iconfn = "reject";
|
205
|
else
|
206
|
$iconfn = "block";
|
207
|
} else
|
208
|
$iconfn = "pass";
|
209
|
if (isset($filterent['disabled'])) {
|
210
|
$textss = "<span class=\"gray\">";
|
211
|
$textse = "</span>";
|
212
|
$iconfn .= "_d";
|
213
|
} else {
|
214
|
$textss = $textse = "";
|
215
|
}
|
216
|
?>
|
217
|
<a href="?if=<?=$if;?>&act=toggle&id=<?=$i;?>"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_<?=$iconfn;?>.gif" width="11" height="11" border="0" title="click to toggle enabled/disabled status"></a>
|
218
|
<?php if (isset($filterent['log'])):
|
219
|
$iconfn = "log_s";
|
220
|
if (isset($filterent['disabled']))
|
221
|
$iconfn .= "_d";
|
222
|
?>
|
223
|
<br><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_<?=$iconfn;?>.gif" width="11" height="15" border="0">
|
224
|
<?php endif; ?>
|
225
|
</td>
|
226
|
<td class="listlr" onClick="fr_toggle(<?=$nrules;?>)" id="frd<?=$nrules;?>" ondblclick="document.location='firewall_rules_edit.php?id=<?=$i;?>';">
|
227
|
<?=$textss;?><?php if (isset($filterent['protocol'])) echo strtoupper($filterent['protocol']); else echo "*"; ?><?=$textse;?>
|
228
|
</td>
|
229
|
<td class="listr" onClick="fr_toggle(<?=$nrules;?>)" id="frd<?=$nrules;?>" ondblclick="document.location='firewall_rules_edit.php?id=<?=$i;?>';">
|
230
|
<?=$textss;?><?php echo htmlspecialchars(pprint_address($filterent['source'])); ?><?=$textse;?>
|
231
|
</td>
|
232
|
<td class="listr" onClick="fr_toggle(<?=$nrules;?>)" id="frd<?=$nrules;?>" ondblclick="document.location='firewall_rules_edit.php?id=<?=$i;?>';">
|
233
|
<?=$textss;?><?php echo htmlspecialchars(pprint_port($filterent['source']['port'])); ?><?=$textse;?>
|
234
|
</td>
|
235
|
<td class="listr" onClick="fr_toggle(<?=$nrules;?>)" id="frd<?=$nrules;?>" ondblclick="document.location='firewall_rules_edit.php?id=<?=$i;?>';">
|
236
|
<?=$textss;?><?php echo htmlspecialchars(pprint_address($filterent['destination'])); ?><?=$textse;?>
|
237
|
</td>
|
238
|
<td class="listr" onClick="fr_toggle(<?=$nrules;?>)" id="frd<?=$nrules;?>" ondblclick="document.location='firewall_rules_edit.php?id=<?=$i;?>';">
|
239
|
<?=$textss;?><?php echo htmlspecialchars(pprint_port($filterent['destination']['port'])); ?><?=$textse;?>
|
240
|
</td>
|
241
|
<td class="listbg" onClick="fr_toggle(<?=$nrules;?>)" ondblclick="document.location='firewall_rules_edit.php?id=<?=$i;?>';" bcolor="#990000"><font color="white">
|
242
|
<?=$textss;?><?=htmlspecialchars($filterent['descr']);?> <?=$textse;?>
|
243
|
</td>
|
244
|
<td valign="middle" nowrap class="list">
|
245
|
<table border="0" cellspacing="0" cellpadding="1">
|
246
|
<tr>
|
247
|
<td><input name="move_<?=$i;?>" type="image" src="./themes/<?= $g['theme']; ?>/images/icons/icon_left.gif" width="17" height="17" title="move selected rules before this rule" onMouseOver="fr_insline(<?=$nrules;?>, true)" onMouseOut="fr_insline(<?=$nrules;?>, false)"></td>
|
248
|
<td><a href="firewall_rules_edit.php?id=<?=$i;?>"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_e.gif" title="edit rule" width="17" height="17" border="0"></a></td>
|
249
|
</tr>
|
250
|
<tr>
|
251
|
<td align="center" valign="middle"></td>
|
252
|
<td><a href="firewall_rules_edit.php?dup=<?=$i;?>"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" title="add a new rule based on this one" width="17" height="17" border="0"></a></td>
|
253
|
</tr>
|
254
|
</table>
|
255
|
</td>
|
256
|
</tr>
|
257
|
<?php $nrules++; endfor; ?>
|
258
|
<?php if ($nrules == 0): ?>
|
259
|
<td class="listt"></td>
|
260
|
<td class="listt"></td>
|
261
|
<td class="listlr" colspan="6" align="center" valign="middle">
|
262
|
<span class="gray">
|
263
|
No rules are currently defined for this interface.<br>
|
264
|
All incoming connections on this interface will be blocked until you add pass rules.<br><br>
|
265
|
Click the <a href="firewall_rules_edit.php?if=<?=$if;?>"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" title="add new rule" border="0" width="17" height="17" align="absmiddle"></a> button to add a new rule.</span>
|
266
|
</td>
|
267
|
<?php endif; ?>
|
268
|
<tr id="fr<?=$nrules;?>">
|
269
|
<td class="list"></td>
|
270
|
<td class="list"></td>
|
271
|
<td class="list"> </td>
|
272
|
<td class="list"> </td>
|
273
|
<td class="list"> </td>
|
274
|
<td class="list"> </td>
|
275
|
<td class="list"> </td>
|
276
|
<td class="list"> </td>
|
277
|
<td class="list">
|
278
|
<table border="0" cellspacing="0" cellpadding="1">
|
279
|
<tr>
|
280
|
<td>
|
281
|
<?php if ($nrules == 0): ?><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_left_d.gif" width="17" height="17" title="move selected rules to end" border="0"><?php else: ?><input name="move_<?=$i;?>" type="image" src="./themes/<?= $g['theme']; ?>/images/icons/icon_left.gif" width="17" height="17" title="move selected rules to end" onMouseOver="fr_insline(<?=$nrules;?>, true)" onMouseOut="fr_insline(<?=$nrules;?>, false)"><?php endif; ?></td>
|
282
|
<td></td>
|
283
|
</tr>
|
284
|
<tr>
|
285
|
<td><?php if ($nrules == 0): ?><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_x_d.gif" width="17" height="17" title="delete selected rules" border="0"><?php else: ?><input name="del" type="image" src="./themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" width="17" height="17" title="delete selected rules" onclick="return confirm('Do you really want to delete the selected rules?')"><?php endif; ?></td>
|
286
|
<td><a href="firewall_rules_edit.php?if=<?=$if;?>"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" title="add new rule" width="17" height="17" border="0"></a></td>
|
287
|
</tr>
|
288
|
</table>
|
289
|
</td>
|
290
|
</tr>
|
291
|
</table>
|
292
|
<table class="tabcont" width="100%" border="0" cellspacing="0" cellpadding="0">
|
293
|
<tr>
|
294
|
<td width="16"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_pass.gif" width="11" height="11"></td>
|
295
|
<td>pass</td>
|
296
|
<td width="14"></td>
|
297
|
<td width="16"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_block.gif" width="11" height="11"></td>
|
298
|
<td>block</td>
|
299
|
<td width="14"></td>
|
300
|
<td width="16"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_reject.gif" width="11" height="11"></td>
|
301
|
<td>reject</td>
|
302
|
<td width="14"></td>
|
303
|
<td width="16"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_log.gif" width="11" height="11"></td>
|
304
|
<td>log</td>
|
305
|
</tr>
|
306
|
<tr>
|
307
|
<td><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_pass_d.gif" width="11" height="11"></td>
|
308
|
<td nowrap>pass (disabled)</td>
|
309
|
<td> </td>
|
310
|
<td><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_block_d.gif" width="11" height="11"></td>
|
311
|
<td nowrap>block (disabled)</td>
|
312
|
<td> </td>
|
313
|
<td><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_reject_d.gif" width="11" height="11"></td>
|
314
|
<td nowrap>reject (disabled)</td>
|
315
|
<td> </td>
|
316
|
<td width="16"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_log_d.gif" width="11" height="11"></td>
|
317
|
<td nowrap>log (disabled)</td>
|
318
|
</tr>
|
319
|
<tr>
|
320
|
<td colspan="9">
|
321
|
<p>
|
322
|
<strong><span class="red">Hint:<br>
|
323
|
</span></strong>Rules are evaluated on a first-match basis (i.e.
|
324
|
the action of the first rule to match a packet will be executed).
|
325
|
This means that if you use block rules, you'll have to pay attention
|
326
|
to the rule order. Everything that isn't explicitly passed is blocked
|
327
|
by default.</p>
|
328
|
</td>
|
329
|
</tr>
|
330
|
</table>
|
331
|
</div>
|
332
|
</td>
|
333
|
</tr>
|
334
|
</table>
|
335
|
<input type="hidden" name="if" value="<?=$if;?>">
|
336
|
</form>
|
337
|
<?php include("fend.inc"); ?>
|
338
|
</body>
|
339
|
</html>
|