# Path: wifiphisher/common/constants.py
# NETWORK_GW_IP = "10.0.0.1"
# 
# PORT = 8080
# 
# SSL_PORT = 443
# 
# Path: wifiphisher/common/utilities.py
# def execute_commands(commands):
#     """Execute each command and log any errors."""
#     for command in commands:
#         _, error = Popen(command.split(), stderr=PIPE, stdout=DN).communicate()
#         if error:
#             logger.error(
#                 "{command} has failed with the following error:\n{error}".
#                 format(command=command, error=error))


from wifiphisher.common.constants import NETWORK_GW_IP, PORT, SSL_PORT
from wifiphisher.common.utilities import execute_commands
                internal_interface, external_interface)
        ])

    @staticmethod
    def clear_rules():
        # type: () -> None
        """Clear all rules."""
        execute_commands([
            "iptables -F", "iptables -X", "iptables -t nat -F",
            "iptables -t nat -X"
        ])

    @staticmethod
    def redirect_requests_localhost():
        # type: () -> None
        """Redirect HTTP, HTTPS & DNS requests to localhost.

        Redirect the following requests to localhost:
            * HTTP (Port 80)
            * HTTPS (Port 443)
            * DNS (Port 53)
        """
        execute_commands([
            "iptables -t nat -A PREROUTING -p tcp --dport 80 -j DNAT "
            "--to-destination {}:{}".format(NETWORK_GW_IP, PORT),
            "iptables -t nat -A PREROUTING -p udp --dport 53 -j DNAT "
            "--to-destination {}:{}".format(NETWORK_GW_IP, 53),
            "iptables -t nat -A PREROUTING -p tcp --dport 53 -j DNAT "
            "--to-destination {}:{}".format(NETWORK_GW_IP, 53),
            "iptables -t nat -A PREROUTING -p tcp --dport 443 -j DNAT "

# Path: wifiphisher/common/constants.py
# NETWORK_GW_IP = "10.0.0.1"
# 
# PORT = 8080
# 
# SSL_PORT = 443
# 
# Path: wifiphisher/common/utilities.py
# def execute_commands(commands):
#     """Execute each command and log any errors."""
#     for command in commands:
#         _, error = Popen(command.split(), stderr=PIPE, stdout=DN).communicate()
#         if error:
#             logger.error(
#                 "{command} has failed with the following error:\n{error}".
#                 format(command=command, error=error))


# Path: wifiphisher/common/firewall.py
from wifiphisher.common.constants import NETWORK_GW_IP, PORT, SSL_PORT
from wifiphisher.common.utilities import execute_commands

                internal_interface, external_interface)
        ])

    @staticmethod
    def clear_rules():
        # type: () -> None
        """Clear all rules."""
        execute_commands([
            "iptables -F", "iptables -X", "iptables -t nat -F",
            "iptables -t nat -X"
        ])

    @staticmethod
    def redirect_requests_localhost():
        # type: () -> None
        """Redirect HTTP, HTTPS & DNS requests to localhost.

        Redirect the following requests to localhost:
            * HTTP (Port 80)
            * HTTPS (Port 443)
            * DNS (Port 53)
        """
        execute_commands([
            "iptables -t nat -A PREROUTING -p tcp --dport 80 -j DNAT "
            "--to-destination {}:{}".format(NETWORK_GW_IP, PORT),
            "iptables -t nat -A PREROUTING -p udp --dport 53 -j DNAT "
            "--to-destination {}:{}".format(NETWORK_GW_IP, 53),
            "iptables -t nat -A PREROUTING -p tcp --dport 53 -j DNAT "
            "--to-destination {}:{}".format(NETWORK_GW_IP, 53),
            "iptables -t nat -A PREROUTING -p tcp --dport 443 -j DNAT "

            "--to-destination {}:{}".format(NETWORK_GW_IP, SSL_PORT)