&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; } // Обработка создания пользователя //if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'create_user' && !empty(CREATE_CRT) && file_exists(CREATE_CRT)) { if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'create_user' && !empty(CREATE_CRT)) { // Проверка CSRF /* if (empty($_POST['csrf']) || $_POST['csrf'] !== $_SESSION['csrf_token']) { header('HTTP/1.0 403 Forbidden'); die(json_encode(['success' => false, 'message' => 'Invalid CSRF token'])); } */ $server_name = $_POST['server'] ?? ''; $username = trim($_POST['username'] ?? ''); if (empty($username) || !isset($servers[$server_name]) || empty($servers[$server_name]['cert_index'])) { die(json_encode(['success' => false, 'message' => 'Invalid parameters'])); } mb_internal_encoding('UTF-8'); $username = mb_strtolower($username); // Проверка на пробельные символы if (preg_match('/\s/', $username)) { die(json_encode(['success' => false, 'message' => 'Username cannot contain spaces'])); } $server = $servers[$server_name]; $rsa_dir = dirname(dirname($server['cert_index'])); $script_path = CREATE_CRT; $command = sprintf( 'sudo %s %s %s 2>&1', escapeshellcmd($script_path), escapeshellarg($rsa_dir), escapeshellarg($username) ); exec($command, $output, $return_var); if ($return_var === 0) { echo json_encode(['success' => true, 'message' => 'User created successfully']); } else { echo json_encode(['success' => false, 'message' => 'Failed to create user: ' . implode("\n", $output)]); } exit; } ?> <?= htmlspecialchars($page_title) ?>

Create User

$server): ?>

Loading data...
© 2024– — OpenVPN Status Monitoring. Based on openvpn-status-page by rajven. All rights reserved.