Project

General

Profile

Download (8 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
##|+PRIV
35
##|*IDENT=page-firewall-aliases
36
##|*NAME=Firewall: Aliases page
37
##|*DESCR=Allow access to the 'Firewall: Aliases' page.
38
##|*MATCH=firewall_aliases.php*
39
##|-PRIV
40

    
41

    
42
require("guiconfig.inc");
43

    
44
if (!is_array($config['aliases']['alias']))
45
	$config['aliases']['alias'] = array();
46

    
47
aliases_sort();
48
$a_aliases = &$config['aliases']['alias'];
49

    
50
if ($_POST) {
51

    
52
	$pconfig = $_POST;
53

    
54
	if ($_POST['apply']) {
55
		$retval = 0;
56

    
57
		config_lock();
58
		/* reload all components that use aliases */
59
		$retval = filter_configure();
60
		config_unlock();
61

    
62
		if(stristr($retval, "error") <> true)
63
		    $savemsg = get_std_save_message($retval);
64
		else
65
		    $savemsg = $retval;
66
		if ($retval == 0) {
67
			if (file_exists($d_aliasesdirty_path))
68
				unlink($d_aliasesdirty_path);
69
		}
70
	}
71
}
72

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

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

    
156
?>
157

    
158
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
159
<?php include("fbegin.inc"); ?>
160
<form action="firewall_aliases.php" method="post">
161
<?php if ($savemsg) print_info_box($savemsg); ?>
162
<?php if (file_exists($d_aliasesdirty_path)): ?><p>
163
<?php print_info_box_np("The alias list has been changed.<br>You must apply the changes in order for them to take effect.");?>
164
<?php endif; ?>
165

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