Project

General

Profile

Feature #3859 » system_gateways_edit.php.patch

User interface to set the srcip option for gateways - Patrick Bihan-Faou, 09/11/2014 09:40 AM

View differences:

/usr/local/www/system_gateways_edit.php 2014-09-11 10:55:23.000000000 +0200
84 84
	$pconfig['monitor_disable'] = isset($a_gateways[$id]['monitor_disable']);
85 85
	$pconfig['descr'] = $a_gateways[$id]['descr'];
86 86
	$pconfig['attribute'] = $a_gateways[$id]['attribute'];
87
	$pconfig['srcip'] = $a_gateways[$id]['srcip'];
87 88
}
88 89

  
89 90
if (isset($_GET['dup']) && is_numericint($_GET['dup'])) {
......
184 185
	if (($_POST['monitor'] <> "") && !is_ipaddr($_POST['monitor']) && $_POST['monitor'] != "dynamic") {
185 186
		$input_errors[] = gettext("A valid monitor IP address must be specified.");
186 187
	}
188
	if (($_POST['srcip'] <> "") && !is_ipaddr($_POST['srcip'])) {
189
		$input_errors[] = gettext("A valid source IP address must be specified.");
190
	}
187 191
	/* only allow correct IPv4 and IPv6 gateway addresses */
188 192
	if (($_POST['gateway'] <> "") && is_ipaddr($_POST['gateway']) && $_POST['gateway'] != "dynamic") {
189 193
		if(is_ipaddrv6($_POST['gateway']) && ($_POST['ipprotocol'] == "inet")) {
......
202 206
			$input_errors[] = gettext("The IPv4 monitor address '{$_POST['monitor']}' can not be used on a IPv6 gateway'.");
203 207
		}
204 208
	}
209
	/* only allow correct IPv4 and IPv6 source ip addresses */
210
	if (($_POST['srcip'] <> "") && is_ipaddr($_POST['srcip'])) {
211
		if(is_ipaddrv6($_POST['srcip']) && ($_POST['ipprotocol'] == "inet")) {
212
			$input_errors[] = gettext("The IPv6 source IP address '{$_POST['srcip']}' can not be used on a IPv4 gateway'.");
213
		}
214
		if(is_ipaddrv4($_POST['srcip']) && ($_POST['ipprotocol'] == "inet6")) {
215
			$input_errors[] = gettext("The IPv4 source IP address '{$_POST['srcip']}' can not be used on a IPv6 gateway'.");
216
		}
217
	}
205 218

  
206 219
	if (isset($_POST['name'])) {
207 220
		/* check for overlaps */
......
389 402
			$gateway['monitor_disable'] = true;
390 403
		if (is_ipaddr($_POST['monitor']))
391 404
			$gateway['monitor'] = $_POST['monitor'];
405
		if (is_ipaddr($_POST['srcip']))
406
			$gateway['srcip'] = $_POST['srcip'];
392 407

  
393 408
		/* NOTE: If monitor ip is changed need to cleanup the old static route */
394 409
		if ($_POST['monitor'] != "dynamic" && !empty($a_gateway_item[$realid]) && is_ipaddr($a_gateway_item[$realid]['monitor']) &&
......
576 591
				</td>
577 592
			</tr>
578 593
			<tr>
594
				<td width="22%" valign="top" class="vncell"><?=gettext("Source IP"); ?></td>
595
				<td width="78%" class="vtable">
596
					<?php
597
						$srcip = htmlspecialchars($pconfig['srcip']);
598
					?>
599
					<input name="srcip" type="text" id="srcip" value="<?php echo htmlspecialchars($srcip); ?>" size="28" />
600
					<strong><?=gettext("Alternative source IP"); ?></strong> <br />
601
					<?=gettext("Enter an alternative address here to be used as the source IP to monitor the link. " .
602
					"This may be required if there are many IP addresses on an interface to ensure that the correct " .
603
					"source IP address is selected to ping the monitor/gateway"); ?>.
604
					<br />
605
				</td>
606
			</tr>
607
			<tr>
579 608
				<td width="22%" valign="top" class="vncell"><?=gettext("Advanced");?></td>
580 609
				<td width="78%" class="vtable">
581 610
					<?php $showbutton = (!empty($pconfig['latencylow']) || !empty($pconfig['latencyhigh']) || !empty($pconfig['losslow']) || !empty($pconfig['losshigh']) || (isset($pconfig['weight']) && $pconfig['weight'] > 1) || (isset($pconfig['interval']) && ($pconfig['interval'] > $apinger_default['interval'])) || (isset($pconfig['down']) && !($pconfig['down'] == $apinger_default['down']))); ?>
(2-2/2)