1 |
a26686cb
|
Scott Ullrich
|
<?php
|
2 |
|
|
/*
|
3 |
c5d81585
|
Renato Botelho
|
* status_carp.php
|
4 |
fd9ebcd5
|
Stephen Beaver
|
*
|
5 |
c5d81585
|
Renato Botelho
|
* part of pfSense (https://www.pfsense.org)
|
6 |
38809d47
|
Renato Botelho do Couto
|
* Copyright (c) 2004-2013 BSD Perimeter
|
7 |
|
|
* Copyright (c) 2013-2016 Electric Sheep Fencing
|
8 |
a68f7a3d
|
Luiz Otavio O Souza
|
* Copyright (c) 2014-2024 Rubicon Communications, LLC (Netgate)
|
9 |
c5d81585
|
Renato Botelho
|
* All rights reserved.
|
10 |
fd9ebcd5
|
Stephen Beaver
|
*
|
11 |
b12ea3fb
|
Renato Botelho
|
* 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 |
fd9ebcd5
|
Stephen Beaver
|
*
|
15 |
b12ea3fb
|
Renato Botelho
|
* http://www.apache.org/licenses/LICENSE-2.0
|
16 |
fd9ebcd5
|
Stephen Beaver
|
*
|
17 |
b12ea3fb
|
Renato Botelho
|
* 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 |
fd9ebcd5
|
Stephen Beaver
|
*/
|
23 |
a26686cb
|
Scott Ullrich
|
|
24 |
6b07c15a
|
Matthew Grooms
|
##|+PRIV
|
25 |
|
|
##|*IDENT=page-status-carp
|
26 |
5230f468
|
jim-p
|
##|*NAME=Status: CARP
|
27 |
6b07c15a
|
Matthew Grooms
|
##|*DESCR=Allow access to the 'Status: CARP' page.
|
28 |
1af5edbf
|
Stephen Beaver
|
##|*MATCH=status_carp.php*
|
29 |
6b07c15a
|
Matthew Grooms
|
##|-PRIV
|
30 |
|
|
|
31 |
670fafe5
|
Scott Ullrich
|
require_once("guiconfig.inc");
|
32 |
783f1ee2
|
PiBa-NL
|
require_once("globals.inc");
|
33 |
a26686cb
|
Scott Ullrich
|
|
34 |
a1e58090
|
Scott Ullrich
|
unset($interface_arr_cache);
|
35 |
07e5afeb
|
Scott Ullrich
|
unset($interface_ip_arr_cache);
|
36 |
a1e58090
|
Scott Ullrich
|
|
37 |
2a5960b0
|
Luiz Otavio O Souza
|
|
38 |
|
|
function find_ipalias($carpif) {
|
39 |
|
|
$ips = array();
|
40 |
a9238fdd
|
Christopher Cope
|
foreach (config_get_path('virtualip/vip', []) as $vip) {
|
41 |
d9901ff4
|
Chris Buechler
|
if ($vip['mode'] != "ipalias") {
|
42 |
2a5960b0
|
Luiz Otavio O Souza
|
continue;
|
43 |
d9901ff4
|
Chris Buechler
|
}
|
44 |
|
|
if ($vip['interface'] != $carpif) {
|
45 |
2a5960b0
|
Luiz Otavio O Souza
|
continue;
|
46 |
d9901ff4
|
Chris Buechler
|
}
|
47 |
2a5960b0
|
Luiz Otavio O Souza
|
$ips[] = "{$vip['subnet']}/{$vip['subnet_bits']}";
|
48 |
|
|
}
|
49 |
|
|
|
50 |
|
|
return ($ips);
|
51 |
|
|
}
|
52 |
|
|
|
53 |
a26686cb
|
Scott Ullrich
|
$status = get_carp_status();
|
54 |
9e4bb200
|
Stephen Beaver
|
|
55 |
cf11a8a5
|
Viktor G
|
if ($_POST['carp_maintenancemode'] != "") {
|
56 |
a9238fdd
|
Christopher Cope
|
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 |
cf11a8a5
|
Viktor G
|
} else {
|
64 |
a9238fdd
|
Christopher Cope
|
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 |
cf11a8a5
|
Viktor G
|
}
|
71 |
a9238fdd
|
Christopher Cope
|
|
72 |
cf11a8a5
|
Viktor G
|
/* allow to switch to Persistent Maintenance Mode if CARP is disabled
|
73 |
|
|
* see https://redmine.pfsense.org/issues/11727 */
|
74 |
a9238fdd
|
Christopher Cope
|
if (!$errmsg) {
|
75 |
|
|
interfaces_carp_set_maintenancemode($maintenancemode);
|
76 |
|
|
}
|
77 |
cf11a8a5
|
Viktor G
|
if ($status == 0) {
|
78 |
577cd0eb
|
Marcos Mendoza
|
$_POST['disablecarp'] = "disable";
|
79 |
cf11a8a5
|
Viktor G
|
}
|
80 |
783f1ee2
|
PiBa-NL
|
}
|
81 |
d3a01571
|
Stephen Beaver
|
|
82 |
|
|
if ($_POST['disablecarp'] != "") {
|
83 |
a9238fdd
|
Christopher Cope
|
$viparr = config_get_path('virtualip/vip', []);
|
84 |
3575058b
|
Luiz Otavio O Souza
|
if ($status != 0) {
|
85 |
a9238fdd
|
Christopher Cope
|
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 |
aae16684
|
Renato Botelho
|
}
|
99 |
a26686cb
|
Scott Ullrich
|
} else {
|
100 |
a9238fdd
|
Christopher Cope
|
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 |
aae16684
|
Renato Botelho
|
}
|
116 |
a9238fdd
|
Christopher Cope
|
interfaces_sync_setup();
|
117 |
|
|
enable_carp();
|
118 |
|
|
$status = 1;
|
119 |
aae16684
|
Renato Botelho
|
}
|
120 |
a26686cb
|
Scott Ullrich
|
}
|
121 |
|
|
}
|
122 |
|
|
|
123 |
0a4fbd99
|
jim-p
|
$carp_detected_problems = get_single_sysctl("net.inet.carp.demotion");
|
124 |
|
|
|
125 |
|
|
if (!empty($_POST['resetdemotion'])) {
|
126 |
52a3580a
|
jim-p
|
set_single_sysctl("net.inet.carp.demotion", 0 - $carp_detected_problems);
|
127 |
0a4fbd99
|
jim-p
|
sleep(1);
|
128 |
|
|
$carp_detected_problems = get_single_sysctl("net.inet.carp.demotion");
|
129 |
|
|
}
|
130 |
8a84b3ab
|
jim-p
|
|
131 |
b191b7b1
|
Stephen Beaver
|
$pgtitle = array(gettext("Status"), gettext("CARP"));
|
132 |
b32dd0a6
|
jim-p
|
$shortcut_section = "carp";
|
133 |
d3a01571
|
Stephen Beaver
|
|
134 |
b63695db
|
Scott Ullrich
|
include("head.inc");
|
135 |
abe98adb
|
Phil Davis
|
if ($savemsg) {
|
136 |
d3a01571
|
Stephen Beaver
|
print_info_box($savemsg, 'success');
|
137 |
a9238fdd
|
Christopher Cope
|
} else if ($errmsg) {
|
138 |
|
|
print_info_box($errmsg);
|
139 |
abe98adb
|
Phil Davis
|
}
|
140 |
8a84b3ab
|
jim-p
|
|
141 |
7d5b007c
|
Sjon Hortensius
|
$carpcount = 0;
|
142 |
20fb5adf
|
Christian McDonald
|
foreach(config_get_path('virtualip/vip', []) as $carp) {
|
143 |
|
|
if ($carp['mode'] == "carp") {
|
144 |
|
|
$carpcount++;
|
145 |
|
|
break;
|
146 |
7d5b007c
|
Sjon Hortensius
|
}
|
147 |
|
|
}
|
148 |
d3a01571
|
Stephen Beaver
|
|
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 |
0da0d43e
|
Phil Davis
|
'<a href="system_hasync.php" class="alert-link">' .
|
155 |
530c7ccf
|
NOYB
|
gettext("High availability sync settings can be configured here.") .
|
156 |
d3a01571
|
Stephen Beaver
|
'</a>');
|
157 |
abe98adb
|
Phil Davis
|
} else {
|
158 |
d3a01571
|
Stephen Beaver
|
?>
|
159 |
60f533b7
|
Viktor G
|
<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 |
9e4bb200
|
Stephen Beaver
|
<?php
|
165 |
3575058b
|
Luiz Otavio O Souza
|
if ($status != 0) {
|
166 |
9e4bb200
|
Stephen Beaver
|
$carp_enabled = true;
|
167 |
abe98adb
|
Phil Davis
|
} else {
|
168 |
9e4bb200
|
Stephen Beaver
|
$carp_enabled = false;
|
169 |
abe98adb
|
Phil Davis
|
}
|
170 |
0da0d43e
|
Phil Davis
|
|
171 |
|
|
// Sadly this needs to be here so that it is inside the form
|
172 |
52a3580a
|
jim-p
|
if ($carp_detected_problems != 0) {
|
173 |
61f75117
|
Stephen Beaver
|
print_info_box(
|
174 |
52a3580a
|
jim-p
|
gettext("CARP has detected a problem and this unit has a non-zero demotion status.") .
|
175 |
98128ad6
|
Phil Davis
|
"<br/>" .
|
176 |
52a3580a
|
jim-p
|
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 |
98128ad6
|
Phil Davis
|
"<br/><br/>" .
|
179 |
27d6a45b
|
jim-p
|
'<button type="submit" class="btn btn-warning" name="resetdemotion" id="resetdemotion" value="' .
|
180 |
52a3580a
|
jim-p
|
gettext("Reset CARP Demotion Status") .
|
181 |
e0cb987c
|
Marcos Mendoza
|
'"><i class="fa-solid fa-undo icon-embed-btn"></i>' .
|
182 |
52a3580a
|
jim-p
|
gettext("Reset CARP Demotion Status") .
|
183 |
27d6a45b
|
jim-p
|
'</button>',
|
184 |
98128ad6
|
Phil Davis
|
'danger'
|
185 |
61f75117
|
Stephen Beaver
|
);
|
186 |
|
|
}
|
187 |
|
|
|
188 |
9e4bb200
|
Stephen Beaver
|
?>
|
189 |
d365c2c7
|
Marcos Mendoza
|
<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 |
e0cb987c
|
Marcos Mendoza
|
<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 |
60f533b7
|
Viktor G
|
</div>
|
192 |
|
|
</div>
|
193 |
|
|
</div>
|
194 |
0da0d43e
|
Phil Davis
|
|
195 |
d3a01571
|
Stephen Beaver
|
<div class="panel panel-default">
|
196 |
60f533b7
|
Viktor G
|
<div class="panel-heading"><h2 class="panel-title"><?=gettext('CARP Status')?></h2></div>
|
197 |
d3a01571
|
Stephen Beaver
|
<div class="panel-body table-responsive">
|
198 |
10fe1eb5
|
Stephen Beaver
|
<table class="table table-striped table-condensed table-hover sortable-theme-bootstrap " data-sortable>
|
199 |
d3a01571
|
Stephen Beaver
|
<thead>
|
200 |
|
|
<tr>
|
201 |
60f533b7
|
Viktor G
|
<th><?=gettext("Interface and VHID")?></th>
|
202 |
|
|
<th><?=gettext("Virtual IP Address")?></th>
|
203 |
d02e9664
|
jim-p
|
<th><?=gettext("Description")?></th>
|
204 |
d3a01571
|
Stephen Beaver
|
<th><?=gettext("Status")?></th>
|
205 |
|
|
</tr>
|
206 |
|
|
</thead>
|
207 |
|
|
<tbody>
|
208 |
a26686cb
|
Scott Ullrich
|
<?php
|
209 |
a9238fdd
|
Christopher Cope
|
foreach (config_get_path('virtualip/vip', []) as $carp) {
|
210 |
288a2a0f
|
Phil Davis
|
if ($carp['mode'] != "carp") {
|
211 |
7d5b007c
|
Sjon Hortensius
|
continue;
|
212 |
288a2a0f
|
Phil Davis
|
}
|
213 |
0da0d43e
|
Phil Davis
|
|
214 |
1d87a144
|
Luiz Otavio O Souza
|
$icon = '';
|
215 |
7d5b007c
|
Sjon Hortensius
|
$vhid = $carp['vhid'];
|
216 |
f92ea2e2
|
Luiz Otavio O Souza
|
$status = get_carp_interface_status("_vip{$carp['uniqid']}");
|
217 |
2a5960b0
|
Luiz Otavio O Souza
|
$aliases = find_ipalias("_vip{$carp['uniqid']}");
|
218 |
0da0d43e
|
Phil Davis
|
|
219 |
abe98adb
|
Phil Davis
|
if ($carp_enabled == false) {
|
220 |
d365c2c7
|
Marcos Mendoza
|
$icon = 'fa-solid fa-times-circle';
|
221 |
7d5b007c
|
Sjon Hortensius
|
$status = "DISABLED";
|
222 |
|
|
} else {
|
223 |
288a2a0f
|
Phil Davis
|
if ($status == "MASTER") {
|
224 |
d365c2c7
|
Marcos Mendoza
|
$icon = 'fa-solid fa-play-circle text-success';
|
225 |
288a2a0f
|
Phil Davis
|
} else if ($status == "BACKUP") {
|
226 |
d365c2c7
|
Marcos Mendoza
|
$icon = 'fa-solid fa-pause-circle text-warning';
|
227 |
288a2a0f
|
Phil Davis
|
} else if ($status == "INIT") {
|
228 |
d365c2c7
|
Marcos Mendoza
|
$icon = 'fa-solid fa-question-circle text-danger';
|
229 |
7d5b007c
|
Sjon Hortensius
|
}
|
230 |
|
|
}
|
231 |
a26686cb
|
Scott Ullrich
|
?>
|
232 |
d3a01571
|
Stephen Beaver
|
<tr>
|
233 |
d02e9664
|
jim-p
|
<td><?=htmlspecialchars(convert_friendly_interface_to_friendly_descr($carp['interface']) . "@{$vhid}");?></td>
|
234 |
2a5960b0
|
Luiz Otavio O Souza
|
<td>
|
235 |
|
|
<?php
|
236 |
|
|
printf("{$carp['subnet']}/{$carp['subnet_bits']}");
|
237 |
d9901ff4
|
Chris Buechler
|
for ($i = 0; $i < count($aliases); $i++) {
|
238 |
2a5960b0
|
Luiz Otavio O Souza
|
printf("<br>{$aliases[$i]}");
|
239 |
d9901ff4
|
Chris Buechler
|
}
|
240 |
2a5960b0
|
Luiz Otavio O Souza
|
?>
|
241 |
|
|
</td>
|
242 |
d02e9664
|
jim-p
|
<td><?=htmlspecialchars($carp['descr'])?></td>
|
243 |
d365c2c7
|
Marcos Mendoza
|
<td><i class="<?=$icon?>"></i> <?=$status?></td>
|
244 |
d3a01571
|
Stephen Beaver
|
</tr>
|
245 |
7d5b007c
|
Sjon Hortensius
|
<?php }?>
|
246 |
d3a01571
|
Stephen Beaver
|
</tbody>
|
247 |
|
|
</table>
|
248 |
61f75117
|
Stephen Beaver
|
</div>
|
249 |
d3a01571
|
Stephen Beaver
|
</div>
|
250 |
0f4317d3
|
Colin Fleming
|
</form>
|
251 |
a26686cb
|
Scott Ullrich
|
|
252 |
d3a01571
|
Stephen Beaver
|
<div class="panel panel-default">
|
253 |
60f533b7
|
Viktor G
|
<div class="panel-heading"><h2 class="panel-title"><?=gettext('State Synchronization Status')?></h2></div>
|
254 |
062972b3
|
Jim Pingle
|
<div class="panel-body"><div class="content">
|
255 |
|
|
<?= gettext("State Creator Host IDs") ?>:
|
256 |
d3a01571
|
Stephen Beaver
|
<ul>
|
257 |
1f919154
|
Scott Ullrich
|
<?php
|
258 |
062972b3
|
Jim Pingle
|
$my_id = strtolower(ltrim(filter_get_host_id(), '0'));
|
259 |
e17a8991
|
jim-p
|
exec("/sbin/pfctl -sc | /usr/bin/tail -n +2 | /usr/bin/sort", $hostids);
|
260 |
062972b3
|
Jim Pingle
|
if (!is_array($hostids)) {
|
261 |
|
|
$hostids = array();
|
262 |
|
|
}
|
263 |
1f919154
|
Scott Ullrich
|
?>
|
264 |
062972b3
|
Jim Pingle
|
<?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 |
d3a01571
|
Stephen Beaver
|
</ul>
|
274 |
062972b3
|
Jim Pingle
|
|
275 |
|
|
<div class="infoblock blockopen">
|
276 |
60f533b7
|
Viktor G
|
<?php
|
277 |
e5d97d7c
|
jim-p
|
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 |
60f533b7
|
Viktor G
|
?>
|
283 |
062972b3
|
Jim Pingle
|
</div>
|
284 |
|
|
</div></div>
|
285 |
60f533b7
|
Viktor G
|
</div>
|
286 |
d3a01571
|
Stephen Beaver
|
|
287 |
|
|
<?php
|
288 |
|
|
}
|
289 |
1f919154
|
Scott Ullrich
|
|
290 |
d3a01571
|
Stephen Beaver
|
include("foot.inc");
|