Project

General

Profile

Download (8.73 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
$a_aliases = &$config['aliases']['alias'];
52

    
53
if ($_POST) {
54

    
55
	$pconfig = $_POST;
56

    
57
	if ($_POST['apply']) {
58
		$retval = 0;
59

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

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

    
72
if ($_GET['act'] == "del") {
73
	if ($a_aliases[$_GET['id']]) {
74
		/* 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
		if(is_array($config['nat']['rule'])) {
79
			foreach($config['nat']['rule'] as $rule) {
80
				if($rule['localip'] == $alias_name) {
81
					$is_alias_referenced = true;
82
					$referenced_by = $rule['descr'];
83
					break;
84
				}
85
			}
86
		}
87
		if($is_alias_referenced == false) {
88
			if(is_array($config['filter']['rule'])) {
89
				foreach($config['filter']['rule'] as $rule) {
90
					if($rule['source']['address'] && $rule['source']['address'] == $alias_name) {
91
						$is_alias_referenced = true;
92
						$referenced_by = $rule['descr'];
93
						break;
94
					}
95
					if($rule['source']['port'] && $rule['source']['port'] == $alias_name) {
96
						$is_alias_referenced = true;
97
						$referenced_by = $rule['descr'];
98
						break;
99
					}
100
					if($rule['destination']['address'] && $rule['destination']['address'] == $alias_name) {
101
						$is_alias_referenced = true;
102
						$referenced_by = $rule['descr'];
103
						break;
104
					}
105
					if($rule['destination']['port'] && $rule['destination']['port'] == $alias_name) {
106
						$is_alias_referenced = true;
107
						$referenced_by = $rule['descr'];
108
						break;
109
					}
110
				}
111
			}
112
		}
113
		if($is_alias_referenced == false) {
114
			if(is_array($config['nat']['rule'])) {
115
				foreach($config['nat']['rule'] as $rule) {
116
					if($rule['source']['address'] && $rule['source']['address'] == $alias_name) {
117
						$is_alias_referenced = true;
118
						$referenced_by = $rule['descr'];
119
						break;
120
					}
121
					if($rule['source']['port'] && $rule['source']['port'] == $alias_name) {
122
						$is_alias_referenced = true;
123
						$referenced_by = $rule['descr'];
124
						break;
125
					}
126
					if($rule['destination']['address'] && $rule['destination']['address'] == $alias_name) {
127
						$is_alias_referenced = true;
128
						$referenced_by = $rule['descr'];
129
						break;
130
					}
131
					if($rule['destination']['port'] && $rule['destination']['port'] == $alias_name) {
132
						$is_alias_referenced = true;
133
						$referenced_by = $rule['descr'];
134
						break;
135
					}
136
					if($rule['target'] && $rule['target'] == $alias_name) {
137
						$is_alias_referenced = true;
138
						$referenced_by = $rule['descr'];
139
						break;
140
					}
141
					if($rule['local-port'] && $rule['local-port'] == $alias_name) {
142
						$is_alias_referenced = true;
143
						$referenced_by = $rule['descr'];
144
						break;
145
					}
146
				}
147
			}
148
		}
149
		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
			filter_configure();
155
			mark_subsystem_dirty('aliases');
156
			header("Location: firewall_aliases.php");
157
			exit;
158
		}
159
	}
160
}
161

    
162
$pgtitle = array("Firewall","Aliases");
163
include("head.inc");
164

    
165
?>
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
<?php if (is_subsystem_dirty('aliases')): ?><p>
172
<?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
<?php endif; ?>
174

    
175
<table width="100%" border="0" cellpadding="0" cellspacing="0">
176
<tr>
177
  <td width="25%" class="listhdrr">Name</td>
178
  <td width="25%" class="listhdrr">Values</td>
179
  <td width="25%" class="listhdr">Description</td>
180
  <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
</tr>
189
	  <?php $i = 0; foreach ($a_aliases as $alias): ?>
190
<tr>
191
  <td class="listlr" ondblclick="document.location='firewall_aliases_edit.php?id=<?=$i;?>';">
192
    <?=htmlspecialchars($alias['name']);?>
193
  </td>
194
  <td class="listr" ondblclick="document.location='firewall_aliases_edit.php?id=<?=$i;?>';">
195
      <?php
196
	if ($alias["url"]) {
197
		echo $alias["url"] . "<br/>";
198
	}
199
	if ($alias["aliasurl"]) {
200
		echo $alias["aliasurl"] . "<br/>";
201
	}
202
	$tmpaddr = explode(" ", $alias['address']);
203
	$addresses = implode(", ", array_slice($tmpaddr, 0, 10));
204
	echo $addresses;
205
	if(count($tmpaddr) > 10) {
206
		echo "...";
207
	}
208
    ?>
209
  </td>
210
  <td class="listbg" ondblclick="document.location='firewall_aliases_edit.php?id=<?=$i;?>';">
211
    <?=htmlspecialchars($alias['descr']);?>&nbsp;
212
  </td>
213
  <td valign="middle" nowrap class="list">
214
    <table border="0" cellspacing="0" cellpadding="1">
215
      <tr>
216
        <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
      </tr>
219
    </table>
220
  </td>
221
</tr>
222
	  <?php $i++; endforeach; ?>
223
<tr>
224
  <td class="list" colspan="3"></td>
225
  <td class="list">
226
    <table border="0" cellspacing="0" cellpadding="1">
227
      <tr>
228
	<td valign="middle" width="17">&nbsp;</td>
229
        <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
        </td>
232
	      <td valign="middle">
233
           <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
        </td>
235
      </tr>
236
    </table>
237
  </td>
238
</tr>
239
<tr>
240
  <td class="tabcont" colspan="3">
241
   <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
  </td>
243
</tr>
244
</table>
245
</form>
246
<?php include("fend.inc"); ?>
247
</body>
248
</html>
(47-47/221)