Projet

Général

Profil

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

univnautes / usr / local / www / load_balancer_virtual_server_edit.php @ fab1cd2f

1
<?php
2
/* $Id$ */
3
/*
4
        load_balancer_virtual_server_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-virtualserver-edit
37
##|*NAME=Load Balancer: Virtual Server: Edit page
38
##|*DESCR=Allow access to the 'Load Balancer: Virtual Server: Edit' page.
39
##|*MATCH=load_balancer_virtual_server_edit.php*
40
##|-PRIV
41

    
42
require("guiconfig.inc");
43

    
44
if (!is_array($config['load_balancer']['virtual_server'])) {
45
        $config['load_balancer']['virtual_server'] = array();
46
}
47
$a_vs = &$config['load_balancer']['virtual_server'];
48

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

    
54
if (isset($id) && $a_vs[$id]) {
55
  $pconfig = $a_vs[$id];
56
} else {
57
  // Sane defaults
58
  $pconfig['mode'] = 'redirect';
59
}
60

    
61
$changedesc = gettext("Load Balancer: Virtual Server:") . " ";
62
$changecount = 0;
63

    
64
if ($_POST) {
65
	unset($input_errors);
66
	$pconfig = $_POST;
67

    
68
	/* input validation */
69
  switch($pconfig['mode']) {
70
    case "redirect": {
71
    	$reqdfields = explode(" ", "ipaddr name mode");
72
    	$reqdfieldsn = array(gettext("IP Address"),gettext("Name"),gettext("Mode"));
73
    	break;
74
    }
75
    case "relay": {
76
    	$reqdfields = explode(" ", "ipaddr name mode relay_protocol");
77
    	$reqdfieldsn = array(gettext("IP Address"),gettext("Name"),gettext("Relay Protocol"));
78
      break;
79
    }
80
  }
81

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

    
84
	for ($i=0; isset($config['load_balancer']['virtual_server'][$i]); $i++)
85
		if (($_POST['name'] == $config['load_balancer']['virtual_server'][$i]['name']) && ($i != $id))
86
			$input_errors[] = gettext("This virtual server name has already been used.  Virtual server names must be unique.");
87

    
88
	if (preg_match('/[ \/]/', $_POST['name']))
89
		$input_errors[] = gettext("You cannot use spaces or slashes in the 'name' field.");
90

    
91
	if ($_POST['port'] != "" && !is_portoralias($_POST['port']))
92
		$input_errors[] = gettext("The port must be an integer between 1 and 65535, a port alias, or left blank.");
93

    
94
	if (!is_ipaddroralias($_POST['ipaddr']) && !is_subnetv4($_POST['ipaddr']))
95
		$input_errors[] = sprintf(gettext("%s is not a valid IP address, IPv4 subnet, or alias."), $_POST['ipaddr']);
96
	else if (is_subnetv4($_POST['ipaddr']) && subnet_size($_POST['ipaddr']) > 64)
97
		$input_errors[] = sprintf(gettext("%s is a subnet containing more than 64 IP addresses."), $_POST['ipaddr']);
98

    
99
	if ((strtolower($_POST['relay_protocol']) == "dns") && !empty($_POST['sitedown']))
100
		$input_errors[] = gettext("You cannot select a Fall Back Pool when using the DNS relay protocol.");
101

    
102
	if (!$input_errors) {
103
		$vsent = array();
104
		if(isset($id) && $a_vs[$id])
105
			$vsent = $a_vs[$id];
106
		if($vsent['name'] != "")
107
			$changedesc .= " " . sprintf(gettext("modified '%s' vs:"), $vsent['name']);
108
		else
109
			$changedesc .= " " . sprintf(gettext("created '%s' vs:"), $_POST['name']);
110

    
111
		update_if_changed("name", $vsent['name'], $_POST['name']);
112
		update_if_changed("descr", $vsent['descr'], $_POST['descr']);
113
		update_if_changed("poolname", $vsent['poolname'], $_POST['poolname']);
114
		update_if_changed("port", $vsent['port'], $_POST['port']);
115
		update_if_changed("sitedown", $vsent['sitedown'], $_POST['sitedown']);
116
		update_if_changed("ipaddr", $vsent['ipaddr'], $_POST['ipaddr']);
117
		update_if_changed("mode", $vsent['mode'], $_POST['mode']);
118
		update_if_changed("relay protocol", $vsent['relay_protocol'], $_POST['relay_protocol']);
119

    
120
		if($_POST['sitedown'] == "")
121
			unset($vsent['sitedown']);
122

    
123
		if (isset($id) && $a_vs[$id]) {
124
			if ($a_vs[$id]['name'] != $_POST['name']) {
125
				/* Because the VS name changed, mark the old name for cleanup. */
126
				cleanup_lb_mark_anchor($a_vs[$id]['name']);
127
			}
128
			$a_vs[$id] = $vsent;
129
		} else
130
			$a_vs[] = $vsent;
131

    
132
		if ($changecount > 0) {
133
			/* Mark virtual server dirty */
134
			mark_subsystem_dirty('loadbalancer');
135
			write_config($changedesc);
136
		}
137

    
138
		header("Location: load_balancer_virtual_server.php");
139
		exit;
140
	}
