Project

General

Profile

Download (8.73 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
	$pconfig = $_POST;
56
57
	if ($_POST['apply']) {
58
		$retval = 0;
59 920b3bb0 Scott Ullrich
60
		/* reload all components that use aliases */
61
		$retval = filter_configure();
62
63 b2774343 Scott Ullrich
		if(stristr($retval, "error") <> true)
64
		    $savemsg = get_std_save_message($retval);
65
		else
66
		    $savemsg = $retval;
67 a368a026 Ermal Lu?i
		if ($retval == 0)
68
			clear_subsystem_dirty('aliases');
69 5b237745 Scott Ullrich
	}
70
}
71
72
if ($_GET['act'] == "del") {
73
	if ($a_aliases[$_GET['id']]) {
74 58c32a28 Scott Ullrich
		/* make sure rule is not being referenced by any nat or filter rules */
75
		$is_alias_referenced = false;
76
		$referenced_by = false;
77
		$alias_name = $a_aliases[$_GET['id']]['name'];
78 676abc7c Scott Ullrich
		if(is_array($config['nat']['rule'])) {
79
			foreach($config['nat']['rule'] as $rule) {
80
				if($rule['localip'] == $alias_name) {
81 58c32a28 Scott Ullrich
					$is_alias_referenced = true;
82
					$referenced_by = $rule['descr'];
83
					break;
84
				}
85 676abc7c Scott Ullrich
			}
86 58c32a28 Scott Ullrich
		}
87 3e3e9bee Scott Ullrich
		if($is_alias_referenced == false) {
88 676abc7c Scott Ullrich
			if(is_array($config['filter']['rule'])) {
89
				foreach($config['filter']['rule'] as $rule) {
90 532f800b Renato Botelho
					if($rule['source']['address'] && $rule['source']['address'] == $alias_name) {
91 676abc7c Scott Ullrich
						$is_alias_referenced = true;
92
						$referenced_by = $rule['descr'];
93
						break;
94
					}
95 532f800b Renato Botelho
					if($rule['source']['port'] && $rule['source']['port'] == $alias_name) {
96 676abc7c Scott Ullrich
						$is_alias_referenced = true;
97
						$referenced_by = $rule['descr'];
98
						break;
99
					}
100 532f800b Renato Botelho
					if($rule['destination']['address'] && $rule['destination']['address'] == $alias_name) {
101 676abc7c Scott Ullrich
						$is_alias_referenced = true;
102
						$referenced_by = $rule['descr'];
103
						break;
104
					}
105 532f800b Renato Botelho
					if($rule['destination']['port'] && $rule['destination']['port'] == $alias_name) {
106 676abc7c Scott Ullrich
						$is_alias_referenced = true;
107
						$referenced_by = $rule['descr'];
108
						break;
109
					}
110 3e3e9bee Scott Ullrich
				}
111 676abc7c Scott Ullrich
			}
112
		}
113
		if($is_alias_referenced == false) {
114
			if(is_array($config['nat']['rule'])) {
115
				foreach($config['nat']['rule'] as $rule) {
116 532f800b Renato Botelho
					if($rule['source']['address'] && $rule['source']['address'] == $alias_name) {
117 b52d3aa5 Renato Botelho
						$is_alias_referenced = true;
118
						$referenced_by = $rule['descr'];
119
						break;
120
					}
121 532f800b Renato Botelho
					if($rule['source']['port'] && $rule['source']['port'] == $alias_name) {
122 676abc7c Scott Ullrich
						$is_alias_referenced = true;
123
						$referenced_by = $rule['descr'];
124
						break;
125
					}
126 532f800b Renato Botelho
					if($rule['destination']['address'] && $rule['destination']['address'] == $alias_name) {
127 676abc7c Scott Ullrich
						$is_alias_referenced = true;
128
						$referenced_by = $rule['descr'];
129
						break;
130
					}
131 532f800b Renato Botelho
					if($rule['destination']['port'] && $rule['destination']['port'] == $alias_name) {
132 b52d3aa5 Renato Botelho
						$is_alias_referenced = true;
133
						$referenced_by = $rule['descr'];
134
						break;
135
					}
136 532f800b Renato Botelho
					if($rule['target'] && $rule['target'] == $alias_name) {
137 676abc7c Scott Ullrich
						$is_alias_referenced = true;
138
						$referenced_by = $rule['descr'];
139
						break;
140
					}
141 532f800b Renato Botelho
					if($rule['local-port'] && $rule['local-port'] == $alias_name) {
142 676abc7c Scott Ullrich
						$is_alias_referenced = true;
143
						$referenced_by = $rule['descr'];
144
						break;
145
					}
146 3e3e9bee Scott Ullrich
				}
147 676abc7c Scott Ullrich
			}
148
		}
149 58c32a28 Scott Ullrich
		if($is_alias_referenced == true) {
150
			$savemsg = "Cannot delete rule.  Currently in use by {$referenced_by}";
151
		} else {
152
			unset($a_aliases[$_GET['id']]);
153
			write_config();
154 339495c7 Scott Ullrich
			filter_configure();
155 a368a026 Ermal Lu?i
			mark_subsystem_dirty('aliases');
156 58c32a28 Scott Ullrich
			header("Location: firewall_aliases.php");
157
			exit;
158
		}
159 5b237745 Scott Ullrich
	}
160
}
161 b63695db Scott Ullrich
162 d88c6a9f Scott Ullrich
$pgtitle = array("Firewall","Aliases");
163 b63695db Scott Ullrich
include("head.inc");
164
165 5b237745 Scott Ullrich
?>
166
167
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
168
<?php include("fbegin.inc"); ?>
169
<form action="firewall_aliases.php" method="post">
170
<?php if ($savemsg) print_info_box($savemsg); ?>
171 a368a026 Ermal Lu?i
<?php if (is_subsystem_dirty('aliases')): ?><p>
172 a0509c58 Scott Ullrich
<?php print_info_box_np("The alias list has been changed.<br>You must apply the changes in order for them to take effect.");?>
173 5b237745 Scott Ullrich
<?php endif; ?>
174 d2cfb7a4 Scott Ullrich
175
<table width="100%" border="0" cellpadding="0" cellspacing="0">
176
<tr>
177
  <td width="25%" class="listhdrr">Name</td>
