示例#1
0
def forbidden(error: str) -> Union[str, Tuple[str, int]]:
    """the function returns the 403 error page when the user is logged in"""
    utils = Webutils()
    payload = utils.get_default_payload("403 Error", "error")
    payload.error_code = 403
    payload.error_desc = error
    return render_template('error.html', vars=payload), 403
示例#2
0
def index():
    """the function returns the index page when the user is logged in"""
    utils = Webutils()
    if utils.check_login() is True:
        return render_template('index.html',
                               vars=utils.get_default_payload("Home"))
    return login("", None)
示例#3
0
def page_not_found(error):
    """the function returns the 404 error page when the user is logged in"""
    utils = Webutils()
    if utils.check_login() is True:
        return render_template('404.html',
                               vars=utils.get_default_payload(
                                   "404 Error", "error")), 404
    return login("", None)
示例#4
0
def page_not_found(error: int) -> Union[str, Tuple[str, int]]:
    """the function returns the 404 error page when the user is logged in"""
    utils = Webutils()
    if utils.check_login(request) is True:
        return render_template('404.html',
                               vars=utils.get_default_payload(
                                   "404 Error", "error")), 404
    return login()
示例#5
0
def options(saved=False):
    """the function returns the options page when the user is logged in"""
    utils = Webutils()
    if utils.check_login() is True:
        payload = utils.get_default_payload("Options")
        payload.config = utils.cfg
        payload.saved = saved
        return render_template('options.html', vars=payload)
    return login("", None)
示例#6
0
def page_not_found(error: str) -> Union[str, Tuple[str, int]]:
    """the function returns the 404 error page when the user is logged in"""
    utils = Webutils()
    if utils.check_login(request) is True:
        payload = utils.get_default_payload("404 Error", "error")
        payload.error_code = 404
        payload.error_desc = error
        return render_template('error.html', vars=payload), 404
    return login()
示例#7
0
def custom(saved=False):
    """the function returns the custom rules page when the user is logged in"""
    utils = Webutils()
    if utils.check_login() is True:
        payload = utils.get_default_payload("Custom")
        payload.rules = utils.get_rule_list("custom")
        payload.custom = utils.get_rule_status("custom") == "custom"
        payload.saved = saved
        return render_template('custom.html', vars=payload)
    return login("", None)
示例#8
0
def whitelist(saved=False):
    """the function returns the whitelist page when the user is logged in"""
    utils = Webutils()
    rules = RulesHandler()
    if utils.check_login() is True:
        payload = utils.get_default_payload("Whitelist")
        payload.addresses = rules.get_rules_for_web("whitelist")
        payload.custom = rules.diff_new_current("whitelist")
        payload.saved = saved
        return render_template('whitelist.html', vars=payload)
    return login("", None)
示例#9
0
def apply(saved=False, step=1):
    """the function returns the apply page when the user is logged in"""
    utils = Webutils()
    if utils.check_login() is True:
        payload = utils.get_default_payload("Apply")
        payload.saved = saved
        payload.step = step
        payload.lastapplied = utils.get_last_accept_time()
        payload.running = utils.check_acceptance_running()
        payload.accepttime = utils.cfg.get_value("ACCEPTANCE", "time")
        return render_template(
            'apply.html', vars=payload)
    return login("", None)
示例#10
0
def login(message, messagetype):
    """
    the function returns the login page which shows messages
    also the function updates the last commit informations in the config file
    """
    utils = Webutils()
    utils.update_last_commit_infos()
    payload = utils.get_default_payload("Signin", "signin")
    if messagetype is not None:
        payload.messagetype = messagetype
    if message is not None:
        payload.message = message
    return render_template('login.html', vars=payload)
示例#11
0
def ports(saved=False):
    """the function returns the ports page when the user is logged in"""
    utils = Webutils()
    if utils.check_login() is True:
        payload = utils.get_default_payload("Ports")
        payload.tcp = utils.get_rule_list("tcp")
        payload.udp = utils.get_rule_list("udp")
        payload.custom = False
        if utils.get_rule_status("tcp") == "custom" or utils.get_rule_status(
                "udp") == "custom":
            payload.custom = True
        payload.saved = saved
        return render_template('ports.html', vars=payload)
    return login("", None)
示例#12
0
def ports(saved=False):
    """the function returns the ports page when the user is logged in"""
    utils = Webutils()
    rules = RulesHandler()
    if utils.check_login() is True:
        payload = utils.get_default_payload("Ports")
        payload.tcp = rules.get_rules_for_web("tcp")
        payload.udp = rules.get_rules_for_web("udp")
        payload.custom = False
        if rules.diff_new_current("tcp") is True or rules.diff_new_current(
                "udp") is True:
            payload.custom = True
        payload.saved = saved
        return render_template('ports.html', vars=payload)
    return login("", None)
