Project

General

Profile

Download (7.24 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-2016 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", "-{$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 been demoted to BACKUP status.") .
150
			"<br/>" .
151
			gettext("Check the link status on all interfaces with configured CARP VIPs.") .
152
			"<br/>" .
153
			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>") .
154
			"<br/><br/>" .
155
			'<button type="submit" class="btn btn-warning" name="resetdemotion" id="resetdemotion" value="' .
156
			gettext("Reset CARP Demotion Status.") .
157
			'"><i class="fa fa-undo icon-embed-btn"></i>' .
158
			gettext("Reset CARP Demotion Status.") .
159
			'</button>',
160
			'danger'
161
		);
162
	}
163

    
164
?>
165
	<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>
166
	<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>
167

    
168
	<br /><br />
169

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

    
188
		$icon = '';
189
		$vhid = $carp['vhid'];
190
		$status = get_carp_interface_status("_vip{$carp['uniqid']}");
191
		$aliases = find_ipalias("_vip{$carp['uniqid']}");
192

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

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

    
236
		</ul>
237
	</div>
238
</div>
239

    
240
<?php
241
}
242

    
243
include("foot.inc");
(155-155/225)