Skip to content

Commit 1bfbaa7

Browse files
committed
Pretty print
1 parent 4160f64 commit 1bfbaa7

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

IPBanCore/Linux/IPBanLinuxFirewallD.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
3030
using System.Threading;
3131
using System.Threading.Tasks;
3232
using System.Xml;
33+
using System.Xml.Linq;
3334

3435
namespace DigitalRuby.IPBanCore
3536
{
@@ -389,8 +390,20 @@ private bool CreateOrUpdateRule(bool drop, int priority, string ruleIP4, string
389390
ruleElement6.AppendChild(accept6);
390391
}
391392

393+
// make sure forward node is at the end
394+
var forwardNode = doc.DocumentElement.SelectSingleNode("/forward");
395+
if (forwardNode is XmlElement forwardElement)
396+
{
397+
forwardNode.ParentNode.RemoveChild(forwardElement);
398+
doc.DocumentElement.AppendChild(forwardElement);
399+
}
400+
401+
// pretty print
402+
XDocument xDoc = XDocument.Parse(doc.OuterXml);
403+
var xml = xDoc.ToString();
404+
392405
// write the zone file back out and reload the firewall
393-
ExtensionMethods.Retry(() => File.WriteAllText(zoneFile, doc.OuterXml, ExtensionMethods.Utf8EncodingNoPrefix));
406+
ExtensionMethods.Retry(() => File.WriteAllText(zoneFile, xml, ExtensionMethods.Utf8EncodingNoPrefix));
394407
dirty = true;
395408
return true;
396409
}

0 commit comments

Comments
 (0)