Skip to content

Commit

Permalink
Pretty print
Browse files Browse the repository at this point in the history
  • Loading branch information
jjxtra committed Jul 11, 2023
1 parent 4160f64 commit 1bfbaa7
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion IPBanCore/Linux/IPBanLinuxFirewallD.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
using System.Threading;
using System.Threading.Tasks;
using System.Xml;
using System.Xml.Linq;

namespace DigitalRuby.IPBanCore
{
Expand Down Expand Up @@ -389,8 +390,20 @@ private bool CreateOrUpdateRule(bool drop, int priority, string ruleIP4, string
ruleElement6.AppendChild(accept6);
}

// make sure forward node is at the end
var forwardNode = doc.DocumentElement.SelectSingleNode("/forward");
if (forwardNode is XmlElement forwardElement)
{
forwardNode.ParentNode.RemoveChild(forwardElement);
doc.DocumentElement.AppendChild(forwardElement);
}

// pretty print
XDocument xDoc = XDocument.Parse(doc.OuterXml);
var xml = xDoc.ToString();

// write the zone file back out and reload the firewall
ExtensionMethods.Retry(() => File.WriteAllText(zoneFile, doc.OuterXml, ExtensionMethods.Utf8EncodingNoPrefix));
ExtensionMethods.Retry(() => File.WriteAllText(zoneFile, xml, ExtensionMethods.Utf8EncodingNoPrefix));
dirty = true;
return true;
}
Expand Down

0 comments on commit 1bfbaa7

Please sign in to comment.