用 augeas 修改 centos firewalld 区域文件丢失缩进
modify centos firewalld zone file with augeas loses indentation
我正在尝试使用 augeas 和 xml lens 修改 centos firewalld 区域文件。
默认的 public 区域文件如下所示:
<?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添加新节点无法保持缩进
我正在尝试使用 augeas 和 xml lens 修改 centos firewalld 区域文件。
默认的 public 区域文件如下所示:
<?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添加新节点无法保持缩进