Project

General

Profile

Download (14.1 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
		if (file_exists("{$g['tmp_path']}/.firewall_virtual_ip.apply")) {
67
                        $toapplylist = unserialize(file_get_contents("{$g['tmp_path']}/.firewall_virtual_ip.apply"));
68
			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
		$retval = 0;
90
		$retval |= filter_configure();
91
		$savemsg = get_std_save_message($retval);
92

    
93
		clear_subsystem_dirty('vip');
94
	}
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
				if($rule['destination']['address'] <> "") {
103
					if ($rule['destination']['address'] == $a_vip[$_GET['id']]['subnet']) {
104
						$input_errors[] = gettext("This entry cannot be deleted because it is still referenced by at least one NAT mapping.");
105
						break;
106
					}
107
				}
108
			}
109
		}
110

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

    
131
		if (is_ipaddrv6($a_vip[$_GET['id']]['subnet'])) {
132
			$is_ipv6 = true;
133
			$subnet = gen_subnetv6($a_vip[$_GET['id']]['subnet'], $a_vip[$_GET['id']]['subnet_bits']);
134
			$if_subnet_bits = get_interface_subnetv6($a_vip[$_GET['id']]['interface']);
135
			$if_subnet = gen_subnetv6(get_interface_ipv6($a_vip[$_GET['id']]['interface']), $if_subnet_bits);
136
		} else {
137
			$is_ipv6 = false;
138
			$subnet = gen_subnet($a_vip[$_GET['id']]['subnet'], $a_vip[$_GET['id']]['subnet_bits']);
139
			$if_subnet_bits = get_interface_subnet($a_vip[$_GET['id']]['interface']);
140
			$if_subnet = gen_subnet(get_interface_ip($a_vip[$_GET['id']]['interface']), $if_subnet_bits);
141
		}
142

    
143
		$subnet .= "/" . $a_vip[$_GET['id']]['subnet_bits'];
144
		$if_subnet .= "/" . $if_subnet_bits;
145

    
146
		if (is_array($config['gateways']['gateway_item']))
147
			foreach($config['gateways']['gateway_item'] as $gateway) {
148
				if ($a_vip[$_GET['id']]['interface'] != $gateway['interface'])
149
					continue;
150
				if ($is_ipv6 && $gateway['ipprotocol'] == 'inet')
151
					continue;
152
				if (!$is_ipv6 && $gateway['ipprotocol'] == 'inet6')
153
					continue;
154
				if (ip_in_subnet($gateway['gateway'], $if_subnet))
155
					continue;
156

    
157
				if (ip_in_subnet($gateway['gateway'], $subnet)) {
158
					$input_errors[] = gettext("This entry cannot be deleted because it is still referenced by at least one Gateway.");
159
					break;
160
				}
161
			}
162

    
163
		if ($a_vip[$_GET['id']]['mode'] == "ipalias") {
164
			$subnet = gen_subnet($a_vip[$_GET['id']]['subnet'], $a_vip[$_GET['id']]['subnet_bits']) . "/" . $a_vip[$_GET['id']]['subnet_bits'];
165
			$found_if = false;
166
			$found_carp = false;
167
			$found_other_alias = false;
168

    
169
			if ($subnet == $if_subnet)
170
				$found_if = true;
171
			
172
			$vipiface = $a_vip[$_GET['id']]['interface'];
173
			foreach ($a_vip as $vip_id => $vip) {
174
				if ($vip_id == $_GET['id'])
175
					continue;
176

    
177
				if ($vip['interface'] == $vipiface && ip_in_subnet($vip['subnet'], $subnet))
178
					if ($vip['mode'] == "carp")
179
						$found_carp = true;
180
					else if ($vip['mode'] == "ipalias")
181
						$found_other_alias = true;
182
			}
183

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

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

    
223
$pgtitle = array(gettext("Firewall"),gettext("Virtual IP Addresses"));
224
include("head.inc");
225

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