<?php header('Content-Type: application/json'); ini_set('display_errors', 0); $inputData = file_get_contents('php://input'); $data = json_decode($inputData, true); if (!$data) { echo json_encode(['success' => false, 'message' => 'Пустой запрос']); exit; } // Жесткая очистка строк $clean_hostname = preg_replace('/[^a-zA-Z0-9_\-\.]/', '', substr(trim($data['hostname']), 0, 16)); $clean_username = preg_replace('/[^a-zA-Z0-9_\-\.]/', '', substr(trim($data['username']), 0, 16)); $clean_password = preg_replace('/[^a-zA-Z0-9_\-\.]/', '', substr(trim($data['password']), 0, 16)); // Пишем конфиг с нуля (всегда новые данные) $configContent = "SYS_LANG=" . $data['lang'] . "\n"; $configContent .= "SYS_LAYOUT=" . $data['layout'] . "\n"; $configContent .= "SYS_TIMEZONE=" . $data['timezone'] . "\n"; $configContent .= "SYS_HOSTNAME=" . $clean_hostname . "\n"; $configContent .= "DISK_MODE=" . $data['disk_mode'] . "\n"; $configContent .= "SELECTED_DISKS=" . implode(' ', $data['disks']) . "\n"; $configContent .= "SYS_USER=" . $clean_username . "\n"; $configContent .= "SYS_PASS=" . $clean_password . "\n"; $target_file = __DIR__ . '/install_config.txt'; // Перезаписываем файл актуальными данными if (file_put_contents($target_file, $configContent) !== false) { chmod($target_file, 0600); // Передаем управление ОДНОМУ управляющему скрипту exec('sudo /srv/http/installer/api/disk_prepare.sh > /dev/null 2>&1 &'); echo json_encode(['success' => true, 'message' => 'Установка успешно запущена.']); } else { echo json_encode(['success' => false, 'message' => 'Ошибка записи конфигурации']); } exit;