Project

General

Profile

Download (8.47 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
function gentitle_pkg($pgname) {
67
	global $config;
68
	return $config['system']['hostname'] . "." . $config['system']['domain'] . " - " . $pgname;
69
}
70

    
71
unset($interface_arr_cache);
72
unset($carp_interface_count_cache);
73
unset($interface_ip_arr_cache);
74

    
75
$status = get_carp_status();
76
$status = intval($status);
77

    
78
if ($_POST['carp_maintenancemode'] != "") {
79
	interfaces_carp_set_maintenancemode(!isset($config["virtualip_carp_maintenancemode"]));
80
}
81

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

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

    
103
								services_radvd_configure();
104
								break;
105
							}
106
						}
107

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

    
139
$carp_detected_problems = get_single_sysctl("net.inet.carp.demotion");
140

    
141
if (!empty($_POST['resetdemotion'])) {
142
	set_single_sysctl("net.inet.carp.demotion", "-{$carp_detected_problems}");
143
	sleep(1);
144
	$carp_detected_problems = get_single_sysctl("net.inet.carp.demotion");
145
}
146

    
147
$pgtitle = array(gettext("Status"), gettext("CARP"));
148
$shortcut_section = "carp";
149

    
150
include("head.inc");
151
if ($savemsg) {
152
	print_info_box($savemsg, 'success');
153
}
154

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

    
165

    
166
// If $carpcount > 0 display buttons then display table
167
// otherwise display error box and quit
168

    
169
?>
170

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

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

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

    
207
	<br /><br />
208

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

    
227
		$ipaddress = $carp['subnet'];
228
		$vhid = $carp['vhid'];
229
		$status = get_carp_interface_status("_vip{$carp['uniqid']}");
230

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

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

    
269
<?php
270
}
271

    
272
include("foot.inc");
(155-155/228)