Project

General

Profile

Download (8.59 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 page
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
			$found_dhcpdv6 = false;
92
			foreach ($viparr as $vip) {
93
				$carp_iface = "{$vip['interface']}_vip{$vip['vhid']}";
94
				switch ($vip['mode']) {
95
					case "carp":
96
						interface_vip_bring_down($vip);
97
						interface_ipalias_cleanup($carp_iface);
98

    
99
						/*
100
						 * Reconfigure radvd when necessary
101
						 * XXX: Is it the best way to do it?
102
						 */
103
						if (isset($config['dhcpdv6']) && is_array($config['dhcpdv6'])) {
104
							foreach ($config['dhcpdv6'] as $dhcpv6if => $dhcpv6ifconf) {
105
								if ($dhcpv6ifconf['rainterface'] != $carp_iface) {
106
									continue;
107
								}
108

    
109
								services_radvd_configure();
110
								break;
111
							}
112
						}
113

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

    
145
$carp_detected_problems = get_single_sysctl("net.inet.carp.demotion");
146

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

    
153
$pgtitle = array(gettext("Status"), gettext("CARP"));
154
$shortcut_section = "carp";
155

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

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

    
170

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

    
174
?>
175

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

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

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

    
212
	<br /><br />
213

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

    
232
		$ipaddress = $carp['subnet'];
233
		$vhid = $carp['vhid'];
234
		$status = get_carp_interface_status("{$carp['interface']}_vip{$carp['vhid']}");
235

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

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

    
274
<?php
275
}
276

    
277
include("foot.inc");
(3-3/230)