Projet

Général

Profil

Télécharger (19,1 ko) Statistiques
| Branche: | Tag: | Révision:

univnautes / usr / local / www / load_balancer_relay_action_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-action-edit
37
##|*NAME=Services: Load Balancer: Relay Action: Edit page
38
##|*DESCR=Allow access to the 'Services: Load Balancer: Relay Action: Edit' page.
39
##|*MATCH=load_balancer_relay_action_edit.php*
40
##|-PRIV
41

    
42
require("guiconfig.inc");
43
if (!is_array($config['load_balancer']['lbaction'])) {
44
	$config['load_balancer']['lbaction'] = array();
45
}
46
$a_action = &$config['load_balancer']['lbaction'];
47

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

    
53
if (isset($id) && $a_action[$id]) {
54
  $pconfig = array();
55
	$pconfig = $a_action[$id];
56
} else {
57
  // XXX - TODO, this isn't sane for this page :)
58
	/* Some sane page defaults */
59
	$pconfig['protocol'] = 'http';
60
	$pconfig['direction'] = 'request';
61
	$pconfig['type'] = 'cookie';	
62
	$pconfig['action'] = 'change';
63
}
64

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

    
68
$kv = array('key', 'value');
69
$vk = array('value', 'key');
70
$hr_actions = array();
71
$hr_actions['append'] = $vk;
72
$hr_actions['change'] = $kv;
73
$hr_actions['expect'] = $vk;
74
$hr_actions['filter'] = $vk;
75
$hr_actions['hash'] = 'key';
76
$hr_actions['log'] = 'key';
77
// mark is disabled until I can figure out how to make the display clean
78
//$hr_actions['mark'] = array('value', 'key', 'id');
79
//$hr_actions[] = 'label';
80
//$hr_actions[] = 'no label';
81
$hr_actions['remove'] = 'key';
82
//$hr_actions[] = 'return error';
83
/* Setup decision tree */
84
$action = array();
85
$actions['protocol']['http'] = 'HTTP';
86
$actions['protocol']['tcp'] = 'TCP';
87
$actions['protocol']['dns'] = 'DNS';
88
$actions['direction'] = array();
89
$actions['direction']['request'] = array();
90
$actions['direction']['request']['cookie'] = $hr_actions;
91
$actions['direction']['request']['header'] = $hr_actions;
92
$actions['direction']['request']['path'] = $hr_actions;
93
$actions['direction']['request']['query'] = $hr_actions;
94
$actions['direction']['request']['url'] = $hr_actions;
95
$actions['direction']['response'] = array();
96
$actions['direction']['response']['cookie'] = $hr_actions;
97
$actions['direction']['response']['header'] = $hr_actions;
98
//$action['http']['tcp'] = array();
99
//$action['http']['ssl'] = array();
100

    
101

    
102

    
103
if ($_POST) {
104
	$changecount++;
105

    
106
	unset($input_errors);
107
	$pconfig = $_POST;
108

    
109
  // Peel off the action and type from the post and fix $pconfig
110
  $action = explode('_', $pconfig['action']);
111
  $pconfig['action'] = $action[2];
112
  $pconfig['type'] = $action[1];
113
  unset($pconfig["type_{$pconfig['direction']}"]);
114

    
115
	/* input validation */
116
	$reqdfields = explode(" ", "name protocol direction action descr");
117
	$reqdfieldsn = array(gettext("Name"),gettext("Protocol"),gettext("Direction"),gettext("Action"),gettext("Description"));
118

    
119
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
120

    
121
	/* Ensure that our monitor names are unique */
122
	for ($i=0; isset($config['load_balancer']['lbactions'][$i]); $i++)
123
		if (($_POST['name'] == $config['load_balancer']['lbactions'][$i]['name']) && ($i != $id))
124
			$input_errors[] = gettext("This action name has already been used.  Action names must be unique.");
125

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

    
129
	if (!$input_errors) {
130
		$actent = array();
131
		if(isset($id) && $a_action[$id])
132
			$actent = $a_action[$id];
133
		if($actent['name'] != "")
134
			$changedesc .= " " . sprintf(gettext("modified '%s' action:"), $actent['name']);
135
		
136
		update_if_changed("name", $actent['name'], $pconfig['name']);
137
		update_if_changed("protocol", $actent['protocol'], $pconfig['protocol']);
138
		update_if_changed("type", $actent['type'], $pconfig['type']);
139
		update_if_changed("direction", $actent['direction'], $pconfig['direction']);
140
		update_if_changed("description", $actent['descr'], $pconfig['descr']);
141
    update_if_changed("action", $actent['action'], $pconfig['action']);
142
    switch ($pconfig['action']) {
143
      case "append":
144
      case "change":
145
      case "expect":
146
      case "filter": {
147
        update_if_changed("value", $actent['options']['value'], $pconfig['option_action_value']);
148
        update_if_changed("key", $actent['options']['akey'], $pconfig['option_action_key']);
149
        break; 
150
      }
151
      case "hash":
152
      case "log": {
153
        update_if_changed("key", $actent['options']['akey'], $pconfig['option_action_key']);
154
        break;
155
      }
156
    }
157
    
158
		if (isset($id) && $a_action[$id]) {
159
//    XXX - TODO
160
			/* modify all virtual servers with this name */
161
//			for ($i = 0; isset($config['load_balancer']['virtual_server'][$i]); $i++) {
162
//				if ($config['load_balancer']['virtual_server'][$i]['protocol'] == $a_protocol[$id]['name'])
163
//					$config['load_balancer']['virtual_server'][$i]['protocol'] = $protent['name'];
164
//			}
165
			$a_action[$id] = $actent;
166
		} else {
167
			$a_action[] = $actent;
168
		}
169
		if ($changecount > 0) {
170
			/* Mark config dirty */
171
			mark_subsystem_dirty('loadbalancer');
172
			write_config($changedesc);
173
		}
174

    
175
		header("Location: load_balancer_relay_action.php");
176
		exit;
177
	}
178
}
179

    
180
$pgtitle = array(gettext("Services"), gettext("Load Balancer"),gettext("Relay Action"),gettext("Edit"));
181
$shortcut_section = "relayd";
182

    
183
include("head.inc");
184
	$types = array("http" => gettext("HTTP"), "tcp" => gettext("TCP"), "dns" => gettext("DNS"));
