Project

General

Profile

Download (10.7 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
                			case "carpdev-dhcp":
82
                        			interface_carpdev_configure($a_vip[$vid]);
83
                        			break;
84
                			default:
85
                        			break;
86
					}
87
                		}
88
        		}
89
			@unlink("{$g['tmp_path']}/.firewall_virtual_ip.apply");
90
		}
91 b0ae75c5 Bill Marquette
		$retval = 0;
92 920b3bb0 Scott Ullrich
		$retval |= filter_configure();
93 b0ae75c5 Bill Marquette
		$savemsg = get_std_save_message($retval);
94 abcb2bed Ermal Lu?i
95 a368a026 Ermal Lu?i
		clear_subsystem_dirty('vip');
96 b0ae75c5 Bill Marquette
	}
97
}
98
99
if ($_GET['act'] == "del") {
100
	if ($a_vip[$_GET['id']]) {
101
		/* make sure no inbound NAT mappings reference this entry */
102
		if (is_array($config['nat']['rule'])) {
103
			foreach ($config['nat']['rule'] as $rule) {
104 93e485e3 Renato Botelho
				if($rule['destination']['address'] <> "") {
105 3504e10b Renato Botelho
					if ($rule['destination']['address'] == $a_vip[$_GET['id']]['subnet']) {
106 3e2a70d9 Rafael Lucas
						$input_errors[] = gettext("This entry cannot be deleted because it is still referenced by at least one NAT mapping.");
107 7c99b15c Scott Ullrich
						break;
108
					}
109 b0ae75c5 Bill Marquette
				}
110
			}
111
		}
112
113 e8471084 Ermal
		if ($a_vip[$_GET['id']]['mode'] == "ipalias") {
114 e19b7d1e Ermal
			$vipiface = $a_vip[$_GET['id']]['interface'];
115
			foreach ($a_vip as $vip) {
116
				if ($vip['interface'] == $vipiface && $vip['mode'] == "carp")
117
					if (ip_in_subnet($vip['subnet'], gen_subnet($a_vip[$_GET['id']]['subnet'], $a_vip[$_GET['id']]['subnet_bits']) . "/" . $a_vip[$_GET['id']]['subnet_bits']))
118
						$input_errors[] = gettext("This entry cannot be deleted because it is still referenced by CARP") . " {$vip['descr']}.";
119
			}
120 82db1bc5 Ermal
		} else if ($a_vip[$_GET['id']]['mode'] == "carp") {
121 7b47bd4c Ermal
			$vipiface = "{$a_vip[$_GET['id']]['interface']}_vip{$a_vip[$_GET['id']]['vhid']}";
122 82db1bc5 Ermal
			foreach ($a_vip as $vip) {
123 1127df5f Ermal
				if ($vipiface == $vip['interface'] && $vip['mode'] == "ipalias")
124 82db1bc5 Ermal
					$input_errors[] = gettext("This entry cannot be deleted because it is still referenced by ip alias entry") . " {$vip['descr']}.";
125
			}
126 e19b7d1e Ermal
		}
127
128 e8471084 Ermal
		
129 b0ae75c5 Bill Marquette
		if (!$input_errors) {
130 1ba7a81b Ermal Lu?i
			// Special case since every proxyarp vip is handled by the same daemon.
131
			if ($a_vip[$_GET['id']]['mode'] == "proxyarp") {
132 e8471084 Ermal
				$viface = $a_vip[$_GET['id']]['interface'];
133 1ba7a81b Ermal Lu?i
				unset($a_vip[$_GET['id']]);
134 e8471084 Ermal
				interface_proxyarp_configure($viface);
135 1ba7a81b Ermal Lu?i
			} else {
136
				interface_vip_bring_down($a_vip[$_GET['id']]);
137
				unset($a_vip[$_GET['id']]);
138
			}
139 ed65eb04 Ermal Lu?i
			if (count($config['virtualip']['vip']) == 0)
140
				unset($config['virtualip']['vip']);
141 b0ae75c5 Bill Marquette
			write_config();
142 406abd6e Rafael Lucas
			header("Location: firewall_virtual_ip.php");
143 b0ae75c5 Bill Marquette
			exit;
144
		}
145
	}
146 abcb2bed Ermal Lu?i
} else if ($_GET['changes'] == "mods")
147
	$id = $_GET['id'];
148 b0ae75c5 Bill Marquette
149 3e2a70d9 Rafael Lucas
$pgtitle = array(gettext("Firewall"),gettext("Virtual IP Addresses"));
150 b0ae75c5 Bill Marquette
include("head.inc");
151
152
?>
153
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
154
<?php include("fbegin.inc"); ?>
155
<form action="firewall_virtual_ip.php" method="post">
156 b760a120 Scott Ullrich
<?php 
157
	if ($input_errors) 
158
		print_input_errors($input_errors);
159
	else
160
	if ($savemsg) 
161
		print_info_box($savemsg); 
162
	else
163 a368a026 Ermal Lu?i
	if (is_subsystem_dirty('vip'))
164 3c7b2c1e Vinicius Coque
		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."));
165 b760a120 Scott Ullrich
?>
166
<br>
167 49424ec0 Bill Marquette
<table width="100%" border="0" cellpadding="0" cellspacing="0">
168
  <tr><td class="tabnavtbl">
169
  <?php
170
        /* active tabs */
171
        $tab_array = array();
172 3e2a70d9 Rafael Lucas
        $tab_array[] = array(gettext("Virtual IPs"), true, "firewall_virtual_ip.php");
173 f97a5b04 Darren Embry
        $tab_array[] = array(gettext("CARP Settings"), false, "system_hasync.php");
