Project

General

Profile

« Previous | Next » 

Revision f7335af3

Added by Renato Botelho over 5 years ago

Deduplicate code in openvpn.inc

View differences:

src/etc/inc/openvpn.inc
1578 1578
	}
1579 1579

  
1580 1580
	// Check if OpenVPN clients and servers require a resync.
1581
	if (is_array($config['openvpn']['openvpn-server'])) {
1582
		foreach ($config['openvpn']['openvpn-server'] as & $settings) {
1583
			$fpath = "{$g['varetc_path']}/openvpn/server" .
1584
			    $settings['vpnid'] . ".interface";
1585
			$gw_group_change = FALSE;
1586
			$ip_change = ($interface === "") || ($interface === $settings['interface']);
1587
			if (!$ip_change && file_exists($fpath)) {
1588
				$gw_group_change = (trim(file_get_contents($fpath), " \t\n") != get_failover_interface($settings['interface']));
1589
			}
1590
			if ($ip_change || $gw_group_change) {
1591
				openvpn_resync('server', $settings);
1592
			}
1581
	foreach (array("server", "client") as $type) {
1582
		if (!is_array($config['openvpn']["openvpn-{$type}"])) {
1583
			continue;
1593 1584
		}
1594
	}
1595
	if (is_array($config['openvpn']['openvpn-client'])) {
1596
		foreach ($config['openvpn']['openvpn-client'] as & $settings) {
1597
			$fpath = "{$g['varetc_path']}/openvpn/client" .
1585
		foreach ($config['openvpn']["openvpn-{$type}"] as & $settings) {
1586
			$fpath = "{$g['varetc_path']}/openvpn/{$type}" .
1598 1587
			    $settings['vpnid'] . ".interface";
1599 1588
			$gw_group_change = FALSE;
1600
			$ip_change = ($interface === "") || ($interface === $settings['interface']);
1589
			$ip_change = ($interface === "") ||
1590
			    ($interface === $settings['interface']);
1591

  
1601 1592
			if (!$ip_change && file_exists($fpath)) {
1602
				$gw_group_change = (trim(file_get_contents($fpath), " \t\n") != get_failover_interface($settings['interface']));
1593
				$gw_group_change =
1594
				    (trim(file_get_contents($fpath), " \t\n") !=
1595
				    get_failover_interface(
1596
					$settings['interface']));
1603 1597
			}
1598

  
1604 1599
			if ($ip_change || $gw_group_change) {
1605
				openvpn_resync('client', $settings);
1600
				openvpn_resync($type, $settings);
1606 1601
			}
1607 1602
		}
1608 1603
	}

Also available in: Unified diff