Project

General

Profile

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