Project

General

Profile

Download (19.6 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php 
2
/* $Id$ */
3
/*
4
	system_gateways_edit.php
5
	part of pfSense (http://pfsense.com)
6
	
7
	Copyright (C) 2010 Seth Mos <seth.mos@dds.nl>.
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-system-gateways-editgateway
37
##|*NAME=System: Gateways: Edit Gateway page
38
##|*DESCR=Allow access to the 'System: Gateways: Edit Gateway' page.
39
##|*MATCH=system_gateways_edit.php*
40
##|-PRIV
41

    
42
require("guiconfig.inc");
43
require("pkg-utils.inc");
44

    
45
$a_gateways = return_gateways_array(true);
46
$a_gateways_arr = array();
47
foreach($a_gateways as $gw) {
48
	$a_gateways_arr[] = $gw;
49
}
50
$a_gateways = $a_gateways_arr;
51

    
52
if (!is_array($config['gateways']['gateway_item']))
53
        $config['gateways']['gateway_item'] = array();
54
        
55
$a_gateway_item = &$config['gateways']['gateway_item'];
56

    
57
$id = $_GET['id'];
58
if (isset($_POST['id']))
59
	$id = $_POST['id'];
60

    
61
if (isset($_GET['dup'])) {
62
	$id = $_GET['dup'];
63
}
64

    
65
if (isset($id) && $a_gateways[$id]) {
66
	$pconfig = array();
67
	$pconfig['name'] = $a_gateways[$id]['name'];
68
	$pconfig['weight'] = $a_gateways[$id]['weight'];
69
	$pconfig['interface'] = $a_gateways[$id]['interface'];
70
	$pconfig['friendlyiface'] = $a_gateways[$id]['friendlyiface'];
71
	if (isset($a_gateways[$id]['dynamic']))
72
		$pconfig['dynamic'] = true;
73
	$pconfig['gateway'] = $a_gateways[$id]['gateway'];
74
	$pconfig['defaultgw'] = isset($a_gateways[$id]['defaultgw']);
75
	$pconfig['latencylow'] = $a_gateway_item[$id]['latencylow'];
76
        $pconfig['latencyhigh'] = $a_gateway_item[$id]['latencyhigh'];
77
        $pconfig['losslow'] = $a_gateway_item[$id]['losslow'];
78
        $pconfig['losshigh'] = $a_gateway_item[$id]['losshigh'];
79
        $pconfig['down'] = $a_gateway_item[$id]['down'];
80
	$pconfig['monitor'] = $a_gateways[$id]['monitor'];
81
	$pconfig['descr'] = $a_gateways[$id]['descr'];
82
	$pconfig['attribute'] = $a_gateways[$id]['attribute'];
83
}
84

    
85
if (isset($_GET['dup'])) {
86
	unset($id);
87
	unset($pconfig['attribute']);
88
}
89

    
90
if ($_POST) {
91

    
92
	unset($input_errors);
93

    
94
	/* input validation */
95
	$reqdfields = explode(" ", "name interface");
96
	$reqdfieldsn = array(gettext("Name"), gettext("Interface"));
97

    
98
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
99

    
100
	if (! isset($_POST['name'])) {
101
		$input_errors[] = "A valid gateway name must be specified.";
102
	}
103
	if (! is_validaliasname($_POST['name'])) {
104
		$input_errors[] = gettext("The gateway name must not contain invalid characters.");
105
	}
106
	/* skip system gateways which have been automatically added */
107
	if (($_POST['gateway'] && (!is_ipaddr($_POST['gateway'])) && ($_POST['attribute'] != "system")) && ($_POST['gateway'] != "dynamic")) {
108
		$input_errors[] = gettext("A valid gateway IP address must be specified.");
109
	}
110

    
111
	if ($_POST['gateway'] && (is_ipaddr($_POST['gateway'])) && !$_REQUEST['isAjax']) {
112
		if (!empty($config['interfaces'][$_POST['interface']]['ipaddr'])) {
113
			if (is_ipaddr($config['interfaces'][$_POST['interface']]['ipaddr']) && (empty($_POST['gateway']) || $_POST['gateway'] == "dynamic"))
114
				$input_errors[] = gettext("Dynamic gateway values cannot be specified for interfaces with a static ip configuration.");
115
		}
116
		$parent_ip = get_interface_ip($_POST['interface']);
117
		if (is_ipaddr($parent_ip)) {
118
			$parent_sn = get_interface_subnet($_POST['interface']);
119
			if(!ip_in_subnet($_POST['gateway'], gen_subnet($parent_ip, $parent_sn) . "/" . $parent_sn)) {
120
				$input_errors[] = sprintf(gettext("The gateway address %s does not lie within the chosen interface's subnet."), $_POST['gateway']);
121
			}
122
		}
123
	}
124
	if (($_POST['monitor'] <> "") && !is_ipaddr($_POST['monitor']) && $_POST['monitor'] != "dynamic") {
125
		$input_errors[] = gettext("A valid monitor IP address must be specified.");
126
	}
127

    
128
	if (isset($_POST['name'])) {
129
		/* check for overlaps */
130
		foreach ($a_gateways as $gateway) {
131
			if (isset($id) && ($a_gateways[$id]) && ($a_gateways[$id] === $gateway)) {
132
				if ($gateway['name'] != $_POST['name'])
133
					$input_errors[] = gettext("Changing name on a gateway is not allowed because it can leave stale gateways around.");
134
				continue;
135
			}
136
			if($_POST['name'] <> "") {
137
				if (($gateway['name'] <> "") && ($_POST['name'] == $gateway['name']) && ($gateway['attribute'] != "system")) {
138
					$input_errors[] = sprintf(gettext('The gateway name "%s" already exists.'), $_POST['name']);
139
					break;
140
				}
141
			}
142
			if(is_ipaddr($_POST['gateway'])) {
143
				if (($gateway['gateway'] <> "") && ($_POST['gateway'] == $gateway['gateway']) && ($gateway['attribute'] != "system")) {
144
					$input_errors[] = sprintf(gettext('The gateway IP address "%s" already exists.'), $_POST['gateway']);
145
					break;
146
				}
147
			}
148
			if(is_ipaddr($_POST['monitor'])) {
149
				if (($gateway['monitor'] <> "") && ($_POST['monitor'] == $gateway['monitor']) && ($gateway['attribute'] != "system")) {
150
					$input_errors[] = sprintf(gettext('The monitor IP address "%s" is already in use. You must choose a different monitor IP.'), $_POST['monitor']);
151
					break;
152
				}
153
			}
154
		}
155
	}
156

    
157
	/* input validation */
158
        if($_POST['latencylow']) {
159
                if (! is_numeric($_POST['latencylow'])) {
160
                        $input_errors[] = gettext("The low latency watermark needs to be a numeric value.");
161
                }
162
        }
163

    
164
        if($_POST['latencyhigh']) {
165
                if (! is_numeric($_POST['latencyhigh'])) {
166
                        $input_errors[] = gettext("The high latency watermark needs to be a numeric value.");
167
                }
168
        }
169
        if($_POST['losslow']) {
170
                if (! is_numeric($_POST['losslow'])) {
171
                        $input_errors[] = gettext("The low loss watermark needs to be a numeric value.");
172
                }
173
        }
174
        if($_POST['losshigh']) {
175
                if (! is_numeric($_POST['losshigh'])) {
176
                        $input_errors[] = gettext("The high loss watermark needs to be a numeric value.");
177
                }
178
        }
179

    
180
        if(($_POST['latencylow']) && ($_POST['latencyhigh'])){
181
                if(($_POST['latencylow'] > $_POST['latencyhigh'])) {
182
                        $input_errors[] = gettext("The High latency watermark needs to be higher then the low latency watermark");
183
                }
184
        }
185

    
186
        if(($_POST['losslow']) && ($_POST['losshigh'])){
187
                if($_POST['losslow'] > $_POST['losshigh']) {
188
                        $input_errors[] = gettext("The High packet loss watermark needs to be higher then the low packet loss watermark");
189
                }
190
        }
191
	if($_POST['down']) {
192
                if (! is_numeric($_POST['down']) || $_POST['down'] < 1) {
193
                        $input_errors[] = gettext("The low latency watermark needs to be a numeric value.");
194
                }
195
        }
196

    
197
	if (!$input_errors) {
198
		if (!(($_POST['weight'] && $_POST['weight'] > 1) || $_POST['latencylow'] || $_POST['latencyhigh'] ||
199
		    $_POST['losslow'] || $_POST['losshigh'] || $_POST['down'] ||
200
		    (empty($_POST['monitor']) || (!empty($_POST['gateway']) && $_POST['gateway'] != "dynamic")) ||
201
		    (empty($_POST['monitor']) || (!empty($_POST['monitor']) && $_POST['monitor'] != "dynamic")))) {
202
			if (isset($id) && $a_gateway_item[$id])
203
				unset($a_gateway_item[$id]);
204
			write_config();
205
			header("Location: system_gateways.php");
206
			exit;
207
		}
208

    
209

    
210
		$reloadif = false;
211
		$gateway = array();
212

    
213
		if (empty($_POST['interface']))
214
			$gateway['interface'] = $pconfig['friendlyiface'];
215
		else
216
			$gateway['interface'] = $_POST['interface'];
217
		if (is_ipaddr($_POST['gateway']))
218
			$gateway['gateway'] = $_POST['gateway'];
219
		else
220
			$gateway['gateway'] = "dynamic";
221
		$gateway['name'] = $_POST['name'];
222
		$gateway['weight'] = $_POST['weight'];
223
		$gateway['descr'] = $_POST['descr'];
224
		if (is_ipaddr($_POST['monitor']))
225
			$gateway['monitor'] = $_POST['monitor'];
226

    
227
		if ($_POST['defaultgw'] == "yes" || $_POST['defaultgw'] == "on") {
228
			$reloadif = true;
229
			$i = 0;
230
			foreach($a_gateway_item as $gw_item_id => $gw) {
231
				unset($config['gateways']['gateway_item'][$i]['defaultgw']);
232
				/* if true $gw is the *saved* gateway config data and 
233
				* we don't need to reload if this GW interface didn't change AND this GW was already default */
234
				if (isset($id) && $gw_item_id == $id) 
235
					if ($gw['interface'] == $_POST['interface'] && isset($gw['defaultgw']) )
236
						$reloadif = false;
237
				$i++;
238
			}
239
			$gateway['defaultgw'] = true;
240
		}
241

    
242
		if ($_POST['latencylow'])
243
			$gateway['latencylow'] = $_POST['latencylow'];
244
		if ($_POST['latencyhigh'])
245
               		$gateway['latencyhigh'] = $_POST['latencyhigh'];
246
		if ($_POST['losslow'])
247
              			$gateway['losslow'] = $_POST['losslow'];
248
		if ($_POST['losshigh'])
249
               		$gateway['losshigh'] = $_POST['losshigh'];
250
		if ($_POST['down'])
251
               		$gateway['down'] = $_POST['down'];
252

    
253
		/* when saving the manual gateway we use the attribute which has the corresponding id */
254
		if (isset($id) && $a_gateway_item[$id])
255
			$a_gateway_item[$id] = $gateway;
256
		else
257
			$a_gateway_item[] = $gateway;
258

    
259
		mark_subsystem_dirty('staticroutes');
260
	
261
		write_config();
262

    
263
		if($_REQUEST['isAjax']) {
264
			echo $_POST['name'];
265
			exit;
266
		} else if ($reloadif == true)
267
			send_event("interface reconfigure {$_POST['interface']}");
268
		
269
		header("Location: system_gateways.php");
270
		exit;
271
	} else {
272
		$pconfig = $_POST;
273
		if (empty($_POST['friendlyiface']))
274
			$pconfig['friendlyiface'] = $_POST['interface'];
275
	}
276
}
277

    
278

    
279
$pgtitle = array(gettext("System"),gettext("Gateways"),gettext("Edit gateway"));
280
$statusurl = "status_gateways.php";
281

    
282
include("head.inc");
283

    
284
?>
285

    
286
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
287
<?php include("fbegin.inc"); ?>
288
<script language="JavaScript">
289
function show_advanced_gateway() {
290
        document.getElementById("showadvgatewaybox").innerHTML='';
291
        aodiv = document.getElementById('showgatewayadv');
292
        aodiv.style.display = "block";
293
}
294
</script>
295
<?php if ($input_errors) print_input_errors($input_errors); ?>
296
            <form action="system_gateways_edit.php" method="post" name="iform" id="iform">
