Project

General

Profile

Download (8.89 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($interface_ip_arr_cache);
68

    
69

    
70
function find_ipalias($carpif) {
71
	global $config;
72

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

    
84
	return ($ips);
85
}
86

    
87
$status = get_carp_status();
88

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

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

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

    
132
$carp_detected_problems = get_single_sysctl("net.inet.carp.demotion");
133

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

    
140
$pgtitle = array(gettext("Status"), gettext("CARP"));
141
$shortcut_section = "carp";
142

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

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

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

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

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

    
194
?>
195
	<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>
196
	<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>
197

    
198
	<br /><br />
199

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

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

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

    
254
<div class="panel panel-default">
255
	<div class="panel-heading"><h2 class="panel-title"><?=gettext('pfSync Nodes')?></h2></div>
256
	<div class="panel-body">
257
		<ul>
258
<?php
259

    
260
	$nodes = array();
261
	$states = pfSense_get_pf_states();
262
	for ($i = 0; $states != NULL && $i < count($states); $i++) {
263
		$nodes[$states[$i]['creatorid']] = 1;
264
	}
265
	foreach ($nodes as $node => $nenabled) {
266
		echo "<li>$node</li>";
267
	}
268
?>
269
		</ul>
270
	</div>
271
</div>
272

    
273
<?php
274
}
275

    
276
include("foot.inc");
(156-156/225)