Project

General

Profile

Download (10.8 KB) Statistics
| Branch: | Tag: | Revision:
1
#!/usr/local/bin/php
2
<?php
3
/*
4
	firewall_rules.php
5
	Copyright (C) 2004 Scott Ullrich
6
	All rights reserved.
7

    
8
	originally part of m0n0wall (http://m0n0.ch/wall)
9
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
10
	All rights reserved.
11
	
12
	Redistribution and use in source and binary forms, with or without
13
	modification, are permitted provided that the following conditions are met:
14

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

    
18
	2. Redistributions in binary form must reproduce the above copyright
19
	   notice, this list of conditions and the following disclaimer in the
20
	   documentation and/or other materials provided with the distribution.
21

    
22
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
23
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
24
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
26
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31
	POSSIBILITY OF SUCH DAMAGE.
32
*/
33

    
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 ($_POST) {
43

    
44
	$pconfig = $_POST;
45

    
46
	if ($_POST['apply']) {
47
		$retval = 0;
48
		if (!file_exists($d_sysrebootreqd_path)) {
49
			config_lock();
50
			$retval = filter_configure();
51
			config_unlock();
52
		}
53
		$savemsg = get_std_save_message($retval);
54
		if ($retval == 0) {
55
			if (file_exists($d_natconfdirty_path))
56
				unlink($d_natconfdirty_path);
57
			if (file_exists($d_filterconfdirty_path))
58
				unlink($d_filterconfdirty_path);
59
		}
60
	}
61
}
62

    
63
if ($_GET['act'] == "del") {
64
	if ($a_filter[$_GET['id']]) {
65
		unset($a_filter[$_GET['id']]);
66
		write_config();
67
		touch($d_filterconfdirty_path);
68
		header("Location: firewall_rules.php");
69
		exit;
70
	}
71
} else if ($_GET['act'] == "down") {
72
	if ($a_filter[$_GET['id']] && $a_filter[$_GET['id']+1]) {
73
		$tmp = $a_filter[$_GET['id']+1];
74
		$a_filter[$_GET['id']+1] = $a_filter[$_GET['id']];
75
		$a_filter[$_GET['id']] = $tmp;
76
		write_config();
77
		touch($d_filterconfdirty_path);
78
		header("Location: firewall_rules.php");
79
		exit;
80
	}
81
} else if ($_GET['act'] == "up") {
82
	if (($_GET['id'] > 0) && $a_filter[$_GET['id']]) {
83
		$tmp = $a_filter[$_GET['id']-1];
84
		$a_filter[$_GET['id']-1] = $a_filter[$_GET['id']];
85
		$a_filter[$_GET['id']] = $tmp;
86
		write_config();
87
		touch($d_filterconfdirty_path);
88
		header("Location: firewall_rules.php");
89
		exit;
90
	}
91
} else if ($_GET['act'] == "toggle") {
92
	if ($a_filter[$_GET['id']]) {
93
		$a_filter[$_GET['id']]['disabled'] = !isset($a_filter[$_GET['id']]['disabled']);
94
		write_config();
95
		touch($d_filterconfdirty_path);
96
		header("Location: firewall_rules.php");
97
		exit;
98
	}
99
}
100

    
101
?>
102
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
103
<html>
104
<head>
105
<title><?=gentitle("Firewall: Rules");?></title>
106
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
107
<link href="gui.css" rel="stylesheet" type="text/css">
108
</head>
109

    
110
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
111
<?php include("fbegin.inc"); ?>
112
<p class="pgtitle">Firewall: Rules</p>
113
<form action="firewall_rules.php" method="post">
114
<?php if ($savemsg) print_info_box($savemsg); ?>
115
<?php if (file_exists($d_filterconfdirty_path)): ?><p>
116
<?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>
117
<input name="apply" type="submit" class="formbtn" id="apply" value="Apply changes"></p>
118
<?php endif; ?>
119
              <table width="100%" border="0" cellpadding="0" cellspacing="0">
120

    
121
	      	<tr><td colspan="9">
122
		<ul id="tabnav">
123
		  <li class="tabact">Rules</li>
124
		  <li class="tabinact"><a href="firewall_shaper_queues.php">Queues</a></li>
125
		</ul>
126
		</td></tr>
127
		<tr>
128
			<td class="tabcont">
129
			<table width="100%" border="0" cellpadding="0" cellspacing="0">
130

    
131
	        <?php $lastif = ""; for ($i = 0; isset($a_filter[$i]); $i++):
132
				$filterent = $a_filter[$i];
133
                if ($filterent['interface'] != $lastif):
134
                if ($i):
135
				?>
136

    
137
                <tr>
138
                  <td colspan="8" class="list" height="12"></td>
139
				</tr>
140
				<?php endif; ?>
141
                <tr>
142
                  <td colspan="7" class="listtopic"><?php
143
				  $iflabels = array('lan' => 'LAN interface', 'wan' => 'WAN interface', 'pptp' => 'PPTP clients');
144
				  for ($j = 1; isset($config['interfaces']['opt' . $j]); $j++)
145
				  	$iflabels['opt' . $j] = $config['interfaces']['opt' . $j]['name'] . " interface";
146
				  echo htmlspecialchars($iflabels[$filterent['interface']]); ?></td>
147
				  <td class="list"></td>
148
				</tr>
149
                <tr>
150
                  <td width="5%" class="list">&nbsp;</td>
151
                  <td width="10%" class="listhdrr">Proto</td>
152
                  <td width="15%" class="listhdrr">Source</td>
153
                  <td width="10%" class="listhdrr">Port</td>
154
                  <td width="15%" class="listhdrr">Destination</td>
155
                  <td width="10%" class="listhdrr">Port</td>
