&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) : null; // Получаем вывод скрипта $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; $clean_url = strtok($_SERVER['REQUEST_URI'], '?'); header("Refresh:0; url=" . $clean_url); exit; } ?>