Project

General

Profile

Download (7.09 KB) Statistics
| Branch: | Tag: | Revision:
1 6b6a76f9 Scott Ullrich
<?php
2
/* $Id$ */
3
/*
4 477dcf13 Chris Buechler
	status_lb_pool.php
5 6b6a76f9 Scott Ullrich
	part of pfSense (http://www.pfsense.com/)
6
7 6216690b smos
	Copyright (C) 2010 Seth Mos <seth.mos@dds.nl>.
8 6b6a76f9 Scott Ullrich
	All rights reserved.
9
10
	Redistribution and use in source and binary forms, with or without
11
	modification, are permitted provided that the following conditions are met:
12
13
	1. Redistributions of source code must retain the above copyright notice,
14
	   this list of conditions and the following disclaimer.
15
16
	2. Redistributions in binary form must reproduce the above copyright
17
	   notice, this list of conditions and the following disclaimer in the
18
	   documentation and/or other materials provided with the distribution.
19
20
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
21
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
22
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
24
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
	POSSIBILITY OF SUCH DAMAGE.
30
*/
31 beca7814 jim-p
/*
32 1d333258 Scott Ullrich
	pfSense_MODULE:	routing
33
*/
34 6b6a76f9 Scott Ullrich
35 6b07c15a Matthew Grooms
##|+PRIV
36
##|*IDENT=page-status-loadbalancer-pool
37
##|*NAME=Status: Load Balancer: Pool page
38
##|*DESCR=Allow access to the 'Status: Load Balancer: Pool' page.
39 477dcf13 Chris Buechler
##|*MATCH=status_lb_pool.php*
40 6b07c15a Matthew Grooms
##|-PRIV
41
42 0c450e71 jim-p
require_once("guiconfig.inc");
43
require_once("functions.inc");
44
require_once("filter.inc");
45
require_once("shaper.inc");
46 a776c720 jim-p
require_once("vslb.inc");
47 6b6a76f9 Scott Ullrich
48
if (!is_array($config['load_balancer']['lbpool'])) {
49
	$config['load_balancer']['lbpool'] = array();
50
}
51
$a_pool = &$config['load_balancer']['lbpool'];
52
53 087a89f8 Chris Buechler
$lb_logfile = "{$g['varlog_path']}/relayd.log";
54 6b6a76f9 Scott Ullrich
55
$nentries = $config['syslog']['nentries'];
56
if (!$nentries)
57 beca7814 jim-p
	$nentries = 50;