297
	<?php
298

    
299
	/* If this is a system gateway we need this var */
300
	if(($pconfig['attribute'] == "system") || is_numeric($pconfig['attribute'])) {
301
		echo "<input type='hidden' name='attribute' id='attribute' value='{$pconfig['attribute']}' >\n";
302
	}
303
	echo "<input type='hidden' name='friendlyiface' id='friendlyiface' value='{$pconfig['friendlyiface']}' >\n";
304
	?>
305
              <table width="100%" border="0" cellpadding="6" cellspacing="0">
306
				<tr>
307
					<td colspan="2" valign="top" class="listtopic"><?=gettext("Edit gateway"); ?></td>
308
				</tr>	
309
                <tr> 
310
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("Interface"); ?></td>
311
                  <td width="78%" class="vtable">
312
		 	<select name='interface' class='formselect' >
313

    
314
		<?php 
315
                      	$interfaces = get_configured_interface_with_descr(false, true);
316
			foreach ($interfaces as $iface => $ifacename) {
317
				echo "<option value=\"{$iface}\"";
318
				if ($iface == $pconfig['friendlyiface'])
319
					echo " selected";
320
				echo ">" . htmlspecialchars($ifacename) . "</option>";
321
			}
322
			if (is_package_installed("openbgpd") == 1) {
323
				echo "<option value=\"bgpd\"";
324
				if ($pconfig['interface'] == "bgpd") 
325
					echo " selected";
326
				echo ">" . gettext("Use BGPD") . "</option>";
327
			}
