Project

General

Profile

Download (8.72 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 Electric Sheep Fencing, LLC
7
 * All rights reserved.
8
 *
9
 * Redistribution and use in source and binary forms, with or without
10
 * modification, are permitted provided that the following conditions are met:
11
 *
12
 * 1. Redistributions of source code must retain the above copyright notice,
13
 *    this list of conditions and the following disclaimer.
14
 *
15
 * 2. Redistributions in binary form must reproduce the above copyright
16
 *    notice, this list of conditions and the following disclaimer in
17
 *    the documentation and/or other materials provided with the
18
 *    distribution.
19
 *
20
 * 3. All advertising materials mentioning features or use of this software
21
 *    must display the following acknowledgment:
22
 *    "This product includes software developed by the pfSense Project
23
 *    for use in the pfSense® software distribution. (http://www.pfsense.org/).
24
 *
25
 * 4. The names "pfSense" and "pfSense Project" must not be used to
26
 *    endorse or promote products derived from this software without
27
 *    prior written permission. For written permission, please contact
28
 *    coreteam@pfsense.org.
29
 *
30
 * 5. Products derived from this software may not be called "pfSense"
31
 *    nor may "pfSense" appear in their names without prior written
32
 *    permission of the Electric Sheep Fencing, LLC.
33
 *
34
 * 6. Redistributions of any form whatsoever must retain the following
35
 *    acknowledgment:
36
 *
37
 * "This product includes software developed by the pfSense Project
38
 * for use in the pfSense software distribution (http://www.pfsense.org/).
39
 *
40
 * THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
41
 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
43
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
44
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
46
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
47
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
49
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
50
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
51
 * OF THE POSSIBILITY OF SUCH DAMAGE.
52
 */
53

    
54
##|+PRIV
55
##|*IDENT=page-status-carp
56
##|*NAME=Status: CARP
57
##|*DESCR=Allow access to the 'Status: CARP' page.
58
##|*MATCH=status_carp.php*
59
##|-PRIV
60

    
61
require_once("guiconfig.inc");
62
require_once("globals.inc");
63

    
64
unset($interface_arr_cache);
65
unset($interface_ip_arr_cache);
66

    
67

    
68
function find_ipalias($carpif) {
69
	global $config;
70

    
71
	$ips = array();
72
	foreach ($config['virtualip']['vip'] as $vip) {
73
		if ($vip['mode'] != "ipalias") {
74
			continue;
75
		}
76
		if ($vip['interface'] != $carpif) {
77
			continue;
78
		}
79
		$ips[] = "{$vip['subnet']}/{$vip['subnet_bits']}";
80
	}
81

    
82
	return ($ips);
83
}
84

    
85
$status = get_carp_status();
86

    
87
if ($_POST['carp_maintenancemode'] != "") {
88
	interfaces_carp_set_maintenancemode(!isset($config["virtualip_carp_maintenancemode"]));
89
}
90

    
91
if ($_POST['disablecarp'] != "") {
92
	if ($status > 0) {
93
		set_single_sysctl('net.inet.carp.allow', '0');
94
		if (is_array($config['virtualip']['vip'])) {
95
			$viparr = &$config['virtualip']['vip'];
96
			foreach ($viparr as $vip) {
97
				if ($vip['mode'] != "carp" && $vip['mode'] != "ipalias")
98
					continue;
99
				if ($vip['mode'] == "ipalias" && substr($vip['interface'], 0, 4) != "_vip")
100
					continue;
101

    
102
				interface_vip_bring_down($vip);
103
			}
104
		}
105
		$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);
106
		$status = 0;
107
	} else {
108
		$savemsg = gettext("CARP has been enabled.");
109
		if (is_array($config['virtualip']['vip'])) {
110
			$viparr = &$config['virtualip']['vip'];
111
			foreach ($viparr as $vip) {
112
				switch ($vip['mode']) {
113
					case "carp":
114
						interface_carp_configure($vip);
115
						break;
116
					case 'ipalias':
117
						if (substr($vip['interface'], 0, 4) == "_vip") {
118
							interface_ipalias_configure($vip);
119
						}
120
						break;
121
				}
122
			}
123
		}
124
		interfaces_sync_setup();
125
		set_single_sysctl('net.inet.carp.allow', '1');
126
		$status = 1;
127
	}
128
}
129

    
130
$carp_detected_problems = get_single_sysctl("net.inet.carp.demotion");
131

    
132
if (!empty($_POST['resetdemotion'])) {
133
	set_single_sysctl("net.inet.carp.demotion", "-{$carp_detected_problems}");
134
	sleep(1);
135
	$carp_detected_problems = get_single_sysctl("net.inet.carp.demotion");
136
}
137

    
138
$pgtitle = array(gettext("Status"), gettext("CARP"));
139
$shortcut_section = "carp";
140

    
141
include("head.inc");
142
if ($savemsg) {
143
	print_info_box($savemsg, 'success');
144
}
145

    
146
$carpcount = 0;
147
if (is_array($config['virtualip']['vip'])) {
148
	foreach ($config['virtualip']['vip'] as $carp) {
149
		if ($carp['mode'] == "carp") {
150
			$carpcount++;
151
			break;
152
		}
153
	}
154
}
155

    
156
// If $carpcount > 0 display buttons then display table
157
// otherwise display error box and quit
158

    
159
if ($carpcount == 0) {
160
	print_info_box(gettext('No CARP interfaces have been defined.') . '<br />' .
161
				   '<a href="system_hasync.php" class="alert-link">' .
162
				   gettext("High availability sync settings can be configured here.") .
163
				   '</a>');
164
} else {
165
?>
166
<form action="status_carp.php" method="post">
167
<?php
168
	if ($status > 0) {
169
		$carp_enabled = true;
170
	} else {
171
		$carp_enabled = false;
172
	}
173

    
174
	// Sadly this needs to be here so that it is inside the form
175
	if ($carp_detected_problems > 0) {
176
		print_info_box(
177
			gettext("CARP has detected a problem and this unit has been demoted to BACKUP status.") .
178
			"<br/>" .
179
			gettext("Check the link status on all interfaces with configured CARP VIPs.") .
180
			"<br/>" .
181
			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>") .
182
			"<br/><br/>" .
183
			'<button type="submit" class="btn btn-warning" name="resetdemotion" id="resetdemotion" value="' .
184
			gettext("Reset CARP Demotion Status.") .
185
			'"><i class="fa fa-undo icon-embed-btn"></i>' .
186
			gettext("Reset CARP Demotion Status.") .
187
			'</button>',
188
			'danger'
189
		);
190
	}
191

    
192
?>
193
	<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>
194
	<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>
195

    
196
	<br /><br />
197

    
198
	<div class="panel panel-default">
199
		<div class="panel-heading"><h2 class="panel-title"><?=gettext('CARP Interfaces')?></h2></div>
200
			<div class="panel-body table-responsive">
201
				<table class="table table-striped table-condensed table-hover sortable-theme-bootstrap " data-sortable>
202
					<thead>
203
						<tr>
204
							<th><?=gettext("CARP Interface")?></th>
205
							<th><?=gettext("Virtual IP")?></th>
206
							<th><?=gettext("Status")?></th>
207
						</tr>
208
					</thead>
209
					<tbody>
210
<?php
211
	foreach ($config['virtualip']['vip'] as $carp) {
212
		if ($carp['mode'] != "carp") {
213
			continue;
214
		}
215

    
216
		$vhid = $carp['vhid'];
217
		$status = get_carp_interface_status("_vip{$carp['uniqid']}");
218
		$aliases = find_ipalias("_vip{$carp['uniqid']}");
219

    
220
		if ($carp_enabled == false) {
221
			$icon = 'times-circle';
222
			$status = "DISABLED";
223
		} else {
224
			if ($status == "MASTER") {
225
				$icon = 'play-circle text-success';
226
			} else if ($status == "BACKUP") {
227
				$icon = 'pause-circle text-warning';
228
			} else if ($status == "INIT") {
229
				$icon = 'question-circle text-danger';
230
			}
231
		}
232
?>
233
					<tr>
234
						<td><?=convert_friendly_interface_to_friendly_descr($carp['interface'])?>@<?=$vhid?></td>
235
						<td>
236
<?php
237
		printf("{$carp['subnet']}/{$carp['subnet_bits']}");
238
		for ($i = 0; $i < count($aliases); $i++) {
239
			printf("<br>{$aliases[$i]}");
240
		}
241
?>
242
						</td>
243
						<td><i class="fa fa-<?=$icon?>"></i>&nbsp;<?=$status?></td>
244
					</tr>
245
<?php }?>
246
				</tbody>
247
			</table>
248
		</div>
249
	</div>
250
</form>
251

    
252
<div class="panel panel-default">
253
	<div class="panel-heading"><h2 class="panel-title"><?=gettext('pfSync Nodes')?></h2></div>
254
	<div class="panel-body">
255
		<ul>
256
<?php
257
        echo "<br />" . gettext("pfSync nodes") . ":<br />";
258
        echo "<pre>";
259
        system("/sbin/pfctl -vvss | /usr/bin/grep creator | /usr/bin/cut -d\" \" -f7 | /usr/bin/sort -u");
260
        echo "</pre>";
261
?>
262

    
263
		</ul>
264
	</div>
265
</div>
266

    
267
<?php
268
}
269

    
270
include("foot.inc");
(157-157/227)