Project

General

Profile

Download (7.84 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
?>
122

    
123
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
124
<?php include("fbegin.inc"); ?>
125
<form action="carp_status.php" method="post">
126
<?php if ($savemsg) print_info_box($savemsg); ?>
127

    
128
<?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.")); ?>
129

    
130

    
131
<div id="mainlevel">
132
	<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="carp status">
133
		<tr>
134
			<td>
135
<?php
136
			$carpcount = 0;
137
			if(is_array($config['virtualip']['vip'])) {
138
				foreach($config['virtualip']['vip'] as $carp) {
139
					if ($carp['mode'] == "carp") {
140
						$carpcount++;
141
						break;
142
					}
143
				}
144
			}
145
			if($carpcount > 0) {
146
				if($status > 0) {
147
					$carp_enabled = true;
148
					echo "<input type=\"submit\" name=\"disablecarp\" id=\"disablecarp\" value=\"" . gettext("Temporarily Disable CARP") . "\" />";
149
				} else {
150
					$carp_enabled = false;
151
					echo "<input type=\"submit\" name=\"disablecarp\" id=\"disablecarp\" value=\"" . gettext("Enable CARP") . "\" />";
152
				}
153
				if(isset($config["virtualip_carp_maintenancemode"])) {
154
					echo "<input type=\"submit\" name=\"carp_maintenancemode\" id=\"carp_maintenancemode\" value=\"" . gettext("Leave Persistent CARP Maintenance Mode") . "\" />";
155
				} else {
156
					echo "<input type=\"submit\" name=\"carp_maintenancemode\" id=\"carp_maintenancemode\" value=\"" . gettext("Enter Persistent CARP Maintenance Mode") . "\" />";
157
				}
158
			}
159
?>
160

    
161
			<br/><br/>
162
			<table class="tabcont sortable" width="100%" border="0" cellpadding="6" cellspacing="0" summary="results">
163
				<tr>
164
					<td class="listhdrr" align="center"><?=gettext("CARP Interface"); ?></td>
165
					<td class="listhdrr" align="center"><?=gettext("Virtual IP"); ?></td>
166
					<td class="listhdrr" align="center"><?=gettext("Status"); ?></td>
167
				</tr>
168
<?php
169
				if ($carpcount == 0) {
170
					echo "</table></td></tr></table></div></form><center><br />" . gettext("Could not locate any defined CARP interfaces.");
171
					echo "</center>";
172

    
173
					include("fend.inc");
174
					echo "</body></html>";
175
					return;
176
				}
177
				if(is_array($config['virtualip']['vip'])) {
178
					foreach($config['virtualip']['vip'] as $carp) {
179
						if ($carp['mode'] != "carp")
180
							continue;
181
						$ipaddress = $carp['subnet'];
182
						$password = $carp['password'];
183
						$netmask = $carp['subnet_bits'];
184
						$vhid = $carp['vhid'];
185
						$advskew = $carp['advskew'];
186
						$advbase = $carp['advbase'];
187
						$status = get_carp_interface_status("{$carp['interface']}_vip{$carp['vhid']}");
188
						echo "<tr>";
189
						$align = "style=\"vertical-align:middle\"";
190
						if($carp_enabled == false) {
191
							$icon = "<img {$align} src=\"/themes/".$g['theme']."/images/icons/icon_block.gif\" alt=\"disabled\" />";
192
							$status = "DISABLED";
193
						} else {
194
							if($status == "MASTER") {
195
								$icon = "<img {$align} src=\"/themes/".$g['theme']."/images/icons/icon_pass.gif\" alt=\"master\" />";
196
							} else if($status == "BACKUP") {
197
								$icon = "<img {$align} src=\"/themes/".$g['theme']."/images/icons/icon_pass_d.gif\" alt=\"backup\" />";
198
							} else if($status == "INIT") {
199
								$icon = "<img {$align} src=\"/themes/".$g['theme']."/images/icons/icon_log.gif\" alt=\"init\" />";
200
							}
201
						}
202
						echo "<td class=\"listlr\" align=\"center\">" . convert_friendly_interface_to_friendly_descr($carp['interface']) . "@{$vhid} &nbsp;</td>";
203
						echo "<td class=\"listlr\" align=\"center\">" . $ipaddress . "&nbsp;</td>";
204
						echo "<td class=\"listlr\" align=\"center\">{$icon}&nbsp;&nbsp;" . $status . "&nbsp;</td>";
205
						echo "</tr>";
206
					}
207
				}
208
?>
209
			</table>
210
			</td>
211
		</tr>
212
	</table>
213
</div>
214
</form>
215

    
216
<p class="vexpl">
217
<span class="red"><strong><?=gettext("Note"); ?>:</strong></span>
218
<br />
219
<?=gettext("You can configure high availability sync settings"); ?> <a href="system_hasync.php"><?=gettext("here"); ?></a>.
220
</p>
221

    
222
<?php
223
	echo "<br />" . gettext("pfSync nodes") . ":<br />";
224
	echo "<pre>";
225
	system("/sbin/pfctl -vvss | /usr/bin/grep creator | /usr/bin/cut -d\" \" -f7 | /usr/bin/sort -u");
226
	echo "</pre>";
227
?>
228

    
229
<?php include("fend.inc"); ?>
230

    
231
</body>
232
</html>
(3-3/256)