58 6b6a76f9 Scott Ullrich
59
$now = time();
60
$year = date("Y");
61
62 bbaba7e6 Rafael Lucas
$pgtitle = array(gettext("Status"),gettext("Load Balancer"),gettext("Pool"));
63 9fa2a880 jim-p
$shortcut_section = "relayd";
64 6b6a76f9 Scott Ullrich
include("head.inc");
65
66 a776c720 jim-p
$relay_hosts = get_lb_summary();
67 8c29490e Chris Buechler
68 0c450e71 jim-p
if ($_POST) {
69
	if ($_POST['apply']) {
70
		$retval = 0;
71
		$retval |= filter_configure();
72
		$retval |= relayd_configure();
73
		$savemsg = get_std_save_message($retval);
74
		clear_subsystem_dirty('loadbalancer');
75
	} else {
76
		/* Keep a list of servers we find in POST variables */
77
		$newservers = array();
78
		foreach ($_POST as $name => $value) {
79
			/* Look through the POST vars to find the pool data */
80
			if (strpos($name, '|') !== false){
81
				list($poolname, $ip) = explode("|", $name);
82
				$ip = str_replace('_', '.', $ip);
83
				$newservers[$poolname][] = $ip;
84
			} elseif (is_ipaddr($value)) {
85
				$newservers[$name][] = $value;
86
			}
87
		}
88
		foreach ($a_pool as & $pool) {
89
			if (is_array($pool['servers']) && is_array($pool['serversdisabled'])) {
90
				$oldservers = array_merge($pool['servers'], $pool['serversdisabled']);
91
			} elseif (is_array($pool['servers'])) {
92
				$oldservers = $pool['servers'];
93
			} elseif (is_array($pool['serversdisabled'])) {
94
				$oldservers = $pool['serversdisabled'];
95
			} else {
96
				$oldservers = array();
97
			}
98
			if (is_array($newservers[$pool['name']])) {
99
				$pool['servers'] = $newservers[$pool['name']];
100
				$pool['serversdisabled'] = array_diff($oldservers, $newservers[$pool['name']]);
101
			}
102
		}
103
		mark_subsystem_dirty('loadbalancer');
104
		write_config("Updated load balancer pools via status screen.");
105
	}
106
}
107
108 6b6a76f9 Scott Ullrich
?>
109
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
110
<?php include("fbegin.inc"); ?>
111 3ae16b9b Colin Fleming
<form action="status_lb_pool.php" method="post">
112 0c450e71 jim-p
<?php if (is_subsystem_dirty('loadbalancer')): ?><p>
113
<?php print_info_box_np(sprintf(gettext("The load balancer configuration has been changed%sYou must apply the changes in order for them to take effect."), "<br>"));?><br>
114
<?php endif; ?>
115 6b6a76f9 Scott Ullrich
<table width="100%" border="0" cellpadding="0" cellspacing="0">
116 beca7814 jim-p
	<tr><td class="tabnavtbl">
117
	<?php
118
	/* active tabs */
119
	$tab_array = array();
120
	$tab_array[] = array(gettext("Pools"), true, "status_lb_pool.php");
121
	$tab_array[] = array(gettext("Virtual Servers"), false, "status_lb_vs.php");
122
	display_top_tabs($tab_array);
123
	?>
124
	</td></tr>
125
	<tr>
126
	<td>
127 6b6a76f9 Scott Ullrich
	<div id="mainarea">
128 beca7814 jim-p
		<table width="100%" border="0" cellpadding="0" cellspacing="0" class="tabcont sortable" name="sortabletable" id="sortabletable">
129
		<tr>
130
		<td width="10%" class="listhdrr"><?=gettext("Name");?></td>
131
		<td width="10%" class="listhdrr"><?=gettext("Mode");?></td>
132 e6a8a626 Eirik Oeverby
		<td width="20%" class="listhdrr"><?=gettext("Servers");?></td>
133 beca7814 jim-p
		<td width="10%" class="listhdrr"><?=gettext("Monitor");?></td>
134
		<td width="30%" class="listhdr"><?=gettext("Description");?></td>
135
		</tr>
136 0c450e71 jim-p
		<?php foreach ($a_pool as & $pool): ?>
137 beca7814 jim-p
		<tr>
138
		<td class="listlr">
139 191b00d9 jim-p
			<?=$pool['name'];?>
140 beca7814 jim-p
		</td>
141
		<td class="listr" align="center" >
142
		<?php
143 191b00d9 jim-p
		switch($pool['mode']) {
144 beca7814 jim-p
			case "loadbalance":
145
				echo "Load balancing";
146
				break;
147
			case "failover":
148
				echo "Manual failover";
149
				break;
150
			default:
151
				echo "(default)";
152
		}
153
		?>
154
		</td>
155 e6a8a626 Eirik Oeverby
		<td class="listr" align="center">
156
		<table border="0" cellpadding="2" cellspacing="0">
157 beca7814 jim-p
		<?php
158 e34f19ec Eirik Oeverby
		$pool_hosts=array();
159 191b00d9 jim-p
		foreach ((array) $pool['servers'] as $server) {
160 e34f19ec Eirik Oeverby
			$svr['ip']['addr']=$server;
161 94933d56 Eirik Oeverby
			$svr['ip']['state']=$relay_hosts[$pool['name'].":".$pool['port']][$server]['state'];
162 e6a8a626 Eirik Oeverby
			$svr['ip']['avail']=$relay_hosts[$pool['name'].":".$pool['port']][$server]['avail'];
163 e34f19ec Eirik Oeverby
			$pool_hosts[]=$svr;
164
		}