328
 		  ?>
329
                    </select> <br>
330
                    <span class="vexpl"><?=gettext("Choose which interface this gateway applies to."); ?></span></td>
331
                </tr>
332
                <tr>
333
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("Name"); ?></td>
334
                  <td width="78%" class="vtable"> 
335
                    <input name="name" type="text" class="formfld unknown" id="name" size="20" value="<?=htmlspecialchars($pconfig['name']);?>"> 
336
                    <br> <span class="vexpl"><?=gettext("Gateway name"); ?></span></td>
337
                </tr>
338
		<tr>
339
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("Gateway"); ?></td>
340
                  <td width="78%" class="vtable"> 
341
                    <input name="gateway" type="text" class="formfld host" id="gateway" size="40" value="<?php if ($pconfig['dynamic']) echo "dynamic"; else echo $pconfig['gateway']; ?>">
342
                    <br> <span class="vexpl"><?=gettext("Gateway IP address"); ?></span></td>
343
                </tr>
344
		<tr>
345
		  <td width="22%" valign="top" class="vncell"><?=gettext("Default Gateway"); ?></td>
346
		  <td width="78%" class="vtable">
347
			<input name="defaultgw" type="checkbox" id="defaultgw" value="yes" <?php if ($pconfig['defaultgw'] == true) echo "checked"; ?> />
