Project

General

Profile

Download (12.3 KB) Statistics
| Branch: | Tag: | Revision:
1 5b237745 Scott Ullrich
<?php
2 b46bfcf5 Bill Marquette
/* $Id$ */
3 5b237745 Scott Ullrich
/*
4
	firewall_aliases.php
5 4d875b4f Scott Ullrich
	Copyright (C) 2004 Scott Ullrich
6
	All rights reserved.
7 f0fe3d30 Scott Ullrich
8 4d875b4f Scott Ullrich
	originially part of m0n0wall (http://m0n0.ch/wall)
9 5b237745 Scott Ullrich
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
10
	All rights reserved.
11 f0fe3d30 Scott Ullrich
12 5b237745 Scott Ullrich
	Redistribution and use in source and binary forms, with or without
13
	modification, are permitted provided that the following conditions are met:
14 f0fe3d30 Scott Ullrich
15 5b237745 Scott Ullrich
	1. Redistributions of source code must retain the above copyright notice,
16
	   this list of conditions and the following disclaimer.
17 f0fe3d30 Scott Ullrich
18 5b237745 Scott Ullrich
	2. Redistributions in binary form must reproduce the above copyright
19
	   notice, this list of conditions and the following disclaimer in the
20
	   documentation and/or other materials provided with the distribution.
21 f0fe3d30 Scott Ullrich
22 5b237745 Scott Ullrich
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
23
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
24
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
26
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31
	POSSIBILITY OF SUCH DAMAGE.
32
*/
33 7ac5a4cb Scott Ullrich
/*
34
	pfSense_MODULE:	aliases
35
*/
36 5b237745 Scott Ullrich
37 6b07c15a Matthew Grooms
##|+PRIV
38
##|*IDENT=page-firewall-aliases
39
##|*NAME=Firewall: Aliases page
40
##|*DESCR=Allow access to the 'Firewall: Aliases' page.
41
##|*MATCH=firewall_aliases.php*
42
##|-PRIV
43
44 5b237745 Scott Ullrich
require("guiconfig.inc");
45 7a927e67 Scott Ullrich
require_once("functions.inc");
46
require_once("filter.inc");
47
require_once("shaper.inc");
48 5b237745 Scott Ullrich
49
if (!is_array($config['aliases']['alias']))
50
	$config['aliases']['alias'] = array();
