Commit 38cae64c authored by Franco Fichtner's avatar Franco Fichtner

src: fix openvpn server restart regression

parent f1a31bd0
...@@ -380,14 +380,16 @@ function openvpn_add_keyfile(& $data, & $conf, $mode_id, $directive, $opt = "") ...@@ -380,14 +380,16 @@ function openvpn_add_keyfile(& $data, & $conf, $mode_id, $directive, $opt = "")
$conf .= "{$directive} {$fpath} {$opt}\n"; $conf .= "{$directive} {$fpath} {$opt}\n";
} }
function openvpn_reconfigure($mode, $settings) { function openvpn_reconfigure($mode, $settings)
{
global $g, $config; global $g, $config;
if (empty($settings)) if (empty($settings) || isset($settings['disable'])) {
return;
if (isset($settings['disable']))
return; return;
}
openvpn_create_dirs(); openvpn_create_dirs();
/* /*
* NOTE: Deleting tap devices causes spontaneous reboots. Instead, * NOTE: Deleting tap devices causes spontaneous reboots. Instead,
* we use a vpnid number which is allocated for a particular client * we use a vpnid number which is allocated for a particular client
...@@ -397,17 +399,18 @@ function openvpn_reconfigure($mode, $settings) { ...@@ -397,17 +399,18 @@ function openvpn_reconfigure($mode, $settings) {
$vpnid = $settings['vpnid']; $vpnid = $settings['vpnid'];
$mode_id = $mode.$vpnid; $mode_id = $mode.$vpnid;
if (isset($settings['dev_mode'])) if (isset($settings['dev_mode'])) {
$tunname = "{$settings['dev_mode']}{$vpnid}"; $tunname = "{$settings['dev_mode']}{$vpnid}";
else { /* defaults to tun */ } else { /* defaults to tun */
$tunname = "tun{$vpnid}"; $tunname = "tun{$vpnid}";
$settings['dev_mode'] = "tun"; $settings['dev_mode'] = "tun";
} }
if ($mode == "server") if ($mode == "server") {
$devname = "ovpns{$vpnid}"; $devname = "ovpns{$vpnid}";
else } else {
$devname = "ovpnc{$vpnid}"; $devname = "ovpnc{$vpnid}";
}
/* is our device already configured */ /* is our device already configured */
if (!does_interface_exist($devname)) { if (!does_interface_exist($devname)) {
...@@ -423,7 +426,6 @@ function openvpn_reconfigure($mode, $settings) { ...@@ -423,7 +426,6 @@ function openvpn_reconfigure($mode, $settings) {
mwexec("/sbin/ifconfig " . escapeshellarg($devname) . " group openvpn"); mwexec("/sbin/ifconfig " . escapeshellarg($devname) . " group openvpn");
} }
$pfile = $g['varrun_path'] . "/openvpn_{$mode_id}.pid";
$proto = strtolower($settings['protocol']); $proto = strtolower($settings['protocol']);
if (substr($settings['protocol'], 0, 3) == "TCP") if (substr($settings['protocol'], 0, 3) == "TCP")
$proto = "{$proto}-{$mode}"; $proto = "{$proto}-{$mode}";
...@@ -469,7 +471,7 @@ function openvpn_reconfigure($mode, $settings) { ...@@ -469,7 +471,7 @@ function openvpn_reconfigure($mode, $settings) {
break; break;
} }
$conf .= "dev-node /dev/{$tunname}\n"; $conf .= "dev-node /dev/{$tunname}\n";
$conf .= "writepid {$pfile}\n"; $conf .= "writepid /var/run/openvpn_{$mode_id}.pid\n";
$conf .= "#user nobody\n"; $conf .= "#user nobody\n";
$conf .= "#group nobody\n"; $conf .= "#group nobody\n";
$conf .= "script-security 3\n"; $conf .= "script-security 3\n";
...@@ -799,35 +801,28 @@ function openvpn_reconfigure($mode, $settings) { ...@@ -799,35 +801,28 @@ function openvpn_reconfigure($mode, $settings) {
@chmod("{$g['varetc_path']}/openvpn/{$mode_id}.conf", 0600); @chmod("{$g['varetc_path']}/openvpn/{$mode_id}.conf", 0600);
} }
function openvpn_restart($mode, $settings) { function openvpn_restart($mode, $settings)
{
global $g, $config; global $g, $config;
$vpnid = $settings['vpnid']; $vpnid = $settings['vpnid'];
$mode_id = $mode.$vpnid; $mode_id = $mode.$vpnid;
/* kill the process if running */ /* kill the process if running */
$pfile = $g['varrun_path']."/openvpn_{$mode_id}.pid"; $pfile = "/var/run/openvpn_{$mode_id}.pid";
if (file_exists($pfile)) { killbypid($pfile);
while (isvalidpid($pfile)) {
/* read the pid file */ usleep(250000);
$pid = rtrim(file_get_contents($pfile));
unlink($pfile);
/* send a term signal to the process */
killbypid($pid);
/* wait until the process exits */
while(isvalidpid($pid)) {
usleep(250000);
}
} }
if (isset($settings['disable'])) if (isset($settings['disable'])) {
return; return;
}
/* Do not start a client if we are a CARP backup on this vip! */ /* Do not start a client if we are a CARP backup on this vip! */
if (($mode == "client") && (strstr($settings['interface'], "_vip") && get_carp_interface_status($settings['interface']) == "BACKUP")) if (($mode == "client") && (strstr($settings['interface'], "_vip") && get_carp_interface_status($settings['interface']) == "BACKUP")) {
return; return;
}
/* Check if client is bound to a gateway group */ /* Check if client is bound to a gateway group */
$a_groups = return_gateway_groups_array(); $a_groups = return_gateway_groups_array();
...@@ -846,34 +841,27 @@ function openvpn_restart($mode, $settings) { ...@@ -846,34 +841,27 @@ function openvpn_restart($mode, $settings) {
configd_run("filter reload"); configd_run("filter reload");
} }
function openvpn_delete($mode, & $settings) { function openvpn_delete($mode, & $settings)
{
global $g, $config; global $g, $config;
$vpnid = $settings['vpnid']; $vpnid = $settings['vpnid'];
$mode_id = $mode.$vpnid; $mode_id = $mode.$vpnid;
if (isset($settings['dev_mode'])) if (isset($settings['dev_mode'])) {
$tunname = "{$settings['dev_mode']}{$vpnid}"; $tunname = "{$settings['dev_mode']}{$vpnid}";
else { /* defaults to tun */ } else { /* defaults to tun */
$tunname = "tun{$vpnid}"; $tunname = "tun{$vpnid}";
} }
if ($mode == "server") if ($mode == "server") {
$devname = "ovpns{$vpnid}"; $devname = "ovpns{$vpnid}";
else } else {
$devname = "ovpnc{$vpnid}"; $devname = "ovpnc{$vpnid}";
}
/* kill the process if running */ /* kill the process if running */
$pfile = "{$g['varrun_path']}/openvpn_{$mode_id}.pid"; killbypid("/var/run/openvpn_{$mode_id}.pid");
if (file_exists($pfile)) {
/* read the pid file */
$pid = trim(file_get_contents($pfile));
unlink($pfile);
/* send a term signal to the process */
killbypid($pid);
}
/* remove the device from the openvpn group */ /* remove the device from the openvpn group */
mwexec("/sbin/ifconfig " . escapeshellarg($devname) . " -group openvpn"); mwexec("/sbin/ifconfig " . escapeshellarg($devname) . " -group openvpn");
......
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