Project

General

Profile

Download (8.6 KB) Statistics
| Branch: | Tag: | Revision:
1 5b237745 Scott Ullrich
<?php
2
/*
3 c5d81585 Renato Botelho
 * firewall_aliases.php
4 9da2cf1c Stephen Beaver
 *
5 c5d81585 Renato Botelho
 * part of pfSense (https://www.pfsense.org)
6 38809d47 Renato Botelho do Couto
 * Copyright (c) 2004-2013 BSD Perimeter
7
 * Copyright (c) 2013-2016 Electric Sheep Fencing
8 a68f7a3d Luiz Otavio O Souza
 * Copyright (c) 2014-2024 Rubicon Communications, LLC (Netgate)
9 c5d81585 Renato Botelho
 * All rights reserved.
10 fd9ebcd5 Stephen Beaver
 *
11 c5d81585 Renato Botelho
 * originally based on m0n0wall (http://m0n0.ch/wall)
12
 * Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net>.
13
 * All rights reserved.
14 fd9ebcd5 Stephen Beaver
 *
15 b12ea3fb Renato Botelho
 * Licensed under the Apache License, Version 2.0 (the "License");
16
 * you may not use this file except in compliance with the License.
17
 * You may obtain a copy of the License at
18 fd9ebcd5 Stephen Beaver
 *
19 b12ea3fb Renato Botelho
 * http://www.apache.org/licenses/LICENSE-2.0
20 fd9ebcd5 Stephen Beaver
 *
21 b12ea3fb Renato Botelho
 * Unless required by applicable law or agreed to in writing, software
22
 * distributed under the License is distributed on an "AS IS" BASIS,
23
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24
 * See the License for the specific language governing permissions and
25
 * limitations under the License.
26 fd9ebcd5 Stephen Beaver
 */
27 5b237745 Scott Ullrich
28 6b07c15a Matthew Grooms
##|+PRIV
29
##|*IDENT=page-firewall-aliases
30 5230f468 jim-p
##|*NAME=Firewall: Aliases
31 6b07c15a Matthew Grooms
##|*DESCR=Allow access to the 'Firewall: Aliases' page.
32
##|*MATCH=firewall_aliases.php*
33
##|-PRIV
34
35 c81ef6e2 Phil Davis
require_once("guiconfig.inc");
36 7a927e67 Scott Ullrich
require_once("functions.inc");
37
require_once("filter.inc");
38
require_once("shaper.inc");
39 be14a369 Steve Beaver
require_once("alias-utils.inc");
40 5b237745 Scott Ullrich
41 6c07db48 Phil Davis
$tab = ($_REQUEST['tab'] == "" ? "ip" : preg_replace("/\W/", "", $_REQUEST['tab']));
42 5b237745 Scott Ullrich
43 d1fd8c3b Steve Beaver
if ($_POST['apply']) {
44
	$retval = 0;
45 920b3bb0 Scott Ullrich
46 d1fd8c3b Steve Beaver
	/* reload all components that use aliases */
47
	$retval |= filter_configure();
48 920b3bb0 Scott Ullrich
49 d1fd8c3b Steve Beaver
	if ($retval == 0) {
50
		clear_subsystem_dirty('aliases');
51 5b237745 Scott Ullrich
	}
52
}
53
54 d1fd8c3b Steve Beaver
55
if ($_POST['act'] == "del") {
56 a903e9a6 Steve Beaver
	$delete_error = deleteAlias($_POST['id']);
57 c769f983 Erik Fonnesbeck
58 a903e9a6 Steve Beaver
	if (strlen($delete_error) == 0) {
59
		header("Location: firewall_aliases.php?tab=" . $tab);
60
		exit;
61 c769f983 Erik Fonnesbeck
	}
62
}
63
64 e1515be9 Stephen Beaver
$tab_array = array();
65
$tab_array[] = array(gettext("IP"),    ($tab == "ip" ? true : ($tab == "host" ? true : ($tab == "network" ? true : false))), "/firewall_aliases.php?tab=ip");
66
$tab_array[] = array(gettext("Ports"), ($tab == "port"? true : false), "/firewall_aliases.php?tab=port");
67
$tab_array[] = array(gettext("URLs"),  ($tab == "url"? true : false), "/firewall_aliases.php?tab=url");
68
$tab_array[] = array(gettext("All"),   ($tab == "all"? true : false), "/firewall_aliases.php?tab=all");
69
70
foreach ($tab_array as $dtab) {
71 67c2baf1 Phil Davis
	if ($dtab[1] == true) {
72 e1515be9 Stephen Beaver
		$bctab = $dtab[0];
73
		break;
74
	}
75
}
76
77
$pgtitle = array(gettext("Firewall"), gettext("Aliases"), $bctab);
78 edcd7535 Phil Davis
$pglinks = array("", "firewall_aliases.php", "@self");
79 d71fc5d3 jim-p
$shortcut_section = "aliases";
80
81 b63695db Scott Ullrich
include("head.inc");
82
83 44c42356 Phil Davis
if ($delete_error) {
84
	print_info_box($delete_error, 'danger');
85
}
86
if ($_POST['apply']) {
87
	print_apply_result_box($retval);
88 67c2baf1 Phil Davis
}
89 6cb366de Stephen Beaver
90 67c2baf1 Phil Davis
if (is_subsystem_dirty('aliases')) {
91 381ad9f3 NOYB
	print_apply_box(gettext("The alias list has been changed.") . "<br />" . gettext("The changes must be applied for them to take effect."));
92 67c2baf1 Phil Davis
}
93 14726356 Sjon Hortensius
94
display_top_tabs($tab_array);
95
96 35c1ebd0 Marcos Mendoza
/* Show system aliases. */
97
if ($tab == 'all'):
98
	?>