185
?>
186

    
187
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
188

    
189
<script type="text/javascript">
190

    
191
function updateProtocol(m) {
192
  // Default to HTTP
193
  if (m == "") {
194
    m = "http";
195
  }
196
	switch (m) {
197
		case "dns": {
198
			jQuery('#type_row').hide();
199
			jQuery('#tcp_options_row').hide();
200
			jQuery('#ssl_options_row').hide();
201
			jQuery('#direction_row').hide();
202
			jQuery('#action_row').hide();
203
			break;
204
		}
205
		case "tcp": {
206
			jQuery('#type_row').hide();
207
			jQuery('#tcp_options_row').show();
208
			jQuery('#ssl_options_row').hide();
209
			jQuery('#direction_row').hide();
210
			jQuery('#action_row').hide();
211
			break;
212
		}
213
		case "http": {
214
			jQuery('#type_row').show();
215
			jQuery('#tcp_options_row').hide();
216
			jQuery('#ssl_options_row').show();
217
			jQuery('#direction_row').show();
218
			jQuery('#direction').prop('disabled',false);
219
			jQuery('#type_' + jQuery('#direction').val()).prop('disabled',false);
220
			jQuery('#type_' + jQuery('#direction').val()).show();
221
			jQuery('#action_row').show();
222
<?php
223
  /* Generate lots of .appear() entries for the action row select list
224
   * based on what's been either preconfigured or "defaults"
225
   * This really did have to be done in PHP.
226
   */
227
  if (isset($pconfig['type'])) {
228
    $dtype = $pconfig['type'];
229
    $ddir = $pconfig['direction'];
230
  } else {
231
    $dtype = "cookie";
232
    $ddir = "request";
233
  }
234
	foreach ($actions['direction'][$ddir] as $type => $tv) {
235
		foreach ($actions['direction'][$ddir][$type] as $action => $av ) {
236
			if($dtype == $type) {
237
				echo "jQuery('#{$ddir}_{$type}_{$action}').show();";
238
 			}
239
		}
240
	}
241
?>
242

    
243
			break;
244
		}
245
	}
246
}
247

    
248
function updateDirection(d) {
249
  // Default to request
250
  if (d == "") {
251
    d = "request";
252
  }
253

    
254
  switch (d) {
255
    case "request": {
256
      jQuery('#type_response').prop('disabled',true);
257
      jQuery('#type_response').hide();
258
      jQuery('#type_request').prop('disabled',false);
259
      jQuery('#type_request').show();
260
      break;
261
    }
262
    case "response": {
263
      jQuery('#type_request').prop('disabled',true);
264
      jQuery('#type_request').hide();
265
      jQuery('#type_response').prop('disabled',false);
266
      jQuery('#type_response').show();
267
      break;
268
    }
269
  }
270
}
271

    
272

    
273
function updateType(t){
274
  // Default to action_row
275
  // XXX - does this actually make any sense?
276
  if (t == "") {
277
    t = "action_row";
278
  }
279

    
280
	switch(t) {
281
<?php
282
	/* OK, so this is sick using php to generate javascript, but it needed to be done */
283
	foreach ($types as $key => $val) {
284
		echo "		case \"{$key}\": {\n";
285
		$t = $types;
286
		foreach ($t as $k => $v) {
287
			if ($k != $key) {
288
				echo "			jQuery('#{$k}').hide();\n";
289
			}
290
		}
291
		echo "		}\n";
292
	}
293
?>
294
	}
295
	jQuery('#' + t).show();
296
}
297

    
298

    
299
function updateAction(a) {
300
  // Default to change
301
  if (a == "") {
302
    a = "change";
303
  }
304
  switch(a) {
305
    case "append": {
306
      jQuery('#input_action_value').show();
307
      jQuery('#option_action_value').prop('disabled',false);
308
      jQuery('#input_action_key').show();
309
      jQuery('#option_action_key').prop('disabled',false);
310
      jQuery('#input_action_id').hide();
311
      jQuery('#option_action_id').prop('disabled',true);
312
      jQuery('#action_action_value').html("&nbsp;to&nbsp;");
313
      jQuery('#action_action_id').html("");
314
      break;
315
    }
316
    case "change": {
317
      jQuery('#input_action_value').show();
318
      jQuery('#option_action_value').prop('disabled',false);
319
      jQuery('#input_action_key').show();
320
      jQuery('#option_action_key').prop('disabled',false);
321
      jQuery('#input_action_id').hide();
322
      jQuery('#option_action_id').prop('disabled',true);
323
      jQuery('#action_action_value').html("&nbsp;of&nbsp;");
324
      jQuery('#action_action_id').html("");
325
      break;
326
    }
327
    case "expect": {
328
      jQuery('#input_action_value').show();
329
      jQuery('#option_action_value').prop('disabled',false);
330
      jQuery('#input_action_key').show();
331
      jQuery('#option_action_key').prop('disabled',false);
332
      jQuery('#input_action_id').hide();
333
      jQuery('#option_action_id').prop('disabled',true);
334
      jQuery('#action_action_value').html("&nbsp;from&nbsp;");
335
      jQuery('#action_action_id').html("");
336
      break;
337
    }
338
    case "filter": {
339
      jQuery('#input_action_value').show();
340
      jQuery('#option_action_value').prop('disabled',false);
341
      jQuery('#input_action_key').show();
342
      jQuery('#option_action_key').prop('disabled',false);
343
      jQuery('#input_action_id').hide();
344
      jQuery('#option_action_id').prop('disabled',true);
345
      jQuery('#action_action_value').html("&nbsp;from&nbsp;");
346
      jQuery('#action_action_id').html("");
347
      break;
348
    }
349
    case "hash": {
350
      jQuery('#input_action_value').hide();
351
      jQuery('#option_action_value').prop('disabled',true);
352
      jQuery('#input_action_key').show();
353
      jQuery('#option_action_key').prop('disabled',false);
354
      jQuery('#input_action_id').hide();
355
      jQuery('#option_action_id').prop('disabled',true);
356
      jQuery('#action_action_value').html("");
357
      jQuery('#action_action_id').html("");
358
      break;
359
    }
360
    case "log": {
361
      jQuery('#input_action_value').hide();
362
      jQuery('#option_action_value').prop('disabled',true);
363
      jQuery('#input_action_key').show();
364
      jQuery('#option_action_key').prop('disabled',false);
365
      jQuery('#input_action_id').hide();
366
      jQuery('#option_action_id').prop('disabled',true);
367
      jQuery('#action_action_value').html("");
368
      jQuery('#action_action_id').html("");
369
      break;
370
    }
371
    case "mark": {
372
      jQuery('#input_action_value').show();
373
      jQuery('#option_action_value').prop('disabled',false);
374
      jQuery('#input_action_key').show();
375
      jQuery('#option_action_key').prop('disabled',false);
376
      jQuery('#input_action_id').show();
377
      jQuery('#option_action_id').prop('disabled',false);
378
      jQuery('#action_action_value').html("&nbsp;from&nbsp;");
379
      jQuery('#action_action_id').html("&nbsp;with&nbsp;");
380
      break;
381
    }
382
  }
383
}
384

    
385

    
386
function num_options() {
387
	return jQuery('#options_table').children().length - 1;
388
}
389

    
390

    
391
jQuery(document).ready(function() {
392
  updateProtocol('<?=htmlspecialchars($pconfig['protocol'])?>');  
393
  updateDirection('<?=htmlspecialchars($pconfig['direction'])?>');  
394
  updateType('<?=htmlspecialchars($pconfig['type'])?>');  
395
  updateAction('<?=htmlspecialchars($pconfig['action'])?>');  
396
});
397

    
398
</script>
399

    
400
<?php include("fbegin.inc"); ?>
401
<?php if ($input_errors) print_input_errors($input_errors); ?>
402
	<form action="load_balancer_relay_action_edit.php" method="post" name="iform" id="iform">
