Project

General

Profile

Download (6.53 KB) Statistics
| Branch: | Tag: | Revision:
1 a26686cb Scott Ullrich
<?php
2
/*
3 7d5b007c Sjon Hortensius
	carp_status.php
4
	Copyright (C) 2004 Scott Ullrich
5 8a07e316 Sjon Hortensius
	Copyright (C) 2013-2015 Electric Sheep Fencing, LP
6 7d5b007c Sjon Hortensius
	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 a26686cb Scott Ullrich
*/
29
30 6b07c15a Matthew Grooms
##|+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 13d193c2 Scott Ullrich
/*
38
	pfSense_MODULE:	carp
39
*/
40 6b07c15a Matthew Grooms
41 670fafe5 Scott Ullrich
require_once("guiconfig.inc");
42 783f1ee2 PiBa-NL
require_once("globals.inc");
43 a26686cb Scott Ullrich
44
function gentitle_pkg($pgname) {
45
	global $config;
46
	return $config['system']['hostname'] . "." . $config['system']['domain'] . " - " . $pgname;
47
}
48
49 a1e58090 Scott Ullrich
unset($interface_arr_cache);
50
unset($carp_interface_count_cache);
51 07e5afeb Scott Ullrich
unset($interface_ip_arr_cache);
52 a1e58090 Scott Ullrich
53 a26686cb Scott Ullrich
$status = get_carp_status();
54 9c296826 Ermal
$status = intval($status);
55 783f1ee2 PiBa-NL
if($_POST['carp_maintenancemode'] <> "") {
56
	interfaces_carp_set_maintenancemode(!isset($config["virtualip_carp_maintenancemode"]));
57
}
58 a26686cb Scott Ullrich
if($_POST['disablecarp'] <> "") {
59 9c296826 Ermal
	if($status > 0) {
60 971de1f9 Renato Botelho
		set_single_sysctl('net.inet.carp.allow', '0');
61 8e2986f8 Ermal
		if(is_array($config['virtualip']['vip'])) {
62
			$viparr = &$config['virtualip']['vip'];
63 9b527a79 Renato Botelho
			$found_dhcpdv6 = false;
64 aae16684 Renato Botelho
			foreach ($viparr as $vip) {
65 9b527a79 Renato Botelho
				$carp_iface = "{$vip['interface']}_vip{$vip['vhid']}";
66 aae16684 Renato Botelho
				switch ($vip['mode']) {
67
				case "carp":
68
					interface_vip_bring_down($vip);
69 9b527a79 Renato Botelho
					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 aae16684 Renato Botelho
					sleep(1);
86
					break;
87
				}
88
			}
89
		}
90 cccee755 Chris Buechler
		$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 9c296826 Ermal
		$status = 0;
92 a26686cb Scott Ullrich
	} else {
93 2df8214a Carlos Eduardo Ramos
		$savemsg = gettext("CARP has been enabled.");
94 8e2986f8 Ermal
		if(is_array($config['virtualip']['vip'])) {
95 aae16684 Renato Botelho
			$viparr = &$config['virtualip']['vip'];
96
			foreach ($viparr as $vip) {
97 a133bb38 Ermal
				switch ($vip['mode']) {
98 aae16684 Renato Botelho
				case "carp":
99
					interface_carp_configure($vip);
100
					sleep(1);
101 a133bb38 Ermal
					break;
102 5063f1df Ermal
				case 'ipalias':
103
					if (strpos($vip['interface'], '_vip'))
104
						interface_ipalias_configure($vip);
105
					break;
106 e120d5ce Chris Buechler
				}
107 aae16684 Renato Botelho
			}
108
		}
109 8ff85c39 Ermal
		interfaces_sync_setup();
110 971de1f9 Renato Botelho
		set_single_sysctl('net.inet.carp.allow', '1');
111 9c296826 Ermal
		$status = 1;
112 a26686cb Scott Ullrich
	}
113
}
114
115 0a4fbd99 jim-p
$carp_detected_problems = get_single_sysctl("net.inet.carp.demotion");
116
117
if (!empty($_POST['resetdemotion'])) {
118
	set_single_sysctl("net.inet.carp.demotion", "-{$carp_detected_problems}");
119
	sleep(1);
120
	$carp_detected_problems = get_single_sysctl("net.inet.carp.demotion");
121
}
122 8a84b3ab jim-p
123 2df8214a Carlos Eduardo Ramos
$pgtitle = array(gettext("Status"),gettext("CARP"));
124 b32dd0a6 jim-p
$shortcut_section = "carp";
125 b63695db Scott Ullrich
include("head.inc");
126 a26686cb Scott Ullrich
?>
127
<form action="carp_status.php" method="post">
128
<?php if ($savemsg) print_info_box($savemsg); ?>
129
130 0a4fbd99 jim-p
<?PHP if ($carp_detected_problems > 0) {
131
	print_info_box(
132
		gettext("CARP has detected a problem and this unit has been demoted to BACKUP status.") . "<br/>" .
133
		gettext("Check the link status on all interfaces with configured CARP VIPs.") . "<br/>" .
134
		gettext("Search the") .
135
		" <a href=\"/diag_logs.php?filtertext=carp%3A+demoted+by\">" .
136
		gettext("system log") .
137
		"</a> " .
138
		gettext("for CARP demotion-related events.") . "<br/>" .
139
		"<input type=\"submit\" name=\"resetdemotion\" id=\"resetdemotion\" value=\"" .
140
		gettext("Reset CARP Demotion Status") .
141
		"\" />"
142
	);
143
144
} ?>
145 8a84b3ab jim-p
146 a26686cb Scott Ullrich
<?php
147 7d5b007c Sjon Hortensius
$carpcount = 0;
148
if(is_array($config['virtualip']['vip'])) {
149
	foreach($config['virtualip']['vip'] as $carp) {
150
		if ($carp['mode'] == "carp") {
151
			$carpcount++;
152
			break;
153
		}
154
	}
155
}
156
if ($carpcount > 0):
157
	$carp_enabled = ($status > 0);
