Project

General

Profile

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

univnautes / usr / local / www / load_balancer_relay_action_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-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

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

    
46
if (!is_array($config['load_balancer']['lbaction'])) {
47
	$config['load_balancer']['lbaction'] = array();
48
}
49
$a_action = &$config['load_balancer']['lbaction'];
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_action[$id]) {
57
  $pconfig = array();
58
	$pconfig = $a_action[$id];
59
} else {
60
  // XXX - TODO, this isn't sane for this page :)
61
	/* Some sane page defaults */
62
	$pconfig['protocol'] = 'http';
63
	$pconfig['direction'] = 'request';
64
	$pconfig['type'] = 'cookie';	
65
	$pconfig['action'] = 'change';
66
}
67

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

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

    
104

    
105

    
106
if ($_POST) {
107
	$changecount++;
108

    
109
	unset($input_errors);
110
	$pconfig = $_POST;
111

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

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

    
122
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
123

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

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

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

    
178
		header("Location: load_balancer_relay_action.php");
179
		exit;
180
	}
181
}
182

    
183
$pgtitle = array(gettext("Services"), gettext("Load Balancer"),gettext("Relay Action"),gettext("Edit"));
184
$shortcut_section = "relayd";
185

    
186
include("head.inc");
187
	$types = array("http" => gettext("HTTP"), "tcp" => gettext("TCP"), "dns" => gettext("DNS"));
188
?>
189

    
190
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
191

    
192
<script type="text/javascript">
193

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

    
246
			break;
247
		}
248
	}
249
}
250

    
251
function updateDirection(d) {
252
  // Default to request
253
  if (d == "") {
254
    d = "request";
255
  }
256

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

    
275

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

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

    
301

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

    
388

    
389
function num_options() {
390
	return jQuery('#options_table').children().length - 1;
391
}
392

    
393

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

    
401
</script>
402

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

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

    
458
			</td>
459
		</tr>
460

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

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