Project

General

Profile

Download (14.1 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
?>
148
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
149
<html>
150
<head>
151
<title><?=gentitle("Firewall: Rules");?></title>
152
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
153
<link href="gui.css" rel="stylesheet" type="text/css">
154
</head>
155
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
156
<?php include("fbegin.inc"); ?>
157
<p class="pgtitle">Firewall: Rules</p>
158
<form action="firewall_rules.php" method="post">
159 6a8d35ca Bill Marquette
<script type="text/javascript" language="javascript" src="row_toggle.js">
160 fa65a62b Scott Ullrich
</script>
161 5b237745 Scott Ullrich
<?php if ($savemsg) print_info_box($savemsg); ?>
162
<?php if (file_exists($d_filterconfdirty_path)): ?><p>
163
<?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>
164
<input name="apply" type="submit" class="formbtn" id="apply" value="Apply changes"></p>
165
<?php endif; ?>
166 07bd3f83 Scott Ullrich
<table width="100%" border="0" cellpadding="0" cellspacing="0">
167 37e2071c Scott Ullrich
  <tr><td class="tabnavtbl">
168 07bd3f83 Scott Ullrich
  <ul id="tabnav">
169 37e2071c Scott Ullrich
<?php $i = 0; foreach ($iflist as $ifent => $ifname):
170 07bd3f83 Scott Ullrich
	if ($ifent == $if): ?>
171
    <li class="tabact"><?=htmlspecialchars($ifname);?></li>
172
<?php else: ?>
173 37e2071c Scott Ullrich
    <li class="<?php if ($i == 0) echo "tabinact1"; else echo "tabinact";?>"><a href="firewall_rules.php?if=<?=$ifent;?>"><?=htmlspecialchars($ifname);?></a></li>
174 07bd3f83 Scott Ullrich
<?php endif; ?>
175 37e2071c Scott Ullrich
<?php $i++; endforeach; ?>
176 07bd3f83 Scott Ullrich
  </ul>
177
  </td></tr>
178 b2ffe419 Scott Ullrich
  <tr>
179 07bd3f83 Scott Ullrich
    <td class="tabcont">
180 5b237745 Scott Ullrich
              <table width="100%" border="0" cellpadding="0" cellspacing="0">
181 fa65a62b Scott Ullrich
                <tr id="frheader">
182 37e2071c Scott Ullrich
                  <td width="3%" class="list">&nbsp;</td>
183 5b237745 Scott Ullrich
                  <td width="5%" class="list">&nbsp;</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 37e2071c Scott Ullrich
                  <td width="22%" class="listhdr">Description</td>
190 5b237745 Scott Ullrich
                  <td width="10%" class="list"></td>
191
				</tr>
192 07bd3f83 Scott Ullrich
				<?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 37e2071c Scott Ullrich
                <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 5b237745 Scott Ullrich
				  <?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 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>
218 5b237745 Scott Ullrich
				  <?php if (isset($filterent['log'])):
219
							$iconfn = "log_s";
220
						if (isset($filterent['disabled']))
221
							$iconfn .= "_d";
222
				  	?>
223
				  <br><img src="<?=$iconfn;?>.gif" width="11" height="15" border="0">
224
				  <?php endif; ?>
225
				  </td>
226 98e29097 Bill Marquette
                  <td class="listlr" onClick="fr_toggle(<?=$nrules;?>)" id="frd<?=$nrules;?>" ondblclick="document.location='firewall_rules_edit.php?id=<?=$i;?>';">
227 5b237745 Scott Ullrich
                    <?=$textss;?><?php if (isset($filterent['protocol'])) echo strtoupper($filterent['protocol']); else echo "*"; ?><?=$textse;?>
228
                  </td>
229 98e29097 Bill Marquette
                  <td class="listr" onClick="fr_toggle(<?=$nrules;?>)" id="frd<?=$nrules;?>" ondblclick="document.location='firewall_rules_edit.php?id=<?=$i;?>';">
230 5b237745 Scott Ullrich
				    <?=$textss;?><?php echo htmlspecialchars(pprint_address($filterent['source'])); ?><?=$textse;?>
231
                  </td>
232 98e29097 Bill Marquette
                  <td class="listr" onClick="fr_toggle(<?=$nrules;?>)" id="frd<?=$nrules;?>" ondblclick="document.location='firewall_rules_edit.php?id=<?=$i;?>';">
233 5b237745 Scott Ullrich
                    <?=$textss;?><?php echo htmlspecialchars(pprint_port($filterent['source']['port'])); ?><?=$textse;?>
234
                  </td>
235 98e29097 Bill Marquette
                  <td class="listr" onClick="fr_toggle(<?=$nrules;?>)" id="frd<?=$nrules;?>" ondblclick="document.location='firewall_rules_edit.php?id=<?=$i;?>';">
236 5b237745 Scott Ullrich
				    <?=$textss;?><?php echo htmlspecialchars(pprint_address($filterent['destination'])); ?><?=$textse;?>
237
                  </td>
238 98e29097 Bill Marquette
                  <td class="listr" onClick="fr_toggle(<?=$nrules;?>)" id="frd<?=$nrules;?>" ondblclick="document.location='firewall_rules_edit.php?id=<?=$i;?>';">
239 5b237745 Scott Ullrich
                    <?=$textss;?><?php echo htmlspecialchars(pprint_port($filterent['destination']['port'])); ?><?=$textse;?>
240
                  </td>
241 98e29097 Bill Marquette
                  <td class="listbg" onClick="fr_toggle(<?=$nrules;?>)" ondblclick="document.location='firewall_rules_edit.php?id=<?=$i;?>';" bcolor="#990000"><font color="white">
242 07bd3f83 Scott Ullrich
                    <?=$textss;?><?=htmlspecialchars($filterent['descr']);?>&nbsp;<?=$textse;?>
243 5b237745 Scott Ullrich
                  </td>
244
                  <td valign="middle" nowrap class="list">
245 07bd3f83 Scott Ullrich
				    <table border="0" cellspacing="0" cellpadding="1">
246
					<tr>
247 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>
248 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>
249
					</tr>
250
					<tr>
251 37e2071c Scott Ullrich
					  <td align="center" valign="middle"></td>
252 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>
253
					</tr>
254
					</table>
255 5b237745 Scott Ullrich
				  </td>
256
				</tr>
257 07bd3f83 Scott Ullrich
			  <?php $nrules++; endfor; ?>
258
			  <?php if ($nrules == 0): ?>
259 37e2071c Scott Ullrich
              <td class="listt"></td>
260 07bd3f83 Scott Ullrich
			  <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="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 37e2071c Scott Ullrich
                <tr id="fr<?=$nrules;?>">
269
                  <td class="list"></td>
270
                  <td class="list"></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
                  <td class="list">&nbsp;</td>
277 07bd3f83 Scott Ullrich
                  <td class="list">
278
				    <table border="0" cellspacing="0" cellpadding="1">
279
					<tr>
280
				      <td>
281 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>
282
					  <td></td>
283 07bd3f83 Scott Ullrich
				    </tr>
284
					<tr>
285
					  <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>
286 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>
287 07bd3f83 Scott Ullrich
					</tr>
288
				    </table>
289
				  </td>
290 5b237745 Scott Ullrich
				</tr>
291
              </table>
292
			  <table border="0" cellspacing="0" cellpadding="0">
293 b2ffe419 Scott Ullrich
                <tr>
294 5b237745 Scott Ullrich
                  <td width="16"><img src="pass.gif" width="11" height="11"></td>
295
                  <td>pass</td>
296
                  <td width="14"></td>
297
                  <td width="16"><img src="block.gif" width="11" height="11"></td>
298
                  <td>block</td>
299
                  <td width="14"></td>
300
                  <td width="16"><img src="reject.gif" width="11" height="11"></td>
301
                  <td>reject</td>
302
                  <td width="14"></td>
303
                  <td width="16"><img src="log.gif" width="11" height="11"></td>
304
                  <td>log</td>
305
                </tr>
306
                <tr>
307
                  <td colspan="5" height="4"></td>
308
                </tr>
309 b2ffe419 Scott Ullrich
                <tr>
310 5b237745 Scott Ullrich
                  <td><img src="pass_d.gif" width="11" height="11"></td>
311
                  <td>pass (disabled)</td>
312
                  <td></td>
313
                  <td><img src="block_d.gif" width="11" height="11"></td>
314
                  <td>block (disabled)</td>
315
                  <td></td>
316
                  <td><img src="reject_d.gif" width="11" height="11"></td>
317
                  <td>reject (disabled)</td>
318
                  <td></td>
319
                  <td width="16"><img src="log_d.gif" width="11" height="11"></td>
320
                  <td>log (disabled)</td>
321
                </tr>
322
              </table>
323 07bd3f83 Scott Ullrich
    </td>
324
  </tr>
325
</table>
326
  <p>
327
  <strong><span class="red">Hint:<br>
328 37e2071c Scott Ullrich
  </span></strong>Rules are evaluated on a first-match basis (i.e.
329 b2ffe419 Scott Ullrich
  the action of the first rule to match a packet will be executed).
330
  This means that if you use block rules, you'll have to pay attention
331
  to the rule order. Everything that isn't explicitly passed is blocked
332 07bd3f83 Scott Ullrich
  by default.</p>
333 37e2071c Scott Ullrich
  <input type="hidden" name="if" value="<?=$if;?>">
334 07bd3f83 Scott Ullrich
</form>
335 5b237745 Scott Ullrich
<?php include("fend.inc"); ?>