Project

General

Profile

Download (7.92 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 a368a026 Ermal Lu?i
		if ($retval == 0)
65
			clear_subsystem_dirty('aliases');
66 5b237745 Scott Ullrich
	}
67
}
68
69
if ($_GET['act'] == "del") {
70
	if ($a_aliases[$_GET['id']]) {
71 58c32a28 Scott Ullrich
		/* make sure rule is not being referenced by any nat or filter rules */
72
		$is_alias_referenced = false;
73
		$referenced_by = false;
74
		$alias_name = $a_aliases[$_GET['id']]['name'];
75 676abc7c Scott Ullrich
		if(is_array($config['nat']['rule'])) {
76
			foreach($config['nat']['rule'] as $rule) {
77
				if($rule['localip'] == $alias_name) {
78 58c32a28 Scott Ullrich
					$is_alias_referenced = true;
79
					$referenced_by = $rule['descr'];
80
					break;
81
				}
82 676abc7c Scott Ullrich
			}
83 58c32a28 Scott Ullrich
		}
84 3e3e9bee Scott Ullrich
		if($is_alias_referenced == false) {
85 676abc7c Scott Ullrich
			if(is_array($config['filter']['rule'])) {
86
				foreach($config['filter']['rule'] as $rule) {
87
					if($rule['source']['address'] == $alias_name) {
88
						$is_alias_referenced = true;
89
						$referenced_by = $rule['descr'];
90
						break;
91
					}
92
					if($rule['source']['address'] == $alias_name) {
93
						$is_alias_referenced = true;
94
						$referenced_by = $rule['descr'];
95
						break;
96
					}
97
					if($rule['source']['port'] == $alias_name) {
98
						$is_alias_referenced = true;
99
						$referenced_by = $rule['descr'];
100
						break;
101
					}
102
					if($rule['destination']['port'] == $alias_name) {
103
						$is_alias_referenced = true;
104
						$referenced_by = $rule['descr'];
105
						break;
106
					}
107 3e3e9bee Scott Ullrich
				}
108 676abc7c Scott Ullrich
			}
109
		}
110
		if($is_alias_referenced == false) {
111
			if(is_array($config['nat']['rule'])) {
112
				foreach($config['nat']['rule'] as $rule) {
113
					if($rule['target'] == $alias_name) {
114
						$is_alias_referenced = true;
115
						$referenced_by = $rule['descr'];
116
						break;
117
					}
118
					if($rule['external-address'] == $alias_name) {
119
						$is_alias_referenced = true;
120
						$referenced_by = $rule['descr'];
121
						break;
122
					}
123
					if($rule['external-port'] == $alias_name) {
124
						$is_alias_referenced = true;
125
						$referenced_by = $rule['descr'];
126
						break;
127
					}
128
					if($rule['local-port'] == $alias_name) {
129
						$is_alias_referenced = true;
130
						$referenced_by = $rule['descr'];
131
						break;
132
					}
133 3e3e9bee Scott Ullrich
				}
134 676abc7c Scott Ullrich
			}
135
		}
136 58c32a28 Scott Ullrich
		if($is_alias_referenced == true) {
137
			$savemsg = "Cannot delete rule.  Currently in use by {$referenced_by}";
138
		} else {
139
			unset($a_aliases[$_GET['id']]);
140
			write_config();
141 339495c7 Scott Ullrich
			filter_configure();
142 a368a026 Ermal Lu?i
			mark_subsystem_dirty('aliases');
143 58c32a28 Scott Ullrich
			header("Location: firewall_aliases.php");
144
			exit;
145
		}
146 5b237745 Scott Ullrich
	}
147
}
148 b63695db Scott Ullrich
149 d88c6a9f Scott Ullrich
$pgtitle = array("Firewall","Aliases");
150 b63695db Scott Ullrich
include("head.inc");
151
152 5b237745 Scott Ullrich
?>
153
154
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
155
<?php include("fbegin.inc"); ?>
156
<form action="firewall_aliases.php" method="post">
157
<?php if ($savemsg) print_info_box($savemsg); ?>
158 a368a026 Ermal Lu?i
<?php if (is_subsystem_dirty('aliases')): ?><p>
159 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.");?>
160 5b237745 Scott Ullrich
<?php endif; ?>
161 d2cfb7a4 Scott Ullrich
162
<table width="100%" border="0" cellpadding="0" cellspacing="0">
163
<tr>
164
  <td width="25%" class="listhdrr">Name</td>
