Project

General

Profile

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

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

    
65
/*
66
	pfSense_MODULE:	carp
67
*/
68

    
69
require_once("guiconfig.inc");
70
require_once("globals.inc");
71

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

    
77
unset($interface_arr_cache);
78
unset($carp_interface_count_cache);
79
unset($interface_ip_arr_cache);
80

    
81
$status = get_carp_status();
82
$status = intval($status);
83

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

    
88
if ($_POST['disablecarp'] != "") {
89
	if ($status > 0) {
90
		set_single_sysctl('net.inet.carp.allow', '0');
91
		if (is_array($config['virtualip']['vip'])) {
92
			$viparr = &$config['virtualip']['vip'];
93
			$found_dhcpdv6 = false;
94
			foreach ($viparr as $vip) {
95
				$carp_iface = "{$vip['interface']}_vip{$vip['vhid']}";
96
				switch ($vip['mode']) {
97
					case "carp":
98
						interface_vip_bring_down($vip);
99
						interface_ipalias_cleanup($carp_iface);
100

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

    
111
								services_radvd_configure();
112
								break;
113
							}
114
						}
115

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

    
147
$carp_detected_problems = get_single_sysctl("net.inet.carp.demotion");
148

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

    
155
$pgtitle = array(gettext("Status"), gettext("CARP"));
156
$shortcut_section = "carp";
157

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

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

    
172

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

    
176
?>
177

    
178
<?php
179
if ($carpcount == 0) {
180
	print_info_box(gettext('No CARP interfaces have been defined.') . '<br />' .
181
				   '<a href="system_hasync.php" class="alert-link">' . 
182
				   gettext("You can configure high availability sync settings here") .
183
				   '</a>');
184
} else
185
{
186
?>
187
<form action="carp_status.php" method="post">
188
<?php
189
	if($status > 0)
190
		$carp_enabled = true;
191
	else
192
		$carp_enabled = false;
193
	
194
	// SAdly this needs to be here so that it is inside the form
195
	if ($carp_detected_problems > 0) {
196
		print_info_box(
197
			gettext("CARP has detected a problem and this unit has been demoted to BACKUP status.") . "<br/>" .
198
			gettext("Check the link status on all interfaces with configured CARP VIPs.") . "<br/>" .
199
			gettext("Search the") .
200
			" <a href=\"/diag_logs.php?filtertext=carp%3A+demoted+by\">" .
201
			gettext("system log") .
202
			"</a> " .
203
			gettext("for CARP demotion-related events.") . "<br/><br/>" .
204
			'<input type="submit" class="btn btn-warning" name="resetdemotion" id="resetdemotion" value="' .
205
			gettext("Reset CARP Demotion Status") .
206
			'" />', 'danger'
207
		);
208
	}
209

    
210
?>
211
	<input type="submit" class="btn btn-warning" name="disablecarp" value="<?=($carp_enabled ? gettext("Temporarily Disable CARP") : gettext("Enable CARP"))?>" />
212
	<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"))?>" />
213
	
214
	<br /><br />
215
	
216
	<div class="panel panel-default">
217
		<div class="panel-heading"><h2 class="panel-title"><?=gettext('OpenVPN Servers')?></h2></div>
218
			<div class="panel-body table-responsive">
219
				<table class="table table-striped table-hover table-condensed">
220
					<thead>
221
						<tr>
222
							<th><?=gettext("CARP Interface")?></th>
223
							<th><?=gettext("Virtual IP")?></th>
224
							<th><?=gettext("Status")?></th>
225
						</tr>
226
					</thead>
227
					<tbody>
228
<?php
229
	foreach ($config['virtualip']['vip'] as $carp) {
230
		if ($carp['mode'] != "carp") {
231
			continue;
232
		}
233
			
234
		$ipaddress = $carp['subnet'];
235
		$vhid = $carp['vhid'];
236
		$status = get_carp_interface_status("{$carp['interface']}_vip{$carp['vhid']}");
237
		
238
		if($carp_enabled == false) {
239
			$icon = 'remove-sign';
240
			$status = "DISABLED";
241
		} else {
242
			if ($status == "MASTER") {
243
				$icon = 'ok-sign';
244
			} else if ($status == "BACKUP") {
245
				$icon = 'ok-circle';
246
			} else if ($status == "INIT") {
247
				$icon = 'question-sign';
248
			}
249
		}
250
?>
251
					<tr>
252
						<td><?=convert_friendly_interface_to_friendly_descr($carp['interface'])?>@<?=$vhid?></td>
253
						<td><?=$ipaddress?></td>
254
						<td><i class="icon icon-<?=$icon?>"></i>&nbsp;<?=$status?></td>
255
					</tr>
256
<?php }?>
257
				</tbody>
258
			</table>
259
		</div>
260
	</div>
261
</form>
262

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

    
276
<?php
277
}
278

    
279
include("foot.inc");
(3-3/235)