Projet

Général

Profil

Télécharger (9,29 ko) Statistiques
| Branche: | Tag: | Révision:

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

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

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

    
68

    
69

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

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

    
76

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

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

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

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

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

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

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

    
132
		header("Location: load_balancer_relay_protocol.php");
133
		exit;
134
	}
135
}
136

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

    
140
include("head.inc");
141

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

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

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

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

    
255
						<td>
256
							<center>
257
							<b><?=gettext("Enabled Actions"); ?></b>
258
							<br />
259
							<select id="lbaction" name="lbaction[]" multiple="true" size="5">
260
<?php
261
if (is_array($pconfig['lbaction'])) {
262
	foreach($pconfig['lbaction'] as $actent) {
263
		echo "    <option value=\"{$actent}\">{$actent}</option>\n";
264
	}
265
}
266
echo "</select>";
267
?>
268
							<br />
269
						</td>
270
					</tr>
271
					</tbody>
272
				</table>
273
			</td>
274
		</tr>
275
		<tr align="left">
276
			<td width="22%" valign="top">&nbsp;</td>
277
			<td width="78%">
278
				<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save"); ?>" onClick="AllOptions($('lbaction'), true); AllOptions($('available_action'), false);"><input type="button" class="formbtn" value="<?=gettext("Cancel"); ?>" onclick="history.back()">
279
				<?php if (isset($id) && $a_protocol[$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
<?php include("fend.inc"); ?>
288
</body>
289
</html>
(122-122/255)