当前位置: 首页>>代码示例>>Python>>正文


Python Checker.check_firewall_policy方法代码示例

本文整理汇总了Python中karesansui.lib.checker.Checker.check_firewall_policy方法的典型用法代码示例。如果您正苦于以下问题:Python Checker.check_firewall_policy方法的具体用法?Python Checker.check_firewall_policy怎么用?Python Checker.check_firewall_policy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在karesansui.lib.checker.Checker的用法示例。


在下文中一共展示了Checker.check_firewall_policy方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: validates_policy

# 需要导入模块: from karesansui.lib.checker import Checker [as 别名]
# 或者: from karesansui.lib.checker.Checker import check_firewall_policy [as 别名]
def validates_policy(obj):
    checker = Checker()
    check = True

    _ = obj._
    checker.errors = []

    if not is_param(obj.input, "input_policy"):
        check = False
        checker.add_error(_('"%s" is required.') % _("INPUT Chain"))
    else:
        check = (
            checker.check_firewall_policy(_("INPUT Chain"), obj.input.input_policy, CHECK_EMPTY | CHECK_VALID) and check
        )

    if not is_param(obj.input, "output_policy"):
        check = False
        checker.add_error(_('"%s" is required.') % _("OUTPUT Chain"))
    else:
        check = (
            checker.check_firewall_policy(_("OUTPUT Chain"), obj.input.output_policy, CHECK_EMPTY | CHECK_VALID)
            and check
        )

    if not is_param(obj.input, "forward_policy"):
        check = False
        checker.add_error(_('"%s" is required.') % _("FORWARD Chain"))
    else:
        check = (
            checker.check_firewall_policy(_("FORWARD Chain"), obj.input.input_policy, CHECK_EMPTY | CHECK_VALID)
            and check
        )

    obj.view.alert = checker.errors
    return check
开发者ID:goura,项目名称:karesansui,代码行数:37,代码来源:hostby1firewallpolicy.py

示例2: validates_rule

# 需要导入模块: from karesansui.lib.checker import Checker [as 别名]
# 或者: from karesansui.lib.checker.Checker import check_firewall_policy [as 别名]
def validates_rule(obj, is_newrule=False):
    checker = Checker()
    check = True
          
    _ = obj._ 
    checker.errors = []

    obj.view.error_msg = checker.errors

    if is_newrule: 
        kit = KaresansuiIpTables()
        rule_id_max_length = 1
        if os.path.exists(kit.firewall_xml_file) is False:
            check = False
            checker.add_error(_('Has not been initialized. Please initialize.'))
        else:
            kit.firewall_xml = kit.read_firewall_xml()
            rule_id_max_length += len(kit.get_rules())

        if not is_param(obj.input, 'rule_id'):
            check = False
            checker.add_error(_('"%s" is required.') % _('ID'))
        else:
            check = checker.check_number(
                    _('ID'),
                    obj.input.rule_id,
                    CHECK_EMPTY | CHECK_VALID | CHECK_MIN | CHECK_MAX,
                    min = ID_MIN_LENGTH,
                    max = rule_id_max_length,
                    ) and check

    if not is_param(obj.input, 'target'):
        check = False
        checker.add_error(_('"%s" is required.') % _('Target'))
    else:
        check = checker.check_firewall_policy(
                _('Target'),
                obj.input.target,
                CHECK_EMPTY | CHECK_VALID,
                ) and check

    if not is_param(obj.input, 'protocol'):
        check = False
        checker.add_error(_('"%s" is required.') % _('Protocol'))
    else:
        check = checker.check_firewall_protocol(
                _('Protocol'),
                obj.input.protocol,
                CHECK_VALID,
                ) and check

    if not is_param(obj.input, 'source'):
        check = False
        checker.add_error(_('"%s" is required.') % _('Source Address'))
    else:
        check = checker.check_ipaddr(
                _('Source Address'),
                obj.input.source,
                CHECK_VALID,
                ) and check

    if not is_param(obj.input, 'sport'):
        check = False
        checker.add_error(_('"%s" is required.') % _('Source Port'))
    else:
        if obj.input.protocol == 'tcp' or obj.input.protocol == 'udp':
            check = checker.check_number(
                    _('Source Port'),
                    obj.input.sport,
                    CHECK_VALID | CHECK_MIN | CHECK_MAX,
                    min = PORT_MIN_NUMBER,
                    max = PORT_MAX_NUMBER,
                    ) and check

    if not is_param(obj.input, 'destination'):
        check = False
        checker.add_error(_('"%s" is required.') % _('Destination Address'))
    else:
        check = checker.check_ipaddr(
                _('Destination Address'),
                obj.input.destination,
                CHECK_VALID,
                ) and check

    if not is_param(obj.input, 'dport'):
        check = False
        checker.add_error(_('"%s" is required.') % _('Destination Port'))
    else:
        if obj.input.protocol == 'tcp' or obj.input.protocol == 'udp':
            check = checker.check_number(
                    _('Destination Port'),
                    obj.input.dport,
                    CHECK_VALID | CHECK_MIN | CHECK_MAX,
                    min = PORT_MIN_NUMBER,
                    max = PORT_MAX_NUMBER,
                    ) and check

    if not is_param(obj.input, 'inif'):
        check = False
        checker.add_error(_('"%s" is required.') % _('In Interface'))
#.........这里部分代码省略.........
开发者ID:AdUser,项目名称:karesansui,代码行数:103,代码来源:hostby1firewallrule.py


注:本文中的karesansui.lib.checker.Checker.check_firewall_policy方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。