Projet

Général

Profil

Télécharger (14,3 ko) Statistiques
| Branche: | Tag: | Révision:

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

1
<?php
2
/* $Id$ */
3
/*
4
        load_balancer_monitor_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-monitor-edit
37
##|*NAME=Services: Load Balancer: Monitor: Edit page
38
##|*DESCR=Allow access to the 'Services: Load Balancer: Monitor: Edit' page.
39
##|*MATCH=load_balancer_monitor_edit.php*
40
##|-PRIV
41

    
42
require("guiconfig.inc");
43

    
44
if (!is_array($config['load_balancer']['monitor_type'])) {
45
	$config['load_balancer']['monitor_type'] = array();
46
}
47
$a_monitor = &$config['load_balancer']['monitor_type'];
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_monitor[$id]) {
55
	$pconfig['name'] = $a_monitor[$id]['name'];
56
	$pconfig['type'] = $a_monitor[$id]['type'];
57
	$pconfig['descr'] = $a_monitor[$id]['descr'];
58
	$pconfig['options'] = array();
59
	$pconfig['options'] = $a_monitor[$id]['options'];
60
} else {
61
	/* Some sane page defaults */
62
	$pconfig['options']['path'] = '/';
63
	$pconfig['options']['code'] = 200;
64
}
65

    
66
$changedesc = gettext("Load Balancer: Monitor:") . " ";
67
$changecount = 0;
68

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

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

    
75
	/* turn $_POST['http_options_*'] into $pconfig['options'][*] */
76
	foreach($_POST as $key => $val) {
77
		if (stristr($key, 'options') !== false) {
78
			if (stristr($key, $pconfig['type'].'_') !== false) {
79
				$opt = explode('_',$key);
80
				$pconfig['options'][$opt[2]] = $val;
81
			}
82
			unset($pconfig[$key]);
83
		}
84
	}
85

    
86
	/* input validation */
87
	$reqdfields = explode(" ", "name type descr");
88
	$reqdfieldsn = array(gettext("Name"),gettext("Type"),gettext("Description"));
89

    
90
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
91

    
92
	/* Ensure that our monitor names are unique */
93
	for ($i=0; isset($config['load_balancer']['monitor_type'][$i]); $i++)
94
		if (($_POST['name'] == $config['load_balancer']['monitor_type'][$i]['name']) && ($i != $id))
95
			$input_errors[] = gettext("This monitor name has already been used.  Monitor names must be unique.");
96

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

    
100
	switch($_POST['type']) {
101
		case 'icmp': {
102
			break;
103
		}
104
		case 'tcp': {
105
			break;
106
		}
107
		case 'http':
108
		case 'https': {
109
			if (is_array($pconfig['options'])) {
110
				if (isset($pconfig['options']['host']) && $pconfig['options']['host'] != "") {
111
					if (!is_hostname($pconfig['options']['host'])) {
112
						$input_errors[] = gettext("The hostname can only contain the characters A-Z, 0-9 and '-'.");
113
					}
114
				}
115
				if (isset($pconfig['options']['code']) && $pconfig['options']['code'] != "") {
116
					// Check code
117
					if(!is_rfc2616_code($pconfig['options']['code'])) {
118
						$input_errors[] = gettext("HTTP(s) codes must be from RFC2616.");
119
					}
120
				}
121
				if (!isset($pconfig['options']['path']) || $pconfig['options']['path'] == "") {
122
					$input_errors[] = gettext("The path to monitor must be set.");
123
				}
124
			}
125
			break;
126
		}
127
		case 'send': {
128
			if (is_array($pconfig['options'])) {
129
				if (isset($pconfig['options']['send']) && $pconfig['options']['send'] != "") {
130
					// Check send
131
				}
132
				if (isset($pconfig['options']['expect']) && $pconfig['options']['expect'] != "") {
133
					// Check expect
134
				}
135
			}
136
			break;
137
		}
138
	}
