Project

General

Profile

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

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

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
$referer = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/load_balancer_virtual_server.php');
45

    
46
if (!is_array($config['load_balancer']['virtual_server'])) {
47
        $config['load_balancer']['virtual_server'] = array();
48
}
49
$a_vs = &$config['load_balancer']['virtual_server'];
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_vs[$id]) {
57
  $pconfig = $a_vs[$id];
58
} else {
59
  // Sane defaults
60
  $pconfig['mode'] = 'redirect';
61
}
62

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

    
66
if ($_POST) {
67
	unset($input_errors);
68
	$pconfig = $_POST;
69

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

    
84
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
85

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

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

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

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

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

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

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

    
122
		if($_POST['sitedown'] == "")
123
			unset($vsent['sitedown']);
124

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

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

    
140
		header("Location: load_balancer_virtual_server.php");
141
		exit;
142
	}
143
}
144

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

    
148
include("head.inc");
149

    
150
?>
151

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

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

    
253
                  <br />
254
                  </td>
255
				</tr>
256
-->
257
		<tr id="relay" align="left">
258
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Relay Protocol"); ?></td>
259
			<td width="78%" class="vtable" colspan="2">
260
			<select id="relay_protocol" name="relay_protocol">
261
			<?php
262
				$lb_def_protos = array("tcp", "dns");
263
				foreach ($lb_def_protos as $lb_proto) {
264
					$selected = "";
265
					if ( $pconfig['relay_protocol'] == $lb_proto )
266
						$selected = " selected=\"selected\"";
267
					echo "<option value=\"{$lb_proto}\"{$selected}>{$lb_proto}</option>";
268
				}
269
			?>
270
			</select>
271
			<br />
272
			</td>
273
		</tr>
274
                <tr align="left">
275
                  <td width="22%" valign="top">&nbsp;</td>
276
                  <td align="left" valign="bottom" width="78%">
277
					<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Submit"); ?>" />
278
					<input type="button" class="formbtn" value="<?=gettext("Cancel");?>" onclick="window.location.href='<?=$referer;?>'" />
279
			<?php if (isset($id) && $a_vs[$id] && $_GET['act'] != 'dup'): ?>
280
				<input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" />
281
			<?php endif; ?>
282
		  	</td>
283
			</tr>
284
		</table>
285
	</form>
286
	<br />
287
	<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."); ?>
288
<?php include("fend.inc"); ?>
289
</body>
290
</html>
(126-126/256)