Project

General

Profile

Download (13.8 KB) Statistics
| Branch: | Tag: | Revision:
1 5b237745 Scott Ullrich
#!/usr/local/bin/php
2 b2ffe419 Scott Ullrich
<?php
3 b46bfcf5 Bill Marquette
/* $Id$ */
4 5b237745 Scott Ullrich
/*
5 37e2071c Scott Ullrich
	firewall_rules.php
6
	part of m0n0wall (http://m0n0.ch/wall)
7 b2ffe419 Scott Ullrich
8 37e2071c Scott Ullrich
	Copyright (C) 2003-2005 Manuel Kasper <mk@neon1.net>.
9
	All rights reserved.
10 b2ffe419 Scott Ullrich
11 37e2071c Scott Ullrich
	Redistribution and use in source and binary forms, with or without
12
	modification, are permitted provided that the following conditions are met:
13 b2ffe419 Scott Ullrich
14 37e2071c Scott Ullrich
	1. Redistributions of source code must retain the above copyright notice,
15
	   this list of conditions and the following disclaimer.
16 b2ffe419 Scott Ullrich
17 37e2071c Scott Ullrich
	2. Redistributions in binary form must reproduce the above copyright
18
	   notice, this list of conditions and the following disclaimer in the
19
	   documentation and/or other materials provided with the distribution.
20 b2ffe419 Scott Ullrich
21 37e2071c Scott Ullrich
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
22
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
23
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
25
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30
	POSSIBILITY OF SUCH DAMAGE.
31 5b237745 Scott Ullrich
*/
32
33 37e2071c Scott Ullrich
$pgtitle = array("Firewall", "Rules");
34 5b237745 Scott Ullrich
require("guiconfig.inc");
35
36
if (!is_array($config['filter']['rule'])) {
37
	$config['filter']['rule'] = array();
38
}
39
filter_rules_sort();
40
$a_filter = &$config['filter']['rule'];
41
42 07bd3f83 Scott Ullrich
$if = $_GET['if'];
43
if ($_POST['if'])
44
	$if = $_POST['if'];
45 b2ffe419 Scott Ullrich
46 07bd3f83 Scott Ullrich
$iflist = array("lan" => "LAN", "wan" => "WAN");
47
48
if ($config['pptpd']['mode'] == "server")
49
	$iflist['pptp'] = "PPTP VPN";
50
51
for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) {
52
	$iflist['opt' . $i] = $config['interfaces']['opt' . $i]['descr'];
53
}
54
55
if (!$if || !isset($iflist[$if]))
56 37e2071c Scott Ullrich
	$if = "wan";
