Project

General

Profile

Download (14.3 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	firewall_virtual_ip.php
5
	part of pfSense (https://www.pfsense.org/)
6

    
7
	Copyright (C) 2005 Bill Marquette <bill.marquette@gmail.com>.
8
	Copyright (C) 2013-2015 Electric Sheep Fencing, LP
9
	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
/*
41
	pfSense_BUILDER_BINARIES:	/sbin/ifconfig
42
	pfSense_MODULE:	interfaces
43
*/
44

    
45
##|+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
require("guiconfig.inc");
53
require_once("functions.inc");
54
require_once("filter.inc");
55
require_once("shaper.inc");
56

    
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
		$check_carp = false;
67
		if (file_exists("{$g['tmp_path']}/.firewall_virtual_ip.apply")) {
68
                        $toapplylist = unserialize(file_get_contents("{$g['tmp_path']}/.firewall_virtual_ip.apply"));
69
			foreach ($toapplylist as $vid => $ovip) {
70
				if (!empty($ovip))
71
					interface_vip_bring_down($ovip);
72
				if ($a_vip[$vid]) {
73
                			switch ($a_vip[$vid]['mode']) {
74
                			case "ipalias":
75
                        			interface_ipalias_configure($a_vip[$vid]);
76
                        			break;
77
                			case "proxyarp":
78
                        			interface_proxyarp_configure($a_vip[$vid]['interface']);
79
                        			break;
80
                			case "carp":
81
						$check_carp = true;
82
                        			interface_carp_configure($a_vip[$vid]);
83
						break;
84
                			default:
85
                        			break;
86
					}
87
                		}
88
        		}
89
			@unlink("{$g['tmp_path']}/.firewall_virtual_ip.apply");
90
		}
91
		/* Before changing check #4633 */
92
                if ($check_carp === true && !get_carp_status())
93
                        set_single_sysctl("net.inet.carp.allow", "1");
94

    
95
		$retval = 0;
96
		$retval |= filter_configure();
97
		$savemsg = get_std_save_message($retval);
98

    
99
		clear_subsystem_dirty('vip');
100
	}
101
}
102

    
103
if ($_GET['act'] == "del") {
104
	if ($a_vip[$_GET['id']]) {
105
		/* make sure no inbound NAT mappings reference this entry */
106
		if (is_array($config['nat']['rule'])) {
107
			foreach ($config['nat']['rule'] as $rule) {
108
				if($rule['destination']['address'] <> "") {
109
					if ($rule['destination']['address'] == $a_vip[$_GET['id']]['subnet']) {
110
						$input_errors[] = gettext("This entry cannot be deleted because it is still referenced by at least one NAT mapping.");
111
						break;
112
					}
113
				}
114
			}
115
		}
116

    
117
		/* make sure no OpenVPN server or client references this entry */
118
		$openvpn_types_a = array("openvpn-server" => gettext("server"), "openvpn-client" => gettext("client"));
119
		foreach ($openvpn_types_a as $openvpn_type => $openvpn_type_text) {
120
			if (is_array($config['openvpn'][$openvpn_type])) {
121
				foreach ($config['openvpn'][$openvpn_type] as $openvpn) {
122
					if ($openvpn['ipaddr'] <> "") {
123
						if ($openvpn['ipaddr'] == $a_vip[$_GET['id']]['subnet']) {
124
							if (strlen($openvpn['description'])) {
125
								$openvpn_desc = $openvpn['description'];
126
							} else {
127
								$openvpn_desc = $openvpn['ipaddr'] . ":" . $openvpn['local_port'];
128
							}
129
							$input_errors[] = sprintf(gettext("This entry cannot be deleted because it is still referenced by OpenVPN %s %s."), $openvpn_type_text, $openvpn_desc);
130
							break;
131
						}
132
					}
133
				}
134
			}
135
		}
136

    
137
		if (is_ipaddrv6($a_vip[$_GET['id']]['subnet'])) {
138
			$is_ipv6 = true;
139
			$subnet = gen_subnetv6($a_vip[$_GET['id']]['subnet'], $a_vip[$_GET['id']]['subnet_bits']);
140
			$if_subnet_bits = get_interface_subnetv6($a_vip[$_GET['id']]['interface']);
141
			$if_subnet = gen_subnetv6(get_interface_ipv6($a_vip[$_GET['id']]['interface']), $if_subnet_bits);
142
		} else {
143
			$is_ipv6 = false;
144
			$subnet = gen_subnet($a_vip[$_GET['id']]['subnet'], $a_vip[$_GET['id']]['subnet_bits']);
145
			$if_subnet_bits = get_interface_subnet($a_vip[$_GET['id']]['interface']);
146
			$if_subnet = gen_subnet(get_interface_ip($a_vip[$_GET['id']]['interface']), $if_subnet_bits);
147
		}
148

    
149
		$subnet .= "/" . $a_vip[$_GET['id']]['subnet_bits'];
150
		$if_subnet .= "/" . $if_subnet_bits;
151

    
152
		if (is_array($config['gateways']['gateway_item']))
153
			foreach($config['gateways']['gateway_item'] as $gateway) {
154
				if ($a_vip[$_GET['id']]['interface'] != $gateway['interface'])
155
					continue;
156
				if ($is_ipv6 && $gateway['ipprotocol'] == 'inet')
157
					continue;
158
				if (!$is_ipv6 && $gateway['ipprotocol'] == 'inet6')
159
					continue;
160
				if (ip_in_subnet($gateway['gateway'], $if_subnet))
161
					continue;
162

    
163
				if (ip_in_subnet($gateway['gateway'], $subnet)) {
164
					$input_errors[] = gettext("This entry cannot be deleted because it is still referenced by at least one Gateway.");
165
					break;
166
				}
167
			}
168

    
169
		if ($a_vip[$_GET['id']]['mode'] == "ipalias") {
170
			$subnet = gen_subnet($a_vip[$_GET['id']]['subnet'], $a_vip[$_GET['id']]['subnet_bits']) . "/" . $a_vip[$_GET['id']]['subnet_bits'];
171
			$found_if = false;
172
			$found_carp = false;
173
			$found_other_alias = false;
174

    
175
			if ($subnet == $if_subnet)
176
				$found_if = true;
177
			
178
			$vipiface = $a_vip[$_GET['id']]['interface'];
179
			foreach ($a_vip as $vip_id => $vip) {
180
				if ($vip_id == $_GET['id'])
181
					continue;
182

    
183
				if ($vip['interface'] == $vipiface && ip_in_subnet($vip['subnet'], $subnet))
184
					if ($vip['mode'] == "carp")
185
						$found_carp = true;
186
					else if ($vip['mode'] == "ipalias")
187
						$found_other_alias = true;
188
			}
189

    
190
			if ($found_carp === true && $found_other_alias === false && $found_if === false)
191
				$input_errors[] = gettext("This entry cannot be deleted because it is still referenced by a CARP IP with the description") . " {$vip['descr']}.";
192
		} else if ($a_vip[$_GET['id']]['mode'] == "carp") {
193
			$vipiface = "{$a_vip[$_GET['id']]['interface']}_vip{$a_vip[$_GET['id']]['vhid']}";
194
			foreach ($a_vip as $vip) {
195
				if ($vipiface == $vip['interface'] && $vip['mode'] == "ipalias")
196
					$input_errors[] = gettext("This entry cannot be deleted because it is still referenced by an IP alias entry with the description") . " {$vip['descr']}.";
197
			}
198
		}
199
		
200
		if (!$input_errors) {
201
			if (!session_id())
202
				session_start();
203
			$user = getUserEntry($_SESSION['Username']);
204
			if (is_array($user) && userHasPrivilege($user, "user-config-readonly")) {
205
				header("Location: firewall_virtual_ip.php");
206
				exit;
207
			}
208
			session_commit();
209

    
210
			// Special case since every proxyarp vip is handled by the same daemon.
211
			if ($a_vip[$_GET['id']]['mode'] == "proxyarp") {
212
				$viface = $a_vip[$_GET['id']]['interface'];
213
				unset($a_vip[$_GET['id']]);
214
				interface_proxyarp_configure($viface);
215
			} else {
216
				interface_vip_bring_down($a_vip[$_GET['id']]);
217
				unset($a_vip[$_GET['id']]);
218
			}
219
			if (count($config['virtualip']['vip']) == 0)
220
				unset($config['virtualip']['vip']);
221
			write_config();
222
			header("Location: firewall_virtual_ip.php");
223
			exit;
224
		}
225
	}
226
} else if ($_GET['changes'] == "mods" && is_numericint($_GET['id']))
227
	$id = $_GET['id'];
