Project

General

Profile

Download (7.97 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
		/* reload all components that use aliases */
58
		$retval = filter_configure();
59

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

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

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

    
154
?>
155

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

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