139

    
140
	if (!$input_errors) {
141
		$monent = array();
142
		if(isset($id) && $a_monitor[$id])
143
			$monent = $a_monitor[$id];
144
		if($monent['name'] != "")
145
			$changedesc .= " " . sprintf(gettext("modified '%s' monitor:"), $monent['name']);
146
		
147
		update_if_changed("name", $monent['name'], $pconfig['name']);
148
		update_if_changed("type", $monent['type'], $pconfig['type']);
149
		update_if_changed("description", $monent['descr'], $pconfig['descr']);
150
		if($pconfig['type'] == "http" || $pconfig['type'] == "https" ) {
151
			/* log updates, then clear array and reassign - dumb, but easiest way to have a clear array */
152
			update_if_changed("path", $monent['options']['path'], $pconfig['options']['path']);
153
			update_if_changed("host", $monent['options']['host'], $pconfig['options']['host']);
154
			update_if_changed("code", $monent['options']['code'], $pconfig['options']['code']);
155
			$monent['options'] = array();
156
			$monent['options']['path'] = $pconfig['options']['path'];
157
			$monent['options']['host'] = $pconfig['options']['host'];
158
			$monent['options']['code'] = $pconfig['options']['code'];
159
		}
160
		if($pconfig['type'] == "send" ) {
161
			/* log updates, then clear array and reassign - dumb, but easiest way to have a clear array */
162
			update_if_changed("send", $monent['options']['send'], $pconfig['options']['send']);
163
			update_if_changed("expect", $monent['options']['expect'], $pconfig['options']['expect']);
164
			$monent['options'] = array();
165
			$monent['options']['send'] = $pconfig['options']['send'];
166
			$monent['options']['expect'] = $pconfig['options']['expect'];
167
		}
168
		if($pconfig['type'] == "tcp" || $pconfig['type'] == "icmp") {
169
			$monent['options'] = array();
170
		}
171

    
172
		if (isset($id) && $a_monitor[$id]) {
173
			/* modify all pools with this name */
174
			for ($i = 0; isset($config['load_balancer']['lbpool'][$i]); $i++) {
175
				if ($config['load_balancer']['lbpool'][$i]['monitor'] == $a_monitor[$id]['name'])
176
					$config['load_balancer']['lbpool'][$i]['monitor'] = $monent['name'];
177
			}
178
			$a_monitor[$id] = $monent;
179
		} else
180
			$a_monitor[] = $monent;
181
		
182
		if ($changecount > 0) {
183
			/* Mark config dirty */
184
			mark_subsystem_dirty('loadbalancer');
185
			write_config($changedesc);
186
		}
187

    
188
		header("Location: load_balancer_monitor.php");
189
		exit;
190
	}
191
}
192

    
193
$pgtitle = array(gettext("Services"),gettext("Load Balancer"),gettext("Monitor"),gettext("Edit"));
194
$shortcut_section = "relayd";
195

    
196
include("head.inc");
197
$types = array("icmp" => gettext("ICMP"), "tcp" => gettext("TCP"), "http" => gettext("HTTP"), "https" => gettext("HTTPS"), "send" => gettext("Send/Expect"));
198

    
199
?>
200

    
201
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
202
<?php include("fbegin.inc"); ?>
203
<script type="text/javascript">
204
//<![CDATA[
205
function updateType(t){
206
	switch(t) {
207
<?php
208
	/* OK, so this is sick using php to generate javascript, but it needed to be done */
209
	foreach ($types as $key => $val) {
210
		echo "		case \"{$key}\": {\n";
211
		$t = $types;
212
		foreach ($t as $k => $v) {
213
			if ($k != $key) {
214
				echo "			jQuery('#{$k}').hide();\n";
215
			}
216
		}
217
		echo "		}\n";
218
	}
219
?>
220
	}
221
	jQuery('#' + t).show();
222
}
223
//]]>
224
</script>
225

    
226
<?php if ($input_errors) print_input_errors($input_errors); ?>
227

    
228
	<form action="load_balancer_monitor_edit.php" method="post" name="iform" id="iform">
