using System.Text.Json; namespace UCVL.VPNPlus; // Non-interactive recovery for a verified, separate test watchdog. No login, // connection, install, token export, or forced takeover of another owner's lease. internal static class NetworkRecoveryTool { internal static async Task RunAsync() { var report = new Dictionary { ["time"] = DateTimeOffset.Now, ["kind"] = "recover_owned_network_only", ["passed"] = false, }; try { using var deadline = new CancellationTokenSource(TimeSpan.FromSeconds(45)); await using (var manager = new XrayManager()) await manager.InitializeAsync(deadline.Token).ConfigureAwait(false); if (new[] { AppPaths.TunStateFile, AppPaths.ProxyStateFile, AppPaths.PidFile, Path.Combine(AppPaths.DataDirectory, "proxy-dns-owned.json") }.Any(File.Exists)) throw new IOException("Network recovery journal remains; recovery has not been confirmed."); report["passed"] = true; return 0; } catch (Exception error) { report["error"] = error.GetBaseException().Message; return 51; } finally { File.WriteAllText(Path.Combine(AppContext.BaseDirectory, "network-recovery-result.json"), JsonSerializer.Serialize(report, new JsonSerializerOptions { WriteIndented = true })); } } }