403
	<table width="100%" border="0" cellpadding="6" cellspacing="0">
404
		<tr>
405
			<td colspan="2" valign="top" class="listtopic"><?=gettext("Edit Load Balancer - Relay Action entry"); ?></td>
406
		</tr>
407
		<tr align="left" id="name">
408
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Name"); ?></td>
409
			<td width="78%" class="vtable" colspan="2">
410
				<input name="name" type="text" <?if(isset($pconfig['name'])) echo "value=\"{$pconfig['name']}\"";?> size="16" maxlength="16">
411
			</td>
412
		</tr>
413
		<tr align="left">
414
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Description"); ?></td>
415
			<td width="78%" class="vtable" colspan="2">
416
				<input name="descr" type="text" <?if(isset($pconfig['descr'])) echo "value=\"{$pconfig['descr']}\"";?>size="64">
417
			</td>
418
		</tr>
419
<!-- Protocol -->
420
		<tr align="left" id="protocol_row">
421
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Protocol"); ?></td>
422
			<td width="78%" class="vtable" colspan="2">
423
				<select id="protocol" name="protocol">
424
<?
425
	foreach ($actions['protocol'] as $key => $val) {
426
		if(isset($pconfig['protocol']) && $pconfig['protocol'] == $key) {
427
			$selected = " selected";
428
		} else {
429
			$selected = "";
430
		}
431
		echo "<option value=\"{$key}\" onclick=\"updateProtocol('{$key}');\"{$selected}>{$val}</option>\n";
432
	}