229
	<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="monitor entry">
230
 		<tr>
231
			<td colspan="2" valign="top" class="listtopic"><?=gettext("Edit Load Balancer - Monitor entry"); ?></td>
232
                </tr>
233
		<tr align="left">
234
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Name"); ?></td>
235
			<td width="78%" class="vtable" colspan="2">
236
				<input name="name" type="text" <?if(isset($pconfig['name'])) echo "value=\"" . htmlspecialchars($pconfig['name']) . "\"";?> size="16" maxlength="16" />
237
			</td>
238
		</tr>
239
		<tr align="left">
240
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Description"); ?></td>
241
			<td width="78%" class="vtable" colspan="2">
242
				<input name="descr" type="text" <?if(isset($pconfig['descr'])) echo "value=\"" . htmlspecialchars($pconfig['descr']) . "\"";?> size="64" />
243
			</td>
244
		</tr>
245
		<tr align="left">
246
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Type"); ?></td>
247
			<td width="78%" class="vtable" colspan="2">
248
				<select id="type" name="type">
249
<?
250
					foreach ($types as $key => $val) {
251
						if(isset($pconfig['type']) && $pconfig['type'] == $key) {
252
							$selected = " selected=\"selected\"";
253
						} else {
254
							$selected = "";
255
						}
256
						echo "<option value=\"{$key}\" onclick=\"updateType('{$key}');\"{$selected}>{$val}</option>\n";
257
					}
258
?>
259
				</select>
260
			</td>
261
		</tr>
262
		<tr align="left" id="icmp"<?= $pconfig['type'] == "icmp" ? "" : " style=\"display:none;\""?>><td></td>
263
		</tr>
264
		<tr align="left" id="tcp"<?= $pconfig['type'] == "tcp" ? "" : " style=\"display:none;\""?>><td></td>
265
		</tr>
266
		<tr align="left" id="http"<?= $pconfig['type'] == "http" ? "" : " style=\"display:none;\""?>>
267
			<td width="22%" valign="top" class="vncellreq"><?=gettext("HTTP"); ?></td>
268
			<td width="78%" class="vtable" colspan="2">
269
				<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="http">
270
					<tr align="left">
271
						<td valign="top" align="right" class="vtable"><?=gettext("Path"); ?></td>
272
						<td class="vtable" colspan="2">
273
							<input name="http_options_path" type="text" <?if(isset($pconfig['options']['path'])) echo "value=\"" . htmlspecialchars($pconfig['options']['path']) . "\"";?> size="64" />
274
						</td>
275
					</tr>
276
					<tr align="left">
277
						<td valign="top"  align="right" class="vtable"><?=gettext("Host"); ?></td>
278
						<td class="vtable" colspan="2">
279
							<input name="http_options_host" type="text" <?if(isset($pconfig['options']['host'])) echo "value=\"" . htmlspecialchars($pconfig['options']['host']) . "\"";?> size="64" /><br /><?=gettext("Hostname for Host: header if needed."); ?>
280
						</td>
281
					</tr>
282
					<tr align="left">
283
						<td valign="top"  align="right" class="vtable"><?=gettext("HTTP Code"); ?></td>
284
						<td class="vtable" colspan="2">
285
							<?= print_rfc2616_select("http_options_code", $pconfig['options']['code']); ?>
286
						</td>
287
					</tr>
288
<!-- BILLM: XXX not supported digest checking just yet
289
					<tr align="left">
290
						<td width="22%" valign="top" class="vncell">MD5 Page Digest</td>
291
						<td width="78%" class="vtable" colspan="2">
292
							<input name="digest" type="text" <?if(isset($pconfig['digest'])) echo "value=\"" . htmlspecialchars($pconfig['digest']) . "\"";?>size="32"><br /><b>TODO: add fetch functionality here</b>
