Project

General

Profile

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

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

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

    
7
        Copyright (C) 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-services-loadbalancer-relay-protocol-edit
37
##|*NAME=Services: Load Balancer: Relay Protocol: Edit page
38
##|*DESCR=Allow access to the 'Services: Load Balancer: Relay Protocol: Edit' page.
39
##|*MATCH=load_balancer_relay_protocol_edit.php*
40
##|-PRIV
41

    
42
require("guiconfig.inc");
43

    
44
$referer = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/load_balancer_relay_protocol.php');
45

    
46
if (!is_array($config['load_balancer']['lbprotocol'])) {
47
	$config['load_balancer']['lbprotocol'] = array();
48
}
49
$a_protocol = &$config['load_balancer']['lbprotocol'];
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_protocol[$id]) {
57
	$pconfig = $a_protocol[$id];
58
	$pconfig['type'] = $a_protocol[$id]['type'];
59
	$pconfig['descr'] = $a_protocol[$id]['descr'];
60
	$pconfig['lbaction'] = array();
61
	$pconfig['options'] = $a_protocol[$id]['options'];
62
} else {
63
	/* Some sane page defaults */
64
	$pconfig['type'] = 'http';
65
}
66

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

    
70

    
71

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

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

    
78

    
79
	/* input validation */
80
	$reqdfields = explode(" ", "name type descr");
81
	$reqdfieldsn = array(gettext("Name"),gettext("Type"),gettext("Description"));
82

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

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

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

    
93
	switch($_POST['type']) {
94
		case 'tcp':
95
		case 'http':
96
		case 'https':
97
		case 'dns': {
98
			break;
99
		}
100
	}
101

    
102
	if (!$input_errors) {
103
		$protent = array();
104
		if(isset($id) && $a_protocol[$id])
105
			$protent = $a_protocol[$id];
106
		if($protent['name'] != "")
107
			$changedesc .= " " . sprintf(gettext("modified '%s' load balancing protocol:"), $protent['name']);
108
		
109
		update_if_changed(gettext("name"), $protent['name'], $pconfig['name']);
110
		update_if_changed(gettext("type"), $protent['type'], $pconfig['type']);
111
		update_if_changed(gettext("description"), $protent['descr'], $pconfig['descr']);
112
		update_if_changed(gettext("type"), $protent['type'], $pconfig['type']);
113
		update_if_changed(gettext("action"), $protent['lbaction'], $pconfig['lbaction']);
114

    
115
		if (isset($id) && $a_protocol[$id]) {
116
			/* modify all virtual servers with this name */
117
/*
118
			for ($i = 0; isset($config['load_balancer']['virtual_server'][$i]); $i++) {
119
				if ($config['load_balancer']['virtual_server'][$i]['protocol'] == $a_protocol[$id]['name'])
120
					$config['load_balancer']['virtual_server'][$i]['protocol'] = $protent['name'];
121
			}
122
*/	
123
			$a_protocol[$id] = $protent;
124
		} else {
125
			$a_protocol[] = $protent;
126
    }	
127
    
128
		if ($changecount > 0) {
129
			/* Mark config dirty */
130
			mark_subsystem_dirty('loadbalancer');
131
			write_config($changedesc);
132
		}
133

    
134
		header("Location: load_balancer_relay_protocol.php");
135
		exit;
136
	}
137
}
138

    
139
$pgtitle = array(gettext("Services"), gettext("Load Balancer"),gettext("Relay Protocol"),gettext("Edit"));
140
$shortcut_section = "relayd";
141

    
142
include("head.inc");
143

    
144
$types = array("http" => gettext("HTTP"), "tcp" => gettext("TCP"), "dns" => gettext("DNS"));
145
?>
146
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
147
<script type="text/javascript">
148
function updateType(t){
149
	switch(t) {
150
<?php
151
	/* OK, so this is sick using php to generate javascript, but it needed to be done */
152
	foreach ($types as $key => $val) {
153
		echo "		case \"{$key}\": {\n";
154
		$t = $types;
155
		foreach ($t as $k => $v) {
156
			if ($k != $key) {
157
				echo "			jQuery('#{$k}').hide();\n";
158
			}
159
		}
160
		echo "		}\n";
161
	}
162
?>
163
	}
164
	jQuery('#' + t).show();
165
}
166

    
167
function num_options() {
168
	return jQuery('#options_table').children().length - 1;
169
}
170

    
171
/*
172
jQuery(document).ready(function(){
173
  $$('.action').each(function(action) {
174
    new Draggable(action, {revert: true, ghosting: true});
175
  });
176
  Droppables.add('actions', {
177
    accept: 'action', onDrop: function(action) {
178
      var new_action = new Element('li');
179
      new Draggable(new_action, {revert: true});
180
      $('action_list').appendChild(new_action);
181
    }
182
  });
183
});
184
*/
185
</script>
186

    
187
<?php include("fbegin.inc"); ?>
188
<?php if ($input_errors) print_input_errors($input_errors); ?>
189
	<form action="load_balancer_relay_protocol_edit.php" method="post" name="iform" id="iform">