51
$a_aliases = &$config['aliases']['alias'];
52
53
if ($_POST) {
54
55 a5416de2 Warren Baker
	if($_POST['tab'])
56
		$tab = $_POST['tab'];
57 5b237745 Scott Ullrich
58
	if ($_POST['apply']) {
59
		$retval = 0;
60 920b3bb0 Scott Ullrich
61
		/* reload all components that use aliases */
62
		$retval = filter_configure();
63
64 b2774343 Scott Ullrich
		if(stristr($retval, "error") <> true)
65
		    $savemsg = get_std_save_message($retval);
66
		else
67
		    $savemsg = $retval;
68 a368a026 Ermal Lu?i
		if ($retval == 0)
69
			clear_subsystem_dirty('aliases');
70 5b237745 Scott Ullrich
	}
71
}
72
73
if ($_GET['act'] == "del") {
74
	if ($a_aliases[$_GET['id']]) {
75 58c32a28 Scott Ullrich
		/* make sure rule is not being referenced by any nat or filter rules */
76
		$is_alias_referenced = false;
77
		$referenced_by = false;
78
		$alias_name = $a_aliases[$_GET['id']]['name'];
79 c769f983 Erik Fonnesbeck
		// Firewall rules
80
		find_alias_reference(array('filter', 'rule'), array('source', 'address'), $alias_name, $is_alias_referenced, $referenced_by);
81
		find_alias_reference(array('filter', 'rule'), array('destination', 'address'), $alias_name, $is_alias_referenced, $referenced_by);
82
		find_alias_reference(array('filter', 'rule'), array('source', 'port'), $alias_name, $is_alias_referenced, $referenced_by);
83
		find_alias_reference(array('filter', 'rule'), array('destination', 'port'), $alias_name, $is_alias_referenced, $referenced_by);
84
		// NAT Rules
85
		find_alias_reference(array('nat', 'rule'), array('source', 'address'), $alias_name, $is_alias_referenced, $referenced_by);
86
		find_alias_reference(array('nat', 'rule'), array('source', 'port'), $alias_name, $is_alias_referenced, $referenced_by);
87
		find_alias_reference(array('nat', 'rule'), array('destination', 'address'), $alias_name, $is_alias_referenced, $referenced_by);
88
		find_alias_reference(array('nat', 'rule'), array('destination', 'port'), $alias_name, $is_alias_referenced, $referenced_by);
89
		find_alias_reference(array('nat', 'rule'), array('target'), $alias_name, $is_alias_referenced, $referenced_by);
90
		find_alias_reference(array('nat', 'rule'), array('local-port'), $alias_name, $is_alias_referenced, $referenced_by);
91 b43b7613 Erik Fonnesbeck
		// NAT 1:1 Rules
92
		//find_alias_reference(array('nat', 'onetoone'), array('external'), $alias_name, $is_alias_referenced, $referenced_by);
93
		//find_alias_reference(array('nat', 'onetoone'), array('source', 'address'), $alias_name, $is_alias_referenced, $referenced_by);
94
		find_alias_reference(array('nat', 'onetoone'), array('destination', 'address'), $alias_name, $is_alias_referenced, $referenced_by);
95
		// NAT Outbound Rules
96
		find_alias_reference(array('nat', 'advancedoutbound', 'rule'), array('source', 'network'), $alias_name, $is_alias_referenced, $referenced_by);
97 ca640261 Erik Fonnesbeck
		find_alias_reference(array('nat', 'advancedoutbound', 'rule'), array('sourceport'), $alias_name, $is_alias_referenced, $referenced_by);
98 b43b7613 Erik Fonnesbeck
		find_alias_reference(array('nat', 'advancedoutbound', 'rule'), array('destination', 'address'), $alias_name, $is_alias_referenced, $referenced_by);
99 ca640261 Erik Fonnesbeck
		find_alias_reference(array('nat', 'advancedoutbound', 'rule'), array('dstport'), $alias_name, $is_alias_referenced, $referenced_by);
100 b43b7613 Erik Fonnesbeck
		find_alias_reference(array('nat', 'advancedoutbound', 'rule'), array('target'), $alias_name, $is_alias_referenced, $referenced_by);
101 c769f983 Erik Fonnesbeck
		// Alias in an alias
102
		find_alias_reference(array('aliases', 'alias'), array('address'), $alias_name, $is_alias_referenced, $referenced_by);
103 3df59bab Darren Embry
		// Load Balancer
104
		find_alias_reference(array('load_balancer', 'lbpool'),         array('port'), $alias_name, $is_alias_referenced, $referenced_by);
105
		find_alias_reference(array('load_balancer', 'virtual_server'), array('port'), $alias_name, $is_alias_referenced, $referenced_by);
106 58c32a28 Scott Ullrich
		if($is_alias_referenced == true) {
107 4b4d550a Chris Buechler
			$savemsg = sprintf(gettext("Cannot delete alias. Currently in use by %s"), $referenced_by);
108 58c32a28 Scott Ullrich
		} else {
109
			unset($a_aliases[$_GET['id']]);
110 3a343d73 jim-p
			if (write_config()) {
111
				filter_configure();
112
				mark_subsystem_dirty('aliases');
113
			}
114 58c32a28 Scott Ullrich
			header("Location: firewall_aliases.php");
115
			exit;
116
		}
117 5b237745 Scott Ullrich
	}
118
}
119 b63695db Scott Ullrich
120 c769f983 Erik Fonnesbeck
function find_alias_reference($section, $field, $origname, &$is_alias_referenced, &$referenced_by) {
121
	global $config;
122
	if(!$origname || $is_alias_referenced)
123
		return;
124
125
	$sectionref = &$config;
126
	foreach($section as $sectionname) {
127
		if(is_array($sectionref) && isset($sectionref[$sectionname]))
128
			$sectionref = &$sectionref[$sectionname];
129
		else
130
			return;
131
	}
132
133
	if(is_array($sectionref)) {
134
		foreach($sectionref as $itemkey => $item) {
135
			$fieldfound = true;
136
			$fieldref = &$sectionref[$itemkey];
137
			foreach($field as $fieldname) {
138
				if(is_array($fieldref) && isset($fieldref[$fieldname]))
139
					$fieldref = &$fieldref[$fieldname];
140
				else {
141
					$fieldfound = false;
142
					break;
143
				}
144
			}
145
			if($fieldfound && $fieldref == $origname) {
146
				$is_alias_referenced = true;
147
				if(is_array($item))
148
					$referenced_by = $item['descr'];
149
				break;
150
			}
151
		}
152
	}
153
}
154
155 9dc65295 Carlos Eduardo Ramos
$pgtitle = array(gettext("Firewall"),gettext("Aliases"));
156 d71fc5d3 jim-p
$shortcut_section = "aliases";
157
158 b63695db Scott Ullrich
include("head.inc");
159
160 5b237745 Scott Ullrich
?>
161
162
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
163
<?php include("fbegin.inc"); ?>
164
<form action="firewall_aliases.php" method="post">
165
<?php if ($savemsg) print_info_box($savemsg); ?>
166 a368a026 Ermal Lu?i
<?php if (is_subsystem_dirty('aliases')): ?><p>
167 808614b1 Renato Botelho
<?php print_info_box_np(gettext("The alias list has been changed.") . "<br>" . gettext("You must apply the changes in order for them to take effect."));?>
168 5b237745 Scott Ullrich
<?php endif; ?>
169 173d8e75 Scott Ullrich
<?php pfSense_handle_custom_code("/usr/local/pkg/firewall_aliases/pre_table"); ?>
170 0f89c125 marcelloc
<table width="100%" border="0" cellpadding="0" cellspacing="0" >
171 a5416de2 Warren Baker
	<tr>
