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-2024 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
|
$ips = array();
|
40
|
foreach (config_get_path('virtualip/vip', []) as $vip) {
|
41
|
if ($vip['mode'] != "ipalias") {
|
42
|
continue;
|
43
|
}
|
44
|
if ($vip['interface'] != $carpif) {
|
45
|
continue;
|
46
|
}
|
47
|
$ips[] = "{$vip['subnet']}/{$vip['subnet_bits']}";
|
48
|
}
|
49
|
|
50
|
return ($ips);
|
51
|
}
|
52
|
|
53
|
$status = get_carp_status();
|
54
|
|
55
|
if ($_POST['carp_maintenancemode'] != "") {
|
56
|
if (!config_path_enabled('', 'virtualip_carp_maintenancemode')) {
|
57
|
if ($_POST['carp_maintenancemode'] == "disable"){
|
58
|
$errmsg = gettext("Persistent CARP Maintenance Mode is already disabled.");
|
59
|
} else {
|
60
|
$maintenancemode = true;
|
61
|
$savemsg = gettext("Entering Persistent CARP Maintenance Mode.");
|
62
|
}
|
63
|
} else {
|
64
|
if ($_POST['carp_maintenancemode'] == "enable"){
|
65
|
$errmsg = gettext("Persistent CARP Maintenance Mode is already enabled.");
|
66
|
} else {
|
67
|
$maintenancemode = false;
|
68
|
$savemsg = gettext("Leaving Persistent CARP Maintenance Mode.");
|
69
|
}
|
70
|
}
|
71
|
|
72
|
/* allow to switch to Persistent Maintenance Mode if CARP is disabled
|
73
|
* see https://redmine.pfsense.org/issues/11727 */
|
74
|
if (!$errmsg) {
|
75
|
interfaces_carp_set_maintenancemode($maintenancemode);
|
76
|
}
|
77
|
if ($status == 0) {
|
78
|
$_POST['disablecarp'] = "off";
|
79
|
}
|
80
|
}
|
81
|
|
82
|
if ($_POST['disablecarp'] != "") {
|
83
|
$viparr = config_get_path('virtualip/vip', []);
|
84
|
if ($status != 0) {
|
85
|
if ($_POST['disablecarp'] == "enable"){
|
86
|
$errmsg = gettext("CARP is already enabled.");
|
87
|
} else {
|
88
|
enable_carp(false);
|
89
|
foreach ($viparr as $vip) {
|
90
|
if ($vip['mode'] != "carp" && $vip['mode'] != "ipalias")
|
91
|
continue;
|
92
|
if ($vip['mode'] == "ipalias" && substr($vip['interface'], 0, 4) != "_vip")
|
93
|
continue;
|
94
|
interface_vip_bring_down($vip);
|
95
|
}
|
96
|
$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);
|
97
|
$status = 0;
|
98
|
}
|
99
|
} else {
|
100
|
if ($_POST['disablecarp'] == "disable"){
|
101
|
$errmsg = gettext("CARP is already disabled.");
|
102
|
} else {
|
103
|
$savemsg .= gettext("CARP has been enabled.");
|
104
|
foreach ($viparr as $vip) {
|
105
|
switch ($vip['mode']) {
|
106
|
case "carp":
|
107
|
interface_carp_configure($vip);
|
108
|
break;
|
109
|
case 'ipalias':
|
110
|
if (substr($vip['interface'], 0, 4) == "_vip") {
|
111
|
interface_ipalias_configure($vip);
|
112
|
}
|
113
|
break;
|
114
|
}
|
115
|
}
|
116
|
interfaces_sync_setup();
|
117
|
enable_carp();
|
118
|
$status = 1;
|
119
|
}
|
120
|
}
|
121
|
}
|
122
|
|
123
|
$carp_detected_problems = get_single_sysctl("net.inet.carp.demotion");
|
124
|
|
125
|
if (!empty($_POST['resetdemotion'])) {
|
126
|
set_single_sysctl("net.inet.carp.demotion", 0 - $carp_detected_problems);
|
127
|
sleep(1);
|
128
|
$carp_detected_problems = get_single_sysctl("net.inet.carp.demotion");
|
129
|
}
|
130
|
|
131
|
$pgtitle = array(gettext("Status"), gettext("CARP"));
|
132
|
$shortcut_section = "carp";
|
133
|
|
134
|
include("head.inc");
|
135
|
if ($savemsg) {
|
136
|
print_info_box($savemsg, 'success');
|
137
|
} else if ($errmsg) {
|
138
|
print_info_box($errmsg);
|
139
|
}
|
140
|
|
141
|
$carpcount = 0;
|
142
|
foreach(config_get_path('virtualip/vip', []) as $carp) {
|
143
|
if ($carp['mode'] == "carp") {
|
144
|
$carpcount++;
|
145
|
break;
|
146
|
}
|
147
|
}
|
148
|
|
149
|
// If $carpcount > 0 display buttons then display table
|
150
|
// otherwise display error box and quit
|
151
|
|
152
|
if ($carpcount == 0) {
|
153
|
print_info_box(gettext('No CARP interfaces have been defined.') . '<br />' .
|
154
|
'<a href="system_hasync.php" class="alert-link">' .
|
155
|
gettext("High availability sync settings can be configured here.") .
|
156
|
'</a>');
|
157
|
} else {
|
158
|
?>
|
159
|
<div class="panel panel-default">
|
160
|
<div class="panel-heading"><h2 class="panel-title"><?=gettext("CARP Maintenance");?></h2></div>
|
161
|
<div class="panel-body">
|
162
|
<div class="content">
|
163
|
<form action="status_carp.php" method="post">
|
164
|
<?php
|
165
|
if ($status != 0) {
|
166
|
$carp_enabled = true;
|
167
|
} else {
|
168
|
$carp_enabled = false;
|
169
|
}
|
170
|
|
171
|
// Sadly this needs to be here so that it is inside the form
|
172
|
if ($carp_detected_problems != 0) {
|
173
|
print_info_box(
|
174
|
gettext("CARP has detected a problem and this unit has a non-zero demotion status.") .
|
175
|
"<br/>" .
|
176
|
gettext("Check the link status on all interfaces configured with CARP VIPs and ") .
|
177
|
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>") .
|
178
|
"<br/><br/>" .
|
179
|
'<button type="submit" class="btn btn-warning" name="resetdemotion" id="resetdemotion" value="' .
|
180
|
gettext("Reset CARP Demotion Status") .
|
181
|
'"><i class="fa-solid fa-undo icon-embed-btn"></i>' .
|
182
|
gettext("Reset CARP Demotion Status") .
|
183
|
'</button>',
|
184
|
'danger'
|
185
|
);
|
186
|
}
|
187
|
|
188
|
?>
|
189
|
<button type="submit" class="btn btn-warning" name="disablecarp" value="<?=($carp_enabled ? 'disable' : 'enable')?>" ><i class="<?=($carp_enabled) ? 'fa-solid fa-ban' : 'fa-solid fa-check' ; ?> icon-embed-btn"></i><?=($carp_enabled ? gettext("Temporarily Disable CARP") : gettext("Enable CARP"))?></button>
|
190
|
<button type="submit" class="btn btn-info" name="carp_maintenancemode" id="carp_maintenancemode" value="<?=(config_path_enabled('', 'virtualip_carp_maintenancemode') ? 'disable' : 'enable')?>" ><i class="fa-solid fa-wrench icon-embed-btn"></i><?=(config_path_enabled('', 'virtualip_carp_maintenancemode') ? gettext("Leave Persistent CARP Maintenance Mode") : gettext("Enter Persistent CARP Maintenance Mode"))?></button>
|
191
|
</div>
|
192
|
</div>
|
193
|
</div>
|
194
|
|
195
|
<div class="panel panel-default">
|
196
|
<div class="panel-heading"><h2 class="panel-title"><?=gettext('CARP Status')?></h2></div>
|
197
|
<div class="panel-body table-responsive">
|
198
|
<table class="table table-striped table-condensed table-hover sortable-theme-bootstrap " data-sortable>
|
199
|
<thead>
|
200
|
<tr>
|
201
|
<th><?=gettext("Interface and VHID")?></th>
|
202
|
<th><?=gettext("Virtual IP Address")?></th>
|
203
|
<th><?=gettext("Description")?></th>
|
204
|
<th><?=gettext("Status")?></th>
|
205
|
</tr>
|
206
|
</thead>
|
207
|
<tbody>
|
208
|
<?php
|
209
|
foreach (config_get_path('virtualip/vip', []) as $carp) {
|
210
|
if ($carp['mode'] != "carp") {
|
211
|
continue;
|
212
|
}
|
213
|
|
214
|
$icon = '';
|
215
|
$vhid = $carp['vhid'];
|
216
|
$status = get_carp_interface_status("_vip{$carp['uniqid']}");
|
217
|
$aliases = find_ipalias("_vip{$carp['uniqid']}");
|
218
|
|
219
|
if ($carp_enabled == false) {
|
220
|
$icon = 'fa-solid fa-times-circle';
|
221
|
$status = "DISABLED";
|
222
|
} else {
|
223
|
if ($status == "MASTER") {
|
224
|
$icon = 'fa-solid fa-play-circle text-success';
|
225
|
} else if ($status == "BACKUP") {
|
226
|
$icon = 'fa-solid fa-pause-circle text-warning';
|
227
|
} else if ($status == "INIT") {
|
228
|
$icon = 'fa-solid fa-question-circle text-danger';
|
229
|
}
|
230
|
}
|
231
|
?>
|
232
|
<tr>
|
233
|
<td><?=htmlspecialchars(convert_friendly_interface_to_friendly_descr($carp['interface']) . "@{$vhid}");?></td>
|
234
|
<td>
|
235
|
<?php
|
236
|
printf("{$carp['subnet']}/{$carp['subnet_bits']}");
|
237
|
for ($i = 0; $i < count($aliases); $i++) {
|
238
|
printf("<br>{$aliases[$i]}");
|
239
|
}
|
240
|
?>
|
241
|
</td>
|
242
|
<td><?=htmlspecialchars($carp['descr'])?></td>
|
243
|
<td><i class="<?=$icon?>"></i> <?=$status?></td>
|
244
|
</tr>
|
245
|
<?php }?>
|
246
|
</tbody>
|
247
|
</table>
|
248
|
</div>
|
249
|
</div>
|
250
|
</form>
|
251
|
|
252
|
<div class="panel panel-default">
|
253
|
<div class="panel-heading"><h2 class="panel-title"><?=gettext('State Synchronization Status')?></h2></div>
|
254
|
<div class="panel-body"><div class="content">
|
255
|
<?= gettext("State Creator Host IDs") ?>:
|
256
|
<ul>
|
257
|
<?php
|
258
|
$my_id = strtolower(ltrim(filter_get_host_id(), '0'));
|
259
|
exec("/sbin/pfctl -sc | /usr/bin/tail -n +2 | /usr/bin/sort", $hostids);
|
260
|
if (!is_array($hostids)) {
|
261
|
$hostids = array();
|
262
|
}
|
263
|
?>
|
264
|
<?php foreach ($hostids as $hid):
|
265
|
$hid = strtolower(ltrim($hid, '0')); ?>
|
266
|
<li>
|
267
|
<?= $hid ?>
|
268
|
<?php if ($hid == $my_id): ?>
|
269
|
(<?= gettext("This node") ?>)
|
270
|
<?php endif; ?>
|
271
|
</li>
|
272
|
<?php endforeach; ?>
|
273
|
</ul>
|
274
|
|
275
|
<div class="infoblock blockopen">
|
276
|
<?php
|
277
|
print_info_box(sprintf(gettext(
|
278
|
'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' .
|
279
|
'The state creator host ID for this node can be set to a custom value under System > High Avail Sync. ' .
|
280
|
'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.'
|
281
|
), '<br/>'), 'info', false);
|
282
|
?>
|
283
|
</div>
|
284
|
</div></div>
|
285
|
</div>
|
286
|
|
287
|
<?php
|
288
|
}
|
289
|
|
290
|
include("foot.inc");
|