141
}
142

    
143
$pgtitle = array(gettext("Services"),gettext("Load Balancer"),gettext("Virtual Server"),gettext("Edit"));
144
$shortcut_section = "relayd-virtualservers";
145

    
146
include("head.inc");
147

    
148
?>
149

    
150
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
151
<?php include("fbegin.inc"); ?>
152
<script type="text/javascript" src="/javascript/autosuggest.js"></script>
153
<script type="text/javascript" src="/javascript/suggestions.js"></script>
154

    
155
<?php if ($input_errors) print_input_errors($input_errors); ?>
156
            <form action="load_balancer_virtual_server_edit.php" method="post" name="iform" id="iform">
157
              <table width="100%" border="0" cellpadding="6" cellspacing="0" summary="load balancer server entry">
158
				<tr>
159
					<td colspan="3" valign="top" class="listtopic"><?=gettext("Edit Load Balancer - Virtual Server entry"); ?></td>
160
				</tr>
161
                <tr align="left">
162
		  			<td width="22%" valign="top" class="vncellreq"><?=gettext("Name"); ?></td>
163
                  <td width="78%" class="vtable" colspan="2">
164
                    <input name="name" type="text" <?if(isset($pconfig['name'])) echo "value=\"" . htmlspecialchars($pconfig['name']) . "\"";?> size="32" maxlength="32" />
165
                  </td>
166
			</tr>
167
                <tr align="left">
168
		  			<td width="22%" valign="top" class="vncell"><?=gettext("Description"); ?></td>
169
                  <td width="78%" class="vtable" colspan="2">
170
                    <input name="descr" type="text" <?if(isset($pconfig['descr'])) echo "value=\"" . htmlspecialchars($pconfig['descr']) . "\"";?> size="64" />
171
                  </td>
172
			</tr>
173
                <tr align="left">
174
		  			<td width="22%" valign="top" class="vncellreq"><?=gettext("IP Address"); ?></td>
175
                  <td width="78%" class="vtable" colspan="2">
176
                    <input class="formfldalias" id="ipaddr" name="ipaddr" type="text" <?if(isset($pconfig['ipaddr'])) echo "value=\"" . htmlspecialchars($pconfig['ipaddr']) . "\"";?> size="39" maxlength="39" />
177
					<br /><?=gettext("This is normally the WAN IP address that you would like the server to listen on.  All connections to this IP and port will be forwarded to the pool cluster."); ?>
178
					<br /><?=gettext("You may also specify a host alias listed in Firewall -&gt; Aliases here."); ?>
179
					<script type="text/javascript">
180
					//<![CDATA[
181
						var host_aliases = <?= json_encode(get_alias_list(array("host", "network", "url", "urltable"))) ?>;
182
						var oTextbox1 = new AutoSuggestControl(document.getElementById("ipaddr"), new StateSuggestions(host_aliases));
183
					//]]>
184
					</script>
185
                  </td>
186
			</tr>
187
                <tr align="left">
188
		  			<td width="22%" valign="top" class="vncell"><?=gettext("Port"); ?></td>
189
                  <td width="78%" class="vtable" colspan="2">
190
                    <input class="formfldalias" name="port" id="port" type="text" <?if(isset($pconfig['port'])) echo "value=\"" . htmlspecialchars($pconfig['port']) . "\"";?> size="16" maxlength="16" />
191
					<br /><?=gettext("This is the port that the clients will connect to.  All connections to this port will be forwarded to the pool cluster."); ?>
192
					<br /><?=gettext("If left blank, listening ports from the pool will be used."); ?>
193
					<br /><?=gettext("You may also specify a port alias listed in Firewall -&gt; Aliases here."); ?>
194
					<script type="text/javascript">
195
					//<![CDATA[
196
						var port_aliases = <?= json_encode(get_alias_list(array("port", "url_ports", "urltable_ports"))) ?>;
197
						var oTextbox2 = new AutoSuggestControl(document.getElementById("port"), new StateSuggestions(port_aliases));
198
					//]]>
199
					</script>
200
                  </td>
201
			</tr>
202
                <tr align="left">
203
		  			<td width="22%" valign="top" class="vncellreq"><?=gettext("Virtual Server Pool"); ?></td>
204
					<td width="78%" class="vtable" colspan="2">
