diff options
author | Phil Davis <phil.davis@world.inf.org> | 2013-06-29 21:09:39 -0700 |
---|---|---|
committer | Phil Davis <phil.davis@world.inf.org> | 2013-06-29 21:09:39 -0700 |
commit | 7ef9de3fedb7b1bff40f290bf50324833a5a7dec (patch) | |
tree | 8bb6c41e8312dc333f01d4136e00d699e4aa86f7 /etc/rc.openvpn | |
parent | 2b125a17e91b5b63694de0c272e5f4fd154598da (diff) | |
download | pfsense-7ef9de3fedb7b1bff40f290bf50324833a5a7dec.zip pfsense-7ef9de3fedb7b1bff40f290bf50324833a5a7dec.tar.gz |
Handle comma-separated list arg to rc.openvpn
The argument passed to rc.openvpn can be a comma-separated list of gateways - not just 1 gateway. Enhance the code to loop and process each gateway.
Diffstat (limited to 'etc/rc.openvpn')
-rwxr-xr-x | etc/rc.openvpn | 52 |
1 files changed, 29 insertions, 23 deletions
diff --git a/etc/rc.openvpn b/etc/rc.openvpn index 531fa40..e30d130 100755 --- a/etc/rc.openvpn +++ b/etc/rc.openvpn @@ -63,42 +63,48 @@ function openvpn_resync_if_needed ($mode, $ovpn_settings, $interface) { if (file_exists("{$g['varrun_path']}/booting")) return; +/* Input argument is a comma-separated list of gateway names, blank or "all". */ $argument = trim($argv[1], " \n"); if(is_array($config['openvpn']['openvpn-server']) || is_array($config['openvpn']['openvpn-client'])) { - if (empty($argument) || $argument == "all") + if (empty($argument) || $argument == "all") { + $argument = "all"; $log_text = "all"; - else + } else { $log_text = "endpoints that may use " . $argument; + } log_error("OpenVPN: One or more OpenVPN tunnel endpoints may have changed its IP. Reloading " . $log_text . "."); } else return; -$gwgroups = array(); $openvpnlck = lock('openvpn', LOCK_EX); -if (empty($argument) || $argument == "all") - $interface = ""; -else { - // e.g. $argument = "WANGW", $interface = "wan" - $interface = lookup_gateway_interface_by_name($argument); - if (empty($interface)) - $interface = $argument; - else - // e.g. $argument = "WANGW", $gwgroups = array of gateway groups that use "wan" - $gwgroups = gateway_is_gwgroup_member($argument); -} +$arg_array = explode(",",$argument); +foreach ($arg_array as $arg_element) { + $gwgroups = array(); + if ($arg_element == "all") + $interface = ""; + else { + // e.g. $arg_element = "WANGW", $interface = "wan" + $interface = lookup_gateway_interface_by_name($arg_element); + if (empty($interface)) + $interface = $arg_element; + else + // e.g. $arg_element = "WANGW", $gwgroups = array of gateway groups that use "wan" + $gwgroups = gateway_is_gwgroup_member($arg_element); + } -if(is_array($config['openvpn']['openvpn-server'])) { - foreach($config['openvpn']['openvpn-server'] as &$server) { - if ($server['interface'] == $interface || empty($interface) || (!empty($gwgroups) && in_array($server['interface'], $gwgroups))) - openvpn_resync_if_needed('server', $server, $interface); + if(is_array($config['openvpn']['openvpn-server'])) { + foreach($config['openvpn']['openvpn-server'] as &$server) { + if ($server['interface'] == $interface || empty($interface) || (!empty($gwgroups) && in_array($server['interface'], $gwgroups))) + openvpn_resync_if_needed('server', $server, $interface); + } } -} -if (is_array($config['openvpn']['openvpn-client'])) { - foreach($config['openvpn']['openvpn-client'] as &$client) { - if ($client['interface'] == $interface || empty($interface) || (!empty($gwgroups) && in_array($client['interface'], $gwgroups))) - openvpn_resync_if_needed('client', $client, $interface); + if (is_array($config['openvpn']['openvpn-client'])) { + foreach($config['openvpn']['openvpn-client'] as &$client) { + if ($client['interface'] == $interface || empty($interface) || (!empty($gwgroups) && in_array($client['interface'], $gwgroups))) + openvpn_resync_if_needed('client', $client, $interface); + } } } |