Exemplo n.º 1
0
 def check_name(self, name):
     super(Zone, self).check_name(name)
     if name.startswith('/'):
         raise FirewallError(errors.INVALID_NAME,
                             "'%s' can't start with '/'" % name)
     elif name.endswith('/'):
         raise FirewallError(errors.INVALID_NAME,
                             "'%s' can't end with '/'" % name)
     elif name.count('/') > 1:
         raise FirewallError(errors.INVALID_NAME,
                             "more than one '/' in '%s'" % name)
     else:
         if "/" in name:
             checked_name = name[:name.find('/')]
         else:
             checked_name = name
         if len(checked_name) > max_zone_name_len():
             raise FirewallError(
                 errors.INVALID_NAME,
                 "Zone of '%s' has %d chars, max is %d %s" %
                 (name, len(checked_name), max_zone_name_len(),
                  self.combined))
         if self.fw_config:
             if checked_name in self.fw_config.get_policy_objects():
                 raise FirewallError(
                     errors.NAME_CONFLICT,
                     "Zones can't have the same name as a policy.")
Exemplo n.º 2
0
def zone_reader(filename, path):
    zone = Zone()
    if not filename.endswith(".xml"):
        raise FirewallError(INVALID_NAME,
                            "'%s' is missing .xml suffix" % filename)
    zone.name = filename[:-4]
    if len(zone.name) > max_zone_name_len():
        raise FirewallError(
            INVALID_NAME, "'%s' has %d chars, max is %d" %
            (zone.name, len(zone.name), max_zone_name_len()))
    zone.check_name(zone.name)
    zone.filename = filename
    zone.path = path
    zone.default = False if path.startswith(ETC_FIREWALLD) else True
    handler = zone_ContentHandler(zone)
    parser = sax.make_parser()
    parser.setContentHandler(handler)
    name = "%s/%s" % (path, filename)
    with open(name, "r") as f:
        parser.parse(f)
    del handler
    del parser
    if PY2:
        zone.encode_strings()
    return zone
Exemplo n.º 3
0
 def check_name(self, name):
     super(Zone, self).check_name(name)
     if name.startswith('/'):
         raise FirewallError(INVALID_NAME, "'%s' can't start with '/'" % name)
     elif name.endswith('/'):
         raise FirewallError(INVALID_NAME, "'%s' can't end with '/'" % name)
     elif name.count('/') > 1:
         raise FirewallError(INVALID_NAME, "more than one '/' in '%s'" % name)
     elif len(name) > max_zone_name_len():
         raise FirewallError(INVALID_NAME,
                             "'%s' has %d chars, max is %d" % (name, len(name), max_zone_name_len()))
Exemplo n.º 4
0
 def check_name(self, name):
     super(Zone, self).check_name(name)
     if name.startswith('/'):
         raise FirewallError(INVALID_NAME,
                             "'%s' can't start with '/'" % name)
     elif name.endswith('/'):
         raise FirewallError(INVALID_NAME, "'%s' can't end with '/'" % name)
     elif name.count('/') > 1:
         raise FirewallError(INVALID_NAME,
                             "more than one '/' in '%s'" % name)
     elif len(name) > max_zone_name_len():
         raise FirewallError(
             INVALID_NAME, "'%s' has %d chars, max is %d" %
             (name, len(name), max_zone_name_len()))
Exemplo n.º 5
0
def zone_reader(filename, path):
    zone = Zone()
    if not filename.endswith(".xml"):
        raise FirewallError(INVALID_NAME,
                            "'%s' is missing .xml suffix" % filename)
    zone.name = filename[:-4]
    if len(zone.name) > max_zone_name_len():
        raise FirewallError(INVALID_NAME,
                            "'%s' has %d chars, max is %d" % (zone.name, len(zone.name), max_zone_name_len()))
    zone.check_name(zone.name)
    zone.filename = filename
    zone.path = path
    zone.builtin = False if path.startswith(ETC_FIREWALLD) else True
    zone.default = zone.builtin
    handler = zone_ContentHandler(zone)
    parser = sax.make_parser()
    parser.setContentHandler(handler)
    name = "%s/%s" % (path, filename)
    with open(name, "r") as f:
        parser.parse(f)
    del handler
    del parser
    if PY2:
        zone.encode_strings()
    return zone
Exemplo n.º 6
0
 def check_name(self, name):
     super(Zone, self).check_name(name)
     if name.startswith('/'):
         raise FirewallError(errors.INVALID_NAME,
                             "'%s' can't start with '/'" % name)
     elif name.endswith('/'):
         raise FirewallError(errors.INVALID_NAME,
                             "'%s' can't end with '/'" % name)
     elif name.count('/') > 1:
         raise FirewallError(errors.INVALID_NAME,
                             "more than one '/' in '%s'" % name)
     else:
         if "/" in name:
             checked_name = name[:name.find('/')]
         else:
             checked_name = name
         if len(checked_name) > max_zone_name_len():
             raise FirewallError(
                 errors.INVALID_NAME,
                 "Zone of '%s' has %d chars, max is %d %s" %
                 (name, len(checked_name), max_zone_name_len(),
                  self.combined))
