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
|
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
|
/*
|
32
|
pfSense_MODULE: routing
|
33
|
*/
|
34
|
|
35
|
##|+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
|
##|*MATCH=status_lb_pool.php*
|
40
|
##|-PRIV
|
41
|
|
42
|
require_once("guiconfig.inc");
|
43
|
require_once("functions.inc");
|
44
|
require_once("filter.inc");
|
45
|
require_once("shaper.inc");
|
46
|
require_once("vslb.inc");
|
47
|
|
48
|
if (!is_array($config['load_balancer']['lbpool'])) {
|
49
|
$config['load_balancer']['lbpool'] = array();
|
50
|
}
|
51
|
$a_pool = &$config['load_balancer']['lbpool'];
|
52
|
|
53
|
$lb_logfile = "{$g['varlog_path']}/relayd.log";
|
54
|
|
55
|
$nentries = $config['syslog']['nentries'];
|
56
|
if (!$nentries)
|
57
|
$nentries = 50;
|
58
|
|
59
|
$now = time();
|
60
|
$year = date("Y");
|
61
|
|
62
|
$pgtitle = array(gettext("Status"),gettext("Load Balancer"),gettext("Pool"));
|
63
|
$shortcut_section = "relayd";
|
64
|
include("head.inc");
|
65
|
|
66
|
$relay_hosts = get_lb_summary();
|
67
|
|
68
|
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
|
?>
|
109
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
|
110
|
<?php include("fbegin.inc"); ?>
|
111
|
<form action="status_lb_pool.php" method="post">
|
112
|
<?php if (is_subsystem_dirty('loadbalancer')): ?><br/>
|
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
|
<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="status load balancer pools">
|
116
|
<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
|
<div id="mainarea">
|
128
|
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="tabcont sortable" id="sortabletable" summary="main area">
|
129
|
<tr>
|
130
|
<td width="10%" class="listhdrr"><?=gettext("Name");?></td>
|
131
|
<td width="10%" class="listhdrr"><?=gettext("Mode");?></td>
|
132
|
<td width="20%" class="listhdrr"><?=gettext("Servers");?></td>
|
133
|
<td width="10%" class="listhdrr"><?=gettext("Monitor");?></td>
|
134
|
<td width="30%" class="listhdr"><?=gettext("Description");?></td>
|
135
|
</tr>
|
136
|
<?php foreach ($a_pool as & $pool): ?>
|
137
|
<tr>
|
138
|
<td class="listlr">
|
139
|
<?=$pool['name'];?>
|
140
|
</td>
|
141
|
<td class="listr" align="center" >
|
142
|
<?php
|
143
|
switch($pool['mode']) {
|
144
|
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
|
<td class="listr" align="center">
|
156
|
<table border="0" cellpadding="2" cellspacing="0" summary="status">
|
157
|
<?php
|
158
|
$pool_hosts=array();
|
159
|
foreach ((array) $pool['servers'] as $server) {
|
160
|
$svr['ip']['addr']=$server;
|
161
|
$svr['ip']['state']=$relay_hosts[$pool['name'].":".$pool['port']][$server]['state'];
|
162
|
$svr['ip']['avail']=$relay_hosts[$pool['name'].":".$pool['port']][$server]['avail'];
|
163
|
$pool_hosts[]=$svr;
|
164
|
}
|
165
|
foreach ((array) $pool['serversdisabled'] as $server) {
|
166
|
$svr['ip']['addr']="$server";
|
167
|
$svr['ip']['state']='disabled';
|
168
|
$svr['ip']['avail']='disabled';
|
169
|
$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
|
case 'up':
|
177
|
$bgcolor = "#90EE90"; // lightgreen
|
178
|
$checked = "checked=\"checked\"";
|
179
|
break;
|
180
|
case 'disabled':
|
181
|
$bgcolor = "white";
|
182
|
$checked = "";
|
183
|
break;
|
184
|
default:
|
185
|
$bgcolor = "#F08080"; // lightcoral
|
186
|
$checked = "checked=\"checked\"";
|
187
|
}
|
188
|
echo "<tr>";
|
189
|
switch ($pool['mode']) {
|
190
|
case 'loadbalance':
|
191
|
echo "<td><input type=\"checkbox\" name=\"{$pool['name']}|" . str_replace('.', '_', $server['ip']['addr']) . "\" {$checked} /></td>\n";
|
192
|
break;
|
193
|
case 'failover':
|
194
|
echo "<td><input type=\"radio\" name=\"{$pool['name']}\" value=\"{$server['ip']['addr']}\" {$checked} /></td>\n";
|
195
|
break;
|
196
|
}
|
197
|
echo "<td bgcolor=\"{$bgcolor}\"> {$server['ip']['addr']}:{$pool['port']} </td><td bgcolor=\"{$bgcolor}\"> ";
|
198
|
# echo "<td bgcolor=\"{$bgcolor}\"> {$server['ip']['addr']}:{$pool['port']} ";
|
199
|
if($server['ip']['avail'])
|
200
|
echo " ({$server['ip']['avail']}) ";
|
201
|
echo " </td></tr>";
|
202
|
}
|
203
|
}
|
204
|
?>
|
205
|
</table>
|
206
|
</td>
|
207
|
<td class="listr" >
|
208
|
<?php echo $pool['monitor']; ?>
|
209
|
</td>
|
210
|
<td class="listbg" >
|
211
|
<?=$pool['descr'];?>
|
212
|
</td>
|
213
|
</tr>
|
214
|
<?php endforeach; ?>
|
215
|
<tr>
|
216
|
<td colspan="5">
|
217
|
<input name="Submit" type="submit" class="formbtn" value="<?= gettext("Save"); ?>" />
|
218
|
<input name="Reset" type="reset" class="formbtn" value="<?= gettext("Reset"); ?>" />
|
219
|
</td>
|
220
|
</tr>
|
221
|
</table>
|
222
|
</div>
|
223
|
</td></tr>
|
224
|
</table>
|
225
|
</form>
|
226
|
<?php include("fend.inc"); ?>
|
227
|
</body>
|
228
|
</html>
|