Project

General

Profile

Download (7.93 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
 * status_carp.php
4
 *
5
 * part of pfSense (https://www.pfsense.org)
6
 * Copyright (c) 2004-2013 BSD Perimeter
7
 * Copyright (c) 2013-2016 Electric Sheep Fencing
8
 * Copyright (c) 2014-2022 Rubicon Communications, LLC (Netgate)
9
 * All rights reserved.
10
 *
11
 * Licensed under the Apache License, Version 2.0 (the "License");
12
 * you may not use this file except in compliance with the License.
13
 * You may obtain a copy of the License at
14
 *
15
 * http://www.apache.org/licenses/LICENSE-2.0
16
 *
17
 * Unless required by applicable law or agreed to in writing, software
18
 * distributed under the License is distributed on an "AS IS" BASIS,
19
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
 * See the License for the specific language governing permissions and
21
 * limitations under the License.
22
 */
23

    
24
##|+PRIV
25
##|*IDENT=page-status-carp
26
##|*NAME=Status: CARP
27
##|*DESCR=Allow access to the 'Status: CARP' page.
28
##|*MATCH=status_carp.php*
29
##|-PRIV
30

    
31
require_once("guiconfig.inc");
32
require_once("globals.inc");
33

    
34
unset($interface_arr_cache);
35
unset($interface_ip_arr_cache);
36

    
37

    
38
function find_ipalias($carpif) {
39
	global $config;
40

    
41
	$ips = array();
42
	foreach ($config['virtualip']['vip'] as $vip) {
43
		if ($vip['mode'] != "ipalias") {
44
			continue;
45
		}
46
		if ($vip['interface'] != $carpif) {
47
			continue;
48
		}
49
		$ips[] = "{$vip['subnet']}/{$vip['subnet_bits']}";
50
	}
51

    
52
	return ($ips);
53
}
54

    
55
$status = get_carp_status();
56

    
57
if ($_POST['carp_maintenancemode'] != "") {
58
	if (!isset($config["virtualip_carp_maintenancemode"])) {
59
		$maintenancemode = true;
60
		$savemsg = gettext("Entering Persistent CARP Maintenance Mode.");
61
	} else {
62
		$maintenancemode = false;
63
		$savemsg = gettext("Leaving Persistent CARP Maintenance Mode.");
64
	}
65
	/* allow to switch to Persistent Maintenance Mode if CARP is disabled
66
	 * see https://redmine.pfsense.org/issues/11727 */
67
	interfaces_carp_set_maintenancemode($maintenancemode);
68
	if ($status == 0) {
69
		$_POST['disablecarp'] = "off";
70
	}
71
}
72

    
73
if ($_POST['disablecarp'] != "") {
74
	init_config_arr(array('virtualip', 'vip'));
75
	$viparr = &$config['virtualip']['vip'];
76
	if ($status != 0) {
77
		set_single_sysctl('net.inet.carp.allow', '0');
78
		foreach ($viparr as $vip) {
79
			if ($vip['mode'] != "carp" && $vip['mode'] != "ipalias")
80
				continue;
81
			if ($vip['mode'] == "ipalias" && substr($vip['interface'], 0, 4) != "_vip")
82
				continue;
83
			interface_vip_bring_down($vip);
84
		}
85
		$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);
86
		$status = 0;
87
	} else {
88
		$savemsg .= gettext("CARP has been enabled.");
89
		foreach ($viparr as $vip) {
90
			switch ($vip['mode']) {
91
				case "carp":
92
					interface_carp_configure($vip);
93
					break;
94
				case 'ipalias':
95
					if (substr($vip['interface'], 0, 4) == "_vip") {
96
						interface_ipalias_configure($vip);
97
					}
98
					break;
99
			}
100
		}
101
		interfaces_sync_setup();
102
		set_single_sysctl('net.inet.carp.allow', '1');
103
		$status = 1;
104
	}
105
}
106

    
107
$carp_detected_problems = get_single_sysctl("net.inet.carp.demotion");
108

    
109
if (!empty($_POST['resetdemotion'])) {
110
	set_single_sysctl("net.inet.carp.demotion", 0 - $carp_detected_problems);
111
	sleep(1);
112
	$carp_detected_problems = get_single_sysctl("net.inet.carp.demotion");
113
}
114

    
115
$pgtitle = array(gettext("Status"), gettext("CARP"));
116
$shortcut_section = "carp";
117

    
118
include("head.inc");
119
if ($savemsg) {
120
	print_info_box($savemsg, 'success');
121
}
122

    
123
$carpcount = 0;
124
if (is_array($config['virtualip']['vip'])) {
125
	foreach ($config['virtualip']['vip'] as $carp) {
126
		if ($carp['mode'] == "carp") {
127
			$carpcount++;
128
			break;
129
		}
130
	}
131
}
132

    
133
// If $carpcount > 0 display buttons then display table
134
// otherwise display error box and quit
135

    
136
if ($carpcount == 0) {
137
	print_info_box(gettext('No CARP interfaces have been defined.') . '<br />' .
138
				   '<a href="system_hasync.php" class="alert-link">' .
139
				   gettext("High availability sync settings can be configured here.") .
140
				   '</a>');
141
} else {
142
?>
143
	<div class="panel panel-default">
144
		<div class="panel-heading"><h2 class="panel-title"><?=gettext("CARP Maintenance");?></h2></div>
145
		<div class="panel-body">
146
			<div class="content">
147
				<form action="status_carp.php" method="post">
148
<?php
149
	if ($status != 0) {
150
		$carp_enabled = true;
151
	} else {
152
		$carp_enabled = false;
153
	}
154

    
155
	// Sadly this needs to be here so that it is inside the form
156
	if ($carp_detected_problems != 0) {
157
		print_info_box(
158
			gettext("CARP has detected a problem and this unit has a non-zero demotion status.") .
159
			"<br/>" .
160
			gettext("Check the link status on all interfaces configured with CARP VIPs and ") .
161
			sprintf(gettext('search the %1$sSystem Log%2$s for CARP demotion-related events.'), "<a href=\"/status_logs.php?filtertext=carp%3A+demoted+by\">", "</a>") .
162
			"<br/><br/>" .
163
			'<button type="submit" class="btn btn-warning" name="resetdemotion" id="resetdemotion" value="' .
164
			gettext("Reset CARP Demotion Status") .
165
			'"><i class="fa fa-undo icon-embed-btn"></i>' .
166
			gettext("Reset CARP Demotion Status") .
167
			'</button>',
168
			'danger'
169
		);
170
	}
171

    
172
?>
173
				<button type="submit" class="btn btn-warning" name="disablecarp" value="<?=($carp_enabled ? gettext("Temporarily Disable CARP") : gettext("Enable CARP"))?>" ><i class="fa fa-<?=($carp_enabled) ? 'ban' : 'check' ; ?> icon-embed-btn"></i><?=($carp_enabled ? gettext("Temporarily Disable CARP") : gettext("Enable CARP"))?></button>
174
				<button type="submit" class="btn btn-info" name="carp_maintenancemode" id="carp_maintenancemode" value="<?=(isset($config["virtualip_carp_maintenancemode"]) ? gettext("Leave Persistent CARP Maintenance Mode") : gettext("Enter Persistent CARP Maintenance Mode"))?>" ><i class="fa fa-wrench icon-embed-btn"></i><?=(isset($config["virtualip_carp_maintenancemode"]) ? gettext("Leave Persistent CARP Maintenance Mode") : gettext("Enter Persistent CARP Maintenance Mode"))?></button>
175
			</div>
176
		</div>
177
	</div>
178

    
179
	<div class="panel panel-default">
180
		<div class="panel-heading"><h2 class="panel-title"><?=gettext('CARP Status')?></h2></div>
181
			<div class="panel-body table-responsive">
182
				<table class="table table-striped table-condensed table-hover sortable-theme-bootstrap " data-sortable>
183
					<thead>
184
						<tr>
185
							<th><?=gettext("Interface and VHID")?></th>
186
							<th><?=gettext("Virtual IP Address")?></th>
187
							<th><?=gettext("Status")?></th>
188
						</tr>
189
					</thead>
190
					<tbody>
191
<?php
192
	foreach ($config['virtualip']['vip'] as $carp) {
193
		if ($carp['mode'] != "carp") {
194
			continue;
195
		}
196

    
197
		$icon = '';
198
		$vhid = $carp['vhid'];
199
		$status = get_carp_interface_status("_vip{$carp['uniqid']}");
200
		$aliases = find_ipalias("_vip{$carp['uniqid']}");
201

    
202
		if ($carp_enabled == false) {
203
			$icon = 'times-circle';
204
			$status = "DISABLED";
205
		} else {
206
			if ($status == "MASTER") {
207
				$icon = 'play-circle text-success';
208
			} else if ($status == "BACKUP") {
209
				$icon = 'pause-circle text-warning';
210
			} else if ($status == "INIT") {
211
				$icon = 'question-circle text-danger';
212
			}
213
		}
214
?>
215
					<tr>
216
						<td><?=convert_friendly_interface_to_friendly_descr($carp['interface'])?>@<?=$vhid?></td>
217
						<td>
218
<?php
219
		printf("{$carp['subnet']}/{$carp['subnet_bits']}");
220
		for ($i = 0; $i < count($aliases); $i++) {
221
			printf("<br>{$aliases[$i]}");
222
		}
223
?>
224
						</td>
225
						<td><i class="fa fa-<?=$icon?>"></i>&nbsp;<?=$status?></td>
226
					</tr>
227
<?php }?>
228
				</tbody>
229
			</table>
230
		</div>
231
	</div>
232
</form>
233

    
234
<div class="panel panel-default">
235
	<div class="panel-heading"><h2 class="panel-title"><?=gettext('State Synchronization Status')?></h2></div>
236
	<div class="panel-body">
237
		<ul>
238
<?php
239
        echo "<br />" . gettext("State Creator IDs") . ":<br />";
240
        echo "<pre>";
241
        system("/sbin/pfctl -vvss | /usr/bin/grep creator | /usr/bin/cut -d\" \" -f7 | /usr/bin/sort -u");
242
        echo "</pre>";
243
?>
244

    
245
		</ul>
246
	</div>
247
</div>
248
<div class="infoblock blockopen">
249
<?php
250
	print_info_box(gettext("When state synchronization is enabled and functioning properly the list of state creator IDs will be nearly identical on each node participating in state synchronization."), 'info', false);
251
?>
252
</div>
253

    
254
<?php
255
}
256

    
257
include("foot.inc");
(156-156/228)