Project

General

Profile

Download (9.8 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
		$toapplylist = array();
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) {
69
			if ($a_vip[$vid]) {
70
                		switch ($a_vip[$vid]['mode']) {
71
                		case "ipalias":
72
                        		interface_ipalias_configure($a_vip[$vid]);
73
                        		break;
74
                		case "proxyarp":
75
                        		interface_proxyarp_configure($a_vip[$vid]['interface']);
76
                        		break;
77
                		case "carp":
78
                        		interface_carp_configure($a_vip[$vid]);
79
					break;
80
                		case "carpdev-dhcp":
81
                        		interface_carpdev_configure($a_vip[$vid]);
82
                        		break;
83
                		default:
84
                        		break;
85
				}
86
                	}
87
        	}
88
		@unlink("{$g['tmp_path']}/firewall_virtual_ip.apply");
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
		if (!$input_errors) {
112
			// Special case since every proxyarp vip is handled by the same daemon.
113
			if ($a_vip[$_GET['id']]['mode'] == "proxyarp") {
114
				unset($a_vip[$_GET['id']]);
115
				interface_proxyarp_configure();
116
			} else {
117
				interface_vip_bring_down($a_vip[$_GET['id']]);
118
				unset($a_vip[$_GET['id']]);
119
			}
120
			if (count($config['virtualip']['vip']) == 0)
121
				unset($config['virtualip']['vip']);
122
			write_config();
123
			mark_subsystem_dirty('vip');
124
			header("Location: firewall_virtual_ip.php");
125
			exit;
126
		}
127
	}
128
} else if ($_GET['changes'] == "mods")
129
	$id = $_GET['id'];
130

    
131
$pgtitle = array(gettext("Firewall"),gettext("Virtual IP Addresses"));
132
include("head.inc");
133

    
134
?>
135
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
136
<?php include("fbegin.inc"); ?>
137
<form action="firewall_virtual_ip.php" method="post">
138
<?php 
139
	if ($input_errors) 
140
		print_input_errors($input_errors);
141
	else
142
	if ($savemsg) 
143
		print_info_box($savemsg); 
144
	else
145
	if (is_subsystem_dirty('vip'))
146
		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."));
147
?>
148
<br>
149
<table width="100%" border="0" cellpadding="0" cellspacing="0">
150
  <tr><td class="tabnavtbl">
151
  <?php
152
        /* active tabs */
153
        $tab_array = array();
154
        $tab_array[] = array(gettext("Virtual IPs"), true, "firewall_virtual_ip.php");
155
        $tab_array[] = array(gettext("CARP Settings"), false, "pkg_edit.php?xml=carp_settings.xml&id=0");
156
        display_top_tabs($tab_array);
157
  ?>
158
  </td></tr>
159
  <tr>
160
	<td><input type="hidden" id="id" name="id" value="<? echo $id; ?>"></td>
161
  </tr>
162
  <tr>
163
    <td>
164
	<div id="mainarea">
165
              <table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
166
                <tr>
167
                  <td width="30%" class="listhdrr"><?=gettext("Virtual IP address");?></td>
168
                  <td width="10%" class="listhdrr"><?=gettext("Type");?></td>
169
                  <td width="40%" class="listhdr"><?=gettext("Description");?></td>
170
                  <td width="10%" class="list">
171
                    <table border="0" cellspacing="0" cellpadding="1">
172
                      <tr>
173
			<td width="17"></td>
174
                        <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>
175
                      </tr>
176
                    </table>
177
		  </td>
178
		</tr>
179
			  <?php $i = 0; foreach ($a_vip as $vipent): ?>
180
			  <?php if($vipent['subnet'] <> "" or $vipent['range'] <> "" or
181
			        $vipent['subnet_bits'] <> "" or (isset($vipent['range']['from']) && $vipent['range']['from'] <> "") or $vipent['mode'] == "carpdev-dhcp"): ?>
182
                <tr>
183
                  <td class="listlr" ondblclick="document.location='firewall_virtual_ip_edit.php?id=<?=$i;?>';">
184
					<?php	if (($vipent['type'] == "single") || ($vipent['type'] == "network"))
185
								if($vipent['subnet_bits'])
186
									echo "{$vipent['subnet']}/{$vipent['subnet_bits']}";
187
							if ($vipent['type'] == "range")
188
								echo "{$vipent['range']['from']}-{$vipent['range']['to']}";
189
					?>
190
					<?php if($vipent['mode'] == "carpdev-dhcp") echo "DHCP"; ?>
191
					<?php if($vipent['mode'] == "carp" or $vipent['mode'] == "carpdev-dhcp") echo " (vhid {$vipent['vhid']})"; ?>
192
                  </td>
193
                  <td class="listr" align="center" ondblclick="document.location='firewall_virtual_ip_edit.php?id=<?=$i;?>';">
194
                    <? 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'>";?>
195
                  </td>
196
                  <td class="listbg" ondblclick="document.location='firewall_virtual_ip_edit.php?id=<?=$i;?>';">
197
                    <?=htmlspecialchars($vipent['descr']);?>&nbsp;
198
                  </td>
199
                  <td class="list" nowrap>
200
                    <table border="0" cellspacing="0" cellpadding="1">
201
                      <tr>
202
                        <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>
203
                        <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>
204
                      </tr>
205
                    </table>
206
                  </td>
207
                </tr>
208
		<?php endif; ?>
209
                <?php $i++; endforeach; ?>
210
                <tr>
211
                  <td class="list" colspan="3"></td>
212
                  <td class="list">
213
                    <table border="0" cellspacing="0" cellpadding="1">
214
                      <tr>
215
			<td width="17"></td>
216
                        <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>
217
                      </tr>
218
                    </table>
219
                  </td>
220
                </tr>
221
		<tr>
222
		  <td colspan="4">
223
		      <p><span class="vexpl"><span class="red"><strong><?=gettext("Note");?>:<br>
224
                      </strong></span><?=gettext("The virtual IP addresses defined on this page may be used in");?><a href="firewall_nat.php"> NAT </a><?=gettext("mappings.");?><br>
225
                      <?=gettext("You can check the status of your CARP Virtual IPs and interfaces ");?><a href="carp_status.php"><?=gettext("here");?></a>.</span></p>
226
		  </td>
227
		</tr>
228
              </table>
229
	   </div>
230
	</table>
231
            </form>
232
<?php include("fend.inc"); ?>
233
</body>
234
</html>
(65-65/221)