Project

General

Profile

Download (8.32 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
	status_carp.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=status_carp.php*
61
##|-PRIV
62

    
63
require_once("guiconfig.inc");
64
require_once("globals.inc");
65

    
66
unset($interface_arr_cache);
67
unset($carp_interface_count_cache);
68
unset($interface_ip_arr_cache);
69

    
70
$status = get_carp_status();
71
$status = intval($status);
72

    
73
if ($_POST['carp_maintenancemode'] != "") {
74
	interfaces_carp_set_maintenancemode(!isset($config["virtualip_carp_maintenancemode"]));
75
}
76

    
77
if ($_POST['disablecarp'] != "") {
78
	if ($status > 0) {
79
		set_single_sysctl('net.inet.carp.allow', '0');
80
		if (is_array($config['virtualip']['vip'])) {
81
			$viparr = &$config['virtualip']['vip'];
82
			foreach ($viparr as $vip) {
83
				switch ($vip['mode']) {
84
					case "carp":
85
						interface_vip_bring_down($vip);
86

    
87
						/*
88
						 * Reconfigure radvd when necessary
89
						 * XXX: Is it the best way to do it?
90
						 */
91
						if (isset($config['dhcpdv6']) && is_array($config['dhcpdv6'])) {
92
							foreach ($config['dhcpdv6'] as $dhcpv6if => $dhcpv6ifconf) {
93
								if ($dhcpv6if !== $vip['interface'] ||
94
								    $dhcpv6ifconf['ramode'] === "disabled") {
95
									continue;
96
								}
97

    
98
								services_radvd_configure();
99
								break;
100
							}
101
						}
102

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

    
134
$carp_detected_problems = get_single_sysctl("net.inet.carp.demotion");
135

    
136
if (!empty($_POST['resetdemotion'])) {
137
	set_single_sysctl("net.inet.carp.demotion", "-{$carp_detected_problems}");
138
	sleep(1);
139
	$carp_detected_problems = get_single_sysctl("net.inet.carp.demotion");
140
}
141

    
142
$pgtitle = array(gettext("Status"), gettext("CARP"));
143
$shortcut_section = "carp";
144

    
145
include("head.inc");
146
if ($savemsg) {
147
	print_info_box($savemsg, 'success');
148
}
149

    
150
$carpcount = 0;
151
if (is_array($config['virtualip']['vip'])) {
152
	foreach ($config['virtualip']['vip'] as $carp) {
153
		if ($carp['mode'] == "carp") {
154
			$carpcount++;
155
			break;
156
		}
157
	}
158
}
159

    
160

    
161
// If $carpcount > 0 display buttons then display table
162
// otherwise display error box and quit
163

    
164
?>
165

    
166
<?php
167
if ($carpcount == 0) {
168
	print_info_box(gettext('No CARP interfaces have been defined.') . '<br />' .
169
				   '<a href="system_hasync.php" class="alert-link">' .
170
				   gettext("You can configure high availability sync settings here") .
171
				   '</a>');
172
} else {
173
?>
174
<form action="status_carp.php" method="post">
175
<?php
176
	if ($status > 0) {
177
		$carp_enabled = true;
178
	} else {
179
		$carp_enabled = false;
180
	}
181

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

    
198
?>
199
	<input type="submit" class="btn btn-warning" name="disablecarp" value="<?=($carp_enabled ? gettext("Temporarily Disable CARP") : gettext("Enable CARP"))?>" />
200
	<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"))?>" />
201

    
202
	<br /><br />
203

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

    
222
		$ipaddress = $carp['subnet'];
223
		$vhid = $carp['vhid'];
224
		$status = get_carp_interface_status("_vip{$carp['uniqid']}");
225

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

    
251
<div class="panel panel-default">
252
	<div class="panel-heading"><h2 class="panel-title"><?=gettext('pfSync nodes')?></h2></div>
253
	<div class="panel-body">
254
		<ul>
255
<?php
256
	foreach (explode("\n", exec_command("/sbin/pfctl -vvss | /usr/bin/grep creator | /usr/bin/cut -d\" \" -f7 | /usr/bin/sort -u")) as $node) {
257
		echo '<li>'. $node .'</li>';
258
	}
259
?>
260
		</ul>
261
	</div>
262
</div>
263

    
264
<?php
265
}
266

    
267
include("foot.inc");
(155-155/229)