Project

General

Profile

Download (12.6 KB) Statistics
| Branch: | Tag: | Revision:
1 b0ae75c5 Bill Marquette
<?php
2
/* $Id$ */
3
/*
4
	firewall_virtual_ip.php
5
	part of pfSense (http://www.pfsense.com/)
6
7
	Copyright (C) 2005 Bill Marquette <bill.marquette@gmail.com>.
8
	All rights reserved.
9
10
	Includes code from m0n0wall which is:
11
	Copyright (C) 2003-2005 Manuel Kasper <mk@neon1.net>.
12
	All rights reserved.
13
14
	Includes code from pfSense which is:
15
	Copyright (C) 2004-2005 Scott Ullrich <geekgod@pfsense.com>.
16
	All rights reserved.
17
18
	Redistribution and use in source and binary forms, with or without
19
	modification, are permitted provided that the following conditions are met:
20
21
	1. Redistributions of source code must retain the above copyright notice,
22
	   this list of conditions and the following disclaimer.
23
24
	2. Redistributions in binary form must reproduce the above copyright
25
	   notice, this list of conditions and the following disclaimer in the
26
	   documentation and/or other materials provided with the distribution.
27
28
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
29
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
30
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
31
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
32
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37
	POSSIBILITY OF SUCH DAMAGE.
38
*/
39 7ac5a4cb Scott Ullrich
/*
40
	pfSense_BUILDER_BINARIES:	/sbin/ifconfig
41
	pfSense_MODULE:	interfaces
42
*/
43 b0ae75c5 Bill Marquette
44 6b07c15a Matthew Grooms
##|+PRIV
45
##|*IDENT=page-firewall-virtualipaddresses
46
##|*NAME=Firewall: Virtual IP Addresses page
47
##|*DESCR=Allow access to the 'Firewall: Virtual IP Addresses' page.
48
##|*MATCH=firewall_virtual_ip.php*
49
##|-PRIV
50
51 b0ae75c5 Bill Marquette
require("guiconfig.inc");
52 7a927e67 Scott Ullrich
require_once("functions.inc");
53
require_once("filter.inc");
54
require_once("shaper.inc");
55 b0ae75c5 Bill Marquette
56
if (!is_array($config['virtualip']['vip'])) {
57
	$config['virtualip']['vip'] = array();
58
}
59
$a_vip = &$config['virtualip']['vip'];
60
61
if ($_POST) {
62
	$pconfig = $_POST;
63
64
	if ($_POST['apply']) {
65 68071477 Ermal
		if (file_exists("{$g['tmp_path']}/.firewall_virtual_ip.apply")) {
66 e8471084 Ermal
                        $toapplylist = unserialize(file_get_contents("{$g['tmp_path']}/.firewall_virtual_ip.apply"));
67 68071477 Ermal
			foreach ($toapplylist as $vid => $ovip) {
68
				if (!empty($ovip))
69
					interface_vip_bring_down($ovip);
70
				if ($a_vip[$vid]) {
71
                			switch ($a_vip[$vid]['mode']) {
72
                			case "ipalias":
73
                        			interface_ipalias_configure($a_vip[$vid]);
74
                        			break;
75
                			case "proxyarp":
76
                        			interface_proxyarp_configure($a_vip[$vid]['interface']);
77
                        			break;
78
                			case "carp":
79
                        			interface_carp_configure($a_vip[$vid]);
80
						break;
81
                			default:
82
                        			break;
83
					}
84
                		}
85
        		}
86
			@unlink("{$g['tmp_path']}/.firewall_virtual_ip.apply");
87
		}
88 b0ae75c5 Bill Marquette
		$retval = 0;
89 920b3bb0 Scott Ullrich
		$retval |= filter_configure();
90 b0ae75c5 Bill Marquette
		$savemsg = get_std_save_message($retval);
91 abcb2bed Ermal Lu?i
92 a368a026 Ermal Lu?i
		clear_subsystem_dirty('vip');
93 b0ae75c5 Bill Marquette
	}
94
}
95
96
if ($_GET['act'] == "del") {
97
	if ($a_vip[$_GET['id']]) {
98
		/* make sure no inbound NAT mappings reference this entry */
99
		if (is_array($config['nat']['rule'])) {
100
			foreach ($config['nat']['rule'] as $rule) {
101 93e485e3 Renato Botelho
				if($rule['destination']['address'] <> "") {
102 3504e10b Renato Botelho
					if ($rule['destination']['address'] == $a_vip[$_GET['id']]['subnet']) {
103 3e2a70d9 Rafael Lucas
						$input_errors[] = gettext("This entry cannot be deleted because it is still referenced by at least one NAT mapping.");
104 7c99b15c Scott Ullrich
						break;
105
					}
106 b0ae75c5 Bill Marquette
				}
107
			}
108
		}
109
110 ff9f40d5 Renato Botelho
		if (is_ipaddrv6($a_vip[$_GET['id']]['subnet'])) {
111
			$is_ipv6 = true;
112 55705b33 Renato Botelho
			$subnet = gen_subnetv6($a_vip[$_GET['id']]['subnet'], $a_vip[$_GET['id']]['subnet_bits']);
113 ba47a890 Renato Botelho
			$if_subnet_bits = get_interface_subnetv6($a_vip[$_GET['id']]['interface']);
114
			$if_subnet = gen_subnetv6(get_interface_ipv6($a_vip[$_GET['id']]['interface']), $if_subnet_bits);
115 ff9f40d5 Renato Botelho
		} else {
116
			$is_ipv6 = false;
117 55705b33 Renato Botelho
			$subnet = gen_subnet($a_vip[$_GET['id']]['subnet'], $a_vip[$_GET['id']]['subnet_bits']);
118 ba47a890 Renato Botelho
			$if_subnet_bits = get_interface_subnet($a_vip[$_GET['id']]['interface']);
119
			$if_subnet = gen_subnet(get_interface_ip($a_vip[$_GET['id']]['interface']), $if_subnet_bits);
120 ff9f40d5 Renato Botelho
		}
121 55705b33 Renato Botelho
122
		$subnet .= "/" . $a_vip[$_GET['id']]['subnet_bits'];
123 ff9f40d5 Renato Botelho
		$if_subnet .= "/" . $if_subnet_bits;
124 55705b33 Renato Botelho
125
		if (is_array($config['gateways']['gateway_item']))
126
			foreach($config['gateways']['gateway_item'] as $gateway) {
127
				if ($a_vip[$_GET['id']]['interface'] != $gateway['interface'])
128
					continue;
129
				if ($is_ipv6 && $gateway['ipprotocol'] == 'inet')
130
					continue;
131
				if (!$is_ipv6 && $gateway['ipprotocol'] == 'inet6')
132
					continue;
133 ff9f40d5 Renato Botelho
				if (ip_in_subnet($gateway['gateway'], $if_subnet))
134
					continue;
135 55705b33 Renato Botelho
136
				if (ip_in_subnet($gateway['gateway'], $subnet)) {
137
					$input_errors[] = gettext("This entry cannot be deleted because it is still referenced by at least one Gateway.");
138
					break;
139
				}
140
			}
141
142 e8471084 Ermal
		if ($a_vip[$_GET['id']]['mode'] == "ipalias") {
143 b030e035 Renato Botelho
			$found_carp = false;
144
			$found_other_alias = false;
145
146 e19b7d1e Ermal
			$vipiface = $a_vip[$_GET['id']]['interface'];
147 b030e035 Renato Botelho
			foreach ($a_vip as $vip_id => $vip) {
148
				if ($vip_id == $_GET['id'])
149
					continue;
150
151
				if ($vip['interface'] == $vipiface && ip_in_subnet($vip['subnet'], gen_subnet($a_vip[$_GET['id']]['subnet'], $a_vip[$_GET['id']]['subnet_bits']) . "/" . $a_vip[$_GET['id']]['subnet_bits']))
152
					if ($vip['mode'] == "carp")
153
						$found_carp = true;
154
					else if ($vip['mode'] == "ipalias")
155
						$found_other_alias = true;
156 e19b7d1e Ermal
			}
157 b030e035 Renato Botelho
158
			if ($found_carp === true && $found_other_alias === false)
159
				$input_errors[] = gettext("This entry cannot be deleted because it is still referenced by a CARP IP with the description") . " {$vip['descr']}.";
160 e19b7d1e Ermal
		}
161 e8471084 Ermal
		
162 b0ae75c5 Bill Marquette
		if (!$input_errors) {
163 4111fcf5 Ermal
			if (!session_id())
164
				session_start();
165 3a343d73 jim-p
			$user = getUserEntry($_SESSION['Username']);
166
			if (is_array($user) && userHasPrivilege($user, "user-config-readonly")) {
167
				header("Location: firewall_virtual_ip.php");
168
				exit;
169
			}
170 4111fcf5 Ermal
			session_commit();
171 3a343d73 jim-p
172 1ba7a81b Ermal Lu?i
			// Special case since every proxyarp vip is handled by the same daemon.
173
			if ($a_vip[$_GET['id']]['mode'] == "proxyarp") {
174 e8471084 Ermal
				$viface = $a_vip[$_GET['id']]['interface'];
175 1ba7a81b Ermal Lu?i
				unset($a_vip[$_GET['id']]);
176 e8471084 Ermal
				interface_proxyarp_configure($viface);
177 1ba7a81b Ermal Lu?i
			} else {
178
				interface_vip_bring_down($a_vip[$_GET['id']]);
179
				unset($a_vip[$_GET['id']]);
180
			}
181 ed65eb04 Ermal Lu?i
			if (count($config['virtualip']['vip']) == 0)
182
				unset($config['virtualip']['vip']);
183 b0ae75c5 Bill Marquette
			write_config();
184 406abd6e Rafael Lucas
			header("Location: firewall_virtual_ip.php");
185 b0ae75c5 Bill Marquette
			exit;
186
		}
187
	}
188 abcb2bed Ermal Lu?i
} else if ($_GET['changes'] == "mods")
189
	$id = $_GET['id'];
