1
|
#!/usr/local/bin/php
|
2
|
<?php
|
3
|
/*
|
4
|
firewall_rules.php
|
5
|
part of m0n0wall (http://m0n0.ch/wall)
|
6
|
|
7
|
Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
|
8
|
All rights reserved.
|
9
|
|
10
|
Redistribution and use in source and binary forms, with or without
|
11
|
modification, are permitted provided that the following conditions are met:
|
12
|
|
13
|
1. Redistributions of source code must retain the above copyright notice,
|
14
|
this list of conditions and the following disclaimer.
|
15
|
|
16
|
2. Redistributions in binary form must reproduce the above copyright
|
17
|
notice, this list of conditions and the following disclaimer in the
|
18
|
documentation and/or other materials provided with the distribution.
|
19
|
|
20
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
21
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
22
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
23
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
24
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
25
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
26
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
27
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
28
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
29
|
POSSIBILITY OF SUCH DAMAGE.
|
30
|
*/
|
31
|
|
32
|
require("guiconfig.inc");
|
33
|
|
34
|
if (!is_array($config['filter']['rule'])) {
|
35
|
$config['filter']['rule'] = array();
|
36
|
}
|
37
|
filter_rules_sort();
|
38
|
$a_filter = &$config['filter']['rule'];
|
39
|
|
40
|
if ($_POST) {
|
41
|
|
42
|
$pconfig = $_POST;
|
43
|
|
44
|
if ($_POST['apply']) {
|
45
|
$retval = 0;
|
46
|
if (!file_exists($d_sysrebootreqd_path)) {
|
47
|
config_lock();
|
48
|
$retval = filter_configure();
|
49
|
config_unlock();
|
50
|
}
|
51
|
$savemsg = get_std_save_message($retval);
|
52
|
if ($retval == 0) {
|
53
|
if (file_exists($d_natconfdirty_path))
|
54
|
unlink($d_natconfdirty_path);
|
55
|
if (file_exists($d_filterconfdirty_path))
|
56
|
unlink($d_filterconfdirty_path);
|
57
|
}
|
58
|
}
|
59
|
}
|
60
|
|
61
|
if ($_GET['act'] == "del") {
|
62
|
if ($a_filter[$_GET['id']]) {
|
63
|
unset($a_filter[$_GET['id']]);
|
64
|
write_config();
|
65
|
touch($d_filterconfdirty_path);
|
66
|
header("Location: firewall_rules.php");
|
67
|
exit;
|
68
|
}
|
69
|
} else if ($_GET['act'] == "down") {
|
70
|
if ($a_filter[$_GET['id']] && $a_filter[$_GET['id']+1]) {
|
71
|
$tmp = $a_filter[$_GET['id']+1];
|
72
|
$a_filter[$_GET['id']+1] = $a_filter[$_GET['id']];
|
73
|
$a_filter[$_GET['id']] = $tmp;
|
74
|
write_config();
|
75
|
touch($d_filterconfdirty_path);
|
76
|
header("Location: firewall_rules.php");
|
77
|
exit;
|
78
|
}
|
79
|
} else if ($_GET['act'] == "up") {
|
80
|
if (($_GET['id'] > 0) && $a_filter[$_GET['id']]) {
|
81
|
$tmp = $a_filter[$_GET['id']-1];
|
82
|
$a_filter[$_GET['id']-1] = $a_filter[$_GET['id']];
|
83
|
$a_filter[$_GET['id']] = $tmp;
|
84
|
write_config();
|
85
|
touch($d_filterconfdirty_path);
|
86
|
header("Location: firewall_rules.php");
|
87
|
exit;
|
88
|
}
|
89
|
} else if ($_GET['act'] == "toggle") {
|
90
|
if ($a_filter[$_GET['id']]) {
|
91
|
$a_filter[$_GET['id']]['disabled'] = !isset($a_filter[$_GET['id']]['disabled']);
|
92
|
write_config();
|
93
|
touch($d_filterconfdirty_path);
|
94
|
header("Location: firewall_rules.php");
|
95
|
exit;
|
96
|
}
|
97
|
}
|
98
|
|
99
|
?>
|
100
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
101
|
<html>
|
102
|
<head>
|
103
|
<title><?=gentitle("Firewall: Rules");?></title>
|
104
|
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
105
|
<link href="gui.css" rel="stylesheet" type="text/css">
|
106
|
</head>
|
107
|
|
108
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
|
109
|
<?php include("fbegin.inc"); ?>
|
110
|
<p class="pgtitle">Firewall: Rules</p>
|
111
|
<form action="firewall_rules.php" method="post">
|
112
|
<?php if ($savemsg) print_info_box($savemsg); ?>
|
113
|
<?php if (file_exists($d_filterconfdirty_path)): ?><p>
|
114
|
<?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>
|
115
|
<input name="apply" type="submit" class="formbtn" id="apply" value="Apply changes"></p>
|
116
|
<?php endif; ?>
|
117
|
<table width="100%" border="0" cellpadding="0" cellspacing="0">
|
118
|
|
119
|
<tr><td colspan="9">
|
120
|
<ul id="tabnav">
|
121
|
<li class="tabact">Rules</li>
|
122
|
<li class="tabinact"><a href="firewall_shaper_queues.php">Queues</a></li>
|
123
|
</ul>
|
124
|
</td></tr>
|
125
|
<tr>
|
126
|
<td class="tabcont">
|
127
|
<table width="100%" border="0" cellpadding="0" cellspacing="0">
|
128
|
|
129
|
<?php $lastif = ""; for ($i = 0; isset($a_filter[$i]); $i++):
|
130
|
$filterent = $a_filter[$i];
|
131
|
if ($filterent['interface'] != $lastif):
|
132
|
if ($i):
|
133
|
?>
|
134
|
|
135
|
<tr>
|
136
|
<td colspan="8" class="list" height="12"></td>
|
137
|
</tr>
|
138
|
<?php endif; ?>
|
139
|
<tr>
|
140
|
<td colspan="7" class="listtopic"><?php
|
141
|
$iflabels = array('lan' => 'LAN interface', 'wan' => 'WAN interface', 'pptp' => 'PPTP clients');
|
142
|
for ($j = 1; isset($config['interfaces']['opt' . $j]); $j++)
|
143
|
$iflabels['opt' . $j] = $config['interfaces']['opt' . $j]['name'] . " interface";
|
144
|
echo htmlspecialchars($iflabels[$filterent['interface']]); ?></td>
|
145
|
<td class="list"></td>
|
146
|
</tr>
|
147
|
<tr>
|
148
|
<td width="5%" class="list"> </td>
|
149
|
<td width="10%" class="listhdrr">Proto</td>
|
150
|
<td width="15%" class="listhdrr">Source</td>
|
151
|
<td width="10%" class="listhdrr">Port</td>
|
152
|
<td width="15%" class="listhdrr">Destination</td>
|
153
|
<td width="10%" class="listhdrr">Port</td>
|
154
|
<td width="25%" class="listhdr">Description</td>
|
155
|
<td width="10%" class="list"></td>
|
156
|
</tr>
|
157
|
<?php $lastif = $filterent['interface']; endif; ?>
|
158
|
<tr valign="top">
|
159
|
<td class="listt">
|
160
|
<?php if ($filterent['type'] == "block")
|
161
|
$iconfn = "block";
|
162
|
else if ($filterent['type'] == "reject") {
|
163
|
if ($filterent['protocol'] == "tcp" || $filterent['protocol'] == "udp")
|
164
|
$iconfn = "reject";
|
165
|
else
|
166
|
$iconfn = "block";
|
167
|
} else
|
168
|
$iconfn = "pass";
|
169
|
if (isset($filterent['disabled'])) {
|
170
|
$textss = "<span class=\"gray\">";
|
171
|
$textse = "</span>";
|
172
|
$iconfn .= "_d";
|
173
|
} else {
|
174
|
$textss = $textse = "";
|
175
|
}
|
176
|
?>
|
177
|
<a href="?act=toggle&id=<?=$i;?>"><img src="<?=$iconfn;?>.gif" width="11" height="11" border="0" title="click to toggle enabled/disabled status"></a>
|
178
|
<?php if (isset($filterent['log'])):
|
179
|
$iconfn = "log_s";
|
180
|
if (isset($filterent['disabled']))
|
181
|
$iconfn .= "_d";
|
182
|
?>
|
183
|
<br><img src="<?=$iconfn;?>.gif" width="11" height="15" border="0">
|
184
|
<?php endif; ?>
|
185
|
</td>
|
186
|
<td class="listlr">
|
187
|
<?=$textss;?><?php if (isset($filterent['protocol'])) echo strtoupper($filterent['protocol']); else echo "*"; ?><?=$textse;?>
|
188
|
</td>
|
189
|
<td class="listr">
|
190
|
<?=$textss;?><?php echo htmlspecialchars(pprint_address($filterent['source'])); ?><?=$textse;?>
|
191
|
</td>
|
192
|
<td class="listr">
|
193
|
<?=$textss;?><?php echo htmlspecialchars(pprint_port($filterent['source']['port'])); ?><?=$textse;?>
|
194
|
</td>
|
195
|
<td class="listr">
|
196
|
<?=$textss;?><?php echo htmlspecialchars(pprint_address($filterent['destination'])); ?><?=$textse;?>
|
197
|
</td>
|
198
|
<td class="listr">
|
199
|
<?=$textss;?><?php echo htmlspecialchars(pprint_port($filterent['destination']['port'])); ?><?=$textse;?>
|
200
|
</td>
|
201
|
<td class="listbg">
|
202
|
<?=$textss;?><?=htmlspecialchars($filterent['descr']);?> <?=$textse;?>
|
203
|
</td>
|
204
|
<td valign="middle" nowrap class="list">
|
205
|
<a href="firewall_rules_edit.php?id=<?=$i;?>"><img src="e.gif" title="edit rule" width="17" height="17" border="0"></a>
|
206
|
<?php if (($i > 0) && ($a_filter[$i-1]['interface'] == $filterent['interface'])): ?>
|
207
|
<a href="firewall_rules.php?act=up&id=<?=$i;?>"><img src="up.gif" title="move up" width="17" height="17" border="0"></a>
|
208
|
<?php else: ?>
|
209
|
<img src="up_d.gif" width="17" height="17" border="0">
|
210
|
<?php endif; ?><br>
|
211
|
<a href="firewall_rules.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>
|
212
|
<?php if ($a_filter[$i+1]['interface'] == $filterent['interface']): ?>
|
213
|
<a href="firewall_rules.php?act=down&id=<?=$i;?>"><img src="down.gif" title="move down" width="17" height="17" border="0"></a>
|
214
|
<?php else: ?>
|
215
|
<img src="down_d.gif" width="17" height="17" border="0">
|
216
|
<?php endif; ?>
|
217
|
<a href="firewall_rules_edit.php?dup=<?=$i;?>"><img src="plus.gif" title="add a new rule based on this one" width="17" height="17" border="0"></a>
|
218
|
</td>
|
219
|
</tr>
|
220
|
<?php endfor; ?>
|
221
|
<tr>
|
222
|
<td class="list" colspan="7"></td>
|
223
|
<td class="list"> <a href="firewall_rules_edit.php"><img src="plus.gif" title="add new rule" width="17" height="17" border="0"></a></td>
|
224
|
</tr>
|
225
|
</table>
|
226
|
<table border="0" cellspacing="0" cellpadding="0">
|
227
|
<tr>
|
228
|
<td width="16"><img src="pass.gif" width="11" height="11"></td>
|
229
|
<td>pass</td>
|
230
|
<td width="14"></td>
|
231
|
<td width="16"><img src="block.gif" width="11" height="11"></td>
|
232
|
<td>block</td>
|
233
|
<td width="14"></td>
|
234
|
<td width="16"><img src="reject.gif" width="11" height="11"></td>
|
235
|
<td>reject</td>
|
236
|
<td width="14"></td>
|
237
|
<td width="16"><img src="log.gif" width="11" height="11"></td>
|
238
|
<td>log</td>
|
239
|
</tr>
|
240
|
<tr>
|
241
|
<td colspan="5" height="4"></td>
|
242
|
</tr>
|
243
|
<tr>
|
244
|
<td><img src="pass_d.gif" width="11" height="11"></td>
|
245
|
<td>pass (disabled)</td>
|
246
|
<td></td>
|
247
|
<td><img src="block_d.gif" width="11" height="11"></td>
|
248
|
<td>block (disabled)</td>
|
249
|
<td></td>
|
250
|
<td><img src="reject_d.gif" width="11" height="11"></td>
|
251
|
<td>reject (disabled)</td>
|
252
|
<td></td>
|
253
|
<td width="16"><img src="log_d.gif" width="11" height="11"></td>
|
254
|
<td>log (disabled)</td>
|
255
|
</tr>
|
256
|
</table>
|
257
|
</tr></table>
|
258
|
<p>
|
259
|
<strong><span class="red">Hint:<br>
|
260
|
</span></strong>rules are evaluated on a first-match basis (i.e.
|
261
|
the action of the first rule to match a packet will be executed).
|
262
|
This means that if you use block rules, you'll have to pay attention
|
263
|
to the rule order. Everything that isn't explicitly passed is blocked
|
264
|
by default.</p>
|
265
|
</form>
|
266
|
<?php include("fend.inc"); ?>
|
267
|
</body>
|
268
|
</html>
|