Project

General

Profile

Download (12.7 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	firewall_aliases.php
5
	Copyright (C) 2004 Scott Ullrich
6
	All rights reserved.
7

    
8
	originially part of m0n0wall (http://m0n0.ch/wall)
9
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
10
	All rights reserved.
11

    
12
	Redistribution and use in source and binary forms, with or without
13
	modification, are permitted provided that the following conditions are met:
14

    
15
	1. Redistributions of source code must retain the above copyright notice,
16
	   this list of conditions and the following disclaimer.
17

    
18
	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

    
22
	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
	pfSense_MODULE:	aliases
35
*/
36

    
37
##|+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
require("guiconfig.inc");
45
require_once("functions.inc");
46
require_once("filter.inc");
47
require_once("shaper.inc");
48

    
49
if (!is_array($config['aliases']['alias']))
50
	$config['aliases']['alias'] = array();
51
$a_aliases = &$config['aliases']['alias'];
52

    
53
$tab = ($_REQUEST['tab'] == "" ? "ip" : preg_replace("/\W/","",$_REQUEST['tab']));
54

    
55
if ($_POST) {
56

    
57
	if ($_POST['apply']) {
58
		$retval = 0;
59

    
60
		/* reload all components that use aliases */
61
		$retval = filter_configure();
62

    
63
		if(stristr($retval, "error") <> true)
64
		    $savemsg = get_std_save_message($retval);
65
		else
66
		    $savemsg = $retval;
67
		if ($retval == 0)
68
			clear_subsystem_dirty('aliases');
69
	}
70
}
71

    
72
if ($_GET['act'] == "del") {
73
	if ($a_aliases[$_GET['id']]) {
74
		/* 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
		// 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
		// 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
		find_alias_reference(array('nat', 'advancedoutbound', 'rule'), array('sourceport'), $alias_name, $is_alias_referenced, $referenced_by);
97
		find_alias_reference(array('nat', 'advancedoutbound', 'rule'), array('destination', 'address'), $alias_name, $is_alias_referenced, $referenced_by);
98
		find_alias_reference(array('nat', 'advancedoutbound', 'rule'), array('dstport'), $alias_name, $is_alias_referenced, $referenced_by);
99
		find_alias_reference(array('nat', 'advancedoutbound', 'rule'), array('target'), $alias_name, $is_alias_referenced, $referenced_by);
100
		// Alias in an alias
101
		find_alias_reference(array('aliases', 'alias'), array('address'), $alias_name, $is_alias_referenced, $referenced_by);
102
		// Load Balancer
103
		find_alias_reference(array('load_balancer', 'lbpool'),         array('port'), $alias_name, $is_alias_referenced, $referenced_by);
104
		find_alias_reference(array('load_balancer', 'virtual_server'), array('port'), $alias_name, $is_alias_referenced, $referenced_by);
105
		if($is_alias_referenced == true) {
106
			$savemsg = sprintf(gettext("Cannot delete alias. Currently in use by %s"), $referenced_by);
107
		} else {
108
			unset($a_aliases[$_GET['id']]);
109
			if (write_config()) {
110
				filter_configure();
111
				mark_subsystem_dirty('aliases');
112
			}
113
			header("Location: firewall_aliases.php?tab=" . $tab);
114
			exit;
115
		}
116
	}
117
}
118

    
119
function find_alias_reference($section, $field, $origname, &$is_alias_referenced, &$referenced_by) {
120
	global $config;
121
	if(!$origname || $is_alias_referenced)
122
		return;
123

    
124
	$sectionref = &$config;
125
	foreach($section as $sectionname) {
126
		if(is_array($sectionref) && isset($sectionref[$sectionname]))
127
			$sectionref = &$sectionref[$sectionname];
128
		else
129
			return;
130
	}
131

    
132
	if(is_array($sectionref)) {
133
		foreach($sectionref as $itemkey => $item) {
134
			$fieldfound = true;
135
			$fieldref = &$sectionref[$itemkey];
136
			foreach($field as $fieldname) {
137
				if(is_array($fieldref) && isset($fieldref[$fieldname]))
138
					$fieldref = &$fieldref[$fieldname];
139
				else {
140
					$fieldfound = false;
141
					break;
142
				}
143
			}
144
			if($fieldfound && $fieldref == $origname) {
145
				$is_alias_referenced = true;
146
				if(is_array($item))
147
					$referenced_by = $item['descr'];
148
				break;
149
			}
150
		}
151
	}
152
}
153

    
154
$pgtitle = array(gettext("Firewall"),gettext("Aliases"));
155
$shortcut_section = "aliases";
156

    
157
include("head.inc");
158

    
159
?>
160

    
161
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
162
<?php include("fbegin.inc"); ?>
163
<form action="firewall_aliases.php" method="post">
164
<?php if ($savemsg) print_info_box($savemsg); ?>
165
<?php if (is_subsystem_dirty('aliases')): ?><p>
166
<?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."));?>
167
<?php endif; ?>
168
<?php pfSense_handle_custom_code("/usr/local/pkg/firewall_aliases/pre_table"); ?>
169
<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="firewall aliases">
170
	<tr>
171
		<td class="tabnavtbl">
172
			<?php
173
				$tab_array = array();
174
				$tab_array[] = array(gettext("IP"),($tab=="ip" ? true : ($tab=="host" ? true : ($tab == "network" ? true : false))), "/firewall_aliases.php?tab=ip");
175
				$tab_array[] = array(gettext("Ports"), ($tab=="port"? true : false), "/firewall_aliases.php?tab=port");
176
				$tab_array[] = array(gettext("Urls"), ($tab=="url"? true : false), "/firewall_aliases.php?tab=url");
177
				$tab_array[] = array(gettext("All"), ($tab=="all"? true : false), "/firewall_aliases.php?tab=all");
178
				display_top_tabs($tab_array);
179
			?>
180
			<input type="hidden" name="tab" value="<?=htmlspecialchars($tab);?>" />
181
		</td>
182
	</tr>
183
	<tr>
184
		<td>
185
			<div id="mainarea">
186
				<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0" summary="main area">
187
					<tr>
188
						<td width="20%" class="listhdrr"><?=gettext("Name"); ?></td>
189
						<td width="43%" class="listhdrr"><?=gettext("Values"); ?></td>
190
						<td width="30%" class="listhdr"><?=gettext("Description"); ?></td>
191
						<td width="7%" class="list">
192
							<table  border="0" cellspacing="0" cellpadding="1" summary="add">
193
								<tr>
194
									<td valign="middle" width="17">&nbsp;</td>
195
									<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>
196
								</tr>
197
							</table>
198
						</td>
199
					</tr>
200
					<?php
201
					asort($a_aliases);
202
					foreach ($a_aliases as $i=> $alias){
203
						unset ($show_alias);
204
						switch ($tab){
205
						case "all":
206
							$show_alias= true;
207
							break;
208
						case "ip":
209
						case "host":
210
						case "network":
211
							if (preg_match("/(host|network)/",$alias["type"]))
212
								$show_alias= true;
213
							break;
214
						case "url":
215
							if (preg_match("/(url)/i",$alias["type"]))
216
								$show_alias= true;
217
							break;
218
						case "port":
219
							if($alias["type"] == "port")
220
								$show_alias= true;
221
							break;
222
						}
223
						if ($show_alias) {
224
					?>
225
					<tr>
226
						<td class="listlr" ondblclick="document.location='firewall_aliases_edit.php?id=<?=$i;?>';">
227
							<?=htmlspecialchars($alias['name']);?>
228
						</td>
229
						<td class="listr" ondblclick="document.location='firewall_aliases_edit.php?id=<?=$i;?>';">
230
						<?php
231
						if ($alias["url"]) {
232
							echo $alias["url"] . "<br/>";
233
						} else {
234
							if(is_array($alias["aliasurl"])) {
235
								$aliasurls = implode(", ", array_slice($alias["aliasurl"], 0, 10));
236
								echo $aliasurls;
237
								if(count($aliasurls) > 10) {
238
									echo "...<br/>";
239
								}
240
								echo "<br/>\n";
241
							}
242
							$tmpaddr = explode(" ", $alias['address']);
243
							$addresses = implode(", ", array_slice($tmpaddr, 0, 10));
244
							echo $addresses;
245
							if(count($tmpaddr) > 10) {
246
								echo "...";
247
							}
248
						}
249
						?>
250
						</td>
251
						<td class="listbg" ondblclick="document.location='firewall_aliases_edit.php?id=<?=$i;?>';">
252
							<?=htmlspecialchars($alias['descr']);?>&nbsp;
253
						</td>
254
						<td valign="middle" class="list nowrap">
255
							<table border="0" cellspacing="0" cellpadding="1" summary="icons">
256
								<tr>
257
									<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>
258
									<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>
259
								</tr>
260
							</table>
261
						</td>
262
					</tr>
263
					<?php
264
						} // if ($show_alias)
265
					} // foreach
266
					?>
267

    
268
					<tr>
269
						<td colspan="3">&nbsp;</td>
270
						<td valign="middle" class="list nowrap">
271
							<table border="0" cellspacing="0" cellpadding="1" summary="edit">
272
								<tbody>
273
									<tr>
274
										<td valign="middle">
275
											<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>
276
										</td>
277
										<td valign="middle">
278
											<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>
279
										</td>
280
									</tr>
281
								</tbody>
282
							</table>
283
						</td>
284
					</tr>
285

    
286
					<tr>
287
						<td class="tabcont" colspan="3">
288
							<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>
289
						</td>
290
					</tr>
291
				</table>
292
			</div>
293
		</td>
294
	</tr>
295
</table>
296
</form>
297
<?php include("fend.inc"); ?>
298
</body>
299
</html>
(58-58/246)