293
						</td>
294
					</tr>
295
-->
296
				</table>
297
			</td>
298
		</tr>
299
		<tr align="left" id="https"<?= $pconfig['type'] == "https" ? "" : " style=\"display:none;\""?>>
300
			<td width="22%" valign="top" class="vncellreq"><?=gettext("HTTPS"); ?></td>
301
			<td width="78%" class="vtable" colspan="2">
302
				<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="https">
303
					<tr align="left">
304
						<td valign="top"  align="right" class="vtable"><?=gettext("Path"); ?></td>
305
						<td class="vtable" colspan="2">
306
							<input name="https_options_path" type="text" <?if(isset($pconfig['options']['path'])) echo "value=\"" . htmlspecialchars($pconfig['options']['path']) ."\"";?> size="64" />
307
						</td>
308
					</tr>
309
					<tr align="left">
310
						<td valign="top"  align="right" class="vtable"><?=gettext("Host"); ?></td>
311
						<td class="vtable" colspan="2">
312
							<input name="https_options_host" type="text" <?if(isset($pconfig['options']['host'])) echo "value=\"" . htmlspecialchars($pconfig['options']['host']) . "\"";?> size="64" /><br /><?=gettext("Hostname for Host: header if needed."); ?>
313
						</td>
314
					</tr>
315
					<tr align="left">
316
						<td valign="top"  align="right" class="vtable"><?=gettext("HTTP Code"); ?></td>
317
						<td class="vtable" colspan="2">
318
							<?= print_rfc2616_select("https_options_code", $pconfig['options']['code']); ?>
319
						</td>
320
					</tr>
321
<!-- BILLM: XXX not supported digest checking just yet
322

    
323
					<tr align="left">
324
						<td width="22%" valign="top" class="vncellreq">MD5 Page Digest</td>
325
						<td width="78%" class="vtable" colspan="2">
326
							<input name="digest" type="text" <?if(isset($pconfig['digest'])) echo "value=\"" . htmlspecialchars($pconfig['digest']) . "\"";?>size="32"><br /><b>TODO: add fetch functionality here</b>
327
						</td>
328
					</tr>
329
-->
330
				</table>
331
			</td>
332
		</tr>
333
		<tr align="left" id="send"<?= $pconfig['type'] == "send" ? "" : " style=\"display:none;\""?>>
334
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Send/Expect"); ?></td>
335
			<td width="78%" class="vtable" colspan="2">
336
				<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="send expect">
337
					<tr align="left">
338
						<td valign="top"  align="right" class="vtable"><?=gettext("Send string"); ?></td>
339
						<td class="vtable" colspan="2">
340
							<input name="send_options_send" type="text" <?if(isset($pconfig['options']['send'])) echo "value=\"" . htmlspecialchars($pconfig['options']['send']) . "\"";?> size="64" />
341
						</td>
342
					</tr>
343
					<tr align="left">
344
						<td valign="top" align="right"  class="vtable"><?=gettext("Expect string"); ?></td>
345
						<td class="vtable" colspan="2">
346
							<input name="send_options_expect" type="text" <?if(isset($pconfig['options']['expect'])) echo "value=\"" . htmlspecialchars($pconfig['options']['expect']) . "\"";?> size="64" />
347
						</td>
348
					</tr>
349
				</table>
350
			</td>
351
		</tr>
352
		<tr align="left">
353
			<td width="22%" valign="top">&nbsp;</td>
354
			<td width="78%">
355
				<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save"); ?>" /><input type="button" class="formbtn" value="<?=gettext("Cancel"); ?>" onclick="history.back()" />
356
				<?php if (isset($id) && $a_monitor[$id]): ?>
357
				<input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" />
358
				<?php endif; ?>
359
			</td>
360
		</tr>
361
	</table>
362
	</form>
363
<br />
364
<?php include("fend.inc"); ?>
365
</body>
366
</html>
(116-116/255)