Project

General

Profile

Download (13.1 KB) Statistics
| Branch: | Tag: | Revision:
1
<?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
/*
40
	pfSense_BUILDER_BINARIES:	/sbin/ifconfig
41
	pfSense_MODULE:	interfaces
42
*/
43

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

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

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

    
110
		if (is_ipaddrv6($a_vip[$_GET['id']]['subnet'])) {
111
			$is_ipv6 = true;
112
			$subnet = gen_subnetv6($a_vip[$_GET['id']]['subnet'], $a_vip[$_GET['id']]['subnet_bits']);
113
			$if_subnet = gen_subnetv6(get_interface_ipv6($a_vip[$_GET['id']]['interface']), get_interface_subnetv6($a_vip[$_GET['id']]['interface']));
114
		} else {
115
			$is_ipv6 = false;
116
			$subnet = gen_subnet($a_vip[$_GET['id']]['subnet'], $a_vip[$_GET['id']]['subnet_bits']);
117
			$if_subnet = gen_subnet(get_interface_ip($a_vip[$_GET['id']]['interface']), get_interface_subnet($a_vip[$_GET['id']]['interface']));
118
		}
119

    
120
		$subnet .= "/" . $a_vip[$_GET['id']]['subnet_bits'];
121
		$if_subnet .= "/" . $if_subnet_bits;
122

    
123
		if (is_array($config['gateways']['gateway_item']))
124
			foreach($config['gateways']['gateway_item'] as $gateway) {
125
				if ($a_vip[$_GET['id']]['interface'] != $gateway['interface'])
126
					continue;
127
				if ($is_ipv6 && $gateway['ipprotocol'] == 'inet')
128
					continue;
129
				if (!$is_ipv6 && $gateway['ipprotocol'] == 'inet6')
130
					continue;
131
				if (ip_in_subnet($gateway['gateway'], $if_subnet))
132
					continue;
133

    
134
				if (ip_in_subnet($gateway['gateway'], $subnet)) {
135
					$input_errors[] = gettext("This entry cannot be deleted because it is still referenced by at least one Gateway.");
136
					break;
137
				}
138
			}
139

    
140
		if ($a_vip[$_GET['id']]['mode'] == "ipalias") {
141
			$found_carp = false;
142
			$found_other_alias = false;
143

    
144
			$vipiface = $a_vip[$_GET['id']]['interface'];
145
			foreach ($a_vip as $vip_id => $vip) {
146
				if ($vip_id == $_GET['id'])
147
					continue;
148

    
149
				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']))
150
					if ($vip['mode'] == "carp")
151
						$found_carp = true;
152
					else if ($vip['mode'] == "ipalias")
153
						$found_other_alias = true;
154
			}
155

    
156
			if ($found_carp === true && $found_other_alias === false)
157
				$input_errors[] = gettext("This entry cannot be deleted because it is still referenced by a CARP IP with the description") . " {$vip['descr']}.";
158
		} else if ($a_vip[$_GET['id']]['mode'] == "carp") {
159
			$vipiface = "{$a_vip[$_GET['id']]['interface']}_vip{$a_vip[$_GET['id']]['vhid']}";
160
			foreach ($a_vip as $vip) {
161
				if ($vipiface == $vip['interface'] && $vip['mode'] == "ipalias")
162
					$input_errors[] = gettext("This entry cannot be deleted because it is still referenced by an IP alias entry with the description") . " {$vip['descr']}.";
163
			}
164
		}
165

    
166
		
167
		if (!$input_errors) {
168
			if (!session_id())
169
				session_start();
170
			$user = getUserEntry($_SESSION['Username']);
171
			if (is_array($user) && userHasPrivilege($user, "user-config-readonly")) {
172
				header("Location: firewall_virtual_ip.php");
173
				exit;
174
			}
175
			session_commit();
176

    
177
			// Special case since every proxyarp vip is handled by the same daemon.
178
			if ($a_vip[$_GET['id']]['mode'] == "proxyarp") {
179
				$viface = $a_vip[$_GET['id']]['interface'];
180
				unset($a_vip[$_GET['id']]);
181
				interface_proxyarp_configure($viface);
182
			} else {
183
				interface_vip_bring_down($a_vip[$_GET['id']]);
184
				unset($a_vip[$_GET['id']]);
185
			}
186
			if (count($config['virtualip']['vip']) == 0)
187
				unset($config['virtualip']['vip']);
188
			write_config();
189
			header("Location: firewall_virtual_ip.php");
190
			exit;
191
		}
192
	}
193
} else if ($_GET['changes'] == "mods")
194
	$id = $_GET['id'];
195

    
196
$pgtitle = array(gettext("Firewall"),gettext("Virtual IP Addresses"));
197
include("head.inc");
198

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