Project

General

Profile

Download (7.97 KB) Statistics
| Branch: | Tag: | Revision:
1 5b237745 Scott Ullrich
<?php
2 b46bfcf5 Bill Marquette
/* $Id$ */
3 5b237745 Scott Ullrich
/*
4
	firewall_aliases.php
5 4d875b4f Scott Ullrich
	Copyright (C) 2004 Scott Ullrich
6
	All rights reserved.
7 f0fe3d30 Scott Ullrich
8 4d875b4f Scott Ullrich
	originially part of m0n0wall (http://m0n0.ch/wall)
9 5b237745 Scott Ullrich
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
10
	All rights reserved.
11 f0fe3d30 Scott Ullrich
12 5b237745 Scott Ullrich
	Redistribution and use in source and binary forms, with or without
13
	modification, are permitted provided that the following conditions are met:
14 f0fe3d30 Scott Ullrich
15 5b237745 Scott Ullrich
	1. Redistributions of source code must retain the above copyright notice,
16
	   this list of conditions and the following disclaimer.
17 f0fe3d30 Scott Ullrich
18 5b237745 Scott Ullrich
	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 f0fe3d30 Scott Ullrich
22 5b237745 Scott Ullrich
	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 6b07c15a Matthew Grooms
##|+PRIV
35
##|*IDENT=page-firewall-aliases
36
##|*NAME=Firewall: Aliases page
37
##|*DESCR=Allow access to the 'Firewall: Aliases' page.
38
##|*MATCH=firewall_aliases.php*
39
##|-PRIV
40
41
42 5b237745 Scott Ullrich
require("guiconfig.inc");
43
44
if (!is_array($config['aliases']['alias']))
45
	$config['aliases']['alias'] = array();
46
47
aliases_sort();
48
$a_aliases = &$config['aliases']['alias'];
49
50
if ($_POST) {
51
52
	$pconfig = $_POST;
53
54
	if ($_POST['apply']) {
55
		$retval = 0;
56 920b3bb0 Scott Ullrich
57
		/* reload all components that use aliases */
58
		$retval = filter_configure();
59
60 b2774343 Scott Ullrich
		if(stristr($retval, "error") <> true)
61
		    $savemsg = get_std_save_message($retval);
62
		else
63
		    $savemsg = $retval;
64 5b237745 Scott Ullrich
		if ($retval == 0) {
65
			if (file_exists($d_aliasesdirty_path))
66
				unlink($d_aliasesdirty_path);
67
		}
68
	}
69
}
70
71
if ($_GET['act'] == "del") {
72
	if ($a_aliases[$_GET['id']]) {
73 58c32a28 Scott Ullrich
		/* make sure rule is not being referenced by any nat or filter rules */
74
		$is_alias_referenced = false;
75
		$referenced_by = false;
76
		$alias_name = $a_aliases[$_GET['id']]['name'];
77 676abc7c Scott Ullrich
		if(is_array($config['nat']['rule'])) {
78
			foreach($config['nat']['rule'] as $rule) {
79
				if($rule['localip'] == $alias_name) {
80 58c32a28 Scott Ullrich
					$is_alias_referenced = true;
81
					$referenced_by = $rule['descr'];
82
					break;
83
				}
84 676abc7c Scott Ullrich
			}
85 58c32a28 Scott Ullrich
		}
86 3e3e9bee Scott Ullrich
		if($is_alias_referenced == false) {
87 676abc7c Scott Ullrich
			if(is_array($config['filter']['rule'])) {
88
				foreach($config['filter']['rule'] as $rule) {
89
					if($rule['source']['address'] == $alias_name) {
90
						$is_alias_referenced = true;
91
						$referenced_by = $rule['descr'];
92
						break;
93
					}
94
					if($rule['source']['address'] == $alias_name) {
95
						$is_alias_referenced = true;
96
						$referenced_by = $rule['descr'];
97
						break;
98
					}
99
					if($rule['source']['port'] == $alias_name) {
100
						$is_alias_referenced = true;
101
						$referenced_by = $rule['descr'];
102
						break;
103
					}
104
					if($rule['destination']['port'] == $alias_name) {
105
						$is_alias_referenced = true;
106
						$referenced_by = $rule['descr'];
107
						break;
108
					}
109 3e3e9bee Scott Ullrich
				}
110 676abc7c Scott Ullrich
			}
111
		}
112
		if($is_alias_referenced == false) {
113
			if(is_array($config['nat']['rule'])) {
114
				foreach($config['nat']['rule'] as $rule) {
115
					if($rule['target'] == $alias_name) {
116
						$is_alias_referenced = true;
117
						$referenced_by = $rule['descr'];
118
						break;
119
					}
120
					if($rule['external-address'] == $alias_name) {
121
						$is_alias_referenced = true;
122
						$referenced_by = $rule['descr'];
123
						break;
124
					}
125
					if($rule['external-port'] == $alias_name) {
126
						$is_alias_referenced = true;
127
						$referenced_by = $rule['descr'];
128
						break;
129
					}
130
					if($rule['local-port'] == $alias_name) {
131
						$is_alias_referenced = true;
132
						$referenced_by = $rule['descr'];
133
						break;
134
					}
135 3e3e9bee Scott Ullrich
				}
136 676abc7c Scott Ullrich
			}
137
		}
138 58c32a28 Scott Ullrich
		if($is_alias_referenced == true) {
139
			$savemsg = "Cannot delete rule.  Currently in use by {$referenced_by}";
140
		} else {
141
			unset($a_aliases[$_GET['id']]);
142
			write_config();
143 339495c7 Scott Ullrich
			filter_configure();
144 58c32a28 Scott Ullrich
			touch($d_aliasesdirty_path);
145
			header("Location: firewall_aliases.php");
146
			exit;
147
		}
148 5b237745 Scott Ullrich
	}
149
}
150 b63695db Scott Ullrich
151 d88c6a9f Scott Ullrich
$pgtitle = array("Firewall","Aliases");
152 b63695db Scott Ullrich
include("head.inc");
153
154 5b237745 Scott Ullrich
?>
155
156
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
157
<?php include("fbegin.inc"); ?>
158
<form action="firewall_aliases.php" method="post">
159
<?php if ($savemsg) print_info_box($savemsg); ?>
160
<?php if (file_exists($d_aliasesdirty_path)): ?><p>
161 a0509c58 Scott Ullrich
<?php print_info_box_np("The alias list has been changed.<br>You must apply the changes in order for them to take effect.");?>
162 5b237745 Scott Ullrich
<?php endif; ?>
163 d2cfb7a4 Scott Ullrich
164
<table width="100%" border="0" cellpadding="0" cellspacing="0">
165
<tr>
166
  <td width="25%" class="listhdrr">Name</td>