174 49424ec0 Bill Marquette
        display_top_tabs($tab_array);
175
  ?>
176 b0ae75c5 Bill Marquette
  </td></tr>
177 abcb2bed Ermal Lu?i
  <tr>
178
	<td><input type="hidden" id="id" name="id" value="<? echo $id; ?>"></td>
179
  </tr>
180 b0ae75c5 Bill Marquette
  <tr>
181
    <td>
182
	<div id="mainarea">
183
              <table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
184
                <tr>
185 3e2a70d9 Rafael Lucas
                  <td width="30%" class="listhdrr"><?=gettext("Virtual IP address");?></td>
186
                  <td width="10%" class="listhdrr"><?=gettext("Type");?></td>
187
                  <td width="40%" class="listhdr"><?=gettext("Description");?></td>
188 d415d821 Seth Mos
                  <td width="10%" class="list">
189
                    <table border="0" cellspacing="0" cellpadding="1">
190
                      <tr>
191
			<td width="17"></td>
192
                        <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"></a></td>
193
                      </tr>
194
                    </table>
195
		  </td>
196
		</tr>
197 b0ae75c5 Bill Marquette
			  <?php $i = 0; foreach ($a_vip as $vipent): ?>
198 21784301 Scott Ullrich
			  <?php if($vipent['subnet'] <> "" or $vipent['range'] <> "" or
199 2064fb9d Ermal Lu?i
			        $vipent['subnet_bits'] <> "" or (isset($vipent['range']['from']) && $vipent['range']['from'] <> "") or $vipent['mode'] == "carpdev-dhcp"): ?>
200 b0ae75c5 Bill Marquette
                <tr>
201
                  <td class="listlr" ondblclick="document.location='firewall_virtual_ip_edit.php?id=<?=$i;?>';">
202
					<?php	if (($vipent['type'] == "single") || ($vipent['type'] == "network"))
203 2db680e1 Scott Ullrich
								if($vipent['subnet_bits'])
204
									echo "{$vipent['subnet']}/{$vipent['subnet_bits']}";
205 b0ae75c5 Bill Marquette
							if ($vipent['type'] == "range")
206
								echo "{$vipent['range']['from']}-{$vipent['range']['to']}";
207
					?>
208 2db680e1 Scott Ullrich
					<?php if($vipent['mode'] == "carpdev-dhcp") echo "DHCP"; ?>
209 7633ddd8 Scott Ullrich
					<?php if($vipent['mode'] == "carp" or $vipent['mode'] == "carpdev-dhcp") echo " (vhid {$vipent['vhid']})"; ?>
210 b0ae75c5 Bill Marquette
                  </td>
211 902b4e72 Bill Marquette
                  <td class="listr" align="center" ondblclick="document.location='firewall_virtual_ip_edit.php?id=<?=$i;?>';">
212 3dee90e6 Bill Marquette
                    <? if($vipent['mode'] == "proxyarp") echo "<img src='./themes/".$g['theme']."/images/icons/icon_parp.gif' title='Proxy ARP'>"; elseif($vipent['mode'] == "carp" or $vipent['mode'] == "carpdev-dhcp") echo "<img src='./themes/".$g['theme']."/images/icons/icon_carp.gif' title='CARP'>"; elseif($vipent['mode'] == "other") echo "<img src='./themes/".$g['theme']."/images/icons/icon_other.gif' title='Other'>"; elseif($vipent['mode'] == "ipalias") echo "<img src='./themes/".$g['theme']."/images/icons/icon_ifalias.gif' title='IP Alias'>";?>
213 b0ae75c5 Bill Marquette
                  </td>
214
                  <td class="listbg" ondblclick="document.location='firewall_virtual_ip_edit.php?id=<?=$i;?>';">
215 30d4c469 Scott Ullrich
                    <?=htmlspecialchars($vipent['descr']);?>&nbsp;
216 b0ae75c5 Bill Marquette
                  </td>
217
                  <td class="list" nowrap>
218
                    <table border="0" cellspacing="0" cellpadding="1">
219
                      <tr>
220 677c0869 Erik Kristensen
                        <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"></a></td>
221 c59639d1 Vinicius Coque
                        <td valign="middle"><a href="firewall_virtual_ip.php?act=del&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"></a></td>
222 b0ae75c5 Bill Marquette
                      </tr>
223
                    </table>
224
                  </td>
225
                </tr>
226 21784301 Scott Ullrich
		<?php endif; ?>
227 b0ae75c5 Bill Marquette
                <?php $i++; endforeach; ?>
228
                <tr>
229 9f3103a9 Bill Marquette
                  <td class="list" colspan="3"></td>
230 b0ae75c5 Bill Marquette
                  <td class="list">
231
                    <table border="0" cellspacing="0" cellpadding="1">
232
                      <tr>
233 d415d821 Seth Mos
			<td width="17"></td>
234 677c0869 Erik Kristensen
                        <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"></a></td>
235 b0ae75c5 Bill Marquette
                      </tr>
236
                    </table>
237
                  </td>
238
                </tr>
239
		<tr>
240
		  <td colspan="4">
241 f8c0efc9 Vinicius Coque
		      <p><span class="vexpl"><span class="red"><strong><?=gettext("Note:");?><br>
242 e4fc92de Carlos Eduardo Ramos
                      </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>
243 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>
244 b0ae75c5 Bill Marquette
		  </td>
245
		</tr>
246
              </table>
247
	   </div>
248
	</table>
249
            </form>
250
<?php include("fend.inc"); ?>
251
</body>
252
</html>