Project

General

Profile

Download (7.27 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
if (!is_array($config['load_balancer']['lbpool'])) {
50
	$config['load_balancer']['lbpool'] = array();
51
}
52
$a_pool = &$config['load_balancer']['lbpool'];
53

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

    
56
$nentries = $config['syslog']['nentries'];
57
if (!$nentries)
58
	$nentries = 50;
59

    
60
$now = time();
61
$year = date("Y");
62

    
63
$pgtitle = array(gettext("Status"),gettext("Load Balancer"),gettext("Pool"));
64
$shortcut_section = "relayd";
65
include("head.inc");
66

    
67
$relay_hosts = get_lb_summary();
68

    
69
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
?>
110
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
111
<?php include("fbegin.inc"); ?>
112
<form action="status_lb_pool.php" method="post">
113
<?php if (is_subsystem_dirty('loadbalancer')): ?><br/>
114
<?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
<?php endif; ?>
116
<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="status load balancer pools">
117
	<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
	<div id="mainarea">
129
		<table width="100%" border="0" cellpadding="0" cellspacing="0" class="tabcont sortable" id="sortabletable" summary="main area">
130
		<tr>
131
		<td width="10%" class="listhdrr"><?=gettext("Name");?></td>
132
		<td width="10%" class="listhdrr"><?=gettext("Mode");?></td>
133
		<td width="20%" class="listhdrr"><?=gettext("Servers");?></td>
134
		<td width="10%" class="listhdrr"><?=gettext("Monitor");?></td>
135
		<td width="30%" class="listhdr"><?=gettext("Description");?></td>
136
		</tr>
137
		<?php foreach ($a_pool as & $pool): ?>
138
		<tr>
139
		<td class="listlr">
140
			<?=$pool['name'];?>
141
		</td>
142
		<td class="listr" align="center" >
143
		<?php
144
		switch($pool['mode']) {
145
			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
		<td class="listr" align="center">
157
		<table border="0" cellpadding="2" cellspacing="0" summary="status">
158
		<?php
159
		$pool_hosts=array();
160
		foreach ((array) $pool['servers'] as $server) {
161
			$svr['ip']['addr']=$server;
162
			$svr['ip']['state']=$relay_hosts[$pool['name'].":".$pool['port']][$server]['state'];
163
			$svr['ip']['avail']=$relay_hosts[$pool['name'].":".$pool['port']][$server]['avail'];
164
			$pool_hosts[]=$svr;
165
		}
166
		foreach ((array) $pool['serversdisabled'] as $server) {
167
			$svr['ip']['addr']="$server";
168
			$svr['ip']['state']='disabled';
169
			$svr['ip']['avail']='disabled';
170
			$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
					case 'up':
178
						$bgcolor = "#90EE90";  // lightgreen
179
						$checked = "checked=\"checked\"";
180
						break;
181
					case 'disabled':
182
						$bgcolor = "white";
183
						$checked = "";
184
						break;
185
					default:
186
						$bgcolor = "#F08080";  // lightcoral
187
						$checked = "checked=\"checked\"";
188
				}
189
				echo "<tr>";
190
				switch ($pool['mode']) {
191
					case 'loadbalance':
192
						echo "<td><input type=\"checkbox\" name=\"{$pool['name']}|" . str_replace('.', '_', $server['ip']['addr']) . "\" {$checked} /></td>\n";
193
						break;
194
					case 'failover':
195
						echo "<td><input type=\"radio\" name=\"{$pool['name']}\" value=\"{$server['ip']['addr']}\" {$checked} /></td>\n";
196
						break;
197
				}
198
				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
				if($server['ip']['avail'])
201
				  echo " ({$server['ip']['avail']}) ";
202
				echo "&nbsp;</td></tr>";
203
			}
204
		}
205
		?>
206
		</table>
207
		</td>
208
		<td class="listr" >
209
			<?php echo $pool['monitor']; ?>
210
		</td>
211
		<td class="listbg" >
212
			<?=$pool['descr'];?>
213
		</td>
214
		</tr>
215
		<?php endforeach; ?>
216
		<tr>
217
			<td colspan="5">
218
			<input name="Submit" type="submit" class="formbtn" value="<?= gettext("Save"); ?>" />
219
			<input name="Reset"  type="reset"  class="formbtn" value="<?= gettext("Reset"); ?>" />
220
			</td>
221
		</tr>
222
		</table>
223
	</div>
224
</td></tr>
225
</table>
226
</form>
227
<?php include("fend.inc"); ?>
228
</body>
229
</html>
(193-193/256)