57 07bd3f83 Scott Ullrich
58 5b237745 Scott Ullrich
if ($_POST) {
59
60
	$pconfig = $_POST;
61
62
	if ($_POST['apply']) {
63 37e2071c Scott Ullrich
		$retval = 0;
64 5b237745 Scott Ullrich
		if (!file_exists($d_sysrebootreqd_path)) {
65
			config_lock();
66
			$retval = filter_configure();
67
			config_unlock();
68
		}
69 37e2071c Scott Ullrich
		$savemsg = get_std_save_message($retval);
70 5b237745 Scott Ullrich
		if ($retval == 0) {
71
			if (file_exists($d_natconfdirty_path))
72
				unlink($d_natconfdirty_path);
73
			if (file_exists($d_filterconfdirty_path))
74
				unlink($d_filterconfdirty_path);
75
		}
76
	}
77
}
78
79 07bd3f83 Scott Ullrich
if (isset($_POST['del_x'])) {
80
	/* delete selected rules */
81
	if (is_array($_POST['rule']) && count($_POST['rule'])) {
82
		foreach ($_POST['rule'] as $rulei) {
83
			unset($a_filter[$rulei]);
84
		}
85 5b237745 Scott Ullrich
		write_config();
86
		touch($d_filterconfdirty_path);
87 07bd3f83 Scott Ullrich
		header("Location: firewall_rules.php?if={$if}");
88 5b237745 Scott Ullrich
		exit;
89
	}
90 07bd3f83 Scott Ullrich
} else if ($_GET['act'] == "toggle") {
91
	if ($a_filter[$_GET['id']]) {
92 f53b85a3 Scott Ullrich
                if(isset($a_filter[$_GET['id']]['disabled']))
93 734edbdf Bill Marquette
                        unset($a_filter[$_GET['id']]['disabled']);
94
                else
95
                        $a_filter[$_GET['id']]['disabled'] = true;
96 5b237745 Scott Ullrich
		write_config();
97
		touch($d_filterconfdirty_path);
98 07bd3f83 Scott Ullrich
		header("Location: firewall_rules.php?if={$if}");
99 5b237745 Scott Ullrich
		exit;
100
	}
101 07bd3f83 Scott Ullrich
} else {
102 b2ffe419 Scott Ullrich
	/* yuck - IE won't send value attributes for image buttons, while Mozilla does -
103 37e2071c Scott Ullrich
	   so we use .x/.y to fine move button clicks instead... */
104 07bd3f83 Scott Ullrich
	unset($movebtn);
105
	foreach ($_POST as $pn => $pd) {
106
		if (preg_match("/move_(\d+)_x/", $pn, $matches)) {
107
			$movebtn = $matches[1];
108
			break;
109
		}
110 5b237745 Scott Ullrich
	}
111 07bd3f83 Scott Ullrich
	/* move selected rules before this rule */
112
	if (isset($movebtn) && is_array($_POST['rule']) && count($_POST['rule'])) {
113
		$a_filter_new = array();
114 b2ffe419 Scott Ullrich
115 07bd3f83 Scott Ullrich
		/* copy all rules < $movebtn and not selected */
116
		for ($i = 0; $i < $movebtn; $i++) {
117
			if (!in_array($i, $_POST['rule']))
118
				$a_filter_new[] = $a_filter[$i];
119
		}
120 b2ffe419 Scott Ullrich
121 07bd3f83 Scott Ullrich
		/* copy all selected rules */
122
		for ($i = 0; $i < count($a_filter); $i++) {
123
			if ($i == $movebtn)
124
				continue;
125
			if (in_array($i, $_POST['rule']))
126
				$a_filter_new[] = $a_filter[$i];
127
		}
128 b2ffe419 Scott Ullrich
129 07bd3f83 Scott Ullrich
		/* copy $movebtn rule */
130
		if ($movebtn < count($a_filter))
131
			$a_filter_new[] = $a_filter[$movebtn];
132 b2ffe419 Scott Ullrich
133 07bd3f83 Scott Ullrich
		/* copy all rules > $movebtn and not selected */
134
		for ($i = $movebtn+1; $i < count($a_filter); $i++) {
135
			if (!in_array($i, $_POST['rule']))
136
				$a_filter_new[] = $a_filter[$i];
137
		}
138 b2ffe419 Scott Ullrich
139 07bd3f83 Scott Ullrich
		$a_filter = $a_filter_new;
140 5b237745 Scott Ullrich
		write_config();
141
		touch($d_filterconfdirty_path);
142 07bd3f83 Scott Ullrich
		header("Location: firewall_rules.php?if={$if}");
143 5b237745 Scott Ullrich
		exit;
144
	}
145
}
146
147 9a25487b Scott Ullrich
$pgtitle = "Firewall: Rules";
148
include("head.inc");
149
150 5b237745 Scott Ullrich
?>
151
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
152
<?php include("fbegin.inc"); ?>
153 da7ae7ef Bill Marquette
<p class="pgtitle"><?=$pgtitle?></p>
154 5b237745 Scott Ullrich
<form action="firewall_rules.php" method="post">
155 6a8d35ca Bill Marquette
<script type="text/javascript" language="javascript" src="row_toggle.js">
156 fa65a62b Scott Ullrich
</script>
157 5b237745 Scott Ullrich
<?php if ($savemsg) print_info_box($savemsg); ?>
158
<?php if (file_exists($d_filterconfdirty_path)): ?><p>
159
<?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>
160
<?php endif; ?>
161 07bd3f83 Scott Ullrich
<table width="100%" border="0" cellpadding="0" cellspacing="0">
162 37e2071c Scott Ullrich
  <tr><td class="tabnavtbl">
