Project

General

Profile

Download (6.56 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 8f2f85c3 Luiz Otavio O Souza
 * Copyright (c) 2014-2022 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 c6c398c6 jim-p
init_config_arr(array('aliases', 'alias'));
42 5b237745 Scott Ullrich
$a_aliases = &$config['aliases']['alias'];
43
44 6c07db48 Phil Davis
$tab = ($_REQUEST['tab'] == "" ? "ip" : preg_replace("/\W/", "", $_REQUEST['tab']));
45 5b237745 Scott Ullrich
46 d1fd8c3b Steve Beaver
if ($_POST['apply']) {
47
	$retval = 0;
48 920b3bb0 Scott Ullrich
49 d1fd8c3b Steve Beaver
	/* reload all components that use aliases */
50
	$retval |= filter_configure();
51 920b3bb0 Scott Ullrich
52 d1fd8c3b Steve Beaver
	if ($retval == 0) {
53
		clear_subsystem_dirty('aliases');
54 5b237745 Scott Ullrich
	}
55
}
56
57 d1fd8c3b Steve Beaver
58
if ($_POST['act'] == "del") {
59 a903e9a6 Steve Beaver
	$delete_error = deleteAlias($_POST['id']);
60 c769f983 Erik Fonnesbeck
61 a903e9a6 Steve Beaver
	if (strlen($delete_error) == 0) {
62
		header("Location: firewall_aliases.php?tab=" . $tab);
63
		exit;
64 c769f983 Erik Fonnesbeck
	}
65
}
66
67 e1515be9 Stephen Beaver
$tab_array = array();
68
$tab_array[] = array(gettext("IP"),    ($tab == "ip" ? true : ($tab == "host" ? true : ($tab == "network" ? true : false))), "/firewall_aliases.php?tab=ip");
69
$tab_array[] = array(gettext("Ports"), ($tab == "port"? true : false), "/firewall_aliases.php?tab=port");
70
$tab_array[] = array(gettext("URLs"),  ($tab == "url"? true : false), "/firewall_aliases.php?tab=url");
71
$tab_array[] = array(gettext("All"),   ($tab == "all"? true : false), "/firewall_aliases.php?tab=all");
72
73
foreach ($tab_array as $dtab) {
74 67c2baf1 Phil Davis
	if ($dtab[1] == true) {
75 e1515be9 Stephen Beaver
		$bctab = $dtab[0];
76
		break;
77
	}
78
}
79
80
$pgtitle = array(gettext("Firewall"), gettext("Aliases"), $bctab);
81 edcd7535 Phil Davis
$pglinks = array("", "firewall_aliases.php", "@self");
82 d71fc5d3 jim-p
$shortcut_section = "aliases";
83
84 b63695db Scott Ullrich
include("head.inc");
85
86 44c42356 Phil Davis
if ($delete_error) {
87
	print_info_box($delete_error, 'danger');
88
}
89
if ($_POST['apply']) {
90
	print_apply_result_box($retval);
91 67c2baf1 Phil Davis
}
92 6cb366de Stephen Beaver
93 67c2baf1 Phil Davis
if (is_subsystem_dirty('aliases')) {
94 381ad9f3 NOYB
	print_apply_box(gettext("The alias list has been changed.") . "<br />" . gettext("The changes must be applied for them to take effect."));
95 67c2baf1 Phil Davis
}
96 14726356 Sjon Hortensius
97
display_top_tabs($tab_array);
98
99 5b237745 Scott Ullrich
?>
100 b40fb789 Colin Fleming
101
<div class="panel panel-default">
102 7d95365e Phil Davis
	<div class="panel-heading"><h2 class="panel-title"><?=sprintf(gettext('Firewall Aliases %s'), $bctab)?></h2></div>
103 b40fb789 Colin Fleming
	<div class="panel-body">
104
105 0ce45fdf Sander van Leeuwen
<div class="table-responsive">
106 250061b0 Stephen Beaver
<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" data-sortable>
107 14726356 Sjon Hortensius
	<thead>
108
		<tr>
109 0ce45fdf Sander van Leeuwen
			<th><?=gettext("Name")?></th>
110
			<th><?=gettext("Values")?></th>
111
			<th><?=gettext("Description")?></th>
112 af5e730b Stephen Beaver
			<th><?=gettext("Actions")?></th>
113 14726356 Sjon Hortensius
		</tr>
114
	</thead>
115
	<tbody>
116
<?php
117
	asort($a_aliases);
118 e6f34d22 Phil Davis
	foreach ($a_aliases as $i => $alias):
119 14726356 Sjon Hortensius
		unset ($show_alias);
120 e6f34d22 Phil Davis
		switch ($tab) {
121 14726356 Sjon Hortensius
		case "all":
122
			$show_alias= true;
123
			break;
124
		case "ip":
125
		case "host":
126
		case "network":
127 67c2baf1 Phil Davis
			if (preg_match("/(host|network)/", $alias["type"])) {
128 14726356 Sjon Hortensius
				$show_alias= true;
129 67c2baf1 Phil Davis
			}
130 14726356 Sjon Hortensius
			break;
131
		case "url":
132 67c2baf1 Phil Davis
			if (preg_match("/(url)/i", $alias["type"])) {
133 14726356 Sjon Hortensius
				$show_alias= true;
134 67c2baf1 Phil Davis
			}
135 14726356 Sjon Hortensius
			break;
136
		case "port":
137 67c2baf1 Phil Davis
			if ($alias["type"] == "port") {
138 14726356 Sjon Hortensius
				$show_alias= true;
139 67c2baf1 Phil Davis
			}
140 14726356 Sjon Hortensius
			break;
141
		}
142
		if ($show_alias):
143
?>
144
		<tr>
145 f9a2b76d Stephen Beaver
			<td ondblclick="document.location='firewall_aliases_edit.php?id=<?=$i;?>';">
146 14726356 Sjon Hortensius
				<?=htmlspecialchars($alias['name'])?>
147
			</td>
148 f9a2b76d Stephen Beaver
			<td ondblclick="document.location='firewall_aliases_edit.php?id=<?=$i;?>';">
149 14726356 Sjon Hortensius
<?php
150
	if ($alias["url"]) {
151 ac6e07b5 jim-p
		echo htmlspecialchars($alias["url"]) . "<br />";
152 14726356 Sjon Hortensius
	} else {
153 e6f34d22 Phil Davis
		if (is_array($alias["aliasurl"])) {
154 14726356 Sjon Hortensius
			$aliasurls = implode(", ", array_slice($alias["aliasurl"], 0, 10));
155 ac6e07b5 jim-p
			echo htmlspecialchars($aliasurls);
156 d6d46650 Steve Beaver
			if (is_array($aliasurls) && (count($aliasurls) > 10)) {
157 14726356 Sjon Hortensius
				echo "&hellip;<br />";
158
			}
159
			echo "<br />\n";
160
		}
161 314f7804 Viktor G
		$tmpaddr = explode(" ", $alias['address']);
162
		if ($alias['type'] == 'host') {
163
			$tmpaddr = array_map('alias_idn_to_utf8', $tmpaddr);
164
		}
165 14726356 Sjon Hortensius
		$addresses = implode(", ", array_slice($tmpaddr, 0, 10));
166 ac6e07b5 jim-p
		echo htmlspecialchars($addresses);
167 e6f34d22 Phil Davis
		if (count($tmpaddr) > 10) {
168 14726356 Sjon Hortensius
			echo '&hellip;';
169
		}
170
	}
171
?>
172
			</td>
173 f9a2b76d Stephen Beaver
			<td ondblclick="document.location='firewall_aliases_edit.php?id=<?=$i;?>';">
174 14726356 Sjon Hortensius
				<?=htmlspecialchars($alias['descr'])?>&nbsp;
175
			</td>
176
			<td>
177 84147b7b Steve Beaver
				<a class="fa fa-pencil" title="<?=gettext("Edit alias"); ?>" href="firewall_aliases_edit.php?id=<?=$i?>"></a>
178 6978b39e Viktor G
				<a class="fa fa-clone" title="<?=gettext('Copy alias')?>" href="firewall_aliases_edit.php?dup=<?=$i;?>" ></a>
179 d1fd8c3b Steve Beaver
				<a class="fa fa-trash"	title="<?=gettext("Delete alias")?>" href="?act=del&amp;tab=<?=$tab?>&amp;id=<?=$i?>" usepost></a>
180 df4957e4 Stephen Beaver
			</td>
181
		</tr>
182 14726356 Sjon Hortensius
<?php endif?>
183
<?php endforeach?>
184
	</tbody>
185
</table>
186 0ce45fdf Sander van Leeuwen
</div>
187 5b237745 Scott Ullrich
188 ac950976 Colin Fleming
	</div>
189
</div>
190 b40fb789 Colin Fleming
191 c10cb196 Stephen Beaver
<nav class="action-buttons">
192 84147b7b Steve Beaver
	<a href="firewall_aliases_edit.php?tab=<?=$tab?>" role="button" class="btn btn-success btn-sm">
193 9d5a20cf heper
		<i class="fa fa-plus icon-embed-btn"></i>
194 df4957e4 Stephen Beaver
		<?=gettext("Add");?>
195 11486640 Sjon Hortensius
	</a>
196 e4c784bf Phil Davis
<?php
197
if (($tab == "ip") || ($tab == "port") || ($tab == "all")):
198
?>
199 84147b7b Steve Beaver
	<a href="firewall_aliases_import.php?tab=<?=$tab?>" role="button" class="btn btn-primary btn-sm">
200 c933c798 jim-p
		<i class="fa fa-upload icon-embed-btn"></i>
201 df4957e4 Stephen Beaver
		<?=gettext("Import");?>
202 11486640 Sjon Hortensius
	</a>
203 e4c784bf Phil Davis
<?php
204
endif
205
?>
206 11486640 Sjon Hortensius
</nav>
207 0f89c125 marcelloc
208 df4957e4 Stephen Beaver
<!-- Information section. Icon ID must be "showinfo" and the information <div> ID must be "infoblock".
209
	 That way jQuery (in pfenseHelpers.js) will automatically take care of the display. -->
210
<div>
211 35681930 Stephen Beaver
	<div class="infoblock">
212 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 ' .
213 1a147fcd Phil Davis
			'of changes that have to be made if a host, network or port changes.') . '<br />' .
214
			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 />' .
215
			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); ?>
216 df4957e4 Stephen Beaver
	</div>
217
</div>
218 0f89c125 marcelloc
219 df4957e4 Stephen Beaver
<?php
220 5932fc6a heper
include("foot.inc");