Project

General

Profile

Download (6.52 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
	carp_status.php
4
	Copyright (C) 2004 Scott Ullrich
5
	Copyright (C) 2013-2015 Electric Sheep Fencing, LP
6
	All rights reserved.
7

    
8
	Redistribution and use in source and binary forms, with or without
9
	modification, are permitted provided that the following conditions are met:
10

    
11
	1. Redistributions of source code must retain the above copyright notice,
12
	   this list of conditions and the following disclaimer.
13

    
14
	2. Redistributions in binary form must reproduce the above copyright
15
	   notice, this list of conditions and the following disclaimer in the
16
	   documentation and/or other materials provided with the distribution.
17

    
18
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
19
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
20
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
21
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
22
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27
	POSSIBILITY OF SUCH DAMAGE.
28
*/
29

    
30
##|+PRIV
31
##|*IDENT=page-status-carp
32
##|*NAME=Status: CARP page
33
##|*DESCR=Allow access to the 'Status: CARP' page.
34
##|*MATCH=carp_status.php*
35
##|-PRIV
36

    
37
/*
38
	pfSense_MODULE:	carp
39
*/
40

    
41
require_once("guiconfig.inc");
42
require_once("globals.inc");
43

    
44
function gentitle_pkg($pgname) {
45
	global $config;
46
	return $config['system']['hostname'] . "." . $config['system']['domain'] . " - " . $pgname;
47
}
48

    
49
unset($interface_arr_cache);
50
unset($carp_interface_count_cache);
51
unset($interface_ip_arr_cache);
52

    
53
$status = get_carp_status();
54
$status = intval($status);
55
if($_POST['carp_maintenancemode'] <> "") {
56
	interfaces_carp_set_maintenancemode(!isset($config["virtualip_carp_maintenancemode"]));
57
}
58
if($_POST['disablecarp'] <> "") {
59
	if($status > 0) {
60
		set_single_sysctl('net.inet.carp.allow', '0');
61
		if(is_array($config['virtualip']['vip'])) {
62
			$viparr = &$config['virtualip']['vip'];
63
			$found_dhcpdv6 = false;
64
			foreach ($viparr as $vip) {
65
				$carp_iface = "{$vip['interface']}_vip{$vip['vhid']}";
66
				switch ($vip['mode']) {
67
				case "carp":
68
					interface_vip_bring_down($vip);
69
					interface_ipalias_cleanup($carp_iface);
70

    
71
					/*
72
					 * Reconfigure radvd when necessary
73
					 * XXX: Is it the best way to do it?
74
					 */
75
					if (isset($config['dhcpdv6']) && is_array($config['dhcpdv6'])) {
76
						foreach ($config['dhcpdv6'] as $dhcpv6if => $dhcpv6ifconf) {
77
							if ($dhcpv6ifconf['rainterface'] != $carp_iface)
78
								continue;
79

    
80
							services_radvd_configure();
81
							break;
82
						}
83
					}
84

    
85
					sleep(1);
86
					break;
87
				}
88
			}
89
		}
90
		$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);
91
		$status = 0;
92
	} else {
93
		$savemsg = gettext("CARP has been enabled.");
94
		if(is_array($config['virtualip']['vip'])) {
95
			$viparr = &$config['virtualip']['vip'];
96
			foreach ($viparr as $vip) {
97
				switch ($vip['mode']) {
98
				case "carp":
99
					interface_carp_configure($vip);
100
					sleep(1);
101
					break;
102
				case 'ipalias':
103
					if (strpos($vip['interface'], '_vip'))
104
						interface_ipalias_configure($vip);
105
					break;
106
				}
107
			}
108
		}
109
		interfaces_sync_setup();
110
		set_single_sysctl('net.inet.carp.allow', '1');
111
		$status = 1;
112
	}
113
}
114

    
115
$carp_detected_problems = get_single_sysctl("net.inet.carp.demotion");
116

    
117
if (!empty($_POST['resetdemotion'])) {
118
	set_single_sysctl("net.inet.carp.demotion", "-{$carp_detected_problems}");
119
	sleep(1);
120
	$carp_detected_problems = get_single_sysctl("net.inet.carp.demotion");
121
}
122

    
123
$pgtitle = array(gettext("Status"),gettext("CARP"));
124
$shortcut_section = "carp";
125
include("head.inc");
126
?>
127
<form action="carp_status.php" method="post">
128
<?php if ($savemsg) print_info_box($savemsg); ?>
129

    
130
<?PHP if ($carp_detected_problems > 0) {
131
	print_info_box(
132
		gettext("CARP has detected a problem and this unit has been demoted to BACKUP status.") . "<br/>" .
133
		gettext("Check the link status on all interfaces with configured CARP VIPs.") . "<br/>" .
134
		gettext("Search the") .
135
		" <a href=\"/diag_logs.php?filtertext=carp%3A+demoted+by\">" .
136
		gettext("system log") .
137
		"</a> " .
138
		gettext("for CARP demotion-related events.") . "<br/>" .
139
		"<input type=\"submit\" name=\"resetdemotion\" id=\"resetdemotion\" value=\"" .
140
		gettext("Reset CARP Demotion Status") .
141
		"\" />"
142
	);
143

    
144
} ?>
145

    
146
<?php
147
$carpcount = 0;
148
if(is_array($config['virtualip']['vip'])) {
149
	foreach($config['virtualip']['vip'] as $carp) {
150
		if ($carp['mode'] == "carp") {
151
			$carpcount++;
152
			break;
153
		}
154
	}
155
}
156
if ($carpcount > 0):
157
	$carp_enabled = ($status > 0);
