예제 #1
0
def test_server_nat_traversal():
    subnet = '192.168.0.0/24'
    address = '192.168.0.1'

    server = Server(
        'test-server',
        subnet,
        address=address,
    )

    server.add_nat_traversal('eth1')

    assert len(server.post_up) == 3
    for line in server.post_up:
        assert 'eth1' in line

    assert len(server.post_down) == 3
    for line in server.post_down:
        assert 'eth1' in line

    config = server.config().local_config
    assert 'PostUp' in config
    assert 'PostDown' in config
    assert 'iptables' in config
    assert 'eth1' in config
예제 #2
0
def server(
    endpoint,
    subnet,
    address=None,
    private_key=None,
    port=None,
    interface=None,
    nat_traversal_interface=None,
    write=False,
):
    """
    Display, and optionally write, a WireGuard basic server config
    """

    obj = Server(
        endpoint,
        subnet,
        endpoint=endpoint,
        address=address,
        private_key=private_key,
        port=port,
        interface=interface,
    )
    if nat_traversal_interface:
        obj.add_nat_traversal(nat_traversal_interface)

    click.echo(obj.config())

    if write:
        if os.path.isfile(obj.config().full_path):
            if not click.prompt(
                    f'{obj.config().full_path} exists! Overwrite? [y/N]'):
                click.Abort()
        if os.path.isfile(obj.config().peers_full_path):
            if not click.prompt(
                    f'{obj.config().peers_full_path} exists! Overwrite? [y/N]'
            ):
                click.Abort()

        obj.config().write()