Project

General

Profile

Download (8.41 KB) Statistics
| Branch: | Tag: | Revision:
1 a26686cb Scott Ullrich
<?php
2
/*
3
    carp_status.php
4
    Copyright (C) 2004 Scott Ullrich
5 d961e7e3 Renato Botelho
    Copyright (C) 2013-2015 Electric Sheep Fencing, LP
6 a26686cb Scott Ullrich
    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 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 8e24d1da Renato Botelho
			$found_dhcpdv6 = false;
64 aae16684 Renato Botelho
			foreach ($viparr as $vip) {
65 8e24d1da 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 8e24d1da 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 e63734ff 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 7ba5aeeb 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
127 a26686cb Scott Ullrich
?>
128
129
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
130 e8fc8fa0 Erik Kristensen
<?php include("fbegin.inc"); ?>
131 a26686cb Scott Ullrich
<form action="carp_status.php" method="post">
132
<?php if ($savemsg) print_info_box($savemsg); ?>
133
134 7ba5aeeb jim-p
<?PHP if ($carp_detected_problems > 0) {
135
	print_info_box(
136
		gettext("CARP has detected a problem and this unit has been demoted to BACKUP status.") . "<br/>" .
137
		gettext("Check the link status on all interfaces with configured CARP VIPs.") . "<br/>" .
138
		gettext("Search the") .
139
		" <a href=\"/diag_logs.php?filtertext=carp%3A+demoted+by\">" .
140
		gettext("system log") .
141
		"</a> " .
142
		gettext("for CARP demotion-related events.") . "<br/>" .
143
		"<input type=\"submit\" name=\"resetdemotion\" id=\"resetdemotion\" value=\"" .
144
		gettext("Reset CARP Demotion Status") .
145
		"\" />"
146
	);
147
148
} ?>
149 8a84b3ab jim-p
150 4208d208 Scott Ullrich
<div id="mainlevel">
151 0f4317d3 Colin Fleming
	<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="carp status">
152 e8fc8fa0 Erik Kristensen
		<tr>
153 1f919154 Scott Ullrich
			<td>
154 a26686cb Scott Ullrich
<?php
155 2bfade90 Ermal
			$carpcount = 0;
156 e8fc8fa0 Erik Kristensen
			if(is_array($config['virtualip']['vip'])) {
157
				foreach($config['virtualip']['vip'] as $carp) {
158 4ed5ad5a Ermal
					if ($carp['mode'] == "carp") {
159 9175156f Scott Ullrich
						$carpcount++;
160 4ed5ad5a Ermal
						break;
161
					}
162 9175156f Scott Ullrich
				}
163
			}
164
			if($carpcount > 0) {
165 9c296826 Ermal
				if($status > 0) {
166 9175156f Scott Ullrich
					$carp_enabled = true;
167 0f4317d3 Colin Fleming
					echo "<input type=\"submit\" name=\"disablecarp\" id=\"disablecarp\" value=\"" . gettext("Temporarily Disable CARP") . "\" />";
168 9c296826 Ermal
				} else {
169
					$carp_enabled = false;
170
					echo "<input type=\"submit\" name=\"disablecarp\" id=\"disablecarp\" value=\"" . gettext("Enable CARP") . "\" />";
171 783f1ee2 PiBa-NL
				}
172
				if(isset($config["virtualip_carp_maintenancemode"])) {
173 0f4317d3 Colin Fleming
					echo "<input type=\"submit\" name=\"carp_maintenancemode\" id=\"carp_maintenancemode\" value=\"" . gettext("Leave Persistent CARP Maintenance Mode") . "\" />";
174 783f1ee2 PiBa-NL
				} else {
175 0f4317d3 Colin Fleming
					echo "<input type=\"submit\" name=\"carp_maintenancemode\" id=\"carp_maintenancemode\" value=\"" . gettext("Enter Persistent CARP Maintenance Mode") . "\" />";
176 e8fc8fa0 Erik Kristensen
				}
177
			}
178 a26686cb Scott Ullrich
?>
179
180 0f4317d3 Colin Fleming
			<br/><br/>
181
			<table class="tabcont sortable" width="100%" border="0" cellpadding="6" cellspacing="0" summary="results">
182 e8fc8fa0 Erik Kristensen
				<tr>
183 0f4317d3 Colin Fleming
					<td class="listhdrr" align="center"><?=gettext("CARP Interface"); ?></td>
184
					<td class="listhdrr" align="center"><?=gettext("Virtual IP"); ?></td>
185
					<td class="listhdrr" align="center"><?=gettext("Status"); ?></td>
186 e8fc8fa0 Erik Kristensen
				</tr>
187 a26686cb Scott Ullrich
<?php
188 172bd075 Scott Ullrich
				if ($carpcount == 0) {
189 0f4317d3 Colin Fleming
					echo "</table></td></tr></table></div></form><center><br />" . gettext("Could not locate any defined CARP interfaces.");
190 172bd075 Scott Ullrich
					echo "</center>";
191
192
					include("fend.inc");
193
					echo "</body></html>";
194 8a84b3ab jim-p
					return;
195 172bd075 Scott Ullrich
				}
196 e8fc8fa0 Erik Kristensen
				if(is_array($config['virtualip']['vip'])) {
197
					foreach($config['virtualip']['vip'] as $carp) {
198 4ed5ad5a Ermal
						if ($carp['mode'] != "carp")
199
							continue;
200 e8fc8fa0 Erik Kristensen
						$ipaddress = $carp['subnet'];
201
						$password = $carp['password'];
202
						$netmask = $carp['subnet_bits'];
203
						$vhid = $carp['vhid'];
204
						$advskew = $carp['advskew'];
205 6f247d1f Ermal
						$advbase = $carp['advbase'];
206 0c21eb70 Ermal
						$status = get_carp_interface_status("{$carp['interface']}_vip{$carp['vhid']}");
207 e8fc8fa0 Erik Kristensen
						echo "<tr>";
208 0f4317d3 Colin Fleming
						$align = "style=\"vertical-align:middle\"";
209 e8fc8fa0 Erik Kristensen
						if($carp_enabled == false) {
210 23b3e679 Renato Botelho
							$icon = "<img {$align} src=\"/themes/".$g['theme']."/images/icons/icon_block.gif\" alt=\"disabled\" />";
211 e8fc8fa0 Erik Kristensen
							$status = "DISABLED";
212
						} else {
213
							if($status == "MASTER") {
214 0f4317d3 Colin Fleming
								$icon = "<img {$align} src=\"/themes/".$g['theme']."/images/icons/icon_pass.gif\" alt=\"master\" />";
215 e8fc8fa0 Erik Kristensen
							} else if($status == "BACKUP") {
216 0f4317d3 Colin Fleming
								$icon = "<img {$align} src=\"/themes/".$g['theme']."/images/icons/icon_pass_d.gif\" alt=\"backup\" />";
217 e8fc8fa0 Erik Kristensen
							} else if($status == "INIT") {
218 0f4317d3 Colin Fleming
								$icon = "<img {$align} src=\"/themes/".$g['theme']."/images/icons/icon_log.gif\" alt=\"init\" />";
219 478188c2 k-paulius
							} else {
220 b5ecfe0f PiBa-NL
								$icon = "";
221 7ba5aeeb jim-p
							}
222 e8fc8fa0 Erik Kristensen
						}
223 0f4317d3 Colin Fleming
						echo "<td class=\"listlr\" align=\"center\">" . convert_friendly_interface_to_friendly_descr($carp['interface']) . "@{$vhid} &nbsp;</td>";
224
						echo "<td class=\"listlr\" align=\"center\">" . $ipaddress . "&nbsp;</td>";
225
						echo "<td class=\"listlr\" align=\"center\">{$icon}&nbsp;&nbsp;" . $status . "&nbsp;</td>";
226 e8fc8fa0 Erik Kristensen
						echo "</tr>";
227
					}
228
				}
229 a26686cb Scott Ullrich
?>
230 e8fc8fa0 Erik Kristensen
			</table>
231
			</td>
232
		</tr>
233
	</table>
234 e2de5461 Scott Ullrich
</div>
235 0f4317d3 Colin Fleming
</form>
236 a26686cb Scott Ullrich
237 0f4317d3 Colin Fleming
<p class="vexpl">
238 2df8214a Carlos Eduardo Ramos
<span class="red"><strong><?=gettext("Note"); ?>:</strong></span>
239 1f919154 Scott Ullrich
<br />
240 f97a5b04 Darren Embry
<?=gettext("You can configure high availability sync settings"); ?> <a href="system_hasync.php"><?=gettext("here"); ?></a>.
241 0f4317d3 Colin Fleming
</p>
242 1f919154 Scott Ullrich
243
<?php
244 8cd558b6 ayvis
	echo "<br />" . gettext("pfSync nodes") . ":<br />";
245 1f919154 Scott Ullrich
	echo "<pre>";
246
	system("/sbin/pfctl -vvss | /usr/bin/grep creator | /usr/bin/cut -d\" \" -f7 | /usr/bin/sort -u");
247
	echo "</pre>";
248
?>
249
250
<?php include("fend.inc"); ?>
251 e2de5461 Scott Ullrich
252 a26686cb Scott Ullrich
</body>
253 07bdf973 Bill Marquette
</html>