Project

General

Profile

Download (7.19 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-2020 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 ($status != 0 && $_POST['carp_maintenancemode'] != "") {
58
	interfaces_carp_set_maintenancemode(!isset($config["virtualip_carp_maintenancemode"]));
59
}
60

    
61
if ($_POST['disablecarp'] != "") {
62
	init_config_arr(array('virtualip', 'vip'));
63
	$viparr = &$config['virtualip']['vip'];
64
	if ($status != 0) {
65
		set_single_sysctl('net.inet.carp.allow', '0');
66
		foreach ($viparr as $vip) {
67
			if ($vip['mode'] != "carp" && $vip['mode'] != "ipalias")
68
				continue;
69
			if ($vip['mode'] == "ipalias" && substr($vip['interface'], 0, 4) != "_vip")
70
				continue;
71
			interface_vip_bring_down($vip);
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
		foreach ($viparr as $vip) {
78
			switch ($vip['mode']) {
79
				case "carp":
80
					interface_carp_configure($vip);
81
					break;
82
				case 'ipalias':
83
					if (substr($vip['interface'], 0, 4) == "_vip") {
84
						interface_ipalias_configure($vip);
85
					}
86
					break;
87
			}
88
		}
89
		interfaces_sync_setup();
90
		set_single_sysctl('net.inet.carp.allow', '1');
91
		$status = 1;
92
	}
93
}
94

    
95
$carp_detected_problems = get_single_sysctl("net.inet.carp.demotion");
96

    
97
if (!empty($_POST['resetdemotion'])) {
98
	set_single_sysctl("net.inet.carp.demotion", 0 - $carp_detected_problems);
99
	sleep(1);
100
	$carp_detected_problems = get_single_sysctl("net.inet.carp.demotion");
101
}
102

    
103
$pgtitle = array(gettext("Status"), gettext("CARP"));
104
$shortcut_section = "carp";
105

    
106
include("head.inc");
107
if ($savemsg) {
108
	print_info_box($savemsg, 'success');
109
}
110

    
111
if ($status == 0 && $_POST['carp_maintenancemode'] != "") {
112
	print_info_box('Please enable CARP before setting the maintenance mode.');
113
}
114

    
115
$carpcount = 0;
116
if (is_array($config['virtualip']['vip'])) {
117
	foreach ($config['virtualip']['vip'] as $carp) {
118
		if ($carp['mode'] == "carp") {
119
			$carpcount++;
120
			break;
121
		}
122
	}
123
}
124

    
125
// If $carpcount > 0 display buttons then display table
126
// otherwise display error box and quit
127

    
128
if ($carpcount == 0) {
129
	print_info_box(gettext('No CARP interfaces have been defined.') . '<br />' .
130
				   '<a href="system_hasync.php" class="alert-link">' .
131
				   gettext("High availability sync settings can be configured here.") .
132
				   '</a>');
133
} else {
134
?>
135
<form action="status_carp.php" method="post">
136
<?php
137
	if ($status != 0) {
138
		$carp_enabled = true;
139
	} else {
140
		$carp_enabled = false;
141
	}
142

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

    
160
?>
161
	<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>
162
	<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>
163

    
164
	<br /><br />
165

    
166
	<div class="panel panel-default">
167
		<div class="panel-heading"><h2 class="panel-title"><?=gettext('CARP Interfaces')?></h2></div>
168
			<div class="panel-body table-responsive">
169
				<table class="table table-striped table-condensed table-hover sortable-theme-bootstrap " data-sortable>
170
					<thead>
171
						<tr>
172
							<th><?=gettext("CARP Interface")?></th>
173
							<th><?=gettext("Virtual IP")?></th>
174
							<th><?=gettext("Status")?></th>
175
						</tr>
176
					</thead>
177
					<tbody>
178
<?php
179
	foreach ($config['virtualip']['vip'] as $carp) {
180
		if ($carp['mode'] != "carp") {
181
			continue;
182
		}
183

    
184
		$icon = '';
185
		$vhid = $carp['vhid'];
186
		$status = get_carp_interface_status("_vip{$carp['uniqid']}");
187
		$aliases = find_ipalias("_vip{$carp['uniqid']}");
188

    
189
		if ($carp_enabled == false) {
190
			$icon = 'times-circle';
191
			$status = "DISABLED";
192
		} else {
193
			if ($status == "MASTER") {
194
				$icon = 'play-circle text-success';
195
			} else if ($status == "BACKUP") {
196
				$icon = 'pause-circle text-warning';
197
			} else if ($status == "INIT") {
198
				$icon = 'question-circle text-danger';
199
			}
200
		}
201
?>
202
					<tr>
203
						<td><?=convert_friendly_interface_to_friendly_descr($carp['interface'])?>@<?=$vhid?></td>
204
						<td>
205
<?php
206
		printf("{$carp['subnet']}/{$carp['subnet_bits']}");
207
		for ($i = 0; $i < count($aliases); $i++) {
208
			printf("<br>{$aliases[$i]}");
209
		}
210
?>
211
						</td>
212
						<td><i class="fa fa-<?=$icon?>"></i>&nbsp;<?=$status?></td>
213
					</tr>
214
<?php }?>
215
				</tbody>
216
			</table>
217
		</div>
218
	</div>
219
</form>
220

    
221
<div class="panel panel-default">
222
	<div class="panel-heading"><h2 class="panel-title"><?=gettext('pfSync Nodes')?></h2></div>
223
	<div class="panel-body">
224
		<ul>
225
<?php
226
        echo "<br />" . gettext("pfSync nodes") . ":<br />";
227
        echo "<pre>";
228
        system("/sbin/pfctl -vvss | /usr/bin/grep creator | /usr/bin/cut -d\" \" -f7 | /usr/bin/sort -u");
229
        echo "</pre>";
230
?>
231

    
232
		</ul>
233
	</div>
234
</div>
235

    
236
<?php
237
}
238

    
239
include("foot.inc");
(156-156/227)