Beispiel #1
0
def flask_dev_server(host, port):
    """Starts Flask development server for testing without WSGI/Reverse Proxy"""
    try:
        from hyperglass import hyperglass
        from hyperglass import configuration
        from hyperglass import render

        debug_state = configuration.debug_state()
        render.css()
        click.secho(f"✓ Starting Flask development server", fg="green", bold=True)
        hyperglass.app.run(host=host, debug=debug_state, port=port)
    except:
        click.secho("✗ Failed to start test server.", fg="red", bold=True)
        raise
from logzero import logger
from netaddr.core import AddrFormatError
from netaddr import IPNetwork, IPAddress, IPSet  # pylint: disable=unused-import

# Dear PyLint, the netaddr library is a special snowflake. You might not see `IPAddress` get used, \
# but when you use something like `IPNetwork("192.0.2.1/24").ip`, the returned value is \
# IPAddress("192.0.2.1"), so I do actually need this import. <3, -ML

# Project Imports
from hyperglass import configuration

# Configuration Imports
config = configuration.params()

# Logzero Configuration
if configuration.debug_state():
    logzero.loglevel(logging.DEBUG)
else:
    logzero.loglevel(logging.INFO)


class IPType:
    """
    Passes input through IPv4/IPv6 regex patterns to determine if input is formatted as a host \
    (e.g. 192.0.2.1), or as CIDR (e.g. 192.0.2.0/24). is_host() and is_cidr() return a boolean.
    """
    def __init__(self):
        self.ipv4_host = (
            r"^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4]"
            r"[0-9]|[01]?[0-9][0-9]?)?$")
        self.ipv4_cidr = (