Exemplo n.º 1
0
def get_custom_config(config):
    from mmc.plugins.shorewall import get_zones, get_zones_interfaces
    zones = get_zones('lan')
    interfaces = get_zones_interfaces(zones)
    options = []
    for interface in interfaces:
        if_detail = netifaces.ifaddresses(interface[1])
        # check interface is configured
        if netifaces.AF_INET in if_detail:
            addr = if_detail[netifaces.AF_INET][0]['addr']
            netmask = if_detail[netifaces.AF_INET][0]['netmask']
            network = str(IP(addr).make_net(netmask).net())
            options.append({
                'name': interface[0] + '(' + network + ')',
                'value': interface[1]
            })

    config.append({
        'slug':
        'mds_samba4',
        'name':
        'net',
        'require':
        'yes',
        'label':
        _('Network', 'mds_samba4'),
        'help':
        _('Choose the network for the DNS zone and DHCP.', 'mds_samba4'),
        'type':
        'options',
        'options':
        options
    })

    return config
Exemplo n.º 2
0
def get_internal_interfaces():
    """
    Return string with all the internal interfaces separated by a space
    Something like: "eth1 eth2"

    @rtype str
    @return Names of internal interfaces
    """
    shorewall_config = ShorewallPluginConfig("shorewall")
    interfaces = get_zones_interfaces(shorewall_config.internal_zones_names)
    if not interfaces:
        raise Exception("No internal networks detected")
    return " ".join([interface[1] for interface in interfaces])
Exemplo n.º 3
0
def get_push_networks_config(config):
    """
    Get list of internal networks to push to VPN clients
    """
    internal_zones = get_zones_types()[0]
    internal_interfaces = get_zones_interfaces(internal_zones)

    networks = []
    for interface in netifaces.interfaces():
        if interface.startswith(MANAGED_INTERFACE_NAMES):
            for internal_interface in internal_interfaces:
                if internal_interface[1] == interface:
                    detail = netifaces.ifaddresses(interface)
                    addr = detail[netifaces.AF_INET][0]['addr']
                    netmask = detail[netifaces.AF_INET][0]['netmask']
                    network = IP(addr).make_net(netmask)
                    networks.append(
                        [str(network.net()),
                         str(network.netmask())])

    config.append({
        'slug':
        'openvpn',
        'name':
        'push_networks',
        'label':
        _('Shared networks', 'openvpn'),
        'help':
        _(
            'The list of internal networks that will be accessible to VPN clients.',
            'openvpn'),
        'type':
        'network',
        'format':
        'long',
        'multi':
        'yes',
        'default':
        networks
    })

    return config
Exemplo n.º 4
0
def get_listen_config(config):
    """
    Get list of external addresses for openvpn
    """
    external_zones = get_zones_types()[1]
    external_interfaces = get_zones_interfaces(external_zones)

    ifaces = []
    for interface in netifaces.interfaces():
        if interface.startswith(MANAGED_INTERFACE_NAMES):
            for external_interface in external_interfaces:
                # tuple of ('zone', 'interface', 'options')
                if external_interface[1] == interface:
                    detail = netifaces.ifaddresses(interface)
                    addr = detail[netifaces.AF_INET][0]['addr']
                    ifaces.append({
                        'name':
                        '%s (%s)' % (addr, external_interface[0]),
                        'value':
                        "%s:%s" % (addr, external_interface[0])
                    })

    config.append({
        'slug':
        'openvpn',
        'name':
        'listen',
        'require':
        'yes',
        'label':
        _('Listen address', 'openvpn'),
        'help':
        _(
            'The IP address where the VPN server will listen. It must be accessible by your VPN clients.',
            'openvpn'),
        'type':
        'options',
        'options':
        ifaces
    })

    return config
Exemplo n.º 5
0
def get_custom_config(config):
    from mmc.plugins.shorewall import get_zones, get_zones_interfaces
    zones = get_zones('lan')
    interfaces = get_zones_interfaces(zones)
    options = []
    for interface in interfaces:
        if_detail = netifaces.ifaddresses(interface[1])
        # check interface is configured
        if netifaces.AF_INET in if_detail:
            addr = if_detail[netifaces.AF_INET][0]['addr']
            netmask = if_detail[netifaces.AF_INET][0]['netmask']
            network = str(IP(addr).make_net(netmask).net())
            options.append({'name': interface[0] + '(' + network + ')',
                            'value': interface[1]})

    config.append({'slug': 'mds_samba4',
                   'name': 'net',
                   'require': 'yes',
                   'label': _('Network', 'mds_samba4'),
                   'help': _('Choose the network for the DNS zone and DHCP.', 'mds_samba4'),
                   'type': 'options',
                   'options': options})

    return config