From a8f538a88ea58a513b2e4928ea277a9964d9999a Mon Sep 17 00:00:00 2001 From: jim-p Date: Wed, 21 Nov 2012 10:13:55 -0500 Subject: Wrap dir creation for openvpn in a function to reduce duplication, and use the function before places that could potentially write in the dir. --- etc/inc/openvpn.inc | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) (limited to 'etc') diff --git a/etc/inc/openvpn.inc b/etc/inc/openvpn.inc index 4001c94..5dcd509 100644 --- a/etc/inc/openvpn.inc +++ b/etc/inc/openvpn.inc @@ -276,6 +276,7 @@ function openvpn_add_keyfile(& $data, & $conf, $mode_id, $directive, $opt = "") global $g; $fpath = $g['varetc_path']."/openvpn/{$mode_id}.{$directive}"; + openvpn_create_dirs(); file_put_contents($fpath, base64_decode($data)); //chown($fpath, 'nobody'); //chgrp($fpath, 'nobody'); @@ -291,7 +292,7 @@ function openvpn_reconfigure($mode, $settings) { return; if (isset($settings['disable'])) return; - + openvpn_create_dirs(); /* * NOTE: Deleting tap devices causes spontaneous reboots. Instead, * we use a vpnid number which is allocated for a particular client @@ -654,10 +655,7 @@ function openvpn_reconfigure($mode, $settings) { openvpn_add_custom($settings, $conf); - if (!is_dir("{$g['varetc_path']}/openvpn")) - safe_mkdir("{$g['varetc_path']}/openvpn", 0750); - if (!is_dir("{$g['varetc_path']}/openvpn-csc")) - safe_mkdir("{$g['varetc_path']}/openvpn-csc", 0750); + openvpn_create_dirs(); $fpath = "{$g['varetc_path']}/openvpn/{$mode_id}.conf"; file_put_contents($fpath, $conf); unset($conf); @@ -754,6 +752,7 @@ function openvpn_resync_csc(& $settings) { unlink_if_exists($fpath); return; } + openvpn_create_dirs(); $conf = ''; if ($settings['block']) @@ -805,10 +804,7 @@ function openvpn_resync_all($interface = "") { if ($g['platform'] == 'jail') return; - if (!is_dir("{$g['varetc_path']}/openvpn")) - safe_mkdir("{$g['varetc_path']}/openvpn", 0750); - if (!is_dir("{$g['varetc_path']}/openvpn-csc")) - safe_mkdir("{$g['varetc_path']}/openvpn-csc", 0750); + openvpn_create_dirs(); if (!is_array($config['openvpn'])) $config['openvpn'] = array(); @@ -1075,10 +1071,7 @@ function openvpn_get_client_status($client, $socket) { function openvpn_refresh_crls() { global $g, $config; - if (!is_dir("{$g['varetc_path']}/openvpn")) - safe_mkdir("{$g['varetc_path']}/openvpn", 0750); - if (!is_dir("{$g['varetc_path']}/openvpn-csc")) - safe_mkdir("{$g['varetc_path']}/openvpn-csc", 0750); + openvpn_create_dirs(); if (is_array($config['openvpn']['openvpn-server'])) { foreach ($config['openvpn']['openvpn-server'] as $settings) { @@ -1105,4 +1098,12 @@ function openvpn_refresh_crls() { } } +function openvpn_create_dirs() { + global $g; + if (!is_dir("{$g['varetc_path']}/openvpn")) + safe_mkdir("{$g['varetc_path']}/openvpn", 0750); + if (!is_dir("{$g['varetc_path']}/openvpn-csc")) + safe_mkdir("{$g['varetc_path']}/openvpn-csc", 0750); +} + ?> -- cgit v1.1