Project

General

Profile

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