99
	<div class="panel panel-default">
100
		<div class="panel-heading"><h2 class="panel-title"><?=gettext('System Aliases')?></h2></div>
101
		<div class="panel-body"><div class="table-responsive">
102
			<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" data-sortable>
103
				<thead>
104
					<tr>
105
						<th><?=gettext("Name")?></th>
106
						<th><?=gettext("Type")?></th>
107
						<th><?=gettext("Description")?></th>
108
						<th><?=gettext("Values")?></th>
109
					</tr>
110
				</thead>
111
				<tbody>
112
	<?php
113
	$system_aliases = get_reserved_table_names();
114
	foreach ($system_aliases as $alias):
115
	?>
116
					<tr>
117
						<td>
118
							<?=htmlspecialchars($alias['name'])?>
119
						</td>
120
						<td>
121
							<?=htmlspecialchars($alias_types[$alias['type']])?>
122
						</td>
123
						<td>
124
							<?=htmlspecialchars($alias['descr'])?>&nbsp;
125
						</td>
126
						<td>
127
		<?php
128
		if ($alias["url"]) {
129
			echo htmlspecialchars($alias["url"]);
130
		} elseif (is_array($alias["aliasurl"])) {
131
			$aliasurls = implode(", ", array_slice($alias["aliasurl"], 0, 10));
132
			echo htmlspecialchars($aliasurls);
133
			if (is_array($aliasurls) && (count($aliasurls) > 10)) {
134
				echo "&hellip;";
135
			}
136
		} elseif (!empty($alias['address'])) {
137
			$tmpaddr = explode(" ", $alias['address']);
138
			if ($alias['type'] == 'host') {
139
				$tmpaddr = array_map('alias_idn_to_utf8', $tmpaddr);
140
			}
141
			echo htmlspecialchars(implode(", ", array_slice($tmpaddr, 0, 10)));
142
			if (count($tmpaddr) > 10) {
143
				echo '&hellip;';
144
			}
145
		} else {
146
			?>
147
							<span style="font-style:italic;"><?=gettext('Values set dynamically.')?>
148
			<?php
149
		}
150
		?>
151
						</td>
152
					</tr>
153
	<?php
154
	endforeach;
155
	?>
156
				</tbody>
157
			</table>
158
		</div></div>
159
	</div>
160 05a43510 jim-p
	<?php