172
		<td class="tabnavtbl">
173
			<?php
174
				$tab=($_REQUEST['tab'] == "" ? "ip" : preg_replace("/\W/","",$_REQUEST['tab']));
175
				$tab_array = array();
176 983fb4d2 Warren Baker
				$tab_array[] = array(gettext("IP"),($tab=="ip" ? true : ($tab=="host" ? true : ($tab == "network" ? true : false))), "/firewall_aliases.php?tab=ip");
177 a5416de2 Warren Baker
				$tab_array[] = array(gettext("Ports"), ($tab=="port"? true : false), "/firewall_aliases.php?tab=port");
178
				$tab_array[] = array(gettext("Urls"), ($tab=="url"? true : false), "/firewall_aliases.php?tab=url");
179
				$tab_array[] = array(gettext("All"), ($tab=="all"? true : false), "/firewall_aliases.php?tab=all");
180
				display_top_tabs($tab_array);
181
			?>
182
		<input type="hidden" name="tab" value="<?=htmlspecialchars($tab);?>">
183
		</td>
184
	</tr>
185 0f89c125 marcelloc
<tr><td><div id="mainarea">
186
		<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
187
		<tr>
188
  <td width="20%" class="listhdrr"><?=gettext("Name"); ?></td>
189
  <td width="43%" class="listhdrr"><?=gettext("Values"); ?></td>
190
  <td width="30%" class="listhdr"><?=gettext("Description"); ?></td>
191
  <td width="7%" class="list">
192
    <table  border="0" cellspacing="0" cellpadding="1">
193 d415d821 Seth Mos
      <tr>
194
	<td valign="middle" width="17">&nbsp;</td>
195 0f89c125 marcelloc
        <td valign="middle"><a href="firewall_aliases_edit.php?tab=<?=$tab?>"><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0" <?=dom_title(gettext("Add a new alias"));?>></a></td>
196 d415d821 Seth Mos
      </tr>
197
    </table>
198
  </td>
199 d2cfb7a4 Scott Ullrich
</tr>
200 0f89c125 marcelloc
	  <?php
201
	  asort($a_aliases);
