Project

General

Profile

Download (8.09 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	firewall_aliases.php
5
	Copyright (C) 2004 Scott Ullrich
6
	All rights reserved.
7

    
8
	originially part of m0n0wall (http://m0n0.ch/wall)
9
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
10
	All rights reserved.
11

    
12
	Redistribution and use in source and binary forms, with or without
13
	modification, are permitted provided that the following conditions are met:
14

    
15
	1. Redistributions of source code must retain the above copyright notice,
16
	   this list of conditions and the following disclaimer.
17

    
18
	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

    
22
	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
/*
34
	pfSense_MODULE:	aliases
35
*/
36

    
37
##|+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
require("guiconfig.inc");
45
require_once("functions.inc");
46
require_once("filter.inc");
47
require_once("shaper.inc");
48

    
49
if (!is_array($config['aliases']['alias']))
50
	$config['aliases']['alias'] = array();
51

    
52
aliases_sort();
53
$a_aliases = &$config['aliases']['alias'];
54

    
55
if ($_POST) {
56

    
57
	$pconfig = $_POST;
58

    
59
	if ($_POST['apply']) {
60
		$retval = 0;
61

    
62
		/* reload all components that use aliases */
63
		$retval = filter_configure();
64

    
65
		if(stristr($retval, "error") <> true)
66
		    $savemsg = get_std_save_message($retval);
67
		else
68
		    $savemsg = $retval;
69
		if ($retval == 0)
70
			clear_subsystem_dirty('aliases');
71
	}
72
}
73

    
74
if ($_GET['act'] == "del") {
75
	if ($a_aliases[$_GET['id']]) {
76
		/* make sure rule is not being referenced by any nat or filter rules */
77
		$is_alias_referenced = false;
78
		$referenced_by = false;
79
		$alias_name = $a_aliases[$_GET['id']]['name'];
80
		if(is_array($config['nat']['rule'])) {
81
			foreach($config['nat']['rule'] as $rule) {
82
				if($rule['localip'] == $alias_name) {
83
					$is_alias_referenced = true;
84
					$referenced_by = $rule['descr'];
85
					break;
86
				}
87
			}
88
		}
89
		if($is_alias_referenced == false) {
90
			if(is_array($config['filter']['rule'])) {
91
				foreach($config['filter']['rule'] as $rule) {
92
					if($rule['source']['address'] == $alias_name) {
93
						$is_alias_referenced = true;
94
						$referenced_by = $rule['descr'];
95
						break;
96
					}
97
					if($rule['source']['address'] == $alias_name) {
98
						$is_alias_referenced = true;
99
						$referenced_by = $rule['descr'];
100
						break;
101
					}
102
					if($rule['source']['port'] == $alias_name) {
103
						$is_alias_referenced = true;
104
						$referenced_by = $rule['descr'];
105
						break;
106
					}
107
					if($rule['destination']['port'] == $alias_name) {
108
						$is_alias_referenced = true;
109
						$referenced_by = $rule['descr'];
110
						break;
111
					}
112
				}
113
			}
114
		}
115
		if($is_alias_referenced == false) {
116
			if(is_array($config['nat']['rule'])) {
117
				foreach($config['nat']['rule'] as $rule) {
118
					if($rule['target'] == $alias_name) {
119
						$is_alias_referenced = true;
120
						$referenced_by = $rule['descr'];
121
						break;
122
					}
123
					if($rule['external-address'] == $alias_name) {
124
						$is_alias_referenced = true;
125
						$referenced_by = $rule['descr'];
126
						break;
127
					}
128
					if($rule['external-port'] == $alias_name) {
129
						$is_alias_referenced = true;
130
						$referenced_by = $rule['descr'];
131
						break;
132
					}
133
					if($rule['local-port'] == $alias_name) {
134
						$is_alias_referenced = true;
135
						$referenced_by = $rule['descr'];
136
						break;
137
					}
138
				}
139
			}
140
		}
141
		if($is_alias_referenced == true) {
142
			$savemsg = "Cannot delete rule.  Currently in use by {$referenced_by}";
143
		} else {
144
			unset($a_aliases[$_GET['id']]);
145
			write_config();
146
			filter_configure();
147
			mark_subsystem_dirty('aliases');
148
			header("Location: firewall_aliases.php");
149
			exit;
150
		}
151
	}
152
}
153

    
154
$pgtitle = array("Firewall","Aliases");
155
include("head.inc");
156

    
157
// Sort list
158
$a_aliases = msort($a_aliases, "name");
159

    
160
?>
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
<?php if (is_subsystem_dirty('aliases')): ?><p>
167
<?php print_info_box_np("The alias list has been changed.<br>You must apply the changes in order for them to take effect.");?>
168
<?php endif; ?>
169

    
170
<table width="100%" border="0" cellpadding="0" cellspacing="0">
171
<tr>
172
  <td width="25%" class="listhdrr">Name</td>
173
  <td width="25%" class="listhdrr">Values</td>
174
  <td width="25%" class="listhdr">Description</td>
175
  <td width="10%" class="list">
176
    <table border="0" cellspacing="0" cellpadding="1">
177
      <tr>
178
	<td valign="middle" width="17">&nbsp;</td>
179
        <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>
180
      </tr>
181
    </table>
182
  </td>
183
</tr>
184
	  <?php $i = 0; foreach ($a_aliases as $alias): ?>
185
<tr>
186
  <td class="listlr" ondblclick="document.location='firewall_aliases_edit.php?id=<?=$i;?>';">
187
    <?=htmlspecialchars($alias['name']);?>
188
  </td>
189
  <td class="listr" ondblclick="document.location='firewall_aliases_edit.php?id=<?=$i;?>';">
190
      <?php
191
	$addresses = implode(", ", array_slice(explode(" ", $alias['address']), 0, 10));
192
	echo $addresses;
193
	if(count($addresses) < 10) {
194
		echo " ";
195
	} else {
196
		echo "...";
197
	}
198
    ?>
199
  </td>
200
  <td class="listbg" ondblclick="document.location='firewall_aliases_edit.php?id=<?=$i;?>';">
201
    <?=htmlspecialchars($alias['descr']);?>&nbsp;
202
  </td>
203
  <td valign="middle" nowrap class="list">
204
    <table border="0" cellspacing="0" cellpadding="1">
205
      <tr>
206
        <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>
207
        <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>
208
      </tr>
209
    </table>
210
  </td>
211
</tr>
212
	  <?php $i++; endforeach; ?>
213
<tr>
214
  <td class="list" colspan="3"></td>
215
  <td class="list">
216
    <table border="0" cellspacing="0" cellpadding="1">
217
      <tr>
218
	<td valign="middle" width="17">&nbsp;</td>
219
        <td valign="middle">
220
          <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>
221
        </td>
222
	      <td valign="middle">
223
          <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("import aliases from list");?>" alt="" /></a>
224
        </td>
225
      </tr>
226
    </table>
227
  </td>
228
</tr>
229
<tr>
230
  <td class="tabcont" colspan="3">
231
   <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>
232
  </td>
233
</tr>
234
</table>
235
</form>
236
<?php include("fend.inc"); ?>
237
</body>
238
</html>
(46-46/214)