From 9b4de46a5827ae619637a35b0e1a6b8e3a7ae394 Mon Sep 17 00:00:00 2001 From: Paul Rock Date: Tue, 30 Jan 2018 18:35:36 +0300 Subject: [PATCH] openvpn config generator moved to non public folder --- {public => app}/ovpn.php | 12 ------ public/index.php | 82 +++++++++++++++------------------------- 2 files changed, 30 insertions(+), 64 deletions(-) rename {public => app}/ovpn.php (59%) diff --git a/public/ovpn.php b/app/ovpn.php similarity index 59% rename from public/ovpn.php rename to app/ovpn.php index 6589379..adb207c 100644 --- a/public/ovpn.php +++ b/app/ovpn.php @@ -1,15 +1,3 @@ -load(); - -$vpn_dev = getenv('VPN_INIF'); -$vpn_proto = getenv('VPN_PROTO'); -$vpn_remote = getenv('VPN_ADDR'). ' ' . getenv('VPN_PORT'); - -header('Content-Type:text/plain'); -?> client dev proto -client diff --git a/public/index.php b/public/index.php index 3768f6d..88a480b 100644 --- a/public/index.php +++ b/public/index.php @@ -25,49 +25,27 @@ if (isset($_POST['configuration_get'], $_POST['configuration_username'], $_POST[ // Error ? if ($data && passEqual($_POST['configuration_pass'], $data['user_pass'])) { - // Thanks http://stackoverflow.com/questions/4914750/how-to-zip-a-whole-folder-using-php - if ($_POST['configuration_os'] == "gnu_linux") { - $conf_dir = 'gnu-linux'; - } elseif ($_POST['configuration_os'] == "osx_viscosity") { - $conf_dir = 'osx-viscosity'; - } else { - $conf_dir = 'windows'; - } - $rootPath = realpath("./client-conf/$conf_dir"); - - // Initialize archive object - $archive_base_name = "openvpn-$conf_dir"; - $archive_name = "$archive_base_name.zip"; - $archive_path = "./client-conf/$archive_name"; - $zip = new ZipArchive(); - $zip->open($archive_path, ZipArchive::CREATE | ZipArchive::OVERWRITE); - - $files = new RecursiveIteratorIterator( - new RecursiveDirectoryIterator($rootPath), - RecursiveIteratorIterator::LEAVES_ONLY - ); - - foreach ($files as $name => $file) { - // Skip directories (they would be added automatically) - if (!$file->isDir()) { - // Get real and relative path for current file - $filePath = $file->getRealPath(); - $relativePath = substr($filePath, strlen($rootPath) + 1); - - // Add current file to archive - $zip->addFile($filePath, "$archive_base_name/$relativePath"); - } + $vpn_dev = getenv('VPN_INIF'); + $vpn_proto = getenv('VPN_PROTO'); + $vpn_remote = getenv('VPN_ADDR'). ' ' . getenv('VPN_PORT'); + + switch ($_POST['configuration_os']) { + case 'gnu_linux': + case 'configuration_os': + $filename = 'client.conf'; + break; + default: + $filename = 'client.ovpn'; + break; } - // Zip archive will be created only after closing object - $zip->close(); - - //then send the headers to foce download the zip file - header("Content-type: application/zip"); - header("Content-Disposition: attachment; filename=$archive_name"); + header('Content-Type:text/plain'); + header("Content-Disposition: attachment; filename=$filename"); header("Pragma: no-cache"); header("Expires: 0"); - readfile($archive_path); + + require(dirname(__FILE__) . '/../app/ovpn.php'); + die(); } else { $error = true; } @@ -96,13 +74,13 @@ else if (isset($_POST['admin_login'], $_POST['admin_username'], $_POST['admin_pa OpenVPN-Admin - - - - - + + + + + - + - - - - - - - + + + + + + +