Project

General

Profile

Download (6.9 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
 * firewall_aliases.php
4
 *
5
 * part of pfSense (https://www.pfsense.org)
6
 * Copyright (c) 2004-2013 BSD Perimeter
7
 * Copyright (c) 2013-2016 Electric Sheep Fencing
8
 * Copyright (c) 2014-2024 Rubicon Communications, LLC (Netgate)
9
 * All rights reserved.
10
 *
11
 * originally based on m0n0wall (http://m0n0.ch/wall)
12
 * Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net>.
13
 * All rights reserved.
14
 *
15
 * 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
 *
19
 * http://www.apache.org/licenses/LICENSE-2.0
20
 *
21
 * 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
 */
27

    
28
##|+PRIV
29
##|*IDENT=page-firewall-aliases
30
##|*NAME=Firewall: Aliases
31
##|*DESCR=Allow access to the 'Firewall: Aliases' page.
32
##|*MATCH=firewall_aliases.php*
33
##|-PRIV
34

    
35
require_once("guiconfig.inc");
36
require_once("functions.inc");
37
require_once("filter.inc");
38
require_once("shaper.inc");
39
require_once("alias-utils.inc");
40

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

    
43
if ($_POST['apply']) {
44
	$retval = 0;
45

    
46
	/* reload all components that use aliases */
47
	$retval |= filter_configure();
48

    
49
	if ($retval == 0) {
50
		clear_subsystem_dirty('aliases');
51
	}
52
}
53

    
54

    
55
if ($_POST['act'] == "del") {
56
	$delete_error = deleteAlias($_POST['id']);
57

    
58
	if (strlen($delete_error) == 0) {
59
		header("Location: firewall_aliases.php?tab=" . $tab);
60
		exit;
61
	}
62
}
63

    
64
$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
	if ($dtab[1] == true) {
72
		$bctab = $dtab[0];
73
		break;
74
	}
75
}
76

    
77
$pgtitle = array(gettext("Firewall"), gettext("Aliases"), $bctab);
78
$pglinks = array("", "firewall_aliases.php", "@self");
79
$shortcut_section = "aliases";
80

    
81
include("head.inc");
82

    
83
if ($delete_error) {
84
	print_info_box($delete_error, 'danger');
85
}
86
if ($_POST['apply']) {
87
	print_apply_result_box($retval);
88
}
89

    
90
if (is_subsystem_dirty('aliases')) {
91
	print_apply_box(gettext("The alias list has been changed.") . "<br />" . gettext("The changes must be applied for them to take effect."));
92
}
93

    
94
display_top_tabs($tab_array);
95

    
96
?>
97

    
98
<div class="panel panel-default">
99
	<div class="panel-heading"><h2 class="panel-title"><?=sprintf(gettext('Firewall Aliases %s'), $bctab)?></h2></div>
100
	<div class="panel-body">
101

    
102
<div class="table-responsive">
103
<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" data-sortable>
104
	<thead>
105
		<tr>
106
			<th><?=gettext("Name")?></th>
107
			<th><?=gettext("Type")?></th>
108
			<th><?=gettext("Values")?></th>
109
			<th><?=gettext("Description")?></th>
110
			<th><?=gettext("Actions")?></th>
111
		</tr>
112
	</thead>
113
	<tbody>
114
<?php
115
	/* Ensure aliases are presented in natural sort order so they are easier to locate.
116
	 * and preserve keys so that the IDs match in the config and the list.
117
	 * https://redmine.pfsense.org/issues/14015 */
118
	$aliases = get_sorted_aliases();
119

    
120
	foreach ($aliases as $i => $alias):
121
		unset($show_alias);
122
		switch ($tab) {
123
		case "all":
124
			$show_alias= true;
125
			break;
126
		case "ip":
127
		case "host":
128
		case "network":
129
			if (preg_match("/(host|network)/", $alias["type"])) {
130
				$show_alias= true;
131
			}
132
			break;
133
		case "url":
134
			if (preg_match("/(url)/i", $alias["type"])) {
135
				$show_alias= true;
136
			}
137
			break;
138
		case "port":
139
			if ($alias["type"] == "port") {
140
				$show_alias= true;
141
			}
142
			break;
143
		}
144
		if ($show_alias):
145
?>
146
		<tr>
147
			<td ondblclick="document.location='firewall_aliases_edit.php?id=<?=$i;?>';">
148
				<?=htmlspecialchars($alias['name'])?>
149
			</td>
150
			<td nowrap ondblclick="document.location='firewall_aliases_edit.php?id=<?=$i;?>';">
151
				<?=htmlspecialchars($alias_types[$alias['type']])?>
152
			</td>
153
			<td ondblclick="document.location='firewall_aliases_edit.php?id=<?=$i;?>';">
154
<?php
155
	if ($alias["url"]) {
156
		echo htmlspecialchars($alias["url"]) . "<br />";
157
	} else {
158
		if (is_array($alias["aliasurl"])) {
159
			$aliasurls = implode(", ", array_slice($alias["aliasurl"], 0, 10));
160
			echo htmlspecialchars($aliasurls);
161
			if (is_array($aliasurls) && (count($aliasurls) > 10)) {
162
				echo "&hellip;<br />";
163
			}
164
			echo "<br />\n";
165
		}
166
		$tmpaddr = explode(" ", $alias['address']);
167
		if ($alias['type'] == 'host') {
168
			$tmpaddr = array_map('alias_idn_to_utf8', $tmpaddr);
169
		}
170
		$addresses = implode(", ", array_slice($tmpaddr, 0, 10));
171
		echo htmlspecialchars($addresses);
172
		if (count($tmpaddr) > 10) {
173
			echo '&hellip;';
174
		}
175
	}
176
?>
177
			</td>
178
			<td ondblclick="document.location='firewall_aliases_edit.php?id=<?=$i;?>';">
179
				<?=htmlspecialchars($alias['descr'])?>&nbsp;
180
			</td>
181
			<td>
182
				<a class="fa-solid fa-pencil" title="<?=gettext("Edit alias"); ?>" href="firewall_aliases_edit.php?id=<?=$i?>"></a>
183
				<a class="fa-regular fa-clone" title="<?=gettext('Copy alias')?>" href="firewall_aliases_edit.php?dup=<?=$i;?>" ></a>
184
				<a class="fa-solid fa-trash-can"	title="<?=gettext("Delete alias")?>" href="?act=del&amp;tab=<?=$tab?>&amp;id=<?=$i?>" usepost></a>
185
			</td>
186
		</tr>
187
<?php endif?>
188
<?php endforeach?>
189
	</tbody>
190
</table>
191
</div>
192

    
193
	</div>
194
</div>
195

    
196
<nav class="action-buttons">
197
	<a href="firewall_aliases_edit.php?tab=<?=$tab?>" role="button" class="btn btn-success btn-sm">
198
		<i class="fa-solid fa-plus icon-embed-btn"></i>
199
		<?=gettext("Add");?>
200
	</a>
201
<?php
202
if (($tab == "ip") || ($tab == "port") || ($tab == "all")):
203
?>
204
	<a href="firewall_aliases_import.php?tab=<?=$tab?>" role="button" class="btn btn-primary btn-sm">
205
		<i class="fa-solid fa-upload icon-embed-btn"></i>
206
		<?=gettext("Import");?>
207
	</a>
208
<?php
209
endif
210
?>
211
</nav>
212

    
213
<!-- Information section. Icon ID must be "showinfo" and the information <div> ID must be "infoblock".
214
	 That way jQuery (in pfenseHelpers.js) will automatically take care of the display. -->
215
<div>
216
	<div class="infoblock">
217
		<?php print_info_box(gettext('Aliases act as placeholders for real hosts, networks or ports. They can be used to minimize the number ' .
218
			'of changes that have to be made if a host, network or port changes.') . '<br />' .
219
			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 />' .
220
			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); ?>
221
	</div>
222
</div>
223

    
224
<?php
225
include("foot.inc");
(41-41/230)