Project

General

Profile

Download (8.25 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");
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

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

    
127
?>
128

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

    
134
<?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

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

    
180
			<br/><br/>
181
			<table class="tabcont sortable" width="100%" border="0" cellpadding="6" cellspacing="0" summary="results">
182
				<tr>
183
					<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
				</tr>
187
<?php
188
				if ($carpcount == 0) {
189
					echo "</table></td></tr></table></div></form><center><br />" . gettext("Could not locate any defined CARP interfaces.");
190
					echo "</center>";
191

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

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

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

    
246
<?php include("fend.inc"); ?>
247

    
248
</body>
249
</html>
(3-3/256)