202
	  foreach ($a_aliases as $i=> $alias){
203
		  unset ($show_alias);
204
		  switch ($tab){
205 d0df92dc marcelloc
		  	case "all":
206
		  	$show_alias= true;
207
		  	break;
208 0f89c125 marcelloc
			case "ip":
209 983fb4d2 Warren Baker
			case "host":
210
			case "network":
211 0f89c125 marcelloc
				if (preg_match("/(host|network)/",$alias["type"]))
212
					$show_alias= true;
213
			break;
214
			case "url":
215
				if (preg_match("/(url)/i",$alias["type"]))
216
					$show_alias= true;
217
			break;
218
			case "port":
219
				if($alias["type"] == "port")
220
					$show_alias= true;
221
				break;
222
		  	}
223
		  if ($show_alias){?>
224
			<tr>
225
			  <td class="listlr" ondblclick="document.location='firewall_aliases_edit.php?id=<?=$i;?>';">
226
			    <?=htmlspecialchars($alias['name']);?>
227
			  </td>
228
			  <td class="listr" ondblclick="document.location='firewall_aliases_edit.php?id=<?=$i;?>';">
229
			      <?php
230
				if ($alias["url"]) {
231
					echo $alias["url"] . "<br/>";
232
				}
233 86675c70 Warren Baker
				if(is_array($alias["aliasurl"])) {
234 3a8e5e3c Warren Baker
					$aliasurls = implode(", ", array_slice($alias["aliasurl"], 0, 10));
235
					echo $aliasurls;
236
					if(count($aliasurls) > 10) {
237
						echo "...<br/>";
238
					}
239
					echo "<br/>\n";
240 0f89c125 marcelloc
				}
241
				$tmpaddr = explode(" ", $alias['address']);
242
				$addresses = implode(", ", array_slice($tmpaddr, 0, 10));
243
				echo $addresses;
244
				if(count($tmpaddr) > 10) {
245
					echo "...";
246
				}
247
			    ?>
248
			  </td>
249
			  <td class="listbg" ondblclick="document.location='firewall_aliases_edit.php?id=<?=$i;?>';">
250
			    <?=htmlspecialchars($alias['descr']);?>&nbsp;
251
			  </td>
252
			  <td valign="middle" nowrap class="list">
253
			    <table border="0" cellspacing="0" cellpadding="1">
254
			      <tr>
255
			        <td valign="middle"><a href="firewall_aliases_edit.php?id=<?=$i;?>"><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_e.gif" width="17" height="17" border="0" <?=dom_title(gettext("Edit alias")." {$alias['name']}");?>></a></td>
256
				<td><a href="firewall_aliases.php?act=del&id=<?=$i;?>" onclick="return confirm('<?=gettext("Do you really want to delete this alias? All elements that still use it will become invalid (e.g. filter rules)!");?>')"><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" width="17" height="17" border="0" <?=dom_title(gettext("Delete alias")." {$alias['name']}");?>></a></td>
257
			      </tr>
258
			    </table>
259
			  </td>
260
			</tr>
261
		  <?php
262
		  }
263
	  }?>
264
265 d2cfb7a4 Scott Ullrich
<tr>
266 0f89c125 marcelloc
    <td colspan="3"/>&nbsp;</td>
267
    <td valign="middle" nowrap class="list">
268
        <table border="0" cellspacing="0" cellpadding="1">
269
            <tbody>
270
                <tr>
271
                    <td valign="middle">
272
                        <a href="firewall_aliases_edit.php?tab=<?=$tab?>"><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0" <?=dom_title(gettext("Add a new alias")); ?>></a>
273
                    </td>
274
                    <td valign="middle">
275
                        <a href="firewall_aliases_import.php"><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_import_alias.gif" width="17" height="17" border="0" <?=dom_title(gettext("Bulk import aliases from list"));?> alt="" /></a>                 
276
                    </td>
277
                </tr>
278
            </tbody>
279
        </table>
280
    </td>
281 d2cfb7a4 Scott Ullrich
</tr>
282 0f89c125 marcelloc
283 d2cfb7a4 Scott Ullrich
  <td class="tabcont" colspan="3">
284 0f89c125 marcelloc
   <p><span class="vexpl"><span class="red"><strong><?=gettext("Note:"); ?><br></strong></span><div style="overflow:hidden; text-align:justify;"><?=gettext("Aliases act as placeholders for real hosts, networks or ports. They can be used to minimize the number of changes that have to be made if a host, network or port changes. You can enter the name of an alias instead of the host, network or port in all fields that have a red background. The alias will be resolved according to the list above. If an alias cannot be resolved (e.g. because you deleted it), the corresponding element (e.g. filter/NAT/shaper rule) will be considered invalid and skipped."); ?></div></span></p>
285 d2cfb7a4 Scott Ullrich
  </td>
286
</tr>
287
</table>
288 0f89c125 marcelloc
	</div>
289
    </td>
290
  </tr>
291
 </table>
292 d2cfb7a4 Scott Ullrich
</form>
293 5b237745 Scott Ullrich
<?php include("fend.inc"); ?>
294
</body>
295
</html>