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 |
ce77a9c4
|
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 |
af66ad8d
|
sbeaver
|
pfSense_MODULE: routing
|
34 |
1d333258
|
Scott Ullrich
|
*/
|
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 |
af66ad8d
|
sbeaver
|
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 |
6b6a76f9
|
Scott Ullrich
|
if (!is_array($config['load_balancer']['lbpool'])) {
|
57 |
|
|
$config['load_balancer']['lbpool'] = array();
|
58 |
|
|
}
|
59 |
af66ad8d
|
sbeaver
|
|
60 |
6b6a76f9
|
Scott Ullrich
|
$a_pool = &$config['load_balancer']['lbpool'];
|
61 |
|
|
|
62 |
087a89f8
|
Chris Buechler
|
$lb_logfile = "{$g['varlog_path']}/relayd.log";
|
63 |
6b6a76f9
|
Scott Ullrich
|
|
64 |
|
|
$nentries = $config['syslog']['nentries'];
|
65 |
af66ad8d
|
sbeaver
|
|
66 |
6b6a76f9
|
Scott Ullrich
|
if (!$nentries)
|
67 |
beca7814
|
jim-p
|
$nentries = 50;
|
68 |
6b6a76f9
|
Scott Ullrich
|
|
69 |
|
|
$now = time();
|
70 |
|
|
$year = date("Y");
|
71 |
|
|
|
72 |
bbaba7e6
|
Rafael Lucas
|
$pgtitle = array(gettext("Status"),gettext("Load Balancer"),gettext("Pool"));
|
73 |
9fa2a880
|
jim-p
|
$shortcut_section = "relayd";
|
74 |
af66ad8d
|
sbeaver
|
|
75 |
6b6a76f9
|
Scott Ullrich
|
include("head.inc");
|
76 |
|
|
|
77 |
a776c720
|
jim-p
|
$relay_hosts = get_lb_summary();
|
78 |
8c29490e
|
Chris Buechler
|
|
79 |
0c450e71
|
jim-p
|
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 |
af66ad8d
|
sbeaver
|
|
90 |
0c450e71
|
jim-p
|
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 |
af66ad8d
|
sbeaver
|
|
101 |
0c450e71
|
jim-p
|
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 |
af66ad8d
|
sbeaver
|
|
117 |
0c450e71
|
jim-p
|
mark_subsystem_dirty('loadbalancer');
|
118 |
|
|
write_config("Updated load balancer pools via status screen.");
|
119 |
|
|
}
|
120 |
|
|
}
|
121 |
|
|
|
122 |
af66ad8d
|
sbeaver
|
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 |
6b6a76f9
|
Scott Ullrich
|
?>
|
133 |
af66ad8d
|
sbeaver
|
|
134 |
3ae16b9b
|
Colin Fleming
|
<form action="status_lb_pool.php" method="post">
|
135 |
af66ad8d
|
sbeaver
|
<div class="panel panel-default">
|
136 |
f17594c7
|
Sjon Hortensius
|
<div class="panel-heading"><h2 class="panel-title">Load Balancer Pools</h2></div>
|
137 |
af66ad8d
|
sbeaver
|
<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 |
b33c73ff
|
Sjon Hortensius
|
foreach ($a_pool as $pool):
|
151 |
af66ad8d
|
sbeaver
|
$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}\"> {$server['ip']['addr']}:{$pool['port']} </td><td bgcolor=\"{$bgcolor}\"> ");
|
220 |
|
|
|
221 |
|
|
if($server['ip']['avail'])
|
222 |
|
|
print(" ({$server['ip']['avail']}) ");
|
223 |
|
|
?>
|
224 |
|
|
</td>
|
225 |
|
|
</tr>
|
226 |
|
|
<?php
|
227 |
beca7814
|
jim-p
|
}
|
228 |
|
|
}
|
229 |
af66ad8d
|
sbeaver
|
?>
|
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 |
beca7814
|
jim-p
|
</div>
|
256 |
faf207f1
|
jim-p
|
</form>
|
257 |
af66ad8d
|
sbeaver
|
<?php include("foot.inc");
|