Project

General

Profile

Download (13.9 KB) Statistics
| Branch: | Tag: | Revision:

univnautes / usr / local / www / load_balancer_pool_edit.php @ a1b66bec

1
<?php
2
/* $Id$ */
3
/*
4
        load_balancer_pool_edit.php
5
        part of pfSense (https://www.pfsense.org/)
6

    
7
        Copyright (C) 2005-2008 Bill Marquette <bill.marquette@gmail.com>.
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-loadbalancer-pool-edit
37
##|*NAME=Load Balancer: Pool: Edit page
38
##|*DESCR=Allow access to the 'Load Balancer: Pool: Edit' page.
39
##|*MATCH=load_balancer_pool_edit.php*
40
##|-PRIV
41

    
42
require("guiconfig.inc");
43
require_once("filter.inc");
44
require_once("util.inc");
45

    
46
$referer = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/load_balancer_pool.php');
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
if (is_numericint($_GET['id']))
54
	$id = $_GET['id'];
55
if (isset($_POST['id']) && is_numericint($_POST['id']))
56
	$id = $_POST['id'];
57

    
58
if (isset($id) && $a_pool[$id]) {
59
	$pconfig['name'] = $a_pool[$id]['name'];
60
	$pconfig['mode'] = $a_pool[$id]['mode'];
61
	$pconfig['descr'] = $a_pool[$id]['descr'];
62
	$pconfig['port'] = $a_pool[$id]['port'];
63
	$pconfig['retry'] = $a_pool[$id]['retry'];
64
	$pconfig['servers'] = &$a_pool[$id]['servers'];
65
	$pconfig['serversdisabled'] = &$a_pool[$id]['serversdisabled'];
66
	$pconfig['monitor'] = $a_pool[$id]['monitor'];
67
}
68

    
69
$changedesc = gettext("Load Balancer: Pool:") . " ";
70
$changecount = 0;
71

    
72
if ($_POST) {
73
	$changecount++;
74

    
75
	unset($input_errors);
76
	$pconfig = $_POST;
77

    
78
	/* input validation */
79
	$reqdfields = explode(" ", "name mode port monitor servers");
80
	$reqdfieldsn = array(gettext("Name"),gettext("Mode"),gettext("Port"),gettext("Monitor"),gettext("Server List"));
81

    
82
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
83

    
84
	/* Ensure that our pool names are unique */
85
	for ($i=0; isset($config['load_balancer']['lbpool'][$i]); $i++)
86
		if (($_POST['name'] == $config['load_balancer']['lbpool'][$i]['name']) && ($i != $id))
87
			$input_errors[] = gettext("This pool name has already been used.  Pool names must be unique.");
88

    
89
	if (strpos($_POST['name'], " ") !== false)
90
		$input_errors[] = gettext("You cannot use spaces in the 'name' field.");
91

    
92
	if (in_array($_POST['name'], $reserved_table_names))
93
		$input_errors[] = sprintf(gettext("The name '%s' is a reserved word and cannot be used."), $_POST['name']);
94

    
95
	if (is_alias($_POST['name']))
96
		$input_errors[] = sprintf(gettext("Sorry, an alias is already named %s."), $_POST['name']);
97

    
98
	if (!is_portoralias($_POST['port']))
99
		$input_errors[] = gettext("The port must be an integer between 1 and 65535, or a port alias.");
100

    
101
	// May as well use is_port as we want a positive integer and such.
102
	if (!empty($_POST['retry']) && !is_port($_POST['retry']))
103
		$input_errors[] = gettext("The retry value must be an integer between 1 and 65535.");
104

    
105
	if (is_array($_POST['servers'])) {
106
		foreach($pconfig['servers'] as $svrent) {
107
			if (!is_ipaddr($svrent) && !is_subnetv4($svrent)) {
108
				$input_errors[] = sprintf(gettext("%s is not a valid IP address or IPv4 subnet (in \"enabled\" list)."), $svrent);
109
			}
110
			else if (is_subnetv4($svrent) && subnet_size($svrent) > 64) {
111
				$input_errors[] = sprintf(gettext("%s is a subnet containing more than 64 IP addresses (in \"enabled\" list)."), $svrent);
112
			}
113
		}
114
	}