190
	<table width="100%" border="0" cellpadding="6" cellspacing="0">
191
		<tr>
192
			<td colspan="2" valign="top" class="listtopic"><?=gettext("Edit Load Balancer - Relay Protocol entry"); ?></td>
193
		</tr>
194
		<tr align="left">
195
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Name"); ?></td>
196
			<td width="78%" class="vtable" colspan="2">
197
				<input name="name" type="text" <?if(isset($pconfig['name'])) echo "value=\"{$pconfig['name']}\"";?> size="16" maxlength="16">
198
			</td>
199
		</tr>
200
		<tr align="left">
201
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Type"); ?></td>
202
			<td width="78%" class="vtable" colspan="2">
203
				<select id="type" name="type">
204
<?
205
	foreach ($types as $key => $val) {
206
		if(isset($pconfig['type']) && $pconfig['type'] == $key) {
207
			$selected = " selected";
208
		} else {
209
			$selected = "";
210
		}
211
		echo "<option value=\"{$key}\" onclick=\"updateType('{$key}');\"{$selected}>{$val}</option>\n";
212
	}
213
?>
214
				</select>
215
			</td>
216
		</tr>
217
		<tr align="left">
218
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Description"); ?></td>
219
			<td width="78%" class="vtable" colspan="2">
220
				<input name="descr" type="text" <?if(isset($pconfig['descr'])) echo "value=\"{$pconfig['descr']}\"";?>size="64">
221
			</td>
222
		</tr>
223
		<tr>
224
			<td>&nbsp;</td>
225
		</tr>
226
		<tr>
227
			<td colspan="2" valign="top" class="listtopic"><?=gettext("Add / remove available actions"); ?></td>
228
		</tr>
229
		<tr align="left" id="actions">
230
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Actions"); ?></td>
231
			<td width="78%" class="vtable" colspan="2">
232
				<table>
233
					<tbody>
234
					<tr>
235
						<td>
236
							<center>
237
							<b><?=gettext("Available Actions"); ?></b>
238
							<br />
239
							<select id="available_action" name="available_action[]" multiple="true" size="5">
240
<?php
241
if (is_array($config['load_balancer']['lbaction'])) {
242
	foreach($config['load_balancer']['lbaction'] as $actent) {
243
		if($actent != '') echo "    <option value=\"{$actent['name']}\">{$actent['name']}</option>\n";
244
	}
245
}
246
echo "</select>";
247
?>
248
							<br />
249
						</td>
250
						<td valign="middle">
251
							<center>
252
								<input class="formbtn" type="button" name="copyToEnabled" value="<?=gettext("Add"); ?>" onclick="copyOption($('available_action'), $('lbaction'));" /><br />
253
								<input class="formbtn" type="button" name="removeFromEnabled" value="<?=gettext("Remove"); ?>" onclick="deleteOption($('lbaction'));" />
254
							</center>
255
						</td>
256

    
257
						<td>
258
							<center>
259
							<b><?=gettext("Enabled Actions"); ?></b>
260
							<br />
261
							<select id="lbaction" name="lbaction[]" multiple="true" size="5">
262
<?php
263
if (is_array($pconfig['lbaction'])) {
264
	foreach($pconfig['lbaction'] as $actent) {
265
		echo "    <option value=\"{$actent}\">{$actent}</option>\n";
266
	}
267
}
268
echo "</select>";
269
?>
270
							<br />
271
						</td>
272
					</tr>
273
					</tbody>
274
				</table>
275
			</td>
276
		</tr>
277
		<tr align="left">
278
			<td width="22%" valign="top">&nbsp;</td>
279
			<td width="78%">
280
				<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save"); ?>" onClick="AllOptions($('lbaction'), true); AllOptions($('available_action'), false);">
281
				<input type="button" class="formbtn" value="<?=gettext("Cancel");?>" onclick="window.location.href='<?=$referer;?>'" />
282
				<?php if (isset($id) && $a_protocol[$id] && $_GET['act'] != 'dup'): ?>
283
				<input name="id" type="hidden" value="<?=htmlspecialchars($id);?>">
284
				<?php endif; ?>
285
			</td>
286
		</tr>
287
	</table>
288
	</form>
289
<br />
290
<?php include("fend.inc"); ?>
291
</body>
292
</html>
(123-123/256)