From 4c97c990fbf691d22639ade11daf035949d7439e Mon Sep 17 00:00:00 2001 From: Ad Schellevis Date: Sun, 22 Apr 2018 17:20:28 +0200 Subject: [PATCH] OpenVPN, save client specific overrides for non user auth types on client connect and cleanup on disconnect, this should remove the need to flush all and cleanup when a csc changes or when server changes occur and is more aligned with how the user authenticated overrides function now. The attributes.sh still looks a bit weird, kept the state reset, although it looks odd that we only do this for part of the server options. Next step is cleanup and additional testing. for https://github.com/opnsense/core/issues/2348 --- src/etc/inc/plugins.inc.d/openvpn.inc | 9 ++- .../inc/plugins.inc.d/openvpn/attributes.sh | 1 + .../openvpn/ovpn_cleanup_cso.php | 41 +++++++++++++ .../plugins.inc.d/openvpn/ovpn_setup_cso.php | 57 +++++++++++++++++++ 4 files changed, 106 insertions(+), 2 deletions(-) create mode 100755 src/etc/inc/plugins.inc.d/openvpn/ovpn_cleanup_cso.php create mode 100755 src/etc/inc/plugins.inc.d/openvpn/ovpn_setup_cso.php diff --git a/src/etc/inc/plugins.inc.d/openvpn.inc b/src/etc/inc/plugins.inc.d/openvpn.inc index c42be199b..5d08350fd 100644 --- a/src/etc/inc/plugins.inc.d/openvpn.inc +++ b/src/etc/inc/plugins.inc.d/openvpn.inc @@ -594,9 +594,14 @@ function openvpn_reconfigure($mode, $settings, $device_only = false) switch ($settings['mode']) { case 'server_user': case 'server_tls_user': - $conf .= "client-connect /usr/local/etc/inc/plugins.inc.d/openvpn/attributes.sh\n"; - $conf .= "client-disconnect /usr/local/etc/inc/plugins.inc.d/openvpn/attributes.sh\n"; + $conf .= "client-disconnect \"/usr/local/etc/inc/plugins.inc.d/openvpn/attributes.sh {$mode_id} \"\n"; break; + case 'server_tls': + case 'p2p_tls': + // For non user auth types setup client specific overrides, user authenticated ones are commissioned + // using the auth script in option auth-user-pass-verify + $conf .= "client-connect \"/usr/local/etc/inc/plugins.inc.d/openvpn/ovpn_setup_cso.php {$mode_id}\"\n"; + $conf .= "client-disconnect \"/usr/local/etc/inc/plugins.inc.d/openvpn/ovpn_cleanup_cso.php {$mode_id} \"\n"; default: break; } diff --git a/src/etc/inc/plugins.inc.d/openvpn/attributes.sh b/src/etc/inc/plugins.inc.d/openvpn/attributes.sh index 942cac6b4..60f2040a8 100755 --- a/src/etc/inc/plugins.inc.d/openvpn/attributes.sh +++ b/src/etc/inc/plugins.inc.d/openvpn/attributes.sh @@ -3,6 +3,7 @@ if [ "$script_type" = "client-disconnect" ]; then /sbin/pfctl -k $ifconfig_pool_remote_ip /sbin/pfctl -K $ifconfig_pool_remote_ip + /usr/local/etc/inc/plugins.inc.d/openvpn/ovpn_cleanup_cso.php $1 fi exit 0 diff --git a/src/etc/inc/plugins.inc.d/openvpn/ovpn_cleanup_cso.php b/src/etc/inc/plugins.inc.d/openvpn/ovpn_cleanup_cso.php new file mode 100755 index 000000000..ca7160f05 --- /dev/null +++ b/src/etc/inc/plugins.inc.d/openvpn/ovpn_cleanup_cso.php @@ -0,0 +1,41 @@ +#!/usr/local/bin/php + $common_name); + } + $cso_filename = openvpn_csc_conf_write($cso, $server); + if (!empty($cso_filename)) { + syslog(LOG_NOTICE, "client config created @ {$cso_filename}"); + } + break; + } + } +} + +closelog(); +exit(0);