433
?>
434
				</select>
435
			</td>
436
		</tr>
437

    
438
<!-- Direction -->
439
		<tr align="left" id="direction_row">
440
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Direction"); ?></td>
441
			<td width="78%" class="vtable" colspan="2">
442
				<select id="direction" name="direction" style="disabled">
443
<?
444
	foreach ($actions['direction'] as $key => $val) {
445
		if(isset($pconfig['direction']) && $pconfig['direction'] == $key) {
446
			$selected = " selected";
447
		} else {
448
			$selected = "";
449
		}
450
		echo "<option value=\"{$key}\" onclick=\"updateDirection('{$key}');\"{$selected}>{$key}</option>\n";
451
	}
452
?>
453
				</select>
454

    
455
			</td>
456
		</tr>
457

    
458
<!-- Type -->
459
    <tr align="left" id="type_row"<?= $pconfig['protocol'] == "http" ? "" : " style=\"display:none;\""?>>
460
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Type"); ?></td>
461
			<td width="78%" class="vtable" colspan="2">
462
<?
463
	foreach ($actions['direction'] as $dir => $v) {
464
		echo"		<select id=\"type_{$dir}\" name=\"type_{$dir}\" style=\"display:none; disabled;\">";
465
		foreach ($actions['direction'][$dir] as $key => $val) {
466
			if(isset($pconfig['type']) && $pconfig['type'] == $key) {
467
				$selected = " selected";
468
			} else {
469
				$selected = "";
470
			}
471
			echo "<option value=\"{$key}\" onclick=\"updateDirection('$key');\"{$selected}>{$key}</option>\n";
472
		}
473
	}
474
?>
475
				</select>
476
			</td>
477
		</tr>
