Project

General

Profile

« Previous | Next » 

Revision fd34d6a9

Added by Ermal LUÇI over 12 years ago

Simplify a bit code branching no change on functionality

View differences:

etc/inc/gwlb.inc
304 304
	 * or are down, which could cause gateway groups to fail */
305 305
	$gateways_arr = return_gateways_array();
306 306
	foreach($gateways_arr as $gwitem) {
307
		if(isset($gwitem['monitor_disable'])) {
308
			if(!is_ipaddr($gwitem['monitorip'])) {
309
				$realif = $gwitem['interface'];
310
				$tgtip = get_interface_gateway($realif);
311
				$srcip = find_interface_ip($realif);
312
			} else {
313
				$tgtip = $gwitem['monitorip'];
314
				$srcip = find_interface_ip($realif);
315
			}
316
			if($byname == true)
317
				$target = $gwitem['name'];
318
			else
319
				$target = $tgtip;
320

  
321
			/* failsafe for down interfaces */
322
			if($target == "") {
323
				$target = $gwitem['name'];
324
				$status[$target]['name'] = $gwitem['name'];
325
				$status[$target]['lastcheck'] = date('r');
326
				$status[$target]['delay'] = "0.0ms";
327
				$status[$target]['loss'] = "100.0%";
328
				$status[$target]['status'] = "down";
329
			} else {
330
				$status[$target]['monitorip'] = $tgtip;
331
				$status[$target]['srcip'] = $srcip;
332
				$status[$target]['name'] = $gwitem['name'];
333
				$status[$target]['lastcheck'] = date('r');
334
				$status[$target]['delay'] = "0.0ms";
335
				$status[$target]['loss'] = "0.0%";
336
				$status[$target]['status'] = "none";
337
			}
307
		if(isset($gwitem['monitor_disable']))
308
			continue;
309
		if(!is_ipaddr($gwitem['monitorip'])) {
310
			$realif = $gwitem['interface'];
311
			$tgtip = get_interface_gateway($realif);
312
			if (!is_ipaddr($tgtip))
313
				$tgtip = "none";
314
			$srcip = find_interface_ip($realif);
315
		} else {
316
			$tgtip = $gwitem['monitorip'];
317
			$srcip = find_interface_ip($realif);
318
		}
319
		if($byname == true)
320
			$target = $gwitem['name'];
321
		else
322
			$target = $tgtip;
323

  
324
		/* failsafe for down interfaces */
325
		if($target == "none") {
326
			$target = $gwitem['name'];
327
			$status[$target]['name'] = $gwitem['name'];
328
			$status[$target]['lastcheck'] = date('r');
329
			$status[$target]['delay'] = "0.0ms";
330
			$status[$target]['loss'] = "100.0%";
331
			$status[$target]['status'] = "down";
332
		} else {
333
			$status[$target]['monitorip'] = $tgtip;
334
			$status[$target]['srcip'] = $srcip;
335
			$status[$target]['name'] = $gwitem['name'];
336
			$status[$target]['lastcheck'] = date('r');
337
			$status[$target]['delay'] = "0.0ms";
338
			$status[$target]['loss'] = "0.0%";
339
			$status[$target]['status'] = "none";
338 340
		}
339 341
	}
340 342
	return($status);

Also available in: Unified diff