115
	if (is_array($_POST['serversdisabled'])) {
116
		foreach($pconfig['serversdisabled'] as $svrent) {
117
			if (!is_ipaddr($svrent) && !is_subnetv4($svrent)) {
118
				$input_errors[] = sprintf(gettext("%s is not a valid IP address or IPv4 subnet (in \"disabled\" list)."), $svrent);
119
			}
120
			else if (is_subnetv4($svrent) && subnet_size($svrent) > 64) {
121
				$input_errors[] = sprintf(gettext("%s is a subnet containing more than 64 IP addresses (in \"disabled\" list)."), $svrent);
122
			}
123
		}
124
	}
125
	$m = array();
126
	for ($i=0; isset($config['load_balancer']['monitor_type'][$i]); $i++)
127
		$m[$config['load_balancer']['monitor_type'][$i]['name']] = $config['load_balancer']['monitor_type'][$i];
128

    
129
	if (!isset($m[$_POST['monitor']]))
130
		$input_errors[] = gettext("Invalid monitor chosen.");
131

    
132
	if (!$input_errors) {
133
		$poolent = array();
134
		if(isset($id) && $a_pool[$id])
135
			$poolent = $a_pool[$id];
136
		if($poolent['name'] != "")
137
			$changedesc .= sprintf(gettext(" modified '%s' pool:"), $poolent['name']);
138
		
139
		update_if_changed("name", $poolent['name'], $_POST['name']);
140
		update_if_changed("mode", $poolent['mode'], $_POST['mode']);
141
		update_if_changed("description", $poolent['descr'], $_POST['descr']);
142
		update_if_changed("port", $poolent['port'], $_POST['port']);
143
		update_if_changed("retry", $poolent['retry'], $_POST['retry']);
144
		update_if_changed("servers", $poolent['servers'], $_POST['servers']);
145
		update_if_changed("serversdisabled", $poolent['serversdisabled'], $_POST['serversdisabled']);
146
		update_if_changed("monitor", $poolent['monitor'], $_POST['monitor']);
147

    
148
		if (isset($id) && $a_pool[$id]) {
149
			/* modify all virtual servers with this name */
150
			for ($i = 0; isset($config['load_balancer']['virtual_server'][$i]); $i++) {
151
				if ($config['load_balancer']['virtual_server'][$i]['lbpool'] == $a_pool[$id]['name'])
152
					$config['load_balancer']['virtual_server'][$i]['lbpool'] = $poolent['name'];
153
			}
154
			$a_pool[$id] = $poolent;
155
		} else
156
			$a_pool[] = $poolent;
157
		
158
		if ($changecount > 0) {
159
			/* Mark pool dirty */
160
			mark_subsystem_dirty('loadbalancer');
161
			write_config($changedesc);
162
		}
163

    
164
		header("Location: load_balancer_pool.php");
165
		exit;
166
	}
167
}
168

    
169
$pgtitle = array(gettext("Services"), gettext("Load Balancer"),gettext("Pool"),gettext("Edit"));
170
$shortcut_section = "relayd";
171

    
172
include("head.inc");
173

    
174
?>
175

    
176
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
177
<?php include("fbegin.inc"); ?>
178
<script type="text/javascript">
179
//<![CDATA[
180
function clearcombo(){
181
  for (var i=document.iform.serversSelect.options.length-1; i>=0; i--){
182
    document.iform.serversSelect.options[i] = null;
183
  }
184
  document.iform.serversSelect.selectedIndex = -1;
185
}
186
//]]>
187
</script>
188

    
189
<script type="text/javascript" src="/javascript/autosuggest.js"></script>
190
<script type="text/javascript" src="/javascript/suggestions.js"></script>
191

    
192
<?php if ($input_errors) print_input_errors($input_errors); ?>
193

    
194
	<form action="load_balancer_pool_edit.php" method="post" name="iform" id="iform">
