Project

General

Profile

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

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

    
63
/*
64
	pfSense_MODULE:	carp
65
*/
66

    
67
require_once("guiconfig.inc");
68
require_once("globals.inc");
69

    
70
function gentitle_pkg($pgname) {
71
	global $config;
72
	return $config['system']['hostname'] . "." . $config['system']['domain'] . " - " . $pgname;
73
}
74

    
75
unset($interface_arr_cache);
76
unset($carp_interface_count_cache);
77
unset($interface_ip_arr_cache);
78

    
79
$status = get_carp_status();
80
$status = intval($status);
81

    
82
if ($_POST['carp_maintenancemode'] != "") {
83
	interfaces_carp_set_maintenancemode(!isset($config["virtualip_carp_maintenancemode"]));
84
}
85

    
86
if ($_POST['disablecarp'] != "") {
87
	if ($status > 0) {
88
		set_single_sysctl('net.inet.carp.allow', '0');
89
		if (is_array($config['virtualip']['vip'])) {
90
			$viparr = &$config['virtualip']['vip'];
91
			foreach ($viparr as $vip) {
92
				switch ($vip['mode']) {
93
					case "carp":
94
						interface_vip_bring_down($vip);
95

    
96
						/*
97
						 * Reconfigure radvd when necessary
98
						 * XXX: Is it the best way to do it?
99
						 */
100
						if (isset($config['dhcpdv6']) && is_array($config['dhcpdv6'])) {
101
							foreach ($config['dhcpdv6'] as $dhcpv6if => $dhcpv6ifconf) {
102
								if ($dhcpv6if !== $vip['interface'] ||
103
								    $dhcpv6ifconf['ramode'] === "disabled") {
104
									continue;
105
								}
106

    
107
								services_radvd_configure();
108
								break;
109
							}
110
						}
111

    
112
						sleep(1);
113
						break;
114
				}
115
			}
116
		}
117
		$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);
118
		$status = 0;
119
	} else {
120
		$savemsg = gettext("CARP has been enabled.");
121
		if (is_array($config['virtualip']['vip'])) {
122
			$viparr = &$config['virtualip']['vip'];
123
			foreach ($viparr as $vip) {
124
				switch ($vip['mode']) {
125
					case "carp":
126
						interface_carp_configure($vip);
127
						sleep(1);
128
						break;
129
					case 'ipalias':
130
						if (strpos($vip['interface'], '_vip')) {
131
							interface_ipalias_configure($vip);
132
						}
133
						break;
134
				}
135
			}
136
		}
137
		interfaces_sync_setup();
138
		set_single_sysctl('net.inet.carp.allow', '1');
139
		$status = 1;
140
	}
141
}
142

    
143
$carp_detected_problems = get_single_sysctl("net.inet.carp.demotion");
144

    
145
if (!empty($_POST['resetdemotion'])) {
146
	set_single_sysctl("net.inet.carp.demotion", "-{$carp_detected_problems}");
147
	sleep(1);
148
	$carp_detected_problems = get_single_sysctl("net.inet.carp.demotion");
149
}
150

    
151
$pgtitle = array(gettext("Status"), gettext("CARP"));
152
$shortcut_section = "carp";
153

    
154
include("head.inc");
155
if ($savemsg)
156
	print_info_box($savemsg, 'success');
