Project

General

Profile

Download (5.27 KB) Statistics
| Branch: | Tag: | Revision:
1
#!/usr/local/bin/php
2
<?php
3
/*
4
    carp_status.php
5
    Copyright (C) 2004 Scott Ullrich
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
require_once("guiconfig.inc");
31
require_once("xmlparse.inc");
32

    
33
function gentitle_pkg($pgname) {
34
	global $config;
35
	return $config['system']['hostname'] . "." . $config['system']['domain'] . " - " . $pgname;
36
}
37

    
38
$status = get_carp_status();
39
if($_POST['disablecarp'] <> "") {
40
	if($status == true) {
41
		$carp_counter=find_number_of_created_carp_interfaces();
42
		mwexec("/sbin/sysctl net.inet.carp.allow=0");
43
		for($x=0; $x<$carp_counter; $x++) {
44
			mwexec("/sbin/ifconfig carp{$x} down");
45
			mwexec("/sbin/ifconfig carp{$x} destroy");
46
		}
47
		$savemsg = "{$carp_counter} IPs have been disabled.";
48
	} else {
49
		$savemsg = "CARP has been enabled.";
50
		mwexec("/sbin/sysctl net.inet.carp.allow=1");
51
		interfaces_carp_configure();
52
		interfaces_carp_bringup();
53
	}
54
}
55

    
56
$status = get_carp_status();
57

    
58
$pgtitle = "CARP: Status";
59
include("head.inc");
60

    
61
?>
62

    
63
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
64
<?php
65
include("fbegin.inc");
66
?>
67
<p class="pgtitle"><?=$pgtitle?></p>
68
<form action="carp_status.php" method="post">
69
<?php if ($savemsg) print_info_box($savemsg); ?>
70

    
71
<div id="mainlevel">
72
<table width="100%" border="0" cellpadding="0" cellspacing="0">
73
<tr><td>
74
<?php
75
	$tab_array = array();
76
	$tab_array[0] = array("CARP Virtual IPs", false, "/pkg.php?xml=carp.xml");
77
	$tab_array[1] = array("CARP Status", true, "carp_status.php");
78
	$tab_array[2] = array("CARP Settings", false, "/pkg_edit.php?xml=carp_settings.xml&id=0");
79
	display_top_tabs($tab_array);
80
?> 
81
</td></tr>
82
<tr><td class="tabcont">
83

    
84
<?php
85
	if($status == false) {
86
		$carp_enabled = false;
87
		echo "<input type=\"submit\" name=\"disablecarp\" id=\"disablecarp\" value=\"Enable Carp\">";
88
	} else {
89
		$carp_enabled = true;
90
		echo "<input type=\"submit\" name=\"disablecarp\" id=\"disablecarp\" value=\"Disable Carp\">";
91
	}
92

    
93
if(!is_array($config['installedpackages']['carp']['config'])) {
94
	echo "</td></tr></table><center><br>Could not locate any defined CARP interfaces.";
95
	echo "</center>";
96

    
97
	include("fend.inc");
98
	echo "</body></html>";
99
	exit;
100
}
101
?>
102

    
103
<p>
104

    
105
<table width="100%" border="0" cellpadding="6" cellspacing="0">
106
</tr>
107
<tr>
108
  <td class="listhdrr"><b><center>Carp Interface</center></b></td>
109
  <td class="listhdrr"><b><center>Virtual IP</center></b></td>
110
  <td class="listhdrr"><b><center>Status</center></b></td>
111
</tr>
112
<?php
113

    
114
if($config['installedpackages']['carp']['config'] <> "")
115
	$carpint=0;
116
	foreach($config['installedpackages']['carp']['config'] as $carp) {
117
		$ipaddress = $carp['ipaddress'];
118
		$premption = $carp['premption'];
119
		$password = $carp['password'];
120
		$netmask = $carp['netmask'];
121
		$vhid = $carp['vhid'];
122
		$advskew = $carp['advskew'];
123
		$pfsync = $carp['pfsync'];
124
		$synciface = $carp['synciface'];
125
		$carp_int = find_carp_interface($ipaddress);
126
		$status = get_carp_interface_status($carp_int);
127
		if(isset($carp['balancing'])) $balancing = "true"; else $balancing = "false";
128
		if(isset($carp['premption'])) $premption = "true"; else $premption = "false";
129
		echo "<tr>";
130
		$align = "valign='middle'";
131
		if($carp_enabled == false) {
132
			$icon = "<img {$align} src='/block.gif'>";
133
			$status = "DISABLED";
134
			$carp_int = "carp" . $carpint;
135
		} else {
136
			if($status == "MASTER") {
137
				$icon = "<img {$align} src='/pass.gif'>";
138
			} else if($status == "BACKUP") {
139
				$icon = "<img {$align} src='/pass_d.gif'>";
140
			} else if($status == "INIT") {
141
				$icon = "<img {$align} src='/log.gif'>";
142
			}
143
		}
144
		echo "<td class=\"listlr\"><center>" . $carp_int . "&nbsp;</td>";
145
		echo "<td class=\"listlr\"><center>" . $ipaddress . "&nbsp;</td>";
146
		echo "<td class=\"listlr\"><center>{$icon}&nbsp;&nbsp;" . $status . "&nbsp;</td>";
147
		echo "</tr>";
148
		$carpint++;
149
	}
150

    
151
?>
152
<tr><td>
153
<center>
154
<?php
155
  echo "<br>pfSync nodes:<br>";
156
  echo "<pre>";
157
  system("/sbin/pfctl -vvss | /usr/bin/grep creator | /usr/bin/cut -d\" \" -f7 | /usr/bin/sort -u");
158
  echo "</pre>";
159
?>
160
</center>
161
</td></tr>
162
</table>
163
</td></tr>
164
</table>
165
</div>
166

    
167
<?php include("fend.inc"); ?>
168
<script type="text/javascript">
169
NiftyCheck();
170
Rounded("div#mainlevel","bl br","#FFF","#eeeeee","smooth");
171
</script>
172

    
173
</body>
174
</html>
175

    
(2-2/128)