161 35c1ebd0 Marcos Mendoza
endif;
162 5b237745 Scott Ullrich
?>
163 b40fb789 Colin Fleming
164
<div class="panel panel-default">
165 7d95365e Phil Davis
	<div class="panel-heading"><h2 class="panel-title"><?=sprintf(gettext('Firewall Aliases %s'), $bctab)?></h2></div>
166 b40fb789 Colin Fleming
	<div class="panel-body">
167
168 0ce45fdf Sander van Leeuwen
<div class="table-responsive">
169 250061b0 Stephen Beaver
<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" data-sortable>
170 14726356 Sjon Hortensius
	<thead>
171
		<tr>
172 0ce45fdf Sander van Leeuwen
			<th><?=gettext("Name")?></th>
173 33cd2690 jim-p
			<th><?=gettext("Type")?></th>
174 0ce45fdf Sander van Leeuwen
			<th><?=gettext("Values")?></th>
175
			<th><?=gettext("Description")?></th>
176 af5e730b Stephen Beaver
			<th><?=gettext("Actions")?></th>
177 14726356 Sjon Hortensius
		</tr>
178
	</thead>
179
	<tbody>
180
<?php
181 5c4a6ada jim-p
	/* Ensure aliases are presented in natural sort order so they are easier to locate.
182
	 * and preserve keys so that the IDs match in the config and the list.
183
	 * https://redmine.pfsense.org/issues/14015 */
184
	$aliases = get_sorted_aliases();
185
186 29cd08ea Christian McDonald
	foreach ($aliases as $i => $alias):
187
		unset($show_alias);
188 e6f34d22 Phil Davis
		switch ($tab) {
189 14726356 Sjon Hortensius
		case "all":
190
			$show_alias= true;
191
			break;
192
		case "ip":
193
		case "host":
194
		case "network":
195 67c2baf1 Phil Davis
			if (preg_match("/(host|network)/", $alias["type"])) {
196 14726356 Sjon Hortensius
				$show_alias= true;
197 67c2baf1 Phil Davis
			}
198 14726356 Sjon Hortensius
			break;
199
		case "url":
200 67c2baf1 Phil Davis
			if (preg_match("/(url)/i", $alias["type"])) {
201 14726356 Sjon Hortensius
				$show_alias= true;
202 67c2baf1 Phil Davis
			}
203 14726356 Sjon Hortensius
			break;
204
		case "port":
205 67c2baf1 Phil Davis
			if ($alias["type"] == "port") {
206 14726356 Sjon Hortensius
				$show_alias= true;
207 67c2baf1 Phil Davis
			}
208 14726356 Sjon Hortensius
			break;
209
		}
210
		if ($show_alias):
211
?>
212
		<tr>
213 f9a2b76d Stephen Beaver
			<td ondblclick="document.location='firewall_aliases_edit.php?id=<?=$i;?>';">
214 14726356 Sjon Hortensius
				<?=htmlspecialchars($alias['name'])?>
215
			</td>
216 33cd2690 jim-p
			<td nowrap ondblclick="document.location='firewall_aliases_edit.php?id=<?=$i;?>';">
217
				<?=htmlspecialchars($alias_types[$alias['type']])?>
218
			</td>
219 f9a2b76d Stephen Beaver
			<td ondblclick="document.location='firewall_aliases_edit.php?id=<?=$i;?>';">
220 14726356 Sjon Hortensius
<?php
221
	if ($alias["url"]) {
222 ac6e07b5 jim-p
		echo htmlspecialchars($alias["url"]) . "<br />";
223 14726356 Sjon Hortensius
	} else {
224 e6f34d22 Phil Davis
		if (is_array($alias["aliasurl"])) {
225 14726356 Sjon Hortensius
			$aliasurls = implode(", ", array_slice($alias["aliasurl"], 0, 10));
226 ac6e07b5 jim-p
			echo htmlspecialchars($aliasurls);
227 d6d46650 Steve Beaver
			if (is_array($aliasurls) && (count($aliasurls) > 10)) {
228 14726356 Sjon Hortensius
				echo "&hellip;<br />";
229
			}
230
			echo "<br />\n";
231
		}
232 314f7804 Viktor G
		$tmpaddr = explode(" ", $alias['address']);
233
		if ($alias['type'] == 'host') {
234
			$tmpaddr = array_map('alias_idn_to_utf8', $tmpaddr);
235
		}
236 14726356 Sjon Hortensius
		$addresses = implode(", ", array_slice($tmpaddr, 0, 10));
237 ac6e07b5 jim-p
		echo htmlspecialchars($addresses);
238 e6f34d22 Phil Davis
		if (count($tmpaddr) > 10) {
239 14726356 Sjon Hortensius
			echo '&hellip;';
240
		}
241
	}