195
	<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="load balancer pool entry">
196
		<tr>
197
			<td colspan="2" valign="top" class="listtopic"><?=gettext("Add/edit Load Balancer - Pool entry"); ?></td>
198
		</tr>
199
		<tr align="left">
200
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Name"); ?></td>
201
			<td width="78%" class="vtable" colspan="2">
202
				<input name="name" type="text" <?if(isset($pconfig['name'])) echo "value=\"{$pconfig['name']}\"";?> size="16" maxlength="16" />
203
			</td>
204
		</tr>
205
		<tr align="left">
206
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Mode"); ?></td>
207
			<td width="78%" class="vtable" colspan="2">
208
				<select id="mode" name="mode" onchange="enforceFailover(); checkPoolControls();">
209
					<option value="loadbalance" <?if(!isset($pconfig['mode']) || ($pconfig['mode'] == "loadbalance")) echo "selected=\"selected\"";?>><?=gettext("Load Balance");?></option>
210
					<option value="failover"  <?if($pconfig['mode'] == "failover") echo "selected=\"selected\"";?>><?=gettext("Manual Failover");?></option>
211
				</select>
212
			</td>
213
		</tr>
214
		<tr align="left">
215
			<td width="22%" valign="top" class="vncell"><?=gettext("Description"); ?></td>
216
			<td width="78%" class="vtable" colspan="2">
217
				<input name="descr" type="text" <?if(isset($pconfig['descr'])) echo "value=\"{$pconfig['descr']}\"";?> size="64" />
218
			</td>
219
		</tr>
220

    
221
		<tr align="left">
222
			<td width="22%" valign="top" id="monitorport_text" class="vncellreq"><?=gettext("Port"); ?></td>
223
			<td width="78%" class="vtable" colspan="2">
224
				<input class="formfldalias" id="port" name="port" type="text" <?if(isset($pconfig['port'])) echo "value=\"{$pconfig['port']}\"";?> size="16" maxlength="16" /><br />
225
				<div id="monitorport_desc">
226
					<?=gettext("This is the port your servers are listening on."); ?><br />
227
					<?=gettext("You may also specify a port alias listed in Firewall -&gt; Aliases here."); ?>
228
				</div>
229
				<script type="text/javascript">
230
				//<![CDATA[
231
					var addressarray = <?= json_encode(get_alias_list(array("port", "url_ports", "urltable_ports"))) ?>;
232
					var oTextbox1 = new AutoSuggestControl(document.getElementById("port"), new StateSuggestions(addressarray));
233
				//]]>
234
				</script>
235
			</td>
236
		</tr>
237
		<tr align="left">
238
			<td width="22%" valign="top" id="retry_text" class="vncell"><?=gettext("Retry"); ?></td>
239
			<td width="78%" class="vtable" colspan="2">
240
				<input name="retry" type="text" <?if(isset($pconfig['retry'])) echo "value=\"{$pconfig['retry']}\"";?> size="16" maxlength="16" /><br />
241
				<div id="retry_desc"><?=gettext("Optionally specify how many times to retry checking a server before declaring it down."); ?></div>
242
			</td>
243
		</tr>
244
		<tr>
245
			<td>&nbsp;</td>
246
		</tr>
247
		<tr>
248
			<td colspan="2" valign="top" class="listtopic"><?=gettext("Add item to pool"); ?></td>
249
		</tr>
250
		<tr align="left">
251
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Monitor"); ?></td>
252
			<td width="78%" class="vtable" colspan="2">
253
				<?php if(count($config['load_balancer']['monitor_type'])): ?>
254
				<select id="monitor" name="monitor">
255
					<?php
256
						foreach ($config['load_balancer']['monitor_type'] as $monitor) {
257
							if ($monitor['name'] == $pconfig['monitor']) {
258
								$selected=" selected=\"selected\"";
259
							} else {
260
								$selected = "";
261
							}
262
							echo "<option value=\"{$monitor['name']}\"{$selected}>{$monitor['name']}</option>";
263
						}
