Project

General

Profile

Download (14.1 KB) Statistics
| Branch: | Tag: | Revision:
1
#!/usr/local/bin/php
2
<?php
3
/* $Id$ */
4
/*
5
	firewall_rules.php
6
	part of m0n0wall (http://m0n0.ch/wall)
7

    
8
	Copyright (C) 2003-2005 Manuel Kasper <mk@neon1.net>.
9
	All rights reserved.
10

    
11
	Redistribution and use in source and binary forms, with or without
12
	modification, are permitted provided that the following conditions are met:
13

    
14
	1. Redistributions of source code must retain the above copyright notice,
15
	   this list of conditions and the following disclaimer.
16

    
17
	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

    
21
	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
*/
32

    
33
$pgtitle = array("Firewall", "Rules");
34
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
$if = $_GET['if'];
43
if ($_POST['if'])
44
	$if = $_POST['if'];
45

    
46
$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
	$if = "wan";
57

    
58
if ($_POST) {
59

    
60
	$pconfig = $_POST;
61

    
62
	if ($_POST['apply']) {
63
		$retval = 0;
64
		if (!file_exists($d_sysrebootreqd_path)) {
65
			config_lock();
66
			$retval = filter_configure();
67
			config_unlock();
68
		}
69
		$savemsg = get_std_save_message($retval);
70
		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
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
		write_config();
86
		touch($d_filterconfdirty_path);
87
		header("Location: firewall_rules.php?if={$if}");
88
		exit;
89
	}
90
} else if ($_GET['act'] == "toggle") {
91
	if ($a_filter[$_GET['id']]) {
92
                if(isset($a_filter[$_GET['id']]['disabled']))
93
                        unset($a_filter[$_GET['id']]['disabled']);
94
                else
95
                        $a_filter[$_GET['id']]['disabled'] = true;
96
		write_config();
97
		touch($d_filterconfdirty_path);
98
		header("Location: firewall_rules.php?if={$if}");
99
		exit;
100
	}
101
} else {
102
	/* yuck - IE won't send value attributes for image buttons, while Mozilla does -
103
	   so we use .x/.y to fine move button clicks instead... */
104
	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
	}
111
	/* move selected rules before this rule */
112
	if (isset($movebtn) && is_array($_POST['rule']) && count($_POST['rule'])) {
113
		$a_filter_new = array();
114

    
115
		/* 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

    
121
		/* 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

    
129
		/* copy $movebtn rule */
130
		if ($movebtn < count($a_filter))
131
			$a_filter_new[] = $a_filter[$movebtn];
132

    
133
		/* 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

    
139
		$a_filter = $a_filter_new;
140
		write_config();
141
		touch($d_filterconfdirty_path);
142
		header("Location: firewall_rules.php?if={$if}");
143
		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
<script type="text/javascript" language="javascript" src="row_toggle.js">
160
</script>
161
<?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
<table width="100%" border="0" cellpadding="0" cellspacing="0">
167
  <tr><td class="tabnavtbl">
168
  <ul id="tabnav">
169
<?php $i = 0; foreach ($iflist as $ifent => $ifname):
170
	if ($ifent == $if): ?>
171
    <li class="tabact"><?=htmlspecialchars($ifname);?></li>
172
<?php else: ?>
173
    <li class="<?php if ($i == 0) echo "tabinact1"; else echo "tabinact";?>"><a href="firewall_rules.php?if=<?=$ifent;?>"><?=htmlspecialchars($ifname);?></a></li>
174
<?php endif; ?>
175
<?php $i++; endforeach; ?>
176
  </ul>
177
  </td></tr>
178
  <tr>
179
    <td class="tabcont">
180
              <table width="100%" border="0" cellpadding="0" cellspacing="0">
181
                <tr id="frheader">
182
                  <td width="3%" class="list">&nbsp;</td>
183
                  <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
                  <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="<?=$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="<?=$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']);?>&nbsp;<?=$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="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="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="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="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">&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
                  <td class="list">
278
				    <table border="0" cellspacing="0" cellpadding="1">
279
					<tr>
280
				      <td>
281
					  <?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
				    </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
					  <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
					</tr>
288
				    </table>
289
				  </td>
290
				</tr>
291
              </table>
292
			  <table border="0" cellspacing="0" cellpadding="0">
293
                <tr>
294
                  <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
                <tr>
310
                  <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
    </td>
324
  </tr>
325
</table>
326
  <p>
327
  <strong><span class="red">Hint:<br>
328
  </span></strong>Rules are evaluated on a first-match basis (i.e.
329
  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
  by default.</p>
333
  <input type="hidden" name="if" value="<?=$if;?>">
334
</form>
335
<?php include("fend.inc"); ?>
(36-36/117)