From 10847b39b869455a23fb29eaae02cf70be5a74a2 Mon Sep 17 00:00:00 2001 From: Shreyas Zare Date: Sat, 9 Nov 2024 20:20:13 +0530 Subject: [PATCH] FilterAaaa: updated InitializeAsync() to update the existing config to include the new option. --- Apps/FilterAaaaApp/App.cs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/Apps/FilterAaaaApp/App.cs b/Apps/FilterAaaaApp/App.cs index ff63418e..bb0562e4 100644 --- a/Apps/FilterAaaaApp/App.cs +++ b/Apps/FilterAaaaApp/App.cs @@ -65,7 +65,21 @@ namespace FilterAaaa JsonElement jsonConfig = jsonDocument.RootElement; _enableFilterAaaa = jsonConfig.GetPropertyValue("enableFilterAaaa", false); - _defaultTtl = jsonConfig.GetPropertyValue("defaultTtl", 30u); + + if (jsonConfig.TryGetProperty("defaultTtl", out JsonElement jsonValue)) + { + if (!jsonValue.TryGetUInt32(out _defaultTtl)) + _defaultTtl = 30u; + } + else + { + _defaultTtl = 30u; + + //update config for new option + config = config.Replace("\"bypassLocalZones\"", "\"defaultTtl\": 30,\r\n \"bypassLocalZones\""); + await File.WriteAllTextAsync(Path.Combine(dnsServer.ApplicationFolder, "dnsApp.config"), config); + } + _bypassLocalZones = jsonConfig.GetPropertyValue("bypassLocalZones", false); if (jsonConfig.TryReadArray("bypassNetworks", NetworkAddress.Parse, out NetworkAddress[] bypassNetworks))