示例#13
0
def options(saved: bool = False, error: str = "") -> str:
    """the function returns the options page when the user is logged in"""
    utils = Webutils()
    if utils.check_login(request) is True:
        payload = utils.get_default_payload("Options")
        payload.lead = """
            On this page you can configure easywall.<br />
            All entries from the configuration files for the core
            and the web interface are available.<br />
            Some entries require a restart of the respective program part.
        """
        payload.config = utils.cfg_easywall
        payload.config_web = utils.cfg
        payload.saved = saved
        payload.error = error
        return render_template('options.html', vars=payload)
    return login()
示例#14
0
def blacklist(saved: bool = False) -> str:
    """the function returns the blacklist page when the user is logged in"""
    utils = Webutils()
    rules = RulesHandler()
    if utils.check_login(request) is True:
        payload = utils.get_default_payload("Blacklist")
        payload.lead = """
            On this page you can list IP addresses that are not allowed to connect to this machine.
            <br />
            Please check the IP addresses carefully, as they are not checked by easywall.<br />
            You can add IPv4 and IPv6 addresses to the list.
        """
        payload.addresses = rules.get_rules_for_web("blacklist")
        payload.custom = rules.diff_new_current("blacklist")
        payload.saved = saved
        return render_template('blacklist.html', vars=payload)
    return login()
示例#15
0
def custom(saved: bool = False) -> str:
    """the function returns the custom rules page when the user is logged in"""
    utils = Webutils()
    rules = RulesHandler()
    if utils.check_login(request) is True:
        payload = utils.get_default_payload("Custom")
        payload.lead = """
            On this page you can add your own firewall rules.<br />
            Please check the rules for accuracy, as these are not tested by easywall.<br />
            <br />
            To add your own rule, simply copy the rule into the text box. One rule per line.<br />
            It is important to omit the iptables command.<br />
            Example: <code>-P FORWARD DROP</code>
        """
        payload.rules = rules.get_rules_for_web("custom")
        payload.custom = rules.diff_new_current("custom")
        payload.saved = saved
        return render_template('custom.html', vars=payload)
    return login()
示例#16
0
def apply(saved: bool = False, step: int = 1) -> str:
    """
    the function returns the apply page when the user is logged in
    """
    utils = Webutils()
    if utils.check_login(request) is True:
        payload = utils.get_default_payload("Apply")
        payload.lead = """
            The defined firewall rules were not automatically activated for security reasons.<br>
            On this page, you can safely apply the defined rules.<br>
            The activation takes place in two steps and an exclusion from the server
            should be prevented.
            """
        payload.saved = saved
        payload.step = step
        payload.lastapplied = utils.get_last_accept_time()
        payload.running = step > 1
        payload.accepttime = str(
            utils.cfg_easywall.get_value("ACCEPTANCE", "duration"))
        return render_template('apply.html', vars=payload)
    return login()
示例#17
0
def forwarding(saved: bool = False) -> str:
    """
    TODO: Docu
    """
    utils = Webutils()
    rules = RulesHandler()
    if utils.check_login(request):
        payload = utils.get_default_payload("Port Forwarding")
        payload.lead = """
            This page allows you to forward ports from the local system to ports on the
            Internet.<br />
            This is especially useful if the port of an application cannot be changed.<br />
            Enter the port type, source and destination.<br />
            You do not have to release the public port separately, easywall will do that for you.
        """
        payload.forwardings = rules.get_rules_for_web("forwarding")
        payload.custom = False
        if rules.diff_new_current("forwarding"):
            payload.custom = True
        payload.saved = saved
        return render_template('forwarding.html', vars=payload)
    return login()
示例#18
0
def ports(saved: bool = False) -> str:
    """the function returns the ports page when the user is logged in"""
    utils = Webutils()
    rules = RulesHandler()
    if utils.check_login(request) is True:
        payload = utils.get_default_payload("Open Ports")
        payload.lead = """
            On this page you can open ports for incoming connections.<br />
            You can add tcp and udp ports.<br />
            Please check whether the entries in the list are needed in the future and
            remove old entries if they are no longer needed.<br />
            To list all open ports under Linux use the command <code>netstat -ln</code>
        """
        payload.tcp = natsorted(rules.get_rules_for_web("tcp"))
        payload.udp = natsorted(rules.get_rules_for_web("udp"))
        payload.custom = False
        if rules.diff_new_current("tcp") is True or rules.diff_new_current(
                "udp") is True:
            payload.custom = True
        payload.saved = saved
        return render_template('ports.html', vars=payload)
    return login()