157

    
158
$carpcount = 0;
159
if (is_array($config['virtualip']['vip'])) {
160
	foreach ($config['virtualip']['vip'] as $carp) {
161
		if ($carp['mode'] == "carp") {
162
			$carpcount++;
163
			break;
164
		}
165
	}
166
}
167

    
168

    
169
// If $carpcount > 0 display buttons then display table
170
// otherwise display error box and quit
171

    
172
?>
173

    
174
<?php
175
if ($carpcount == 0) {
176
	print_info_box(gettext('No CARP interfaces have been defined.') . '<br />' .
177
				   '<a href="system_hasync.php" class="alert-link">' .
178
				   gettext("You can configure high availability sync settings here") .
179
				   '</a>');
180
} else
181
{
182
?>
183
<form action="carp_status.php" method="post">
184
<?php
185
	if($status > 0)
186
		$carp_enabled = true;
187
	else
188
		$carp_enabled = false;
189

    
190
	// Sadly this needs to be here so that it is inside the form
191
	if ($carp_detected_problems > 0) {
192
		print_info_box(
193
			gettext("CARP has detected a problem and this unit has been demoted to BACKUP status.") . "<br/>" .
194
			gettext("Check the link status on all interfaces with configured CARP VIPs.") . "<br/>" .
195
			gettext("Search the") .
196
			" <a href=\"/diag_logs.php?filtertext=carp%3A+demoted+by\">" .
197
			gettext("system log") .
198
			"</a> " .
199
			gettext("for CARP demotion-related events.") . "<br/><br/>" .
200
			'<input type="submit" class="btn btn-warning" name="resetdemotion" id="resetdemotion" value="' .
201
			gettext("Reset CARP Demotion Status") .
202
			'" />', 'danger'
203
		);
204
	}
205

    
206
?>
207
	<input type="submit" class="btn btn-warning" name="disablecarp" value="<?=($carp_enabled ? gettext("Temporarily Disable CARP") : gettext("Enable CARP"))?>" />
208
	<input 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"))?>" />
209

    
210
	<br /><br />
211

    
212
	<div class="panel panel-default">
213
		<div class="panel-heading"><h2 class="panel-title"><?=gettext('CARP Interfaces')?></h2></div>
214
			<div class="panel-body table-responsive">
215
				<table class="table table-striped table-condensed table-hover sortable-theme-bootstrap " data-sortable>
216
					<thead>
217
						<tr>
218
							<th><?=gettext("CARP Interface")?></th>
219
							<th><?=gettext("Virtual IP")?></th>
220
							<th><?=gettext("Status")?></th>
221
						</tr>
222
					</thead>
223
					<tbody>
224
<?php
225
	foreach ($config['virtualip']['vip'] as $carp) {
226
		if ($carp['mode'] != "carp") {
227
			continue;
228
		}
229

    
230
		$ipaddress = $carp['subnet'];
231
		$vhid = $carp['vhid'];
232
		$status = get_carp_interface_status("_vip{$carp['uniqid']}");
233

    
234
		if($carp_enabled == false) {
235
			$icon = 'times-circle';
236
			$status = "DISABLED";
237
		} else {
238
			if ($status == "MASTER") {
239
				$icon = 'check-circle';
240
			} else if ($status == "BACKUP") {
241
				$icon = 'check-circle-o';
242
			} else if ($status == "INIT") {
243
				$icon = 'question-circle';
244
			}
245
		}
246
?>
247
					<tr>
248
						<td><?=convert_friendly_interface_to_friendly_descr($carp['interface'])?>@<?=$vhid?></td>
249
						<td><?=$ipaddress?></td>
250
						<td><i class="fa fa-<?=$icon?>"></i>&nbsp;<?=$status?></td>
251
					</tr>
252
<?php }?>
253
				</tbody>
254
			</table>
255
		</div>
256
	</div>
257
</form>
258

    
259
<div class="panel panel-default">
260
	<div class="panel-heading"><h2 class="panel-title"><?=gettext('pfSync nodes')?></h2></div>
261
	<div class="panel-body">
262
		<ul>
263
<?php
264
	foreach (explode("\n", exec_command("/sbin/pfctl -vvss | /usr/bin/grep creator | /usr/bin/cut -d\" \" -f7 | /usr/bin/sort -u")) as $node) {
265
		echo '<li>'. $node .'</li>';
266
	}
267
?>
268
		</ul>
269
	</div>
270
</div>
271

    
272
<?php
273
}
274

    
275
include("foot.inc");
(3-3/228)