Commit 768eb2ef authored by Franco Fichtner's avatar Franco Fichtner

openvpn: create devices before running initial configure; closes #980

(cherry picked from commit 44cd7aee)
parent 19280d21
......@@ -382,7 +382,7 @@ function openvpn_add_keyfile(&$data, &$conf, $mode_id, $directive, $opt = '')
$conf .= "{$directive} {$fpath} {$opt}\n";
}
function openvpn_reconfigure($mode, $settings)
function openvpn_reconfigure($mode, $settings, $device_only = false)
{
global $config;
......@@ -425,6 +425,10 @@ function openvpn_reconfigure($mode, $settings)
mwexec("/sbin/ifconfig " . escapeshellarg($devname) . " group openvpn");
}
if ($device_only) {
return;
}
$proto = strtolower($settings['protocol']);
if (substr($settings['protocol'], 0, 3) == "TCP") {
$proto = "{$proto}-{$mode}";
......@@ -1005,6 +1009,24 @@ function openvpn_resync_csc()
}
}
function openvpn_prepare_all()
{
global $config;
if (!isset($config['openvpn'])) {
return;
}
log_error('Creating OpenVPN instances.');
foreach (array('server', 'client') as $mode) {
if (isset($config['openvpn']["openvpn-{$mode}"])) {
foreach ($config['openvpn']["openvpn-{$mode}"] as &$settings) {
openvpn_reconfigure($mode, $settings, true);
}
}
}
}
function openvpn_resync($mode, $settings)
{
......@@ -1012,43 +1034,38 @@ function openvpn_resync($mode, $settings)
openvpn_restart($mode, $settings);
}
function openvpn_resync_all($interface = '')
function openvpn_resync_all($interface = null)
{
global $config;
openvpn_create_dirs();
if (!isset($config['openvpn']) || !is_array($config['openvpn'])) {
if (!isset($config['openvpn'])) {
return;
}
if ($interface <> "") {
log_error("Resyncing OpenVPN instances for interface " . convert_friendly_interface_to_friendly_descr($interface) . ".");
if (!empty($interface)) {
log_error(sprintf(
'Resyncing OpenVPN instances for interface %s.',
convert_friendly_interface_to_friendly_descr($interface)
));
} else {
log_error("Resyncing OpenVPN instances.");
log_error('Resyncing OpenVPN instances.');
}
if (is_array($config['openvpn']['openvpn-server'])) {
foreach ($config['openvpn']['openvpn-server'] as & $settings) {
if ($interface <> "" && $interface != $settings['interface']) {
continue;
foreach (array('server', 'client') as $mode) {
if (isset($config['openvpn']["openvpn-{$mode}"])) {
foreach ($config['openvpn']["openvpn-{$mode}"] as &$settings) {
if (empty($interface) || $interface == $settings['interface']) {
openvpn_resync($mode, $settings);
}
}
openvpn_resync('server', $settings);
}
}
if (is_array($config['openvpn']['openvpn-client'])) {
foreach ($config['openvpn']['openvpn-client'] as & $settings) {
if ($interface <> "" && $interface != $settings['interface']) {
continue;
}
openvpn_resync('client', $settings);
}
}
openvpn_resync_csc();
}
function openvpn_get_active_servers($type = 'multipoint')
{
global $config;
......
......@@ -233,6 +233,7 @@ echo "done.\n";
/* set up interfaces */
mute_kernel_msgs();
openvpn_prepare_all();
interfaces_configure();
unmute_kernel_msgs();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment