&1', escapeshellcmd($script_path), escapeshellarg($username), escapeshellarg($pki_dir) ); exec($command, $output, $return_var); if ($return_var !== 0) { die('Failed to generate config: ' . implode("\n", $output)); } } // Формируем контент $template_content = file_exists($template_path) && is_readable($template_path) ? file_get_contents($template_path) : die ('Error: Neither template: '.$template_path); // Получаем вывод скрипта $script_output = !empty($output) ? implode("\n", $output) : null; // Формируем итоговый контент по приоритетам if ($template_content !== null && $script_output !== null) { // Оба источника доступны - объединяем $config_content = $template_content . "\n" . $script_output; } elseif ($template_content !== null) { // Только шаблон доступен $config_content = $template_content; } elseif ($script_output !== null) { // Только вывод скрипта доступен $config_content = $script_output; } else { // Ничего не доступно - ошибка die('Error: Neither template nor script output available'); } // Прямая отдача контента header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename="' . $server['name'].'-'.$username . '.ovpn"'); header('Content-Length: ' . strlen($config_content)); echo $config_content; exit; } function showApacheAuthRequired() { header('WWW-Authenticate: Basic realm="OpenVPN Config Download"'); header('HTTP/1.0 401 Unauthorized'); echo '
This site uses Apache Basic Authentication. Please enter your credentials in the browser authentication dialog.
If you don\'t see the login prompt, try refreshing the page or check your browser settings.