Project

General

Profile

Download (6.68 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-2023 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("Values")?></th>
108
			<th><?=gettext("Description")?></th>
109
			<th><?=gettext("Actions")?></th>
110
		</tr>
111
	</thead>
112
	<tbody>
113
<?php
114
	/* Ensure aliases are presented in natural sort order so they are easier to locate.
115
	 * and preserve keys so that the IDs match in the config and the list.
116
	 * https://redmine.pfsense.org/issues/14015 */
117
	$aliases = get_sorted_aliases();
118

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

    
189
	</div>
190
</div>
191

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

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

    
220
<?php
221
include("foot.inc");
(39-39/228)