Project

General

Profile

Download (12.9 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 6317d31d Phil Davis
	Copyright (C) 2013-2015 Electric Sheep Fencing, LP
7 4d875b4f Scott Ullrich
	All rights reserved.
8 f0fe3d30 Scott Ullrich
9 ec074a86 Phil Davis
	originally part of m0n0wall (http://m0n0.ch/wall)
10 5b237745 Scott Ullrich
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
11
	All rights reserved.
12 f0fe3d30 Scott Ullrich
13 5b237745 Scott Ullrich
	Redistribution and use in source and binary forms, with or without
14
	modification, are permitted provided that the following conditions are met:
15 f0fe3d30 Scott Ullrich
16 5b237745 Scott Ullrich
	1. Redistributions of source code must retain the above copyright notice,
17
	   this list of conditions and the following disclaimer.
18 f0fe3d30 Scott Ullrich
19 5b237745 Scott Ullrich
	2. Redistributions in binary form must reproduce the above copyright
20
	   notice, this list of conditions and the following disclaimer in the
21
	   documentation and/or other materials provided with the distribution.
22 f0fe3d30 Scott Ullrich
23 5b237745 Scott Ullrich
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
24
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
25
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
27
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32
	POSSIBILITY OF SUCH DAMAGE.
33
*/
34 7ac5a4cb Scott Ullrich
/*
35
	pfSense_MODULE:	aliases
36
*/
37 5b237745 Scott Ullrich
38 6b07c15a Matthew Grooms
##|+PRIV
39
##|*IDENT=page-firewall-aliases
40
##|*NAME=Firewall: Aliases page
41
##|*DESCR=Allow access to the 'Firewall: Aliases' page.
42
##|*MATCH=firewall_aliases.php*
43
##|-PRIV
44
45 5b237745 Scott Ullrich
require("guiconfig.inc");
46 7a927e67 Scott Ullrich
require_once("functions.inc");
47
require_once("filter.inc");
48
require_once("shaper.inc");
49 5b237745 Scott Ullrich
50
if (!is_array($config['aliases']['alias']))
51
	$config['aliases']['alias'] = array();
52
$a_aliases = &$config['aliases']['alias'];
53
54 ac7f1763 Renato Botelho
$tab = ($_REQUEST['tab'] == "" ? "ip" : preg_replace("/\W/","",$_REQUEST['tab']));
55 5b237745 Scott Ullrich
56 ac7f1763 Renato Botelho
if ($_POST) {
57 5b237745 Scott Ullrich
58
	if ($_POST['apply']) {
59
		$retval = 0;
60 920b3bb0 Scott Ullrich
61
		/* reload all components that use aliases */
62
		$retval = filter_configure();
63
64 b2774343 Scott Ullrich
		if(stristr($retval, "error") <> true)
65
		    $savemsg = get_std_save_message($retval);
66
		else
67
		    $savemsg = $retval;
68 a368a026 Ermal Lu?i
		if ($retval == 0)
69
			clear_subsystem_dirty('aliases');
70 5b237745 Scott Ullrich
	}
71
}
72
73
if ($_GET['act'] == "del") {
74
	if ($a_aliases[$_GET['id']]) {
75 58c32a28 Scott Ullrich
		/* make sure rule is not being referenced by any nat or filter rules */
76
		$is_alias_referenced = false;
77
		$referenced_by = false;
78
		$alias_name = $a_aliases[$_GET['id']]['name'];
79 c769f983 Erik Fonnesbeck
		// Firewall rules
80
		find_alias_reference(array('filter', 'rule'), array('source', 'address'), $alias_name, $is_alias_referenced, $referenced_by);
81
		find_alias_reference(array('filter', 'rule'), array('destination', 'address'), $alias_name, $is_alias_referenced, $referenced_by);
82
		find_alias_reference(array('filter', 'rule'), array('source', 'port'), $alias_name, $is_alias_referenced, $referenced_by);
83
		find_alias_reference(array('filter', 'rule'), array('destination', 'port'), $alias_name, $is_alias_referenced, $referenced_by);
84
		// NAT Rules
85
		find_alias_reference(array('nat', 'rule'), array('source', 'address'), $alias_name, $is_alias_referenced, $referenced_by);
86
		find_alias_reference(array('nat', 'rule'), array('source', 'port'), $alias_name, $is_alias_referenced, $referenced_by);
87
		find_alias_reference(array('nat', 'rule'), array('destination', 'address'), $alias_name, $is_alias_referenced, $referenced_by);
88
		find_alias_reference(array('nat', 'rule'), array('destination', 'port'), $alias_name, $is_alias_referenced, $referenced_by);
89
		find_alias_reference(array('nat', 'rule'), array('target'), $alias_name, $is_alias_referenced, $referenced_by);
90
		find_alias_reference(array('nat', 'rule'), array('local-port'), $alias_name, $is_alias_referenced, $referenced_by);
91 b43b7613 Erik Fonnesbeck
		// NAT 1:1 Rules
92
		//find_alias_reference(array('nat', 'onetoone'), array('external'), $alias_name, $is_alias_referenced, $referenced_by);
93
		//find_alias_reference(array('nat', 'onetoone'), array('source', 'address'), $alias_name, $is_alias_referenced, $referenced_by);
94
		find_alias_reference(array('nat', 'onetoone'), array('destination', 'address'), $alias_name, $is_alias_referenced, $referenced_by);
95
		// NAT Outbound Rules
96
		find_alias_reference(array('nat', 'advancedoutbound', 'rule'), array('source', 'network'), $alias_name, $is_alias_referenced, $referenced_by);
97 ca640261 Erik Fonnesbeck
		find_alias_reference(array('nat', 'advancedoutbound', 'rule'), array('sourceport'), $alias_name, $is_alias_referenced, $referenced_by);
98 b43b7613 Erik Fonnesbeck
		find_alias_reference(array('nat', 'advancedoutbound', 'rule'), array('destination', 'address'), $alias_name, $is_alias_referenced, $referenced_by);
99 ca640261 Erik Fonnesbeck
		find_alias_reference(array('nat', 'advancedoutbound', 'rule'), array('dstport'), $alias_name, $is_alias_referenced, $referenced_by);
100 b43b7613 Erik Fonnesbeck
		find_alias_reference(array('nat', 'advancedoutbound', 'rule'), array('target'), $alias_name, $is_alias_referenced, $referenced_by);
101 c769f983 Erik Fonnesbeck
		// Alias in an alias
102
		find_alias_reference(array('aliases', 'alias'), array('address'), $alias_name, $is_alias_referenced, $referenced_by);
103 3df59bab Darren Embry
		// Load Balancer
104
		find_alias_reference(array('load_balancer', 'lbpool'),         array('port'), $alias_name, $is_alias_referenced, $referenced_by);
105
		find_alias_reference(array('load_balancer', 'virtual_server'), array('port'), $alias_name, $is_alias_referenced, $referenced_by);
106 a161bfb8 Renato Botelho
		// Static routes
107
		find_alias_reference(array('staticroutes', 'route'), array('network'), $alias_name, $is_alias_referenced, $referenced_by);
108 58c32a28 Scott Ullrich
		if($is_alias_referenced == true) {
109 4b4d550a Chris Buechler
			$savemsg = sprintf(gettext("Cannot delete alias. Currently in use by %s"), $referenced_by);
110 58c32a28 Scott Ullrich
		} else {
111
			unset($a_aliases[$_GET['id']]);
112 3a343d73 jim-p
			if (write_config()) {
113
				filter_configure();
114
				mark_subsystem_dirty('aliases');
115
			}
116 ac7f1763 Renato Botelho
			header("Location: firewall_aliases.php?tab=" . $tab);
117 58c32a28 Scott Ullrich
			exit;
118
		}
119 5b237745 Scott Ullrich
	}
120
}
121 b63695db Scott Ullrich
122 c769f983 Erik Fonnesbeck
function find_alias_reference($section, $field, $origname, &$is_alias_referenced, &$referenced_by) {
123
	global $config;
124
	if(!$origname || $is_alias_referenced)
125
		return;
126
127
	$sectionref = &$config;
128
	foreach($section as $sectionname) {
129
		if(is_array($sectionref) && isset($sectionref[$sectionname]))
130
			$sectionref = &$sectionref[$sectionname];
131
		else
132
			return;
133
	}
134
135
	if(is_array($sectionref)) {
136
		foreach($sectionref as $itemkey => $item) {
137
			$fieldfound = true;
138
			$fieldref = &$sectionref[$itemkey];
139
			foreach($field as $fieldname) {
140
				if(is_array($fieldref) && isset($fieldref[$fieldname]))
141
					$fieldref = &$fieldref[$fieldname];
142
				else {
143
					$fieldfound = false;
144
					break;
145
				}
146
			}
147
			if($fieldfound && $fieldref == $origname) {
148
				$is_alias_referenced = true;
149
				if(is_array($item))
150
					$referenced_by = $item['descr'];
151
				break;
152
			}
153
		}
154
	}
155
}
156
157 9dc65295 Carlos Eduardo Ramos
$pgtitle = array(gettext("Firewall"),gettext("Aliases"));
158 d71fc5d3 jim-p
$shortcut_section = "aliases";
159
160 b63695db Scott Ullrich
include("head.inc");
161
162 5b237745 Scott Ullrich
?>
163
164
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
165
<?php include("fbegin.inc"); ?>
166
<form action="firewall_aliases.php" method="post">
167
<?php if ($savemsg) print_info_box($savemsg); ?>
168 a368a026 Ermal Lu?i
<?php if (is_subsystem_dirty('aliases')): ?><p>
169 8cd558b6 ayvis
<?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."));?>
170 5b237745 Scott Ullrich
<?php endif; ?>
171 173d8e75 Scott Ullrich
<?php pfSense_handle_custom_code("/usr/local/pkg/firewall_aliases/pre_table"); ?>
172 709e62f0 Colin Fleming
<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="firewall aliases">
173 a5416de2 Warren Baker
	<tr>
174
		<td class="tabnavtbl">
175
			<?php
176
				$tab_array = array();
177 983fb4d2 Warren Baker
				$tab_array[] = array(gettext("IP"),($tab=="ip" ? true : ($tab=="host" ? true : ($tab == "network" ? true : false))), "/firewall_aliases.php?tab=ip");
178 a5416de2 Warren Baker
				$tab_array[] = array(gettext("Ports"), ($tab=="port"? true : false), "/firewall_aliases.php?tab=port");
179 e0658637 Chris Buechler
				$tab_array[] = array(gettext("URLs"), ($tab=="url"? true : false), "/firewall_aliases.php?tab=url");
180 a5416de2 Warren Baker
				$tab_array[] = array(gettext("All"), ($tab=="all"? true : false), "/firewall_aliases.php?tab=all");
181
				display_top_tabs($tab_array);
182
			?>
183 709e62f0 Colin Fleming
			<input type="hidden" name="tab" value="<?=htmlspecialchars($tab);?>" />
184 a5416de2 Warren Baker
		</td>
185
	</tr>
186 9db1ff32 Renato Botelho
	<tr>
187
		<td>
188
			<div id="mainarea">
189 709e62f0 Colin Fleming
				<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0" summary="main area">
190 9db1ff32 Renato Botelho
					<tr>
191
						<td width="20%" class="listhdrr"><?=gettext("Name"); ?></td>
192
						<td width="43%" class="listhdrr"><?=gettext("Values"); ?></td>
193
						<td width="30%" class="listhdr"><?=gettext("Description"); ?></td>
194
						<td width="7%" class="list">
195 709e62f0 Colin Fleming
							<table  border="0" cellspacing="0" cellpadding="1" summary="add">
196 9db1ff32 Renato Botelho
								<tr>
197
									<td valign="middle" width="17">&nbsp;</td>
198 709e62f0 Colin Fleming
									<td valign="middle"><a href="firewall_aliases_edit.php?tab=<?=$tab?>"><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0" <?=dom_title(gettext("Add a new alias"));?> alt="add" /></a></td>
199 9db1ff32 Renato Botelho
								</tr>
200
							</table>
201
						</td>
202
					</tr>
203
					<?php
204
					asort($a_aliases);
205
					foreach ($a_aliases as $i=> $alias){
206
						unset ($show_alias);
207
						switch ($tab){
208
						case "all":
209
							$show_alias= true;
210
							break;
211
						case "ip":
212
						case "host":
213
						case "network":
214
							if (preg_match("/(host|network)/",$alias["type"]))
215
								$show_alias= true;
216
							break;
217
						case "url":
218
							if (preg_match("/(url)/i",$alias["type"]))
219
								$show_alias= true;
220
							break;
221
						case "port":
222
							if($alias["type"] == "port")
223
								$show_alias= true;
224
							break;
225
						}
226
						if ($show_alias) {
227
					?>
228
					<tr>
229
						<td class="listlr" ondblclick="document.location='firewall_aliases_edit.php?id=<?=$i;?>';">
230
							<?=htmlspecialchars($alias['name']);?>
231
						</td>
232
						<td class="listr" ondblclick="document.location='firewall_aliases_edit.php?id=<?=$i;?>';">
233
						<?php
234
						if ($alias["url"]) {
235 8cd558b6 ayvis
							echo $alias["url"] . "<br />";
236 94597308 Renato Botelho
						} else {
237
							if(is_array($alias["aliasurl"])) {
238
								$aliasurls = implode(", ", array_slice($alias["aliasurl"], 0, 10));
239
								echo $aliasurls;
240
								if(count($aliasurls) > 10) {
241 8cd558b6 ayvis
									echo "...<br />";
242 94597308 Renato Botelho
								}
243 8cd558b6 ayvis
								echo "<br />\n";
244 94597308 Renato Botelho
							}
245
							$tmpaddr = explode(" ", $alias['address']);
246
							$addresses = implode(", ", array_slice($tmpaddr, 0, 10));
247
							echo $addresses;
248
							if(count($tmpaddr) > 10) {
249
								echo "...";
250 9db1ff32 Renato Botelho
							}
251
						}
252
						?>
253
						</td>
254
						<td class="listbg" ondblclick="document.location='firewall_aliases_edit.php?id=<?=$i;?>';">
255
							<?=htmlspecialchars($alias['descr']);?>&nbsp;
256
						</td>
257 709e62f0 Colin Fleming
						<td valign="middle" class="list nowrap">
258
							<table border="0" cellspacing="0" cellpadding="1" summary="icons">
259 9db1ff32 Renato Botelho
								<tr>
260 709e62f0 Colin Fleming
									<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" <?=dom_title(gettext("Edit alias")." {$alias['name']}");?> alt="edit" /></a></td>
261
									<td><a href="firewall_aliases.php?act=del&amp;tab=<?=$tab;?>&amp;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" <?=dom_title(gettext("Delete alias")." {$alias['name']}");?> alt="delete" /></a></td>
262 9db1ff32 Renato Botelho
								</tr>
263
							</table>
264
						</td>
265
					</tr>
266
					<?php
267
						} // if ($show_alias)
268
					} // foreach
269
					?>
270 0f89c125 marcelloc
271 9db1ff32 Renato Botelho
					<tr>
272 709e62f0 Colin Fleming
						<td colspan="3">&nbsp;</td>
273
						<td valign="middle" class="list nowrap">
274
							<table border="0" cellspacing="0" cellpadding="1" summary="edit">
275 9db1ff32 Renato Botelho
								<tbody>
276
									<tr>
277
										<td valign="middle">
278 709e62f0 Colin Fleming
											<a href="firewall_aliases_edit.php?tab=<?=$tab?>"><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0" <?=dom_title(gettext("Add a new alias")); ?> alt="add" /></a>
279 9db1ff32 Renato Botelho
										</td>
280
										<td valign="middle">
281 709e62f0 Colin Fleming
											<a href="firewall_aliases_import.php"><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_import_alias.gif" width="17" height="17" border="0" <?=dom_title(gettext("Bulk import aliases from list"));?> alt="import" /></a>
282 9db1ff32 Renato Botelho
										</td>
283
									</tr>
284
								</tbody>
285
							</table>
286
						</td>
287
					</tr>
288 0f89c125 marcelloc
289 9db1ff32 Renato Botelho
					<tr>
290
						<td class="tabcont" colspan="3">
291 8cd558b6 ayvis
							<p><span class="vexpl"><span class="red"><strong><?=gettext("Note:"); ?><br /></strong></span></span></p><div style="overflow:hidden; text-align:justify;"><p><span class="vexpl"><?=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></div>
292 9db1ff32 Renato Botelho
						</td>
293
					</tr>
294
				</table>
295
			</div>
296
		</td>
297
	</tr>
298 d2cfb7a4 Scott Ullrich
</table>
299
</form>
300 5b237745 Scott Ullrich
<?php include("fend.inc"); ?>
301
</body>
302
</html>