348
			<strong><?=gettext("Default Gateway"); ?></strong><br />
349
			<?=gettext("This will select the above gateway as the default gateway"); ?>
350
		  </td>
351
		</tr>
352
		<tr>
353
		  <td width="22%" valign="top" class="vncell"><?=gettext("Monitor IP"); ?></td>
354
		  <td width="78%" class="vtable">
355
			<?php
356
				if ($pconfig['gateway'] == $pconfig['monitor'])
357
					$monitor = "";
358
				else
359
					$monitor = htmlspecialchars($pconfig['monitor']);
360
			?>
361
			<input name="monitor" type="text" id="monitor" value="<?php echo $monitor; ?>" />
362
			<strong><?=gettext("Alternative monitor IP"); ?></strong> <br />
363
			<?=gettext("Enter an alternative address here to be used to monitor the link. This is used for the " .
364
			"quality RRD graphs as well as the load balancer entries. Use this if the gateway does not respond " .
365
			"to ICMP echo requests (pings)"); ?>.</strong>
366
			<br />
367
		  </td>
368
		</tr>
369
		<tr>
370
		  <td width="22%" valign="top" class="vncell"><?=gettext("Advanced");?></td>
371
		  <td width="78%" class="vtable">
372
			<div id="showadvgatewaybox" <? if (!empty($pconfig['latencylow']) || !empty($pconfig['latencyhigh']) || !empty($pconfig['losslow']) || !empty($pconfig['losshigh']) || (isset($pconfig['weight']) && $pconfig['weight'] > 1)) echo "style='display:none'"; ?>>
373
				<input type="button" onClick="show_advanced_gateway()" value="Advanced"></input> - Show advanced option</a>
374
			</div>