190 b0ae75c5 Bill Marquette
191 3e2a70d9 Rafael Lucas
$pgtitle = array(gettext("Firewall"),gettext("Virtual IP Addresses"));
192 b0ae75c5 Bill Marquette
include("head.inc");
193
194
?>
195
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
196
<?php include("fbegin.inc"); ?>
197
<form action="firewall_virtual_ip.php" method="post">
198 b760a120 Scott Ullrich
<?php 
199
	if ($input_errors) 
200
		print_input_errors($input_errors);
201
	else
202
	if ($savemsg) 
203
		print_info_box($savemsg); 
204
	else
205 a368a026 Ermal Lu?i
	if (is_subsystem_dirty('vip'))
206 3bfe618a Colin Fleming
		print_info_box_np(gettext("The VIP configuration has been changed.")."<br/>".gettext("You must apply the changes in order for them to take effect."));
207 b760a120 Scott Ullrich
?>
208 3bfe618a Colin Fleming
<br/>
209
<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="virtual ip">
210 49424ec0 Bill Marquette
  <tr><td class="tabnavtbl">
211
  <?php
212
        /* active tabs */
213
        $tab_array = array();
214 3e2a70d9 Rafael Lucas
        $tab_array[] = array(gettext("Virtual IPs"), true, "firewall_virtual_ip.php");
