#!/usr/bin/python2 -Es # -*- coding: utf-8 -*- # # Copyright (C) 2009-2016 Red Hat, Inc. # # Authors: # Thomas Woerner
# Jiri Popelka
# # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see
. # from gi.repository import GObject import sys sys.modules['gobject'] = GObject import argparse import os from firewall.client import FirewallClientIPSetSettings, \ FirewallClientZoneSettings, FirewallClientServiceSettings, \ FirewallClientIcmpTypeSettings, FirewallClientHelperSettings from firewall.errors import FirewallError from firewall import config from firewall.core.fw_test import Firewall_test from firewall.functions import joinArgs, splitArgs from firewall.core.io.functions import check_config from firewall.core.io.zone import zone_reader from firewall.core.io.service import service_reader from firewall.core.io.ipset import ipset_reader from firewall.core.io.icmptype import icmptype_reader from firewall.core.io.helper import helper_reader from firewall.command import FirewallCommand # check for root user def assert_root(): if os.getuid() != 0: sys.stderr.write("You need to be root to run %s.\n" % sys.argv[0]) sys.exit(-1) SYSTEM_CONFIG_FIREWALL = config.SYSCONFIGDIR + '/system-config-firewall' def __usage(): sys.stdout.write(""" Usage: firewall-offline-cmd [OPTIONS...] If no options are given, configuration from '%s' will be migrated. General Options -h, --help Prints a short help text and exists -V, --version Print the version string of firewalld -q, --quiet Do not print status messages --system-config Path to firewalld system configuration --default-config Path to firewalld default configuration --check-config Check system and default configuration Lokkit Compatibility Options --migrate-system-config-firewall=
Import configuration data from the given configuration file. --enabled Enable firewall (default) --disabled Disable firewall --addmodule=
Ignored option, was used to enable an iptables module --removemodule=
Ignored option, was used to disable an iptables module -s
, --service=
Enable a service in the default zone (example: ssh) --remove-service=
Disable a service in the default zone (example: ssh) -p
[-
]:
, --port=
[-
]:
Enable a port in the default zone (example: ssh:tcp) -t
, --trust=
Bind an interface to the trusted zone -m
, --masq=
Enables masquerading in the default zone, interface argument is ignored. This is IPv4 only. --custom-rules=[
:][
:]
Ignored option. Was used to add custom rules to the firewall (Example: ipv4:filter:%s/ipv4_filter_addon) --forward-port=if=
:port=
:proto=
[:toport=
][:toaddr=
] Forward the port with protocol for the interface to either another local destination port (no destination address given) or to an other destination address with an optional destination port. This will be added to the default zone. This is IPv4 only. --block-icmp=
Block this ICMP type in the default zone. The default is to accept all ICMP types. Log Denied Options --get-log-denied Print the log denied value --set-log-denied=
Set log denied value Automatic Helpers Options --get-automatic-helpers Print the automatic helpers value --set-automatic-helpers=
Set automatic helpers value Zone Options --get-default-zone Print default zone for connections and interfaces --set-default-zone=
Set default zone --get-zones Print predefined zones --get-services Print predefined services --get-icmptypes Print predefined icmptypes --get-zone-of-interface=
Print name of the zone the interface is bound to --get-zone-of-source=
[/
]|
|ipset:
Print name of the zone the source is bound to --list-all-zones List everything added for or enabled in all zones --new-zone=
Add a new empty zone --new-zone-from-file=
[--name=
] Add a new zone from file with optional name override [P only] --delete-zone=
Delete an existing zone --load-zone-defaults=
Load zone default settings [Z] --zone=
Use this zone to set or query options, else default zone Usable for options marked with [Z] --set-description=
Set new description to zone --get-description Print description for zone --get-target Get the zone target --set-target=
Set the zone target --info-zone=
Print information about a zone --path-zone=
Print file path of a zone IPSet Options --new-ipset=
--type=
[--option=
[=
]].. Add a new empty ipset --new-ipset-from-file=
[--name=
] Add a new ipset from file with optional name override [P only] --delete-ipset=
Delete an existing ipset --load-ipset-defaults=
Load ipset default settings --info-ipset=
Print information about an ipset --path-ipset=
Print file path of an ipset --get-ipsets Print predefined ipsets --ipset=
--set-description=
Set new description to ipset --ipset=
--get-description Print description for ipset --ipset=
--set-short=
Set new short description to ipset --ipset=
--get-short Print short description for ipset --ipset=
--add-entry=
Add a new entry to an ipset --ipset=
--remove-entry=
Remove an entry from an ipset --ipset=
--query-entry=
Return whether ipset has an entry --ipset=
--get-entries List entries of an ipset --ipset=
--add-entries-from-file=
Add a new entries to an ipset [P] --ipset=
--remove-entries-from-file=
Remove entries from an ipset [P] IcmpType Options --new-icmptype=
Add a new empty icmptype --new-icmptype-from-file=
[--name=
] Add a new icmptype from file with optional name override [P only] --delete-icmptype=
Delete an existing icmptype --load-icmptype-defaults=
Load icmptype default settings --info-icmptype=
Print information about an icmptype --path-icmptype=
Print file path of an icmptype --icmptype=
--set-description=
Set new description to icmptype --icmptype=
--get-description Print description for icmptype --icmptype=
--set-short=
Set new short description to icmptype --icmptype=
--get-short Print short description for icmptype --icmptype=
--add-destination=
Enable destination for ipv in icmptype --icmptype=
--remove-destination=
Disable destination for ipv in icmptype --icmptype=
--query-destination=
Return whether destination ipv is enabled in icmptype --icmptype=
--get-destinations List destinations in icmptype Service Options --new-service=
Add a new empty service --new-service-from-file=
[--name=
] Add a new service from file with optional name override [P only] --delete-service=
Delete an existing service --load-service-defaults=
Load icmptype default settings --info-service=
Print information about a service --path-service=
Print file path of a service --service=
--set-description=
Set new description to service --service=
--get-description Print description for service --service=
--set-short=
Set new short description to service --service=
--get-short Print short description for service --service=
--add-port=
[-
]/
Add a new port to service --service=
--remove-port=
[-
]/
Remove a port from service --service=
--query-port=
[-
]/
Return whether the port has been added for service --service=
--get-ports List ports of service --service=
--add-protocol=
Add a new protocol to service --service=
--remove-protocol=
Remove a protocol from service --service=
--query-protocol=
Return whether the protocol has been added for service --service=
--get-protocols List protocols of service --service=
--add-source-port=
[-
]/
Add a new source port to service --service=
--remove-source-port=
[-
]/
Remove a source port from service --service=
--query-source-port=
[-
]/
Return whether the source port has been added for service [P only] --service=
--get-source-ports List source ports of service --service=
--add-module=
Add a new module to service --service=
--remove-module=
Remove a module from service --service=
--query-module=
Return whether the module has been added for service --service=
--get-modules List modules of service --service=
--set-destination=
:
[/
] Set destination for ipv to address in service --service=
--remove-destination=
Disable destination for ipv i service --service=
--query-destination=
:
[/
] Return whether destination ipv is set for service --service=
--get-destinations List destinations in service Options to Adapt and Query Zones --list-all List everything added for or enabled in a zone [Z] --list-services List services added for a zone [Z] --add-service=
Add a service for a zone [Z] --remove-service-from-zone=
Remove a service from a zone [Z] --query-service=
Return whether service has been added for a zone [Z] --list-ports List ports added for a zone [Z] --add-port=
[-
]/
Add the port for a zone [Z] --remove-port=
[-
]/
Remove the port from a zone [Z] --query-port=
[-
]/
Return whether the port has been added for zone [Z] --list-protocols List protocols added for a zone [Z] --add-protocol=
Add the protocol for a zone [Z] --remove-protocol=
Remove the protocol from a zone [Z] --query-protocol=
Return whether the protocol has been added for zone [Z] --list-source-ports List source ports added for a zone [Z] --add-source-port=
[-
]/
Add the source port for a zone [Z] --remove-source-port=
[-
]/
Remove the source port from a zone [Z] --query-source-port=
[-
]/
Return whether the source port has been added for zone [Z] --list-icmp-blocks List Internet ICMP type blocks added for a zone [Z] --add-icmp-block=
Add an ICMP block for a zone [Z] --remove-icmp-block=
Remove the ICMP block from a zone [Z] --query-icmp-block=
Return whether an ICMP block has been added for a zone [Z] --add-icmp-block-inversion Enable inversion of icmp blocks for a zone [Z] --remove-icmp-block-inversion Disable inversion of icmp blocks for a zone [Z] --query-icmp-block-inversion Return whether inversion of icmp blocks has been enabled for a zone [Z] --list-forward-ports List IPv4 forward ports added for a zone [Z] --add-forward-port=port=
[-
]:proto=
[:toport=
[-
]][:toaddr=
[/
]] Add the IPv4 forward port for a zone [Z] --remove-forward-port=port=
[-
]:proto=
[:toport=
[-
]][:toaddr=
[/
]] Remove the IPv4 forward port from a zone [Z] --query-forward-port=port=
[-
]:proto=
[:toport=
[-
]][:toaddr=
[/
]] Return whether the IPv4 forward port has been added for a zone [Z] --add-masquerade Enable IPv4 masquerade for a zone [Z] --remove-masquerade Disable IPv4 masquerade for a zone [Z] --query-masquerade Return whether IPv4 masquerading has been enabled for a zone [Z] --list-rich-rules List rich language rules added for a zone [Z] --add-rich-rule=
Add rich language rule 'rule' for a zone [Z] --remove-rich-rule=
Remove rich language rule 'rule' from a zone [Z] --query-rich-rule=
Return whether a rich language rule 'rule' has been added for a zone [Z] Options to Handle Bindings of Interfaces --list-interfaces List interfaces that are bound to a zone [Z] --add-interface=
Bind the
to a zone [Z] --change-interface=
Change zone the
is bound to [Z] --query-interface=
Query whether
is bound to a zone [Z] --remove-interface=
Remove binding of
from a zone [Z] Options to Handle Bindings of Sources --list-sources List sources that are bound to a zone [Z] --add-source=
[/
]|
|ipset:
Bind the source to a zone [Z] --change-source=
[/
]|
|ipset:
Change zone the source is bound to [Z] --query-source=
[/
]|
|ipset:
Query whether the source is bound to a zone [Z] --remove-source=
[/
]|
|ipset:
Remove binding of the source from a zone [Z] Helper Options --new-helper=
--module=
[--family=
] Add a new helper --new-helper-from-file=
[--name=
] Add a new helper from file with optional name --delete-helper=
Delete an existing helper --load-helper-defaults=
Load helper default settings --info-helper=
Print information about an helper --path-helper=
Print file path of an helper --get-helpers Print predefined helpers --helper=
--set-description=
Set new description to helper --helper=
--get-description Print description for helper --helper=
--set-short=
Set new short description to helper --helper=
--get-short Print short description for helper --helper=
--add-port=
[-
]/
Add a new port to helper --helper=
--remove-port=
[-
]/