diff options
-rwxr-xr-x | etc/rc.openvpn | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/etc/rc.openvpn b/etc/rc.openvpn index e30d130..4cabffe 100755 --- a/etc/rc.openvpn +++ b/etc/rc.openvpn @@ -41,19 +41,22 @@ require_once("openvpn.inc"); function openvpn_resync_if_needed ($mode, $ovpn_settings, $interface) { global $g, $config; - $resync_needed = false; - if (empty($interface)) { - $resync_needed = true; - } else { + $resync_needed = true; + if (!empty($interface)) { $mode_id = $mode . $ovpn_settings['vpnid']; $fpath = "{$g['varetc_path']}/openvpn/{$mode_id}.interface"; - $current_device = file_get_contents($fpath); - $new_device = get_failover_interface($ovpn_settings['interface']); - $this_device = $config['interfaces'][$interface]['if']; - if (($current_device != $new_device) || ($current_device == $this_device) || ($new_device == $this_device)) - $resync_needed = true; + if (file_exists($fpath)) { + $current_device = file_get_contents($fpath); + $current_device = trim($current_device, " \t\n"); + $new_device = get_failover_interface($ovpn_settings['interface']); + if (isset($config['interfaces'][$interface])) { + $this_device = $config['interfaces'][$interface]['if']; + if (($current_device == $new_device) || ($current_device != $this_device) || ($new_device != $this_device)) + $resync_needed = false; + } + } } - if ($resync_needed) { + if ($resync_needed == true) { log_error("OpenVPN: Resync " . $mode_id . " " . $ovpn_settings['description']); openvpn_resync($mode, $ovpn_settings); } |