Project

General

Profile

Download (8.26 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

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

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

    
117
$carp_detected_problems = get_single_sysctl("net.inet.carp.demotion");
118

    
119
if (!empty($_POST['resetdemotion'])) {
120
	set_single_sysctl("net.inet.carp.demotion", "-{$carp_detected_problems}");
121
	sleep(1);
122
	$carp_detected_problems = get_single_sysctl("net.inet.carp.demotion");
123
}
124

    
125
$pgtitle = array(gettext("Status"),gettext("CARP"));
126
$shortcut_section = "carp";
127
include("head.inc");
128

    
129
?>
130

    
131
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
132
<?php include("fbegin.inc"); ?>
133
<form action="carp_status.php" method="post">
134
<?php if ($savemsg) print_info_box($savemsg); ?>
135

    
136
<?PHP if ($carp_detected_problems > 0) {
137
	print_info_box(
138
		gettext("CARP has detected a problem and this unit has been demoted to BACKUP status.") . "<br/>" .
139
		gettext("Check the link status on all interfaces with configured CARP VIPs.") . "<br/>" .
140
		gettext("Search the") .
141
		" <a href=\"/diag_logs.php?filtertext=carp%3A+demoted+by\">" .
142
		gettext("system log") .
143
		"</a> " .
144
		gettext("for CARP demotion-related events.") . "<br/>" .
145
		"<input type=\"submit\" name=\"resetdemotion\" id=\"resetdemotion\" value=\"" .
146
		gettext("Reset CARP Demotion Status") .
147
		"\" />"
148
	);
149

    
150
} ?>
151

    
152
<div id="mainlevel">
153
	<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="carp status">
154
		<tr>
155
			<td>
156
<?php
157
			$carpcount = 0;
158
			if (is_array($config['virtualip']['vip'])) {
159
				foreach ($config['virtualip']['vip'] as $carp) {
160
					if ($carp['mode'] == "carp") {
161
						$carpcount++;
162
						break;
163
					}
164
				}
165
			}
166
			if ($carpcount > 0) {
167
				if ($status > 0) {
168
					$carp_enabled = true;
169
					echo "<input type=\"submit\" name=\"disablecarp\" id=\"disablecarp\" value=\"" . gettext("Temporarily Disable CARP") . "\" />";
170
				} else {
171
					$carp_enabled = false;
172
					echo "<input type=\"submit\" name=\"disablecarp\" id=\"disablecarp\" value=\"" . gettext("Enable CARP") . "\" />";
173
				}
174
				if (isset($config["virtualip_carp_maintenancemode"])) {
175
					echo "<input type=\"submit\" name=\"carp_maintenancemode\" id=\"carp_maintenancemode\" value=\"" . gettext("Leave Persistent CARP Maintenance Mode") . "\" />";
176
				} else {
177
					echo "<input type=\"submit\" name=\"carp_maintenancemode\" id=\"carp_maintenancemode\" value=\"" . gettext("Enter Persistent CARP Maintenance Mode") . "\" />";
178
				}
179
			}
180
?>
181

    
182
			<br/><br/>
183
			<table class="tabcont sortable" width="100%" border="0" cellpadding="6" cellspacing="0" summary="results">
184
				<tr>
185
					<td class="listhdrr" align="center"><?=gettext("CARP Interface"); ?></td>
186
					<td class="listhdrr" align="center"><?=gettext("Virtual IP"); ?></td>
187
					<td class="listhdrr" align="center"><?=gettext("Status"); ?></td>
188
				</tr>
189
<?php
190
				if ($carpcount == 0) {
191
					echo "</table></td></tr></table></div></form><center><br />" . gettext("Could not locate any defined CARP interfaces.");
192
					echo "</center>";
193

    
194
					include("fend.inc");
195
					echo "</body></html>";
196
					return;
197
				}
198
				if (is_array($config['virtualip']['vip'])) {
199
					foreach ($config['virtualip']['vip'] as $carp) {
200
						if ($carp['mode'] != "carp") {
201
							continue;
202
						}
203
						$ipaddress = $carp['subnet'];
204
						$vhid = $carp['vhid'];
205
						$status = get_carp_interface_status("_vip{$carp['uniqid']}");
206
						echo "<tr>";
207
						$align = "style=\"vertical-align:middle\"";
208
						if ($carp_enabled == false) {
209
							$icon = "<img {$align} src=\"/themes/".$g['theme']."/images/icons/icon_block.gif\" alt=\"disabled\" />";
210
							$status = "DISABLED";
211
						} else {
212
							if ($status == "MASTER") {
213
								$icon = "<img {$align} src=\"/themes/".$g['theme']."/images/icons/icon_pass.gif\" alt=\"master\" />";
214
							} else if ($status == "BACKUP") {
215
								$icon = "<img {$align} src=\"/themes/".$g['theme']."/images/icons/icon_pass_d.gif\" alt=\"backup\" />";
216
							} else if ($status == "INIT") {
217
								$icon = "<img {$align} src=\"/themes/".$g['theme']."/images/icons/icon_log.gif\" alt=\"init\" />";
218
							} else {
219
								$icon = "";
220
							}
221
						}
222
						echo "<td class=\"listlr\" align=\"center\">" . convert_friendly_interface_to_friendly_descr($carp['interface']) . "@{$vhid} &nbsp;</td>";
223
						echo "<td class=\"listlr\" align=\"center\">" . $ipaddress . "&nbsp;</td>";
224
						echo "<td class=\"listlr\" align=\"center\">{$icon}&nbsp;&nbsp;" . $status . "&nbsp;</td>";
225
						echo "</tr>";
226
					}
227
				}
228
?>
229
			</table>
230
			</td>
231
		</tr>
232
	</table>
233
</div>
234
</form>
235

    
236
<p class="vexpl">
237
<span class="red"><strong><?=gettext("Note"); ?>:</strong></span>
238
<br />
239
<?=gettext("You can configure high availability sync settings"); ?> <a href="system_hasync.php"><?=gettext("here"); ?></a>.
240
</p>
241

    
242
<?php
243
	echo "<br />" . gettext("pfSync nodes") . ":<br />";
244
	echo "<pre>";
245
	system("/sbin/pfctl -vvss | /usr/bin/grep creator | /usr/bin/cut -d\" \" -f7 | /usr/bin/sort -u");
246
	echo "</pre>";
247
?>
248

    
249
<?php include("fend.inc"); ?>
250

    
251
</body>
252
</html>
(3-3/252)