defaults to master.conf // POST file= content= // // RESPONSE // GET {"ok":true,"content":"…","file":"…","allowed":["…"]} // POST {"ok":true,"push":[{"host","ok","ready","error"}, …]} // push is empty for host confs and on hosts with no partners // {"ok":false,"error":"Not allowed"|"Syntax error: …"|"Method not allowed"} // // DEPENDS ON // include/config.php vv_get_conf_files(), vv_read_conf_raw(), // vv_push_master_conf(), vv_push_setup_state() // include/confform.php vv_conf_syntax_error(), vv_conf_edit() // ═══════════════════════════════════════════════════════════════════════════════════════════════ header('Content-Type: application/json'); require_once dirname(__DIR__) . '/include/config.php'; require_once dirname(__DIR__) . '/include/confform.php'; $allowed = vv_get_conf_files(); if ($_SERVER['REQUEST_METHOD'] === 'GET') { $file = trim($_GET['file'] ?? 'master.conf'); if (!in_array($file, $allowed, true) || str_contains($file, '..')) { echo json_encode(['ok' => false, 'error' => 'Not allowed']); exit; } echo json_encode(['ok' => true, 'content' => vv_read_conf_raw($file), 'file' => $file, 'allowed' => $allowed]); exit; } if ($_SERVER['REQUEST_METHOD'] === 'POST') { $file = trim($_POST['file'] ?? ''); $content = $_POST['content'] ?? ''; if (!in_array($file, $allowed, true) || str_contains($file, '..')) { echo json_encode(['ok' => false, 'error' => 'Not allowed']); exit; } // Every script sources these, and master.conf is pushed to every partner from here — a // syntax error saved through this endpoint would propagate the outage across the mesh. // Checked here as well as inside vv_conf_edit() so the editor can show bash's own complaint; // the write path only knows whether to proceed, not what to tell the person typing. $syntax = vv_conf_syntax_error($content, $file); if ($syntax !== null) { echo json_encode(['ok' => false, 'error' => 'Syntax error: ' . $syntax, 'push' => []]); exit; } $written = vv_conf_edit($file, fn() => $content, [], ['whole-file']); $push = []; if ($written && $file === 'master.conf') { $push = vv_push_master_conf(); vv_push_setup_state(); } echo json_encode(['ok' => $written, 'push' => $push]); exit; } echo json_encode(['ok' => false, 'error' => 'Method not allowed']);