Project

General

Profile

Download (8.34 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
require("guiconfig.inc");
41

    
42
if (!is_array($config['virtualip']['vip'])) {
43
	$config['virtualip']['vip'] = array();
44
}
45
$a_vip = &$config['virtualip']['vip'];
46

    
47
if ($_GET['act'] == "del") {
48
	if ($a_vip[$_GET['id']]) {
49
		/* make sure no inbound NAT mappings reference this entry */
50
		if (is_array($config['nat']['rule'])) {
51
			foreach ($config['nat']['rule'] as $rule) {
52
				if($rule['external-address'] <> "") {
53
					if ($rule['external-address'] == $a_vip[$_GET['id']]['ipaddr']) {
54
						$input_errors[] = "This entry cannot be deleted because it is still referenced by at least one NAT mapping.";
55
						unlink("/tmp/carp_reboot_needed");
56
						break;
57
					}
58
				}
59
			}
60
		}
61

    
62
		if (!$input_errors) {
63
			if($a_vip[$_GET['id']]['mode'] == "carp")  
64
				touch("/tmp/carp_reboot_needed");
65
			unset($a_vip[$_GET['id']]);
66
			write_config();
67
			touch($d_vipconfdirty_path);
68
			header("Location: firewall_virtual_ip.php");
69
			exit;
70
		}
71
	}
72
}
73

    
74
if ($_POST['apply']) {
75
	if (file_exists("/tmp/carp_reboot_needed")) {
76
		$savemsg = "The firewall is now rebooting, please wait.";	
77
		unlink_if_exists($d_vipconfdirty_path);
78
	}
79
}
80

    
81
if ($_POST) {
82
			unlink_if_exists($d_vipconfdirty_path);
83
}
84

    
85
$pgtitle = "Firewall: Virtual IP Addresses";
86
include("head.inc");
87

    
88
?>
89
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
90
<?php include("fbegin.inc"); ?>
91
<p class="pgtitle"><?=$pgtitle?></p>
92
<form action="firewall_virtual_ip.php" method="post">
93
<?php 
94
	if ($input_errors) 
95
		print_input_errors($input_errors);
96
	else if ($savemsg) 
97
		print_info_box($savemsg);
98
	else if (file_exists("/tmp/carp_reboot_needed"))
99
		print_info_box_np("The VIP configuration changes require a reboot to apply. <br>THE FIREWALL WILL REBOOT WHEN YOU CLICK APPLY CHANGES.<br>You must manually reboot your secondary firewall for these changes to apply to it.");
100
	else if (file_exists($d_vipconfdirty_path))
101
		print_info_box_np("The VIP configuration has been changed.<br>You must apply the changes in order for them to take effect.");
102
?>
103
<p>
104
<table width="100%" border="0" cellpadding="0" cellspacing="0">
105
  <tr><td class="tabnavtbl">
106
  <?php
107
        /* active tabs */
108
        $tab_array = array();
109
        $tab_array[] = array("Virtual IPs", true, "firewall_virtual_ip.php");
110
        $tab_array[] = array("CARP Settings", false, "pkg_edit.php?xml=carp_settings.xml&id=0");
111
        display_top_tabs($tab_array);
112
  ?>
113
  </td></tr>
114
  <tr>
115
    <td>
116
	<div id="mainarea">
117
              <table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
118
                <tr>
119
                  <td width="30%" class="listhdrr">Virtual IP address</td>
120
                  <td width="10%" class="listhdrr">Type</td>
121
                  <td width="40%" class="listhdr">Description</td>
122
                  <td width="10%" class="list">
123
                    <table border="0" cellspacing="0" cellpadding="1">
124
                      <tr>
125
			<td width="17"></td>
126
                        <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>
127
                      </tr>
128
                    </table>
129
		  </td>
130
		</tr>
131
			  <?php $i = 0; foreach ($a_vip as $vipent): ?>
132
			  <?php if($vipent['subnet'] <> "" or $vipent['range'] <> "" or
133
			        $vipent['subnet_bits'] <> "" or $vipent['range']['from'] <> ""): ?>
134
                <tr>
135
                  <td class="listlr" ondblclick="document.location='firewall_virtual_ip_edit.php?id=<?=$i;?>';">
136
					<?php	if (($vipent['type'] == "single") || ($vipent['type'] == "network"))
137
								echo "{$vipent['subnet']}/{$vipent['subnet_bits']}";
138
							if ($vipent['type'] == "range")
139
								echo "{$vipent['range']['from']}-{$vipent['range']['to']}";
140
					?>
141
					<?php if($vipent['mode'] == "carp") echo " (vhid {$vipent['vhid']})"; ?>
142
                  </td>
143
                  <td class="listlr" align="center" ondblclick="document.location='firewall_virtual_ip_edit.php?id=<?=$i;?>';">
144
                    <? 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'>";?>
145
                  </td>
146
                  <td class="listbg" ondblclick="document.location='firewall_virtual_ip_edit.php?id=<?=$i;?>';">
147
                    <font color="#FFFFFF"><?=htmlspecialchars($vipent['descr']);?>&nbsp;
148
                  </td>
149
                  <td class="list" nowrap>
150
                    <table border="0" cellspacing="0" cellpadding="1">
151
                      <tr>
152
                        <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>
153
                        <td valign="middle"><a href="firewall_virtual_ip.php?act=del&id=<?=$i;?>" onclick="return confirm('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>
154
                      </tr>
155
                    </table>
156
                  </td>
157
                </tr>
158
		<?php endif; ?>
159
                <?php $i++; endforeach; ?>
160
                <tr>
161
                  <td class="list" colspan="3"></td>
162
                  <td class="list">
163
                    <table border="0" cellspacing="0" cellpadding="1">
164
                      <tr>
165
			<td width="17"></td>
166
                        <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>
167
                      </tr>
168
                    </table>
169
                  </td>
170
                </tr>
171
		<tr>
172
		  <td colspan="4">
173
		      <p><span class="vexpl"><span class="red"><strong>Note:<br>
174
                      </strong></span>The virtual IP addresses defined on this page may be used in <a href="firewall_nat.php">NAT</a> mappings.<br>
175
                      You can check the status of your CARP Virtual IPs and interfaces <a href="carp_status.php">here</a>.</span></p>
176
		  </td>
177
		</tr>
178
              </table>
179
	   </div>
180
	</table>
181
            </form>
182
<?php include("fend.inc"); ?>
183
</body>
184
</html>
185

    
186
<?php 
187

    
188
if ($_POST) {
189
	$pconfig = $_POST;
190

    
191
	if ($_POST['apply']) {
192
		if (file_exists("/tmp/carp_reboot_needed")) {
193
			flush();
194
			ob_flush();
195
			usleep(1000);
196
			mwexec_bg("sleep 3; /sbin/shutdown -r now");
197
			exit;
198
		} else {
199
			$retval = 0;
200
	
201
			config_lock();
202
			$retval = services_proxyarp_configure();
203
			/* Bring up any configured CARP interfaces */
204
			reset_carp();
205
			$retval |= filter_configure();
206
			config_unlock();
207
			
208
			unlink_if_exists($d_vipconfdirty_path);
209
		}
210
	}
211
}
212

    
213
?>
(58-58/173)