修改 CentOS 防火墙区域文件,使用 AUGEAS 丢失缩进



我正在尝试使用augeas和xml镜头修改centos防火墙区域文件。

默认公共区域文件如下所示:

<?xml version="1.0" encoding="utf-8"?>
<zone>
  <short>Public</short>
  <description>For use in public areas. You do not trust the other computers on networks to not harm your computer. Only selected incoming connections are accepted.</description>
  <service name="dhcpv6-client"/>
  <service name="ssh"/>
</zone>

如果我将其加载到augtool中,我会得到以下内容:

# augtool --noload --noautoload --echo
augtool> set /augeas/load/xml/lens "Xml.lns"
augtool> set /augeas/load/xml/incl "/etc/firewalld/zones/public.xml"
augtool> load
augtool> print /files/etc/firewalld/zones/public.xml
/files/etc/firewalld/zones/public.xml
/files/etc/firewalld/zones/public.xml/#declaration
/files/etc/firewalld/zones/public.xml/#declaration/#attribute
/files/etc/firewalld/zones/public.xml/#declaration/#attribute/version = "1.0"
/files/etc/firewalld/zones/public.xml/#declaration/#attribute/encoding = "utf-8"
/files/etc/firewalld/zones/public.xml/zone
/files/etc/firewalld/zones/public.xml/zone/#text[1] = "n  "
/files/etc/firewalld/zones/public.xml/zone/short
/files/etc/firewalld/zones/public.xml/zone/short/#text = "Public"
/files/etc/firewalld/zones/public.xml/zone/#text[2] = "  "
/files/etc/firewalld/zones/public.xml/zone/description
/files/etc/firewalld/zones/public.xml/zone/description/#text = "For use in public areas. You do not trust the other computers on networks to not harm your computer. Only selected incoming connections are accepted."
/files/etc/firewalld/zones/public.xml/zone/#text[3] = "  "
/files/etc/firewalld/zones/public.xml/zone/service[1] = "#empty"
/files/etc/firewalld/zones/public.xml/zone/service[1]/#attribute
/files/etc/firewalld/zones/public.xml/zone/service[1]/#attribute/name = "dhcpv6-client"
/files/etc/firewalld/zones/public.xml/zone/#text[4] = "  "
/files/etc/firewalld/zones/public.xml/zone/service[2] = "#empty"
/files/etc/firewalld/zones/public.xml/zone/service[2]/#attribute

然后我试试

augtool> defnode service /files/etc/firewalld/zones/public.xml/zone/service[attribute/#name="http"]
augtool> set $service "#empty"
augtool> set $service/#attribute/name "http"
augtool> save

如果我现在查看 public.xml 文件,它看起来像:

<?xml version="1.0" encoding="utf-8"?>
<zone>
  <short>Public</short>
  <description>For use in public areas. You do not trust the other computers on networks to not harm your computer. Only selected incoming connections are accepted.</description>
  <service name="dhcpv6-client"/>
  <service name="ssh"/>
<service name="http"/>
</zone>

谁能建议我如何在我添加的<service name="http">条目之前保留缩进?

使用 Augeas 添加新节点时无法保留缩进。

相关内容

  • 没有找到相关文章

最新更新