Exemplo n.º 7
0
 def check_name(self, name):
     super(Zone, self).check_name(name)
     if name.startswith('/'):
         raise FirewallError(
             errors.INVALID_NAME,
             "Zone '{}': name can't start with '/'".format(name))
     elif name.endswith('/'):
         raise FirewallError(
             errors.INVALID_NAME,
             "Zone '{}': name can't end with '/'".format(name))
     elif name.count('/') > 1:
         raise FirewallError(
             errors.INVALID_NAME,
             "Zone '{}': name has more than one '/'".format(name))
     else:
         if "/" in name:
             checked_name = name[:name.find('/')]
         else:
             checked_name = name
         if len(checked_name) > max_zone_name_len():
             raise FirewallError(
                 errors.INVALID_NAME,
                 "Zone '{}': name has {} chars, max is {}".format(
                     name, len(checked_name), max_zone_name_len()))
Exemplo n.º 8
0
def zone_reader(filename, path):
    zone = Zone()
    if not filename.endswith(".xml"):
        raise FirewallError(INVALID_NAME, filename)
    zone.name = filename[:-4]
    if len(zone.name) > max_zone_name_len():
        raise FirewallError(INVALID_NAME, filename)
    zone.check_name(zone.name)
    zone.filename = filename
    zone.path = path
    zone.default = False if path.startswith(ETC_FIREWALLD) else True
    handler = zone_ContentHandler(zone)
    parser = sax.make_parser()
    parser.setContentHandler(handler)
    name = "%s/%s" % (path, filename)
    with open(name, "r") as f:
        parser.parse(f)
    return zone
Exemplo n.º 9
0
def zone_reader(filename, path):
    zone = Zone()
    if not filename.endswith(".xml"):
        raise FirewallError(INVALID_NAME, filename)
    zone.name = filename[:-4]
    if len(zone.name) > max_zone_name_len():
        raise FirewallError(INVALID_NAME, filename)
    zone.check_name(zone.name)
    zone.filename = filename
    zone.path = path
    zone.default = False if path.startswith(ETC_FIREWALLD) else True
    handler = zone_ContentHandler(zone)
    parser = sax.make_parser()
    parser.setContentHandler(handler)
    name = "%s/%s" % (path, filename)
    with open(name, "r") as f:
        parser.parse(f)
    return zone
Exemplo n.º 10
0
    def _add_edit_zone(self, add):
        '''
    adds or edit zone (parameter add True if adding)
    '''
        zoneBaseInfo = {}
        zoneBaseInfo['max_zone_name_len'] = functions.max_zone_name_len()
        if not add:
            # fill zoneBaseInfo for zoneBaseDialog fields
            selected_zoneitem = self.selectedConfigurationCombo.selectedItem()
            if selected_zoneitem:
                selected_zone = selected_zoneitem.label()
                zone = self.fw.config().getZoneByName(selected_zone)
                settings = zone.getSettings()
                props = zone.get_properties()
                zoneBaseInfo['name'] = zone.get_property("name")
                zoneBaseInfo['version'] = settings.getVersion()
                zoneBaseInfo['short'] = settings.getShort()
                zoneBaseInfo['description'] = settings.getDescription()
                zoneBaseInfo['default'] = props["default"]
                zoneBaseInfo['builtin'] = props["builtin"]
                zoneBaseInfo['target'] = settings.getTarget()
                if zoneBaseInfo['target'] == DEFAULT_ZONE_TARGET:
                    zoneBaseInfo['target'] = 'default'

        zoneBaseDlg = zoneBaseDialog.ZoneBaseDialog(zoneBaseInfo)
        newZoneBaseInfo = zoneBaseDlg.run()
        # Cancelled if None is returned
        if newZoneBaseInfo is None:
            return

        if not add:
            if zoneBaseInfo['name']        == newZoneBaseInfo['name'] and \
               zoneBaseInfo['version']     == newZoneBaseInfo['version'] and  \
               zoneBaseInfo['short']       == newZoneBaseInfo['short'] and \
               zoneBaseInfo['description'] == newZoneBaseInfo['description'] and \
               zoneBaseInfo['target']      == newZoneBaseInfo['target']:
                # no changes
                return
            selected_zoneitem = self.selectedConfigurationCombo.selectedItem()
            if selected_zoneitem:
                selected_zone = selected_zoneitem.label()
                zone = self.fw.config().getZoneByName(selected_zone)
                if zoneBaseInfo['version'] != newZoneBaseInfo['version'] or  \
                 zoneBaseInfo['short'] != newZoneBaseInfo['short'] or \
                 zoneBaseInfo['description'] != newZoneBaseInfo['description'] or \
                 zoneBaseInfo['target'] != newZoneBaseInfo['target']:
                    settings = zone.getSettings()
                    settings.setVersion(newZoneBaseInfo['version'])
                    settings.setShort(newZoneBaseInfo['short'])
                    settings.setDescription(newZoneBaseInfo['description'])
                    settings.setTarget(newZoneBaseInfo['target'])
                    zone.update(settings)
                if zoneBaseInfo['name'] == newZoneBaseInfo['name']:
                    return
                zone.rename(newZoneBaseInfo['name'])
        else:
            settings = client.FirewallClientZoneSettings()
            settings.setVersion(newZoneBaseInfo['version'])
            settings.setShort(newZoneBaseInfo['short'])
            settings.setDescription(newZoneBaseInfo['description'])
            settings.setTarget(newZoneBaseInfo['target'])
            self.fw.config().addZone(newZoneBaseInfo['name'], settings)