205
			<?php if(count($config['load_balancer']['lbpool']) == 0): ?>
206
				<b><?=gettext("NOTE:"); ?></b> <?=gettext("Please add a pool on the Pools tab to use this feature."); ?>
207
			<?php else: ?>
208
				<select id="poolname" name="poolname">
209
			<?php
210
				for ($i = 0; isset($config['load_balancer']['lbpool'][$i]); $i++) {
211
					$selected = "";
212
					if ( $config['load_balancer']['lbpool'][$i]['name'] == $pconfig['poolname'] )
213
						$selected = " selected=\"selected\"";
214
					echo "<option value=\"" . htmlspecialchars($config['load_balancer']['lbpool'][$i]['name']) . "\"{$selected}>{$config['load_balancer']['lbpool'][$i]['name']}</option>";
215
				}
216
			?>
217
				</select>
218
			<?php endif; ?>
219
				</td>
220
			</tr>
221
                <tr align="left">
222
		  			<td width="22%" valign="top" class="vncellreq"><?=gettext("Fall Back Pool"); ?></td>
223
					<td width="78%" class="vtable" colspan="2">
224
					<?php if(count($config['load_balancer']['lbpool']) == 0): ?>
225
						<b><?=gettext("NOTE:"); ?></b> <?=gettext("Please add a pool on the Pools tab to use this feature."); ?>
226
					<?php else: ?>
227
						<select id="sitedown" name="sitedown">
228
							<option value=""<?=htmlspecialchars($pconfig['sitedown']) == '' ? ' selected' : ''?>><?=gettext("none"); ?></option>
229
            			<?php
230
            				for ($i = 0; isset($config['load_balancer']['lbpool'][$i]); $i++) {
231
            					$selected = "";
232
            					if ( $config['load_balancer']['lbpool'][$i]['name'] == $pconfig['sitedown'] )
233
            						$selected = " selected=\"selected\"";
234
						echo "<option value=\"" . htmlspecialchars($config['load_balancer']['lbpool'][$i]['name']) . "\"{$selected}>{$config['load_balancer']['lbpool'][$i]['name']}</option>";
235
            				}
236
            			?>
237
            			</select>
238
				<br /><?=gettext("The server pool to which clients will be redirected if *ALL* servers in the Virtual Server Pool are offline."); ?>
239
				<br /><?=gettext("This option is NOT compatible with the DNS relay protocol."); ?>
240
				  <?php endif; ?>
241
                  </td>
242
				</tr>
243
				<tr style="display:none;"><td><input type="hidden" name="mode" value="redirect_mode" /></td></tr>
244
<!--
245
                <tr align="left">
246
		  			<td width="22%" valign="top" class="vncellreq">Mode</td>
247
                  <td width="78%" class="vtable" colspan="2">
248
                    <input id="redirect_mode" type="radio" name="mode" value="redirect"<?=htmlspecialchars($pconfig['mode']) == 'redirect' ? ' checked="checked"': ''?> /> Redirect
249
                    <input id="relay_mode" type="radio" name="mode" value="relay"<?=htmlspecialchars($pconfig['mode']) == 'relay' ? ' checked="checked"': ''?> /> Relay
250

    
251
                  <br />
252
                  </td>
253
				</tr>
254
-->
255
		<tr id="relay" align="left">
256
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Relay Protocol"); ?></td>
257
			<td width="78%" class="vtable" colspan="2">
258
			<select id="relay_protocol" name="relay_protocol">
259
			<?php
260
				$lb_def_protos = array("tcp", "dns");
261
				foreach ($lb_def_protos as $lb_proto) {
262
					$selected = "";
263
					if ( $pconfig['relay_protocol'] == $lb_proto )
264
						$selected = " selected=\"selected\"";
265
					echo "<option value=\"{$lb_proto}\"{$selected}>{$lb_proto}</option>";
266
				}
267
			?>
268
			</select>
269
			<br />
270
			</td>
271
		</tr>
272
                <tr align="left">
273
                  <td width="22%" valign="top">&nbsp;</td>
274
                  <td align="left" valign="bottom" width="78%">
275
					<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Submit"); ?>" />
276
					<input type="button" class="formbtn" value="<?=gettext("Cancel"); ?>" onclick="history.back()" />
277
			<?php if (isset($id) && $a_vs[$id] && $_GET['act'] != 'dup'): ?>
278
				<input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" />
279
			<?php endif; ?>
280
		  	</td>
281
			</tr>
282
		</table>
283
	</form>
284
	<br />
285
	<span class="red"><strong><?=gettext("Note:"); ?></strong></span> <?=gettext("Don't forget to add a firewall rule for the virtual server/pool after you're finished setting it up."); ?>
286
<?php include("fend.inc"); ?>
287
</body>
288
</html>
(125-125/255)