From 7f64d42fbf7028e19b1e630b9a1b472cf188f63e Mon Sep 17 00:00:00 2001 From: Paul Rock Date: Wed, 31 Jan 2018 04:06:02 +0300 Subject: [PATCH] client config generating part was rewrited to plugin --- app/ovpn.php | 72 +++++++++++++++++++++++++++++------------------- public/index.php | 23 ++-------------- 2 files changed, 46 insertions(+), 49 deletions(-) diff --git a/app/ovpn.php b/app/ovpn.php index adb207c..1a5ffdd 100644 --- a/app/ovpn.php +++ b/app/ovpn.php @@ -1,28 +1,44 @@ -client -dev -proto -client -remote -resolv-retry infinite -cipher AES-256-CBC -redirect-gateway - -# Keys -ca [inline] - -tls-auth [inline] 1 - - -key-direction 1 -remote-cert-tls server -auth-user-pass -auth-nocache - -# Security -nobind -persist-key -persist-tun -comp-lzo -verb 3 - -# Proxy ? -# http-proxy cache.univ.fr 3128 +dev = getenv('VPN_INIF'); +$_ovpn->proto = getenv('VPN_PROTO'); +$_ovpn->port = getenv('VPN_PORT'); +$_ovpn->remote = getenv('VPN_REMOTE'); +$_ovpn->resolvRetry = 'infinite'; +$_ovpn->cipher = 'AES-256-CBC'; +$_ovpn->redirectGateway = true; + +$_ovpn->addCert('ca', getenv('VPN_CONF') . '/ca.crt', true) +->addCert('tls-auth', getenv('VPN_CONF') . '/ta.key', true); + +$_ovpn->keyDirection = 1; +$_ovpn->remoteCertTls = 'server'; +$_ovpn->authUserPass = true; +$_ovpn->authNocache = true; + +$_ovpn->nobind = true; +$_ovpn->persistKey = true; +$_ovpn->persistTun = true; +$_ovpn->compLzo = true; +$_ovpn->verb = 3; + +$config = $_ovpn->getClientConfig(); + +switch ($_POST['configuration_os']) { +case 'gnu_linux': +case 'configuration_os': +$filename = 'client.conf'; +break; +default: +$filename = 'client.ovpn'; +break; +} + +header('Content-Type:text/plain'); +header("Content-Disposition: attachment; filename=$filename"); +header("Pragma: no-cache"); +header("Expires: 0"); + +die("$config"); \ No newline at end of file diff --git a/public/index.php b/public/index.php index 499c871..0b9be39 100644 --- a/public/index.php +++ b/public/index.php @@ -25,27 +25,8 @@ if (isset($_POST['configuration_get'], $_POST['configuration_username'], $_POST[ // Error ? if ($data && passEqual($_POST['configuration_pass'], $data['user_pass'])) { - $vpn_dev = getenv('VPN_INIF'); - $vpn_proto = getenv('VPN_PROTO'); - $vpn_remote = getenv('VPN_REMOTE'). ' ' . getenv('VPN_PORT'); - - switch ($_POST['configuration_os']) { - case 'gnu_linux': - case 'configuration_os': - $filename = 'client.conf'; - break; - default: - $filename = 'client.ovpn'; - break; - } - - header('Content-Type:text/plain'); - header("Content-Disposition: attachment; filename=$filename"); - header("Pragma: no-cache"); - header("Expires: 0"); - - require(dirname(__FILE__) . '/../app/ovpn.php'); - die(); + // Answer with config + include __DIR__ . "/../app/ovpn.php"; } else { $error = true; }