Project

General

Profile

Download (7.85 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	carp_status.php
5
*/
6
/* ====================================================================
7
 *  Copyright (c)  2004-2015  Electric Sheep Fencing, LLC. All rights reserved. 
8
 *  Copyright (c)  2004, 2005 Scott Ullrich
9
 *
10
 *  Redistribution and use in source and binary forms, with or without modification, 
11
 *  are permitted provided that the following conditions are met: 
12
 *
13
 *  1. Redistributions of source code must retain the above copyright notice,
14
 *      this list of conditions and the following disclaimer.
15
 *
16
 *  2. Redistributions in binary form must reproduce the above copyright
17
 *      notice, this list of conditions and the following disclaimer in
18
 *      the documentation and/or other materials provided with the
19
 *      distribution. 
20
 *
21
 *  3. All advertising materials mentioning features or use of this software 
22
 *      must display the following acknowledgment:
23
 *      "This product includes software developed by the pfSense Project
24
 *       for use in the pfSense software distribution. (http://www.pfsense.org/). 
25
 *
26
 *  4. The names "pfSense" and "pfSense Project" must not be used to
27
 *       endorse or promote products derived from this software without
28
 *       prior written permission. For written permission, please contact
29
 *       coreteam@pfsense.org.
30
 *
31
 *  5. Products derived from this software may not be called "pfSense"
32
 *      nor may "pfSense" appear in their names without prior written
33
 *      permission of the Electric Sheep Fencing, LLC.
34
 *
35
 *  6. Redistributions of any form whatsoever must retain the following
36
 *      acknowledgment:
37
 *
38
 *  "This product includes software developed by the pfSense Project
39
 *  for use in the pfSense software distribution (http://www.pfsense.org/).
40
  *
41
 *  THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
42
 *  EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43
 *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
44
 *  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
45
 *  ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
46
 *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
47
 *  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
48
 *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
49
 *  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
50
 *  STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
51
 *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
52
 *  OF THE POSSIBILITY OF SUCH DAMAGE.
53
 *
54
 *  ====================================================================
55
 *
56
 */
57

    
58
##|+PRIV
59
##|*IDENT=page-status-carp
60
##|*NAME=Status: CARP page
61
##|*DESCR=Allow access to the 'Status: CARP' page.
62
##|*MATCH=carp_status.php*
63
##|-PRIV
64

    
65
/*
66
	pfSense_MODULE:	carp
67
*/
68

    
69
require_once("guiconfig.inc");
70
require_once("globals.inc");
71

    
72
function gentitle_pkg($pgname) {
73
	global $config;
74
	return $config['system']['hostname'] . "." . $config['system']['domain'] . " - " . $pgname;
75
}
76

    
77
unset($interface_arr_cache);
78
unset($carp_interface_count_cache);
79
unset($interface_ip_arr_cache);
80

    
81
$status = get_carp_status();
82
$status = intval($status);
83
if ($_POST['carp_maintenancemode'] <> "") {
84
	interfaces_carp_set_maintenancemode(!isset($config["virtualip_carp_maintenancemode"]));
85
}
86
if ($_POST['disablecarp'] <> "") {
87
	if ($status > 0) {
88
		set_single_sysctl('net.inet.carp.allow', '0');
89
		if (is_array($config['virtualip']['vip'])) {
90
			$viparr = &$config['virtualip']['vip'];
91
			$found_dhcpdv6 = false;
92
			foreach ($viparr as $vip) {
93
				$carp_iface = "{$vip['interface']}_vip{$vip['vhid']}";
94
				switch ($vip['mode']) {
95
					case "carp":
96
						interface_vip_bring_down($vip);
97
						interface_ipalias_cleanup($carp_iface);
98

    
99
						/*
100
						 * Reconfigure radvd when necessary
101
						 * XXX: Is it the best way to do it?
102
						 */
103
						if (isset($config['dhcpdv6']) && is_array($config['dhcpdv6'])) {
104
							foreach ($config['dhcpdv6'] as $dhcpv6if => $dhcpv6ifconf) {
105
								if ($dhcpv6ifconf['rainterface'] != $carp_iface) {
106
									continue;
107
								}
108

    
109
								services_radvd_configure();
110
								break;
111
							}
112
						}
113

    
114
						sleep(1);
115
						break;
116
				}
117
			}
118
		}
119
		$savemsg = sprintf(gettext("%s IPs have been disabled. Please note that disabling does not survive a reboot and some configuration changes will re-enable."), $carp_counter);
120
		$status = 0;
121
	} else {
122
		$savemsg = gettext("CARP has been enabled.");
123
		if (is_array($config['virtualip']['vip'])) {
124
			$viparr = &$config['virtualip']['vip'];
125
			foreach ($viparr as $vip) {
126
				switch ($vip['mode']) {
127
					case "carp":
128
						interface_carp_configure($vip);
129
						sleep(1);
130
						break;
131
					case 'ipalias':
132
						if (strpos($vip['interface'], '_vip')) {
133
							interface_ipalias_configure($vip);
134
						}
135
						break;
136
				}
137
			}
138
		}
139
		interfaces_sync_setup();
140
		set_single_sysctl('net.inet.carp.allow', '1');
141
		$status = 1;
142
	}
143
}
144

    
145
$carp_detected_problems = get_single_sysctl("net.inet.carp.demotion");
146

    
147
if (!empty($_POST['resetdemotion'])) {
148
	set_single_sysctl("net.inet.carp.demotion", "-{$carp_detected_problems}");
149
	sleep(1);
150
	$carp_detected_problems = get_single_sysctl("net.inet.carp.demotion");
151
}
152

    
153
$pgtitle = array(gettext("Status"), gettext("CARP"));
154
$shortcut_section = "carp";
155
include("head.inc");
156
?>
157
<form action="carp_status.php" method="post">
158
<?php if ($savemsg) print_info_box($savemsg); ?>
159

    
160
<?PHP if ($carp_detected_problems > 0) {
161
	print_info_box(
162
		gettext("CARP has detected a problem and this unit has been demoted to BACKUP status.") . "<br/>" .
163
		gettext("Check the link status on all interfaces with configured CARP VIPs.") . "<br/>" .
164
		gettext("Search the") .
165
		" <a href=\"/diag_logs.php?filtertext=carp%3A+demoted+by\">" .
166
		gettext("system log") .
167
		"</a> " .
168
		gettext("for CARP demotion-related events.") . "<br/>" .
169
		"<input type=\"submit\" name=\"resetdemotion\" id=\"resetdemotion\" value=\"" .
170
		gettext("Reset CARP Demotion Status") .
171
		"\" />"
172
	);
173

    
174
} ?>
175

    
176
<?php
177
$carpcount = 0;
178
if(is_array($config['virtualip']['vip'])) {
179
	foreach($config['virtualip']['vip'] as $carp) {
180
		if ($carp['mode'] == "carp") {
181
			$carpcount++;
182
			break;
183
		}
184
	}
185
}
186
if ($carpcount > 0):
187
	$carp_enabled = ($status > 0);
188
?>
189
	<input type="submit" name="disablecarp" value="<?=($carp_enabled ? gettext("Temporarily Disable CARP") : gettext("Enable CARP"))?>" />
190
	<input type="submit" name="carp_maintenancemode" value="<?=($config["virtualip_carp_maintenancemode"] ? gettext("Leave Persistent CARP Maintenance Mode") : gettext("Enter Persistent CARP Maintenance Mode"))?>" />
191
<?php elseif ($carpcount == 0): ?>
192
	<div class="alert alert-info" role="alert">
193
		<p>
194
			<?=gettext("Could not locate any defined CARP interfaces.")?><br/>
195
			<a href="system_hasync.php" class="alert-link"><?=gettext("You can configure high availability sync settings here")?></a>.
196
		</p>
197
	</div>
198
<?php else: ?>
199
<table>
200
	<tr>
201
		<td><?=gettext("CARP Interface")?></td>
202
		<td><?=gettext("Virtual IP")?></td>
203
		<td><?=gettext("Status")?></td>
204
	</tr>
205
<?php
206
	foreach($config['virtualip']['vip'] as $carp) {
207
		if ($carp['mode'] != "carp")
208
			continue;
209
		$ipaddress = $carp['subnet'];
210
		$vhid = $carp['vhid'];
211
		$status = get_carp_interface_status("{$carp['interface']}_vip{$carp['vhid']}");
212
		if($carp_enabled == false) {
213
			$icon = 'remove-sign';
214
			$status = "DISABLED";
215
		} else {
216
			if($status == "MASTER") {
217
				$icon = 'ok-sign';
218
			} else if($status == "BACKUP") {
219
				$icon = 'ok-circle';
220
			} else if($status == "INIT") {
221
				$icon = 'question-sign';
222
			}
223
		}
224
?>
225
	<tr>
226
		<td>
227
			<td><?=convert_friendly_interface_to_friendly_descr($carp['interface'])?>@<?=$vhid?></td>
228
			<td><?=$ipaddress?></td>
229
			<td><i class="icon icon-<?=$icon?>">$status</i></td>
230
	</tr>
231
<?php }?>
232
</table>
233
</form>
234
<?php endif?>
235

    
236
<h4><?=gettext("pfSync nodes")?></h4>
237
<ul>
238
<?php
239
	foreach (explode("\n", exec_command("/sbin/pfctl -vvss | /usr/bin/grep creator | /usr/bin/cut -d\" \" -f7 | /usr/bin/sort -u")) as $node)
240
		echo '<li>'. $node .'</li>';
241
?>
242
</ul>
243

    
244
<?php include("foot.inc")?>
(3-3/237)