Project

General

Profile

Download (7.4 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	status_lb_pool.php
5
	part of pfSense (http://www.pfsense.com/)
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

    
47
if (!is_array($config['load_balancer']['lbpool'])) {
48
	$config['load_balancer']['lbpool'] = array();
49
}
50
$a_pool = &$config['load_balancer']['lbpool'];
51

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

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

    
58
$now = time();
59
$year = date("Y");
60

    
61
$pgtitle = array(gettext("Status"),gettext("Load Balancer"),gettext("Pool"));
62
include("head.inc");
63

    
64
$relayctl=split("\n", shell_exec("/usr/local/sbin/relayctl show summary"));
65
$relay_hosts=Array();
66
foreach( (array) $relayctl as $line) {
67
	$t=split("\t", $line);
68
	switch (trim($t[1])) {
69
		case "table":
70
			$curpool=trim($t[2]);
71
		break;
72
		case "host":
73
			$curhost=trim($t[2]);
74
			$relay_hosts[$curpool][$curhost]['avail']=trim($t[3]);
75
			$relay_hosts[$curpool][$curhost]['state']=trim($t[4]);
76
		break;
77
	}
78
}
79

    
80
if ($_POST) {
81
	if ($_POST['apply']) {
82
		$retval = 0;
83
		$retval |= filter_configure();
84
		$retval |= relayd_configure();
85
		$savemsg = get_std_save_message($retval);
86
		clear_subsystem_dirty('loadbalancer');
87
	} else {
88
		/* Keep a list of servers we find in POST variables */
89
		$newservers = array();
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
		foreach ($a_pool as & $pool) {
101
			if (is_array($pool['servers']) && is_array($pool['serversdisabled'])) {
102
				$oldservers = array_merge($pool['servers'], $pool['serversdisabled']);
103
			} elseif (is_array($pool['servers'])) {
104
				$oldservers = $pool['servers'];
105
			} elseif (is_array($pool['serversdisabled'])) {
106
				$oldservers = $pool['serversdisabled'];
107
			} else {
108
				$oldservers = array();
109
			}
110
			if (is_array($newservers[$pool['name']])) {
111
				$pool['servers'] = $newservers[$pool['name']];
112
				$pool['serversdisabled'] = array_diff($oldservers, $newservers[$pool['name']]);
113
			}
114
		}
115
		mark_subsystem_dirty('loadbalancer');
116
		write_config("Updated load balancer pools via status screen.");
117
	}
118
}
119

    
120
?>
121
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
122
<script src="/javascript/sorttable.js"></script>
123
<?php include("fbegin.inc"); ?>
124
<form action="status_lb_pool.php" method="POST">
125
<?php if (is_subsystem_dirty('loadbalancer')): ?><p>
126
<?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>
127
<?php endif; ?>
128
<table width="100%" border="0" cellpadding="0" cellspacing="0">
129
	<tr><td class="tabnavtbl">
130
	<?php
131
	/* active tabs */
132
	$tab_array = array();
133
	$tab_array[] = array(gettext("Pools"), true, "status_lb_pool.php");
134
	$tab_array[] = array(gettext("Virtual Servers"), false, "status_lb_vs.php");
135
	display_top_tabs($tab_array);
136
	?>
137
	</td></tr>
138
	<tr>
139
	<td>
140
	<div id="mainarea">
141
		<table width="100%" border="0" cellpadding="0" cellspacing="0" class="tabcont sortable" name="sortabletable" id="sortabletable">
142
		<tr>
143
		<td width="10%" class="listhdrr"><?=gettext("Name");?></td>
144
		<td width="10%" class="listhdrr"><?=gettext("Mode");?></td>
145
		<td width="20%" class="listhdrr"><?=gettext("Servers");?></td>
146
		<td width="10%" class="listhdrr"><?=gettext("Monitor");?></td>
147
		<td width="30%" class="listhdr"><?=gettext("Description");?></td>
148
		</tr>
149
		<?php foreach ($a_pool as & $pool): ?>
150
		<tr>
151
		<td class="listlr">
152
			<?=$pool['name'];?>
153
		</td>
154
		<td class="listr" align="center" >
155
		<?php
156
		switch($pool['mode']) {
157
			case "loadbalance":
158
				echo "Load balancing";
159
				break;
160
			case "failover":
161
				echo "Manual failover";
162
				break;
163
			default:
164
				echo "(default)";
165
		}
166
		?>
167
		</td>
168
		<td class="listr" align="center">
169
		<table border="0" cellpadding="2" cellspacing="0">
170
		<?php
171
		$pool_hosts=array();
172
		foreach ((array) $pool['servers'] as $server) {
173
			$svr['ip']['addr']=$server;
174
			$svr['ip']['state']=$relay_hosts[$pool['name'].":".$pool['port']][$server]['state'];
175
			$svr['ip']['avail']=$relay_hosts[$pool['name'].":".$pool['port']][$server]['avail'];
176
			$pool_hosts[]=$svr;
177
		}
178
		foreach ((array) $pool['serversdisabled'] as $server) {
179
			$svr['ip']['addr']="$server";
180
			$svr['ip']['state']='disabled';
181
			$svr['ip']['avail']='disabled';
182
			$pool_hosts[]=$svr;
183
		}
184
		asort($pool_hosts);
185

    
186
		foreach ((array) $pool_hosts as $server) {
187
			if($server['ip']['addr']!="") {
188
				switch ($server['ip']['state']) {
189
					case 'up':
190
						$bgcolor = "lightgreen";
191
						$checked = "checked";
192
						break;
193
					case 'disabled':
194
						$bgcolor = "white";
195
						$checked = "";
196
						break;
197
					default:
198
						$bgcolor = "lightcoral";
199
						$checked = "checked";
200
				}
201
				echo "<tr>";
202
				switch ($pool['mode']) {
203
					case 'loadbalance':
204
						echo "<td><input type='checkbox' name='{$pool['name']}|".str_replace('.', '_', $server['ip']['addr'])."' {$checked}></td>\n";
205
						break;
206
					case 'failover':
207
						echo "<td><input type='radio' name='{$pool['name']}' value='{$server['ip']['addr']}' {$checked}></td>\n";
208
						break;
209
				}
210
				echo "<td bgcolor={$bgcolor}> {$server['ip']['addr']}:{$pool['port']} </td><td bgcolor={$bgcolor}>";
211
#				echo "<td bgcolor={$bgcolor}> {$server['ip']['addr']}:{$pool['port']} ";
212
				if($server['ip']['avail'])
213
				  echo " ({$server['ip']['avail']}) ";
214
				echo "</td></tr>";
215
			}
216
		}
217
		?>
218
		</table>
219
		</td>
220
		<td class="listr" >
221
			<?php echo $pool['monitor']; ?>
222
		</td>
223
		<td class="listbg" >
224
			<?=$pool['descr'];?>
225
		</td>
226
		</tr>
227
		<?php endforeach; ?>
228
		<tr>
229
			<td colspan="5">
230
			<input name="Submit" type="submit" class="formbtn" value="<?= gettext("Save"); ?>">
231
			<input name="Reset"  type="reset"  class="formbtn" value="<?= gettext("Reset"); ?>">
232
			</td>
233
		</tr>
234
		</table>
235
	</div>
236
	</table>
237
</form>
238
<?php include("fend.inc"); ?>
239
</body>
240
</html>
(163-163/222)