242
?>
243
			</td>
244 f9a2b76d Stephen Beaver
			<td ondblclick="document.location='firewall_aliases_edit.php?id=<?=$i;?>';">
245 14726356 Sjon Hortensius
				<?=htmlspecialchars($alias['descr'])?>&nbsp;
246
			</td>
247
			<td>
248 e0cb987c Marcos Mendoza
				<a class="fa-solid fa-pencil" title="<?=gettext("Edit alias"); ?>" href="firewall_aliases_edit.php?id=<?=$i?>"></a>
249 c1d304b3 Marcos Mendoza
				<a class="fa-regular fa-clone" title="<?=gettext('Copy alias')?>" href="firewall_aliases_edit.php?dup=<?=$i;?>" ></a>
250
				<a class="fa-solid fa-trash-can"	title="<?=gettext("Delete alias")?>" href="?act=del&amp;tab=<?=$tab?>&amp;id=<?=$i?>" usepost></a>
251 df4957e4 Stephen Beaver
			</td>
252
		</tr>
253 14726356 Sjon Hortensius
<?php endif?>
254
<?php endforeach?>
255
	</tbody>
256
</table>
257 0ce45fdf Sander van Leeuwen
</div>
258 5b237745 Scott Ullrich
259 ac950976 Colin Fleming
	</div>
260
</div>
261 b40fb789 Colin Fleming
262 c10cb196 Stephen Beaver
<nav class="action-buttons">
263 84147b7b Steve Beaver
	<a href="firewall_aliases_edit.php?tab=<?=$tab?>" role="button" class="btn btn-success btn-sm">
264 e0cb987c Marcos Mendoza
		<i class="fa-solid fa-plus icon-embed-btn"></i>
265 df4957e4 Stephen Beaver
		<?=gettext("Add");?>
266 11486640 Sjon Hortensius
	</a>
267 e4c784bf Phil Davis
<?php
268
if (($tab == "ip") || ($tab == "port") || ($tab == "all")):
269
?>
270 84147b7b Steve Beaver
	<a href="firewall_aliases_import.php?tab=<?=$tab?>" role="button" class="btn btn-primary btn-sm">
271 e0cb987c Marcos Mendoza
		<i class="fa-solid fa-upload icon-embed-btn"></i>
272 df4957e4 Stephen Beaver
		<?=gettext("Import");?>
273 11486640 Sjon Hortensius
	</a>
274 e4c784bf Phil Davis
<?php
275
endif
276
?>
277 11486640 Sjon Hortensius
</nav>
278 0f89c125 marcelloc
279 df4957e4 Stephen Beaver
<!-- Information section. Icon ID must be "showinfo" and the information <div> ID must be "infoblock".
280
	 That way jQuery (in pfenseHelpers.js) will automatically take care of the display. -->
281
<div>
282 35681930 Stephen Beaver
	<div class="infoblock">
283 f6aebbcc NewEraCracker
		<?php print_info_box(gettext('Aliases act as placeholders for real hosts, networks or ports. They can be used to minimize the number ' .
284 1a147fcd Phil Davis
			'of changes that have to be made if a host, network or port changes.') . '<br />' .
285
			gettext('The name of an alias can be entered instead of the host, network or port where indicated. The alias will be resolved according to the list above.') . '<br />' .
286
			gettext('If an alias cannot be resolved (e.g. because it was deleted), the corresponding element (e.g. filter/NAT/shaper rule) will be considered invalid and skipped.'), 'info', false); ?>
287 df4957e4 Stephen Beaver
	</div>
288
</div>
289 0f89c125 marcelloc
290 df4957e4 Stephen Beaver
<?php
291 5932fc6a heper
include("foot.inc");