215 f97a5b04 Darren Embry
        $tab_array[] = array(gettext("CARP Settings"), false, "system_hasync.php");
216 49424ec0 Bill Marquette
        display_top_tabs($tab_array);
217
  ?>
218 b0ae75c5 Bill Marquette
  </td></tr>
219 abcb2bed Ermal Lu?i
  <tr>
220 3bfe618a Colin Fleming
	<td><input type="hidden" id="id" name="id" value="<?php echo $id; ?>" /></td>
221 abcb2bed Ermal Lu?i
  </tr>
222 b0ae75c5 Bill Marquette
  <tr>
223
    <td>
224
	<div id="mainarea">
225 3bfe618a Colin Fleming
              <table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0" summary="main area">
226 b0ae75c5 Bill Marquette
                <tr>
227 3e2a70d9 Rafael Lucas
                  <td width="30%" class="listhdrr"><?=gettext("Virtual IP address");?></td>
228 e3449857 PiBa-NL
                  <td width="10%" class="listhdrr"><?=gettext("Interface");?></td>
229 3e2a70d9 Rafael Lucas
                  <td width="10%" class="listhdrr"><?=gettext("Type");?></td>
230
                  <td width="40%" class="listhdr"><?=gettext("Description");?></td>
231 d415d821 Seth Mos
                  <td width="10%" class="list">
232 3bfe618a Colin Fleming
                    <table border="0" cellspacing="0" cellpadding="1" summary="edit">
233 d415d821 Seth Mos
                      <tr>
234
			<td width="17"></td>
235 3bfe618a Colin Fleming
                        <td valign="middle"><a href="firewall_virtual_ip_edit.php"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0" alt="edit" /></a></td>
236 d415d821 Seth Mos
                      </tr>
237
                    </table>
238
		  </td>
239
		</tr>
240 79ea2726 Renato Botelho
		<?php
241
			$interfaces = get_configured_interface_with_descr(false, true);
242 19d90bce jim-p
			$interfaces['lo0'] = "Localhost";
243 79ea2726 Renato Botelho
		?>
244 b0ae75c5 Bill Marquette
			  <?php $i = 0; foreach ($a_vip as $vipent): ?>
245 21784301 Scott Ullrich
			  <?php if($vipent['subnet'] <> "" or $vipent['range'] <> "" or
246 3e662cb0 Ermal
			        $vipent['subnet_bits'] <> "" or (isset($vipent['range']['from']) && $vipent['range']['from'] <> "")): ?>
247 b0ae75c5 Bill Marquette
                <tr>
248
                  <td class="listlr" ondblclick="document.location='firewall_virtual_ip_edit.php?id=<?=$i;?>';">
249
					<?php	if (($vipent['type'] == "single") || ($vipent['type'] == "network"))
250 2db680e1 Scott Ullrich
								if($vipent['subnet_bits'])