228

    
229
$pgtitle = array(gettext("Firewall"),gettext("Virtual IP Addresses"));
230
include("head.inc");
231

    
232
?>
233
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
234
<?php include("fbegin.inc"); ?>
235
<form action="firewall_virtual_ip.php" method="post">
236
<?php 
237
	if ($input_errors) 
238
		print_input_errors($input_errors);
239
	else
240
	if ($savemsg) 
241
		print_info_box($savemsg); 
242
	else
243
	if (is_subsystem_dirty('vip'))
244
		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."));
245
?>
246
<br />
247
<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="virtual ip">
248
  <tr><td class="tabnavtbl">
249
  <?php
250
        /* active tabs */
251
        $tab_array = array();
252
        $tab_array[] = array(gettext("Virtual IPs"), true, "firewall_virtual_ip.php");
253
        $tab_array[] = array(gettext("CARP Settings"), false, "system_hasync.php");
254
        display_top_tabs($tab_array);
255
  ?>
256
  </td></tr>
257
  <tr>
258
	<td><input type="hidden" id="id" name="id" value="<?php echo htmlspecialchars($id); ?>" /></td>
259
  </tr>
260
  <tr>
261
    <td>
262
	<div id="mainarea">
263
              <table class="tabcont sortable" width="100%" border="0" cellpadding="0" cellspacing="0" summary="main area">
