Project

General

Profile

Download (5.98 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
	carp_status.php
4
	Copyright (C) 2004 Scott Ullrich
5
	Copyright (C) 2013-2015 Electric Sheep Fencing, LP
6
	All rights reserved.
7

    
8
	Redistribution and use in source and binary forms, with or without
9
	modification, 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 the
16
	   documentation and/or other materials provided with the distribution.
17

    
18
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
19
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
20
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
21
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
22
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27
	POSSIBILITY OF SUCH DAMAGE.
28
*/
29

    
30
##|+PRIV
31
##|*IDENT=page-status-carp
32
##|*NAME=Status: CARP page
33
##|*DESCR=Allow access to the 'Status: CARP' page.
34
##|*MATCH=carp_status.php*
35
##|-PRIV
36

    
37
/*
38
	pfSense_MODULE:	carp
39
*/
40

    
41
require_once("guiconfig.inc");
42
require_once("globals.inc");
43

    
44
function gentitle_pkg($pgname) {
45
	global $config;
46
	return $config['system']['hostname'] . "." . $config['system']['domain'] . " - " . $pgname;
47
}
48

    
49
unset($interface_arr_cache);
50
unset($carp_interface_count_cache);
51
unset($interface_ip_arr_cache);
52

    
53
$status = get_carp_status();
54
$status = intval($status);
55
if($_POST['carp_maintenancemode'] <> "") {
56
	interfaces_carp_set_maintenancemode(!isset($config["virtualip_carp_maintenancemode"]));
57
}
58
if($_POST['disablecarp'] <> "") {
59
	if($status > 0) {
60
		set_single_sysctl('net.inet.carp.allow', '0');
61
		if(is_array($config['virtualip']['vip'])) {
62
			$viparr = &$config['virtualip']['vip'];
63
			$found_dhcpdv6 = false;
64
			foreach ($viparr as $vip) {
65
				$carp_iface = "{$vip['interface']}_vip{$vip['vhid']}";
66
				switch ($vip['mode']) {
67
				case "carp":
68
					interface_vip_bring_down($vip);
69
					interface_ipalias_cleanup($carp_iface);
70

    
71
					/*
72
					 * Reconfigure radvd when necessary
73
					 * XXX: Is it the best way to do it?
74
					 */
75
					if (isset($config['dhcpdv6']) && is_array($config['dhcpdv6'])) {
76
						foreach ($config['dhcpdv6'] as $dhcpv6if => $dhcpv6ifconf) {
77
							if ($dhcpv6ifconf['rainterface'] != $carp_iface)
78
								continue;
79

    
80
							services_radvd_configure();
81
							break;
82
						}
83
					}
84

    
85
					sleep(1);
86
					break;
87
				}
88
			}
89
		}
90
		$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);
91
		$status = 0;
92
	} else {
93
		$savemsg = gettext("CARP has been enabled.");
94
		if(is_array($config['virtualip']['vip'])) {
95
			$viparr = &$config['virtualip']['vip'];
96
			foreach ($viparr as $vip) {
97
				switch ($vip['mode']) {
98
				case "carp":
99
					interface_carp_configure($vip);
100
					sleep(1);
101
					break;
102
				case 'ipalias':
103
					if (strpos($vip['interface'], '_vip'))
104
						interface_ipalias_configure($vip);
105
					break;
106
				}
107
			}
108
		}
109
		interfaces_sync_setup();
110
		set_single_sysctl('net.inet.carp.allow', '1');
111
		$status = 1;
112
	}
113
}
114

    
115
$carp_detected_problems = ((get_single_sysctl("net.inet.carp.demotion")) > 0);
116

    
117
$pgtitle = array(gettext("Status"),gettext("CARP"));
118
$shortcut_section = "carp";
119
include("head.inc");
120
?>
121
<form action="carp_status.php" method="post">
122
<?php if ($savemsg) print_info_box($savemsg)?>
123
<?php if ($carp_detected_problems) print_info_box(gettext("CARP has detected a problem and this unit has been demoted to BACKUP status.") . "<br />" . gettext("Check link status on all interfaces with configured CARP VIPs."))?>
124
<?php
125
$carpcount = 0;
126
if(is_array($config['virtualip']['vip'])) {
127
	foreach($config['virtualip']['vip'] as $carp) {
128
		if ($carp['mode'] == "carp") {
129
			$carpcount++;
130
			break;
131
		}
132
	}
133
}
134
if ($carpcount > 0):
135
	$carp_enabled = ($status > 0);
136
?>
137
	<input type="submit" name="disablecarp" value="<?=($carp_enabled ? gettext("Temporarily Disable CARP") : gettext("Enable CARP"))?>" />
138
	<input type="submit" name="carp_maintenancemode" value="<?=($config["virtualip_carp_maintenancemode"] ? gettext("Leave Persistent CARP Maintenance Mode") : gettext("Enter Persistent CARP Maintenance Mode"))?>" />
139
<?php elseif ($carpcount == 0): ?>
140
	<div class="alert alert-info" role="alert">
141
		<p>
142
			<?=gettext("Could not locate any defined CARP interfaces.")?><br/>
143
			<a href="system_hasync.php" class="alert-link"><?=gettext("You can configure high availability sync settings here")?></a>.
144
		</p>
145
	</div>
146
<?php else: ?>
147
<table>
148
	<tr>
149
		<td><?=gettext("CARP Interface")?></td>
150
		<td><?=gettext("Virtual IP")?></td>
151
		<td><?=gettext("Status")?></td>
152
	</tr>
153
<?php
154
	foreach($config['virtualip']['vip'] as $carp) {
155
		if ($carp['mode'] != "carp")
156
			continue;
157
		$ipaddress = $carp['subnet'];
158
		$vhid = $carp['vhid'];
159
		$status = get_carp_interface_status("{$carp['interface']}_vip{$carp['vhid']}");
160
		if($carp_enabled == false) {
161
			$icon = 'remove-sign';
162
			$status = "DISABLED";
163
		} else {
164
			if($status == "MASTER") {
165
				$icon = 'ok-sign';
166
			} else if($status == "BACKUP") {
167
				$icon = 'ok-circle';
168
			} else if($status == "INIT") {
169
				$icon = 'question-sign';
170
			}
171
		}
172
?>
173
	<tr>
174
		<td>
175
			<td><?=convert_friendly_interface_to_friendly_descr($carp['interface'])?>@<?=$vhid?></td>
176
			<td><?=$ipaddress?></td>
177
			<td><i class="icon icon-<?=$icon?>">$status</td>
178
	</tr>
179
<?php }?>
180
</table>
181
</form>
182
<?php endif?>
183

    
184
<h4><?=gettext("pfSync nodes")?></h4>
185
<ul>
186
<?php
187
	foreach (explode("\n", exec_command("/sbin/pfctl -vvss | /usr/bin/grep creator | /usr/bin/cut -d\" \" -f7 | /usr/bin/sort -u")) as $node)
188
		echo '<li>'. $node .'</li>';
189
?>
190
</ul>
191

    
192
<?php include("foot.inc")?>
(3-3/252)