Project

General

Profile

« Previous | Next » 

Revision 23d9f686

Added by Renato Botelho over 11 years ago

Fix an issue that changes wrong gateway entry when items are hidden

View differences:

etc/inc/gwlb.inc
372 372
	$interfaces_v4 = array();
373 373
	$interfaces_v6 = array();
374 374

  
375
	$i = 0;
375
	$i = -1;
376 376
	/* Process/add all the configured gateways. */
377 377
	if (is_array($config['gateways']['gateway_item'])) {
378 378
		foreach ($config['gateways']['gateway_item'] as $gateway) {
379
			/* Increment it here to do not skip items */
380
			$i++;
381

  
379 382
			if (empty($config['interfaces'][$gateway['interface']]))
380 383
				continue;
381 384
			$wancfg = $config['interfaces'][$gateway['interface']];
......
445 448
			$gateway['attribute'] = $i;
446 449

  
447 450
			$gateways_arr[$gateway['name']] = $gateway;
448
			$i++;
449 451
		}
450 452
	}
451 453
	unset($gateway);
usr/local/www/system_gateways_edit.php
75 75
		$pconfig['dynamic'] = true;
76 76
	$pconfig['gateway'] = $a_gateways[$id]['gateway'];
77 77
	$pconfig['defaultgw'] = isset($a_gateways[$id]['defaultgw']);
78
	$pconfig['latencylow'] = $a_gateway_item[$id]['latencylow'];
79
	$pconfig['latencyhigh'] = $a_gateway_item[$id]['latencyhigh'];
80
	$pconfig['losslow'] = $a_gateway_item[$id]['losslow'];
81
	$pconfig['losshigh'] = $a_gateway_item[$id]['losshigh'];
82
	$pconfig['down'] = $a_gateway_item[$id]['down'];
78
	$pconfig['latencylow'] = $a_gateways[$id]['latencylow'];
79
	$pconfig['latencyhigh'] = $a_gateways[$id]['latencyhigh'];
80
	$pconfig['losslow'] = $a_gateways[$id]['losslow'];
81
	$pconfig['losshigh'] = $a_gateways[$id]['losshigh'];
82
	$pconfig['down'] = $a_gateways[$id]['down'];
83 83
	$pconfig['monitor'] = $a_gateways[$id]['monitor'];
84 84
	$pconfig['monitor_disable'] = isset($a_gateways[$id]['monitor_disable']);
85 85
	$pconfig['descr'] = $a_gateways[$id]['descr'];
......
91 91
	unset($pconfig['attribute']);
92 92
}
93 93

  
94
if (isset($id) && $a_gateways[$id])
95
	$realid = $a_gateways[$id]['attribute'];
96

  
94 97
if ($_POST) {
95 98

  
96 99
	unset($input_errors);
......
386 389
			$gateway['monitor_disable'] = true;
387 390
		else if (is_ipaddr($_POST['monitor'])) {
388 391
			/* NOTE: If monitor ip is changed need to cleanup the old static route */
389
			if ($_POST['monitor'] != "dynamic" && !empty($a_gateway_item[$id]) && is_ipaddr($a_gateway_item[$id]['monitor']) &&
390
			    $_POST['monitor'] != $a_gateway_item[$id]['monitor'] && $gateway['gateway'] != $a_gateway_item[$id]['monitor']) {
391
				if (is_ipaddrv4($a_gateway_item[$id]['monitor']))
392
					mwexec("/sbin/route delete " . escapeshellarg($a_gateway_item[$id]['monitor']));
392
			if ($_POST['monitor'] != "dynamic" && !empty($a_gateway_item[$realid]) && is_ipaddr($a_gateway_item[$realid]['monitor']) &&
393
			    $_POST['monitor'] != $a_gateway_item[$realid]['monitor'] && $gateway['gateway'] != $a_gateway_item[$realid]['monitor']) {
394
				if (is_ipaddrv4($a_gateway_item[$realid]['monitor']))
395
					mwexec("/sbin/route delete " . escapeshellarg($a_gateway_item[$realid]['monitor']));
393 396
				else
394
					mwexec("/sbin/route delete -inet6 " . escapeshellarg($a_gateway_item[$id]['monitor']));
397
					mwexec("/sbin/route delete -inet6 " . escapeshellarg($a_gateway_item[$realid]['monitor']));
395 398
			}
396 399
			$gateway['monitor'] = $_POST['monitor'];
397 400
		}
......
422 425
			$gateway['down'] = $_POST['down'];
423 426

  
424 427
		/* when saving the manual gateway we use the attribute which has the corresponding id */
425
		if (isset($id) && $a_gateway_item[$id])
426
			$a_gateway_item[$id] = $gateway;
428
		if (isset($realid) && $a_gateway_item[$realid])
429
			$a_gateway_item[$realid] = $gateway;
427 430
		else
428 431
			$a_gateway_item[] = $gateway;
429 432

  

Also available in: Unified diff