Project

General

Profile

Download (10.1 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 7ac5a4cb Scott Ullrich
/*
34
	pfSense_MODULE:	aliases
35
*/
36 5b237745 Scott Ullrich
37 6b07c15a Matthew Grooms
##|+PRIV
38
##|*IDENT=page-firewall-aliases
39
##|*NAME=Firewall: Aliases page
40
##|*DESCR=Allow access to the 'Firewall: Aliases' page.
41
##|*MATCH=firewall_aliases.php*
42
##|-PRIV
43
44 5b237745 Scott Ullrich
require("guiconfig.inc");
45 7a927e67 Scott Ullrich
require_once("functions.inc");
46
require_once("filter.inc");
47
require_once("shaper.inc");
48 5b237745 Scott Ullrich
49
if (!is_array($config['aliases']['alias']))
50
	$config['aliases']['alias'] = array();
51
$a_aliases = &$config['aliases']['alias'];
52
53
if ($_POST) {
54
55
	$pconfig = $_POST;
56
57
	if ($_POST['apply']) {
58
		$retval = 0;
59 920b3bb0 Scott Ullrich
60
		/* reload all components that use aliases */
61
		$retval = filter_configure();
62
63 b2774343 Scott Ullrich
		if(stristr($retval, "error") <> true)
64
		    $savemsg = get_std_save_message($retval);
65
		else
66
		    $savemsg = $retval;
67 a368a026 Ermal Lu?i
		if ($retval == 0)
68
			clear_subsystem_dirty('aliases');
69 5b237745 Scott Ullrich
	}
70
}
71
72
if ($_GET['act'] == "del") {
73
	if ($a_aliases[$_GET['id']]) {
74 58c32a28 Scott Ullrich
		/* make sure rule is not being referenced by any nat or filter rules */
75
		$is_alias_referenced = false;
76
		$referenced_by = false;
77
		$alias_name = $a_aliases[$_GET['id']]['name'];
78 c769f983 Erik Fonnesbeck
		// Firewall rules
79
		find_alias_reference(array('filter', 'rule'), array('source', 'address'), $alias_name, $is_alias_referenced, $referenced_by);
80
		find_alias_reference(array('filter', 'rule'), array('destination', 'address'), $alias_name, $is_alias_referenced, $referenced_by);
81
		find_alias_reference(array('filter', 'rule'), array('source', 'port'), $alias_name, $is_alias_referenced, $referenced_by);
82
		find_alias_reference(array('filter', 'rule'), array('destination', 'port'), $alias_name, $is_alias_referenced, $referenced_by);
83
		// NAT Rules
84
		find_alias_reference(array('nat', 'rule'), array('source', 'address'), $alias_name, $is_alias_referenced, $referenced_by);
85
		find_alias_reference(array('nat', 'rule'), array('source', 'port'), $alias_name, $is_alias_referenced, $referenced_by);
86
		find_alias_reference(array('nat', 'rule'), array('destination', 'address'), $alias_name, $is_alias_referenced, $referenced_by);
87
		find_alias_reference(array('nat', 'rule'), array('destination', 'port'), $alias_name, $is_alias_referenced, $referenced_by);
88
		find_alias_reference(array('nat', 'rule'), array('target'), $alias_name, $is_alias_referenced, $referenced_by);
89
		find_alias_reference(array('nat', 'rule'), array('local-port'), $alias_name, $is_alias_referenced, $referenced_by);
90 b43b7613 Erik Fonnesbeck
		// NAT 1:1 Rules
91
		//find_alias_reference(array('nat', 'onetoone'), array('external'), $alias_name, $is_alias_referenced, $referenced_by);
92
		//find_alias_reference(array('nat', 'onetoone'), array('source', 'address'), $alias_name, $is_alias_referenced, $referenced_by);
93
		find_alias_reference(array('nat', 'onetoone'), array('destination', 'address'), $alias_name, $is_alias_referenced, $referenced_by);
94
		// NAT Outbound Rules
95
		find_alias_reference(array('nat', 'advancedoutbound', 'rule'), array('source', 'network'), $alias_name, $is_alias_referenced, $referenced_by);
96 ca640261 Erik Fonnesbeck
		find_alias_reference(array('nat', 'advancedoutbound', 'rule'), array('sourceport'), $alias_name, $is_alias_referenced, $referenced_by);
97 b43b7613 Erik Fonnesbeck
		find_alias_reference(array('nat', 'advancedoutbound', 'rule'), array('destination', 'address'), $alias_name, $is_alias_referenced, $referenced_by);
98 ca640261 Erik Fonnesbeck
		find_alias_reference(array('nat', 'advancedoutbound', 'rule'), array('dstport'), $alias_name, $is_alias_referenced, $referenced_by);
99 b43b7613 Erik Fonnesbeck
		find_alias_reference(array('nat', 'advancedoutbound', 'rule'), array('target'), $alias_name, $is_alias_referenced, $referenced_by);
100 c769f983 Erik Fonnesbeck
		// Alias in an alias
101
		find_alias_reference(array('aliases', 'alias'), array('address'), $alias_name, $is_alias_referenced, $referenced_by);
102 58c32a28 Scott Ullrich
		if($is_alias_referenced == true) {
103 4b4d550a Chris Buechler
			$savemsg = sprintf(gettext("Cannot delete alias. Currently in use by %s"), $referenced_by);
104 58c32a28 Scott Ullrich
		} else {
105
			unset($a_aliases[$_GET['id']]);
106
			write_config();
107 339495c7 Scott Ullrich
			filter_configure();
108 a368a026 Ermal Lu?i
			mark_subsystem_dirty('aliases');
109 58c32a28 Scott Ullrich
			header("Location: firewall_aliases.php");
110
			exit;
111
		}
112 5b237745 Scott Ullrich
	}
113
}
114 b63695db Scott Ullrich
115 c769f983 Erik Fonnesbeck
function find_alias_reference($section, $field, $origname, &$is_alias_referenced, &$referenced_by) {
116
	global $config;
117
	if(!$origname || $is_alias_referenced)
118
		return;
119
120
	$sectionref = &$config;
121
	foreach($section as $sectionname) {
122
		if(is_array($sectionref) && isset($sectionref[$sectionname]))
123
			$sectionref = &$sectionref[$sectionname];
124
		else
125
			return;
126
	}
127
128
	if(is_array($sectionref)) {
129
		foreach($sectionref as $itemkey => $item) {
130
			$fieldfound = true;
131
			$fieldref = &$sectionref[$itemkey];
132
			foreach($field as $fieldname) {
133
				if(is_array($fieldref) && isset($fieldref[$fieldname]))
134
					$fieldref = &$fieldref[$fieldname];
135
				else {
136
					$fieldfound = false;
137
					break;
138
				}
139
			}
140
			if($fieldfound && $fieldref == $origname) {
141
				$is_alias_referenced = true;
142
				if(is_array($item))
143
					$referenced_by = $item['descr'];
144
				break;
145
			}
146
		}
147
	}
148
}
149
150 9dc65295 Carlos Eduardo Ramos
$pgtitle = array(gettext("Firewall"),gettext("Aliases"));
151 b63695db Scott Ullrich
include("head.inc");
152
153 5b237745 Scott Ullrich
?>
154
155
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
156
<?php include("fbegin.inc"); ?>
157
<form action="firewall_aliases.php" method="post">
158
<?php if ($savemsg) print_info_box($savemsg); ?>
159 a368a026 Ermal Lu?i
<?php if (is_subsystem_dirty('aliases')): ?><p>
160 808614b1 Renato Botelho
<?php print_info_box_np(gettext("The alias list has been changed.") . "<br>" . gettext("You must apply the changes in order for them to take effect."));?>
161 5b237745 Scott Ullrich
<?php endif; ?>
162 d2cfb7a4 Scott Ullrich
163 17d5077f Evgeny Yurchenko
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="tabcont">
164 d2cfb7a4 Scott Ullrich
<tr>
165 ecacce60 Carlos Eduardo Ramos
  <td width="25%" class="listhdrr"><?=gettext("Name"); ?></td>
166
  <td width="25%" class="listhdrr"><?=gettext("Values"); ?></td>
167
  <td width="25%" class="listhdr"><?=gettext("Description"); ?></td>
168 d415d821 Seth Mos
  <td width="10%" class="list">
169
    <table border="0" cellspacing="0" cellpadding="1">
170
      <tr>
171
	<td valign="middle" width="17">&nbsp;</td>
172 ecacce60 Carlos Eduardo Ramos
        <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="<?=gettext("add a new alias"); ?>"></a></td>
173 d415d821 Seth Mos
      </tr>
174
    </table>
175
  </td>
176 d2cfb7a4 Scott Ullrich
</tr>
177
	  <?php $i = 0; foreach ($a_aliases as $alias): ?>
178
<tr>
179 20ba0ca5 Bill Marquette
  <td class="listlr" ondblclick="document.location='firewall_aliases_edit.php?id=<?=$i;?>';">
180 d2cfb7a4 Scott Ullrich
    <?=htmlspecialchars($alias['name']);?>
181
  </td>
182 20ba0ca5 Bill Marquette
  <td class="listr" ondblclick="document.location='firewall_aliases_edit.php?id=<?=$i;?>';">
183 7e65fc22 Scott Ullrich
      <?php
184 c7de8be4 jim-p
	if ($alias["url"]) {
185
		echo $alias["url"] . "<br/>";
186
	}
187
	if ($alias["aliasurl"]) {
188
		echo $alias["aliasurl"] . "<br/>";
189
	}
190 4ef606fb Ermal
	$tmpaddr = explode(" ", $alias['address']);
191
	$addresses = implode(", ", array_slice($tmpaddr, 0, 10));
192 9e49dae8 Scott Ullrich
	echo $addresses;
193 6c33fb4b Ermal
	if(count($tmpaddr) > 10) {
194 9e49dae8 Scott Ullrich
		echo "...";
195 7e65fc22 Scott Ullrich
	}
196
    ?>
197 d2cfb7a4 Scott Ullrich
  </td>
198 20ba0ca5 Bill Marquette
  <td class="listbg" ondblclick="document.location='firewall_aliases_edit.php?id=<?=$i;?>';">
199 7e65fc22 Scott Ullrich
    <?=htmlspecialchars($alias['descr']);?>&nbsp;
200 d2cfb7a4 Scott Ullrich
  </td>
201 725f5e5a Bill Marquette
  <td valign="middle" nowrap class="list">
202 676abc7c Scott Ullrich
    <table border="0" cellspacing="0" cellpadding="1">
203 725f5e5a Bill Marquette
      <tr>
204 ecacce60 Carlos Eduardo Ramos
        <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="<?=gettext("edit alias"); ?>"></a></td>
205 3ced0d25 Erik Fonnesbeck
	<td><a href="firewall_aliases.php?act=del&id=<?=$i;?>" onclick="return confirm('<?=gettext("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="<?=gettext("delete alias"); ?>"></a></td>
206 725f5e5a Bill Marquette
      </tr>
207
    </table>
208
  </td>
209 d2cfb7a4 Scott Ullrich
</tr>
210
	  <?php $i++; endforeach; ?>
211
<tr>
212
  <td class="list" colspan="3"></td>
213 725f5e5a Bill Marquette
  <td class="list">
214
    <table border="0" cellspacing="0" cellpadding="1">
215
      <tr>
216 d415d821 Seth Mos
	<td valign="middle" width="17">&nbsp;</td>
217 19f11aef Bill Marquette
        <td valign="middle">
218 ecacce60 Carlos Eduardo Ramos
          <a href="firewall_aliases_edit.php"><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0" title="<?=gettext("add a new alias"); ?>"></a></td>
219 f724d6b6 Scott Ullrich
        </td>
220
	      <td valign="middle">
221 ecacce60 Carlos Eduardo Ramos
           <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("Bulk import aliases from list"); ?>" alt="" /></a>
222 f724d6b6 Scott Ullrich
        </td>
223 725f5e5a Bill Marquette
      </tr>
224
    </table>
225
  </td>
226 d2cfb7a4 Scott Ullrich
</tr>
227
<tr>
228
  <td class="tabcont" colspan="3">
229 3931c643 Carlos Eduardo Ramos
   <p><span class="vexpl"><span class="red"><strong><?=gettext("Note:"); ?><br></strong></span><?=gettext("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>
230 d2cfb7a4 Scott Ullrich
  </td>
231
</tr>
232
</table>
233
</form>
234 5b237745 Scott Ullrich
<?php include("fend.inc"); ?>
235
</body>
236
</html>