158 a26686cb Scott Ullrich
?>
159 7d5b007c Sjon Hortensius
	<input type="submit" name="disablecarp" value="<?=($carp_enabled ? gettext("Temporarily Disable CARP") : gettext("Enable CARP"))?>" />
160
	<input type="submit" name="carp_maintenancemode" value="<?=($config["virtualip_carp_maintenancemode"] ? gettext("Leave Persistent CARP Maintenance Mode") : gettext("Enter Persistent CARP Maintenance Mode"))?>" />
161
<?php elseif ($carpcount == 0): ?>
162
	<div class="alert alert-info" role="alert">
163
		<p>
164
			<?=gettext("Could not locate any defined CARP interfaces.")?><br/>
165
			<a href="system_hasync.php" class="alert-link"><?=gettext("You can configure high availability sync settings here")?></a>.
166
		</p>
167
	</div>
168
<?php else: ?>
169
<table>
170
	<tr>
171
		<td><?=gettext("CARP Interface")?></td>
172
		<td><?=gettext("Virtual IP")?></td>
173
		<td><?=gettext("Status")?></td>
174
	</tr>
175 a26686cb Scott Ullrich
<?php
176 7d5b007c Sjon Hortensius
	foreach($config['virtualip']['vip'] as $carp) {
177
		if ($carp['mode'] != "carp")
178
			continue;
179
		$ipaddress = $carp['subnet'];
180
		$vhid = $carp['vhid'];
181
		$status = get_carp_interface_status("{$carp['interface']}_vip{$carp['vhid']}");
182
		if($carp_enabled == false) {
183
			$icon = 'remove-sign';
184
			$status = "DISABLED";
185
		} else {
186
			if($status == "MASTER") {
187
				$icon = 'ok-sign';
188
			} else if($status == "BACKUP") {
189
				$icon = 'ok-circle';
190
			} else if($status == "INIT") {
191
				$icon = 'question-sign';
192
			}
193
		}
194 a26686cb Scott Ullrich
?>
195 7d5b007c Sjon Hortensius
	<tr>
196
		<td>
197
			<td><?=convert_friendly_interface_to_friendly_descr($carp['interface'])?>@<?=$vhid?></td>
198
			<td><?=$ipaddress?></td>
199 45d6ada5 Sjon Hortensius
			<td><i class="icon icon-<?=$icon?>">$status</i></td>
200 ccda8a1d Sjon Hortensius
	</tr>
201 7d5b007c Sjon Hortensius
<?php }?>
202 ccda8a1d Sjon Hortensius
</table>
203 0f4317d3 Colin Fleming
</form>
204 7d5b007c Sjon Hortensius
<?php endif?>
205 a26686cb Scott Ullrich
206 7d5b007c Sjon Hortensius
<h4><?=gettext("pfSync nodes")?></h4>
207
<ul>
208 1f919154 Scott Ullrich
<?php
209 7d5b007c Sjon Hortensius
	foreach (explode("\n", exec_command("/sbin/pfctl -vvss | /usr/bin/grep creator | /usr/bin/cut -d\" \" -f7 | /usr/bin/sort -u")) as $node)
210
		echo '<li>'. $node .'</li>';
211 1f919154 Scott Ullrich
?>
212 7d5b007c Sjon Hortensius
</ul>
213 1f919154 Scott Ullrich
214 ccda8a1d Sjon Hortensius
<?php include("foot.inc")?>