Project

General

Profile

Download (8.72 KB) Statistics
| Branch: | Tag: | Revision:
1 a26686cb Scott Ullrich
<?php
2
/*
3 aaec5634 Renato Botelho
 * status_carp.php
4 fd9ebcd5 Stephen Beaver
 *
5 aaec5634 Renato Botelho
 * part of pfSense (https://www.pfsense.org)
6 2a2396a6 Renato Botelho
 * Copyright (c) 2004-2016 Rubicon Communications, LLC (Netgate)
7 aaec5634 Renato Botelho
 * All rights reserved.
8 fd9ebcd5 Stephen Beaver
 *
9 aaec5634 Renato Botelho
 * Redistribution and use in source and binary forms, with or without
10
 * modification, are permitted provided that the following conditions are met:
11 fd9ebcd5 Stephen Beaver
 *
12 aaec5634 Renato Botelho
 * 1. Redistributions of source code must retain the above copyright notice,
13
 *    this list of conditions and the following disclaimer.
14 fd9ebcd5 Stephen Beaver
 *
15 aaec5634 Renato Botelho
 * 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 fd9ebcd5 Stephen Beaver
 *
20 aaec5634 Renato Botelho
 * 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 fd9ebcd5 Stephen Beaver
 *
25 aaec5634 Renato Botelho
 * 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 fd9ebcd5 Stephen Beaver
 *
30 aaec5634 Renato Botelho
 * 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 fd9ebcd5 Stephen Beaver
 *
34 aaec5634 Renato Botelho
 * 6. Redistributions of any form whatsoever must retain the following
35
 *    acknowledgment:
36 0da0d43e Phil Davis
 *
37 aaec5634 Renato Botelho
 * "This product includes software developed by the pfSense Project
38
 * for use in the pfSense software distribution (http://www.pfsense.org/).
39 fd9ebcd5 Stephen Beaver
 *
40 aaec5634 Renato Botelho
 * 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 fd9ebcd5 Stephen Beaver
 */
