Project

General

Profile

Download (11.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 ($a_vip[$_GET['id']]['mode'] == "ipalias") {
111
			$vipiface = $a_vip[$_GET['id']]['interface'];
112
			foreach ($a_vip as $vip) {
113
				if ($vip['interface'] == $vipiface && $vip['mode'] == "carp")
114
					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']))
115
						$input_errors[] = gettext("This entry cannot be deleted because it is still referenced by a CARP IP with the description") . " {$vip['descr']}.";
116
			}
117
		} else if ($a_vip[$_GET['id']]['mode'] == "carp") {
118
			$vipiface = "{$a_vip[$_GET['id']]['interface']}_vip{$a_vip[$_GET['id']]['vhid']}";
119
			foreach ($a_vip as $vip) {
120
				if ($vipiface == $vip['interface'] && $vip['mode'] == "ipalias")
121
					$input_errors[] = gettext("This entry cannot be deleted because it is still referenced by an IP alias entry with the description") . " {$vip['descr']}.";
122
			}
123
		}
124

    
125
		
126
		if (!$input_errors) {
127
			if (!session_id())
128
				session_start();
129
			$user = getUserEntry($_SESSION['Username']);
130
			if (is_array($user) && userHasPrivilege($user, "user-config-readonly")) {
131
				header("Location: firewall_virtual_ip.php");
132
				exit;
133
			}
134
			session_commit();
135

    
136
			// Special case since every proxyarp vip is handled by the same daemon.
137
			if ($a_vip[$_GET['id']]['mode'] == "proxyarp") {
138
				$viface = $a_vip[$_GET['id']]['interface'];
139
				unset($a_vip[$_GET['id']]);
140
				interface_proxyarp_configure($viface);
141
			} else {
142
				interface_vip_bring_down($a_vip[$_GET['id']]);
143
				unset($a_vip[$_GET['id']]);
144
			}
145
			if (count($config['virtualip']['vip']) == 0)
146
				unset($config['virtualip']['vip']);
147
			write_config();
148
			header("Location: firewall_virtual_ip.php");
149
			exit;
150
		}
151
	}
152
} else if ($_GET['changes'] == "mods")
153
	$id = $_GET['id'];
154

    
155
$pgtitle = array(gettext("Firewall"),gettext("Virtual IP Addresses"));
156
include("head.inc");
157

    
158
?>
159
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
160
<?php include("fbegin.inc"); ?>
161
<form action="firewall_virtual_ip.php" method="post">
162
<?php 
163
	if ($input_errors) 
164
		print_input_errors($input_errors);
165
	else
166
	if ($savemsg) 
167
		print_info_box($savemsg); 
168
	else
169
	if (is_subsystem_dirty('vip'))
170
		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."));
171
?>
172
<br>
173
<table width="100%" border="0" cellpadding="0" cellspacing="0">
174
  <tr><td class="tabnavtbl">
175
  <?php
176
        /* active tabs */
177
        $tab_array = array();
178
        $tab_array[] = array(gettext("Virtual IPs"), true, "firewall_virtual_ip.php");
179
        $tab_array[] = array(gettext("CARP Settings"), false, "system_hasync.php");
180
        display_top_tabs($tab_array);
181
  ?>
182
  </td></tr>
183
  <tr>
184
	<td><input type="hidden" id="id" name="id" value="<?php echo $id; ?>"></td>
185
  </tr>
186
  <tr>
187
    <td>
188
	<div id="mainarea">
189
              <table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
190
                <tr>
191
                  <td width="30%" class="listhdrr"><?=gettext("Virtual IP address");?></td>
192
                  <td width="10%" class="listhdrr"><?=gettext("Interface");?></td>
193
                  <td width="10%" class="listhdrr"><?=gettext("Type");?></td>
194
                  <td width="40%" class="listhdr"><?=gettext("Description");?></td>
195
                  <td width="10%" class="list">
196
                    <table border="0" cellspacing="0" cellpadding="1">
197
                      <tr>
198
			<td width="17"></td>
199
                        <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>
200
                      </tr>
201
                    </table>
202
		  </td>
203
		</tr>
204
			  <?php $i = 0; foreach ($a_vip as $vipent): ?>
205
			  <?php if($vipent['subnet'] <> "" or $vipent['range'] <> "" or
206
			        $vipent['subnet_bits'] <> "" or (isset($vipent['range']['from']) && $vipent['range']['from'] <> "")): ?>
207
                <tr>
208
                  <td class="listlr" ondblclick="document.location='firewall_virtual_ip_edit.php?id=<?=$i;?>';">
209
					<?php	if (($vipent['type'] == "single") || ($vipent['type'] == "network"))
210
								if($vipent['subnet_bits'])
211
									echo "{$vipent['subnet']}/{$vipent['subnet_bits']}";
212
							if ($vipent['type'] == "range")
213
								echo "{$vipent['range']['from']}-{$vipent['range']['to']}";
214
					?>
215
					<?php if($vipent['mode'] == "carp") echo " (vhid {$vipent['vhid']})"; ?>
216
                  </td>
217
                  <td class="listr" ondblclick="document.location='firewall_virtual_ip_edit.php?id=<?=$i;?>';">
218
                    <?=htmlspecialchars(strtoupper($config['interfaces'][$vipent['interface']]['descr']));?>&nbsp;
219
                  </td>
220
                  <td class="listr" align="center" ondblclick="document.location='firewall_virtual_ip_edit.php?id=<?=$i;?>';">
221
                    <?php if($vipent['mode'] == "proxyarp") echo "<img src='./themes/".$g['theme']."/images/icons/icon_parp.gif' title='Proxy ARP'>"; elseif($vipent['mode'] == "carp") 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'>";?>
222
                  </td>
223
                  <td class="listbg" ondblclick="document.location='firewall_virtual_ip_edit.php?id=<?=$i;?>';">
224
                    <?=htmlspecialchars($vipent['descr']);?>&nbsp;
225
                  </td>
226
                  <td class="list" nowrap>
227
                    <table border="0" cellspacing="0" cellpadding="1">
228
                      <tr>
229
                        <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>
230
                        <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>
231
                      </tr>
232
                    </table>
233
                  </td>
234
                </tr>
235
		<?php endif; ?>
236
                <?php $i++; endforeach; ?>
237
                <tr>
238
                  <td class="list" colspan="4"></td>
239
                  <td class="list">
240
                    <table border="0" cellspacing="0" cellpadding="1">
241
                      <tr>
242
			<td width="17"></td>
243
                        <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>
244
                      </tr>
245
                    </table>
246
                  </td>
247
                </tr>
248
		<tr>
249
		  <td colspan="5">
250
		      <p><span class="vexpl"><span class="red"><strong><?=gettext("Note:");?><br>
251
                      </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>
252
                      <?=gettext("You can check the status of your CARP Virtual IPs and interfaces ");?><a href="carp_status.php"><?=gettext("here");?></a>.</span></p>
253
		  </td>
254
		</tr>
255
              </table>
256
	   </div>
257
	</table>
258
            </form>
259
<?php include("fend.inc"); ?>
260
</body>
261
</html>
(78-78/249)