178 1dc8c3eb Scott Ullrich
  <td width="25%" class="listhdrr">Values</td>
179
  <td width="25%" class="listhdr">Description</td>
180 d415d821 Seth Mos
  <td width="10%" class="list">
181
    <table border="0" cellspacing="0" cellpadding="1">
182
      <tr>
183
	<td valign="middle" width="17">&nbsp;</td>
184
        <td valign="middle"><a href="firewall_aliases_edit.php"><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0" title="add a new alias"></a></td>
185
      </tr>
186
    </table>
187
  </td>
188 d2cfb7a4 Scott Ullrich
</tr>
189
	  <?php $i = 0; foreach ($a_aliases as $alias): ?>
190
<tr>
191 20ba0ca5 Bill Marquette
  <td class="listlr" ondblclick="document.location='firewall_aliases_edit.php?id=<?=$i;?>';">
192 d2cfb7a4 Scott Ullrich
    <?=htmlspecialchars($alias['name']);?>
193
  </td>
194 20ba0ca5 Bill Marquette
  <td class="listr" ondblclick="document.location='firewall_aliases_edit.php?id=<?=$i;?>';">
195 7e65fc22 Scott Ullrich
      <?php
196 c7de8be4 jim-p
	if ($alias["url"]) {
197
		echo $alias["url"] . "<br/>";
198
	}
199
	if ($alias["aliasurl"]) {
200
		echo $alias["aliasurl"] . "<br/>";
201
	}
202 4ef606fb Ermal
	$tmpaddr = explode(" ", $alias['address']);
203
	$addresses = implode(", ", array_slice($tmpaddr, 0, 10));
204 9e49dae8 Scott Ullrich
	echo $addresses;
205 6c33fb4b Ermal
	if(count($tmpaddr) > 10) {
206 9e49dae8 Scott Ullrich
		echo "...";
207 7e65fc22 Scott Ullrich
	}
208
    ?>
209 d2cfb7a4 Scott Ullrich
  </td>
210 20ba0ca5 Bill Marquette
  <td class="listbg" ondblclick="document.location='firewall_aliases_edit.php?id=<?=$i;?>';">
211 7e65fc22 Scott Ullrich
    <?=htmlspecialchars($alias['descr']);?>&nbsp;
212 d2cfb7a4 Scott Ullrich
  </td>
213 725f5e5a Bill Marquette
  <td valign="middle" nowrap class="list">
214 676abc7c Scott Ullrich
    <table border="0" cellspacing="0" cellpadding="1">
215 725f5e5a Bill Marquette
      <tr>
216 ec3418ed Bill Marquette
        <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" title="edit alias"></a></td>
217
        <td><a href="firewall_aliases.php?act=del&id=<?=$i;?>" onclick="return confirm('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" title="delete alias"></a></td>
218 725f5e5a Bill Marquette
      </tr>
219
    </table>
220
  </td>
221 d2cfb7a4 Scott Ullrich
</tr>
222
	  <?php $i++; endforeach; ?>
223
<tr>
224
  <td class="list" colspan="3"></td>
225 725f5e5a Bill Marquette
  <td class="list">
226
    <table border="0" cellspacing="0" cellpadding="1">
227
      <tr>
228 d415d821 Seth Mos
	<td valign="middle" width="17">&nbsp;</td>
229 19f11aef Bill Marquette
        <td valign="middle">
230
          <a href="firewall_aliases_edit.php"><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0" title="add a new alias"></a></td>
231 f724d6b6 Scott Ullrich
        </td>
232
	      <td valign="middle">
233 27f9c8b4 Scott Ullrich
           <a href="firewall_aliases_import.php"><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_import_alias.gif" width="17" height="17" border="0" title="<?=gettext("Bulk import aliases from list");?>" alt="" /></a>
234 f724d6b6 Scott Ullrich
        </td>
235 725f5e5a Bill Marquette
      </tr>
236
    </table>
237
  </td>
238 d2cfb7a4 Scott Ullrich
</tr>
239
<tr>
240
  <td class="tabcont" colspan="3">
241 31e92b6a Scott Ullrich
   <p><span class="vexpl"><span class="red"><strong>Note:<br></strong></span>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.</span></p>
242 d2cfb7a4 Scott Ullrich
  </td>
243
</tr>
244
</table>
245
</form>
246 5b237745 Scott Ullrich
<?php include("fend.inc"); ?>
247
</body>
248
</html>