Project

General

Profile

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