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-2021 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
|
<form action="status_carp.php" method="post">
|
144
|
<?php
|
145
|
if ($status != 0) {
|
146
|
$carp_enabled = true;
|
147
|
} else {
|
148
|
$carp_enabled = false;
|
149
|
}
|
150
|
|
151
|
// Sadly this needs to be here so that it is inside the form
|
152
|
if ($carp_detected_problems != 0) {
|
153
|
print_info_box(
|
154
|
gettext("CARP has detected a problem and this unit has a non-zero demotion status.") .
|
155
|
"<br/>" .
|
156
|
gettext("Check the link status on all interfaces configured with CARP VIPs and ") .
|
157
|
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>") .
|
158
|
"<br/><br/>" .
|
159
|
'<button type="submit" class="btn btn-warning" name="resetdemotion" id="resetdemotion" value="' .
|
160
|
gettext("Reset CARP Demotion Status") .
|
161
|
'"><i class="fa fa-undo icon-embed-btn"></i>' .
|
162
|
gettext("Reset CARP Demotion Status") .
|
163
|
'</button>',
|
164
|
'danger'
|
165
|
);
|
166
|
}
|
167
|
|
168
|
?>
|
169
|
<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>
|
170
|
<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>
|
171
|
|
172
|
<br /><br />
|
173
|
|
174
|
<div class="panel panel-default">
|
175
|
<div class="panel-heading"><h2 class="panel-title"><?=gettext('CARP Interfaces')?></h2></div>
|
176
|
<div class="panel-body table-responsive">
|
177
|
<table class="table table-striped table-condensed table-hover sortable-theme-bootstrap " data-sortable>
|
178
|
<thead>
|
179
|
<tr>
|
180
|
<th><?=gettext("CARP Interface")?></th>
|
181
|
<th><?=gettext("Virtual IP")?></th>
|
182
|
<th><?=gettext("Status")?></th>
|
183
|
</tr>
|
184
|
</thead>
|
185
|
<tbody>
|
186
|
<?php
|
187
|
foreach ($config['virtualip']['vip'] as $carp) {
|
188
|
if ($carp['mode'] != "carp") {
|
189
|
continue;
|
190
|
}
|
191
|
|
192
|
$icon = '';
|
193
|
$vhid = $carp['vhid'];
|
194
|
$status = get_carp_interface_status("_vip{$carp['uniqid']}");
|
195
|
$aliases = find_ipalias("_vip{$carp['uniqid']}");
|
196
|
|
197
|
if ($carp_enabled == false) {
|
198
|
$icon = 'times-circle';
|
199
|
$status = "DISABLED";
|
200
|
} else {
|
201
|
if ($status == "MASTER") {
|
202
|
$icon = 'play-circle text-success';
|
203
|
} else if ($status == "BACKUP") {
|
204
|
$icon = 'pause-circle text-warning';
|
205
|
} else if ($status == "INIT") {
|
206
|
$icon = 'question-circle text-danger';
|
207
|
}
|
208
|
}
|
209
|
?>
|
210
|
<tr>
|
211
|
<td><?=convert_friendly_interface_to_friendly_descr($carp['interface'])?>@<?=$vhid?></td>
|
212
|
<td>
|
213
|
<?php
|
214
|
printf("{$carp['subnet']}/{$carp['subnet_bits']}");
|
215
|
for ($i = 0; $i < count($aliases); $i++) {
|
216
|
printf("<br>{$aliases[$i]}");
|
217
|
}
|
218
|
?>
|
219
|
</td>
|
220
|
<td><i class="fa fa-<?=$icon?>"></i> <?=$status?></td>
|
221
|
</tr>
|
222
|
<?php }?>
|
223
|
</tbody>
|
224
|
</table>
|
225
|
</div>
|
226
|
</div>
|
227
|
</form>
|
228
|
|
229
|
<div class="panel panel-default">
|
230
|
<div class="panel-heading"><h2 class="panel-title"><?=gettext('pfSync Nodes')?></h2></div>
|
231
|
<div class="panel-body">
|
232
|
<ul>
|
233
|
<?php
|
234
|
echo "<br />" . gettext("pfSync nodes") . ":<br />";
|
235
|
echo "<pre>";
|
236
|
system("/sbin/pfctl -vvss | /usr/bin/grep creator | /usr/bin/cut -d\" \" -f7 | /usr/bin/sort -u");
|
237
|
echo "</pre>";
|
238
|
?>
|
239
|
|
240
|
</ul>
|
241
|
</div>
|
242
|
</div>
|
243
|
|
244
|
<?php
|
245
|
}
|
246
|
|
247
|
include("foot.inc");
|