Beispiel #1
0
    def create(self, parent):
        self.setIPv6()
        self.auto_update_id = True
        self.resource_id = None
        self.resource_parent = parent
        self.name_text.setText(u'')
        self.identifier_text.setText(u'')

        if parent:
            parent_type = parent['type']
            if not self.ruleset.is_template:
                if parent_type == GENERIC_INTERFACE_RESTYPE:
                    parent_type = INTERFACE_RESTYPE
                elif parent_type == GENERIC_NETWORK_RESTYPE:
                    parent_type = NETWORK_RESTYPE
            if parent_type == GENERIC_INTERFACE_RESTYPE:
                types = (GENERIC_NETWORK_RESTYPE, NETWORK_RESTYPE, IPSEC_NETWORK_RESTYPE)
                child_type = GENERIC_NETWORK_RESTYPE
            elif parent_type == INTERFACE_RESTYPE:
                types = (NETWORK_RESTYPE, IPSEC_NETWORK_RESTYPE)
                child_type = NETWORK_RESTYPE
            elif parent_type == GENERIC_NETWORK_RESTYPE:
                types = (
                    GENERIC_NETWORK_RESTYPE, NETWORK_RESTYPE, IPSEC_NETWORK_RESTYPE,
                    GENERIC_HOST_RESTYPE, HOST_RESTYPE, HOSTNAME_RESTYPE)
                child_type = GENERIC_HOST_RESTYPE
            else: # parent_type == NETWORK_RESTYPE:
                types = (
                    NETWORK_RESTYPE, IPSEC_NETWORK_RESTYPE,
                    HOST_RESTYPE, HOSTNAME_RESTYPE)
                if parent.isInternet():
                    child_type = HOSTNAME_RESTYPE
                else:
                    child_type = HOST_RESTYPE
        else:
            if self.ruleset.is_template:
                child_type = GENERIC_INTERFACE_RESTYPE
            else:
                child_type = INTERFACE_RESTYPE
            types = (child_type,)
        if (IPSEC_NETWORK_RESTYPE in types) \
        and (not self.compatibility.ipsec_network):
            types = list(types)
            types.remove(IPSEC_NETWORK_RESTYPE)
        self.setType(types, (len(types) != 1), child_type)

        if self.ipv6:
            mask = 64
        else:
            mask = 24
        network_text = u''
        if parent and ("address" in parent) and (not parent.isInternet()):
            text = parent['address']
            ip = IP(text)
            network_text = unicode(ip.net())
            if isNetwork(ip):
                address = unicode(IP(ip.int() + 1))
                mask = ip.prefixlen() + 1
            else:
                address = text
            self.identifier_text.setText(address)
        else:
            address = u''
        self.network_text.setText(network_text)
        self.ipsec_network_text.setText(network_text)
        self.address_text.setText(address)
        self.ipsec_gateway_text.setText(address)
        if address:
            self.auto_update_id = False
        if mask is not None:
            self.network_spin.setValue(mask)
            self.ipsec_network_spin.setValue(mask)
        self.hostname_text.setText(u'')

        self.setWindowTitle(tr("Create a new network"))
        self.identifier_text.setFocus()
        return self.execLoop()
Beispiel #2
0
def checkHost(address):
    if isNetwork(address):
        raise RulesetError(
            tr('"%s" is not an host address!'),
            unicode(address))