251
									echo "{$vipent['subnet']}/{$vipent['subnet_bits']}";
252 b0ae75c5 Bill Marquette
							if ($vipent['type'] == "range")
253
								echo "{$vipent['range']['from']}-{$vipent['range']['to']}";
254
					?>
255 3e662cb0 Ermal
					<?php if($vipent['mode'] == "carp") echo " (vhid {$vipent['vhid']})"; ?>
256 b0ae75c5 Bill Marquette
                  </td>
257 e3449857 PiBa-NL
                  <td class="listr" ondblclick="document.location='firewall_virtual_ip_edit.php?id=<?=$i;?>';">
258 79ea2726 Renato Botelho
                    <?=htmlspecialchars($interfaces[$vipent['interface']]);?>&nbsp;
259 e3449857 PiBa-NL
                  </td>
260 902b4e72 Bill Marquette
                  <td class="listr" align="center" ondblclick="document.location='firewall_virtual_ip_edit.php?id=<?=$i;?>';">
261 3bfe618a Colin Fleming
                    <?php if($vipent['mode'] == "proxyarp") echo "<img src='./themes/".$g['theme']."/images/icons/icon_parp.gif' title='Proxy ARP' alt='proxy arp' />"; elseif($vipent['mode'] == "carp") echo "<img src='./themes/".$g['theme']."/images/icons/icon_carp.gif' title='CARP' alt='carp' />"; elseif($vipent['mode'] == "other") echo "<img src='./themes/".$g['theme']."/images/icons/icon_other.gif' title='Other' alt='other' />"; elseif($vipent['mode'] == "ipalias") echo "<img src='./themes/".$g['theme']."/images/icons/icon_ifalias.gif' title='IP Alias' alt='ip alias' />";?>
262 b0ae75c5 Bill Marquette
                  </td>
263
                  <td class="listbg" ondblclick="document.location='firewall_virtual_ip_edit.php?id=<?=$i;?>';">
264 30d4c469 Scott Ullrich
                    <?=htmlspecialchars($vipent['descr']);?>&nbsp;
265 b0ae75c5 Bill Marquette
                  </td>
266 3bfe618a Colin Fleming
                  <td class="list nowrap">
267
                    <table border="0" cellspacing="0" cellpadding="1" summary="icons">
268 b0ae75c5 Bill Marquette
                      <tr>
269 3bfe618a Colin Fleming
                        <td valign="middle"><a href="firewall_virtual_ip_edit.php?id=<?=$i;?>"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_e.gif" width="17" height="17" border="0" alt="edit" /></a></td>
270
                        <td valign="middle"><a href="firewall_virtual_ip.php?act=del&amp;id=<?=$i;?>" onclick="return confirm('<?=gettext('Do you really want to delete this entry?');?>')"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" width="17" height="17" border="0" alt="delete" /></a></td>
271 b0ae75c5 Bill Marquette
                      </tr>
272
                    </table>
273
                  </td>
274
                </tr>
275 21784301 Scott Ullrich
		<?php endif; ?>
276 b0ae75c5 Bill Marquette
                <?php $i++; endforeach; ?>
277
                <tr>
278 e3449857 PiBa-NL
                  <td class="list" colspan="4"></td>
279 b0ae75c5 Bill Marquette
                  <td class="list">
280 3bfe618a Colin Fleming
                    <table border="0" cellspacing="0" cellpadding="1" summary="edit">
281 b0ae75c5 Bill Marquette
                      <tr>
282 d415d821 Seth Mos
			<td width="17"></td>
283 3bfe618a Colin Fleming
                        <td valign="middle"><a href="firewall_virtual_ip_edit.php"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0" alt="edit" /></a></td>
284 b0ae75c5 Bill Marquette
                      </tr>
285
                    </table>
286
                  </td>
287
                </tr>
288
		<tr>
289 e3449857 PiBa-NL
		  <td colspan="5">
290 3bfe618a Colin Fleming
		      <p><span class="vexpl"><span class="red"><strong><?=gettext("Note:");?><br/>
291
                      </strong></span><?=gettext("The virtual IP addresses defined on this page may be used in");?><a href="firewall_nat.php"> <?=gettext("NAT"); ?> </a><?=gettext("mappings.");?><br/>
292 c59639d1 Vinicius Coque
                      <?=gettext("You can check the status of your CARP Virtual IPs and interfaces ");?><a href="carp_status.php"><?=gettext("here");?></a>.</span></p>
293 b0ae75c5 Bill Marquette
		  </td>
294
		</tr>
295
              </table>
296 3bfe618a Colin Fleming
	   </div><!-- div:mainarea -->
297
	   </td></tr>
298 b0ae75c5 Bill Marquette
	</table>
299
            </form>
300
<?php include("fend.inc"); ?>
301
</body>
302
</html>