264
					?>
265
				<?php else: ?>
266
					<b><?=gettext("NOTE"); ?>:</b> <?=gettext("Please add a monitor IP address on the monitors tab if you wish to use this feature."); ?>
267
				<?php endif; ?>
268
				</select>
269
			</td>
270
		</tr>
271
		<tr align="left">
272
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Server IP Address"); ?></td>
273
			<td width="78%" class="vtable" colspan="2">
274
				<input name="ipaddr" type="text" size="16" style="float: left;" /> 
275
				<input class="formbtn" type="button" name="button1" value="<?=gettext("Add to pool"); ?>" onclick="AddServerToPool(document.iform); enforceFailover(); checkPoolControls();" /><br />
276
			</td>
277
		</tr>
278
		<tr>
279
			<td>&nbsp;</td>
280
		</tr>
281
		<tr>
282
			<td colspan="2" valign="top" class="listtopic"><?=gettext("Current Pool Members"); ?></td>
283
		</tr>
284
		<tr>
285
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Members"); ?></td>
286
			<td width="78%" class="vtable" colspan="2" valign="top">
287
				<table summary="members">
288
					<tbody>
289
					<tr>
290
						<td align="center">
291
								<b><?=gettext("Pool Disabled"); ?></b>
292
							<br/>
293
							<select id="serversDisabledSelect" name="serversdisabled[]" multiple="multiple" size="5">
294
<?php
295
	if (is_array($pconfig['serversdisabled'])) {
296
		foreach($pconfig['serversdisabled'] as $svrent) {
297
			if($svrent != '') echo "    <option value=\"{$svrent}\">{$svrent}</option>\n";
298
		}
299
	}
300
?>
301
							</select>
302
							<input class="formbtn" type="button" name="removeDisabled" value="<?=gettext("Remove"); ?>" onclick="RemoveServerFromPool(document.iform, 'serversdisabled[]');" />
303
						</td>
304

    
305
						<td valign="middle">
306
							<input class="formbtn" type="button" id="moveToEnabled" name="moveToEnabled" value=">" onclick="moveOptions(document.iform.serversDisabledSelect, document.iform.serversSelect); checkPoolControls();" /><br />
307
							<input class="formbtn" type="button" id="moveToDisabled" name="moveToDisabled" value="<" onclick="moveOptions(document.iform.serversSelect, document.iform.serversDisabledSelect); checkPoolControls();" />
308
						</td>
309

    
310
						<td align="center">
311
								<b><?=gettext("Enabled (default)"); ?></b>
312
							<br/>
313
							<select id="serversSelect" name="servers[]" multiple="multiple" size="5">
314
<?php
315
if (is_array($pconfig['servers'])) {
316
	foreach($pconfig['servers'] as $svrent) {
317
		echo "    <option value=\"{$svrent}\">{$svrent}</option>\n";
318
	}
319
}
320
?>
321
							</select>
322
							<input class="formbtn" type="button" name="removeEnabled" value="<?=gettext("Remove"); ?>" onclick="RemoveServerFromPool(document.iform, 'servers[]');" />
323
						</td>
324
					</tr>
325
					</tbody>
326
				</table>
327
			</td>
328
		</tr>
329
		<tr align="left">
330
			<td width="22%" valign="top">&nbsp;</td>
331
			<td width="78%">
332
				<br />
333
				<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save"); ?>" onclick="AllServers('serversSelect', true); AllServers('serversDisabledSelect', true);" /> 
334
				<input type="button" class="formbtn" value="<?=gettext("Cancel");?>" onclick="window.location.href='<?=$referer;?>'" />
335
				<?php if (isset($id) && $a_pool[$id] && $_GET['act'] != 'dup'): ?>
336
				<input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" />
337
				<?php endif; ?>
338
			</td>
339
		</tr>
340
	</table>
341
	</form>
342
<br />
343
<?php include("fend.inc"); ?>
344
</body>
345
</html>
(119-119/256)