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
|
$referer = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/load_balancer_monitor.php');
|
45
|
|
46
|
if (!is_array($config['load_balancer']['monitor_type'])) {
|
47
|
$config['load_balancer']['monitor_type'] = array();
|
48
|
}
|
49
|
$a_monitor = &$config['load_balancer']['monitor_type'];
|
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_monitor[$id]) {
|
57
|
$pconfig['name'] = $a_monitor[$id]['name'];
|
58
|
$pconfig['type'] = $a_monitor[$id]['type'];
|
59
|
$pconfig['descr'] = $a_monitor[$id]['descr'];
|
60
|
$pconfig['options'] = array();
|
61
|
$pconfig['options'] = $a_monitor[$id]['options'];
|
62
|
} else {
|
63
|
/* Some sane page defaults */
|
64
|
$pconfig['options']['path'] = '/';
|
65
|
$pconfig['options']['code'] = 200;
|
66
|
}
|
67
|
|
68
|
$changedesc = gettext("Load Balancer: Monitor:") . " ";
|
69
|
$changecount = 0;
|
70
|
|
71
|
if ($_POST) {
|
72
|
$changecount++;
|
73
|
|
74
|
unset($input_errors);
|
75
|
$pconfig = $_POST;
|
76
|
|
77
|
/* turn $_POST['http_options_*'] into $pconfig['options'][*] */
|
78
|
foreach($_POST as $key => $val) {
|
79
|
if (stristr($key, 'options') !== false) {
|
80
|
if (stristr($key, $pconfig['type'].'_') !== false) {
|
81
|
$opt = explode('_',$key);
|
82
|
$pconfig['options'][$opt[2]] = $val;
|
83
|
}
|
84
|
unset($pconfig[$key]);
|
85
|
}
|
86
|
}
|
87
|
|
88
|
/* input validation */
|
89
|
$reqdfields = explode(" ", "name type descr");
|
90
|
$reqdfieldsn = array(gettext("Name"),gettext("Type"),gettext("Description"));
|
91
|
|
92
|
do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
|
93
|
|
94
|
/* Ensure that our monitor names are unique */
|
95
|
for ($i=0; isset($config['load_balancer']['monitor_type'][$i]); $i++)
|
96
|
if (($_POST['name'] == $config['load_balancer']['monitor_type'][$i]['name']) && ($i != $id))
|
97
|
$input_errors[] = gettext("This monitor name has already been used. Monitor names must be unique.");
|
98
|
|
99
|
if (strpos($_POST['name'], " ") !== false)
|
100
|
$input_errors[] = gettext("You cannot use spaces in the 'name' field.");
|
101
|
|
102
|
switch($_POST['type']) {
|
103
|
case 'icmp': {
|
104
|
break;
|
105
|
}
|
106
|
case 'tcp': {
|
107
|
break;
|
108
|
}
|
109
|
case 'http':
|
110
|
case 'https': {
|
111
|
if (is_array($pconfig['options'])) {
|
112
|
if (isset($pconfig['options']['host']) && $pconfig['options']['host'] != "") {
|
113
|
if (!is_hostname($pconfig['options']['host'])) {
|
114
|
$input_errors[] = gettext("The hostname can only contain the characters A-Z, 0-9 and '-'.");
|
115
|
}
|
116
|
}
|
117
|
if (isset($pconfig['options']['code']) && $pconfig['options']['code'] != "") {
|
118
|
// Check code
|
119
|
if(!is_rfc2616_code($pconfig['options']['code'])) {
|
120
|
$input_errors[] = gettext("HTTP(s) codes must be from RFC2616.");
|
121
|
}
|
122
|
}
|
123
|
if (!isset($pconfig['options']['path']) || $pconfig['options']['path'] == "") {
|
124
|
$input_errors[] = gettext("The path to monitor must be set.");
|
125
|
}
|
126
|
}
|
127
|
break;
|
128
|
}
|
129
|
case 'send': {
|
130
|
if (is_array($pconfig['options'])) {
|
131
|
if (isset($pconfig['options']['send']) && $pconfig['options']['send'] != "") {
|
132
|
// Check send
|
133
|
}
|
134
|
if (isset($pconfig['options']['expect']) && $pconfig['options']['expect'] != "") {
|
135
|
// Check expect
|
136
|
}
|
137
|
}
|
138
|
break;
|
139
|
}
|
140
|
}
|
141
|
|
142
|
if (!$input_errors) {
|
143
|
$monent = array();
|
144
|
if(isset($id) && $a_monitor[$id])
|
145
|
$monent = $a_monitor[$id];
|
146
|
if($monent['name'] != "")
|
147
|
$changedesc .= " " . sprintf(gettext("modified '%s' monitor:"), $monent['name']);
|
148
|
|
149
|
update_if_changed("name", $monent['name'], $pconfig['name']);
|
150
|
update_if_changed("type", $monent['type'], $pconfig['type']);
|
151
|
update_if_changed("description", $monent['descr'], $pconfig['descr']);
|
152
|
if($pconfig['type'] == "http" || $pconfig['type'] == "https" ) {
|
153
|
/* log updates, then clear array and reassign - dumb, but easiest way to have a clear array */
|
154
|
update_if_changed("path", $monent['options']['path'], $pconfig['options']['path']);
|
155
|
update_if_changed("host", $monent['options']['host'], $pconfig['options']['host']);
|
156
|
update_if_changed("code", $monent['options']['code'], $pconfig['options']['code']);
|
157
|
$monent['options'] = array();
|
158
|
$monent['options']['path'] = $pconfig['options']['path'];
|
159
|
$monent['options']['host'] = $pconfig['options']['host'];
|
160
|
$monent['options']['code'] = $pconfig['options']['code'];
|
161
|
}
|
162
|
if($pconfig['type'] == "send" ) {
|
163
|
/* log updates, then clear array and reassign - dumb, but easiest way to have a clear array */
|
164
|
update_if_changed("send", $monent['options']['send'], $pconfig['options']['send']);
|
165
|
update_if_changed("expect", $monent['options']['expect'], $pconfig['options']['expect']);
|
166
|
$monent['options'] = array();
|
167
|
$monent['options']['send'] = $pconfig['options']['send'];
|
168
|
$monent['options']['expect'] = $pconfig['options']['expect'];
|
169
|
}
|
170
|
if($pconfig['type'] == "tcp" || $pconfig['type'] == "icmp") {
|
171
|
$monent['options'] = array();
|
172
|
}
|
173
|
|
174
|
if (isset($id) && $a_monitor[$id]) {
|
175
|
/* modify all pools with this name */
|
176
|
for ($i = 0; isset($config['load_balancer']['lbpool'][$i]); $i++) {
|
177
|
if ($config['load_balancer']['lbpool'][$i]['monitor'] == $a_monitor[$id]['name'])
|
178
|
$config['load_balancer']['lbpool'][$i]['monitor'] = $monent['name'];
|
179
|
}
|
180
|
$a_monitor[$id] = $monent;
|
181
|
} else
|
182
|
$a_monitor[] = $monent;
|
183
|
|
184
|
if ($changecount > 0) {
|
185
|
/* Mark config dirty */
|
186
|
mark_subsystem_dirty('loadbalancer');
|
187
|
write_config($changedesc);
|
188
|
}
|
189
|
|
190
|
header("Location: load_balancer_monitor.php");
|
191
|
exit;
|
192
|
}
|
193
|
}
|
194
|
|
195
|
$pgtitle = array(gettext("Services"),gettext("Load Balancer"),gettext("Monitor"),gettext("Edit"));
|
196
|
$shortcut_section = "relayd";
|
197
|
|
198
|
include("head.inc");
|
199
|
$types = array("icmp" => gettext("ICMP"), "tcp" => gettext("TCP"), "http" => gettext("HTTP"), "https" => gettext("HTTPS"), "send" => gettext("Send/Expect"));
|
200
|
|
201
|
?>
|
202
|
|
203
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
|
204
|
<?php include("fbegin.inc"); ?>
|
205
|
<script type="text/javascript">
|
206
|
//<![CDATA[
|
207
|
function updateType(t){
|
208
|
switch(t) {
|
209
|
<?php
|
210
|
/* OK, so this is sick using php to generate javascript, but it needed to be done */
|
211
|
foreach ($types as $key => $val) {
|
212
|
echo " case \"{$key}\": {\n";
|
213
|
$t = $types;
|
214
|
foreach ($t as $k => $v) {
|
215
|
if ($k != $key) {
|
216
|
echo " jQuery('#{$k}').hide();\n";
|
217
|
}
|
218
|
}
|
219
|
echo " }\n";
|
220
|
}
|
221
|
?>
|
222
|
}
|
223
|
jQuery('#' + t).show();
|
224
|
}
|
225
|
//]]>
|
226
|
</script>
|
227
|
|
228
|
<?php if ($input_errors) print_input_errors($input_errors); ?>
|
229
|
|
230
|
<form action="load_balancer_monitor_edit.php" method="post" name="iform" id="iform">
|
231
|
<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="monitor entry">
|
232
|
<tr>
|
233
|
<td colspan="2" valign="top" class="listtopic"><?=gettext("Edit Load Balancer - Monitor entry"); ?></td>
|
234
|
</tr>
|
235
|
<tr align="left">
|
236
|
<td width="22%" valign="top" class="vncellreq"><?=gettext("Name"); ?></td>
|
237
|
<td width="78%" class="vtable" colspan="2">
|
238
|
<input name="name" type="text" <?if(isset($pconfig['name'])) echo "value=\"" . htmlspecialchars($pconfig['name']) . "\"";?> size="16" maxlength="16" />
|
239
|
</td>
|
240
|
</tr>
|
241
|
<tr align="left">
|
242
|
<td width="22%" valign="top" class="vncellreq"><?=gettext("Description"); ?></td>
|
243
|
<td width="78%" class="vtable" colspan="2">
|
244
|
<input name="descr" type="text" <?if(isset($pconfig['descr'])) echo "value=\"" . htmlspecialchars($pconfig['descr']) . "\"";?> size="64" />
|
245
|
</td>
|
246
|
</tr>
|
247
|
<tr align="left">
|
248
|
<td width="22%" valign="top" class="vncellreq"><?=gettext("Type"); ?></td>
|
249
|
<td width="78%" class="vtable" colspan="2">
|
250
|
<select id="type" name="type">
|
251
|
<?
|
252
|
foreach ($types as $key => $val) {
|
253
|
if(isset($pconfig['type']) && $pconfig['type'] == $key) {
|
254
|
$selected = " selected=\"selected\"";
|
255
|
} else {
|
256
|
$selected = "";
|
257
|
}
|
258
|
echo "<option value=\"{$key}\" onclick=\"updateType('{$key}');\"{$selected}>{$val}</option>\n";
|
259
|
}
|
260
|
?>
|
261
|
</select>
|
262
|
</td>
|
263
|
</tr>
|
264
|
<tr align="left" id="icmp"<?= $pconfig['type'] == "icmp" ? "" : " style=\"display:none;\""?>><td></td>
|
265
|
</tr>
|
266
|
<tr align="left" id="tcp"<?= $pconfig['type'] == "tcp" ? "" : " style=\"display:none;\""?>><td></td>
|
267
|
</tr>
|
268
|
<tr align="left" id="http"<?= $pconfig['type'] == "http" ? "" : " style=\"display:none;\""?>>
|
269
|
<td width="22%" valign="top" class="vncellreq"><?=gettext("HTTP"); ?></td>
|
270
|
<td width="78%" class="vtable" colspan="2">
|
271
|
<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="http">
|
272
|
<tr align="left">
|
273
|
<td valign="top" align="right" class="vtable"><?=gettext("Path"); ?></td>
|
274
|
<td class="vtable" colspan="2">
|
275
|
<input name="http_options_path" type="text" <?if(isset($pconfig['options']['path'])) echo "value=\"" . htmlspecialchars($pconfig['options']['path']) . "\"";?> size="64" />
|
276
|
</td>
|
277
|
</tr>
|
278
|
<tr align="left">
|
279
|
<td valign="top" align="right" class="vtable"><?=gettext("Host"); ?></td>
|
280
|
<td class="vtable" colspan="2">
|
281
|
<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."); ?>
|
282
|
</td>
|
283
|
</tr>
|
284
|
<tr align="left">
|
285
|
<td valign="top" align="right" class="vtable"><?=gettext("HTTP Code"); ?></td>
|
286
|
<td class="vtable" colspan="2">
|
287
|
<?= print_rfc2616_select("http_options_code", $pconfig['options']['code']); ?>
|
288
|
</td>
|
289
|
</tr>
|
290
|
<!-- BILLM: XXX not supported digest checking just yet
|
291
|
<tr align="left">
|
292
|
<td width="22%" valign="top" class="vncell">MD5 Page Digest</td>
|
293
|
<td width="78%" class="vtable" colspan="2">
|
294
|
<input name="digest" type="text" <?if(isset($pconfig['digest'])) echo "value=\"" . htmlspecialchars($pconfig['digest']) . "\"";?>size="32"><br /><b>TODO: add fetch functionality here</b>
|
295
|
</td>
|
296
|
</tr>
|
297
|
-->
|
298
|
</table>
|
299
|
</td>
|
300
|
</tr>
|
301
|
<tr align="left" id="https"<?= $pconfig['type'] == "https" ? "" : " style=\"display:none;\""?>>
|
302
|
<td width="22%" valign="top" class="vncellreq"><?=gettext("HTTPS"); ?></td>
|
303
|
<td width="78%" class="vtable" colspan="2">
|
304
|
<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="https">
|
305
|
<tr align="left">
|
306
|
<td valign="top" align="right" class="vtable"><?=gettext("Path"); ?></td>
|
307
|
<td class="vtable" colspan="2">
|
308
|
<input name="https_options_path" type="text" <?if(isset($pconfig['options']['path'])) echo "value=\"" . htmlspecialchars($pconfig['options']['path']) ."\"";?> size="64" />
|
309
|
</td>
|
310
|
</tr>
|
311
|
<tr align="left">
|
312
|
<td valign="top" align="right" class="vtable"><?=gettext("Host"); ?></td>
|
313
|
<td class="vtable" colspan="2">
|
314
|
<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."); ?>
|
315
|
</td>
|
316
|
</tr>
|
317
|
<tr align="left">
|
318
|
<td valign="top" align="right" class="vtable"><?=gettext("HTTP Code"); ?></td>
|
319
|
<td class="vtable" colspan="2">
|
320
|
<?= print_rfc2616_select("https_options_code", $pconfig['options']['code']); ?>
|
321
|
</td>
|
322
|
</tr>
|
323
|
<!-- BILLM: XXX not supported digest checking just yet
|
324
|
|
325
|
<tr align="left">
|
326
|
<td width="22%" valign="top" class="vncellreq">MD5 Page Digest</td>
|
327
|
<td width="78%" class="vtable" colspan="2">
|
328
|
<input name="digest" type="text" <?if(isset($pconfig['digest'])) echo "value=\"" . htmlspecialchars($pconfig['digest']) . "\"";?>size="32"><br /><b>TODO: add fetch functionality here</b>
|
329
|
</td>
|
330
|
</tr>
|
331
|
-->
|
332
|
</table>
|
333
|
</td>
|
334
|
</tr>
|
335
|
<tr align="left" id="send"<?= $pconfig['type'] == "send" ? "" : " style=\"display:none;\""?>>
|
336
|
<td width="22%" valign="top" class="vncellreq"><?=gettext("Send/Expect"); ?></td>
|
337
|
<td width="78%" class="vtable" colspan="2">
|
338
|
<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="send expect">
|
339
|
<tr align="left">
|
340
|
<td valign="top" align="right" class="vtable"><?=gettext("Send string"); ?></td>
|
341
|
<td class="vtable" colspan="2">
|
342
|
<input name="send_options_send" type="text" <?if(isset($pconfig['options']['send'])) echo "value=\"" . htmlspecialchars($pconfig['options']['send']) . "\"";?> size="64" />
|
343
|
</td>
|
344
|
</tr>
|
345
|
<tr align="left">
|
346
|
<td valign="top" align="right" class="vtable"><?=gettext("Expect string"); ?></td>
|
347
|
<td class="vtable" colspan="2">
|
348
|
<input name="send_options_expect" type="text" <?if(isset($pconfig['options']['expect'])) echo "value=\"" . htmlspecialchars($pconfig['options']['expect']) . "\"";?> size="64" />
|
349
|
</td>
|
350
|
</tr>
|
351
|
</table>
|
352
|
</td>
|
353
|
</tr>
|
354
|
<tr align="left">
|
355
|
<td width="22%" valign="top"> </td>
|
356
|
<td width="78%">
|
357
|
<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save"); ?>" />
|
358
|
<input type="button" class="formbtn" value="<?=gettext("Cancel");?>" onclick="window.location.href='<?=$referer;?>'" />
|
359
|
<?php if (isset($id) && $a_monitor[$id]): ?>
|
360
|
<input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" />
|
361
|
<?php endif; ?>
|
362
|
</td>
|
363
|
</tr>
|
364
|
</table>
|
365
|
</form>
|
366
|
<br />
|
367
|
<?php include("fend.inc"); ?>
|
368
|
</body>
|
369
|
</html>
|