Project

General

Profile

Download (7.3 KB) Statistics
| Branch: | Tag: | Revision:
1 a26686cb Scott Ullrich
<?php
2
/*
3
    carp_status.php
4
    Copyright (C) 2004 Scott Ullrich
5 dd447bde Jim Thompson
    Copyright (C) 2013-2014 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 aae16684 Renato Botelho
			foreach ($viparr as $vip) {
64
				switch ($vip['mode']) {
65
				case "carp":
66
					interface_vip_bring_down($vip);
67
					sleep(1);
68
					break;
69
				}
70
			}
71
		}
72 24143605 Scott Ullrich
		$savemsg = sprintf(gettext("%s IPs have been disabled. Please note that disabling does not survive a reboot."), $carp_counter);
73 9c296826 Ermal
		$status = 0;
74 a26686cb Scott Ullrich
	} else {
75 2df8214a Carlos Eduardo Ramos
		$savemsg = gettext("CARP has been enabled.");
76 8e2986f8 Ermal
		if(is_array($config['virtualip']['vip'])) {
77 aae16684 Renato Botelho
			$viparr = &$config['virtualip']['vip'];
78
			foreach ($viparr as $vip) {
79 a133bb38 Ermal
				switch ($vip['mode']) {
80 aae16684 Renato Botelho
				case "carp":
81
					interface_carp_configure($vip);
82
					sleep(1);
83 a133bb38 Ermal
					break;
84 5063f1df Ermal
				case 'ipalias':
85
					if (strpos($vip['interface'], '_vip'))
86
						interface_ipalias_configure($vip);
87
					break;
88 e120d5ce Chris Buechler
				}
89 aae16684 Renato Botelho
			}
90
		}
91 8ff85c39 Ermal
		interfaces_sync_setup();
92 971de1f9 Renato Botelho
		set_single_sysctl('net.inet.carp.allow', '1');
93 9c296826 Ermal
		$status = 1;
94 a26686cb Scott Ullrich
	}
95
}
96
97 9c296826 Ermal
$carp_detected_problems = ((get_single_sysctl("net.inet.carp.demotion")) > 0);
98 8a84b3ab jim-p
99 2df8214a Carlos Eduardo Ramos
$pgtitle = array(gettext("Status"),gettext("CARP"));
100 b32dd0a6 jim-p
$shortcut_section = "carp";
101 b63695db Scott Ullrich
include("head.inc");
102
103 a26686cb Scott Ullrich
?>
104
105
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
106 e8fc8fa0 Erik Kristensen
<?php include("fbegin.inc"); ?>
107 a26686cb Scott Ullrich
<form action="carp_status.php" method="post">
108
<?php if ($savemsg) print_info_box($savemsg); ?>
109
110 8a84b3ab jim-p
<?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.")); ?>
111
112
113 4208d208 Scott Ullrich
<div id="mainlevel">
114 0f4317d3 Colin Fleming
	<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="carp status">
115 e8fc8fa0 Erik Kristensen
		<tr>
116 1f919154 Scott Ullrich
			<td>
117 a26686cb Scott Ullrich
<?php
118 2bfade90 Ermal
			$carpcount = 0;
119 e8fc8fa0 Erik Kristensen
			if(is_array($config['virtualip']['vip'])) {
120
				foreach($config['virtualip']['vip'] as $carp) {
121 4ed5ad5a Ermal
					if ($carp['mode'] == "carp") {
122 9175156f Scott Ullrich
						$carpcount++;
123 4ed5ad5a Ermal
						break;
124
					}
125 9175156f Scott Ullrich
				}
126
			}
127
			if($carpcount > 0) {
128 9c296826 Ermal
				if($status > 0) {
129 9175156f Scott Ullrich
					$carp_enabled = true;
130 0f4317d3 Colin Fleming
					echo "<input type=\"submit\" name=\"disablecarp\" id=\"disablecarp\" value=\"" . gettext("Temporarily Disable CARP") . "\" />";
131 9c296826 Ermal
				} else {
132
					$carp_enabled = false;
133
					echo "<input type=\"submit\" name=\"disablecarp\" id=\"disablecarp\" value=\"" . gettext("Enable CARP") . "\" />";
134 783f1ee2 PiBa-NL
				}
135
				if(isset($config["virtualip_carp_maintenancemode"])) {
136 0f4317d3 Colin Fleming
					echo "<input type=\"submit\" name=\"carp_maintenancemode\" id=\"carp_maintenancemode\" value=\"" . gettext("Leave Persistent CARP Maintenance Mode") . "\" />";
137 783f1ee2 PiBa-NL
				} else {
138 0f4317d3 Colin Fleming
					echo "<input type=\"submit\" name=\"carp_maintenancemode\" id=\"carp_maintenancemode\" value=\"" . gettext("Enter Persistent CARP Maintenance Mode") . "\" />";
139 e8fc8fa0 Erik Kristensen
				}
140
			}
141 a26686cb Scott Ullrich
?>
142
143 0f4317d3 Colin Fleming
			<br/><br/>
144
			<table class="tabcont sortable" width="100%" border="0" cellpadding="6" cellspacing="0" summary="results">
145 e8fc8fa0 Erik Kristensen
				<tr>
146 0f4317d3 Colin Fleming
					<td class="listhdrr" align="center"><?=gettext("CARP Interface"); ?></td>
147
					<td class="listhdrr" align="center"><?=gettext("Virtual IP"); ?></td>
148
					<td class="listhdrr" align="center"><?=gettext("Status"); ?></td>
149 e8fc8fa0 Erik Kristensen
				</tr>
150 a26686cb Scott Ullrich
<?php
151 172bd075 Scott Ullrich
				if ($carpcount == 0) {
152 0f4317d3 Colin Fleming
					echo "</table></td></tr></table></div></form><center><br />" . gettext("Could not locate any defined CARP interfaces.");
153 172bd075 Scott Ullrich
					echo "</center>";
154
155
					include("fend.inc");
156
					echo "</body></html>";
157 8a84b3ab jim-p
					return;
158 172bd075 Scott Ullrich
				}
159 e8fc8fa0 Erik Kristensen
				if(is_array($config['virtualip']['vip'])) {
160
					foreach($config['virtualip']['vip'] as $carp) {
161 4ed5ad5a Ermal
						if ($carp['mode'] != "carp")
162
							continue;
163 e8fc8fa0 Erik Kristensen
						$ipaddress = $carp['subnet'];
164
						$password = $carp['password'];
165
						$netmask = $carp['subnet_bits'];
166
						$vhid = $carp['vhid'];
167
						$advskew = $carp['advskew'];
168 6f247d1f Ermal
						$advbase = $carp['advbase'];
169 0c21eb70 Ermal
						$status = get_carp_interface_status("{$carp['interface']}_vip{$carp['vhid']}");
170 e8fc8fa0 Erik Kristensen
						echo "<tr>";
171 0f4317d3 Colin Fleming
						$align = "style=\"vertical-align:middle\"";
172 e8fc8fa0 Erik Kristensen
						if($carp_enabled == false) {
173 23b3e679 Renato Botelho
							$icon = "<img {$align} src=\"/themes/".$g['theme']."/images/icons/icon_block.gif\" alt=\"disabled\" />";
174 e8fc8fa0 Erik Kristensen
							$status = "DISABLED";
175
						} else {
176
							if($status == "MASTER") {
177 0f4317d3 Colin Fleming
								$icon = "<img {$align} src=\"/themes/".$g['theme']."/images/icons/icon_pass.gif\" alt=\"master\" />";
178 e8fc8fa0 Erik Kristensen
							} else if($status == "BACKUP") {
179 0f4317d3 Colin Fleming
								$icon = "<img {$align} src=\"/themes/".$g['theme']."/images/icons/icon_pass_d.gif\" alt=\"backup\" />";
180 e8fc8fa0 Erik Kristensen
							} else if($status == "INIT") {
181 0f4317d3 Colin Fleming
								$icon = "<img {$align} src=\"/themes/".$g['theme']."/images/icons/icon_log.gif\" alt=\"init\" />";
182 e8fc8fa0 Erik Kristensen
							}
183
						}
184 0f4317d3 Colin Fleming
						echo "<td class=\"listlr\" align=\"center\">" . convert_friendly_interface_to_friendly_descr($carp['interface']) . "@{$vhid} &nbsp;</td>";
185
						echo "<td class=\"listlr\" align=\"center\">" . $ipaddress . "&nbsp;</td>";
186
						echo "<td class=\"listlr\" align=\"center\">{$icon}&nbsp;&nbsp;" . $status . "&nbsp;</td>";
187 e8fc8fa0 Erik Kristensen
						echo "</tr>";
188
					}
189
				}
190 a26686cb Scott Ullrich
?>
191 e8fc8fa0 Erik Kristensen
			</table>
192
			</td>
193
		</tr>
194
	</table>
195 e2de5461 Scott Ullrich
</div>
196 0f4317d3 Colin Fleming
</form>
197 a26686cb Scott Ullrich
198 0f4317d3 Colin Fleming
<p class="vexpl">
199 2df8214a Carlos Eduardo Ramos
<span class="red"><strong><?=gettext("Note"); ?>:</strong></span>
200 1f919154 Scott Ullrich
<br />
201 f97a5b04 Darren Embry
<?=gettext("You can configure high availability sync settings"); ?> <a href="system_hasync.php"><?=gettext("here"); ?></a>.
202 0f4317d3 Colin Fleming
</p>
203 1f919154 Scott Ullrich
204
<?php
205 8cd558b6 ayvis
	echo "<br />" . gettext("pfSync nodes") . ":<br />";
206 1f919154 Scott Ullrich
	echo "<pre>";
207
	system("/sbin/pfctl -vvss | /usr/bin/grep creator | /usr/bin/cut -d\" \" -f7 | /usr/bin/sort -u");
208
	echo "</pre>";
209
?>
210
211
<?php include("fend.inc"); ?>
212 e2de5461 Scott Ullrich
213 a26686cb Scott Ullrich
</body>
214 07bdf973 Bill Marquette
</html>