165
		foreach ((array) $pool['serversdisabled'] as $server) {
166
			$svr['ip']['addr']="$server";
167
			$svr['ip']['state']='disabled';
168 e6a8a626 Eirik Oeverby
			$svr['ip']['avail']='disabled';
169 e34f19ec Eirik Oeverby
			$pool_hosts[]=$svr;
170
		}
171
		asort($pool_hosts);
172
173
		foreach ((array) $pool_hosts as $server) {
174
			if($server['ip']['addr']!="") {
175
				switch ($server['ip']['state']) {
176 beca7814 jim-p
					case 'up':
177 a0c0e8ae Colin Fleming
						$bgcolor = "#90EE90";  // lightgreen
178 e34f19ec Eirik Oeverby
						$checked = "checked";
179
						break;
180
					case 'disabled':
181
						$bgcolor = "white";
182
						$checked = "";
183 beca7814 jim-p
						break;
184
					default:
185 a0c0e8ae Colin Fleming
						$bgcolor = "#F08080";  // lightcoral
186 e34f19ec Eirik Oeverby
						$checked = "checked";
187 beca7814 jim-p
				}
188 3b370abf jim-p
				echo "<tr>";
189 191b00d9 jim-p
				switch ($pool['mode']) {
190 beca7814 jim-p
					case 'loadbalance':
191 e34f19ec Eirik Oeverby
						echo "<td><input type='checkbox' name='{$pool['name']}|".str_replace('.', '_', $server['ip']['addr'])."' {$checked}></td>\n";
192 cdad3139 Eirik Oeverby
						break;
193 beca7814 jim-p
					case 'failover':
194 e34f19ec Eirik Oeverby
						echo "<td><input type='radio' name='{$pool['name']}' value='{$server['ip']['addr']}' {$checked}></td>\n";
195 cdad3139 Eirik Oeverby
						break;
196 8c29490e Chris Buechler
				}
197 a0c0e8ae Colin Fleming
				echo "<td bgcolor={$bgcolor}>&nbsp;{$server['ip']['addr']}:{$pool['port']}&nbsp;</td><td bgcolor={$bgcolor}>&nbsp;";
198
#				echo "<td bgcolor={$bgcolor}>&nbsp;{$server['ip']['addr']}:{$pool['port']} ";
199 e6a8a626 Eirik Oeverby
				if($server['ip']['avail'])
200
				  echo " ({$server['ip']['avail']}) ";
201 a0c0e8ae Colin Fleming
				echo "&nbsp;</td></tr>";
202 beca7814 jim-p
			}
203
		}
204
		?>
205
		</table>
206
		</td>
207
		<td class="listr" >
208 191b00d9 jim-p
			<?php echo $pool['monitor']; ?>
209 beca7814 jim-p
		</td>
210
		<td class="listbg" >
211 e988813d jim-p
			<?=$pool['descr'];?>
212 beca7814 jim-p
		</td>
213
		</tr>
214 0c450e71 jim-p
		<?php endforeach; ?>
215 faf207f1 jim-p
		<tr>
216
			<td colspan="5">
217
			<input name="Submit" type="submit" class="formbtn" value="<?= gettext("Save"); ?>">
218 beca7814 jim-p
			<input name="Reset"  type="reset"  class="formbtn" value="<?= gettext("Reset"); ?>">
219 faf207f1 jim-p
			</td>
220
		</tr>
221 beca7814 jim-p
		</table>
222
	</div>
223 6b6a76f9 Scott Ullrich
	</table>
224 faf207f1 jim-p
</form>
225 6b6a76f9 Scott Ullrich
<?php include("fend.inc"); ?>
226
</body>
227
</html>