167 1dc8c3eb Scott Ullrich
  <td width="25%" class="listhdrr">Values</td>
168
  <td width="25%" class="listhdr">Description</td>
169 d415d821 Seth Mos
  <td width="10%" class="list">
170
    <table border="0" cellspacing="0" cellpadding="1">
171
      <tr>
172
	<td valign="middle" width="17">&nbsp;</td>
173
        <td valign="middle"><a href="firewall_aliases_edit.php"><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0" title="add a new alias"></a></td>
174
      </tr>
175
    </table>
176
  </td>
177 d2cfb7a4 Scott Ullrich
</tr>
178
	  <?php $i = 0; foreach ($a_aliases as $alias): ?>
179
<tr>
180 20ba0ca5 Bill Marquette
  <td class="listlr" ondblclick="document.location='firewall_aliases_edit.php?id=<?=$i;?>';">
181 d2cfb7a4 Scott Ullrich
    <?=htmlspecialchars($alias['name']);?>
182
  </td>
183 20ba0ca5 Bill Marquette
  <td class="listr" ondblclick="document.location='firewall_aliases_edit.php?id=<?=$i;?>';">
184 7e65fc22 Scott Ullrich
      <?php
185 9e49dae8 Scott Ullrich
	$addresses = implode(", ", array_slice(explode(" ", $alias['address']), 0, 10));
186
	echo $addresses;
187
	if(count($addresses) < 10) {
188 2e445a9e Scott Ullrich
		echo " ";
189 9e49dae8 Scott Ullrich
	} else {
190
		echo "...";
191 7e65fc22 Scott Ullrich
	}
192
    ?>
193 d2cfb7a4 Scott Ullrich
  </td>
194 20ba0ca5 Bill Marquette
  <td class="listbg" ondblclick="document.location='firewall_aliases_edit.php?id=<?=$i;?>';">
195 7e65fc22 Scott Ullrich
    <?=htmlspecialchars($alias['descr']);?>&nbsp;
196 d2cfb7a4 Scott Ullrich
  </td>
197 725f5e5a Bill Marquette
  <td valign="middle" nowrap class="list">
198 676abc7c Scott Ullrich
    <table border="0" cellspacing="0" cellpadding="1">
199 725f5e5a Bill Marquette
      <tr>
200 ec3418ed Bill Marquette
        <td valign="middle"><a href="firewall_aliases_edit.php?id=<?=$i;?>"><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_e.gif" width="17" height="17" border="0" title="edit alias"></a></td>
201
        <td><a href="firewall_aliases.php?act=del&id=<?=$i;?>" onclick="return confirm('Do you really want to delete this alias? All elements that still use it will become invalid (e.g. filter rules)!')"><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" width="17" height="17" border="0" title="delete alias"></a></td>
202 725f5e5a Bill Marquette
      </tr>
203
    </table>
204
  </td>
205 d2cfb7a4 Scott Ullrich
</tr>
206
	  <?php $i++; endforeach; ?>
207
<tr>
208
  <td class="list" colspan="3"></td>
209 725f5e5a Bill Marquette
  <td class="list">
210
    <table border="0" cellspacing="0" cellpadding="1">
211
      <tr>
212 d415d821 Seth Mos
	<td valign="middle" width="17">&nbsp;</td>
213 19f11aef Bill Marquette
        <td valign="middle">
214
          <a href="firewall_aliases_edit.php"><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0" title="add a new alias"></a></td>
215 f724d6b6 Scott Ullrich
        </td>
216
	      <td valign="middle">
217 19f11aef Bill Marquette
          <a href="firewall_aliases_import.php"><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_import_alias.gif" width="17" height="17" border="0" title="<?=gettext("import aliases from list");?>" alt="" /></a>
218 f724d6b6 Scott Ullrich
        </td>
219 725f5e5a Bill Marquette
      </tr>
220
    </table>
221
  </td>
222 d2cfb7a4 Scott Ullrich
</tr>
223
<tr>
224
  <td class="tabcont" colspan="3">
225 31e92b6a Scott Ullrich
   <p><span class="vexpl"><span class="red"><strong>Note:<br></strong></span>Aliases act as placeholders for real hosts, networks or ports. They can be used to minimize the number of changes that have to be made if a host, network or port changes. You can enter the name of an alias instead of the host, network or port in all fields that have a red background. The alias will be resolved according to the list above. If an alias cannot be resolved (e.g. because you deleted it), the corresponding element (e.g. filter/NAT/shaper rule) will be considered invalid and skipped.</span></p>
226 d2cfb7a4 Scott Ullrich
  </td>
227
</tr>
228
</table>
229
</form>
230 5b237745 Scott Ullrich
<?php include("fend.inc"); ?>
231
</body>
232
</html>