| 1 |
5b237745
|
Scott Ullrich
|
<?php
|
| 2 |
b46bfcf5
|
Bill Marquette
|
/* $Id$ */
|
| 3 |
5b237745
|
Scott Ullrich
|
/*
|
| 4 |
|
|
firewall_aliases.php
|
| 5 |
4d875b4f
|
Scott Ullrich
|
Copyright (C) 2004 Scott Ullrich
|
| 6 |
|
|
All rights reserved.
|
| 7 |
f0fe3d30
|
Scott Ullrich
|
|
| 8 |
4d875b4f
|
Scott Ullrich
|
originially part of m0n0wall (http://m0n0.ch/wall)
|
| 9 |
5b237745
|
Scott Ullrich
|
Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
|
| 10 |
|
|
All rights reserved.
|
| 11 |
f0fe3d30
|
Scott Ullrich
|
|
| 12 |
5b237745
|
Scott Ullrich
|
Redistribution and use in source and binary forms, with or without
|
| 13 |
|
|
modification, are permitted provided that the following conditions are met:
|
| 14 |
f0fe3d30
|
Scott Ullrich
|
|
| 15 |
5b237745
|
Scott Ullrich
|
1. Redistributions of source code must retain the above copyright notice,
|
| 16 |
|
|
this list of conditions and the following disclaimer.
|
| 17 |
f0fe3d30
|
Scott Ullrich
|
|
| 18 |
5b237745
|
Scott Ullrich
|
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 |
f0fe3d30
|
Scott Ullrich
|
|
| 22 |
5b237745
|
Scott Ullrich
|
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 |
920b3bb0
|
Scott Ullrich
|
|
| 49 |
|
|
config_lock();
|
| 50 |
|
|
/* reload all components that use aliases */
|
| 51 |
|
|
$retval = filter_configure();
|
| 52 |
|
|
config_unlock();
|
| 53 |
|
|
|
| 54 |
b2774343
|
Scott Ullrich
|
if(stristr($retval, "error") <> true)
|
| 55 |
|
|
$savemsg = get_std_save_message($retval);
|
| 56 |
|
|
else
|
| 57 |
|
|
$savemsg = $retval;
|
| 58 |
5b237745
|
Scott Ullrich
|
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 |
58c32a28
|
Scott Ullrich
|
/* 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 |
676abc7c
|
Scott Ullrich
|
if(is_array($config['nat']['rule'])) {
|
| 72 |
|
|
foreach($config['nat']['rule'] as $rule) {
|
| 73 |
|
|
if($rule['localip'] == $alias_name) {
|
| 74 |
58c32a28
|
Scott Ullrich
|
$is_alias_referenced = true;
|
| 75 |
|
|
$referenced_by = $rule['descr'];
|
| 76 |
|
|
break;
|
| 77 |
|
|
}
|
| 78 |
676abc7c
|
Scott Ullrich
|
}
|
| 79 |
58c32a28
|
Scott Ullrich
|
}
|
| 80 |
3e3e9bee
|
Scott Ullrich
|
if($is_alias_referenced == false) {
|
| 81 |
676abc7c
|
Scott Ullrich
|
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 |
3e3e9bee
|
Scott Ullrich
|
}
|
| 104 |
676abc7c
|
Scott Ullrich
|
}
|
| 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 |
3e3e9bee
|
Scott Ullrich
|
}
|
| 130 |
676abc7c
|
Scott Ullrich
|
}
|
| 131 |
|
|
}
|
| 132 |
58c32a28
|
Scott Ullrich
|
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 |
339495c7
|
Scott Ullrich
|
filter_configure();
|
| 138 |
58c32a28
|
Scott Ullrich
|
touch($d_aliasesdirty_path);
|
| 139 |
|
|
header("Location: firewall_aliases.php");
|
| 140 |
|
|
exit;
|
| 141 |
|
|
}
|
| 142 |
5b237745
|
Scott Ullrich
|
}
|
| 143 |
|
|
}
|
| 144 |
b63695db
|
Scott Ullrich
|
|
| 145 |
|
|
$pgtitle = "Firewall: Aliases";
|
| 146 |
|
|
include("head.inc");
|
| 147 |
|
|
|
| 148 |
5b237745
|
Scott Ullrich
|
?>
|
| 149 |
|
|
|
| 150 |
|
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
|
| 151 |
|
|
<?php include("fbegin.inc"); ?>
|
| 152 |
da7ae7ef
|
Bill Marquette
|
<p class="pgtitle"><?=$pgtitle?></p>
|
| 153 |
5b237745
|
Scott Ullrich
|
<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 |
a0509c58
|
Scott Ullrich
|
<?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 |
5b237745
|
Scott Ullrich
|
<?php endif; ?>
|
| 158 |
d2cfb7a4
|
Scott Ullrich
|
|
| 159 |
|
|
<table width="100%" border="0" cellpadding="0" cellspacing="0">
|
| 160 |
|
|
<tr>
|
| 161 |
|
|
<td width="25%" class="listhdrr">Name</td>
|
| 162 |
1dc8c3eb
|
Scott Ullrich
|
<td width="25%" class="listhdrr">Values</td>
|
| 163 |
|
|
<td width="25%" class="listhdr">Description</td>
|
| 164 |
d415d821
|
Seth Mos
|
<td width="10%" class="list">
|
| 165 |
|
|
<table border="0" cellspacing="0" cellpadding="1">
|
| 166 |
|
|
<tr>
|
| 167 |
|
|
<td valign="middle" width="17"> </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 |
d2cfb7a4
|
Scott Ullrich
|
</tr>
|
| 173 |
|
|
<?php $i = 0; foreach ($a_aliases as $alias): ?>
|
| 174 |
|
|
<tr>
|
| 175 |
20ba0ca5
|
Bill Marquette
|
<td class="listlr" ondblclick="document.location='firewall_aliases_edit.php?id=<?=$i;?>';">
|
| 176 |
d2cfb7a4
|
Scott Ullrich
|
<?=htmlspecialchars($alias['name']);?>
|
| 177 |
|
|
</td>
|
| 178 |
20ba0ca5
|
Bill Marquette
|
<td class="listr" ondblclick="document.location='firewall_aliases_edit.php?id=<?=$i;?>';">
|
| 179 |
7e65fc22
|
Scott Ullrich
|
<?php
|
| 180 |
9e49dae8
|
Scott Ullrich
|
$addresses = implode(", ", array_slice(explode(" ", $alias['address']), 0, 10));
|
| 181 |
|
|
echo $addresses;
|
| 182 |
|
|
if(count($addresses) < 10) {
|
| 183 |
2e445a9e
|
Scott Ullrich
|
echo " ";
|
| 184 |
9e49dae8
|
Scott Ullrich
|
} else {
|
| 185 |
|
|
echo "...";
|
| 186 |
7e65fc22
|
Scott Ullrich
|
}
|
| 187 |
|
|
?>
|
| 188 |
d2cfb7a4
|
Scott Ullrich
|
</td>
|
| 189 |
20ba0ca5
|
Bill Marquette
|
<td class="listbg" ondblclick="document.location='firewall_aliases_edit.php?id=<?=$i;?>';">
|
| 190 |
7e65fc22
|
Scott Ullrich
|
<font color="#FFFFFF">
|
| 191 |
|
|
<?=htmlspecialchars($alias['descr']);?>
|
| 192 |
d2cfb7a4
|
Scott Ullrich
|
</td>
|
| 193 |
725f5e5a
|
Bill Marquette
|
<td valign="middle" nowrap class="list">
|
| 194 |
676abc7c
|
Scott Ullrich
|
<table border="0" cellspacing="0" cellpadding="1">
|
| 195 |
725f5e5a
|
Bill Marquette
|
<tr>
|
| 196 |
ec3418ed
|
Bill Marquette
|
<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 |
725f5e5a
|
Bill Marquette
|
</tr>
|
| 199 |
|
|
</table>
|
| 200 |
|
|
</td>
|
| 201 |
d2cfb7a4
|
Scott Ullrich
|
</tr>
|
| 202 |
|
|
<?php $i++; endforeach; ?>
|
| 203 |
|
|
<tr>
|
| 204 |
|
|
<td class="list" colspan="3"></td>
|
| 205 |
725f5e5a
|
Bill Marquette
|
<td class="list">
|
| 206 |
|
|
<table border="0" cellspacing="0" cellpadding="1">
|
| 207 |
|
|
<tr>
|
| 208 |
d415d821
|
Seth Mos
|
<td valign="middle" width="17"> </td>
|
| 209 |
ec3418ed
|
Bill Marquette
|
<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 |
725f5e5a
|
Bill Marquette
|
</tr>
|
| 211 |
|
|
</table>
|
| 212 |
|
|
</td>
|
| 213 |
d2cfb7a4
|
Scott Ullrich
|
</tr>
|
| 214 |
|
|
<tr>
|
| 215 |
|
|
<td class="tabcont" colspan="3">
|
| 216 |
31e92b6a
|
Scott Ullrich
|
<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 |
d2cfb7a4
|
Scott Ullrich
|
</td>
|
| 218 |
|
|
</tr>
|
| 219 |
|
|
</table>
|
| 220 |
|
|
</form>
|
| 221 |
5b237745
|
Scott Ullrich
|
<?php include("fend.inc"); ?>
|
| 222 |
|
|
</body>
|
| 223 |
|
|
</html>
|