53 a26686cb Scott Ullrich
54 6b07c15a Matthew Grooms
##|+PRIV
55
##|*IDENT=page-status-carp
56 5230f468 jim-p
##|*NAME=Status: CARP
57 6b07c15a Matthew Grooms
##|*DESCR=Allow access to the 'Status: CARP' page.
58 1af5edbf Stephen Beaver
##|*MATCH=status_carp.php*
59 6b07c15a Matthew Grooms
##|-PRIV
60
61 670fafe5 Scott Ullrich
require_once("guiconfig.inc");
62 783f1ee2 PiBa-NL
require_once("globals.inc");
63 a26686cb Scott Ullrich
64 a1e58090 Scott Ullrich
unset($interface_arr_cache);
65 07e5afeb Scott Ullrich
unset($interface_ip_arr_cache);
66 a1e58090 Scott Ullrich
67 2a5960b0 Luiz Otavio O Souza
68
function find_ipalias($carpif) {
69
	global $config;
70
71
	$ips = array();
72
	foreach ($config['virtualip']['vip'] as $vip) {
73 d9901ff4 Chris Buechler
		if ($vip['mode'] != "ipalias") {
74 2a5960b0 Luiz Otavio O Souza
			continue;
75 d9901ff4 Chris Buechler
		}
76
		if ($vip['interface'] != $carpif) {
77 2a5960b0 Luiz Otavio O Souza
			continue;
78 d9901ff4 Chris Buechler
		}
79 2a5960b0 Luiz Otavio O Souza
		$ips[] = "{$vip['subnet']}/{$vip['subnet_bits']}";
80
	}
81
82
	return ($ips);
83
}
84
85 a26686cb Scott Ullrich
$status = get_carp_status();
86 9e4bb200 Stephen Beaver
87 d3a01571 Stephen Beaver
if ($_POST['carp_maintenancemode'] != "") {
88 783f1ee2 PiBa-NL
	interfaces_carp_set_maintenancemode(!isset($config["virtualip_carp_maintenancemode"]));
89
}
90 d3a01571 Stephen Beaver
91
if ($_POST['disablecarp'] != "") {
92 b191b7b1 Stephen Beaver
	if ($status > 0) {
93 971de1f9 Renato Botelho
		set_single_sysctl('net.inet.carp.allow', '0');
94 b191b7b1 Stephen Beaver
		if (is_array($config['virtualip']['vip'])) {
95 8e2986f8 Ermal
			$viparr = &$config['virtualip']['vip'];
96 aae16684 Renato Botelho
			foreach ($viparr as $vip) {
97 2a5960b0 Luiz Otavio O Souza
				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 aae16684 Renato Botelho
			}
104
		}
105 cccee755 Chris Buechler
		$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 9c296826 Ermal
		$status = 0;
107 a26686cb Scott Ullrich
	} else {
108 2df8214a Carlos Eduardo Ramos
		$savemsg = gettext("CARP has been enabled.");
109 b191b7b1 Stephen Beaver
		if (is_array($config['virtualip']['vip'])) {
110 aae16684 Renato Botelho
			$viparr = &$config['virtualip']['vip'];
111
			foreach ($viparr as $vip) {
112 a133bb38 Ermal
				switch ($vip['mode']) {
113 b191b7b1 Stephen Beaver
					case "carp":
114
						interface_carp_configure($vip);
115
						break;
116
					case 'ipalias':
117 d9901ff4 Chris Buechler
						if (substr($vip['interface'], 0, 4) == "_vip") {
118 b191b7b1 Stephen Beaver
							interface_ipalias_configure($vip);
119 d9901ff4 Chris Buechler
						}
120 b191b7b1 Stephen Beaver
						break;
121 e120d5ce Chris Buechler
				}
122 aae16684 Renato Botelho
			}
123
		}
124 8ff85c39 Ermal
		interfaces_sync_setup();
125 971de1f9 Renato Botelho
		set_single_sysctl('net.inet.carp.allow', '1');
126 9c296826 Ermal
		$status = 1;
127 a26686cb Scott Ullrich
	}
128
}
129
130 0a4fbd99 jim-p
$carp_detected_problems = get_single_sysctl("net.inet.carp.demotion");
131
132
if (!empty($_POST['resetdemotion'])) {
133 01dc8395 jim-p
	set_single_sysctl("net.inet.carp.demotion", 0 - $carp_detected_problems);
134 0a4fbd99 jim-p
	sleep(1);
135
	$carp_detected_problems = get_single_sysctl("net.inet.carp.demotion");
136
}
137 8a84b3ab jim-p
138 b191b7b1 Stephen Beaver
$pgtitle = array(gettext("Status"), gettext("CARP"));
139 b32dd0a6 jim-p
$shortcut_section = "carp";
140 d3a01571 Stephen Beaver
141 b63695db Scott Ullrich
include("head.inc");
142 abe98adb Phil Davis
if ($savemsg) {
143 d3a01571 Stephen Beaver
	print_info_box($savemsg, 'success');
144 abe98adb Phil Davis
}
145 8a84b3ab jim-p
146 7d5b007c Sjon Hortensius
$carpcount = 0;
147 288a2a0f Phil Davis
if (is_array($config['virtualip']['vip'])) {
148
	foreach ($config['virtualip']['vip'] as $carp) {
149 7d5b007c Sjon Hortensius
		if ($carp['mode'] == "carp") {
150
			$carpcount++;
151
			break;
152
		}
153
	}
154
}
155 d3a01571 Stephen Beaver
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 0da0d43e Phil Davis
				   '<a href="system_hasync.php" class="alert-link">' .
162 4a22d33f Stephen Beaver
				   gettext("High availability sync settings can be configured here.") .
163 d3a01571 Stephen Beaver
				   '</a>');
