Example #1
0
    def test_generate_server_config(self):
        attachment_point = AttachmentPoint.objects.first()
        vpn = attachment_point.vpn
        server_config = generate_vpn_server_config(vpn)
        ifconfig_string_match = re.findall('ifconfig ([0-9.:]*) ([0-9.:]*)',
                                           server_config)
        self.assertEqual(len(ifconfig_string_match), 1)
        server_ip, netmask = ifconfig_string_match[0]
        route_string_match = re.findall('route ([0-9.:/]*) ([0-9.:]*)',
                                        server_config)
        self.assertEqual(len(route_string_match), 1)
        subnet, route_netmask = route_string_match[0]
        self.assertEqual(route_netmask, netmask)

        vpn_network = ipaddress.ip_network(vpn.subnet)

        # Check VPN IPs valid
        self.assertEqual(str(vpn_network.netmask), netmask)
        self.assertEqual(str(vpn_network), subnet)
        self.assertTrue(ipaddress.ip_address(server_ip) in vpn_network.hosts())

        # Check CCD
        user_as = create_user_as(attachment_point)

        vpn_client = user_as.hosts.first().vpn_clients.first()
        ccd_filename, ccd_config_entry = ccd_config(vpn_client)
        self.assertEqual(
            ccd_filename,
            vpn_client.host.AS.owner.email + "_" + user_as.as_path_str())
        ccd_string_match = re.findall(r'ifconfig-push (\S*) (\S*)',
                                      ccd_config_entry)
        self.assertTrue(len(ccd_string_match) == 1)
        client_ip, netmask = ccd_string_match[0]
        self.assertEqual(str(vpn_client.ip), client_ip)
        self.assertEqual(str(vpn_network.netmask), netmask)
Example #2
0
def _add_vpn_server_config(host, archive):
    server = host.vpn_servers.first()  # only one server per host supported for now
    if server:
        archive.write_text("server.conf", generate_vpn_server_config(server))
        archive.add_dir("ccd")
        for client in server.clients.iterator():
            common_name, config_string = ccd_config(client)
            archive.write_text("ccd/" + common_name, config_string)
Example #3
0
def _add_vpn_server_config(host, archive):
    vpn_dir = OPENVPN_CONFIG_DIR.lstrip(
        "/")  # don't use absolute paths in the archive
    server = host.vpn_servers.first(
    )  # only one server per host supported for now
    if server:
        archive.write_text((vpn_dir, "server.conf"),
                           generate_vpn_server_config(server))
        archive.add_dir((vpn_dir, "ccd"))
        for client in server.clients.iterator():
            common_name, config_string = ccd_config(client)
            archive.write_text((vpn_dir, "ccd", common_name), config_string)
Example #4
0
def _add_vpn_config(host, tar):
    """
    Generate the VPN config files and add them to the tar.
    """
    vpn_clients = list(host.vpn_clients.filter(active=True))
    for vpn_client in vpn_clients:
        client_config = generate_vpn_client_config(vpn_client)
        tar_add_textfile(tar, "client.conf", client_config)

    vpn_servers = list(host.vpn_servers.all())
    for vpn_server in vpn_servers:
        tar_add_textfile(tar, "server.conf",
                         generate_vpn_server_config(vpn_server))
        tar_add_dir(tar, 'ccd')
        for vpn_client in vpn_server.clients.iterator():
            common_name, config_string = ccd_config(vpn_client)
            tar_add_textfile(tar, 'ccd/' + common_name, config_string)
Example #5
0
def _add_vpn_config(host, archive):
    """
    Generate the VPN config files and add them to the tar.
    """
    vpn_clients = list(host.vpn_clients.filter(active=True))
    for vpn_client in vpn_clients:
        client_config = generate_vpn_client_config(vpn_client)
        archive.write_text("client.conf", client_config)

    vpn_servers = list(host.vpn_servers.all())
    for vpn_server in vpn_servers:
        archive.write_text("server.conf",
                           generate_vpn_server_config(vpn_server))
        archive.add_dir("ccd")
        for vpn_client in vpn_server.clients.iterator():
            common_name, config_string = ccd_config(vpn_client)
            archive.write_text("ccd/" + common_name, config_string)