Project

General

Profile

Download (6.5 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-2020 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
init_config_arr(array('aliases', 'alias'));
42
$a_aliases = &$config['aliases']['alias'];
43

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

    
46
if ($_POST['apply']) {
47
	$retval = 0;
48

    
49
	/* reload all components that use aliases */
50
	$retval |= filter_configure();
51

    
52
	if ($retval == 0) {
53
		clear_subsystem_dirty('aliases');
54
	}
55
}
56

    
57

    
58
if ($_POST['act'] == "del") {
59
	$delete_error = deleteAlias($_POST['id']);
60

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

    
67
$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
	if ($dtab[1] == true) {
75
		$bctab = $dtab[0];
76
		break;
77
	}
78
}
79

    
80
$pgtitle = array(gettext("Firewall"), gettext("Aliases"), $bctab);
81
$pglinks = array("", "firewall_aliases.php", "@self");
82
$shortcut_section = "aliases";
83

    
84
include("head.inc");
85

    
86
if ($delete_error) {
87
	print_info_box($delete_error, 'danger');
88
}
89
if ($_POST['apply']) {
90
	print_apply_result_box($retval);
91
}
92

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

    
97
display_top_tabs($tab_array);
98

    
99
?>
100

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

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

    
188
	</div>
189
</div>
190

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

    
208
<!-- 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
	<div class="infoblock">
212
		<?php print_info_box(gettext('Aliases act as placeholders for real hosts, networks or ports. They can be used to minimize the number ' .
213
			'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
	</div>
217
</div>
218

    
219
<?php
220
include("foot.inc");
(39-39/229)