164 abe98adb Phil Davis
} else {
165 d3a01571 Stephen Beaver
?>
166 1af5edbf Stephen Beaver
<form action="status_carp.php" method="post">
167 9e4bb200 Stephen Beaver
<?php
168 abe98adb Phil Davis
	if ($status > 0) {
169 9e4bb200 Stephen Beaver
		$carp_enabled = true;
170 abe98adb Phil Davis
	} else {
171 9e4bb200 Stephen Beaver
		$carp_enabled = false;
172 abe98adb Phil Davis
	}
173 0da0d43e Phil Davis
174
	// Sadly this needs to be here so that it is inside the form
175 01dc8395 jim-p
	if ($carp_detected_problems != 0) {
176 61f75117 Stephen Beaver
		print_info_box(
177 01dc8395 jim-p
			gettext("CARP has detected a problem and this unit has a non-zero demotion status.") .
178 98128ad6 Phil Davis
			"<br/>" .
179 01dc8395 jim-p
			gettext("Check the link status on all interfaces configured with CARP VIPs and ") .
180
			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>") .
181 98128ad6 Phil Davis
			"<br/><br/>" .
182 27d6a45b jim-p
			'<button type="submit" class="btn btn-warning" name="resetdemotion" id="resetdemotion" value="' .
183 01dc8395 jim-p
			gettext("Reset CARP Demotion Status") .
184 27d6a45b jim-p
			'"><i class="fa fa-undo icon-embed-btn"></i>' .
185 01dc8395 jim-p
			gettext("Reset CARP Demotion Status") .
186 27d6a45b jim-p
			'</button>',
187 98128ad6 Phil Davis
			'danger'
188 61f75117 Stephen Beaver
		);
189
	}
190
191 9e4bb200 Stephen Beaver
?>
192 37676f4e jim-p
	<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>
193
	<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>
194 0da0d43e Phil Davis
195 d3a01571 Stephen Beaver
	<br /><br />
196 0da0d43e Phil Davis
197 d3a01571 Stephen Beaver
	<div class="panel panel-default">
198 6f3a6c31 Stephen Beaver
		<div class="panel-heading"><h2 class="panel-title"><?=gettext('CARP Interfaces')?></h2></div>
199 d3a01571 Stephen Beaver
			<div class="panel-body table-responsive">
200 10fe1eb5 Stephen Beaver
				<table class="table table-striped table-condensed table-hover sortable-theme-bootstrap " data-sortable>
201 d3a01571 Stephen Beaver
					<thead>
202
						<tr>
203
							<th><?=gettext("CARP Interface")?></th>
204
							<th><?=gettext("Virtual IP")?></th>
205
							<th><?=gettext("Status")?></th>
206
						</tr>
207
					</thead>
208
					<tbody>
209 a26686cb Scott Ullrich
<?php
210 288a2a0f Phil Davis
	foreach ($config['virtualip']['vip'] as $carp) {
211
		if ($carp['mode'] != "carp") {
212 7d5b007c Sjon Hortensius
			continue;
213 288a2a0f Phil Davis
		}
214 0da0d43e Phil Davis
215 7d5b007c Sjon Hortensius
		$vhid = $carp['vhid'];
216 f92ea2e2 Luiz Otavio O Souza
		$status = get_carp_interface_status("_vip{$carp['uniqid']}");
217 2a5960b0 Luiz Otavio O Souza
		$aliases = find_ipalias("_vip{$carp['uniqid']}");
218 0da0d43e Phil Davis
219 abe98adb Phil Davis
		if ($carp_enabled == false) {
220 1b7379f9 Jared Dillard
			$icon = 'times-circle';
221 7d5b007c Sjon Hortensius
			$status = "DISABLED";
222
		} else {
223 288a2a0f Phil Davis
			if ($status == "MASTER") {
224 8f934add jim-p
				$icon = 'play-circle text-success';
225 288a2a0f Phil Davis
			} else if ($status == "BACKUP") {
226 8f934add jim-p
				$icon = 'pause-circle text-warning';
227 288a2a0f Phil Davis
			} else if ($status == "INIT") {
228 8f934add jim-p
				$icon = 'question-circle text-danger';
229 7d5b007c Sjon Hortensius
			}
230
		}
231 a26686cb Scott Ullrich
?>
232 d3a01571 Stephen Beaver
					<tr>
233
						<td><?=convert_friendly_interface_to_friendly_descr($carp['interface'])?>@<?=$vhid?></td>
234 2a5960b0 Luiz Otavio O Souza
						<td>
235
<?php
236
		printf("{$carp['subnet']}/{$carp['subnet_bits']}");
237 d9901ff4 Chris Buechler
		for ($i = 0; $i < count($aliases); $i++) {
238 2a5960b0 Luiz Otavio O Souza
			printf("<br>{$aliases[$i]}");
239 d9901ff4 Chris Buechler
		}
240 2a5960b0 Luiz Otavio O Souza
?>
241
						</td>
242 1b7379f9 Jared Dillard
						<td><i class="fa fa-<?=$icon?>"></i>&nbsp;<?=$status?></td>
243 d3a01571 Stephen Beaver
					</tr>
244 7d5b007c Sjon Hortensius
<?php }?>
245 d3a01571 Stephen Beaver
				</tbody>
246
			</table>
247 61f75117 Stephen Beaver
		</div>
248 d3a01571 Stephen Beaver
	</div>
249 0f4317d3 Colin Fleming
</form>
250 a26686cb Scott Ullrich
251 d3a01571 Stephen Beaver
<div class="panel panel-default">
252 3d7a8696 k-paulius
	<div class="panel-heading"><h2 class="panel-title"><?=gettext('pfSync Nodes')?></h2></div>
253 d3a01571 Stephen Beaver
	<div class="panel-body">
254
		<ul>
255 1f919154 Scott Ullrich
<?php
256 e38e1efd Chris Buechler
        echo "<br />" . gettext("pfSync nodes") . ":<br />";
257
        echo "<pre>";
258
        system("/sbin/pfctl -vvss | /usr/bin/grep creator | /usr/bin/cut -d\" \" -f7 | /usr/bin/sort -u");
259
        echo "</pre>";
260 1f919154 Scott Ullrich
?>
261 e38e1efd Chris Buechler
262 d3a01571 Stephen Beaver
		</ul>
263
	</div>
264
</div>
265
266
<?php
267
}
268 1f919154 Scott Ullrich
269 d3a01571 Stephen Beaver
include("foot.inc");