163 0366b748 Scott Ullrich
  <?php
164
	/* active tabs */
165
	$tab_array = array();
166
	$tabscounter = 0; $i = 0; foreach ($iflist as $ifent => $ifname) {
167
		if ($ifent == $if)
168
			$active = true;
169
		else
170
			$active = false;
171
		$tab_array[] = array($ifname, $active, "firewall_rules.php?if={$ifent}");
172
	}
173
	display_top_tabs($tab_array);
174
  ?>
175 07bd3f83 Scott Ullrich
  </td></tr>
176 b2ffe419 Scott Ullrich
  <tr>
177 d732f186 Bill Marquette
    <td>
178
	<div id="mainarea">
179
              <table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
180 fa65a62b Scott Ullrich
                <tr id="frheader">
181 37e2071c Scott Ullrich
                  <td width="3%" class="list">&nbsp;</td>
182 5b237745 Scott Ullrich
                  <td width="5%" class="list">&nbsp;</td>
183
                  <td width="10%" class="listhdrr">Proto</td>
184
                  <td width="15%" class="listhdrr">Source</td>
185
                  <td width="10%" class="listhdrr">Port</td>
186
                  <td width="15%" class="listhdrr">Destination</td>
187
                  <td width="10%" class="listhdrr">Port</td>
188 37e2071c Scott Ullrich
                  <td width="22%" class="listhdr">Description</td>
189 5b237745 Scott Ullrich
                  <td width="10%" class="list"></td>
190
				</tr>
191 07bd3f83 Scott Ullrich
				<?php $nrules = 0; for ($i = 0; isset($a_filter[$i]); $i++):
192
					$filterent = $a_filter[$i];
193
					if ($filterent['interface'] != $if)
194
						continue;
195
				?>
196 37e2071c Scott Ullrich
                <tr valign="top" id="fr<?=$nrules;?>">
197
                  <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>
198
                  <td class="listt" align="center">
199 5b237745 Scott Ullrich
				  <?php if ($filterent['type'] == "block")
200
				  			$iconfn = "block";
201
						else if ($filterent['type'] == "reject") {
202
							if ($filterent['protocol'] == "tcp" || $filterent['protocol'] == "udp")
203
								$iconfn = "reject";
204
							else
205
								$iconfn = "block";
206
						} else
207
							$iconfn = "pass";
208
						if (isset($filterent['disabled'])) {
209
							$textss = "<span class=\"gray\">";
210
							$textse = "</span>";
211
							$iconfn .= "_d";
212
						} else {
213
							$textss = $textse = "";
214
						}
215
				  ?>
216 07bd3f83 Scott Ullrich
				  <a href="?if=<?=$if;?>&act=toggle&id=<?=$i;?>"><img src="<?=$iconfn;?>.gif" width="11" height="11" border="0" title="click to toggle enabled/disabled status"></a>
217 5b237745 Scott Ullrich
				  <?php if (isset($filterent['log'])):
218
							$iconfn = "log_s";
219
						if (isset($filterent['disabled']))
220
							$iconfn .= "_d";
221
				  	?>
222
				  <br><img src="<?=$iconfn;?>.gif" width="11" height="15" border="0">
223
				  <?php endif; ?>
224
				  </td>
225 98e29097 Bill Marquette
                  <td class="listlr" onClick="fr_toggle(<?=$nrules;?>)" id="frd<?=$nrules;?>" ondblclick="document.location='firewall_rules_edit.php?id=<?=$i;?>';">
226 5b237745 Scott Ullrich
                    <?=$textss;?><?php if (isset($filterent['protocol'])) echo strtoupper($filterent['protocol']); else echo "*"; ?><?=$textse;?>
227
                  </td>
228 98e29097 Bill Marquette
                  <td class="listr" onClick="fr_toggle(<?=$nrules;?>)" id="frd<?=$nrules;?>" ondblclick="document.location='firewall_rules_edit.php?id=<?=$i;?>';">
