Project

General

Profile

Download (7 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	status_lb_pool.php
5
	part of pfSense (https://www.pfsense.org/)
6

    
7
	Copyright (C) 2010 Seth Mos <seth.mos@dds.nl>.
8
	Copyright (C) 2013-2015 Electric Sheep Fencing, LP
9
	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
/*
33
	pfSense_MODULE: routing
34
*/
35

    
36
##|+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
##|*MATCH=status_lb_pool.php*
41
##|-PRIV
42

    
43
require_once("guiconfig.inc");
44
require_once("functions.inc");
45
require_once("filter.inc");
46
require_once("shaper.inc");
47
require_once("vslb.inc");
48

    
49
define('COLOR', true);
50
define('LIGHTGREEN', '#90EE90');
51
define('LIGHTCORAL', '#F08080');
52
define('KHAKI',		 '#F0E68C');
53
define('LIGHTGRAY',	 '#D3D3D3');
54
define('WHITE',		 '#FFFFFF');
55

    
56
if (!is_array($config['load_balancer']['lbpool'])) {
57
	$config['load_balancer']['lbpool'] = array();
58
}
59

    
60
$a_pool = &$config['load_balancer']['lbpool'];
61

    
62
$lb_logfile = "{$g['varlog_path']}/relayd.log";
63

    
64
$nentries = $config['syslog']['nentries'];
65

    
66
if (!$nentries)
67
	$nentries = 50;
68

    
69
$now = time();
70
$year = date("Y");
71

    
72
$pgtitle = array(gettext("Status"),gettext("Load Balancer"),gettext("Pool"));
73
$shortcut_section = "relayd";
74

    
75
include("head.inc");
76

    
77
$relay_hosts = get_lb_summary();
78

    
79
if ($_POST) {
80
	if ($_POST['apply']) {
81
		$retval = 0;
82
		$retval |= filter_configure();
83
		$retval |= relayd_configure();
84
		$savemsg = get_std_save_message($retval);
85
		clear_subsystem_dirty('loadbalancer');
86
	} else {
87
		/* Keep a list of servers we find in POST variables */
88
		$newservers = array();
89

    
90
		foreach ($_POST as $name => $value) {
91
			/* Look through the POST vars to find the pool data */
92
			if (strpos($name, '|') !== false){
93
				list($poolname, $ip) = explode("|", $name);
94
				$ip = str_replace('_', '.', $ip);
95
				$newservers[$poolname][] = $ip;
96
			} elseif (is_ipaddr($value)) {
97
				$newservers[$name][] = $value;
98
			}
99
		}
100

    
101
		foreach ($a_pool as & $pool) {
102
			if (is_array($pool['servers']) && is_array($pool['serversdisabled'])) {
103
				$oldservers = array_merge($pool['servers'], $pool['serversdisabled']);
104
			} elseif (is_array($pool['servers'])) {
105
				$oldservers = $pool['servers'];
106
			} elseif (is_array($pool['serversdisabled'])) {
107
				$oldservers = $pool['serversdisabled'];
108
			} else {
109
				$oldservers = array();
110
			}
111
			if (is_array($newservers[$pool['name']])) {
112
				$pool['servers'] = $newservers[$pool['name']];
113
				$pool['serversdisabled'] = array_diff($oldservers, $newservers[$pool['name']]);
114
			}
115
		}
116

    
117
		mark_subsystem_dirty('loadbalancer');
118
		write_config("Updated load balancer pools via status screen.");
119
	}
120
}
121

    
122
if (is_subsystem_dirty('loadbalancer'))
123
	print_info_box_np('The load balancer configuration has been changed You must apply the changes in order for them to take effect.');
124

    
125
/* active tabs */
126
$tab_array = array();
127
$tab_array[] = array(gettext("Pools"), true, "status_lb_pool.php");
128
$tab_array[] = array(gettext("Virtual Servers"), false, "status_lb_vs.php");
129
display_top_tabs($tab_array);
130

    
131
$rowsprinted = 0;
132
?>
133

    
134
<form action="status_lb_pool.php" method="post">
135
	<div class="panel panel-default">
136
		<div class="panel-heading">Load Balancer Pools</div>
137
		<div class="panel-body table-responsive">
138
			<table class="table table-striped table-hover table-condensed">
139
				<thead>
140
					<tr>
141
						<th><?=gettext("Name")?></th>
142
						<th><?=gettext("Mode")?></th>
143
						<th><?=gettext("Servers")?></th>
144
						<th><?=gettext("Monitor")?></th>
145
						<th><?=gettext("Description")?></th>
146
					</tr>
147
				</thead>
148
				<tbody>
149
<?php
150
foreach ($a_pool as $pool):
151
	$rowsprinted++;
152
?>
153
					<tr>
154
						<td>
155
							<?=$pool['name']?>
156
						</td>
157
						<td>
158
<?php
159
	switch($pool['mode']) {
160
		case "loadbalance":
161
			echo "Load balancing";
162
			break;
163
		case "failover":
164
			echo "Manual failover";
165
			break;
166
		default:
167
			echo "(default)";
168
	}
169
?>
170
						</td>
171
						<td>
172
							<table> <!-- Mini-table allows manipulation of cell colors-->
173
<?php
174
	$pool_hosts=array();
175

    
176
	foreach ((array) $pool['servers'] as $server) {
177
		$svr['ip']['addr']=$server;
178
		$svr['ip']['state']=$relay_hosts[$pool['name'].":".$pool['port']][$server]['state'];
179
		$svr['ip']['avail']=$relay_hosts[$pool['name'].":".$pool['port']][$server]['avail'];
180
		$pool_hosts[]=$svr;
181
	}
182

    
183
	foreach ((array) $pool['serversdisabled'] as $server) {
184
		$svr['ip']['addr']="$server";
185
		$svr['ip']['state']='disabled';
186
		$svr['ip']['avail']='disabled';
187
		$pool_hosts[]=$svr;
188
	}
189

    
190
	asort($pool_hosts);
191

    
192
	foreach ((array) $pool_hosts as $server) {
193
		if($server['ip']['addr']!="") {
194
			switch ($server['ip']['state']) {
195
				case 'up':
196
					$bgcolor = LIGHTGREEN;	// lightgreen
197
					$checked = "checked=\"checked\"";
198
					break;
199
				case 'disabled':
200
					$bgcolor = WHITE;
201
					$checked = "";
202
					break;
203
				default:
204
					$bgcolor = LIGHTCORAL;	// lightcoral
205
					$checked = "checked=\"checked\"";
206
			}
207
?>
208
								<tr>
209
<?php
210
			switch ($pool['mode']) {
211
				case 'loadbalance':
212
					print("<td><input type=\"checkbox\" name=\"{$pool['name']}|" . str_replace('.', '_', $server['ip']['addr']) . "\" {$checked} /></td>\n");
213
					break;
214
				case 'failover':
215
					print("<td><input type=\"radio\" name=\"{$pool['name']}\" value=\"{$server['ip']['addr']}\" {$checked} /></td>\n");
216
					break;
217
			}
218

    
219
			print("<td bgcolor=\"{$bgcolor}\">&nbsp;{$server['ip']['addr']}:{$pool['port']}&nbsp;</td><td bgcolor=\"{$bgcolor}\">&nbsp;");
220

    
221
			if($server['ip']['avail'])
222
				print(" ({$server['ip']['avail']}) ");
223
?>
224
									</td>
225
								</tr>
226
<?php
227
			}
228
		}
229
?>
230
							</table>
231
						</td>
232
						<td >
233
							<?=$pool['monitor']; ?>
234
						</td>
235
						<td>
236
							<?=$pool['descr']?>
237
						</td>
238
					</tr>
239
<?php
240
endforeach;
241
?>
242
				</tbody>
243
			</table>
244
<?php
245
if($rowsprinted > 0) {
246
?>
247
			<nav class="action-buttons">
248
				<input name="Submit" type="submit" class="btn btn-primary" value="<?= gettext("Save"); ?>" />
249
				<input name="Reset"	 type="reset"  class="btn btn-danger" value="<?= gettext("Reset"); ?>" />
250
			</nav>
251
<?php
252
}
253
?>
254
		</div>
255
	</div>
256
</form>
257
<?php include("foot.inc");
(179-179/241)