165 1dc8c3eb Scott Ullrich
  <td width="25%" class="listhdrr">Values</td>
166
  <td width="25%" class="listhdr">Description</td>
167 d415d821 Seth Mos
  <td width="10%" class="list">
168
    <table border="0" cellspacing="0" cellpadding="1">
169
      <tr>
170
	<td valign="middle" width="17">&nbsp;</td>
171
        <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>
172
      </tr>
173
    </table>
174
  </td>
175 d2cfb7a4 Scott Ullrich
</tr>
176
	  <?php $i = 0; foreach ($a_aliases as $alias): ?>
177
<tr>
178 20ba0ca5 Bill Marquette
  <td class="listlr" ondblclick="document.location='firewall_aliases_edit.php?id=<?=$i;?>';">
179 d2cfb7a4 Scott Ullrich
    <?=htmlspecialchars($alias['name']);?>
180
  </td>
181 20ba0ca5 Bill Marquette
  <td class="listr" ondblclick="document.location='firewall_aliases_edit.php?id=<?=$i;?>';">
182 7e65fc22 Scott Ullrich
      <?php
183 9e49dae8 Scott Ullrich
	$addresses = implode(", ", array_slice(explode(" ", $alias['address']), 0, 10));
184
	echo $addresses;
185
	if(count($addresses) < 10) {
186 2e445a9e Scott Ullrich
		echo " ";
187 9e49dae8 Scott Ullrich
	} else {
188
		echo "...";
189 7e65fc22 Scott Ullrich
	}
190
    ?>
191 d2cfb7a4 Scott Ullrich
  </td>
192 20ba0ca5 Bill Marquette
  <td class="listbg" ondblclick="document.location='firewall_aliases_edit.php?id=<?=$i;?>';">
193 7e65fc22 Scott Ullrich
    <?=htmlspecialchars($alias['descr']);?>&nbsp;
194 d2cfb7a4 Scott Ullrich
  </td>
195 725f5e5a Bill Marquette
  <td valign="middle" nowrap class="list">
196 676abc7c Scott Ullrich
    <table border="0" cellspacing="0" cellpadding="1">
197 725f5e5a Bill Marquette
      <tr>
198 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>
199
        <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>
200 725f5e5a Bill Marquette
      </tr>
201
    </table>
202
  </td>
203 d2cfb7a4 Scott Ullrich
</tr>
204
	  <?php $i++; endforeach; ?>
205
<tr>
206
  <td class="list" colspan="3"></td>
207 725f5e5a Bill Marquette
  <td class="list">
208
    <table border="0" cellspacing="0" cellpadding="1">
209
      <tr>
210 d415d821 Seth Mos
	<td valign="middle" width="17">&nbsp;</td>
211 19f11aef Bill Marquette
        <td valign="middle">
212
          <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>
213 f724d6b6 Scott Ullrich
        </td>
214
	      <td valign="middle">
215 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>
216 f724d6b6 Scott Ullrich
        </td>
217 725f5e5a Bill Marquette
      </tr>
218
    </table>
219
  </td>
220 d2cfb7a4 Scott Ullrich
</tr>
221
<tr>
222
  <td class="tabcont" colspan="3">
223 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>
224 d2cfb7a4 Scott Ullrich
  </td>
225
</tr>
226
</table>
227
</form>
228 5b237745 Scott Ullrich
<?php include("fend.inc"); ?>
229
</body>
230
</html>