Project

General

Profile

Download (7.61 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
require("guiconfig.inc");
35

    
36
if (!is_array($config['aliases']['alias']))
37
	$config['aliases']['alias'] = array();
38

    
39
aliases_sort();
40
$a_aliases = &$config['aliases']['alias'];
41

    
42
if ($_POST) {
43

    
44
	$pconfig = $_POST;
45

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

    
49
		config_lock();
50
		/* reload all components that use aliases */
51
		$retval = filter_configure();
52
		config_unlock();
53

    
54
		if(stristr($retval, "error") <> true)
55
		    $savemsg = get_std_save_message($retval);
56
		else
57
		    $savemsg = $retval;
58
		if ($retval == 0) {
59
			if (file_exists($d_aliasesdirty_path))
60
				unlink($d_aliasesdirty_path);
61
		}
62
	}
63
}
64

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

    
145
$pgtitle = "Firewall: Aliases";
146
include("head.inc");
147

    
148
?>
149

    
150
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
151
<?php include("fbegin.inc"); ?>
152
<p class="pgtitle"><?=$pgtitle?></p>
153
<form action="firewall_aliases.php" method="post">
154
<?php if ($savemsg) print_info_box($savemsg); ?>
155
<?php if (file_exists($d_aliasesdirty_path)): ?><p>
156
<?php print_info_box_np("The alias list has been changed.<br>You must apply the changes in order for them to take effect.");?>
157
<?php endif; ?>
158

    
159
<table width="100%" border="0" cellpadding="0" cellspacing="0">
160
<tr>
161
  <td width="25%" class="listhdrr">Name</td>
162
  <td width="25%" class="listhdrr">Values</td>
163
  <td width="25%" class="listhdr">Description</td>
164
  <td width="10%" class="list">
165
    <table border="0" cellspacing="0" cellpadding="1">
166
      <tr>
167
	<td valign="middle" width="17">&nbsp;</td>
168
        <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>
169
      </tr>
170
    </table>
171
  </td>
172
</tr>
173
	  <?php $i = 0; foreach ($a_aliases as $alias): ?>
174
<tr>
175
  <td class="listlr" ondblclick="document.location='firewall_aliases_edit.php?id=<?=$i;?>';">
176
    <?=htmlspecialchars($alias['name']);?>
177
  </td>
178
  <td class="listr" ondblclick="document.location='firewall_aliases_edit.php?id=<?=$i;?>';">
179
      <?php
180
	$addresses = implode(", ", array_slice(explode(" ", $alias['address']), 0, 10));
181
	echo $addresses;
182
	if(count($addresses) < 10) {
183
		echo " ";
184
	} else {
185
		echo "...";
186
	}
187
    ?>
188
  </td>
189
  <td class="listbg" ondblclick="document.location='firewall_aliases_edit.php?id=<?=$i;?>';">
190
    <font color="#FFFFFF">
191
    <?=htmlspecialchars($alias['descr']);?>&nbsp;
192
  </td>
193
  <td valign="middle" nowrap class="list">
194
    <table border="0" cellspacing="0" cellpadding="1">
195
      <tr>
196
        <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>
197
        <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>
198
      </tr>
199
    </table>
200
  </td>
201
</tr>
202
	  <?php $i++; endforeach; ?>
203
<tr>
204
  <td class="list" colspan="3"></td>
205
  <td class="list">
206
    <table border="0" cellspacing="0" cellpadding="1">
207
      <tr>
208
	<td valign="middle" width="17">&nbsp;</td>
209
        <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>
210
      </tr>
211
    </table>
212
  </td>
213
</tr>
214
<tr>
215
  <td class="tabcont" colspan="3">
216
   <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>
217
  </td>
218
</tr>
219
</table>
220
</form>
221
<?php include("fend.inc"); ?>
222
</body>
223
</html>
(41-41/175)