<?php
header('Content-Type: application/json');
require_once dirname(__DIR__) . '/include/scheduler.php';

$name    = trim($_POST['name']    ?? '');
$enabled = ($_POST['enabled'] ?? '0') === '1';

if (!$name || !preg_match('/^[A-Z_]+_RSYNC_ENABLED$/', $name)) {
    echo json_encode(['ok' => false, 'error' => 'Invalid flag name']);
    exit;
}

$ok = vv_conf_flag_set($name, $enabled);
echo json_encode(['ok' => $ok, 'error' => $ok ? null : 'Failed to write master.conf']);
