Project

General

Profile

Download (7.4 KB) Statistics
| Branch: | Tag: | Revision:
1 6b6a76f9 Scott Ullrich
<?php
2
/* $Id$ */
3
/*
4 477dcf13 Chris Buechler
	status_lb_pool.php
5 6b6a76f9 Scott Ullrich
	part of pfSense (http://www.pfsense.com/)
6
7 6216690b smos
	Copyright (C) 2010 Seth Mos <seth.mos@dds.nl>.
8 6b6a76f9 Scott Ullrich
	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 beca7814 jim-p
/*
32 1d333258 Scott Ullrich
	pfSense_MODULE:	routing
33
*/
34 6b6a76f9 Scott Ullrich
35 6b07c15a Matthew Grooms
##|+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 477dcf13 Chris Buechler
##|*MATCH=status_lb_pool.php*
40 6b07c15a Matthew Grooms
##|-PRIV
41
42 0c450e71 jim-p
require_once("guiconfig.inc");
43
require_once("functions.inc");
44
require_once("filter.inc");
45
require_once("shaper.inc");
46 6b6a76f9 Scott Ullrich
47
if (!is_array($config['load_balancer']['lbpool'])) {
48
	$config['load_balancer']['lbpool'] = array();
49
}
50
$a_pool = &$config['load_balancer']['lbpool'];
51
52 087a89f8 Chris Buechler
$lb_logfile = "{$g['varlog_path']}/relayd.log";
53 6b6a76f9 Scott Ullrich
54
$nentries = $config['syslog']['nentries'];
55
if (!$nentries)
56 beca7814 jim-p
	$nentries = 50;
57 6b6a76f9 Scott Ullrich
58
$now = time();
59
$year = date("Y");
60
61 bbaba7e6 Rafael Lucas
$pgtitle = array(gettext("Status"),gettext("Load Balancer"),gettext("Pool"));
62 6b6a76f9 Scott Ullrich
include("head.inc");
63
64 8c29490e Chris Buechler
$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 beca7814 jim-p
		case "table":
70
			$curpool=trim($t[2]);
71
		break;
72
		case "host":
73
			$curhost=trim($t[2]);
74 e6a8a626 Eirik Oeverby
			$relay_hosts[$curpool][$curhost]['avail']=trim($t[3]);
75 beca7814 jim-p
			$relay_hosts[$curpool][$curhost]['state']=trim($t[4]);
76
		break;
77 8c29490e Chris Buechler
	}
78
}
79
80 0c450e71 jim-p
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 6b6a76f9 Scott Ullrich
?>
121
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
122 ff9d6728 Scott Ullrich
<script src="/javascript/sorttable.js"></script>
123 6b6a76f9 Scott Ullrich
<?php include("fbegin.inc"); ?>
124 faf207f1 jim-p
<form action="status_lb_pool.php" method="POST">
125 0c450e71 jim-p
<?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 6b6a76f9 Scott Ullrich
<table width="100%" border="0" cellpadding="0" cellspacing="0">
129 beca7814 jim-p
	<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 6b6a76f9 Scott Ullrich
	<div id="mainarea">
141 beca7814 jim-p
		<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 e6a8a626 Eirik Oeverby
		<td width="20%" class="listhdrr"><?=gettext("Servers");?></td>
146 beca7814 jim-p
		<td width="10%" class="listhdrr"><?=gettext("Monitor");?></td>
147
		<td width="30%" class="listhdr"><?=gettext("Description");?></td>
148
		</tr>
149 0c450e71 jim-p
		<?php foreach ($a_pool as & $pool): ?>
150 beca7814 jim-p
		<tr>
151
		<td class="listlr">
152 191b00d9 jim-p
			<?=$pool['name'];?>
153 beca7814 jim-p
		</td>
154
		<td class="listr" align="center" >
155
		<?php
156 191b00d9 jim-p
		switch($pool['mode']) {
157 beca7814 jim-p
			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 e6a8a626 Eirik Oeverby
		<td class="listr" align="center">
169
		<table border="0" cellpadding="2" cellspacing="0">
170 beca7814 jim-p
		<?php
171 e34f19ec Eirik Oeverby
		$pool_hosts=array();
172 191b00d9 jim-p
		foreach ((array) $pool['servers'] as $server) {
173 e34f19ec Eirik Oeverby
			$svr['ip']['addr']=$server;
174 94933d56 Eirik Oeverby
			$svr['ip']['state']=$relay_hosts[$pool['name'].":".$pool['port']][$server]['state'];
175 e6a8a626 Eirik Oeverby
			$svr['ip']['avail']=$relay_hosts[$pool['name'].":".$pool['port']][$server]['avail'];
176 e34f19ec Eirik Oeverby
			$pool_hosts[]=$svr;
177
		}
178
		foreach ((array) $pool['serversdisabled'] as $server) {
179
			$svr['ip']['addr']="$server";
180
			$svr['ip']['state']='disabled';
181 e6a8a626 Eirik Oeverby
			$svr['ip']['avail']='disabled';
182 e34f19ec Eirik Oeverby
			$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 beca7814 jim-p
					case 'up':
190
						$bgcolor = "lightgreen";
191 e34f19ec Eirik Oeverby
						$checked = "checked";
192
						break;
193
					case 'disabled':
194
						$bgcolor = "white";
195
						$checked = "";
196 beca7814 jim-p
						break;
197
					default:
198
						$bgcolor = "lightcoral";
199 e34f19ec Eirik Oeverby
						$checked = "checked";
200 beca7814 jim-p
				}
201 3b370abf jim-p
				echo "<tr>";
202 191b00d9 jim-p
				switch ($pool['mode']) {
203 beca7814 jim-p
					case 'loadbalance':
204 e34f19ec Eirik Oeverby
						echo "<td><input type='checkbox' name='{$pool['name']}|".str_replace('.', '_', $server['ip']['addr'])."' {$checked}></td>\n";
205 cdad3139 Eirik Oeverby
						break;
206 beca7814 jim-p
					case 'failover':
207 e34f19ec Eirik Oeverby
						echo "<td><input type='radio' name='{$pool['name']}' value='{$server['ip']['addr']}' {$checked}></td>\n";
208 cdad3139 Eirik Oeverby
						break;
209 8c29490e Chris Buechler
				}
210 e6a8a626 Eirik Oeverby
				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 beca7814 jim-p
			}
216
		}
217
		?>
218
		</table>
219
		</td>
220
		<td class="listr" >
221 191b00d9 jim-p
			<?php echo $pool['monitor']; ?>
222 beca7814 jim-p
		</td>
223
		<td class="listbg" >
224 e988813d jim-p
			<?=$pool['descr'];?>
225 beca7814 jim-p
		</td>
226
		</tr>
227 0c450e71 jim-p
		<?php endforeach; ?>
228 faf207f1 jim-p
		<tr>
229
			<td colspan="5">
230
			<input name="Submit" type="submit" class="formbtn" value="<?= gettext("Save"); ?>">
231 beca7814 jim-p
			<input name="Reset"  type="reset"  class="formbtn" value="<?= gettext("Reset"); ?>">
232 faf207f1 jim-p
			</td>
233
		</tr>
234 beca7814 jim-p
		</table>
235
	</div>
236 6b6a76f9 Scott Ullrich
	</table>
237 faf207f1 jim-p
</form>
238 6b6a76f9 Scott Ullrich
<?php include("fend.inc"); ?>
239
</body>
240
</html>