229 5b237745 Scott Ullrich
				    <?=$textss;?><?php echo htmlspecialchars(pprint_address($filterent['source'])); ?><?=$textse;?>
230
                  </td>
231 98e29097 Bill Marquette
                  <td class="listr" onClick="fr_toggle(<?=$nrules;?>)" id="frd<?=$nrules;?>" ondblclick="document.location='firewall_rules_edit.php?id=<?=$i;?>';">
232 5b237745 Scott Ullrich
                    <?=$textss;?><?php echo htmlspecialchars(pprint_port($filterent['source']['port'])); ?><?=$textse;?>
233
                  </td>
234 98e29097 Bill Marquette
                  <td class="listr" onClick="fr_toggle(<?=$nrules;?>)" id="frd<?=$nrules;?>" ondblclick="document.location='firewall_rules_edit.php?id=<?=$i;?>';">
235 5b237745 Scott Ullrich
				    <?=$textss;?><?php echo htmlspecialchars(pprint_address($filterent['destination'])); ?><?=$textse;?>
236
                  </td>
237 98e29097 Bill Marquette
                  <td class="listr" onClick="fr_toggle(<?=$nrules;?>)" id="frd<?=$nrules;?>" ondblclick="document.location='firewall_rules_edit.php?id=<?=$i;?>';">
238 5b237745 Scott Ullrich
                    <?=$textss;?><?php echo htmlspecialchars(pprint_port($filterent['destination']['port'])); ?><?=$textse;?>
239
                  </td>
240 98e29097 Bill Marquette
                  <td class="listbg" onClick="fr_toggle(<?=$nrules;?>)" ondblclick="document.location='firewall_rules_edit.php?id=<?=$i;?>';" bcolor="#990000"><font color="white">
241 07bd3f83 Scott Ullrich
                    <?=$textss;?><?=htmlspecialchars($filterent['descr']);?>&nbsp;<?=$textse;?>
242 5b237745 Scott Ullrich
                  </td>
243
                  <td valign="middle" nowrap class="list">
244 07bd3f83 Scott Ullrich
				    <table border="0" cellspacing="0" cellpadding="1">
245
					<tr>
246 37e2071c Scott Ullrich
					  <td><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)"></td>
247 07bd3f83 Scott Ullrich
					  <td><a href="firewall_rules_edit.php?id=<?=$i;?>"><img src="e.gif" title="edit rule" width="17" height="17" border="0"></a></td>
248
					</tr>
249
					<tr>
250 37e2071c Scott Ullrich
					  <td align="center" valign="middle"></td>
251 07bd3f83 Scott Ullrich
					  <td><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></td>
252
					</tr>
253
					</table>
254 5b237745 Scott Ullrich
				  </td>
255
				</tr>
256 07bd3f83 Scott Ullrich
			  <?php $nrules++; endfor; ?>
257
			  <?php if ($nrules == 0): ?>
258 37e2071c Scott Ullrich
              <td class="listt"></td>
259 07bd3f83 Scott Ullrich
			  <td class="listt"></td>
260
			  <td class="listlr" colspan="6" align="center" valign="middle">
261
			  <span class="gray">
262
			  No rules are currently defined for this interface.<br>
263
			  All incoming connections on this interface will be blocked until you add pass rules.<br><br>
264
			  Click the <a href="firewall_rules_edit.php?if=<?=$if;?>"><img src="plus.gif" title="add new rule" border="0" width="17" height="17" align="absmiddle"></a> button to add a new rule.</span>
265
			  </td>
266
			  <?php endif; ?>
267 37e2071c Scott Ullrich
                <tr id="fr<?=$nrules;?>">
268
                  <td class="list"></td>
269
                  <td class="list"></td>
270
                  <td class="list">&nbsp;</td>
271
                  <td class="list">&nbsp;</td>
272
                  <td class="list">&nbsp;</td>
273
                  <td class="list">&nbsp;</td>
274
                  <td class="list">&nbsp;</td>