478

    
479
<!-- Action -->
480
    <tr align="left" id="action_row"<?= $pconfig['protocol'] == "http" ? "" : " style=\"display:none;\""?>>
481
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Action"); ?></td>
482
			<td width="78%" class="vtable" colspan="2">
483
				<select id="action" name="action" style=\"display: none;\">
484
<?
485
	foreach ($actions['direction'] as $dir => $dv) {
486
		foreach ($actions['direction'][$dir] as $type => $tv) {
487
			foreach ($actions['direction'][$dir][$type] as $action => $av ) {
488
				if(isset($pconfig['action']) && $pconfig['action'] == $action) {
489
					$selected = " selected";
490
				} else if ($action == "change" ){
491
  					$selected = " selected";
492
  				} else {
493
  					$selected = "";
494
				}
495
				echo "<option id=\"{$dir}_{$type}_{$action}\" value=\"{$dir}_{$type}_{$action}\" onClick=\"updateAction('$action');\" style=\"display: none;\"{$selected}>{$action}</option>\n";
496
			}
497
		}
498
	}
499
?>
500
				</select>
501
<br />
502
<table><tr>
503
<td><div id="input_action_value"><?=gettext("Value"); ?>&nbsp;<input id="option_action_value" name="option_action_value" type="text" <?if(isset($pconfig['options']['value'])) echo "value=\"{$pconfig['options']['value']}\"";?>size="20"></div></td>
504
<td><div id="action_action_value"></div></td>
505
<td><div id="input_action_key"><?=gettext("Key"); ?>&nbsp;<input id="option_action_key" name="option_action_key" type="text" <?if(isset($pconfig['options']['akey'])) echo "value=\"{$pconfig['options']['akey']}\"";?>size="20"></div></td>
506
<td><div id="action_action_id"></div></td>
507
<td><div id="input_action_id"><?=gettext("ID"); ?>&nbsp;<input id="option_action_id" name="option_action_id" type="text" <?if(isset($pconfig['options']['id'])) echo "value=\"{$pconfig['options']['id']}\"";?>size="20"></div></td>
508
</tr></table>
509
			</td>
510
		</tr>
511
		<tr align="left" id="tcp_options_row"<?= $pconfig['protocol'] == "tcp" ? "" : " style=\"display:none;\""?>>
512
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Options"); ?></td>
513
			<td width="78%" class="vtable" colspan="2">
514
				XXX: <?=gettext("TODO"); ?>
515
				<select id="options" name="options">
516
<!-- XXX TODO >
517
<?
518
	foreach ($types as $key => $val) {
519
		if(isset($pconfig['protocol']) && $pconfig['protocol'] == $key) {
520
			$selected = " selected";
521
		} else {
522
			$selected = "";
523
		}
524
		echo "<option value=\"{$key}\" onclick=\"updateType('{$key}');\"{$selected}>{$val}</option>\n";
525
	}
526
?>
527
				</select>
528
< XXX TODO -->
529
			</td>
530
		</tr>
531
		<tr align="left" id="ssl_options_row"<?= $pconfig['protocol'] == "http" ? "" : " style=\"display:none;\""?>>
532
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Options"); ?></td>
533
			<td width="78%" class="vtable" colspan="2">
534
				XXX: <?=gettext("TODO"); ?>
535
<!-- XXX TODO >
536
				<select id="options" name="options">
537
<?
538
	foreach ($types as $key => $val) {
539
		if(isset($pconfig['protocol']) && $pconfig['protocol'] == $key) {
540
			$selected = " selected";
541
		} else {
542
			$selected = "";
543
		}
544
		echo "<option value=\"{$key}\" onclick=\"updateType('{$key}');\"{$selected}>{$val}</option>\n";
545
	}
546
?>
547
				</select>
548
< XXX TODO -->
549
			</td>
550
		</tr>
551
		<tr align="left">
552
			<td width="22%" valign="top">&nbsp;</td>
553
			<td width="78%">
554
				<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save"); ?>"><input type="button" class="formbtn" value="<?=gettext("Cancel"); ?>" onclick="history.back()">
555
				<?php if (isset($id) && $a_action[$id] && $_GET['act'] != 'dup'): ?>
556
				<input name="id" type="hidden" value="<?=htmlspecialchars($id);?>">
557
				<?php endif; ?>
558
			</td>
559
		</tr>
560
	</table>
561
	</form>
562
<br />
563
<?php include("fend.inc"); ?>
564
</body>
565
</html>
(120-120/255)