1
|
<?php
|
2
|
/*
|
3
|
* status_carp.php
|
4
|
*
|
5
|
* part of pfSense (https://www.pfsense.org)
|
6
|
* Copyright (c) 2004-2018 Rubicon Communications, LLC (Netgate)
|
7
|
* All rights reserved.
|
8
|
*
|
9
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
10
|
* you may not use this file except in compliance with the License.
|
11
|
* You may obtain a copy of the License at
|
12
|
*
|
13
|
* http://www.apache.org/licenses/LICENSE-2.0
|
14
|
*
|
15
|
* Unless required by applicable law or agreed to in writing, software
|
16
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
17
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
18
|
* See the License for the specific language governing permissions and
|
19
|
* limitations under the License.
|
20
|
*/
|
21
|
|
22
|
##|+PRIV
|
23
|
##|*IDENT=page-status-carp
|
24
|
##|*NAME=Status: CARP
|
25
|
##|*DESCR=Allow access to the 'Status: CARP' page.
|
26
|
##|*MATCH=status_carp.php*
|
27
|
##|-PRIV
|
28
|
|
29
|
require_once("guiconfig.inc");
|
30
|
require_once("globals.inc");
|
31
|
|
32
|
unset($interface_arr_cache);
|
33
|
unset($interface_ip_arr_cache);
|
34
|
|
35
|
|
36
|
function find_ipalias($carpif) {
|
37
|
global $config;
|
38
|
|
39
|
$ips = array();
|
40
|
foreach ($config['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 ($status != 0 && $_POST['carp_maintenancemode'] != "") {
|
56
|
interfaces_carp_set_maintenancemode(!isset($config["virtualip_carp_maintenancemode"]));
|
57
|
}
|
58
|
|
59
|
if ($_POST['disablecarp'] != "") {
|
60
|
if ($status != 0) {
|
61
|
set_single_sysctl('net.inet.carp.allow', '0');
|
62
|
if (is_array($config['virtualip']['vip'])) {
|
63
|
$viparr = &$config['virtualip']['vip'];
|
64
|
foreach ($viparr as $vip) {
|
65
|
if ($vip['mode'] != "carp" && $vip['mode'] != "ipalias")
|
66
|
continue;
|
67
|
if ($vip['mode'] == "ipalias" && substr($vip['interface'], 0, 4) != "_vip")
|
68
|
continue;
|
69
|
|
70
|
interface_vip_bring_down($vip);
|
71
|
}
|
72
|
}
|
73
|
$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);
|
74
|
$status = 0;
|
75
|
} else {
|
76
|
$savemsg = gettext("CARP has been enabled.");
|
77
|
if (is_array($config['virtualip']['vip'])) {
|
78
|
$viparr = &$config['virtualip']['vip'];
|
79
|
foreach ($viparr as $vip) {
|
80
|
switch ($vip['mode']) {
|
81
|
case "carp":
|
82
|
interface_carp_configure($vip);
|
83
|
break;
|
84
|
case 'ipalias':
|
85
|
if (substr($vip['interface'], 0, 4) == "_vip") {
|
86
|
interface_ipalias_configure($vip);
|
87
|
}
|
88
|
break;
|
89
|
}
|
90
|
}
|
91
|
}
|
92
|
interfaces_sync_setup();
|
93
|
set_single_sysctl('net.inet.carp.allow', '1');
|
94
|
$status = 1;
|
95
|
}
|
96
|
}
|
97
|
|
98
|
$carp_detected_problems = get_single_sysctl("net.inet.carp.demotion");
|
99
|
|
100
|
if (!empty($_POST['resetdemotion'])) {
|
101
|
set_single_sysctl("net.inet.carp.demotion", 0 - $carp_detected_problems);
|
102
|
sleep(1);
|
103
|
$carp_detected_problems = get_single_sysctl("net.inet.carp.demotion");
|
104
|
}
|
105
|
|
106
|
$pgtitle = array(gettext("Status"), gettext("CARP"));
|
107
|
$shortcut_section = "carp";
|
108
|
|
109
|
include("head.inc");
|
110
|
if ($savemsg) {
|
111
|
print_info_box($savemsg, 'success');
|
112
|
}
|
113
|
|
114
|
if ($status == 0 && $_POST['carp_maintenancemode'] != "") {
|
115
|
print_info_box('Please enable CARP before setting the maintenance mode.');
|
116
|
}
|
117
|
|
118
|
$carpcount = 0;
|
119
|
if (is_array($config['virtualip']['vip'])) {
|
120
|
foreach ($config['virtualip']['vip'] as $carp) {
|
121
|
if ($carp['mode'] == "carp") {
|
122
|
$carpcount++;
|
123
|
break;
|
124
|
}
|
125
|
}
|
126
|
}
|
127
|
|
128
|
// If $carpcount > 0 display buttons then display table
|
129
|
// otherwise display error box and quit
|
130
|
|
131
|
if ($carpcount == 0) {
|
132
|
print_info_box(gettext('No CARP interfaces have been defined.') . '<br />' .
|
133
|
'<a href="system_hasync.php" class="alert-link">' .
|
134
|
gettext("High availability sync settings can be configured here.") .
|
135
|
'</a>');
|
136
|
} else {
|
137
|
?>
|
138
|
<form action="status_carp.php" method="post">
|
139
|
<?php
|
140
|
if ($status != 0) {
|
141
|
$carp_enabled = true;
|
142
|
} else {
|
143
|
$carp_enabled = false;
|
144
|
}
|
145
|
|
146
|
// Sadly this needs to be here so that it is inside the form
|
147
|
if ($carp_detected_problems != 0) {
|
148
|
print_info_box(
|
149
|
gettext("CARP has detected a problem and this unit has a non-zero demotion status.") .
|
150
|
"<br/>" .
|
151
|
gettext("Check the link status on all interfaces configured with CARP VIPs and ") .
|
152
|
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>") .
|
153
|
"<br/><br/>" .
|
154
|
'<button type="submit" class="btn btn-warning" name="resetdemotion" id="resetdemotion" value="' .
|
155
|
gettext("Reset CARP Demotion Status") .
|
156
|
'"><i class="fa fa-undo icon-embed-btn"></i>' .
|
157
|
gettext("Reset CARP Demotion Status") .
|
158
|
'</button>',
|
159
|
'danger'
|
160
|
);
|
161
|
}
|
162
|
|
163
|
?>
|
164
|
<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>
|
165
|
<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>
|
166
|
|
167
|
<br /><br />
|
168
|
|
169
|
<div class="panel panel-default">
|
170
|
<div class="panel-heading"><h2 class="panel-title"><?=gettext('CARP Interfaces')?></h2></div>
|
171
|
<div class="panel-body table-responsive">
|
172
|
<table class="table table-striped table-condensed table-hover sortable-theme-bootstrap " data-sortable>
|
173
|
<thead>
|
174
|
<tr>
|
175
|
<th><?=gettext("CARP Interface")?></th>
|
176
|
<th><?=gettext("Virtual IP")?></th>
|
177
|
<th><?=gettext("Status")?></th>
|
178
|
</tr>
|
179
|
</thead>
|
180
|
<tbody>
|
181
|
<?php
|
182
|
foreach ($config['virtualip']['vip'] as $carp) {
|
183
|
if ($carp['mode'] != "carp") {
|
184
|
continue;
|
185
|
}
|
186
|
|
187
|
$icon = '';
|
188
|
$vhid = $carp['vhid'];
|
189
|
$status = get_carp_interface_status("_vip{$carp['uniqid']}");
|
190
|
$aliases = find_ipalias("_vip{$carp['uniqid']}");
|
191
|
|
192
|
if ($carp_enabled == false) {
|
193
|
$icon = 'times-circle';
|
194
|
$status = "DISABLED";
|
195
|
} else {
|
196
|
if ($status == "MASTER") {
|
197
|
$icon = 'play-circle text-success';
|
198
|
} else if ($status == "BACKUP") {
|
199
|
$icon = 'pause-circle text-warning';
|
200
|
} else if ($status == "INIT") {
|
201
|
$icon = 'question-circle text-danger';
|
202
|
}
|
203
|
}
|
204
|
?>
|
205
|
<tr>
|
206
|
<td><?=convert_friendly_interface_to_friendly_descr($carp['interface'])?>@<?=$vhid?></td>
|
207
|
<td>
|
208
|
<?php
|
209
|
printf("{$carp['subnet']}/{$carp['subnet_bits']}");
|
210
|
for ($i = 0; $i < count($aliases); $i++) {
|
211
|
printf("<br>{$aliases[$i]}");
|
212
|
}
|
213
|
?>
|
214
|
</td>
|
215
|
<td><i class="fa fa-<?=$icon?>"></i> <?=$status?></td>
|
216
|
</tr>
|
217
|
<?php }?>
|
218
|
</tbody>
|
219
|
</table>
|
220
|
</div>
|
221
|
</div>
|
222
|
</form>
|
223
|
|
224
|
<div class="panel panel-default">
|
225
|
<div class="panel-heading"><h2 class="panel-title"><?=gettext('pfSync Nodes')?></h2></div>
|
226
|
<div class="panel-body">
|
227
|
<ul>
|
228
|
<?php
|
229
|
echo "<br />" . gettext("pfSync nodes") . ":<br />";
|
230
|
echo "<pre>";
|
231
|
system("/sbin/pfctl -vvss | /usr/bin/grep creator | /usr/bin/cut -d\" \" -f7 | /usr/bin/sort -u");
|
232
|
echo "</pre>";
|
233
|
?>
|
234
|
|
235
|
</ul>
|
236
|
</div>
|
237
|
</div>
|
238
|
|
239
|
<?php
|
240
|
}
|
241
|
|
242
|
include("foot.inc");
|