275
                  <td class="list">&nbsp;</td>
276 07bd3f83 Scott Ullrich
                  <td class="list">
277
				    <table border="0" cellspacing="0" cellpadding="1">
278
					<tr>
279
				      <td>
280 37e2071c Scott Ullrich
					  <?php if ($nrules == 0): ?><img src="left_d.gif" width="17" height="17" title="move selected rules to end" border="0"><?php else: ?><input name="move_<?=$i;?>" type="image" src="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>
281
					  <td></td>
282 07bd3f83 Scott Ullrich
				    </tr>
283
					<tr>
284
					  <td><?php if ($nrules == 0): ?><img src="x_d.gif" width="17" height="17" title="delete selected rules" border="0"><?php else: ?><input name="del" type="image" src="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>
285 37e2071c Scott Ullrich
					  <td><a href="firewall_rules_edit.php?if=<?=$if;?>"><img src="plus.gif" title="add new rule" width="17" height="17" border="0"></a></td>
286 07bd3f83 Scott Ullrich
					</tr>
287
				    </table>
288
				  </td>
289 5b237745 Scott Ullrich
				</tr>
290
              </table>
291 d732f186 Bill Marquette
	      <table class="tabcont" width="100%" border="0" cellspacing="0" cellpadding="0">
292 b2ffe419 Scott Ullrich
                <tr>
293 5b237745 Scott Ullrich
                  <td width="16"><img src="pass.gif" width="11" height="11"></td>
294
                  <td>pass</td>
295
                  <td width="14"></td>
296
                  <td width="16"><img src="block.gif" width="11" height="11"></td>
297
                  <td>block</td>
298
                  <td width="14"></td>
299
                  <td width="16"><img src="reject.gif" width="11" height="11"></td>
300
                  <td>reject</td>
301
                  <td width="14"></td>
302
                  <td width="16"><img src="log.gif" width="11" height="11"></td>
303
                  <td>log</td>
304
                </tr>
305 b2ffe419 Scott Ullrich
                <tr>
306 5b237745 Scott Ullrich
                  <td><img src="pass_d.gif" width="11" height="11"></td>
307 d732f186 Bill Marquette
                  <td nowrap>pass (disabled)</td>
308
                  <td>&nbsp;</td>
309 5b237745 Scott Ullrich
                  <td><img src="block_d.gif" width="11" height="11"></td>
310 d732f186 Bill Marquette
                  <td nowrap>block (disabled)</td>
311
                  <td>&nbsp;</td>
312 5b237745 Scott Ullrich
                  <td><img src="reject_d.gif" width="11" height="11"></td>
313 d732f186 Bill Marquette
                  <td nowrap>reject (disabled)</td>
314
                  <td>&nbsp;</td>
315 5b237745 Scott Ullrich
                  <td width="16"><img src="log_d.gif" width="11" height="11"></td>
316 d732f186 Bill Marquette
                  <td nowrap>log (disabled)</td>
317 5b237745 Scott Ullrich
                </tr>
318 d732f186 Bill Marquette
		<tr>
319
		  <td colspan="9">
320 07bd3f83 Scott Ullrich
  <p>
321
  <strong><span class="red">Hint:<br>
322 37e2071c Scott Ullrich
  </span></strong>Rules are evaluated on a first-match basis (i.e.
323 b2ffe419 Scott Ullrich
  the action of the first rule to match a packet will be executed).
324
  This means that if you use block rules, you'll have to pay attention
325
  to the rule order. Everything that isn't explicitly passed is blocked
326 07bd3f83 Scott Ullrich
  by default.</p>
327 d732f186 Bill Marquette
		 </td>
328
	        </tr>
329
              </table>
330
	</div>
331
    </td>
332
  </tr>
333
</table>
334 37e2071c Scott Ullrich
  <input type="hidden" name="if" value="<?=$if;?>">
335 07bd3f83 Scott Ullrich
</form>
336 5b237745 Scott Ullrich
<?php include("fend.inc"); ?>
337 af4aa061 Scott Ullrich
</body>
338
</html>