Project

General

Profile

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

    
138
$pgtitle = "Firewall: Aliases";
139
include("head.inc");
140

    
141
?>
142

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

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