375
			<div id="showgatewayadv" <? if (empty($pconfig['latencylow']) && empty($pconfig['latencyhigh']) && empty($pconfig['losslow']) && empty($pconfig['losshigh']) && (empty($pconfig['weight']) || $pconfig['weight'] == 1)) echo "style='display:none'"; ?>>
376
                        <table class="tabcont" width="100%" border="0" cellspacing="0" cellpadding="6">
377
			<tr>
378
                                <td width="22%" valign="top" class="vncellreq"><?=gettext("Weight");?></td>
379
                                <td width="78%" class="vtable">
380
					<select name='weight' class='formfldselect' id='weight'>
381
				<?php
382
					for ($i = 1; $i < 6; $i++) {
383
                                        	$selected = "";
384
                                        	if ($pconfig['weight'] == $i)
385
                                                	$selected = "selected";
386
                                        	echo "<option value='{$i}' {$selected} >{$i}</option>";
387
                                	}
388
				?>
389
					</select>
390
					<br /><?=gettext("Weight for this gateway when used in a Gateway Group.");?> <br />
391
		   		</td>
392
			</tr>
393
                        <tr>
394
                                <td width="22%" valign="top" class="vncellreq"><?=gettext("Latency thresholds");?></td>
395
                                <td width="78%" class="vtable">
396
                                <?=gettext("From");?>
397
                                    <input name="latencylow" type="text" class="formfld unknown" id="latencylow" size="2"
398
                                        value="<?=htmlspecialchars($pconfig['latencylow']);?>">
399
                                <?=gettext("To");?>
400
                                    <input name="latencyhigh" type="text" class="formfld unknown" id="latencyhigh" size="2"
401
                                        value="<?=htmlspecialchars($pconfig['latencyhigh']);?>">
402
                                    <br> <span class="vexpl"><?=gettext("These define the low and high water marks for latency in milliseconds.");?></span></td>
403
                                </td>
404
                        </tr>
405
                        <tr>
406
                                <td width="22%" valign="top" class="vncellreq"><?=gettext("Packet Loss thresholds");?></td>
407
                                <td width="78%" class="vtable">
408
                                <?=gettext("From");?>
409
                                    <input name="losslow" type="text" class="formfld unknown" id="losslow" size="2"
410
                                        value="<?=htmlspecialchars($pconfig['losslow']);?>">
411
                                <?=gettext("To");?>
412
                                    <input name="losshigh" type="text" class="formfld unknown" id="losshigh" size="2"
413
                                        value="<?=htmlspecialchars($pconfig['losshigh']);?>">
414
                                    <br> <span class="vexpl"><?=gettext("These define the low and high water marks for packet loss in %.");?></span></td>
415
                                </td>
416
                        </tr>
417
			<tr>
418
                                <td width="22%" valign="top" class="vncellreq"><?=gettext("Down");?></td>
419
                                <td width="78%" class="vtable">
420
                                    <input name="down" type="text" class="formfld unknown" id="down" size="2"
421
                                        value="<?=htmlspecialchars($pconfig['down']);?>">
422
                                    <br> <span class="vexpl"><?=gettext("This defines the down time for the alarm to fire, in seconds.");?></span></td>
423
                                </td>
424
                        </tr>
425
                        </table>
426
			</div>
427
		   </td>
428
		</tr>
429
		<tr>
430
                  <td width="22%" valign="top" class="vncell"><?=gettext("Description"); ?></td>
431
                  <td width="78%" class="vtable"> 
432
                    <input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>">
433
                    <br> <span class="vexpl"><?=gettext("You may enter a description here for your reference (not parsed)"); ?>.</span></td>
434
                </tr>
435
                <tr>
436
                  <td width="22%" valign="top">&nbsp;</td>
437
                  <td width="78%"> 
438
                    <input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save");?>"> <input type="button" value="<?=gettext("Cancel");?>" class="formbtn"  onclick="history.back()">
439
                    <?php if (isset($id) && $a_gateways[$id]): ?>
440
                    <input name="id" type="hidden" value="<?=$id;?>">
441
                    <?php endif; ?>
442
                  </td>
443
                </tr>
444
              </table>
445
</form>
446
<?php include("fend.inc"); ?>
447
<script language="JavaScript">
448
enable_change(document.iform.defaultgw);
449
</script>
450
</body>
451
</html>
(189-189/220)