158
?>
159
	<input type="submit" name="disablecarp" value="<?=($carp_enabled ? gettext("Temporarily Disable CARP") : gettext("Enable CARP"))?>" />
160
	<input type="submit" name="carp_maintenancemode" value="<?=($config["virtualip_carp_maintenancemode"] ? gettext("Leave Persistent CARP Maintenance Mode") : gettext("Enter Persistent CARP Maintenance Mode"))?>" />
161
<?php elseif ($carpcount == 0): ?>
162
	<div class="alert alert-info" role="alert">
163
		<p>
164
			<?=gettext("Could not locate any defined CARP interfaces.")?><br/>
165
			<a href="system_hasync.php" class="alert-link"><?=gettext("You can configure high availability sync settings here")?></a>.
166
		</p>
167
	</div>
168
<?php else: ?>
169
<table>
170
	<tr>
171
		<td><?=gettext("CARP Interface")?></td>
172
		<td><?=gettext("Virtual IP")?></td>
173
		<td><?=gettext("Status")?></td>
174
	</tr>
175
<?php
176
	foreach($config['virtualip']['vip'] as $carp) {
177
		if ($carp['mode'] != "carp")
178
			continue;
179
		$ipaddress = $carp['subnet'];
180
		$vhid = $carp['vhid'];
181
		$status = get_carp_interface_status("{$carp['interface']}_vip{$carp['vhid']}");
182
		if($carp_enabled == false) {
183
			$icon = 'remove-sign';
184
			$status = "DISABLED";
185
		} else {
186
			if($status == "MASTER") {
187
				$icon = 'ok-sign';
188
			} else if($status == "BACKUP") {
189
				$icon = 'ok-circle';
190
			} else if($status == "INIT") {
191
				$icon = 'question-sign';
192
			}
193
		}
194
?>
195
	<tr>
196
		<td>
197
			<td><?=convert_friendly_interface_to_friendly_descr($carp['interface'])?>@<?=$vhid?></td>
198
			<td><?=$ipaddress?></td>
199
			<td><i class="icon icon-<?=$icon?>">$status</td>
200
	</tr>
201
<?php }?>
202
</table>
203
</form>
204
<?php endif?>
205

    
206
<h4><?=gettext("pfSync nodes")?></h4>
207
<ul>
208
<?php
209
	foreach (explode("\n", exec_command("/sbin/pfctl -vvss | /usr/bin/grep creator | /usr/bin/cut -d\" \" -f7 | /usr/bin/sort -u")) as $node)
210
		echo '<li>'. $node .'</li>';
211
?>
212
</ul>
213

    
214
<?php include("foot.inc")?>
(3-3/252)