3 ܓiC@s*ddlmZmZmZGdddeeZdS))PluginIndependentPlugin SoSPredicatec@sDeZdZdZdZdZdZdZdZd d Z ddZ ddZ ddZ dS)FirewallTablesaCollects information about local firewall tables, such as iptables, and nf_tables (via nft). Note that this plugin does _not_ collect firewalld information, which is handled by a separate plugin. Collections from this plugin are largely gated byt the presence of relevant kernel modules - for example, the plugin will not collect the nf_tables ruleset if both the `nf_tables` and `nfnetlink` kernel modules are not currently loaded (unless using the --allow-system-changes option). zfirewall tablesZfirewall_tablesnetworksystem /etc/nftables ip_tables ip6_tables nf_tables nfnetlinkebtablescCs2d|}d|d}|j|t||dgdddS)z Collecting iptables rules for a table loads either kernel module of the table name (for kernel <= 3), or nf_tables (for kernel >= 4). If neither module is present, the rules must be empty.Ziptable_z iptables -t z -nvLr )kmods)predN)add_cmd_outputr)self tablenamemodnamecmdr%/usr/lib/python3.6/firewall_tables.pycollect_iptables  zFirewallTables.collect_iptablecCs2d|}d|d}|j|t||dgdddS)z& Same as function above, but for ipv6 Z ip6table_z ip6tables -t z -nvLr )r)rN)rr)rrrrrrrcollect_ip6table*s  zFirewallTables.collect_ip6tablecCs&t|ddgddid}|jd|ddS) zS Collects nftables rulesets with 'nft' commands if the modules are present r r rall)rZrequiredznft -a list rulesetT)rZchanges)rZcollect_cmd_output)rZnft_predrrrcollect_nftables3s  zFirewallTables.collect_nftablesc Cs|j}ggd}|ddkr&|dnd}xZ|jD]N}|jdd}t|dkr4|ddkr4|d|kr4||dj|d q4Wd }y*d }t|d d d}|j} WdQRXWntk r|} YnXx2| jD]&} |ddkr| |dkr|j| qWy*d} t| d d d} | j} WdQRXWntk rF|} YnXx8| jD],} |ddkrR| |dkrR|j | qRW|ddksd|dkr|j dt |ddgdd|ddksd|dkr|j dt |ddgdd|j dddgdS)N)ipip6Zstatusroutputtablezmangle filter nat z/proc/net/ip_tables_namesrzUTF-8)encodingrz/proc/net/ip6_tables_namesrfilterziptables -vnxLZiptable_filterr )r)rzip6tables -vnxLZip6table_filterz /etc/nftablesz/etc/sysconfig/nftables.confz/etc/nftables.conf) r splitlinessplitlenappendopenreadIOErrorrrrrZ add_copy_spec) rZnft_listZ nft_ip_tablesZ nft_lineslineZwordsZdefault_ip_tablesZproc_net_ip_tablesZifileZip_tables_namesr Zproc_net_ip6_tablesZipfilerrrsetup>sN    zFirewallTables.setupN)rr)r)r r r r r ) __name__ __module__ __qualname____doc__Z short_descZ plugin_nameZprofilesfilesZ kernel_modsrrrr.rrrrr s    rN)Zsos.report.pluginsrrrrrrrr s