264
                <tr>
265
                  <td width="30%" class="listhdrr"><?=gettext("Virtual IP address");?></td>
266
                  <td width="10%" class="listhdrr"><?=gettext("Interface");?></td>
267
                  <td width="10%" class="listhdrr"><?=gettext("Type");?></td>
268
                  <td width="40%" class="listhdr"><?=gettext("Description");?></td>
269
                  <td width="10%" class="list">
270
                    <table border="0" cellspacing="0" cellpadding="1" summary="edit">
271
                      <tr>
272
			<td width="17"></td>
273
                        <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>
274
                      </tr>
275
                    </table>
276
		  </td>
277
		</tr>
278
		<?php
279
			$interfaces = get_configured_interface_with_descr(false, true);
280
			$carplist = get_configured_carp_interface_list();
281
			foreach ($carplist as $cif => $carpip)
282
				$interfaces[$cif] = $carpip." (".get_vip_descr($carpip).")";
283
			$interfaces['lo0'] = "Localhost";
284
		?>
285
			  <?php $i = 0; foreach ($a_vip as $vipent): ?>
286
			  <?php if($vipent['subnet'] <> "" or $vipent['range'] <> "" or
287
			        $vipent['subnet_bits'] <> "" or (isset($vipent['range']['from']) && $vipent['range']['from'] <> "")): ?>
288
                <tr>
289
                  <td class="listlr" ondblclick="document.location='firewall_virtual_ip_edit.php?id=<?=$i;?>';">
290
					<?php	if (($vipent['type'] == "single") || ($vipent['type'] == "network"))
291
								if($vipent['subnet_bits'])
292
									echo "{$vipent['subnet']}/{$vipent['subnet_bits']}";
293
							if ($vipent['type'] == "range")
294
								echo "{$vipent['range']['from']}-{$vipent['range']['to']}";
295
					?>
296
					<?php if($vipent['mode'] == "carp") echo " (vhid {$vipent['vhid']})"; ?>
297
                  </td>
298
                  <td class="listr" ondblclick="document.location='firewall_virtual_ip_edit.php?id=<?=$i;?>';">
299
                    <?=htmlspecialchars($interfaces[$vipent['interface']]);?>&nbsp;
300
                  </td>
301
                  <td class="listr" align="center" ondblclick="document.location='firewall_virtual_ip_edit.php?id=<?=$i;?>';">
302
                    <?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' />";?>
303
                  </td>
304
                  <td class="listbg" ondblclick="document.location='firewall_virtual_ip_edit.php?id=<?=$i;?>';">
305
                    <?=htmlspecialchars($vipent['descr']);?>&nbsp;
306
                  </td>
307
                  <td class="list nowrap">
308
                    <table border="0" cellspacing="0" cellpadding="1" summary="icons">
309
                      <tr>
310
                        <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>
311
                        <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>
312
                      </tr>
313
                    </table>
314
                  </td>
315
                </tr>
316
		<?php endif; ?>
317
                <?php $i++; endforeach; ?>
318
			<tfoot>
319
				<tr>
320
					<td class="list" colspan="4"></td>
321
					<td class="list">
322
						<table border="0" cellspacing="0" cellpadding="1" summary="edit">
323
							<tr>
324
								<td width="17"></td>
325
								<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>
326
							</tr>
327
						</table>
328
					</td>
329
				</tr>
330
				<tr>
331
					<td colspan="5">
332
					  <p><span class="vexpl"><span class="red"><strong><?=gettext("Note:");?><br />
333
							  </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 />
334
							  <?=gettext("You can check the status of your CARP Virtual IPs and interfaces ");?><a href="carp_status.php"><?=gettext("here");?></a>.</span></p>
335
					</td>
336
				</tr>
337
			</tfoot>
338
		</table>
339
	   </div><!-- div:mainarea -->
340
	   </td></tr>
341
	</table>
342
  </form>
343
<?php include("fend.inc"); ?>
344
</body>
345
</html>
(79-79/251)