Project

General

Profile

Download (8.42 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-2023 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
foreach(config_get_path('virtualip/vip', []) as $carp) {
125
	if ($carp['mode'] == "carp") {
126
		$carpcount++;
127
		break;
128
	}
129
}
130

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

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

    
153
	// Sadly this needs to be here so that it is inside the form
154
	if ($carp_detected_problems != 0) {
155
		print_info_box(
156
			gettext("CARP has detected a problem and this unit has a non-zero demotion status.") .
157
			"<br/>" .
158
			gettext("Check the link status on all interfaces configured with CARP VIPs and ") .
159
			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>") .
160
			"<br/><br/>" .
161
			'<button type="submit" class="btn btn-warning" name="resetdemotion" id="resetdemotion" value="' .
162
			gettext("Reset CARP Demotion Status") .
163
			'"><i class="fa fa-undo icon-embed-btn"></i>' .
164
			gettext("Reset CARP Demotion Status") .
165
			'</button>',
166
			'danger'
167
		);
168
	}
169

    
170
?>
171
				<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>
172
				<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>
173
			</div>
174
		</div>
175
	</div>
176

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

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

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

    
232
<div class="panel panel-default">
233
	<div class="panel-heading"><h2 class="panel-title"><?=gettext('State Synchronization Status')?></h2></div>
234
	<div class="panel-body"><div class="content">
235
		<?= gettext("State Creator Host IDs") ?>:
236
		<ul>
237
<?php
238
	$my_id = strtolower(ltrim(filter_get_host_id(), '0'));
239
	exec("/sbin/pfctl -vvss | /usr/bin/awk '/creatorid:/ {print $4;}' | /usr/bin/sort -u", $hostids);
240
	if (!is_array($hostids)) {
241
		$hostids = array();
242
	}
243
?>
244
<?php	foreach ($hostids as $hid):
245
		$hid = strtolower(ltrim($hid, '0')); ?>
246
			<li>
247
				<?= $hid ?>
248
<?php		if ($hid == $my_id): ?>
249
				(<?= gettext("This node") ?>)
250
<?php		endif; ?>
251
			</li>
252
<?php	endforeach; ?>
253
		</ul>
254

    
255
		<div class="infoblock blockopen">
256
<?php
257
	print_info_box(sprintf(gettext(
258
		'When state synchronization is enabled and functioning properly the list of state creator host IDs will be identical on each node participating in state synchronization.%1$s%1$s' .
259
		'The state creator host ID for this node can be set to a custom value under System > High Avail Sync. ' .
260
		'If the state creator host ID has recently changed, the old ID will remain until all states using the old ID expire or are removed.'
261
		), '<br/>'), 'info', false);
262
?>
263
		</div>
264
	</div></div>
265
</div>
266

    
267
<?php
268
}
269

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