156
                  <td width="25%" class="listhdr">Description</td>
157
                  <td width="10%" class="list"></td>
158
				</tr>
159
				<?php $lastif = $filterent['interface']; endif; ?>
160
                <tr valign="top">
161
                  <td class="listt">
162
				  <?php if ($filterent['type'] == "block")
163
				  			$iconfn = "block";
164
						else if ($filterent['type'] == "reject") {
165
							if ($filterent['protocol'] == "tcp" || $filterent['protocol'] == "udp")
166
								$iconfn = "reject";
167
							else
168
								$iconfn = "block";
169
						} else
170
							$iconfn = "pass";
171
						if (isset($filterent['disabled'])) {
172
							$textss = "<span class=\"gray\">";
173
							$textse = "</span>";
174
							$iconfn .= "_d";
175
						} else {
176
							$textss = $textse = "";
177
						}
178
				  ?>
179
				  <a href="?act=toggle&id=<?=$i;?>"><img src="<?=$iconfn;?>.gif" width="11" height="11" border="0" title="click to toggle enabled/disabled status"></a>
180
				  <?php if (isset($filterent['log'])):
181
							$iconfn = "log_s";
182
						if (isset($filterent['disabled']))
183
							$iconfn .= "_d";
184
				  	?>
185
				  <br><img src="<?=$iconfn;?>.gif" width="11" height="15" border="0">
186
				  <?php endif; ?>
187
				  </td>
188
                  <td class="listlr">
189
                    <?=$textss;?><?php if (isset($filterent['protocol'])) echo strtoupper($filterent['protocol']); else echo "*"; ?><?=$textse;?>
190
                  </td>
191
                  <td class="listr">
192
				    <?=$textss;?><?php echo htmlspecialchars(pprint_address($filterent['source'])); ?><?=$textse;?>
193
                  </td>
194
                  <td class="listr">
195
                    <?=$textss;?><?php echo htmlspecialchars(pprint_port($filterent['source']['port'])); ?><?=$textse;?>
196
                  </td>
197
                  <td class="listr">
198
				    <?=$textss;?><?php echo htmlspecialchars(pprint_address($filterent['destination'])); ?><?=$textse;?>
199
                  </td>
200
                  <td class="listr">
201
                    <?=$textss;?><?php echo htmlspecialchars(pprint_port($filterent['destination']['port'])); ?><?=$textse;?>
202
                  </td>
203
                  <td class="listbg">
204
                    <?=$textss;?><font color="#FFFFFF"><?=htmlspecialchars($filterent['descr']);?>&nbsp;<?=$textse;?>
205
                  </td>
206
                  <td valign="middle" nowrap class="list">
207
				    <a href="firewall_rules_edit.php?id=<?=$i;?>"><img src="e.gif" title="edit rule" width="17" height="17" border="0"></a>
208
					<?php if (($i > 0) && ($a_filter[$i-1]['interface'] == $filterent['interface'])): ?>
209
					<a href="firewall_rules.php?act=up&id=<?=$i;?>"><img src="up.gif" title="move up" width="17" height="17" border="0"></a>
210
					<?php else: ?>
211
					<img src="up_d.gif" width="17" height="17" border="0">
212
					<?php endif; ?><br>
213
					<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>
214
					<?php if ($a_filter[$i+1]['interface'] == $filterent['interface']): ?>
215
					<a href="firewall_rules.php?act=down&id=<?=$i;?>"><img src="down.gif" title="move down" width="17" height="17" border="0"></a>
216
                    <?php else: ?>
217
					<img src="down_d.gif" width="17" height="17" border="0">
218
					<?php endif; ?>
219
					<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>
220
				  </td>
221
				</tr>
222
			  <?php endfor; ?>
223
                <tr>
224
                  <td class="list" colspan="7"></td>
225
                  <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>
226
				</tr>
227
              </table>
228
			  <table border="0" cellspacing="0" cellpadding="0">
229
                <tr>
230
                  <td width="16"><img src="pass.gif" width="11" height="11"></td>
231
                  <td>pass</td>
232
                  <td width="14"></td>
233
                  <td width="16"><img src="block.gif" width="11" height="11"></td>
234
                  <td>block</td>
235
                  <td width="14"></td>
236
                  <td width="16"><img src="reject.gif" width="11" height="11"></td>
237
                  <td>reject</td>
238
                  <td width="14"></td>
239
                  <td width="16"><img src="log.gif" width="11" height="11"></td>
240
                  <td>log</td>
241
                </tr>
242
                <tr>
243
                  <td colspan="5" height="4"></td>
244
                </tr>
245
                <tr>
246
                  <td><img src="pass_d.gif" width="11" height="11"></td>
247
                  <td>pass (disabled)</td>
248
                  <td></td>
249
                  <td><img src="block_d.gif" width="11" height="11"></td>
250
                  <td>block (disabled)</td>
251
                  <td></td>
252
                  <td><img src="reject_d.gif" width="11" height="11"></td>
253
                  <td>reject (disabled)</td>
254
                  <td></td>
255
                  <td width="16"><img src="log_d.gif" width="11" height="11"></td>
256
                  <td>log (disabled)</td>
257
                </tr>
258
              </table>
259
	      </tr></table>
260
              <p>
261
              <strong><span class="red">Hint:<br>
262
              </span></strong>rules are evaluated on a first-match basis (i.e.
263
              the action of the first rule to match a packet will be executed).
264
              This means that if you use block rules, you'll have to pay attention
265
              to the rule order. Everything that isn't explicitly passed is blocked
266
              by default.</p>
267
            </form>
268
<?php include("fend.inc"); ?>
269
</body>
270
</html>
(28-28/88)