Project

General

Profile

Download (7.1 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-2020 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
	init_config_arr(array('virtualip', 'vip'));
61
	$viparr = &$config['virtualip']['vip'];
62
	if ($status != 0) {
63
		set_single_sysctl('net.inet.carp.allow', '0');
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
			interface_vip_bring_down($vip);
70
		}
71
		$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);
72
		$status = 0;
73
	} else {
74
		$savemsg = gettext("CARP has been enabled.");
75
		foreach ($viparr as $vip) {
76
			switch ($vip['mode']) {
77
				case "carp":
78
					interface_carp_configure($vip);
79
					break;
80
				case 'ipalias':
81
					if (substr($vip['interface'], 0, 4) == "_vip") {
82
						interface_ipalias_configure($vip);
83
					}
84
					break;
85
			}
86
		}
87
		interfaces_sync_setup();
88
		set_single_sysctl('net.inet.carp.allow', '1');
89
		$status = 1;
90
	}
91
}
92

    
93
$carp_detected_problems = get_single_sysctl("net.inet.carp.demotion");
94

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

    
101
$pgtitle = array(gettext("Status"), gettext("CARP"));
102
$shortcut_section = "carp";
103

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

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

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

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

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

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

    
158
?>
159
	<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>
160
	<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>
161

    
162
	<br /><br />
163

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

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

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

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

    
230
		</ul>
231
	</div>
232
</div>
233

    
234
<?php
235
}
236

    
237
include("foot.inc");
(163-163/235)