Projet

Général

Profil

Télécharger (13,8 ko) Statistiques
| Branche: | Tag: | Révision:

univnautes / usr / local / www / load_balancer_pool_edit.php @ 226a09d4

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
if (!is_array($config['load_balancer']['lbpool'])) {
47
	$config['load_balancer']['lbpool'] = array();
48
}
49
$a_pool = &$config['load_balancer']['lbpool'];
50

    
51
if (is_numericint($_GET['id']))
52
	$id = $_GET['id'];
53
if (isset($_POST['id']) && is_numericint($_POST['id']))
54
	$id = $_POST['id'];
55

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

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

    
70
if ($_POST) {
71
	$changecount++;
72

    
73
	unset($input_errors);
74
	$pconfig = $_POST;
75

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

    
80
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
81

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

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

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

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

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

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

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

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

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

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

    
162
		header("Location: load_balancer_pool.php");
163
		exit;
164
	}
165
}
166

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

    
170
include("head.inc");
171

    
172
?>
173

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

    
187
<script type="text/javascript" src="/javascript/autosuggest.js"></script>
188
<script type="text/javascript" src="/javascript/suggestions.js"></script>
189

    
190
<?php if ($input_errors) print_input_errors($input_errors); ?>
191

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

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

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

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