Project

General

Profile

Download (7.42 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
			foreach ($viparr as $vip) {
64
				switch ($vip['mode']) {
65
				case "carp":
66
					interface_vip_bring_down($vip);
67
					interface_ipalias_cleanup("{$vip['interface']}_vip{$vip['vhid']}");
68
					sleep(1);
69
					break;
70
				}
71
			}
72
		}
73
		$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);
74
		$status = 0;
75
	} else {
76
		$savemsg = gettext("CARP has been enabled.");
77
		if(is_array($config['virtualip']['vip'])) {
78
			$viparr = &$config['virtualip']['vip'];
79
			foreach ($viparr as $vip) {
80
				switch ($vip['mode']) {
81
				case "carp":
82
					interface_carp_configure($vip);
83
					sleep(1);
84
					break;
85
				case 'ipalias':
86
					if (strpos($vip['interface'], '_vip'))
87
						interface_ipalias_configure($vip);
88
					break;
89
				}
90
			}
91
		}
92
		interfaces_sync_setup();
93
		set_single_sysctl('net.inet.carp.allow', '1');
94
		$status = 1;
95
	}
96
}
97

    
98
$carp_detected_problems = ((get_single_sysctl("net.inet.carp.demotion")) > 0);
99

    
100
$pgtitle = array(gettext("Status"),gettext("CARP"));
101
$shortcut_section = "carp";
102
include("head.inc");
103

    
104
?>
105

    
106
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
107
<?php include("fbegin.inc"); ?>
108
<form action="carp_status.php" method="post">
109
<?php if ($savemsg) print_info_box($savemsg); ?>
110

    
111
<?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.")); ?>
112

    
113

    
114
<div id="mainlevel">
115
	<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="carp status">
116
		<tr>
117
			<td>
118
<?php
119
			$carpcount = 0;
120
			if(is_array($config['virtualip']['vip'])) {
121
				foreach($config['virtualip']['vip'] as $carp) {
122
					if ($carp['mode'] == "carp") {
123
						$carpcount++;
124
						break;
125
					}
126
				}
127
			}
128
			if($carpcount > 0) {
129
				if($status > 0) {
130
					$carp_enabled = true;
131
					echo "<input type=\"submit\" name=\"disablecarp\" id=\"disablecarp\" value=\"" . gettext("Temporarily Disable CARP") . "\" />";
132
				} else {
133
					$carp_enabled = false;
134
					echo "<input type=\"submit\" name=\"disablecarp\" id=\"disablecarp\" value=\"" . gettext("Enable CARP") . "\" />";
135
				}
136
				if(isset($config["virtualip_carp_maintenancemode"])) {
137
					echo "<input type=\"submit\" name=\"carp_maintenancemode\" id=\"carp_maintenancemode\" value=\"" . gettext("Leave Persistent CARP Maintenance Mode") . "\" />";
138
				} else {
139
					echo "<input type=\"submit\" name=\"carp_maintenancemode\" id=\"carp_maintenancemode\" value=\"" . gettext("Enter Persistent CARP Maintenance Mode") . "\" />";
140
				}
141
			}
142
?>
143

    
144
			<br/><br/>
145
			<table class="tabcont sortable" width="100%" border="0" cellpadding="6" cellspacing="0" summary="results">
146
				<tr>
147
					<td class="listhdrr" align="center"><?=gettext("CARP Interface"); ?></td>
148
					<td class="listhdrr" align="center"><?=gettext("Virtual IP"); ?></td>
149
					<td class="listhdrr" align="center"><?=gettext("Status"); ?></td>
150
				</tr>
151
<?php
152
				if ($carpcount == 0) {
153
					echo "</table></td></tr></table></div></form><center><br />" . gettext("Could not locate any defined CARP interfaces.");
154
					echo "</center>";
155

    
156
					include("fend.inc");
157
					echo "</body></html>";
158
					return;
159
				}
160
				if(is_array($config['virtualip']['vip'])) {
161
					foreach($config['virtualip']['vip'] as $carp) {
162
						if ($carp['mode'] != "carp")
163
							continue;
164
						$ipaddress = $carp['subnet'];
165
						$password = $carp['password'];
166
						$netmask = $carp['subnet_bits'];
167
						$vhid = $carp['vhid'];
168
						$advskew = $carp['advskew'];
169
						$advbase = $carp['advbase'];
170
						$status = get_carp_interface_status("{$carp['interface']}_vip{$carp['vhid']}");
171
						echo "<tr>";
172
						$align = "style=\"vertical-align:middle\"";
173
						if($carp_enabled == false) {
174
							$icon = "<img {$align} src=\"/themes/".$g['theme']."/images/icons/icon_block.gif\" alt=\"disabled\" />";
175
							$status = "DISABLED";
176
						} else {
177
							if($status == "MASTER") {
178
								$icon = "<img {$align} src=\"/themes/".$g['theme']."/images/icons/icon_pass.gif\" alt=\"master\" />";
179
							} else if($status == "BACKUP") {
180
								$icon = "<img {$align} src=\"/themes/".$g['theme']."/images/icons/icon_pass_d.gif\" alt=\"backup\" />";
181
							} else if($status == "INIT") {
182
								$icon = "<img {$align} src=\"/themes/".$g['theme']."/images/icons/icon_log.gif\" alt=\"init\" />";
183
							}
184
						}
185
						echo "<td class=\"listlr\" align=\"center\">" . convert_friendly_interface_to_friendly_descr($carp['interface']) . "@{$vhid} &nbsp;</td>";
186
						echo "<td class=\"listlr\" align=\"center\">" . $ipaddress . "&nbsp;</td>";
187
						echo "<td class=\"listlr\" align=\"center\">{$icon}&nbsp;&nbsp;" . $status . "&nbsp;</td>";
188
						echo "</tr>";
189
					}
190
				}
191
?>
192
			</table>
193
			</td>
194
		</tr>
195
	</table>
196
</div>
197
</form>
198

    
199
<p class="vexpl">
200
<span class="red"><strong><?=gettext("Note"); ?>:</strong></span>
201
<br />
202
<?=gettext("You can configure high availability sync settings"); ?> <a href="system_hasync.php"><?=gettext("here"); ?></a>.
203
</p>
204

    
205
<?php
206
	echo "<br />" . gettext("pfSync nodes") . ":<br />";
207
	echo "<pre>";
208
	system("/sbin/pfctl -vvss | /usr/bin/grep creator | /usr/bin/cut -d\" \" -f7 | /usr/bin/sort -u");
209
	echo "</pre>";
210
?>
211

    
212
<?php include("fend.inc"); ?>
213

    
214
</body>
215
</html>
(3-3/256)